Skip to content

Commit

Permalink
introduce static contexts
Browse files Browse the repository at this point in the history
Signed-off-by: F-Node-Karlsruhe <christian.fries@eecc.de>
  • Loading branch information
F-Node-Karlsruhe committed Oct 20, 2023
1 parent a6681cb commit 68dbbd0
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 17 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ VC Verifier Changelog
WIP
---

- introduce static contexts


1.7.4 (2023-10-10)
---

Expand Down
4 changes: 2 additions & 2 deletions api/__tests__/credential.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ describe("Verifier API Test for Credentials", () => {
/**
* Test StatusList2020 revoked credential
*/
test("Verify revoked credential", async () => {
test("Verify revoked credential - RevocationList2020", async () => {
const res = await request(server).post("/api/verifier").send([revoked2020Credential]);
expect(res.statusCode).toEqual(200);
expect(res.body[0]).toHaveProperty('verified');
Expand All @@ -244,7 +244,7 @@ describe("Verifier API Test for Credentials", () => {
/**
* Test StatusList2021 revoked credential
*/
test("Verify revoked credential", async () => {
test("Verify revoked credential - StatusList2021", async () => {
const res = await request(server).post("/api/verifier").send([revoked2021Credential]);
expect(res.statusCode).toEqual(200);
expect(res.body[0]).toHaveProperty('verified');
Expand Down
5 changes: 5 additions & 0 deletions api/src/services/documentLoader/context/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { statusList2021Context } from "./status-list-2021";

export const contexts = new Map([
['https://w3id.org/vc/status-list/2021/v1', statusList2021Context]
]);
55 changes: 55 additions & 0 deletions api/src/services/documentLoader/context/status-list-2021.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
export const statusList2021Context: any = {
"@context": {
"@protected": true,

"StatusList2021Credential": {
"@id":
"https://w3id.org/vc/status-list#StatusList2021Credential",
"@context": {
"@protected": true,

"id": "@id",
"type": "@type",

"description": "http://schema.org/description",
"name": "http://schema.org/name"
}
},

"StatusList2021": {
"@id":
"https://w3id.org/vc/status-list#StatusList2021",
"@context": {
"@protected": true,

"id": "@id",
"type": "@type",

"statusPurpose":
"https://w3id.org/vc/status-list#statusPurpose",
"encodedList": "https://w3id.org/vc/status-list#encodedList"
}
},

"StatusList2021Entry": {
"@id":
"https://w3id.org/vc/status-list#StatusList2021Entry",
"@context": {
"@protected": true,

"id": "@id",
"type": "@type",

"statusPurpose":
"https://w3id.org/vc/status-list#statusPurpose",
"statusListIndex":
"https://w3id.org/vc/status-list#statusListIndex",
"statusListCredential": {
"@id":
"https://w3id.org/vc/status-list#statusListCredential",
"@type": "@id"
}
}
}
}
}
19 changes: 4 additions & 15 deletions api/src/services/documentLoader/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
import jsonldSignatures from 'jsonld-signatures';
import { getResolver } from './didresolver.js';
import { fetch_jsonld, fetchIPFS } from '../fetch/index.js';
import { contexts } from './context/index.js';

const TRUSTED_CONTEXT_DOMAINS: [string] = ['https://ssi.eecc.de']

const cache = new Map();
const cache = contexts;

const documentLoader: Promise<any> = jsonldSignatures.extendContextLoader(async (url: string) => {

Expand Down Expand Up @@ -54,24 +53,14 @@ const documentLoader: Promise<any> = jsonldSignatures.extendContextLoader(async

document = await fetchIPFS(url);

// always cache IPFS
cache.set(url, document);

} else {

document = await fetch_jsonld(url);

// cache and warn if external
if (!TRUSTED_CONTEXT_DOMAINS.some((trusted) => url.startsWith(trusted))) {

// console.log(`Fetched and cached @context from ${url}. Use with care!`);

cache.set(url, document);

}

}

cache.set(url, document);

}

return {
Expand Down

0 comments on commit 68dbbd0

Please sign in to comment.