/** * Copyright Amazon.com, Inc. and its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). You * may not use this file except in compliance with the License. A copy of * the License is located at * * http://aws.amazon.com/apache2.0/ * * or in the "license" file accompanying this file. This file is * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF * ANY KIND, either express or implied. See the License for the specific * language governing permissions and limitations under the License. */ /** * Base error class for all FIDO2/WebAuthn related errors */ export declare class Fido2Error extends Error { readonly code: string; readonly cause?: unknown; /** * User-friendly message suitable for display to end users. * Uses passkey terminology and avoids technical jargon. */ readonly userMessage: string; constructor(message: string, code: string, userMessage?: string, cause?: unknown); } /** * Thrown when WebAuthn operation is cancelled/aborted by user or application * * Example: User closes passkey dialog, component unmounts during authentication */ export declare class Fido2AbortError extends Fido2Error { constructor(message?: string, userMessage?: string); } /** * Thrown when credential operations fail * * Examples: * - No credential returned from browser * - Invalid credential format * - Credential not found */ export declare class Fido2CredentialError extends Fido2Error { constructor(message: string, cause?: unknown, userMessage?: string); } /** * Thrown when FIDO2 configuration is missing or invalid * * Examples: * - Missing fido2 config in configure() * - Invalid baseUrl or rpId */ export declare class Fido2ConfigError extends Fido2Error { constructor(message: string, userMessage?: string); } /** * Thrown when validation of FIDO2 options or responses fails * * Examples: * - Invalid challenge format * - Missing required fields in server response * - Type mismatch in credential response */ export declare class Fido2ValidationError extends Fido2Error { readonly invalidValue?: unknown; constructor(message: string, invalidValue?: unknown, userMessage?: string); } /** * Thrown when authentication/authorization fails * * Examples: * - No JWT token available * - Token expired * - Insufficient permissions */ export declare class Fido2AuthError extends Fido2Error { constructor(message: string, userMessage?: string); } /** * Thrown when server/network requests fail * * Examples: * - HTTP error responses * - Network timeout * - Server unreachable */ export declare class Fido2NetworkError extends Fido2Error { readonly statusCode?: number | undefined; readonly response?: unknown; constructor(message: string, statusCode?: number | undefined, response?: unknown, userMessage?: string); } /** * Type guard to check if error is a Fido2Error */ export declare function isFido2Error(error: unknown): error is Fido2Error; /** * Type guard to check if error is an abort error */ export declare function isFido2AbortError(error: unknown): error is Fido2AbortError; /** * Helper to convert DOMException (from WebAuthn API) to appropriate Fido2Error * * Based on WebAuthn Level 2 specification: * - navigator.credentials.create() can throw: AbortError, ConstraintError, * InvalidStateError, NotSupportedError, SecurityError, NotAllowedError, UnknownError * - navigator.credentials.get() can throw: AbortError, InvalidStateError, * SecurityError, NotAllowedError, UnknownError */ export declare function fromDOMException(error: DOMException): Fido2Error;