From 6bc364f7e31822dc5d8578260ff81929b97fff2d Mon Sep 17 00:00:00 2001 From: MaysWind Date: Sun, 22 Nov 2020 12:22:37 +0800 Subject: [PATCH] code refactor --- src/lib/webauthn.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lib/webauthn.js b/src/lib/webauthn.js index 23e2f893..d8094b16 100644 --- a/src/lib/webauthn.js +++ b/src/lib/webauthn.js @@ -61,13 +61,13 @@ function registerCredential({ username, nickname }, userSecret) { const challenge = utils.generateRandomString(); const publicKeyCredentialCreationOptions = Object.assign({}, PUBLIC_KEY_CREDENTIAL_CREATION_OPTIONS_TEMPLATE, { - challenge: Uint8Array.from(challenge, c => c.charCodeAt(0)), + challenge: utils.stringToArrayBuffer(challenge), rp: { name: window.location.hostname, id: window.location.hostname }, user: { - id: Uint8Array.from(userSecret, c => c.charCodeAt(0)), + id: utils.stringToArrayBuffer(userSecret), name: username, displayName: nickname } @@ -140,10 +140,10 @@ function verifyCredential(credentialId) { const challenge = utils.generateRandomString(); const publicKeyCredentialRequestOptions = Object.assign({}, PUBLIC_KEY_CREDENTIAL_REQUEST_OPTIONS_TEMPLATE, { - challenge: Uint8Array.from(challenge, c => c.charCodeAt(0)), + challenge: utils.stringToArrayBuffer(challenge), rpId: window.location.hostname }); - publicKeyCredentialRequestOptions.allowCredentials[0].id = Uint8Array.from(atob(credentialId), c=>c.charCodeAt(0)).buffer; + publicKeyCredentialRequestOptions.allowCredentials[0].id = utils.stringToArrayBuffer(atob(credentialId)); logger.debug('webauthn get options', publicKeyCredentialRequestOptions);