@sphereon/ssi-types 0.36.1-feature.SSISDK.82.and.SSISDK.70.37 → 0.36.1-next.39
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/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/mapper/credential-mapper.ts +29 -29
- package/src/types/sd-jwt-vc.ts +2 -2
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.36.1-
|
|
4
|
+
"version": "0.36.1-next.39+f060eb6e",
|
|
5
5
|
"source": "./src/index.ts",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "./dist/index.cjs",
|
|
@@ -59,5 +59,5 @@
|
|
|
59
59
|
"Verifiable Credentials",
|
|
60
60
|
"DIDs"
|
|
61
61
|
],
|
|
62
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "f060eb6e9930932f91cfbaa7535465d403a6c63c"
|
|
63
63
|
}
|
|
@@ -48,7 +48,7 @@ import { jwtDecode } from 'jwt-decode'
|
|
|
48
48
|
|
|
49
49
|
type DeviceResponseCbor = mdocPkg.com.sphereon.mdoc.data.device.DeviceResponseCbor
|
|
50
50
|
|
|
51
|
-
export const sha256 = (data: string | ArrayBuffer
|
|
51
|
+
export const sha256 = (data: string | ArrayBuffer): Uint8Array => {
|
|
52
52
|
return defaultHasher(data, 'sha256')
|
|
53
53
|
}
|
|
54
54
|
|
|
@@ -73,7 +73,7 @@ export class CredentialMapper {
|
|
|
73
73
|
*/
|
|
74
74
|
static decodeVerifiablePresentation(
|
|
75
75
|
presentation: OriginalVerifiablePresentation,
|
|
76
|
-
hasher?: HasherSync
|
|
76
|
+
hasher?: HasherSync,
|
|
77
77
|
): JwtDecodedVerifiablePresentation | IVerifiablePresentation | SdJwtDecodedVerifiableCredential | MdocOid4vpMdocVpToken | MdocDeviceResponse {
|
|
78
78
|
if (CredentialMapper.isJwtEncoded(presentation)) {
|
|
79
79
|
const payload = jwtDecode(presentation as string) as JwtDecodedVerifiablePresentation
|
|
@@ -116,7 +116,7 @@ export class CredentialMapper {
|
|
|
116
116
|
*/
|
|
117
117
|
static decodeVerifiableCredential(
|
|
118
118
|
credential: OriginalVerifiableCredential,
|
|
119
|
-
hasher?: HasherSync
|
|
119
|
+
hasher?: HasherSync,
|
|
120
120
|
): JwtDecodedVerifiableCredential | IVerifiableCredential | SdJwtDecodedVerifiableCredential {
|
|
121
121
|
if (CredentialMapper.isJwtEncoded(credential)) {
|
|
122
122
|
const payload = jwtDecode(credential as string) as JwtDecodedVerifiableCredential
|
|
@@ -155,7 +155,7 @@ export class CredentialMapper {
|
|
|
155
155
|
*/
|
|
156
156
|
static toWrappedVerifiablePresentation(
|
|
157
157
|
originalPresentation: OriginalVerifiablePresentation,
|
|
158
|
-
opts?: { maxTimeSkewInMS?: number; hasher?: HasherSync }
|
|
158
|
+
opts?: { maxTimeSkewInMS?: number; hasher?: HasherSync },
|
|
159
159
|
): WrappedVerifiablePresentation {
|
|
160
160
|
// MSO_MDOC
|
|
161
161
|
if (CredentialMapper.isMsoMdocDecodedPresentation(originalPresentation) || CredentialMapper.isMsoMdocOid4VPEncoded(originalPresentation)) {
|
|
@@ -170,7 +170,7 @@ export class CredentialMapper {
|
|
|
170
170
|
}
|
|
171
171
|
|
|
172
172
|
const mdocCredentials = deviceResponse.documents?.map(
|
|
173
|
-
(doc) => CredentialMapper.toWrappedVerifiableCredential(doc, opts) as WrappedMdocCredential
|
|
173
|
+
(doc) => CredentialMapper.toWrappedVerifiableCredential(doc, opts) as WrappedMdocCredential,
|
|
174
174
|
)
|
|
175
175
|
if (!mdocCredentials || mdocCredentials.length === 0) {
|
|
176
176
|
throw new Error('could not extract any mdoc credentials from mdoc device response')
|
|
@@ -210,7 +210,7 @@ export class CredentialMapper {
|
|
|
210
210
|
typeof originalPresentation !== 'string' && CredentialMapper.hasJWTProofType(originalPresentation) ? proof?.jwt : originalPresentation
|
|
211
211
|
if (!original) {
|
|
212
212
|
throw Error(
|
|
213
|
-
'Could not determine original presentation, probably it was a converted JWT presentation, that is now missing the JWT value in the proof'
|
|
213
|
+
'Could not determine original presentation, probably it was a converted JWT presentation, that is now missing the JWT value in the proof',
|
|
214
214
|
)
|
|
215
215
|
}
|
|
216
216
|
const decoded = CredentialMapper.decodeVerifiablePresentation(original) as IVerifiablePresentation | JwtDecodedVerifiablePresentation
|
|
@@ -238,7 +238,7 @@ export class CredentialMapper {
|
|
|
238
238
|
? []
|
|
239
239
|
: (CredentialMapper.toWrappedVerifiableCredentials(
|
|
240
240
|
vp.verifiableCredential ?? [] /*.map(value => value.original)*/,
|
|
241
|
-
opts
|
|
241
|
+
opts,
|
|
242
242
|
) as WrappedW3CVerifiableCredential[])
|
|
243
243
|
|
|
244
244
|
const presentation = {
|
|
@@ -266,7 +266,7 @@ export class CredentialMapper {
|
|
|
266
266
|
*/
|
|
267
267
|
static toWrappedVerifiableCredentials(
|
|
268
268
|
verifiableCredentials: OriginalVerifiableCredential[],
|
|
269
|
-
opts?: { maxTimeSkewInMS?: number; hasher?: HasherSync }
|
|
269
|
+
opts?: { maxTimeSkewInMS?: number; hasher?: HasherSync },
|
|
270
270
|
): WrappedVerifiableCredential[] {
|
|
271
271
|
return verifiableCredentials.map((vc) => CredentialMapper.toWrappedVerifiableCredential(vc, opts))
|
|
272
272
|
}
|
|
@@ -282,7 +282,7 @@ export class CredentialMapper {
|
|
|
282
282
|
*/
|
|
283
283
|
static toWrappedVerifiableCredential(
|
|
284
284
|
verifiableCredential: OriginalVerifiableCredential,
|
|
285
|
-
opts?: { maxTimeSkewInMS?: number; hasher?: HasherSync }
|
|
285
|
+
opts?: { maxTimeSkewInMS?: number; hasher?: HasherSync },
|
|
286
286
|
): WrappedVerifiableCredential {
|
|
287
287
|
// MSO_MDOC
|
|
288
288
|
if (CredentialMapper.isMsoMdocDecodedCredential(verifiableCredential) || CredentialMapper.isMsoMdocOid4VPEncoded(verifiableCredential)) {
|
|
@@ -322,10 +322,10 @@ export class CredentialMapper {
|
|
|
322
322
|
|
|
323
323
|
// If the VC is not an encoded/decoded SD-JWT, we assume it will be a W3C VC
|
|
324
324
|
const proof = CredentialMapper.getFirstProof(verifiableCredential)
|
|
325
|
-
const original = CredentialMapper.hasJWTProofType(verifiableCredential) && proof ? proof.jwt ?? verifiableCredential : verifiableCredential
|
|
325
|
+
const original = CredentialMapper.hasJWTProofType(verifiableCredential) && proof ? (proof.jwt ?? verifiableCredential) : verifiableCredential
|
|
326
326
|
if (!original) {
|
|
327
327
|
throw Error(
|
|
328
|
-
'Could not determine original credential, probably it was a converted JWT credential, that is now missing the JWT value in the proof'
|
|
328
|
+
'Could not determine original credential, probably it was a converted JWT credential, that is now missing the JWT value in the proof',
|
|
329
329
|
)
|
|
330
330
|
}
|
|
331
331
|
const decoded = CredentialMapper.decodeVerifiableCredential(original) as JwtDecodedVerifiableCredential | IVerifiableCredential
|
|
@@ -441,7 +441,7 @@ export class CredentialMapper {
|
|
|
441
441
|
}
|
|
442
442
|
|
|
443
443
|
public static isW3cPresentation(
|
|
444
|
-
presentation: UniformVerifiablePresentation | IPresentation | SdJwtDecodedVerifiableCredential | DeviceResponseCbor
|
|
444
|
+
presentation: UniformVerifiablePresentation | IPresentation | SdJwtDecodedVerifiableCredential | DeviceResponseCbor,
|
|
445
445
|
): presentation is IPresentation {
|
|
446
446
|
return (
|
|
447
447
|
typeof presentation === 'object' &&
|
|
@@ -451,7 +451,7 @@ export class CredentialMapper {
|
|
|
451
451
|
}
|
|
452
452
|
|
|
453
453
|
public static isSdJwtDecodedCredentialPayload(
|
|
454
|
-
credential: ICredential | SdJwtDecodedVerifiableCredentialPayload
|
|
454
|
+
credential: ICredential | SdJwtDecodedVerifiableCredentialPayload,
|
|
455
455
|
): credential is SdJwtDecodedVerifiableCredentialPayload {
|
|
456
456
|
return typeof credential === 'object' && 'vct' in credential
|
|
457
457
|
}
|
|
@@ -483,7 +483,7 @@ export class CredentialMapper {
|
|
|
483
483
|
}
|
|
484
484
|
|
|
485
485
|
public static isSdJwtDecodedCredential(
|
|
486
|
-
original: OriginalVerifiableCredential | OriginalVerifiablePresentation | ICredential | IPresentation
|
|
486
|
+
original: OriginalVerifiableCredential | OriginalVerifiablePresentation | ICredential | IPresentation,
|
|
487
487
|
): original is SdJwtDecodedVerifiableCredential {
|
|
488
488
|
return (
|
|
489
489
|
typeof original === 'object' &&
|
|
@@ -492,7 +492,7 @@ export class CredentialMapper {
|
|
|
492
492
|
}
|
|
493
493
|
|
|
494
494
|
public static isSdJwtVcdm2DecodedCredential(
|
|
495
|
-
original: OriginalVerifiableCredential | OriginalVerifiablePresentation | ICredential | IPresentation
|
|
495
|
+
original: OriginalVerifiableCredential | OriginalVerifiablePresentation | ICredential | IPresentation,
|
|
496
496
|
): original is SdJwtDecodedVerifiableCredential {
|
|
497
497
|
if (typeof original !== 'object') {
|
|
498
498
|
return false
|
|
@@ -502,7 +502,7 @@ export class CredentialMapper {
|
|
|
502
502
|
}
|
|
503
503
|
|
|
504
504
|
public static isMsoMdocDecodedCredential(
|
|
505
|
-
original: OriginalVerifiableCredential | OriginalVerifiablePresentation | ICredential | IPresentation
|
|
505
|
+
original: OriginalVerifiableCredential | OriginalVerifiablePresentation | ICredential | IPresentation,
|
|
506
506
|
): original is MdocDocument {
|
|
507
507
|
return typeof original === 'object' && 'issuerSigned' in original && (<MdocDocument>original).issuerSigned !== undefined
|
|
508
508
|
}
|
|
@@ -537,7 +537,7 @@ export class CredentialMapper {
|
|
|
537
537
|
static jwtEncodedPresentationToUniformPresentation(
|
|
538
538
|
jwt: string,
|
|
539
539
|
makeCredentialsUniform: boolean = true,
|
|
540
|
-
opts?: { maxTimeSkewInMS?: number }
|
|
540
|
+
opts?: { maxTimeSkewInMS?: number },
|
|
541
541
|
): IPresentation {
|
|
542
542
|
return CredentialMapper.jwtDecodedPresentationToUniformPresentation(jwtDecode(jwt), makeCredentialsUniform, opts)
|
|
543
543
|
}
|
|
@@ -545,7 +545,7 @@ export class CredentialMapper {
|
|
|
545
545
|
static jwtDecodedPresentationToUniformPresentation(
|
|
546
546
|
decoded: JwtDecodedVerifiablePresentation,
|
|
547
547
|
makeCredentialsUniform: boolean = true,
|
|
548
|
-
opts?: { maxTimeSkewInMS?: number }
|
|
548
|
+
opts?: { maxTimeSkewInMS?: number },
|
|
549
549
|
): IVerifiablePresentation {
|
|
550
550
|
const { iss, aud, jti, vp, ...rest } = decoded
|
|
551
551
|
|
|
@@ -592,7 +592,7 @@ export class CredentialMapper {
|
|
|
592
592
|
opts?: {
|
|
593
593
|
maxTimeSkewInMS?: number
|
|
594
594
|
hasher?: HasherSync
|
|
595
|
-
}
|
|
595
|
+
},
|
|
596
596
|
): IVerifiableCredential {
|
|
597
597
|
if (CredentialMapper.isMsoMdocDecodedCredential(verifiableCredential)) {
|
|
598
598
|
return mdocDecodedCredentialToUniformCredential(verifiableCredential)
|
|
@@ -606,7 +606,7 @@ export class CredentialMapper {
|
|
|
606
606
|
: verifiableCredential
|
|
607
607
|
if (!original) {
|
|
608
608
|
throw Error(
|
|
609
|
-
'Could not determine original credential from passed in credential. Probably because a JWT proof type was present, but now is not available anymore'
|
|
609
|
+
'Could not determine original credential from passed in credential. Probably because a JWT proof type was present, but now is not available anymore',
|
|
610
610
|
)
|
|
611
611
|
}
|
|
612
612
|
const decoded = CredentialMapper.decodeVerifiableCredential(original, opts?.hasher ?? sha256)
|
|
@@ -629,7 +629,7 @@ export class CredentialMapper {
|
|
|
629
629
|
|
|
630
630
|
static toUniformPresentation(
|
|
631
631
|
presentation: OriginalVerifiablePresentation,
|
|
632
|
-
opts?: { maxTimeSkewInMS?: number; addContextIfMissing?: boolean; hasher?: HasherSync }
|
|
632
|
+
opts?: { maxTimeSkewInMS?: number; addContextIfMissing?: boolean; hasher?: HasherSync },
|
|
633
633
|
): IVerifiablePresentation {
|
|
634
634
|
if (CredentialMapper.isSdJwtDecodedCredential(presentation)) {
|
|
635
635
|
throw new Error('Converting SD-JWT VC to uniform VP is not supported.')
|
|
@@ -641,7 +641,7 @@ export class CredentialMapper {
|
|
|
641
641
|
const original = typeof presentation !== 'string' && CredentialMapper.hasJWTProofType(presentation) ? proof?.jwt : presentation
|
|
642
642
|
if (!original) {
|
|
643
643
|
throw Error(
|
|
644
|
-
'Could not determine original presentation, probably it was a converted JWT presentation, that is now missing the JWT value in the proof'
|
|
644
|
+
'Could not determine original presentation, probably it was a converted JWT presentation, that is now missing the JWT value in the proof',
|
|
645
645
|
)
|
|
646
646
|
}
|
|
647
647
|
const decoded = CredentialMapper.decodeVerifiablePresentation(original, opts?.hasher ?? sha256)
|
|
@@ -658,7 +658,7 @@ export class CredentialMapper {
|
|
|
658
658
|
}
|
|
659
659
|
|
|
660
660
|
uniformPresentation.verifiableCredential = uniformPresentation.verifiableCredential?.map((vc) =>
|
|
661
|
-
CredentialMapper.toUniformCredential(vc, opts)
|
|
661
|
+
CredentialMapper.toUniformCredential(vc, opts),
|
|
662
662
|
) as IVerifiableCredential[] // We cast it because we IPresentation needs a VC. The internal Credential doesn't have the required Proof anymore (that is intended)
|
|
663
663
|
return uniformPresentation
|
|
664
664
|
}
|
|
@@ -667,14 +667,14 @@ export class CredentialMapper {
|
|
|
667
667
|
jwt: string,
|
|
668
668
|
opts?: {
|
|
669
669
|
maxTimeSkewInMS?: number
|
|
670
|
-
}
|
|
670
|
+
},
|
|
671
671
|
): IVerifiableCredential {
|
|
672
672
|
return CredentialMapper.jwtDecodedCredentialToUniformCredential(jwtDecode(jwt), opts)
|
|
673
673
|
}
|
|
674
674
|
|
|
675
675
|
static jwtDecodedCredentialToUniformCredential(
|
|
676
676
|
decoded: JwtDecodedVerifiableCredential,
|
|
677
|
-
opts?: { maxTimeSkewInMS?: number }
|
|
677
|
+
opts?: { maxTimeSkewInMS?: number },
|
|
678
678
|
): IVerifiableCredential {
|
|
679
679
|
const { exp, nbf, iss, vc, sub, jti, ...rest } = decoded
|
|
680
680
|
const credential: IVerifiableCredential = {
|
|
@@ -842,7 +842,7 @@ export class CredentialMapper {
|
|
|
842
842
|
}
|
|
843
843
|
|
|
844
844
|
static toCompactJWT(
|
|
845
|
-
jwtDocument: W3CVerifiableCredential | JwtDecodedVerifiableCredential | W3CVerifiablePresentation | JwtDecodedVerifiablePresentation | string
|
|
845
|
+
jwtDocument: W3CVerifiableCredential | JwtDecodedVerifiableCredential | W3CVerifiablePresentation | JwtDecodedVerifiablePresentation | string,
|
|
846
846
|
): string {
|
|
847
847
|
if (!jwtDocument || CredentialMapper.detectDocumentType(jwtDocument) !== DocumentFormat.JWT) {
|
|
848
848
|
throw Error('Cannot convert non JWT credential to JWT')
|
|
@@ -872,7 +872,7 @@ export class CredentialMapper {
|
|
|
872
872
|
| JwtDecodedVerifiablePresentation
|
|
873
873
|
| SdJwtDecodedVerifiableCredential
|
|
874
874
|
| MdocDeviceResponse
|
|
875
|
-
| MdocDocument
|
|
875
|
+
| MdocDocument,
|
|
876
876
|
): DocumentFormat {
|
|
877
877
|
if (this.isMsoMdocOid4VPEncoded(document as any) || this.isMsoMdocDecodedCredential(document as any)) {
|
|
878
878
|
return DocumentFormat.MSO_MDOC
|
|
@@ -900,7 +900,7 @@ export class CredentialMapper {
|
|
|
900
900
|
}
|
|
901
901
|
|
|
902
902
|
private static hasJWTProofType(
|
|
903
|
-
document: W3CVerifiableCredential | W3CVerifiablePresentation | JwtDecodedVerifiableCredential | JwtDecodedVerifiablePresentation
|
|
903
|
+
document: W3CVerifiableCredential | W3CVerifiablePresentation | JwtDecodedVerifiableCredential | JwtDecodedVerifiablePresentation,
|
|
904
904
|
): boolean {
|
|
905
905
|
if (typeof document === 'string') {
|
|
906
906
|
return false
|
|
@@ -909,7 +909,7 @@ export class CredentialMapper {
|
|
|
909
909
|
}
|
|
910
910
|
|
|
911
911
|
private static getFirstProof(
|
|
912
|
-
document: W3CVerifiableCredential | W3CVerifiablePresentation | JwtDecodedVerifiableCredential | JwtDecodedVerifiablePresentation
|
|
912
|
+
document: W3CVerifiableCredential | W3CVerifiablePresentation | JwtDecodedVerifiableCredential | JwtDecodedVerifiablePresentation,
|
|
913
913
|
): IProof | undefined {
|
|
914
914
|
if (!document || typeof document === 'string') {
|
|
915
915
|
return undefined
|
package/src/types/sd-jwt-vc.ts
CHANGED
|
@@ -169,8 +169,8 @@ export interface WrappedSdJwtVerifiableCredential {
|
|
|
169
169
|
credential: SdJwtDecodedVerifiableCredential
|
|
170
170
|
}
|
|
171
171
|
|
|
172
|
-
export type HasherSync = (data: string | ArrayBuffer
|
|
173
|
-
export type Hasher = (data: string | ArrayBuffer
|
|
172
|
+
export type HasherSync = (data: string | ArrayBuffer, alg: string) => Uint8Array
|
|
173
|
+
export type Hasher = (data: string | ArrayBuffer, alg: string) => OrPromise<Uint8Array>
|
|
174
174
|
|
|
175
175
|
export interface WrappedSdJwtVerifiablePresentation {
|
|
176
176
|
/**
|