Skip to content

Commit 5a23c1f

Browse files
authored
Add tests for prefix expansion with other protected contexts
1 parent f734d3f commit 5a23c1f

File tree

5 files changed

+436
-9
lines changed

5 files changed

+436
-9
lines changed

mocks/contexts/index.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/* istanbul ignore file */
2+
3+
import { IDocumentLoader, IJsonLdContext } from 'jsonld-context-parser';
4+
import vc from './vc';
5+
6+
const allContexts = {
7+
"https://www.w3.org/2018/credentials/v1": vc,
8+
}
9+
10+
export default allContexts;
11+
12+
export class MockedDocumentLoader implements IDocumentLoader {
13+
async load(url: string): Promise<IJsonLdContext> {
14+
if (!(url in allContexts)) {
15+
throw new Error(`URL [${url}] is not in the set of hard coded contexts`);
16+
}
17+
return allContexts[url];
18+
}
19+
}

mocks/contexts/vc.ts

Lines changed: 258 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,258 @@
1+
export default {
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+
}
238+
239+
240+
const data = {
241+
"@context": {
242+
"@version": 1.1,
243+
"@protected": true,
244+
"id": "@id",
245+
"type": "@type",
246+
"VerifiableCredential": {
247+
"@id": "https://www.w3.org/2018/credentials#VerifiableCredential",
248+
"@context": {
249+
"@version": 1.1,
250+
"@protected": true,
251+
"id": "@id",
252+
"type": "@type",
253+
"cred": "https://www.w3.org/2018/credentials#",
254+
"credentialSubject": {"@id": "cred:credentialSubject", "@type": "@id"},
255+
}
256+
},
257+
}
258+
}

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"buffer": "^6.0.3",
3939
"canonicalize": "^1.0.1",
4040
"http-link-header": "^1.0.2",
41-
"jsonld-context-parser": "^2.3.0",
41+
"jsonld-context-parser": "^2.3.3",
4242
"rdf-data-factory": "^1.1.0",
4343
"readable-stream": "^4.0.0"
4444
},
@@ -94,7 +94,7 @@
9494
"test": "jest ${1}",
9595
"test-watch": "jest ${1} --watch",
9696
"coveralls": "jest --coverage && cat ./coverage/lcov.info | coveralls",
97-
"lint": "tslint index.ts lib/**/*.ts test/**/*.ts --exclude '**/*.d.ts'",
97+
"lint": "tslint index.ts lib/**/*.ts test/**/*.ts test/*.ts --exclude '**/*.d.ts'",
9898
"build": "tsc",
9999
"build-watch": "tsc --watch",
100100
"validate": "npm ls",

0 commit comments

Comments
 (0)