@sphereon/ssi-types 0.8.1-next.66 → 0.8.1-next.77
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.
|
@@ -2,18 +2,36 @@ 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;
|
|
18
36
|
}
|
|
19
37
|
//# 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,EACL,WAAW,EACX,aAAa,EACb,qBAAqB,EACrB,uBAAuB,EACvB,8BAA8B,EAC9B,gCAAgC,EAEhC,4BAA4B,EAC5B,8BAA8B,EAE9B,2BAA2B,EAC3B,6BAA6B,EAC9B,MAAM,UAAU,CAAA;AAIjB,qBAAa,gBAAgB;IAC3B,MAAM,CAAC,4BAA4B,CAAC,YAAY,EAAE,8BAA8B,GAAG,gCAAgC,GAAG,uBAAuB;IAY7I,MAAM,CAAC,0BAA0B,CAAC,UAAU,EAAE,4BAA4B,GAAG,8BAA8B,GAAG,qBAAqB;IAYnI,MAAM,CAAC,+BAA+B,
|
|
1
|
+
{"version":3,"file":"credential-mapper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A2C,CAChD,OAAO,EAAE,gCAAgC,EACzC,sBAAsB,GAAE,OAAc,EACtC,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;CA2E1I"}
|
|
@@ -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,23 +140,27 @@ 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) {
|
|
149
|
+
static jwtDecodedCredentialToUniformCredential(decoded, opts) {
|
|
150
150
|
const credential = Object.assign({}, decoded.vc);
|
|
151
151
|
// Since this is a credential, we delete any proof just to be sure (should not occur on JWT, but better safe than sorry)
|
|
152
152
|
delete credential.proof;
|
|
153
|
+
const maxSkewInMS = (opts === null || opts === void 0 ? void 0 : opts.maxTimeSkewInMS) !== undefined ? opts.maxTimeSkewInMS : 999;
|
|
153
154
|
if (decoded.exp) {
|
|
154
155
|
const expDate = credential.expirationDate;
|
|
155
156
|
const jwtExp = parseInt(decoded.exp.toString());
|
|
156
157
|
// fix seconds to millisecs for the date
|
|
157
158
|
const expDateAsStr = jwtExp < 9999999999 ? new Date(jwtExp * 1000).toISOString().replace(/\.000Z/, 'Z') : new Date(jwtExp).toISOString();
|
|
158
159
|
if (expDate && expDate !== expDateAsStr) {
|
|
159
|
-
|
|
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
|
+
}
|
|
160
164
|
}
|
|
161
165
|
credential.expirationDate = expDateAsStr;
|
|
162
166
|
}
|
|
@@ -166,7 +170,10 @@ class CredentialMapper {
|
|
|
166
170
|
// fix seconds to millisecs for the date
|
|
167
171
|
const nbfDateAsStr = jwtNbf < 9999999999 ? new Date(jwtNbf * 1000).toISOString().replace(/\.000Z/, 'Z') : new Date(jwtNbf).toISOString();
|
|
168
172
|
if (issuanceDate && issuanceDate !== nbfDateAsStr) {
|
|
169
|
-
|
|
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
|
+
}
|
|
170
177
|
}
|
|
171
178
|
credential.issuanceDate = nbfDateAsStr;
|
|
172
179
|
}
|
|
@@ -184,7 +191,9 @@ class CredentialMapper {
|
|
|
184
191
|
}
|
|
185
192
|
}
|
|
186
193
|
}
|
|
187
|
-
|
|
194
|
+
else {
|
|
195
|
+
credential.issuer = decoded.iss;
|
|
196
|
+
}
|
|
188
197
|
}
|
|
189
198
|
if (decoded.sub) {
|
|
190
199
|
const subjects = Array.isArray(credential.credentialSubject) ? credential.credentialSubject : [credential.credentialSubject];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"credential-mapper.js","sourceRoot":"","sources":["../../src/mapper/credential-mapper.ts"],"names":[],"mappings":";;;;;;AAAA,oCAaiB;AACjB,4DAAmC;AACnC,oCAAsC;AAEtC,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,CAAA;SACrE;aAAM;YACL,OAAO,YAAuC,CAAA;SAC/C;IACH,CAAC;IAED,MAAM,CAAC,0BAA0B,CAAC,UAAwC;QACxE,IAAI,gBAAgB,CAAC,YAAY,CAAC,UAAU,CAAC,EAAE;YAC7C,OAAO,IAAA,oBAAU,EAAC,UAAoB,CAAmC,CAAA;SAC1E;aAAM,IAAI,gBAAgB,CAAC,sBAAsB,CAAC,UAAU,CAAC,EAAE;YAC9D,OAAO,UAA4C,CAAA;SACpD;aAAM,IAAI,gBAAgB,CAAC,cAAc,CAAC,UAAU,CAAC,EAAE;YACtD,OAAO,IAAI,CA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G,mBAAmB,EAAE,GAAG,CAAC,CAAA;aACvG;YACD,UAAU,CAAC,EAAE,GAAG,OAAO,CAAC,GAAG,CAAA;SAC5B;QACD,OAAO,UAAU,CAAA;IACnB,CAAC;CACF;AAjQD,4CAiQC"}
|
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.77+473b111",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
@@ -37,5 +37,5 @@
|
|
|
37
37
|
"Verifiable Credentials",
|
|
38
38
|
"DIDs"
|
|
39
39
|
],
|
|
40
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "473b111b98030a1f795ff1e521ce17caf202b4b8"
|
|
41
41
|
}
|
|
@@ -40,7 +40,10 @@ export class CredentialMapper {
|
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
static toWrappedVerifiablePresentation(
|
|
43
|
+
static toWrappedVerifiablePresentation(
|
|
44
|
+
presentation: OriginalVerifiablePresentation,
|
|
45
|
+
opts?: { maxTimeSkewInMS?: number }
|
|
46
|
+
): WrappedVerifiablePresentation {
|
|
44
47
|
const original = presentation
|
|
45
48
|
const isJwtEncoded: boolean = CredentialMapper.isJwtEncoded(original)
|
|
46
49
|
const isJwtDecoded: boolean = CredentialMapper.isJwtDecodedPresentation(original)
|
|
@@ -50,9 +53,9 @@ export class CredentialMapper {
|
|
|
50
53
|
const decoded = CredentialMapper.decodeVerifiablePresentation(original)
|
|
51
54
|
const vp: IPresentation =
|
|
52
55
|
isJwtEncoded || isJwtDecoded
|
|
53
|
-
? CredentialMapper.jwtDecodedPresentationToUniformPresentation(decoded as JwtDecodedVerifiablePresentation, false)
|
|
56
|
+
? CredentialMapper.jwtDecodedPresentationToUniformPresentation(decoded as JwtDecodedVerifiablePresentation, false, opts)
|
|
54
57
|
: (decoded as IPresentation)
|
|
55
|
-
const vcs: WrappedVerifiableCredential[] = CredentialMapper.toWrappedVerifiableCredentials(vp.verifiableCredential)
|
|
58
|
+
const vcs: WrappedVerifiableCredential[] = CredentialMapper.toWrappedVerifiableCredentials(vp.verifiableCredential, opts)
|
|
56
59
|
|
|
57
60
|
// todo: We probably want to add proofs as well
|
|
58
61
|
return {
|
|
@@ -68,11 +71,17 @@ export class CredentialMapper {
|
|
|
68
71
|
}
|
|
69
72
|
}
|
|
70
73
|
|
|
71
|
-
static toWrappedVerifiableCredentials(
|
|
72
|
-
|
|
74
|
+
static toWrappedVerifiableCredentials(
|
|
75
|
+
verifiableCredentials: OriginalVerifiableCredential[],
|
|
76
|
+
opts?: { maxTimeSkewInMS?: number }
|
|
77
|
+
): WrappedVerifiableCredential[] {
|
|
78
|
+
return verifiableCredentials.map((vc) => CredentialMapper.toWrappedVerifiableCredential(vc, opts))
|
|
73
79
|
}
|
|
74
80
|
|
|
75
|
-
static toWrappedVerifiableCredential(
|
|
81
|
+
static toWrappedVerifiableCredential(
|
|
82
|
+
verifiableCredential: OriginalVerifiableCredential,
|
|
83
|
+
opts?: { maxTimeSkewInMS?: number }
|
|
84
|
+
): WrappedVerifiableCredential {
|
|
76
85
|
const original = verifiableCredential
|
|
77
86
|
|
|
78
87
|
const decoded = CredentialMapper.decodeVerifiableCredential(verifiableCredential)
|
|
@@ -83,7 +92,7 @@ export class CredentialMapper {
|
|
|
83
92
|
|
|
84
93
|
const credential =
|
|
85
94
|
isJwtDecoded || isJwtDecoded
|
|
86
|
-
? CredentialMapper.jwtDecodedCredentialToUniformCredential(decoded as JwtDecodedVerifiableCredential)
|
|
95
|
+
? CredentialMapper.jwtDecodedCredentialToUniformCredential(decoded as JwtDecodedVerifiableCredential, opts)
|
|
87
96
|
: (decoded as ICredential)
|
|
88
97
|
const format = isJwtDecoded || isJwtDecoded ? 'jwt_vc' : 'ldp_vc'
|
|
89
98
|
//todo: We probably want to add proofs as well
|
|
@@ -112,19 +121,26 @@ export class CredentialMapper {
|
|
|
112
121
|
return (<JwtDecodedVerifiablePresentation>original)['vp'] !== undefined && (<JwtDecodedVerifiablePresentation>original)['iss'] !== undefined
|
|
113
122
|
}
|
|
114
123
|
|
|
115
|
-
static jwtEncodedPresentationToUniformPresentation(
|
|
116
|
-
|
|
124
|
+
static jwtEncodedPresentationToUniformPresentation(
|
|
125
|
+
jwt: string,
|
|
126
|
+
makeCredentialsUniform: boolean = true,
|
|
127
|
+
opts?: { maxTimeSkewInMS?: number }
|
|
128
|
+
): IPresentation {
|
|
129
|
+
return CredentialMapper.jwtDecodedPresentationToUniformPresentation(jwt_decode(jwt), makeCredentialsUniform, opts)
|
|
117
130
|
}
|
|
118
131
|
|
|
119
132
|
static jwtDecodedPresentationToUniformPresentation(
|
|
120
133
|
decoded: JwtDecodedVerifiablePresentation,
|
|
121
|
-
makeCredentialsUniform: boolean = true
|
|
134
|
+
makeCredentialsUniform: boolean = true,
|
|
135
|
+
opts?: { maxTimeSkewInMS?: number }
|
|
122
136
|
): IPresentation {
|
|
123
137
|
const presentation: IPresentation = {
|
|
124
138
|
...(decoded.vp as IPresentation),
|
|
125
139
|
}
|
|
126
140
|
if (makeCredentialsUniform) {
|
|
127
|
-
presentation.verifiableCredential = decoded.vp.verifiableCredential.map(
|
|
141
|
+
presentation.verifiableCredential = decoded.vp.verifiableCredential.map((vc) =>
|
|
142
|
+
CredentialMapper.toUniformCredential(vc, opts)
|
|
143
|
+
) 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
144
|
}
|
|
129
145
|
// Since this is a presentation, we delete any proof just to be sure (should not occur on JWT, but better safe than sorry)
|
|
130
146
|
delete presentation.proof
|
|
@@ -148,7 +164,7 @@ export class CredentialMapper {
|
|
|
148
164
|
return presentation
|
|
149
165
|
}
|
|
150
166
|
|
|
151
|
-
static toUniformCredential(verifiableCredential: OriginalVerifiableCredential): ICredential {
|
|
167
|
+
static toUniformCredential(verifiableCredential: OriginalVerifiableCredential, opts?: { maxTimeSkewInMS?: number }): ICredential {
|
|
152
168
|
const original = verifiableCredential
|
|
153
169
|
const decoded = CredentialMapper.decodeVerifiableCredential(verifiableCredential)
|
|
154
170
|
|
|
@@ -156,13 +172,13 @@ export class CredentialMapper {
|
|
|
156
172
|
const isJwtDecoded: boolean = CredentialMapper.isJwtDecodedCredential(original)
|
|
157
173
|
|
|
158
174
|
if (isJwtDecoded || isJwtEncoded) {
|
|
159
|
-
return CredentialMapper.jwtDecodedCredentialToUniformCredential(decoded as JwtDecodedVerifiableCredential)
|
|
175
|
+
return CredentialMapper.jwtDecodedCredentialToUniformCredential(decoded as JwtDecodedVerifiableCredential, opts)
|
|
160
176
|
} else {
|
|
161
177
|
return decoded as ICredential
|
|
162
178
|
}
|
|
163
179
|
}
|
|
164
180
|
|
|
165
|
-
static toUniformPresentation(presentation: OriginalVerifiablePresentation): IPresentation {
|
|
181
|
+
static toUniformPresentation(presentation: OriginalVerifiablePresentation, opts?: { maxTimeSkewInMS?: number }): IPresentation {
|
|
166
182
|
const original = presentation
|
|
167
183
|
const decoded = CredentialMapper.decodeVerifiablePresentation(original)
|
|
168
184
|
const isJwtEncoded: boolean = CredentialMapper.isJwtEncoded(original)
|
|
@@ -171,30 +187,35 @@ export class CredentialMapper {
|
|
|
171
187
|
isJwtEncoded || isJwtDecoded
|
|
172
188
|
? CredentialMapper.jwtDecodedPresentationToUniformPresentation(decoded as JwtDecodedVerifiablePresentation, false)
|
|
173
189
|
: (decoded as IPresentation)
|
|
174
|
-
uniformPresentation.verifiableCredential = uniformPresentation.verifiableCredential?.map(
|
|
175
|
-
CredentialMapper.toUniformCredential
|
|
190
|
+
uniformPresentation.verifiableCredential = uniformPresentation.verifiableCredential?.map((vc) =>
|
|
191
|
+
CredentialMapper.toUniformCredential(vc, opts)
|
|
176
192
|
) 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
193
|
return uniformPresentation
|
|
178
194
|
}
|
|
179
195
|
|
|
180
|
-
static jwtEncodedCredentialToUniformCredential(jwt: string): ICredential {
|
|
181
|
-
return CredentialMapper.jwtDecodedCredentialToUniformCredential(jwt_decode(jwt))
|
|
196
|
+
static jwtEncodedCredentialToUniformCredential(jwt: string, opts?: { maxTimeSkewInMS?: number }): ICredential {
|
|
197
|
+
return CredentialMapper.jwtDecodedCredentialToUniformCredential(jwt_decode(jwt), opts)
|
|
182
198
|
}
|
|
183
199
|
|
|
184
|
-
static jwtDecodedCredentialToUniformCredential(decoded: JwtDecodedVerifiableCredential): ICredential {
|
|
200
|
+
static jwtDecodedCredentialToUniformCredential(decoded: JwtDecodedVerifiableCredential, opts?: { maxTimeSkewInMS?: number }): ICredential {
|
|
185
201
|
const credential: ICredential = {
|
|
186
202
|
...(decoded.vc as ICredential),
|
|
187
203
|
}
|
|
188
204
|
// Since this is a credential, we delete any proof just to be sure (should not occur on JWT, but better safe than sorry)
|
|
189
205
|
delete credential.proof
|
|
190
206
|
|
|
207
|
+
const maxSkewInMS = opts?.maxTimeSkewInMS !== undefined ? opts.maxTimeSkewInMS : 999
|
|
208
|
+
|
|
191
209
|
if (decoded.exp) {
|
|
192
210
|
const expDate = credential.expirationDate
|
|
193
211
|
const jwtExp = parseInt(decoded.exp.toString())
|
|
194
212
|
// fix seconds to millisecs for the date
|
|
195
213
|
const expDateAsStr = jwtExp < 9999999999 ? new Date(jwtExp * 1000).toISOString().replace(/\.000Z/, 'Z') : new Date(jwtExp).toISOString()
|
|
196
214
|
if (expDate && expDate !== expDateAsStr) {
|
|
197
|
-
|
|
215
|
+
const diff = Math.abs(new Date(expDateAsStr).getTime() - new Date(expDate).getTime())
|
|
216
|
+
if (!maxSkewInMS || diff > maxSkewInMS) {
|
|
217
|
+
throw new Error(`Inconsistent expiration dates between JWT claim (${expDateAsStr}) and VC value (${expDate})`)
|
|
218
|
+
}
|
|
198
219
|
}
|
|
199
220
|
credential.expirationDate = expDateAsStr
|
|
200
221
|
}
|
|
@@ -205,7 +226,10 @@ export class CredentialMapper {
|
|
|
205
226
|
// fix seconds to millisecs for the date
|
|
206
227
|
const nbfDateAsStr = jwtNbf < 9999999999 ? new Date(jwtNbf * 1000).toISOString().replace(/\.000Z/, 'Z') : new Date(jwtNbf).toISOString()
|
|
207
228
|
if (issuanceDate && issuanceDate !== nbfDateAsStr) {
|
|
208
|
-
|
|
229
|
+
const diff = Math.abs(new Date(nbfDateAsStr).getTime() - new Date(issuanceDate).getTime())
|
|
230
|
+
if (!maxSkewInMS || diff > maxSkewInMS) {
|
|
231
|
+
throw new Error(`Inconsistent issuance dates between JWT claim (${nbfDateAsStr}) and VC value (${issuanceDate})`)
|
|
232
|
+
}
|
|
209
233
|
}
|
|
210
234
|
credential.issuanceDate = nbfDateAsStr
|
|
211
235
|
}
|
|
@@ -222,8 +246,9 @@ export class CredentialMapper {
|
|
|
222
246
|
throw new Error(`Inconsistent issuers between JWT claim (${decoded.iss}) and VC value (${issuer.id})`)
|
|
223
247
|
}
|
|
224
248
|
}
|
|
249
|
+
} else {
|
|
250
|
+
credential.issuer = decoded.iss
|
|
225
251
|
}
|
|
226
|
-
credential.issuer = decoded.iss
|
|
227
252
|
}
|
|
228
253
|
|
|
229
254
|
if (decoded.sub) {
|