import { WebAuthnOutcome, WebAuthnStepType } from './enums.js'; import type { HiddenValueCallback } from '../callbacks/hidden-value-callback.js'; import type { JourneyStep } from '../step.utils.js'; import type { AttestationType, RelyingParty, WebAuthnAuthenticationMetadata, WebAuthnCallbacks, WebAuthnRegistrationMetadata } from './interfaces.js'; import type { MetadataCallback } from '../callbacks/metadata-callback.js'; import type { TextOutputCallback } from '../callbacks/text-output-callback.js'; export type OutcomeWithName = Name extends infer P extends string ? `${ClientId}::${Attestation}::${PubKeyCred['id']}${P extends '' ? '' : `::${P}`}` : never; /** * Utility for integrating a web browser's WebAuthn API. * * Example: * * ```js * // Determine if a step is a WebAuthn step * const stepType = WebAuthn.getWebAuthnStepType(step); * if (stepType === WebAuthnStepType.Registration) { * // Register a new device * await WebAuthn.register(step); * } else if (stepType === WebAuthnStepType.Authentication) { * // Authenticate with a registered device * await WebAuthn.authenticate(step); * } * ``` * * Conditional mediation (passkey autofill) support: * * Conditional mediation is **server-driven** in this SDK via WebAuthn metadata (`meta.mediation`). * * ```js * // Optional: feature-detect conditional UI before attempting * const supportsConditionalUI = await WebAuthn.isConditionalMediationSupported(); * * if (supportsConditionalUI) { * const controller = new AbortController(); * * // Optional: provide a signal to cancel an in-flight request * await WebAuthn.authenticate(step, controller.signal); * } * ``` * * Notes: * - When server-driven mediation is `'conditional'`, an `AbortSignal` will be used. * If you don't provide one, the SDK will create one. * - If conditional mediation is requested but not supported by the browser, * `authenticate()` throws a `NotSupportedError` and sets the hidden WebAuthn outcome to `unsupported`. * - To enable passkey autofill, add `autocomplete="webauthn"` to your username field: * `` */ export declare abstract class WebAuthn { private static conditionalAbortController?; /** * Determines if the given step is a WebAuthn step. * * @param step The step to evaluate * @return A WebAuthnStepType value */ static getWebAuthnStepType(step: JourneyStep): WebAuthnStepType; /** * Determines if the browser supports conditional mediation. * * @return Whether the browser supports conditional mediation */ static isConditionalMediationSupported(): Promise; /** * Populates the step with the necessary authentication outcome. * * @param step The step that contains WebAuthn authentication data * @param signal Optional AbortSignal passed through to `navigator.credentials.get()` * @return The populated step */ static authenticate(step: JourneyStep, signal?: AbortSignal): Promise; /** * Populates the step with the necessary registration outcome. * * @param step The step that contains WebAuthn registration data * @return The populated step */ static register(step: JourneyStep, deviceName?: T): Promise; /** * Returns an object containing the two WebAuthn callbacks. * * @param step The step that contains WebAuthn callbacks * @return The WebAuthn callbacks */ static getCallbacks(step: JourneyStep): WebAuthnCallbacks; /** * Returns the WebAuthn metadata callback containing data to pass to the browser * Web Authentication API. * * @param step The step that contains WebAuthn callbacks * @return The metadata callback */ static getMetadataCallback(step: JourneyStep): MetadataCallback | undefined; /** * Returns the WebAuthn hidden value callback where the outcome should be populated. * * @param step The step that contains WebAuthn callbacks * @return The hidden value callback */ static getOutcomeCallback(step: JourneyStep): HiddenValueCallback | undefined; /** * Returns the WebAuthn metadata callback containing data to pass to the browser * Web Authentication API. * * @param step The step that contains WebAuthn callbacks * @return The metadata callback */ static getTextOutputCallback(step: JourneyStep): TextOutputCallback | undefined; /** * Retrieves the credential from the browser Web Authentication API. * * @param options The public key options associated with the request * @param mediation Optional mediation requirement passed through to `navigator.credentials.get()` * @param signal Optional AbortSignal passed through to `navigator.credentials.get()` * @return The credential */ static getAuthenticationCredential(options: PublicKeyCredentialRequestOptions, mediation?: CredentialMediationRequirement, signal?: AbortSignal): Promise; /** * Converts an authentication credential into the outcome expected by OpenAM. * * @param credential The credential to convert * @return The outcome string */ static getAuthenticationOutcome(credential: PublicKeyCredential | null): OutcomeWithName | OutcomeWithName; /** * Retrieves the credential from the browser Web Authentication API. * * @param options The public key options associated with the request * @return The credential */ static getRegistrationCredential(options: PublicKeyCredentialCreationOptions): Promise; /** * Converts a registration credential into the outcome expected by OpenAM. * * @param credential The credential to convert * @return The outcome string */ static getRegistrationOutcome(credential: PublicKeyCredential | null): OutcomeWithName; /** * Converts authentication tree metadata into options required by the browser * Web Authentication API. * * @param metadata The metadata provided in the authentication tree MetadataCallback * @return The Web Authentication API request options */ static createAuthenticationPublicKey(metadata: WebAuthnAuthenticationMetadata): PublicKeyCredentialRequestOptions; /** * Converts authentication tree metadata into options required by the browser * Web Authentication API. * * @param metadata The metadata provided in the authentication tree MetadataCallback * @return The Web Authentication API request options */ static createRegistrationPublicKey(metadata: WebAuthnRegistrationMetadata): PublicKeyCredentialCreationOptions; /** * Creates and stores an SDK-owned {@link AbortController} for conditional mediation, * aborting any previous SDK-owned controller first. * * @return A new AbortController for conditional mediation. */ private static createAbortController; } export { WebAuthnOutcome, WebAuthnStepType }; export type { RelyingParty, WebAuthnAuthenticationMetadata, WebAuthnCallbacks, WebAuthnRegistrationMetadata, }; export type { AttestationType, UserVerificationType } from './interfaces.js'; export type { HiddenValueCallback } from '../callbacks/hidden-value-callback.js'; export type { MetadataCallback } from '../callbacks/metadata-callback.js'; export type { TextOutputCallback } from '../callbacks/text-output-callback.js'; export type { JourneyStep } from '../step.utils.js'; export type { BaseCallback } from '../callbacks/base-callback.js'; //# sourceMappingURL=webauthn.d.ts.map