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 try catch block in canAuthenticateWithCredId #6

Open
wants to merge 1 commit 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 18 additions & 12 deletions fidoutils.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,26 +286,32 @@ function base64utobase64(base64Str) {
return jsrsasign.b64utob64(base64Str);
}

/**
* Attempts to resolve the private key from the candidate credential ID bytes.
* For each credential ID in the allowCredentials array, use resolvePrivateKeyHexFromCredentialIdBytes
* to retrieve the private key hex. If a non-null, non-empty private key is found, return true;
* otherwise, return false.
*/
function canAuthenticateWithCredId(options) {
// try and use resolvePrivateKeyHexFromCredentialIdBytes and check the return
// if candiateprivkeyhex is not null and candiateprivkeyhex length greather than zero
// return true, else return false
console.log(options.publicKey.allowCredentials[0].id);
let privateKeyHexfromCandidateCredIdBytes;
let canAuthenticate = false;
if (options.publicKey.allowCredentials !== null && options.publicKey.allowCredentials.length > 0) {
for (let i = 0; i < options.publicKey.allowCredentials.length; i++) {
let candidateCredId = options.publicKey.allowCredentials[i].id;
console.log("candidateCredId", candidateCredId);
privateKeyHexfromCandidateCredIdBytes = resolvePrivateKeyHexFromCredentialIdBytes(candidateCredId);
console.log("privateKeyHexfromCandidateCredIdBytes", privateKeyHexfromCandidateCredIdBytes);
if (privateKeyHexfromCandidateCredIdBytes !== null && privateKeyHexfromCandidateCredIdBytes.length > 0) {
canAuthenticate = true;
break;
try {
let candidateCredId = options.publicKey.allowCredentials[i].id;
console.log("candidateCredId", candidateCredId);
privateKeyHexfromCandidateCredIdBytes = resolvePrivateKeyHexFromCredentialIdBytes(candidateCredId);
console.log("privateKeyHexfromCandidateCredIdBytes", privateKeyHexfromCandidateCredIdBytes);
if (privateKeyHexfromCandidateCredIdBytes !== null && privateKeyHexfromCandidateCredIdBytes.length > 0) {
canAuthenticate = true;
break;
}
} catch (error) {
console.log("Error in canAuthenticateWithCredId method: ", error)
}
}
}
console.log("canAuthenticate", canAuthenticate);
console.log("Can authenticate: ", canAuthenticate);
return canAuthenticate;
}

Expand Down