/** * Alternate paths used by the SDK to route API calls to your proxy server. */ interface WebauthnApis { /** * @defaultValue `/v1/auth/webauthn/authenticate/start` */ startAuthentication: string; /** * @defaultValue `/v1/auth/webauthn/register/start` */ startRegistration: string; /** * @defaultValue `/v1/auth/webauthn/cross-device/register/start` */ startCrossDeviceRegistration: string; /** * @defaultValue `/v1/auth/webauthn/cross-device/authenticate/init` */ initCrossDeviceAuthentication: string; /** * @defaultValue `/v1/auth/webauthn/cross-device/authenticate/start` */ startCrossDeviceAuthentication: string; /** * @defaultValue `/v1/auth/webauthn/cross-device/status` */ getCrossDeviceTicketStatus: string; /** * @defaultValue `/v1/auth/webauthn/cross-device/attach-device` */ attachDeviceToCrossDeviceSession: string; } /** * @private */ interface WebAuthnInitOptions { /** * Base path for sending API requests. This would be either a Transmit Security API deployment URL * such as documented for sandbox, or if you are proxying API requests from your backend - then the base path to your proxy. */ serverPath: string; /** * Override endpoints when using a proxy server in case the proxy server implements its own paths. */ webauthnApiPaths?: WebauthnApis; } /** * WebAuthn cross device interfaces */ declare enum WebauthnCrossDeviceStatus { Pending = "pending", Scanned = "scanned", Success = "success", Error = "error", Timeout = "timeout", Aborted = "aborted" } /** * WebAuthn cross device handlers interfaces */ interface CrossDeviceController { /** * Ticket ID for this cross-device flow. */ crossDeviceTicketId: string; /** * Stops listening for events from devices in cross-device flows */ stop: () => void; } /** * WebAuthn cross device status response interfaces */ interface ApiCrossDeviceStatusResponse { /** * cross device status */ status: WebauthnCrossDeviceStatus; /** * authentication session id */ session_id?: string; } /** * WebAuthn cross device attach device result interfaces */ interface AttachDeviceResult { /** * cross device status */ status: WebauthnCrossDeviceStatus; /** * ticket creation timestamp */ startedAt: string; /** * session's approval data (if exists) */ approvalData?: Record; } interface BaseCrossDeviceHandlers { /** * Called when the user has successfully attached a device to the cross-device flow using the {@link WebauthnCrossDeviceFlows.attachDevice} method. */ onDeviceAttach: () => Promise; /** * Called when there was an error in the cross-device flow with status response {@link ApiCrossDeviceStatusResponse}. */ onFailure: (error: ApiCrossDeviceStatusResponse) => Promise; } interface CrossDeviceAuthenticationHandlers extends BaseCrossDeviceHandlers { /** * Called upon successful webauthn authentication. * @param sessionId Session ID that will be exchanged for the user's access and ID tokens using the /v1/auth/session/authenticate API */ onCredentialAuthenticate: (sessionId: string) => Promise; } interface CrossDeviceRegistrationHandlers extends BaseCrossDeviceHandlers { /** * Called upon successful webauthn registration. */ onCredentialRegister: () => Promise; } interface WebauthnCrossDeviceRegistrationOptions { /** * Allow registration using cross-platform authenticators, such as a USB security key or a different device. If enabled, cross-device authentication flows can be performed using the native browser experience (via QR code). default: True */ allowCrossPlatformAuthenticators?: boolean; /** * Must be set to true to register credentials as passkeys when supported (except for Apple devices, which always register credentials as passkeys). default: True */ registerAsDiscoverable?: boolean; } interface WebauthnRegistrationOptions extends WebauthnCrossDeviceRegistrationOptions { /** * Human-palatable name for the user account, only for display (max 64 characters). If not set, the username parameter will also act as the display name */ displayName?: string; /** * The timeout in seconds for the registration process. If the timeout is reached, the registration process will be aborted with error {@link ErrorCode.RegistrationAbortedTimeout}. */ timeout?: number; /** * Set to True in order to limit the creation of multiple credentials for the same account on a single authenticator. default: False */ limitSingleCredentialToDevice?: boolean; } interface WebauthnCrossDeviceFlows { /** * Initializes a cross device flow, such as when users request to login to a desktop using their mobile device. Once invoked, the SDK will start listening for events occurring on the other device, * and calls your handlers when a state change is detected. * These methods return a promise that resolves to a {@link CrossDeviceController} object, which allows you to stop listening to events and includes the cross-device ticket ID which is used when attaching another device to the flow. */ init: { /** * Start a cross device registration flow * This call receives a cross-device ticket ID, and a {@link CrossDeviceRegistrationHandlers} instance that contains your handlers for cross device events. * For example, these handlers may update the UI or any other relevant application state. * @throws {@link ErrorCode.NotInitialized} * @returns {@link CrossDeviceController} - Object that allows you to stop the event loop, and obtain the cross-device ticket ID. */ registration: (params: { crossDeviceTicketId: string; handlers: CrossDeviceRegistrationHandlers; }) => Promise; /** * Start a cross device authentication flow * This call receives an optional username (if already known), and a {@link CrossDeviceAuthenticationHandlers} instance that contains your handlers for cross device events. * For example, these handlers may update the UI or any other relevant application state. * If username isn't provided, it will promote a modal with a list of all discoverable credentials on the attached device. If username is provided, this call must be invoked for a registered username. * If the target username is not registered, an SdkError will be thrown when trying to authenticate in the attached device.
* @throws {@link ErrorCode.NotInitialized} * @throws {@link ErrorCode.FailedToInitCrossDeviceSession} * @returns {@link CrossDeviceController} - Object that allows you to stop the event loop, and obtain the cross-device ticket ID. */ authentication: (params: { username?: string; handlers: CrossDeviceAuthenticationHandlers; }) => Promise; /** * Start a cross device approval flow * This call receives a optional username, approval data (data to be signed using a passkey), and a {@link CrossDeviceAuthenticationHandlers} instance that contains your handlers for cross device events. * For example, these handlers may update the UI or any other relevant application state. * This call must be invoked for a registered username. * If the target username is not registered, an SdkError will be thrown when trying to authenticate in the attached device.
* @throws {@link ErrorCode.NotInitialized} * @throws {@link ErrorCode.InvalidApprovalData} * @throws {@link ErrorCode.FailedToInitCrossDeviceSession} * @returns {@link CrossDeviceController} - Object that allows you to stop the event loop, and obtain the cross-device ticket ID. */ approval: (params: { username: string; approvalData: Record; handlers: CrossDeviceAuthenticationHandlers; }) => Promise; }; authenticate: { /** * Invokes a WebAuthn authentication for the user used in the cross device session init, including prompting the user to select from a list of registered credentials, and then prompting the user for biometrics. The credentials list is displayed using the native browser modal.
* If authentication is completed successfully, this call will return a promise that resolves to the credential result, which is an object encoded as a base64 string. This encoded result should then be passed to the [backend authentication endpoint](/openapi/user/backend-webauthn/#operation/authenticateWebauthnCredential) to retrieve user tokens.
* Once tokens are retrieved, {@link CrossDeviceAuthenticationHandlers.onCredentialAuthenticate} will be called with a session ID that can also be used to retrieve tokens. * @param crossDeviceTicketId Ticket ID of the cross-device flow. retrieved from the {@link CrossDeviceController} object. * @throws {@link ErrorCode.NotInitialized} * @throws {@link ErrorCode.AuthenticationFailed} * @throws {@link ErrorCode.AuthenticationCanceled} * @returns Base64-encoded object, which contains the credential result. This encoded result will be used to fetch user tokens via the [backend authentication endpoint](/openapi/user/backend-webauthn/#operation/authenticateWebauthnCredential). */ modal: (crossDeviceTicketId: string) => Promise; }; approve: { /** * Invokes a WebAuthn approval for the user used in the cross device session init, including prompting the user to select from a list of registered credentials, and then prompting the user for biometrics. The credentials list is displayed using the native browser modal.
* If authentication is completed successfully, this call will return a promise that resolves to the credential result, which is an object encoded as a base64 string. This encoded result should then be passed to the [backend authentication endpoint](/openapi/user/backend-webauthn/#operation/authenticateWebauthnCredential) to retrieve user tokens.
* Once tokens are retrieved, {@link CrossDeviceAuthenticationHandlers.onCredentialAuthenticate} will be called with a session ID that can also be used to retrieve tokens. * @param crossDeviceTicketId Ticket ID of the cross-device flow. retrieved from the {@link CrossDeviceController} object. * @throws {@link ErrorCode.NotInitialized} * @throws {@link ErrorCode.AuthenticationFailed} * @throws {@link ErrorCode.AuthenticationCanceled} * @returns Base64-encoded object, which contains the credential result. This encoded result will be used to fetch user tokens via the [backend authentication endpoint](/openapi/user/backend-webauthn/#operation/authenticateWebauthnCredential). */ modal: (crossDeviceTicketId: string) => Promise; }; /** * Invokes a WebAuthn credential registration for the user used in the cross device session init, including prompting the user for biometrics. * If registration is completed successfully, this call will return a promise that resolves to the credential result, which is an object encoded as a base64 string. This encoded result should then be passed to the relevant backend registration endpoint to complete the registration for either a [logged-in user](/openapi/user/backend-webauthn/#operation/webauthn-registration) or [logged-out user](/openapi/user/backend-webauthn/#operation/webauthn-registration-external). * If registration fails, an SdkError will be thrown. * If the backend registration call was successful, {@link CrossDeviceRegistrationHandlers.onCredentialRegister} will be called. * @param crossDeviceTicketId Ticket ID of the cross-device flow. retrieved from the {@link CrossDeviceController} object. * @param options Additional configuration for registration flow * @throws {@link ErrorCode.NotInitialized} * @throws {@link ErrorCode.RegistrationFailed} * @throws {@link ErrorCode.RegistrationCanceled} */ register: (params: { crossDeviceTicketId: string; options?: WebauthnCrossDeviceRegistrationOptions; }) => Promise; /** * Indicates when a session is accepted on another device in cross-device flows. * * If successful,{@link CrossDeviceRegistrationHandlers.onDeviceAttach} will be called in registration flow and {@link CrossDeviceAuthenticationHandlers.onDeviceAttach} for authentication. * @param crossDeviceTicketId Ticket ID of the cross-device flow. retrieved from the {@link CrossDeviceController} object. * @returns AttachDeviceResult {@link AttachDeviceResult}. Object containing the ticket status, creation timestamp, and approval data (if passed in the init.authentication() call) */ attachDevice: (crossDeviceTicketId: string) => Promise; } /** * @enum */ declare enum ErrorCode { /** * Either the SDK init call failed or another function was called before initializing the SDK */ NotInitialized = "not_initialized", /** * When the call to {@link WebauthnApis.startAuthentication} failed */ AuthenticationFailed = "authentication_failed", /** * When {@link WebauthnAuthenticationFlows.modal authenticate.modal} or {@link AutofillHandlers.activate authenticate.autofill.activate} is called and the modal is closed by the user */ AuthenticationAbortedTimeout = "authentication_aborted_timeout", /** * When {@link register} is called and the modal is closed when reaching the timeout */ AuthenticationCanceled = "webauthn_authentication_canceled", /** * When the call to {@link WebauthnApis.startRegistration} failed */ RegistrationFailed = "registration_failed", /** / When The user attempted to register an authenticator that contains one of the credentials already registered with the relying party. */ AlreadyRegistered = "username_already_registered", /** * When {@link register} is called and the modal is closed by the user */ RegistrationAbortedTimeout = "registration_aborted_timeout", /** * When {@link register} is called and the modal is closed when reaching the timeout */ RegistrationCanceled = "webauthn_registration_canceled", /** * Passkey autofill authentication was aborted by {@link AutofillHandlers.abort} */ AutofillAuthenticationAborted = "autofill_authentication_aborted", /** * Passkey authentication is already active. To start a new authentication, abort the current one first by calling {@link AutofillHandlers.abort} */ AuthenticationProcessAlreadyActive = "authentication_process_already_active", /** * The ApprovalData parameter was sent in the wrong format */ InvalidApprovalData = "invalid_approval_data", /** * When the call to {@link WebauthnApis.initCrossDeviceAuthentication} failed */ FailedToInitCrossDeviceSession = "cross_device_init_failed", /** * When the call to {@link WebauthnApis.getCrossDeviceTicketStatus} failed */ FailedToGetCrossDeviceStatus = "cross_device_status_failed", /** * When the SDK operation fails on an unhandled error */ Unknown = "unknown" } /** * Common interface for `Promise` rejections. * Developers should handle according to the `errorCode` */ interface SdkError { /** * Error code from {@link ErrorCode} */ readonly errorCode: ErrorCode; /** * Error message */ readonly message: string; /** * Additional data */ readonly data?: any; } interface AuthenticationAutofillActivateHandlers { /** * A Callback function that will be triggered once biometrics signing is completed successfully. * @param webauthn_encoded_result */ onSuccess: (webauthn_encoded_result: string) => Promise; /** * A Callback function that will be triggered if authentication fails with an SdkError. * @param err */ onError?: (err: SdkError) => Promise; /** * A Callback function that will be triggered when challenge excepted from the service and autofill is ready to use. */ onReady?: () => void; } interface AutofillHandlers { /** * Invokes a WebAuthn authentication, including prompting the user to select from a list of registered credentials using autofill, and then prompting the user for biometrics. In order to prompt this credentials list, the autocomplete="username webauthn" attribute **must** be defined on the username input box of the authentication page.
* If authentication is completed successfully, the `onSuccess` callback will be triggered with the credential result, which is an object encoded as a base64 string. This encoded result should then be passed to the [backend authentication endpoint](/openapi/user/backend-webauthn/#operation/authenticateWebauthnCredential) to retrieve user tokens.
* If it fails, the `onError` callback will be triggered with an SdkError. * @param params.handlers - Handlers that will be invoked once the authentication is completed (success or failure) * @param params.username - Name of user account, as used in the WebAuthn registration. If not provided, the authentication will start without the context of a user and it will be inferred by the chosen passkey * @throws {@link ErrorCode.NotInitialized} * @throws {@link ErrorCode.AuthenticationFailed} * @throws {@link ErrorCode.AuthenticationCanceled} * @throws {@link ErrorCode.AutofillAuthenticationAborted} */ activate(params: { handlers: AuthenticationAutofillActivateHandlers; username?: string; }): void; /** * Aborts a WebAuthn authentication. This method should be called after the passkey autofill is dismissed in order to be able to query existing passkeys once again. This will end the browser's `navigator.credentials.get()` operation. */ abort(): void; } interface WebauthnAuthenticationOptions { /** * The timeout in seconds for the authentication process. If the timeout is reached, the registration process will be aborted with error {@link ErrorCode.AuthenticationAbortedTimeout}. */ timeout?: number; } interface WebauthnAuthenticationFlows { /** * Invokes a WebAuthn authentication, including prompting the user to select from a list of registered credentials, and then prompting the user for biometrics. The credentials list is displayed using the native browser modal.
* If username isn't provided, it will promote a modal with a list of all discoverable credentials on the device. If username is provided, this call must be invoked for a registered username. If the target username is not registered or in case of any other failure, an SdkError will be thrown.
* If authentication is completed successfully, this call will return a promise that resolves to the credential result, which is an object encoded as a base64 string. This encoded result should then be passed to the [backend authentication endpoint](/openapi/user/backend-webauthn/#operation/authenticateWebauthnCredential) to retrieve user tokens.
* * @param params.username - Name of user account, as used in the WebAuthn registration. If not provided, the authentication will start without the context of a user and it will be inferred by the chosen passkey * @param params.options - Options for the authentication process * @param params.identifier - Identifier value (email, phone number, user ID, or custom identifier). Mutually exclusive with username. * @param params.identifierType - Type of identifier (email, phone_number, user_id, username, or custom identifier type). Required when using identifier. * @throws {@link ErrorCode.NotInitialized} * @throws {@link ErrorCode.AuthenticationFailed} * @throws {@link ErrorCode.AuthenticationCanceled} * @throws {@link ErrorCode.InvalidApprovalData} * @throws {@link ErrorCode.AuthenticationProcessAlreadyActive} * @returns Base64-encoded object, which contains the credential result. This encoded result will be used to fetch user tokens via the [backend authentication endpoint](/openapi/user/backend-webauthn/#operation/authenticateWebauthnCredential). */ modal(params: { username?: string; options?: WebauthnAuthenticationOptions; } | { identifier?: string; identifierType?: string; options?: WebauthnAuthenticationOptions; }): Promise; /** * Property used to implement credential selection via autofill UI. */ autofill: AutofillHandlers; } interface WebauthnApprovalFlows { /** * Invokes a WebAuthn approval, including prompting the user to select from a list of registered credentials, and then prompting the user for biometrics. The credentials list is displayed using the native browser modal.
* This call must be invoked for a registered username. If the target username is not registered or in case of any other failure, an SdkError will be thrown.
* If approval is completed successfully, this call will return a promise that resolves to the credential result, which is an object encoded as a base64 string. This encoded result should then be passed to the [backend authentication endpoint](/openapi/user/backend-webauthn/#operation/authenticateWebauthnCredential) to retrieve user tokens.
* @param params.username Name of user account, as used in the WebAuthn registration. * @param params.approvalData Data that represents the approval to be signed with a passkey * @throws {@link ErrorCode.NotInitialized} * @throws {@link ErrorCode.InvalidApprovalData} * @throws {@link ErrorCode.AuthenticationFailed} * @throws {@link ErrorCode.AuthenticationCanceled} * @throws {@link ErrorCode.AuthenticationProcessAlreadyActive} * @returns Base64-encoded object, which contains the credential result. This encoded result will be used to fetch user tokens via the [backend authentication endpoint](/openapi/user/backend-webauthn/#operation/authenticateWebauthnCredential). */ modal(params: { username: string | undefined; approvalData: Record; }): Promise; } declare module '@transmit-security/web-sdk-common/dist/module-metadata/module-metadata' { interface initConfigParams { webauthn?: WebAuthnInitOptions; } } /** * Returns the authentication flows for webauthn */ declare const authenticate: WebauthnAuthenticationFlows; declare const approve: WebauthnApprovalFlows; /** * Invokes a WebAuthn credential registration for the specified user, including prompting the user for biometrics. * If registration is completed successfully, this call will return a promise that resolves to the credential result, which is an object encoded as a base64 string. This encoded result should then be passed to the relevant backend registration endpoint to complete the registration for either a [logged-in user](/openapi/user/backend-webauthn/#operation/webauthn-registration) or [logged-out user](/openapi/user/backend-webauthn/#operation/webauthn-registration-external). * * If registration fails, an SdkError will be thrown. * * @param params.username - WebAuthn username to register * @param params.options - Additional configuration for registration flow * @throws {@link ErrorCode.NotInitialized} * @throws {@link ErrorCode.RegistrationFailed} * @throws {@link ErrorCode.RegistrationCanceled} */ declare function register(params: { username: string; options?: WebauthnRegistrationOptions; }): Promise; /** * Returns webauthn cross device flows * @type WebauthnCrossDeviceFlows */ declare const crossDevice: WebauthnCrossDeviceFlows; /** * Indicates whether this browser supports WebAuthn, and has a platform authenticator */ declare const isPlatformAuthenticatorSupported: () => Promise; /** * Indicates whether this browser supports Passkey Autofill */ declare const isAutofillSupported: () => Promise; /** * Returns the default API paths for webauthn */ declare const getDefaultPaths: () => WebauthnApis; declare const PACKAGE_VERSION: string; declare function initialize(config: any): void; export { ApiCrossDeviceStatusResponse, AttachDeviceResult, AuthenticationAutofillActivateHandlers, AutofillHandlers, CrossDeviceAuthenticationHandlers, CrossDeviceController, CrossDeviceRegistrationHandlers, ErrorCode, PACKAGE_VERSION, SdkError, WebauthnApis, WebauthnApprovalFlows, WebauthnAuthenticationFlows, WebauthnAuthenticationOptions, WebauthnCrossDeviceFlows, WebauthnCrossDeviceRegistrationOptions, WebauthnCrossDeviceStatus, WebauthnRegistrationOptions, approve, authenticate, crossDevice, getDefaultPaths, initialize, isAutofillSupported, isPlatformAuthenticatorSupported, register };