@sphereon/ssi-types 0.28.1-next.51 → 0.28.1-next.52

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sphereon/ssi-types",
3
3
  "description": "SSI Common Types",
4
- "version": "0.28.1-next.51+ff2d0615",
4
+ "version": "0.28.1-next.52+a462f5db",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "scripts": {
@@ -44,5 +44,5 @@
44
44
  "Verifiable Credentials",
45
45
  "DIDs"
46
46
  ],
47
- "gitHead": "ff2d0615809c84db792f2d5cb96d2ef9eb0e8c83"
47
+ "gitHead": "a462f5dbcd8fd274d150273b03f908bf24ef01ae"
48
48
  }
@@ -54,7 +54,7 @@ export class CredentialMapper {
54
54
  */
55
55
  static decodeVerifiablePresentation(
56
56
  presentation: OriginalVerifiablePresentation,
57
- hasher?: Hasher
57
+ hasher?: Hasher,
58
58
  ): JwtDecodedVerifiablePresentation | IVerifiablePresentation | SdJwtDecodedVerifiableCredential {
59
59
  if (CredentialMapper.isJwtEncoded(presentation)) {
60
60
  const payload = jwt_decode(presentation as string) as JwtDecodedVerifiablePresentation
@@ -95,7 +95,7 @@ export class CredentialMapper {
95
95
  */
96
96
  static decodeVerifiableCredential(
97
97
  credential: OriginalVerifiableCredential,
98
- hasher?: Hasher
98
+ hasher?: Hasher,
99
99
  ): JwtDecodedVerifiableCredential | IVerifiableCredential | SdJwtDecodedVerifiableCredential {
100
100
  if (CredentialMapper.isJwtEncoded(credential)) {
101
101
  const payload = jwt_decode(credential as string) as JwtDecodedVerifiableCredential
@@ -135,7 +135,7 @@ export class CredentialMapper {
135
135
  */
136
136
  static toWrappedVerifiablePresentation(
137
137
  originalPresentation: OriginalVerifiablePresentation,
138
- opts?: { maxTimeSkewInMS?: number; hasher?: Hasher }
138
+ opts?: { maxTimeSkewInMS?: number; hasher?: Hasher },
139
139
  ): WrappedVerifiablePresentation {
140
140
  // SD-JWT
141
141
  if (CredentialMapper.isSdJwtDecodedCredential(originalPresentation) || CredentialMapper.isSdJwtEncoded(originalPresentation)) {
@@ -165,7 +165,7 @@ export class CredentialMapper {
165
165
  typeof originalPresentation !== 'string' && CredentialMapper.hasJWTProofType(originalPresentation) ? proof?.jwt : originalPresentation
166
166
  if (!original) {
167
167
  throw Error(
168
- 'Could not determine original presentation, probably it was a converted JWT presentation, that is now missing the JWT value in the proof'
168
+ 'Could not determine original presentation, probably it was a converted JWT presentation, that is now missing the JWT value in the proof',
169
169
  )
170
170
  }
171
171
  const decoded = CredentialMapper.decodeVerifiablePresentation(original) as IVerifiablePresentation | JwtDecodedVerifiablePresentation
@@ -193,7 +193,7 @@ export class CredentialMapper {
193
193
  ? []
194
194
  : (CredentialMapper.toWrappedVerifiableCredentials(
195
195
  vp.verifiableCredential ?? [] /*.map(value => value.original)*/,
196
- opts
196
+ opts,
197
197
  ) as WrappedW3CVerifiableCredential[])
198
198
 
199
199
  const presentation = {
@@ -221,7 +221,7 @@ export class CredentialMapper {
221
221
  */
222
222
  static toWrappedVerifiableCredentials(
223
223
  verifiableCredentials: OriginalVerifiableCredential[],
224
- opts?: { maxTimeSkewInMS?: number; hasher?: Hasher }
224
+ opts?: { maxTimeSkewInMS?: number; hasher?: Hasher },
225
225
  ): WrappedVerifiableCredential[] {
226
226
  return verifiableCredentials.map((vc) => CredentialMapper.toWrappedVerifiableCredential(vc, opts))
227
227
  }
@@ -237,7 +237,7 @@ export class CredentialMapper {
237
237
  */
238
238
  static toWrappedVerifiableCredential(
239
239
  verifiableCredential: OriginalVerifiableCredential,
240
- opts?: { maxTimeSkewInMS?: number; hasher?: Hasher }
240
+ opts?: { maxTimeSkewInMS?: number; hasher?: Hasher },
241
241
  ): WrappedVerifiableCredential {
242
242
  // SD-JWT
243
243
  if (CredentialMapper.isSdJwtDecodedCredential(verifiableCredential) || CredentialMapper.isSdJwtEncoded(verifiableCredential)) {
@@ -265,7 +265,7 @@ export class CredentialMapper {
265
265
  const original = CredentialMapper.hasJWTProofType(verifiableCredential) && proof ? (proof.jwt ?? verifiableCredential) : verifiableCredential
266
266
  if (!original) {
267
267
  throw Error(
268
- 'Could not determine original credential, probably it was a converted JWT credential, that is now missing the JWT value in the proof'
268
+ 'Could not determine original credential, probably it was a converted JWT credential, that is now missing the JWT value in the proof',
269
269
  )
270
270
  }
271
271
  const decoded = CredentialMapper.decodeVerifiableCredential(original) as JwtDecodedVerifiableCredential | IVerifiableCredential
@@ -360,13 +360,13 @@ export class CredentialMapper {
360
360
  }
361
361
 
362
362
  public static isW3cPresentation(
363
- presentation: UniformVerifiablePresentation | IPresentation | SdJwtDecodedVerifiableCredential
363
+ presentation: UniformVerifiablePresentation | IPresentation | SdJwtDecodedVerifiableCredential,
364
364
  ): presentation is IPresentation {
365
365
  return '@context' in presentation && ((presentation as IPresentation).type?.includes('VerifiablePresentation') || false)
366
366
  }
367
367
 
368
368
  public static isSdJwtDecodedCredentialPayload(
369
- credential: ICredential | SdJwtDecodedVerifiableCredentialPayload
369
+ credential: ICredential | SdJwtDecodedVerifiableCredentialPayload,
370
370
  ): credential is SdJwtDecodedVerifiableCredentialPayload {
371
371
  return 'vct' in credential
372
372
  }
@@ -388,7 +388,7 @@ export class CredentialMapper {
388
388
  }
389
389
 
390
390
  public static isSdJwtDecodedCredential(
391
- original: OriginalVerifiableCredential | OriginalVerifiablePresentation | ICredential | IPresentation
391
+ original: OriginalVerifiableCredential | OriginalVerifiablePresentation | ICredential | IPresentation,
392
392
  ): original is SdJwtDecodedVerifiableCredential {
393
393
  return (<SdJwtDecodedVerifiableCredential>original).compactSdJwtVc !== undefined
394
394
  }
@@ -409,7 +409,7 @@ export class CredentialMapper {
409
409
  static jwtEncodedPresentationToUniformPresentation(
410
410
  jwt: string,
411
411
  makeCredentialsUniform: boolean = true,
412
- opts?: { maxTimeSkewInMS?: number }
412
+ opts?: { maxTimeSkewInMS?: number },
413
413
  ): IPresentation {
414
414
  return CredentialMapper.jwtDecodedPresentationToUniformPresentation(jwt_decode(jwt), makeCredentialsUniform, opts)
415
415
  }
@@ -417,7 +417,7 @@ export class CredentialMapper {
417
417
  static jwtDecodedPresentationToUniformPresentation(
418
418
  decoded: JwtDecodedVerifiablePresentation,
419
419
  makeCredentialsUniform: boolean = true,
420
- opts?: { maxTimeSkewInMS?: number }
420
+ opts?: { maxTimeSkewInMS?: number },
421
421
  ): IVerifiablePresentation {
422
422
  const { iss, aud, jti, vp, ...rest } = decoded
423
423
 
@@ -463,7 +463,7 @@ export class CredentialMapper {
463
463
  verifiableCredential: OriginalVerifiableCredential,
464
464
  opts?: {
465
465
  maxTimeSkewInMS?: number
466
- }
466
+ },
467
467
  ): IVerifiableCredential {
468
468
  if (CredentialMapper.isSdJwtDecodedCredential(verifiableCredential)) {
469
469
  throw new Error('Converting SD-JWT VC to uniform VC is not supported.')
@@ -474,7 +474,7 @@ export class CredentialMapper {
474
474
  : verifiableCredential
475
475
  if (!original) {
476
476
  throw Error(
477
- 'Could not determine original credential from passed in credential. Probably because a JWT proof type was present, but now is not available anymore'
477
+ 'Could not determine original credential from passed in credential. Probably because a JWT proof type was present, but now is not available anymore',
478
478
  )
479
479
  }
480
480
  const decoded = CredentialMapper.decodeVerifiableCredential(original)
@@ -491,7 +491,7 @@ export class CredentialMapper {
491
491
 
492
492
  static toUniformPresentation(
493
493
  presentation: OriginalVerifiablePresentation,
494
- opts?: { maxTimeSkewInMS?: number; addContextIfMissing?: boolean }
494
+ opts?: { maxTimeSkewInMS?: number; addContextIfMissing?: boolean },
495
495
  ): IVerifiablePresentation {
496
496
  if (CredentialMapper.isSdJwtDecodedCredential(presentation)) {
497
497
  throw new Error('Converting SD-JWT VC to uniform VP is not supported.')
@@ -501,7 +501,7 @@ export class CredentialMapper {
501
501
  const original = typeof presentation !== 'string' && CredentialMapper.hasJWTProofType(presentation) ? proof?.jwt : presentation
502
502
  if (!original) {
503
503
  throw Error(
504
- 'Could not determine original presentation, probably it was a converted JWT presentation, that is now missing the JWT value in the proof'
504
+ 'Could not determine original presentation, probably it was a converted JWT presentation, that is now missing the JWT value in the proof',
505
505
  )
506
506
  }
507
507
  const decoded = CredentialMapper.decodeVerifiablePresentation(original)
@@ -518,7 +518,7 @@ export class CredentialMapper {
518
518
  }
519
519
 
520
520
  uniformPresentation.verifiableCredential = uniformPresentation.verifiableCredential?.map((vc) =>
521
- CredentialMapper.toUniformCredential(vc, opts)
521
+ CredentialMapper.toUniformCredential(vc, opts),
522
522
  ) as IVerifiableCredential[] // We cast it because we IPresentation needs a VC. The internal Credential doesn't have the required Proof anymore (that is intended)
523
523
  return uniformPresentation
524
524
  }
@@ -527,14 +527,14 @@ export class CredentialMapper {
527
527
  jwt: string,
528
528
  opts?: {
529
529
  maxTimeSkewInMS?: number
530
- }
530
+ },
531
531
  ): IVerifiableCredential {
532
532
  return CredentialMapper.jwtDecodedCredentialToUniformCredential(jwt_decode(jwt), opts)
533
533
  }
534
534
 
535
535
  static jwtDecodedCredentialToUniformCredential(
536
536
  decoded: JwtDecodedVerifiableCredential,
537
- opts?: { maxTimeSkewInMS?: number }
537
+ opts?: { maxTimeSkewInMS?: number },
538
538
  ): IVerifiableCredential {
539
539
  const { exp, nbf, iss, vc, sub, jti, ...rest } = decoded
540
540
  const credential: IVerifiableCredential = {
@@ -686,7 +686,7 @@ export class CredentialMapper {
686
686
  }
687
687
 
688
688
  static toCompactJWT(
689
- jwtDocument: W3CVerifiableCredential | JwtDecodedVerifiableCredential | W3CVerifiablePresentation | JwtDecodedVerifiablePresentation | string
689
+ jwtDocument: W3CVerifiableCredential | JwtDecodedVerifiableCredential | W3CVerifiablePresentation | JwtDecodedVerifiablePresentation | string,
690
690
  ): string {
691
691
  if (!jwtDocument || CredentialMapper.detectDocumentType(jwtDocument) !== DocumentFormat.JWT) {
692
692
  throw Error('Cannot convert non JWT credential to JWT')
@@ -714,7 +714,7 @@ export class CredentialMapper {
714
714
  | W3CVerifiablePresentation
715
715
  | JwtDecodedVerifiableCredential
716
716
  | JwtDecodedVerifiablePresentation
717
- | SdJwtDecodedVerifiableCredential
717
+ | SdJwtDecodedVerifiableCredential,
718
718
  ): DocumentFormat {
719
719
  if (this.isJsonLdAsString(document)) {
720
720
  return DocumentFormat.JSONLD
@@ -736,7 +736,7 @@ export class CredentialMapper {
736
736
  }
737
737
 
738
738
  private static hasJWTProofType(
739
- document: W3CVerifiableCredential | W3CVerifiablePresentation | JwtDecodedVerifiableCredential | JwtDecodedVerifiablePresentation
739
+ document: W3CVerifiableCredential | W3CVerifiablePresentation | JwtDecodedVerifiableCredential | JwtDecodedVerifiablePresentation,
740
740
  ): boolean {
741
741
  if (typeof document === 'string') {
742
742
  return false
@@ -745,7 +745,7 @@ export class CredentialMapper {
745
745
  }
746
746
 
747
747
  private static getFirstProof(
748
- document: W3CVerifiableCredential | W3CVerifiablePresentation | JwtDecodedVerifiableCredential | JwtDecodedVerifiablePresentation
748
+ document: W3CVerifiableCredential | W3CVerifiablePresentation | JwtDecodedVerifiableCredential | JwtDecodedVerifiablePresentation,
749
749
  ): IProof | undefined {
750
750
  if (!document || typeof document === 'string') {
751
751
  return undefined