UNPKG

@sphereon/pex

Version:

A Typescript implementation of the v1 and v2 DIF Presentation Exchange specification

113 lines 10.3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PEXv2 = void 0; const ssi_types_1 = require("@sphereon/ssi-types"); const PEX_1 = require("./PEX"); const evaluation_1 = require("./evaluation"); const signing_1 = require("./signing"); const types_1 = require("./types"); const validation_1 = require("./validation"); /** * This is the main interfacing class to be used from outside the library to use the functionality provided by the library. */ class PEXv2 extends PEX_1.PEX { /*** * The evaluatePresentationV2 compares what is expected from a presentation with a presentationDefinitionV2. * * @param presentationDefinition the definition of what is expected in the presentation. * @param presentations 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.modelEntityInternalPresentationDefinitionV2(presentationDefinition); // only doing validation return super.evaluatePresentation(presentationDefinition, presentation, opts); } /*** * The evaluateCredentialsV2 compares what is expected from a verifiableCredentials with the presentationDefinitionV2. * * @param presentationDefinition the v2 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.modelEntityInternalPresentationDefinitionV2(presentationDefinition); // only doing validation return super.evaluateCredentials(presentationDefinition, verifiableCredentials, opts); } /** * The selectFromV2 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 v2 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) { this._evaluationClientWrapper = new evaluation_1.EvaluationClientWrapper(); return this._evaluationClientWrapper.selectFrom(types_1.SSITypesBuilder.modelEntityInternalPresentationDefinitionV2(presentationDefinition), types_1.SSITypesBuilder.mapExternalVerifiableCredentialsToWrappedVcs(verifiableCredentials), opts); } /** * This method helps create a Presentation. A Presentation after signing becomes a Verifiable Presentation and can be sent to * a verifier. * * @param presentationDefinition the v2 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 identifier of the Credential subject. 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.modelEntityInternalPresentationDefinitionV2(presentationDefinition), types_1.SSITypesBuilder.mapExternalVerifiableCredentialsToWrappedVcs(selectedCredentials), opts); const hasSdJwtCredentials = selectedCredentials.some((c) => ssi_types_1.CredentialMapper.isSdJwtDecodedCredential(c) || ssi_types_1.CredentialMapper.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 presentationDefinitionV2 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(presentationDefinitionV2) { const pd = types_1.SSITypesBuilder.modelEntityInternalPresentationDefinitionV2(presentationDefinitionV2); return new validation_1.ValidationEngine().validate([ { bundler: new validation_1.PresentationDefinitionV2VB('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.PEXv2 = PEXv2; //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiUEVYdjIuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9saWIvUEVYdjIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7O0FBQ0EsbURBQW9JO0FBRXBJLCtCQUE0QjtBQUM1Qiw2Q0FBd0g7QUFDeEgsdUNBQXFHO0FBQ3JHLG1DQUEwQztBQUMxQyw2Q0FBdUY7QUFFdkY7O0dBRUc7QUFDSCxNQUFhLEtBQU0sU0FBUSxTQUFHO0lBQzVCOzs7Ozs7Ozs7T0FTRztJQUNJLG9CQUFvQixDQUN6QixzQkFBZ0QsRUFDaEQsWUFBNEQsRUFDNUQsSUFJQztRQUVELHVCQUFlLENBQUMsMkNBQTJDLENBQUMsc0JBQXNCLENBQUMsQ0FBQyxDQUFDLHdCQUF3QjtRQUM3RyxPQUFPLEtBQUssQ0FBQyxvQkFBb0IsQ0FBQyxzQkFBc0IsRUFBRSxZQUFZLEVBQUUsSUFBSSxDQUFDLENBQUM7SUFDaEYsQ0FBQztJQUVEOzs7Ozs7Ozs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