@sphereon/ssi-types 0.34.1-next.91 → 0.36.0
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 +13 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +45 -35
- package/dist/index.d.ts +45 -35
- package/dist/index.js +13 -1
- package/dist/index.js.map +1 -1
- package/package.json +3 -2
- package/src/index.ts +1 -2
- package/src/mapper/credential-mapper.ts +33 -31
- package/src/types/datastore.ts +6 -0
- package/src/types/index.ts +1 -1
- package/src/types/sd-jwt-vc.ts +1 -3
- package/src/types/vc.ts +40 -0
- package/src/types/vcdm2-sdjwt/index.ts +2 -2
- package/src/types/vcdm2-sdjwt/sd-jwt-vc-config.ts +7 -7
- package/src/types/w3c-vc.ts +2 -3
- package/src/utils/mdoc.ts +4 -4
- package/src/utils/sd-jwt.ts +17 -12
- package/src/utils/vc.ts +1 -1
- package/src/types/dcql.ts +0 -39
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.
|
|
4
|
+
"version": "0.36.0",
|
|
5
5
|
"source": "./src/index.ts",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "./dist/index.cjs",
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
"@sd-jwt/decode": "^0.15.0",
|
|
27
27
|
"@sd-jwt/types": "^0.15.0",
|
|
28
28
|
"@sphereon/kmp-mdoc-core": "0.2.0-SNAPSHOT.26",
|
|
29
|
+
"dcql": "1.0.1",
|
|
29
30
|
"debug": "^4.3.5",
|
|
30
31
|
"events": "^3.3.0",
|
|
31
32
|
"jwt-decode": "^4.0.0",
|
|
@@ -58,5 +59,5 @@
|
|
|
58
59
|
"Verifiable Credentials",
|
|
59
60
|
"DIDs"
|
|
60
61
|
],
|
|
61
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "f713d3a83948ef69aaa7d435700b16d5655ac863"
|
|
62
63
|
}
|
package/src/index.ts
CHANGED
|
@@ -3,9 +3,8 @@ import { Loggers } from './logging'
|
|
|
3
3
|
const logger = Loggers.DEFAULT.get('sphereon:ssi')
|
|
4
4
|
logger.debug(`Sphereon logger initialized`)
|
|
5
5
|
|
|
6
|
-
export
|
|
6
|
+
export * from './types'
|
|
7
7
|
export * from './logging'
|
|
8
8
|
export * from './events'
|
|
9
9
|
export * from './utils'
|
|
10
10
|
export * from './mapper'
|
|
11
|
-
|
|
@@ -57,7 +57,7 @@ export class CredentialMapper {
|
|
|
57
57
|
* Decodes a compact SD-JWT vc to it's decoded variant. This method can be used when the hasher implementation used is Async, and therefore not suitable for usage
|
|
58
58
|
* with the other decode methods.
|
|
59
59
|
*/
|
|
60
|
-
static decodeSdJwtVcAsync(compactSdJwtVc: string, hasher: Hasher) {
|
|
60
|
+
static decodeSdJwtVcAsync(compactSdJwtVc: string, hasher: Hasher): Promise<SdJwtDecodedVerifiableCredential> {
|
|
61
61
|
return decodeSdJwtVcAsyncFunc(compactSdJwtVc, hasher ?? sha256)
|
|
62
62
|
}
|
|
63
63
|
|
|
@@ -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
|
|
@@ -111,11 +111,12 @@ export class CredentialMapper {
|
|
|
111
111
|
* an async hasher implementation, use the decodeSdJwtVcAsync method instead and you can provide the decoded payload to methods
|
|
112
112
|
* instead of the compact SD-JWT.
|
|
113
113
|
*
|
|
114
|
+
* @param credential
|
|
114
115
|
* @param hasher Hasher implementation to use for SD-JWT decoding
|
|
115
116
|
*/
|
|
116
117
|
static decodeVerifiableCredential(
|
|
117
118
|
credential: OriginalVerifiableCredential,
|
|
118
|
-
hasher?: HasherSync
|
|
119
|
+
hasher?: HasherSync,
|
|
119
120
|
): JwtDecodedVerifiableCredential | IVerifiableCredential | SdJwtDecodedVerifiableCredential {
|
|
120
121
|
if (CredentialMapper.isJwtEncoded(credential)) {
|
|
121
122
|
const payload = jwtDecode(credential as string) as JwtDecodedVerifiableCredential
|
|
@@ -149,11 +150,12 @@ export class CredentialMapper {
|
|
|
149
150
|
* an async hasher implementation, use the decodeSdJwtVcAsync method instead and you can provide the decoded payload to methods
|
|
150
151
|
* instead of the compact SD-JWT.
|
|
151
152
|
*
|
|
152
|
-
* @param
|
|
153
|
+
* @param originalPresentation
|
|
154
|
+
* @param opts
|
|
153
155
|
*/
|
|
154
156
|
static toWrappedVerifiablePresentation(
|
|
155
157
|
originalPresentation: OriginalVerifiablePresentation,
|
|
156
|
-
opts?: { maxTimeSkewInMS?: number; hasher?: HasherSync }
|
|
158
|
+
opts?: { maxTimeSkewInMS?: number; hasher?: HasherSync },
|
|
157
159
|
): WrappedVerifiablePresentation {
|
|
158
160
|
// MSO_MDOC
|
|
159
161
|
if (CredentialMapper.isMsoMdocDecodedPresentation(originalPresentation) || CredentialMapper.isMsoMdocOid4VPEncoded(originalPresentation)) {
|
|
@@ -168,7 +170,7 @@ export class CredentialMapper {
|
|
|
168
170
|
}
|
|
169
171
|
|
|
170
172
|
const mdocCredentials = deviceResponse.documents?.map(
|
|
171
|
-
(doc) => CredentialMapper.toWrappedVerifiableCredential(doc, opts) as WrappedMdocCredential
|
|
173
|
+
(doc) => CredentialMapper.toWrappedVerifiableCredential(doc, opts) as WrappedMdocCredential,
|
|
172
174
|
)
|
|
173
175
|
if (!mdocCredentials || mdocCredentials.length === 0) {
|
|
174
176
|
throw new Error('could not extract any mdoc credentials from mdoc device response')
|
|
@@ -208,7 +210,7 @@ export class CredentialMapper {
|
|
|
208
210
|
typeof originalPresentation !== 'string' && CredentialMapper.hasJWTProofType(originalPresentation) ? proof?.jwt : originalPresentation
|
|
209
211
|
if (!original) {
|
|
210
212
|
throw Error(
|
|
211
|
-
'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',
|
|
212
214
|
)
|
|
213
215
|
}
|
|
214
216
|
const decoded = CredentialMapper.decodeVerifiablePresentation(original) as IVerifiablePresentation | JwtDecodedVerifiablePresentation
|
|
@@ -236,7 +238,7 @@ export class CredentialMapper {
|
|
|
236
238
|
? []
|
|
237
239
|
: (CredentialMapper.toWrappedVerifiableCredentials(
|
|
238
240
|
vp.verifiableCredential ?? [] /*.map(value => value.original)*/,
|
|
239
|
-
opts
|
|
241
|
+
opts,
|
|
240
242
|
) as WrappedW3CVerifiableCredential[])
|
|
241
243
|
|
|
242
244
|
const presentation = {
|
|
@@ -264,7 +266,7 @@ export class CredentialMapper {
|
|
|
264
266
|
*/
|
|
265
267
|
static toWrappedVerifiableCredentials(
|
|
266
268
|
verifiableCredentials: OriginalVerifiableCredential[],
|
|
267
|
-
opts?: { maxTimeSkewInMS?: number; hasher?: HasherSync }
|
|
269
|
+
opts?: { maxTimeSkewInMS?: number; hasher?: HasherSync },
|
|
268
270
|
): WrappedVerifiableCredential[] {
|
|
269
271
|
return verifiableCredentials.map((vc) => CredentialMapper.toWrappedVerifiableCredential(vc, opts))
|
|
270
272
|
}
|
|
@@ -280,7 +282,7 @@ export class CredentialMapper {
|
|
|
280
282
|
*/
|
|
281
283
|
static toWrappedVerifiableCredential(
|
|
282
284
|
verifiableCredential: OriginalVerifiableCredential,
|
|
283
|
-
opts?: { maxTimeSkewInMS?: number; hasher?: HasherSync }
|
|
285
|
+
opts?: { maxTimeSkewInMS?: number; hasher?: HasherSync },
|
|
284
286
|
): WrappedVerifiableCredential {
|
|
285
287
|
// MSO_MDOC
|
|
286
288
|
if (CredentialMapper.isMsoMdocDecodedCredential(verifiableCredential) || CredentialMapper.isMsoMdocOid4VPEncoded(verifiableCredential)) {
|
|
@@ -320,10 +322,10 @@ export class CredentialMapper {
|
|
|
320
322
|
|
|
321
323
|
// If the VC is not an encoded/decoded SD-JWT, we assume it will be a W3C VC
|
|
322
324
|
const proof = CredentialMapper.getFirstProof(verifiableCredential)
|
|
323
|
-
const original = CredentialMapper.hasJWTProofType(verifiableCredential) && proof ? proof.jwt ?? verifiableCredential : verifiableCredential
|
|
325
|
+
const original = CredentialMapper.hasJWTProofType(verifiableCredential) && proof ? (proof.jwt ?? verifiableCredential) : verifiableCredential
|
|
324
326
|
if (!original) {
|
|
325
327
|
throw Error(
|
|
326
|
-
'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',
|
|
327
329
|
)
|
|
328
330
|
}
|
|
329
331
|
const decoded = CredentialMapper.decodeVerifiableCredential(original) as JwtDecodedVerifiableCredential | IVerifiableCredential
|
|
@@ -439,7 +441,7 @@ export class CredentialMapper {
|
|
|
439
441
|
}
|
|
440
442
|
|
|
441
443
|
public static isW3cPresentation(
|
|
442
|
-
presentation: UniformVerifiablePresentation | IPresentation | SdJwtDecodedVerifiableCredential | DeviceResponseCbor
|
|
444
|
+
presentation: UniformVerifiablePresentation | IPresentation | SdJwtDecodedVerifiableCredential | DeviceResponseCbor,
|
|
443
445
|
): presentation is IPresentation {
|
|
444
446
|
return (
|
|
445
447
|
typeof presentation === 'object' &&
|
|
@@ -449,7 +451,7 @@ export class CredentialMapper {
|
|
|
449
451
|
}
|
|
450
452
|
|
|
451
453
|
public static isSdJwtDecodedCredentialPayload(
|
|
452
|
-
credential: ICredential | SdJwtDecodedVerifiableCredentialPayload
|
|
454
|
+
credential: ICredential | SdJwtDecodedVerifiableCredentialPayload,
|
|
453
455
|
): credential is SdJwtDecodedVerifiableCredentialPayload {
|
|
454
456
|
return typeof credential === 'object' && 'vct' in credential
|
|
455
457
|
}
|
|
@@ -481,7 +483,7 @@ export class CredentialMapper {
|
|
|
481
483
|
}
|
|
482
484
|
|
|
483
485
|
public static isSdJwtDecodedCredential(
|
|
484
|
-
original: OriginalVerifiableCredential | OriginalVerifiablePresentation | ICredential | IPresentation
|
|
486
|
+
original: OriginalVerifiableCredential | OriginalVerifiablePresentation | ICredential | IPresentation,
|
|
485
487
|
): original is SdJwtDecodedVerifiableCredential {
|
|
486
488
|
return (
|
|
487
489
|
typeof original === 'object' &&
|
|
@@ -490,7 +492,7 @@ export class CredentialMapper {
|
|
|
490
492
|
}
|
|
491
493
|
|
|
492
494
|
public static isSdJwtVcdm2DecodedCredential(
|
|
493
|
-
original: OriginalVerifiableCredential | OriginalVerifiablePresentation | ICredential | IPresentation
|
|
495
|
+
original: OriginalVerifiableCredential | OriginalVerifiablePresentation | ICredential | IPresentation,
|
|
494
496
|
): original is SdJwtDecodedVerifiableCredential {
|
|
495
497
|
if (typeof original !== 'object') {
|
|
496
498
|
return false
|
|
@@ -500,7 +502,7 @@ export class CredentialMapper {
|
|
|
500
502
|
}
|
|
501
503
|
|
|
502
504
|
public static isMsoMdocDecodedCredential(
|
|
503
|
-
original: OriginalVerifiableCredential | OriginalVerifiablePresentation | ICredential | IPresentation
|
|
505
|
+
original: OriginalVerifiableCredential | OriginalVerifiablePresentation | ICredential | IPresentation,
|
|
504
506
|
): original is MdocDocument {
|
|
505
507
|
return typeof original === 'object' && 'issuerSigned' in original && (<MdocDocument>original).issuerSigned !== undefined
|
|
506
508
|
}
|
|
@@ -535,7 +537,7 @@ export class CredentialMapper {
|
|
|
535
537
|
static jwtEncodedPresentationToUniformPresentation(
|
|
536
538
|
jwt: string,
|
|
537
539
|
makeCredentialsUniform: boolean = true,
|
|
538
|
-
opts?: { maxTimeSkewInMS?: number }
|
|
540
|
+
opts?: { maxTimeSkewInMS?: number },
|
|
539
541
|
): IPresentation {
|
|
540
542
|
return CredentialMapper.jwtDecodedPresentationToUniformPresentation(jwtDecode(jwt), makeCredentialsUniform, opts)
|
|
541
543
|
}
|
|
@@ -543,7 +545,7 @@ export class CredentialMapper {
|
|
|
543
545
|
static jwtDecodedPresentationToUniformPresentation(
|
|
544
546
|
decoded: JwtDecodedVerifiablePresentation,
|
|
545
547
|
makeCredentialsUniform: boolean = true,
|
|
546
|
-
opts?: { maxTimeSkewInMS?: number }
|
|
548
|
+
opts?: { maxTimeSkewInMS?: number },
|
|
547
549
|
): IVerifiablePresentation {
|
|
548
550
|
const { iss, aud, jti, vp, ...rest } = decoded
|
|
549
551
|
|
|
@@ -590,7 +592,7 @@ export class CredentialMapper {
|
|
|
590
592
|
opts?: {
|
|
591
593
|
maxTimeSkewInMS?: number
|
|
592
594
|
hasher?: HasherSync
|
|
593
|
-
}
|
|
595
|
+
},
|
|
594
596
|
): IVerifiableCredential {
|
|
595
597
|
if (CredentialMapper.isMsoMdocDecodedCredential(verifiableCredential)) {
|
|
596
598
|
return mdocDecodedCredentialToUniformCredential(verifiableCredential)
|
|
@@ -604,7 +606,7 @@ export class CredentialMapper {
|
|
|
604
606
|
: verifiableCredential
|
|
605
607
|
if (!original) {
|
|
606
608
|
throw Error(
|
|
607
|
-
'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',
|
|
608
610
|
)
|
|
609
611
|
}
|
|
610
612
|
const decoded = CredentialMapper.decodeVerifiableCredential(original, opts?.hasher ?? sha256)
|
|
@@ -627,7 +629,7 @@ export class CredentialMapper {
|
|
|
627
629
|
|
|
628
630
|
static toUniformPresentation(
|
|
629
631
|
presentation: OriginalVerifiablePresentation,
|
|
630
|
-
opts?: { maxTimeSkewInMS?: number; addContextIfMissing?: boolean; hasher?: HasherSync }
|
|
632
|
+
opts?: { maxTimeSkewInMS?: number; addContextIfMissing?: boolean; hasher?: HasherSync },
|
|
631
633
|
): IVerifiablePresentation {
|
|
632
634
|
if (CredentialMapper.isSdJwtDecodedCredential(presentation)) {
|
|
633
635
|
throw new Error('Converting SD-JWT VC to uniform VP is not supported.')
|
|
@@ -639,7 +641,7 @@ export class CredentialMapper {
|
|
|
639
641
|
const original = typeof presentation !== 'string' && CredentialMapper.hasJWTProofType(presentation) ? proof?.jwt : presentation
|
|
640
642
|
if (!original) {
|
|
641
643
|
throw Error(
|
|
642
|
-
'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',
|
|
643
645
|
)
|
|
644
646
|
}
|
|
645
647
|
const decoded = CredentialMapper.decodeVerifiablePresentation(original, opts?.hasher ?? sha256)
|
|
@@ -656,7 +658,7 @@ export class CredentialMapper {
|
|
|
656
658
|
}
|
|
657
659
|
|
|
658
660
|
uniformPresentation.verifiableCredential = uniformPresentation.verifiableCredential?.map((vc) =>
|
|
659
|
-
CredentialMapper.toUniformCredential(vc, opts)
|
|
661
|
+
CredentialMapper.toUniformCredential(vc, opts),
|
|
660
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)
|
|
661
663
|
return uniformPresentation
|
|
662
664
|
}
|
|
@@ -665,14 +667,14 @@ export class CredentialMapper {
|
|
|
665
667
|
jwt: string,
|
|
666
668
|
opts?: {
|
|
667
669
|
maxTimeSkewInMS?: number
|
|
668
|
-
}
|
|
670
|
+
},
|
|
669
671
|
): IVerifiableCredential {
|
|
670
672
|
return CredentialMapper.jwtDecodedCredentialToUniformCredential(jwtDecode(jwt), opts)
|
|
671
673
|
}
|
|
672
674
|
|
|
673
675
|
static jwtDecodedCredentialToUniformCredential(
|
|
674
676
|
decoded: JwtDecodedVerifiableCredential,
|
|
675
|
-
opts?: { maxTimeSkewInMS?: number }
|
|
677
|
+
opts?: { maxTimeSkewInMS?: number },
|
|
676
678
|
): IVerifiableCredential {
|
|
677
679
|
const { exp, nbf, iss, vc, sub, jti, ...rest } = decoded
|
|
678
680
|
const credential: IVerifiableCredential = {
|
|
@@ -840,7 +842,7 @@ export class CredentialMapper {
|
|
|
840
842
|
}
|
|
841
843
|
|
|
842
844
|
static toCompactJWT(
|
|
843
|
-
jwtDocument: W3CVerifiableCredential | JwtDecodedVerifiableCredential | W3CVerifiablePresentation | JwtDecodedVerifiablePresentation | string
|
|
845
|
+
jwtDocument: W3CVerifiableCredential | JwtDecodedVerifiableCredential | W3CVerifiablePresentation | JwtDecodedVerifiablePresentation | string,
|
|
844
846
|
): string {
|
|
845
847
|
if (!jwtDocument || CredentialMapper.detectDocumentType(jwtDocument) !== DocumentFormat.JWT) {
|
|
846
848
|
throw Error('Cannot convert non JWT credential to JWT')
|
|
@@ -870,7 +872,7 @@ export class CredentialMapper {
|
|
|
870
872
|
| JwtDecodedVerifiablePresentation
|
|
871
873
|
| SdJwtDecodedVerifiableCredential
|
|
872
874
|
| MdocDeviceResponse
|
|
873
|
-
| MdocDocument
|
|
875
|
+
| MdocDocument,
|
|
874
876
|
): DocumentFormat {
|
|
875
877
|
if (this.isMsoMdocOid4VPEncoded(document as any) || this.isMsoMdocDecodedCredential(document as any)) {
|
|
876
878
|
return DocumentFormat.MSO_MDOC
|
|
@@ -898,7 +900,7 @@ export class CredentialMapper {
|
|
|
898
900
|
}
|
|
899
901
|
|
|
900
902
|
private static hasJWTProofType(
|
|
901
|
-
document: W3CVerifiableCredential | W3CVerifiablePresentation | JwtDecodedVerifiableCredential | JwtDecodedVerifiablePresentation
|
|
903
|
+
document: W3CVerifiableCredential | W3CVerifiablePresentation | JwtDecodedVerifiableCredential | JwtDecodedVerifiablePresentation,
|
|
902
904
|
): boolean {
|
|
903
905
|
if (typeof document === 'string') {
|
|
904
906
|
return false
|
|
@@ -907,7 +909,7 @@ export class CredentialMapper {
|
|
|
907
909
|
}
|
|
908
910
|
|
|
909
911
|
private static getFirstProof(
|
|
910
|
-
document: W3CVerifiableCredential | W3CVerifiablePresentation | JwtDecodedVerifiableCredential | JwtDecodedVerifiablePresentation
|
|
912
|
+
document: W3CVerifiableCredential | W3CVerifiablePresentation | JwtDecodedVerifiableCredential | JwtDecodedVerifiablePresentation,
|
|
911
913
|
): IProof | undefined {
|
|
912
914
|
if (!document || typeof document === 'string') {
|
|
913
915
|
return undefined
|
|
@@ -957,7 +959,7 @@ export enum OriginalType {
|
|
|
957
959
|
|
|
958
960
|
export const JWT_PROOF_TYPE_2020 = 'JwtProof2020'
|
|
959
961
|
|
|
960
|
-
export
|
|
962
|
+
export enum DocumentFormat {
|
|
961
963
|
// W3C
|
|
962
964
|
JWT,
|
|
963
965
|
JSONLD,
|
package/src/types/index.ts
CHANGED
package/src/types/sd-jwt-vc.ts
CHANGED
|
@@ -200,8 +200,6 @@ export interface WrappedSdJwtVerifiablePresentation {
|
|
|
200
200
|
vcs: [WrappedSdJwtVerifiableCredential]
|
|
201
201
|
}
|
|
202
202
|
|
|
203
|
-
|
|
204
|
-
|
|
205
203
|
export type SdJwtVcType = 'dc+sd-jwt' | 'vc+sd-jwt'
|
|
206
204
|
export type SdJwtVpType = 'dc+sd-jwt' | 'vp+sd-jwt'
|
|
207
|
-
export type SdJwtType = SdJwtVcType | SdJwtVpType
|
|
205
|
+
export type SdJwtType = SdJwtVcType | SdJwtVpType
|
package/src/types/vc.ts
CHANGED
|
@@ -64,3 +64,43 @@ export type OriginalVerifiablePresentation =
|
|
|
64
64
|
| MdocOid4vpMdocVpToken
|
|
65
65
|
| MdocDeviceResponse
|
|
66
66
|
export type Original = OriginalVerifiablePresentation | OriginalVerifiableCredential
|
|
67
|
+
|
|
68
|
+
export type JwtObject = {
|
|
69
|
+
alg_values: Array<string>
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export type LdpObject = {
|
|
73
|
+
proof_type_values: Array<string>
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export type DiObject = {
|
|
77
|
+
proof_type_values: Array<string>
|
|
78
|
+
cryptosuite: Array<string>
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export type SdJwtObject = {
|
|
82
|
+
['sd-jwt_alg_values']?: Array<string>
|
|
83
|
+
['kb-jwt_alg_values']?: Array<string>
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export type MsoMdocObject = {
|
|
87
|
+
['issuerauth_alg_values']?: Array<number>
|
|
88
|
+
['deviceauth_alg_values']?: Array<number>
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export type Format = {
|
|
92
|
+
jwt?: JwtObject
|
|
93
|
+
jwt_vc?: JwtObject
|
|
94
|
+
jwt_vc_json?: JwtObject
|
|
95
|
+
jwt_vp?: JwtObject
|
|
96
|
+
jwt_vp_json?: JwtObject
|
|
97
|
+
ldp?: LdpObject
|
|
98
|
+
ldp_vc?: LdpObject
|
|
99
|
+
ldp_vp?: LdpObject
|
|
100
|
+
di?: DiObject
|
|
101
|
+
di_vc?: DiObject
|
|
102
|
+
di_vp?: DiObject
|
|
103
|
+
['vc+sd-jwt']?: SdJwtObject
|
|
104
|
+
['dc+sd-jwt']?: SdJwtObject
|
|
105
|
+
mso_mdoc?: MsoMdocObject
|
|
106
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export type * from './sd-jwt-vc-config'
|
|
2
|
-
export type * from './sd-jwt-vc-payload'
|
|
1
|
+
export type * from './sd-jwt-vc-config'
|
|
2
|
+
export type * from './sd-jwt-vc-payload'
|
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import type { SDJWTConfig, Verifier } from '@sd-jwt/types'
|
|
2
2
|
|
|
3
3
|
export type StatusListFetcher = (uri: string) => Promise<string>
|
|
4
|
-
export type StatusValidator = (status: number) => Promise<void
|
|
4
|
+
export type StatusValidator = (status: number) => Promise<void>
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Configuration for SD-JWT-VC
|
|
8
8
|
*/
|
|
9
9
|
export type SDJWTVCDM2Config = SDJWTConfig & {
|
|
10
10
|
// A function that fetches the status list from the uri. If not provided, the library will assume that the response is a compact JWT.
|
|
11
|
-
statusListFetcher?: StatusListFetcher
|
|
11
|
+
statusListFetcher?: StatusListFetcher
|
|
12
12
|
// validte the status and decide if the status is valid or not. If not provided, the code will continue if it is 0, otherwise it will throw an error.
|
|
13
|
-
statusValidator?: StatusValidator
|
|
13
|
+
statusValidator?: StatusValidator
|
|
14
14
|
// a function that fetches the type metadata format from the uri. If not provided, the library will assume that the response is a TypeMetadataFormat. Caching has to be implemented in this function. If the integrity value is passed, it to be validated according to https://www.w3.org/TR/SRI/
|
|
15
15
|
// vctFetcher?: VcTFetcher;
|
|
16
16
|
// a function that verifies the status of the JWT. If not provided, the library will assume that the status is valid if it is 0.
|
|
17
|
-
statusVerifier?: Verifier
|
|
17
|
+
statusVerifier?: Verifier
|
|
18
18
|
// if set to true, it will load the metadata format based on the vct value. If not provided, it will default to false.
|
|
19
|
-
loadTypeMetadataFormat?: boolean
|
|
19
|
+
loadTypeMetadataFormat?: boolean
|
|
20
20
|
// timeout value in milliseconds when to abort the fetch request. If not provided, it will default to 10000.
|
|
21
|
-
timeout?: number
|
|
22
|
-
}
|
|
21
|
+
timeout?: number
|
|
22
|
+
}
|
package/src/types/w3c-vc.ts
CHANGED
|
@@ -16,7 +16,7 @@ export interface IVcdmBaseCredential {
|
|
|
16
16
|
// If iss is present, the value MUST be used to set the issuer property of the new credential JSON object or the holderDID property of the new presentation JSON object.
|
|
17
17
|
issuer: IIssuerId | IIssuer
|
|
18
18
|
// If sub is present, the value MUST be used to set the value of the id property of credentialSubject of the new credential JSON object.
|
|
19
|
-
credentialSubject: SingleOrArray<
|
|
19
|
+
credentialSubject: SingleOrArray<ICredentialSubject & AdditionalClaims>
|
|
20
20
|
// If jti is present, the value MUST be used to set the value of the id property of the new JSON object.
|
|
21
21
|
id?: string
|
|
22
22
|
credentialStatus?: SingleOrArray<ICredentialStatus>
|
|
@@ -35,8 +35,7 @@ export interface IVcdm2Credential extends IVcdmBaseCredential {
|
|
|
35
35
|
[x: string]: any
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
export interface ICredential
|
|
39
|
-
|
|
38
|
+
export interface ICredential extends IVcdmBaseCredential {
|
|
40
39
|
// If nbf is present, the UNIX timestamp MUST be converted to an [XMLSCHEMA11-2] date-time, and MUST be used to set the value of the issuanceDate property of the new JSON object.
|
|
41
40
|
issuanceDate: string
|
|
42
41
|
// If exp is present, the UNIX timestamp MUST be converted to an [XMLSCHEMA11-2] date-time, and MUST be used to set the value of the expirationDate property of credentialSubject of the new JSON object.
|
package/src/utils/mdoc.ts
CHANGED
|
@@ -41,7 +41,7 @@ export function getMdocDecodedPayload(mdoc: MdocDocument): MdocDecodedPayload {
|
|
|
41
41
|
...acc,
|
|
42
42
|
[item.key]: item.value.value,
|
|
43
43
|
}),
|
|
44
|
-
{}
|
|
44
|
+
{},
|
|
45
45
|
)
|
|
46
46
|
}
|
|
47
47
|
|
|
@@ -56,7 +56,7 @@ export function getMdocDecodedPayload(mdoc: MdocDocument): MdocDecodedPayload {
|
|
|
56
56
|
export function decodeMdocIssuerSigned(oid4vpIssuerSigned: MdocOid4vpIssuerSigned): MdocDocument {
|
|
57
57
|
// Issuer signed according to 18013-7 in base64url
|
|
58
58
|
const issuerSigned: MdocIssuerSigned = com.sphereon.mdoc.data.device.IssuerSignedCbor.Static.cborDecode(
|
|
59
|
-
com.sphereon.kmp.decodeFrom(oid4vpIssuerSigned, com.sphereon.kmp.Encoding.BASE64URL)
|
|
59
|
+
com.sphereon.kmp.decodeFrom(oid4vpIssuerSigned, com.sphereon.kmp.Encoding.BASE64URL),
|
|
60
60
|
)
|
|
61
61
|
// Create an mdoc from it. // Validations need to be performed by the caller after this!
|
|
62
62
|
const holderMdoc: MdocDocument = issuerSigned.toDocument()
|
|
@@ -74,7 +74,7 @@ export function encodeMdocIssuerSigned(issuerSigned: MdocIssuerSigned, encoding:
|
|
|
74
74
|
*/
|
|
75
75
|
export function decodeMdocDeviceResponse(vpToken: MdocOid4vpMdocVpToken): MdocDeviceResponse {
|
|
76
76
|
const deviceResponse = com.sphereon.mdoc.data.device.DeviceResponseCbor.Static.cborDecode(
|
|
77
|
-
com.sphereon.kmp.decodeFrom(vpToken, com.sphereon.kmp.Encoding.BASE64URL)
|
|
77
|
+
com.sphereon.kmp.decodeFrom(vpToken, com.sphereon.kmp.Encoding.BASE64URL),
|
|
78
78
|
)
|
|
79
79
|
return deviceResponse
|
|
80
80
|
}
|
|
@@ -83,7 +83,7 @@ export function decodeMdocDeviceResponse(vpToken: MdocOid4vpMdocVpToken): MdocDe
|
|
|
83
83
|
export const mdocDecodedCredentialToUniformCredential = (
|
|
84
84
|
decoded: MdocDocument,
|
|
85
85
|
// @ts-ignore
|
|
86
|
-
opts?: { maxTimeSkewInMS?: number }
|
|
86
|
+
opts?: { maxTimeSkewInMS?: number },
|
|
87
87
|
): IVerifiableCredential => {
|
|
88
88
|
const document = decoded.toJson()
|
|
89
89
|
const json = document.toJsonDTO<DocumentJson>()
|
package/src/utils/sd-jwt.ts
CHANGED
|
@@ -104,7 +104,9 @@ export const sdJwtDecodedCredentialToUniformCredential = (
|
|
|
104
104
|
): IVerifiableCredential => {
|
|
105
105
|
const { decodedPayload } = decoded
|
|
106
106
|
const { exp, nbf, iss, iat, vct, cnf, status, jti, validUntil, validFrom } = decodedPayload
|
|
107
|
-
let credentialSubject:
|
|
107
|
+
let credentialSubject: SingleOrArray<ICredentialSubject & AdditionalClaims> | undefined = decodedPayload.credentialSubject as
|
|
108
|
+
| SingleOrArray<ICredentialSubject & AdditionalClaims>
|
|
109
|
+
| undefined
|
|
108
110
|
|
|
109
111
|
let issuer = iss ?? decodedPayload.issuer
|
|
110
112
|
if (typeof issuer === 'object' && 'id' in issuer && typeof issuer.id === 'string') {
|
|
@@ -136,17 +138,20 @@ export const sdJwtDecodedCredentialToUniformCredential = (
|
|
|
136
138
|
// Filter out the fields we don't want in credentialSubject
|
|
137
139
|
const excludedFields = new Set(['vct', 'cnf', 'iss', 'iat', 'exp', 'nbf', 'jti', 'sub'])
|
|
138
140
|
if (!credentialSubject) {
|
|
139
|
-
credentialSubject = Object.entries(decodedPayload).reduce(
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
141
|
+
credentialSubject = Object.entries(decodedPayload).reduce(
|
|
142
|
+
(acc, [key, value]) => {
|
|
143
|
+
if (
|
|
144
|
+
!excludedFields.has(key) &&
|
|
145
|
+
value !== undefined &&
|
|
146
|
+
value !== '' &&
|
|
147
|
+
!(typeof value === 'object' && value !== null && Object.keys(value).length === 0)
|
|
148
|
+
) {
|
|
149
|
+
acc[key] = value
|
|
150
|
+
}
|
|
151
|
+
return acc
|
|
152
|
+
},
|
|
153
|
+
{} as Record<string, any>,
|
|
154
|
+
)
|
|
150
155
|
}
|
|
151
156
|
const sdJwtVc = decodedPayload.vct && !decodedPayload.type
|
|
152
157
|
const credential: Omit<IVerifiableCredential, 'issuer' | 'issuanceDate'> = {
|
package/src/utils/vc.ts
CHANGED
|
@@ -24,7 +24,7 @@ export enum StatusListType {
|
|
|
24
24
|
|
|
25
25
|
function isVcdmCredential(
|
|
26
26
|
credential: CredentialPayload | IVerifiableCredential | ICredential | VerifiableCredential | unknown,
|
|
27
|
-
vcdmType: string
|
|
27
|
+
vcdmType: string,
|
|
28
28
|
): boolean {
|
|
29
29
|
if (!credential || typeof credential !== 'object') {
|
|
30
30
|
return false
|
package/src/types/dcql.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
// FIXME Temporary minimal DCQL schema for PD manager, the DcqlQuery used by Animo does not serialize properly (over REST / Veramo)
|
|
2
|
-
|
|
3
|
-
export interface DcqlQueryREST {
|
|
4
|
-
credentials: DcqlCredentialQuery[]
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export interface DcqlCredentialQuery {
|
|
8
|
-
id: string
|
|
9
|
-
format: string
|
|
10
|
-
alg?: string[]
|
|
11
|
-
claims: DcqlClaim[]
|
|
12
|
-
meta?: Record<string, any>
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export interface DcqlClaim {
|
|
16
|
-
namespace: string
|
|
17
|
-
claim_name: string
|
|
18
|
-
filter?: DcqlFilter
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export interface DcqlFilter {
|
|
22
|
-
type: 'string' | 'number' | 'boolean'
|
|
23
|
-
pattern?: string
|
|
24
|
-
minimum?: number
|
|
25
|
-
maximum?: number
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export interface DcqlPresentationResult {
|
|
29
|
-
canBeSatisfied: boolean
|
|
30
|
-
credential_matches: Record<string, DcqlCredentialMatch>
|
|
31
|
-
invalid_matches?: Record<string, DcqlCredentialMatch>
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export interface DcqlCredentialMatch {
|
|
35
|
-
success: boolean
|
|
36
|
-
input_credential_index: number
|
|
37
|
-
claim_set_index?: number
|
|
38
|
-
output: any
|
|
39
|
-
}
|