@sphereon/ssi-types 0.8.1-next.6 → 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.
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/mapper/credential-mapper.d.ts +37 -0
- package/dist/mapper/credential-mapper.d.ts.map +1 -0
- package/dist/mapper/credential-mapper.js +221 -0
- package/dist/mapper/credential-mapper.js.map +1 -0
- package/dist/mapper/index.d.ts +2 -0
- package/dist/mapper/index.d.ts.map +1 -0
- package/dist/mapper/index.js +18 -0
- package/dist/mapper/index.js.map +1 -0
- package/dist/types/pex.d.ts +1 -12
- package/dist/types/pex.d.ts.map +1 -1
- package/dist/types/vc.d.ts +78 -30
- package/dist/types/vc.d.ts.map +1 -1
- package/dist/types/vc.js +7 -7
- package/dist/types/vc.js.map +1 -1
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +18 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/object.d.ts +7 -0
- package/dist/utils/object.d.ts.map +1 -0
- package/dist/utils/object.js +21 -0
- package/dist/utils/object.js.map +1 -0
- package/package.json +16 -3
- package/src/index.ts +2 -0
- package/src/mapper/credential-mapper.ts +275 -0
- package/src/mapper/index.ts +1 -0
- package/src/types/pex.ts +1 -13
- package/src/types/vc.ts +89 -32
- package/src/utils/index.ts +1 -0
- package/src/utils/object.ts +19 -0
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAA;AACvB,cAAc,SAAS,CAAA;AACvB,cAAc,UAAU,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -15,4 +15,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./types"), exports);
|
|
18
|
+
__exportStar(require("./utils"), exports);
|
|
19
|
+
__exportStar(require("./mapper"), exports);
|
|
18
20
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAuB"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAuB;AACvB,0CAAuB;AACvB,2CAAwB"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { ICredential, IPresentation, IVerifiableCredential, IVerifiablePresentation, JwtDecodedVerifiableCredential, JwtDecodedVerifiablePresentation, OriginalVerifiableCredential, OriginalVerifiablePresentation, WrappedVerifiableCredential, WrappedVerifiablePresentation } from '../types';
|
|
2
|
+
export declare class CredentialMapper {
|
|
3
|
+
static decodeVerifiablePresentation(presentation: OriginalVerifiablePresentation): JwtDecodedVerifiablePresentation | IVerifiablePresentation;
|
|
4
|
+
static decodeVerifiableCredential(credential: OriginalVerifiableCredential): JwtDecodedVerifiableCredential | IVerifiableCredential;
|
|
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;
|
|
14
|
+
static isJwtEncoded(original: OriginalVerifiableCredential | OriginalVerifiablePresentation): boolean;
|
|
15
|
+
private static isJsonLdString;
|
|
16
|
+
static isJwtDecodedCredential(original: OriginalVerifiableCredential): boolean;
|
|
17
|
+
static isJwtDecodedPresentation(original: OriginalVerifiablePresentation): boolean;
|
|
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
|
+
}
|
|
37
|
+
//# sourceMappingURL=credential-mapper.d.ts.map
|
|
@@ -0,0 +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,E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AAM,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"}
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.CredentialMapper = void 0;
|
|
7
|
+
const types_1 = require("../types");
|
|
8
|
+
const jwt_decode_1 = __importDefault(require("jwt-decode"));
|
|
9
|
+
const utils_1 = require("../utils");
|
|
10
|
+
class CredentialMapper {
|
|
11
|
+
static decodeVerifiablePresentation(presentation) {
|
|
12
|
+
if (CredentialMapper.isJwtEncoded(presentation)) {
|
|
13
|
+
return (0, jwt_decode_1.default)(presentation);
|
|
14
|
+
}
|
|
15
|
+
else if (CredentialMapper.isJwtDecodedPresentation(presentation)) {
|
|
16
|
+
return presentation;
|
|
17
|
+
}
|
|
18
|
+
else if (CredentialMapper.isJsonLdString(presentation)) {
|
|
19
|
+
return JSON.parse(presentation);
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
return presentation;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
static decodeVerifiableCredential(credential) {
|
|
26
|
+
if (CredentialMapper.isJwtEncoded(credential)) {
|
|
27
|
+
return (0, jwt_decode_1.default)(credential);
|
|
28
|
+
}
|
|
29
|
+
else if (CredentialMapper.isJwtDecodedCredential(credential)) {
|
|
30
|
+
return credential;
|
|
31
|
+
}
|
|
32
|
+
else if (CredentialMapper.isJsonLdString(credential)) {
|
|
33
|
+
return JSON.parse(credential);
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
return credential;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
static toWrappedVerifiablePresentation(presentation, opts) {
|
|
40
|
+
const original = presentation;
|
|
41
|
+
const isJwtEncoded = CredentialMapper.isJwtEncoded(original);
|
|
42
|
+
const isJwtDecoded = CredentialMapper.isJwtDecodedPresentation(original);
|
|
43
|
+
const type = isJwtEncoded ? types_1.OriginalType.JWT_ENCODED : isJwtDecoded ? types_1.OriginalType.JWT_DECODED : types_1.OriginalType.JSONLD;
|
|
44
|
+
const format = isJwtDecoded || isJwtEncoded ? 'jwt_vp' : 'ldp_vp';
|
|
45
|
+
const decoded = CredentialMapper.decodeVerifiablePresentation(original);
|
|
46
|
+
const vp = isJwtEncoded || isJwtDecoded
|
|
47
|
+
? CredentialMapper.jwtDecodedPresentationToUniformPresentation(decoded, false, opts)
|
|
48
|
+
: decoded;
|
|
49
|
+
const vcs = CredentialMapper.toWrappedVerifiableCredentials(vp.verifiableCredential, opts);
|
|
50
|
+
// todo: We probably want to add proofs as well
|
|
51
|
+
return {
|
|
52
|
+
type,
|
|
53
|
+
format,
|
|
54
|
+
original,
|
|
55
|
+
decoded,
|
|
56
|
+
presentation: Object.assign(Object.assign({}, vp), { verifiableCredential: vcs }),
|
|
57
|
+
vcs,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
static toWrappedVerifiableCredentials(verifiableCredentials, opts) {
|
|
61
|
+
return verifiableCredentials.map((vc) => CredentialMapper.toWrappedVerifiableCredential(vc, opts));
|
|
62
|
+
}
|
|
63
|
+
static toWrappedVerifiableCredential(verifiableCredential, opts) {
|
|
64
|
+
const original = verifiableCredential;
|
|
65
|
+
const decoded = CredentialMapper.decodeVerifiableCredential(verifiableCredential);
|
|
66
|
+
const isJwtEncoded = CredentialMapper.isJwtEncoded(original);
|
|
67
|
+
const isJwtDecoded = CredentialMapper.isJwtDecodedCredential(original);
|
|
68
|
+
const type = isJwtEncoded ? types_1.OriginalType.JWT_ENCODED : isJwtDecoded ? types_1.OriginalType.JWT_DECODED : types_1.OriginalType.JSONLD;
|
|
69
|
+
const credential = isJwtDecoded || isJwtDecoded
|
|
70
|
+
? CredentialMapper.jwtDecodedCredentialToUniformCredential(decoded, opts)
|
|
71
|
+
: decoded;
|
|
72
|
+
const format = isJwtDecoded || isJwtDecoded ? 'jwt_vc' : 'ldp_vc';
|
|
73
|
+
//todo: We probably want to add proofs as well
|
|
74
|
+
return {
|
|
75
|
+
original,
|
|
76
|
+
decoded,
|
|
77
|
+
format,
|
|
78
|
+
type,
|
|
79
|
+
credential,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
static isJwtEncoded(original) {
|
|
83
|
+
return utils_1.ObjectUtils.isString(original) && original.startsWith('ey');
|
|
84
|
+
}
|
|
85
|
+
static isJsonLdString(original) {
|
|
86
|
+
return utils_1.ObjectUtils.isString(original) && original.includes('@context');
|
|
87
|
+
}
|
|
88
|
+
static isJwtDecodedCredential(original) {
|
|
89
|
+
return original['vc'] !== undefined && original['iss'] !== undefined;
|
|
90
|
+
}
|
|
91
|
+
static isJwtDecodedPresentation(original) {
|
|
92
|
+
return original['vp'] !== undefined && original['iss'] !== undefined;
|
|
93
|
+
}
|
|
94
|
+
static jwtEncodedPresentationToUniformPresentation(jwt, makeCredentialsUniform = true, opts) {
|
|
95
|
+
return CredentialMapper.jwtDecodedPresentationToUniformPresentation((0, jwt_decode_1.default)(jwt), makeCredentialsUniform, opts);
|
|
96
|
+
}
|
|
97
|
+
static jwtDecodedPresentationToUniformPresentation(decoded, makeCredentialsUniform = true, opts) {
|
|
98
|
+
const presentation = Object.assign({}, decoded.vp);
|
|
99
|
+
if (makeCredentialsUniform) {
|
|
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
|
+
}
|
|
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
|
+
if (decoded.iss) {
|
|
105
|
+
const holder = presentation.holder;
|
|
106
|
+
if (holder) {
|
|
107
|
+
if (holder !== decoded.iss) {
|
|
108
|
+
throw new Error(`Inconsistent holders between JWT claim (${decoded.iss}) and VC value (${holder})`);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
presentation.holder = decoded.iss;
|
|
112
|
+
}
|
|
113
|
+
if (decoded.jti) {
|
|
114
|
+
const id = presentation.id;
|
|
115
|
+
if (id && id !== decoded.jti) {
|
|
116
|
+
throw new Error(`Inconsistent VP ids between JWT claim (${decoded.jti}) and VP value (${id})`);
|
|
117
|
+
}
|
|
118
|
+
presentation.id = decoded.jti;
|
|
119
|
+
}
|
|
120
|
+
return presentation;
|
|
121
|
+
}
|
|
122
|
+
static toUniformCredential(verifiableCredential, opts) {
|
|
123
|
+
const original = verifiableCredential;
|
|
124
|
+
const decoded = CredentialMapper.decodeVerifiableCredential(verifiableCredential);
|
|
125
|
+
const isJwtEncoded = CredentialMapper.isJwtEncoded(original);
|
|
126
|
+
const isJwtDecoded = CredentialMapper.isJwtDecodedCredential(original);
|
|
127
|
+
if (isJwtDecoded || isJwtEncoded) {
|
|
128
|
+
return CredentialMapper.jwtDecodedCredentialToUniformCredential(decoded, opts);
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
return decoded;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
static toUniformPresentation(presentation, opts) {
|
|
135
|
+
var _a;
|
|
136
|
+
const original = presentation;
|
|
137
|
+
const decoded = CredentialMapper.decodeVerifiablePresentation(original);
|
|
138
|
+
const isJwtEncoded = CredentialMapper.isJwtEncoded(original);
|
|
139
|
+
const isJwtDecoded = CredentialMapper.isJwtDecodedPresentation(original);
|
|
140
|
+
const uniformPresentation = isJwtEncoded || isJwtDecoded
|
|
141
|
+
? CredentialMapper.jwtDecodedPresentationToUniformPresentation(decoded, false)
|
|
142
|
+
: decoded;
|
|
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
|
+
return uniformPresentation;
|
|
145
|
+
}
|
|
146
|
+
static jwtEncodedCredentialToUniformCredential(jwt, opts) {
|
|
147
|
+
return CredentialMapper.jwtDecodedCredentialToUniformCredential((0, jwt_decode_1.default)(jwt), opts);
|
|
148
|
+
}
|
|
149
|
+
static jwtDecodedCredentialToUniformCredential(decoded, opts) {
|
|
150
|
+
const credential = Object.assign({}, decoded.vc);
|
|
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
|
+
delete credential.proof;
|
|
153
|
+
const maxSkewInMS = (opts === null || opts === void 0 ? void 0 : opts.maxTimeSkewInMS) !== undefined ? opts.maxTimeSkewInMS : 999;
|
|
154
|
+
if (decoded.exp) {
|
|
155
|
+
const expDate = credential.expirationDate;
|
|
156
|
+
const jwtExp = parseInt(decoded.exp.toString());
|
|
157
|
+
// fix seconds to millisecs for the date
|
|
158
|
+
const expDateAsStr = jwtExp < 9999999999 ? new Date(jwtExp * 1000).toISOString().replace(/\.000Z/, 'Z') : new Date(jwtExp).toISOString();
|
|
159
|
+
if (expDate && expDate !== expDateAsStr) {
|
|
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
|
+
}
|
|
164
|
+
}
|
|
165
|
+
credential.expirationDate = expDateAsStr;
|
|
166
|
+
}
|
|
167
|
+
if (decoded.nbf) {
|
|
168
|
+
const issuanceDate = credential.issuanceDate;
|
|
169
|
+
const jwtNbf = parseInt(decoded.nbf.toString());
|
|
170
|
+
// fix seconds to millisecs for the date
|
|
171
|
+
const nbfDateAsStr = jwtNbf < 9999999999 ? new Date(jwtNbf * 1000).toISOString().replace(/\.000Z/, 'Z') : new Date(jwtNbf).toISOString();
|
|
172
|
+
if (issuanceDate && issuanceDate !== nbfDateAsStr) {
|
|
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
|
+
}
|
|
177
|
+
}
|
|
178
|
+
credential.issuanceDate = nbfDateAsStr;
|
|
179
|
+
}
|
|
180
|
+
if (decoded.iss) {
|
|
181
|
+
const issuer = credential.issuer;
|
|
182
|
+
if (issuer) {
|
|
183
|
+
if (typeof issuer === 'string') {
|
|
184
|
+
if (issuer !== decoded.iss) {
|
|
185
|
+
throw new Error(`Inconsistent issuers between JWT claim (${decoded.iss}) and VC value (${issuer})`);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
if (issuer.id !== decoded.iss) {
|
|
190
|
+
throw new Error(`Inconsistent issuers between JWT claim (${decoded.iss}) and VC value (${issuer.id})`);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
credential.issuer = decoded.iss;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
if (decoded.sub) {
|
|
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);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
if (decoded.jti) {
|
|
211
|
+
const id = credential.id;
|
|
212
|
+
if (id && id !== decoded.jti) {
|
|
213
|
+
throw new Error(`Inconsistent credential ids between JWT claim (${decoded.jti}) and VC value (${id})`);
|
|
214
|
+
}
|
|
215
|
+
credential.id = decoded.jti;
|
|
216
|
+
}
|
|
217
|
+
return credential;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
exports.CredentialMapper = CredentialMapper;
|
|
221
|
+
//# sourceMappingURL=credential-mapper.js.map
|
|
@@ -0,0 +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,gBAAg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xC,MAAM,IAAI,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,CAAA;gBAC3B,IAAI,IAAI,IAAI,IAAI,KAAK,OAAO,CAAC,GAAG,EAAE;oBAChC,MAAM,IAAI,KAAK,CAAC,0DAA0D,OAAO,CAAC,GAAG,mBAAmB,IAAI,GAAG,CAAC,CAAA;iBACjH;gBACD,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,iBAAiB,CAAC;oBACzC,CAAC,CAAC,CAAC,UAAU,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC;oBACpD,CAAC,CAAC,CAAC,UAAU,CAAC,iBAAiB,CAAC,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC,CAAA;aACpD;SACF;QACD,IAAI,OAAO,CAAC,GAAG,EAAE;YACf,MAAM,EAAE,GAAG,UAAU,CAAC,EAAE,CAAA;YACxB,IAAI,EAAE,IAAI,EAAE,KAAK,OAAO,CAAC,GAAG,EAAE;gBAC5B,MAAM,IAAI,KAAK,CAAC,kDAAkD,OAAO,CAAC,GAAG,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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/mapper/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./credential-mapper"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/mapper/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,sDAAmC"}
|
package/dist/types/pex.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* It
|
|
2
|
+
* It expresses how the inputs are presented as proofs to a Verifier.
|
|
3
3
|
*/
|
|
4
4
|
export interface PresentationSubmission {
|
|
5
5
|
/**
|
|
@@ -15,17 +15,6 @@ export interface PresentationSubmission {
|
|
|
15
15
|
*/
|
|
16
16
|
descriptor_map: Array<Descriptor>;
|
|
17
17
|
}
|
|
18
|
-
/**
|
|
19
|
-
* Presentation Echange API
|
|
20
|
-
* Presentation Exchange API
|
|
21
|
-
*
|
|
22
|
-
* The version of the OpenAPI document: 1.1.0
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
|
26
|
-
* https://openapi-generator.tech
|
|
27
|
-
* Do not edit the class manually.
|
|
28
|
-
*/
|
|
29
18
|
/**
|
|
30
19
|
* descriptor map laying out the structure of the presentation submission.
|
|
31
20
|
*/
|
package/dist/types/pex.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pex.d.ts","sourceRoot":"","sources":["../../src/types/pex.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC;;OAEG;IACH,EAAE,EAAE,MAAM,CAAA;IACV;;OAEG;IACH,aAAa,EAAE,MAAM,CAAA;IACrB;;OAEG;IACH,cAAc,EAAE,KAAK,CAAC,UAAU,CAAC,CAAA;CAClC;AAED
|
|
1
|
+
{"version":3,"file":"pex.d.ts","sourceRoot":"","sources":["../../src/types/pex.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC;;OAEG;IACH,EAAE,EAAE,MAAM,CAAA;IACV;;OAEG;IACH,aAAa,EAAE,MAAM,CAAA;IACrB;;OAEG;IACH,cAAc,EAAE,KAAK,CAAC,UAAU,CAAC,CAAA;CAClC;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB;;OAEG;IACH,EAAE,EAAE,MAAM,CAAA;IACV;;OAEG;IACH,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,CAAC,EAAE,UAAU,CAAA;IACxB;;OAEG;IACH,MAAM,EAAE,MAAM,CAAA;CACf"}
|
package/dist/types/vc.d.ts
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
import { PresentationSubmission } from './pex';
|
|
2
2
|
import { IProofPurpose, IProofType } from './did';
|
|
3
|
+
export declare type AdditionalClaims = Record<string, any>;
|
|
4
|
+
export declare type IIssuerId = string;
|
|
3
5
|
export interface ICredential {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
+
'@context': ICredentialContextType | ICredentialContextType[];
|
|
7
|
+
type: string[];
|
|
8
|
+
credentialSchema?: undefined | ICredentialSchemaType | ICredentialSchemaType[];
|
|
9
|
+
issuer: IIssuerId | IIssuer;
|
|
6
10
|
issuanceDate: string;
|
|
7
|
-
credentialSubject: ICredentialSubject;
|
|
11
|
+
credentialSubject: (ICredentialSubject & AdditionalClaims) | (ICredentialSubject & AdditionalClaims)[];
|
|
12
|
+
expirationDate?: string;
|
|
8
13
|
id?: string;
|
|
9
|
-
'@context': ICredentialContextType[] | ICredentialContextType;
|
|
10
14
|
credentialStatus?: ICredentialStatus;
|
|
11
|
-
credentialSchema?: undefined | ICredentialSchemaType | ICredentialSchemaType[];
|
|
12
15
|
description?: string;
|
|
13
16
|
name?: string;
|
|
14
|
-
|
|
15
|
-
[x: string]: unknown;
|
|
17
|
+
[x: string]: any;
|
|
16
18
|
}
|
|
17
19
|
export interface ICredentialSubject {
|
|
18
20
|
id?: string;
|
|
19
|
-
[x: string]: unknown;
|
|
20
21
|
}
|
|
21
|
-
export declare type ICredentialContextType = ICredentialContext | string;
|
|
22
|
+
export declare type ICredentialContextType = (ICredentialContext & AdditionalClaims) | string;
|
|
22
23
|
export interface ICredentialContext {
|
|
23
24
|
name?: string;
|
|
24
25
|
did?: string;
|
|
25
|
-
[x: string]: unknown;
|
|
26
26
|
}
|
|
27
27
|
export declare type ICredentialSchemaType = ICredentialSchema | string;
|
|
28
28
|
export interface ICredentialSchema {
|
|
@@ -40,7 +40,7 @@ export interface IProof {
|
|
|
40
40
|
jws?: string;
|
|
41
41
|
nonce?: string;
|
|
42
42
|
requiredRevealStatements?: string[];
|
|
43
|
-
[x: string]:
|
|
43
|
+
[x: string]: any;
|
|
44
44
|
}
|
|
45
45
|
export interface ICredentialStatus {
|
|
46
46
|
id: string;
|
|
@@ -48,72 +48,120 @@ export interface ICredentialStatus {
|
|
|
48
48
|
}
|
|
49
49
|
export interface IIssuer {
|
|
50
50
|
id: string;
|
|
51
|
-
[x: string]:
|
|
51
|
+
[x: string]: any;
|
|
52
52
|
}
|
|
53
53
|
export interface IHasProof {
|
|
54
54
|
proof: IProof | IProof[];
|
|
55
55
|
}
|
|
56
56
|
export declare type IVerifiableCredential = ICredential & IHasProof;
|
|
57
|
+
/**
|
|
58
|
+
* Represents a Json Web Token in compact form.
|
|
59
|
+
*/
|
|
60
|
+
export declare type CompactJWT = string;
|
|
61
|
+
/**
|
|
62
|
+
* Represents a signed Verifiable Credential (includes proof), in either JSON or compact JWT format.
|
|
63
|
+
* See {@link https://www.w3.org/TR/vc-data-model/#credentials | VC data model}
|
|
64
|
+
* See {@link https://www.w3.org/TR/vc-data-model/#proof-formats | proof formats}
|
|
65
|
+
*/
|
|
66
|
+
export declare type W3CVerifiableCredential = IVerifiableCredential | CompactJWT;
|
|
57
67
|
export interface IPresentation {
|
|
58
68
|
id?: string;
|
|
59
69
|
'@context': ICredentialContextType | ICredentialContextType[];
|
|
60
70
|
type: string[];
|
|
61
|
-
verifiableCredential:
|
|
71
|
+
verifiableCredential: W3CVerifiableCredential[];
|
|
62
72
|
presentation_submission?: PresentationSubmission;
|
|
63
73
|
holder?: string;
|
|
74
|
+
[x: string]: any;
|
|
64
75
|
}
|
|
65
76
|
export declare type IVerifiablePresentation = IPresentation & IHasProof;
|
|
77
|
+
/**
|
|
78
|
+
* Represents a signed Verifiable Presentation (includes proof), in either JSON or compact JWT format.
|
|
79
|
+
* See {@link https://www.w3.org/TR/vc-data-model/#presentations | VC data model}
|
|
80
|
+
* See {@link https://www.w3.org/TR/vc-data-model/#proof-formats | proof formats}
|
|
81
|
+
*/
|
|
82
|
+
export declare type W3CVerifiablePresentation = IVerifiablePresentation | CompactJWT;
|
|
66
83
|
export interface WrappedVerifiableCredential {
|
|
67
84
|
/**
|
|
68
85
|
* Original VC that we've received
|
|
69
86
|
*/
|
|
70
|
-
original:
|
|
87
|
+
original: OriginalVerifiableCredential;
|
|
71
88
|
/**
|
|
72
89
|
* In case of JWT credential it will be the decoded version. In other cases it will be the same as original one
|
|
73
90
|
*/
|
|
74
|
-
decoded:
|
|
91
|
+
decoded: JwtDecodedVerifiableCredential | IVerifiableCredential;
|
|
92
|
+
/**
|
|
93
|
+
* Type of this credential. Supported types are json-ld and jwt (decoded/encoded)
|
|
94
|
+
*/
|
|
95
|
+
type: OriginalType;
|
|
75
96
|
/**
|
|
76
|
-
*
|
|
97
|
+
* The claim format, typically used during exchange transport protocols
|
|
77
98
|
*/
|
|
78
|
-
|
|
99
|
+
format: CredentialFormat;
|
|
79
100
|
/**
|
|
80
|
-
* created based on https://www.w3.org/TR/vc-data-model/#jwt-decoding
|
|
101
|
+
* Internal stable representation of a Credential without Proofs, created based on https://www.w3.org/TR/vc-data-model/#jwt-decoding
|
|
81
102
|
*/
|
|
82
|
-
|
|
103
|
+
credential: ICredential;
|
|
83
104
|
}
|
|
84
105
|
export interface WrappedVerifiablePresentation {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
106
|
+
/**
|
|
107
|
+
* Original VP that we've received
|
|
108
|
+
*/
|
|
109
|
+
original: OriginalVerifiablePresentation;
|
|
110
|
+
/**
|
|
111
|
+
* In case of JWT VP it will be the decoded version. In other cases it will be the same as original one
|
|
112
|
+
*/
|
|
113
|
+
decoded: JwtDecodedVerifiablePresentation | IVerifiablePresentation;
|
|
114
|
+
/**
|
|
115
|
+
* Type of this Presentation. Supported types are json-ld and jwt (decoded/encoded)
|
|
116
|
+
*/
|
|
117
|
+
type: OriginalType;
|
|
118
|
+
/**
|
|
119
|
+
* The claim format, typically used during exchange transport protocols
|
|
120
|
+
*/
|
|
121
|
+
format: PresentationFormat;
|
|
122
|
+
/**
|
|
123
|
+
* Internal stable representation of a Presentation without proofs, created based on https://www.w3.org/TR/vc-data-model/#jwt-decoding
|
|
124
|
+
*/
|
|
125
|
+
presentation: UniformVerifiablePresentation;
|
|
126
|
+
/**
|
|
127
|
+
* Wrapped Verifiable Credentials belonging to the Presentation
|
|
128
|
+
*/
|
|
89
129
|
vcs: WrappedVerifiableCredential[];
|
|
90
130
|
}
|
|
91
|
-
export declare enum
|
|
92
|
-
JSONLD =
|
|
93
|
-
JWT_ENCODED =
|
|
94
|
-
JWT_DECODED =
|
|
131
|
+
export declare enum OriginalType {
|
|
132
|
+
JSONLD = "json-ld",
|
|
133
|
+
JWT_ENCODED = "jwt-encoded",
|
|
134
|
+
JWT_DECODED = "jwt-decoded"
|
|
95
135
|
}
|
|
96
|
-
export interface
|
|
136
|
+
export interface UniformVerifiablePresentation {
|
|
97
137
|
'@context': ICredentialContextType | ICredentialContextType[];
|
|
98
138
|
type: string[];
|
|
99
139
|
verifiableCredential: WrappedVerifiableCredential[];
|
|
100
140
|
presentation_submission?: PresentationSubmission;
|
|
101
141
|
holder?: string;
|
|
102
142
|
}
|
|
103
|
-
export interface
|
|
143
|
+
export interface JwtDecodedVerifiableCredential {
|
|
104
144
|
vc: ICredential;
|
|
105
145
|
exp: string;
|
|
106
146
|
iss: string;
|
|
107
147
|
nbf: string;
|
|
108
148
|
sub: string;
|
|
109
149
|
jti: string;
|
|
150
|
+
[x: string]: any;
|
|
110
151
|
}
|
|
111
|
-
export interface
|
|
152
|
+
export interface JwtDecodedVerifiablePresentation {
|
|
112
153
|
vp: IVerifiablePresentation;
|
|
113
154
|
exp: string;
|
|
114
155
|
iss: string;
|
|
115
156
|
nbf: string;
|
|
116
157
|
sub: string;
|
|
117
158
|
jti: string;
|
|
159
|
+
[x: string]: any;
|
|
118
160
|
}
|
|
161
|
+
export declare type CredentialFormat = 'jwt' | 'ldp' | 'jwt_vc' | 'ldp_vc' | string;
|
|
162
|
+
export declare type PresentationFormat = 'jwt' | 'ldp' | 'jwt_vp' | 'ldp_vp' | string;
|
|
163
|
+
export declare type ClaimFormat = CredentialFormat | PresentationFormat;
|
|
164
|
+
export declare type OriginalVerifiableCredential = W3CVerifiableCredential | JwtDecodedVerifiableCredential;
|
|
165
|
+
export declare type OriginalVerifiablePresentation = W3CVerifiablePresentation | JwtDecodedVerifiablePresentation;
|
|
166
|
+
export declare type Original = OriginalVerifiablePresentation | OriginalVerifiableCredential;
|
|
119
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"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AAED,MAAM,WAAW,8BAA8B;IAC7C,EAAE,EAAE,WAAW,CAAA;IACf,GAAG,EAAE,MAAM,CAAA;IACX,GAAG,EAAE,MAAM,CAAA;IACX,GAAG,EAAE,MAAM,CAAA;IACX,GAAG,EAAE,MAAM,CAAA;IACX,GAAG,EAAE,MAAM,CAAA;IAEX,CAAC,CAAC,EAAE,MAAM,GAAG,GAAG,CAAA;CACjB;AAED,MAAM,WAAW,gCAAgC;IAC/C,EAAE,EAAE,uBAAuB,CAAA;IAC3B,GAAG,EAAE,MAAM,CAAA;IACX,GAAG,EAAE,MAAM,CAAA;IACX,GAAG,EAAE,MAAM,CAAA;IACX,GAAG,EAAE,MAAM,CAAA;IACX,GAAG,EAAE,MAAM,CAAA;IAEX,CAAC,CAAC,EAAE,MAAM,GAAG,GAAG,CAAA;CACjB;AAED,oBAAY,gBAAgB,GAAG,KAAK,GAAG,KAAK,GAAG,QAAQ,GAAG,QAAQ,GAAG,MAAM,CAAA;AAC3E,oBAAY,kBAAkB,GAAG,KAAK,GAAG,KAAK,GAAG,QAAQ,GAAG,QAAQ,GAAG,MAAM,CAAA;AAC7E,oBAAY,WAAW,GAAG,gBAAgB,GAAG,kBAAkB,CAAA;AAE/D,oBAAY,4BAA4B,GAAG,uBAAuB,GAAG,8BAA8B,CAAA;AACnG,oBAAY,8BAA8B,GAAG,yBAAyB,GAAG,gCAAgC,CAAA;AACzG,oBAAY,QAAQ,GAAG,8BAA8B,GAAG,4BAA4B,CAAA"}
|
package/dist/types/vc.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
var
|
|
5
|
-
(function (
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
})(
|
|
3
|
+
exports.OriginalType = void 0;
|
|
4
|
+
var OriginalType;
|
|
5
|
+
(function (OriginalType) {
|
|
6
|
+
OriginalType["JSONLD"] = "json-ld";
|
|
7
|
+
OriginalType["JWT_ENCODED"] = "jwt-encoded";
|
|
8
|
+
OriginalType["JWT_DECODED"] = "jwt-decoded";
|
|
9
|
+
})(OriginalType = exports.OriginalType || (exports.OriginalType = {}));
|
|
10
10
|
//# 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":";;;AAgKA,IAAY,YAIX;AAJD,WAAY,YAAY;IACtB,kCAAkB,CAAA;IAClB,2CAA2B,CAAA;IAC3B,2CAA2B,CAAA;AAC7B,CAAC,EAJW,YAAY,GAAZ,oBAAY,KAAZ,oBAAY,QAIvB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./object"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAwB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"object.d.ts","sourceRoot":"","sources":["../../src/utils/object.ts"],"names":[],"mappings":"AAAA,qBAAa,WAAW;WACR,OAAO,CAAC,KAAK,EAAE,OAAO;WAItB,QAAQ,CAAC,KAAK,EAAE,OAAO;WAIvB,aAAa,CAAC,GAAG,EAAE,MAAM;WAMzB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO;CAGhD"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ObjectUtils = void 0;
|
|
4
|
+
class ObjectUtils {
|
|
5
|
+
static asArray(value) {
|
|
6
|
+
return Array.isArray(value) ? value : [value];
|
|
7
|
+
}
|
|
8
|
+
static isObject(value) {
|
|
9
|
+
return Object.prototype.toString.call(value) === '[object Object]';
|
|
10
|
+
}
|
|
11
|
+
static isUrlAbsolute(url) {
|
|
12
|
+
// regex to check for absolute IRI (starting scheme and ':') or blank node IRI
|
|
13
|
+
const isAbsoluteRegex = /^([A-Za-z][A-Za-z0-9+-.]*|_):[^\s]*$/;
|
|
14
|
+
ObjectUtils.isString(url) && isAbsoluteRegex.test(url);
|
|
15
|
+
}
|
|
16
|
+
static isString(value) {
|
|
17
|
+
return typeof value === 'string' || Object.prototype.toString.call(value) === '[object String]';
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.ObjectUtils = ObjectUtils;
|
|
21
|
+
//# sourceMappingURL=object.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"object.js","sourceRoot":"","sources":["../../src/utils/object.ts"],"names":[],"mappings":";;;AAAA,MAAa,WAAW;IACf,MAAM,CAAC,OAAO,CAAC,KAAc;QAClC,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAA;IAC/C,CAAC;IAEM,MAAM,CAAC,QAAQ,CAAC,KAAc;QACnC,OAAO,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,iBAAiB,CAAA;IACpE,CAAC;IAEM,MAAM,CAAC,aAAa,CAAC,GAAW;QACrC,8EAA8E;QAC9E,MAAM,eAAe,GAAG,sCAAsC,CAAA;QAC9D,WAAW,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,eAAe,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;IACxD,CAAC;IAEM,MAAM,CAAC,QAAQ,CAAC,KAAc;QACnC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,iBAAiB,CAAA;IACjG,CAAC;CACF;AAlBD,kCAkBC"}
|
package/package.json
CHANGED
|
@@ -1,13 +1,20 @@
|
|
|
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": {
|
|
8
8
|
"build": "tsc --build"
|
|
9
9
|
},
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"jwt-decode": "^3.1.2"
|
|
12
|
+
},
|
|
10
13
|
"devDependencies": {
|
|
14
|
+
"@types/jest": "^27.0.2",
|
|
15
|
+
"jest": "^27.3.1",
|
|
16
|
+
"prettier": "^2.4.1",
|
|
17
|
+
"ts-jest": "^27.0.7",
|
|
11
18
|
"typescript": "4.6.4"
|
|
12
19
|
},
|
|
13
20
|
"files": [
|
|
@@ -23,6 +30,12 @@
|
|
|
23
30
|
"repository": "git@github.com:Sphereon-OpenSource/ssi-sdk.git",
|
|
24
31
|
"author": "Sphereon <dev@sphereon.com>",
|
|
25
32
|
"license": "Apache-2.0",
|
|
26
|
-
"keywords": [
|
|
27
|
-
|
|
33
|
+
"keywords": [
|
|
34
|
+
"SSI",
|
|
35
|
+
"Common Credential Types",
|
|
36
|
+
"Credential Mapping",
|
|
37
|
+
"Verifiable Credentials",
|
|
38
|
+
"DIDs"
|
|
39
|
+
],
|
|
40
|
+
"gitHead": "473b111b98030a1f795ff1e521ce17caf202b4b8"
|
|
28
41
|
}
|
package/src/index.ts
CHANGED
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ICredential,
|
|
3
|
+
IPresentation,
|
|
4
|
+
IVerifiableCredential,
|
|
5
|
+
IVerifiablePresentation,
|
|
6
|
+
JwtDecodedVerifiableCredential,
|
|
7
|
+
JwtDecodedVerifiablePresentation,
|
|
8
|
+
OriginalType,
|
|
9
|
+
OriginalVerifiableCredential,
|
|
10
|
+
OriginalVerifiablePresentation,
|
|
11
|
+
PresentationFormat,
|
|
12
|
+
WrappedVerifiableCredential,
|
|
13
|
+
WrappedVerifiablePresentation,
|
|
14
|
+
} from '../types'
|
|
15
|
+
import jwt_decode from 'jwt-decode'
|
|
16
|
+
import { ObjectUtils } from '../utils'
|
|
17
|
+
|
|
18
|
+
export class CredentialMapper {
|
|
19
|
+
static decodeVerifiablePresentation(presentation: OriginalVerifiablePresentation): JwtDecodedVerifiablePresentation | IVerifiablePresentation {
|
|
20
|
+
if (CredentialMapper.isJwtEncoded(presentation)) {
|
|
21
|
+
return jwt_decode(presentation as string) as JwtDecodedVerifiablePresentation
|
|
22
|
+
} else if (CredentialMapper.isJwtDecodedPresentation(presentation)) {
|
|
23
|
+
return presentation as JwtDecodedVerifiablePresentation
|
|
24
|
+
} else if (CredentialMapper.isJsonLdString(presentation)) {
|
|
25
|
+
return JSON.parse(presentation as string) as IVerifiablePresentation
|
|
26
|
+
} else {
|
|
27
|
+
return presentation as IVerifiablePresentation
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
static decodeVerifiableCredential(credential: OriginalVerifiableCredential): JwtDecodedVerifiableCredential | IVerifiableCredential {
|
|
32
|
+
if (CredentialMapper.isJwtEncoded(credential)) {
|
|
33
|
+
return jwt_decode(credential as string) as JwtDecodedVerifiableCredential
|
|
34
|
+
} else if (CredentialMapper.isJwtDecodedCredential(credential)) {
|
|
35
|
+
return credential as JwtDecodedVerifiableCredential
|
|
36
|
+
} else if (CredentialMapper.isJsonLdString(credential)) {
|
|
37
|
+
return JSON.parse(credential as string) as IVerifiableCredential
|
|
38
|
+
} else {
|
|
39
|
+
return credential as IVerifiableCredential
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
static toWrappedVerifiablePresentation(
|
|
44
|
+
presentation: OriginalVerifiablePresentation,
|
|
45
|
+
opts?: { maxTimeSkewInMS?: number }
|
|
46
|
+
): WrappedVerifiablePresentation {
|
|
47
|
+
const original = presentation
|
|
48
|
+
const isJwtEncoded: boolean = CredentialMapper.isJwtEncoded(original)
|
|
49
|
+
const isJwtDecoded: boolean = CredentialMapper.isJwtDecodedPresentation(original)
|
|
50
|
+
|
|
51
|
+
const type = isJwtEncoded ? OriginalType.JWT_ENCODED : isJwtDecoded ? OriginalType.JWT_DECODED : OriginalType.JSONLD
|
|
52
|
+
const format: PresentationFormat = isJwtDecoded || isJwtEncoded ? 'jwt_vp' : 'ldp_vp'
|
|
53
|
+
const decoded = CredentialMapper.decodeVerifiablePresentation(original)
|
|
54
|
+
const vp: IPresentation =
|
|
55
|
+
isJwtEncoded || isJwtDecoded
|
|
56
|
+
? CredentialMapper.jwtDecodedPresentationToUniformPresentation(decoded as JwtDecodedVerifiablePresentation, false, opts)
|
|
57
|
+
: (decoded as IPresentation)
|
|
58
|
+
const vcs: WrappedVerifiableCredential[] = CredentialMapper.toWrappedVerifiableCredentials(vp.verifiableCredential, opts)
|
|
59
|
+
|
|
60
|
+
// todo: We probably want to add proofs as well
|
|
61
|
+
return {
|
|
62
|
+
type,
|
|
63
|
+
format,
|
|
64
|
+
original,
|
|
65
|
+
decoded,
|
|
66
|
+
presentation: {
|
|
67
|
+
...vp,
|
|
68
|
+
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
|
|
69
|
+
},
|
|
70
|
+
vcs,
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
static toWrappedVerifiableCredentials(
|
|
75
|
+
verifiableCredentials: OriginalVerifiableCredential[],
|
|
76
|
+
opts?: { maxTimeSkewInMS?: number }
|
|
77
|
+
): WrappedVerifiableCredential[] {
|
|
78
|
+
return verifiableCredentials.map((vc) => CredentialMapper.toWrappedVerifiableCredential(vc, opts))
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
static toWrappedVerifiableCredential(
|
|
82
|
+
verifiableCredential: OriginalVerifiableCredential,
|
|
83
|
+
opts?: { maxTimeSkewInMS?: number }
|
|
84
|
+
): WrappedVerifiableCredential {
|
|
85
|
+
const original = verifiableCredential
|
|
86
|
+
|
|
87
|
+
const decoded = CredentialMapper.decodeVerifiableCredential(verifiableCredential)
|
|
88
|
+
|
|
89
|
+
const isJwtEncoded = CredentialMapper.isJwtEncoded(original)
|
|
90
|
+
const isJwtDecoded = CredentialMapper.isJwtDecodedCredential(original)
|
|
91
|
+
const type = isJwtEncoded ? OriginalType.JWT_ENCODED : isJwtDecoded ? OriginalType.JWT_DECODED : OriginalType.JSONLD
|
|
92
|
+
|
|
93
|
+
const credential =
|
|
94
|
+
isJwtDecoded || isJwtDecoded
|
|
95
|
+
? CredentialMapper.jwtDecodedCredentialToUniformCredential(decoded as JwtDecodedVerifiableCredential, opts)
|
|
96
|
+
: (decoded as ICredential)
|
|
97
|
+
const format = isJwtDecoded || isJwtDecoded ? 'jwt_vc' : 'ldp_vc'
|
|
98
|
+
//todo: We probably want to add proofs as well
|
|
99
|
+
return {
|
|
100
|
+
original,
|
|
101
|
+
decoded,
|
|
102
|
+
format,
|
|
103
|
+
type,
|
|
104
|
+
credential,
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
public static isJwtEncoded(original: OriginalVerifiableCredential | OriginalVerifiablePresentation) {
|
|
109
|
+
return ObjectUtils.isString(original) && (original as string).startsWith('ey')
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
private static isJsonLdString(original: OriginalVerifiableCredential | OriginalVerifiablePresentation) {
|
|
113
|
+
return ObjectUtils.isString(original) && (original as string).includes('@context')
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
public static isJwtDecodedCredential(original: OriginalVerifiableCredential): boolean {
|
|
117
|
+
return (<JwtDecodedVerifiableCredential>original)['vc'] !== undefined && (<JwtDecodedVerifiableCredential>original)['iss'] !== undefined
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
public static isJwtDecodedPresentation(original: OriginalVerifiablePresentation): boolean {
|
|
121
|
+
return (<JwtDecodedVerifiablePresentation>original)['vp'] !== undefined && (<JwtDecodedVerifiablePresentation>original)['iss'] !== undefined
|
|
122
|
+
}
|
|
123
|
+
|
|
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)
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
static jwtDecodedPresentationToUniformPresentation(
|
|
133
|
+
decoded: JwtDecodedVerifiablePresentation,
|
|
134
|
+
makeCredentialsUniform: boolean = true,
|
|
135
|
+
opts?: { maxTimeSkewInMS?: number }
|
|
136
|
+
): IPresentation {
|
|
137
|
+
const presentation: IPresentation = {
|
|
138
|
+
...(decoded.vp as IPresentation),
|
|
139
|
+
}
|
|
140
|
+
if (makeCredentialsUniform) {
|
|
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)
|
|
144
|
+
}
|
|
145
|
+
// Since this is a presentation, we delete any proof just to be sure (should not occur on JWT, but better safe than sorry)
|
|
146
|
+
delete presentation.proof
|
|
147
|
+
|
|
148
|
+
if (decoded.iss) {
|
|
149
|
+
const holder = presentation.holder
|
|
150
|
+
if (holder) {
|
|
151
|
+
if (holder !== decoded.iss) {
|
|
152
|
+
throw new Error(`Inconsistent holders between JWT claim (${decoded.iss}) and VC value (${holder})`)
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
presentation.holder = decoded.iss
|
|
156
|
+
}
|
|
157
|
+
if (decoded.jti) {
|
|
158
|
+
const id = presentation.id
|
|
159
|
+
if (id && id !== decoded.jti) {
|
|
160
|
+
throw new Error(`Inconsistent VP ids between JWT claim (${decoded.jti}) and VP value (${id})`)
|
|
161
|
+
}
|
|
162
|
+
presentation.id = decoded.jti
|
|
163
|
+
}
|
|
164
|
+
return presentation
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
static toUniformCredential(verifiableCredential: OriginalVerifiableCredential, opts?: { maxTimeSkewInMS?: number }): ICredential {
|
|
168
|
+
const original = verifiableCredential
|
|
169
|
+
const decoded = CredentialMapper.decodeVerifiableCredential(verifiableCredential)
|
|
170
|
+
|
|
171
|
+
const isJwtEncoded: boolean = CredentialMapper.isJwtEncoded(original)
|
|
172
|
+
const isJwtDecoded: boolean = CredentialMapper.isJwtDecodedCredential(original)
|
|
173
|
+
|
|
174
|
+
if (isJwtDecoded || isJwtEncoded) {
|
|
175
|
+
return CredentialMapper.jwtDecodedCredentialToUniformCredential(decoded as JwtDecodedVerifiableCredential, opts)
|
|
176
|
+
} else {
|
|
177
|
+
return decoded as ICredential
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
static toUniformPresentation(presentation: OriginalVerifiablePresentation, opts?: { maxTimeSkewInMS?: number }): IPresentation {
|
|
182
|
+
const original = presentation
|
|
183
|
+
const decoded = CredentialMapper.decodeVerifiablePresentation(original)
|
|
184
|
+
const isJwtEncoded: boolean = CredentialMapper.isJwtEncoded(original)
|
|
185
|
+
const isJwtDecoded: boolean = CredentialMapper.isJwtDecodedPresentation(original)
|
|
186
|
+
const uniformPresentation =
|
|
187
|
+
isJwtEncoded || isJwtDecoded
|
|
188
|
+
? CredentialMapper.jwtDecodedPresentationToUniformPresentation(decoded as JwtDecodedVerifiablePresentation, false)
|
|
189
|
+
: (decoded as IPresentation)
|
|
190
|
+
uniformPresentation.verifiableCredential = uniformPresentation.verifiableCredential?.map((vc) =>
|
|
191
|
+
CredentialMapper.toUniformCredential(vc, opts)
|
|
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)
|
|
193
|
+
return uniformPresentation
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
static jwtEncodedCredentialToUniformCredential(jwt: string, opts?: { maxTimeSkewInMS?: number }): ICredential {
|
|
197
|
+
return CredentialMapper.jwtDecodedCredentialToUniformCredential(jwt_decode(jwt), opts)
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
static jwtDecodedCredentialToUniformCredential(decoded: JwtDecodedVerifiableCredential, opts?: { maxTimeSkewInMS?: number }): ICredential {
|
|
201
|
+
const credential: ICredential = {
|
|
202
|
+
...(decoded.vc as ICredential),
|
|
203
|
+
}
|
|
204
|
+
// Since this is a credential, we delete any proof just to be sure (should not occur on JWT, but better safe than sorry)
|
|
205
|
+
delete credential.proof
|
|
206
|
+
|
|
207
|
+
const maxSkewInMS = opts?.maxTimeSkewInMS !== undefined ? opts.maxTimeSkewInMS : 999
|
|
208
|
+
|
|
209
|
+
if (decoded.exp) {
|
|
210
|
+
const expDate = credential.expirationDate
|
|
211
|
+
const jwtExp = parseInt(decoded.exp.toString())
|
|
212
|
+
// fix seconds to millisecs for the date
|
|
213
|
+
const expDateAsStr = jwtExp < 9999999999 ? new Date(jwtExp * 1000).toISOString().replace(/\.000Z/, 'Z') : new Date(jwtExp).toISOString()
|
|
214
|
+
if (expDate && expDate !== expDateAsStr) {
|
|
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
|
+
}
|
|
219
|
+
}
|
|
220
|
+
credential.expirationDate = expDateAsStr
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
if (decoded.nbf) {
|
|
224
|
+
const issuanceDate = credential.issuanceDate
|
|
225
|
+
const jwtNbf = parseInt(decoded.nbf.toString())
|
|
226
|
+
// fix seconds to millisecs for the date
|
|
227
|
+
const nbfDateAsStr = jwtNbf < 9999999999 ? new Date(jwtNbf * 1000).toISOString().replace(/\.000Z/, 'Z') : new Date(jwtNbf).toISOString()
|
|
228
|
+
if (issuanceDate && issuanceDate !== nbfDateAsStr) {
|
|
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
|
+
}
|
|
233
|
+
}
|
|
234
|
+
credential.issuanceDate = nbfDateAsStr
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
if (decoded.iss) {
|
|
238
|
+
const issuer = credential.issuer
|
|
239
|
+
if (issuer) {
|
|
240
|
+
if (typeof issuer === 'string') {
|
|
241
|
+
if (issuer !== decoded.iss) {
|
|
242
|
+
throw new Error(`Inconsistent issuers between JWT claim (${decoded.iss}) and VC value (${issuer})`)
|
|
243
|
+
}
|
|
244
|
+
} else {
|
|
245
|
+
if (issuer.id !== decoded.iss) {
|
|
246
|
+
throw new Error(`Inconsistent issuers between JWT claim (${decoded.iss}) and VC value (${issuer.id})`)
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
} else {
|
|
250
|
+
credential.issuer = decoded.iss
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
if (decoded.sub) {
|
|
255
|
+
const subjects = Array.isArray(credential.credentialSubject) ? credential.credentialSubject : [credential.credentialSubject]
|
|
256
|
+
for (let i = 0; i < subjects.length; i++) {
|
|
257
|
+
const csId = subjects[i].id
|
|
258
|
+
if (csId && csId !== decoded.sub) {
|
|
259
|
+
throw new Error(`Inconsistent credential subject ids between JWT claim (${decoded.sub}) and VC value (${csId})`)
|
|
260
|
+
}
|
|
261
|
+
Array.isArray(credential.credentialSubject)
|
|
262
|
+
? (credential.credentialSubject[i].id = decoded.sub)
|
|
263
|
+
: (credential.credentialSubject.id = decoded.sub)
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
if (decoded.jti) {
|
|
267
|
+
const id = credential.id
|
|
268
|
+
if (id && id !== decoded.jti) {
|
|
269
|
+
throw new Error(`Inconsistent credential ids between JWT claim (${decoded.jti}) and VC value (${id})`)
|
|
270
|
+
}
|
|
271
|
+
credential.id = decoded.jti
|
|
272
|
+
}
|
|
273
|
+
return credential
|
|
274
|
+
}
|
|
275
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './credential-mapper'
|
package/src/types/pex.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* It
|
|
2
|
+
* It expresses how the inputs are presented as proofs to a Verifier.
|
|
3
3
|
*/
|
|
4
4
|
export interface PresentationSubmission {
|
|
5
5
|
/**
|
|
@@ -16,18 +16,6 @@ export interface PresentationSubmission {
|
|
|
16
16
|
descriptor_map: Array<Descriptor>
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
/**
|
|
20
|
-
* Presentation Echange API
|
|
21
|
-
* Presentation Exchange API
|
|
22
|
-
*
|
|
23
|
-
* The version of the OpenAPI document: 1.1.0
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
|
27
|
-
* https://openapi-generator.tech
|
|
28
|
-
* Do not edit the class manually.
|
|
29
|
-
*/
|
|
30
|
-
|
|
31
19
|
/**
|
|
32
20
|
* descriptor map laying out the structure of the presentation submission.
|
|
33
21
|
*/
|
package/src/types/vc.ts
CHANGED
|
@@ -1,39 +1,40 @@
|
|
|
1
1
|
import { PresentationSubmission } from './pex'
|
|
2
2
|
import { IProofPurpose, IProofType } from './did'
|
|
3
3
|
|
|
4
|
+
export type AdditionalClaims = Record<string, any>
|
|
5
|
+
|
|
6
|
+
export type IIssuerId = string
|
|
7
|
+
|
|
4
8
|
export interface ICredential {
|
|
5
|
-
|
|
6
|
-
|
|
9
|
+
'@context': ICredentialContextType | ICredentialContextType[]
|
|
10
|
+
type: string[]
|
|
11
|
+
credentialSchema?: undefined | ICredentialSchemaType | ICredentialSchemaType[]
|
|
7
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.
|
|
8
|
-
issuer:
|
|
13
|
+
issuer: IIssuerId | IIssuer
|
|
9
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.
|
|
10
15
|
issuanceDate: string
|
|
11
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.
|
|
12
|
-
credentialSubject: ICredentialSubject
|
|
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
|
|
13
20
|
// If jti is present, the value MUST be used to set the value of the id property of the new JSON object.
|
|
14
21
|
id?: string
|
|
15
|
-
'@context': ICredentialContextType[] | ICredentialContextType
|
|
16
22
|
credentialStatus?: ICredentialStatus
|
|
17
|
-
credentialSchema?: undefined | ICredentialSchemaType | ICredentialSchemaType[]
|
|
18
23
|
description?: string
|
|
19
24
|
name?: string
|
|
20
|
-
type: string[]
|
|
21
25
|
|
|
22
|
-
[x: string]:
|
|
26
|
+
[x: string]: any
|
|
23
27
|
}
|
|
24
28
|
|
|
25
29
|
export interface ICredentialSubject {
|
|
26
30
|
id?: string
|
|
27
|
-
|
|
28
|
-
[x: string]: unknown
|
|
29
31
|
}
|
|
30
32
|
|
|
31
|
-
export type ICredentialContextType = ICredentialContext | string
|
|
33
|
+
export type ICredentialContextType = (ICredentialContext & AdditionalClaims) | string
|
|
32
34
|
|
|
33
35
|
export interface ICredentialContext {
|
|
34
36
|
name?: string
|
|
35
37
|
did?: string
|
|
36
|
-
[x: string]: unknown
|
|
37
38
|
}
|
|
38
39
|
|
|
39
40
|
export type ICredentialSchemaType = ICredentialSchema | string
|
|
@@ -55,7 +56,7 @@ export interface IProof {
|
|
|
55
56
|
nonce?: string // Similar to challenge. A nonce to protect against replay attacks, used in some ZKP proofs
|
|
56
57
|
requiredRevealStatements?: string[] // The parts of the proof that must be revealed in a derived proof
|
|
57
58
|
|
|
58
|
-
[x: string]:
|
|
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
|
|
59
60
|
}
|
|
60
61
|
|
|
61
62
|
export interface ICredentialStatus {
|
|
@@ -66,7 +67,7 @@ export interface ICredentialStatus {
|
|
|
66
67
|
export interface IIssuer {
|
|
67
68
|
id: string
|
|
68
69
|
|
|
69
|
-
[x: string]:
|
|
70
|
+
[x: string]: any
|
|
70
71
|
}
|
|
71
72
|
|
|
72
73
|
export interface IHasProof {
|
|
@@ -75,51 +76,95 @@ export interface IHasProof {
|
|
|
75
76
|
|
|
76
77
|
export type IVerifiableCredential = ICredential & IHasProof
|
|
77
78
|
|
|
79
|
+
/**
|
|
80
|
+
* Represents a Json Web Token in compact form.
|
|
81
|
+
*/
|
|
82
|
+
export type CompactJWT = string
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Represents a signed Verifiable Credential (includes proof), in either JSON or compact JWT format.
|
|
86
|
+
* See {@link https://www.w3.org/TR/vc-data-model/#credentials | VC data model}
|
|
87
|
+
* See {@link https://www.w3.org/TR/vc-data-model/#proof-formats | proof formats}
|
|
88
|
+
*/
|
|
89
|
+
export type W3CVerifiableCredential = IVerifiableCredential | CompactJWT
|
|
90
|
+
|
|
78
91
|
export interface IPresentation {
|
|
79
92
|
id?: string
|
|
80
93
|
'@context': ICredentialContextType | ICredentialContextType[]
|
|
81
94
|
type: string[]
|
|
82
|
-
verifiableCredential:
|
|
95
|
+
verifiableCredential: W3CVerifiableCredential[] // we relax to ICredential for internal decoded stable representations without proofs
|
|
83
96
|
presentation_submission?: PresentationSubmission
|
|
84
97
|
holder?: string
|
|
98
|
+
|
|
99
|
+
[x: string]: any
|
|
85
100
|
}
|
|
86
101
|
|
|
87
102
|
export type IVerifiablePresentation = IPresentation & IHasProof
|
|
88
103
|
|
|
104
|
+
/**
|
|
105
|
+
* Represents a signed Verifiable Presentation (includes proof), in either JSON or compact JWT format.
|
|
106
|
+
* See {@link https://www.w3.org/TR/vc-data-model/#presentations | VC data model}
|
|
107
|
+
* See {@link https://www.w3.org/TR/vc-data-model/#proof-formats | proof formats}
|
|
108
|
+
*/
|
|
109
|
+
export type W3CVerifiablePresentation = IVerifiablePresentation | CompactJWT
|
|
110
|
+
|
|
89
111
|
export interface WrappedVerifiableCredential {
|
|
90
112
|
/**
|
|
91
113
|
* Original VC that we've received
|
|
92
114
|
*/
|
|
93
|
-
original:
|
|
115
|
+
original: OriginalVerifiableCredential
|
|
94
116
|
/**
|
|
95
117
|
* In case of JWT credential it will be the decoded version. In other cases it will be the same as original one
|
|
96
118
|
*/
|
|
97
|
-
decoded:
|
|
119
|
+
decoded: JwtDecodedVerifiableCredential | IVerifiableCredential
|
|
120
|
+
/**
|
|
121
|
+
* Type of this credential. Supported types are json-ld and jwt (decoded/encoded)
|
|
122
|
+
*/
|
|
123
|
+
type: OriginalType
|
|
98
124
|
/**
|
|
99
|
-
*
|
|
125
|
+
* The claim format, typically used during exchange transport protocols
|
|
100
126
|
*/
|
|
101
|
-
|
|
127
|
+
format: CredentialFormat
|
|
102
128
|
/**
|
|
103
|
-
* created based on https://www.w3.org/TR/vc-data-model/#jwt-decoding
|
|
129
|
+
* Internal stable representation of a Credential without Proofs, created based on https://www.w3.org/TR/vc-data-model/#jwt-decoding
|
|
104
130
|
*/
|
|
105
|
-
|
|
131
|
+
credential: ICredential
|
|
106
132
|
}
|
|
107
133
|
|
|
108
134
|
export interface WrappedVerifiablePresentation {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
135
|
+
/**
|
|
136
|
+
* Original VP that we've received
|
|
137
|
+
*/
|
|
138
|
+
original: OriginalVerifiablePresentation
|
|
139
|
+
/**
|
|
140
|
+
* In case of JWT VP it will be the decoded version. In other cases it will be the same as original one
|
|
141
|
+
*/
|
|
142
|
+
decoded: JwtDecodedVerifiablePresentation | IVerifiablePresentation
|
|
143
|
+
/**
|
|
144
|
+
* Type of this Presentation. Supported types are json-ld and jwt (decoded/encoded)
|
|
145
|
+
*/
|
|
146
|
+
type: OriginalType
|
|
147
|
+
/**
|
|
148
|
+
* The claim format, typically used during exchange transport protocols
|
|
149
|
+
*/
|
|
150
|
+
format: PresentationFormat
|
|
151
|
+
/**
|
|
152
|
+
* Internal stable representation of a Presentation without proofs, created based on https://www.w3.org/TR/vc-data-model/#jwt-decoding
|
|
153
|
+
*/
|
|
154
|
+
presentation: UniformVerifiablePresentation
|
|
155
|
+
/**
|
|
156
|
+
* Wrapped Verifiable Credentials belonging to the Presentation
|
|
157
|
+
*/
|
|
113
158
|
vcs: WrappedVerifiableCredential[]
|
|
114
159
|
}
|
|
115
160
|
|
|
116
|
-
export enum
|
|
117
|
-
JSONLD,
|
|
118
|
-
JWT_ENCODED,
|
|
119
|
-
JWT_DECODED,
|
|
161
|
+
export enum OriginalType {
|
|
162
|
+
JSONLD = 'json-ld',
|
|
163
|
+
JWT_ENCODED = 'jwt-encoded',
|
|
164
|
+
JWT_DECODED = 'jwt-decoded',
|
|
120
165
|
}
|
|
121
166
|
|
|
122
|
-
export interface
|
|
167
|
+
export interface UniformVerifiablePresentation {
|
|
123
168
|
'@context': ICredentialContextType | ICredentialContextType[]
|
|
124
169
|
type: string[]
|
|
125
170
|
verifiableCredential: WrappedVerifiableCredential[]
|
|
@@ -127,20 +172,32 @@ export interface InternalPresentation {
|
|
|
127
172
|
holder?: string
|
|
128
173
|
}
|
|
129
174
|
|
|
130
|
-
export interface
|
|
175
|
+
export interface JwtDecodedVerifiableCredential {
|
|
131
176
|
vc: ICredential
|
|
132
177
|
exp: string
|
|
133
178
|
iss: string
|
|
134
179
|
nbf: string
|
|
135
180
|
sub: string
|
|
136
181
|
jti: string
|
|
182
|
+
|
|
183
|
+
[x: string]: any
|
|
137
184
|
}
|
|
138
185
|
|
|
139
|
-
export interface
|
|
186
|
+
export interface JwtDecodedVerifiablePresentation {
|
|
140
187
|
vp: IVerifiablePresentation
|
|
141
188
|
exp: string
|
|
142
189
|
iss: string
|
|
143
190
|
nbf: string
|
|
144
191
|
sub: string
|
|
145
192
|
jti: string
|
|
193
|
+
|
|
194
|
+
[x: string]: any
|
|
146
195
|
}
|
|
196
|
+
|
|
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
|
|
200
|
+
|
|
201
|
+
export type OriginalVerifiableCredential = W3CVerifiableCredential | JwtDecodedVerifiableCredential
|
|
202
|
+
export type OriginalVerifiablePresentation = W3CVerifiablePresentation | JwtDecodedVerifiablePresentation
|
|
203
|
+
export type Original = OriginalVerifiablePresentation | OriginalVerifiableCredential
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './object'
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export class ObjectUtils {
|
|
2
|
+
public static asArray(value: unknown) {
|
|
3
|
+
return Array.isArray(value) ? value : [value]
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
public static isObject(value: unknown) {
|
|
7
|
+
return Object.prototype.toString.call(value) === '[object Object]'
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
public static isUrlAbsolute(url: string) {
|
|
11
|
+
// regex to check for absolute IRI (starting scheme and ':') or blank node IRI
|
|
12
|
+
const isAbsoluteRegex = /^([A-Za-z][A-Za-z0-9+-.]*|_):[^\s]*$/
|
|
13
|
+
ObjectUtils.isString(url) && isAbsoluteRegex.test(url)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
public static isString(value: unknown): boolean {
|
|
17
|
+
return typeof value === 'string' || Object.prototype.toString.call(value) === '[object String]'
|
|
18
|
+
}
|
|
19
|
+
}
|