diff --git a/.eslintrc.js b/.eslintrc.js index 74ac416..fab9b28 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -11,6 +11,7 @@ module.exports = { 'prettier/prettier': 'off', 'arrow-body-style': 'off', 'prefer-arrow-callback': 'off', - '@typescript-eslint/return-await': 'off' + '@typescript-eslint/return-await': 'off', + '@typescript-eslint/restrict-template-expressions': 'off' } } diff --git a/package.json b/package.json index 174eefd..76008fc 100644 --- a/package.json +++ b/package.json @@ -31,6 +31,7 @@ "./package.json": "./package.json" }, "dependencies": { + "@digitalbazaar/http-client": "^4.1.0", "@digitalbazaar/vc-status-list-context": "^3.0.1", "@digitalcredentials/crypto-ld": "^7.0.2", "@digitalcredentials/dcc-context": "^1.0.0", diff --git a/src/declarations.d.ts b/src/declarations.d.ts index e6e72ad..a7cd5ca 100644 --- a/src/declarations.d.ts +++ b/src/declarations.d.ts @@ -19,3 +19,4 @@ 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'; diff --git a/src/documentLoader.ts b/src/documentLoader.ts index 2f13c39..22e73a5 100644 --- a/src/documentLoader.ts +++ b/src/documentLoader.ts @@ -18,6 +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 { httpClient } from '@digitalbazaar/http-client'; // import vc2Context from '@digitalbazaar/credentials-v2-context'; const cryptoLd = new CryptoLD(); @@ -53,9 +54,9 @@ export const httpClientHandler = { 'Cache-Control': 'no-cache', 'Pragma': 'no-cache' }; - result = await fetch(params.url, { headers }); - } catch(e) { - throw new Error('NotFoundError'); + result = await httpClient.get(params.url, { headers }); + } catch(e: any) { + throw new Error(`NotFoundError loading "${params.url}": ${e.message}`); } return parseResponseBody(result); diff --git a/test/documentLoader.spec.ts b/test/documentLoader.spec.ts index 06d1e78..90436d7 100644 --- a/test/documentLoader.spec.ts +++ b/test/documentLoader.spec.ts @@ -15,6 +15,15 @@ describe('documentLoader', () => { expect(result.document).to.equal(contextObject) }) + it('should load a status VC from web', async () => { + const documentLoader = securityLoader({fetchRemoteContexts: true}).build(); + + const url = 'https://digitalcredentials.github.io/credential-status-playground/JWZM3H8WKU'; + const result = await documentLoader(url); + expect(result.document.issuer).to + .equal('did:key:z6MkhVTX9BF3NGYX6cc7jWpbNnR7cAjH8LUffabZP8Qu4ysC'); + }); + it('supports beta OBv3 context', async () => { const load = securityLoader().build() const { document } = await load('https://purl.imsglobal.org/spec/ob/v3p0/context.json')