WebAuthnCeremony.from
Creates a WebAuthnCeremony from a custom implementation.
Usage
import { WebAuthnCeremony } from 'accounts'
const ceremony = WebAuthnCeremony.from({
async getRegistrationOptions(params) { /* ... */ },
async verifyRegistration(credential) { /* ... */ },
async getAuthenticationOptions(params) { /* ... */ },
async verifyAuthentication(response) { /* ... */ },
})Properties
getRegistrationOptions
Get credential creation options for navigator.credentials.create().
declare function getRegistrationOptions(parameters: {
/** Credential IDs to exclude (prevents re-registering existing credentials). */
excludeCredentialIds?: readonly string[] | undefined
/** Credential display name (e.g. `"alice"`). */
name: string
/** Opaque user identifier. Encoded as `user.id` in the WebAuthn creation options. */
userId?: string | undefined
}): Promise<{ options: Registration.Options }>verifyRegistration
Verify a registration response and extract the public key.
declare function verifyRegistration(
credential: Registration.Credential,
options?: {
/** Credential display name forwarded from `getRegistrationOptions`. */
name?: string | undefined
/**
* Resolves once earlier verifications have settled. A ceremony that calls
* a server should await it before sending, so an earlier registration or
* login landing later can't replace this one's session.
*/
ready?: Promise<unknown> | undefined
/** Aborts verification still in flight (e.g. superseded by a later session). */
signal?: AbortSignal | undefined
} | undefined,
): Promise<{
/** The registered credential's ID. */
credentialId: string
/** Email associated with the account. */
email?: string | null | undefined
/** The credential's public key (uncompressed P256, hex-encoded). */
publicKey: Hex
/** Username associated with the account. */
username?: string | null | undefined
/**
* For a ceremony that answers before the server stores the credential:
* resolves once it lands (`session` is whether its response issued the
* session), and rejects if the server refuses it.
*/
verified?: Promise<{ session: boolean }> | undefined
}>A ceremony that calls a server should await options.ready before sending its request. One that ignores it loses the ordering behind earlier verifications.
getAuthenticationOptions
Get credential request options for navigator.credentials.get().
declare function getAuthenticationOptions(parameters?: {
/** Challenge to use. */
challenge?: Hex | undefined
/** Credential ID or IDs to restrict authentication to. */
credentialId?: string | readonly string[] | undefined
/** Mediation hint for passkey autofill / conditional UI. */
mediation?: 'conditional' | 'optional' | 'required' | 'silent' | undefined
} | undefined): Promise<{ options: Authentication.Options }>verifyAuthentication
Verify an authentication response and extract the public key.
declare function verifyAuthentication(
response: Authentication.Response,
options?: {
/**
* The known credential's challenge, public key and RP ID, so the ceremony
* can check the passkey's signature itself.
*/
credential?: { challenge: Hex; publicKey: Hex; rpId: string } | undefined
/** Resolves once earlier verifications have settled; await it before sending (as for `verifyRegistration`). */
ready?: Promise<unknown> | undefined
/** Aborts verification still in flight. */
signal?: AbortSignal | undefined
} | undefined,
): Promise<{
/** The authenticated credential's ID. */
credentialId: string
/** Email associated with the account. */
email?: string | null | undefined
/** The credential's public key (uncompressed P256, hex-encoded). */
publicKey: Hex
/** User identifier from the authenticator's `userHandle` (discoverable / conditional flows). */
userId?: string | undefined
/** Username associated with the account. */
username?: string | null | undefined
/**
* For a ceremony that answers before the server verifies the login:
* resolves once it lands (`session` is whether it issued the session), and
* rejects if the server refuses the credential.
*/
verified?: Promise<{ session: boolean }> | undefined
}>