From 1c8b522864e85d618ebf2c0e755ea88132ba4080 Mon Sep 17 00:00:00 2001 From: Matthew Miller <matthew@millerti.me> Date: Sun, 8 Dec 2024 12:10:37 -0800 Subject: [PATCH] Move some docstrings around --- .../browser/src/helpers/webAuthnAbortService.ts | 16 ++++++++-------- .../browser/src/methods/startAuthentication.ts | 12 ++++++------ .../browser/src/methods/startRegistration.ts | 10 +++++----- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/packages/browser/src/helpers/webAuthnAbortService.ts b/packages/browser/src/helpers/webAuthnAbortService.ts index 8ed915fc..9cc68576 100644 --- a/packages/browser/src/helpers/webAuthnAbortService.ts +++ b/packages/browser/src/helpers/webAuthnAbortService.ts @@ -1,16 +1,19 @@ interface WebAuthnAbortService { + /** + * Prepare an abort signal that will help support multiple auth attempts without needing to + * reload the page. This is automatically called whenever `startRegistration()` and + * `startAuthentication()` are called. + */ createNewAbortSignal(): AbortSignal; + /** + * Manually cancel any active WebAuthn registration or authentication attempt. + */ cancelCeremony(): void; } class BaseWebAuthnAbortService implements WebAuthnAbortService { private controller: AbortController | undefined; - /** - * Prepare an abort signal that will help support multiple auth attempts without needing to - * reload the page. This is automatically called whenever `startRegistration()` and - * `startAuthentication()` are called. - */ createNewAbortSignal(): AbortSignal { // Abort any existing calls to navigator.credentials.create() or navigator.credentials.get() if (this.controller) { @@ -27,9 +30,6 @@ class BaseWebAuthnAbortService implements WebAuthnAbortService { return newController.signal; } - /** - * Manually cancel any active WebAuthn registration or authentication attempt. - */ cancelCeremony(): void { if (this.controller) { const abortError = new Error( diff --git a/packages/browser/src/methods/startAuthentication.ts b/packages/browser/src/methods/startAuthentication.ts index dab7b9e3..021b6b3b 100644 --- a/packages/browser/src/methods/startAuthentication.ts +++ b/packages/browser/src/methods/startAuthentication.ts @@ -12,11 +12,7 @@ import { identifyAuthenticationError } from '../helpers/identifyAuthenticationEr import { WebAuthnAbortService } from '../helpers/webAuthnAbortService.ts'; import { toAuthenticatorAttachment } from '../helpers/toAuthenticatorAttachment.ts'; -export type StartAuthenticationOpts = { - optionsJSON: PublicKeyCredentialRequestOptionsJSON; - useBrowserAutofill?: boolean; - verifyBrowserAutofillInput?: boolean; -}; +export type StartAuthenticationOpts = Parameters<typeof startAuthentication>[0]; /** * Begin authenticator "login" via WebAuthn assertion @@ -26,7 +22,11 @@ export type StartAuthenticationOpts = { * @param verifyBrowserAutofillInput (Optional) Ensure a suitable `<input>` element is present when `useBrowserAutofill` is `true`. Defaults to `true`. */ export async function startAuthentication( - options: StartAuthenticationOpts, + options: { + optionsJSON: PublicKeyCredentialRequestOptionsJSON; + useBrowserAutofill?: boolean; + verifyBrowserAutofillInput?: boolean; + }, ): Promise<AuthenticationResponseJSON> { const { optionsJSON, diff --git a/packages/browser/src/methods/startRegistration.ts b/packages/browser/src/methods/startRegistration.ts index b2c3f739..aa756f21 100644 --- a/packages/browser/src/methods/startRegistration.ts +++ b/packages/browser/src/methods/startRegistration.ts @@ -12,10 +12,7 @@ import { identifyRegistrationError } from '../helpers/identifyRegistrationError. import { WebAuthnAbortService } from '../helpers/webAuthnAbortService.ts'; import { toAuthenticatorAttachment } from '../helpers/toAuthenticatorAttachment.ts'; -export type StartRegistrationOpts = { - optionsJSON: PublicKeyCredentialCreationOptionsJSON; - useAutoRegister?: boolean; -}; +export type StartRegistrationOpts = Parameters<typeof startRegistration>[0]; /** * Begin authenticator "registration" via WebAuthn attestation @@ -24,7 +21,10 @@ export type StartRegistrationOpts = { * @param useAutoRegister (Optional) Try to silently create a passkey with the password manager that the user just signed in with. Defaults to `false`. */ export async function startRegistration( - options: StartRegistrationOpts, + options: { + optionsJSON: PublicKeyCredentialCreationOptionsJSON; + useAutoRegister?: boolean; + }, ): Promise<RegistrationResponseJSON> { const { optionsJSON, useAutoRegister = false } = options;