From 8bf420c2840e1c67d8b374bd1308550e01790fc5 Mon Sep 17 00:00:00 2001 From: Kayode Ezike Date: Sat, 9 Mar 2024 18:15:46 -0500 Subject: [PATCH] adds data integrity context --- package.json | 1 + src/declarations.d.ts | 1 + src/documentLoader.ts | 36 ++++++++++++++++++++++-------------- 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/package.json b/package.json index 2d7214a..09de6c5 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/declarations.d.ts b/src/declarations.d.ts index 5891de2..0dfc00c 100644 --- a/src/declarations.d.ts +++ b/src/declarations.d.ts @@ -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'; diff --git a/src/documentLoader.ts b/src/documentLoader.ts index 298049a..3d8b437 100644 --- a/src/documentLoader.ts +++ b/src/documentLoader.ts @@ -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'; @@ -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);