@sphereon/ssi-types 0.8.1-next.18 → 0.8.1-next.192
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/mapper/credential-mapper.d.ts +28 -9
- package/dist/mapper/credential-mapper.d.ts.map +1 -1
- package/dist/mapper/credential-mapper.js +60 -28
- package/dist/mapper/credential-mapper.js.map +1 -1
- package/dist/types/vc.d.ts +24 -21
- package/dist/types/vc.d.ts.map +1 -1
- package/dist/types/vc.js.map +1 -1
- package/package.json +3 -2
- package/src/mapper/credential-mapper.ts +95 -30
- package/src/types/vc.ts +16 -11
|
@@ -2,18 +2,37 @@ import { ICredential, IPresentation, IVerifiableCredential, IVerifiablePresentat
|
|
|
2
2
|
export declare class CredentialMapper {
|
|
3
3
|
static decodeVerifiablePresentation(presentation: OriginalVerifiablePresentation): JwtDecodedVerifiablePresentation | IVerifiablePresentation;
|
|
4
4
|
static decodeVerifiableCredential(credential: OriginalVerifiableCredential): JwtDecodedVerifiableCredential | IVerifiableCredential;
|
|
5
|
-
static toWrappedVerifiablePresentation(presentation: OriginalVerifiablePresentation
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
static toWrappedVerifiablePresentation(presentation: OriginalVerifiablePresentation, opts?: {
|
|
6
|
+
maxTimeSkewInMS?: number;
|
|
7
|
+
}): WrappedVerifiablePresentation;
|
|
8
|
+
static toWrappedVerifiableCredentials(verifiableCredentials: OriginalVerifiableCredential[], opts?: {
|
|
9
|
+
maxTimeSkewInMS?: number;
|
|
10
|
+
}): WrappedVerifiableCredential[];
|
|
11
|
+
static toWrappedVerifiableCredential(verifiableCredential: OriginalVerifiableCredential, opts?: {
|
|
12
|
+
maxTimeSkewInMS?: number;
|
|
13
|
+
}): WrappedVerifiableCredential;
|
|
8
14
|
static isJwtEncoded(original: OriginalVerifiableCredential | OriginalVerifiablePresentation): boolean;
|
|
9
15
|
private static isJsonLdString;
|
|
10
16
|
static isJwtDecodedCredential(original: OriginalVerifiableCredential): boolean;
|
|
11
17
|
static isJwtDecodedPresentation(original: OriginalVerifiablePresentation): boolean;
|
|
12
|
-
static jwtEncodedPresentationToUniformPresentation(jwt: string, makeCredentialsUniform?: boolean
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
static
|
|
16
|
-
|
|
17
|
-
|
|
18
|
+
static jwtEncodedPresentationToUniformPresentation(jwt: string, makeCredentialsUniform?: boolean, opts?: {
|
|
19
|
+
maxTimeSkewInMS?: number;
|
|
20
|
+
}): IPresentation;
|
|
21
|
+
static jwtDecodedPresentationToUniformPresentation(decoded: JwtDecodedVerifiablePresentation, makeCredentialsUniform?: boolean, opts?: {
|
|
22
|
+
maxTimeSkewInMS?: number;
|
|
23
|
+
}): IPresentation;
|
|
24
|
+
static toUniformCredential(verifiableCredential: OriginalVerifiableCredential, opts?: {
|
|
25
|
+
maxTimeSkewInMS?: number;
|
|
26
|
+
}): ICredential;
|
|
27
|
+
static toUniformPresentation(presentation: OriginalVerifiablePresentation, opts?: {
|
|
28
|
+
maxTimeSkewInMS?: number;
|
|
29
|
+
}): IPresentation;
|
|
30
|
+
static jwtEncodedCredentialToUniformCredential(jwt: string, opts?: {
|
|
31
|
+
maxTimeSkewInMS?: number;
|
|
32
|
+
}): ICredential;
|
|
33
|
+
static jwtDecodedCredentialToUniformCredential(decoded: JwtDecodedVerifiableCredential, opts?: {
|
|
34
|
+
maxTimeSkewInMS?: number;
|
|
35
|
+
}): ICredential;
|
|
36
|
+
static toExternalVerifiableCredential(verifiableCredential: any): IVerifiableCredential;
|
|
18
37
|
}
|
|
19
38
|
//# sourceMappingURL=credential-mapper.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"credential-mapper.d.ts","sourceRoot":"","sources":["../../src/mapper/credential-mapper.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"credential-mapper.d.ts","sourceRoot":"","sources":["../../src/mapper/credential-mapper.ts"],"names":[],"mappings":"A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tC,IAAI,CAAC,EAAE;QAAE,eAAe,CAAC,EAAE,MAAM,CAAA;KAAE,GAClC,aAAa;IA+BhB,MAAM,CAAC,mBAAmB,CAAC,oBAAoB,EAAE,4BAA4B,EAAE,IAAI,CAAC,EAAE;QAAE,eAAe,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,WAAW;IAchI,MAAM,CAAC,qBAAqB,CAAC,YAAY,EAAE,8BAA8B,EAAE,IAAI,CAAC,EAAE;QAAE,eAAe,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,aAAa;IAe9H,MAAM,CAAC,uCAAuC,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE;QAAE,eAAe,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,WAAW;IAI7G,MAAM,CAAC,uCAAuC,CAAC,OAAO,EAAE,8BAA8B,EAAE,IAAI,CAAC,EAAE;QAAE,eAAe,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,WAAW;IA4EzI,MAAM,CAAC,8BAA8B,CAAC,oBAAoB,EAAE,GAAG,GAAG,qBAAqB;CAiCxF"}
|
|
@@ -36,7 +36,7 @@ class CredentialMapper {
|
|
|
36
36
|
return credential;
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
|
-
static toWrappedVerifiablePresentation(presentation) {
|
|
39
|
+
static toWrappedVerifiablePresentation(presentation, opts) {
|
|
40
40
|
const original = presentation;
|
|
41
41
|
const isJwtEncoded = CredentialMapper.isJwtEncoded(original);
|
|
42
42
|
const isJwtDecoded = CredentialMapper.isJwtDecodedPresentation(original);
|
|
@@ -44,9 +44,9 @@ class CredentialMapper {
|
|
|
44
44
|
const format = isJwtDecoded || isJwtEncoded ? 'jwt_vp' : 'ldp_vp';
|
|
45
45
|
const decoded = CredentialMapper.decodeVerifiablePresentation(original);
|
|
46
46
|
const vp = isJwtEncoded || isJwtDecoded
|
|
47
|
-
? CredentialMapper.jwtDecodedPresentationToUniformPresentation(decoded, false)
|
|
47
|
+
? CredentialMapper.jwtDecodedPresentationToUniformPresentation(decoded, false, opts)
|
|
48
48
|
: decoded;
|
|
49
|
-
const vcs = CredentialMapper.toWrappedVerifiableCredentials(vp.verifiableCredential);
|
|
49
|
+
const vcs = CredentialMapper.toWrappedVerifiableCredentials(vp.verifiableCredential, opts);
|
|
50
50
|
// todo: We probably want to add proofs as well
|
|
51
51
|
return {
|
|
52
52
|
type,
|
|
@@ -57,17 +57,17 @@ class CredentialMapper {
|
|
|
57
57
|
vcs,
|
|
58
58
|
};
|
|
59
59
|
}
|
|
60
|
-
static toWrappedVerifiableCredentials(verifiableCredentials) {
|
|
61
|
-
return verifiableCredentials.map(CredentialMapper.toWrappedVerifiableCredential);
|
|
60
|
+
static toWrappedVerifiableCredentials(verifiableCredentials, opts) {
|
|
61
|
+
return verifiableCredentials.map((vc) => CredentialMapper.toWrappedVerifiableCredential(vc, opts));
|
|
62
62
|
}
|
|
63
|
-
static toWrappedVerifiableCredential(verifiableCredential) {
|
|
63
|
+
static toWrappedVerifiableCredential(verifiableCredential, opts) {
|
|
64
64
|
const original = verifiableCredential;
|
|
65
65
|
const decoded = CredentialMapper.decodeVerifiableCredential(verifiableCredential);
|
|
66
66
|
const isJwtEncoded = CredentialMapper.isJwtEncoded(original);
|
|
67
67
|
const isJwtDecoded = CredentialMapper.isJwtDecodedCredential(original);
|
|
68
68
|
const type = isJwtEncoded ? types_1.OriginalType.JWT_ENCODED : isJwtDecoded ? types_1.OriginalType.JWT_DECODED : types_1.OriginalType.JSONLD;
|
|
69
69
|
const credential = isJwtDecoded || isJwtDecoded
|
|
70
|
-
? CredentialMapper.jwtDecodedCredentialToUniformCredential(decoded)
|
|
70
|
+
? CredentialMapper.jwtDecodedCredentialToUniformCredential(decoded, opts)
|
|
71
71
|
: decoded;
|
|
72
72
|
const format = isJwtDecoded || isJwtDecoded ? 'jwt_vc' : 'ldp_vc';
|
|
73
73
|
//todo: We probably want to add proofs as well
|
|
@@ -91,13 +91,13 @@ class CredentialMapper {
|
|
|
91
91
|
static isJwtDecodedPresentation(original) {
|
|
92
92
|
return original['vp'] !== undefined && original['iss'] !== undefined;
|
|
93
93
|
}
|
|
94
|
-
static jwtEncodedPresentationToUniformPresentation(jwt, makeCredentialsUniform = true) {
|
|
95
|
-
return CredentialMapper.jwtDecodedPresentationToUniformPresentation((0, jwt_decode_1.default)(jwt), makeCredentialsUniform);
|
|
94
|
+
static jwtEncodedPresentationToUniformPresentation(jwt, makeCredentialsUniform = true, opts) {
|
|
95
|
+
return CredentialMapper.jwtDecodedPresentationToUniformPresentation((0, jwt_decode_1.default)(jwt), makeCredentialsUniform, opts);
|
|
96
96
|
}
|
|
97
|
-
static jwtDecodedPresentationToUniformPresentation(decoded, makeCredentialsUniform = true) {
|
|
97
|
+
static jwtDecodedPresentationToUniformPresentation(decoded, makeCredentialsUniform = true, opts) {
|
|
98
98
|
const presentation = Object.assign({}, decoded.vp);
|
|
99
99
|
if (makeCredentialsUniform) {
|
|
100
|
-
presentation.verifiableCredential = decoded.vp.verifiableCredential.map(CredentialMapper.toUniformCredential); // We cast it because we IPresentation needs a VC. The internal Credential doesn't have the required Proof anymore (that is intended)
|
|
100
|
+
presentation.verifiableCredential = decoded.vp.verifiableCredential.map((vc) => CredentialMapper.toUniformCredential(vc, opts)); // We cast it because we IPresentation needs a VC. The internal Credential doesn't have the required Proof anymore (that is intended)
|
|
101
101
|
}
|
|
102
102
|
// Since this is a presentation, we delete any proof just to be sure (should not occur on JWT, but better safe than sorry)
|
|
103
103
|
delete presentation.proof;
|
|
@@ -119,19 +119,19 @@ class CredentialMapper {
|
|
|
119
119
|
}
|
|
120
120
|
return presentation;
|
|
121
121
|
}
|
|
122
|
-
static toUniformCredential(verifiableCredential) {
|
|
122
|
+
static toUniformCredential(verifiableCredential, opts) {
|
|
123
123
|
const original = verifiableCredential;
|
|
124
124
|
const decoded = CredentialMapper.decodeVerifiableCredential(verifiableCredential);
|
|
125
125
|
const isJwtEncoded = CredentialMapper.isJwtEncoded(original);
|
|
126
126
|
const isJwtDecoded = CredentialMapper.isJwtDecodedCredential(original);
|
|
127
127
|
if (isJwtDecoded || isJwtEncoded) {
|
|
128
|
-
return CredentialMapper.jwtDecodedCredentialToUniformCredential(decoded);
|
|
128
|
+
return CredentialMapper.jwtDecodedCredentialToUniformCredential(decoded, opts);
|
|
129
129
|
}
|
|
130
130
|
else {
|
|
131
131
|
return decoded;
|
|
132
132
|
}
|
|
133
133
|
}
|
|
134
|
-
static toUniformPresentation(presentation) {
|
|
134
|
+
static toUniformPresentation(presentation, opts) {
|
|
135
135
|
var _a;
|
|
136
136
|
const original = presentation;
|
|
137
137
|
const decoded = CredentialMapper.decodeVerifiablePresentation(original);
|
|
@@ -140,26 +140,29 @@ class CredentialMapper {
|
|
|
140
140
|
const uniformPresentation = isJwtEncoded || isJwtDecoded
|
|
141
141
|
? CredentialMapper.jwtDecodedPresentationToUniformPresentation(decoded, false)
|
|
142
142
|
: decoded;
|
|
143
|
-
uniformPresentation.verifiableCredential = (_a = uniformPresentation.verifiableCredential) === null || _a === void 0 ? void 0 : _a.map(CredentialMapper.toUniformCredential); // We cast it because we IPresentation needs a VC. The internal Credential doesn't have the required Proof anymore (that is intended)
|
|
143
|
+
uniformPresentation.verifiableCredential = (_a = uniformPresentation.verifiableCredential) === null || _a === void 0 ? void 0 : _a.map((vc) => CredentialMapper.toUniformCredential(vc, opts)); // We cast it because we IPresentation needs a VC. The internal Credential doesn't have the required Proof anymore (that is intended)
|
|
144
144
|
return uniformPresentation;
|
|
145
145
|
}
|
|
146
|
-
static jwtEncodedCredentialToUniformCredential(jwt) {
|
|
147
|
-
return CredentialMapper.jwtDecodedCredentialToUniformCredential((0, jwt_decode_1.default)(jwt));
|
|
146
|
+
static jwtEncodedCredentialToUniformCredential(jwt, opts) {
|
|
147
|
+
return CredentialMapper.jwtDecodedCredentialToUniformCredential((0, jwt_decode_1.default)(jwt), opts);
|
|
148
148
|
}
|
|
149
|
-
static jwtDecodedCredentialToUniformCredential(decoded) {
|
|
150
|
-
var _a, _b;
|
|
149
|
+
static jwtDecodedCredentialToUniformCredential(decoded, opts) {
|
|
151
150
|
const credential = Object.assign({}, decoded.vc);
|
|
152
151
|
// Since this is a credential, we delete any proof just to be sure (should not occur on JWT, but better safe than sorry)
|
|
153
152
|
delete credential.proof;
|
|
153
|
+
const maxSkewInMS = (opts === null || opts === void 0 ? void 0 : opts.maxTimeSkewInMS) !== undefined ? opts.maxTimeSkewInMS : 999;
|
|
154
154
|
if (decoded.exp) {
|
|
155
|
-
const expDate =
|
|
155
|
+
const expDate = credential.expirationDate;
|
|
156
156
|
const jwtExp = parseInt(decoded.exp.toString());
|
|
157
157
|
// fix seconds to millisecs for the date
|
|
158
158
|
const expDateAsStr = jwtExp < 9999999999 ? new Date(jwtExp * 1000).toISOString().replace(/\.000Z/, 'Z') : new Date(jwtExp).toISOString();
|
|
159
159
|
if (expDate && expDate !== expDateAsStr) {
|
|
160
|
-
|
|
160
|
+
const diff = Math.abs(new Date(expDateAsStr).getTime() - new Date(expDate).getTime());
|
|
161
|
+
if (!maxSkewInMS || diff > maxSkewInMS) {
|
|
162
|
+
throw new Error(`Inconsistent expiration dates between JWT claim (${expDateAsStr}) and VC value (${expDate})`);
|
|
163
|
+
}
|
|
161
164
|
}
|
|
162
|
-
credential.
|
|
165
|
+
credential.expirationDate = expDateAsStr;
|
|
163
166
|
}
|
|
164
167
|
if (decoded.nbf) {
|
|
165
168
|
const issuanceDate = credential.issuanceDate;
|
|
@@ -167,7 +170,10 @@ class CredentialMapper {
|
|
|
167
170
|
// fix seconds to millisecs for the date
|
|
168
171
|
const nbfDateAsStr = jwtNbf < 9999999999 ? new Date(jwtNbf * 1000).toISOString().replace(/\.000Z/, 'Z') : new Date(jwtNbf).toISOString();
|
|
169
172
|
if (issuanceDate && issuanceDate !== nbfDateAsStr) {
|
|
170
|
-
|
|
173
|
+
const diff = Math.abs(new Date(nbfDateAsStr).getTime() - new Date(issuanceDate).getTime());
|
|
174
|
+
if (!maxSkewInMS || diff > maxSkewInMS) {
|
|
175
|
+
throw new Error(`Inconsistent issuance dates between JWT claim (${nbfDateAsStr}) and VC value (${issuanceDate})`);
|
|
176
|
+
}
|
|
171
177
|
}
|
|
172
178
|
credential.issuanceDate = nbfDateAsStr;
|
|
173
179
|
}
|
|
@@ -185,14 +191,21 @@ class CredentialMapper {
|
|
|
185
191
|
}
|
|
186
192
|
}
|
|
187
193
|
}
|
|
188
|
-
|
|
194
|
+
else {
|
|
195
|
+
credential.issuer = decoded.iss;
|
|
196
|
+
}
|
|
189
197
|
}
|
|
190
198
|
if (decoded.sub) {
|
|
191
|
-
const
|
|
192
|
-
|
|
193
|
-
|
|
199
|
+
const subjects = Array.isArray(credential.credentialSubject) ? credential.credentialSubject : [credential.credentialSubject];
|
|
200
|
+
for (let i = 0; i < subjects.length; i++) {
|
|
201
|
+
const csId = subjects[i].id;
|
|
202
|
+
if (csId && csId !== decoded.sub) {
|
|
203
|
+
throw new Error(`Inconsistent credential subject ids between JWT claim (${decoded.sub}) and VC value (${csId})`);
|
|
204
|
+
}
|
|
205
|
+
Array.isArray(credential.credentialSubject)
|
|
206
|
+
? (credential.credentialSubject[i].id = decoded.sub)
|
|
207
|
+
: (credential.credentialSubject.id = decoded.sub);
|
|
194
208
|
}
|
|
195
|
-
credential.credentialSubject.id = decoded.sub;
|
|
196
209
|
}
|
|
197
210
|
if (decoded.jti) {
|
|
198
211
|
const id = credential.id;
|
|
@@ -203,6 +216,25 @@ class CredentialMapper {
|
|
|
203
216
|
}
|
|
204
217
|
return credential;
|
|
205
218
|
}
|
|
219
|
+
static toExternalVerifiableCredential(verifiableCredential) {
|
|
220
|
+
if (!verifiableCredential.proof.type) {
|
|
221
|
+
throw new Error('Verifiable credential proof is missing a type');
|
|
222
|
+
}
|
|
223
|
+
if (!verifiableCredential.proof.created) {
|
|
224
|
+
throw new Error('Verifiable credential proof is missing a created date');
|
|
225
|
+
}
|
|
226
|
+
if (!verifiableCredential.proof.proofPurpose) {
|
|
227
|
+
throw new Error('Verifiable credential proof is missing a proof purpose');
|
|
228
|
+
}
|
|
229
|
+
if (!verifiableCredential.proof.verificationMethod) {
|
|
230
|
+
throw new Error('Verifiable credential proof is missing a verification method');
|
|
231
|
+
}
|
|
232
|
+
return Object.assign(Object.assign({}, verifiableCredential), { type: verifiableCredential.type
|
|
233
|
+
? typeof verifiableCredential.type === 'string'
|
|
234
|
+
? [verifiableCredential.type]
|
|
235
|
+
: verifiableCredential.type
|
|
236
|
+
: ['VerifiableCredential'], proof: Object.assign(Object.assign({}, verifiableCredential.proof), { type: verifiableCredential.proof.type, created: verifiableCredential.proof.created, proofPurpose: verifiableCredential.proof.proofPurpose, verificationMethod: verifiableCredential.proof.verificationMethod }) });
|
|
237
|
+
}
|
|
206
238
|
}
|
|
207
239
|
exports.CredentialMapper = CredentialMapper;
|
|
208
240
|
//# sourceMappingURL=credential-mapper.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"credential-mapper.js","sourceRoot":"","sources":["../../src/mapper/credential-mapper.ts"],"names":[],"mappings":";;;;;;AAAA,oCAaiB;AACjB,4DAAmC;AACnC,oCAAsC;
|
|
1
|
+
{"version":3,"file":"credential-mapper.js","sourceRoot":"","sources":["../../src/mapper/credential-mapper.ts"],"names":[],"mappings":";;;;;;AAAA,oCAaiB;AACjB,4DAAmC;AACnC,oCAAsC;AAGtC,MAAa,gBAAgB;IAC3B,MAAM,CAAC,4BAA4B,CAAC,YAA4C;QAC9E,IAAI,gBAAgB,CAAC,YAAY,CAAC,YAAY,CAAC,EAAE;YAC/C,OAAO,IAAA,oBAAU,EAAC,YAAsB,CAAqC,CAAA;SAC9E;aAAM,IAAI,gBAAgB,CAAC,wBAAwB,CAAC,YAAY,CAAC,EAAE;YAClE,OAAO,YAAgD,CAAA;SACxD;aAAM,IAAI,gBAAgB,CAAC,cAAc,CAAC,YAAY,CAAC,EAAE;YACxD,OAAO,IAAI,CAAC,KAAK,CAAC,YAAsB,CAA4B,C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AED,uCACK,oBAAoB,KACvB,IAAI,EAAE,oBAAoB,CAAC,IAAI;gBAC7B,CAAC,CAAC,OAAO,oBAAoB,CAAC,IAAI,KAAK,QAAQ;oBAC7C,CAAC,CAAC,CAAC,oBAAoB,CAAC,IAAI,CAAC;oBAC7B,CAAC,CAAC,oBAAoB,CAAC,IAAI;gBAC7B,CAAC,CAAC,CAAC,sBAAsB,CAAC,EAC5B,KAAK,kCACA,oBAAoB,CAAC,KAAK,KAC7B,IAAI,EAAE,oBAAoB,CAAC,KAAK,CAAC,IAAI,EACrC,OAAO,EAAE,oBAAoB,CAAC,KAAK,CAAC,OAAO,EAC3C,YAAY,EAAE,oBAAoB,CAAC,KAAK,CAAC,YAAY,EACrD,kBAAkB,EAAE,oBAAoB,CAAC,KAAK,CAAC,kBAAkB,OAEpE;IACH,CAAC;CACF;AAnSD,4CAmSC"}
|
package/dist/types/vc.d.ts
CHANGED
|
@@ -1,29 +1,30 @@
|
|
|
1
1
|
import { PresentationSubmission } from './pex';
|
|
2
2
|
import { IProofPurpose, IProofType } from './did';
|
|
3
|
-
export
|
|
3
|
+
export type AdditionalClaims = Record<string, any>;
|
|
4
|
+
export type IIssuerId = string;
|
|
4
5
|
export interface ICredential {
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
'@context': ICredentialContextType | ICredentialContextType[];
|
|
7
|
+
type: string[];
|
|
8
|
+
credentialSchema?: undefined | ICredentialSchemaType | ICredentialSchemaType[];
|
|
9
|
+
issuer: IIssuerId | IIssuer;
|
|
7
10
|
issuanceDate: string;
|
|
8
|
-
credentialSubject: ICredentialSubject & AdditionalClaims;
|
|
11
|
+
credentialSubject: (ICredentialSubject & AdditionalClaims) | (ICredentialSubject & AdditionalClaims)[];
|
|
12
|
+
expirationDate?: string;
|
|
9
13
|
id?: string;
|
|
10
|
-
'@context': ICredentialContextType[] | ICredentialContextType;
|
|
11
14
|
credentialStatus?: ICredentialStatus;
|
|
12
|
-
credentialSchema?: undefined | ICredentialSchemaType | ICredentialSchemaType[];
|
|
13
15
|
description?: string;
|
|
14
16
|
name?: string;
|
|
15
|
-
type: string[];
|
|
16
17
|
[x: string]: any;
|
|
17
18
|
}
|
|
18
19
|
export interface ICredentialSubject {
|
|
19
20
|
id?: string;
|
|
20
21
|
}
|
|
21
|
-
export
|
|
22
|
+
export type ICredentialContextType = (ICredentialContext & AdditionalClaims) | string;
|
|
22
23
|
export interface ICredentialContext {
|
|
23
24
|
name?: string;
|
|
24
25
|
did?: string;
|
|
25
26
|
}
|
|
26
|
-
export
|
|
27
|
+
export type ICredentialSchemaType = ICredentialSchema | string;
|
|
27
28
|
export interface ICredentialSchema {
|
|
28
29
|
id: string;
|
|
29
30
|
type?: string;
|
|
@@ -39,7 +40,7 @@ export interface IProof {
|
|
|
39
40
|
jws?: string;
|
|
40
41
|
nonce?: string;
|
|
41
42
|
requiredRevealStatements?: string[];
|
|
42
|
-
[x: string]:
|
|
43
|
+
[x: string]: any;
|
|
43
44
|
}
|
|
44
45
|
export interface ICredentialStatus {
|
|
45
46
|
id: string;
|
|
@@ -52,17 +53,17 @@ export interface IIssuer {
|
|
|
52
53
|
export interface IHasProof {
|
|
53
54
|
proof: IProof | IProof[];
|
|
54
55
|
}
|
|
55
|
-
export
|
|
56
|
+
export type IVerifiableCredential = ICredential & IHasProof;
|
|
56
57
|
/**
|
|
57
58
|
* Represents a Json Web Token in compact form.
|
|
58
59
|
*/
|
|
59
|
-
export
|
|
60
|
+
export type CompactJWT = string;
|
|
60
61
|
/**
|
|
61
62
|
* Represents a signed Verifiable Credential (includes proof), in either JSON or compact JWT format.
|
|
62
63
|
* See {@link https://www.w3.org/TR/vc-data-model/#credentials | VC data model}
|
|
63
64
|
* See {@link https://www.w3.org/TR/vc-data-model/#proof-formats | proof formats}
|
|
64
65
|
*/
|
|
65
|
-
export
|
|
66
|
+
export type W3CVerifiableCredential = IVerifiableCredential | CompactJWT;
|
|
66
67
|
export interface IPresentation {
|
|
67
68
|
id?: string;
|
|
68
69
|
'@context': ICredentialContextType | ICredentialContextType[];
|
|
@@ -72,13 +73,13 @@ export interface IPresentation {
|
|
|
72
73
|
holder?: string;
|
|
73
74
|
[x: string]: any;
|
|
74
75
|
}
|
|
75
|
-
export
|
|
76
|
+
export type IVerifiablePresentation = IPresentation & IHasProof;
|
|
76
77
|
/**
|
|
77
78
|
* Represents a signed Verifiable Presentation (includes proof), in either JSON or compact JWT format.
|
|
78
79
|
* See {@link https://www.w3.org/TR/vc-data-model/#presentations | VC data model}
|
|
79
80
|
* See {@link https://www.w3.org/TR/vc-data-model/#proof-formats | proof formats}
|
|
80
81
|
*/
|
|
81
|
-
export
|
|
82
|
+
export type W3CVerifiablePresentation = IVerifiablePresentation | CompactJWT;
|
|
82
83
|
export interface WrappedVerifiableCredential {
|
|
83
84
|
/**
|
|
84
85
|
* Original VC that we've received
|
|
@@ -95,7 +96,7 @@ export interface WrappedVerifiableCredential {
|
|
|
95
96
|
/**
|
|
96
97
|
* The claim format, typically used during exchange transport protocols
|
|
97
98
|
*/
|
|
98
|
-
format:
|
|
99
|
+
format: CredentialFormat;
|
|
99
100
|
/**
|
|
100
101
|
* Internal stable representation of a Credential without Proofs, created based on https://www.w3.org/TR/vc-data-model/#jwt-decoding
|
|
101
102
|
*/
|
|
@@ -117,7 +118,7 @@ export interface WrappedVerifiablePresentation {
|
|
|
117
118
|
/**
|
|
118
119
|
* The claim format, typically used during exchange transport protocols
|
|
119
120
|
*/
|
|
120
|
-
format:
|
|
121
|
+
format: PresentationFormat;
|
|
121
122
|
/**
|
|
122
123
|
* Internal stable representation of a Presentation without proofs, created based on https://www.w3.org/TR/vc-data-model/#jwt-decoding
|
|
123
124
|
*/
|
|
@@ -157,8 +158,10 @@ export interface JwtDecodedVerifiablePresentation {
|
|
|
157
158
|
jti: string;
|
|
158
159
|
[x: string]: any;
|
|
159
160
|
}
|
|
160
|
-
export
|
|
161
|
-
export
|
|
162
|
-
export
|
|
163
|
-
export
|
|
161
|
+
export type CredentialFormat = 'jwt' | 'ldp' | 'jwt_vc' | 'ldp_vc' | string;
|
|
162
|
+
export type PresentationFormat = 'jwt' | 'ldp' | 'jwt_vp' | 'ldp_vp' | string;
|
|
163
|
+
export type ClaimFormat = CredentialFormat | PresentationFormat;
|
|
164
|
+
export type OriginalVerifiableCredential = W3CVerifiableCredential | JwtDecodedVerifiableCredential;
|
|
165
|
+
export type OriginalVerifiablePresentation = W3CVerifiablePresentation | JwtDecodedVerifiablePresentation;
|
|
166
|
+
export type Original = OriginalVerifiablePresentation | OriginalVerifiableCredential;
|
|
164
167
|
//# sourceMappingURL=vc.d.ts.map
|
package/dist/types/vc.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vc.d.ts","sourceRoot":"","sources":["../../src/types/vc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,OAAO,CAAA;AAC9C,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,OAAO,CAAA;AAEjD,
|
|
1
|
+
{"version":3,"file":"vc.d.ts","sourceRoot":"","sources":["../../src/types/vc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,OAAO,CAAA;AAC9C,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,OAAO,CAAA;AAEjD,MAAM,MAAM,gBAAgB,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;AAElD,MAAM,MAAM,SAAS,GAAG,MAAM,CAAA;AAE9B,MAAM,WAAW,WAAW;IAC1B,UAAU,EAAE,sBAAsB,GAAG,sBAAsB,EAAE,CAAA;IAC7D,IAAI,EAAE,MAAM,EAAE,CAAA;IACd,gBAAgB,CAAC,EAAE,SAAS,GAAG,qBAAqB,GAAG,qBAAqB,EAAE,CAAA;IAE9E,MAAM,EAAE,SAAS,GAAG,OAAO,CAAA;IAE3B,YAAY,EAAE,MAAM,CAAA;IAEpB,iBAAiB,EAAE,CAAC,kBAAkB,GA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AA;AAC7E,MAAM,MAAM,WAAW,GAAG,gBAAgB,GAAG,kBAAkB,CAAA;AAE/D,MAAM,MAAM,4BAA4B,GAAG,uBAAuB,GAAG,8BAA8B,CAAA;AACnG,MAAM,MAAM,8BAA8B,GAAG,yBAAyB,GAAG,gCAAgC,CAAA;AACzG,MAAM,MAAM,QAAQ,GAAG,8BAA8B,GAAG,4BAA4B,CAAA"}
|
package/dist/types/vc.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vc.js","sourceRoot":"","sources":["../../src/types/vc.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"vc.js","sourceRoot":"","sources":["../../src/types/vc.ts"],"names":[],"mappings":";;;AAgKA,IAAY,YAIX;AAJD,WAAY,YAAY;IACtB,kCAAkB,CAAA;IAClB,2CAA2B,CAAA;IAC3B,2CAA2B,CAAA;AAC7B,CAAC,EAJW,YAAY,GAAZ,oBAAY,KAAZ,oBAAY,QAIvB"}
|
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.8.1-next.
|
|
4
|
+
"version": "0.8.1-next.192+7033a2e",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
},
|
|
13
13
|
"devDependencies": {
|
|
14
14
|
"@types/jest": "^27.0.2",
|
|
15
|
+
"@veramo/core": "4.2.0",
|
|
15
16
|
"jest": "^27.3.1",
|
|
16
17
|
"prettier": "^2.4.1",
|
|
17
18
|
"ts-jest": "^27.0.7",
|
|
@@ -37,5 +38,5 @@
|
|
|
37
38
|
"Verifiable Credentials",
|
|
38
39
|
"DIDs"
|
|
39
40
|
],
|
|
40
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "7033a2e5a80935335e5ad7989f1c03850270a986"
|
|
41
42
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import {
|
|
2
|
-
ClaimFormat,
|
|
3
2
|
ICredential,
|
|
4
3
|
IPresentation,
|
|
5
4
|
IVerifiableCredential,
|
|
@@ -9,12 +8,14 @@ import {
|
|
|
9
8
|
OriginalType,
|
|
10
9
|
OriginalVerifiableCredential,
|
|
11
10
|
OriginalVerifiablePresentation,
|
|
11
|
+
PresentationFormat,
|
|
12
12
|
WrappedVerifiableCredential,
|
|
13
13
|
WrappedVerifiablePresentation,
|
|
14
14
|
} from '../types'
|
|
15
15
|
import jwt_decode from 'jwt-decode'
|
|
16
16
|
import { ObjectUtils } from '../utils'
|
|
17
17
|
|
|
18
|
+
|
|
18
19
|
export class CredentialMapper {
|
|
19
20
|
static decodeVerifiablePresentation(presentation: OriginalVerifiablePresentation): JwtDecodedVerifiablePresentation | IVerifiablePresentation {
|
|
20
21
|
if (CredentialMapper.isJwtEncoded(presentation)) {
|
|
@@ -40,19 +41,22 @@ export class CredentialMapper {
|
|
|
40
41
|
}
|
|
41
42
|
}
|
|
42
43
|
|
|
43
|
-
static toWrappedVerifiablePresentation(
|
|
44
|
+
static toWrappedVerifiablePresentation(
|
|
45
|
+
presentation: OriginalVerifiablePresentation,
|
|
46
|
+
opts?: { maxTimeSkewInMS?: number }
|
|
47
|
+
): WrappedVerifiablePresentation {
|
|
44
48
|
const original = presentation
|
|
45
49
|
const isJwtEncoded: boolean = CredentialMapper.isJwtEncoded(original)
|
|
46
50
|
const isJwtDecoded: boolean = CredentialMapper.isJwtDecodedPresentation(original)
|
|
47
51
|
|
|
48
52
|
const type = isJwtEncoded ? OriginalType.JWT_ENCODED : isJwtDecoded ? OriginalType.JWT_DECODED : OriginalType.JSONLD
|
|
49
|
-
const format:
|
|
53
|
+
const format: PresentationFormat = isJwtDecoded || isJwtEncoded ? 'jwt_vp' : 'ldp_vp'
|
|
50
54
|
const decoded = CredentialMapper.decodeVerifiablePresentation(original)
|
|
51
55
|
const vp: IPresentation =
|
|
52
56
|
isJwtEncoded || isJwtDecoded
|
|
53
|
-
? CredentialMapper.jwtDecodedPresentationToUniformPresentation(decoded as JwtDecodedVerifiablePresentation, false)
|
|
57
|
+
? CredentialMapper.jwtDecodedPresentationToUniformPresentation(decoded as JwtDecodedVerifiablePresentation, false, opts)
|
|
54
58
|
: (decoded as IPresentation)
|
|
55
|
-
const vcs: WrappedVerifiableCredential[] = CredentialMapper.toWrappedVerifiableCredentials(vp.verifiableCredential)
|
|
59
|
+
const vcs: WrappedVerifiableCredential[] = CredentialMapper.toWrappedVerifiableCredentials(vp.verifiableCredential, opts)
|
|
56
60
|
|
|
57
61
|
// todo: We probably want to add proofs as well
|
|
58
62
|
return {
|
|
@@ -68,11 +72,17 @@ export class CredentialMapper {
|
|
|
68
72
|
}
|
|
69
73
|
}
|
|
70
74
|
|
|
71
|
-
static toWrappedVerifiableCredentials(
|
|
72
|
-
|
|
75
|
+
static toWrappedVerifiableCredentials(
|
|
76
|
+
verifiableCredentials: OriginalVerifiableCredential[],
|
|
77
|
+
opts?: { maxTimeSkewInMS?: number }
|
|
78
|
+
): WrappedVerifiableCredential[] {
|
|
79
|
+
return verifiableCredentials.map((vc) => CredentialMapper.toWrappedVerifiableCredential(vc, opts))
|
|
73
80
|
}
|
|
74
81
|
|
|
75
|
-
static toWrappedVerifiableCredential(
|
|
82
|
+
static toWrappedVerifiableCredential(
|
|
83
|
+
verifiableCredential: OriginalVerifiableCredential,
|
|
84
|
+
opts?: { maxTimeSkewInMS?: number }
|
|
85
|
+
): WrappedVerifiableCredential {
|
|
76
86
|
const original = verifiableCredential
|
|
77
87
|
|
|
78
88
|
const decoded = CredentialMapper.decodeVerifiableCredential(verifiableCredential)
|
|
@@ -83,7 +93,7 @@ export class CredentialMapper {
|
|
|
83
93
|
|
|
84
94
|
const credential =
|
|
85
95
|
isJwtDecoded || isJwtDecoded
|
|
86
|
-
? CredentialMapper.jwtDecodedCredentialToUniformCredential(decoded as JwtDecodedVerifiableCredential)
|
|
96
|
+
? CredentialMapper.jwtDecodedCredentialToUniformCredential(decoded as JwtDecodedVerifiableCredential, opts)
|
|
87
97
|
: (decoded as ICredential)
|
|
88
98
|
const format = isJwtDecoded || isJwtDecoded ? 'jwt_vc' : 'ldp_vc'
|
|
89
99
|
//todo: We probably want to add proofs as well
|
|
@@ -112,19 +122,26 @@ export class CredentialMapper {
|
|
|
112
122
|
return (<JwtDecodedVerifiablePresentation>original)['vp'] !== undefined && (<JwtDecodedVerifiablePresentation>original)['iss'] !== undefined
|
|
113
123
|
}
|
|
114
124
|
|
|
115
|
-
static jwtEncodedPresentationToUniformPresentation(
|
|
116
|
-
|
|
125
|
+
static jwtEncodedPresentationToUniformPresentation(
|
|
126
|
+
jwt: string,
|
|
127
|
+
makeCredentialsUniform: boolean = true,
|
|
128
|
+
opts?: { maxTimeSkewInMS?: number }
|
|
129
|
+
): IPresentation {
|
|
130
|
+
return CredentialMapper.jwtDecodedPresentationToUniformPresentation(jwt_decode(jwt), makeCredentialsUniform, opts)
|
|
117
131
|
}
|
|
118
132
|
|
|
119
133
|
static jwtDecodedPresentationToUniformPresentation(
|
|
120
134
|
decoded: JwtDecodedVerifiablePresentation,
|
|
121
|
-
makeCredentialsUniform: boolean = true
|
|
135
|
+
makeCredentialsUniform: boolean = true,
|
|
136
|
+
opts?: { maxTimeSkewInMS?: number }
|
|
122
137
|
): IPresentation {
|
|
123
138
|
const presentation: IPresentation = {
|
|
124
139
|
...(decoded.vp as IPresentation),
|
|
125
140
|
}
|
|
126
141
|
if (makeCredentialsUniform) {
|
|
127
|
-
presentation.verifiableCredential = decoded.vp.verifiableCredential.map(
|
|
142
|
+
presentation.verifiableCredential = decoded.vp.verifiableCredential.map((vc) =>
|
|
143
|
+
CredentialMapper.toUniformCredential(vc, opts)
|
|
144
|
+
) as IVerifiableCredential[] // We cast it because we IPresentation needs a VC. The internal Credential doesn't have the required Proof anymore (that is intended)
|
|
128
145
|
}
|
|
129
146
|
// Since this is a presentation, we delete any proof just to be sure (should not occur on JWT, but better safe than sorry)
|
|
130
147
|
delete presentation.proof
|
|
@@ -148,7 +165,7 @@ export class CredentialMapper {
|
|
|
148
165
|
return presentation
|
|
149
166
|
}
|
|
150
167
|
|
|
151
|
-
static toUniformCredential(verifiableCredential: OriginalVerifiableCredential): ICredential {
|
|
168
|
+
static toUniformCredential(verifiableCredential: OriginalVerifiableCredential, opts?: { maxTimeSkewInMS?: number }): ICredential {
|
|
152
169
|
const original = verifiableCredential
|
|
153
170
|
const decoded = CredentialMapper.decodeVerifiableCredential(verifiableCredential)
|
|
154
171
|
|
|
@@ -156,13 +173,13 @@ export class CredentialMapper {
|
|
|
156
173
|
const isJwtDecoded: boolean = CredentialMapper.isJwtDecodedCredential(original)
|
|
157
174
|
|
|
158
175
|
if (isJwtDecoded || isJwtEncoded) {
|
|
159
|
-
return CredentialMapper.jwtDecodedCredentialToUniformCredential(decoded as JwtDecodedVerifiableCredential)
|
|
176
|
+
return CredentialMapper.jwtDecodedCredentialToUniformCredential(decoded as JwtDecodedVerifiableCredential, opts)
|
|
160
177
|
} else {
|
|
161
178
|
return decoded as ICredential
|
|
162
179
|
}
|
|
163
180
|
}
|
|
164
181
|
|
|
165
|
-
static toUniformPresentation(presentation: OriginalVerifiablePresentation): IPresentation {
|
|
182
|
+
static toUniformPresentation(presentation: OriginalVerifiablePresentation, opts?: { maxTimeSkewInMS?: number }): IPresentation {
|
|
166
183
|
const original = presentation
|
|
167
184
|
const decoded = CredentialMapper.decodeVerifiablePresentation(original)
|
|
168
185
|
const isJwtEncoded: boolean = CredentialMapper.isJwtEncoded(original)
|
|
@@ -171,32 +188,37 @@ export class CredentialMapper {
|
|
|
171
188
|
isJwtEncoded || isJwtDecoded
|
|
172
189
|
? CredentialMapper.jwtDecodedPresentationToUniformPresentation(decoded as JwtDecodedVerifiablePresentation, false)
|
|
173
190
|
: (decoded as IPresentation)
|
|
174
|
-
uniformPresentation.verifiableCredential = uniformPresentation.verifiableCredential?.map(
|
|
175
|
-
CredentialMapper.toUniformCredential
|
|
191
|
+
uniformPresentation.verifiableCredential = uniformPresentation.verifiableCredential?.map((vc) =>
|
|
192
|
+
CredentialMapper.toUniformCredential(vc, opts)
|
|
176
193
|
) as IVerifiableCredential[] // We cast it because we IPresentation needs a VC. The internal Credential doesn't have the required Proof anymore (that is intended)
|
|
177
194
|
return uniformPresentation
|
|
178
195
|
}
|
|
179
196
|
|
|
180
|
-
static jwtEncodedCredentialToUniformCredential(jwt: string): ICredential {
|
|
181
|
-
return CredentialMapper.jwtDecodedCredentialToUniformCredential(jwt_decode(jwt))
|
|
197
|
+
static jwtEncodedCredentialToUniformCredential(jwt: string, opts?: { maxTimeSkewInMS?: number }): ICredential {
|
|
198
|
+
return CredentialMapper.jwtDecodedCredentialToUniformCredential(jwt_decode(jwt), opts)
|
|
182
199
|
}
|
|
183
200
|
|
|
184
|
-
static jwtDecodedCredentialToUniformCredential(decoded: JwtDecodedVerifiableCredential): ICredential {
|
|
201
|
+
static jwtDecodedCredentialToUniformCredential(decoded: JwtDecodedVerifiableCredential, opts?: { maxTimeSkewInMS?: number }): ICredential {
|
|
185
202
|
const credential: ICredential = {
|
|
186
203
|
...(decoded.vc as ICredential),
|
|
187
204
|
}
|
|
188
205
|
// Since this is a credential, we delete any proof just to be sure (should not occur on JWT, but better safe than sorry)
|
|
189
206
|
delete credential.proof
|
|
190
207
|
|
|
208
|
+
const maxSkewInMS = opts?.maxTimeSkewInMS !== undefined ? opts.maxTimeSkewInMS : 999
|
|
209
|
+
|
|
191
210
|
if (decoded.exp) {
|
|
192
|
-
const expDate = credential.
|
|
211
|
+
const expDate = credential.expirationDate
|
|
193
212
|
const jwtExp = parseInt(decoded.exp.toString())
|
|
194
213
|
// fix seconds to millisecs for the date
|
|
195
214
|
const expDateAsStr = jwtExp < 9999999999 ? new Date(jwtExp * 1000).toISOString().replace(/\.000Z/, 'Z') : new Date(jwtExp).toISOString()
|
|
196
215
|
if (expDate && expDate !== expDateAsStr) {
|
|
197
|
-
|
|
216
|
+
const diff = Math.abs(new Date(expDateAsStr).getTime() - new Date(expDate).getTime())
|
|
217
|
+
if (!maxSkewInMS || diff > maxSkewInMS) {
|
|
218
|
+
throw new Error(`Inconsistent expiration dates between JWT claim (${expDateAsStr}) and VC value (${expDate})`)
|
|
219
|
+
}
|
|
198
220
|
}
|
|
199
|
-
credential.
|
|
221
|
+
credential.expirationDate = expDateAsStr
|
|
200
222
|
}
|
|
201
223
|
|
|
202
224
|
if (decoded.nbf) {
|
|
@@ -205,7 +227,10 @@ export class CredentialMapper {
|
|
|
205
227
|
// fix seconds to millisecs for the date
|
|
206
228
|
const nbfDateAsStr = jwtNbf < 9999999999 ? new Date(jwtNbf * 1000).toISOString().replace(/\.000Z/, 'Z') : new Date(jwtNbf).toISOString()
|
|
207
229
|
if (issuanceDate && issuanceDate !== nbfDateAsStr) {
|
|
208
|
-
|
|
230
|
+
const diff = Math.abs(new Date(nbfDateAsStr).getTime() - new Date(issuanceDate).getTime())
|
|
231
|
+
if (!maxSkewInMS || diff > maxSkewInMS) {
|
|
232
|
+
throw new Error(`Inconsistent issuance dates between JWT claim (${nbfDateAsStr}) and VC value (${issuanceDate})`)
|
|
233
|
+
}
|
|
209
234
|
}
|
|
210
235
|
credential.issuanceDate = nbfDateAsStr
|
|
211
236
|
}
|
|
@@ -222,16 +247,22 @@ export class CredentialMapper {
|
|
|
222
247
|
throw new Error(`Inconsistent issuers between JWT claim (${decoded.iss}) and VC value (${issuer.id})`)
|
|
223
248
|
}
|
|
224
249
|
}
|
|
250
|
+
} else {
|
|
251
|
+
credential.issuer = decoded.iss
|
|
225
252
|
}
|
|
226
|
-
credential.issuer = decoded.iss
|
|
227
253
|
}
|
|
228
254
|
|
|
229
255
|
if (decoded.sub) {
|
|
230
|
-
const
|
|
231
|
-
|
|
232
|
-
|
|
256
|
+
const subjects = Array.isArray(credential.credentialSubject) ? credential.credentialSubject : [credential.credentialSubject]
|
|
257
|
+
for (let i = 0; i < subjects.length; i++) {
|
|
258
|
+
const csId = subjects[i].id
|
|
259
|
+
if (csId && csId !== decoded.sub) {
|
|
260
|
+
throw new Error(`Inconsistent credential subject ids between JWT claim (${decoded.sub}) and VC value (${csId})`)
|
|
261
|
+
}
|
|
262
|
+
Array.isArray(credential.credentialSubject)
|
|
263
|
+
? (credential.credentialSubject[i].id = decoded.sub)
|
|
264
|
+
: (credential.credentialSubject.id = decoded.sub)
|
|
233
265
|
}
|
|
234
|
-
credential.credentialSubject.id = decoded.sub
|
|
235
266
|
}
|
|
236
267
|
if (decoded.jti) {
|
|
237
268
|
const id = credential.id
|
|
@@ -242,4 +273,38 @@ export class CredentialMapper {
|
|
|
242
273
|
}
|
|
243
274
|
return credential
|
|
244
275
|
}
|
|
276
|
+
|
|
277
|
+
static toExternalVerifiableCredential(verifiableCredential: any): IVerifiableCredential {
|
|
278
|
+
if (!verifiableCredential.proof.type) {
|
|
279
|
+
throw new Error('Verifiable credential proof is missing a type')
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
if (!verifiableCredential.proof.created) {
|
|
283
|
+
throw new Error('Verifiable credential proof is missing a created date')
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
if (!verifiableCredential.proof.proofPurpose) {
|
|
287
|
+
throw new Error('Verifiable credential proof is missing a proof purpose')
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
if (!verifiableCredential.proof.verificationMethod) {
|
|
291
|
+
throw new Error('Verifiable credential proof is missing a verification method')
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
return {
|
|
295
|
+
...verifiableCredential,
|
|
296
|
+
type: verifiableCredential.type
|
|
297
|
+
? typeof verifiableCredential.type === 'string'
|
|
298
|
+
? [verifiableCredential.type]
|
|
299
|
+
: verifiableCredential.type
|
|
300
|
+
: ['VerifiableCredential'],
|
|
301
|
+
proof: {
|
|
302
|
+
...verifiableCredential.proof,
|
|
303
|
+
type: verifiableCredential.proof.type,
|
|
304
|
+
created: verifiableCredential.proof.created,
|
|
305
|
+
proofPurpose: verifiableCredential.proof.proofPurpose,
|
|
306
|
+
verificationMethod: verifiableCredential.proof.verificationMethod,
|
|
307
|
+
},
|
|
308
|
+
}
|
|
309
|
+
}
|
|
245
310
|
}
|
package/src/types/vc.ts
CHANGED
|
@@ -3,23 +3,25 @@ import { IProofPurpose, IProofType } from './did'
|
|
|
3
3
|
|
|
4
4
|
export type AdditionalClaims = Record<string, any>
|
|
5
5
|
|
|
6
|
+
export type IIssuerId = string
|
|
7
|
+
|
|
6
8
|
export interface ICredential {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
+
'@context': ICredentialContextType | ICredentialContextType[]
|
|
10
|
+
type: string[]
|
|
11
|
+
credentialSchema?: undefined | ICredentialSchemaType | ICredentialSchemaType[]
|
|
9
12
|
// If iss is present, the value MUST be used to set the issuer property of the new credential JSON object or the holder property of the new presentation JSON object.
|
|
10
|
-
issuer:
|
|
13
|
+
issuer: IIssuerId | IIssuer
|
|
11
14
|
// 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.
|
|
12
15
|
issuanceDate: string
|
|
13
16
|
// 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.
|
|
14
|
-
credentialSubject: ICredentialSubject & AdditionalClaims
|
|
17
|
+
credentialSubject: (ICredentialSubject & AdditionalClaims) | (ICredentialSubject & AdditionalClaims)[]
|
|
18
|
+
// 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.
|
|
19
|
+
expirationDate?: string
|
|
15
20
|
// If jti is present, the value MUST be used to set the value of the id property of the new JSON object.
|
|
16
21
|
id?: string
|
|
17
|
-
'@context': ICredentialContextType[] | ICredentialContextType
|
|
18
22
|
credentialStatus?: ICredentialStatus
|
|
19
|
-
credentialSchema?: undefined | ICredentialSchemaType | ICredentialSchemaType[]
|
|
20
23
|
description?: string
|
|
21
24
|
name?: string
|
|
22
|
-
type: string[]
|
|
23
25
|
|
|
24
26
|
[x: string]: any
|
|
25
27
|
}
|
|
@@ -53,7 +55,8 @@ export interface IProof {
|
|
|
53
55
|
jws?: string // JWS based proof
|
|
54
56
|
nonce?: string // Similar to challenge. A nonce to protect against replay attacks, used in some ZKP proofs
|
|
55
57
|
requiredRevealStatements?: string[] // The parts of the proof that must be revealed in a derived proof
|
|
56
|
-
|
|
58
|
+
|
|
59
|
+
[x: string]: any // Any because we want to be able to access value1.value2.value3, which unknown does not allow for without a cast
|
|
57
60
|
}
|
|
58
61
|
|
|
59
62
|
export interface ICredentialStatus {
|
|
@@ -121,7 +124,7 @@ export interface WrappedVerifiableCredential {
|
|
|
121
124
|
/**
|
|
122
125
|
* The claim format, typically used during exchange transport protocols
|
|
123
126
|
*/
|
|
124
|
-
format:
|
|
127
|
+
format: CredentialFormat
|
|
125
128
|
/**
|
|
126
129
|
* Internal stable representation of a Credential without Proofs, created based on https://www.w3.org/TR/vc-data-model/#jwt-decoding
|
|
127
130
|
*/
|
|
@@ -144,7 +147,7 @@ export interface WrappedVerifiablePresentation {
|
|
|
144
147
|
/**
|
|
145
148
|
* The claim format, typically used during exchange transport protocols
|
|
146
149
|
*/
|
|
147
|
-
format:
|
|
150
|
+
format: PresentationFormat
|
|
148
151
|
/**
|
|
149
152
|
* Internal stable representation of a Presentation without proofs, created based on https://www.w3.org/TR/vc-data-model/#jwt-decoding
|
|
150
153
|
*/
|
|
@@ -191,7 +194,9 @@ export interface JwtDecodedVerifiablePresentation {
|
|
|
191
194
|
[x: string]: any
|
|
192
195
|
}
|
|
193
196
|
|
|
194
|
-
export type
|
|
197
|
+
export type CredentialFormat = 'jwt' | 'ldp' | 'jwt_vc' | 'ldp_vc' | string
|
|
198
|
+
export type PresentationFormat = 'jwt' | 'ldp' | 'jwt_vp' | 'ldp_vp' | string
|
|
199
|
+
export type ClaimFormat = CredentialFormat | PresentationFormat
|
|
195
200
|
|
|
196
201
|
export type OriginalVerifiableCredential = W3CVerifiableCredential | JwtDecodedVerifiableCredential
|
|
197
202
|
export type OriginalVerifiablePresentation = W3CVerifiablePresentation | JwtDecodedVerifiablePresentation
|