accounts
Version:
Tempo Accounts SDK
102 lines • 4.09 kB
TypeScript
import type { RpcRequest, RpcResponse } from 'ox';
import type { Mutate, StoreApi } from 'zustand';
import type { OneOf } from '../internal/types.js';
import type { AccessKey } from './AccessKey.js';
import type { Store as Account } from './Account.js';
import * as Storage from './Storage.js';
export type { AccessKey, Account };
/** Reactive state for the provider. */
export type State = {
/** Stored access keys. */
accessKeys: readonly 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;
/** Queued RPC requests pending resolution by the dialog. */
requestQueue: readonly QueuedRequest[];
};
/** Provider state persisted as a refresh snapshot. */
export 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. */
export type Store = Mutate<StoreApi<State>, [
['zustand/subscribeWithSelector', never],
['zustand/persist', Persisted]
]>;
/** Options for {@link create}. */
export type Options = {
/** Initial chain ID. */
chainId: number;
/** 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;
};
/** A queued JSON-RPC request tracked in the store. */
export type QueuedRequest<result = unknown> = OneOf<{
request: RpcRequest.RpcRequest;
status: 'pending';
} | {
request: RpcRequest.RpcRequest;
result: result;
status: 'success';
} | {
request: RpcRequest.RpcRequest;
error: RpcResponse.ErrorObject;
status: 'error';
}>;
/**
* Creates a Zustand vanilla store with `subscribeWithSelector` and `persist` middleware.
*/
export declare function create(options: Options): Store;
/** Converts runtime provider state into the persisted refresh snapshot. */
export declare function serialize(state: State, options?: serialize.Options): Persisted;
export declare namespace serialize {
/** Options for {@link serialize}. */
type Options = {
/** Maximum number of accounts to persist. Oldest accounts are evicted when exceeded. */
maxAccounts?: number | undefined;
/** Whether to persist credentials and access keys to storage. @default true */
persistCredentials?: boolean | undefined;
};
}
/** Restores runtime provider state from a persisted refresh snapshot. */
export declare function hydrate(persisted: unknown, current: State): State;
/**
* 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