import { RialoClientConfig, RialoClient } from '@rialo/ts-cdk'; import { Store } from '@tanstack/store'; import { IdentifierString, WalletAccount, Wallet } from '@wallet-standard/base'; /** Discovered wallet metadata */ interface WalletEntity { /** Display name of the wallet */ readonly name: string; /** Base64-encoded wallet icon (data URI) */ readonly icon?: string; /** Chains supported by this wallet */ readonly chains: readonly IdentifierString[]; /** Feature identifiers supported by this wallet */ readonly features: readonly string[]; /** Wallet version if reported */ readonly installedVersion?: string; /** UI sort priority (higher = first) */ priority?: number; /** Timestamp of last successful connection */ lastConnectedAt?: number; } /** User account from wallet */ interface AccountEntity { /** Base58-encoded address */ readonly address: string; /** Raw public key bytes */ readonly publicKey: Uint8Array; /** Name of the wallet this account belongs to */ readonly walletName: string; /** Chains this account is valid for */ readonly chains: readonly IdentifierString[]; /** Optional user-defined label */ readonly label?: string; /** * @internal Raw wallet-standard account reference. * Required for signing operations. Not serialized to storage. */ readonly _raw?: WalletAccount; } /** Connection status */ type ConnectionStatus = "disconnected" | "connecting" | "connected" | "reconnecting"; /** Complete application state */ interface FrostAppState { /** Current connection status */ status: ConnectionStatus; /** Target chain ID for transactions */ chainId: string; /** Name of the currently connected wallet (null when disconnected) */ walletName: string | null; /** Address of the currently active account (null when disconnected) */ accountAddress: string | null; /** Timestamp when connection was established */ connectedAt: number | null; /** Timestamp when session expires (for auto-disconnect) */ sessionExpiresAt: number | null; /** Timestamp of last user activity (for idle timeout) */ lastUsedAt: number; /** Whether user explicitly disconnected (prevents auto-reconnect until next connect) */ userDisconnected: boolean; /** Map of wallet name -> WalletEntity */ wallets: Map; /** Map of address -> AccountEntity */ accounts: Map; /** Internal: Wallet runtime references (not serialized) */ _walletRefs: Map; } declare class WalletEventBridge { private readonly config; private readonly subscriptions; constructor(config: FrostConfig); subscribeToWallet(wallet: Wallet): void; unsubscribeFromWallet(walletName: string): void; private handleAccountChange; destroy(): void; } declare class WalletRegistry { private readonly config; private unsubscribe?; private readyPromise; private readyResolve; constructor(config: FrostConfig); private initialize; /** * Register a wallet if it supports Rialo chains * @returns true if wallet was registered (supports Rialo) */ private registerWallet; private unregisterWallet; /** Wait for a specific wallet to be discovered */ waitForWallet(name: string, options?: { timeout?: number; }): Promise; /** Promise that resolves when at least one Rialo wallet is discovered */ get ready(): Promise; /** Check if any wallets have been discovered */ get isReady(): boolean; destroy(): void; } /** * Creates a persistence manager for a specific config instance. * This encapsulates the debounce timeout per-config to avoid shared state issues. */ interface PersistenceManager { persist(state: FrostAppState): void; clear(): void; destroy(): void; } interface CreateConfigOptions { /** * Client configuration for the RPC client. * * Use one of the preset chains with `getDefaultRialoClientConfig()` or create * a custom config with your own chain definition and transport settings. * * @example * ```ts * import { getDefaultRialoClientConfig } from '@rialo/ts-cdk'; * * // Using preset config * createConfig({ clientConfig: getDefaultRialoClientConfig('devnet') }) * * // Using custom RPC URL * createConfig({ * clientConfig: { * chain: { * id: 'rialo:mainnet', * name: 'Mainnet', * rpcUrl: 'https://my-quicknode-endpoint.com', * }, * transport: { timeout: 30000 } * } * }) * ``` */ clientConfig: RialoClientConfig; /** Auto-reconnect on page load (default: true) */ autoConnect?: boolean; /** Session TTL in milliseconds (default: 7 days) */ sessionTTL?: number; /** Storage key prefix (default: 'rialo-frost') */ storageKey?: string; /** Custom storage implementation (default: localStorage) */ storage?: Storage | null; } /** Required config options after defaults are applied */ type ResolvedConfigOptions = Readonly>; interface FrostConfig { /** Core reactive store */ readonly store: Store; /** * RPC client for blockchain queries and transactions. * Use `switchChain()` to switch to a different chain. */ readonly client: RialoClient; /** * Get the current chain identifier from the client. * This is the single source of truth for chain ID. */ getChainId(): string; /** * Switch to a different chain/network. * Creates a new RPC client and updates the store's chainId. * * @param clientConfig - New client configuration (chain, endpoint, transport) */ switchChain(clientConfig: RialoClientConfig): void; /** Internal: Wallet discovery service */ _registry: WalletRegistry | null; /** Internal: Wallet event handler */ _bridge: WalletEventBridge | null; /** Internal: Persistence manager */ _persistence: PersistenceManager | null; /** Resolved configuration options */ readonly options: ResolvedConfigOptions; /** Cleanup all subscriptions and resources */ destroy(): void; } /** * Creates a Frost configuration object. * * **Important:** Create the config outside of React components to ensure * it's only created once and remains stable across re-renders. * * @param options - Configuration options including client config and optional settings * @returns A Frost configuration object to be passed to `FrostProvider` * * @example * ```ts * import { createConfig, getDefaultRialoClientConfig } from '@rialo/frost'; * * export const config = createConfig({ * clientConfig: getDefaultRialoClientConfig('devnet'), * autoConnect: true, * }); * ``` */ declare function createConfig(options: CreateConfigOptions): FrostConfig; /** * Initializes wallet discovery and event handling for the config. * * Called internally by `FrostProvider`. You typically don't need to call this directly. * * @param config - The Frost configuration object * @param registry - Wallet registry for discovering available wallets * @param bridge - Event bridge for handling wallet events * @internal */ declare function initializeConfig(config: FrostConfig, registry: WalletRegistry, bridge: WalletEventBridge): void; export { type AccountEntity as A, type ConnectionStatus as C, type FrostConfig as F, type WalletEntity as W, type FrostAppState as a, type CreateConfigOptions as b, createConfig as c, WalletEventBridge as d, WalletRegistry as e, initializeConfig as i };