diff --git a/src/utils/passkey.js b/src/utils/passkey.js index f0c095b5a..44d3fbacb 100644 --- a/src/utils/passkey.js +++ b/src/utils/passkey.js @@ -8,7 +8,9 @@ for (let i = 0; i < chars.length; i++) { const encode = function(arraybuffer) { const bytes = new Uint8Array(arraybuffer) - let i; const len = bytes.length; let base64url = '' + let i + const len = bytes.length + let base64url = '' for (i = 0; i < len; i += 3) { base64url += chars[bytes[i] >> 2] @@ -17,7 +19,7 @@ const encode = function(arraybuffer) { base64url += chars[bytes[i + 2] & 63] } - if ((len % 3) === 2) { + if (len % 3 === 2) { base64url = base64url.substring(0, base64url.length - 1) } else if (len % 3 === 1) { base64url = base64url.substring(0, base64url.length - 2) @@ -28,8 +30,13 @@ const encode = function(arraybuffer) { const decode = function(base64string) { const bufferLength = base64string.length * 0.75 - const len = base64string.length; let i; let p = 0 - let encoded1; let encoded2; let encoded3; let encoded4 + const len = base64string.length + let i + let p = 0 + let encoded1 + let encoded2 + let encoded3 + let encoded4 const bytes = new Uint8Array(bufferLength) @@ -47,15 +54,16 @@ const decode = function(base64string) { return bytes.buffer } -const publicKeyCredentialToJSON = (pubKeyCred) => { +const publicKeyCredentialToJSON = pubKeyCred => { if (pubKeyCred instanceof Array) { const arr = [] - for (const i of pubKeyCred) { arr.push(publicKeyCredentialToJSON(i)) } - + for (const i of pubKeyCred) { + arr.push(publicKeyCredentialToJSON(i)) + } return arr } - if (pubKeyCred instanceof ArrayBuffer) { + if (pubKeyCred instanceof ArrayBuffer || pubKeyCred instanceof Uint8Array) { return encode(pubKeyCred) } @@ -73,8 +81,7 @@ const publicKeyCredentialToJSON = (pubKeyCred) => { } export default { - 'decode': decode, - 'encode': encode, - 'publicKeyCredentialToJSON': publicKeyCredentialToJSON + decode: decode, + encode: encode, + publicKeyCredentialToJSON: publicKeyCredentialToJSON } -