Skip to content

Commit 6834638

Browse files
committed
Make contexts file easier to read.
1 parent 2e12124 commit 6834638

File tree

1 file changed

+11
-17
lines changed

1 file changed

+11
-17
lines changed

vc-generator/contexts.js

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,20 @@ import dataIntegrityCtx from '@digitalbazaar/data-integrity-context';
99
import didCtx from '@digitalcredentials/did-context';
1010
import multikeyCtx from '@digitalbazaar/multikey-context';
1111

12-
const contextMap = new Map(credentialsContexts);
13-
addContexts({
14-
contexts: dataIntegrityCtx.contexts,
15-
map: contextMap
16-
});
12+
// setup the context map;
13+
export const contextMap = new Map();
14+
// add all the contexts here
15+
addContexts({contexts: dataIntegrityCtx.contexts});
16+
addContexts({contexts: didCtx.contexts});
17+
addContexts({contexts: credentialsContexts});
1718

1819
//FIXME this really should be done in separate documentLoaders
1920
//so that other tests do not get the modified context
2021
//FIXME this also should be a structuredClone of the v2 context
2122
//which replaces the original jsonld context in the contextMap
23+
const {
24+
id: v1ContextUrl,
25+
} = structuredClone(namedCredentialsContexts.get('v1'));
2226
const {
2327
id: v2ContextUrl,
2428
context: v2Context
@@ -57,27 +61,19 @@ contextMap.set(
5761
v2ContextUrl,
5862
v2Context
5963
);
60-
addContexts({
61-
contexts: didCtx.contexts,
62-
map: contextMap
63-
});
6464

6565
function copyTerm({context, oldTerm, newTerm}) {
6666
const ctx = context['@context'];
6767
ctx[newTerm] = structuredClone(ctx[oldTerm]);
6868
}
6969

70-
function addContexts({contexts, map, mutate = id => id}) {
70+
function addContexts({contexts, map = contextMap, mutate = id => id}) {
7171
for(const [key, value] of contexts) {
7272
map.set(key, mutate(structuredClone(value)));
7373
}
7474
}
7575

76-
const {
77-
id: v1ContextUrl,
78-
} = structuredClone(namedCredentialsContexts.get('v1'));
79-
80-
function getVcVersion(credential) {
76+
export function getVcVersion(credential) {
8177
const [firstContext] = credential?.['@context'];
8278
if(firstContext === v2ContextUrl) {
8379
return '2.0';
@@ -87,5 +83,3 @@ function getVcVersion(credential) {
8783
}
8884
throw new Error(`Could not determine vcVersion from context ${firstContext}`);
8985
}
90-
91-
export {contextMap, getVcVersion};

0 commit comments

Comments
 (0)