@animo-id/pex
Version:
A Typescript implementation of the v1 and v2 DIF Presentation Exchange specification
116 lines • 10.7 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.PEXv1 = void 0;
const PEX_1 = require("./PEX");
const evaluation_1 = require("./evaluation");
const signing_1 = require("./signing");
const types_1 = require("./types");
const PexCredentialMapper_1 = require("./types/PexCredentialMapper");
const validation_1 = require("./validation");
/**
* This is the main interfacing class for using this library for v1 of presentation exchange
*/
class PEXv1 extends PEX_1.PEX {
/***
* The evaluatePresentationV1 compares what is expected from a presentation with a presentationDefinitionV1.
*
* @param presentationDefinition the definition of what is expected in the presentation.
* @param presentation the presentation which has to be evaluated in comparison of the definition.
* @param opts - limitDisclosureSignatureSuites the credential signature suites that support limit disclosure
*
* @return the evaluation results specify what was expected and was fulfilled and also specifies which requirements described in the input descriptors
* were not fulfilled by the presentation.
*/
evaluatePresentation(presentationDefinition, presentation, opts) {
types_1.SSITypesBuilder.modelEntityToInternalPresentationDefinitionV1(presentationDefinition); // only doing validation
return super.evaluatePresentation(presentationDefinition, presentation, opts);
}
/***
* To evaluate compares what is expected from a verifiableCredentials with the presentationDefinition.
*
* @param presentationDefinition the v1 definition of what is expected in the presentation.
* @param verifiableCredentials the verifiable credentials which are candidates to fulfill requirements defined in the presentationDefinition param.
* @param opts - holderDIDs the list of the DIDs that the wallet holders controlls.
* limitDisclosureSignatureSuites the credential signature suites that support limit disclosure
*
* @return the evaluation results specify what was expected and was fulfilled and also specifies which requirements described in the input descriptors
* were not fulfilled by the verifiable credentials.
*/
evaluateCredentials(presentationDefinition, verifiableCredentials, opts) {
types_1.SSITypesBuilder.modelEntityToInternalPresentationDefinitionV1(presentationDefinition); // only doing validation
return super.evaluateCredentials(presentationDefinition, verifiableCredentials, opts);
}
/**
* The selectFrom method is a helper function that helps filter out the verifiable credentials which can not be selected and returns
* the selectable credentials.
*
* @param presentationDefinition the v1 definition of what is expected in the presentation.
* @param verifiableCredentials verifiable credentials are the credentials from wallet provided to the library to find selectable credentials.
* @param opts - holderDIDs the decentralized identity of the wallet holderDID. This is used to identify the credentials issued to the holderDID of wallet.
* limitDisclosureSignatureSuites the credential signature suites that support limit disclosure
*
* @return the selectable credentials.
*/
selectFrom(presentationDefinition, verifiableCredentials, opts) {
const verifiableCredentialCopy = JSON.parse(JSON.stringify(verifiableCredentials));
this._evaluationClientWrapper = new evaluation_1.EvaluationClientWrapper();
return this._evaluationClientWrapper.selectFrom(types_1.SSITypesBuilder.modelEntityToInternalPresentationDefinitionV1(presentationDefinition), types_1.SSITypesBuilder.mapExternalVerifiableCredentialsToWrappedVcs(verifiableCredentialCopy), opts);
}
/**
* This method helps create a submittablePresentation. A submittablePresentation after signing becomes a Presentation. And can be sent to
* the verifier after signing it.
*
* IMPORTANT NOTE: this method creates a presentation object based on the SELECTED verifiable credentials. You can get the selected verifiable credentials using selectFrom method
*
* @param presentationDefinition the v1 definition of what is expected in the presentation.
* @param selectedCredentials the credentials which were declared selectable by getSelectableCredentials and then chosen by the intelligent-user
* (e.g. human).
* @param opts - holderDID optional; the decentralized identity of the wallet holderDID. This is used to identify the holderDID of the presentation.
*
* @return the presentation.
*/
presentationFrom(presentationDefinition, selectedCredentials, opts) {
var _a;
const presentationSubmission = this._evaluationClientWrapper.submissionFrom(types_1.SSITypesBuilder.modelEntityToInternalPresentationDefinitionV1(presentationDefinition), types_1.SSITypesBuilder.mapExternalVerifiableCredentialsToWrappedVcs(selectedCredentials), opts);
const hasSdJwtCredentials = selectedCredentials.some((c) => PexCredentialMapper_1.PexCredentialMapper.isSdJwtDecodedCredential(c) || PexCredentialMapper_1.PexCredentialMapper.isSdJwtEncoded(c));
// We could include it in the KB-JWT? Not sure if we want that
if ((opts === null || opts === void 0 ? void 0 : opts.presentationSubmissionLocation) === signing_1.PresentationSubmissionLocation.PRESENTATION && hasSdJwtCredentials) {
throw new Error('Presentation submission location cannot be set to presentation when creating a presentation with an SD-JWT VC');
}
const presentationSubmissionLocation = (_a = opts === null || opts === void 0 ? void 0 : opts.presentationSubmissionLocation) !== null && _a !== void 0 ? _a : (hasSdJwtCredentials ? signing_1.PresentationSubmissionLocation.EXTERNAL : signing_1.PresentationSubmissionLocation.PRESENTATION);
const presentations = this.constructPresentations(selectedCredentials, Object.assign(Object.assign({}, opts), { presentationSubmission: presentationSubmissionLocation === signing_1.PresentationSubmissionLocation.PRESENTATION ? presentationSubmission : undefined }));
return {
presentations,
presentationSubmissionLocation,
presentationSubmission,
};
}
/**
* This method validates whether an object is usable as a presentation definition or not.
*
* @param presentationDefinitionV1 the object to be validated.
*
* @return the validation results to reveal what is acceptable/unacceptable about the passed object to be considered a valid presentation definition
*/
static validateDefinition(presentationDefinitionV1) {
const pd = types_1.SSITypesBuilder.modelEntityToInternalPresentationDefinitionV1(presentationDefinitionV1);
return new validation_1.ValidationEngine().validate([
{
bundler: new validation_1.PresentationDefinitionV1VB('root'),
target: pd,
},
]);
}
/**
* This method validates whether an object is usable as a presentation submission or not.
*
* @param presentationSubmission the object to be validated.
*
* @return the validation results to reveal what is acceptable/unacceptable about the passed object to be considered a valid presentation submission
*/
static validateSubmission(presentationSubmission) {
return PEX_1.PEX.validateSubmission(presentationSubmission);
}
}
exports.PEXv1 = PEXv1;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiUEVYdjEuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9saWIvUEVYdjEudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7O0FBR0EsK0JBQTRCO0FBQzVCLDZDQUF3SDtBQUN4SCx1Q0FBcUc7QUFDckcsbUNBQTBDO0FBQzFDLHFFQUFnSTtBQUNoSSw2Q0FBdUY7QUFFdkY7O0dBRUc7QUFDSCxNQUFhLEtBQU0sU0FBUSxTQUFHO0lBQzVCOzs7Ozs7Ozs7T0FTRztJQUNJLG9CQUFvQixDQUN6QixzQkFBZ0QsRUFDaEQsWUFBNEQsRUFDNUQsSUF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