diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index be9fde5..910f940 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -25,6 +25,10 @@ jobs: run: npm install --legacy-peer-deps - name: Clean VDLs run: rm -f ./credentials/*.json + - name: Generate VDLs + env: + KEY_SEED_DB: ${{ secrets.KEY_SEED_DB }} + run: npm run generate-vdls - name: Run test with Node.js ${{ matrix.node-version }} env: KEY_SEED_DB: ${{ secrets.KEY_SEED_DB }} diff --git a/bbs/package.json b/bbs/package.json index 8728bba..a34c9a9 100644 --- a/bbs/package.json +++ b/bbs/package.json @@ -3,6 +3,7 @@ "version": "1.0.0", "description": "", "main": "index.js", + "type": "module", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", "build": "webpack", @@ -11,10 +12,12 @@ "author": "", "license": "ISC", "dependencies": { - "@mattrglobal/bbs-signatures": "^0.6.0", - "@mattrglobal/bls12381-key-pair": "^0.7.0", - "@mattrglobal/jsonld-signatures-bbs": "^0.11.0", - "@mattrglobal/node-bbs-signatures": "^0.12.0", - "jsonld-signatures": "^5.0.0" + "@mattrglobal/bbs-signatures": "^1.1.0", + "@mattrglobal/bls12381-key-pair": "^1.0.0", + "@mattrglobal/jsonld-signatures-bbs": "^1.1.0", + "@mattrglobal/node-bbs-signatures": "^0.15.0", + "install": "^0.13.0", + "jsonld-signatures": "^5.0.0", + "npm": "^9.1.1" } } diff --git a/bbs/src/index.js b/bbs/src/index.js index 728b2cd..4d469de 100644 --- a/bbs/src/index.js +++ b/bbs/src/index.js @@ -17,14 +17,14 @@ import { BbsBlsSignatureProof2020, deriveProof } from '@mattrglobal/jsonld-signatures-bbs'; -import {extendContextLoader, sign, verify, purposes} from 'jsonld-signatures'; +import jsigs from 'jsonld-signatures'; -import _keyPairOptions from './data/keyPair.json'; -import _disclosures from './data/deriveProofFrame.json'; -import exampleControllerDoc from './data/controllerDocument.json'; -import bbsContext from './data/bbs.json'; -import credentialContext from './data/credentialsContext.json'; -import jwsContext from './data/jwsContext.json'; +import _keyPairOptions from './data/keyPair.json' assert {type: 'json'}; +import _disclosures from './data/deriveProofFrame.json' assert {type: 'json'}; +import exampleControllerDoc from './data/controllerDocument.json' assert {type: 'json'}; +import bbsContext from './data/bbs.json' assert {type: 'json'}; +import credentialContext from './data/credentialsContext.json' assert {type: 'json'}; +import jwsContext from './data/jwsContext.json' assert {type: 'json'}; import {CONTEXT_URL as vdlContextUri, CONTEXT} from 'vdl-context'; const documents = { @@ -56,7 +56,7 @@ const customDocLoader = url => { }; //Extended document load that uses local contexts -const _documentLoader = extendContextLoader(customDocLoader); +const _documentLoader = jsigs.extendContextLoader(customDocLoader); /** * Creates a BBS+ report for a VC. @@ -81,16 +81,16 @@ export const createBBSreport = async ({ const keyPair = await new Bls12381G2KeyPair(keyPairOptions); //Sign the input document - const signedDocument = await sign(inputDocument, { + const signedDocument = await jsigs.sign(inputDocument, { suite: new BbsBlsSignature2020({key: keyPair}), - purpose: new purposes.AssertionProofPurpose(), + purpose: new jsigs.purposes.AssertionProofPurpose(), documentLoader }); //Verify the proof - let verified = await verify(signedDocument, { + let verified = await jsigs.verify(signedDocument, { suite: new BbsBlsSignature2020(), - purpose: new purposes.AssertionProofPurpose(), + purpose: new jsigs.purposes.AssertionProofPurpose(), documentLoader }); //Derive a proof @@ -100,9 +100,9 @@ export const createBBSreport = async ({ }); //Verify the derived proof - verified = await verify(derivedProof, { + verified = await jsigs.verify(derivedProof, { suite: new BbsBlsSignatureProof2020(), - purpose: new purposes.AssertionProofPurpose(), + purpose: new jsigs.purposes.AssertionProofPurpose(), documentLoader }); return { diff --git a/credentials.js b/credentials.cjs similarity index 100% rename from credentials.js rename to credentials.cjs diff --git a/files.js b/files.js index 503ed95..80a215c 100644 --- a/files.js +++ b/files.js @@ -3,11 +3,16 @@ */ 'use strict'; -const {join} = require('path'); -const {createReadStream, writeFile, readdir, readFile} = require('fs'); -const {finished} = require('stream'); -const {promisify} = require('util'); -const csv = require('csv-parse'); +import { + createReadStream, + readdir, + readFile, + writeFile +} from 'fs'; +import csv from 'csv-parse'; +import {finished} from 'stream'; +import {join} from 'path'; +import {promisify} from 'util'; const asyncFinished = promisify(finished); const asyncReadDir = promisify(readdir); @@ -23,7 +28,7 @@ const asyncReadFile = promisify(readFile); * * @returns {Promise>} Dir and file names. */ -async function getDir(path) { +export async function getDir(path) { const directory = await asyncReadDir(path); if(directory.length <= 0) { throw new Error(`Dir ${path} is empty`); @@ -38,14 +43,14 @@ async function getDir(path) { * * @returns {Promise>} Gets files as strings. */ -async function getDirFiles(path) { +export async function getDirFiles(path) { const dir = await getDir(path); const files = await Promise.all(dir.map( fileName => asyncReadFile(join(path, fileName), 'utf8'))); return files; } -async function getJSONFiles(path) { +export async function getJSONFiles(path) { const strings = await getDirFiles(path); return strings.map(JSON.parse); } @@ -59,7 +64,7 @@ async function getJSONFiles(path) { * * @returns {Promise>>} Each row is an array of strings. */ -async function getCSV({path, parser = new csv.Parser()}) { +export async function getCSV({path, parser = new csv.Parser()}) { const records = []; const fileStream = createReadStream(path).pipe(parser); fileStream.on('readable', function() { @@ -82,15 +87,6 @@ async function getCSV({path, parser = new csv.Parser()}) { * * @returns {Promise} Resolves on write. */ -async function writeJSON({path, data}) { +export async function writeJSON({path, data}) { return asyncWriteFile(path, JSON.stringify(data, null, 2)); } - -module.exports = { - getCSV, - getDir, - getDirFiles, - getJSONFiles, - writeJSON -}; - diff --git a/generate-vdls.js b/generate-vdls.js index 55cfd23..743d1be 100644 --- a/generate-vdls.js +++ b/generate-vdls.js @@ -3,12 +3,14 @@ */ 'use strict'; -const {join} = require('path'); -const {writeJSON} = require('./files'); -const {paths} = require('./paths'); -const {CONTEXT_URL} = require('vdl-context'); -const stateList = require('./states'); -const didKeyDriver = require('@digitalbazaar/did-method-key').driver(); +import {CONTEXT_URL} from 'vdl-context'; +import {driver} from '@digitalbazaar/did-method-key'; +import {join} from 'path'; +import {paths} from './paths.js'; +import stateList from './states.json' assert {type: 'json'}; +import {writeJSON} from './files.js'; + +const didKeyDriver = driver(); async function createVC(state) { const contexts = [ diff --git a/implementations.js b/implementations.js deleted file mode 100644 index 0c70a48..0000000 --- a/implementations.js +++ /dev/null @@ -1,10 +0,0 @@ -/*! - * Copyright (c) 2021 Digital Bazaar, Inc. All rights reserved. - */ -'use strict'; - -const requireDir = require('require-dir'); - -const dir = requireDir('./implementations'); - -module.exports = Object.values(dir); diff --git a/implementations/DigitalBazaar.json b/implementations/DigitalBazaar.json deleted file mode 100644 index 32d286e..0000000 --- a/implementations/DigitalBazaar.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "name": "Digital Bazaar", - "implementation": "Demo", - "issuer": { - "id": "did:key:z6MkiRtEtiyPSisyTo35SrF4p8rTxjV8Pu528tX2kXfEF5bN", - "endpoint": "https://issuer.demo.digitalbazaar.com/vc-issuer/issue", - "headers": { - "authorization": "Bearer OWYxNzUwYWUtODljNi00ZWZlLThhNDgtNGQ3ZTBmZDViNWIw" - } - }, - "verifier": "https://verifier.demo.digitalbazaar.com/verifier/credentials" -} diff --git a/implementations/Mattr.json b/implementations/Mattr.json deleted file mode 100644 index 61060b8..0000000 --- a/implementations/Mattr.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "name": "MATTR", - "implementation": "MATTR", - "issuer": { - "id": "did:key:z6MkftZWDTkv62SbkKHzPTKSMs8wYAZrysdxagXAMkP7P2Xg", - "endpoint": "https://platform.interop.mattrlabs.io/vc-http-api/v1/credentials" - }, - "verifier": "https://platform.interop.mattrlabs.io/vc-http-api/v1/credentials/verify" -} diff --git a/implementations/Spruce.json b/implementations/Spruce.json deleted file mode 100644 index 879ae8d..0000000 --- a/implementations/Spruce.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "name": "Spruce", - "implementation": "Spruce", - "issuer": { - "id": "did:key:z6MkhL2wNXYZ8pSf4ctHPotrpkWggeb6ipCWYaPfDhaQ1NLM", - "endpoint": "https://demo.spruceid.com/credentials/issue" - }, - "verifier": "https://demo.spruceid.com/credentials/verify" -} diff --git a/matrix.hbs b/matrix.hbs index c05ab9a..4b63f7f 100644 --- a/matrix.hbs +++ b/matrix.hbs @@ -28,6 +28,26 @@ .small-font { font-size: 0.75rem; } + .highlight-on-hover:hover { + background-color: yellow; + cursor: default; + } + .highlight-on-hover:hover + .relative-pos > .err { + display: block; + } + pre, code.hljs { + overflow: auto; + } + .relative-pos { + position: relative; + width: 0.5rem; + height: 0.5rem; + z-index: 1; + } + .relative-pos:hover > .err { + display: block; + } + pre, code.hljs{ overflow: auto; } @@ -54,7 +74,10 @@ {{id}} {{#each cells}} - {{getStatusMark state}} + +
{{getStatusMark state}}
+ {{> error.hbs error=err}} + {{/each}} {{/each}} diff --git a/package.json b/package.json index 4bcec6a..db5fdbb 100644 --- a/package.json +++ b/package.json @@ -3,9 +3,9 @@ "version": "0.0.1", "description": "Test suite to demonstrate interoperability between various VC issuers & verifiers.", "main": "index.js", + "type": "module", "scripts": { - "parallel": "npm run generate-vdls && mocha tests/ --require esm --reporter @digitalbazaar/mocha-w3c-interop-reporter --reporter-options body=\"$PWD/body.hbs\",matrix=\"$PWD/matrix.hbs\",reportDir=\"$PWD/reports\",respec=\"$PWD/respecConfig.json\",title=\"Verifiable Driver's License Interoperability Report 1.0\",helpers=\"$PWD/templateHelpers.js\",suiteLog='./suite.log' --parallel --timeout 15000", - "test": "npm run generate-vdls && mocha tests/ --require esm --reporter @digitalbazaar/mocha-w3c-interop-reporter --reporter-options body=\"$PWD/body.hbs\",matrix=\"$PWD/matrix.hbs\",reportDir=\"$PWD/reports\",respec=\"$PWD/respecConfig.json\",title=\"Verifiable Driver's License Interoperability Report 1.0\",helpers=\"$PWD/templateHelpers.js\",suiteLog='./suite.log' --timeout 15000", + "test": "mocha tests/ --reporter @digitalbazaar/mocha-w3c-interop-reporter --reporter-options body=\"$PWD/body.hbs\",matrix=\"$PWD/matrix.hbs\",reportDir=\"$PWD/reports\",respec=\"$PWD/respecConfig.json\",title=\"Verifiable Driver's License Interoperability Report 1.0\",helpers=\"$PWD/templateHelpers.cjs\",suiteLog='./suite.log' --timeout 15000", "generate-vdls": "node generate-vdls.js", "lint": "eslint *.js", "postinstall": "cd bbs && npm i" @@ -30,28 +30,29 @@ }, "homepage": "https://github.com/w3c-ccg/vdl-test-suite#readme", "dependencies": { - "@digitalbazaar/did-method-key": "^1.0.0", - "@digitalbazaar/ed25519-signature-2020": "^2.1.0", - "@digitalbazaar/ed25519-verification-key-2020": "^2.1.1", - "@digitalbazaar/http-client": "^1.0.0", - "@digitalbazaar/mocha-w3c-interop-reporter": "^1.0.0", + "@digitalbazaar/did-method-key": "^3.0.0", + "@digitalbazaar/ed25519-signature-2020": "^5.0.0", + "@digitalbazaar/ed25519-verification-key-2020": "^4.1.0", + "@digitalbazaar/http-client": "^3.2.0", + "@digitalbazaar/mocha-w3c-interop-reporter": "^1.3.0", "@digitalbazaar/security-context": "^1.0.0", - "@digitalbazaar/vc": "^1.0.0", - "@digitalbazaar/vpqr": "^2.1.0", + "@digitalbazaar/vc": "^5.0.0", + "@digitalbazaar/vpqr": "^3.0.0", "axios": "^0.21.1", "chai": "^4.3.4", "cit-context": "^2.0.0", - "credentials-context": "^1.0.0", + "credentials-context": "^2.0.0", "csv-parse": "^4.15.3", "did-context": "^3.0.1", "ed25519-signature-2020-context": "^1.0.1", - "esm": "^3.2.25", "file-size": "^1.0.0", "jsonld-document-loader": "^1.1.0", + "klona": "^2.0.5", "mocha": "^8.3.2", "node-cbor": "^5.0.4", "require-dir": "^1.2.0", "uuid": "^8.3.2", + "vc-api-test-suite-implementations": "github:w3c-ccg/vc-api-test-suite-implementations", "vc-revocation-list-context": "^1.0.0", "vdl-context": "github:digitalbazaar/vdl-context", "x25519-key-agreement-2020-context": "^1.0.0" @@ -60,8 +61,8 @@ "node": ">=14.0.0" }, "devDependencies": { - "eslint": "^7.23.0", - "eslint-config-digitalbazaar": "^2.6.1", - "eslint-plugin-jsdoc": "^32.3.0" + "eslint": "^8.27.0", + "eslint-config-digitalbazaar": "^4.1.0", + "eslint-plugin-jsdoc": "^39.6.2" } } diff --git a/paths.js b/paths.js index 7b4d505..2412d8b 100644 --- a/paths.js +++ b/paths.js @@ -3,13 +3,9 @@ */ 'use strict'; -const {join} = require('path'); +import {join} from 'path'; -const paths = { +export const paths = { credentials: join(process.cwd(), 'credentials'), implementations: join(process.cwd(), 'implementations') }; - -module.exports = { - paths -}; diff --git a/templateHelpers.js b/templateHelpers.cjs similarity index 79% rename from templateHelpers.js rename to templateHelpers.cjs index ec4d305..a1bc46b 100644 --- a/templateHelpers.js +++ b/templateHelpers.cjs @@ -1,4 +1,4 @@ -const states = require('./states'); +const states = require('./states.json'); const api = { getState(abbreviation) { @@ -6,4 +6,6 @@ const api = { return name || 'Unknown'; } }; + module.exports = api; + diff --git a/tests/10-interop.js b/tests/10-interop.js index 04eaae2..5040f26 100644 --- a/tests/10-interop.js +++ b/tests/10-interop.js @@ -1,46 +1,44 @@ /*! - * Copyright (c) 2021 Digital Bazaar, Inc. All rights reserved. + * Copyright (c) 2021-2022 Digital Bazaar, Inc. All rights reserved. */ -'use strict'; -const vpqr = require('@digitalbazaar/vpqr'); -const chai = require('chai'); -const filesize = require('file-size'); -const Implementation = require('./implementation.cjs'); -const {testCredential} = require('./assertions'); -const certificates = require('../credentials'); -const allVendors = require('../implementations'); -const {documentLoader} = require('./loader.js'); -const {createCompressedVC, deepClone} = require('./helpers'); -const {createBBSreport} = require('../bbs/src'); +import * as vpqr from '@digitalbazaar/vpqr'; +import { + createCompressedVC, + createIssuerBody, + createVerifierBody +} from './helpers.js'; +import certificates from '../credentials.cjs'; +import chai from 'chai'; +import {createBBSreport} from '../bbs/src/index.js'; +import {documentLoader} from './loader.js'; +import filesize from 'file-size'; +import {filterImplementations} from 'vc-api-test-suite-implementations'; +import {klona} from 'klona'; +import {testCredential} from './assertions.js'; const should = chai.should(); - -// test these implementations' issuers or verifiers -const test = [ - 'Digital Bazaar', - 'MATTR', - 'Spruce' -]; +const tag = 'vdl-test'; // only test listed implementations -const implementations = allVendors.filter(v => test.includes(v.name)); - +const {match: implementations} = filterImplementations({ + filter: ({value}) => + value.issuers.some(issuer => issuer.tags.has(tag) && + value.verifiers.some(verifier => verifier.tags.has(tag))) +}); describe('Verifiable Driver\'s License Credentials', function() { const summaries = new Set(); this.summary = summaries; for(const certificate of certificates) { const {credentialSubject: {license}} = certificate; describe(license.issuing_authority, function() { - // column names for the matrix go here - const columnNames = []; const reportData = []; const images = []; // this will tell the report // to make an interop matrix with this suite this.matrix = true; this.report = true; - this.implemented = columnNames; + this.implemented = [...implementations.keys()]; this.rowLabel = 'Issuer'; this.columnLabel = 'Verifier'; // this will be displayed under the test title @@ -53,7 +51,7 @@ describe('Verifiable Driver\'s License Credentials', function() { {certificate, documentLoader}); const [_vc] = compressedVP.verifiableCredential; // format VC so context is first in examples - let vc = deepClone(_vc); + let vc = klona(_vc); vc = {'@context': _vc['@context'], ..._vc}; // remove driving privleges to avoid a CBOR-LD error delete vc.credentialSubject.license.driving_privileges; @@ -107,25 +105,28 @@ describe('Verifiable Driver\'s License Credentials', function() { data: JSON.stringify(verified, null, 2) }); }); - for(const issuer of implementations) { + for(const [name, implementation] of implementations) { // this is the credential for the verifier tests let credential = null; //FIXME issuerResponse should be used to check status 201 //let issuerResponse = null; let error = null; - describe(issuer.name, function() { + const issuer = implementation.issuers.find(i => i.tags.has(tag)); + describe(name, function() { before(async function() { try { - // ensure this implementation is a column in the matrix - columnNames.push(issuer.name); - const implementation = new Implementation(issuer); - const response = await implementation.issue( - {credential: certificate}); + const json = createIssuerBody({issuer, vc: certificate}); + const {error, data} = await issuer.post({ + json + }); + if(error) { + throw error; + } //FIXME issuerResponse should be used to check status 201 //issuerResponse = response; // this credential is not tested // we just send it to each verifier - credential = response.data; + credential = data; // if the response.data is not directly jsonld unwrap it if(!credential['@context']) { for(const key of Object.keys(credential)) { @@ -146,14 +147,13 @@ describe('Verifiable Driver\'s License Credentials', function() { }); // this ensures the implementation issuer // issues correctly - it(`should be issued by ${issuer.name}`, async function() { + it(`should be issued by ${name}`, async function() { should.exist( credential, `Expected VC from ${issuer.name} to exist.`); should.not.exist(error, `Expected ${issuer.name} to not error.`); // FIXME issuer should return 201 //issuerResponse.status.should.equal(201); - testCredential(credential); credential.credentialSubject.should.eql( certificate.credentialSubject); @@ -192,15 +192,18 @@ describe('Verifiable Driver\'s License Credentials', function() { }); // this sends a credential issued by the implementation // to each verifier - for(const verifier of implementations) { - const testTitle = `should be verified by ${verifier.name}`; + for(const [name, implementation] of implementations) { + const verifier = implementation.verifiers.find( + v => v.tags.has(tag)); + const testTitle = `should be verified by ${name}`; it(testTitle, async function() { // this tells the test report which cell // in the interop matrix the result goes in - this.test.cell = {columnId: verifier.name, rowId: issuer.name}; + this.test.cell = {columnId: name, rowId: issuer.name}; should.exist(credential); - const implementation = new Implementation(verifier); - const response = await implementation.verify({credential}); + const {result: response} = await verifier.post({ + json: createVerifierBody({vc: credential}) + }); should.exist(response); // verifier returns 200 response.status.should.equal(200); diff --git a/tests/assertions.js b/tests/assertions.js index 2caa3ed..2c5a401 100644 --- a/tests/assertions.js +++ b/tests/assertions.js @@ -1,11 +1,9 @@ /*! - * Copyright (c) 2021 Digital Bazaar, Inc. All rights reserved. + * Copyright (c) 2021-2022 Digital Bazaar, Inc. All rights reserved. */ 'use strict'; -const chai = require('chai'); -const {CONTEXT_URL: testContextUri} = require('vdl-context'); - +import chai from 'chai'; const should = chai.should(); /** @@ -22,7 +20,6 @@ export const testCredential = credential => { // NOTE: some issuers add a revocation list context to the types credential['@context'].should.include( 'https://www.w3.org/2018/credentials/v1'); - credential['@context'].should.include(testContextUri); credential.should.have.property('type'); credential.type.should.eql([ 'VerifiableCredential', diff --git a/tests/helpers.js b/tests/helpers.js index 616e88b..ec7a738 100644 --- a/tests/helpers.js +++ b/tests/helpers.js @@ -1,7 +1,38 @@ -const vc = require('@digitalbazaar/vc'); -const {Ed25519Signature2020} = require('@digitalbazaar/ed25519-signature-2020'); +/*! + * Copyright (c) 2021-2022 Digital Bazaar, Inc. All rights reserved. + */ +'use strict'; -const didKeyDriver = require('@digitalbazaar/did-method-key').driver(); +import * as vc from '@digitalbazaar/vc'; +import {driver} from '@digitalbazaar/did-method-key'; +import {Ed25519Signature2020} from '@digitalbazaar/ed25519-signature-2020'; +import {klona} from 'klona'; +import {v4 as uuidv4} from 'uuid'; + +const didKeyDriver = driver(); + +export function createIssuerBody({issuer, vc}) { + const _vc = klona(vc); + const {settings: {id, options}} = issuer; + _vc.issuer = id; + _vc.id = `urn:uuid:${uuidv4()}`; + _vc.expirationDate = ISOTimeStamp({ + date: new Date(Date.now() + 60 * 60 * 24 * 7 * 52 * 3 * 1000) + }); + return { + credential: _vc, + options + }; +} + +export function createVerifierBody({vc}) { + return { + verifiableCredential: vc, + options: { + checks: ['proof'], + } + }; +} export const createCompressedVC = async ({certificate, documentLoader}) => { const {didDocument, keyPairs} = await didKeyDriver.generate(); @@ -24,8 +55,6 @@ export const createCompressedVC = async ({certificate, documentLoader}) => { // Javascript's default ISO timestamp is contains milliseconds. // This lops off the MS part of the UTC RFC3339 TimeStamp and replaces // it with a terminal Z. -export const ISOTimeStamp = ({date = new Date()} = {}) => { +export function ISOTimeStamp({date = new Date()} = {}) { return date.toISOString().replace(/\.\d+Z$/, 'Z'); -}; - -export const deepClone = data => JSON.parse(JSON.stringify(data, null, 2)); +} diff --git a/tests/implementation.cjs b/tests/implementation.cjs deleted file mode 100644 index 283ef13..0000000 --- a/tests/implementation.cjs +++ /dev/null @@ -1,79 +0,0 @@ -/*! - * Copyright (c) 2021 Digital Bazaar, Inc. All rights reserved. - */ -'use strict'; - -const axios = require('axios'); -const https = require('https'); -const {v4: uuidv4} = require('uuid'); -const httpsAgent = new https.Agent({rejectUnauthorized: false}); -const {ISOTimeStamp} = require('./helpers'); - -const _headers = { - Accept: 'application/ld+json,application/json', - 'Content-Type': 'application/json', -}; - -class Implementation { - constructor(settings) { - this.settings = settings; - } - async issue({credential}) { - try { - const headers = {..._headers, ...this.settings.issuer.headers}; - const expires = () => { - const date = new Date(); - date.setMonth(date.getMonth() + 2); - return ISOTimeStamp({date}); - }; - const body = { - credential: { - ...credential, - id: `urn:uuid:${uuidv4()}`, - issuanceDate: ISOTimeStamp(), - expirationDate: expires(), - issuer: this.settings.issuer.id, - '@context': credential['@context'] - } - }; - const result = await axios.post( - this.settings.issuer.endpoint, - JSON.stringify(body), - {headers, httpsAgent} - ); - return result; - } catch(e) { - // this is just to make debugging easier - //console.error(e); - throw e; - } - } - async verify({credential, auth}) { - try { - const headers = {..._headers}; - if(auth && auth.type === 'oauth2-bearer-token') { - headers.Authorization = `Bearer ${auth.accessToken}`; - } - const body = { - verifiableCredential: credential, - options: { - checks: ['proof'], - }, - }; - const result = await axios.post( - this.settings.verifier, - body, - {headers, httpsAgent} - ); - return result; - } catch(e) { - // this is just to make debugging easier - if(e && e.response && e.response.data) { - throw new Error(JSON.stringify(e.response.data, null, 2)); - } - throw e; - } - } -} - -module.exports = Implementation; diff --git a/tests/loader.js b/tests/loader.js index 4f0ee9e..49a469f 100644 --- a/tests/loader.js +++ b/tests/loader.js @@ -1,22 +1,22 @@ /*! - * Copyright (c) 2021 Digital Bazaar, Inc. All rights reserved. + * Copyright (c) 2021-2022 Digital Bazaar, Inc. All rights reserved. */ -'use strict'; -const didKey = require('@digitalbazaar/did-method-key'); -const citContext = require('cit-context'); -const didContext = require('did-context'); -const revocationContext = require('vc-revocation-list-context'); -const ed25519 = require('ed25519-signature-2020-context'); -const x25519 = require('x25519-key-agreement-2020-context'); -const cred = require('credentials-context'); -const securityContext = require('@digitalbazaar/security-context'); -const {JsonLdDocumentLoader} = require('jsonld-document-loader'); -const {CONTEXT_URL: testContextUri, CONTEXT} = require('vdl-context'); -const _keyPairOptions = require('../bbs/src/data/keyPair.json'); -const exampleControllerDoc = require('../bbs/src/data/controllerDocument.json'); -const bbsContext = require('../bbs/src/data/bbs.json'); -const jwsContext = require('../bbs/src/data/jwsContext.json'); +import {CONTEXT_URL as testContextUri, CONTEXT} from 'vdl-context'; +import citContext from 'cit-context'; +import cred from 'credentials-context'; +import didContext from 'did-context'; +import {driver} from '@digitalbazaar/did-method-key'; +import ed25519 from 'ed25519-signature-2020-context'; +import {JsonLdDocumentLoader} from 'jsonld-document-loader'; +import revocationContext from 'vc-revocation-list-context'; +import securityContext from '@digitalbazaar/security-context'; +import x25519 from 'x25519-key-agreement-2020-context'; + +import _keyPairOptions from '../bbs/src/data/keyPair.json' assert { type: 'json' }; +import exampleControllerDoc from '../bbs/src/data/controllerDocument.json' assert { type: 'json' }; +import bbsContext from '../bbs/src/data/bbs.json' assert { type: 'json' }; +import jwsContext from '../bbs/src/data/jwsContext.json' assert { type: 'json' }; const {contexts: credentialsContext, constants: {CREDENTIALS_CONTEXT_V1_URL}} = cred; @@ -53,7 +53,7 @@ staticLoader.addStatic('https://w3id.org/security/v2', bbsContext); staticLoader.addStatic( 'https://w3id.org/security/suites/jws-2020/v1', jwsContext); -const didKeyDriver = didKey.driver(); +const didKeyDriver = driver(); export const documentLoader = async url => { if(url && url.startsWith('did:key:')) { diff --git a/tests/mock-data.js b/tests/mock-data.js index c7b7db1..e577535 100644 --- a/tests/mock-data.js +++ b/tests/mock-data.js @@ -1,5 +1,5 @@ /*! - * Copyright (c) 2020 Digital Bazaar, Inc. All rights reserved. + * Copyright (c) 2020-2022 Digital Bazaar, Inc. All rights reserved. */ export const mockKey = { type: 'Ed25519VerificationKey2020',