summaryrefslogtreecommitdiffhomepage
path: root/packages/browser/src/methods
diff options
context:
space:
mode:
authorMatthew Miller <matthew@millerti.me>2020-07-29 22:25:48 -0700
committerMatthew Miller <matthew@millerti.me>2020-07-29 22:25:48 -0700
commitbeeb60e20c942b65ff242e32ffcf9e8037db0bc1 (patch)
tree5d5b3d37e479214afbd97d82dd1250796c4e650c /packages/browser/src/methods
parent1861476c31e14ae855575e783a284d3179f7e653 (diff)
Update browser to handle base64url challenges
Diffstat (limited to 'packages/browser/src/methods')
-rw-r--r--packages/browser/src/methods/startAssertion.ts10
-rw-r--r--packages/browser/src/methods/startAttestation.ts9
2 files changed, 8 insertions, 11 deletions
diff --git a/packages/browser/src/methods/startAssertion.ts b/packages/browser/src/methods/startAssertion.ts
index b65325b..09e416f 100644
--- a/packages/browser/src/methods/startAssertion.ts
+++ b/packages/browser/src/methods/startAssertion.ts
@@ -4,8 +4,8 @@ import {
AssertionCredentialJSON,
} from '@simplewebauthn/typescript-types';
-import toUint8Array from '../helpers/toUint8Array';
import bufferToBase64URLString from '../helpers/bufferToBase64URLString';
+import base64URLStringToBuffer from '../helpers/base64URLStringToBuffer';
import supportsWebauthn from '../helpers/supportsWebauthn';
import toPublicKeyCredentialDescriptor from '../helpers/toPublicKeyCredentialDescriptor';
@@ -24,14 +24,12 @@ export default async function startAssertion(
// We need to convert some values to Uint8Arrays before passing the credentials to the navigator
const publicKey: PublicKeyCredentialRequestOptions = {
...requestOptionsJSON,
- challenge: toUint8Array(requestOptionsJSON.challenge),
- allowCredentials: requestOptionsJSON.allowCredentials.map(
- toPublicKeyCredentialDescriptor,
- ),
+ challenge: base64URLStringToBuffer(requestOptionsJSON.challenge),
+ allowCredentials: requestOptionsJSON.allowCredentials.map(toPublicKeyCredentialDescriptor),
};
// Wait for the user to complete assertion
- const credential = await navigator.credentials.get({ publicKey }) as AssertionCredential;
+ const credential = (await navigator.credentials.get({ publicKey })) as AssertionCredential;
if (!credential) {
throw new Error('Assertion was not completed');
diff --git a/packages/browser/src/methods/startAttestation.ts b/packages/browser/src/methods/startAttestation.ts
index d5e540f..b6faa83 100644
--- a/packages/browser/src/methods/startAttestation.ts
+++ b/packages/browser/src/methods/startAttestation.ts
@@ -6,6 +6,7 @@ import {
import toUint8Array from '../helpers/toUint8Array';
import bufferToBase64URLString from '../helpers/bufferToBase64URLString';
+import base64URLStringToBuffer from '../helpers/base64URLStringToBuffer';
import supportsWebauthn from '../helpers/supportsWebauthn';
import toPublicKeyCredentialDescriptor from '../helpers/toPublicKeyCredentialDescriptor';
@@ -24,18 +25,16 @@ export default async function startAttestation(
// We need to convert some values to Uint8Arrays before passing the credentials to the navigator
const publicKey: PublicKeyCredentialCreationOptions = {
...creationOptionsJSON,
- challenge: toUint8Array(creationOptionsJSON.challenge),
+ challenge: base64URLStringToBuffer(creationOptionsJSON.challenge),
user: {
...creationOptionsJSON.user,
id: toUint8Array(creationOptionsJSON.user.id),
},
- excludeCredentials: creationOptionsJSON.excludeCredentials.map(
- toPublicKeyCredentialDescriptor,
- ),
+ excludeCredentials: creationOptionsJSON.excludeCredentials.map(toPublicKeyCredentialDescriptor),
};
// Wait for the user to complete attestation
- const credential = await navigator.credentials.create({ publicKey }) as AttestationCredential;
+ const credential = (await navigator.credentials.create({ publicKey })) as AttestationCredential;
if (!credential) {
throw new Error('Attestation was not completed');