Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

docs(wallet): add README for wallet module

Steven Enamakel4908d3ec4861
diff --git a/crates/openhuman-core/src/web3/wallet/README.md b/crates/openhuman-core/src/web3/wallet/README.md
index 5955a198e6..6a6cf198eb 100644
--- a/crates/openhuman-core/src/web3/wallet/README.md
+++ b/crates/openhuman-core/src/web3/wallet/README.md
@@ -1,6 +1,6 @@
# wallet
-Core-owned local multi-chain crypto wallet, deliberately **basic**: key/account management plus the primitive on-chain operations. Owns onboarding metadata (consent + derived per-chain account addresses), secret material at rest (an encrypted recovery phrase stored in the OS keychain or workspace JSON), and the agent-facing surface: address + balance reads, network/asset catalogs, chain readiness, a prepare-then-confirm-then-execute flow for **native sends and token transfers** (ERC20 / SPL / TRC20 / BEP20), transaction broadcast, and read-only transaction inspection (status, receipt, lookup) across EVM (Ethereum + Base/Arbitrum/Optimism/Polygon/BNB Chain), Bitcoin (P2WPKH), Solana (native + SPL), and Tron (native + TRC20). Signing and broadcast happen in-core from the decrypted recovery phrase; no private keys ever cross the wire.
+Core-owned local multi-chain crypto wallet, deliberately **basic**: key/account management plus the primitive on-chain operations. Owns onboarding metadata (consent + derived per-chain account addresses), secret material at rest (an encrypted recovery phrase stored in the OS keychain or workspace JSON), and the agent-facing surface: address + balance reads, network/asset catalogs, chain readiness, a prepare-then-confirm-then-execute flow for **native sends and token transfers** (ERC20 / SPL / TRC20 / BEP20), transaction broadcast, and read-only transaction inspection (status, receipt, lookup) across EVM (Ethereum + Base/Arbitrum/Optimism/Polygon/BNB Chain), Bitcoin (P2WPKH), Solana (native + SPL), and Tron (native + TRC20). This process decrypts the recovery phrase and hands it, as a `tinywallet_bus::wire::SecretMaterial`, to the loaded `tinywallet` native module (`crate::modules::wallet`), which derives the key, signs, and returns the raw signed bytes; the core then broadcasts. The binary never assembles a private key outside `cfg(test)`.
Higher-level DeFi affordances (swaps, bridges, generic dapp/contract calls) live in the separate [`web3`](../README.md) module, which builds on the wallet's **crate-internal** `sign_and_broadcast_evm` / `sign_and_broadcast_solana` primitives. They are not part of the wallet's agent / RPC surface.
@@ -28,7 +28,7 @@ drift.
- Build prepared-transaction quotes (validated, fee-estimated, TTL'd) that must be explicitly confirmed before execution.
- Sign and broadcast confirmed quotes per chain; restore (and TTL-refresh) the quote on failure so it stays retryable.
- Bind each quote to the chat thread that prepared it so a leaked `quote_id` in a shared channel can't be hijacked from another agent session.
-- Expose six agent tools (`wallet_status`, `wallet_chain_status`, `wallet_prepare_transfer`, `wallet_tx_status`, `wallet_tx_receipt`, `wallet_lookup_tx`) and twelve `wallet.*` RPC controllers.
+- Expose six agent tools (`wallet_status`, `wallet_chain_status`, `wallet_prepare_transfer`, `wallet_tx_status`, `wallet_tx_receipt`, `wallet_lookup_tx`) and thirteen `wallet.*` RPC controllers.
- Provide crate-internal `sign_and_broadcast_evm` / `sign_and_broadcast_solana` primitives for the `web3` layer (sign+broadcast an externally-built unsigned transaction). Not exposed to the agent / RPC surface.
## Key files
@@ -36,7 +36,7 @@ drift.
| File | Role |
| --- | --- |
| `crates/openhuman-core/src/web3/wallet/mod.rs` | Export-focused module root; module docstring, `mod`/`pub use` re-exports. |
-| `crates/openhuman-core/src/web3/wallet/ops.rs` | Onboarding metadata + secret persistence: `WalletChain`/`WalletAccount`/`WalletStatus` types, `setup`/`status`, atomic `wallet-state.json` writes (temp-file + fsync), corrupt-state quarantine, keychain load/save/migrate, `validate_setup`, and `secret_material` (crate-internal) used by chain signers. |
+| `crates/openhuman-core/src/web3/wallet/ops.rs` | Onboarding metadata + secret persistence: `WalletChain`/`WalletAccount`/`WalletStatus` types, `setup`/`status`/`reveal_recovery_phrase`, atomic `wallet-state.json` writes (temp-file + fsync), corrupt-state quarantine, keychain load/save/migrate, `validate_setup`, and `secret_material` (crate-internal) used by chain signers. |
| `crates/openhuman-core/src/web3/wallet/execution.rs` | Execution surface: balances/network_defaults/supported_assets/chain_status reads, `prepare_transfer`/`execute_prepared` (native + token transfers only), `tx_status`/`tx_receipt`/`lookup_tx` readers, the crate-internal `sign_and_broadcast_evm`/`sign_and_broadcast_solana` re-exports, the in-memory quote store (TTL'd, capped at 64), `QuoteOwner` chat-thread binding, amount/address/calldata validation, fee estimation, hex/u256 helpers. |
| `crates/openhuman-core/src/web3/wallet/defaults.rs` | `EvmNetwork` enum (chain id, default RPC, explorer base, env var), default RPC/REST URLs for BTC/Solana/Tron, env-override resolution, and per-chain/per-network asset catalogs. |
| `crates/openhuman-core/src/web3/wallet/abi.rs` | `encode_erc20_transfer` — delegates the `transfer(address,uint256)` calldata encoding to `tinywallet_bus::abi`, mapping its typed errors (`InvalidRecipient`/`InvalidAmount`) to the plain-`String` shape the RPC/tool surface uses. |
@@ -49,30 +49,30 @@ drift.
| `crates/openhuman-core/src/web3/wallet/tools/prepare_transfer.rs` | `WalletPrepareTransferTool` (`wallet_prepare_transfer`). |
| `crates/openhuman-core/src/web3/wallet/tools/tx_query.rs` | `WalletTxStatusTool` (`wallet_tx_status`), `WalletTxReceiptTool` (`wallet_tx_receipt`), `WalletLookupTxTool` (`wallet_lookup_tx`) — share a `{chain, hash, evmNetwork?}` input and delegate to the matching `wallet::*` dispatcher. |
| `crates/openhuman-core/src/web3/wallet/chains/mod.rs` | Per-chain executor namespace; docstring of the small per-chain surface (`execute_*_quote`, `native_balance`, `validate_*_address`). |
-| `crates/openhuman-core/src/web3/wallet/chains/evm.rs` | EVM signing/broadcast built on `tinywallet_bus::wire::{SecretMaterial, TransactionSpec}` and `tinywallet_bus::address::evm::validate`; one derivation path shared across all EVM networks, EIP-1559 signing, `eth_*` balance/gas/broadcast. |
-| `crates/openhuman-core/src/web3/wallet/chains/btc.rs` | Bitcoin P2WPKH (BIP84) derivation/signing via `tinywallet_bus::wire`/`tinywallet_bus::address::btc`, plus Esplora REST balance/broadcast. |
-| `crates/openhuman-core/src/web3/wallet/chains/solana.rs` | Solana native + SPL transfers: hand-rolled wire format (`ed25519_dalek`, `curve25519_dalek`, `sha2`) to avoid pulling in `solana-sdk`; JSON-RPC balance/broadcast. |
-| `crates/openhuman-core/src/web3/wallet/chains/tron.rs` | Tron derivation/signing + TronGrid REST native + TRC20 transfers. |
+| `crates/openhuman-core/src/web3/wallet/chains/evm.rs` | EVM path: validates addresses with `tinywallet_bus::address::evm::validate`, gathers `eth_chainId`/nonce/`eth_gasPrice`/`eth_estimateGas` over JSON-RPC, builds a legacy gas-price `tinywallet_bus::wire::TransactionSpec::Evm`, signs it in the module via `modules::wallet::sign_transaction_in_module`, and broadcasts with `eth_sendRawTransaction`. One derivation path shared across all EVM networks. Also hosts the crate-internal `sign_and_broadcast_evm`. |
+| `crates/openhuman-core/src/web3/wallet/chains/btc.rs` | Bitcoin P2WPKH (BIP84) path: Esplora REST UTXO discovery, largest-first coin selection and fee policy stay here; the `TransactionSpec::Btc` (selected UTXOs, amount, fee) is encoded and signed in the module via `sign_transaction_in_module`, then broadcast over Esplora. Address checks via `tinywallet_bus::address::btc::{validate, validate_sender}`. |
+| `crates/openhuman-core/src/web3/wallet/chains/solana.rs` | Solana native + SPL transfers: hand-rolled message/transaction wire format (`sha2`, `bs58`, `curve25519_dalek` for the off-curve ATA check) so `solana-sdk` is not pulled in; the message is signed in the module via `modules::wallet::sign_message` (`Scheme::Ed25519`), broadcast over JSON-RPC. The `ed25519_dalek` local signer is `cfg(test)` only. Also hosts `sign_and_broadcast_versioned` behind the crate-internal `sign_and_broadcast_solana`. |
+| `crates/openhuman-core/src/web3/wallet/chains/tron.rs` | Tron native + TRC20 transfers over TronGrid REST: the node builds the raw transaction, `tinywallet_bus::tx::tron::{recompute_txid, verify_contract}` checks it matches what was requested, then it is signed in the module as `TransactionSpec::Tron`. Address checks via `tinywallet_bus::address::tron`. |
| `crates/openhuman-core/src/web3/wallet/stub.rs` | Disabled-wallet facade compiled when `web3` is off; mirrors the subset of the real surface that always-on / other-gated callers need, with no-op / disabled-error bodies. See the Compile-time gate section. |
| `crates/openhuman-core/src/web3/wallet/test_support.rs` | `#[cfg(test)]` shared plumbing: `TEST_LOCK`, `setup_wallet_in` (deterministic "abandon … about" mnemonic), per-chain sample addresses. |
## Public surface
From `mod.rs` re-exports:
-- **Onboarding (`ops`)**: `setup`, `status`, `WalletAccount`, `WalletChain`, `WalletSetupParams`, `WalletSetupSource`, `WalletStatus`; `pub(crate) secret_material`.
+- **Onboarding (`ops`)**: `setup`, `status`, `reveal_recovery_phrase`, `RevealRecoveryPhraseResult`, `WalletAccount`, `WalletChain`, `WalletSetupParams`, `WalletSetupSource`, `WalletStatus`, `WALLET_NOT_CONFIGURED_MESSAGE`; `pub(crate) secret_material`.
- **Execution (`execution`)**: `balances`, `chain_status`, `execute_prepared`, `wallet_network_defaults`, `prepare_transfer`, `tx_status`, `tx_receipt`, `lookup_tx`, `supported_assets`, `prepared_quotes_for_test`; types `BalanceInfo`, `ChainStatus`, `ExecutePreparedParams`, `ExecutionResult`, `PrepareTransferParams`, `PreparedKind` (NativeTransfer / TokenTransfer), `PreparedStatus`, `PreparedTransaction`, `ProviderStatus`, `SupportedAsset`, `TxState`, `TxStatusInfo`, `TxReceiptInfo`, `TxLookupInfo`. Crate-internal: `sign_and_broadcast_evm`, `sign_and_broadcast_solana`, `RawBroadcastResult`.
-- **Defaults (`defaults`)**: `asset_catalog`, `default_rpc_url`, `env_var_for_chain`, `evm_asset_catalog`, `explorer_tx_url`, `find_asset`, `find_asset_for_network`, `network_defaults`, `rpc_source_for_chain`, `rpc_url_for_chain`, `rpc_url_for_evm_network`, `EvmNetwork`, `RpcSource`, `WalletAssetDefinition`, `WalletNetworkDefaults`.
+- **Defaults (`defaults`)**: `asset_catalog`, `default_rpc_url`, `env_var_for_chain`, `evm_asset_catalog`, `explorer_tx_url`, `find_asset`, `find_asset_for_network`, `network_defaults`, `rpc_source_for_chain`, `rpc_url_for_chain`, `rpc_url_for_evm_network`, `solana_cluster`, `EvmNetwork`, `RpcSource`, `SolanaCluster`, `WalletAssetDefinition`, `WalletNetworkDefaults`.
- **ABI**: `encode_erc20_transfer`.
- **Schemas**: `all_controller_schemas`, `all_registered_controllers`, `all_wallet_controller_schemas`, `all_wallet_registered_controllers`, `schemas`, `wallet_schemas`.
## RPC / controllers
-Namespace `wallet` (method form `openhuman.wallet_<function>`), 12 controllers registered via `all_wallet_registered_controllers`:
+Namespace `wallet` (method form `openhuman.wallet_<function>`), 13 controllers registered via `all_wallet_registered_controllers`:
| Function | Purpose |
| --- | --- |
| `status` | Onboarding status + safe account metadata (addresses). |
-| `setup` | Persist consent + derived accounts + encrypted mnemonic (all inputs required). |
+| `setup` | Persist consent + derived accounts + encrypted mnemonic (all inputs required); refuses to overwrite a configured wallet unless `force: true`. |
| `balances` | Native-asset balances per account (EVM live; others provider-gated). |
| `network_defaults` | RPC/explorer/capability flags + asset catalogs per chain. |
| `supported_assets` | Built-in asset catalog incl. default EVM ERC-20s / BEP20s. |
@@ -83,6 +83,7 @@ Namespace `wallet` (method form `openhuman.wallet_<function>`), 12 controllers r
| `tx_status` | Check a transaction's lifecycle state (pending/confirmed/failed/not_found) by hash. |
| `tx_receipt` | Fetch a transaction receipt (success, fee, block) by hash. |
| `lookup_tx` | Look up the raw transaction payload by hash. |
+| `reveal_recovery_phrase` | Decrypt and return the stored BIP-39 phrase (`{phrase, wordCount}`); read-only, for transient display in the UI. |
Wired into the registry in `crates/openhuman-core/src/core/all.rs` (controllers + schemas + capability description).
@@ -105,20 +106,21 @@ None. The module publishes/subscribes no `DomainEvent`s and has no `bus.rs`. Cha
## Persistence
- **`{workspace_dir}/state/wallet-state.json`** — `StoredWalletState`: consent flag, source, mnemonic word count, accounts, `updated_at_ms`, and (only as fallback) the encrypted mnemonic. Written atomically (temp file + `sync_all` + dir fsync + `persist`), guarded by a process-wide `WALLET_STATE_FILE_LOCK`. Corrupt/unreadable/invalid files are quarantined to `…json.corrupted.<ts>`.
-- **OS keychain** — preferred home for the encrypted mnemonic under key `wallet.mnemonic`, scoped by a workspace-derived user id (`crate::security::keyring`). When available, the secret is stripped from JSON; load promotes any JSON-resident secret into the keychain.
+- **OS keychain** — preferred home for the encrypted mnemonic under key `wallet.mnemonic`, scoped by a workspace-derived user id (`crate::security::keyring`), used only when `keyring_consent::policy::check_secret_access()` returns `Proceed` and the keyring is available. When available, the secret is stripped from JSON; load promotes any JSON-resident secret into the keychain.
- **In-memory quote store** (`execution.rs`) — `PreparedTransaction`s, 5-minute TTL, cap 64, pruned on access. Not persisted across restarts.
## Dependencies
- `crate::config` (`Config`, `config::rpc::load_config_with_timeout`) — resolves workspace dir and config for state paths, keychain user id, and decryption.
- `crate::security::keyring` (`is_available`/`get`/`set`) — OS keychain storage for the encrypted mnemonic.
-- `crate::security::encryption::rpc` (`encrypt_secret`/`decrypt_secret`) — chain signers decrypt the recovery phrase before derivation.
+- `crate::security::encryption::rpc` (`encrypt_secret`/`decrypt_secret`) — chain executors decrypt the recovery phrase before handing it to the wallet module.
+- `crate::modules::wallet` (`derive_account`, `sign_transaction_in_module`, `sign_message`) — the loaded `tinywallet` native module does every derivation and signature; the phrase is only sent after the module passes the attestation check (`modules::wallet::attested_proxy`).
- `crate::security::approval::APPROVAL_CHAT_CONTEXT` — task-local chat owner (`thread_id`/`client_id`) used to bind quotes to their originating thread.
- `crate::tools::traits` — `Tool`/`ToolResult`/`ToolCallOptions` for the agent tools.
- `crate::core::all` (`ControllerFuture`, `RegisteredController`) and `crate::core` (`ControllerSchema`, `FieldSchema`, `TypeSchema`) — RPC controller registry wiring.
- `crate::rpc::RpcOutcome` — standard RPC return shape.
- `tinywallet-bus` (`vendor/tinywallet/crates/tinywallet-bus`, optional, gated by the `web3` feature; features `btc`, `evm`, `solana`, `tron`, `keccak`, `net`, `wire`, `eip712`, `abi`, `tx-codec`) — the contract crate. It owns address formats (parsing/validation/conversion) and the wire types crossing the `Transport` seam (`SecretMaterial`, `TransactionSpec`, `NetworkId`), the ERC-20/EIP-712 encoders, and the Tron verifier. Per Cargo.toml's own rationale: taken as the contract crate and NOT the root `tinywallet` crate — key derivation, transaction building, signing and the chain clients (including the `bitcoin` crate and its native secp256k1 build) live inside that loaded module now, so this binary links none of it. The root `tinywallet` crate is still a dev-dependency, used only so test fixtures can derive a known account from a BIP-39 vector phrase.
-- Other external crates: `k256` (secp256k1 signing over digests the wallet hands back — replaces `bitcoin`/`secp256k1` as a direct dependency), `coins-bip39` (shared BIP-39 mnemonic → seed for BTC/Tron/Solana derivation), `ed25519-dalek` (Solana signing), `curve25519-dalek` (Solana off-curve ATA check), `bs58` (Solana/Tron base58 addresses), `sha2`, `hex`, `reqwest`, `serde`/`serde_json`, `tempfile`, `parking_lot`, `once_cell`.
+- Other external crates: `curve25519-dalek` (optional, pulled in by the `web3` feature; Solana off-curve ATA check), `bs58` (Solana base58 program ids/addresses), `sha2` (Solana ATA/PDA derivation), `hex`, `reqwest`, `serde`/`serde_json`, `tempfile`, `parking_lot`, `once_cell`. `k256`, `coins-bip39`, `ed25519-dalek` and the root `tinywallet` crate are test-only here (the `web3` feature does not enable `k256`/`coins-bip39`): they back the `cfg(test)` local signers in `chains/solana.rs`, `execution.rs` and the test fixtures, so unit tests can run without a loaded module.
## Used by