UNPKG

accounts

Version:

Tempo Accounts SDK

229 lines 10.1 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 type { JsonRpcAccount } from 'viem/accounts'; import { Account as TempoAccount } from 'viem/tempo'; import { tempo } from 'viem/tempo/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 Keystore from './Keystore.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 the active root account as a viem account. */ getAccount(options: Omit<Account.find.Options, 'store'> & { signable: true; }): TempoAccount.Account; getAccount(options?: Omit<Account.find.Options, 'store'>): JsonRpcAccount; /** 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>; /** Returns mppx Tempo client parameters backed by this provider. */ getMppxParameters(options?: getMppxParameters.Options | undefined): MppxParameters; /** Reactive state store. */ store: Store.Store; }; type MppxParameters = { getClient: NonNullable<mppx_tempo.Parameters['getClient']>; resolveAccount: NonNullable<mppx_tempo.Parameters['resolveAccount']>; }; /** * 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 = { /** Access-key configuration: authorization policy and key material. */ accessKey?: { /** * Access-key parameters to authorize automatically when no stored * key satisfies a request. * * Applies to `wallet_connect` and transaction sends. Pass an object * to use the same parameters for every request, or a function to * compute them per request — return `undefined` to skip * authorization for that request. */ authorize?: AuthorizeAccessKey | undefined; /** * Keystores backing provider-generated access keys, one per key * type. A keystore creates key material and turns persisted * records back into signing accounts — see * {@link Keystore.Keystore} for the contract. * * App-level keystores override adapter-supplied defaults. * Keystores hold key material; `storage` persists provider state. * Access keys created before a keystore was configured keep * working. * * @default Keystore.defaults — `{ p256: Keystore.webCryptoP256() }` * * @example * ```ts * import { Keystore, Provider } from 'accounts' * * const provider = Provider.create({ * accessKey: { * keystores: { p256: Keystore.webCryptoP256({ extractable: true }) }, * }, * }) * ``` */ keystores?: Keystore.Keystores | undefined; } | undefined; /** 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; /** @deprecated Use `accessKey.authorize` instead. */ authorizeAccessKey?: AuthorizeAccessKey | 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']; /** * Identity (verified email) token minting for local adapters. When a * `wallet_connect` request asks for `identity.email` and the adapter * returns no identity claims (local adapters have no wallet host to mint * them), the provider mints the id token from this issuer's `/token` * route (`Handler.oidcProvider` shape). The issuer must trust * body-supplied subjects, so this is for development deployments. */ identity?: { /** Audience (`aud`) bound into minted tokens. @default `location.origin` */ audience?: string | undefined; /** Credential mode for token requests. @default "same-origin" */ credentials?: RequestCredentials | undefined; /** OIDC issuer whose `/token` route mints the id token. */ issuer: string; } | undefined; /** 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/tempo/chains' * * const provider = Provider.create({ * transports: { * [tempo.id]: http('/relay/' + tempo.id), * [tempoModerato.id]: http('/relay/' + tempoModerato.id), * }, * }) * ``` */ transports?: Record<number, Transport> | undefined; }; /** Access-key parameters to authorize automatically, with SDK-only reuse policy. */ type AuthorizeAccessKeyParameters = Adapter.authorizeAccessKey.Parameters & { /** SDK-only policy for deciding whether a stored local key can be reused. */ reuse?: AccessKey.ReusePolicy | undefined; }; /** Static or per-request access-key authorization parameters. */ type AuthorizeAccessKey = AuthorizeAccessKeyParameters | (() => AuthorizeAccessKeyParameters | 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 = 'missing' | 'pending' | 'published' | 'expired'; } export declare namespace getMppxParameters { /** Options for {@link Provider.getMppxParameters}. */ type Options = { /** Specific access key address to use for mppx signing. */ accessKey?: Address.Address | undefined; }; } export declare namespace mpp { /** Options for Machine Payment Protocol (mppx) integration. */ type Options = Omit<mppx_tempo.Parameters, 'account' | 'getClient' | 'resolveAccount'> & { /** * 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; }; } export {}; //# sourceMappingURL=Provider.d.ts.map