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

Add support for optionally loading OBv3 BETA context. #7

Merged
merged 2 commits into from
Jul 16, 2023
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
Included functionality:

* Bundled contexts:
- DID, VC 1.0 and 2.0-BETA, DCC, Open Badges v3, ed25519 and x25519 crypto suite contexts
- DID, VC 1.0, DCC, Open Badges v3, ed25519 and x25519 crypto suite contexts
* DID resolver for `did:key` and `did:web`
* Optional loading of arbitrary contexts from the web (see Usage).

Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
"@digitalcredentials/x25519-key-agreement-key-2020": "^3.0.0",
"@interop/did-web-resolver": "^3.0.0",
"credentials-context": "^2.0.0",
"crypto-ld": "^7.0.0",
"did-context": "^3.1.1",
"ed25519-signature-2020-context": "^1.1.0",
"html-entities": "^2.3.3",
Expand Down
13 changes: 10 additions & 3 deletions src/documentLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { CryptoLD } from '@digitalcredentials/crypto-ld';
import * as didWeb from '@interop/did-web-resolver';
import { parseResponseBody } from './parseResponse';
import obCtx from '@digitalcredentials/open-badges-context';
import vc2Context from '@digitalbazaar/credentials-v2-context';
// import vc2Context from '@digitalbazaar/credentials-v2-context';

const cryptoLd = new CryptoLD();
cryptoLd.use(Ed25519VerificationKey2020);
Expand Down Expand Up @@ -80,9 +80,10 @@ declare class IJsonLdDocumentLoader {

interface SecurityLoaderParams {
fetchRemoteContexts?: boolean;
useOBv3BetaContext?: boolean;
}

export function securityLoader({ fetchRemoteContexts = false }: SecurityLoaderParams = {}): IJsonLdDocumentLoader {
export function securityLoader({ fetchRemoteContexts = false, useOBv3BetaContext = false }: SecurityLoaderParams = {}): IJsonLdDocumentLoader {
const loader: IJsonLdDocumentLoader = new JsonLdDocumentLoader();

loader.addStatic(
Expand All @@ -106,7 +107,7 @@ export function securityLoader({ fetchRemoteContexts = false }: SecurityLoaderPa
credentialsContext.get(CREDENTIALS_CONTEXT_V1_URL),
);
// Verifiable Credentials Data Model 2.0 - BETA / non-final
loader.addStatic(vc2Context.CONTEXT_URL, vc2Context.CONTEXT);
// loader.addStatic(vc2Context.CONTEXT_URL, vc2Context.CONTEXT);

loader.addStatic(dccCtx.CONTEXT_URL_V1, dccCtx.CONTEXT_V1);

Expand All @@ -117,6 +118,12 @@ export function securityLoader({ fetchRemoteContexts = false }: SecurityLoaderPa
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.setDidResolver(resolver);

// Enable loading of arbitrary contexts from web
Expand Down
12 changes: 12 additions & 0 deletions test/documentLoader.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,16 @@ describe('documentLoader', () => {
const result = await documentLoader('https://example.com/my-context/v1')
expect(result.document).to.equal(contextObject)
})

it('supports beta OBv3 context', async () => {
const load = securityLoader().build()
const { document } = await load('https://purl.imsglobal.org/spec/ob/v3p0/context.json')
expect(document['@context'].OpenBadgeCredential['@id'])
.to.equal('https://purl.imsglobal.org/spec/vc/ob/vocab.html#OpenBadgeCredential')

const legacyLoad = securityLoader({useOBv3BetaContext: true}).build()
const { document: legacyDocument } = await legacyLoad('https://purl.imsglobal.org/spec/ob/v3p0/context.json')
expect(legacyDocument['@context'].OpenBadgeCredential['@id'])
.to.equal('https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential')
})
})