Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add verification event log mechanism to verify() operation (for fine-grained UI) #92

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 31 additions & 9 deletions lib/vc.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ async function verifyCredential(options = {}) {
return {
verified: false,
results: [{credential, verified: false, error}],
error
error,
};
}
}
Expand All @@ -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',
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we include user-friendly event descriptions in these log entries as well or do you think the ID-description mapping responsibility should be left to the client code?

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;
Expand All @@ -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});
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't this line overwrite line 302, since we are not returning after we push that log entry?

result.log = log;
return result;
}

Expand Down