@@ -9,16 +9,20 @@ import dataIntegrityCtx from '@digitalbazaar/data-integrity-context';
9
9
import didCtx from '@digitalcredentials/did-context' ;
10
10
import multikeyCtx from '@digitalbazaar/multikey-context' ;
11
11
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 } ) ;
17
18
18
19
//FIXME this really should be done in separate documentLoaders
19
20
//so that other tests do not get the modified context
20
21
//FIXME this also should be a structuredClone of the v2 context
21
22
//which replaces the original jsonld context in the contextMap
23
+ const {
24
+ id : v1ContextUrl ,
25
+ } = structuredClone ( namedCredentialsContexts . get ( 'v1' ) ) ;
22
26
const {
23
27
id : v2ContextUrl ,
24
28
context : v2Context
@@ -57,27 +61,19 @@ contextMap.set(
57
61
v2ContextUrl ,
58
62
v2Context
59
63
) ;
60
- addContexts ( {
61
- contexts : didCtx . contexts ,
62
- map : contextMap
63
- } ) ;
64
64
65
65
function copyTerm ( { context, oldTerm, newTerm} ) {
66
66
const ctx = context [ '@context' ] ;
67
67
ctx [ newTerm ] = structuredClone ( ctx [ oldTerm ] ) ;
68
68
}
69
69
70
- function addContexts ( { contexts, map, mutate = id => id } ) {
70
+ function addContexts ( { contexts, map = contextMap , mutate = id => id } ) {
71
71
for ( const [ key , value ] of contexts ) {
72
72
map . set ( key , mutate ( structuredClone ( value ) ) ) ;
73
73
}
74
74
}
75
75
76
- const {
77
- id : v1ContextUrl ,
78
- } = structuredClone ( namedCredentialsContexts . get ( 'v1' ) ) ;
79
-
80
- function getVcVersion ( credential ) {
76
+ export function getVcVersion ( credential ) {
81
77
const [ firstContext ] = credential ?. [ '@context' ] ;
82
78
if ( firstContext === v2ContextUrl ) {
83
79
return '2.0' ;
@@ -87,5 +83,3 @@ function getVcVersion(credential) {
87
83
}
88
84
throw new Error ( `Could not determine vcVersion from context ${ firstContext } ` ) ;
89
85
}
90
-
91
- export { contextMap , getVcVersion } ;
0 commit comments