import { AccountSigner, AccountSignerConfig, HexAddress } from "../../account-signer/types.js"; import { PolyesterEnvironment } from "../../environment.js"; import { AuthAndPublicApiTransports } from "../../shared/transports.js"; import { PolyesterRealtime } from "../../realtime/types.js"; import "../../realtime/index.js"; import { SubaccountChallenge } from "../subaccounts/subaccounts.schemas.js"; import { SubaccountsService } from "../subaccounts/subaccounts.js"; import { AuthService } from "./auth.js"; import { AuthTokenStorage } from "./token-storage.js"; import { AuthHydrationData, AuthLoginMethod, AuthState, SessionData } from "./session.types.js"; import { AuthSessionStore } from "./session.js"; import { EventEmitter } from "../../utils/event-emitter.js"; import "../subaccounts/index.js"; //#region src/services/auth/account-signer-auth.d.ts interface AccountSignerAuthEvents { authenticated: { accountId: string; username: string; }; loggedOut: void; error: { code: string; message: string; }; servicesReady: void; stateChange: AuthState; } interface LoginResult { accountId: string; username: string; expiresAt: Date; } interface LoginOptions { /** * The wallet provider to use for login. */ provider: SessionData["provider"]; /** Browser origin requesting the signature; defaults to location.origin in browsers. Required outside browsers. */ uri?: string; loginMethod?: AuthLoginMethod | null; } interface CreateSubaccountParams { /** * Signer for the new subaccount, or a factory that derives it from the server challenge * (for example via Turnkey with `challenge.smartAccountSaltNonce`). Its accountAddress must * equal `challenge.smartAccountAddress`. */ accountSigner: AccountSigner | ((challenge: SubaccountChallenge) => AccountSigner | Promise); /** Optional human-readable label for this subaccount */ label?: string; /** Browser origin requesting the signature; defaults to location.origin in browsers. Required outside browsers. */ uri?: string; /** Root owner EOA bound to the authenticated account; defaults to the configured signer's owner. */ ownerAddress?: HexAddress; } interface CreateSubaccountResult { subaccountId: string; smartAccountSaltNonce: number; revision: string; } /** A subaccounts service, or a loader that resolves it when a subaccount is first created. */ type SubaccountsServiceSource = SubaccountsService | (() => Promise); /** * Coordinates wallet/account-signer authentication, session storage, subaccount selection, and session refresh. */ declare class AccountSignerAuthService extends AuthService { #private; readonly events: EventEmitter; constructor({ transports, accountSignerConfig, environment, subaccounts, realtime, tokenStorage, sessionStore }: { transports: AuthAndPublicApiTransports; accountSignerConfig?: AccountSignerConfig; environment: PolyesterEnvironment; subaccounts: SubaccountsServiceSource; realtime: PolyesterRealtime; tokenStorage: AuthTokenStorage; sessionStore?: AuthSessionStore; }); /** * Attaches the subaccounts service used when creating a subaccount during authenticated flows. */ setSubaccountsService(subaccounts: SubaccountsService): void; /** * Sets the account signer used to sign login and account-switch challenges. */ setAccountSigner(accountSigner: AccountSigner | null): void; /** * Returns the active account signer, throwing if one has not been configured. */ getAccountSigner(): AccountSigner | null; /** * Signs a server-issued SIWE message with the configured account signer, exchanges it for a session token, and stores the hydrated account/subaccount session state. */ login(options: LoginOptions): Promise; /** * Builds auth state from a session token and optional active account override. */ hydrateAuthState(state: AuthHydrationData): void; /** * Loads the stored token, validates that it still belongs to this environment, and restores auth state when possible. */ restoreSession(): Promise<{ accountId: string; username: string; } | null>; /** * Clears stored auth state and removes the persisted auth token. */ logout(): Promise; /** * Ends the session after the backend rejected `token` as unauthenticated (revoked, * or expired despite a lagging local clock). Ignored when the token has since been * replaced or a login/refresh is in flight. Browser clients call this automatically. */ handleRejectedToken(token: string): void; /** * Returns the remaining lifetime of the stored session token in milliseconds. */ getSessionTimeToExpiry(): number; /** * Refreshes the active account-signer session and updates persisted auth state. */ refreshSession(params?: { /** Overrides the origin remembered from login. */ uri?: string; provider?: SessionData["provider"]; loginMethod?: AuthLoginMethod | null; }): Promise; /** * Switches the active account/subaccount by signing the required account switch flow. */ switchAccount(accountId: string, options?: { smartAccountAddress?: string; label?: string; }): { accountId: string; isMain: boolean; }; /** Keeps the display-session identity current for the next server render. */ syncSessionUsername(username: string | null): void; /** * Creates a subaccount for the authenticated account and makes it available to the session state. */ createSubaccount(params: CreateSubaccountParams): Promise; /** * Returns the current account-signer auth state snapshot. */ getState(): AuthState; } //#endregion export { AccountSignerAuthEvents, AccountSignerAuthService, CreateSubaccountParams, CreateSubaccountResult, LoginOptions, LoginResult, SubaccountsServiceSource }; //# sourceMappingURL=account-signer-auth.d.ts.map