@sphereon/ssi-types 0.8.1-next.20 → 0.8.1-next.272
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 +34 -11
- package/dist/mapper/credential-mapper.d.ts.map +1 -1
- package/dist/mapper/credential-mapper.js +169 -48
- package/dist/mapper/credential-mapper.js.map +1 -1
- package/dist/types/did.d.ts +2 -1
- package/dist/types/did.d.ts.map +1 -1
- package/dist/types/did.js +1 -0
- package/dist/types/did.js.map +1 -1
- package/dist/types/vc.d.ts +35 -26
- package/dist/types/vc.d.ts.map +1 -1
- package/dist/types/vc.js +7 -1
- package/dist/types/vc.js.map +1 -1
- package/package.json +3 -2
- package/src/mapper/credential-mapper.ts +219 -63
- package/src/types/did.ts +1 -0
- package/src/types/vc.ts +27 -16
|
@@ -1,19 +1,42 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DocumentFormat, IPresentation, IVerifiableCredential, IVerifiablePresentation, JwtDecodedVerifiableCredential, JwtDecodedVerifiablePresentation, OriginalVerifiableCredential, OriginalVerifiablePresentation, W3CVerifiableCredential, W3CVerifiablePresentation, WrappedVerifiableCredential, WrappedVerifiablePresentation } from '../types';
|
|
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(
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
static toWrappedVerifiablePresentation(originalPresentation: 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
|
-
private static
|
|
15
|
+
private static isJsonLdAsString;
|
|
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
|
+
}): IVerifiablePresentation;
|
|
24
|
+
static toUniformCredential(verifiableCredential: OriginalVerifiableCredential, opts?: {
|
|
25
|
+
maxTimeSkewInMS?: number;
|
|
26
|
+
}): IVerifiableCredential;
|
|
27
|
+
static toUniformPresentation(presentation: OriginalVerifiablePresentation, opts?: {
|
|
28
|
+
maxTimeSkewInMS?: number;
|
|
29
|
+
}): IVerifiablePresentation;
|
|
30
|
+
static jwtEncodedCredentialToUniformCredential(jwt: string, opts?: {
|
|
31
|
+
maxTimeSkewInMS?: number;
|
|
32
|
+
}): IVerifiableCredential;
|
|
33
|
+
static jwtDecodedCredentialToUniformCredential(decoded: JwtDecodedVerifiableCredential, opts?: {
|
|
34
|
+
maxTimeSkewInMS?: number;
|
|
35
|
+
}): IVerifiableCredential;
|
|
36
|
+
static toExternalVerifiableCredential(verifiableCredential: any): IVerifiableCredential;
|
|
37
|
+
static storedCredentialToOriginalFormat(credential: W3CVerifiableCredential): W3CVerifiableCredential;
|
|
38
|
+
static storedPresentationToOriginalFormat(presentation: W3CVerifiablePresentation): W3CVerifiablePresentation;
|
|
39
|
+
static toCompactJWT(jwtDocument: W3CVerifiableCredential | JwtDecodedVerifiableCredential | W3CVerifiablePresentation | JwtDecodedVerifiablePresentation): string;
|
|
40
|
+
static detectDocumentType(document: W3CVerifiableCredential | W3CVerifiablePresentation | JwtDecodedVerifiableCredential | JwtDecodedVerifiablePresentation): DocumentFormat;
|
|
18
41
|
}
|
|
19
42
|
//# 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":"AAAA,OAAO,EACL,cAAc,EACd,aAAa,EAIb,qBAAqB,EACrB,uBAAuB,EACvB,8BAA8B,EAC9B,gCAAgC,EAEhC,4BAA4B,EAC5B,8BAA8B,EAG9B,uBAAuB,EACvB,yBAAyB,EACzB,2BAA2B,EAC3B,6BAA6B,EAC9B,MAAM,UAAU,CAAA;AAIjB,qBAAa,gBAAgB;IAC3B,MAAM,CAAC,4BAA4B,CAAC,YAAY,EAAE,8BAA8B,GAAG,gCAAgC,GAAG,uBAAuB;IAsB7I,MAAM,CAAC,0BAA0B,CAAC,UAAU,EAAE,4BAA4B,GAAG,8BAA8B,GAAG,qBAAqB;IAqBnI,MAAM,CAAC,+BAA+B,CACpC,oBAAoB,EAAE,8BAA8B,EACpD,IAAI,CAAC,EAAE;QAAE,eAAe,CAAC,EAAE,MAAM,CAAA;KAAE,GAClC,6BAA6B;IAiChC,MAA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AAC,OAAO,EAAE,8BAA8B,EAAE,IAAI,CAAC,EAAE;QAAE,eAAe,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,qBAAqB;IA2EnJ,MAAM,CAAC,8BAA8B,CAAC,oBAAoB,EAAE,GAAG,GAAG,qBAAqB;IAsCvF,MAAM,CAAC,gCAAgC,CAAC,UAAU,EAAE,uBAAuB,GAAG,uBAAuB;IAYrG,MAAM,CAAC,kCAAkC,CAAC,YAAY,EAAE,yBAAyB,GAAG,yBAAyB;IAY7G,MAAM,CAAC,YAAY,CAAC,WAAW,EAAE,uBAAuB,GAAG,8BAA8B,GAAG,yBAAyB,GAAG,gCAAgC,GAAG,MAAM;IAqBjK,MAAM,CAAC,kBAAkB,CAAC,QAAQ,EAAE,uBAAuB,GAAG,yBAAyB,GAAG,8BAA8B,GAAG,gCAAgC,GAAG,cAAc;CAc7K"}
|
|
@@ -9,13 +9,23 @@ const jwt_decode_1 = __importDefault(require("jwt-decode"));
|
|
|
9
9
|
const utils_1 = require("../utils");
|
|
10
10
|
class CredentialMapper {
|
|
11
11
|
static decodeVerifiablePresentation(presentation) {
|
|
12
|
+
var _a;
|
|
12
13
|
if (CredentialMapper.isJwtEncoded(presentation)) {
|
|
13
|
-
|
|
14
|
+
const payload = (0, jwt_decode_1.default)(presentation);
|
|
15
|
+
const header = (0, jwt_decode_1.default)(presentation, { header: true });
|
|
16
|
+
payload.vp.proof = {
|
|
17
|
+
type: types_1.IProofType.JwtProof2020,
|
|
18
|
+
created: payload.nbf,
|
|
19
|
+
proofPurpose: types_1.IProofPurpose.authentication,
|
|
20
|
+
verificationMethod: (_a = header['kid']) !== null && _a !== void 0 ? _a : payload.iss,
|
|
21
|
+
jwt: presentation,
|
|
22
|
+
};
|
|
23
|
+
return payload;
|
|
14
24
|
}
|
|
15
25
|
else if (CredentialMapper.isJwtDecodedPresentation(presentation)) {
|
|
16
26
|
return presentation;
|
|
17
27
|
}
|
|
18
|
-
else if (CredentialMapper.
|
|
28
|
+
else if (CredentialMapper.isJsonLdAsString(presentation)) {
|
|
19
29
|
return JSON.parse(presentation);
|
|
20
30
|
}
|
|
21
31
|
else {
|
|
@@ -23,54 +33,70 @@ class CredentialMapper {
|
|
|
23
33
|
}
|
|
24
34
|
}
|
|
25
35
|
static decodeVerifiableCredential(credential) {
|
|
36
|
+
var _a;
|
|
26
37
|
if (CredentialMapper.isJwtEncoded(credential)) {
|
|
27
|
-
|
|
38
|
+
const payload = (0, jwt_decode_1.default)(credential);
|
|
39
|
+
const header = (0, jwt_decode_1.default)(credential, { header: true });
|
|
40
|
+
payload.vc.proof = {
|
|
41
|
+
type: types_1.IProofType.JwtProof2020,
|
|
42
|
+
created: payload.nbf,
|
|
43
|
+
proofPurpose: types_1.IProofPurpose.authentication,
|
|
44
|
+
verificationMethod: (_a = header['kid']) !== null && _a !== void 0 ? _a : payload.iss,
|
|
45
|
+
jwt: credential,
|
|
46
|
+
};
|
|
47
|
+
return payload;
|
|
28
48
|
}
|
|
29
49
|
else if (CredentialMapper.isJwtDecodedCredential(credential)) {
|
|
30
50
|
return credential;
|
|
31
51
|
}
|
|
32
|
-
else if (CredentialMapper.
|
|
52
|
+
else if (CredentialMapper.isJsonLdAsString(credential)) {
|
|
33
53
|
return JSON.parse(credential);
|
|
34
54
|
}
|
|
35
55
|
else {
|
|
36
56
|
return credential;
|
|
37
57
|
}
|
|
38
58
|
}
|
|
39
|
-
static toWrappedVerifiablePresentation(
|
|
40
|
-
const original =
|
|
59
|
+
static toWrappedVerifiablePresentation(originalPresentation, opts) {
|
|
60
|
+
const original = originalPresentation;
|
|
41
61
|
const isJwtEncoded = CredentialMapper.isJwtEncoded(original);
|
|
42
62
|
const isJwtDecoded = CredentialMapper.isJwtDecodedPresentation(original);
|
|
43
63
|
const type = isJwtEncoded ? types_1.OriginalType.JWT_ENCODED : isJwtDecoded ? types_1.OriginalType.JWT_DECODED : types_1.OriginalType.JSONLD;
|
|
44
64
|
const format = isJwtDecoded || isJwtEncoded ? 'jwt_vp' : 'ldp_vp';
|
|
45
65
|
const decoded = CredentialMapper.decodeVerifiablePresentation(original);
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
66
|
+
let vp;
|
|
67
|
+
if (isJwtEncoded || isJwtDecoded) {
|
|
68
|
+
vp = CredentialMapper.jwtDecodedPresentationToUniformPresentation(decoded, false, opts);
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
vp = decoded;
|
|
72
|
+
}
|
|
73
|
+
if (!vp || !('verifiableCredential' in vp) || !vp.verifiableCredential || vp.verifiableCredential.length === 0) {
|
|
74
|
+
throw Error(`VP needs to have at least one verifiable credential at this point`);
|
|
75
|
+
}
|
|
76
|
+
const vcs = CredentialMapper.toWrappedVerifiableCredentials(vp.verifiableCredential /*.map(value => value.original)*/, opts);
|
|
77
|
+
const presentation = Object.assign(Object.assign({}, vp), { verifiableCredential: vcs });
|
|
51
78
|
return {
|
|
52
79
|
type,
|
|
53
80
|
format,
|
|
54
81
|
original,
|
|
55
82
|
decoded,
|
|
56
|
-
presentation
|
|
83
|
+
presentation,
|
|
57
84
|
vcs,
|
|
58
85
|
};
|
|
59
86
|
}
|
|
60
|
-
static toWrappedVerifiableCredentials(verifiableCredentials) {
|
|
61
|
-
return verifiableCredentials.map(CredentialMapper.toWrappedVerifiableCredential);
|
|
87
|
+
static toWrappedVerifiableCredentials(verifiableCredentials, opts) {
|
|
88
|
+
return verifiableCredentials.map((vc) => CredentialMapper.toWrappedVerifiableCredential(vc, opts));
|
|
62
89
|
}
|
|
63
|
-
static toWrappedVerifiableCredential(verifiableCredential) {
|
|
90
|
+
static toWrappedVerifiableCredential(verifiableCredential, opts) {
|
|
64
91
|
const original = verifiableCredential;
|
|
65
92
|
const decoded = CredentialMapper.decodeVerifiableCredential(verifiableCredential);
|
|
66
93
|
const isJwtEncoded = CredentialMapper.isJwtEncoded(original);
|
|
67
94
|
const isJwtDecoded = CredentialMapper.isJwtDecodedCredential(original);
|
|
68
95
|
const type = isJwtEncoded ? types_1.OriginalType.JWT_ENCODED : isJwtDecoded ? types_1.OriginalType.JWT_DECODED : types_1.OriginalType.JSONLD;
|
|
69
|
-
const credential =
|
|
70
|
-
? CredentialMapper.jwtDecodedCredentialToUniformCredential(decoded)
|
|
96
|
+
const credential = isJwtEncoded || isJwtDecoded
|
|
97
|
+
? CredentialMapper.jwtDecodedCredentialToUniformCredential(decoded, opts)
|
|
71
98
|
: decoded;
|
|
72
|
-
const format =
|
|
73
|
-
//todo: We probably want to add proofs as well
|
|
99
|
+
const format = isJwtEncoded || isJwtDecoded ? 'jwt_vc' : 'ldp_vc';
|
|
74
100
|
return {
|
|
75
101
|
original,
|
|
76
102
|
decoded,
|
|
@@ -82,7 +108,7 @@ class CredentialMapper {
|
|
|
82
108
|
static isJwtEncoded(original) {
|
|
83
109
|
return utils_1.ObjectUtils.isString(original) && original.startsWith('ey');
|
|
84
110
|
}
|
|
85
|
-
static
|
|
111
|
+
static isJsonLdAsString(original) {
|
|
86
112
|
return utils_1.ObjectUtils.isString(original) && original.includes('@context');
|
|
87
113
|
}
|
|
88
114
|
static isJwtDecodedCredential(original) {
|
|
@@ -91,16 +117,17 @@ class CredentialMapper {
|
|
|
91
117
|
static isJwtDecodedPresentation(original) {
|
|
92
118
|
return original['vp'] !== undefined && original['iss'] !== undefined;
|
|
93
119
|
}
|
|
94
|
-
static jwtEncodedPresentationToUniformPresentation(jwt, makeCredentialsUniform = true) {
|
|
95
|
-
return CredentialMapper.jwtDecodedPresentationToUniformPresentation((0, jwt_decode_1.default)(jwt), makeCredentialsUniform);
|
|
120
|
+
static jwtEncodedPresentationToUniformPresentation(jwt, makeCredentialsUniform = true, opts) {
|
|
121
|
+
return CredentialMapper.jwtDecodedPresentationToUniformPresentation((0, jwt_decode_1.default)(jwt), makeCredentialsUniform, opts);
|
|
96
122
|
}
|
|
97
|
-
static jwtDecodedPresentationToUniformPresentation(decoded, makeCredentialsUniform = true) {
|
|
98
|
-
const presentation = Object.assign({}, decoded.vp);
|
|
123
|
+
static jwtDecodedPresentationToUniformPresentation(decoded, makeCredentialsUniform = true, opts) {
|
|
124
|
+
const presentation = Object.assign({}, (decoded.vp));
|
|
99
125
|
if (makeCredentialsUniform) {
|
|
100
|
-
|
|
126
|
+
if (!decoded.vp.verifiableCredential) {
|
|
127
|
+
throw Error('Verifiable Presentation should have a verifiable credential at this point');
|
|
128
|
+
}
|
|
129
|
+
presentation.verifiableCredential = decoded.vp.verifiableCredential.map((vc) => CredentialMapper.toUniformCredential(vc, opts));
|
|
101
130
|
}
|
|
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
|
-
delete presentation.proof;
|
|
104
131
|
if (decoded.iss) {
|
|
105
132
|
const holder = presentation.holder;
|
|
106
133
|
if (holder) {
|
|
@@ -119,19 +146,19 @@ class CredentialMapper {
|
|
|
119
146
|
}
|
|
120
147
|
return presentation;
|
|
121
148
|
}
|
|
122
|
-
static toUniformCredential(verifiableCredential) {
|
|
149
|
+
static toUniformCredential(verifiableCredential, opts) {
|
|
123
150
|
const original = verifiableCredential;
|
|
124
151
|
const decoded = CredentialMapper.decodeVerifiableCredential(verifiableCredential);
|
|
125
152
|
const isJwtEncoded = CredentialMapper.isJwtEncoded(original);
|
|
126
153
|
const isJwtDecoded = CredentialMapper.isJwtDecodedCredential(original);
|
|
127
154
|
if (isJwtDecoded || isJwtEncoded) {
|
|
128
|
-
return CredentialMapper.jwtDecodedCredentialToUniformCredential(decoded);
|
|
155
|
+
return CredentialMapper.jwtDecodedCredentialToUniformCredential(decoded, opts);
|
|
129
156
|
}
|
|
130
157
|
else {
|
|
131
158
|
return decoded;
|
|
132
159
|
}
|
|
133
160
|
}
|
|
134
|
-
static toUniformPresentation(presentation) {
|
|
161
|
+
static toUniformPresentation(presentation, opts) {
|
|
135
162
|
var _a;
|
|
136
163
|
const original = presentation;
|
|
137
164
|
const decoded = CredentialMapper.decodeVerifiablePresentation(original);
|
|
@@ -140,26 +167,27 @@ class CredentialMapper {
|
|
|
140
167
|
const uniformPresentation = isJwtEncoded || isJwtDecoded
|
|
141
168
|
? CredentialMapper.jwtDecodedPresentationToUniformPresentation(decoded, false)
|
|
142
169
|
: 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)
|
|
170
|
+
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
171
|
return uniformPresentation;
|
|
145
172
|
}
|
|
146
|
-
static jwtEncodedCredentialToUniformCredential(jwt) {
|
|
147
|
-
return CredentialMapper.jwtDecodedCredentialToUniformCredential((0, jwt_decode_1.default)(jwt));
|
|
173
|
+
static jwtEncodedCredentialToUniformCredential(jwt, opts) {
|
|
174
|
+
return CredentialMapper.jwtDecodedCredentialToUniformCredential((0, jwt_decode_1.default)(jwt), opts);
|
|
148
175
|
}
|
|
149
|
-
static jwtDecodedCredentialToUniformCredential(decoded) {
|
|
150
|
-
|
|
151
|
-
const
|
|
152
|
-
// Since this is a credential, we delete any proof just to be sure (should not occur on JWT, but better safe than sorry)
|
|
153
|
-
delete credential.proof;
|
|
176
|
+
static jwtDecodedCredentialToUniformCredential(decoded, opts) {
|
|
177
|
+
const credential = Object.assign({}, (decoded.vc));
|
|
178
|
+
const maxSkewInMS = (opts === null || opts === void 0 ? void 0 : opts.maxTimeSkewInMS) !== undefined ? opts.maxTimeSkewInMS : 999;
|
|
154
179
|
if (decoded.exp) {
|
|
155
|
-
const expDate =
|
|
180
|
+
const expDate = credential.expirationDate;
|
|
156
181
|
const jwtExp = parseInt(decoded.exp.toString());
|
|
157
|
-
// fix seconds to
|
|
182
|
+
// fix seconds to millisecond for the date
|
|
158
183
|
const expDateAsStr = jwtExp < 9999999999 ? new Date(jwtExp * 1000).toISOString().replace(/\.000Z/, 'Z') : new Date(jwtExp).toISOString();
|
|
159
184
|
if (expDate && expDate !== expDateAsStr) {
|
|
160
|
-
|
|
185
|
+
const diff = Math.abs(new Date(expDateAsStr).getTime() - new Date(expDate).getTime());
|
|
186
|
+
if (!maxSkewInMS || diff > maxSkewInMS) {
|
|
187
|
+
throw new Error(`Inconsistent expiration dates between JWT claim (${expDateAsStr}) and VC value (${expDate})`);
|
|
188
|
+
}
|
|
161
189
|
}
|
|
162
|
-
credential.
|
|
190
|
+
credential.expirationDate = expDateAsStr;
|
|
163
191
|
}
|
|
164
192
|
if (decoded.nbf) {
|
|
165
193
|
const issuanceDate = credential.issuanceDate;
|
|
@@ -167,7 +195,10 @@ class CredentialMapper {
|
|
|
167
195
|
// fix seconds to millisecs for the date
|
|
168
196
|
const nbfDateAsStr = jwtNbf < 9999999999 ? new Date(jwtNbf * 1000).toISOString().replace(/\.000Z/, 'Z') : new Date(jwtNbf).toISOString();
|
|
169
197
|
if (issuanceDate && issuanceDate !== nbfDateAsStr) {
|
|
170
|
-
|
|
198
|
+
const diff = Math.abs(new Date(nbfDateAsStr).getTime() - new Date(issuanceDate).getTime());
|
|
199
|
+
if (!maxSkewInMS || diff > maxSkewInMS) {
|
|
200
|
+
throw new Error(`Inconsistent issuance dates between JWT claim (${nbfDateAsStr}) and VC value (${issuanceDate})`);
|
|
201
|
+
}
|
|
171
202
|
}
|
|
172
203
|
credential.issuanceDate = nbfDateAsStr;
|
|
173
204
|
}
|
|
@@ -185,14 +216,21 @@ class CredentialMapper {
|
|
|
185
216
|
}
|
|
186
217
|
}
|
|
187
218
|
}
|
|
188
|
-
|
|
219
|
+
else {
|
|
220
|
+
credential.issuer = decoded.iss;
|
|
221
|
+
}
|
|
189
222
|
}
|
|
190
223
|
if (decoded.sub) {
|
|
191
|
-
const
|
|
192
|
-
|
|
193
|
-
|
|
224
|
+
const subjects = Array.isArray(credential.credentialSubject) ? credential.credentialSubject : [credential.credentialSubject];
|
|
225
|
+
for (let i = 0; i < subjects.length; i++) {
|
|
226
|
+
const csId = subjects[i].id;
|
|
227
|
+
if (csId && csId !== decoded.sub) {
|
|
228
|
+
throw new Error(`Inconsistent credential subject ids between JWT claim (${decoded.sub}) and VC value (${csId})`);
|
|
229
|
+
}
|
|
230
|
+
Array.isArray(credential.credentialSubject)
|
|
231
|
+
? (credential.credentialSubject[i].id = decoded.sub)
|
|
232
|
+
: (credential.credentialSubject.id = decoded.sub);
|
|
194
233
|
}
|
|
195
|
-
credential.credentialSubject.id = decoded.sub;
|
|
196
234
|
}
|
|
197
235
|
if (decoded.jti) {
|
|
198
236
|
const id = credential.id;
|
|
@@ -203,6 +241,89 @@ class CredentialMapper {
|
|
|
203
241
|
}
|
|
204
242
|
return credential;
|
|
205
243
|
}
|
|
244
|
+
static toExternalVerifiableCredential(verifiableCredential) {
|
|
245
|
+
let proof;
|
|
246
|
+
if (verifiableCredential.proof) {
|
|
247
|
+
if (!verifiableCredential.proof.type) {
|
|
248
|
+
throw new Error('Verifiable credential proof is missing a type');
|
|
249
|
+
}
|
|
250
|
+
if (!verifiableCredential.proof.created) {
|
|
251
|
+
throw new Error('Verifiable credential proof is missing a created date');
|
|
252
|
+
}
|
|
253
|
+
if (!verifiableCredential.proof.proofPurpose) {
|
|
254
|
+
throw new Error('Verifiable credential proof is missing a proof purpose');
|
|
255
|
+
}
|
|
256
|
+
if (!verifiableCredential.proof.verificationMethod) {
|
|
257
|
+
throw new Error('Verifiable credential proof is missing a verification method');
|
|
258
|
+
}
|
|
259
|
+
proof = Object.assign(Object.assign({}, verifiableCredential.proof), { type: verifiableCredential.proof.type, created: verifiableCredential.proof.created, proofPurpose: verifiableCredential.proof.proofPurpose, verificationMethod: verifiableCredential.proof.verificationMethod });
|
|
260
|
+
}
|
|
261
|
+
return Object.assign(Object.assign({}, verifiableCredential), { type: verifiableCredential.type
|
|
262
|
+
? typeof verifiableCredential.type === 'string'
|
|
263
|
+
? [verifiableCredential.type]
|
|
264
|
+
: verifiableCredential.type
|
|
265
|
+
: ['VerifiableCredential'], proof });
|
|
266
|
+
}
|
|
267
|
+
static storedCredentialToOriginalFormat(credential) {
|
|
268
|
+
const type = CredentialMapper.detectDocumentType(credential);
|
|
269
|
+
if (typeof credential === 'string') {
|
|
270
|
+
if (type === 0 /* DocumentFormat.JWT */) {
|
|
271
|
+
return CredentialMapper.toCompactJWT(credential);
|
|
272
|
+
}
|
|
273
|
+
else if (type === 1 /* DocumentFormat.JSONLD */) {
|
|
274
|
+
return JSON.parse(credential);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
return credential;
|
|
278
|
+
}
|
|
279
|
+
static storedPresentationToOriginalFormat(presentation) {
|
|
280
|
+
const type = CredentialMapper.detectDocumentType(presentation);
|
|
281
|
+
if (typeof presentation === 'string') {
|
|
282
|
+
if (type === 0 /* DocumentFormat.JWT */) {
|
|
283
|
+
return CredentialMapper.toCompactJWT(presentation);
|
|
284
|
+
}
|
|
285
|
+
else if (type === 1 /* DocumentFormat.JSONLD */) {
|
|
286
|
+
return JSON.parse(presentation);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
return presentation;
|
|
290
|
+
}
|
|
291
|
+
static toCompactJWT(jwtDocument) {
|
|
292
|
+
if (CredentialMapper.detectDocumentType(jwtDocument) !== 0 /* DocumentFormat.JWT */) {
|
|
293
|
+
throw Error('Cannot convert non JWT credential to JWT');
|
|
294
|
+
}
|
|
295
|
+
if (typeof jwtDocument === 'string') {
|
|
296
|
+
return jwtDocument;
|
|
297
|
+
}
|
|
298
|
+
let proof;
|
|
299
|
+
if ('vp' in jwtDocument) {
|
|
300
|
+
proof = jwtDocument.vp.proof;
|
|
301
|
+
}
|
|
302
|
+
else if ('vc' in jwtDocument) {
|
|
303
|
+
proof = jwtDocument.vc.proof;
|
|
304
|
+
}
|
|
305
|
+
else {
|
|
306
|
+
proof = Array.isArray(jwtDocument.proof) ? jwtDocument.proof[0].jwt : jwtDocument.proof.jwt;
|
|
307
|
+
}
|
|
308
|
+
if (!proof) {
|
|
309
|
+
throw Error(`Could not get JWT from supplied document`);
|
|
310
|
+
}
|
|
311
|
+
return proof;
|
|
312
|
+
}
|
|
313
|
+
static detectDocumentType(document) {
|
|
314
|
+
if (typeof document === 'string') {
|
|
315
|
+
return this.isJsonLdAsString(document) ? 1 /* DocumentFormat.JSONLD */ : 0 /* DocumentFormat.JWT */;
|
|
316
|
+
}
|
|
317
|
+
const proofs = 'vc' in document ? document.vc.proof : 'vp' in document ? document.vp.proof : document.proof;
|
|
318
|
+
const proof = Array.isArray(proofs) ? proofs[0] : proofs;
|
|
319
|
+
if (proof.jwt) {
|
|
320
|
+
return 0 /* DocumentFormat.JWT */;
|
|
321
|
+
}
|
|
322
|
+
else if (proof.type === 'EthereumEip712Signature2021') {
|
|
323
|
+
return 2 /* DocumentFormat.EIP712 */;
|
|
324
|
+
}
|
|
325
|
+
return 1 /* DocumentFormat.JSONLD */;
|
|
326
|
+
}
|
|
206
327
|
}
|
|
207
328
|
exports.CredentialMapper = CredentialMapper;
|
|
208
329
|
//# 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;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,cA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,CAAC,CAAC,MAAM,CAAA;QAEhE,IAAI,KAAK,CAAC,GAAG,EAAE;YACb,kCAAyB;SAC1B;aAAM,IAAI,KAAK,CAAC,IAAI,KAAK,6BAA6B,EAAE;YACvD,qCAA4B;SAC7B;QACD,qCAA4B;IAC9B,CAAC;CACF;AAzXD,4CAyXC"}
|
package/dist/types/did.d.ts
CHANGED
|
@@ -17,7 +17,8 @@ export declare enum IProofType {
|
|
|
17
17
|
GpgSignature2020 = "GpgSignature2020",
|
|
18
18
|
JcsEd25519Signature2020 = "JcsEd25519Signature2020",
|
|
19
19
|
BbsBlsSignatureProof2020 = "BbsBlsSignatureProof2020",
|
|
20
|
-
BbsBlsBoundSignatureProof2020 = "BbsBlsBoundSignatureProof2020"
|
|
20
|
+
BbsBlsBoundSignatureProof2020 = "BbsBlsBoundSignatureProof2020",
|
|
21
|
+
JwtProof2020 = "JwtProof2020"
|
|
21
22
|
}
|
|
22
23
|
export interface IParsedDID {
|
|
23
24
|
did: string;
|
package/dist/types/did.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"did.d.ts","sourceRoot":"","sources":["../../src/types/did.ts"],"names":[],"mappings":"AAAA,oBAAY,aAAa;IACvB,kBAAkB,uBAAuB;IACzC,eAAe,oBAAoB;IACnC,cAAc,mBAAmB;IACjC,YAAY,iBAAiB;IAC7B,iBAAiB,qBAAqB;IACtC,oBAAoB,yBAAyB;IAC7C,oBAAoB,yBAAyB;CAC9C;AAED,oBAAY,UAAU;IACpB,oBAAoB,yBAAyB;IAC7C,oBAAoB,yBAAyB;IAC7C,2BAA2B,gCAAgC;IAC3D,mCAAmC,wCAAwC;IAC3E,oBAAoB,yBAAyB;IAC7C,gBAAgB,qBAAqB;IACrC,gBAAgB,qBAAqB;IACrC,uBAAuB,4BAA4B;IACnD,wBAAwB,6BAA6B;IACrD,6BAA6B,kCAAkC;
|
|
1
|
+
{"version":3,"file":"did.d.ts","sourceRoot":"","sources":["../../src/types/did.ts"],"names":[],"mappings":"AAAA,oBAAY,aAAa;IACvB,kBAAkB,uBAAuB;IACzC,eAAe,oBAAoB;IACnC,cAAc,mBAAmB;IACjC,YAAY,iBAAiB;IAC7B,iBAAiB,qBAAqB;IACtC,oBAAoB,yBAAyB;IAC7C,oBAAoB,yBAAyB;CAC9C;AAED,oBAAY,UAAU;IACpB,oBAAoB,yBAAyB;IAC7C,oBAAoB,yBAAyB;IAC7C,2BAA2B,gCAAgC;IAC3D,mCAAmC,wCAAwC;IAC3E,oBAAoB,yBAAyB;IAC7C,gBAAgB,qBAAqB;IACrC,gBAAgB,qBAAqB;IACrC,uBAAuB,4BAA4B;IACnD,wBAAwB,6BAA6B;IACrD,6BAA6B,kCAAkC;IAC/D,YAAY,iBAAiB;CAC9B;AAED,MAAM,WAAW,UAAU;IACzB,GAAG,EAAE,MAAM,CAAA;IACX,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,MAAM,CAAA;IACd,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,EAAE;QACP,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAA;KACxB,CAAA;CACF;AAED,eAAO,MAAM,QAAQ,QAAS,MAAM,KAAG,UAOtC,CAAA"}
|
package/dist/types/did.js
CHANGED
|
@@ -23,6 +23,7 @@ var IProofType;
|
|
|
23
23
|
IProofType["JcsEd25519Signature2020"] = "JcsEd25519Signature2020";
|
|
24
24
|
IProofType["BbsBlsSignatureProof2020"] = "BbsBlsSignatureProof2020";
|
|
25
25
|
IProofType["BbsBlsBoundSignatureProof2020"] = "BbsBlsBoundSignatureProof2020";
|
|
26
|
+
IProofType["JwtProof2020"] = "JwtProof2020";
|
|
26
27
|
})(IProofType = exports.IProofType || (exports.IProofType = {}));
|
|
27
28
|
const parseDid = (did) => {
|
|
28
29
|
const parsedDid = parse(did);
|
package/dist/types/did.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"did.js","sourceRoot":"","sources":["../../src/types/did.ts"],"names":[],"mappings":";;;AAAA,IAAY,aAQX;AARD,WAAY,aAAa;IACvB,0DAAyC,CAAA;IACzC,oDAAmC,CAAA;IACnC,kDAAiC,CAAA;IACjC,8CAA6B,CAAA;IAC7B,uDAAsC,CAAA;IACtC,8DAA6C,CAAA;IAC7C,8DAA6C,CAAA;AAC/C,CAAC,EARW,aAAa,GAAb,qBAAa,KAAb,qBAAa,QAQxB;AAED,IAAY,
|
|
1
|
+
{"version":3,"file":"did.js","sourceRoot":"","sources":["../../src/types/did.ts"],"names":[],"mappings":";;;AAAA,IAAY,aAQX;AARD,WAAY,aAAa;IACvB,0DAAyC,CAAA;IACzC,oDAAmC,CAAA;IACnC,kDAAiC,CAAA;IACjC,8CAA6B,CAAA;IAC7B,uDAAsC,CAAA;IACtC,8DAA6C,CAAA;IAC7C,8DAA6C,CAAA;AAC/C,CAAC,EARW,aAAa,GAAb,qBAAa,KAAb,qBAAa,QAQxB;AAED,IAAY,UAYX;AAZD,WAAY,UAAU;IACpB,2DAA6C,CAAA;IAC7C,2DAA6C,CAAA;IAC7C,yEAA2D,CAAA;IAC3D,yFAA2E,CAAA;IAC3E,2DAA6C,CAAA;IAC7C,mDAAqC,CAAA;IACrC,mDAAqC,CAAA;IACrC,iEAAmD,CAAA;IACnD,mEAAqD,CAAA;IACrD,6EAA+D,CAAA;IAC/D,2CAA6B,CAAA;AAC/B,CAAC,EAZW,UAAU,GAAV,kBAAU,KAAV,kBAAU,QAYrB;AAeM,MAAM,QAAQ,GAAG,CAAC,GAAW,EAAc,EAAE;IAClD,MAAM,SAAS,GAAG,KAAK,CAAC,GAAG,CAAC,CAAA;IAC5B,IAAI,SAAS,KAAK,IAAI,EAAE;QACtB,MAAM,IAAI,KAAK,CAAC,aAAa,CAAC,CAAA;KAC/B;IAED,OAAO,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AC9C,KAAK,CAAC,MAAM,GAAG,EAAE,CAAA;YACjB,KAAK,MAAM,CAAC,IAAI,MAAM,EAAE;gBACtB,MAAM,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;gBACvB,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAA;aAC5B;SACF;QACD,IAAI,QAAQ,CAAC,CAAC,CAAC;YAAE,KAAK,CAAC,IAAI,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAA;QACzC,IAAI,QAAQ,CAAC,CAAC,CAAC;YAAE,KAAK,CAAC,KAAK,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;QACnD,IAAI,QAAQ,CAAC,CAAC,CAAC;YAAE,KAAK,CAAC,QAAQ,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;QACtD,OAAO,KAAK,CAAA;KACb;IAED,OAAO,IAAI,CAAA;AACb,CAAC,CAAA"}
|
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;
|
|
@@ -37,6 +38,7 @@ export interface IProof {
|
|
|
37
38
|
domain?: string;
|
|
38
39
|
proofValue?: string;
|
|
39
40
|
jws?: string;
|
|
41
|
+
jwt?: string;
|
|
40
42
|
nonce?: string;
|
|
41
43
|
requiredRevealStatements?: string[];
|
|
42
44
|
[x: string]: any;
|
|
@@ -52,33 +54,33 @@ export interface IIssuer {
|
|
|
52
54
|
export interface IHasProof {
|
|
53
55
|
proof: IProof | IProof[];
|
|
54
56
|
}
|
|
55
|
-
export
|
|
57
|
+
export type IVerifiableCredential = ICredential & IHasProof;
|
|
56
58
|
/**
|
|
57
59
|
* Represents a Json Web Token in compact form.
|
|
58
60
|
*/
|
|
59
|
-
export
|
|
61
|
+
export type CompactJWT = string;
|
|
60
62
|
/**
|
|
61
63
|
* Represents a signed Verifiable Credential (includes proof), in either JSON or compact JWT format.
|
|
62
64
|
* See {@link https://www.w3.org/TR/vc-data-model/#credentials | VC data model}
|
|
63
65
|
* See {@link https://www.w3.org/TR/vc-data-model/#proof-formats | proof formats}
|
|
64
66
|
*/
|
|
65
|
-
export
|
|
67
|
+
export type W3CVerifiableCredential = IVerifiableCredential | CompactJWT;
|
|
66
68
|
export interface IPresentation {
|
|
67
69
|
id?: string;
|
|
68
70
|
'@context': ICredentialContextType | ICredentialContextType[];
|
|
69
|
-
type
|
|
70
|
-
verifiableCredential
|
|
71
|
+
type?: string | string[];
|
|
72
|
+
verifiableCredential?: W3CVerifiableCredential[];
|
|
71
73
|
presentation_submission?: PresentationSubmission;
|
|
72
74
|
holder?: string;
|
|
73
75
|
[x: string]: any;
|
|
74
76
|
}
|
|
75
|
-
export
|
|
77
|
+
export type IVerifiablePresentation = IPresentation & IHasProof;
|
|
76
78
|
/**
|
|
77
79
|
* Represents a signed Verifiable Presentation (includes proof), in either JSON or compact JWT format.
|
|
78
80
|
* See {@link https://www.w3.org/TR/vc-data-model/#presentations | VC data model}
|
|
79
81
|
* See {@link https://www.w3.org/TR/vc-data-model/#proof-formats | proof formats}
|
|
80
82
|
*/
|
|
81
|
-
export
|
|
83
|
+
export type W3CVerifiablePresentation = IVerifiablePresentation | CompactJWT;
|
|
82
84
|
export interface WrappedVerifiableCredential {
|
|
83
85
|
/**
|
|
84
86
|
* Original VC that we've received
|
|
@@ -95,11 +97,11 @@ export interface WrappedVerifiableCredential {
|
|
|
95
97
|
/**
|
|
96
98
|
* The claim format, typically used during exchange transport protocols
|
|
97
99
|
*/
|
|
98
|
-
format:
|
|
100
|
+
format: CredentialFormat;
|
|
99
101
|
/**
|
|
100
|
-
* Internal stable representation of a Credential
|
|
102
|
+
* Internal stable representation of a Credential
|
|
101
103
|
*/
|
|
102
|
-
credential:
|
|
104
|
+
credential: IVerifiableCredential;
|
|
103
105
|
}
|
|
104
106
|
export interface WrappedVerifiablePresentation {
|
|
105
107
|
/**
|
|
@@ -117,7 +119,7 @@ export interface WrappedVerifiablePresentation {
|
|
|
117
119
|
/**
|
|
118
120
|
* The claim format, typically used during exchange transport protocols
|
|
119
121
|
*/
|
|
120
|
-
format:
|
|
122
|
+
format: PresentationFormat;
|
|
121
123
|
/**
|
|
122
124
|
* Internal stable representation of a Presentation without proofs, created based on https://www.w3.org/TR/vc-data-model/#jwt-decoding
|
|
123
125
|
*/
|
|
@@ -134,13 +136,13 @@ export declare enum OriginalType {
|
|
|
134
136
|
}
|
|
135
137
|
export interface UniformVerifiablePresentation {
|
|
136
138
|
'@context': ICredentialContextType | ICredentialContextType[];
|
|
137
|
-
type: string[];
|
|
139
|
+
type: string | string[];
|
|
138
140
|
verifiableCredential: WrappedVerifiableCredential[];
|
|
139
141
|
presentation_submission?: PresentationSubmission;
|
|
140
142
|
holder?: string;
|
|
141
143
|
}
|
|
142
144
|
export interface JwtDecodedVerifiableCredential {
|
|
143
|
-
vc:
|
|
145
|
+
vc: IVerifiableCredential;
|
|
144
146
|
exp: string;
|
|
145
147
|
iss: string;
|
|
146
148
|
nbf: string;
|
|
@@ -157,8 +159,15 @@ export interface JwtDecodedVerifiablePresentation {
|
|
|
157
159
|
jti: string;
|
|
158
160
|
[x: string]: any;
|
|
159
161
|
}
|
|
160
|
-
export
|
|
161
|
-
export
|
|
162
|
-
export
|
|
163
|
-
export
|
|
162
|
+
export type CredentialFormat = 'jwt' | 'ldp' | 'jwt_vc' | 'ldp_vc' | string;
|
|
163
|
+
export type PresentationFormat = 'jwt' | 'ldp' | 'jwt_vp' | 'ldp_vp' | string;
|
|
164
|
+
export type ClaimFormat = CredentialFormat | PresentationFormat;
|
|
165
|
+
export type OriginalVerifiableCredential = W3CVerifiableCredential | JwtDecodedVerifiableCredential;
|
|
166
|
+
export type OriginalVerifiablePresentation = W3CVerifiablePresentation | JwtDecodedVerifiablePresentation;
|
|
167
|
+
export type Original = OriginalVerifiablePresentation | OriginalVerifiableCredential;
|
|
168
|
+
export declare const enum DocumentFormat {
|
|
169
|
+
JWT = 0,
|
|
170
|
+
JSONLD = 1,
|
|
171
|
+
EIP712 = 2
|
|
172
|
+
}
|
|
164
173
|
//# 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,GAAG,gBAAgB,CAAC,GAAG,CAAC,kBAAkB,GAAG,gBAAgB,CAAC,EAAE,CAAA;IAEtG,cAAc,CAAC,EAAE,MAAM,CAAA;IAEvB,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,gBAAgB,CAAC,EAAE,iBAAiB,CAAA;IACpC,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,IAAI,CAAC,EAAE,MAAM,CAAA;IAEb,CAAC,CAAC,EAAE,MAAM,GAAG,GAAG,CAAA;CACjB;AAED,MAAM,WAAW,kBAAkB;IACjC,EAAE,CAAC,EAAE,MAAM,CAAA;CACZ;A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AAA;IACN,MAAM,IAAA;CACP"}
|
package/dist/types/vc.js
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.OriginalType = void 0;
|
|
3
|
+
exports.DocumentFormat = exports.OriginalType = void 0;
|
|
4
4
|
var OriginalType;
|
|
5
5
|
(function (OriginalType) {
|
|
6
6
|
OriginalType["JSONLD"] = "json-ld";
|
|
7
7
|
OriginalType["JWT_ENCODED"] = "jwt-encoded";
|
|
8
8
|
OriginalType["JWT_DECODED"] = "jwt-decoded";
|
|
9
9
|
})(OriginalType = exports.OriginalType || (exports.OriginalType = {}));
|
|
10
|
+
var DocumentFormat;
|
|
11
|
+
(function (DocumentFormat) {
|
|
12
|
+
DocumentFormat[DocumentFormat["JWT"] = 0] = "JWT";
|
|
13
|
+
DocumentFormat[DocumentFormat["JSONLD"] = 1] = "JSONLD";
|
|
14
|
+
DocumentFormat[DocumentFormat["EIP712"] = 2] = "EIP712";
|
|
15
|
+
})(DocumentFormat = exports.DocumentFormat || (exports.DocumentFormat = {}));
|
|
10
16
|
//# sourceMappingURL=vc.js.map
|
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":";;;AAiKA,IAAY,YAIX;AAJD,WAAY,YAAY;IACtB,kCAAkB,CAAA;IAClB,2CAA2B,CAAA;IAC3B,2CAA2B,CAAA;AAC7B,CAAC,EAJW,YAAY,GAAZ,oBAAY,KAAZ,oBAAY,QAIvB;AAwCD,IAAkB,cAIjB;AAJD,WAAkB,cAAc;IAC9B,iDAAG,CAAA;IACH,uDAAM,CAAA;IACN,uDAAM,CAAA;AACR,CAAC,EAJiB,cAAc,GAAd,sBAAc,KAAd,sBAAc,QAI/B"}
|
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.272+a34f653",
|
|
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": "a34f653b26d26b6d980aa9196b814ad42cfa5e3f"
|
|
41
42
|
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
ICredential,
|
|
2
|
+
DocumentFormat,
|
|
4
3
|
IPresentation,
|
|
4
|
+
IProof,
|
|
5
|
+
IProofPurpose,
|
|
6
|
+
IProofType,
|
|
5
7
|
IVerifiableCredential,
|
|
6
8
|
IVerifiablePresentation,
|
|
7
9
|
JwtDecodedVerifiableCredential,
|
|
@@ -9,6 +11,10 @@ import {
|
|
|
9
11
|
OriginalType,
|
|
10
12
|
OriginalVerifiableCredential,
|
|
11
13
|
OriginalVerifiablePresentation,
|
|
14
|
+
PresentationFormat,
|
|
15
|
+
UniformVerifiablePresentation,
|
|
16
|
+
W3CVerifiableCredential,
|
|
17
|
+
W3CVerifiablePresentation,
|
|
12
18
|
WrappedVerifiableCredential,
|
|
13
19
|
WrappedVerifiablePresentation,
|
|
14
20
|
} from '../types'
|
|
@@ -18,10 +24,20 @@ import { ObjectUtils } from '../utils'
|
|
|
18
24
|
export class CredentialMapper {
|
|
19
25
|
static decodeVerifiablePresentation(presentation: OriginalVerifiablePresentation): JwtDecodedVerifiablePresentation | IVerifiablePresentation {
|
|
20
26
|
if (CredentialMapper.isJwtEncoded(presentation)) {
|
|
21
|
-
|
|
27
|
+
const payload = jwt_decode(presentation as string) as JwtDecodedVerifiablePresentation
|
|
28
|
+
const header = jwt_decode(presentation as string, { header: true }) as Record<string, any>
|
|
29
|
+
|
|
30
|
+
payload.vp.proof = {
|
|
31
|
+
type: IProofType.JwtProof2020,
|
|
32
|
+
created: payload.nbf,
|
|
33
|
+
proofPurpose: IProofPurpose.authentication,
|
|
34
|
+
verificationMethod: header['kid'] ?? payload.iss,
|
|
35
|
+
jwt: presentation as string,
|
|
36
|
+
}
|
|
37
|
+
return payload
|
|
22
38
|
} else if (CredentialMapper.isJwtDecodedPresentation(presentation)) {
|
|
23
39
|
return presentation as JwtDecodedVerifiablePresentation
|
|
24
|
-
} else if (CredentialMapper.
|
|
40
|
+
} else if (CredentialMapper.isJsonLdAsString(presentation)) {
|
|
25
41
|
return JSON.parse(presentation as string) as IVerifiablePresentation
|
|
26
42
|
} else {
|
|
27
43
|
return presentation as IVerifiablePresentation
|
|
@@ -30,51 +46,73 @@ export class CredentialMapper {
|
|
|
30
46
|
|
|
31
47
|
static decodeVerifiableCredential(credential: OriginalVerifiableCredential): JwtDecodedVerifiableCredential | IVerifiableCredential {
|
|
32
48
|
if (CredentialMapper.isJwtEncoded(credential)) {
|
|
33
|
-
|
|
49
|
+
const payload = jwt_decode(credential as string) as JwtDecodedVerifiableCredential
|
|
50
|
+
const header = jwt_decode(credential as string, { header: true }) as Record<string, any>
|
|
51
|
+
payload.vc.proof = {
|
|
52
|
+
type: IProofType.JwtProof2020,
|
|
53
|
+
created: payload.nbf,
|
|
54
|
+
proofPurpose: IProofPurpose.authentication,
|
|
55
|
+
verificationMethod: header['kid'] ?? payload.iss,
|
|
56
|
+
jwt: credential as string,
|
|
57
|
+
}
|
|
58
|
+
return payload
|
|
34
59
|
} else if (CredentialMapper.isJwtDecodedCredential(credential)) {
|
|
35
60
|
return credential as JwtDecodedVerifiableCredential
|
|
36
|
-
} else if (CredentialMapper.
|
|
61
|
+
} else if (CredentialMapper.isJsonLdAsString(credential)) {
|
|
37
62
|
return JSON.parse(credential as string) as IVerifiableCredential
|
|
38
63
|
} else {
|
|
39
64
|
return credential as IVerifiableCredential
|
|
40
65
|
}
|
|
41
66
|
}
|
|
42
67
|
|
|
43
|
-
static toWrappedVerifiablePresentation(
|
|
44
|
-
|
|
68
|
+
static toWrappedVerifiablePresentation(
|
|
69
|
+
originalPresentation: OriginalVerifiablePresentation,
|
|
70
|
+
opts?: { maxTimeSkewInMS?: number },
|
|
71
|
+
): WrappedVerifiablePresentation {
|
|
72
|
+
const original = originalPresentation
|
|
45
73
|
const isJwtEncoded: boolean = CredentialMapper.isJwtEncoded(original)
|
|
46
74
|
const isJwtDecoded: boolean = CredentialMapper.isJwtDecodedPresentation(original)
|
|
47
75
|
|
|
48
76
|
const type = isJwtEncoded ? OriginalType.JWT_ENCODED : isJwtDecoded ? OriginalType.JWT_DECODED : OriginalType.JSONLD
|
|
49
|
-
const format:
|
|
77
|
+
const format: PresentationFormat = isJwtDecoded || isJwtEncoded ? 'jwt_vp' : 'ldp_vp'
|
|
50
78
|
const decoded = CredentialMapper.decodeVerifiablePresentation(original)
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
79
|
+
let vp: OriginalVerifiablePresentation
|
|
80
|
+
if (isJwtEncoded || isJwtDecoded) {
|
|
81
|
+
vp = CredentialMapper.jwtDecodedPresentationToUniformPresentation(decoded as JwtDecodedVerifiablePresentation, false, opts)
|
|
82
|
+
} else {
|
|
83
|
+
vp = decoded as IVerifiablePresentation
|
|
84
|
+
}
|
|
85
|
+
if (!vp || !('verifiableCredential' in vp) || !vp.verifiableCredential || vp.verifiableCredential.length === 0) {
|
|
86
|
+
throw Error(`VP needs to have at least one verifiable credential at this point`)
|
|
87
|
+
}
|
|
88
|
+
const vcs: WrappedVerifiableCredential[] = CredentialMapper.toWrappedVerifiableCredentials(vp.verifiableCredential/*.map(value => value.original)*/, opts)
|
|
56
89
|
|
|
57
|
-
|
|
90
|
+
const presentation = {
|
|
91
|
+
...vp,
|
|
92
|
+
verifiableCredential: vcs, // We overwrite the credentials with wrapped versions, making it an InternalVerifiablePresentation. Note: we keep the singular key name of the vc data model
|
|
93
|
+
} as UniformVerifiablePresentation
|
|
58
94
|
return {
|
|
59
95
|
type,
|
|
60
96
|
format,
|
|
61
97
|
original,
|
|
62
98
|
decoded,
|
|
63
|
-
presentation
|
|
64
|
-
...vp,
|
|
65
|
-
verifiableCredential: vcs, // We overwrite the credentials with wrapped versions, making it an InternalVerifiablePresentation. Note: we keep the singular key name of the vc data model
|
|
66
|
-
},
|
|
99
|
+
presentation,
|
|
67
100
|
vcs,
|
|
68
101
|
}
|
|
69
102
|
}
|
|
70
103
|
|
|
71
|
-
static toWrappedVerifiableCredentials(
|
|
72
|
-
|
|
104
|
+
static toWrappedVerifiableCredentials(
|
|
105
|
+
verifiableCredentials: OriginalVerifiableCredential[],
|
|
106
|
+
opts?: { maxTimeSkewInMS?: number },
|
|
107
|
+
): WrappedVerifiableCredential[] {
|
|
108
|
+
return verifiableCredentials.map((vc) => CredentialMapper.toWrappedVerifiableCredential(vc, opts))
|
|
73
109
|
}
|
|
74
110
|
|
|
75
|
-
static toWrappedVerifiableCredential(
|
|
111
|
+
static toWrappedVerifiableCredential(
|
|
112
|
+
verifiableCredential: OriginalVerifiableCredential,
|
|
113
|
+
opts?: { maxTimeSkewInMS?: number },
|
|
114
|
+
): WrappedVerifiableCredential {
|
|
76
115
|
const original = verifiableCredential
|
|
77
|
-
|
|
78
116
|
const decoded = CredentialMapper.decodeVerifiableCredential(verifiableCredential)
|
|
79
117
|
|
|
80
118
|
const isJwtEncoded = CredentialMapper.isJwtEncoded(original)
|
|
@@ -82,11 +120,11 @@ export class CredentialMapper {
|
|
|
82
120
|
const type = isJwtEncoded ? OriginalType.JWT_ENCODED : isJwtDecoded ? OriginalType.JWT_DECODED : OriginalType.JSONLD
|
|
83
121
|
|
|
84
122
|
const credential =
|
|
85
|
-
|
|
86
|
-
? CredentialMapper.jwtDecodedCredentialToUniformCredential(decoded as JwtDecodedVerifiableCredential)
|
|
87
|
-
: (decoded as
|
|
88
|
-
|
|
89
|
-
|
|
123
|
+
isJwtEncoded || isJwtDecoded
|
|
124
|
+
? CredentialMapper.jwtDecodedCredentialToUniformCredential(decoded as JwtDecodedVerifiableCredential, opts)
|
|
125
|
+
: (decoded as IVerifiableCredential)
|
|
126
|
+
|
|
127
|
+
const format = isJwtEncoded || isJwtDecoded ? 'jwt_vc' : 'ldp_vc'
|
|
90
128
|
return {
|
|
91
129
|
original,
|
|
92
130
|
decoded,
|
|
@@ -100,7 +138,7 @@ export class CredentialMapper {
|
|
|
100
138
|
return ObjectUtils.isString(original) && (original as string).startsWith('ey')
|
|
101
139
|
}
|
|
102
140
|
|
|
103
|
-
private static
|
|
141
|
+
private static isJsonLdAsString(original: OriginalVerifiableCredential | OriginalVerifiablePresentation) {
|
|
104
142
|
return ObjectUtils.isString(original) && (original as string).includes('@context')
|
|
105
143
|
}
|
|
106
144
|
|
|
@@ -112,23 +150,30 @@ export class CredentialMapper {
|
|
|
112
150
|
return (<JwtDecodedVerifiablePresentation>original)['vp'] !== undefined && (<JwtDecodedVerifiablePresentation>original)['iss'] !== undefined
|
|
113
151
|
}
|
|
114
152
|
|
|
115
|
-
static jwtEncodedPresentationToUniformPresentation(
|
|
116
|
-
|
|
153
|
+
static jwtEncodedPresentationToUniformPresentation(
|
|
154
|
+
jwt: string,
|
|
155
|
+
makeCredentialsUniform: boolean = true,
|
|
156
|
+
opts?: { maxTimeSkewInMS?: number },
|
|
157
|
+
): IPresentation {
|
|
158
|
+
return CredentialMapper.jwtDecodedPresentationToUniformPresentation(jwt_decode(jwt), makeCredentialsUniform, opts)
|
|
117
159
|
}
|
|
118
160
|
|
|
119
161
|
static jwtDecodedPresentationToUniformPresentation(
|
|
120
162
|
decoded: JwtDecodedVerifiablePresentation,
|
|
121
|
-
makeCredentialsUniform: boolean = true
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
163
|
+
makeCredentialsUniform: boolean = true,
|
|
164
|
+
opts?: { maxTimeSkewInMS?: number },
|
|
165
|
+
): IVerifiablePresentation {
|
|
166
|
+
const presentation: IVerifiablePresentation = {
|
|
167
|
+
...(decoded.vp),
|
|
125
168
|
}
|
|
126
169
|
if (makeCredentialsUniform) {
|
|
127
|
-
|
|
170
|
+
if (!decoded.vp.verifiableCredential) {
|
|
171
|
+
throw Error('Verifiable Presentation should have a verifiable credential at this point')
|
|
172
|
+
}
|
|
173
|
+
presentation.verifiableCredential = decoded.vp.verifiableCredential.map((vc) =>
|
|
174
|
+
CredentialMapper.toUniformCredential(vc, opts),
|
|
175
|
+
)
|
|
128
176
|
}
|
|
129
|
-
// Since this is a presentation, we delete any proof just to be sure (should not occur on JWT, but better safe than sorry)
|
|
130
|
-
delete presentation.proof
|
|
131
|
-
|
|
132
177
|
if (decoded.iss) {
|
|
133
178
|
const holder = presentation.holder
|
|
134
179
|
if (holder) {
|
|
@@ -148,7 +193,7 @@ export class CredentialMapper {
|
|
|
148
193
|
return presentation
|
|
149
194
|
}
|
|
150
195
|
|
|
151
|
-
static toUniformCredential(verifiableCredential: OriginalVerifiableCredential):
|
|
196
|
+
static toUniformCredential(verifiableCredential: OriginalVerifiableCredential, opts?: { maxTimeSkewInMS?: number }): IVerifiableCredential {
|
|
152
197
|
const original = verifiableCredential
|
|
153
198
|
const decoded = CredentialMapper.decodeVerifiableCredential(verifiableCredential)
|
|
154
199
|
|
|
@@ -156,13 +201,13 @@ export class CredentialMapper {
|
|
|
156
201
|
const isJwtDecoded: boolean = CredentialMapper.isJwtDecodedCredential(original)
|
|
157
202
|
|
|
158
203
|
if (isJwtDecoded || isJwtEncoded) {
|
|
159
|
-
return CredentialMapper.jwtDecodedCredentialToUniformCredential(decoded as JwtDecodedVerifiableCredential)
|
|
204
|
+
return CredentialMapper.jwtDecodedCredentialToUniformCredential(decoded as JwtDecodedVerifiableCredential, opts)
|
|
160
205
|
} else {
|
|
161
|
-
return decoded as
|
|
206
|
+
return decoded as IVerifiableCredential
|
|
162
207
|
}
|
|
163
208
|
}
|
|
164
209
|
|
|
165
|
-
static toUniformPresentation(presentation: OriginalVerifiablePresentation):
|
|
210
|
+
static toUniformPresentation(presentation: OriginalVerifiablePresentation, opts?: { maxTimeSkewInMS?: number }): IVerifiablePresentation {
|
|
166
211
|
const original = presentation
|
|
167
212
|
const decoded = CredentialMapper.decodeVerifiablePresentation(original)
|
|
168
213
|
const isJwtEncoded: boolean = CredentialMapper.isJwtEncoded(original)
|
|
@@ -170,33 +215,36 @@ export class CredentialMapper {
|
|
|
170
215
|
const uniformPresentation =
|
|
171
216
|
isJwtEncoded || isJwtDecoded
|
|
172
217
|
? CredentialMapper.jwtDecodedPresentationToUniformPresentation(decoded as JwtDecodedVerifiablePresentation, false)
|
|
173
|
-
: (decoded as
|
|
174
|
-
uniformPresentation.verifiableCredential = uniformPresentation.verifiableCredential?.map(
|
|
175
|
-
CredentialMapper.toUniformCredential
|
|
218
|
+
: (decoded as IVerifiablePresentation)
|
|
219
|
+
uniformPresentation.verifiableCredential = uniformPresentation.verifiableCredential?.map((vc) =>
|
|
220
|
+
CredentialMapper.toUniformCredential(vc, opts),
|
|
176
221
|
) 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
222
|
return uniformPresentation
|
|
178
223
|
}
|
|
179
224
|
|
|
180
|
-
static jwtEncodedCredentialToUniformCredential(jwt: string):
|
|
181
|
-
return CredentialMapper.jwtDecodedCredentialToUniformCredential(jwt_decode(jwt))
|
|
225
|
+
static jwtEncodedCredentialToUniformCredential(jwt: string, opts?: { maxTimeSkewInMS?: number }): IVerifiableCredential {
|
|
226
|
+
return CredentialMapper.jwtDecodedCredentialToUniformCredential(jwt_decode(jwt), opts)
|
|
182
227
|
}
|
|
183
228
|
|
|
184
|
-
static jwtDecodedCredentialToUniformCredential(decoded: JwtDecodedVerifiableCredential):
|
|
185
|
-
const credential:
|
|
186
|
-
...(decoded.vc
|
|
229
|
+
static jwtDecodedCredentialToUniformCredential(decoded: JwtDecodedVerifiableCredential, opts?: { maxTimeSkewInMS?: number }): IVerifiableCredential {
|
|
230
|
+
const credential: IVerifiableCredential = {
|
|
231
|
+
...(decoded.vc),
|
|
187
232
|
}
|
|
188
|
-
|
|
189
|
-
|
|
233
|
+
|
|
234
|
+
const maxSkewInMS = opts?.maxTimeSkewInMS !== undefined ? opts.maxTimeSkewInMS : 999
|
|
190
235
|
|
|
191
236
|
if (decoded.exp) {
|
|
192
|
-
const expDate = credential.
|
|
237
|
+
const expDate = credential.expirationDate
|
|
193
238
|
const jwtExp = parseInt(decoded.exp.toString())
|
|
194
|
-
// fix seconds to
|
|
239
|
+
// fix seconds to millisecond for the date
|
|
195
240
|
const expDateAsStr = jwtExp < 9999999999 ? new Date(jwtExp * 1000).toISOString().replace(/\.000Z/, 'Z') : new Date(jwtExp).toISOString()
|
|
196
241
|
if (expDate && expDate !== expDateAsStr) {
|
|
197
|
-
|
|
242
|
+
const diff = Math.abs(new Date(expDateAsStr).getTime() - new Date(expDate).getTime())
|
|
243
|
+
if (!maxSkewInMS || diff > maxSkewInMS) {
|
|
244
|
+
throw new Error(`Inconsistent expiration dates between JWT claim (${expDateAsStr}) and VC value (${expDate})`)
|
|
245
|
+
}
|
|
198
246
|
}
|
|
199
|
-
credential.
|
|
247
|
+
credential.expirationDate = expDateAsStr
|
|
200
248
|
}
|
|
201
249
|
|
|
202
250
|
if (decoded.nbf) {
|
|
@@ -205,7 +253,10 @@ export class CredentialMapper {
|
|
|
205
253
|
// fix seconds to millisecs for the date
|
|
206
254
|
const nbfDateAsStr = jwtNbf < 9999999999 ? new Date(jwtNbf * 1000).toISOString().replace(/\.000Z/, 'Z') : new Date(jwtNbf).toISOString()
|
|
207
255
|
if (issuanceDate && issuanceDate !== nbfDateAsStr) {
|
|
208
|
-
|
|
256
|
+
const diff = Math.abs(new Date(nbfDateAsStr).getTime() - new Date(issuanceDate).getTime())
|
|
257
|
+
if (!maxSkewInMS || diff > maxSkewInMS) {
|
|
258
|
+
throw new Error(`Inconsistent issuance dates between JWT claim (${nbfDateAsStr}) and VC value (${issuanceDate})`)
|
|
259
|
+
}
|
|
209
260
|
}
|
|
210
261
|
credential.issuanceDate = nbfDateAsStr
|
|
211
262
|
}
|
|
@@ -222,16 +273,22 @@ export class CredentialMapper {
|
|
|
222
273
|
throw new Error(`Inconsistent issuers between JWT claim (${decoded.iss}) and VC value (${issuer.id})`)
|
|
223
274
|
}
|
|
224
275
|
}
|
|
276
|
+
} else {
|
|
277
|
+
credential.issuer = decoded.iss
|
|
225
278
|
}
|
|
226
|
-
credential.issuer = decoded.iss
|
|
227
279
|
}
|
|
228
280
|
|
|
229
281
|
if (decoded.sub) {
|
|
230
|
-
const
|
|
231
|
-
|
|
232
|
-
|
|
282
|
+
const subjects = Array.isArray(credential.credentialSubject) ? credential.credentialSubject : [credential.credentialSubject]
|
|
283
|
+
for (let i = 0; i < subjects.length; i++) {
|
|
284
|
+
const csId = subjects[i].id
|
|
285
|
+
if (csId && csId !== decoded.sub) {
|
|
286
|
+
throw new Error(`Inconsistent credential subject ids between JWT claim (${decoded.sub}) and VC value (${csId})`)
|
|
287
|
+
}
|
|
288
|
+
Array.isArray(credential.credentialSubject)
|
|
289
|
+
? (credential.credentialSubject[i].id = decoded.sub)
|
|
290
|
+
: (credential.credentialSubject.id = decoded.sub)
|
|
233
291
|
}
|
|
234
|
-
credential.credentialSubject.id = decoded.sub
|
|
235
292
|
}
|
|
236
293
|
if (decoded.jti) {
|
|
237
294
|
const id = credential.id
|
|
@@ -240,6 +297,105 @@ export class CredentialMapper {
|
|
|
240
297
|
}
|
|
241
298
|
credential.id = decoded.jti
|
|
242
299
|
}
|
|
300
|
+
|
|
301
|
+
return credential
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
static toExternalVerifiableCredential(verifiableCredential: any): IVerifiableCredential {
|
|
305
|
+
let proof
|
|
306
|
+
if (verifiableCredential.proof) {
|
|
307
|
+
if (!verifiableCredential.proof.type) {
|
|
308
|
+
throw new Error('Verifiable credential proof is missing a type')
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
if (!verifiableCredential.proof.created) {
|
|
312
|
+
throw new Error('Verifiable credential proof is missing a created date')
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
if (!verifiableCredential.proof.proofPurpose) {
|
|
316
|
+
throw new Error('Verifiable credential proof is missing a proof purpose')
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
if (!verifiableCredential.proof.verificationMethod) {
|
|
320
|
+
throw new Error('Verifiable credential proof is missing a verification method')
|
|
321
|
+
}
|
|
322
|
+
proof = {
|
|
323
|
+
...verifiableCredential.proof,
|
|
324
|
+
type: verifiableCredential.proof.type,
|
|
325
|
+
created: verifiableCredential.proof.created,
|
|
326
|
+
proofPurpose: verifiableCredential.proof.proofPurpose,
|
|
327
|
+
verificationMethod: verifiableCredential.proof.verificationMethod,
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
return {
|
|
332
|
+
...verifiableCredential,
|
|
333
|
+
type: verifiableCredential.type
|
|
334
|
+
? typeof verifiableCredential.type === 'string'
|
|
335
|
+
? [verifiableCredential.type]
|
|
336
|
+
: verifiableCredential.type
|
|
337
|
+
: ['VerifiableCredential'],
|
|
338
|
+
proof,
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
static storedCredentialToOriginalFormat(credential: W3CVerifiableCredential): W3CVerifiableCredential {
|
|
343
|
+
const type: DocumentFormat = CredentialMapper.detectDocumentType(credential)
|
|
344
|
+
if (typeof credential === 'string') {
|
|
345
|
+
if (type === DocumentFormat.JWT) {
|
|
346
|
+
return CredentialMapper.toCompactJWT(credential)
|
|
347
|
+
} else if (type === DocumentFormat.JSONLD) {
|
|
348
|
+
return JSON.parse(credential)
|
|
349
|
+
}
|
|
350
|
+
}
|
|
243
351
|
return credential
|
|
244
352
|
}
|
|
353
|
+
|
|
354
|
+
static storedPresentationToOriginalFormat(presentation: W3CVerifiablePresentation): W3CVerifiablePresentation {
|
|
355
|
+
const type: DocumentFormat = CredentialMapper.detectDocumentType(presentation)
|
|
356
|
+
if (typeof presentation === 'string') {
|
|
357
|
+
if (type === DocumentFormat.JWT) {
|
|
358
|
+
return CredentialMapper.toCompactJWT(presentation)
|
|
359
|
+
} else if (type === DocumentFormat.JSONLD) {
|
|
360
|
+
return JSON.parse(presentation)
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
return presentation
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
static toCompactJWT(jwtDocument: W3CVerifiableCredential | JwtDecodedVerifiableCredential | W3CVerifiablePresentation | JwtDecodedVerifiablePresentation): string {
|
|
367
|
+
if (CredentialMapper.detectDocumentType(jwtDocument) !== DocumentFormat.JWT) {
|
|
368
|
+
throw Error('Cannot convert non JWT credential to JWT')
|
|
369
|
+
}
|
|
370
|
+
if (typeof jwtDocument === 'string') {
|
|
371
|
+
return jwtDocument
|
|
372
|
+
}
|
|
373
|
+
let proof: string | undefined
|
|
374
|
+
if ('vp' in jwtDocument) {
|
|
375
|
+
proof = jwtDocument.vp.proof
|
|
376
|
+
} else if ('vc' in jwtDocument) {
|
|
377
|
+
proof = jwtDocument.vc.proof
|
|
378
|
+
} else {
|
|
379
|
+
proof = Array.isArray(jwtDocument.proof) ? jwtDocument.proof[0].jwt : jwtDocument.proof.jwt
|
|
380
|
+
}
|
|
381
|
+
if (!proof) {
|
|
382
|
+
throw Error(`Could not get JWT from supplied document`)
|
|
383
|
+
}
|
|
384
|
+
return proof
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
static detectDocumentType(document: W3CVerifiableCredential | W3CVerifiablePresentation | JwtDecodedVerifiableCredential | JwtDecodedVerifiablePresentation): DocumentFormat {
|
|
388
|
+
if (typeof document === 'string') {
|
|
389
|
+
return this.isJsonLdAsString(document) ? DocumentFormat.JSONLD : DocumentFormat.JWT
|
|
390
|
+
}
|
|
391
|
+
const proofs = 'vc' in document ? document.vc.proof : 'vp' in document ? document.vp.proof : (<IVerifiableCredential>document).proof
|
|
392
|
+
const proof: IProof = Array.isArray(proofs) ? proofs[0] : proofs
|
|
393
|
+
|
|
394
|
+
if (proof.jwt) {
|
|
395
|
+
return DocumentFormat.JWT
|
|
396
|
+
} else if (proof.type === 'EthereumEip712Signature2021') {
|
|
397
|
+
return DocumentFormat.EIP712
|
|
398
|
+
}
|
|
399
|
+
return DocumentFormat.JSONLD
|
|
400
|
+
}
|
|
245
401
|
}
|
package/src/types/did.ts
CHANGED
|
@@ -19,6 +19,7 @@ export enum IProofType {
|
|
|
19
19
|
JcsEd25519Signature2020 = 'JcsEd25519Signature2020',
|
|
20
20
|
BbsBlsSignatureProof2020 = 'BbsBlsSignatureProof2020',
|
|
21
21
|
BbsBlsBoundSignatureProof2020 = 'BbsBlsBoundSignatureProof2020',
|
|
22
|
+
JwtProof2020 = 'JwtProof2020'
|
|
22
23
|
}
|
|
23
24
|
|
|
24
25
|
export interface IParsedDID {
|
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
|
}
|
|
@@ -51,6 +53,7 @@ export interface IProof {
|
|
|
51
53
|
domain?: string // A string restricting the (usage of a) proof to the domain and protects against replay attacks
|
|
52
54
|
proofValue?: string // One of any number of valid representations of proof values
|
|
53
55
|
jws?: string // JWS based proof
|
|
56
|
+
jwt?: string //Jwt 2020 proof. Used to map a JWT VC onto a uniform presentation, and retain access to the original JWT
|
|
54
57
|
nonce?: string // Similar to challenge. A nonce to protect against replay attacks, used in some ZKP proofs
|
|
55
58
|
requiredRevealStatements?: string[] // The parts of the proof that must be revealed in a derived proof
|
|
56
59
|
|
|
@@ -89,8 +92,8 @@ export type W3CVerifiableCredential = IVerifiableCredential | CompactJWT
|
|
|
89
92
|
export interface IPresentation {
|
|
90
93
|
id?: string
|
|
91
94
|
'@context': ICredentialContextType | ICredentialContextType[]
|
|
92
|
-
type
|
|
93
|
-
verifiableCredential
|
|
95
|
+
type?: string | string[]
|
|
96
|
+
verifiableCredential?: W3CVerifiableCredential[]
|
|
94
97
|
presentation_submission?: PresentationSubmission
|
|
95
98
|
holder?: string
|
|
96
99
|
|
|
@@ -122,11 +125,11 @@ export interface WrappedVerifiableCredential {
|
|
|
122
125
|
/**
|
|
123
126
|
* The claim format, typically used during exchange transport protocols
|
|
124
127
|
*/
|
|
125
|
-
format:
|
|
128
|
+
format: CredentialFormat
|
|
126
129
|
/**
|
|
127
|
-
* Internal stable representation of a Credential
|
|
130
|
+
* Internal stable representation of a Credential
|
|
128
131
|
*/
|
|
129
|
-
credential:
|
|
132
|
+
credential: IVerifiableCredential
|
|
130
133
|
}
|
|
131
134
|
|
|
132
135
|
export interface WrappedVerifiablePresentation {
|
|
@@ -145,7 +148,7 @@ export interface WrappedVerifiablePresentation {
|
|
|
145
148
|
/**
|
|
146
149
|
* The claim format, typically used during exchange transport protocols
|
|
147
150
|
*/
|
|
148
|
-
format:
|
|
151
|
+
format: PresentationFormat
|
|
149
152
|
/**
|
|
150
153
|
* Internal stable representation of a Presentation without proofs, created based on https://www.w3.org/TR/vc-data-model/#jwt-decoding
|
|
151
154
|
*/
|
|
@@ -164,14 +167,14 @@ export enum OriginalType {
|
|
|
164
167
|
|
|
165
168
|
export interface UniformVerifiablePresentation {
|
|
166
169
|
'@context': ICredentialContextType | ICredentialContextType[]
|
|
167
|
-
type: string[]
|
|
170
|
+
type: string | string[]
|
|
168
171
|
verifiableCredential: WrappedVerifiableCredential[]
|
|
169
172
|
presentation_submission?: PresentationSubmission
|
|
170
173
|
holder?: string
|
|
171
174
|
}
|
|
172
175
|
|
|
173
176
|
export interface JwtDecodedVerifiableCredential {
|
|
174
|
-
vc:
|
|
177
|
+
vc: IVerifiableCredential
|
|
175
178
|
exp: string
|
|
176
179
|
iss: string
|
|
177
180
|
nbf: string
|
|
@@ -192,8 +195,16 @@ export interface JwtDecodedVerifiablePresentation {
|
|
|
192
195
|
[x: string]: any
|
|
193
196
|
}
|
|
194
197
|
|
|
195
|
-
export type
|
|
198
|
+
export type CredentialFormat = 'jwt' | 'ldp' | 'jwt_vc' | 'ldp_vc' | string
|
|
199
|
+
export type PresentationFormat = 'jwt' | 'ldp' | 'jwt_vp' | 'ldp_vp' | string
|
|
200
|
+
export type ClaimFormat = CredentialFormat | PresentationFormat
|
|
196
201
|
|
|
197
202
|
export type OriginalVerifiableCredential = W3CVerifiableCredential | JwtDecodedVerifiableCredential
|
|
198
203
|
export type OriginalVerifiablePresentation = W3CVerifiablePresentation | JwtDecodedVerifiablePresentation
|
|
199
204
|
export type Original = OriginalVerifiablePresentation | OriginalVerifiableCredential
|
|
205
|
+
|
|
206
|
+
export const enum DocumentFormat {
|
|
207
|
+
JWT,
|
|
208
|
+
JSONLD,
|
|
209
|
+
EIP712,
|
|
210
|
+
}
|