@veramo/credential-ld 3.1.1-next.8 → 3.1.2-next.30
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/build/action-handler.js +2 -2
- package/build/action-handler.js.map +1 -1
- package/build/ld-context-loader.d.ts +2 -2
- package/build/ld-context-loader.d.ts.map +1 -1
- package/build/ld-context-loader.js +9 -2
- package/build/ld-context-loader.js.map +1 -1
- package/build/ld-credential-module.d.ts +3 -3
- package/build/ld-credential-module.d.ts.map +1 -1
- package/build/ld-credential-module.js +27 -7
- package/build/ld-credential-module.js.map +1 -1
- package/build/ld-default-contexts.d.ts +5 -1
- package/build/ld-default-contexts.d.ts.map +1 -1
- package/build/ld-default-contexts.js +21 -3
- package/build/ld-default-contexts.js.map +1 -1
- package/build/tsdoc-metadata.json +1 -1
- package/build/types.d.ts +12 -0
- package/build/types.d.ts.map +1 -1
- package/contexts/X25519KeyAgreementKey2019.jsonld +26 -0
- package/contexts/did_v0.11.jsonld +58 -0
- package/contexts/ed25519-signature-2018-v1.jsonld +91 -0
- package/contexts/kyc-v1.jsonld +8 -0
- package/contexts/lds-ecdsa-secp256k1-recovery2020-0.0.jsonld +60 -0
- package/contexts/profile-v1.jsonld +8 -0
- package/contexts/security_context_v1.jsonld +58 -0
- package/contexts/socialmedia-v1.jsonld +7 -0
- package/contexts/transmute_v1.jsonld +21 -0
- package/contexts/w3_2018_credentials_v1.jsonld +237 -0
- package/package.json +14 -13
- package/plugin.schema.json +10 -0
- package/src/__tests__/context.loader.test.ts +39 -0
- package/src/__tests__/issue-verify-flow.test.ts +84 -0
- package/src/action-handler.ts +2 -2
- package/src/ld-context-loader.ts +7 -6
- package/src/ld-credential-module.ts +25 -5
- package/src/ld-default-contexts.ts +13 -4
- package/src/types.ts +15 -1
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"@context": {
|
|
3
|
+
"@protected": true,
|
|
4
|
+
"id": "@id",
|
|
5
|
+
"type": "@type",
|
|
6
|
+
|
|
7
|
+
"alsoKnownAs": {
|
|
8
|
+
"@id": "https://www.w3.org/ns/activitystreams#alsoKnownAs",
|
|
9
|
+
"@type": "@id"
|
|
10
|
+
},
|
|
11
|
+
"assertionMethod": {
|
|
12
|
+
"@id": "https://w3id.org/security#assertionMethod",
|
|
13
|
+
"@type": "@id",
|
|
14
|
+
"@container": "@set"
|
|
15
|
+
},
|
|
16
|
+
"authentication": {
|
|
17
|
+
"@id": "https://w3id.org/security#authenticationMethod",
|
|
18
|
+
"@type": "@id",
|
|
19
|
+
"@container": "@set"
|
|
20
|
+
},
|
|
21
|
+
"capabilityDelegation": {
|
|
22
|
+
"@id": "https://w3id.org/security#capabilityDelegationMethod",
|
|
23
|
+
"@type": "@id",
|
|
24
|
+
"@container": "@set"
|
|
25
|
+
},
|
|
26
|
+
"capabilityInvocation": {
|
|
27
|
+
"@id": "https://w3id.org/security#capabilityInvocationMethod",
|
|
28
|
+
"@type": "@id",
|
|
29
|
+
"@container": "@set"
|
|
30
|
+
},
|
|
31
|
+
"controller": {
|
|
32
|
+
"@id": "https://w3id.org/security#controller",
|
|
33
|
+
"@type": "@id"
|
|
34
|
+
},
|
|
35
|
+
"keyAgreement": {
|
|
36
|
+
"@id": "https://w3id.org/security#keyAgreementMethod",
|
|
37
|
+
"@type": "@id",
|
|
38
|
+
"@container": "@set"
|
|
39
|
+
},
|
|
40
|
+
"service": {
|
|
41
|
+
"@id": "https://www.w3.org/ns/did#service",
|
|
42
|
+
"@type": "@id",
|
|
43
|
+
"@context": {
|
|
44
|
+
"@protected": true,
|
|
45
|
+
"id": "@id",
|
|
46
|
+
"type": "@type",
|
|
47
|
+
"serviceEndpoint": {
|
|
48
|
+
"@id": "https://www.w3.org/ns/did#serviceEndpoint",
|
|
49
|
+
"@type": "@id"
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
"verificationMethod": {
|
|
54
|
+
"@id": "https://w3id.org/security#verificationMethod",
|
|
55
|
+
"@type": "@id"
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"@context": [
|
|
3
|
+
{
|
|
4
|
+
"@version": 1.1
|
|
5
|
+
},
|
|
6
|
+
"https://www.w3.org/ns/did/v1",
|
|
7
|
+
{
|
|
8
|
+
"JsonWebKey2020": "https://w3id.org/security#JsonWebKey2020",
|
|
9
|
+
"Ed25519VerificationKey2018": "https://w3id.org/security#Ed25519VerificationKey2018",
|
|
10
|
+
"X25519KeyAgreementKey2019": "https://w3id.org/security#X25519KeyAgreementKey2019",
|
|
11
|
+
|
|
12
|
+
"publicKeyJwk": {
|
|
13
|
+
"@id": "https://w3id.org/security#publicKeyJwk",
|
|
14
|
+
"@type": "@json"
|
|
15
|
+
},
|
|
16
|
+
"publicKeyBase58": {
|
|
17
|
+
"@id": "https://w3id.org/security#publicKeyBase58"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
]
|
|
21
|
+
}
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
{
|
|
2
|
+
"@context": {
|
|
3
|
+
"@version": 1.1,
|
|
4
|
+
"@protected": true,
|
|
5
|
+
|
|
6
|
+
"id": "@id",
|
|
7
|
+
"type": "@type",
|
|
8
|
+
|
|
9
|
+
"VerifiableCredential": {
|
|
10
|
+
"@id": "https://www.w3.org/2018/credentials#VerifiableCredential",
|
|
11
|
+
"@context": {
|
|
12
|
+
"@version": 1.1,
|
|
13
|
+
"@protected": true,
|
|
14
|
+
|
|
15
|
+
"id": "@id",
|
|
16
|
+
"type": "@type",
|
|
17
|
+
|
|
18
|
+
"cred": "https://www.w3.org/2018/credentials#",
|
|
19
|
+
"sec": "https://w3id.org/security#",
|
|
20
|
+
"xsd": "http://www.w3.org/2001/XMLSchema#",
|
|
21
|
+
|
|
22
|
+
"credentialSchema": {
|
|
23
|
+
"@id": "cred:credentialSchema",
|
|
24
|
+
"@type": "@id",
|
|
25
|
+
"@context": {
|
|
26
|
+
"@version": 1.1,
|
|
27
|
+
"@protected": true,
|
|
28
|
+
|
|
29
|
+
"id": "@id",
|
|
30
|
+
"type": "@type",
|
|
31
|
+
|
|
32
|
+
"cred": "https://www.w3.org/2018/credentials#",
|
|
33
|
+
|
|
34
|
+
"JsonSchemaValidator2018": "cred:JsonSchemaValidator2018"
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"credentialStatus": {"@id": "cred:credentialStatus", "@type": "@id"},
|
|
38
|
+
"credentialSubject": {"@id": "cred:credentialSubject", "@type": "@id"},
|
|
39
|
+
"evidence": {"@id": "cred:evidence", "@type": "@id"},
|
|
40
|
+
"expirationDate": {"@id": "cred:expirationDate", "@type": "xsd:dateTime"},
|
|
41
|
+
"holder": {"@id": "cred:holder", "@type": "@id"},
|
|
42
|
+
"issued": {"@id": "cred:issued", "@type": "xsd:dateTime"},
|
|
43
|
+
"issuer": {"@id": "cred:issuer", "@type": "@id"},
|
|
44
|
+
"issuanceDate": {"@id": "cred:issuanceDate", "@type": "xsd:dateTime"},
|
|
45
|
+
"proof": {"@id": "sec:proof", "@type": "@id", "@container": "@graph"},
|
|
46
|
+
"refreshService": {
|
|
47
|
+
"@id": "cred:refreshService",
|
|
48
|
+
"@type": "@id",
|
|
49
|
+
"@context": {
|
|
50
|
+
"@version": 1.1,
|
|
51
|
+
"@protected": true,
|
|
52
|
+
|
|
53
|
+
"id": "@id",
|
|
54
|
+
"type": "@type",
|
|
55
|
+
|
|
56
|
+
"cred": "https://www.w3.org/2018/credentials#",
|
|
57
|
+
|
|
58
|
+
"ManualRefreshService2018": "cred:ManualRefreshService2018"
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
"termsOfUse": {"@id": "cred:termsOfUse", "@type": "@id"},
|
|
62
|
+
"validFrom": {"@id": "cred:validFrom", "@type": "xsd:dateTime"},
|
|
63
|
+
"validUntil": {"@id": "cred:validUntil", "@type": "xsd:dateTime"}
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
|
|
67
|
+
"VerifiablePresentation": {
|
|
68
|
+
"@id": "https://www.w3.org/2018/credentials#VerifiablePresentation",
|
|
69
|
+
"@context": {
|
|
70
|
+
"@version": 1.1,
|
|
71
|
+
"@protected": true,
|
|
72
|
+
|
|
73
|
+
"id": "@id",
|
|
74
|
+
"type": "@type",
|
|
75
|
+
|
|
76
|
+
"cred": "https://www.w3.org/2018/credentials#",
|
|
77
|
+
"sec": "https://w3id.org/security#",
|
|
78
|
+
|
|
79
|
+
"holder": {"@id": "cred:holder", "@type": "@id"},
|
|
80
|
+
"proof": {"@id": "sec:proof", "@type": "@id", "@container": "@graph"},
|
|
81
|
+
"verifiableCredential": {"@id": "cred:verifiableCredential", "@type": "@id", "@container": "@graph"}
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
|
|
85
|
+
"EcdsaSecp256k1Signature2019": {
|
|
86
|
+
"@id": "https://w3id.org/security#EcdsaSecp256k1Signature2019",
|
|
87
|
+
"@context": {
|
|
88
|
+
"@version": 1.1,
|
|
89
|
+
"@protected": true,
|
|
90
|
+
|
|
91
|
+
"id": "@id",
|
|
92
|
+
"type": "@type",
|
|
93
|
+
|
|
94
|
+
"sec": "https://w3id.org/security#",
|
|
95
|
+
"xsd": "http://www.w3.org/2001/XMLSchema#",
|
|
96
|
+
|
|
97
|
+
"challenge": "sec:challenge",
|
|
98
|
+
"created": {"@id": "http://purl.org/dc/terms/created", "@type": "xsd:dateTime"},
|
|
99
|
+
"domain": "sec:domain",
|
|
100
|
+
"expires": {"@id": "sec:expiration", "@type": "xsd:dateTime"},
|
|
101
|
+
"jws": "sec:jws",
|
|
102
|
+
"nonce": "sec:nonce",
|
|
103
|
+
"proofPurpose": {
|
|
104
|
+
"@id": "sec:proofPurpose",
|
|
105
|
+
"@type": "@vocab",
|
|
106
|
+
"@context": {
|
|
107
|
+
"@version": 1.1,
|
|
108
|
+
"@protected": true,
|
|
109
|
+
|
|
110
|
+
"id": "@id",
|
|
111
|
+
"type": "@type",
|
|
112
|
+
|
|
113
|
+
"sec": "https://w3id.org/security#",
|
|
114
|
+
|
|
115
|
+
"assertionMethod": {"@id": "sec:assertionMethod", "@type": "@id", "@container": "@set"},
|
|
116
|
+
"authentication": {"@id": "sec:authenticationMethod", "@type": "@id", "@container": "@set"}
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
"proofValue": "sec:proofValue",
|
|
120
|
+
"verificationMethod": {"@id": "sec:verificationMethod", "@type": "@id"}
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
|
|
124
|
+
"EcdsaSecp256r1Signature2019": {
|
|
125
|
+
"@id": "https://w3id.org/security#EcdsaSecp256r1Signature2019",
|
|
126
|
+
"@context": {
|
|
127
|
+
"@version": 1.1,
|
|
128
|
+
"@protected": true,
|
|
129
|
+
|
|
130
|
+
"id": "@id",
|
|
131
|
+
"type": "@type",
|
|
132
|
+
|
|
133
|
+
"sec": "https://w3id.org/security#",
|
|
134
|
+
"xsd": "http://www.w3.org/2001/XMLSchema#",
|
|
135
|
+
|
|
136
|
+
"challenge": "sec:challenge",
|
|
137
|
+
"created": {"@id": "http://purl.org/dc/terms/created", "@type": "xsd:dateTime"},
|
|
138
|
+
"domain": "sec:domain",
|
|
139
|
+
"expires": {"@id": "sec:expiration", "@type": "xsd:dateTime"},
|
|
140
|
+
"jws": "sec:jws",
|
|
141
|
+
"nonce": "sec:nonce",
|
|
142
|
+
"proofPurpose": {
|
|
143
|
+
"@id": "sec:proofPurpose",
|
|
144
|
+
"@type": "@vocab",
|
|
145
|
+
"@context": {
|
|
146
|
+
"@version": 1.1,
|
|
147
|
+
"@protected": true,
|
|
148
|
+
|
|
149
|
+
"id": "@id",
|
|
150
|
+
"type": "@type",
|
|
151
|
+
|
|
152
|
+
"sec": "https://w3id.org/security#",
|
|
153
|
+
|
|
154
|
+
"assertionMethod": {"@id": "sec:assertionMethod", "@type": "@id", "@container": "@set"},
|
|
155
|
+
"authentication": {"@id": "sec:authenticationMethod", "@type": "@id", "@container": "@set"}
|
|
156
|
+
}
|
|
157
|
+
},
|
|
158
|
+
"proofValue": "sec:proofValue",
|
|
159
|
+
"verificationMethod": {"@id": "sec:verificationMethod", "@type": "@id"}
|
|
160
|
+
}
|
|
161
|
+
},
|
|
162
|
+
|
|
163
|
+
"Ed25519Signature2018": {
|
|
164
|
+
"@id": "https://w3id.org/security#Ed25519Signature2018",
|
|
165
|
+
"@context": {
|
|
166
|
+
"@version": 1.1,
|
|
167
|
+
"@protected": true,
|
|
168
|
+
|
|
169
|
+
"id": "@id",
|
|
170
|
+
"type": "@type",
|
|
171
|
+
|
|
172
|
+
"sec": "https://w3id.org/security#",
|
|
173
|
+
"xsd": "http://www.w3.org/2001/XMLSchema#",
|
|
174
|
+
|
|
175
|
+
"challenge": "sec:challenge",
|
|
176
|
+
"created": {"@id": "http://purl.org/dc/terms/created", "@type": "xsd:dateTime"},
|
|
177
|
+
"domain": "sec:domain",
|
|
178
|
+
"expires": {"@id": "sec:expiration", "@type": "xsd:dateTime"},
|
|
179
|
+
"jws": "sec:jws",
|
|
180
|
+
"nonce": "sec:nonce",
|
|
181
|
+
"proofPurpose": {
|
|
182
|
+
"@id": "sec:proofPurpose",
|
|
183
|
+
"@type": "@vocab",
|
|
184
|
+
"@context": {
|
|
185
|
+
"@version": 1.1,
|
|
186
|
+
"@protected": true,
|
|
187
|
+
|
|
188
|
+
"id": "@id",
|
|
189
|
+
"type": "@type",
|
|
190
|
+
|
|
191
|
+
"sec": "https://w3id.org/security#",
|
|
192
|
+
|
|
193
|
+
"assertionMethod": {"@id": "sec:assertionMethod", "@type": "@id", "@container": "@set"},
|
|
194
|
+
"authentication": {"@id": "sec:authenticationMethod", "@type": "@id", "@container": "@set"}
|
|
195
|
+
}
|
|
196
|
+
},
|
|
197
|
+
"proofValue": "sec:proofValue",
|
|
198
|
+
"verificationMethod": {"@id": "sec:verificationMethod", "@type": "@id"}
|
|
199
|
+
}
|
|
200
|
+
},
|
|
201
|
+
|
|
202
|
+
"RsaSignature2018": {
|
|
203
|
+
"@id": "https://w3id.org/security#RsaSignature2018",
|
|
204
|
+
"@context": {
|
|
205
|
+
"@version": 1.1,
|
|
206
|
+
"@protected": true,
|
|
207
|
+
|
|
208
|
+
"challenge": "sec:challenge",
|
|
209
|
+
"created": {"@id": "http://purl.org/dc/terms/created", "@type": "xsd:dateTime"},
|
|
210
|
+
"domain": "sec:domain",
|
|
211
|
+
"expires": {"@id": "sec:expiration", "@type": "xsd:dateTime"},
|
|
212
|
+
"jws": "sec:jws",
|
|
213
|
+
"nonce": "sec:nonce",
|
|
214
|
+
"proofPurpose": {
|
|
215
|
+
"@id": "sec:proofPurpose",
|
|
216
|
+
"@type": "@vocab",
|
|
217
|
+
"@context": {
|
|
218
|
+
"@version": 1.1,
|
|
219
|
+
"@protected": true,
|
|
220
|
+
|
|
221
|
+
"id": "@id",
|
|
222
|
+
"type": "@type",
|
|
223
|
+
|
|
224
|
+
"sec": "https://w3id.org/security#",
|
|
225
|
+
|
|
226
|
+
"assertionMethod": {"@id": "sec:assertionMethod", "@type": "@id", "@container": "@set"},
|
|
227
|
+
"authentication": {"@id": "sec:authenticationMethod", "@type": "@id", "@container": "@set"}
|
|
228
|
+
}
|
|
229
|
+
},
|
|
230
|
+
"proofValue": "sec:proofValue",
|
|
231
|
+
"verificationMethod": {"@id": "sec:verificationMethod", "@type": "@id"}
|
|
232
|
+
}
|
|
233
|
+
},
|
|
234
|
+
|
|
235
|
+
"proof": {"@id": "https://w3id.org/security#proof", "@type": "@id", "@container": "@graph"}
|
|
236
|
+
}
|
|
237
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@veramo/credential-ld",
|
|
3
3
|
"description": "Veramo plugin for working with W3C JSON-LD Verifiable Credentials & Presentations.",
|
|
4
|
-
"version": "3.1.
|
|
4
|
+
"version": "3.1.2-next.30+ea7641e4",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
@@ -14,27 +14,28 @@
|
|
|
14
14
|
}
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@transmute/credentials-context": "^0.7.0-unstable.
|
|
18
|
-
"@transmute/ed25519-signature-2018": "^0.7.0-unstable.
|
|
17
|
+
"@transmute/credentials-context": "^0.7.0-unstable.34",
|
|
18
|
+
"@transmute/ed25519-signature-2018": "^0.7.0-unstable.34",
|
|
19
19
|
"@transmute/lds-ecdsa-secp256k1-recovery2020": "^0.0.7",
|
|
20
|
-
"@veramo/core": "^3.1.
|
|
21
|
-
"@veramo/did-resolver": "^3.1.
|
|
22
|
-
"@veramo/utils": "^3.1.
|
|
23
|
-
"debug": "^4.
|
|
24
|
-
"did-resolver": "3.1.
|
|
20
|
+
"@veramo/core": "^3.1.2-next.30+ea7641e4",
|
|
21
|
+
"@veramo/did-resolver": "^3.1.2-next.30+ea7641e4",
|
|
22
|
+
"@veramo/utils": "^3.1.2-next.30+ea7641e4",
|
|
23
|
+
"debug": "^4.3.3",
|
|
24
|
+
"did-resolver": "^3.1.5",
|
|
25
25
|
"jsonld": "^5.2.0",
|
|
26
|
-
"jsonld-signatures": "^9.
|
|
27
|
-
"uint8arrays": "^
|
|
26
|
+
"jsonld-signatures": "^9.3.1",
|
|
27
|
+
"uint8arrays": "^3.0.0",
|
|
28
28
|
"vc-js": "^0.6.4"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@types/debug": "4.1.7",
|
|
32
|
-
"borc": "
|
|
33
|
-
"typescript": "4.
|
|
32
|
+
"borc": "3.0.0",
|
|
33
|
+
"typescript": "4.5.4"
|
|
34
34
|
},
|
|
35
35
|
"files": [
|
|
36
36
|
"build/**/*",
|
|
37
37
|
"src/**/*",
|
|
38
|
+
"contexts/**/*.jsonld",
|
|
38
39
|
"plugin.schema.json",
|
|
39
40
|
"README.md",
|
|
40
41
|
"LICENSE"
|
|
@@ -46,5 +47,5 @@
|
|
|
46
47
|
"author": "Mircea Nistor <mircea.nistor@mesh.xyz>",
|
|
47
48
|
"license": "Apache-2.0",
|
|
48
49
|
"keywords": [],
|
|
49
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "ea7641e4e21da0fc02535848c40ff81e644c069e"
|
|
50
51
|
}
|
package/plugin.schema.json
CHANGED
|
@@ -326,6 +326,11 @@
|
|
|
326
326
|
"credential": {
|
|
327
327
|
"$ref": "#/components/schemas/VerifiableCredential",
|
|
328
328
|
"description": "The json payload of the Credential according to the\n {@link https://www.w3.org/TR/vc-data-model/#credentials | canonical model } \n\nThe signer of the Credential is chosen based on the `issuer.id` property of the `credential`"
|
|
329
|
+
},
|
|
330
|
+
"fetchRemoteContexts": {
|
|
331
|
+
"type": "boolean",
|
|
332
|
+
"description": "Set this to true if you want the '@context' URLs to be fetched in case they are not pre-loaded.",
|
|
333
|
+
"default": false
|
|
329
334
|
}
|
|
330
335
|
},
|
|
331
336
|
"required": [
|
|
@@ -347,6 +352,11 @@
|
|
|
347
352
|
"domain": {
|
|
348
353
|
"type": "string",
|
|
349
354
|
"description": "Optional (only for JWT) string domain parameter to verify the verifiable presentation against"
|
|
355
|
+
},
|
|
356
|
+
"fetchRemoteContexts": {
|
|
357
|
+
"type": "boolean",
|
|
358
|
+
"description": "Set this to true if you want the '@context' URLs to be fetched in case they are not pre-loaded.",
|
|
359
|
+
"default": false
|
|
350
360
|
}
|
|
351
361
|
},
|
|
352
362
|
"required": [
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { ContextDoc } from '../types'
|
|
2
|
+
import { LdContextLoader } from '../ld-context-loader'
|
|
3
|
+
import { LdDefaultContexts } from '../ld-default-contexts'
|
|
4
|
+
|
|
5
|
+
describe('credential-ld context loader', () => {
|
|
6
|
+
const customContext: Record<string, ContextDoc> = {
|
|
7
|
+
'https://example.com/custom/context': {
|
|
8
|
+
'@context': {
|
|
9
|
+
'@version': 1.1,
|
|
10
|
+
id: '@id',
|
|
11
|
+
type: '@type',
|
|
12
|
+
nothing: 'https://example.com/nothing',
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
it('loads custom context from record', async () => {
|
|
18
|
+
expect.assertions(2)
|
|
19
|
+
const loader = new LdContextLoader({ contextsPaths: [customContext] })
|
|
20
|
+
expect(loader.has('https://example.com/custom/context')).toBe(true)
|
|
21
|
+
await expect(loader.get('https://example.com/custom/context')).resolves.toEqual({
|
|
22
|
+
'@context': {
|
|
23
|
+
'@version': 1.1,
|
|
24
|
+
id: '@id',
|
|
25
|
+
type: '@type',
|
|
26
|
+
nothing: 'https://example.com/nothing',
|
|
27
|
+
},
|
|
28
|
+
})
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
it('loads context from default map', async () => {
|
|
32
|
+
expect.assertions(2)
|
|
33
|
+
const loader = new LdContextLoader({ contextsPaths: [LdDefaultContexts] })
|
|
34
|
+
expect(loader.has('https://www.w3.org/2018/credentials/v1')).toBe(true)
|
|
35
|
+
|
|
36
|
+
const credsContext = await loader.get('https://www.w3.org/2018/credentials/v1')
|
|
37
|
+
expect(credsContext['@context']).toBeDefined()
|
|
38
|
+
})
|
|
39
|
+
})
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createAgent,
|
|
3
|
+
CredentialPayload,
|
|
4
|
+
IDIDManager,
|
|
5
|
+
IIdentifier,
|
|
6
|
+
IKeyManager,
|
|
7
|
+
IResolver,
|
|
8
|
+
TAgent,
|
|
9
|
+
} from '../../../core/src'
|
|
10
|
+
import { CredentialIssuer, ICredentialIssuer } from '../../../credential-w3c/src'
|
|
11
|
+
import { DIDManager, MemoryDIDStore } from '../../../did-manager/src'
|
|
12
|
+
import { KeyManager, MemoryKeyStore, MemoryPrivateKeyStore } from '../../../key-manager/src'
|
|
13
|
+
import { KeyManagementSystem } from '../../../kms-local/src'
|
|
14
|
+
import { getDidKeyResolver, KeyDIDProvider } from '../../../did-provider-key/src'
|
|
15
|
+
import { DIDResolverPlugin } from '../../../did-resolver/src'
|
|
16
|
+
import { ContextDoc } from '../types'
|
|
17
|
+
import { CredentialIssuerLD } from '../action-handler'
|
|
18
|
+
import { LdDefaultContexts } from '../ld-default-contexts'
|
|
19
|
+
import { VeramoEd25519Signature2018 } from '../suites/Ed25519Signature2018'
|
|
20
|
+
import { Resolver } from 'did-resolver'
|
|
21
|
+
|
|
22
|
+
const customContext: Record<string, ContextDoc> = {
|
|
23
|
+
'custom:example.context': {
|
|
24
|
+
'@context': {
|
|
25
|
+
nothing: 'custom:example.context#blank',
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
describe('credential-LD full flow', () => {
|
|
31
|
+
let didKeyIdentifier: IIdentifier
|
|
32
|
+
let agent: TAgent<IResolver & IKeyManager & IDIDManager & ICredentialIssuer>
|
|
33
|
+
|
|
34
|
+
beforeAll(async () => {
|
|
35
|
+
agent = createAgent({
|
|
36
|
+
plugins: [
|
|
37
|
+
new KeyManager({
|
|
38
|
+
store: new MemoryKeyStore(),
|
|
39
|
+
kms: {
|
|
40
|
+
local: new KeyManagementSystem(new MemoryPrivateKeyStore()),
|
|
41
|
+
},
|
|
42
|
+
}),
|
|
43
|
+
new DIDManager({
|
|
44
|
+
providers: {
|
|
45
|
+
'did:key': new KeyDIDProvider({ defaultKms: 'local' }),
|
|
46
|
+
},
|
|
47
|
+
store: new MemoryDIDStore(),
|
|
48
|
+
defaultProvider: 'did:key',
|
|
49
|
+
}),
|
|
50
|
+
new DIDResolverPlugin({
|
|
51
|
+
resolver: new Resolver({ ...getDidKeyResolver() }),
|
|
52
|
+
}),
|
|
53
|
+
new CredentialIssuer(),
|
|
54
|
+
new CredentialIssuerLD({
|
|
55
|
+
contextMaps: [LdDefaultContexts, customContext],
|
|
56
|
+
suites: [new VeramoEd25519Signature2018()],
|
|
57
|
+
}),
|
|
58
|
+
],
|
|
59
|
+
})
|
|
60
|
+
didKeyIdentifier = await agent.didManagerCreate()
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
it('works with Ed25519Signature2018', async () => {
|
|
64
|
+
const credential: CredentialPayload = {
|
|
65
|
+
issuer: didKeyIdentifier.did,
|
|
66
|
+
'@context': ['custom:example.context'],
|
|
67
|
+
credentialSubject: {
|
|
68
|
+
nothing: 'else matters',
|
|
69
|
+
},
|
|
70
|
+
}
|
|
71
|
+
const verifiableCredential = await agent.createVerifiableCredential({
|
|
72
|
+
credential,
|
|
73
|
+
proofFormat: 'lds',
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
expect(verifiableCredential).toBeDefined()
|
|
77
|
+
|
|
78
|
+
const verified = await agent.verifyCredential({
|
|
79
|
+
credential: verifiableCredential,
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
expect(verified).toBe(true)
|
|
83
|
+
})
|
|
84
|
+
})
|
package/src/action-handler.ts
CHANGED
|
@@ -183,7 +183,7 @@ export class CredentialIssuerLD implements IAgentPlugin {
|
|
|
183
183
|
context: IRequiredContext,
|
|
184
184
|
): Promise<boolean> {
|
|
185
185
|
const credential = args.credential
|
|
186
|
-
return this.ldCredentialModule.verifyCredential(credential, context)
|
|
186
|
+
return this.ldCredentialModule.verifyCredential(credential, args.fetchRemoteContexts || false, context)
|
|
187
187
|
}
|
|
188
188
|
|
|
189
189
|
/** {@inheritdoc ICredentialIssuerLD.verifyPresentationLD} */
|
|
@@ -192,7 +192,7 @@ export class CredentialIssuerLD implements IAgentPlugin {
|
|
|
192
192
|
context: IRequiredContext,
|
|
193
193
|
): Promise<boolean> {
|
|
194
194
|
const presentation = args.presentation
|
|
195
|
-
return this.ldCredentialModule.verifyPresentation(presentation, args.challenge, args.domain, context)
|
|
195
|
+
return this.ldCredentialModule.verifyPresentation(presentation, args.challenge, args.domain, args.fetchRemoteContexts || false, context)
|
|
196
196
|
}
|
|
197
197
|
|
|
198
198
|
private async findSigningKeyWithId(
|
package/src/ld-context-loader.ts
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The LdContextLoader is initialized with a List of Map<string, ContextDoc
|
|
2
|
+
* The LdContextLoader is initialized with a List of Map<string, ContextDoc | Promise<ContextDoc>>
|
|
3
3
|
* that it unifies into a single Map to provide to the documentLoader within
|
|
4
4
|
* the w3c credential module.
|
|
5
5
|
*/
|
|
6
|
-
import { OrPromise, RecordLike } from '@veramo/utils'
|
|
6
|
+
import { isIterable, OrPromise, RecordLike } from '@veramo/utils'
|
|
7
7
|
import { ContextDoc } from './types'
|
|
8
8
|
|
|
9
9
|
export class LdContextLoader {
|
|
10
|
-
private contexts: Record<string, OrPromise<ContextDoc>>
|
|
10
|
+
private readonly contexts: Record<string, OrPromise<ContextDoc>>
|
|
11
11
|
|
|
12
12
|
constructor(options: { contextsPaths: RecordLike<OrPromise<ContextDoc>>[] }) {
|
|
13
13
|
this.contexts = {}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
Array.from(options.contextsPaths, (mapItem) => {
|
|
15
|
+
const map = isIterable(mapItem) ? mapItem : Object.entries(mapItem)
|
|
16
|
+
// generate-plugin-schema is failing unless we use the cast to `any[]`
|
|
17
|
+
for (const [key, value] of map as any[]) {
|
|
17
18
|
this.contexts[key] = value
|
|
18
19
|
}
|
|
19
20
|
})
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
VerifiableCredential,
|
|
8
8
|
VerifiablePresentation,
|
|
9
9
|
} from '@veramo/core'
|
|
10
|
+
import fetch from 'cross-fetch'
|
|
10
11
|
import Debug from 'debug'
|
|
11
12
|
import { extendContextLoader, purposes } from 'jsonld-signatures'
|
|
12
13
|
import * as vc from 'vc-js'
|
|
@@ -34,7 +35,7 @@ export class LdCredentialModule {
|
|
|
34
35
|
this.ldSuiteLoader = options.ldSuiteLoader
|
|
35
36
|
}
|
|
36
37
|
|
|
37
|
-
getDocumentLoader(context: IAgentContext<IResolver
|
|
38
|
+
getDocumentLoader(context: IAgentContext<IResolver>, attemptToFetchContexts: boolean = false) {
|
|
38
39
|
return extendContextLoader(async (url: string) => {
|
|
39
40
|
// console.log(`resolving context for: ${url}`)
|
|
40
41
|
|
|
@@ -65,10 +66,27 @@ export class LdCredentialModule {
|
|
|
65
66
|
documentUrl: url,
|
|
66
67
|
document: contextDoc,
|
|
67
68
|
}
|
|
69
|
+
} else {
|
|
70
|
+
if (attemptToFetchContexts) {
|
|
71
|
+
// attempt to fetch the remote context!!!! MEGA FAIL for JSON-LD.
|
|
72
|
+
debug("WARNING: attempting to fetch the doc directly for ", url)
|
|
73
|
+
try {
|
|
74
|
+
const response = await fetch(url)
|
|
75
|
+
if (response.status === 200) {
|
|
76
|
+
const document = await response.json()
|
|
77
|
+
return {
|
|
78
|
+
contextUrl: null,
|
|
79
|
+
documentUrl: url,
|
|
80
|
+
document
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
} catch (e) {
|
|
84
|
+
debug("WARNING: unable to fetch the doc or interpret it as JSON", e)
|
|
85
|
+
}
|
|
86
|
+
}
|
|
68
87
|
}
|
|
69
88
|
|
|
70
|
-
debug(
|
|
71
|
-
console.log(`WARNING: Possible unknown context/identifier for: ${url}`)
|
|
89
|
+
debug(`WARNING: Possible unknown context/identifier for ${url} \n falling back to default documentLoader`)
|
|
72
90
|
|
|
73
91
|
return vc.defaultDocumentLoader(url)
|
|
74
92
|
})
|
|
@@ -122,12 +140,13 @@ export class LdCredentialModule {
|
|
|
122
140
|
|
|
123
141
|
async verifyCredential(
|
|
124
142
|
credential: VerifiableCredential,
|
|
143
|
+
fetchRemoteContexts: boolean = false,
|
|
125
144
|
context: IAgentContext<IResolver>,
|
|
126
145
|
): Promise<boolean> {
|
|
127
146
|
const result = await vc.verifyCredential({
|
|
128
147
|
credential,
|
|
129
148
|
suite: this.ldSuiteLoader.getAllSignatureSuites().map((x) => x.getSuiteForVerification()),
|
|
130
|
-
documentLoader: this.getDocumentLoader(context),
|
|
149
|
+
documentLoader: this.getDocumentLoader(context, fetchRemoteContexts),
|
|
131
150
|
purpose: new AssertionProofPurpose(),
|
|
132
151
|
compactProof: false,
|
|
133
152
|
})
|
|
@@ -146,12 +165,13 @@ export class LdCredentialModule {
|
|
|
146
165
|
presentation: VerifiablePresentation,
|
|
147
166
|
challenge: string | undefined,
|
|
148
167
|
domain: string | undefined,
|
|
168
|
+
fetchRemoteContexts: boolean = false,
|
|
149
169
|
context: IAgentContext<IResolver>,
|
|
150
170
|
): Promise<boolean> {
|
|
151
171
|
const result = await vc.verify({
|
|
152
172
|
presentation,
|
|
153
173
|
suite: this.ldSuiteLoader.getAllSignatureSuites().map((x) => x.getSuiteForVerification()),
|
|
154
|
-
documentLoader: this.getDocumentLoader(context),
|
|
174
|
+
documentLoader: this.getDocumentLoader(context, fetchRemoteContexts),
|
|
155
175
|
challenge,
|
|
156
176
|
domain,
|
|
157
177
|
purpose: new AssertionProofPurpose(),
|