Skip to content

Commit

Permalink
Add test that checks if dereferencing "verificationMethod" results in
Browse files Browse the repository at this point in the history
an object with "Multikey" type value.
  • Loading branch information
JSAssassin committed Oct 26, 2023
1 parent e6f95af commit 229428a
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 5 deletions.
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,20 @@
"dependencies": {
"@digitalbazaar/data-integrity": "^1.1.0",
"@digitalbazaar/data-integrity-context": "^1.0.0",
"@digitalbazaar/did-method-key": "^3.0.0",
"@digitalbazaar/ed25519-multikey": "^1.0.0",
"@digitalbazaar/did-method-key": "^5.1.0",
"@digitalbazaar/ed25519-multikey": "^1.0.1",
"@digitalbazaar/eddsa-2022-cryptosuite": "^1.0.0",
"@digitalbazaar/http-client": "^4.0.0",
"@digitalbazaar/mocha-w3c-interop-reporter": "^1.4.0",
"@digitalbazaar/multikey-context": "^1.0.0",
"@digitalbazaar/vc": "^5.0.0",
"@digitalbazaar/vc": "^6.0.2",
"@digitalcredentials/did-context": "^1.0.0",
"bnid": "^3.0.0",
"canonicalize": "^1.0.8",
"canonicalize": "^2.0.0",
"chai": "^4.3.6",
"credentials-context": "^2.0.0",
"data-integrity-test-suite-assertion": "github:w3c-ccg/data-integrity-test-suite-assertion",
"jsonld-document-loader": "^1.2.1",
"jsonld-document-loader": "^2.0.0",
"klona": "^2.0.5",
"mocha": "^10.0.0",
"uuid": "^9.0.0",
Expand Down
21 changes: 21 additions & 0 deletions tests/10-create.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import chai from 'chai';
import {
checkDataIntegrityProofFormat
} from 'data-integrity-test-suite-assertion';
import {documentLoader} from './documentLoader.js';
import {endpoints} from 'vc-test-suite-implementations';
import {generateTestData} from './vc-generator/index.js';

Expand Down Expand Up @@ -40,10 +41,19 @@ describe('eddsa-2022 (create)', function() {
v => v.tags.has(tag));
let issuedVc;
let proofs;
const verificationMethodDocuments = [];
before(async function() {
issuedVc = await createInitialVc({issuer, vc: validVc});
proofs = Array.isArray(issuedVc?.proof) ?
issuedVc.proof : [issuedVc?.proof];
const verificationMethods = proofs.map(
proof => proof.verificationMethod);
for(const verificationMethod of verificationMethods) {
const verificationMethodDocument = await documentLoader({
url: verificationMethod
});
verificationMethodDocuments.push(verificationMethodDocument);
}
});
it('The field "cryptosuite" MUST be "eddsa-rdfc-2022" ' +
'or "eddsa-jcs-2022"', function() {
Expand All @@ -54,6 +64,17 @@ describe('eddsa-2022 (create)', function() {
'"cryptosuite" with the value "eddsa-rdfc-2022" or ' +
'"eddsa-rdfc-2022".');
});
it('Dereferencing the "verificationMethod" MUST result in an ' +
'object containing a type property with "Multikey" value.',
function() {
verificationMethodDocuments.should.not.eql([], 'Expected ' +
'at least one "verificationMethodDocument".');
verificationMethodDocuments.some(
verificationMethodDocument =>
verificationMethodDocument?.type === 'Multikey'
).should.equal(true, 'Expected at least one proof to have "type" ' +
'property value "Multikey".');
});
it('"proofValue" field when decoded to raw bytes, MUST be 64 bytes ' +
'in length if the associated public key is 32 bytes or 114 bytes ' +
'in length if the public key is 57 bytes.', async function() {
Expand Down
20 changes: 20 additions & 0 deletions tests/didResolver.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*!
* Copyright 2023 Digital Bazaar, Inc. All Rights Reserved
*/
import * as didMethodKey from '@digitalbazaar/did-method-key';
import * as Ed25519Multikey from '@digitalbazaar/ed25519-multikey';

const multibaseMultikeyHeader = 'z6Mk';
const didKeyDriver = didMethodKey.driver();

didKeyDriver.use({
multibaseMultikeyHeader,
fromMultibase: Ed25519Multikey.from
});

export async function didResolver({url}) {
if(url.startsWith('did:')) {
return didKeyDriver.get({did: url});
}
throw new Error('DID Method not supported by resolver');
}
41 changes: 41 additions & 0 deletions tests/documentLoader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*!
* Copyright 2023 Digital Bazaar, Inc. All Rights Reserved
*/
import {didResolver} from './didResolver.js';
import {httpClient} from '@digitalbazaar/http-client';
import https from 'node:https';
import {JsonLdDocumentLoader} from 'jsonld-document-loader';

const agent = new https.Agent({rejectUnauthorized: false});
const httpClientHandler = {
async get({url}) {
if(!url.startsWith('http')) {
throw new Error('NotFoundError');
}
let result;
try {
result = await httpClient.get(url, {agent});
} catch(e) {
throw new Error('NotFoundError');
}
return result.data;
}
};

const jdl = new JsonLdDocumentLoader();

jdl.setProtocolHandler({protocol: 'http', handler: httpClientHandler});
jdl.setProtocolHandler({protocol: 'https', handler: httpClientHandler});

const webLoader = jdl.build();

export async function documentLoader({url}) {
// resolve all DID URLs through didKeyDriver
if(url.startsWith('did:')) {
return didResolver({url});
}
// use web loader if the URL is a HTTP URL
if(url.startsWith('https')) {
return webLoader(url);
}
}

0 comments on commit 229428a

Please sign in to comment.