@sphereon/ssi-types 0.8.1-next.12 → 0.8.1-next.121
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/mapper/credential-mapper.d.ts +27 -9
- package/dist/mapper/credential-mapper.d.ts.map +1 -1
- package/dist/mapper/credential-mapper.js +41 -28
- package/dist/mapper/credential-mapper.js.map +1 -1
- package/dist/types/vc.d.ts +38 -18
- package/dist/types/vc.d.ts.map +1 -1
- package/dist/types/vc.js.map +1 -1
- package/package.json +2 -2
- package/src/mapper/credential-mapper.ts +60 -30
- package/src/types/vc.ts +38 -13
|
@@ -2,18 +2,36 @@ import { ICredential, IPresentation, IVerifiableCredential, IVerifiablePresentat
|
|
|
2
2
|
export declare class CredentialMapper {
|
|
3
3
|
static decodeVerifiablePresentation(presentation: OriginalVerifiablePresentation): JwtDecodedVerifiablePresentation | IVerifiablePresentation;
|
|
4
4
|
static decodeVerifiableCredential(credential: OriginalVerifiableCredential): JwtDecodedVerifiableCredential | IVerifiableCredential;
|
|
5
|
-
static toWrappedVerifiablePresentation(presentation: OriginalVerifiablePresentation
|
|
6
|
-
|
|
7
|
-
|
|
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;
|
|
8
14
|
static isJwtEncoded(original: OriginalVerifiableCredential | OriginalVerifiablePresentation): boolean;
|
|
9
15
|
private static isJsonLdString;
|
|
10
16
|
static isJwtDecodedCredential(original: OriginalVerifiableCredential): boolean;
|
|
11
17
|
static isJwtDecodedPresentation(original: OriginalVerifiablePresentation): boolean;
|
|
12
|
-
static jwtEncodedPresentationToUniformPresentation(jwt: string, makeCredentialsUniform?: boolean
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
static
|
|
16
|
-
|
|
17
|
-
|
|
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;
|
|
18
36
|
}
|
|
19
37
|
//# sourceMappingURL=credential-mapper.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"credential-mapper.d.ts","sourceRoot":"","sources":["../../src/mapper/credential-mapper.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"credential-mapper.d.ts","sourceRoot":"","sources":["../../src/mapper/credential-mapper.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,aAAa,EACb,qBAAqB,EACrB,uB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AA;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"}
|
|
@@ -36,7 +36,7 @@ class CredentialMapper {
|
|
|
36
36
|
return credential;
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
|
-
static toWrappedVerifiablePresentation(presentation) {
|
|
39
|
+
static toWrappedVerifiablePresentation(presentation, opts) {
|
|
40
40
|
const original = presentation;
|
|
41
41
|
const isJwtEncoded = CredentialMapper.isJwtEncoded(original);
|
|
42
42
|
const isJwtDecoded = CredentialMapper.isJwtDecodedPresentation(original);
|
|
@@ -44,9 +44,9 @@ class CredentialMapper {
|
|
|
44
44
|
const format = isJwtDecoded || isJwtEncoded ? 'jwt_vp' : 'ldp_vp';
|
|
45
45
|
const decoded = CredentialMapper.decodeVerifiablePresentation(original);
|
|
46
46
|
const vp = isJwtEncoded || isJwtDecoded
|
|
47
|
-
? CredentialMapper.jwtDecodedPresentationToUniformPresentation(decoded, false)
|
|
47
|
+
? CredentialMapper.jwtDecodedPresentationToUniformPresentation(decoded, false, opts)
|
|
48
48
|
: decoded;
|
|
49
|
-
const vcs = CredentialMapper.toWrappedVerifiableCredentials(vp.verifiableCredential);
|
|
49
|
+
const vcs = CredentialMapper.toWrappedVerifiableCredentials(vp.verifiableCredential, opts);
|
|
50
50
|
// todo: We probably want to add proofs as well
|
|
51
51
|
return {
|
|
52
52
|
type,
|
|
@@ -57,17 +57,17 @@ class CredentialMapper {
|
|
|
57
57
|
vcs,
|
|
58
58
|
};
|
|
59
59
|
}
|
|
60
|
-
static toWrappedVerifiableCredentials(verifiableCredentials) {
|
|
61
|
-
return verifiableCredentials.map(CredentialMapper.toWrappedVerifiableCredential);
|
|
60
|
+
static toWrappedVerifiableCredentials(verifiableCredentials, opts) {
|
|
61
|
+
return verifiableCredentials.map((vc) => CredentialMapper.toWrappedVerifiableCredential(vc, opts));
|
|
62
62
|
}
|
|
63
|
-
static toWrappedVerifiableCredential(verifiableCredential) {
|
|
63
|
+
static toWrappedVerifiableCredential(verifiableCredential, opts) {
|
|
64
64
|
const original = verifiableCredential;
|
|
65
65
|
const decoded = CredentialMapper.decodeVerifiableCredential(verifiableCredential);
|
|
66
66
|
const isJwtEncoded = CredentialMapper.isJwtEncoded(original);
|
|
67
67
|
const isJwtDecoded = CredentialMapper.isJwtDecodedCredential(original);
|
|
68
68
|
const type = isJwtEncoded ? types_1.OriginalType.JWT_ENCODED : isJwtDecoded ? types_1.OriginalType.JWT_DECODED : types_1.OriginalType.JSONLD;
|
|
69
69
|
const credential = isJwtDecoded || isJwtDecoded
|
|
70
|
-
? CredentialMapper.jwtDecodedCredentialToUniformCredential(decoded)
|
|
70
|
+
? CredentialMapper.jwtDecodedCredentialToUniformCredential(decoded, opts)
|
|
71
71
|
: decoded;
|
|
72
72
|
const format = isJwtDecoded || isJwtDecoded ? 'jwt_vc' : 'ldp_vc';
|
|
73
73
|
//todo: We probably want to add proofs as well
|
|
@@ -91,13 +91,13 @@ class CredentialMapper {
|
|
|
91
91
|
static isJwtDecodedPresentation(original) {
|
|
92
92
|
return original['vp'] !== undefined && original['iss'] !== undefined;
|
|
93
93
|
}
|
|
94
|
-
static jwtEncodedPresentationToUniformPresentation(jwt, makeCredentialsUniform = true) {
|
|
95
|
-
return CredentialMapper.jwtDecodedPresentationToUniformPresentation((0, jwt_decode_1.default)(jwt), makeCredentialsUniform);
|
|
94
|
+
static jwtEncodedPresentationToUniformPresentation(jwt, makeCredentialsUniform = true, opts) {
|
|
95
|
+
return CredentialMapper.jwtDecodedPresentationToUniformPresentation((0, jwt_decode_1.default)(jwt), makeCredentialsUniform, opts);
|
|
96
96
|
}
|
|
97
|
-
static jwtDecodedPresentationToUniformPresentation(decoded, makeCredentialsUniform = true) {
|
|
97
|
+
static jwtDecodedPresentationToUniformPresentation(decoded, makeCredentialsUniform = true, opts) {
|
|
98
98
|
const presentation = Object.assign({}, decoded.vp);
|
|
99
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)
|
|
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
101
|
}
|
|
102
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
103
|
delete presentation.proof;
|
|
@@ -119,19 +119,19 @@ class CredentialMapper {
|
|
|
119
119
|
}
|
|
120
120
|
return presentation;
|
|
121
121
|
}
|
|
122
|
-
static toUniformCredential(verifiableCredential) {
|
|
122
|
+
static toUniformCredential(verifiableCredential, opts) {
|
|
123
123
|
const original = verifiableCredential;
|
|
124
124
|
const decoded = CredentialMapper.decodeVerifiableCredential(verifiableCredential);
|
|
125
125
|
const isJwtEncoded = CredentialMapper.isJwtEncoded(original);
|
|
126
126
|
const isJwtDecoded = CredentialMapper.isJwtDecodedCredential(original);
|
|
127
127
|
if (isJwtDecoded || isJwtEncoded) {
|
|
128
|
-
return CredentialMapper.jwtDecodedCredentialToUniformCredential(decoded);
|
|
128
|
+
return CredentialMapper.jwtDecodedCredentialToUniformCredential(decoded, opts);
|
|
129
129
|
}
|
|
130
130
|
else {
|
|
131
131
|
return decoded;
|
|
132
132
|
}
|
|
133
133
|
}
|
|
134
|
-
static toUniformPresentation(presentation) {
|
|
134
|
+
static toUniformPresentation(presentation, opts) {
|
|
135
135
|
var _a;
|
|
136
136
|
const original = presentation;
|
|
137
137
|
const decoded = CredentialMapper.decodeVerifiablePresentation(original);
|
|
@@ -140,26 +140,29 @@ class CredentialMapper {
|
|
|
140
140
|
const uniformPresentation = isJwtEncoded || isJwtDecoded
|
|
141
141
|
? CredentialMapper.jwtDecodedPresentationToUniformPresentation(decoded, false)
|
|
142
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)
|
|
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
144
|
return uniformPresentation;
|
|
145
145
|
}
|
|
146
|
-
static jwtEncodedCredentialToUniformCredential(jwt) {
|
|
147
|
-
return CredentialMapper.jwtDecodedCredentialToUniformCredential((0, jwt_decode_1.default)(jwt));
|
|
146
|
+
static jwtEncodedCredentialToUniformCredential(jwt, opts) {
|
|
147
|
+
return CredentialMapper.jwtDecodedCredentialToUniformCredential((0, jwt_decode_1.default)(jwt), opts);
|
|
148
148
|
}
|
|
149
|
-
static jwtDecodedCredentialToUniformCredential(decoded) {
|
|
150
|
-
var _a, _b;
|
|
149
|
+
static jwtDecodedCredentialToUniformCredential(decoded, opts) {
|
|
151
150
|
const credential = Object.assign({}, decoded.vc);
|
|
152
151
|
// Since this is a credential, we delete any proof just to be sure (should not occur on JWT, but better safe than sorry)
|
|
153
152
|
delete credential.proof;
|
|
153
|
+
const maxSkewInMS = (opts === null || opts === void 0 ? void 0 : opts.maxTimeSkewInMS) !== undefined ? opts.maxTimeSkewInMS : 999;
|
|
154
154
|
if (decoded.exp) {
|
|
155
|
-
const expDate =
|
|
155
|
+
const expDate = credential.expirationDate;
|
|
156
156
|
const jwtExp = parseInt(decoded.exp.toString());
|
|
157
157
|
// fix seconds to millisecs for the date
|
|
158
158
|
const expDateAsStr = jwtExp < 9999999999 ? new Date(jwtExp * 1000).toISOString().replace(/\.000Z/, 'Z') : new Date(jwtExp).toISOString();
|
|
159
159
|
if (expDate && expDate !== expDateAsStr) {
|
|
160
|
-
|
|
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
|
+
}
|
|
161
164
|
}
|
|
162
|
-
credential.
|
|
165
|
+
credential.expirationDate = expDateAsStr;
|
|
163
166
|
}
|
|
164
167
|
if (decoded.nbf) {
|
|
165
168
|
const issuanceDate = credential.issuanceDate;
|
|
@@ -167,7 +170,10 @@ class CredentialMapper {
|
|
|
167
170
|
// fix seconds to millisecs for the date
|
|
168
171
|
const nbfDateAsStr = jwtNbf < 9999999999 ? new Date(jwtNbf * 1000).toISOString().replace(/\.000Z/, 'Z') : new Date(jwtNbf).toISOString();
|
|
169
172
|
if (issuanceDate && issuanceDate !== nbfDateAsStr) {
|
|
170
|
-
|
|
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
|
+
}
|
|
171
177
|
}
|
|
172
178
|
credential.issuanceDate = nbfDateAsStr;
|
|
173
179
|
}
|
|
@@ -185,14 +191,21 @@ class CredentialMapper {
|
|
|
185
191
|
}
|
|
186
192
|
}
|
|
187
193
|
}
|
|
188
|
-
|
|
194
|
+
else {
|
|
195
|
+
credential.issuer = decoded.iss;
|
|
196
|
+
}
|
|
189
197
|
}
|
|
190
198
|
if (decoded.sub) {
|
|
191
|
-
const
|
|
192
|
-
|
|
193
|
-
|
|
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);
|
|
194
208
|
}
|
|
195
|
-
credential.credentialSubject.id = decoded.sub;
|
|
196
209
|
}
|
|
197
210
|
if (decoded.jti) {
|
|
198
211
|
const id = credential.id;
|
|
@@ -1 +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,Y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AC,OAAO,CAAC,UAAU,CAAC,iBAAiB,CAAC;oBACzC,CAAC,CAAC,CAAC,UAAU,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC;oBACpD,CAAC,CAAC,CAAC,UAAU,CAAC,iBAAiB,CAAC,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC,CAAA;aACpD;SACF;QACD,IAAI,OAAO,CAAC,GAAG,EAAE;YACf,MAAM,EAAE,GAAG,UAAU,CAAC,EAAE,CAAA;YACxB,IAAI,EAAE,IAAI,EAAE,KAAK,OAAO,CAAC,GAAG,EAAE;gBAC5B,MAAM,IAAI,KAAK,CAAC,kDAAkD,OAAO,CAAC,GAAG,mBAAmB,EAAE,GAAG,CAAC,CAAA;aACvG;YACD,UAAU,CAAC,EAAE,GAAG,OAAO,CAAC,GAAG,CAAA;SAC5B;QACD,OAAO,UAAU,CAAA;IACnB,CAAC;CACF;AAjQD,4CAiQC"}
|
package/dist/types/vc.d.ts
CHANGED
|
@@ -1,29 +1,30 @@
|
|
|
1
1
|
import { PresentationSubmission } from './pex';
|
|
2
2
|
import { IProofPurpose, IProofType } from './did';
|
|
3
|
-
export
|
|
3
|
+
export type AdditionalClaims = Record<string, any>;
|
|
4
|
+
export type IIssuerId = string;
|
|
4
5
|
export interface ICredential {
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
'@context': ICredentialContextType | ICredentialContextType[];
|
|
7
|
+
type: string[];
|
|
8
|
+
credentialSchema?: undefined | ICredentialSchemaType | ICredentialSchemaType[];
|
|
9
|
+
issuer: IIssuerId | IIssuer;
|
|
7
10
|
issuanceDate: string;
|
|
8
|
-
credentialSubject: ICredentialSubject & AdditionalClaims;
|
|
11
|
+
credentialSubject: (ICredentialSubject & AdditionalClaims) | (ICredentialSubject & AdditionalClaims)[];
|
|
12
|
+
expirationDate?: string;
|
|
9
13
|
id?: string;
|
|
10
|
-
'@context': ICredentialContextType[] | ICredentialContextType;
|
|
11
14
|
credentialStatus?: ICredentialStatus;
|
|
12
|
-
credentialSchema?: undefined | ICredentialSchemaType | ICredentialSchemaType[];
|
|
13
15
|
description?: string;
|
|
14
16
|
name?: string;
|
|
15
|
-
type: string[];
|
|
16
17
|
[x: string]: any;
|
|
17
18
|
}
|
|
18
19
|
export interface ICredentialSubject {
|
|
19
20
|
id?: string;
|
|
20
21
|
}
|
|
21
|
-
export
|
|
22
|
+
export type ICredentialContextType = (ICredentialContext & AdditionalClaims) | string;
|
|
22
23
|
export interface ICredentialContext {
|
|
23
24
|
name?: string;
|
|
24
25
|
did?: string;
|
|
25
26
|
}
|
|
26
|
-
export
|
|
27
|
+
export type ICredentialSchemaType = ICredentialSchema | string;
|
|
27
28
|
export interface ICredentialSchema {
|
|
28
29
|
id: string;
|
|
29
30
|
type?: string;
|
|
@@ -39,6 +40,7 @@ export interface IProof {
|
|
|
39
40
|
jws?: string;
|
|
40
41
|
nonce?: string;
|
|
41
42
|
requiredRevealStatements?: string[];
|
|
43
|
+
[x: string]: any;
|
|
42
44
|
}
|
|
43
45
|
export interface ICredentialStatus {
|
|
44
46
|
id: string;
|
|
@@ -51,17 +53,33 @@ export interface IIssuer {
|
|
|
51
53
|
export interface IHasProof {
|
|
52
54
|
proof: IProof | IProof[];
|
|
53
55
|
}
|
|
54
|
-
export
|
|
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;
|
|
55
67
|
export interface IPresentation {
|
|
56
68
|
id?: string;
|
|
57
69
|
'@context': ICredentialContextType | ICredentialContextType[];
|
|
58
70
|
type: string[];
|
|
59
|
-
verifiableCredential:
|
|
71
|
+
verifiableCredential: W3CVerifiableCredential[];
|
|
60
72
|
presentation_submission?: PresentationSubmission;
|
|
61
73
|
holder?: string;
|
|
62
74
|
[x: string]: any;
|
|
63
75
|
}
|
|
64
|
-
export
|
|
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
|
|
@@ -78,7 +96,7 @@ export interface WrappedVerifiableCredential {
|
|
|
78
96
|
/**
|
|
79
97
|
* The claim format, typically used during exchange transport protocols
|
|
80
98
|
*/
|
|
81
|
-
format:
|
|
99
|
+
format: CredentialFormat;
|
|
82
100
|
/**
|
|
83
101
|
* Internal stable representation of a Credential without Proofs, created based on https://www.w3.org/TR/vc-data-model/#jwt-decoding
|
|
84
102
|
*/
|
|
@@ -100,7 +118,7 @@ export interface WrappedVerifiablePresentation {
|
|
|
100
118
|
/**
|
|
101
119
|
* The claim format, typically used during exchange transport protocols
|
|
102
120
|
*/
|
|
103
|
-
format:
|
|
121
|
+
format: PresentationFormat;
|
|
104
122
|
/**
|
|
105
123
|
* Internal stable representation of a Presentation without proofs, created based on https://www.w3.org/TR/vc-data-model/#jwt-decoding
|
|
106
124
|
*/
|
|
@@ -140,8 +158,10 @@ export interface JwtDecodedVerifiablePresentation {
|
|
|
140
158
|
jti: string;
|
|
141
159
|
[x: string]: any;
|
|
142
160
|
}
|
|
143
|
-
export
|
|
144
|
-
export
|
|
145
|
-
export
|
|
146
|
-
export
|
|
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;
|
|
147
167
|
//# sourceMappingURL=vc.d.ts.map
|
package/dist/types/vc.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vc.d.ts","sourceRoot":"","sources":["../../src/types/vc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,OAAO,CAAA;AAC9C,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,OAAO,CAAA;AAEjD,
|
|
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,MAAM,gBAAgB,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;AAElD,MAAM,MAAM,SAAS,GAAG,MAAM,CAAA;AAE9B,MAAM,WAAW,WAAW;IAC1B,UAAU,EAAE,sBAAsB,GAAG,sBAAsB,EAAE,CAAA;IAC7D,IAAI,EAAE,MAAM,EAAE,CAAA;IACd,gBAAgB,CAAC,EAAE,SAAS,GAAG,qBAAqB,GAAG,qBAAqB,EAAE,CAAA;IAE9E,MAAM,EAAE,SAAS,GAAG,O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,MAAM,kBAAkB,GAAG,KAAK,GAAG,KAAK,GAAG,QAAQ,GAAG,QAAQ,GAAG,MAAM,CAAA;AAC7E,MAAM,MAAM,WAAW,GAAG,gBAAgB,GAAG,kBAAkB,CAAA;AAE/D,MAAM,MAAM,4BAA4B,GAAG,uBAAuB,GAAG,8BAA8B,CAAA;AACnG,MAAM,MAAM,8BAA8B,GAAG,yBAAyB,GAAG,gCAAgC,CAAA;AACzG,MAAM,MAAM,QAAQ,GAAG,8BAA8B,GAAG,4BAA4B,CAAA"}
|
package/dist/types/vc.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vc.js","sourceRoot":"","sources":["../../src/types/vc.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"vc.js","sourceRoot":"","sources":["../../src/types/vc.ts"],"names":[],"mappings":";;;AAgKA,IAAY,YAIX;AAJD,WAAY,YAAY;IACtB,kCAAkB,CAAA;IAClB,2CAA2B,CAAA;IAC3B,2CAA2B,CAAA;AAC7B,CAAC,EAJW,YAAY,GAAZ,oBAAY,KAAZ,oBAAY,QAIvB"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sphereon/ssi-types",
|
|
3
3
|
"description": "SSI Common Types",
|
|
4
|
-
"version": "0.8.1-next.
|
|
4
|
+
"version": "0.8.1-next.121+d98b358",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
@@ -37,5 +37,5 @@
|
|
|
37
37
|
"Verifiable Credentials",
|
|
38
38
|
"DIDs"
|
|
39
39
|
],
|
|
40
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "d98b358ff7f9c787667b4bf48fd748ae9f58197a"
|
|
41
41
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import {
|
|
2
|
-
ClaimFormat,
|
|
3
2
|
ICredential,
|
|
4
3
|
IPresentation,
|
|
5
4
|
IVerifiableCredential,
|
|
@@ -9,6 +8,7 @@ import {
|
|
|
9
8
|
OriginalType,
|
|
10
9
|
OriginalVerifiableCredential,
|
|
11
10
|
OriginalVerifiablePresentation,
|
|
11
|
+
PresentationFormat,
|
|
12
12
|
WrappedVerifiableCredential,
|
|
13
13
|
WrappedVerifiablePresentation,
|
|
14
14
|
} from '../types'
|
|
@@ -40,19 +40,22 @@ export class CredentialMapper {
|
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
static toWrappedVerifiablePresentation(
|
|
43
|
+
static toWrappedVerifiablePresentation(
|
|
44
|
+
presentation: OriginalVerifiablePresentation,
|
|
45
|
+
opts?: { maxTimeSkewInMS?: number }
|
|
46
|
+
): WrappedVerifiablePresentation {
|
|
44
47
|
const original = presentation
|
|
45
48
|
const isJwtEncoded: boolean = CredentialMapper.isJwtEncoded(original)
|
|
46
49
|
const isJwtDecoded: boolean = CredentialMapper.isJwtDecodedPresentation(original)
|
|
47
50
|
|
|
48
51
|
const type = isJwtEncoded ? OriginalType.JWT_ENCODED : isJwtDecoded ? OriginalType.JWT_DECODED : OriginalType.JSONLD
|
|
49
|
-
const format:
|
|
52
|
+
const format: PresentationFormat = isJwtDecoded || isJwtEncoded ? 'jwt_vp' : 'ldp_vp'
|
|
50
53
|
const decoded = CredentialMapper.decodeVerifiablePresentation(original)
|
|
51
54
|
const vp: IPresentation =
|
|
52
55
|
isJwtEncoded || isJwtDecoded
|
|
53
|
-
? CredentialMapper.jwtDecodedPresentationToUniformPresentation(decoded as JwtDecodedVerifiablePresentation, false)
|
|
56
|
+
? CredentialMapper.jwtDecodedPresentationToUniformPresentation(decoded as JwtDecodedVerifiablePresentation, false, opts)
|
|
54
57
|
: (decoded as IPresentation)
|
|
55
|
-
const vcs: WrappedVerifiableCredential[] = CredentialMapper.toWrappedVerifiableCredentials(vp.verifiableCredential)
|
|
58
|
+
const vcs: WrappedVerifiableCredential[] = CredentialMapper.toWrappedVerifiableCredentials(vp.verifiableCredential, opts)
|
|
56
59
|
|
|
57
60
|
// todo: We probably want to add proofs as well
|
|
58
61
|
return {
|
|
@@ -68,11 +71,17 @@ export class CredentialMapper {
|
|
|
68
71
|
}
|
|
69
72
|
}
|
|
70
73
|
|
|
71
|
-
static toWrappedVerifiableCredentials(
|
|
72
|
-
|
|
74
|
+
static toWrappedVerifiableCredentials(
|
|
75
|
+
verifiableCredentials: OriginalVerifiableCredential[],
|
|
76
|
+
opts?: { maxTimeSkewInMS?: number }
|
|
77
|
+
): WrappedVerifiableCredential[] {
|
|
78
|
+
return verifiableCredentials.map((vc) => CredentialMapper.toWrappedVerifiableCredential(vc, opts))
|
|
73
79
|
}
|
|
74
80
|
|
|
75
|
-
static toWrappedVerifiableCredential(
|
|
81
|
+
static toWrappedVerifiableCredential(
|
|
82
|
+
verifiableCredential: OriginalVerifiableCredential,
|
|
83
|
+
opts?: { maxTimeSkewInMS?: number }
|
|
84
|
+
): WrappedVerifiableCredential {
|
|
76
85
|
const original = verifiableCredential
|
|
77
86
|
|
|
78
87
|
const decoded = CredentialMapper.decodeVerifiableCredential(verifiableCredential)
|
|
@@ -83,7 +92,7 @@ export class CredentialMapper {
|
|
|
83
92
|
|
|
84
93
|
const credential =
|
|
85
94
|
isJwtDecoded || isJwtDecoded
|
|
86
|
-
? CredentialMapper.jwtDecodedCredentialToUniformCredential(decoded as JwtDecodedVerifiableCredential)
|
|
95
|
+
? CredentialMapper.jwtDecodedCredentialToUniformCredential(decoded as JwtDecodedVerifiableCredential, opts)
|
|
87
96
|
: (decoded as ICredential)
|
|
88
97
|
const format = isJwtDecoded || isJwtDecoded ? 'jwt_vc' : 'ldp_vc'
|
|
89
98
|
//todo: We probably want to add proofs as well
|
|
@@ -112,19 +121,26 @@ export class CredentialMapper {
|
|
|
112
121
|
return (<JwtDecodedVerifiablePresentation>original)['vp'] !== undefined && (<JwtDecodedVerifiablePresentation>original)['iss'] !== undefined
|
|
113
122
|
}
|
|
114
123
|
|
|
115
|
-
static jwtEncodedPresentationToUniformPresentation(
|
|
116
|
-
|
|
124
|
+
static jwtEncodedPresentationToUniformPresentation(
|
|
125
|
+
jwt: string,
|
|
126
|
+
makeCredentialsUniform: boolean = true,
|
|
127
|
+
opts?: { maxTimeSkewInMS?: number }
|
|
128
|
+
): IPresentation {
|
|
129
|
+
return CredentialMapper.jwtDecodedPresentationToUniformPresentation(jwt_decode(jwt), makeCredentialsUniform, opts)
|
|
117
130
|
}
|
|
118
131
|
|
|
119
132
|
static jwtDecodedPresentationToUniformPresentation(
|
|
120
133
|
decoded: JwtDecodedVerifiablePresentation,
|
|
121
|
-
makeCredentialsUniform: boolean = true
|
|
134
|
+
makeCredentialsUniform: boolean = true,
|
|
135
|
+
opts?: { maxTimeSkewInMS?: number }
|
|
122
136
|
): IPresentation {
|
|
123
137
|
const presentation: IPresentation = {
|
|
124
138
|
...(decoded.vp as IPresentation),
|
|
125
139
|
}
|
|
126
140
|
if (makeCredentialsUniform) {
|
|
127
|
-
presentation.verifiableCredential = decoded.vp.verifiableCredential.map(
|
|
141
|
+
presentation.verifiableCredential = decoded.vp.verifiableCredential.map((vc) =>
|
|
142
|
+
CredentialMapper.toUniformCredential(vc, opts)
|
|
143
|
+
) as IVerifiableCredential[] // We cast it because we IPresentation needs a VC. The internal Credential doesn't have the required Proof anymore (that is intended)
|
|
128
144
|
}
|
|
129
145
|
// Since this is a presentation, we delete any proof just to be sure (should not occur on JWT, but better safe than sorry)
|
|
130
146
|
delete presentation.proof
|
|
@@ -148,7 +164,7 @@ export class CredentialMapper {
|
|
|
148
164
|
return presentation
|
|
149
165
|
}
|
|
150
166
|
|
|
151
|
-
static toUniformCredential(verifiableCredential: OriginalVerifiableCredential): ICredential {
|
|
167
|
+
static toUniformCredential(verifiableCredential: OriginalVerifiableCredential, opts?: { maxTimeSkewInMS?: number }): ICredential {
|
|
152
168
|
const original = verifiableCredential
|
|
153
169
|
const decoded = CredentialMapper.decodeVerifiableCredential(verifiableCredential)
|
|
154
170
|
|
|
@@ -156,13 +172,13 @@ export class CredentialMapper {
|
|
|
156
172
|
const isJwtDecoded: boolean = CredentialMapper.isJwtDecodedCredential(original)
|
|
157
173
|
|
|
158
174
|
if (isJwtDecoded || isJwtEncoded) {
|
|
159
|
-
return CredentialMapper.jwtDecodedCredentialToUniformCredential(decoded as JwtDecodedVerifiableCredential)
|
|
175
|
+
return CredentialMapper.jwtDecodedCredentialToUniformCredential(decoded as JwtDecodedVerifiableCredential, opts)
|
|
160
176
|
} else {
|
|
161
177
|
return decoded as ICredential
|
|
162
178
|
}
|
|
163
179
|
}
|
|
164
180
|
|
|
165
|
-
static toUniformPresentation(presentation: OriginalVerifiablePresentation): IPresentation {
|
|
181
|
+
static toUniformPresentation(presentation: OriginalVerifiablePresentation, opts?: { maxTimeSkewInMS?: number }): IPresentation {
|
|
166
182
|
const original = presentation
|
|
167
183
|
const decoded = CredentialMapper.decodeVerifiablePresentation(original)
|
|
168
184
|
const isJwtEncoded: boolean = CredentialMapper.isJwtEncoded(original)
|
|
@@ -171,32 +187,37 @@ export class CredentialMapper {
|
|
|
171
187
|
isJwtEncoded || isJwtDecoded
|
|
172
188
|
? CredentialMapper.jwtDecodedPresentationToUniformPresentation(decoded as JwtDecodedVerifiablePresentation, false)
|
|
173
189
|
: (decoded as IPresentation)
|
|
174
|
-
uniformPresentation.verifiableCredential = uniformPresentation.verifiableCredential?.map(
|
|
175
|
-
CredentialMapper.toUniformCredential
|
|
190
|
+
uniformPresentation.verifiableCredential = uniformPresentation.verifiableCredential?.map((vc) =>
|
|
191
|
+
CredentialMapper.toUniformCredential(vc, opts)
|
|
176
192
|
) as IVerifiableCredential[] // We cast it because we IPresentation needs a VC. The internal Credential doesn't have the required Proof anymore (that is intended)
|
|
177
193
|
return uniformPresentation
|
|
178
194
|
}
|
|
179
195
|
|
|
180
|
-
static jwtEncodedCredentialToUniformCredential(jwt: string): ICredential {
|
|
181
|
-
return CredentialMapper.jwtDecodedCredentialToUniformCredential(jwt_decode(jwt))
|
|
196
|
+
static jwtEncodedCredentialToUniformCredential(jwt: string, opts?: { maxTimeSkewInMS?: number }): ICredential {
|
|
197
|
+
return CredentialMapper.jwtDecodedCredentialToUniformCredential(jwt_decode(jwt), opts)
|
|
182
198
|
}
|
|
183
199
|
|
|
184
|
-
static jwtDecodedCredentialToUniformCredential(decoded: JwtDecodedVerifiableCredential): ICredential {
|
|
200
|
+
static jwtDecodedCredentialToUniformCredential(decoded: JwtDecodedVerifiableCredential, opts?: { maxTimeSkewInMS?: number }): ICredential {
|
|
185
201
|
const credential: ICredential = {
|
|
186
202
|
...(decoded.vc as ICredential),
|
|
187
203
|
}
|
|
188
204
|
// Since this is a credential, we delete any proof just to be sure (should not occur on JWT, but better safe than sorry)
|
|
189
205
|
delete credential.proof
|
|
190
206
|
|
|
207
|
+
const maxSkewInMS = opts?.maxTimeSkewInMS !== undefined ? opts.maxTimeSkewInMS : 999
|
|
208
|
+
|
|
191
209
|
if (decoded.exp) {
|
|
192
|
-
const expDate = credential.
|
|
210
|
+
const expDate = credential.expirationDate
|
|
193
211
|
const jwtExp = parseInt(decoded.exp.toString())
|
|
194
212
|
// fix seconds to millisecs for the date
|
|
195
213
|
const expDateAsStr = jwtExp < 9999999999 ? new Date(jwtExp * 1000).toISOString().replace(/\.000Z/, 'Z') : new Date(jwtExp).toISOString()
|
|
196
214
|
if (expDate && expDate !== expDateAsStr) {
|
|
197
|
-
|
|
215
|
+
const diff = Math.abs(new Date(expDateAsStr).getTime() - new Date(expDate).getTime())
|
|
216
|
+
if (!maxSkewInMS || diff > maxSkewInMS) {
|
|
217
|
+
throw new Error(`Inconsistent expiration dates between JWT claim (${expDateAsStr}) and VC value (${expDate})`)
|
|
218
|
+
}
|
|
198
219
|
}
|
|
199
|
-
credential.
|
|
220
|
+
credential.expirationDate = expDateAsStr
|
|
200
221
|
}
|
|
201
222
|
|
|
202
223
|
if (decoded.nbf) {
|
|
@@ -205,7 +226,10 @@ export class CredentialMapper {
|
|
|
205
226
|
// fix seconds to millisecs for the date
|
|
206
227
|
const nbfDateAsStr = jwtNbf < 9999999999 ? new Date(jwtNbf * 1000).toISOString().replace(/\.000Z/, 'Z') : new Date(jwtNbf).toISOString()
|
|
207
228
|
if (issuanceDate && issuanceDate !== nbfDateAsStr) {
|
|
208
|
-
|
|
229
|
+
const diff = Math.abs(new Date(nbfDateAsStr).getTime() - new Date(issuanceDate).getTime())
|
|
230
|
+
if (!maxSkewInMS || diff > maxSkewInMS) {
|
|
231
|
+
throw new Error(`Inconsistent issuance dates between JWT claim (${nbfDateAsStr}) and VC value (${issuanceDate})`)
|
|
232
|
+
}
|
|
209
233
|
}
|
|
210
234
|
credential.issuanceDate = nbfDateAsStr
|
|
211
235
|
}
|
|
@@ -222,16 +246,22 @@ export class CredentialMapper {
|
|
|
222
246
|
throw new Error(`Inconsistent issuers between JWT claim (${decoded.iss}) and VC value (${issuer.id})`)
|
|
223
247
|
}
|
|
224
248
|
}
|
|
249
|
+
} else {
|
|
250
|
+
credential.issuer = decoded.iss
|
|
225
251
|
}
|
|
226
|
-
credential.issuer = decoded.iss
|
|
227
252
|
}
|
|
228
253
|
|
|
229
254
|
if (decoded.sub) {
|
|
230
|
-
const
|
|
231
|
-
|
|
232
|
-
|
|
255
|
+
const subjects = Array.isArray(credential.credentialSubject) ? credential.credentialSubject : [credential.credentialSubject]
|
|
256
|
+
for (let i = 0; i < subjects.length; i++) {
|
|
257
|
+
const csId = subjects[i].id
|
|
258
|
+
if (csId && csId !== decoded.sub) {
|
|
259
|
+
throw new Error(`Inconsistent credential subject ids between JWT claim (${decoded.sub}) and VC value (${csId})`)
|
|
260
|
+
}
|
|
261
|
+
Array.isArray(credential.credentialSubject)
|
|
262
|
+
? (credential.credentialSubject[i].id = decoded.sub)
|
|
263
|
+
: (credential.credentialSubject.id = decoded.sub)
|
|
233
264
|
}
|
|
234
|
-
credential.credentialSubject.id = decoded.sub
|
|
235
265
|
}
|
|
236
266
|
if (decoded.jti) {
|
|
237
267
|
const id = credential.id
|
package/src/types/vc.ts
CHANGED
|
@@ -3,23 +3,25 @@ import { IProofPurpose, IProofType } from './did'
|
|
|
3
3
|
|
|
4
4
|
export type AdditionalClaims = Record<string, any>
|
|
5
5
|
|
|
6
|
+
export type IIssuerId = string
|
|
7
|
+
|
|
6
8
|
export interface ICredential {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
+
'@context': ICredentialContextType | ICredentialContextType[]
|
|
10
|
+
type: string[]
|
|
11
|
+
credentialSchema?: undefined | ICredentialSchemaType | ICredentialSchemaType[]
|
|
9
12
|
// If iss is present, the value MUST be used to set the issuer property of the new credential JSON object or the holder property of the new presentation JSON object.
|
|
10
|
-
issuer:
|
|
13
|
+
issuer: IIssuerId | IIssuer
|
|
11
14
|
// If nbf is present, the UNIX timestamp MUST be converted to an [XMLSCHEMA11-2] date-time, and MUST be used to set the value of the issuanceDate property of the new JSON object.
|
|
12
15
|
issuanceDate: string
|
|
13
16
|
// If sub is present, the value MUST be used to set the value of the id property of credentialSubject of the new credential JSON object.
|
|
14
|
-
credentialSubject: ICredentialSubject & AdditionalClaims
|
|
17
|
+
credentialSubject: (ICredentialSubject & AdditionalClaims) | (ICredentialSubject & AdditionalClaims)[]
|
|
18
|
+
// If exp is present, the UNIX timestamp MUST be converted to an [XMLSCHEMA11-2] date-time, and MUST be used to set the value of the expirationDate property of credentialSubject of the new JSON object.
|
|
19
|
+
expirationDate?: string
|
|
15
20
|
// If jti is present, the value MUST be used to set the value of the id property of the new JSON object.
|
|
16
21
|
id?: string
|
|
17
|
-
'@context': ICredentialContextType[] | ICredentialContextType
|
|
18
22
|
credentialStatus?: ICredentialStatus
|
|
19
|
-
credentialSchema?: undefined | ICredentialSchemaType | ICredentialSchemaType[]
|
|
20
23
|
description?: string
|
|
21
24
|
name?: string
|
|
22
|
-
type: string[]
|
|
23
25
|
|
|
24
26
|
[x: string]: any
|
|
25
27
|
}
|
|
@@ -53,6 +55,8 @@ export interface IProof {
|
|
|
53
55
|
jws?: string // JWS based proof
|
|
54
56
|
nonce?: string // Similar to challenge. A nonce to protect against replay attacks, used in some ZKP proofs
|
|
55
57
|
requiredRevealStatements?: string[] // The parts of the proof that must be revealed in a derived proof
|
|
58
|
+
|
|
59
|
+
[x: string]: any // Any because we want to be able to access value1.value2.value3, which unknown does not allow for without a cast
|
|
56
60
|
}
|
|
57
61
|
|
|
58
62
|
export interface ICredentialStatus {
|
|
@@ -72,11 +76,23 @@ export interface IHasProof {
|
|
|
72
76
|
|
|
73
77
|
export type IVerifiableCredential = ICredential & IHasProof
|
|
74
78
|
|
|
79
|
+
/**
|
|
80
|
+
* Represents a Json Web Token in compact form.
|
|
81
|
+
*/
|
|
82
|
+
export type CompactJWT = string
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Represents a signed Verifiable Credential (includes proof), in either JSON or compact JWT format.
|
|
86
|
+
* See {@link https://www.w3.org/TR/vc-data-model/#credentials | VC data model}
|
|
87
|
+
* See {@link https://www.w3.org/TR/vc-data-model/#proof-formats | proof formats}
|
|
88
|
+
*/
|
|
89
|
+
export type W3CVerifiableCredential = IVerifiableCredential | CompactJWT
|
|
90
|
+
|
|
75
91
|
export interface IPresentation {
|
|
76
92
|
id?: string
|
|
77
93
|
'@context': ICredentialContextType | ICredentialContextType[]
|
|
78
94
|
type: string[]
|
|
79
|
-
verifiableCredential:
|
|
95
|
+
verifiableCredential: W3CVerifiableCredential[] // we relax to ICredential for internal decoded stable representations without proofs
|
|
80
96
|
presentation_submission?: PresentationSubmission
|
|
81
97
|
holder?: string
|
|
82
98
|
|
|
@@ -85,6 +101,13 @@ export interface IPresentation {
|
|
|
85
101
|
|
|
86
102
|
export type IVerifiablePresentation = IPresentation & IHasProof
|
|
87
103
|
|
|
104
|
+
/**
|
|
105
|
+
* Represents a signed Verifiable Presentation (includes proof), in either JSON or compact JWT format.
|
|
106
|
+
* See {@link https://www.w3.org/TR/vc-data-model/#presentations | VC data model}
|
|
107
|
+
* See {@link https://www.w3.org/TR/vc-data-model/#proof-formats | proof formats}
|
|
108
|
+
*/
|
|
109
|
+
export type W3CVerifiablePresentation = IVerifiablePresentation | CompactJWT
|
|
110
|
+
|
|
88
111
|
export interface WrappedVerifiableCredential {
|
|
89
112
|
/**
|
|
90
113
|
* Original VC that we've received
|
|
@@ -101,7 +124,7 @@ export interface WrappedVerifiableCredential {
|
|
|
101
124
|
/**
|
|
102
125
|
* The claim format, typically used during exchange transport protocols
|
|
103
126
|
*/
|
|
104
|
-
format:
|
|
127
|
+
format: CredentialFormat
|
|
105
128
|
/**
|
|
106
129
|
* Internal stable representation of a Credential without Proofs, created based on https://www.w3.org/TR/vc-data-model/#jwt-decoding
|
|
107
130
|
*/
|
|
@@ -124,7 +147,7 @@ export interface WrappedVerifiablePresentation {
|
|
|
124
147
|
/**
|
|
125
148
|
* The claim format, typically used during exchange transport protocols
|
|
126
149
|
*/
|
|
127
|
-
format:
|
|
150
|
+
format: PresentationFormat
|
|
128
151
|
/**
|
|
129
152
|
* Internal stable representation of a Presentation without proofs, created based on https://www.w3.org/TR/vc-data-model/#jwt-decoding
|
|
130
153
|
*/
|
|
@@ -171,8 +194,10 @@ export interface JwtDecodedVerifiablePresentation {
|
|
|
171
194
|
[x: string]: any
|
|
172
195
|
}
|
|
173
196
|
|
|
174
|
-
export type
|
|
197
|
+
export type CredentialFormat = 'jwt' | 'ldp' | 'jwt_vc' | 'ldp_vc' | string
|
|
198
|
+
export type PresentationFormat = 'jwt' | 'ldp' | 'jwt_vp' | 'ldp_vp' | string
|
|
199
|
+
export type ClaimFormat = CredentialFormat | PresentationFormat
|
|
175
200
|
|
|
176
|
-
export type OriginalVerifiableCredential =
|
|
177
|
-
export type OriginalVerifiablePresentation =
|
|
201
|
+
export type OriginalVerifiableCredential = W3CVerifiableCredential | JwtDecodedVerifiableCredential
|
|
202
|
+
export type OriginalVerifiablePresentation = W3CVerifiablePresentation | JwtDecodedVerifiablePresentation
|
|
178
203
|
export type Original = OriginalVerifiablePresentation | OriginalVerifiableCredential
|