UNPKG

accounts

Version:

Tempo Accounts SDK

152 lines 6.23 kB
import { tempo as mppx_tempo } from 'mppx/client'; import { Address, Hex, Provider as ox_Provider } from 'ox'; import { type Chain, type Client as ViemClient, type Transport } from 'viem'; import { tempo } from 'viem/chains'; import * as z from 'zod/mini'; import * as AccessKey from './AccessKey.js'; import * as Account from './Account.js'; import type * as Adapter from './Adapter.js'; import * as Client from './Client.js'; import * as Schema from './Schema.js'; import * as Storage from './Storage.js'; import * as Store from './Store.js'; import * as Rpc from './zod/rpc.js'; export type Provider = ox_Provider.Provider<{ schema: Schema.Ox; }> & ox_Provider.Emitter & { /** Configured chains. */ chains: readonly [Chain, ...Chain[]]; /** Returns a viem Account for the given address (or active account). */ getAccount: Account.Find; /** Returns local or on-chain publication status for an access key. */ getAccessKeyStatus(options?: getAccessKeyStatus.Options | undefined): Promise<getAccessKeyStatus.ReturnType>; /** Returns a viem Client for the given (or current) chain ID. */ getClient(options?: { chainId?: number | undefined; feePayer?: string | undefined; }): ViemClient<Transport, typeof tempo>; /** Reactive state store. */ store: Store.Store; }; /** * Creates an EIP-1193 provider with a pluggable adapter. * * @example * ```ts * import { Provider } from 'accounts' * * const provider = Provider.create() * ``` */ export declare function create(options?: create.Options): create.ReturnType; export declare namespace create { type Options = { /** Adapter to use for account management. @default dialog() */ adapter?: Adapter.Adapter | undefined; /** * Default Server Authentication configuration for `wallet_connect`. * * When set, every `wallet_connect` call orchestrates the round-trip * against this endpoint unless the caller passes their own * `capabilities.auth` (per-call override). */ auth?: z.input<typeof Rpc.wallet_connect.auth> | undefined; /** * Default access key parameters for `wallet_connect`. * * When set, `wallet_connect` will automatically authorize an access key. */ authorizeAccessKey?: (() => Adapter.authorizeAccessKey.Parameters) | undefined; /** * Supported chains. First chain is the default. * @default [tempo, tempoModerato, tempoDevnet] */ chains?: readonly [Chain, ...Chain[]] | undefined; /** Fee payer configuration. @see {@link Client.fromChainId.Options.feePayer} */ feePayer?: Client.fromChainId.Options['feePayer']; /** Maximum number of accounts to persist. Oldest accounts are evicted when exceeded (LRU). */ maxAccounts?: number | undefined; /** * Enable Machine Payment Protocol (mppx) support. * * Pass an options object to configure, or `false` to disable. * * @default true */ mpp?: boolean | mpp.Options | undefined; /** Whether to persist credentials and access keys to storage. When `false`, only account addresses are persisted. @default true */ persistCredentials?: boolean | undefined; /** * Base URL for a wallet relay endpoint. When set, every chain's transport * defaults to `http(`${relay}/${chainId}`)` — a single endpoint that * routes by chain ID via the path. Per-chain entries in `transports` * override this on a chain-by-chain basis. * * @example * ```ts * const provider = Provider.create({ relay: '/relay' }) * // tempo (33139) → http('/relay/33139') * // tempoModerato → http('/relay/<id>') * ``` */ relay?: string | undefined; /** Storage adapter for persistence. @default Storage.idb() in browser, Storage.memory() otherwise. */ storage?: Storage.Storage | undefined; /** * Use testnet. * @default false */ testnet?: boolean | undefined; /** * Per-chain transports keyed by chain ID. When omitted, defaults to * `http()` for each chain (uses the chain's default RPC URL). * * @example * ```ts * import { http } from 'viem' * import { tempo, tempoModerato } from 'viem/chains' * * const provider = Provider.create({ * transports: { * [tempo.id]: http('/relay/' + tempo.id), * [tempoModerato.id]: http('/relay/' + tempoModerato.id), * }, * }) * ``` */ transports?: Record<number, Transport> | undefined; }; type ReturnType = Provider; } export declare namespace getAccessKeyStatus { /** Options for {@link Provider.getAccessKeyStatus}. */ type Options = { /** Root account address. Defaults to the active account. */ address?: Address.Address | undefined; /** Specific access key address to query. When omitted, the first locally matching key is used. */ accessKey?: Address.Address | undefined; /** Calls to match against access key scopes. */ calls?: readonly { to?: Address.Address | undefined; data?: Hex.Hex | undefined; }[] | undefined; /** Chain ID the access key must be authorized on. Defaults to the active chain. */ chainId?: number | undefined; }; /** Access-key publication status. */ type ReturnType = AccessKey.Status; } export declare namespace mpp { /** Options for Machine Payment Protocol (mppx) integration. */ type Options = Omit<mppx_tempo.Parameters, 'account' | 'getClient'> & { /** * Whether to polyfill `globalThis.fetch` with the payment-aware wrapper. * * Defaults to `true` when `globalThis.fetch` is writable, and `false` * otherwise (e.g. Cloudflare Workers, where `globalThis.fetch` is * read-only). */ polyfill?: boolean | undefined; }; } //# sourceMappingURL=Provider.d.ts.map