onionwire/docs/WALLET.md
agent 93deaa5309
All checks were successful
ci / test (pull_request) Successful in 6m39s
ci / sdk (pull_request) Successful in 1m31s
android-ci / android (pull_request) Successful in 12m57s
ci / fuzz (pull_request) Successful in 5m3s
wallet: unlocked balance, restore height, outgoing rows, send, view-only import
`get_balance` carries two numbers and the wallet screen only showed one:
`Node::wallet_balance_line` now reads both out of a single answer
(`balance {total} XMR · unlocked {unlocked} XMR`, the `balance 0 XMR` prefix
kept, total-only when the RPC reports no unlocked half), and
`Node::wallet_unlocked_balance` reports the unlocked half on its own with
`wallet_balance`'s `off` / `err` sentinels. `wallet_balance` keeps its shape.

`get_transfers` sends `out: true` and parses the `out` bucket, so `TransferRow`
carries `direction` (`in`, `out`, `pending`; a pending item's own `type` wins)
and the screen can tell a spent transfer from a received one.

`Wallet::restore_wallet` / `Node::wallet_restore` take an optional
`restore_height` beside the seed offset: blank omits the field, a typed `0` is
sent as `0`, `Some(n)` is a JSON number, and a non-numeric height is a local
refusal (`restore height must be a block number`). A height after the first
receive hides the older funds and this version has no rescan — the TUI says so
on its own step, whose footer is not the offset's.

`Node::wallet_send` spends to a pasted address: `check_address`, then
`xmr_to_atomic`, then `Wallet::transfer` — no friend, no `tip` frame, no chat
line, no payment row. The outgoing transfer list is the record. `pay::check_address`
and `Wallet::transfer` own the gates, so a view-only or unsynced refusal is the
string they already return.

`Wallet::import_view_only` / `Node::wallet_import_view_only` watch an address
through `generate_from_keys` with no `spendkey` in the request at all: same
filename/password refusals, `check_address`, a 64-hex view key or a local
refusal, no 64th catalogue column. The view key is typed into a hidden entry
(twice), is never sealed, never logged and never on an argv, and the screen
wipes it on every exit.

TUI: `n` sends (address, amount, then `SEND`; Esc spends nothing), `y` copies
the receive address over OSC 52, `v` imports a view-only wallet (no seed, so no
`SEEN` gate), and the seed import gained a `restore height` step between the
offset and the file passphrase. The wallet footer and its help line carry the
new keys and keep every old token. The F6 body renders in the flexible region —
a bordered block in the two-row slot it used drew its borders and clipped the
whole body, address and balance line included.

SDK: `wallet_unlocked_balance`, `wallet_send`, `wallet_view_only`,
`import_seed(password, seed, offset, height)` and
`import_view_only(password, address, view_key, height)`, plus
`TransferRow.direction`. `wallet_balance`, `import_wallet` and
`import_wallet_with_offset` are untouched.

Docs: WALLET (unlocked vs total, restore height, outgoing rows, local send,
view-only import), THREAT_MODEL (a view key entered at import is a secret and a
view-only file is not a spend authority), TUI (footer + the new keys and steps),
README (one sentence).

Tests: recorded-request cases in `tests/wallet.rs` (height as a number and
omitted when blank, `generate_from_keys` carries the view key and no spendkey,
`get_transfers` asks for `out`, `wallet_send` reaches `transfer` and never
`tip`, a bad view key never dials), node-level line/unlocked pairs from one
dial, and TUI step tests for the send, copy, height and view-only flows.

No new crate, no Cargo change, no android/ change.
2026-09-25 02:23:09 -04:00

23 KiB

OnionWire + monero-wallet-rpc

Chat does not require a wallet. A wallet is opt-in.

Default: no spend. No seed and no spend key on the device. Receive uses the profile xmr_addr, or a view-only wallet for invoices (create_address) and receipt checks (get_transfers). /tip is off.

Spend is opt-in at wallet create or restore (seed-backed). That makes OnionWire a local spend authority for that wallet file — see the spend-authority warning below. Threat model: THREAT_MODEL.md. TUI keys: TUI.md.

The app talks to monero-wallet-rpc over loopback HTTP Digest only, and it can own that process itself:

  • hand out a receive subaddress for /pay invoices (create_address),
  • read incoming transfers to verify a peer's receipt (get_transfers),
  • and — only if you opted into spend — /tip (transfer).

Prefer view-only until you actually want /tip.

Wallet RPC is never on clearnet and never over .onion. Chain traffic is off unless you opted into a wallet and chose a source. A remote daemon is untrusted (--trusted-daemon is never passed).

Ports (do not swap these)

Port What it is
18081 App-owned local daemon unrestricted RPC (DEFAULT_MONEROD_RPC_PORT in src/wallet_child.rs). Spawned monerod and in-process Cuprate both bind 127.0.0.1:18081. The wallet child dials that.
18089 A daemon's restricted-RPC port. It belongs only in examples of a remote --daemon-address you type. Not the app-owned local port.
random loopback App-owned monero-wallet-rpc bind (127.0.0.1:0, then the port is kept).

A doc or config that puts the local child on 18089 is wrong.

The app-owned wallet child

src/wallet_child.rs owns the child pair instead of asking you to export an env var:

  • monero-wallet-rpc is spawned with --rpc-bind-ip 127.0.0.1, a random free loopback port, a generated --rpc-login (user:pass, random [a-z0-9]), and --wallet-dir $ONIONWIRE_HOME/wallet. No --wallet-file and no --password: argv is world-readable to the same user through ps, so the wallet is opened over RPC (open_wallet) once the child is up, and never named on the command line.
  • monerod is spawned when the chain source is local: --non-interactive --data-dir <datadir> --rpc-bind-ip 127.0.0.1 --rpc-bind-port 18081. The wallet child dials 127.0.0.1:18081.
  • Start waits up to 5s for 127.0.0.1:18081 to accept before spawning monero-wallet-rpc, and up to 5s for that child's own port before open_wallet. A closed port fails the start. A connect refusal while state is still connecting is not shown as an error.
  • arti is spawned as a SOCKS child only when the chain source is a .onion daemon: arti proxy -p <port>.
  • --trusted-daemon is never passed.
  • Wallet dir 0700, wallet file 0600.
  • The child is watched by polling (try_wait). stop() kills children on shutdown. Nothing promises “always running”, and Android will not.

Generated user:pass is sealed with the store data key in the SQLCipher wallet_child table. It never appears in ONIONWIRE_WALLET_RPC.

monero-wallet-rpc starts with no wallet open and keeps one open only for the life of its process, so a restart (app relaunch, Lock/unlock, a wallet re-point) would otherwise answer every read with -13 No wallet file while the file sits on disk. After the child is up the app therefore issues open_wallet for the configured catalogue row.

That needs the passphrase, and the app keeps it: the passphrase you type at create/import (or the one you enter once for a wallet that predates this) is sealed with the store data key in the SQLCipher wallet_config row, beside the RPC creds, under its own AAD. It is never logged, never put in an error string, and never on a process argv. The consequence is deliberate and stated in THREAT_MODEL.md: the store passphrase is now sufficient to spend — an attacker who has it can open the wallet file and move the balance, without a second secret. The spend-authority warning at create/restore is unchanged and is not made weaker by this.

Wipe semantics: /wipe keeps the wallet file and its passphrase (the file survives /wipe today); /wipe-all removes the data dir, as before.

If the stored passphrase does not open the configured file — a wallet the catalogue holds but whose passphrase changed, or one created on another install — the app reports it against that file and does not overwrite the stored one. The child is stopped rather than left answering -13, and the status reports needs passphrase; open the file once with its real passphrase (open_wallet_with_passphrase, or the TUI/Android prompt) and it is remembered.

Nothing spawns the child at boot. Node::start_wallet_child is the only start path. The desktop TUI drives it from F6:

Key Effect
s Start the child, then probe it once. A child whose wallet file needs a passphrase opens the passphrase prompt instead of leaving every read at -13.
x Stop it (idempotent).
p Probe: is wallet RPC answering, is the chain at the tip?
1 / 2 / 3 Store in-process Cuprate as mainnet-pruned / mainnet-full / testnet.

State shown: off / connecting / syncing / ready / exited, plus a chain-source label, plus wallet locked while a catalogue wallet is configured but not open in the child's RPC. ready is never reported for a child that has died. A live child is not a usable wallet: wallet_status() carries wallet_open and needs_passphrase so a client can tell "the wallet is open" from "the child is up and waiting for a passphrase".

Once a probe has read the daemon, the line can include sync <height>/<target> — the daemon's height and the tip it is syncing towards (wallet RPC get_info, or the local daemon's get_info when wallet RPC does not answer). sync 0/0 or no segment means unknown, not caught up.

start is idempotent: a live child is reported, not respawned.

Chain source

You pick one. OnionWire does not pick a public remote node for you.

ChainSource::None                             receive-only; no child, no daemon
ChainSource::Local { monerod_bin, datadir }   spawn monerod on this box (port 18081)
ChainSource::InProcessCuprate { datadir, … }  daemon inside this app (port 18081)
ChainSource::Remote { host, port }            a daemon address you typed
  1. Local monerod. Chain traffic stays on the box.
  2. In-process Cuprate. No monerod binary. Wallet child still dials 127.0.0.1:18081. See below.
  3. A daemon address you supply — becomes --daemon-address on the wallet child. Loopback if you already run monerod. .onion if you want chain traffic over Tor. Clearnet only if you type it — never a default. Restricted RPC on 18089 is a common remote example, but you supply the port.

Settings live in the sealed wallet_child record (ChildConfig: source, wallet_rpc_bin, arti_bin, wallet_filename). Core: Node::wallet_child_config / set_wallet_child_config, then start_wallet_child / stop_wallet_child / wallet_child_status / wallet_child_refresh.

The in-process chain daemon (cuprate-daemon)

cargo build --release --features cuprate-daemon
  • Off by default. cuprated is pre-1.0, not on crates.io (placeholder crates), git-pinned, behind the feature. Without the feature, a stored in-process source can still be read back, but start fails with this build has no in-process chain daemon — rebuild with --features cuprate-daemon.
  • Pre-production. Cuprate's own user book says do not use cuprated for serious purposes. RPC parity is incomplete (docs/cuprate-launch-spike.md).
  • Mainnet is unvalidated. The TUI can store mainnet-pruned (F6 1) or mainnet-full (F6 2) or testnet (F6 3). Every in-process surface still prints testnet only — mainnet is unvalidated (cuprate::TESTNET_ONLY). Cross-compiled is not device-proven. Pointing a mainnet wallet at it is not something this build claims to do.
  • No Tor on the chain path. Cuprate's arti feature is off (arti-client 0.44 vs this crate's 0.46). P2P is clearnet. OnionWire's Arti is the messenger only.
  • Inbound P2P off, restricted RPC listener disabled. Unrestricted RPC is loopback 18081. --trusted-daemon still never passed.
  • Chain lives under $ONIONWIRE_HOME/chain/… (split dirs so pruned mainnet cannot mix with full). Database is fjall, not SQLCipher.
  • Not a child process: dropping the node shuts it down. x / stop_wallet_child asks it to stop with the wallet child.

Chain traffic over Tor (.onion daemons)

A .onion daemon cannot be dialled directly. The wallet child is an external C++ binary, so it reaches Tor through a SOCKS proxy the app provides:

  • Bundled arti binary: arti proxy -p <random free loopback port>. A second Tor client, not the messenger's in-process one. No C-tor.
  • Listener is TCP loopback only. Any local process at your privilege can use it.
  • Wallet child: --proxy socks5://127.0.0.1:<port> and --daemon-address <onion>:<port>. The socks5:// scheme is required (Monero defaults to SOCKS4a for a bare host:port). No local DNS on the onion target.
  • Own state/cache: $ONIONWIRE_HOME/wallet/arti-socks/{state,cache}.
  • Wait up to 20s for the SOCKS listener before spawning the wallet child.
  • SOCKS child stops with the wallet child.

Tor hides the transport, not the host. The daemon operator still sees the wallet's addresses during sync.

Readiness — receipt verification needs a synced daemon

chain_ready() asks the wallet RPC get_info and requires synchronized == true with height > 0 and height >= target_height. A missing field is not ready — fail closed.

Until then, receipt verification stays verified=0. An unsynced wallet cannot see the chain. That is an honest limit, not a UI bug.

Loopback management calls (get_address, query_key, create/import) get 5s. Calls that wait on the chain (get_info, get_transfers, transfer) get 60s (CHAIN_RPC_TIMEOUT).

Env vars (migration path)

Variable Meaning
ONIONWIRE_WALLET_RPC http://[user:pass@]host[:port][/path] for an externally run monero-wallet-rpc. Unset → no wallet; chat still works; /pay falls back to profile xmr_addr. The app-owned child does not use this.
ONIONWIRE_WALLET_RPC_LOGIN user:pass when the URL has no userinfo.
ONIONWIRE_WALLET_NO_SPEND 1 / true / yes / on → /tip refused locally before any RPC dial.

Boot precedence: stored config → env → disabled. Stored config that cannot be used (non-loopback, .onion, missing login) is reported and falls back to env rather than dialling the bad endpoint.

Store::save_wallet_config / Node::wallet_save_config exist. No TUI screen writes them. There is no F7. The not-configured refusal still says wallet not configured — open F7 to set it up, or set ONIONWIRE_WALLET_RPC (src/wallet.rs). Live surfaces: F6, F9, or the env vars.

/pay and /tip run wallet_readiness before send:

  1. not configured → the F7-worded message above
  2. /tip on view-only / ONIONWIRE_WALLET_NO_SPEND → refused before any dial
  3. configured but not connected → wallet not connected — check endpoint, login, daemon
  4. otherwise ready (/pay is fine on view-only)

Android / SDK

UniFFI: set_chain_source(ChainConfig) / chain_source(), start_wallet_child(), stop_wallet_child(), wallet_status() (cached read: no dial, for first paint) and wallet_child_refresh() (a live probe of the same record — it dials the loopback wallet RPC, and the local daemon's get_info when that RPC does not answer, so poll it on the order of seconds). Pass absolute paths for wallet_rpc_bin / arti_bin (nativeLibraryDir); the core never resolves a binary the caller named explicitly.

ChainChoice.InProcessCuprate is the in-process variant. Empty monerod_datadir resolves to $ONIONWIRE_HOME/chain. start_wallet_child() launches the node and the wallet child. wallet_status() carries chain_in_process, node_available, and node_state.

Monero ships no Android binaries. Any vendored blob's provenance doc must say so. Cross-compiled is not device-proven. See android/MONERO_BINARIES.md.

The wallet catalogue, and which wallet is open

wallets() lists every wallet this install remembers (oldest first), each row carrying the wallet_filename the child opens, its label, the owning identity pubkey as hex, and the locator. active_wallet_filename() returns the file the child is currently pointed at (or None on a fresh install), so a picker can mark the open row. open_wallet(filename) switches to a catalogue row: a running child is stopped and restarted onto the new file, an idle one is only re-pointed (the change applies at the next start_wallet_child), and a file the catalogue does not hold is refused — the catalogue is the only directory this app keeps wallets in. The restarted child then opens that file with the stored passphrase; when this install has none for it, the call still succeeds and the status says needs_passphrase — that is what the prompt is for, and open_wallet_with_passphrase(filename, passphrase) is the API behind it. It stores the passphrase only after a live daemon has opened the file with it.

Secrets belong to the open wallet

The seed (wallet_seed(), query_key mnemonic) and the private keys (wallet_keys() → query_key view_key / query_key spend_key) are answered by the wallet file the child has open, so they always belong to the row active_wallet_filename() names. There is deliberately no accessor that reads another saved wallet's seed or keys without opening it: show a backups screen, then open_wallet(...) the row — the UI must say which wallet it is showing. WalletKeys.spend_key is None for a view-only wallet (the RPC's -29), which is an answer, not an error.

Both values are spend secrets. They are displayable on demand in the TUI and in the Android app, are never logged, never written to the store or to disk, and never put into an error string (the core's WalletKeys Debug redacts them). The exposure this creates is enumerated in THREAT_MODEL.md, "The recovery phrase and the private keys are displayable on demand".

Create vs import

/wallet create (F6 then c) → create_wallet, then seed once (query_key mnemonic). Type SPEND, set a passphrase, write the seed, type SEEN. The passphrase you set is sealed in the store (above), so the wallet reopens on the next start without asking for it again.

/wallet import (F6 then i) → restore_deterministic_wallet from a 25-word seed. Do not put the seed on the composer. The import also takes an optional seed-offset passphrase — a second spend secret mixed into the words at restore time, not the wallet-file passphrase. It is never sealed, never stored, never logged and never on an argv: blank Enter skips it, and a wrong offset is not an error — the RPC succeeds and opens a different wallet. After an import that used one, query_key mnemonic is the mnemonic of the keys the wallet actually holds (the derived seed), so a later seed backup restores this wallet without the offset; the original words plus the offset are the other backup, and the app keeps neither.

The import asks for an optional restore height after the offset step. Blank Enter scans from block 0, which is what a plain import wants. A height after your first receive hides the older funds — the wallet never scans below it — and this version has no rescan to undo that, so set a height at or before the first incoming transfer or leave it blank. The request carries a restore_height field only when you typed one (a typed 0 is sent as 0); a height that is not a block number is refused locally with restore height must be a block number.

F6 then v imports an address to watch instead: generate_from_keys with the address and its private view key, and no spendkey in the request at all. The file it writes can see incoming transfers and cannot spend — transfer on it is the RPC's own -29, surfaced as the view-only message. The view key is a secret (anyone holding it and the address sees the incoming transfers): it is typed into a hidden entry (twice — a mismatch is view keys do not match with no dial), goes to the RPC, and is kept nowhere else — not sealed, not in the catalogue, not logged, never on an argv. What is sealed is the wallet-file passphrase, exactly as for a created or seed-imported wallet, so the file reopens on the next start. There is no seed on this path, so there is no SEEN step.

RPC must be started with --wallet-dir (not only --wallet-file). A created wallet gets its own file name (onionwire-1, onionwire-2, …): wallet_filename is UNIQUE in the catalogue, so a second create must not reuse the first file.

Balance: total and unlocked

get_balance answers with two numbers and OnionWire exposes both: the total (wallet_balance, everything the wallet has scanned, including amounts still locked behind confirmations or immature) and the unlocked part (wallet_unlocked_balance), the funds a spend can use right now. The wallet screen shows them on one line, from one request:

balance 0.9 XMR · unlocked 0.45 XMR

Node::wallet_balance_line builds it, and the two sentinels are its own: wallet off when no wallet RPC is configured, balance — when the RPC did not answer with a total. (wallet_balance and wallet_unlocked_balance keep the bare off / err words the WALLETS & SETTINGS menu tones and the SDK read.) A wallet that shows a balance but refuses to spend is usually this distinction: the incoming transfer is still confirming. Both numbers come out of one get_balance request, never two.

Send to a pasted address (F6 then n)

A local transfer on the wallet this install has configured: an address, an amount, then SEND to confirm. There is no friend, no tip frame, no chat line and no payment row — the wallet's own outgoing transfer list is the record, so n works with no peer online and leaves nothing in a conversation. A view-only or unsynced wallet is refused with the same strings /tip uses. The receive address has its own key, y, which copies it through the terminal's clipboard (OSC 52); the seed path stays clipboard-free.

 wallet host (this machine)
 ┌──────────────────────────────────────────────────────────────┐
 │ monero-wallet-rpc  --rpc-bind-ip 127.0.0.1 --rpc-login u:p    │
 │        ▲  HTTP Digest, loopback only                          │
 │        │                                                      │
 │ OnionWire (ONIONWIRE_WALLET_NO_SPEND=1)  ── /pay, receipts    │
 │        └── /tip refused locally                               │
 └──────────────────────────────────────────────────────────────┘

Loopback is the only address OnionWire will dial for wallet RPC.

Create a view-only wallet

Keep the seed / spend key on a machine that is not running OnionWire.

monero-wallet-cli --generate-from-view-key "$HOME/.onionwire-viewonly" \
  --daemon-address "$YOUR_MONEROD:18089" --restore-height "$BIRTH_HEIGHT"

18089 here is the remote daemon's restricted RPC, an address you type — not the app-owned 18081.

monero-wallet-rpc --wallet-file "$HOME/.onionwire-viewonly" \
  --rpc-bind-ip 127.0.0.1 --rpc-bind-port 18083 --rpc-login onionwire:secret \
  --daemon-address "$YOUR_MONEROD:18089"

export ONIONWIRE_WALLET_RPC=http://127.0.0.1:18083
export ONIONWIRE_WALLET_RPC_LOGIN=onionwire:secret
export ONIONWIRE_WALLET_NO_SPEND=1

Restore from a height at or before the first incoming transaction.

What works, what does not

Feature View-only Spend-capable
/pay <xmr> invoice subaddress (create_address) works works
Receipt verification (get_transfers) works, if daemon is synced works, if daemon is synced
Profile xmr_addr fallback when RPC is down works works
/tip <xmr> (transfer) cannot work works
send to a pasted address (F6 n, transfer) cannot work works
OnionWire copies your spend key into its own process never never (it stays in the wallet file / RPC)
Show the backup (seed via query_key mnemonic) no seed to show (the RPC answers -29) works
Show the private keys (wallet_keys) view key only, spend_key is None view + spend key

ONIONWIRE_WALLET_NO_SPEND=1 refuses /tip before RPC with:

wallet is in view-only/no-spend mode — /tip is disabled; /pay and receipt verification still work

View-only detection after a failed transfer: query_key spend_key → -29 watch-only. The spend key is discarded immediately. OnionWire never probes a healthy wallet for this.

Why loopback still needs authentication

--rpc-bind-ip 127.0.0.1 keeps the port off the network; it does not keep it away from other processes on the same machine.

OnionWire refuses an RPC that answers HTTP 200 without a Digest challenge, and refuses URLs without credentials. Prefer ONIONWIRE_WALLET_RPC_LOGIN over userinfo in the URL. Do not log the password.

monero-wallet-rpc mints its Digest nonce per TCP connection (epee's http_custom_handler owns the auth state), so the challenge and the authenticated retry have to ride the same socket — a retry on a fresh connection is refused with 401 no matter how correct the login is. OnionWire does exactly that. A wallet RPC HTTP HTTP/1.1 401 Unauthorized status therefore means one thing: the login does not match the child's --rpc-login. Regenerate the child (and its sealed creds) rather than retrying.

The spend-authority warning

An OnionWire instance pointed at a spend-capable monero-wallet-rpc is a local spend authority: any process that can read the RPC credentials (env var, /proc/<pid>/environ, shell history, a stored URL) can spend the wallet's balance, and /tip gives a chat peer a supported path to ask for a transfer.

That is why view-only plus ONIONWIRE_WALLET_NO_SPEND=1 is the recommended default. If you want tips, use a separate hot wallet with a small balance, not your savings wallet.

Payments are one-shot

/pay and /tip fail when the peer onion is down. There is no queued invoice. File transfer is the same rule.

References