@sphereon/ssi-types 0.8.1-unstable.9 → 0.9.0
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 +34 -11
- package/dist/mapper/credential-mapper.d.ts.map +1 -1
- package/dist/mapper/credential-mapper.js +169 -48
- package/dist/mapper/credential-mapper.js.map +1 -1
- package/dist/types/did.d.ts +2 -1
- package/dist/types/did.d.ts.map +1 -1
- package/dist/types/did.js +1 -0
- package/dist/types/did.js.map +1 -1
- package/dist/types/vc.d.ts +49 -24
- package/dist/types/vc.d.ts.map +1 -1
- package/dist/types/vc.js +7 -1
- package/dist/types/vc.js.map +1 -1
- package/package.json +3 -2
- package/src/mapper/credential-mapper.ts +219 -63
- package/src/types/did.ts +1 -0
- package/src/types/vc.ts +51 -25
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
|
-
|
|
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 &
|
|
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;
|
|
@@ -37,8 +38,10 @@ export interface IProof {
|
|
|
37
38
|
domain?: string;
|
|
38
39
|
proofValue?: string;
|
|
39
40
|
jws?: string;
|
|
41
|
+
jwt?: string;
|
|
40
42
|
nonce?: string;
|
|
41
43
|
requiredRevealStatements?: string[];
|
|
44
|
+
[x: string]: any;
|
|
42
45
|
}
|
|
43
46
|
export interface ICredentialStatus {
|
|
44
47
|
id: string;
|
|
@@ -51,17 +54,33 @@ export interface IIssuer {
|
|
|
51
54
|
export interface IHasProof {
|
|
52
55
|
proof: IProof | IProof[];
|
|
53
56
|
}
|
|
54
|
-
export
|
|
57
|
+
export type IVerifiableCredential = ICredential & IHasProof;
|
|
58
|
+
/**
|
|
59
|
+
* Represents a Json Web Token in compact form.
|
|
60
|
+
*/
|
|
61
|
+
export type CompactJWT = string;
|
|
62
|
+
/**
|
|
63
|
+
* Represents a signed Verifiable Credential (includes proof), in either JSON or compact JWT format.
|
|
64
|
+
* See {@link https://www.w3.org/TR/vc-data-model/#credentials | VC data model}
|
|
65
|
+
* See {@link https://www.w3.org/TR/vc-data-model/#proof-formats | proof formats}
|
|
66
|
+
*/
|
|
67
|
+
export type W3CVerifiableCredential = IVerifiableCredential | CompactJWT;
|
|
55
68
|
export interface IPresentation {
|
|
56
69
|
id?: string;
|
|
57
70
|
'@context': ICredentialContextType | ICredentialContextType[];
|
|
58
|
-
type
|
|
59
|
-
verifiableCredential
|
|
71
|
+
type?: string | string[];
|
|
72
|
+
verifiableCredential?: W3CVerifiableCredential[];
|
|
60
73
|
presentation_submission?: PresentationSubmission;
|
|
61
74
|
holder?: string;
|
|
62
75
|
[x: string]: any;
|
|
63
76
|
}
|
|
64
|
-
export
|
|
77
|
+
export type IVerifiablePresentation = IPresentation & IHasProof;
|
|
78
|
+
/**
|
|
79
|
+
* Represents a signed Verifiable Presentation (includes proof), in either JSON or compact JWT format.
|
|
80
|
+
* See {@link https://www.w3.org/TR/vc-data-model/#presentations | VC data model}
|
|
81
|
+
* See {@link https://www.w3.org/TR/vc-data-model/#proof-formats | proof formats}
|
|
82
|
+
*/
|
|
83
|
+
export type W3CVerifiablePresentation = IVerifiablePresentation | CompactJWT;
|
|
65
84
|
export interface WrappedVerifiableCredential {
|
|
66
85
|
/**
|
|
67
86
|
* Original VC that we've received
|
|
@@ -78,11 +97,11 @@ export interface WrappedVerifiableCredential {
|
|
|
78
97
|
/**
|
|
79
98
|
* The claim format, typically used during exchange transport protocols
|
|
80
99
|
*/
|
|
81
|
-
format:
|
|
100
|
+
format: CredentialFormat;
|
|
82
101
|
/**
|
|
83
|
-
* Internal stable representation of a Credential
|
|
102
|
+
* Internal stable representation of a Credential
|
|
84
103
|
*/
|
|
85
|
-
credential:
|
|
104
|
+
credential: IVerifiableCredential;
|
|
86
105
|
}
|
|
87
106
|
export interface WrappedVerifiablePresentation {
|
|
88
107
|
/**
|
|
@@ -100,7 +119,7 @@ export interface WrappedVerifiablePresentation {
|
|
|
100
119
|
/**
|
|
101
120
|
* The claim format, typically used during exchange transport protocols
|
|
102
121
|
*/
|
|
103
|
-
format:
|
|
122
|
+
format: PresentationFormat;
|
|
104
123
|
/**
|
|
105
124
|
* Internal stable representation of a Presentation without proofs, created based on https://www.w3.org/TR/vc-data-model/#jwt-decoding
|
|
106
125
|
*/
|
|
@@ -117,13 +136,13 @@ export declare enum OriginalType {
|
|
|
117
136
|
}
|
|
118
137
|
export interface UniformVerifiablePresentation {
|
|
119
138
|
'@context': ICredentialContextType | ICredentialContextType[];
|
|
120
|
-
type: string[];
|
|
139
|
+
type: string | string[];
|
|
121
140
|
verifiableCredential: WrappedVerifiableCredential[];
|
|
122
141
|
presentation_submission?: PresentationSubmission;
|
|
123
142
|
holder?: string;
|
|
124
143
|
}
|
|
125
144
|
export interface JwtDecodedVerifiableCredential {
|
|
126
|
-
vc:
|
|
145
|
+
vc: IVerifiableCredential;
|
|
127
146
|
exp: string;
|
|
128
147
|
iss: string;
|
|
129
148
|
nbf: string;
|
|
@@ -140,9 +159,15 @@ export interface JwtDecodedVerifiablePresentation {
|
|
|
140
159
|
jti: string;
|
|
141
160
|
[x: string]: any;
|
|
142
161
|
}
|
|
143
|
-
export
|
|
144
|
-
export
|
|
145
|
-
export
|
|
146
|
-
export
|
|
147
|
-
export
|
|
162
|
+
export type CredentialFormat = 'jwt' | 'ldp' | 'jwt_vc' | 'ldp_vc' | string;
|
|
163
|
+
export type PresentationFormat = 'jwt' | 'ldp' | 'jwt_vp' | 'ldp_vp' | string;
|
|
164
|
+
export type ClaimFormat = CredentialFormat | PresentationFormat;
|
|
165
|
+
export type OriginalVerifiableCredential = W3CVerifiableCredential | JwtDecodedVerifiableCredential;
|
|
166
|
+
export type OriginalVerifiablePresentation = W3CVerifiablePresentation | JwtDecodedVerifiablePresentation;
|
|
167
|
+
export type Original = OriginalVerifiablePresentation | OriginalVerifiableCredential;
|
|
168
|
+
export declare const enum DocumentFormat {
|
|
169
|
+
JWT = 0,
|
|
170
|
+
JSONLD = 1,
|
|
171
|
+
EIP712 = 2
|
|
172
|
+
}
|
|
148
173
|
//# 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,sBAAs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
-
exports.OriginalType = void 0;
|
|
3
|
+
exports.DocumentFormat = exports.OriginalType = void 0;
|
|
4
4
|
var OriginalType;
|
|
5
5
|
(function (OriginalType) {
|
|
6
6
|
OriginalType["JSONLD"] = "json-ld";
|
|
7
7
|
OriginalType["JWT_ENCODED"] = "jwt-encoded";
|
|
8
8
|
OriginalType["JWT_DECODED"] = "jwt-decoded";
|
|
9
9
|
})(OriginalType = exports.OriginalType || (exports.OriginalType = {}));
|
|
10
|
+
var DocumentFormat;
|
|
11
|
+
(function (DocumentFormat) {
|
|
12
|
+
DocumentFormat[DocumentFormat["JWT"] = 0] = "JWT";
|
|
13
|
+
DocumentFormat[DocumentFormat["JSONLD"] = 1] = "JSONLD";
|
|
14
|
+
DocumentFormat[DocumentFormat["EIP712"] = 2] = "EIP712";
|
|
15
|
+
})(DocumentFormat = exports.DocumentFormat || (exports.DocumentFormat = {}));
|
|
10
16
|
//# sourceMappingURL=vc.js.map
|
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":";;;AAiKA,IAAY,YAIX;AAJD,WAAY,YAAY;IACtB,kCAAkB,CAAA;IAClB,2CAA2B,CAAA;IAC3B,2CAA2B,CAAA;AAC7B,CAAC,EAJW,YAAY,GAAZ,oBAAY,KAAZ,oBAAY,QAIvB;AAwCD,IAAkB,cAIjB;AAJD,WAAkB,cAAc;IAC9B,iDAAG,CAAA;IACH,uDAAM,CAAA;IACN,uDAAM,CAAA;AACR,CAAC,EAJiB,cAAc,GAAd,sBAAc,KAAd,sBAAc,QAI/B"}
|
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.
|
|
4
|
+
"version": "0.9.0",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
},
|
|
13
13
|
"devDependencies": {
|
|
14
14
|
"@types/jest": "^27.0.2",
|
|
15
|
+
"@veramo/core": "4.2.0",
|
|
15
16
|
"jest": "^27.3.1",
|
|
16
17
|
"prettier": "^2.4.1",
|
|
17
18
|
"ts-jest": "^27.0.7",
|
|
@@ -37,5 +38,5 @@
|
|
|
37
38
|
"Verifiable Credentials",
|
|
38
39
|
"DIDs"
|
|
39
40
|
],
|
|
40
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "9119280fec93d685824f0baa454163d703431025"
|
|
41
42
|
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
ICredential,
|
|
2
|
+
DocumentFormat,
|
|
4
3
|
IPresentation,
|
|
4
|
+
IProof,
|
|
5
|
+
IProofPurpose,
|
|
6
|
+
IProofType,
|
|
5
7
|
IVerifiableCredential,
|
|
6
8
|
IVerifiablePresentation,
|
|
7
9
|
JwtDecodedVerifiableCredential,
|
|
@@ -9,6 +11,10 @@ import {
|
|
|
9
11
|
OriginalType,
|
|
10
12
|
OriginalVerifiableCredential,
|
|
11
13
|
OriginalVerifiablePresentation,
|
|
14
|
+
PresentationFormat,
|
|
15
|
+
UniformVerifiablePresentation,
|
|
16
|
+
W3CVerifiableCredential,
|
|
17
|
+
W3CVerifiablePresentation,
|
|
12
18
|
WrappedVerifiableCredential,
|
|
13
19
|
WrappedVerifiablePresentation,
|
|
14
20
|
} from '../types'
|
|
@@ -18,10 +24,20 @@ import { ObjectUtils } from '../utils'
|
|
|
18
24
|
export class CredentialMapper {
|
|
19
25
|
static decodeVerifiablePresentation(presentation: OriginalVerifiablePresentation): JwtDecodedVerifiablePresentation | IVerifiablePresentation {
|
|
20
26
|
if (CredentialMapper.isJwtEncoded(presentation)) {
|
|
21
|
-
|
|
27
|
+
const payload = jwt_decode(presentation as string) as JwtDecodedVerifiablePresentation
|
|
28
|
+
const header = jwt_decode(presentation as string, { header: true }) as Record<string, any>
|
|
29
|
+
|
|
30
|
+
payload.vp.proof = {
|
|
31
|
+
type: IProofType.JwtProof2020,
|
|
32
|
+
created: payload.nbf,
|
|
33
|
+
proofPurpose: IProofPurpose.authentication,
|
|
34
|
+
verificationMethod: header['kid'] ?? payload.iss,
|
|
35
|
+
jwt: presentation as string,
|
|
36
|
+
}
|
|
37
|
+
return payload
|
|
22
38
|
} else if (CredentialMapper.isJwtDecodedPresentation(presentation)) {
|
|
23
39
|
return presentation as JwtDecodedVerifiablePresentation
|
|
24
|
-
} else if (CredentialMapper.
|
|
40
|
+
} else if (CredentialMapper.isJsonLdAsString(presentation)) {
|
|
25
41
|
return JSON.parse(presentation as string) as IVerifiablePresentation
|
|
26
42
|
} else {
|
|
27
43
|
return presentation as IVerifiablePresentation
|
|
@@ -30,51 +46,73 @@ export class CredentialMapper {
|
|
|
30
46
|
|
|
31
47
|
static decodeVerifiableCredential(credential: OriginalVerifiableCredential): JwtDecodedVerifiableCredential | IVerifiableCredential {
|
|
32
48
|
if (CredentialMapper.isJwtEncoded(credential)) {
|
|
33
|
-
|
|
49
|
+
const payload = jwt_decode(credential as string) as JwtDecodedVerifiableCredential
|
|
50
|
+
const header = jwt_decode(credential as string, { header: true }) as Record<string, any>
|
|
51
|
+
payload.vc.proof = {
|
|
52
|
+
type: IProofType.JwtProof2020,
|
|
53
|
+
created: payload.nbf,
|
|
54
|
+
proofPurpose: IProofPurpose.authentication,
|
|
55
|
+
verificationMethod: header['kid'] ?? payload.iss,
|
|
56
|
+
jwt: credential as string,
|
|
57
|
+
}
|
|
58
|
+
return payload
|
|
34
59
|
} else if (CredentialMapper.isJwtDecodedCredential(credential)) {
|
|
35
60
|
return credential as JwtDecodedVerifiableCredential
|
|
36
|
-
} else if (CredentialMapper.
|
|
61
|
+
} else if (CredentialMapper.isJsonLdAsString(credential)) {
|
|
37
62
|
return JSON.parse(credential as string) as IVerifiableCredential
|
|
38
63
|
} else {
|
|
39
64
|
return credential as IVerifiableCredential
|
|
40
65
|
}
|
|
41
66
|
}
|
|
42
67
|
|
|
43
|
-
static toWrappedVerifiablePresentation(
|
|
44
|
-
|
|
68
|
+
static toWrappedVerifiablePresentation(
|
|
69
|
+
originalPresentation: OriginalVerifiablePresentation,
|
|
70
|
+
opts?: { maxTimeSkewInMS?: number },
|
|
71
|
+
): WrappedVerifiablePresentation {
|
|
72
|
+
const original = originalPresentation
|
|
45
73
|
const isJwtEncoded: boolean = CredentialMapper.isJwtEncoded(original)
|
|
46
74
|
const isJwtDecoded: boolean = CredentialMapper.isJwtDecodedPresentation(original)
|
|
47
75
|
|
|
48
76
|
const type = isJwtEncoded ? OriginalType.JWT_ENCODED : isJwtDecoded ? OriginalType.JWT_DECODED : OriginalType.JSONLD
|
|
49
|
-
const format:
|
|
77
|
+
const format: PresentationFormat = isJwtDecoded || isJwtEncoded ? 'jwt_vp' : 'ldp_vp'
|
|
50
78
|
const decoded = CredentialMapper.decodeVerifiablePresentation(original)
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
79
|
+
let vp: OriginalVerifiablePresentation
|
|
80
|
+
if (isJwtEncoded || isJwtDecoded) {
|
|
81
|
+
vp = CredentialMapper.jwtDecodedPresentationToUniformPresentation(decoded as JwtDecodedVerifiablePresentation, false, opts)
|
|
82
|
+
} else {
|
|
83
|
+
vp = decoded as IVerifiablePresentation
|
|
84
|
+
}
|
|
85
|
+
if (!vp || !('verifiableCredential' in vp) || !vp.verifiableCredential || vp.verifiableCredential.length === 0) {
|
|
86
|
+
throw Error(`VP needs to have at least one verifiable credential at this point`)
|
|
87
|
+
}
|
|
88
|
+
const vcs: WrappedVerifiableCredential[] = CredentialMapper.toWrappedVerifiableCredentials(vp.verifiableCredential/*.map(value => value.original)*/, opts)
|
|
56
89
|
|
|
57
|
-
|
|
90
|
+
const presentation = {
|
|
91
|
+
...vp,
|
|
92
|
+
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
|
|
93
|
+
} as UniformVerifiablePresentation
|
|
58
94
|
return {
|
|
59
95
|
type,
|
|
60
96
|
format,
|
|
61
97
|
original,
|
|
62
98
|
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
|
-
},
|
|
99
|
+
presentation,
|
|
67
100
|
vcs,
|
|
68
101
|
}
|
|
69
102
|
}
|
|
70
103
|
|
|
71
|
-
static toWrappedVerifiableCredentials(
|
|
72
|
-
|
|
104
|
+
static toWrappedVerifiableCredentials(
|
|
105
|
+
verifiableCredentials: OriginalVerifiableCredential[],
|
|
106
|
+
opts?: { maxTimeSkewInMS?: number },
|
|
107
|
+
): WrappedVerifiableCredential[] {
|
|
108
|
+
return verifiableCredentials.map((vc) => CredentialMapper.toWrappedVerifiableCredential(vc, opts))
|
|
73
109
|
}
|
|
74
110
|
|
|
75
|
-
static toWrappedVerifiableCredential(
|
|
111
|
+
static toWrappedVerifiableCredential(
|
|
112
|
+
verifiableCredential: OriginalVerifiableCredential,
|
|
113
|
+
opts?: { maxTimeSkewInMS?: number },
|
|
114
|
+
): WrappedVerifiableCredential {
|
|
76
115
|
const original = verifiableCredential
|
|
77
|
-
|
|
78
116
|
const decoded = CredentialMapper.decodeVerifiableCredential(verifiableCredential)
|
|
79
117
|
|
|
80
118
|
const isJwtEncoded = CredentialMapper.isJwtEncoded(original)
|
|
@@ -82,11 +120,11 @@ export class CredentialMapper {
|
|
|
82
120
|
const type = isJwtEncoded ? OriginalType.JWT_ENCODED : isJwtDecoded ? OriginalType.JWT_DECODED : OriginalType.JSONLD
|
|
83
121
|
|
|
84
122
|
const credential =
|
|
85
|
-
|
|
86
|
-
? CredentialMapper.jwtDecodedCredentialToUniformCredential(decoded as JwtDecodedVerifiableCredential)
|
|
87
|
-
: (decoded as
|
|
88
|
-
|
|
89
|
-
|
|
123
|
+
isJwtEncoded || isJwtDecoded
|
|
124
|
+
? CredentialMapper.jwtDecodedCredentialToUniformCredential(decoded as JwtDecodedVerifiableCredential, opts)
|
|
125
|
+
: (decoded as IVerifiableCredential)
|
|
126
|
+
|
|
127
|
+
const format = isJwtEncoded || isJwtDecoded ? 'jwt_vc' : 'ldp_vc'
|
|
90
128
|
return {
|
|
91
129
|
original,
|
|
92
130
|
decoded,
|
|
@@ -100,7 +138,7 @@ export class CredentialMapper {
|
|
|
100
138
|
return ObjectUtils.isString(original) && (original as string).startsWith('ey')
|
|
101
139
|
}
|
|
102
140
|
|
|
103
|
-
private static
|
|
141
|
+
private static isJsonLdAsString(original: OriginalVerifiableCredential | OriginalVerifiablePresentation) {
|
|
104
142
|
return ObjectUtils.isString(original) && (original as string).includes('@context')
|
|
105
143
|
}
|
|
106
144
|
|
|
@@ -112,23 +150,30 @@ export class CredentialMapper {
|
|
|
112
150
|
return (<JwtDecodedVerifiablePresentation>original)['vp'] !== undefined && (<JwtDecodedVerifiablePresentation>original)['iss'] !== undefined
|
|
113
151
|
}
|
|
114
152
|
|
|
115
|
-
static jwtEncodedPresentationToUniformPresentation(
|
|
116
|
-
|
|
153
|
+
static jwtEncodedPresentationToUniformPresentation(
|
|
154
|
+
jwt: string,
|
|
155
|
+
makeCredentialsUniform: boolean = true,
|
|
156
|
+
opts?: { maxTimeSkewInMS?: number },
|
|
157
|
+
): IPresentation {
|
|
158
|
+
return CredentialMapper.jwtDecodedPresentationToUniformPresentation(jwt_decode(jwt), makeCredentialsUniform, opts)
|
|
117
159
|
}
|
|
118
160
|
|
|
119
161
|
static jwtDecodedPresentationToUniformPresentation(
|
|
120
162
|
decoded: JwtDecodedVerifiablePresentation,
|
|
121
|
-
makeCredentialsUniform: boolean = true
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
163
|
+
makeCredentialsUniform: boolean = true,
|
|
164
|
+
opts?: { maxTimeSkewInMS?: number },
|
|
165
|
+
): IVerifiablePresentation {
|
|
166
|
+
const presentation: IVerifiablePresentation = {
|
|
167
|
+
...(decoded.vp),
|
|
125
168
|
}
|
|
126
169
|
if (makeCredentialsUniform) {
|
|
127
|
-
|
|
170
|
+
if (!decoded.vp.verifiableCredential) {
|
|
171
|
+
throw Error('Verifiable Presentation should have a verifiable credential at this point')
|
|
172
|
+
}
|
|
173
|
+
presentation.verifiableCredential = decoded.vp.verifiableCredential.map((vc) =>
|
|
174
|
+
CredentialMapper.toUniformCredential(vc, opts),
|
|
175
|
+
)
|
|
128
176
|
}
|
|
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
177
|
if (decoded.iss) {
|
|
133
178
|
const holder = presentation.holder
|
|
134
179
|
if (holder) {
|
|
@@ -148,7 +193,7 @@ export class CredentialMapper {
|
|
|
148
193
|
return presentation
|
|
149
194
|
}
|
|
150
195
|
|
|
151
|
-
static toUniformCredential(verifiableCredential: OriginalVerifiableCredential):
|
|
196
|
+
static toUniformCredential(verifiableCredential: OriginalVerifiableCredential, opts?: { maxTimeSkewInMS?: number }): IVerifiableCredential {
|
|
152
197
|
const original = verifiableCredential
|
|
153
198
|
const decoded = CredentialMapper.decodeVerifiableCredential(verifiableCredential)
|
|
154
199
|
|
|
@@ -156,13 +201,13 @@ export class CredentialMapper {
|
|
|
156
201
|
const isJwtDecoded: boolean = CredentialMapper.isJwtDecodedCredential(original)
|
|
157
202
|
|
|
158
203
|
if (isJwtDecoded || isJwtEncoded) {
|
|
159
|
-
return CredentialMapper.jwtDecodedCredentialToUniformCredential(decoded as JwtDecodedVerifiableCredential)
|
|
204
|
+
return CredentialMapper.jwtDecodedCredentialToUniformCredential(decoded as JwtDecodedVerifiableCredential, opts)
|
|
160
205
|
} else {
|
|
161
|
-
return decoded as
|
|
206
|
+
return decoded as IVerifiableCredential
|
|
162
207
|
}
|
|
163
208
|
}
|
|
164
209
|
|
|
165
|
-
static toUniformPresentation(presentation: OriginalVerifiablePresentation):
|
|
210
|
+
static toUniformPresentation(presentation: OriginalVerifiablePresentation, opts?: { maxTimeSkewInMS?: number }): IVerifiablePresentation {
|
|
166
211
|
const original = presentation
|
|
167
212
|
const decoded = CredentialMapper.decodeVerifiablePresentation(original)
|
|
168
213
|
const isJwtEncoded: boolean = CredentialMapper.isJwtEncoded(original)
|
|
@@ -170,33 +215,36 @@ export class CredentialMapper {
|
|
|
170
215
|
const uniformPresentation =
|
|
171
216
|
isJwtEncoded || isJwtDecoded
|
|
172
217
|
? CredentialMapper.jwtDecodedPresentationToUniformPresentation(decoded as JwtDecodedVerifiablePresentation, false)
|
|
173
|
-
: (decoded as
|
|
174
|
-
uniformPresentation.verifiableCredential = uniformPresentation.verifiableCredential?.map(
|
|
175
|
-
CredentialMapper.toUniformCredential
|
|
218
|
+
: (decoded as IVerifiablePresentation)
|
|
219
|
+
uniformPresentation.verifiableCredential = uniformPresentation.verifiableCredential?.map((vc) =>
|
|
220
|
+
CredentialMapper.toUniformCredential(vc, opts),
|
|
176
221
|
) 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
222
|
return uniformPresentation
|
|
178
223
|
}
|
|
179
224
|
|
|
180
|
-
static jwtEncodedCredentialToUniformCredential(jwt: string):
|
|
181
|
-
return CredentialMapper.jwtDecodedCredentialToUniformCredential(jwt_decode(jwt))
|
|
225
|
+
static jwtEncodedCredentialToUniformCredential(jwt: string, opts?: { maxTimeSkewInMS?: number }): IVerifiableCredential {
|
|
226
|
+
return CredentialMapper.jwtDecodedCredentialToUniformCredential(jwt_decode(jwt), opts)
|
|
182
227
|
}
|
|
183
228
|
|
|
184
|
-
static jwtDecodedCredentialToUniformCredential(decoded: JwtDecodedVerifiableCredential):
|
|
185
|
-
const credential:
|
|
186
|
-
...(decoded.vc
|
|
229
|
+
static jwtDecodedCredentialToUniformCredential(decoded: JwtDecodedVerifiableCredential, opts?: { maxTimeSkewInMS?: number }): IVerifiableCredential {
|
|
230
|
+
const credential: IVerifiableCredential = {
|
|
231
|
+
...(decoded.vc),
|
|
187
232
|
}
|
|
188
|
-
|
|
189
|
-
|
|
233
|
+
|
|
234
|
+
const maxSkewInMS = opts?.maxTimeSkewInMS !== undefined ? opts.maxTimeSkewInMS : 999
|
|
190
235
|
|
|
191
236
|
if (decoded.exp) {
|
|
192
|
-
const expDate = credential.
|
|
237
|
+
const expDate = credential.expirationDate
|
|
193
238
|
const jwtExp = parseInt(decoded.exp.toString())
|
|
194
|
-
// fix seconds to
|
|
239
|
+
// fix seconds to millisecond for the date
|
|
195
240
|
const expDateAsStr = jwtExp < 9999999999 ? new Date(jwtExp * 1000).toISOString().replace(/\.000Z/, 'Z') : new Date(jwtExp).toISOString()
|
|
196
241
|
if (expDate && expDate !== expDateAsStr) {
|
|
197
|
-
|
|
242
|
+
const diff = Math.abs(new Date(expDateAsStr).getTime() - new Date(expDate).getTime())
|
|
243
|
+
if (!maxSkewInMS || diff > maxSkewInMS) {
|
|
244
|
+
throw new Error(`Inconsistent expiration dates between JWT claim (${expDateAsStr}) and VC value (${expDate})`)
|
|
245
|
+
}
|
|
198
246
|
}
|
|
199
|
-
credential.
|
|
247
|
+
credential.expirationDate = expDateAsStr
|
|
200
248
|
}
|
|
201
249
|
|
|
202
250
|
if (decoded.nbf) {
|
|
@@ -205,7 +253,10 @@ export class CredentialMapper {
|
|
|
205
253
|
// fix seconds to millisecs for the date
|
|
206
254
|
const nbfDateAsStr = jwtNbf < 9999999999 ? new Date(jwtNbf * 1000).toISOString().replace(/\.000Z/, 'Z') : new Date(jwtNbf).toISOString()
|
|
207
255
|
if (issuanceDate && issuanceDate !== nbfDateAsStr) {
|
|
208
|
-
|
|
256
|
+
const diff = Math.abs(new Date(nbfDateAsStr).getTime() - new Date(issuanceDate).getTime())
|
|
257
|
+
if (!maxSkewInMS || diff > maxSkewInMS) {
|
|
258
|
+
throw new Error(`Inconsistent issuance dates between JWT claim (${nbfDateAsStr}) and VC value (${issuanceDate})`)
|
|
259
|
+
}
|
|
209
260
|
}
|
|
210
261
|
credential.issuanceDate = nbfDateAsStr
|
|
211
262
|
}
|
|
@@ -222,16 +273,22 @@ export class CredentialMapper {
|
|
|
222
273
|
throw new Error(`Inconsistent issuers between JWT claim (${decoded.iss}) and VC value (${issuer.id})`)
|
|
223
274
|
}
|
|
224
275
|
}
|
|
276
|
+
} else {
|
|
277
|
+
credential.issuer = decoded.iss
|
|
225
278
|
}
|
|
226
|
-
credential.issuer = decoded.iss
|
|
227
279
|
}
|
|
228
280
|
|
|
229
281
|
if (decoded.sub) {
|
|
230
|
-
const
|
|
231
|
-
|
|
232
|
-
|
|
282
|
+
const subjects = Array.isArray(credential.credentialSubject) ? credential.credentialSubject : [credential.credentialSubject]
|
|
283
|
+
for (let i = 0; i < subjects.length; i++) {
|
|
284
|
+
const csId = subjects[i].id
|
|
285
|
+
if (csId && csId !== decoded.sub) {
|
|
286
|
+
throw new Error(`Inconsistent credential subject ids between JWT claim (${decoded.sub}) and VC value (${csId})`)
|
|
287
|
+
}
|
|
288
|
+
Array.isArray(credential.credentialSubject)
|
|
289
|
+
? (credential.credentialSubject[i].id = decoded.sub)
|
|
290
|
+
: (credential.credentialSubject.id = decoded.sub)
|
|
233
291
|
}
|
|
234
|
-
credential.credentialSubject.id = decoded.sub
|
|
235
292
|
}
|
|
236
293
|
if (decoded.jti) {
|
|
237
294
|
const id = credential.id
|
|
@@ -240,6 +297,105 @@ export class CredentialMapper {
|
|
|
240
297
|
}
|
|
241
298
|
credential.id = decoded.jti
|
|
242
299
|
}
|
|
300
|
+
|
|
301
|
+
return credential
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
static toExternalVerifiableCredential(verifiableCredential: any): IVerifiableCredential {
|
|
305
|
+
let proof
|
|
306
|
+
if (verifiableCredential.proof) {
|
|
307
|
+
if (!verifiableCredential.proof.type) {
|
|
308
|
+
throw new Error('Verifiable credential proof is missing a type')
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
if (!verifiableCredential.proof.created) {
|
|
312
|
+
throw new Error('Verifiable credential proof is missing a created date')
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
if (!verifiableCredential.proof.proofPurpose) {
|
|
316
|
+
throw new Error('Verifiable credential proof is missing a proof purpose')
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
if (!verifiableCredential.proof.verificationMethod) {
|
|
320
|
+
throw new Error('Verifiable credential proof is missing a verification method')
|
|
321
|
+
}
|
|
322
|
+
proof = {
|
|
323
|
+
...verifiableCredential.proof,
|
|
324
|
+
type: verifiableCredential.proof.type,
|
|
325
|
+
created: verifiableCredential.proof.created,
|
|
326
|
+
proofPurpose: verifiableCredential.proof.proofPurpose,
|
|
327
|
+
verificationMethod: verifiableCredential.proof.verificationMethod,
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
return {
|
|
332
|
+
...verifiableCredential,
|
|
333
|
+
type: verifiableCredential.type
|
|
334
|
+
? typeof verifiableCredential.type === 'string'
|
|
335
|
+
? [verifiableCredential.type]
|
|
336
|
+
: verifiableCredential.type
|
|
337
|
+
: ['VerifiableCredential'],
|
|
338
|
+
proof,
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
static storedCredentialToOriginalFormat(credential: W3CVerifiableCredential): W3CVerifiableCredential {
|
|
343
|
+
const type: DocumentFormat = CredentialMapper.detectDocumentType(credential)
|
|
344
|
+
if (typeof credential === 'string') {
|
|
345
|
+
if (type === DocumentFormat.JWT) {
|
|
346
|
+
return CredentialMapper.toCompactJWT(credential)
|
|
347
|
+
} else if (type === DocumentFormat.JSONLD) {
|
|
348
|
+
return JSON.parse(credential)
|
|
349
|
+
}
|
|
350
|
+
}
|
|
243
351
|
return credential
|
|
244
352
|
}
|
|
353
|
+
|
|
354
|
+
static storedPresentationToOriginalFormat(presentation: W3CVerifiablePresentation): W3CVerifiablePresentation {
|
|
355
|
+
const type: DocumentFormat = CredentialMapper.detectDocumentType(presentation)
|
|
356
|
+
if (typeof presentation === 'string') {
|
|
357
|
+
if (type === DocumentFormat.JWT) {
|
|
358
|
+
return CredentialMapper.toCompactJWT(presentation)
|
|
359
|
+
} else if (type === DocumentFormat.JSONLD) {
|
|
360
|
+
return JSON.parse(presentation)
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
return presentation
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
static toCompactJWT(jwtDocument: W3CVerifiableCredential | JwtDecodedVerifiableCredential | W3CVerifiablePresentation | JwtDecodedVerifiablePresentation): string {
|
|
367
|
+
if (CredentialMapper.detectDocumentType(jwtDocument) !== DocumentFormat.JWT) {
|
|
368
|
+
throw Error('Cannot convert non JWT credential to JWT')
|
|
369
|
+
}
|
|
370
|
+
if (typeof jwtDocument === 'string') {
|
|
371
|
+
return jwtDocument
|
|
372
|
+
}
|
|
373
|
+
let proof: string | undefined
|
|
374
|
+
if ('vp' in jwtDocument) {
|
|
375
|
+
proof = jwtDocument.vp.proof
|
|
376
|
+
} else if ('vc' in jwtDocument) {
|
|
377
|
+
proof = jwtDocument.vc.proof
|
|
378
|
+
} else {
|
|
379
|
+
proof = Array.isArray(jwtDocument.proof) ? jwtDocument.proof[0].jwt : jwtDocument.proof.jwt
|
|
380
|
+
}
|
|
381
|
+
if (!proof) {
|
|
382
|
+
throw Error(`Could not get JWT from supplied document`)
|
|
383
|
+
}
|
|
384
|
+
return proof
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
static detectDocumentType(document: W3CVerifiableCredential | W3CVerifiablePresentation | JwtDecodedVerifiableCredential | JwtDecodedVerifiablePresentation): DocumentFormat {
|
|
388
|
+
if (typeof document === 'string') {
|
|
389
|
+
return this.isJsonLdAsString(document) ? DocumentFormat.JSONLD : DocumentFormat.JWT
|
|
390
|
+
}
|
|
391
|
+
const proofs = 'vc' in document ? document.vc.proof : 'vp' in document ? document.vp.proof : (<IVerifiableCredential>document).proof
|
|
392
|
+
const proof: IProof = Array.isArray(proofs) ? proofs[0] : proofs
|
|
393
|
+
|
|
394
|
+
if (proof.jwt) {
|
|
395
|
+
return DocumentFormat.JWT
|
|
396
|
+
} else if (proof.type === 'EthereumEip712Signature2021') {
|
|
397
|
+
return DocumentFormat.EIP712
|
|
398
|
+
}
|
|
399
|
+
return DocumentFormat.JSONLD
|
|
400
|
+
}
|
|
245
401
|
}
|
package/src/types/did.ts
CHANGED
|
@@ -19,6 +19,7 @@ export enum IProofType {
|
|
|
19
19
|
JcsEd25519Signature2020 = 'JcsEd25519Signature2020',
|
|
20
20
|
BbsBlsSignatureProof2020 = 'BbsBlsSignatureProof2020',
|
|
21
21
|
BbsBlsBoundSignatureProof2020 = 'BbsBlsBoundSignatureProof2020',
|
|
22
|
+
JwtProof2020 = 'JwtProof2020'
|
|
22
23
|
}
|
|
23
24
|
|
|
24
25
|
export interface IParsedDID {
|