@sphereon/ssi-types 0.8.1-next.2 → 0.8.1-next.26

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 CHANGED
@@ -1,2 +1,4 @@
1
1
  export * from './types';
2
+ export * from './utils';
3
+ export * from './mapper';
2
4
  //# sourceMappingURL=index.d.ts.map
@@ -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,19 @@
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): WrappedVerifiablePresentation;
6
+ static toWrappedVerifiableCredentials(verifiableCredentials: OriginalVerifiableCredential[]): WrappedVerifiableCredential[];
7
+ static toWrappedVerifiableCredential(verifiableCredential: OriginalVerifiableCredential): WrappedVerifiableCredential;
8
+ static isJwtEncoded(original: OriginalVerifiableCredential | OriginalVerifiablePresentation): boolean;
9
+ private static isJsonLdString;
10
+ static isJwtDecodedCredential(original: OriginalVerifiableCredential): boolean;
11
+ static isJwtDecodedPresentation(original: OriginalVerifiablePresentation): boolean;
12
+ static jwtEncodedPresentationToUniformPresentation(jwt: string, makeCredentialsUniform?: boolean): IPresentation;
13
+ static jwtDecodedPresentationToUniformPresentation(decoded: JwtDecodedVerifiablePresentation, makeCredentialsUniform?: boolean): IPresentation;
14
+ static toUniformCredential(verifiableCredential: OriginalVerifiableCredential): ICredential;
15
+ static toUniformPresentation(presentation: OriginalVerifiablePresentation): IPresentation;
16
+ static jwtEncodedCredentialToUniformCredential(jwt: string): ICredential;
17
+ static jwtDecodedCredentialToUniformCredential(decoded: JwtDecodedVerifiableCredential): ICredential;
18
+ }
19
+ //# 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,EAEL,WAAW,EACX,aAAa,EACb,qBAAqB,EACrB,uBAAuB,EACvB,8BAA8B,EAC9B,gCAAgC,EAEhC,4BAA4B,EAC5B,8BAA8B,EAC9B,2BAA2B,EAC3B,6BAA6B,EAC9B,MAAM,UAAU,CAAA;AAIjB,qBAAa,gBAAgB;IAC3B,MAAM,CAAC,4BAA4B,CAAC,YAAY,EAAE,8BAA8B,GAAG,gCAAgC,GAAG,uBAAuB;IAY7I,MAAM,CAAC,0BAA0B,CAAC,UAAU,EAAE,4BAA4B,GAAG,8BAA8B,GAAG,qBAAqB;IAYnI,MAAM,CAAC,+BAA+B,CAAC,YAAY,EAAE,8BAA8B,GAAG,6BAA6B;IA4BnH,MAAM,CAAC,8BAA8B,CAAC,qBAAqB,EAAE,4BAA4B,EAAE,GAAG,2BAA2B,EAAE;IAI3H,MAAM,CAAC,6BAA6B,CAAC,oBAAoB,EAAE,4BAA4B,GAAG,2BAA2B;WAwBvG,YAAY,CAAC,QAAQ,EAAE,4BAA4B,GAAG,8BAA8B;IAIlG,OAAO,CAAC,MAAM,CAAC,cAAc;WAIf,sBAAsB,CAAC,QAAQ,EAAE,4BAA4B,GAAG,OAAO;WAIvE,wBAAwB,CAAC,QAAQ,EAAE,8BAA8B,GAAG,OAAO;IAIzF,MAAM,CAAC,2CAA2C,CAAC,GAAG,EAAE,MAAM,EAAE,sBAAsB,GAAE,OAAc,GAAG,aAAa;IAItH,MAAM,CAAC,2CAA2C,CAChD,OAAO,EAAE,gCAAgC,EACzC,sBAAsB,GAAE,OAAc,GACrC,aAAa;IA6BhB,MAAM,CAAC,mBAAmB,CAAC,oBAAoB,EAAE,4BAA4B,GAAG,WAAW;IAc3F,MAAM,CAAC,qBAAqB,CAAC,YAAY,EAAE,8BAA8B,GAAG,aAAa;IAezF,MAAM,CAAC,uCAAuC,CAAC,GAAG,EAAE,MAAM,GAAG,WAAW;IAIxE,MAAM,CAAC,uCAAuC,CAAC,OAAO,EAAE,8BAA8B,GAAG,WAAW;CAkErG"}
@@ -0,0 +1,212 @@
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) {
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)
48
+ : decoded;
49
+ const vcs = CredentialMapper.toWrappedVerifiableCredentials(vp.verifiableCredential);
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) {
61
+ return verifiableCredentials.map(CredentialMapper.toWrappedVerifiableCredential);
62
+ }
63
+ static toWrappedVerifiableCredential(verifiableCredential) {
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)
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) {
95
+ return CredentialMapper.jwtDecodedPresentationToUniformPresentation((0, jwt_decode_1.default)(jwt), makeCredentialsUniform);
96
+ }
97
+ static jwtDecodedPresentationToUniformPresentation(decoded, makeCredentialsUniform = true) {
98
+ const presentation = Object.assign({}, decoded.vp);
99
+ if (makeCredentialsUniform) {
100
+ presentation.verifiableCredential = decoded.vp.verifiableCredential.map(CredentialMapper.toUniformCredential); // We cast it because we IPresentation needs a VC. The internal Credential doesn't have the required Proof anymore (that is intended)
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) {
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);
129
+ }
130
+ else {
131
+ return decoded;
132
+ }
133
+ }
134
+ static toUniformPresentation(presentation) {
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(CredentialMapper.toUniformCredential); // 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) {
147
+ return CredentialMapper.jwtDecodedCredentialToUniformCredential((0, jwt_decode_1.default)(jwt));
148
+ }
149
+ static jwtDecodedCredentialToUniformCredential(decoded) {
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
+ if (decoded.exp) {
154
+ const expDate = credential.expirationDate;
155
+ const jwtExp = parseInt(decoded.exp.toString());
156
+ // fix seconds to millisecs for the date
157
+ const expDateAsStr = jwtExp < 9999999999 ? new Date(jwtExp * 1000).toISOString().replace(/\.000Z/, 'Z') : new Date(jwtExp).toISOString();
158
+ if (expDate && expDate !== expDateAsStr) {
159
+ throw new Error(`Inconsistent expiration dates between JWT claim (${expDateAsStr}) and VC value (${expDate})`);
160
+ }
161
+ credential.expirationDate = expDateAsStr;
162
+ }
163
+ if (decoded.nbf) {
164
+ const issuanceDate = credential.issuanceDate;
165
+ const jwtNbf = parseInt(decoded.nbf.toString());
166
+ // fix seconds to millisecs for the date
167
+ const nbfDateAsStr = jwtNbf < 9999999999 ? new Date(jwtNbf * 1000).toISOString().replace(/\.000Z/, 'Z') : new Date(jwtNbf).toISOString();
168
+ if (issuanceDate && issuanceDate !== nbfDateAsStr) {
169
+ throw new Error(`Inconsistent issuance dates between JWT claim (${nbfDateAsStr}) and VC value (${issuanceDate})`);
170
+ }
171
+ credential.issuanceDate = nbfDateAsStr;
172
+ }
173
+ if (decoded.iss) {
174
+ const issuer = credential.issuer;
175
+ if (issuer) {
176
+ if (typeof issuer === 'string') {
177
+ if (issuer !== decoded.iss) {
178
+ throw new Error(`Inconsistent issuers between JWT claim (${decoded.iss}) and VC value (${issuer})`);
179
+ }
180
+ }
181
+ else {
182
+ if (issuer.id !== decoded.iss) {
183
+ throw new Error(`Inconsistent issuers between JWT claim (${decoded.iss}) and VC value (${issuer.id})`);
184
+ }
185
+ }
186
+ }
187
+ credential.issuer = decoded.iss;
188
+ }
189
+ if (decoded.sub) {
190
+ const subjects = Array.isArray(credential.credentialSubject) ? credential.credentialSubject : [credential.credentialSubject];
191
+ for (let i = 0; i < subjects.length; i++) {
192
+ const csId = subjects[i].id;
193
+ if (csId && csId !== decoded.sub) {
194
+ throw new Error(`Inconsistent credential subject ids between JWT claim (${decoded.sub}) and VC value (${csId})`);
195
+ }
196
+ Array.isArray(credential.credentialSubject)
197
+ ? (credential.credentialSubject[i].id = decoded.sub)
198
+ : (credential.credentialSubject.id = decoded.sub);
199
+ }
200
+ }
201
+ if (decoded.jti) {
202
+ const id = credential.id;
203
+ if (id && id !== decoded.jti) {
204
+ throw new Error(`Inconsistent credential ids between JWT claim (${decoded.jti}) and VC value (${id})`);
205
+ }
206
+ credential.id = decoded.jti;
207
+ }
208
+ return credential;
209
+ }
210
+ }
211
+ exports.CredentialMapper = CredentialMapper;
212
+ //# 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,gBAAgB,CAAC,cAAc,CAAC,YAAY,CAAC,EAAE;YACxD,OAAO,IAAI,CAAC,KAAK,CAAC,YAAsB,CAA4B,CAAA;SACrE;aAAM;YACL,OAAO,YAAuC,CAAA;SAC/C;IACH,CAAC;IAED,MAAM,CAAC,0BAA0B,CAAC,UAAwC;QACxE,IAAI,gBAAgB,CAAC,YAAY,CAAC,UAAU,CAAC,EAAE;YAC7C,OAAO,IAAA,oBAAU,EAAC,UAAoB,CAAmC,CAAA;SAC1E;aAAM,IAAI,gBAAgB,CAAC,sBAAsB,CAAC,UAAU,CAAC,EAAE;YAC9D,OAAO,UAA4C,CAAA;SACpD;aAAM,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D,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;AAxOD,4CAwOC"}
@@ -0,0 +1,2 @@
1
+ export * from './credential-mapper';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -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"}
@@ -1,5 +1,5 @@
1
1
  /**
2
- * It express how the inputs presented as proofs to a Verifier.
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
  */
@@ -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;;;;;;;;;;GAUG;AAEH;;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"}
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"}
@@ -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
- expirationDate?: string;
5
- issuer: string | IIssuer;
6
+ '@context': ICredentialContextType | ICredentialContextType[];
7
+ type: string[];
8
+ credentialSchema?: undefined | ICredentialSchemaType | ICredentialSchemaType[];
9
+ issuer: IIssuerId | IIssuer;
6
10
  issuanceDate: string;
7
- credentialSubject: ICredentialSubject;
8
- id: string;
9
- '@context': ICredentialContextType[] | ICredentialContextType;
11
+ credentialSubject: (ICredentialSubject & AdditionalClaims) | (ICredentialSubject & AdditionalClaims)[];
12
+ expirationDate?: string;
13
+ id?: string;
10
14
  credentialStatus?: ICredentialStatus;
11
- credentialSchema?: undefined | ICredentialSchemaType | ICredentialSchemaType[];
12
15
  description?: string;
13
16
  name?: string;
14
- type: string[];
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]: string | string[] | undefined;
43
+ [x: string]: any;
44
44
  }
45
45
  export interface ICredentialStatus {
46
46
  id: string;
@@ -48,71 +48,118 @@ export interface ICredentialStatus {
48
48
  }
49
49
  export interface IIssuer {
50
50
  id: string;
51
- [x: string]: unknown;
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 {
68
+ id?: string;
58
69
  '@context': ICredentialContextType | ICredentialContextType[];
59
70
  type: string[];
60
- verifiableCredential: IVerifiableCredential[];
71
+ verifiableCredential: W3CVerifiableCredential[];
61
72
  presentation_submission?: PresentationSubmission;
62
73
  holder?: string;
74
+ [x: string]: any;
63
75
  }
64
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;
65
83
  export interface WrappedVerifiableCredential {
66
84
  /**
67
85
  * Original VC that we've received
68
86
  */
69
- original: string | JwtWrappedVerifiableCredential | IVerifiableCredential;
87
+ original: OriginalVerifiableCredential;
70
88
  /**
71
89
  * In case of JWT credential it will be the decoded version. In other cases it will be the same as original one
72
90
  */
73
- decoded: JwtWrappedVerifiableCredential | IVerifiableCredential;
91
+ decoded: JwtDecodedVerifiableCredential | IVerifiableCredential;
92
+ /**
93
+ * Type of this credential. Supported types are json-ld and jwt (decoded/encoded)
94
+ */
95
+ type: OriginalType;
74
96
  /**
75
- * Type of this credential. Supported types are json-ld and jwt
97
+ * The claim format, typically used during exchange transport protocols
76
98
  */
77
- type: VerifiableDataExchangeType;
99
+ format: ClaimFormat;
78
100
  /**
79
- * 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
80
102
  */
81
- internalCredential: ICredential;
103
+ credential: ICredential;
82
104
  }
83
105
  export interface WrappedVerifiablePresentation {
84
- original: string | JwtWrappedVerifiablePresentation | IVerifiablePresentation;
85
- decoded: JwtWrappedVerifiablePresentation | IVerifiablePresentation;
86
- type: VerifiableDataExchangeType;
87
- internalPresentation: InternalPresentation;
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: ClaimFormat;
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
+ */
88
129
  vcs: WrappedVerifiableCredential[];
89
130
  }
90
- export declare enum VerifiableDataExchangeType {
91
- JSONLD = 0,
92
- JWT_ENCODED = 1,
93
- JWT_DECODED = 2
131
+ export declare enum OriginalType {
132
+ JSONLD = "json-ld",
133
+ JWT_ENCODED = "jwt-encoded",
134
+ JWT_DECODED = "jwt-decoded"
94
135
  }
95
- export interface InternalPresentation {
136
+ export interface UniformVerifiablePresentation {
96
137
  '@context': ICredentialContextType | ICredentialContextType[];
97
138
  type: string[];
98
139
  verifiableCredential: WrappedVerifiableCredential[];
99
140
  presentation_submission?: PresentationSubmission;
100
141
  holder?: string;
101
142
  }
102
- export interface JwtWrappedVerifiableCredential {
143
+ export interface JwtDecodedVerifiableCredential {
103
144
  vc: ICredential;
104
145
  exp: string;
105
146
  iss: string;
106
147
  nbf: string;
107
148
  sub: string;
108
149
  jti: string;
150
+ [x: string]: any;
109
151
  }
110
- export interface JwtWrappedVerifiablePresentation {
152
+ export interface JwtDecodedVerifiablePresentation {
111
153
  vp: IVerifiablePresentation;
112
154
  exp: string;
113
155
  iss: string;
114
156
  nbf: string;
115
157
  sub: string;
116
158
  jti: string;
159
+ [x: string]: any;
117
160
  }
161
+ export declare type ClaimFormat = 'jwt' | 'jwt_vc' | 'jwt_vp' | 'ldp' | 'ldp_vc' | 'ldp_vp' | string;
162
+ export declare type OriginalVerifiableCredential = W3CVerifiableCredential | JwtDecodedVerifiableCredential;
163
+ export declare type OriginalVerifiablePresentation = W3CVerifiablePresentation | JwtDecodedVerifiablePresentation;
164
+ export declare type Original = OriginalVerifiablePresentation | OriginalVerifiableCredential;
118
165
  //# sourceMappingURL=vc.d.ts.map
@@ -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;AA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;CACjB;AAED,oBAAY,WAAW,GAAG,KAAK,GAAG,QAAQ,GAAG,QAAQ,GAAG,KAAK,GAAG,QAAQ,GAAG,QAAQ,GAAG,MAAM,CAAA;AAE5F,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.VerifiableDataExchangeType = void 0;
4
- var VerifiableDataExchangeType;
5
- (function (VerifiableDataExchangeType) {
6
- VerifiableDataExchangeType[VerifiableDataExchangeType["JSONLD"] = 0] = "JSONLD";
7
- VerifiableDataExchangeType[VerifiableDataExchangeType["JWT_ENCODED"] = 1] = "JWT_ENCODED";
8
- VerifiableDataExchangeType[VerifiableDataExchangeType["JWT_DECODED"] = 2] = "JWT_DECODED";
9
- })(VerifiableDataExchangeType = exports.VerifiableDataExchangeType || (exports.VerifiableDataExchangeType = {}));
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
@@ -1 +1 @@
1
- {"version":3,"file":"vc.js","sourceRoot":"","sources":["../../src/types/vc.ts"],"names":[],"mappings":";;;AAkHA,IAAY,0BAIX;AAJD,WAAY,0BAA0B;IACpC,+EAAM,CAAA;IACN,yFAAW,CAAA;IACX,yFAAW,CAAA;AACb,CAAC,EAJW,0BAA0B,GAA1B,kCAA0B,KAA1B,kCAA0B,QAIrC"}
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,2 @@
1
+ export * from './object';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -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,7 @@
1
+ export declare class ObjectUtils {
2
+ static asArray(value: unknown): any[];
3
+ static isObject(value: unknown): boolean;
4
+ static isUrlAbsolute(url: string): void;
5
+ static isString(value: unknown): boolean;
6
+ }
7
+ //# sourceMappingURL=object.d.ts.map
@@ -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.2+0b28de3",
4
+ "version": "0.8.1-next.26+4dc8dea",
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
- "gitHead": "0b28de3de21afd0a224d3d174103e072162231ed"
33
+ "keywords": [
34
+ "SSI",
35
+ "Common Credential Types",
36
+ "Credential Mapping",
37
+ "Verifiable Credentials",
38
+ "DIDs"
39
+ ],
40
+ "gitHead": "4dc8dea175ff9eb8526ce6f1abb4b72ffbb58128"
28
41
  }
package/src/index.ts CHANGED
@@ -1 +1,3 @@
1
1
  export * from './types'
2
+ export * from './utils'
3
+ export * from './mapper'
@@ -0,0 +1,250 @@
1
+ import {
2
+ ClaimFormat,
3
+ ICredential,
4
+ IPresentation,
5
+ IVerifiableCredential,
6
+ IVerifiablePresentation,
7
+ JwtDecodedVerifiableCredential,
8
+ JwtDecodedVerifiablePresentation,
9
+ OriginalType,
10
+ OriginalVerifiableCredential,
11
+ OriginalVerifiablePresentation,
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(presentation: OriginalVerifiablePresentation): WrappedVerifiablePresentation {
44
+ const original = presentation
45
+ const isJwtEncoded: boolean = CredentialMapper.isJwtEncoded(original)
46
+ const isJwtDecoded: boolean = CredentialMapper.isJwtDecodedPresentation(original)
47
+
48
+ const type = isJwtEncoded ? OriginalType.JWT_ENCODED : isJwtDecoded ? OriginalType.JWT_DECODED : OriginalType.JSONLD
49
+ const format: ClaimFormat = isJwtDecoded || isJwtEncoded ? 'jwt_vp' : 'ldp_vp'
50
+ const decoded = CredentialMapper.decodeVerifiablePresentation(original)
51
+ const vp: IPresentation =
52
+ isJwtEncoded || isJwtDecoded
53
+ ? CredentialMapper.jwtDecodedPresentationToUniformPresentation(decoded as JwtDecodedVerifiablePresentation, false)
54
+ : (decoded as IPresentation)
55
+ const vcs: WrappedVerifiableCredential[] = CredentialMapper.toWrappedVerifiableCredentials(vp.verifiableCredential)
56
+
57
+ // todo: We probably want to add proofs as well
58
+ return {
59
+ type,
60
+ format,
61
+ original,
62
+ 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
+ },
67
+ vcs,
68
+ }
69
+ }
70
+
71
+ static toWrappedVerifiableCredentials(verifiableCredentials: OriginalVerifiableCredential[]): WrappedVerifiableCredential[] {
72
+ return verifiableCredentials.map(CredentialMapper.toWrappedVerifiableCredential)
73
+ }
74
+
75
+ static toWrappedVerifiableCredential(verifiableCredential: OriginalVerifiableCredential): WrappedVerifiableCredential {
76
+ const original = verifiableCredential
77
+
78
+ const decoded = CredentialMapper.decodeVerifiableCredential(verifiableCredential)
79
+
80
+ const isJwtEncoded = CredentialMapper.isJwtEncoded(original)
81
+ const isJwtDecoded = CredentialMapper.isJwtDecodedCredential(original)
82
+ const type = isJwtEncoded ? OriginalType.JWT_ENCODED : isJwtDecoded ? OriginalType.JWT_DECODED : OriginalType.JSONLD
83
+
84
+ const credential =
85
+ isJwtDecoded || isJwtDecoded
86
+ ? CredentialMapper.jwtDecodedCredentialToUniformCredential(decoded as JwtDecodedVerifiableCredential)
87
+ : (decoded as ICredential)
88
+ const format = isJwtDecoded || isJwtDecoded ? 'jwt_vc' : 'ldp_vc'
89
+ //todo: We probably want to add proofs as well
90
+ return {
91
+ original,
92
+ decoded,
93
+ format,
94
+ type,
95
+ credential,
96
+ }
97
+ }
98
+
99
+ public static isJwtEncoded(original: OriginalVerifiableCredential | OriginalVerifiablePresentation) {
100
+ return ObjectUtils.isString(original) && (original as string).startsWith('ey')
101
+ }
102
+
103
+ private static isJsonLdString(original: OriginalVerifiableCredential | OriginalVerifiablePresentation) {
104
+ return ObjectUtils.isString(original) && (original as string).includes('@context')
105
+ }
106
+
107
+ public static isJwtDecodedCredential(original: OriginalVerifiableCredential): boolean {
108
+ return (<JwtDecodedVerifiableCredential>original)['vc'] !== undefined && (<JwtDecodedVerifiableCredential>original)['iss'] !== undefined
109
+ }
110
+
111
+ public static isJwtDecodedPresentation(original: OriginalVerifiablePresentation): boolean {
112
+ return (<JwtDecodedVerifiablePresentation>original)['vp'] !== undefined && (<JwtDecodedVerifiablePresentation>original)['iss'] !== undefined
113
+ }
114
+
115
+ static jwtEncodedPresentationToUniformPresentation(jwt: string, makeCredentialsUniform: boolean = true): IPresentation {
116
+ return CredentialMapper.jwtDecodedPresentationToUniformPresentation(jwt_decode(jwt), makeCredentialsUniform)
117
+ }
118
+
119
+ static jwtDecodedPresentationToUniformPresentation(
120
+ decoded: JwtDecodedVerifiablePresentation,
121
+ makeCredentialsUniform: boolean = true
122
+ ): IPresentation {
123
+ const presentation: IPresentation = {
124
+ ...(decoded.vp as IPresentation),
125
+ }
126
+ if (makeCredentialsUniform) {
127
+ presentation.verifiableCredential = decoded.vp.verifiableCredential.map(CredentialMapper.toUniformCredential) as IVerifiableCredential[] // We cast it because we IPresentation needs a VC. The internal Credential doesn't have the required Proof anymore (that is intended)
128
+ }
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
+ if (decoded.iss) {
133
+ const holder = presentation.holder
134
+ if (holder) {
135
+ if (holder !== decoded.iss) {
136
+ throw new Error(`Inconsistent holders between JWT claim (${decoded.iss}) and VC value (${holder})`)
137
+ }
138
+ }
139
+ presentation.holder = decoded.iss
140
+ }
141
+ if (decoded.jti) {
142
+ const id = presentation.id
143
+ if (id && id !== decoded.jti) {
144
+ throw new Error(`Inconsistent VP ids between JWT claim (${decoded.jti}) and VP value (${id})`)
145
+ }
146
+ presentation.id = decoded.jti
147
+ }
148
+ return presentation
149
+ }
150
+
151
+ static toUniformCredential(verifiableCredential: OriginalVerifiableCredential): ICredential {
152
+ const original = verifiableCredential
153
+ const decoded = CredentialMapper.decodeVerifiableCredential(verifiableCredential)
154
+
155
+ const isJwtEncoded: boolean = CredentialMapper.isJwtEncoded(original)
156
+ const isJwtDecoded: boolean = CredentialMapper.isJwtDecodedCredential(original)
157
+
158
+ if (isJwtDecoded || isJwtEncoded) {
159
+ return CredentialMapper.jwtDecodedCredentialToUniformCredential(decoded as JwtDecodedVerifiableCredential)
160
+ } else {
161
+ return decoded as ICredential
162
+ }
163
+ }
164
+
165
+ static toUniformPresentation(presentation: OriginalVerifiablePresentation): IPresentation {
166
+ const original = presentation
167
+ const decoded = CredentialMapper.decodeVerifiablePresentation(original)
168
+ const isJwtEncoded: boolean = CredentialMapper.isJwtEncoded(original)
169
+ const isJwtDecoded: boolean = CredentialMapper.isJwtDecodedPresentation(original)
170
+ const uniformPresentation =
171
+ isJwtEncoded || isJwtDecoded
172
+ ? CredentialMapper.jwtDecodedPresentationToUniformPresentation(decoded as JwtDecodedVerifiablePresentation, false)
173
+ : (decoded as IPresentation)
174
+ uniformPresentation.verifiableCredential = uniformPresentation.verifiableCredential?.map(
175
+ CredentialMapper.toUniformCredential
176
+ ) 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
+ return uniformPresentation
178
+ }
179
+
180
+ static jwtEncodedCredentialToUniformCredential(jwt: string): ICredential {
181
+ return CredentialMapper.jwtDecodedCredentialToUniformCredential(jwt_decode(jwt))
182
+ }
183
+
184
+ static jwtDecodedCredentialToUniformCredential(decoded: JwtDecodedVerifiableCredential): ICredential {
185
+ const credential: ICredential = {
186
+ ...(decoded.vc as ICredential),
187
+ }
188
+ // Since this is a credential, we delete any proof just to be sure (should not occur on JWT, but better safe than sorry)
189
+ delete credential.proof
190
+
191
+ if (decoded.exp) {
192
+ const expDate = credential.expirationDate
193
+ const jwtExp = parseInt(decoded.exp.toString())
194
+ // fix seconds to millisecs for the date
195
+ const expDateAsStr = jwtExp < 9999999999 ? new Date(jwtExp * 1000).toISOString().replace(/\.000Z/, 'Z') : new Date(jwtExp).toISOString()
196
+ if (expDate && expDate !== expDateAsStr) {
197
+ throw new Error(`Inconsistent expiration dates between JWT claim (${expDateAsStr}) and VC value (${expDate})`)
198
+ }
199
+ credential.expirationDate = expDateAsStr
200
+ }
201
+
202
+ if (decoded.nbf) {
203
+ const issuanceDate = credential.issuanceDate
204
+ const jwtNbf = parseInt(decoded.nbf.toString())
205
+ // fix seconds to millisecs for the date
206
+ const nbfDateAsStr = jwtNbf < 9999999999 ? new Date(jwtNbf * 1000).toISOString().replace(/\.000Z/, 'Z') : new Date(jwtNbf).toISOString()
207
+ if (issuanceDate && issuanceDate !== nbfDateAsStr) {
208
+ throw new Error(`Inconsistent issuance dates between JWT claim (${nbfDateAsStr}) and VC value (${issuanceDate})`)
209
+ }
210
+ credential.issuanceDate = nbfDateAsStr
211
+ }
212
+
213
+ if (decoded.iss) {
214
+ const issuer = credential.issuer
215
+ if (issuer) {
216
+ if (typeof issuer === 'string') {
217
+ if (issuer !== decoded.iss) {
218
+ throw new Error(`Inconsistent issuers between JWT claim (${decoded.iss}) and VC value (${issuer})`)
219
+ }
220
+ } else {
221
+ if (issuer.id !== decoded.iss) {
222
+ throw new Error(`Inconsistent issuers between JWT claim (${decoded.iss}) and VC value (${issuer.id})`)
223
+ }
224
+ }
225
+ }
226
+ credential.issuer = decoded.iss
227
+ }
228
+
229
+ if (decoded.sub) {
230
+ const subjects = Array.isArray(credential.credentialSubject) ? credential.credentialSubject : [credential.credentialSubject]
231
+ for (let i = 0; i < subjects.length; i++) {
232
+ const csId = subjects[i].id
233
+ if (csId && csId !== decoded.sub) {
234
+ throw new Error(`Inconsistent credential subject ids between JWT claim (${decoded.sub}) and VC value (${csId})`)
235
+ }
236
+ Array.isArray(credential.credentialSubject)
237
+ ? (credential.credentialSubject[i].id = decoded.sub)
238
+ : (credential.credentialSubject.id = decoded.sub)
239
+ }
240
+ }
241
+ if (decoded.jti) {
242
+ const id = credential.id
243
+ if (id && id !== decoded.jti) {
244
+ throw new Error(`Inconsistent credential ids between JWT claim (${decoded.jti}) and VC value (${id})`)
245
+ }
246
+ credential.id = decoded.jti
247
+ }
248
+ return credential
249
+ }
250
+ }
@@ -0,0 +1 @@
1
+ export * from './credential-mapper'
package/src/types/pex.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * It express how the inputs presented as proofs to a Verifier.
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
- // 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.
6
- expirationDate?: string
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: string | IIssuer
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
- id: string
15
- '@context': ICredentialContextType[] | ICredentialContextType
21
+ id?: string
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]: unknown
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]: string | string[] | undefined
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]: unknown
70
+ [x: string]: any
70
71
  }
71
72
 
72
73
  export interface IHasProof {
@@ -75,50 +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 {
92
+ id?: string
79
93
  '@context': ICredentialContextType | ICredentialContextType[]
80
94
  type: string[]
81
- verifiableCredential: IVerifiableCredential[]
95
+ verifiableCredential: W3CVerifiableCredential[] // we relax to ICredential for internal decoded stable representations without proofs
82
96
  presentation_submission?: PresentationSubmission
83
97
  holder?: string
98
+
99
+ [x: string]: any
84
100
  }
85
101
 
86
102
  export type IVerifiablePresentation = IPresentation & IHasProof
87
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
+
88
111
  export interface WrappedVerifiableCredential {
89
112
  /**
90
113
  * Original VC that we've received
91
114
  */
92
- original: string | JwtWrappedVerifiableCredential | IVerifiableCredential
115
+ original: OriginalVerifiableCredential
93
116
  /**
94
117
  * In case of JWT credential it will be the decoded version. In other cases it will be the same as original one
95
118
  */
96
- decoded: JwtWrappedVerifiableCredential | IVerifiableCredential
119
+ decoded: JwtDecodedVerifiableCredential | IVerifiableCredential
97
120
  /**
98
- * Type of this credential. Supported types are json-ld and jwt
121
+ * Type of this credential. Supported types are json-ld and jwt (decoded/encoded)
99
122
  */
100
- type: VerifiableDataExchangeType
123
+ type: OriginalType
101
124
  /**
102
- * created based on https://www.w3.org/TR/vc-data-model/#jwt-decoding
125
+ * The claim format, typically used during exchange transport protocols
103
126
  */
104
- internalCredential: ICredential
127
+ format: ClaimFormat
128
+ /**
129
+ * Internal stable representation of a Credential without Proofs, created based on https://www.w3.org/TR/vc-data-model/#jwt-decoding
130
+ */
131
+ credential: ICredential
105
132
  }
106
133
 
107
134
  export interface WrappedVerifiablePresentation {
108
- original: string | JwtWrappedVerifiablePresentation | IVerifiablePresentation
109
- decoded: JwtWrappedVerifiablePresentation | IVerifiablePresentation
110
- type: VerifiableDataExchangeType
111
- internalPresentation: InternalPresentation
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: ClaimFormat
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
+ */
112
158
  vcs: WrappedVerifiableCredential[]
113
159
  }
114
160
 
115
- export enum VerifiableDataExchangeType {
116
- JSONLD,
117
- JWT_ENCODED,
118
- JWT_DECODED,
161
+ export enum OriginalType {
162
+ JSONLD = 'json-ld',
163
+ JWT_ENCODED = 'jwt-encoded',
164
+ JWT_DECODED = 'jwt-decoded',
119
165
  }
120
166
 
121
- export interface InternalPresentation {
167
+ export interface UniformVerifiablePresentation {
122
168
  '@context': ICredentialContextType | ICredentialContextType[]
123
169
  type: string[]
124
170
  verifiableCredential: WrappedVerifiableCredential[]
@@ -126,20 +172,30 @@ export interface InternalPresentation {
126
172
  holder?: string
127
173
  }
128
174
 
129
- export interface JwtWrappedVerifiableCredential {
175
+ export interface JwtDecodedVerifiableCredential {
130
176
  vc: ICredential
131
177
  exp: string
132
178
  iss: string
133
179
  nbf: string
134
180
  sub: string
135
181
  jti: string
182
+
183
+ [x: string]: any
136
184
  }
137
185
 
138
- export interface JwtWrappedVerifiablePresentation {
186
+ export interface JwtDecodedVerifiablePresentation {
139
187
  vp: IVerifiablePresentation
140
188
  exp: string
141
189
  iss: string
142
190
  nbf: string
143
191
  sub: string
144
192
  jti: string
193
+
194
+ [x: string]: any
145
195
  }
196
+
197
+ export type ClaimFormat = 'jwt' | 'jwt_vc' | 'jwt_vp' | 'ldp' | 'ldp_vc' | 'ldp_vp' | string
198
+
199
+ export type OriginalVerifiableCredential = W3CVerifiableCredential | JwtDecodedVerifiableCredential
200
+ export type OriginalVerifiablePresentation = W3CVerifiablePresentation | JwtDecodedVerifiablePresentation
201
+ 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
+ }