Skip to content

Commit

Permalink
Use fromKeyDocument() for key documents in get().
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitrizagidulin committed May 3, 2021
1 parent a779a03 commit fa5352e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions lib/VeresOneDriver.js
Expand Up @@ -122,7 +122,7 @@ class VeresOneDriver {
const method = didIo.findVerificationMethod({
doc: didDocument, methodId: did
});
const keyPair = await cryptoLd.from(method);
const keyPair = await cryptoLd.fromKeyDocument({document: method});
return keyPair.export({publicKey: true, includeContext: true});
}

Expand Down Expand Up @@ -394,7 +394,7 @@ class VeresOneDriver {
*
* @param {object} options - Options hashmap.
* @param {string} didDocument - DID document to validate.
* @param {string} [mode='dev'] - Mode: 'test'/'live' etc
* @param {string} [mode='dev'] - Mode: 'test'/'live' etc.
*
* @returns {Promise<{valid: boolean, error: Error}>} - Resolves with the
* validation result.
Expand Down Expand Up @@ -505,7 +505,8 @@ class VeresOneDriver {
* {boolean} valid - true if the DID is valid
* {Error} error - included when `valid` is false
*/
async validateMethodIds() {
async validateMethodIds({didDocument}) {
const did = didDocument.id;
for(const proofPurpose in constants.VERIFICATION_RELATIONSHIPS) {
const methods = this.getAllVerificationMethods(proofPurpose);
if(!methods) {
Expand Down Expand Up @@ -568,9 +569,8 @@ async function fromNym({did} = {}) {
throw new TypeError('The "did" parameter is required.');
}
let invokeKey;
let mode;
// Re-hydrate capabilityInvocation public key from fingerprint
const {didType, id: fingerprint} = _parseDid({did});
const {didType, id: fingerprint, mode} = _parseDid({did});

if(didType !== 'nym') {
throw new Error(`"${did}" is not a cryptonym.`);
Expand Down Expand Up @@ -600,7 +600,7 @@ function _parseDid({did} = {}) {
const match = DID_REGEX.exec(did);

if(!match) {
throw new Error(`Invalid DID format: "${did}".`)
throw new Error(`Invalid DID format: "${did}".`);
}

// Match [2] is the ledger mode, either undefined (live or dev) or 'test:'
Expand Down Expand Up @@ -640,7 +640,7 @@ function _generateDid({key, didType = DEFAULT_DID_TYPE, mode = DEFAULT_MODE}) {
}

function _keyId({did, keyPair}) {
if(keyPair.id.startsWith('did:v1:')) {
if(keyPair.id && keyPair.id.startsWith('did:v1:')) {
return keyPair.id;
}
return `${did}#${keyPair.fingerprint()}`;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -27,7 +27,7 @@
"@digitalbazaar/zcapld": "^3.1.0",
"apisauce": "^1.1.2",
"base64url-universal": "^1.1.0",
"crypto-ld": "^5.1.0",
"crypto-ld": "digitalbazaar/crypto-ld#fromKeyDocument",
"did-context": "^3.0.0",
"esm": "^3.2.25",
"fast-json-patch": "^2.2.1",
Expand Down

0 comments on commit fa5352e

Please sign in to comment.