@biconomy/passkey
Version:
Passkey validator plug in for Biconomy SDK
71 lines • 2.84 kB
TypeScript
import { type Hex } from "viem";
export declare enum WebAuthnMode {
Register = "register",
Login = "login"
}
export type WebAuthnKey = {
pubX: bigint;
pubY: bigint;
authenticatorId: string;
authenticatorIdHash: Hex;
};
type RequestCredentials = "include" | "omit" | "same-origin";
export type BaseWebAuthnAccountParams = {
rpID?: string;
webAuthnKey?: WebAuthnKey;
credentials?: RequestCredentials;
passkeyServerHeaders?: Record<string, string>;
};
export type RegisterWebAuthnAccountParams = BaseWebAuthnAccountParams & {
mode?: WebAuthnMode.Register;
passkeyName: string;
};
export type LoginWebAuthnAccountParams = BaseWebAuthnAccountParams & {
mode: WebAuthnMode.Login;
passkeyName?: string;
};
export type WebAuthnAccountParams = RegisterWebAuthnAccountParams | LoginWebAuthnAccountParams;
/**
* Encodes a WebAuthn public key into a concatenated hex string.
* The resulting hex string contains the X coordinate (32 bytes), Y coordinate (32 bytes),
* and the authenticator ID hash (32 bytes) of the WebAuthn key.
*
* @param pubKey - The WebAuthn key object containing public key coordinates and authenticator details
* @returns A hex string of the concatenated key components
*/
export declare const encodeWebAuthnPubKey: (pubKey: WebAuthnKey) => `0x${string}`;
/**
* Creates or retrieves a WebAuthn key for authentication or registration.
* This function handles both registration of new passkeys and authentication with existing ones.
*
* @param params - WebAuthn account parameters
* @param params.passkeyName - Name identifier for the passkey (required for registration)
* @param params.rpID - Relying Project ID (domain name)
* @param params.webAuthnKey - Existing WebAuthn key (if available)
* @param params.mode - Authentication mode ('register' or 'login')
* @param params.credentials - Request credentials mode ('include', 'omit', or 'same-origin')
* @param params.passkeyServerHeaders - Additional headers for passkey server requests
*
* @returns Promise resolving to a WebAuthnKey object containing:
* - pubX: X coordinate of the public key
* - pubY: Y coordinate of the public key
* - authenticatorId: Original authenticator ID
* - authenticatorIdHash: Keccak256 hash of the authenticator ID
*
* @throws Error if registration/login verification fails or if required key data is missing
*
* @example
* // Registration
* const key = await toWebAuthnKey({
* passkeyName: "my-passkey",
* mode: WebAuthnMode.Register
* });
*
* // Login
* const key = await toWebAuthnKey({
* mode: WebAuthnMode.Login
* });
*/
export declare const toWebAuthnKey: ({ passkeyName, rpID, webAuthnKey, mode, credentials, passkeyServerHeaders }: WebAuthnAccountParams) => Promise<WebAuthnKey>;
export {};
//# sourceMappingURL=toWebAuthnKey.d.ts.map