@sphereon/ssi-types 0.8.1-next.6 → 0.8.1-unstable.11

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;CA6DrG"}
@@ -0,0 +1,208 @@
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
+ var _a, _b;
151
+ const credential = Object.assign({}, decoded.vc);
152
+ // Since this is a credential, we delete any proof just to be sure (should not occur on JWT, but better safe than sorry)
153
+ delete credential.proof;
154
+ if (decoded.exp) {
155
+ const expDate = (_a = credential.credentialSubject) === null || _a === void 0 ? void 0 : _a.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
+ throw new Error(`Inconsistent expiration dates between JWT claim (${expDateAsStr}) and VC value (${expDate})`);
161
+ }
162
+ credential.credentialSubject.expirationDate = expDateAsStr;
163
+ }
164
+ if (decoded.nbf) {
165
+ const issuanceDate = credential.issuanceDate;
166
+ const jwtNbf = parseInt(decoded.nbf.toString());
167
+ // fix seconds to millisecs for the date
168
+ const nbfDateAsStr = jwtNbf < 9999999999 ? new Date(jwtNbf * 1000).toISOString().replace(/\.000Z/, 'Z') : new Date(jwtNbf).toISOString();
169
+ if (issuanceDate && issuanceDate !== nbfDateAsStr) {
170
+ throw new Error(`Inconsistent issuance dates between JWT claim (${nbfDateAsStr}) and VC value (${issuanceDate})`);
171
+ }
172
+ credential.issuanceDate = nbfDateAsStr;
173
+ }
174
+ if (decoded.iss) {
175
+ const issuer = credential.issuer;
176
+ if (issuer) {
177
+ if (typeof issuer === 'string') {
178
+ if (issuer !== decoded.iss) {
179
+ throw new Error(`Inconsistent issuers between JWT claim (${decoded.iss}) and VC value (${issuer})`);
180
+ }
181
+ }
182
+ else {
183
+ if (issuer.id !== decoded.iss) {
184
+ throw new Error(`Inconsistent issuers between JWT claim (${decoded.iss}) and VC value (${issuer.id})`);
185
+ }
186
+ }
187
+ }
188
+ credential.issuer = decoded.iss;
189
+ }
190
+ if (decoded.sub) {
191
+ const csId = (_b = credential.credentialSubject) === null || _b === void 0 ? void 0 : _b.id;
192
+ if (csId && csId !== decoded.sub) {
193
+ throw new Error(`Inconsistent credential subject ids between JWT claim (${decoded.sub}) and VC value (${csId})`);
194
+ }
195
+ credential.credentialSubject.id = decoded.sub;
196
+ }
197
+ if (decoded.jti) {
198
+ const id = credential.id;
199
+ if (id && id !== decoded.jti) {
200
+ throw new Error(`Inconsistent credential ids between JWT claim (${decoded.jti}) and VC value (${id})`);
201
+ }
202
+ credential.id = decoded.jti;
203
+ }
204
+ return credential;
205
+ }
206
+ }
207
+ exports.CredentialMapper = CredentialMapper;
208
+ //# 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,IAAI,gBAAgB,CAAC,cAAc,CAAC,UAAU,CAAC,EAAE;YACtD,OAAO,I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I,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;AAnOD,4CAmOC"}
@@ -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,10 +1,11 @@
1
1
  import { PresentationSubmission } from './pex';
2
2
  import { IProofPurpose, IProofType } from './did';
3
+ export declare type AdditionalClaims = Record<string, any>;
3
4
  export interface ICredential {
4
5
  expirationDate?: string;
5
6
  issuer: string | IIssuer;
6
7
  issuanceDate: string;
7
- credentialSubject: ICredentialSubject;
8
+ credentialSubject: ICredentialSubject & AdditionalClaims;
8
9
  id?: string;
9
10
  '@context': ICredentialContextType[] | ICredentialContextType;
10
11
  credentialStatus?: ICredentialStatus;
@@ -12,17 +13,15 @@ export interface ICredential {
12
13
  description?: string;
13
14
  name?: string;
14
15
  type: string[];
15
- [x: string]: unknown;
16
+ [x: string]: any;
16
17
  }
17
18
  export interface ICredentialSubject {
18
19
  id?: string;
19
- [x: string]: unknown;
20
20
  }
21
- export declare type ICredentialContextType = ICredentialContext | string;
21
+ export declare type ICredentialContextType = (ICredentialContext & AdditionalClaims) | string;
22
22
  export interface ICredentialContext {
23
23
  name?: string;
24
24
  did?: string;
25
- [x: string]: unknown;
26
25
  }
27
26
  export declare type ICredentialSchemaType = ICredentialSchema | string;
28
27
  export interface ICredentialSchema {
@@ -40,7 +39,6 @@ export interface IProof {
40
39
  jws?: string;
41
40
  nonce?: string;
42
41
  requiredRevealStatements?: string[];
43
- [x: string]: string | string[] | undefined;
44
42
  }
45
43
  export interface ICredentialStatus {
46
44
  id: string;
@@ -48,7 +46,7 @@ export interface ICredentialStatus {
48
46
  }
49
47
  export interface IIssuer {
50
48
  id: string;
51
- [x: string]: unknown;
49
+ [x: string]: any;
52
50
  }
53
51
  export interface IHasProof {
54
52
  proof: IProof | IProof[];
@@ -61,59 +59,89 @@ export interface IPresentation {
61
59
  verifiableCredential: IVerifiableCredential[];
62
60
  presentation_submission?: PresentationSubmission;
63
61
  holder?: string;
62
+ [x: string]: any;
64
63
  }
65
64
  export declare type IVerifiablePresentation = IPresentation & IHasProof;
66
65
  export interface WrappedVerifiableCredential {
67
66
  /**
68
67
  * Original VC that we've received
69
68
  */
70
- original: string | JwtWrappedVerifiableCredential | IVerifiableCredential;
69
+ original: OriginalVerifiableCredential;
71
70
  /**
72
71
  * In case of JWT credential it will be the decoded version. In other cases it will be the same as original one
73
72
  */
74
- decoded: JwtWrappedVerifiableCredential | IVerifiableCredential;
73
+ decoded: JwtDecodedVerifiableCredential | IVerifiableCredential;
75
74
  /**
76
- * Type of this credential. Supported types are json-ld and jwt
75
+ * Type of this credential. Supported types are json-ld and jwt (decoded/encoded)
77
76
  */
78
- type: VerifiableDataExchangeType;
77
+ type: OriginalType;
79
78
  /**
80
- * created based on https://www.w3.org/TR/vc-data-model/#jwt-decoding
79
+ * The claim format, typically used during exchange transport protocols
81
80
  */
82
- internalCredential: ICredential;
81
+ format: ClaimFormat;
82
+ /**
83
+ * Internal stable representation of a Credential without Proofs, created based on https://www.w3.org/TR/vc-data-model/#jwt-decoding
84
+ */
85
+ credential: ICredential;
83
86
  }
84
87
  export interface WrappedVerifiablePresentation {
85
- original: string | JwtWrappedVerifiablePresentation | IVerifiablePresentation;
86
- decoded: JwtWrappedVerifiablePresentation | IVerifiablePresentation;
87
- type: VerifiableDataExchangeType;
88
- internalPresentation: InternalPresentation;
88
+ /**
89
+ * Original VP that we've received
90
+ */
91
+ original: OriginalVerifiablePresentation;
92
+ /**
93
+ * In case of JWT VP it will be the decoded version. In other cases it will be the same as original one
94
+ */
95
+ decoded: JwtDecodedVerifiablePresentation | IVerifiablePresentation;
96
+ /**
97
+ * Type of this Presentation. Supported types are json-ld and jwt (decoded/encoded)
98
+ */
99
+ type: OriginalType;
100
+ /**
101
+ * The claim format, typically used during exchange transport protocols
102
+ */
103
+ format: ClaimFormat;
104
+ /**
105
+ * Internal stable representation of a Presentation without proofs, created based on https://www.w3.org/TR/vc-data-model/#jwt-decoding
106
+ */
107
+ presentation: UniformVerifiablePresentation;
108
+ /**
109
+ * Wrapped Verifiable Credentials belonging to the Presentation
110
+ */
89
111
  vcs: WrappedVerifiableCredential[];
90
112
  }
91
- export declare enum VerifiableDataExchangeType {
92
- JSONLD = 0,
93
- JWT_ENCODED = 1,
94
- JWT_DECODED = 2
113
+ export declare enum OriginalType {
114
+ JSONLD = "json-ld",
115
+ JWT_ENCODED = "jwt-encoded",
116
+ JWT_DECODED = "jwt-decoded"
95
117
  }
96
- export interface InternalPresentation {
118
+ export interface UniformVerifiablePresentation {
97
119
  '@context': ICredentialContextType | ICredentialContextType[];
98
120
  type: string[];
99
121
  verifiableCredential: WrappedVerifiableCredential[];
100
122
  presentation_submission?: PresentationSubmission;
101
123
  holder?: string;
102
124
  }
103
- export interface JwtWrappedVerifiableCredential {
125
+ export interface JwtDecodedVerifiableCredential {
104
126
  vc: ICredential;
105
127
  exp: string;
106
128
  iss: string;
107
129
  nbf: string;
108
130
  sub: string;
109
131
  jti: string;
132
+ [x: string]: any;
110
133
  }
111
- export interface JwtWrappedVerifiablePresentation {
134
+ export interface JwtDecodedVerifiablePresentation {
112
135
  vp: IVerifiablePresentation;
113
136
  exp: string;
114
137
  iss: string;
115
138
  nbf: string;
116
139
  sub: string;
117
140
  jti: string;
141
+ [x: string]: any;
118
142
  }
143
+ export declare type ClaimFormat = 'jwt' | 'jwt_vc' | 'jwt_vp' | 'ldp' | 'ldp_vc' | 'ldp_vp' | string;
144
+ export declare type OriginalVerifiableCredential = IVerifiableCredential | JwtDecodedVerifiableCredential | string;
145
+ export declare type OriginalVerifiablePresentation = IPresentation | JwtDecodedVerifiablePresentation | string;
146
+ export declare type Original = OriginalVerifiablePresentation | OriginalVerifiableCredential;
119
147
  //# 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;AAEjD,MAAM,WAAW,WAAW;IAE1B,cAAc,CAAC,EAAE,MAAM,CAAA;IAEvB,MAAM,EA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  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":";;;AAmHA,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":";;;AAyIA,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.6+27069f8",
4
+ "version": "0.8.1-unstable.11+e5fd396",
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": "27069f85062685aa678ccb7846cefb84b253990f"
33
+ "keywords": [
34
+ "SSI",
35
+ "Common Credential Types",
36
+ "Credential Mapping",
37
+ "Verifiable Credentials",
38
+ "DIDs"
39
+ ],
40
+ "gitHead": "e5fd396f0430a594fd72f590136d281355f61408"
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,245 @@
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.credentialSubject?.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.credentialSubject.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 csId = credential.credentialSubject?.id
231
+ if (csId && csId !== decoded.sub) {
232
+ throw new Error(`Inconsistent credential subject ids between JWT claim (${decoded.sub}) and VC value (${csId})`)
233
+ }
234
+ credential.credentialSubject.id = decoded.sub
235
+ }
236
+ if (decoded.jti) {
237
+ const id = credential.id
238
+ if (id && id !== decoded.jti) {
239
+ throw new Error(`Inconsistent credential ids between JWT claim (${decoded.jti}) and VC value (${id})`)
240
+ }
241
+ credential.id = decoded.jti
242
+ }
243
+ return credential
244
+ }
245
+ }
@@ -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,6 +1,8 @@
1
1
  import { PresentationSubmission } from './pex'
2
2
  import { IProofPurpose, IProofType } from './did'
3
3
 
4
+ export type AdditionalClaims = Record<string, any>
5
+
4
6
  export interface ICredential {
5
7
  // 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
8
  expirationDate?: string
@@ -9,7 +11,7 @@ export interface ICredential {
9
11
  // 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
12
  issuanceDate: string
11
13
  // 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
14
+ credentialSubject: ICredentialSubject & AdditionalClaims
13
15
  // If jti is present, the value MUST be used to set the value of the id property of the new JSON object.
14
16
  id?: string
15
17
  '@context': ICredentialContextType[] | ICredentialContextType
@@ -19,21 +21,18 @@ export interface ICredential {
19
21
  name?: string
20
22
  type: string[]
21
23
 
22
- [x: string]: unknown
24
+ [x: string]: any
23
25
  }
24
26
 
25
27
  export interface ICredentialSubject {
26
28
  id?: string
27
-
28
- [x: string]: unknown
29
29
  }
30
30
 
31
- export type ICredentialContextType = ICredentialContext | string
31
+ export type ICredentialContextType = (ICredentialContext & AdditionalClaims) | string
32
32
 
33
33
  export interface ICredentialContext {
34
34
  name?: string
35
35
  did?: string
36
- [x: string]: unknown
37
36
  }
38
37
 
39
38
  export type ICredentialSchemaType = ICredentialSchema | string
@@ -54,8 +53,6 @@ export interface IProof {
54
53
  jws?: string // JWS based proof
55
54
  nonce?: string // Similar to challenge. A nonce to protect against replay attacks, used in some ZKP proofs
56
55
  requiredRevealStatements?: string[] // The parts of the proof that must be revealed in a derived proof
57
-
58
- [x: string]: string | string[] | undefined
59
56
  }
60
57
 
61
58
  export interface ICredentialStatus {
@@ -66,7 +63,7 @@ export interface ICredentialStatus {
66
63
  export interface IIssuer {
67
64
  id: string
68
65
 
69
- [x: string]: unknown
66
+ [x: string]: any
70
67
  }
71
68
 
72
69
  export interface IHasProof {
@@ -79,9 +76,11 @@ export interface IPresentation {
79
76
  id?: string
80
77
  '@context': ICredentialContextType | ICredentialContextType[]
81
78
  type: string[]
82
- verifiableCredential: IVerifiableCredential[]
79
+ verifiableCredential: IVerifiableCredential[] // we relax to ICredential for internal decoded stable representations without proofs
83
80
  presentation_submission?: PresentationSubmission
84
81
  holder?: string
82
+
83
+ [x: string]: any
85
84
  }
86
85
 
87
86
  export type IVerifiablePresentation = IPresentation & IHasProof
@@ -90,36 +89,59 @@ export interface WrappedVerifiableCredential {
90
89
  /**
91
90
  * Original VC that we've received
92
91
  */
93
- original: string | JwtWrappedVerifiableCredential | IVerifiableCredential
92
+ original: OriginalVerifiableCredential
94
93
  /**
95
94
  * In case of JWT credential it will be the decoded version. In other cases it will be the same as original one
96
95
  */
97
- decoded: JwtWrappedVerifiableCredential | IVerifiableCredential
96
+ decoded: JwtDecodedVerifiableCredential | IVerifiableCredential
97
+ /**
98
+ * Type of this credential. Supported types are json-ld and jwt (decoded/encoded)
99
+ */
100
+ type: OriginalType
98
101
  /**
99
- * Type of this credential. Supported types are json-ld and jwt
102
+ * The claim format, typically used during exchange transport protocols
100
103
  */
101
- type: VerifiableDataExchangeType
104
+ format: ClaimFormat
102
105
  /**
103
- * created based on https://www.w3.org/TR/vc-data-model/#jwt-decoding
106
+ * Internal stable representation of a Credential without Proofs, created based on https://www.w3.org/TR/vc-data-model/#jwt-decoding
104
107
  */
105
- internalCredential: ICredential
108
+ credential: ICredential
106
109
  }
107
110
 
108
111
  export interface WrappedVerifiablePresentation {
109
- original: string | JwtWrappedVerifiablePresentation | IVerifiablePresentation
110
- decoded: JwtWrappedVerifiablePresentation | IVerifiablePresentation
111
- type: VerifiableDataExchangeType
112
- internalPresentation: InternalPresentation
112
+ /**
113
+ * Original VP that we've received
114
+ */
115
+ original: OriginalVerifiablePresentation
116
+ /**
117
+ * In case of JWT VP it will be the decoded version. In other cases it will be the same as original one
118
+ */
119
+ decoded: JwtDecodedVerifiablePresentation | IVerifiablePresentation
120
+ /**
121
+ * Type of this Presentation. Supported types are json-ld and jwt (decoded/encoded)
122
+ */
123
+ type: OriginalType
124
+ /**
125
+ * The claim format, typically used during exchange transport protocols
126
+ */
127
+ format: ClaimFormat
128
+ /**
129
+ * Internal stable representation of a Presentation without proofs, created based on https://www.w3.org/TR/vc-data-model/#jwt-decoding
130
+ */
131
+ presentation: UniformVerifiablePresentation
132
+ /**
133
+ * Wrapped Verifiable Credentials belonging to the Presentation
134
+ */
113
135
  vcs: WrappedVerifiableCredential[]
114
136
  }
115
137
 
116
- export enum VerifiableDataExchangeType {
117
- JSONLD,
118
- JWT_ENCODED,
119
- JWT_DECODED,
138
+ export enum OriginalType {
139
+ JSONLD = 'json-ld',
140
+ JWT_ENCODED = 'jwt-encoded',
141
+ JWT_DECODED = 'jwt-decoded',
120
142
  }
121
143
 
122
- export interface InternalPresentation {
144
+ export interface UniformVerifiablePresentation {
123
145
  '@context': ICredentialContextType | ICredentialContextType[]
124
146
  type: string[]
125
147
  verifiableCredential: WrappedVerifiableCredential[]
@@ -127,20 +149,30 @@ export interface InternalPresentation {
127
149
  holder?: string
128
150
  }
129
151
 
130
- export interface JwtWrappedVerifiableCredential {
152
+ export interface JwtDecodedVerifiableCredential {
131
153
  vc: ICredential
132
154
  exp: string
133
155
  iss: string
134
156
  nbf: string
135
157
  sub: string
136
158
  jti: string
159
+
160
+ [x: string]: any
137
161
  }
138
162
 
139
- export interface JwtWrappedVerifiablePresentation {
163
+ export interface JwtDecodedVerifiablePresentation {
140
164
  vp: IVerifiablePresentation
141
165
  exp: string
142
166
  iss: string
143
167
  nbf: string
144
168
  sub: string
145
169
  jti: string
170
+
171
+ [x: string]: any
146
172
  }
173
+
174
+ export type ClaimFormat = 'jwt' | 'jwt_vc' | 'jwt_vp' | 'ldp' | 'ldp_vc' | 'ldp_vp' | string
175
+
176
+ export type OriginalVerifiableCredential = IVerifiableCredential | JwtDecodedVerifiableCredential | string
177
+ export type OriginalVerifiablePresentation = IPresentation | JwtDecodedVerifiablePresentation | string
178
+ 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
+ }