summaryrefslogtreecommitdiffhomepage
path: root/packages/browser/src/methods/startAssertion.ts
diff options
context:
space:
mode:
authorJarrett Helton <jaydhelton@gmail.com>2021-08-21 17:10:21 -0400
committerJarrett Helton <jaydhelton@gmail.com>2021-08-21 17:10:21 -0400
commit100ea77af46317d815b7bf4f695144187414d5b8 (patch)
tree18ae5272bef0d7838b8be11a2b754ee2df6cc76a /packages/browser/src/methods/startAssertion.ts
parentdf30228f4ebcccba03ddcfb3fc2dbd7102ae020d (diff)
renaming assertion -> authentication
Diffstat (limited to 'packages/browser/src/methods/startAssertion.ts')
-rw-r--r--packages/browser/src/methods/startAssertion.ts66
1 files changed, 0 insertions, 66 deletions
diff --git a/packages/browser/src/methods/startAssertion.ts b/packages/browser/src/methods/startAssertion.ts
deleted file mode 100644
index 786d55b..0000000
--- a/packages/browser/src/methods/startAssertion.ts
+++ /dev/null
@@ -1,66 +0,0 @@
-import {
- PublicKeyCredentialRequestOptionsJSON,
- AssertionCredential,
- AssertionCredentialJSON,
-} from '@simplewebauthn/typescript-types';
-
-import bufferToBase64URLString from '../helpers/bufferToBase64URLString';
-import base64URLStringToBuffer from '../helpers/base64URLStringToBuffer';
-import bufferToUTF8String from '../helpers/bufferToUTF8String';
-import supportsWebauthn from '../helpers/supportsWebauthn';
-import toPublicKeyCredentialDescriptor from '../helpers/toPublicKeyCredentialDescriptor';
-
-/**
- * Begin authenticator "login" via WebAuthn assertion
- *
- * @param requestOptionsJSON Output from @simplewebauthn/server's generateAssertionOptions(...)
- */
-export default async function startAssertion(
- requestOptionsJSON: PublicKeyCredentialRequestOptionsJSON,
-): Promise<AssertionCredentialJSON> {
- if (!supportsWebauthn()) {
- throw new Error('WebAuthn is not supported in this browser');
- }
-
- // We need to avoid passing empty array to avoid blocking retrieval
- // of public key
- let allowCredentials;
- if (requestOptionsJSON.allowCredentials?.length !== 0) {
- allowCredentials = requestOptionsJSON.allowCredentials?.map(toPublicKeyCredentialDescriptor);
- }
-
- // We need to convert some values to Uint8Arrays before passing the credentials to the navigator
- const publicKey: PublicKeyCredentialRequestOptions = {
- ...requestOptionsJSON,
- challenge: base64URLStringToBuffer(requestOptionsJSON.challenge),
- allowCredentials,
- };
-
- // Wait for the user to complete assertion
- const credential = (await navigator.credentials.get({ publicKey })) as AssertionCredential;
-
- if (!credential) {
- throw new Error('Assertion was not completed');
- }
-
- const { id, rawId, response, type } = credential;
-
- let userHandle = undefined;
- if (response.userHandle) {
- userHandle = bufferToUTF8String(response.userHandle);
- }
-
- // Convert values to base64 to make it easier to send back to the server
- return {
- id,
- rawId: bufferToBase64URLString(rawId),
- response: {
- authenticatorData: bufferToBase64URLString(response.authenticatorData),
- clientDataJSON: bufferToBase64URLString(response.clientDataJSON),
- signature: bufferToBase64URLString(response.signature),
- userHandle,
- },
- type,
- clientExtensionResults: credential.getClientExtensionResults(),
- };
-}