Skip to content
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

adds VC 2.0 context to document loader #12

Merged
merged 7 commits into from
Aug 4, 2024
Merged
Show file tree
Hide file tree
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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# security-document-loader Changelog

## 6.0.0 -
### Added
- Add support for VC DM 2.0 context

### Changed
- **BREAKING**: Switch to `@digitalcredentials/http-client` fork.

## 5.0.0 - 2024-02-10
### Changed
- **BREAKING**: For the HTTP protocol handler (for fetching un-cached documents
Expand Down
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,19 @@
"./package.json": "./package.json"
},
"dependencies": {
"@digitalbazaar/http-client": "^4.1.0",
"@digitalbazaar/data-integrity-context": "^2.0.0",
"@digitalbazaar/vc-bitstring-status-list-context": "^1.0.0",
"@digitalbazaar/vc-status-list-context": "^3.0.1",
"@digitalcredentials/credentials-v2-context": "~0.0.1-beta.0",
"@digitalcredentials/crypto-ld": "^7.0.2",
"@digitalcredentials/dcc-context": "^1.0.0",
"@digitalcredentials/did-io": "^1.0.2",
"@digitalcredentials/did-method-key": "^2.0.3",
"@digitalcredentials/ed25519-verification-key-2020": "^3.2.2",
"@digitalcredentials/http-client": "^5.0.1",
"@digitalcredentials/open-badges-context": "^2.1.0",
"@digitalcredentials/x25519-key-agreement-key-2020": "^3.0.0",
"@interop/did-web-resolver": "^4.0.0",
"@interop/did-web-resolver": "^5.0.0",
"credentials-context": "^2.0.0",
"did-context": "^3.1.1",
"ed25519-signature-2020-context": "^1.1.0",
Expand Down
6 changes: 4 additions & 2 deletions src/declarations.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ declare module '@digitalcredentials/dcc-context';
declare module '@digitalcredentials/did-io';
declare module '@digitalcredentials/did-method-key';
declare module '@digitalcredentials/vc';
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 All @@ -18,5 +20,5 @@ declare module 'x25519-key-agreement-2020-context';
declare module 'json-canonicalize';
declare module 'react-native-keychain';
declare module '@digitalcredentials/open-badges-context';
declare module '@digitalbazaar/credentials-v2-context';
declare module '@digitalbazaar/http-client';
declare module '@digitalcredentials/credentials-v2-context';
declare module '@digitalcredentials/http-client';
71 changes: 39 additions & 32 deletions src/documentLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,32 @@
* Copyright (c) 2021 Interop Alliance and Dmitri Zagidulin. All rights reserved.
*/
import * as didKey from '@digitalcredentials/did-method-key';
import * as didWeb from '@interop/did-web-resolver';
import * as vc2Context from '@digitalcredentials/credentials-v2-context';
import * as vcBitstringStatusListContext from '@digitalbazaar/vc-bitstring-status-list-context';
import vc1Context from 'credentials-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 cred from 'credentials-context';
import vcStatusListCtx from '@digitalbazaar/vc-status-list-context';
import ed25519Context from 'ed25519-signature-2020-context';
import x25519Context from 'x25519-key-agreement-2020-context';
import { JsonLdDocumentLoader } from 'jsonld-document-loader';
import { CryptoLD } from '@digitalcredentials/crypto-ld';
import * as didWeb from '@interop/did-web-resolver';
import obContext from '@digitalcredentials/open-badges-context';
import { httpClient } from '@digitalcredentials/http-client';
import { parseResponseBody } from './parseResponse';
import obCtx from '@digitalcredentials/open-badges-context';
import { httpClient } from '@digitalbazaar/http-client';
// import vc2Context from '@digitalbazaar/credentials-v2-context';

const cryptoLd = new CryptoLD();
cryptoLd.use(Ed25519VerificationKey2020);
cryptoLd.use(X25519KeyAgreementKey2020);
const didWebDriver = didWeb.driver({ cryptoLd });

const {
contexts: credentialsContext,
constants: {
CREDENTIALS_CONTEXT_V1_URL,
},
} = cred;
const didKeyDriver = didKey.driver();
const resolver = new CachedResolver();
resolver.use(didKeyDriver);
Expand Down Expand Up @@ -87,42 +83,53 @@ 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),
ed25519Context.constants.CONTEXT_URL,
ed25519Context.contexts.get(ed25519Context.constants.CONTEXT_URL),
);

// X25519 Key Agreement 2020 Context
loader.addStatic(
x25519.constants.CONTEXT_URL,
x25519.contexts.get(x25519.constants.CONTEXT_URL),
x25519Context.constants.CONTEXT_URL,
x25519Context.contexts.get(x25519Context.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
loader.addStatic(
CREDENTIALS_CONTEXT_V1_URL,
credentialsContext.get(CREDENTIALS_CONTEXT_V1_URL),
);
// Verifiable Credentials Data Model 2.0 - BETA / non-final
// loader.addStatic(vc2Context.CONTEXT_URL, vc2Context.CONTEXT);
// Verifiable Credentials Data Model 1.0 Context
loader.addStatic(vc1Context.CONTEXT_URL, vc1Context.CONTEXT);

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

// Data Integrity Context
for (const [url, context] of dataIntegrityContext.contexts) {
loader.addStatic(url, context)
}

// DCC Context
loader.addStatic(dccContext.CONTEXT_URL_V1, dccContext.CONTEXT_V1);

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

loader.addStatic(vcStatusListCtx.CONTEXT_URL_V1, vcStatusListCtx.CONTEXT_V1);
// 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) {
loader.addStatic(url, contextBody)
for (const [url, context] of obContext.contexts) {
loader.addStatic(url, context)
}

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
Loading