@sphereon/ssi-types 0.8.0 → 0.8.1-next.114

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,37 @@
1
+ import { ICredential, IPresentation, IVerifiableCredential, IVerifiablePresentation, JwtDecodedVerifiableCredential, JwtDecodedVerifiablePresentation, OriginalVerifiableCredential, OriginalVerifiablePresentation, WrappedVerifiableCredential, WrappedVerifiablePresentation } from '../types';
2
+ export declare class CredentialMapper {
3
+ static decodeVerifiablePresentation(presentation: OriginalVerifiablePresentation): JwtDecodedVerifiablePresentation | IVerifiablePresentation;
4
+ static decodeVerifiableCredential(credential: OriginalVerifiableCredential): JwtDecodedVerifiableCredential | IVerifiableCredential;
5
+ static toWrappedVerifiablePresentation(presentation: OriginalVerifiablePresentation, opts?: {
6
+ maxTimeSkewInMS?: number;
7
+ }): WrappedVerifiablePresentation;
8
+ static toWrappedVerifiableCredentials(verifiableCredentials: OriginalVerifiableCredential[], opts?: {
9
+ maxTimeSkewInMS?: number;
10
+ }): WrappedVerifiableCredential[];
11
+ static toWrappedVerifiableCredential(verifiableCredential: OriginalVerifiableCredential, opts?: {
12
+ maxTimeSkewInMS?: number;
13
+ }): WrappedVerifiableCredential;
14
+ static isJwtEncoded(original: OriginalVerifiableCredential | OriginalVerifiablePresentation): boolean;
15
+ private static isJsonLdString;
16
+ static isJwtDecodedCredential(original: OriginalVerifiableCredential): boolean;
17
+ static isJwtDecodedPresentation(original: OriginalVerifiablePresentation): boolean;
18
+ static jwtEncodedPresentationToUniformPresentation(jwt: string, makeCredentialsUniform?: boolean, opts?: {
19
+ maxTimeSkewInMS?: number;
20
+ }): IPresentation;
21
+ static jwtDecodedPresentationToUniformPresentation(decoded: JwtDecodedVerifiablePresentation, makeCredentialsUniform?: boolean, opts?: {
22
+ maxTimeSkewInMS?: number;
23
+ }): IPresentation;
24
+ static toUniformCredential(verifiableCredential: OriginalVerifiableCredential, opts?: {
25
+ maxTimeSkewInMS?: number;
26
+ }): ICredential;
27
+ static toUniformPresentation(presentation: OriginalVerifiablePresentation, opts?: {
28
+ maxTimeSkewInMS?: number;
29
+ }): IPresentation;
30
+ static jwtEncodedCredentialToUniformCredential(jwt: string, opts?: {
31
+ maxTimeSkewInMS?: number;
32
+ }): ICredential;
33
+ static jwtDecodedCredentialToUniformCredential(decoded: JwtDecodedVerifiableCredential, opts?: {
34
+ maxTimeSkewInMS?: number;
35
+ }): ICredential;
36
+ }
37
+ //# sourceMappingURL=credential-mapper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"credential-mapper.d.ts","sourceRoot":"","sources":["../../src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AgC,EACzC,sBAAsB,GAAE,OAAc,EACtC,IAAI,CAAC,EAAE;QAAE,eAAe,CAAC,EAAE,MAAM,CAAA;KAAE,GAClC,aAAa;IA+BhB,MAAM,CAAC,mBAAmB,CAAC,oBAAoB,EAAE,4BAA4B,EAAE,IAAI,CAAC,EAAE;QAAE,eAAe,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,WAAW;IAchI,MAAM,CAAC,qBAAqB,CAAC,YAAY,EAAE,8BAA8B,EAAE,IAAI,CAAC,EAAE;QAAE,eAAe,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,aAAa;IAe9H,MAAM,CAAC,uCAAuC,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE;QAAE,eAAe,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,WAAW;IAI7G,MAAM,CAAC,uCAAuC,CAAC,OAAO,EAAE,8BAA8B,EAAE,IAAI,CAAC,EAAE;QAAE,eAAe,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,WAAW;CA2E1I"}
@@ -0,0 +1,221 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.CredentialMapper = void 0;
7
+ const types_1 = require("../types");
8
+ const jwt_decode_1 = __importDefault(require("jwt-decode"));
9
+ const utils_1 = require("../utils");
10
+ class CredentialMapper {
11
+ static decodeVerifiablePresentation(presentation) {
12
+ if (CredentialMapper.isJwtEncoded(presentation)) {
13
+ return (0, jwt_decode_1.default)(presentation);
14
+ }
15
+ else if (CredentialMapper.isJwtDecodedPresentation(presentation)) {
16
+ return presentation;
17
+ }
18
+ else if (CredentialMapper.isJsonLdString(presentation)) {
19
+ return JSON.parse(presentation);
20
+ }
21
+ else {
22
+ return presentation;
23
+ }
24
+ }
25
+ static decodeVerifiableCredential(credential) {
26
+ if (CredentialMapper.isJwtEncoded(credential)) {
27
+ return (0, jwt_decode_1.default)(credential);
28
+ }
29
+ else if (CredentialMapper.isJwtDecodedCredential(credential)) {
30
+ return credential;
31
+ }
32
+ else if (CredentialMapper.isJsonLdString(credential)) {
33
+ return JSON.parse(credential);
34
+ }
35
+ else {
36
+ return credential;
37
+ }
38
+ }
39
+ static toWrappedVerifiablePresentation(presentation, opts) {
40
+ const original = presentation;
41
+ const isJwtEncoded = CredentialMapper.isJwtEncoded(original);
42
+ const isJwtDecoded = CredentialMapper.isJwtDecodedPresentation(original);
43
+ const type = isJwtEncoded ? types_1.OriginalType.JWT_ENCODED : isJwtDecoded ? types_1.OriginalType.JWT_DECODED : types_1.OriginalType.JSONLD;
44
+ const format = isJwtDecoded || isJwtEncoded ? 'jwt_vp' : 'ldp_vp';
45
+ const decoded = CredentialMapper.decodeVerifiablePresentation(original);
46
+ const vp = isJwtEncoded || isJwtDecoded
47
+ ? CredentialMapper.jwtDecodedPresentationToUniformPresentation(decoded, false, opts)
48
+ : decoded;
49
+ const vcs = CredentialMapper.toWrappedVerifiableCredentials(vp.verifiableCredential, opts);
50
+ // todo: We probably want to add proofs as well
51
+ return {
52
+ type,
53
+ format,
54
+ original,
55
+ decoded,
56
+ presentation: Object.assign(Object.assign({}, vp), { verifiableCredential: vcs }),
57
+ vcs,
58
+ };
59
+ }
60
+ static toWrappedVerifiableCredentials(verifiableCredentials, opts) {
61
+ return verifiableCredentials.map((vc) => CredentialMapper.toWrappedVerifiableCredential(vc, opts));
62
+ }
63
+ static toWrappedVerifiableCredential(verifiableCredential, opts) {
64
+ const original = verifiableCredential;
65
+ const decoded = CredentialMapper.decodeVerifiableCredential(verifiableCredential);
66
+ const isJwtEncoded = CredentialMapper.isJwtEncoded(original);
67
+ const isJwtDecoded = CredentialMapper.isJwtDecodedCredential(original);
68
+ const type = isJwtEncoded ? types_1.OriginalType.JWT_ENCODED : isJwtDecoded ? types_1.OriginalType.JWT_DECODED : types_1.OriginalType.JSONLD;
69
+ const credential = isJwtDecoded || isJwtDecoded
70
+ ? CredentialMapper.jwtDecodedCredentialToUniformCredential(decoded, opts)
71
+ : decoded;
72
+ const format = isJwtDecoded || isJwtDecoded ? 'jwt_vc' : 'ldp_vc';
73
+ //todo: We probably want to add proofs as well
74
+ return {
75
+ original,
76
+ decoded,
77
+ format,
78
+ type,
79
+ credential,
80
+ };
81
+ }
82
+ static isJwtEncoded(original) {
83
+ return utils_1.ObjectUtils.isString(original) && original.startsWith('ey');
84
+ }
85
+ static isJsonLdString(original) {
86
+ return utils_1.ObjectUtils.isString(original) && original.includes('@context');
87
+ }
88
+ static isJwtDecodedCredential(original) {
89
+ return original['vc'] !== undefined && original['iss'] !== undefined;
90
+ }
91
+ static isJwtDecodedPresentation(original) {
92
+ return original['vp'] !== undefined && original['iss'] !== undefined;
93
+ }
94
+ static jwtEncodedPresentationToUniformPresentation(jwt, makeCredentialsUniform = true, opts) {
95
+ return CredentialMapper.jwtDecodedPresentationToUniformPresentation((0, jwt_decode_1.default)(jwt), makeCredentialsUniform, opts);
96
+ }
97
+ static jwtDecodedPresentationToUniformPresentation(decoded, makeCredentialsUniform = true, opts) {
98
+ const presentation = Object.assign({}, decoded.vp);
99
+ if (makeCredentialsUniform) {
100
+ presentation.verifiableCredential = decoded.vp.verifiableCredential.map((vc) => CredentialMapper.toUniformCredential(vc, opts)); // We cast it because we IPresentation needs a VC. The internal Credential doesn't have the required Proof anymore (that is intended)
101
+ }
102
+ // Since this is a presentation, we delete any proof just to be sure (should not occur on JWT, but better safe than sorry)
103
+ delete presentation.proof;
104
+ if (decoded.iss) {
105
+ const holder = presentation.holder;
106
+ if (holder) {
107
+ if (holder !== decoded.iss) {
108
+ throw new Error(`Inconsistent holders between JWT claim (${decoded.iss}) and VC value (${holder})`);
109
+ }
110
+ }
111
+ presentation.holder = decoded.iss;
112
+ }
113
+ if (decoded.jti) {
114
+ const id = presentation.id;
115
+ if (id && id !== decoded.jti) {
116
+ throw new Error(`Inconsistent VP ids between JWT claim (${decoded.jti}) and VP value (${id})`);
117
+ }
118
+ presentation.id = decoded.jti;
119
+ }
120
+ return presentation;
121
+ }
122
+ static toUniformCredential(verifiableCredential, opts) {
123
+ const original = verifiableCredential;
124
+ const decoded = CredentialMapper.decodeVerifiableCredential(verifiableCredential);
125
+ const isJwtEncoded = CredentialMapper.isJwtEncoded(original);
126
+ const isJwtDecoded = CredentialMapper.isJwtDecodedCredential(original);
127
+ if (isJwtDecoded || isJwtEncoded) {
128
+ return CredentialMapper.jwtDecodedCredentialToUniformCredential(decoded, opts);
129
+ }
130
+ else {
131
+ return decoded;
132
+ }
133
+ }
134
+ static toUniformPresentation(presentation, opts) {
135
+ var _a;
136
+ const original = presentation;
137
+ const decoded = CredentialMapper.decodeVerifiablePresentation(original);
138
+ const isJwtEncoded = CredentialMapper.isJwtEncoded(original);
139
+ const isJwtDecoded = CredentialMapper.isJwtDecodedPresentation(original);
140
+ const uniformPresentation = isJwtEncoded || isJwtDecoded
141
+ ? CredentialMapper.jwtDecodedPresentationToUniformPresentation(decoded, false)
142
+ : decoded;
143
+ uniformPresentation.verifiableCredential = (_a = uniformPresentation.verifiableCredential) === null || _a === void 0 ? void 0 : _a.map((vc) => CredentialMapper.toUniformCredential(vc, opts)); // We cast it because we IPresentation needs a VC. The internal Credential doesn't have the required Proof anymore (that is intended)
144
+ return uniformPresentation;
145
+ }
146
+ static jwtEncodedCredentialToUniformCredential(jwt, opts) {
147
+ return CredentialMapper.jwtDecodedCredentialToUniformCredential((0, jwt_decode_1.default)(jwt), opts);
148
+ }
149
+ static jwtDecodedCredentialToUniformCredential(decoded, opts) {
150
+ const credential = Object.assign({}, decoded.vc);
151
+ // Since this is a credential, we delete any proof just to be sure (should not occur on JWT, but better safe than sorry)
152
+ delete credential.proof;
153
+ const maxSkewInMS = (opts === null || opts === void 0 ? void 0 : opts.maxTimeSkewInMS) !== undefined ? opts.maxTimeSkewInMS : 999;
154
+ if (decoded.exp) {
155
+ const expDate = credential.expirationDate;
156
+ const jwtExp = parseInt(decoded.exp.toString());
157
+ // fix seconds to millisecs for the date
158
+ const expDateAsStr = jwtExp < 9999999999 ? new Date(jwtExp * 1000).toISOString().replace(/\.000Z/, 'Z') : new Date(jwtExp).toISOString();
159
+ if (expDate && expDate !== expDateAsStr) {
160
+ const diff = Math.abs(new Date(expDateAsStr).getTime() - new Date(expDate).getTime());
161
+ if (!maxSkewInMS || diff > maxSkewInMS) {
162
+ throw new Error(`Inconsistent expiration dates between JWT claim (${expDateAsStr}) and VC value (${expDate})`);
163
+ }
164
+ }
165
+ credential.expirationDate = expDateAsStr;
166
+ }
167
+ if (decoded.nbf) {
168
+ const issuanceDate = credential.issuanceDate;
169
+ const jwtNbf = parseInt(decoded.nbf.toString());
170
+ // fix seconds to millisecs for the date
171
+ const nbfDateAsStr = jwtNbf < 9999999999 ? new Date(jwtNbf * 1000).toISOString().replace(/\.000Z/, 'Z') : new Date(jwtNbf).toISOString();
172
+ if (issuanceDate && issuanceDate !== nbfDateAsStr) {
173
+ const diff = Math.abs(new Date(nbfDateAsStr).getTime() - new Date(issuanceDate).getTime());
174
+ if (!maxSkewInMS || diff > maxSkewInMS) {
175
+ throw new Error(`Inconsistent issuance dates between JWT claim (${nbfDateAsStr}) and VC value (${issuanceDate})`);
176
+ }
177
+ }
178
+ credential.issuanceDate = nbfDateAsStr;
179
+ }
180
+ if (decoded.iss) {
181
+ const issuer = credential.issuer;
182
+ if (issuer) {
183
+ if (typeof issuer === 'string') {
184
+ if (issuer !== decoded.iss) {
185
+ throw new Error(`Inconsistent issuers between JWT claim (${decoded.iss}) and VC value (${issuer})`);
186
+ }
187
+ }
188
+ else {
189
+ if (issuer.id !== decoded.iss) {
190
+ throw new Error(`Inconsistent issuers between JWT claim (${decoded.iss}) and VC value (${issuer.id})`);
191
+ }
192
+ }
193
+ }
194
+ else {
195
+ credential.issuer = decoded.iss;
196
+ }
197
+ }
198
+ if (decoded.sub) {
199
+ const subjects = Array.isArray(credential.credentialSubject) ? credential.credentialSubject : [credential.credentialSubject];
200
+ for (let i = 0; i < subjects.length; i++) {
201
+ const csId = subjects[i].id;
202
+ if (csId && csId !== decoded.sub) {
203
+ throw new Error(`Inconsistent credential subject ids between JWT claim (${decoded.sub}) and VC value (${csId})`);
204
+ }
205
+ Array.isArray(credential.credentialSubject)
206
+ ? (credential.credentialSubject[i].id = decoded.sub)
207
+ : (credential.credentialSubject.id = decoded.sub);
208
+ }
209
+ }
210
+ if (decoded.jti) {
211
+ const id = credential.id;
212
+ if (id && id !== decoded.jti) {
213
+ throw new Error(`Inconsistent credential ids between JWT claim (${decoded.jti}) and VC value (${id})`);
214
+ }
215
+ credential.id = decoded.jti;
216
+ }
217
+ return credential;
218
+ }
219
+ }
220
+ exports.CredentialMapper = CredentialMapper;
221
+ //# sourceMappingURL=credential-mapper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"credential-mapper.js","sourceRoot":"","sources":["../../src/mapper/credential-mapper.ts"],"names":[],"mappings":";;;;;;AAAA,oCAaiB;AACjB,4DAAmC;AACnC,oCAAsC;AAEtC,MAAa,gBAAgB;IAC3B,MAAM,CAAC,4BAA4B,CAAC,YAA4C;QAC9E,IAAI,gBAAgB,CAAC,YAAY,CAAC,YAAY,CAAC,EAAE;YAC/C,OAAO,IAAA,oBAAU,EAAC,YAAsB,CAAqC,CAAA;SAC9E;aAAM,IAAI,gBAAgB,CAAC,wBAAwB,CAAC,YAAY,CAAC,EAAE;YAClE,OAAO,YAAgD,CAAA;SACxD;aAAM,IAAI,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;SA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,CAAC,UAAU,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC;oBACpD,CAAC,CAAC,CAAC,UAAU,CAAC,iBAAiB,CAAC,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC,CAAA;aACpD;SACF;QACD,IAAI,OAAO,CAAC,GAAG,EAAE;YACf,MAAM,EAAE,GAAG,UAAU,CAAC,EAAE,CAAA;YACxB,IAAI,EAAE,IAAI,EAAE,KAAK,OAAO,CAAC,GAAG,EAAE;gBAC5B,MAAM,IAAI,KAAK,CAAC,kDAAkD,OAAO,CAAC,GAAG,mBAAmB,EAAE,GAAG,CAAC,CAAA;aACvG;YACD,UAAU,CAAC,EAAE,GAAG,OAAO,CAAC,GAAG,CAAA;SAC5B;QACD,OAAO,UAAU,CAAA;IACnB,CAAC;CACF;AAjQD,4CAiQC"}
@@ -0,0 +1,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"}
@@ -31,4 +31,5 @@ export interface IParsedDID {
31
31
  [index: string]: string;
32
32
  };
33
33
  }
34
+ export declare const parseDid: (did: string) => IParsedDID;
34
35
  //# sourceMappingURL=did.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"did.d.ts","sourceRoot":"","sources":["../../src/types/did.ts"],"names":[],"mappings":"AAAA,oBAAY,aAAa;IACvB,kBAAkB,uBAAuB;IACzC,eAAe,oBAAoB;IACnC,cAAc,mBAAmB;IACjC,YAAY,iBAAiB;IAC7B,iBAAiB,qBAAqB;IACtC,oBAAoB,yBAAyB;IAC7C,oBAAoB,yBAAyB;CAC9C;AAED,oBAAY,UAAU;IACpB,oBAAoB,yBAAyB;IAC7C,oBAAoB,yBAAyB;IAC7C,2BAA2B,gCAAgC;IAC3D,mCAAmC,wCAAwC;IAC3E,oBAAoB,yBAAyB;IAC7C,gBAAgB,qBAAqB;IACrC,gBAAgB,qBAAqB;IACrC,uBAAuB,4BAA4B;IACnD,wBAAwB,6BAA6B;IACrD,6BAA6B,kCAAkC;CAChE;AAED,MAAM,WAAW,UAAU;IACzB,GAAG,EAAE,MAAM,CAAA;IACX,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,MAAM,CAAA;IACd,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,EAAE;QACP,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAA;KACxB,CAAA;CACF"}
1
+ {"version":3,"file":"did.d.ts","sourceRoot":"","sources":["../../src/types/did.ts"],"names":[],"mappings":"AAAA,oBAAY,aAAa;IACvB,kBAAkB,uBAAuB;IACzC,eAAe,oBAAoB;IACnC,cAAc,mBAAmB;IACjC,YAAY,iBAAiB;IAC7B,iBAAiB,qBAAqB;IACtC,oBAAoB,yBAAyB;IAC7C,oBAAoB,yBAAyB;CAC9C;AAED,oBAAY,UAAU;IACpB,oBAAoB,yBAAyB;IAC7C,oBAAoB,yBAAyB;IAC7C,2BAA2B,gCAAgC;IAC3D,mCAAmC,wCAAwC;IAC3E,oBAAoB,yBAAyB;IAC7C,gBAAgB,qBAAqB;IACrC,gBAAgB,qBAAqB;IACrC,uBAAuB,4BAA4B;IACnD,wBAAwB,6BAA6B;IACrD,6BAA6B,kCAAkC;CAChE;AAED,MAAM,WAAW,UAAU;IACzB,GAAG,EAAE,MAAM,CAAA;IACX,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,MAAM,CAAA;IACd,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,EAAE;QACP,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAA;KACxB,CAAA;CACF;AAED,eAAO,MAAM,QAAQ,QAAS,MAAM,KAAG,UAOtC,CAAA"}
package/dist/types/did.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.IProofType = exports.IProofPurpose = void 0;
3
+ exports.parseDid = exports.IProofType = exports.IProofPurpose = void 0;
4
4
  var IProofPurpose;
5
5
  (function (IProofPurpose) {
6
6
  IProofPurpose["verificationMethod"] = "verificationMethod";
@@ -24,4 +24,52 @@ var IProofType;
24
24
  IProofType["BbsBlsSignatureProof2020"] = "BbsBlsSignatureProof2020";
25
25
  IProofType["BbsBlsBoundSignatureProof2020"] = "BbsBlsBoundSignatureProof2020";
26
26
  })(IProofType = exports.IProofType || (exports.IProofType = {}));
27
+ const parseDid = (did) => {
28
+ const parsedDid = parse(did);
29
+ if (parsedDid === null) {
30
+ throw new Error('invalid did');
31
+ }
32
+ return parsedDid;
33
+ };
34
+ exports.parseDid = parseDid;
35
+ const parse = (didUrl) => {
36
+ const PCT_ENCODED = '(?:%[0-9a-fA-F]{2})';
37
+ const ID_CHAR = `(?:[a-zA-Z0-9._-]|${PCT_ENCODED})`;
38
+ const METHOD = '([a-z0-9]+)';
39
+ const METHOD_ID = `((?:${ID_CHAR}*:)*(${ID_CHAR}+))`;
40
+ const PARAM_CHAR = '[a-zA-Z0-9_.:%-]';
41
+ const PARAM = `;${PARAM_CHAR}+=${PARAM_CHAR}*`;
42
+ const PARAMS = `((${PARAM})*)`;
43
+ const PATH = `(/[^#?]*)?`;
44
+ const QUERY = `([?][^#]*)?`;
45
+ const FRAGMENT = `(#.*)?`;
46
+ const DID_MATCHER = new RegExp(`^did:${METHOD}:${METHOD_ID}${PARAMS}${PATH}${QUERY}${FRAGMENT}$`);
47
+ if (didUrl === '' || !didUrl)
48
+ return null;
49
+ const sections = didUrl.match(DID_MATCHER);
50
+ if (sections) {
51
+ const parts = {
52
+ did: `did:${sections[1]}:${sections[2]}`,
53
+ method: sections[1],
54
+ id: sections[2],
55
+ didUrl,
56
+ };
57
+ if (sections[4]) {
58
+ const params = sections[4].slice(1).split(';');
59
+ parts.params = {};
60
+ for (const p of params) {
61
+ const kv = p.split('=');
62
+ parts.params[kv[0]] = kv[1];
63
+ }
64
+ }
65
+ if (sections[6])
66
+ parts.path = sections[6];
67
+ if (sections[7])
68
+ parts.query = sections[7].slice(1);
69
+ if (sections[8])
70
+ parts.fragment = sections[8].slice(1);
71
+ return parts;
72
+ }
73
+ return null;
74
+ };
27
75
  //# sourceMappingURL=did.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"did.js","sourceRoot":"","sources":["../../src/types/did.ts"],"names":[],"mappings":";;;AAAA,IAAY,aAQX;AARD,WAAY,aAAa;IACvB,0DAA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C,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;YAC9C,KAAK,CAAC,MAAM,GAAG,EAAE,CAAA;YACjB,KAAK,MAAM,CAAC,IAAI,MAAM,EAAE;gBACtB,MAAM,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;gBACvB,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAA;aAC5B;SACF;QACD,IAAI,QAAQ,CAAC,CAAC,CAAC;YAAE,KAAK,CAAC,IAAI,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAA;QACzC,IAAI,QAAQ,CAAC,CAAC,CAAC;YAAE,KAAK,CAAC,KAAK,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;QACnD,IAAI,QAAQ,CAAC,CAAC,CAAC;YAAE,KAAK,CAAC,QAAQ,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;QACtD,OAAO,KAAK,CAAA;KACb;IAED,OAAO,IAAI,CAAA;AACb,CAAC,CAAA"}
@@ -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,30 +1,30 @@
1
1
  import { PresentationSubmission } from './pex';
2
2
  import { IProofPurpose, IProofType } from './did';
3
+ export type AdditionalClaims = Record<string, any>;
4
+ export type IIssuerId = string;
3
5
  export interface ICredential {
4
- expirationDate?: string;
5
- issuer: string | IIssuer;
6
+ '@context': ICredentialContextType | ICredentialContextType[];
7
+ type: string[];
8
+ credentialSchema?: undefined | ICredentialSchemaType | ICredentialSchemaType[];
9
+ issuer: IIssuerId | IIssuer;
6
10
  issuanceDate: string;
7
- credentialSubject: ICredentialSubject;
8
- id: string;
9
- '@context': ICredentialContextType[] | ICredentialContextType;
11
+ credentialSubject: (ICredentialSubject & AdditionalClaims) | (ICredentialSubject & AdditionalClaims)[];
12
+ expirationDate?: string;
13
+ id?: string;
10
14
  credentialStatus?: ICredentialStatus;
11
- credentialSchema?: undefined | ICredentialSchemaType | ICredentialSchemaType[];
12
15
  description?: string;
13
16
  name?: string;
14
- type: string[];
15
- [x: string]: unknown;
17
+ [x: string]: any;
16
18
  }
17
19
  export interface ICredentialSubject {
18
20
  id?: string;
19
- [x: string]: unknown;
20
21
  }
21
- export declare type ICredentialContextType = ICredentialContext | string;
22
+ export type ICredentialContextType = (ICredentialContext & AdditionalClaims) | string;
22
23
  export interface ICredentialContext {
23
24
  name?: string;
24
25
  did?: string;
25
- [x: string]: unknown;
26
26
  }
27
- export declare type ICredentialSchemaType = ICredentialSchema | string;
27
+ export type ICredentialSchemaType = ICredentialSchema | string;
28
28
  export interface ICredentialSchema {
29
29
  id: string;
30
30
  type?: string;
@@ -40,7 +40,7 @@ export interface IProof {
40
40
  jws?: string;
41
41
  nonce?: string;
42
42
  requiredRevealStatements?: string[];
43
- [x: string]: string | string[] | undefined;
43
+ [x: string]: any;
44
44
  }
45
45
  export interface ICredentialStatus {
46
46
  id: string;
@@ -48,71 +48,120 @@ export interface ICredentialStatus {
48
48
  }
49
49
  export interface IIssuer {
50
50
  id: string;
51
- [x: string]: unknown;
51
+ [x: string]: any;
52
52
  }
53
53
  export interface IHasProof {
54
54
  proof: IProof | IProof[];
55
55
  }
56
- export declare type IVerifiableCredential = ICredential & IHasProof;
56
+ export type IVerifiableCredential = ICredential & IHasProof;
57
+ /**
58
+ * Represents a Json Web Token in compact form.
59
+ */
60
+ export type CompactJWT = string;
61
+ /**
62
+ * Represents a signed Verifiable Credential (includes proof), in either JSON or compact JWT format.
63
+ * See {@link https://www.w3.org/TR/vc-data-model/#credentials | VC data model}
64
+ * See {@link https://www.w3.org/TR/vc-data-model/#proof-formats | proof formats}
65
+ */
66
+ export type W3CVerifiableCredential = IVerifiableCredential | CompactJWT;
57
67
  export interface IPresentation {
68
+ id?: string;
58
69
  '@context': ICredentialContextType | ICredentialContextType[];
59
70
  type: string[];
60
- verifiableCredential: IVerifiableCredential[];
71
+ verifiableCredential: W3CVerifiableCredential[];
61
72
  presentation_submission?: PresentationSubmission;
62
73
  holder?: string;
74
+ [x: string]: any;
63
75
  }
64
- export declare type IVerifiablePresentation = IPresentation & IHasProof;
76
+ export type IVerifiablePresentation = IPresentation & IHasProof;
77
+ /**
78
+ * Represents a signed Verifiable Presentation (includes proof), in either JSON or compact JWT format.
79
+ * See {@link https://www.w3.org/TR/vc-data-model/#presentations | VC data model}
80
+ * See {@link https://www.w3.org/TR/vc-data-model/#proof-formats | proof formats}
81
+ */
82
+ export type W3CVerifiablePresentation = IVerifiablePresentation | CompactJWT;
65
83
  export interface WrappedVerifiableCredential {
66
84
  /**
67
85
  * Original VC that we've received
68
86
  */
69
- original: string | JwtWrappedVerifiableCredential | IVerifiableCredential;
87
+ original: OriginalVerifiableCredential;
70
88
  /**
71
89
  * In case of JWT credential it will be the decoded version. In other cases it will be the same as original one
72
90
  */
73
- decoded: JwtWrappedVerifiableCredential | IVerifiableCredential;
91
+ decoded: JwtDecodedVerifiableCredential | IVerifiableCredential;
92
+ /**
93
+ * Type of this credential. Supported types are json-ld and jwt (decoded/encoded)
94
+ */
95
+ type: OriginalType;
74
96
  /**
75
- * Type of this credential. Supported types are json-ld and jwt
97
+ * The claim format, typically used during exchange transport protocols
76
98
  */
77
- type: VerifiableDataExchangeType;
99
+ format: CredentialFormat;
78
100
  /**
79
- * created based on https://www.w3.org/TR/vc-data-model/#jwt-decoding
101
+ * Internal stable representation of a Credential without Proofs, created based on https://www.w3.org/TR/vc-data-model/#jwt-decoding
80
102
  */
81
- internalCredential: ICredential;
103
+ credential: ICredential;
82
104
  }
83
105
  export interface WrappedVerifiablePresentation {
84
- original: string | JwtWrappedVerifiablePresentation | IVerifiablePresentation;
85
- decoded: JwtWrappedVerifiablePresentation | IVerifiablePresentation;
86
- type: VerifiableDataExchangeType;
87
- internalPresentation: InternalPresentation;
106
+ /**
107
+ * Original VP that we've received
108
+ */
109
+ original: OriginalVerifiablePresentation;
110
+ /**
111
+ * In case of JWT VP it will be the decoded version. In other cases it will be the same as original one
112
+ */
113
+ decoded: JwtDecodedVerifiablePresentation | IVerifiablePresentation;
114
+ /**
115
+ * Type of this Presentation. Supported types are json-ld and jwt (decoded/encoded)
116
+ */
117
+ type: OriginalType;
118
+ /**
119
+ * The claim format, typically used during exchange transport protocols
120
+ */
121
+ format: PresentationFormat;
122
+ /**
123
+ * Internal stable representation of a Presentation without proofs, created based on https://www.w3.org/TR/vc-data-model/#jwt-decoding
124
+ */
125
+ presentation: UniformVerifiablePresentation;
126
+ /**
127
+ * Wrapped Verifiable Credentials belonging to the Presentation
128
+ */
88
129
  vcs: WrappedVerifiableCredential[];
89
130
  }
90
- export declare enum VerifiableDataExchangeType {
91
- JSONLD = 0,
92
- JWT_ENCODED = 1,
93
- JWT_DECODED = 2
131
+ export declare enum OriginalType {
132
+ JSONLD = "json-ld",
133
+ JWT_ENCODED = "jwt-encoded",
134
+ JWT_DECODED = "jwt-decoded"
94
135
  }
95
- export interface InternalPresentation {
136
+ export interface UniformVerifiablePresentation {
96
137
  '@context': ICredentialContextType | ICredentialContextType[];
97
138
  type: string[];
98
139
  verifiableCredential: WrappedVerifiableCredential[];
99
140
  presentation_submission?: PresentationSubmission;
100
141
  holder?: string;
101
142
  }
102
- export interface JwtWrappedVerifiableCredential {
143
+ export interface JwtDecodedVerifiableCredential {
103
144
  vc: ICredential;
104
145
  exp: string;
105
146
  iss: string;
106
147
  nbf: string;
107
148
  sub: string;
108
149
  jti: string;
150
+ [x: string]: any;
109
151
  }
110
- export interface JwtWrappedVerifiablePresentation {
152
+ export interface JwtDecodedVerifiablePresentation {
111
153
  vp: IVerifiablePresentation;
112
154
  exp: string;
113
155
  iss: string;
114
156
  nbf: string;
115
157
  sub: string;
116
158
  jti: string;
159
+ [x: string]: any;
117
160
  }
161
+ export type CredentialFormat = 'jwt' | 'ldp' | 'jwt_vc' | 'ldp_vc' | string;
162
+ export type PresentationFormat = 'jwt' | 'ldp' | 'jwt_vp' | 'ldp_vp' | string;
163
+ export type ClaimFormat = CredentialFormat | PresentationFormat;
164
+ export type OriginalVerifiableCredential = W3CVerifiableCredential | JwtDecodedVerifiableCredential;
165
+ export type OriginalVerifiablePresentation = W3CVerifiablePresentation | JwtDecodedVerifiablePresentation;
166
+ export type Original = OriginalVerifiablePresentation | OriginalVerifiableCredential;
118
167
  //# sourceMappingURL=vc.d.ts.map