Skip to content

Commit

Permalink
adds data integrity context
Browse files Browse the repository at this point in the history
  • Loading branch information
kezike committed Mar 9, 2024
1 parent b3c888c commit 8bf420c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
},
"dependencies": {
"@digitalbazaar/credentials-v2-context": "github:digitalbazaar/credentials-v2-context#main",
"@digitalbazaar/data-integrity-context": "^2.0.0",
"@digitalbazaar/http-client": "^4.1.0",
"@digitalbazaar/vc-bitstring-status-list-context": "^1.0.0",
"@digitalbazaar/vc-status-list-context": "^3.0.1",
Expand Down
1 change: 1 addition & 0 deletions src/declarations.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ declare module '@digitalbazaar/vc-bitstring-status-list-context';
declare module '@digitalcredentials/vc-status-list';
declare module '@digitalbazaar/vc-status-list-context';
declare module '@digitalcredentials/vpqr';
declare module '@digitalbazaar/data-integrity-context';
declare module '@digitalcredentials/ed25519-verification-key-2020';
declare module '@digitalcredentials/ed25519-signature-2020';
declare module '@digitalcredentials/http-client';
Expand Down
36 changes: 22 additions & 14 deletions src/documentLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,21 @@ import * as didKey from '@digitalcredentials/did-method-key';
import * as didWeb from '@interop/did-web-resolver';
import * as vc1Context from 'credentials-context';
import * as vc2Context from '@digitalbazaar/credentials-v2-context';
import * as vcBitstringStatusListCtx from '@digitalbazaar/vc-bitstring-status-list-context';
import vcStatusListCtx from '@digitalbazaar/vc-status-list-context';
import * as vcBitstringStatusListContext from '@digitalbazaar/vc-bitstring-status-list-context';
import vcStatusListContext from '@digitalbazaar/vc-status-list-context';
import dataIntegrityContext from '@digitalbazaar/data-integrity-context';
import { Ed25519VerificationKey2020 }
from '@digitalcredentials/ed25519-verification-key-2020';
import { X25519KeyAgreementKey2020 }
from '@digitalcredentials/x25519-key-agreement-key-2020';
import { CachedResolver } from '@digitalcredentials/did-io';
import dccCtx from '@digitalcredentials/dcc-context';
import dccContext from '@digitalcredentials/dcc-context';
import didContext from 'did-context';
import ed25519 from 'ed25519-signature-2020-context';
import x25519 from 'x25519-key-agreement-2020-context';
import { JsonLdDocumentLoader } from 'jsonld-document-loader';
import { CryptoLD } from '@digitalcredentials/crypto-ld';
import obCtx from '@digitalcredentials/open-badges-context';
import obContext from '@digitalcredentials/open-badges-context';
import { httpClient } from '@digitalbazaar/http-client';
import { parseResponseBody } from './parseResponse';

Expand Down Expand Up @@ -82,44 +83,51 @@ interface SecurityLoaderParams {
export function securityLoader({ fetchRemoteContexts = false, useOBv3BetaContext = false }: SecurityLoaderParams = {}): IJsonLdDocumentLoader {
const loader: IJsonLdDocumentLoader = new JsonLdDocumentLoader();

// Ed25519 Signature 2020 Context
loader.addStatic(
ed25519.constants.CONTEXT_URL,
ed25519.contexts.get(ed25519.constants.CONTEXT_URL),
);

// X25519 Key Agreement 2020 Context
loader.addStatic(
x25519.constants.CONTEXT_URL,
x25519.contexts.get(x25519.constants.CONTEXT_URL),
);

// DID Context
loader.addStatic(
didContext.constants.DID_CONTEXT_URL,
didContext.contexts.get(didContext.constants.DID_CONTEXT_URL),
);

// Verifiable Credentials Data Model 1.0
// Verifiable Credentials Data Model 1.0 Context
loader.addStatic(vc1Context.CONTEXT_URL, vc1Context.CONTEXT);

// Verifiable Credentials Data Model 2.0 - BETA / non-final
// Verifiable Credentials Data Model 2.0 Context - BETA / non-final
loader.addStatic(vc2Context.CONTEXT_URL, vc2Context.CONTEXT);

loader.addStatic(dccCtx.CONTEXT_URL_V1, dccCtx.CONTEXT_V1);
// Data Integrity Context
loader.addStatic(dataIntegrityContext.CONTEXT_URL, dataIntegrityContext.CONTEXT);

// Bitstring Status List
loader.addStatic(vcBitstringStatusListCtx.CONTEXT_URL, vcBitstringStatusListCtx.CONTEXT);
// DCC Context
loader.addStatic(dccContext.CONTEXT_URL_V1, dccContext.CONTEXT_V1);

// Status List 2021 (DEPRECATED)
loader.addStatic(vcStatusListCtx.CONTEXT_URL_V1, vcStatusListCtx.CONTEXT_V1);
// Bitstring Status List Context
loader.addStatic(vcBitstringStatusListContext.CONTEXT_URL, vcBitstringStatusListContext.CONTEXT);

// Status List 2021 Context (DEPRECATED)
loader.addStatic(vcStatusListContext.CONTEXT_URL_V1, vcStatusListContext.CONTEXT_V1);

// Open Badges v3 Contexts, includes OBv3 Beta, 3.0, 3.0.1, 3.0.2, etc.
for (const [url, contextBody] of obCtx.contexts) {
for (const [url, contextBody] of obContext.contexts) {
loader.addStatic(url, contextBody)
}

if (useOBv3BetaContext) {
// Workaround to validate legacy OBv3 BETA context VCs
loader.addStatic(obCtx.CONTEXT_URL_V3_0_0,
obCtx.contexts.get(obCtx.CONTEXT_URL_V3_BETA))
loader.addStatic(obContext.CONTEXT_URL_V3_0_0,
obContext.contexts.get(obContext.CONTEXT_URL_V3_BETA))
}

loader.setDidResolver(resolver);
Expand Down

0 comments on commit 8bf420c

Please sign in to comment.