From 357627741b0b4869990720d41b3ef008b2aaace5 Mon Sep 17 00:00:00 2001 From: Dushkin Dmitro Date: Mon, 22 Feb 2021 10:48:42 +0200 Subject: [PATCH 1/3] Added verify result array --- lib/vc.js | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/lib/vc.js b/lib/vc.js index 378d1344..e35a5e0f 100644 --- a/lib/vc.js +++ b/lib/vc.js @@ -221,11 +221,23 @@ async function verifyCredential(options = {}) { } return _verifyCredential(options); } catch(error) { - return { - verified: false, - results: [{credential, verified: false, error}], - error - }; + const result_array = []; + result_array.push({ + id: 'check_credential_required_field', + valid: false, + error, + result: { + verified: false, + results: [{credential, verified: false, error}], + error + }, + }); + return result_array; + // return { + // verified: false, + // results: [{credential, verified: false, error}], + // error + // }; } } @@ -261,6 +273,8 @@ async function _verifyCredential(options = {}) { '"credentialStatus".'); } + const result_array = []; + result_array.push({id: 'check_credential_required_field', valid: true}); const documentLoader = options.documentLoader || defaultDocumentLoader; const {controller} = options; @@ -273,17 +287,23 @@ async function _verifyCredential(options = {}) { // if verification has already failed, skip status check if(!result.verified) { - return result; + result_array.push({id: 'verifies_data_signature_on_document', valid: false, error: result.results, result}); + // return result; + return result_array; } + result_array.push({id: 'verifies_data_signature_on_document', valid: true}); if(credential.credentialStatus) { result.statusResult = await checkStatus(options); if(!result.statusResult.verified) { result.verified = false; + result_array.push({id: 'check_status', valid: false, error: new Error('Check status is failure'), result}); } } - return result; + result_array.push({id: 'check_status', valid: true, result}); + return result_array; + // return result; } /** From 8298aa4b95d6e20fcb3c00e913af4a9e946753ef Mon Sep 17 00:00:00 2001 From: Dushkin Dmitro Date: Tue, 23 Feb 2021 17:11:16 +0200 Subject: [PATCH 2/3] Added result_array to the result object --- lib/vc.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/vc.js b/lib/vc.js index e35a5e0f..63a808a2 100644 --- a/lib/vc.js +++ b/lib/vc.js @@ -232,12 +232,12 @@ async function verifyCredential(options = {}) { error }, }); - return result_array; - // return { - // verified: false, - // results: [{credential, verified: false, error}], - // error - // }; + return { + verified: false, + results: [{credential, verified: false, error}], + error, + result_array, + }; } } @@ -288,8 +288,8 @@ async function _verifyCredential(options = {}) { // if verification has already failed, skip status check if(!result.verified) { result_array.push({id: 'verifies_data_signature_on_document', valid: false, error: result.results, result}); - // return result; - return result_array; + result.result_array = result_array; + return result; } result_array.push({id: 'verifies_data_signature_on_document', valid: true}); @@ -302,8 +302,8 @@ async function _verifyCredential(options = {}) { } result_array.push({id: 'check_status', valid: true, result}); - return result_array; - // return result; + result.result_array = result_array; + return result; } /** From c4f9abbbd39d90bd47343ce768a234f4cde6cf86 Mon Sep 17 00:00:00 2001 From: Dushkin Dmitro Date: Mon, 1 Mar 2021 13:35:04 +0200 Subject: [PATCH 3/3] Added result.log --- lib/vc.js | 58 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 30 insertions(+), 28 deletions(-) diff --git a/lib/vc.js b/lib/vc.js index 63a808a2..91b36e1d 100644 --- a/lib/vc.js +++ b/lib/vc.js @@ -221,22 +221,10 @@ async function verifyCredential(options = {}) { } return _verifyCredential(options); } catch(error) { - const result_array = []; - result_array.push({ - id: 'check_credential_required_field', - valid: false, - error, - result: { - verified: false, - results: [{credential, verified: false, error}], - error - }, - }); return { verified: false, results: [{credential, verified: false, error}], error, - result_array, }; } } @@ -262,19 +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 result_array = []; - result_array.push({id: 'check_credential_required_field', valid: true}); + + const log = []; + log.push({id: 'check_credential_required_field', valid: true}); const documentLoader = options.documentLoader || defaultDocumentLoader; const {controller} = options; @@ -287,22 +289,22 @@ async function _verifyCredential(options = {}) { // if verification has already failed, skip status check if(!result.verified) { - result_array.push({id: 'verifies_data_signature_on_document', valid: false, error: result.results, result}); - result.result_array = result_array; + log.push({id: 'verifies_data_signature_on_document', valid: false}); + result.log = log; return result; } - result_array.push({id: 'verifies_data_signature_on_document', valid: true}); + 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; - result_array.push({id: 'check_status', valid: false, error: new Error('Check status is failure'), result}); + log.push({id: 'check_status', valid: false}); } } - result_array.push({id: 'check_status', valid: true, result}); - result.result_array = result_array; + log.push({id: 'check_status', valid: true}); + result.log = log; return result; }