@teamhanko/hanko-frontend-sdk
Version:
A package for simplifying UI integration with the Hanko API. It is meant for use in browsers only.
48 lines (47 loc) • 2.73 kB
TypeScript
import { CredentialRequestOptionsJSON, CredentialCreationOptionsJSON, PublicKeyCredentialWithAssertionJSON, PublicKeyCredentialWithAttestationJSON } from "@github/webauthn-json";
/**
* Manages WebAuthn credential operations as a singleton, ensuring only one active request at a time.
* Uses an internal AbortController to cancel previous requests when a new one is initiated.
*/
declare class WebauthnManager {
private static instance;
private abortController;
private constructor();
/**
* Gets the singleton instance of WebauthnManager.
* Creates a new instance if one doesn't exist, otherwise returns the existing one.
* @returns {WebauthnManager} The singleton instance
*/
static getInstance(): WebauthnManager;
/**
* Creates a new abort signal, aborting any ongoing WebAuthn request.
* @private
* @returns {AbortSignal} The new abort signal
*/
private createAbortSignal;
/**
* Retrieves a WebAuthn credential using the provided options.
* Aborts any previous request before starting a new one.
* @param {CredentialRequestOptionsJSON} options - The options for credential retrieval
* @returns {Promise<PublicKeyCredentialWithAssertionJSON>} A promise resolving to the retrieved credential
* @throws {DOMException} If the WebAuthn request fails (e.g., aborted, not allowed)
*/
getWebauthnCredential(options: CredentialRequestOptionsJSON): Promise<PublicKeyCredentialWithAssertionJSON>;
/**
* Retrieves a WebAuthn credential with conditional UI mediation.
* Aborts any previous request before starting a new one.
* @param {CredentialRequestOptionsJSON} publicKey - The public key options for conditional retrieval
* @returns {Promise<PublicKeyCredentialWithAssertionJSON>} A promise resolving to the retrieved credential
* @throws {DOMException} If the WebAuthn request fails (e.g., aborted, not allowed)
*/
getConditionalWebauthnCredential(publicKey: CredentialRequestOptionsJSON["publicKey"]): Promise<PublicKeyCredentialWithAssertionJSON>;
/**
* Creates a new WebAuthn credential using the provided options.
* Aborts any previous request before starting a new one.
* @param {CredentialCreationOptionsJSON} options - The options for credential creation
* @returns {Promise<PublicKeyCredentialWithAttestationJSON>} A promise resolving to the created credential
* @throws {DOMException} If the WebAuthn request fails (e.g., aborted, not allowed)
*/
createWebauthnCredential(options: CredentialCreationOptionsJSON): Promise<PublicKeyCredentialWithAttestationJSON>;
}
export default WebauthnManager;