@sphereon/ssi-types 0.18.2-next.9 → 0.18.2-unstable.13
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/LICENSE +201 -201
- package/README.md +49 -49
- package/dist/index.d.ts +3 -3
- package/dist/index.js +19 -19
- package/dist/mapper/credential-mapper.d.ts +107 -107
- package/dist/mapper/credential-mapper.js +556 -556
- package/dist/mapper/index.d.ts +1 -1
- package/dist/mapper/index.js +17 -17
- package/dist/types/did.d.ts +35 -35
- package/dist/types/did.js +75 -75
- package/dist/types/generic.d.ts +7 -7
- package/dist/types/generic.js +2 -2
- package/dist/types/index.d.ts +6 -6
- package/dist/types/index.js +22 -22
- package/dist/types/pex.d.ts +35 -35
- package/dist/types/pex.js +2 -2
- package/dist/types/sd-jwt-vc.d.ts +170 -170
- package/dist/types/sd-jwt-vc.js +71 -71
- package/dist/types/vc.d.ts +23 -23
- package/dist/types/vc.js +23 -23
- package/dist/types/w3c-vc.d.ts +247 -247
- package/dist/types/w3c-vc.js +29 -29
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.js +17 -17
- package/dist/utils/object.d.ts +6 -6
- package/dist/utils/object.js +20 -20
- package/package.json +2 -2
- package/src/index.ts +3 -3
- package/src/mapper/credential-mapper.ts +686 -686
- package/src/mapper/index.ts +1 -1
- package/src/types/generic.ts +8 -8
- package/src/types/index.ts +6 -6
- package/src/types/pex.ts +36 -36
- package/src/types/sd-jwt-vc.ts +232 -232
- package/src/types/vc.ts +62 -62
- package/src/types/w3c-vc.ts +300 -300
- package/src/utils/index.ts +1 -1
- package/src/utils/object.ts +19 -19
package/src/mapper/index.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './credential-mapper'
|
|
1
|
+
export * from './credential-mapper'
|
package/src/types/generic.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Accept a Type or a Promise of that Type.
|
|
3
|
-
*
|
|
4
|
-
* @internal
|
|
5
|
-
*/
|
|
6
|
-
export type OrPromise<T> = T | Promise<T>
|
|
7
|
-
|
|
8
|
-
export type BearerTokenArg = (() => Promise<string>) | string
|
|
1
|
+
/**
|
|
2
|
+
* Accept a Type or a Promise of that Type.
|
|
3
|
+
*
|
|
4
|
+
* @internal
|
|
5
|
+
*/
|
|
6
|
+
export type OrPromise<T> = T | Promise<T>
|
|
7
|
+
|
|
8
|
+
export type BearerTokenArg = (() => Promise<string>) | string
|
package/src/types/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export * from './did'
|
|
2
|
-
export * from './pex'
|
|
3
|
-
export * from './vc'
|
|
4
|
-
export * from './generic'
|
|
5
|
-
export * from './sd-jwt-vc'
|
|
6
|
-
export * from './w3c-vc'
|
|
1
|
+
export * from './did'
|
|
2
|
+
export * from './pex'
|
|
3
|
+
export * from './vc'
|
|
4
|
+
export * from './generic'
|
|
5
|
+
export * from './sd-jwt-vc'
|
|
6
|
+
export * from './w3c-vc'
|
package/src/types/pex.ts
CHANGED
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* It expresses how the inputs are presented as proofs to a Verifier.
|
|
3
|
-
*/
|
|
4
|
-
export interface PresentationSubmission {
|
|
5
|
-
/**
|
|
6
|
-
* A UUID or some other unique ID to identify this Presentation Submission
|
|
7
|
-
*/
|
|
8
|
-
id: string
|
|
9
|
-
/**
|
|
10
|
-
* A UUID or some other unique ID to identify this Presentation Definition
|
|
11
|
-
*/
|
|
12
|
-
definition_id: string
|
|
13
|
-
/**
|
|
14
|
-
* List of descriptors of how the claims are being mapped to presentation definition
|
|
15
|
-
*/
|
|
16
|
-
descriptor_map: Array<Descriptor>
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* descriptor map laying out the structure of the presentation submission.
|
|
21
|
-
*/
|
|
22
|
-
export interface Descriptor {
|
|
23
|
-
/**
|
|
24
|
-
* ID to identify the descriptor from Presentation Definition Input Descriptor it coresponds to.
|
|
25
|
-
*/
|
|
26
|
-
id: string
|
|
27
|
-
/**
|
|
28
|
-
* The path where the verifiable credential is located in the presentation submission json
|
|
29
|
-
*/
|
|
30
|
-
path: string
|
|
31
|
-
path_nested?: Descriptor
|
|
32
|
-
/**
|
|
33
|
-
* The Proof or JWT algorith that the proof is in
|
|
34
|
-
*/
|
|
35
|
-
format: string
|
|
36
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* It expresses how the inputs are presented as proofs to a Verifier.
|
|
3
|
+
*/
|
|
4
|
+
export interface PresentationSubmission {
|
|
5
|
+
/**
|
|
6
|
+
* A UUID or some other unique ID to identify this Presentation Submission
|
|
7
|
+
*/
|
|
8
|
+
id: string
|
|
9
|
+
/**
|
|
10
|
+
* A UUID or some other unique ID to identify this Presentation Definition
|
|
11
|
+
*/
|
|
12
|
+
definition_id: string
|
|
13
|
+
/**
|
|
14
|
+
* List of descriptors of how the claims are being mapped to presentation definition
|
|
15
|
+
*/
|
|
16
|
+
descriptor_map: Array<Descriptor>
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* descriptor map laying out the structure of the presentation submission.
|
|
21
|
+
*/
|
|
22
|
+
export interface Descriptor {
|
|
23
|
+
/**
|
|
24
|
+
* ID to identify the descriptor from Presentation Definition Input Descriptor it coresponds to.
|
|
25
|
+
*/
|
|
26
|
+
id: string
|
|
27
|
+
/**
|
|
28
|
+
* The path where the verifiable credential is located in the presentation submission json
|
|
29
|
+
*/
|
|
30
|
+
path: string
|
|
31
|
+
path_nested?: Descriptor
|
|
32
|
+
/**
|
|
33
|
+
* The Proof or JWT algorith that the proof is in
|
|
34
|
+
*/
|
|
35
|
+
format: string
|
|
36
|
+
}
|
package/src/types/sd-jwt-vc.ts
CHANGED
|
@@ -1,232 +1,232 @@
|
|
|
1
|
-
import { OriginalType, WrappedVerifiableCredential, WrappedVerifiablePresentation } from './vc'
|
|
2
|
-
import { decodeSdJwtVc as _decodeSdJwtVc } from '@sd-jwt/decode'
|
|
3
|
-
|
|
4
|
-
type JsonValue = string | number | boolean | { [x: string]: JsonValue | undefined } | Array<JsonValue>
|
|
5
|
-
|
|
6
|
-
type SdJwtJsonValue =
|
|
7
|
-
| string
|
|
8
|
-
| number
|
|
9
|
-
| boolean
|
|
10
|
-
| {
|
|
11
|
-
[x: string]: SdJwtJsonValue | undefined
|
|
12
|
-
_sd?: string[]
|
|
13
|
-
}
|
|
14
|
-
| Array<SdJwtJsonValue | { '...': string }>
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Decoded 'pretty' SD JWT Verifiable Credential. This representation has all the `_sd` properties
|
|
18
|
-
* removed, and includes the disclosures directly within the payload.
|
|
19
|
-
*/
|
|
20
|
-
export interface SdJwtDecodedVerifiableCredentialPayload {
|
|
21
|
-
vct: string
|
|
22
|
-
iss: string
|
|
23
|
-
iat: number
|
|
24
|
-
nbf?: number
|
|
25
|
-
exp?: number
|
|
26
|
-
cnf?: {
|
|
27
|
-
jwk?: any
|
|
28
|
-
kid?: string
|
|
29
|
-
}
|
|
30
|
-
status?: {
|
|
31
|
-
idx: number
|
|
32
|
-
uri: string
|
|
33
|
-
}
|
|
34
|
-
sub?: string
|
|
35
|
-
|
|
36
|
-
[key: string]: JsonValue | undefined
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Represents a selective disclosure JWT vc in compact form.
|
|
41
|
-
*/
|
|
42
|
-
export type CompactSdJwtVc = string
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* The signed payload of an SD-JWT. Includes fields such as `_sd`, `...` and `_sd_alg`
|
|
46
|
-
*/
|
|
47
|
-
interface SdJwtSignedVerifiableCredentialPayload extends SdJwtDecodedVerifiableCredentialPayload {
|
|
48
|
-
// Only present if there are any selectively discloseable claims
|
|
49
|
-
_sd?: string[]
|
|
50
|
-
_sd_alg?: string
|
|
51
|
-
|
|
52
|
-
[x: string]: SdJwtJsonValue | undefined
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
type SdJwtFrameValue = boolean | Array<SdJwtFrameValue> | { [x: string]: SdJwtFrameValue }
|
|
56
|
-
export type SdJwtDisclosureFrame = Record<string, SdJwtFrameValue>
|
|
57
|
-
export type SdJwtPresentationFrame = Record<string, SdJwtFrameValue>
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Input for creating a SD JWT Verifiable Credential. This representation optionally includes the disclosure frame,
|
|
61
|
-
* (as `__disclosureFrame`) to indicate which fields in the signed SD-JWT should be selectively discloseable
|
|
62
|
-
*/
|
|
63
|
-
export interface SdJwtCredentialInput extends SdJwtDecodedVerifiableCredentialPayload {
|
|
64
|
-
/**
|
|
65
|
-
* Disclosure frame, indicating which fields in the signed SD-JWT should be selectively discloseable
|
|
66
|
-
* Will be removed from the actual SD-JWT payload before signing
|
|
67
|
-
*/
|
|
68
|
-
__disclosureFrame?: SdJwtDisclosureFrame
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export type SdJwtDecodedDisclosure = [string, string, JsonValue] | [string, JsonValue]
|
|
72
|
-
export interface SdJwtDisclosure {
|
|
73
|
-
// The encoded disclosure
|
|
74
|
-
encoded: string
|
|
75
|
-
|
|
76
|
-
// The decoded disclosure, in format [salt, claim, value] or in case of array entry [salt, value]
|
|
77
|
-
decoded: SdJwtDecodedDisclosure
|
|
78
|
-
|
|
79
|
-
// Digest over disclosure, can be used to match against a value within the SD JWT payload
|
|
80
|
-
digest: string
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* The decoded SD JWT Verifiable Credential. This representation includes multiple representations of the
|
|
85
|
-
* same SD-JWT, and allows to fully process an SD-JWT, as well as create a presentation SD-JWT (minus the KB-JWT) by removing
|
|
86
|
-
* certain disclosures from the compact SD-JWT.
|
|
87
|
-
*
|
|
88
|
-
* This representation is useful as it doesn't require a hasher implementation to match the different digests in the signed SD-JWT
|
|
89
|
-
* payload, with the different disclosures.
|
|
90
|
-
*/
|
|
91
|
-
export interface SdJwtDecodedVerifiableCredential {
|
|
92
|
-
/**
|
|
93
|
-
* The compact sd jwt is the sd-jwt encoded as string. It is a normal JWT,
|
|
94
|
-
* with the disclosures and kb-jwt appended separated by ~ */
|
|
95
|
-
compactSdJwtVc: string
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* The disclosures included within the SD-JWT in both encoded and decoded format.
|
|
99
|
-
* The digests are also included, and allows the disclosures to be linked against
|
|
100
|
-
* the digests in the signed payload.
|
|
101
|
-
*/
|
|
102
|
-
disclosures: Array<SdJwtDisclosure>
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* The signed payload is the payload of the sd-jwt that is actually signed, and that includes
|
|
106
|
-
* the `_sd` and `...` digests.
|
|
107
|
-
*/
|
|
108
|
-
signedPayload: SdJwtSignedVerifiableCredentialPayload
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* The decoded payload is the payload when all `_sd` and `...` digests have been replaced
|
|
112
|
-
* by the actual values from the disclosures. This format could also be seen as the 'pretty`
|
|
113
|
-
* version of the SD JWT payload.
|
|
114
|
-
*
|
|
115
|
-
* This is useful for displaying the contents of the SD JWT VC to the user, or for example
|
|
116
|
-
* for querying the contents of the SD JWT VC using a PEX presentation definition path.
|
|
117
|
-
*/
|
|
118
|
-
decodedPayload: SdJwtDecodedVerifiableCredentialPayload
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
export interface WrappedSdJwtVerifiableCredential {
|
|
122
|
-
/**
|
|
123
|
-
* Original VC that we've received. Can be either the encoded or decoded variant.
|
|
124
|
-
*/
|
|
125
|
-
original: SdJwtDecodedVerifiableCredential | CompactSdJwtVc
|
|
126
|
-
/**
|
|
127
|
-
* Decoded version of the SD-JWT payload. This is the decoded payload, rather than the whole SD-JWT as the `decoded` property
|
|
128
|
-
* is used in e.g. PEX to check for path filters from fields. The full decoded credential can be found in the `credential` field.
|
|
129
|
-
*/
|
|
130
|
-
decoded: SdJwtDecodedVerifiableCredentialPayload
|
|
131
|
-
/**
|
|
132
|
-
* Type of this credential.
|
|
133
|
-
*/
|
|
134
|
-
type: OriginalType.SD_JWT_VC_DECODED | OriginalType.SD_JWT_VC_ENCODED
|
|
135
|
-
/**
|
|
136
|
-
* The claim format, typically used during exchange transport protocols
|
|
137
|
-
*/
|
|
138
|
-
format: 'vc+sd-jwt'
|
|
139
|
-
/**
|
|
140
|
-
* Internal stable representation of a Credential
|
|
141
|
-
*/
|
|
142
|
-
credential: SdJwtDecodedVerifiableCredential
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
export interface WrappedSdJwtVerifiablePresentation {
|
|
146
|
-
/**
|
|
147
|
-
* Original VP that we've received. Can be either the encoded or decoded variant.
|
|
148
|
-
*/
|
|
149
|
-
original: SdJwtDecodedVerifiableCredential | CompactSdJwtVc
|
|
150
|
-
/**
|
|
151
|
-
* Decoded version of the SD-JWT payload. This is the decoded payload, rather than the whole SD-JWT.
|
|
152
|
-
*/
|
|
153
|
-
decoded: SdJwtDecodedVerifiableCredentialPayload
|
|
154
|
-
/**
|
|
155
|
-
* Type of this Presentation.
|
|
156
|
-
*/
|
|
157
|
-
type: OriginalType.SD_JWT_VC_DECODED | OriginalType.SD_JWT_VC_ENCODED
|
|
158
|
-
/**
|
|
159
|
-
* The claim format, typically used during exchange transport protocols
|
|
160
|
-
*/
|
|
161
|
-
format: 'vc+sd-jwt'
|
|
162
|
-
/**
|
|
163
|
-
* Internal stable representation of a Presentation
|
|
164
|
-
*/
|
|
165
|
-
presentation: SdJwtDecodedVerifiableCredential
|
|
166
|
-
/**
|
|
167
|
-
* Wrapped Verifiable Credentials belonging to the Presentation. Will always be an array
|
|
168
|
-
* with a single SdJwtVerifiableCredential entry.
|
|
169
|
-
*/
|
|
170
|
-
vcs: [WrappedSdJwtVerifiableCredential]
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
export function isWrappedSdJwtVerifiableCredential(vc: WrappedVerifiableCredential): vc is WrappedSdJwtVerifiableCredential {
|
|
174
|
-
return vc.format === 'vc+sd-jwt'
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
export function isWrappedSdJwtVerifiablePresentation(vp: WrappedVerifiablePresentation): vp is WrappedSdJwtVerifiablePresentation {
|
|
178
|
-
return vp.format === 'vc+sd-jwt'
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
export type Hasher = (data: string, alg: string) => Uint8Array
|
|
182
|
-
export type AsyncHasher = (data: string, alg: string) => Promise<Uint8Array>
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
* Decode an SD-JWT vc from its compact format (string) to an object containing the disclosures,
|
|
186
|
-
* signed payload, decoded payload and the compact SD-JWT vc.
|
|
187
|
-
*
|
|
188
|
-
* Both the input and output interfaces of this method are defined in `@sphereon/ssi-types`, so
|
|
189
|
-
* this method hides the actual implementation of SD-JWT (which is currently based on @sd-jwt/core)
|
|
190
|
-
*/
|
|
191
|
-
export function decodeSdJwtVc(compactSdJwtVc: CompactSdJwtVc, hasher: Hasher): SdJwtDecodedVerifiableCredential {
|
|
192
|
-
const { signedPayload, decodedPayload, disclosures } = _decodeSdJwtVc(compactSdJwtVc, hasher)
|
|
193
|
-
|
|
194
|
-
return {
|
|
195
|
-
compactSdJwtVc,
|
|
196
|
-
decodedPayload: decodedPayload as SdJwtDecodedVerifiableCredentialPayload,
|
|
197
|
-
disclosures: disclosures.map((d) => {
|
|
198
|
-
const decoded = d.key ? [d.salt, d.key, d.value] : [d.salt, d.value]
|
|
199
|
-
return {
|
|
200
|
-
decoded: decoded as SdJwtDecodedDisclosure,
|
|
201
|
-
digest: d.digest,
|
|
202
|
-
encoded: d.encoded,
|
|
203
|
-
} satisfies SdJwtDisclosure
|
|
204
|
-
}),
|
|
205
|
-
signedPayload: signedPayload as SdJwtDecodedVerifiableCredentialPayload,
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
/**
|
|
210
|
-
* Decode an SD-JWT vc from its compact format (string) to an object containing the disclosures,
|
|
211
|
-
* signed payload, decoded payload and the compact SD-JWT vc.
|
|
212
|
-
*
|
|
213
|
-
* Both the input and output interfaces of this method are defined in `@sphereon/ssi-types`, so
|
|
214
|
-
* this method hides the actual implementation of SD-JWT (which is currently based on @sd-jwt/core)
|
|
215
|
-
*/
|
|
216
|
-
export async function decodeSdJwtVcAsync(compactSdJwtVc: CompactSdJwtVc, hasher: AsyncHasher): Promise<SdJwtDecodedVerifiableCredential> {
|
|
217
|
-
const { signedPayload, decodedPayload, disclosures } = await _decodeSdJwtVc(compactSdJwtVc, hasher)
|
|
218
|
-
|
|
219
|
-
return {
|
|
220
|
-
compactSdJwtVc,
|
|
221
|
-
decodedPayload: decodedPayload as SdJwtDecodedVerifiableCredentialPayload,
|
|
222
|
-
disclosures: disclosures.map((d) => {
|
|
223
|
-
const decoded = d.key ? [d.salt, d.key, d.value] : [d.salt, d.value]
|
|
224
|
-
return {
|
|
225
|
-
decoded: decoded as SdJwtDecodedDisclosure,
|
|
226
|
-
digest: d.digest,
|
|
227
|
-
encoded: d.encoded,
|
|
228
|
-
} satisfies SdJwtDisclosure
|
|
229
|
-
}),
|
|
230
|
-
signedPayload: signedPayload as SdJwtDecodedVerifiableCredentialPayload,
|
|
231
|
-
}
|
|
232
|
-
}
|
|
1
|
+
import { OriginalType, WrappedVerifiableCredential, WrappedVerifiablePresentation } from './vc'
|
|
2
|
+
import { decodeSdJwtVc as _decodeSdJwtVc } from '@sd-jwt/decode'
|
|
3
|
+
|
|
4
|
+
type JsonValue = string | number | boolean | { [x: string]: JsonValue | undefined } | Array<JsonValue>
|
|
5
|
+
|
|
6
|
+
type SdJwtJsonValue =
|
|
7
|
+
| string
|
|
8
|
+
| number
|
|
9
|
+
| boolean
|
|
10
|
+
| {
|
|
11
|
+
[x: string]: SdJwtJsonValue | undefined
|
|
12
|
+
_sd?: string[]
|
|
13
|
+
}
|
|
14
|
+
| Array<SdJwtJsonValue | { '...': string }>
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Decoded 'pretty' SD JWT Verifiable Credential. This representation has all the `_sd` properties
|
|
18
|
+
* removed, and includes the disclosures directly within the payload.
|
|
19
|
+
*/
|
|
20
|
+
export interface SdJwtDecodedVerifiableCredentialPayload {
|
|
21
|
+
vct: string
|
|
22
|
+
iss: string
|
|
23
|
+
iat: number
|
|
24
|
+
nbf?: number
|
|
25
|
+
exp?: number
|
|
26
|
+
cnf?: {
|
|
27
|
+
jwk?: any
|
|
28
|
+
kid?: string
|
|
29
|
+
}
|
|
30
|
+
status?: {
|
|
31
|
+
idx: number
|
|
32
|
+
uri: string
|
|
33
|
+
}
|
|
34
|
+
sub?: string
|
|
35
|
+
|
|
36
|
+
[key: string]: JsonValue | undefined
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Represents a selective disclosure JWT vc in compact form.
|
|
41
|
+
*/
|
|
42
|
+
export type CompactSdJwtVc = string
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* The signed payload of an SD-JWT. Includes fields such as `_sd`, `...` and `_sd_alg`
|
|
46
|
+
*/
|
|
47
|
+
interface SdJwtSignedVerifiableCredentialPayload extends SdJwtDecodedVerifiableCredentialPayload {
|
|
48
|
+
// Only present if there are any selectively discloseable claims
|
|
49
|
+
_sd?: string[]
|
|
50
|
+
_sd_alg?: string
|
|
51
|
+
|
|
52
|
+
[x: string]: SdJwtJsonValue | undefined
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
type SdJwtFrameValue = boolean | Array<SdJwtFrameValue> | { [x: string]: SdJwtFrameValue }
|
|
56
|
+
export type SdJwtDisclosureFrame = Record<string, SdJwtFrameValue>
|
|
57
|
+
export type SdJwtPresentationFrame = Record<string, SdJwtFrameValue>
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Input for creating a SD JWT Verifiable Credential. This representation optionally includes the disclosure frame,
|
|
61
|
+
* (as `__disclosureFrame`) to indicate which fields in the signed SD-JWT should be selectively discloseable
|
|
62
|
+
*/
|
|
63
|
+
export interface SdJwtCredentialInput extends SdJwtDecodedVerifiableCredentialPayload {
|
|
64
|
+
/**
|
|
65
|
+
* Disclosure frame, indicating which fields in the signed SD-JWT should be selectively discloseable
|
|
66
|
+
* Will be removed from the actual SD-JWT payload before signing
|
|
67
|
+
*/
|
|
68
|
+
__disclosureFrame?: SdJwtDisclosureFrame
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export type SdJwtDecodedDisclosure = [string, string, JsonValue] | [string, JsonValue]
|
|
72
|
+
export interface SdJwtDisclosure {
|
|
73
|
+
// The encoded disclosure
|
|
74
|
+
encoded: string
|
|
75
|
+
|
|
76
|
+
// The decoded disclosure, in format [salt, claim, value] or in case of array entry [salt, value]
|
|
77
|
+
decoded: SdJwtDecodedDisclosure
|
|
78
|
+
|
|
79
|
+
// Digest over disclosure, can be used to match against a value within the SD JWT payload
|
|
80
|
+
digest: string
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* The decoded SD JWT Verifiable Credential. This representation includes multiple representations of the
|
|
85
|
+
* same SD-JWT, and allows to fully process an SD-JWT, as well as create a presentation SD-JWT (minus the KB-JWT) by removing
|
|
86
|
+
* certain disclosures from the compact SD-JWT.
|
|
87
|
+
*
|
|
88
|
+
* This representation is useful as it doesn't require a hasher implementation to match the different digests in the signed SD-JWT
|
|
89
|
+
* payload, with the different disclosures.
|
|
90
|
+
*/
|
|
91
|
+
export interface SdJwtDecodedVerifiableCredential {
|
|
92
|
+
/**
|
|
93
|
+
* The compact sd jwt is the sd-jwt encoded as string. It is a normal JWT,
|
|
94
|
+
* with the disclosures and kb-jwt appended separated by ~ */
|
|
95
|
+
compactSdJwtVc: string
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* The disclosures included within the SD-JWT in both encoded and decoded format.
|
|
99
|
+
* The digests are also included, and allows the disclosures to be linked against
|
|
100
|
+
* the digests in the signed payload.
|
|
101
|
+
*/
|
|
102
|
+
disclosures: Array<SdJwtDisclosure>
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* The signed payload is the payload of the sd-jwt that is actually signed, and that includes
|
|
106
|
+
* the `_sd` and `...` digests.
|
|
107
|
+
*/
|
|
108
|
+
signedPayload: SdJwtSignedVerifiableCredentialPayload
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* The decoded payload is the payload when all `_sd` and `...` digests have been replaced
|
|
112
|
+
* by the actual values from the disclosures. This format could also be seen as the 'pretty`
|
|
113
|
+
* version of the SD JWT payload.
|
|
114
|
+
*
|
|
115
|
+
* This is useful for displaying the contents of the SD JWT VC to the user, or for example
|
|
116
|
+
* for querying the contents of the SD JWT VC using a PEX presentation definition path.
|
|
117
|
+
*/
|
|
118
|
+
decodedPayload: SdJwtDecodedVerifiableCredentialPayload
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export interface WrappedSdJwtVerifiableCredential {
|
|
122
|
+
/**
|
|
123
|
+
* Original VC that we've received. Can be either the encoded or decoded variant.
|
|
124
|
+
*/
|
|
125
|
+
original: SdJwtDecodedVerifiableCredential | CompactSdJwtVc
|
|
126
|
+
/**
|
|
127
|
+
* Decoded version of the SD-JWT payload. This is the decoded payload, rather than the whole SD-JWT as the `decoded` property
|
|
128
|
+
* is used in e.g. PEX to check for path filters from fields. The full decoded credential can be found in the `credential` field.
|
|
129
|
+
*/
|
|
130
|
+
decoded: SdJwtDecodedVerifiableCredentialPayload
|
|
131
|
+
/**
|
|
132
|
+
* Type of this credential.
|
|
133
|
+
*/
|
|
134
|
+
type: OriginalType.SD_JWT_VC_DECODED | OriginalType.SD_JWT_VC_ENCODED
|
|
135
|
+
/**
|
|
136
|
+
* The claim format, typically used during exchange transport protocols
|
|
137
|
+
*/
|
|
138
|
+
format: 'vc+sd-jwt'
|
|
139
|
+
/**
|
|
140
|
+
* Internal stable representation of a Credential
|
|
141
|
+
*/
|
|
142
|
+
credential: SdJwtDecodedVerifiableCredential
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export interface WrappedSdJwtVerifiablePresentation {
|
|
146
|
+
/**
|
|
147
|
+
* Original VP that we've received. Can be either the encoded or decoded variant.
|
|
148
|
+
*/
|
|
149
|
+
original: SdJwtDecodedVerifiableCredential | CompactSdJwtVc
|
|
150
|
+
/**
|
|
151
|
+
* Decoded version of the SD-JWT payload. This is the decoded payload, rather than the whole SD-JWT.
|
|
152
|
+
*/
|
|
153
|
+
decoded: SdJwtDecodedVerifiableCredentialPayload
|
|
154
|
+
/**
|
|
155
|
+
* Type of this Presentation.
|
|
156
|
+
*/
|
|
157
|
+
type: OriginalType.SD_JWT_VC_DECODED | OriginalType.SD_JWT_VC_ENCODED
|
|
158
|
+
/**
|
|
159
|
+
* The claim format, typically used during exchange transport protocols
|
|
160
|
+
*/
|
|
161
|
+
format: 'vc+sd-jwt'
|
|
162
|
+
/**
|
|
163
|
+
* Internal stable representation of a Presentation
|
|
164
|
+
*/
|
|
165
|
+
presentation: SdJwtDecodedVerifiableCredential
|
|
166
|
+
/**
|
|
167
|
+
* Wrapped Verifiable Credentials belonging to the Presentation. Will always be an array
|
|
168
|
+
* with a single SdJwtVerifiableCredential entry.
|
|
169
|
+
*/
|
|
170
|
+
vcs: [WrappedSdJwtVerifiableCredential]
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export function isWrappedSdJwtVerifiableCredential(vc: WrappedVerifiableCredential): vc is WrappedSdJwtVerifiableCredential {
|
|
174
|
+
return vc.format === 'vc+sd-jwt'
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export function isWrappedSdJwtVerifiablePresentation(vp: WrappedVerifiablePresentation): vp is WrappedSdJwtVerifiablePresentation {
|
|
178
|
+
return vp.format === 'vc+sd-jwt'
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export type Hasher = (data: string, alg: string) => Uint8Array
|
|
182
|
+
export type AsyncHasher = (data: string, alg: string) => Promise<Uint8Array>
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Decode an SD-JWT vc from its compact format (string) to an object containing the disclosures,
|
|
186
|
+
* signed payload, decoded payload and the compact SD-JWT vc.
|
|
187
|
+
*
|
|
188
|
+
* Both the input and output interfaces of this method are defined in `@sphereon/ssi-types`, so
|
|
189
|
+
* this method hides the actual implementation of SD-JWT (which is currently based on @sd-jwt/core)
|
|
190
|
+
*/
|
|
191
|
+
export function decodeSdJwtVc(compactSdJwtVc: CompactSdJwtVc, hasher: Hasher): SdJwtDecodedVerifiableCredential {
|
|
192
|
+
const { signedPayload, decodedPayload, disclosures } = _decodeSdJwtVc(compactSdJwtVc, hasher)
|
|
193
|
+
|
|
194
|
+
return {
|
|
195
|
+
compactSdJwtVc,
|
|
196
|
+
decodedPayload: decodedPayload as SdJwtDecodedVerifiableCredentialPayload,
|
|
197
|
+
disclosures: disclosures.map((d) => {
|
|
198
|
+
const decoded = d.key ? [d.salt, d.key, d.value] : [d.salt, d.value]
|
|
199
|
+
return {
|
|
200
|
+
decoded: decoded as SdJwtDecodedDisclosure,
|
|
201
|
+
digest: d.digest,
|
|
202
|
+
encoded: d.encoded,
|
|
203
|
+
} satisfies SdJwtDisclosure
|
|
204
|
+
}),
|
|
205
|
+
signedPayload: signedPayload as SdJwtDecodedVerifiableCredentialPayload,
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Decode an SD-JWT vc from its compact format (string) to an object containing the disclosures,
|
|
211
|
+
* signed payload, decoded payload and the compact SD-JWT vc.
|
|
212
|
+
*
|
|
213
|
+
* Both the input and output interfaces of this method are defined in `@sphereon/ssi-types`, so
|
|
214
|
+
* this method hides the actual implementation of SD-JWT (which is currently based on @sd-jwt/core)
|
|
215
|
+
*/
|
|
216
|
+
export async function decodeSdJwtVcAsync(compactSdJwtVc: CompactSdJwtVc, hasher: AsyncHasher): Promise<SdJwtDecodedVerifiableCredential> {
|
|
217
|
+
const { signedPayload, decodedPayload, disclosures } = await _decodeSdJwtVc(compactSdJwtVc, hasher)
|
|
218
|
+
|
|
219
|
+
return {
|
|
220
|
+
compactSdJwtVc,
|
|
221
|
+
decodedPayload: decodedPayload as SdJwtDecodedVerifiableCredentialPayload,
|
|
222
|
+
disclosures: disclosures.map((d) => {
|
|
223
|
+
const decoded = d.key ? [d.salt, d.key, d.value] : [d.salt, d.value]
|
|
224
|
+
return {
|
|
225
|
+
decoded: decoded as SdJwtDecodedDisclosure,
|
|
226
|
+
digest: d.digest,
|
|
227
|
+
encoded: d.encoded,
|
|
228
|
+
} satisfies SdJwtDisclosure
|
|
229
|
+
}),
|
|
230
|
+
signedPayload: signedPayload as SdJwtDecodedVerifiableCredentialPayload,
|
|
231
|
+
}
|
|
232
|
+
}
|