UNPKG

expo-passkey

Version:

Passkey authentication for Expo apps with Better Auth integration

190 lines 8.92 kB
/** * @file Core implementation of the Expo Passkey client * @module expo-passkey/client/core */ import type { BetterFetchOption, BetterFetchPlugin, ErrorContext } from "@better-fetch/fetch"; import type { AuthenticatePasskeyResult, ChallengeResult, ExpoPasskeyClientOptions, ExpoPasskeyServerPlugin, ListPasskeysResult, PasskeyMetadata, PasskeyRegistrationCheckResult, RegisterPasskeyResult, RevokePasskeyResult } from "../types"; /** * Creates an instance of the Expo Passkey client plugin with WebAuthn support * @param options Configuration options for the client plugin * @returns Better Auth client plugin instance */ export declare const expoPasskeyClient: (options?: ExpoPasskeyClientOptions) => { id: "expo-passkey"; $InferServerPlugin: ExpoPasskeyServerPlugin; pathMethods: { "/expo-passkey/challenge": "POST"; "/expo-passkey/register": "POST"; "/expo-passkey/authenticate": "POST"; "/expo-passkey/list/:userId": "GET"; "/expo-passkey/revoke": "POST"; }; getActions: ($fetch: import("@better-fetch/fetch").BetterFetch) => { /** * Gets a WebAuthn challenge from the server */ getChallenge: (data: { userId: string; type: "registration" | "authentication"; registrationOptions?: { attestation?: "none" | "indirect" | "direct" | "enterprise"; authenticatorSelection?: { authenticatorAttachment?: "platform" | "cross-platform"; residentKey?: "required" | "preferred" | "discouraged"; requireResidentKey?: boolean; userVerification?: "required" | "preferred" | "discouraged"; }; timeout?: number; }; }, fetchOptions?: BetterFetchOption) => Promise<ChallengeResult>; /** * Registers a new passkey for a user using WebAuthn */ registerPasskey: (data: { userId: string; userName: string; displayName?: string; rpName?: string; rpId?: string; attestation?: "none" | "indirect" | "direct" | "enterprise"; authenticatorSelection?: { authenticatorAttachment?: "platform" | "cross-platform"; residentKey?: "required" | "preferred" | "discouraged"; requireResidentKey?: boolean; userVerification?: "required" | "preferred" | "discouraged"; }; timeout?: number; metadata?: Partial<PasskeyMetadata>; }, fetchOptions?: BetterFetchOption) => Promise<RegisterPasskeyResult>; /** * Authenticates a user using a WebAuthn passkey */ authenticateWithPasskey: (data?: { userId?: string; rpId?: string; timeout?: number; userVerification?: "required" | "preferred" | "discouraged"; metadata?: Partial<PasskeyMetadata>; }, fetchOptions?: BetterFetchOption) => Promise<AuthenticatePasskeyResult>; /** * Lists passkeys for a user */ listPasskeys: (data: { userId: string; limit?: number; offset?: number; }, fetchOptions?: BetterFetchOption) => Promise<ListPasskeysResult>; /** * Revokes a passkey */ revokePasskey: (data: { userId: string; credentialId: string; reason?: string; }, fetchOptions?: BetterFetchOption) => Promise<RevokePasskeyResult>; /** * Checks if passkey registration exists for a user */ checkPasskeyRegistration: (userId: string, fetchOptions?: BetterFetchOption) => Promise<PasskeyRegistrationCheckResult>; /** * Checks if passkeys are supported on this device */ isPasskeySupported: () => Promise<boolean>; /** * Gets biometric information for the device */ getBiometricInfo: () => Promise<import("../types").BiometricSupportInfo>; /** * Gets device information */ getDeviceInfo: () => Promise<import("../types").DeviceInfo>; /** * Gets the storage keys used by the plugin */ getStorageKeys: () => { DEVICE_ID: string; STATE: string; USER_ID: string; CREDENTIAL_IDS: string; }; /** * Checks if this device has any registered passkeys */ hasPasskeysRegistered: () => Promise<boolean>; /** * Checks if a specific user has registered passkeys on this device */ hasUserPasskeysRegistered: (userId: string) => Promise<boolean>; /** * Helper function to remove a credential ID from local storage */ removeLocalCredential: (credentialId: string) => Promise<void>; }; fetchPlugins: { id: string; name: string; description: string; version: string; hooks: { onError: (context: ErrorContext) => Promise<void>; }; init: (url: string, options?: BetterFetchOption) => Promise<{ url: string; options: { cache?: RequestCache | undefined; credentials?: RequestCredentials | undefined; headers?: (HeadersInit & (HeadersInit | { accept: "application/json" | "text/plain" | "application/octet-stream"; "content-type": "application/json" | "text/plain" | "application/x-www-form-urlencoded" | "multipart/form-data" | "application/octet-stream"; authorization: "Bearer" | "Basic"; })) | undefined; integrity?: string | undefined; keepalive?: boolean | undefined; method?: string | undefined; mode?: RequestMode | undefined; priority?: RequestPriority | undefined; redirect?: RequestRedirect | undefined; referrer?: string | undefined; referrerPolicy?: ReferrerPolicy | undefined; signal?: (AbortSignal | null) | undefined; window?: null | undefined; onRequest?: (<T extends Record<string, any>>(context: import("@better-fetch/fetch").RequestContext<T>) => Promise<import("@better-fetch/fetch").RequestContext | void> | import("@better-fetch/fetch").RequestContext | void) | undefined; onResponse?: ((context: import("@better-fetch/fetch").ResponseContext) => Promise<Response | void | import("@better-fetch/fetch").ResponseContext> | Response | import("@better-fetch/fetch").ResponseContext | void) | undefined; onSuccess?: ((context: import("@better-fetch/fetch").SuccessContext<any>) => Promise<void> | void) | undefined; onError?: ((context: ErrorContext) => Promise<void> | void) | undefined; onRetry?: ((response: import("@better-fetch/fetch").ResponseContext) => Promise<void> | void) | undefined; hookOptions?: { cloneResponse?: boolean; } | undefined; timeout?: number | undefined; customFetchImpl?: import("@better-fetch/fetch").FetchEsque | undefined; plugins?: BetterFetchPlugin[] | undefined; baseURL?: string | undefined; throw?: boolean | undefined; auth?: ({ type: "Bearer"; token: string | Promise<string | undefined> | (() => string | Promise<string | undefined> | undefined) | undefined; } | { type: "Basic"; username: string | (() => string | undefined) | undefined; password: string | (() => string | undefined) | undefined; } | { type: "Custom"; prefix: string | (() => string | undefined) | undefined; value: string | (() => string | undefined) | undefined; }) | undefined; body?: any; query?: any; params?: any; duplex?: "full" | "half" | undefined; jsonParser?: ((text: string) => Promise<any> | any) | undefined; retry?: import("@better-fetch/fetch").RetryOptions | undefined; retryAttempt?: number | undefined; output?: (import("@better-fetch/fetch").StandardSchemaV1 | typeof Blob | typeof File) | undefined; errorSchema?: import("@better-fetch/fetch").StandardSchemaV1 | undefined; disableValidation?: boolean | undefined; } | undefined; }>; }[]; }; //# sourceMappingURL=core.native.d.ts.map