/** * Authentication Manager * * Handles all authentication-related logic for Eufy Security clients, * including CAPTCHA challenges, 2FA verification, and authentication state management. * * This service encapsulates: * - Authentication state tracking (none, captcha_required, mfa_required) * - CAPTCHA and MFA data management * - User input handling for auth challenges * - WebSocket event listeners for auth events * - Post-authentication device discovery coordination * * @module authentication-manager */ import { Logger, ILogObj } from "tslog"; import { ApiManager } from "./api-manager"; import { StartListeningResponse } from "./server/responses"; /** * Authentication state constants */ export declare const AUTH_STATE: { readonly NONE: "none"; readonly CAPTCHA_REQUIRED: "captcha_required"; readonly MFA_REQUIRED: "mfa_required"; }; /** * Authentication state type derived from constants */ export type AuthState = (typeof AUTH_STATE)[keyof typeof AUTH_STATE]; /** * CAPTCHA challenge data */ export interface CaptchaData { captchaId: string; captcha: string; } /** * MFA challenge data */ export interface MfaData { methods: string[]; } /** * Callback for when authentication state changes (to update UI) */ export type AuthStateChangeCallback = () => void; /** * Callback for device registration after successful authentication */ export type DeviceRegistrationCallback = (result: StartListeningResponse) => Promise; /** * Authentication Manager * * Centralizes all authentication logic, making it easier to: * - Test authentication flows independently * - Reuse authentication logic across different client implementations * - Maintain clear separation of concerns * * @example * ```typescript * const authManager = new AuthenticationManager( * wsClient, * logger, // tslog Logger instance * () => updateUI(), * async (result) => await registerDevices(result) * ); * * // Check for pending auth after connection * await authManager.checkPendingAuth(); * * // Get auth state for UI * const state = authManager.getAuthState(); * const message = authManager.getAuthStatusMessage(true); * * // Handle user input * authManager.updateCaptchaCode("ABC123"); * await authManager.submitCaptcha(); * ``` */ export declare class AuthenticationManager { private wsClient; private logger; private authState; private captchaData; private mfaData; private currentCaptchaCode; private currentVerifyCode; private onStateChange; private onDeviceRegistration; constructor(wsClient: ApiManager, logger: Logger, onStateChange: AuthStateChangeCallback, onDeviceRegistration: DeviceRegistrationCallback); /** * Get current authentication state */ getAuthState(): AuthState; /** * Get current CAPTCHA data (if any) */ getCaptchaData(): CaptchaData | null; /** * Get current MFA data (if any) */ getMfaData(): MfaData | null; /** * Get current CAPTCHA code input */ getCurrentCaptchaCode(): string; /** * Get current verification code input */ getCurrentVerifyCode(): string; /** * Update CAPTCHA code input (called on every keystroke) */ updateCaptchaCode(code: string): void; /** * Update verification code input (called on every keystroke) */ updateVerifyCode(code: string): void; /** * Get a user-friendly authentication status message */ getAuthStatusMessage(isDriverConnected: boolean): string; /** * Check for pending authentication challenges after connection attempt */ checkPendingAuth(): Promise; /** * Submit CAPTCHA code */ submitCaptcha(): Promise; /** * Submit 2FA verification code */ submitVerifyCode(): Promise; /** * Request a new verification code */ requestNewCode(): Promise; /** * Reset authentication state (on successful connection) */ resetAuthState(): void; /** * Set up WebSocket event listeners for authentication events */ private setupEventListeners; /** * Check authentication state after CAPTCHA submission * May transition to 2FA if required, or complete authentication */ private checkPostCaptchaState; /** * Check authentication state after 2FA verification * Completes authentication and discovers devices if successful */ private checkPostVerificationState; } //# sourceMappingURL=authentication-manager.d.ts.map