UNPKG

accounts

Version:

Tempo Accounts SDK

89 lines 3.53 kB
import * as z from 'zod/mini'; import type { Mutate, StoreApi } from 'zustand'; import * as core_AccessKey from './AccessKey.js'; import type { Store as Account } from './Account.js'; import * as core_Keystore from './Keystore.js'; import * as Storage from './Storage.js'; export type { Account }; /** Reactive state for the provider. */ export type State = { /** Stored access keys. */ accessKeys: readonly core_AccessKey.AccessKey[]; /** Connected accounts. */ accounts: readonly Account[]; /** Index of the active account. */ activeAccount: number; /** * Absolutized Server Authentication endpoints from the most recent * `wallet_connect` (or the Provider's `auth` option). Persisted so * `wallet_disconnect` can call `logout` even after a page reload, even * when the URL was passed per-call rather than at Provider creation. */ auth?: { challenge?: string | undefined; verify?: string | undefined; logout?: string | undefined; returnToken?: boolean | undefined; } | undefined; /** Active chain ID. */ chainId: number; }; /** Provider state persisted as a refresh snapshot. */ type Persisted = { /** Stored access keys. */ accessKeys?: readonly unknown[] | undefined; /** Connected accounts. */ accounts?: readonly Account[] | undefined; /** Index of the active account. */ activeAccount?: number | undefined; /** * Absolutized Server Authentication endpoints from the most recent * `wallet_connect` (or the Provider's `auth` option). */ auth?: State['auth'] | undefined; /** Active chain ID. */ chainId?: number | undefined; }; /** Zustand vanilla store with `subscribeWithSelector` and `persist` middleware. */ type ZustandStore = Mutate<StoreApi<State>, [ ['zustand/subscribeWithSelector', never], ['zustand/persist', Persisted] ]>; /** Provider store facade. */ export type Store = ZustandStore & { /** Store-bound access-key operations. */ accessKeys: ReturnType<typeof core_AccessKey.createManager>; /** Disconnects all accounts and clears locally signable access-key material. */ disconnect: () => void; }; /** Options for {@link create}. */ export type Options = { /** * Minimum account schema required for hydration. * * This is a perimeter check for persisted state, not the full account schema. */ schema?: z.ZodMiniType | undefined; /** Initial chain ID. */ chainId: number; /** Keystores backing access-key records that carry an opaque `handle`. */ keystores?: core_Keystore.Keystores | undefined; /** Maximum number of accounts to persist. Oldest accounts are evicted when exceeded (LRU). */ maxAccounts?: number | undefined; /** Whether to persist credentials and access keys to storage. When `false`, only account addresses are persisted. @default true */ persistCredentials?: boolean | undefined; /** Storage adapter for persistence. */ storage?: Storage.Storage | undefined; }; /** * Creates a Zustand vanilla store with `subscribeWithSelector` and `persist` middleware. */ export declare function create(options: Options): Store; /** * Waits for the store to finish hydrating from storage. * * Returns immediately if the store has already hydrated. Otherwise, waits * for the `onFinishHydration` callback with a 100ms safety timeout fallback. */ export declare function waitForHydration(store: Store): Promise<void>; //# sourceMappingURL=Store.d.ts.map