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

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,IAA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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,28 +1,27 @@
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
- id: string;
8
+ credentialSubject: ICredentialSubject & AdditionalClaims;
9
+ id?: string;
9
10
  '@context': ICredentialContextType[] | ICredentialContextType;
10
11
  credentialStatus?: ICredentialStatus;
11
12
  credentialSchema?: undefined | ICredentialSchemaType | ICredentialSchemaType[];
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,7 @@ export interface IProof {
40
39
  jws?: string;
41
40
  nonce?: string;
42
41
  requiredRevealStatements?: string[];
43
- [x: string]: string | string[] | undefined;
42
+ [x: string]: any;
44
43
  }
45
44
  export interface ICredentialStatus {
46
45
  id: string;
@@ -48,71 +47,118 @@ export interface ICredentialStatus {
48
47
  }
49
48
  export interface IIssuer {
50
49
  id: string;
51
- [x: string]: unknown;
50
+ [x: string]: any;
52
51
  }
53
52
  export interface IHasProof {
54
53
  proof: IProof | IProof[];
55
54
  }
56
55
  export declare type IVerifiableCredential = ICredential & IHasProof;
56
+ /**
57
+ * Represents a Json Web Token in compact form.
58
+ */
59
+ export declare type CompactJWT = string;
60
+ /**
61
+ * Represents a signed Verifiable Credential (includes proof), in either JSON or compact JWT format.
62
+ * See {@link https://www.w3.org/TR/vc-data-model/#credentials | VC data model}
63
+ * See {@link https://www.w3.org/TR/vc-data-model/#proof-formats | proof formats}
64
+ */
65
+ export declare type W3CVerifiableCredential = IVerifiableCredential | CompactJWT;
57
66
  export interface IPresentation {
67
+ id?: string;
58
68
  '@context': ICredentialContextType | ICredentialContextType[];
59
69
  type: string[];
60
- verifiableCredential: IVerifiableCredential[];
70
+ verifiableCredential: W3CVerifiableCredential[];
61
71
  presentation_submission?: PresentationSubmission;
62
72
  holder?: string;
73
+ [x: string]: any;
63
74
  }
64
75
  export declare type IVerifiablePresentation = IPresentation & IHasProof;
76
+ /**
77
+ * Represents a signed Verifiable Presentation (includes proof), in either JSON or compact JWT format.
78
+ * See {@link https://www.w3.org/TR/vc-data-model/#presentations | VC data model}
79
+ * See {@link https://www.w3.org/TR/vc-data-model/#proof-formats | proof formats}
80
+ */
81
+ export declare type W3CVerifiablePresentation = IVerifiablePresentation | CompactJWT;
65
82
  export interface WrappedVerifiableCredential {
66
83
  /**
67
84
  * Original VC that we've received
68
85
  */
69
- original: string | JwtWrappedVerifiableCredential | IVerifiableCredential;
86
+ original: OriginalVerifiableCredential;
70
87
  /**
71
88
  * In case of JWT credential it will be the decoded version. In other cases it will be the same as original one
72
89
  */
73
- decoded: JwtWrappedVerifiableCredential | IVerifiableCredential;
90
+ decoded: JwtDecodedVerifiableCredential | IVerifiableCredential;
91
+ /**
92
+ * Type of this credential. Supported types are json-ld and jwt (decoded/encoded)
93
+ */
94
+ type: OriginalType;
74
95
  /**
75
- * Type of this credential. Supported types are json-ld and jwt
96
+ * The claim format, typically used during exchange transport protocols
76
97
  */
77
- type: VerifiableDataExchangeType;
98
+ format: ClaimFormat;
78
99
  /**
79
- * created based on https://www.w3.org/TR/vc-data-model/#jwt-decoding
100
+ * Internal stable representation of a Credential without Proofs, created based on https://www.w3.org/TR/vc-data-model/#jwt-decoding
80
101
  */
81
- internalCredential: ICredential;
102
+ credential: ICredential;
82
103
  }
83
104
  export interface WrappedVerifiablePresentation {
84
- original: string | JwtWrappedVerifiablePresentation | IVerifiablePresentation;
85
- decoded: JwtWrappedVerifiablePresentation | IVerifiablePresentation;
86
- type: VerifiableDataExchangeType;
87
- internalPresentation: InternalPresentation;
105
+ /**
106
+ * Original VP that we've received
107
+ */
108
+ original: OriginalVerifiablePresentation;
109
+ /**
110
+ * In case of JWT VP it will be the decoded version. In other cases it will be the same as original one
111
+ */
112
+ decoded: JwtDecodedVerifiablePresentation | IVerifiablePresentation;
113
+ /**
114
+ * Type of this Presentation. Supported types are json-ld and jwt (decoded/encoded)
115
+ */
116
+ type: OriginalType;
117
+ /**
118
+ * The claim format, typically used during exchange transport protocols
119
+ */
120
+ format: ClaimFormat;
121
+ /**
122
+ * Internal stable representation of a Presentation without proofs, created based on https://www.w3.org/TR/vc-data-model/#jwt-decoding
123
+ */
124
+ presentation: UniformVerifiablePresentation;
125
+ /**
126
+ * Wrapped Verifiable Credentials belonging to the Presentation
127
+ */
88
128
  vcs: WrappedVerifiableCredential[];
89
129
  }
90
- export declare enum VerifiableDataExchangeType {
91
- JSONLD = 0,
92
- JWT_ENCODED = 1,
93
- JWT_DECODED = 2
130
+ export declare enum OriginalType {
131
+ JSONLD = "json-ld",
132
+ JWT_ENCODED = "jwt-encoded",
133
+ JWT_DECODED = "jwt-decoded"
94
134
  }
95
- export interface InternalPresentation {
135
+ export interface UniformVerifiablePresentation {
96
136
  '@context': ICredentialContextType | ICredentialContextType[];
97
137
  type: string[];
98
138
  verifiableCredential: WrappedVerifiableCredential[];
99
139
  presentation_submission?: PresentationSubmission;
100
140
  holder?: string;
101
141
  }
102
- export interface JwtWrappedVerifiableCredential {
142
+ export interface JwtDecodedVerifiableCredential {
103
143
  vc: ICredential;
104
144
  exp: string;
105
145
  iss: string;
106
146
  nbf: string;
107
147
  sub: string;
108
148
  jti: string;
149
+ [x: string]: any;
109
150
  }
110
- export interface JwtWrappedVerifiablePresentation {
151
+ export interface JwtDecodedVerifiablePresentation {
111
152
  vp: IVerifiablePresentation;
112
153
  exp: string;
113
154
  iss: string;
114
155
  nbf: string;
115
156
  sub: string;
116
157
  jti: string;
158
+ [x: string]: any;
117
159
  }
160
+ export declare type ClaimFormat = 'jwt' | 'jwt_vc' | 'jwt_vp' | 'ldp' | 'ldp_vc' | 'ldp_vp' | string;
161
+ export declare type OriginalVerifiableCredential = W3CVerifiableCredential | JwtDecodedVerifiableCredential;
162
+ export declare type OriginalVerifiablePresentation = W3CVerifiablePresentation | JwtDecodedVerifiablePresentation;
163
+ export declare type Original = OriginalVerifiablePresentation | OriginalVerifiableCredential;
118
164
  //# 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,EAAE,MAAM,GAAG,OAAO,CAAA;IAExB,YAAY,EAAE,MAAM,CAAA;IAEpB,iBAAiB,EAAE,kBAAkB,CAAA;IAErC,EAAE,EAAE,MAAM,CAAA;IACV,UAAU,EAAE,sBAAsB,EAAE,GAAG,sBAAsB,CAAA;IAC7D,gBAAgB,CAAC,EAAE,iBAAiB,CAAA;IACpC,gBAAgB,CAAC,EAAE,SAAS,GAAG,qBAAqB,GAAG,qBAAqB,EAAE,CAAA;IAC9E,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,MAAM,EAAE,CAAA;IAEd,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAA;CACrB;AAED,MAAM,WAAW,kBAAkB;IACjC,EAAE,CAAC,EAAE,MAAM,CAAA;IAEX,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAA;CACrB;AAED,oBAAY,sBAAsB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AAE,WAAW,CAAA;IACf,GAAG,EAAE,MAAM,CAAA;IACX,GAAG,EAAE,MAAM,CAAA;IACX,GAAG,EAAE,MAAM,CAAA;IACX,GAAG,EAAE,MAAM,CAAA;IACX,GAAG,EAAE,MAAM,CAAA;IAEX,CAAC,CAAC,EAAE,MAAM,GAAG,GAAG,CAAA;CACjB;AAED,MAAM,WAAW,gCAAgC;IAC/C,EAAE,EAAE,uBAAuB,CAAA;IAC3B,GAAG,EAAE,MAAM,CAAA;IACX,GAAG,EAAE,MAAM,CAAA;IACX,GAAG,EAAE,MAAM,CAAA;IACX,GAAG,EAAE,MAAM,CAAA;IACX,GAAG,EAAE,MAAM,CAAA;IAEX,CAAC,CAAC,EAAE,MAAM,GAAG,GAAG,CAAA;CACjB;AAED,oBAAY,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":";;;AA8JA,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.20+5f951d8",
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": "5f951d8bf776fb33efc6102b61f452b66a8563a6"
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,9 +11,9 @@ 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
- id: string
16
+ id?: string
15
17
  '@context': ICredentialContextType[] | ICredentialContextType
16
18
  credentialStatus?: ICredentialStatus
17
19
  credentialSchema?: undefined | ICredentialSchemaType | ICredentialSchemaType[]
@@ -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
@@ -55,7 +54,7 @@ export interface IProof {
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
56
 
58
- [x: string]: string | string[] | undefined
57
+ [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
58
  }
60
59
 
61
60
  export interface ICredentialStatus {
@@ -66,7 +65,7 @@ export interface ICredentialStatus {
66
65
  export interface IIssuer {
67
66
  id: string
68
67
 
69
- [x: string]: unknown
68
+ [x: string]: any
70
69
  }
71
70
 
72
71
  export interface IHasProof {
@@ -75,50 +74,95 @@ export interface IHasProof {
75
74
 
76
75
  export type IVerifiableCredential = ICredential & IHasProof
77
76
 
77
+ /**
78
+ * Represents a Json Web Token in compact form.
79
+ */
80
+ export type CompactJWT = string
81
+
82
+ /**
83
+ * Represents a signed Verifiable Credential (includes proof), in either JSON or compact JWT format.
84
+ * See {@link https://www.w3.org/TR/vc-data-model/#credentials | VC data model}
85
+ * See {@link https://www.w3.org/TR/vc-data-model/#proof-formats | proof formats}
86
+ */
87
+ export type W3CVerifiableCredential = IVerifiableCredential | CompactJWT
88
+
78
89
  export interface IPresentation {
90
+ id?: string
79
91
  '@context': ICredentialContextType | ICredentialContextType[]
80
92
  type: string[]
81
- verifiableCredential: IVerifiableCredential[]
93
+ verifiableCredential: W3CVerifiableCredential[] // we relax to ICredential for internal decoded stable representations without proofs
82
94
  presentation_submission?: PresentationSubmission
83
95
  holder?: string
96
+
97
+ [x: string]: any
84
98
  }
85
99
 
86
100
  export type IVerifiablePresentation = IPresentation & IHasProof
87
101
 
102
+ /**
103
+ * Represents a signed Verifiable Presentation (includes proof), in either JSON or compact JWT format.
104
+ * See {@link https://www.w3.org/TR/vc-data-model/#presentations | VC data model}
105
+ * See {@link https://www.w3.org/TR/vc-data-model/#proof-formats | proof formats}
106
+ */
107
+ export type W3CVerifiablePresentation = IVerifiablePresentation | CompactJWT
108
+
88
109
  export interface WrappedVerifiableCredential {
89
110
  /**
90
111
  * Original VC that we've received
91
112
  */
92
- original: string | JwtWrappedVerifiableCredential | IVerifiableCredential
113
+ original: OriginalVerifiableCredential
93
114
  /**
94
115
  * In case of JWT credential it will be the decoded version. In other cases it will be the same as original one
95
116
  */
96
- decoded: JwtWrappedVerifiableCredential | IVerifiableCredential
117
+ decoded: JwtDecodedVerifiableCredential | IVerifiableCredential
118
+ /**
119
+ * Type of this credential. Supported types are json-ld and jwt (decoded/encoded)
120
+ */
121
+ type: OriginalType
97
122
  /**
98
- * Type of this credential. Supported types are json-ld and jwt
123
+ * The claim format, typically used during exchange transport protocols
99
124
  */
100
- type: VerifiableDataExchangeType
125
+ format: ClaimFormat
101
126
  /**
102
- * created based on https://www.w3.org/TR/vc-data-model/#jwt-decoding
127
+ * Internal stable representation of a Credential without Proofs, created based on https://www.w3.org/TR/vc-data-model/#jwt-decoding
103
128
  */
104
- internalCredential: ICredential
129
+ credential: ICredential
105
130
  }
106
131
 
107
132
  export interface WrappedVerifiablePresentation {
108
- original: string | JwtWrappedVerifiablePresentation | IVerifiablePresentation
109
- decoded: JwtWrappedVerifiablePresentation | IVerifiablePresentation
110
- type: VerifiableDataExchangeType
111
- internalPresentation: InternalPresentation
133
+ /**
134
+ * Original VP that we've received
135
+ */
136
+ original: OriginalVerifiablePresentation
137
+ /**
138
+ * In case of JWT VP it will be the decoded version. In other cases it will be the same as original one
139
+ */
140
+ decoded: JwtDecodedVerifiablePresentation | IVerifiablePresentation
141
+ /**
142
+ * Type of this Presentation. Supported types are json-ld and jwt (decoded/encoded)
143
+ */
144
+ type: OriginalType
145
+ /**
146
+ * The claim format, typically used during exchange transport protocols
147
+ */
148
+ format: ClaimFormat
149
+ /**
150
+ * Internal stable representation of a Presentation without proofs, created based on https://www.w3.org/TR/vc-data-model/#jwt-decoding
151
+ */
152
+ presentation: UniformVerifiablePresentation
153
+ /**
154
+ * Wrapped Verifiable Credentials belonging to the Presentation
155
+ */
112
156
  vcs: WrappedVerifiableCredential[]
113
157
  }
114
158
 
115
- export enum VerifiableDataExchangeType {
116
- JSONLD,
117
- JWT_ENCODED,
118
- JWT_DECODED,
159
+ export enum OriginalType {
160
+ JSONLD = 'json-ld',
161
+ JWT_ENCODED = 'jwt-encoded',
162
+ JWT_DECODED = 'jwt-decoded',
119
163
  }
120
164
 
121
- export interface InternalPresentation {
165
+ export interface UniformVerifiablePresentation {
122
166
  '@context': ICredentialContextType | ICredentialContextType[]
123
167
  type: string[]
124
168
  verifiableCredential: WrappedVerifiableCredential[]
@@ -126,20 +170,30 @@ export interface InternalPresentation {
126
170
  holder?: string
127
171
  }
128
172
 
129
- export interface JwtWrappedVerifiableCredential {
173
+ export interface JwtDecodedVerifiableCredential {
130
174
  vc: ICredential
131
175
  exp: string
132
176
  iss: string
133
177
  nbf: string
134
178
  sub: string
135
179
  jti: string
180
+
181
+ [x: string]: any
136
182
  }
137
183
 
138
- export interface JwtWrappedVerifiablePresentation {
184
+ export interface JwtDecodedVerifiablePresentation {
139
185
  vp: IVerifiablePresentation
140
186
  exp: string
141
187
  iss: string
142
188
  nbf: string
143
189
  sub: string
144
190
  jti: string
191
+
192
+ [x: string]: any
145
193
  }
194
+
195
+ export type ClaimFormat = 'jwt' | 'jwt_vc' | 'jwt_vp' | 'ldp' | 'ldp_vc' | 'ldp_vp' | string
196
+
197
+ export type OriginalVerifiableCredential = W3CVerifiableCredential | JwtDecodedVerifiableCredential
198
+ export type OriginalVerifiablePresentation = W3CVerifiablePresentation | JwtDecodedVerifiablePresentation
199
+ 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
+ }