Skip to content

Add all data integrity contexts #128

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions vc-generator/contexts.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,20 @@ import dataIntegrityCtx from '@digitalbazaar/data-integrity-context';
import didCtx from '@digitalcredentials/did-context';
import multikeyCtx from '@digitalbazaar/multikey-context';

const contextMap = new Map(credentialsContexts);
// setup the context map;
export const contextMap = new Map();
// add all the contexts here
addContexts({contexts: dataIntegrityCtx.contexts});
addContexts({contexts: didCtx.contexts});
addContexts({contexts: credentialsContexts});

//FIXME this really should be done in separate documentLoaders
//so that other tests do not get the modified context
//FIXME this also should be a structuredClone of the v2 context
//which replaces the original jsonld context in the contextMap
const {
id: v1ContextUrl,
} = structuredClone(namedCredentialsContexts.get('v1'));
const {
id: v2ContextUrl,
context: v2Context
Expand Down Expand Up @@ -52,27 +61,19 @@ contextMap.set(
v2ContextUrl,
v2Context
);
addContexts({
contexts: didCtx.contexts,
map: contextMap
});

function copyTerm({context, oldTerm, newTerm}) {
const ctx = context['@context'];
ctx[newTerm] = structuredClone(ctx[oldTerm]);
}

function addContexts({contexts, map, mutate = id => id}) {
function addContexts({contexts, map = contextMap, mutate = id => id}) {
for(const [key, value] of contexts) {
map.set(key, mutate(structuredClone(value)));
}
}

const {
id: v1ContextUrl,
} = structuredClone(namedCredentialsContexts.get('v1'));

function getVcVersion(credential) {
export function getVcVersion(credential) {
const [firstContext] = credential?.['@context'];
if(firstContext === v2ContextUrl) {
return '2.0';
Expand All @@ -82,5 +83,3 @@ function getVcVersion(credential) {
}
throw new Error(`Could not determine vcVersion from context ${firstContext}`);
}

export {contextMap, getVcVersion};
Loading