11import { Format , PresentationDefinitionV1 , PresentationDefinitionV2 , PresentationSubmission } from '@sphereon/pex-models' ;
22import {
33 CompactSdJwtVc ,
4- CredentialMapper ,
54 Hasher ,
65 ICredential ,
76 IPresentation ,
87 IProof ,
98 JwtDecodedVerifiableCredential ,
10- OriginalVerifiableCredential ,
11- OriginalVerifiablePresentation ,
129 OrPromise ,
1310 SdJwtDecodedVerifiableCredential ,
1411 W3CVerifiableCredential ,
1512 W3CVerifiablePresentation ,
16- WrappedVerifiableCredential ,
17- WrappedVerifiablePresentation ,
1813} from '@sphereon/ssi-types' ;
1914
2015import { Status } from './ConstraintUtils' ;
@@ -30,6 +25,13 @@ import {
3025 VerifiablePresentationResult ,
3126} from './signing' ;
3227import { DiscoveredVersion , IInternalPresentationDefinition , IPresentationDefinition , OrArray , PEVersion , SSITypesBuilder } from './types' ;
28+ import {
29+ OriginalVerifiableCredential ,
30+ OriginalVerifiablePresentation ,
31+ PexCredentialMapper ,
32+ WrappedVerifiableCredential ,
33+ WrappedVerifiablePresentation ,
34+ } from './types/PexCredentialMapper' ;
3335import { calculateSdHash , definitionVersionDiscovery , formatValidationErrors , getSubjectIdsAsString } from './utils' ;
3436import { PresentationDefinitionV1VB , PresentationDefinitionV2VB , PresentationSubmissionVB , Validated , ValidationEngine } from './validation' ;
3537
@@ -38,7 +40,7 @@ export interface PEXOptions {
3840 * Hasher implementation, can be used for tasks such as decoding a compact SD-JWT VC to it's encoded variant.
3941 * When decoding SD-JWT credentials the hasher must be provided. The hasher implementation must be sync. When using
4042 * an async hasher implementation, you must manually decode the credential or presentation first according to the
41- * `SdJwtDecodedVerifiableCredential` interface. You can use the `CredentialMapper .decodeSdJwtAsync` method for
43+ * `SdJwtDecodedVerifiableCredential` interface. You can use the `PexCredentialMapper .decodeSdJwtAsync` method for
4244 * this from the `@sphereon/ssi-types` package. NOTE that this is only needed when using an async hasher, and
4345 * that for sync hashers providing it here is enough for the decoding to be done automatically.
4446 */
@@ -106,15 +108,15 @@ export class PEX {
106108 let presentationSubmission = opts ?. presentationSubmission ;
107109 let presentationSubmissionLocation =
108110 opts ?. presentationSubmissionLocation ??
109- ( ( Array . isArray ( presentations ) && presentations . length > 1 ) || ! CredentialMapper . isW3cPresentation ( wrappedPresentations [ 0 ] . presentation )
111+ ( ( Array . isArray ( presentations ) && presentations . length > 1 ) || ! PexCredentialMapper . isW3cPresentation ( wrappedPresentations [ 0 ] . presentation )
110112 ? PresentationSubmissionLocation . EXTERNAL
111113 : PresentationSubmissionLocation . PRESENTATION ) ;
112114
113115 // When only one presentation, we also allow it to be present in the VP
114116 if (
115117 ! presentationSubmission &&
116118 presentationsArray . length === 1 &&
117- CredentialMapper . isW3cPresentation ( wrappedPresentations [ 0 ] . presentation ) &&
119+ PexCredentialMapper . isW3cPresentation ( wrappedPresentations [ 0 ] . presentation ) &&
118120 ! generatePresentationSubmission
119121 ) {
120122 const decoded = wrappedPresentations [ 0 ] . decoded ;
@@ -138,7 +140,7 @@ export class PEX {
138140 // `wrappedPresentation.original.compactKbJwt`, but as HAIP doesn't use dids, we'll leave it for now.
139141 const holderDIDs = wrappedPresentations
140142 . map ( ( p ) => {
141- return CredentialMapper . isW3cPresentation ( p . presentation ) && p . presentation . holder ? p . presentation . holder : undefined ;
143+ return PexCredentialMapper . isW3cPresentation ( p . presentation ) && p . presentation . holder ? p . presentation . holder : undefined ;
142144 } )
143145 . filter ( ( d ) : d is string => d !== undefined ) ;
144146
@@ -269,7 +271,9 @@ export class PEX {
269271 opts ?: PresentationFromOpts ,
270272 ) : PresentationResult {
271273 const presentationSubmission = this . presentationSubmissionFrom ( presentationDefinition , selectedCredentials , opts ) ;
272- const hasSdJwtCredentials = selectedCredentials . some ( ( c ) => CredentialMapper . isSdJwtDecodedCredential ( c ) || CredentialMapper . isSdJwtEncoded ( c ) ) ;
274+ const hasSdJwtCredentials = selectedCredentials . some (
275+ ( c ) => PexCredentialMapper . isSdJwtDecodedCredential ( c ) || PexCredentialMapper . isSdJwtEncoded ( c ) ,
276+ ) ;
273277
274278 // We could include it in the KB-JWT? Not sure if we want that
275279 if ( opts ?. presentationSubmissionLocation === PresentationSubmissionLocation . PRESENTATION && hasSdJwtCredentials ) {
@@ -310,7 +314,7 @@ export class PEX {
310314 }
311315 const verifiableCredential = ( Array . isArray ( selectedCredentials ) ? selectedCredentials : [ selectedCredentials ] ) as W3CVerifiableCredential [ ] ;
312316
313- const wVCs = verifiableCredential . map ( ( vc ) => CredentialMapper . toWrappedVerifiableCredential ( vc ) ) ;
317+ const wVCs = verifiableCredential . map ( ( vc ) => PexCredentialMapper . toWrappedVerifiableCredential ( vc ) ) ;
314318 const holders = Array . from ( new Set ( wVCs . flatMap ( ( wvc ) => getSubjectIdsAsString ( wvc . credential as ICredential ) ) ) ) ;
315319 const holder = opts ?. holderDID ?? ( holders . length === 1 ? holders [ 0 ] : undefined ) ;
316320
@@ -352,10 +356,10 @@ export class PEX {
352356 } ) ;
353357 } else {
354358 verifiableCredential . forEach ( ( vc ) => {
355- if ( CredentialMapper . isSdJwtDecodedCredential ( vc ) ) {
359+ if ( PexCredentialMapper . isSdJwtDecodedCredential ( vc ) ) {
356360 result . push ( vc as PartialSdJwtDecodedVerifiableCredential ) ;
357- } else if ( CredentialMapper . isSdJwtEncoded ( vc ) ) {
358- const decoded = CredentialMapper . decodeVerifiableCredential ( vc ) ;
361+ } else if ( PexCredentialMapper . isSdJwtEncoded ( vc ) ) {
362+ const decoded = PexCredentialMapper . decodeVerifiableCredential ( vc ) ;
359363 result . push ( decoded as PartialSdJwtDecodedVerifiableCredential ) ;
360364 } else {
361365 // This should be jwt or json-ld
@@ -377,15 +381,15 @@ export class PEX {
377381 TODO SDK-37 refinement needed
378382 */
379383 private static allowMultipleVCsPerPresentation ( verifiableCredentials : Array < OriginalVerifiableCredential > ) : boolean {
380- const jwtCredentials = verifiableCredentials . filter ( ( c ) => CredentialMapper . isJwtEncoded ( c ) || CredentialMapper . isJwtDecodedCredential ( c ) ) ;
384+ const jwtCredentials = verifiableCredentials . filter ( ( c ) => PexCredentialMapper . isJwtEncoded ( c ) || PexCredentialMapper . isJwtDecodedCredential ( c ) ) ;
381385
382386 if ( jwtCredentials . length > 0 ) {
383387 const subjects = new Set < string > ( ) ;
384388 const verificationMethods = new Set < string > ( ) ;
385389
386390 for ( const credential of jwtCredentials ) {
387- const decodedCredential = CredentialMapper . isJwtEncoded ( credential )
388- ? ( CredentialMapper . decodeVerifiableCredential ( credential ) as JwtDecodedVerifiableCredential )
391+ const decodedCredential = PexCredentialMapper . isJwtEncoded ( credential )
392+ ? ( PexCredentialMapper . decodeVerifiableCredential ( credential ) as JwtDecodedVerifiableCredential )
389393 : ( credential as JwtDecodedVerifiableCredential ) ;
390394
391395 const subject =
@@ -406,7 +410,7 @@ export class PEX {
406410 }
407411 }
408412
409- if ( verifiableCredentials . some ( ( c ) => CredentialMapper . isSdJwtEncoded ( c ) || CredentialMapper . isSdJwtDecodedCredential ( c ) ) ) {
413+ if ( verifiableCredentials . some ( ( c ) => PexCredentialMapper . isSdJwtEncoded ( c ) || PexCredentialMapper . isSdJwtDecodedCredential ( c ) ) ) {
410414 return false ;
411415 }
412416
@@ -568,7 +572,7 @@ export class PEX {
568572 ) {
569573 presentations . forEach ( ( presentation , index ) => {
570574 // Select type without kbJwt as isSdJwtDecodedCredential and won't accept the partial sdvc type
571- if ( CredentialMapper . isSdJwtDecodedCredential ( presentation as SdJwtDecodedVerifiableCredential ) ) {
575+ if ( PexCredentialMapper . isSdJwtDecodedCredential ( presentation as SdJwtDecodedVerifiableCredential ) ) {
572576 const sdJwtCredential = presentation as SdJwtDecodedVerifiableCredential ;
573577
574578 // extract sd_alg or default to sha-256
0 commit comments