/** * Economy client — wallets, durable payout requests, and escrows for * agent-to-agent value exchange. * * Mirrors py `agenttool.economy`: 18 shared methods across the wallet, payout, * and escrow surfaces of the agent-economy API. TypeScript also retains the * backward-compatible `createWallet` alias, for 19 methods total. * * @example * ```ts * const at = new AgentTool(); * const wallet = await at.economy.create_wallet("agent-42-wallet", { agent_id: "agent-42" }); * const worker = await at.economy.create_wallet("worker-wallet", { agent_id: "agent-43" }); * await at.economy.fund_wallet(wallet.id, { amount: 500, description: "Weekly budget" }); * await at.economy.spend(wallet.id, { amount: 10, counterparty: "wal_xyz", description: "Task fee" }); * * const escrow = await at.economy.create_escrow({ * creator_wallet_id: wallet.id, * worker_wallet_id: worker.id, * amount: 100, * description: "Summarise 50 papers", * idempotency_key: "summarise-50-papers-v1", * }); * await at.economy.release_escrow(escrow.id); * ``` */ import { type HttpConfig } from "./_http.js"; import type { Escrow, Wallet } from "./types.js"; export declare const WALLET_ADDRESS_CLAIM_SIGNATURE_CONTEXT = "wallet-address-claim/v1"; export interface WalletAddressClaimPayload { wallet_id: string; chain: string; address: string; /** Empty string when undisclosed. The field is never omitted. */ derivation_path?: string; /** Standard base64 of the raw 32-byte ed25519 public key. */ claim_pubkey_b64: string; } /** Exact domain-separated digest verified by `POST /v1/wallets/:id/addresses`. * * Recipe 1 — `sha256( utf8(tag) || 0x00 || fields… )`. The pubkey field is * folded as its raw 32 bytes, not as its base64 text; everything else is * UTF-8. See `docs/CANONICAL-BYTES.md`. * * This is only the identity half of registering an address. The chain-native * signature over a fresh challenge is separate and equally required. */ export declare function canonicalWalletAddressClaimBytes(options: WalletAddressClaimPayload): Uint8Array; /** Sign an address claim locally with a 32-byte Ed25519 seed. * * The seed stays here. What crosses the wire is the signature, the public * key, and the address — never the key that derived them. */ export declare function signWalletAddressClaim(privateKey: string | Uint8Array, options: WalletAddressClaimPayload): string; export interface CreateWalletOpts { agent_id?: string; currency?: string; } export interface FundWalletOpts { amount: number; description?: string; metadata?: Record; } export interface SpendOpts { amount: number; counterparty: string; description: string; metadata?: Record; } export interface SetWalletPolicyOpts { max_per_transaction?: number; max_per_hour?: number; max_per_day?: number; allowed_recipients?: string[]; requires_approval_above?: number; } export type PayoutChain = "ethereum" | "base" | "polygon" | "arbitrum" | "optimism" | "solana"; export type PayoutStatus = "requested" | "signing" | "broadcasting" | "broadcast" | "confirmed" | "failed" | "cancelled"; export type PayoutNetwork = "testnet" | "mainnet"; export interface RequestPayoutOpts { chain: PayoutChain; /** Canonical positive USDC base-unit integer string; never a float. */ amount_base: string; destination_address: string; token?: "USDC"; metadata?: Record; /** * Caller-chosen, required durable request identity. * * Must be 8-256 visible ASCII characters without spaces. The SDK neither * generates nor stores this value. Fresh requests currently rest with * `503 payout_admission_resting`; only an exact replay of durable historical * accepted state can return a payout, and changed input is a conflict. */ idempotency_key: string; } /** Current server state returned only from exact durable historical replay. */ export interface PayoutRequestOutcome { id: string; status: PayoutStatus; /** * Whether the historical row remains pending under its durable state. * This does not claim that the currently resting broadcast path operates. */ broadcast_pending: boolean; /** * True only when the server resolved this call through its durable payout * request reservation. This is not a claim about Redis availability. */ replayed: boolean; note?: string; } /** One outgoing crypto payout row returned by `list_payouts`. */ export interface Payout { id: string; chain: PayoutChain; /** Durable network identity; null only for quarantined legacy rows. */ network: PayoutNetwork | null; token: string; /** Exact token base-unit integer string. */ amount_base: string; destination_address: string; status: PayoutStatus; tx_hash: string | null; requested_at: string; confirmed_at: string | null; } export interface CreateEscrowOpts { creator_wallet_id: string; amount: number; description: string; worker_wallet_id?: string; deadline?: string; /** 8-256 visible ASCII non-space chars. Exact retries return the same escrow's current row. */ idempotency_key?: string; } export declare class EconomyClient { private readonly http; /** @internal */ constructor(http: HttpConfig); /** Create a new wallet. */ create_wallet(name: string, options?: CreateWalletOpts): Promise; /** Backward-compatible alias for `create_wallet` (camelCase form, present since 0.5.0). */ createWallet(opts: { name: string; } & CreateWalletOpts): Promise; /** List all wallets for this project. */ list_wallets(): Promise; /** Get a wallet by ID. */ get_wallet(walletId: string): Promise; /** Add credits to a wallet. */ fund_wallet(walletId: string, options: FundWalletOpts): Promise>; /** Spend credits from a wallet (subject to spending policy). */ spend(walletId: string, options: SpendOpts): Promise>; /** Set or update a wallet's spending policy. */ set_policy(walletId: string, options: SetWalletPolicyOpts): Promise>; /** Freeze a wallet — halts all spending immediately. */ freeze_wallet(walletId: string): Promise; /** Unfreeze a wallet to resume normal operation. */ unfreeze_wallet(walletId: string): Promise; /** Get paginated transaction history for a wallet. */ get_transactions(walletId: string, options?: { limit?: number; offset?: number; }): Promise[]>; /** * Attempt an outgoing crypto payout under a caller-chosen durable key. * * Fresh requests currently rest with `503 payout_admission_resting`; only * an exact replay of durable historical accepted state can succeed. The SDK * sends exactly one request and never generates a key, retries a broadcast, * or treats a Redis cache as the correctness boundary. */ request_payout(walletId: string, options: RequestPayoutOpts): Promise; /** List outgoing crypto payouts for a wallet, newest first. */ list_payouts(walletId: string): Promise; /** Create an escrow — locks wallet balance units until released or refunded. */ create_escrow(options: CreateEscrowOpts): Promise; /** List escrows, optionally filtered by status. */ list_escrows(options?: { status?: Escrow["status"]; }): Promise; /** Get an escrow by ID. */ get_escrow(escrowId: string): Promise; /** Accept an escrow as the worker. */ accept_escrow(escrowId: string, workerWalletId: string): Promise; /** Release escrow funds to the worker. */ release_escrow(escrowId: string): Promise; /** Refund escrow balance units back to the creator. */ refund_escrow(escrowId: string): Promise; /** Flag an escrow as disputed — balance units stay locked. */ dispute_escrow(escrowId: string): Promise; private req; }