UNPKG

accounts

Version:

Tempo Accounts SDK

678 lines 28.2 kB
import * as z from 'zod/mini'; import * as Schema from '../internal/schema.js'; import * as u from './utils.js'; export const log = z.object({ address: u.address(), blockHash: u.hex(), blockNumber: u.bigint(), data: u.hex(), logIndex: u.number(), removed: z.boolean(), topics: z.readonly(z.array(u.hex())), transactionHash: u.hex(), transactionIndex: u.number(), }); export const receipt = z.object({ blobGasPrice: z.optional(u.bigint()), blobGasUsed: z.optional(u.bigint()), blockHash: u.hex(), blockNumber: u.bigint(), contractAddress: z.nullable(u.address()), cumulativeGasUsed: u.bigint(), effectiveGasPrice: u.bigint(), feePayer: z.optional(u.address()), feeToken: z.optional(u.address()), from: u.address(), gasUsed: u.bigint(), logs: z.array(log), logsBloom: u.hex(), root: z.optional(u.hex()), status: z.codec(u.hex(), z.enum(['success', 'reverted']), { decode: (value) => (value === '0x1' ? 'success' : 'reverted'), encode: (value) => (value === 'success' ? '0x1' : '0x0'), }), to: z.nullable(u.address()), transactionHash: u.hex(), transactionIndex: u.number(), type: u.hex(), }); export const signatureEnvelope = z.custom(); export const keyType = z.union([z.literal('secp256k1'), z.literal('p256'), z.literal('webAuthn')]); export const keyAuthorization = z.object({ address: z.optional(u.address()), chainId: u.bigint(), expiry: z.union([u.number(), z.null(), z.undefined()]), keyId: u.address(), keyType, limits: z.optional(z.readonly(z.array(z.object({ token: u.address(), limit: u.bigint(), period: z.optional(u.number()) })))), signature: signatureEnvelope, }); export const call = z.object({ data: z.optional(u.hex()), to: z.optional(u.address()), value: z.optional(u.bigint()), }); export const transactionRequest = z.object({ accessList: z.optional(z.array(z.object({ address: u.address(), storageKeys: z.array(u.hex()) }))), calls: z.optional(z.readonly(z.array(call))), chainId: z.optional(u.number()), data: z.optional(u.hex()), feePayer: z.optional(z.union([z.boolean(), z.string()])), feePayerSignature: z.optional(z.record(z.string(), z.unknown())), feeToken: z.optional(u.address()), from: z.optional(u.address()), gas: z.optional(u.bigint()), keyAuthorization: z.optional(keyAuthorization), keyData: z.optional(u.hex()), keyId: z.optional(u.address()), keyType: z.optional(keyType), maxFeePerGas: z.optional(u.bigint()), maxPriorityFeePerGas: z.optional(u.bigint()), nonce: z.optional(u.number()), nonceKey: z.optional(u.bigint()), to: z.optional(u.address()), validAfter: z.optional(u.number()), validBefore: z.optional(u.number()), value: z.optional(u.bigint()), }); export var eth_accounts; (function (eth_accounts) { eth_accounts.schema = Schema.defineItem({ method: z.literal('eth_accounts'), params: undefined, returns: z.readonly(z.array(u.address())), }); })(eth_accounts || (eth_accounts = {})); export var eth_chainId; (function (eth_chainId) { eth_chainId.schema = Schema.defineItem({ method: z.literal('eth_chainId'), params: undefined, returns: u.hex(), }); })(eth_chainId || (eth_chainId = {})); export var eth_requestAccounts; (function (eth_requestAccounts) { eth_requestAccounts.schema = Schema.defineItem({ method: z.literal('eth_requestAccounts'), params: undefined, returns: z.readonly(z.array(u.address())), }); })(eth_requestAccounts || (eth_requestAccounts = {})); export var eth_sendTransaction; (function (eth_sendTransaction) { eth_sendTransaction.schema = Schema.defineItem({ method: z.literal('eth_sendTransaction'), params: z.readonly(z.tuple([transactionRequest])), returns: u.hex(), }); })(eth_sendTransaction || (eth_sendTransaction = {})); export var eth_fillTransaction; (function (eth_fillTransaction) { const balanceDiff = z.object({ address: u.address(), decimals: z.number(), direction: z.enum(['incoming', 'outgoing']), formatted: z.string(), name: z.string(), recipients: z.readonly(z.array(u.address())), symbol: z.string(), value: u.hex(), }); const swapAmount = z.object({ decimals: z.number(), formatted: z.string(), name: z.string(), symbol: z.string(), token: u.address(), value: u.hex(), }); eth_fillTransaction.schema = Schema.defineItem({ method: z.literal('eth_fillTransaction'), params: z.readonly(z.tuple([transactionRequest])), returns: z.object({ capabilities: z.object({ balanceDiffs: z.optional(z.record(u.address(), z.readonly(z.array(balanceDiff)))), error: z.optional(z.object({ abiItem: z.optional(z.record(z.string(), z.unknown())), data: z.optional(u.hex()), errorName: z.string(), message: z.string(), })), fee: z.optional(z.object({ amount: u.hex(), decimals: z.number(), formatted: z.string(), symbol: z.string(), })), requireFunds: z.optional(z.object({ amount: u.hex(), decimals: z.number(), formatted: z.string(), token: u.address(), symbol: z.string(), })), autoSwap: z.optional(z.object({ maxIn: swapAmount, minOut: swapAmount, slippage: z.number(), })), sponsor: z.optional(z.object({ address: u.address(), name: z.optional(z.string()), url: z.optional(z.string()), })), sponsored: z.boolean(), }), tx: z.record(z.string(), z.unknown()), }), }); })(eth_fillTransaction || (eth_fillTransaction = {})); export var eth_signTransaction; (function (eth_signTransaction) { eth_signTransaction.schema = Schema.defineItem({ method: z.literal('eth_signTransaction'), params: z.readonly(z.tuple([transactionRequest])), returns: u.hex(), }); })(eth_signTransaction || (eth_signTransaction = {})); export var eth_sendTransactionSync; (function (eth_sendTransactionSync) { eth_sendTransactionSync.schema = Schema.defineItem({ method: z.literal('eth_sendTransactionSync'), params: z.readonly(z.tuple([transactionRequest])), returns: receipt, }); })(eth_sendTransactionSync || (eth_sendTransactionSync = {})); export var eth_signTypedData_v4; (function (eth_signTypedData_v4) { eth_signTypedData_v4.schema = Schema.defineItem({ method: z.literal('eth_signTypedData_v4'), params: z.readonly(z.tuple([u.address(), z.string()])), returns: u.hex(), }); })(eth_signTypedData_v4 || (eth_signTypedData_v4 = {})); export var personal_sign; (function (personal_sign) { personal_sign.schema = Schema.defineItem({ method: z.literal('personal_sign'), params: z.readonly(z.tuple([u.hex(), u.address()])), returns: u.hex(), }); })(personal_sign || (personal_sign = {})); const sendCallsCapabilities = z.optional(z.object({ feePayer: z.optional(z.union([z.boolean(), z.string()])), sync: z.optional(z.boolean()), })); export var wallet_sendCalls; (function (wallet_sendCalls) { wallet_sendCalls.schema = Schema.defineItem({ method: z.literal('wallet_sendCalls'), params: z.optional(z.readonly(z.tuple([ z.object({ atomicRequired: z.optional(z.boolean()), calls: z.readonly(z.array(call)), capabilities: sendCallsCapabilities, chainId: z.optional(u.number()), from: z.optional(u.address()), version: z.optional(z.string()), }), ]))), returns: z.object({ atomic: z.optional(z.boolean()), capabilities: sendCallsCapabilities, chainId: z.optional(u.number()), id: z.string(), receipts: z.optional(z.array(receipt)), status: z.optional(z.number()), version: z.optional(z.string()), }), }); })(wallet_sendCalls || (wallet_sendCalls = {})); export var wallet_getBalances; (function (wallet_getBalances) { wallet_getBalances.schema = Schema.defineItem({ method: z.literal('wallet_getBalances'), params: z.optional(z.readonly(z.tuple([ z.object({ account: z.optional(u.address()), chainId: z.optional(u.number()), tokens: z.optional(z.readonly(z.array(u.address()))), }), ]))), returns: z.readonly(z.array(z.object({ address: u.address(), balance: u.bigint(), decimals: z.number(), display: z.string(), name: z.string(), symbol: z.string(), }))), }); })(wallet_getBalances || (wallet_getBalances = {})); export var wallet_getCapabilities; (function (wallet_getCapabilities) { wallet_getCapabilities.schema = Schema.defineItem({ method: z.literal('wallet_getCapabilities'), params: z.optional(z.readonly(z.union([z.tuple([u.address()]), z.tuple([u.address(), z.readonly(z.array(u.hex()))])]))), returns: z.record(u.hex(), z.object({ accessKeys: z.optional(z.object({ status: z.union([z.literal('supported'), z.literal('unsupported')]), })), atomic: z.object({ status: z.union([z.literal('supported'), z.literal('ready'), z.literal('unsupported')]), }), feePayer: z.optional(z.object({ status: z.union([z.literal('supported'), z.literal('unsupported')]), })), })), }); })(wallet_getCapabilities || (wallet_getCapabilities = {})); export var wallet_authorizeAccessKey; (function (wallet_authorizeAccessKey) { wallet_authorizeAccessKey.parameters = z.object({ address: z.optional(u.address()), chainId: z.optional(u.bigint()), expiry: z.number(), keyType: z.optional(keyType), limits: z.optional(z.readonly(z.array(z.object({ token: u.address(), limit: u.bigint(), period: z.optional(z.number()) })))), publicKey: z.optional(u.hex()), scopes: z.optional(z.readonly(z.array(z.object({ address: u.address(), selector: z.optional(z.union([u.hex(), z.string()])), recipients: z.optional(z.readonly(z.array(u.address()))), })))), }); wallet_authorizeAccessKey.returns = z.object({ keyAuthorization, rootAddress: u.address(), }); wallet_authorizeAccessKey.schema = Schema.defineItem({ method: z.literal('wallet_authorizeAccessKey'), params: z.readonly(z.tuple([wallet_authorizeAccessKey.parameters])), returns: wallet_authorizeAccessKey.returns, }); })(wallet_authorizeAccessKey || (wallet_authorizeAccessKey = {})); export var wallet_authorizeAccessKey_strict; (function (wallet_authorizeAccessKey_strict) { wallet_authorizeAccessKey_strict.parameters = z.object({ address: z.optional(u.address()), expiry: z.number(), keyType: z.optional(keyType), limits: z.readonly(z .array(z.object({ token: u.address(), limit: u.bigint(), period: z.optional(z.number()) })) .check(z.minLength(1))), publicKey: z.optional(u.hex()), scopes: z.readonly(z .array(z.object({ address: u.address(), selector: z.optional(z.union([u.hex(), z.string()])), recipients: z.optional(z.readonly(z.array(u.address()))), })) .check(z.minLength(1))), }); })(wallet_authorizeAccessKey_strict || (wallet_authorizeAccessKey_strict = {})); export var wallet_revokeAccessKey; (function (wallet_revokeAccessKey) { wallet_revokeAccessKey.schema = Schema.defineItem({ method: z.literal('wallet_revokeAccessKey'), params: z.readonly(z.tuple([z.object({ address: u.address(), accessKeyAddress: u.address() })])), returns: undefined, }); })(wallet_revokeAccessKey || (wallet_revokeAccessKey = {})); export var wallet_connect; (function (wallet_connect) { wallet_connect.authorizeAccessKey = z.optional(wallet_authorizeAccessKey.parameters); /** * SIWE round-trip configuration. Bare string is shorthand for `{ url }`. * * - `auth: '/api/auth'` derives `${url}/challenge`, `${url}` (verify), `${url}/logout`. * - Object form lets callers override individual endpoints, opt into a * `{ token }` body via `returnToken`, etc. * * Cross-field validation (must include `url` or both `challenge` + `verify`) * is enforced inside `prepareSiwe`, not in zod, so the error message can be * specific. */ wallet_connect.auth = z.optional(z.union([ z.string(), z.object({ /** Base URL. SDK derives `${url}/challenge` and `${url}/logout`; `${url}` itself is verify. */ url: z.optional(z.string()), /** Override individual endpoints. Either `url` or both `challenge` + `verify` must be set. */ challenge: z.optional(z.string()), verify: z.optional(z.string()), logout: z.optional(z.string()), /** * Ask the verify endpoint to also return `{ token }` in the JSON body. * Default `false` — cookie mode relies on `Set-Cookie` only. * Set this for non-browser clients (RN, CLI) that can't store cookies, or * to surface the JWT alongside a cookie in dual-transport setups. */ returnToken: z.optional(z.boolean()), }), ])); /** * Request a `personal_sign` (EIP-191) over the supplied message during * `wallet_connect`. The wallet computes `hashMessage(message)` and signs * the resulting 32-byte digest in the same passkey ceremony that loads * or creates the account, so this costs no extra prompt over a plain * `wallet_connect`. The signature is returned via the top-level * `capabilities.signature` field on the connected account. */ wallet_connect.personalSign = z.optional(z.object({ /** Message to sign. The wallet applies the EIP-191 prehash. */ message: z.string(), })); wallet_connect.capabilities = { request: z.optional(z.union([ z.object({ digest: z.optional(u.hex()), authorizeAccessKey: wallet_connect.authorizeAccessKey, auth: wallet_connect.auth, method: z.literal('register'), name: z.optional(z.string()), personalSign: wallet_connect.personalSign, userId: z.optional(z.string()), }), z.object({ digest: z.optional(u.hex()), credentialId: z.optional(z.string()), authorizeAccessKey: wallet_connect.authorizeAccessKey, auth: wallet_connect.auth, method: z.optional(z.literal('login')), personalSign: wallet_connect.personalSign, selectAccount: z.optional(z.boolean()), }), ])), result: z.object({ email: z.optional(z.nullable(z.string())), keyAuthorization: z.optional(keyAuthorization), /** * Echo of the `personalSign` request, present iff the caller set * `capabilities.personalSign` (or `capabilities.auth` folded a SIWE * message into the same slot). The signature itself lives on the * top-level `capabilities.signature` field. */ personalSign: z.optional(z.object({ message: z.string(), })), signature: z.optional(u.hex()), username: z.optional(z.nullable(z.string())), /** * SIWE round-trip output, populated when the request `auth` capability was set. * `token` is present in JWT mode or when the request set `returnToken: true`. * Cookie-mode default = `{}` (the session arrived via `Set-Cookie`). */ auth: z.optional(z.object({ token: z.optional(z.string()), })), }), }; wallet_connect.schema = Schema.defineItem({ method: z.literal('wallet_connect'), params: z.optional(z.readonly(z.tuple([ z.object({ capabilities: wallet_connect.capabilities.request, chainId: z.optional(u.number()), version: z.optional(z.string()), }), ]))), returns: z.object({ accounts: z.readonly(z.array(z.object({ address: u.address(), capabilities: wallet_connect.capabilities.result, }))), }), }); })(wallet_connect || (wallet_connect = {})); export var wallet_connect_strict; (function (wallet_connect_strict) { const authorizeAccessKey = z.optional(wallet_authorizeAccessKey_strict.parameters); const auth = wallet_connect.auth; const personalSign = wallet_connect.personalSign; wallet_connect_strict.parameters = z.object({ capabilities: z.optional(z.union([ z.object({ digest: z.optional(u.hex()), authorizeAccessKey, auth, method: z.literal('register'), name: z.optional(z.string()), personalSign, userId: z.optional(z.string()), }), z.object({ digest: z.optional(u.hex()), credentialId: z.optional(z.string()), authorizeAccessKey, auth, method: z.optional(z.literal('login')), personalSign, selectAccount: z.optional(z.boolean()), }), ])), chainId: z.optional(u.number()), version: z.optional(z.string()), }); })(wallet_connect_strict || (wallet_connect_strict = {})); export var wallet_disconnect; (function (wallet_disconnect) { wallet_disconnect.schema = Schema.defineItem({ method: z.literal('wallet_disconnect'), params: undefined, returns: undefined, }); })(wallet_disconnect || (wallet_disconnect = {})); export var wallet_getCallsStatus; (function (wallet_getCallsStatus) { wallet_getCallsStatus.schema = Schema.defineItem({ method: z.literal('wallet_getCallsStatus'), params: z.optional(z.readonly(z.tuple([z.string()]))), returns: z.object({ atomic: z.boolean(), chainId: u.number(), id: z.string(), receipts: z.optional(z.array(receipt)), status: z.number(), version: z.string(), }), }); })(wallet_getCallsStatus || (wallet_getCallsStatus = {})); export var wallet_transfer; (function (wallet_transfer) { /** * Parameters for `wallet_transfer`. * * Discriminated on `editable`: * * - omitted or `false` (default): Read-only. `amount` is a * human-readable string (e.g. `"1.5"`), `to` and `token` are * required, no editable UI is shown. Uses an access key when one * matches (signs without UI), otherwise falls back to a confirm * dialog the user has to approve. * - `true`: Editable. Wallet shows a UI with optional fields * pre-filled; the user confirms or edits before signing. */ wallet_transfer.parameters = z.discriminatedUnion('editable', [ z.object({ /** Human-readable amount to transfer (e.g. `"1.5"`). */ amount: z.string(), /** Chain id. Defaults to the active chain. */ chainId: z.optional(u.number()), /** Skip the editable wallet UI (Read-only mode). @default false */ editable: z.optional(z.literal(false)), /** * Fee payer override. `false` to disable the wallet's default fee * payer, a URL string to use a custom fee payer service. */ feePayer: z.optional(z.union([z.boolean(), z.string()])), /** * Address to transfer tokens from. Defaults to the active account. * When set to a different address, the call uses `transferFrom` and * requires the active account to have an allowance from `from`. */ from: z.optional(u.address()), /** * UTF-8 memo to attach to the transfer (max 32 bytes when encoded * as UTF-8). Sent via `transferWithMemo` / `transferFromWithMemo`. */ memo: z.optional(z.string()), /** Recipient address. */ to: u.address(), /** * Token to transfer, accepted as either a contract address or a * curated tokenlist symbol (case-insensitive, e.g. `"pathUsd"`). * Symbols are resolved against the curated tokenlist on the active * chain. */ token: z.union([u.address(), z.string()]), }), z.object({ /** Human-readable amount to pre-fill (e.g. `"1.5"`). */ amount: z.optional(z.string()), /** Chain id. Defaults to the active chain. */ chainId: z.optional(u.number()), /** Show the wallet UI for the user to confirm or edit. */ editable: z.literal(true), /** * Fee payer override. `false` to disable the wallet's default fee * payer, a URL string to use a custom fee payer service. */ feePayer: z.optional(z.union([z.boolean(), z.string()])), /** * UTF-8 memo (max 32 bytes) to attach to the transfer. Wallet * rejects the request if the selected token does not support * memos (non-TIP-20). */ memo: z.optional(z.string()), /** Recipient address to pre-fill. */ to: z.optional(u.address()), /** * Token to pre-fill, accepted as either a contract address or a * curated tokenlist symbol (case-insensitive, e.g. `"pathUsd"`). * Symbols are resolved against the curated tokenlist on the active * chain. Omit to let the user choose. */ token: z.optional(z.union([u.address(), z.string()])), }), ]); wallet_transfer.schema = Schema.defineItem({ method: z.literal('wallet_transfer'), params: z.optional(z.readonly(z.tuple([wallet_transfer.parameters]))), returns: z.object({ /** Chain id the send is to. */ chainId: u.number(), /** Receipt of the submitted send. */ receipt, }), }); })(wallet_transfer || (wallet_transfer = {})); const swapParameters = z.object({ /** Human-readable amount to pre-fill (e.g. "1.5"). */ amount: z.optional(z.string()), /** Other side of the swap pair. For buys, this is the token to sell. For sells, this is the token to buy. */ pairToken: z.optional(u.address()), /** Maximum allowed slippage as a decimal fraction (for example `0.05` for 5%). */ slippage: z.optional(z.number().check(z.minimum(0), z.maximum(1))), /** Token to buy or sell. Omit to let the user choose. */ token: z.optional(u.address()), /** Whether the amount is an exact buy amount (`swapExactAmountOut`) or sell amount (`swapExactAmountIn`). */ type: z.optional(z.union([z.literal('buy'), z.literal('sell')])), }); /** Opens the wallet swap flow with optional pre-filled swap intent fields. */ export var wallet_swap; (function (wallet_swap) { wallet_swap.schema = Schema.defineItem({ method: z.literal('wallet_swap'), params: z.optional(z.readonly(z.tuple([swapParameters]))), returns: z.object({ /** Receipt of the submitted swap. */ receipt, }), }); })(wallet_swap || (wallet_swap = {})); export var wallet_switchEthereumChain; (function (wallet_switchEthereumChain) { wallet_switchEthereumChain.schema = Schema.defineItem({ method: z.literal('wallet_switchEthereumChain'), params: z.readonly(z.tuple([z.object({ chainId: u.number() })])), returns: undefined, }); })(wallet_switchEthereumChain || (wallet_switchEthereumChain = {})); export var wallet_deposit; (function (wallet_deposit) { wallet_deposit.schema = Schema.defineItem({ method: z.literal('wallet_deposit'), params: z.readonly(z.tuple([ z.object({ address: z.optional(u.address()), chainId: z.optional(u.number()), displayName: z.optional(z.string()), token: z.optional(u.address()), value: z.optional(z.string()), }), ])), returns: z.optional(z.object({ /** * Receipts of any onchain operations performed during the * deposit (e.g. testnet faucet drops). Absent for offchain * paths like Apple Pay where funds arrive asynchronously. */ receipts: z.optional(z.readonly(z.array(receipt))), })), }); })(wallet_deposit || (wallet_deposit = {})); /** Opens the wallet zone-deposit flow with optional pre-filled fields. */ export var wallet_depositZone; (function (wallet_depositZone) { /** Parameters object for `wallet_depositZone`. */ wallet_depositZone.parameters = z.object({ /** Human-readable amount to pre-fill (e.g. "1.5"). */ amount: z.optional(z.string()), /** * Fee payer override. `false` to disable the wallet's default fee * payer, a URL string to use a custom fee payer service. */ feePayer: z.optional(z.union([z.boolean(), z.string()])), /** Token contract address to pre-fill. Omit to let the user choose. */ token: z.optional(u.address()), /** Zone id to deposit into. */ zoneId: z.optional(u.number()), }); wallet_depositZone.schema = Schema.defineItem({ method: z.literal('wallet_depositZone'), params: z.optional(z.readonly(z.tuple([wallet_depositZone.parameters]))), returns: z.object({ /** Receipt of the submitted deposit. */ receipt, }), }); })(wallet_depositZone || (wallet_depositZone = {})); /** Opens the wallet zone-withdraw flow with optional pre-filled fields. */ export var wallet_withdrawZone; (function (wallet_withdrawZone) { /** Parameters object for `wallet_withdrawZone`. */ wallet_withdrawZone.parameters = z.object({ /** Human-readable amount to pre-fill (e.g. "1.5"). */ amount: z.optional(z.string()), /** Token contract address to pre-fill. Omit to let the user choose. */ token: z.optional(u.address()), /** Zone id to withdraw from. */ zoneId: z.optional(u.number()), }); wallet_withdrawZone.schema = Schema.defineItem({ method: z.literal('wallet_withdrawZone'), params: z.optional(z.readonly(z.tuple([wallet_withdrawZone.parameters]))), returns: z.object({ /** Receipt of the submitted withdrawal. */ receipt, }), }); })(wallet_withdrawZone || (wallet_withdrawZone = {})); /** Strict parameter schemas keyed by method name. */ export const strictParameters = { wallet_authorizeAccessKey: wallet_authorizeAccessKey_strict.parameters, wallet_connect: wallet_connect_strict.parameters, }; //# sourceMappingURL=rpc.js.map