diff --git a/lib/vc.js b/lib/vc.js index 378d1344..91b36e1d 100644 --- a/lib/vc.js +++ b/lib/vc.js @@ -224,7 +224,7 @@ async function verifyCredential(options = {}) { return { verified: false, results: [{credential, verified: false, error}], - error + error, }; } } @@ -250,17 +250,33 @@ async function verifyCredential(options = {}) { */ async function _verifyCredential(options = {}) { const {credential, checkStatus} = options; + try { + // run common credential checks + _checkCredential(credential); - // run common credential checks - _checkCredential(credential); - - // if credential status is provided, a `checkStatus` function must be given - if(credential.credentialStatus && typeof options.checkStatus !== 'function') { - throw new TypeError( - 'A "checkStatus" function must be given to verify credentials with ' + - '"credentialStatus".'); + // if credential status is provided, a `checkStatus` function must be given + if(credential.credentialStatus && typeof options.checkStatus !== 'function') { + throw new TypeError( + 'A "checkStatus" function must be given to verify credentials with ' + + '"credentialStatus".'); + } + } catch(error) { + const log = []; + log.push({ + id: 'check_credential_required_field', + valid: false, + }); + return { + verified: false, + results: [{credential, verified: false, error}], + error, + log, + }; } + + const log = []; + log.push({id: 'check_credential_required_field', valid: true}); const documentLoader = options.documentLoader || defaultDocumentLoader; const {controller} = options; @@ -273,16 +289,22 @@ async function _verifyCredential(options = {}) { // if verification has already failed, skip status check if(!result.verified) { + log.push({id: 'verifies_data_signature_on_document', valid: false}); + result.log = log; return result; } + log.push({id: 'verifies_data_signature_on_document', valid: true}); if(credential.credentialStatus) { result.statusResult = await checkStatus(options); if(!result.statusResult.verified) { result.verified = false; + log.push({id: 'check_status', valid: false}); } } + log.push({id: 'check_status', valid: true}); + result.log = log; return result; }