onionwire/docs/WALLET.md

452 lines
23 KiB
Markdown
Raw Permalink Normal View History

# 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. The threat-model write-up is [THREAT_MODEL.md](THREAT_MODEL.md).
wallet: app-owned child lifecycle + user-chosen ChainSource The app now owns monero-wallet-rpc (and monerod when the chain source is local) instead of requiring the user to start them and export ONIONWIRE_WALLET_RPC. - ChainSource enum: None / Local { monerod_bin, datadir } / Remote { host, port }. No default remote node; Remote is only constructed from explicit user input. A .onion Remote is refused without a SOCKS proxy (separate card). - WalletChild in src/wallet_child.rs spawns monero-wallet-rpc with --rpc-bind-ip 127.0.0.1, a random free loopback port, generated --rpc-login, and --wallet-dir /wallet; monerod too for a local source. --trusted-daemon is never passed. - Generated RPC creds are sealed in the encrypted SQLCipher store (wallet_child table, AEAD on top of whole-db encryption), never a plaintext file. The Wallet client is built from the generated loopback URL, not from_env. - Readiness predicate: chain_ready() requires synchronized==true, height>0, height>=target_height; can_spend() and can_verify_receipts() gate on it. Unsynced -> receipts stay verified=0, spend refused with a clear message. - Backend-aware timeouts: local management calls keep 5s; chain-dependent calls (get_info, get_transfers, transfer) get 60s (CHAIN_RPC_TIMEOUT), because a first sync or a remote daemon outlasts 5s and a 5s cap there is what left receipts permanently unverified. - node.rs ingest_receipt gates on can_verify_receipts() instead of configured() alone. - docs/WALLET.md rewritten for the child lifecycle + chain source. Base: feat/wallet-create-import (PR #66). Do not rebase onto main. Co-Authored-By: Hermes Agent <agent@local>
2026-09-14 18:55:07 -04:00
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`.** Everything else in this
document explains why, and what breaks when you do.
wallet: app-owned child lifecycle + user-chosen ChainSource The app now owns monero-wallet-rpc (and monerod when the chain source is local) instead of requiring the user to start them and export ONIONWIRE_WALLET_RPC. - ChainSource enum: None / Local { monerod_bin, datadir } / Remote { host, port }. No default remote node; Remote is only constructed from explicit user input. A .onion Remote is refused without a SOCKS proxy (separate card). - WalletChild in src/wallet_child.rs spawns monero-wallet-rpc with --rpc-bind-ip 127.0.0.1, a random free loopback port, generated --rpc-login, and --wallet-dir /wallet; monerod too for a local source. --trusted-daemon is never passed. - Generated RPC creds are sealed in the encrypted SQLCipher store (wallet_child table, AEAD on top of whole-db encryption), never a plaintext file. The Wallet client is built from the generated loopback URL, not from_env. - Readiness predicate: chain_ready() requires synchronized==true, height>0, height>=target_height; can_spend() and can_verify_receipts() gate on it. Unsynced -> receipts stay verified=0, spend refused with a clear message. - Backend-aware timeouts: local management calls keep 5s; chain-dependent calls (get_info, get_transfers, transfer) get 60s (CHAIN_RPC_TIMEOUT), because a first sync or a remote daemon outlasts 5s and a 5s cap there is what left receipts permanently unverified. - node.rs ingest_receipt gates on can_verify_receipts() instead of configured() alone. - docs/WALLET.md rewritten for the child lifecycle + chain source. Base: feat/wallet-create-import (PR #66). Do not rebase onto main. Co-Authored-By: Hermes Agent <agent@local>
2026-09-14 18:55:07 -04:00
## The app-owned wallet child
`src/wallet_child.rs` owns the child pair instead of asking you to start it and
export an env var:
- **`monero-wallet-rpc`** is spawned with `--rpc-bind-ip 127.0.0.1`, a **random
free loopback port** (bind `127.0.0.1:0`, read the port, drop the listener, pass
it on — two instances on one box cannot collide), a generated `--rpc-login`
(`user:pass`, random `[a-z0-9]`, no shell or HTTP metacharacters), and
`--wallet-dir $ONIONWIRE_HOME/wallet`.
- **`monerod`** is spawned too when the chain source is *local*:
`--non-interactive --data-dir <datadir> --rpc-bind-ip 127.0.0.1 --rpc-bind-port
18081`. One box, one daemon: the wallet child dials it at `127.0.0.1:18081`.
- `--trusted-daemon` is never passed. A remote daemon stays untrusted.
- The wallet dir is created `0700` and the wallet file is kept `0600` — it is a
spend authority.
- The child is watched by polling (`try_wait`); an exit is reported rather than
hidden, and `stop()` kills both children on shutdown. The next launch starts
them again. Nothing promises "always running", and Android will not.
### Where the RPC credentials live
The generated `user:pass` is **sealed with the store data key and kept in the
encrypted SQLCipher store** (`wallet_child` table, AEAD with the store key on top
of whole-db encryption). It is never written to a plaintext file next to the
wallet, and it never appears in `ONIONWIRE_WALLET_RPC`. They persist across
launches, so the child restarts with the same login without asking you again.
The wallet passphrase is a separate thing: the child prompts/needs it for
`create_wallet` / `restore_deterministic_wallet`, and that is your runtime choice,
not something the app stores for you.
## Chain source
The wallet needs a daemon for scan, verify, and spend. You pick one; OnionWire
wallet: in-process Cuprate chain daemon behind the cuprate-daemon feature Phase 1 of the Cuprate integration strategy: the chain daemon can run inside the OnionWire process instead of a spawned `monerod`. `monero-wallet-rpc` is unchanged — it still dials the unrestricted loopback RPC on 127.0.0.1:18081, which is the address `WalletChild::daemon_address` already returned — so no wallet-layer code moves. - Cargo.toml: `cuprated` (git, rev 4f8fcd1b) + `toml`, both optional, behind a `cuprate-daemon` feature that is OFF by default. Cuprate's own `arti` feature stays off: its arti-client 0.44 cannot unify with this crate's 0.46, and the in-process daemon is clearnet-only, so this keeps one Tor stack in the process. `Cargo.lock` gains the graph; no arti 0.44 appears in it. - src/cuprate.rs (new): `CuprateNode` builds the cuprated config as TOML (testnet, unrestricted RPC on loopback, restricted RPC disabled, inbound P2P off), launches it, and owns it. Dropping the value is the teardown; `shutdown()` is called before the drop so the services can drain. The type exists in every build: without the feature `launch` fails with the feature name instead of silently doing nothing, so the chain-source type, its stored record and the picker do not fork on a cargo feature. - src/wallet.rs: `ChainSource::InProcessCuprate { datadir }`. - src/wallet_child.rs: starts/holds/stops the node, serializes the choice as `kind = "cuprate"`, and adds `chain_datadir` so the storage gate covers both local sources. It takes the app's Tokio handle (`with_runtime`): the launch is async and `start()` runs on the TUI's blocking thread. - src/node.rs: `wallet_child_start(runtime)`, `default_in_process_chain_source`. - src/tui.rs: a fourth picker row, its testnet caveat, the chain block copy, and a stop of the app-owned children on the quit path so they are not orphaned. - tests/wallet.rs: a `cuprate-daemon`-gated end-to-end test that launches the node and drives get_info / get_height / get_block through the typed daemon client, including the above-the-tip 500 and the listener closing on drop. - docs/WALLET.md: the fourth chain source, the feature flag, the +5.6 MB stripped overhead, and the two limits (testnet only, no Tor in the chain path). Also repaired tests/tui_spec.rs, which the parent commit left un-compilable (the Phase 2a commit had dropped all but the new imports and four new tests, 1221 lines of body); it is restored from the pre-breakage version, with the Phase 2a imports and tests re-applied.
2026-09-17 13:17:32 -04:00
does not pick a public remote node for you. The four shapes are:
wallet: app-owned child lifecycle + user-chosen ChainSource The app now owns monero-wallet-rpc (and monerod when the chain source is local) instead of requiring the user to start them and export ONIONWIRE_WALLET_RPC. - ChainSource enum: None / Local { monerod_bin, datadir } / Remote { host, port }. No default remote node; Remote is only constructed from explicit user input. A .onion Remote is refused without a SOCKS proxy (separate card). - WalletChild in src/wallet_child.rs spawns monero-wallet-rpc with --rpc-bind-ip 127.0.0.1, a random free loopback port, generated --rpc-login, and --wallet-dir /wallet; monerod too for a local source. --trusted-daemon is never passed. - Generated RPC creds are sealed in the encrypted SQLCipher store (wallet_child table, AEAD on top of whole-db encryption), never a plaintext file. The Wallet client is built from the generated loopback URL, not from_env. - Readiness predicate: chain_ready() requires synchronized==true, height>0, height>=target_height; can_spend() and can_verify_receipts() gate on it. Unsynced -> receipts stay verified=0, spend refused with a clear message. - Backend-aware timeouts: local management calls keep 5s; chain-dependent calls (get_info, get_transfers, transfer) get 60s (CHAIN_RPC_TIMEOUT), because a first sync or a remote daemon outlasts 5s and a 5s cap there is what left receipts permanently unverified. - node.rs ingest_receipt gates on can_verify_receipts() instead of configured() alone. - docs/WALLET.md rewritten for the child lifecycle + chain source. Base: feat/wallet-create-import (PR #66). Do not rebase onto main. Co-Authored-By: Hermes Agent <agent@local>
2026-09-14 18:55:07 -04:00
```
ChainSource::None receive-only; no child, no daemon
ChainSource::Local { monerod_bin, datadir } the app spawns monerod on this box
wallet: in-process Cuprate chain daemon behind the cuprate-daemon feature Phase 1 of the Cuprate integration strategy: the chain daemon can run inside the OnionWire process instead of a spawned `monerod`. `monero-wallet-rpc` is unchanged — it still dials the unrestricted loopback RPC on 127.0.0.1:18081, which is the address `WalletChild::daemon_address` already returned — so no wallet-layer code moves. - Cargo.toml: `cuprated` (git, rev 4f8fcd1b) + `toml`, both optional, behind a `cuprate-daemon` feature that is OFF by default. Cuprate's own `arti` feature stays off: its arti-client 0.44 cannot unify with this crate's 0.46, and the in-process daemon is clearnet-only, so this keeps one Tor stack in the process. `Cargo.lock` gains the graph; no arti 0.44 appears in it. - src/cuprate.rs (new): `CuprateNode` builds the cuprated config as TOML (testnet, unrestricted RPC on loopback, restricted RPC disabled, inbound P2P off), launches it, and owns it. Dropping the value is the teardown; `shutdown()` is called before the drop so the services can drain. The type exists in every build: without the feature `launch` fails with the feature name instead of silently doing nothing, so the chain-source type, its stored record and the picker do not fork on a cargo feature. - src/wallet.rs: `ChainSource::InProcessCuprate { datadir }`. - src/wallet_child.rs: starts/holds/stops the node, serializes the choice as `kind = "cuprate"`, and adds `chain_datadir` so the storage gate covers both local sources. It takes the app's Tokio handle (`with_runtime`): the launch is async and `start()` runs on the TUI's blocking thread. - src/node.rs: `wallet_child_start(runtime)`, `default_in_process_chain_source`. - src/tui.rs: a fourth picker row, its testnet caveat, the chain block copy, and a stop of the app-owned children on the quit path so they are not orphaned. - tests/wallet.rs: a `cuprate-daemon`-gated end-to-end test that launches the node and drives get_info / get_height / get_block through the typed daemon client, including the above-the-tip 500 and the listener closing on drop. - docs/WALLET.md: the fourth chain source, the feature flag, the +5.6 MB stripped overhead, and the two limits (testnet only, no Tor in the chain path). Also repaired tests/tui_spec.rs, which the parent commit left un-compilable (the Phase 2a commit had dropped all but the new imports and four new tests, 1221 lines of body); it is restored from the pre-breakage version, with the Phase 2a imports and tests re-applied.
2026-09-17 13:17:32 -04:00
ChainSource::InProcessCuprate { datadir } the daemon is inside this app
wallet: app-owned child lifecycle + user-chosen ChainSource The app now owns monero-wallet-rpc (and monerod when the chain source is local) instead of requiring the user to start them and export ONIONWIRE_WALLET_RPC. - ChainSource enum: None / Local { monerod_bin, datadir } / Remote { host, port }. No default remote node; Remote is only constructed from explicit user input. A .onion Remote is refused without a SOCKS proxy (separate card). - WalletChild in src/wallet_child.rs spawns monero-wallet-rpc with --rpc-bind-ip 127.0.0.1, a random free loopback port, generated --rpc-login, and --wallet-dir /wallet; monerod too for a local source. --trusted-daemon is never passed. - Generated RPC creds are sealed in the encrypted SQLCipher store (wallet_child table, AEAD on top of whole-db encryption), never a plaintext file. The Wallet client is built from the generated loopback URL, not from_env. - Readiness predicate: chain_ready() requires synchronized==true, height>0, height>=target_height; can_spend() and can_verify_receipts() gate on it. Unsynced -> receipts stay verified=0, spend refused with a clear message. - Backend-aware timeouts: local management calls keep 5s; chain-dependent calls (get_info, get_transfers, transfer) get 60s (CHAIN_RPC_TIMEOUT), because a first sync or a remote daemon outlasts 5s and a 5s cap there is what left receipts permanently unverified. - node.rs ingest_receipt gates on can_verify_receipts() instead of configured() alone. - docs/WALLET.md rewritten for the child lifecycle + chain source. Base: feat/wallet-create-import (PR #66). Do not rebase onto main. Co-Authored-By: Hermes Agent <agent@local>
2026-09-14 18:55:07 -04:00
ChainSource::Remote { host, port } a daemon address you typed
```
1. **Local `monerod`.** Chain traffic stays on the box. You accept disk, first
sync, and (on Android) the daemon not always running.
wallet: in-process Cuprate chain daemon behind the cuprate-daemon feature Phase 1 of the Cuprate integration strategy: the chain daemon can run inside the OnionWire process instead of a spawned `monerod`. `monero-wallet-rpc` is unchanged — it still dials the unrestricted loopback RPC on 127.0.0.1:18081, which is the address `WalletChild::daemon_address` already returned — so no wallet-layer code moves. - Cargo.toml: `cuprated` (git, rev 4f8fcd1b) + `toml`, both optional, behind a `cuprate-daemon` feature that is OFF by default. Cuprate's own `arti` feature stays off: its arti-client 0.44 cannot unify with this crate's 0.46, and the in-process daemon is clearnet-only, so this keeps one Tor stack in the process. `Cargo.lock` gains the graph; no arti 0.44 appears in it. - src/cuprate.rs (new): `CuprateNode` builds the cuprated config as TOML (testnet, unrestricted RPC on loopback, restricted RPC disabled, inbound P2P off), launches it, and owns it. Dropping the value is the teardown; `shutdown()` is called before the drop so the services can drain. The type exists in every build: without the feature `launch` fails with the feature name instead of silently doing nothing, so the chain-source type, its stored record and the picker do not fork on a cargo feature. - src/wallet.rs: `ChainSource::InProcessCuprate { datadir }`. - src/wallet_child.rs: starts/holds/stops the node, serializes the choice as `kind = "cuprate"`, and adds `chain_datadir` so the storage gate covers both local sources. It takes the app's Tokio handle (`with_runtime`): the launch is async and `start()` runs on the TUI's blocking thread. - src/node.rs: `wallet_child_start(runtime)`, `default_in_process_chain_source`. - src/tui.rs: a fourth picker row, its testnet caveat, the chain block copy, and a stop of the app-owned children on the quit path so they are not orphaned. - tests/wallet.rs: a `cuprate-daemon`-gated end-to-end test that launches the node and drives get_info / get_height / get_block through the typed daemon client, including the above-the-tip 500 and the listener closing on drop. - docs/WALLET.md: the fourth chain source, the feature flag, the +5.6 MB stripped overhead, and the two limits (testnet only, no Tor in the chain path). Also repaired tests/tui_spec.rs, which the parent commit left un-compilable (the Phase 2a commit had dropped all but the new imports and four new tests, 1221 lines of body); it is restored from the pre-breakage version, with the Phase 2a imports and tests re-applied.
2026-09-17 13:17:32 -04:00
2. **An in-process daemon** ([Cuprate](https://github.com/Cuprate/cuprate)
running inside the OnionWire process). No `monerod` binary to install or
spawn, chain on this device, and the wallet child dials the same loopback
port. **Testnet only** in this build, and it needs the `cuprate-daemon`
feature — see "The in-process chain daemon" below.
3. **A daemon address you supply** — becomes `--daemon-address` on the wallet
wallet: app-owned child lifecycle + user-chosen ChainSource The app now owns monero-wallet-rpc (and monerod when the chain source is local) instead of requiring the user to start them and export ONIONWIRE_WALLET_RPC. - ChainSource enum: None / Local { monerod_bin, datadir } / Remote { host, port }. No default remote node; Remote is only constructed from explicit user input. A .onion Remote is refused without a SOCKS proxy (separate card). - WalletChild in src/wallet_child.rs spawns monero-wallet-rpc with --rpc-bind-ip 127.0.0.1, a random free loopback port, generated --rpc-login, and --wallet-dir /wallet; monerod too for a local source. --trusted-daemon is never passed. - Generated RPC creds are sealed in the encrypted SQLCipher store (wallet_child table, AEAD on top of whole-db encryption), never a plaintext file. The Wallet client is built from the generated loopback URL, not from_env. - Readiness predicate: chain_ready() requires synchronized==true, height>0, height>=target_height; can_spend() and can_verify_receipts() gate on it. Unsynced -> receipts stay verified=0, spend refused with a clear message. - Backend-aware timeouts: local management calls keep 5s; chain-dependent calls (get_info, get_transfers, transfer) get 60s (CHAIN_RPC_TIMEOUT), because a first sync or a remote daemon outlasts 5s and a 5s cap there is what left receipts permanently unverified. - node.rs ingest_receipt gates on can_verify_receipts() instead of configured() alone. - docs/WALLET.md rewritten for the child lifecycle + chain source. Base: feat/wallet-create-import (PR #66). Do not rebase onto main. Co-Authored-By: Hermes Agent <agent@local>
2026-09-14 18:55:07 -04:00
child. Loopback if you already run `monerod`. `.onion` if you want chain
traffic over Tor — that needs a SOCKS proxy for the wallet child and is **not
implemented here**: configuring a `.onion` host today fails with a clear error
instead of silently dialling clearnet. Clearnet only if you type it — your ISP
sees Monero-node traffic; it is never a default.
The port is a convention, not a constant: restricted RPC on `18089` is common,
but you supply it.
wallet: in-process Cuprate chain daemon behind the cuprate-daemon feature Phase 1 of the Cuprate integration strategy: the chain daemon can run inside the OnionWire process instead of a spawned `monerod`. `monero-wallet-rpc` is unchanged — it still dials the unrestricted loopback RPC on 127.0.0.1:18081, which is the address `WalletChild::daemon_address` already returned — so no wallet-layer code moves. - Cargo.toml: `cuprated` (git, rev 4f8fcd1b) + `toml`, both optional, behind a `cuprate-daemon` feature that is OFF by default. Cuprate's own `arti` feature stays off: its arti-client 0.44 cannot unify with this crate's 0.46, and the in-process daemon is clearnet-only, so this keeps one Tor stack in the process. `Cargo.lock` gains the graph; no arti 0.44 appears in it. - src/cuprate.rs (new): `CuprateNode` builds the cuprated config as TOML (testnet, unrestricted RPC on loopback, restricted RPC disabled, inbound P2P off), launches it, and owns it. Dropping the value is the teardown; `shutdown()` is called before the drop so the services can drain. The type exists in every build: without the feature `launch` fails with the feature name instead of silently doing nothing, so the chain-source type, its stored record and the picker do not fork on a cargo feature. - src/wallet.rs: `ChainSource::InProcessCuprate { datadir }`. - src/wallet_child.rs: starts/holds/stops the node, serializes the choice as `kind = "cuprate"`, and adds `chain_datadir` so the storage gate covers both local sources. It takes the app's Tokio handle (`with_runtime`): the launch is async and `start()` runs on the TUI's blocking thread. - src/node.rs: `wallet_child_start(runtime)`, `default_in_process_chain_source`. - src/tui.rs: a fourth picker row, its testnet caveat, the chain block copy, and a stop of the app-owned children on the quit path so they are not orphaned. - tests/wallet.rs: a `cuprate-daemon`-gated end-to-end test that launches the node and drives get_info / get_height / get_block through the typed daemon client, including the above-the-tip 500 and the listener closing on drop. - docs/WALLET.md: the fourth chain source, the feature flag, the +5.6 MB stripped overhead, and the two limits (testnet only, no Tor in the chain path). Also repaired tests/tui_spec.rs, which the parent commit left un-compilable (the Phase 2a commit had dropped all but the new imports and four new tests, 1221 lines of body); it is restored from the pre-breakage version, with the Phase 2a imports and tests re-applied.
2026-09-17 13:17:32 -04:00
### The in-process chain daemon (`cuprate-daemon`)
Cuprate's chain daemon — P2P, consensus, RandomX — can run **inside the OnionWire
process** instead of as a spawned `monerod`. The wallet layer does not change:
`monero-wallet-rpc` is still a child, and it still dials the unrestricted loopback
RPC, `127.0.0.1:18081`, the same address a spawned `monerod` gets.
```
cargo build --release --features cuprate-daemon
```
- **Off by default.** `cuprated` is pre-1.0 and is not published to crates.io, so
it is a git dependency pinned to a revision. Without the feature the picker
still shows the row — the chain-source type and its stored record do not fork
on a cargo feature — but starting it fails with `this build has no in-process
chain daemon — rebuild with --features cuprate-daemon`.
- **+12.3 MB** on a stripped release binary, measured here: 26,942,168 bytes
without the feature and 39,193,032 with it (`cargo build --release` with and
without `--features cuprate-daemon`, then `strip` both). The +5.6 MB figure
that circulated with the spike was an estimate and understates it. It also
pulls a large build tree (RandomX, fjall, axum/hyper, rayon) — a cold build
compiles ~586 crates in release — so a build from cold is noticeably longer
than a plain TUI build.
- **Testnet only.** Cuprate is pre-production and its `monerod` RPC parity is
incomplete (`docs/cuprate-launch-spike.md` §Parity gaps). The config pins
`network = "Testnet"`; pointing a mainnet wallet at it is not something this
build claims to do. The picker row and the chain block both say so.
- **No Tor in the chain path.** Cuprate's own `arti` feature is *not* enabled:
its Tor stack is `arti-client` 0.44, which cannot unify with this crate's 0.46,
and running two Tor stacks in one process is not a trade this app makes.
OnionWire's Arti is the only Tor here, and it serves the messenger. That means
the in-process daemon's P2P traffic is **clearnet**: your ISP can see that this
device talks to Monero testnet peers, exactly as a spawned `monerod` would.
- **Inbound connections are off** and the restricted RPC listener is disabled:
this is a wallet's daemon, not a public node, and the restricted server only
answers placeholder metrics (see below).
- **It is not a child process.** There is no pid to watch or signal: the node is
a value the app owns, and dropping it shuts the daemon down. `n` in the wallet
screen stops it with the wallet child, and it does not outlive the app.
- **The chain lives in `$ONIONWIRE_HOME/chain`** — the same per-identity
directory a spawned `monerod` would use, so the two local sources are
interchangeable on disk. Storage gate: the wallet screen reports free space
there either way.
wallet: typed chain-daemon client for the Cuprate parity gaps The chain probe was a hand-rolled brace-scanner in `src/node.rs`. Cuprate breaks three of its assumptions, all measured in Spike A (`docs/cuprate-launch-spike.md` §Parity gaps, evidence in that spike's `rpc-evidence/`): 1. **A height above the tip is a bare HTTP 500 with an empty body.** monerod answers a JSON-RPC error object instead (`TOO_BIG_HEIGHT`, code -2). The client now parses the HTTP status once, de-chunks `Transfer-Encoding: chunked` bodies (axum/hyper; the old brace-scan is not a parse once a blob spans more than one chunk), and maps both spellings of the height failure to one typed `WalletError::DaemonHeightOutOfRange`. `get_height` and `get_block` are height-addressed: their 5xx is the height error. `get_info` is not: its 5xx is `WalletError::DaemonHttpStatus`. 2. **`get_info` metrics are not measurements.** Cuprate reports zero peers while it downloads blocks, its restricted server answers a placeholder `database_size` (exactly 5 GiB) and an empty `version`, and `free_space` is `u64::MAX` on both servers. `DaemonInfo` carries height and target only, so there is no field for a placeholder to reach the UI. The wallet screen's sync line is now built from block-height movement between two probes: "connected to P2P" needs the height to have moved, "no new blocks" is what a stalled daemon gets, and Cuprate's at-rest `synchronized = true` with `target_height = 0` reads as unknown instead of `1160/0`. 3. **`get_height` is a URI endpoint**: `{"method":"get_height"}` over `/json_rpc` is rejected with 422, so the client uses `GET /get_height`, which both daemons answer. The wallet-child routing rule is pinned too: it dials the daemon's *unrestricted* listener (monerod's `--rpc-bind-port`, and whatever port an in-process Cuprate binds for `[rpc.unrestricted]`), never the restricted one — a restricted listener answers, so a mix-up shows up as a wrong number rather than as an error. Scope deviations, stated plainly: - the card names `src/wallet.rs` + the TUI bindings. The probe itself lived in `src/node.rs`; it now delegates (net -100 lines there), and the routing constant/test live in `src/wallet_child.rs`. Tests are in `tests/wallet.rs`, `tests/tui_spec.rs` and `src/wallet_child.rs`'s test module. - `daemon_get_block()` is **not called by anything yet**: it is the entry point the wallet's own block scan (Phase 2) needs, and the out-of-range answer it has to survive is item 1, so the mapping lives with the client. - the card's item 3 gives the unrestricted port as 18089 and the restricted one as 28089. In monerod's numbering 18089 *is* the restricted port; the app's local source already dials the unrestricted 18081. The rule is what is pinned, not those numbers. - `docs/cuprate-launch-spike.md` merged to `main` after this branch's base commit, so it is not in this tree and its Recommendation bullets are not updated here. - based on `feat/wallet-create-import` (the wallet line, unmerged): the daemon client has no home on `main`. Retarget to `main` when that line lands. Proof: `cargo test --locked` 306 passed / 0 failed, `cargo clippy --locked --all-targets -- -D warnings` clean, `rustfmt --edition 2024 --check` adds no hunk to any file (the inherited hunks in `src/node.rs`/`src/tui.rs`/ `tests/tui_spec.rs` are unchanged in count or region).
2026-09-17 00:24:09 -04:00
### The daemon you point at has to be its *unrestricted* RPC
Both the app-owned child and the chain probe behind the wallet screen dial the
daemon's unrestricted listener: `--rpc-bind-port` for the `monerod` this app
wallet: in-process Cuprate chain daemon behind the cuprate-daemon feature Phase 1 of the Cuprate integration strategy: the chain daemon can run inside the OnionWire process instead of a spawned `monerod`. `monero-wallet-rpc` is unchanged — it still dials the unrestricted loopback RPC on 127.0.0.1:18081, which is the address `WalletChild::daemon_address` already returned — so no wallet-layer code moves. - Cargo.toml: `cuprated` (git, rev 4f8fcd1b) + `toml`, both optional, behind a `cuprate-daemon` feature that is OFF by default. Cuprate's own `arti` feature stays off: its arti-client 0.44 cannot unify with this crate's 0.46, and the in-process daemon is clearnet-only, so this keeps one Tor stack in the process. `Cargo.lock` gains the graph; no arti 0.44 appears in it. - src/cuprate.rs (new): `CuprateNode` builds the cuprated config as TOML (testnet, unrestricted RPC on loopback, restricted RPC disabled, inbound P2P off), launches it, and owns it. Dropping the value is the teardown; `shutdown()` is called before the drop so the services can drain. The type exists in every build: without the feature `launch` fails with the feature name instead of silently doing nothing, so the chain-source type, its stored record and the picker do not fork on a cargo feature. - src/wallet.rs: `ChainSource::InProcessCuprate { datadir }`. - src/wallet_child.rs: starts/holds/stops the node, serializes the choice as `kind = "cuprate"`, and adds `chain_datadir` so the storage gate covers both local sources. It takes the app's Tokio handle (`with_runtime`): the launch is async and `start()` runs on the TUI's blocking thread. - src/node.rs: `wallet_child_start(runtime)`, `default_in_process_chain_source`. - src/tui.rs: a fourth picker row, its testnet caveat, the chain block copy, and a stop of the app-owned children on the quit path so they are not orphaned. - tests/wallet.rs: a `cuprate-daemon`-gated end-to-end test that launches the node and drives get_info / get_height / get_block through the typed daemon client, including the above-the-tip 500 and the listener closing on drop. - docs/WALLET.md: the fourth chain source, the feature flag, the +5.6 MB stripped overhead, and the two limits (testnet only, no Tor in the chain path). Also repaired tests/tui_spec.rs, which the parent commit left un-compilable (the Phase 2a commit had dropped all but the new imports and four new tests, 1221 lines of body); it is restored from the pre-breakage version, with the Phase 2a imports and tests re-applied.
2026-09-17 13:17:32 -04:00
spawns, and `[rpc.unrestricted]` for the in-process Cuprate — `127.0.0.1:18081`
either way, which is why the chain source does not change the wallet child's
argv. Never the restricted listener — it answers, so getting this wrong shows up
as a *wrong number* rather than as an error. On Cuprate its restricted server
reports a placeholder `database_size` (exactly 5 GiB), an empty `version`, and
`free_space = u64::MAX` on both servers; the in-process daemon's restricted
listener is disabled outright (`enable = false`).
wallet: typed chain-daemon client for the Cuprate parity gaps The chain probe was a hand-rolled brace-scanner in `src/node.rs`. Cuprate breaks three of its assumptions, all measured in Spike A (`docs/cuprate-launch-spike.md` §Parity gaps, evidence in that spike's `rpc-evidence/`): 1. **A height above the tip is a bare HTTP 500 with an empty body.** monerod answers a JSON-RPC error object instead (`TOO_BIG_HEIGHT`, code -2). The client now parses the HTTP status once, de-chunks `Transfer-Encoding: chunked` bodies (axum/hyper; the old brace-scan is not a parse once a blob spans more than one chunk), and maps both spellings of the height failure to one typed `WalletError::DaemonHeightOutOfRange`. `get_height` and `get_block` are height-addressed: their 5xx is the height error. `get_info` is not: its 5xx is `WalletError::DaemonHttpStatus`. 2. **`get_info` metrics are not measurements.** Cuprate reports zero peers while it downloads blocks, its restricted server answers a placeholder `database_size` (exactly 5 GiB) and an empty `version`, and `free_space` is `u64::MAX` on both servers. `DaemonInfo` carries height and target only, so there is no field for a placeholder to reach the UI. The wallet screen's sync line is now built from block-height movement between two probes: "connected to P2P" needs the height to have moved, "no new blocks" is what a stalled daemon gets, and Cuprate's at-rest `synchronized = true` with `target_height = 0` reads as unknown instead of `1160/0`. 3. **`get_height` is a URI endpoint**: `{"method":"get_height"}` over `/json_rpc` is rejected with 422, so the client uses `GET /get_height`, which both daemons answer. The wallet-child routing rule is pinned too: it dials the daemon's *unrestricted* listener (monerod's `--rpc-bind-port`, and whatever port an in-process Cuprate binds for `[rpc.unrestricted]`), never the restricted one — a restricted listener answers, so a mix-up shows up as a wrong number rather than as an error. Scope deviations, stated plainly: - the card names `src/wallet.rs` + the TUI bindings. The probe itself lived in `src/node.rs`; it now delegates (net -100 lines there), and the routing constant/test live in `src/wallet_child.rs`. Tests are in `tests/wallet.rs`, `tests/tui_spec.rs` and `src/wallet_child.rs`'s test module. - `daemon_get_block()` is **not called by anything yet**: it is the entry point the wallet's own block scan (Phase 2) needs, and the out-of-range answer it has to survive is item 1, so the mapping lives with the client. - the card's item 3 gives the unrestricted port as 18089 and the restricted one as 28089. In monerod's numbering 18089 *is* the restricted port; the app's local source already dials the unrestricted 18081. The rule is what is pinned, not those numbers. - `docs/cuprate-launch-spike.md` merged to `main` after this branch's base commit, so it is not in this tree and its Recommendation bullets are not updated here. - based on `feat/wallet-create-import` (the wallet line, unmerged): the daemon client has no home on `main`. Retarget to `main` when that line lands. Proof: `cargo test --locked` 306 passed / 0 failed, `cargo clippy --locked --all-targets -- -D warnings` clean, `rustfmt --edition 2024 --check` adds no hunk to any file (the inherited hunks in `src/node.rs`/`src/tui.rs`/ `tests/tui_spec.rs` are unchanged in count or region).
2026-09-17 00:24:09 -04:00
What the wallet client reads from the daemon is chain height, and nothing else:
`daemon_get_info` / `daemon_get_height` in `src/wallet.rs`. No peer count, no
database size, no free space, no version — Cuprate reports zero peers *while it
is downloading blocks*, and the other three are placeholders. Connectivity is
inferred from block-height movement between two probes, which is the only honest
signal on offer.
Two more Cuprate differences the client handles, both measured in
`docs/cuprate-launch-spike.md` §Parity gaps:
- **A height above the tip is a bare HTTP 500 with an empty body**, where
monerod answers a JSON-RPC error object (`code = -2`, `TOO_BIG_HEIGHT`). Both
become the same typed error, so a call that asks too high fails as a height
problem instead of as an undecodable response.
- **`get_height` is a URI endpoint.** `{"method":"get_height"}` over `/json_rpc`
is rejected with 422, so the client uses `GET /get_height`, which both daemons
answer.
`daemon_get_block()` is there for the wallet's own block scan (Phase 2) and is
**not wired into anything yet** — today the scanning is `monero-wallet-rpc`'s.
wallet: app-owned child lifecycle + user-chosen ChainSource The app now owns monero-wallet-rpc (and monerod when the chain source is local) instead of requiring the user to start them and export ONIONWIRE_WALLET_RPC. - ChainSource enum: None / Local { monerod_bin, datadir } / Remote { host, port }. No default remote node; Remote is only constructed from explicit user input. A .onion Remote is refused without a SOCKS proxy (separate card). - WalletChild in src/wallet_child.rs spawns monero-wallet-rpc with --rpc-bind-ip 127.0.0.1, a random free loopback port, generated --rpc-login, and --wallet-dir /wallet; monerod too for a local source. --trusted-daemon is never passed. - Generated RPC creds are sealed in the encrypted SQLCipher store (wallet_child table, AEAD on top of whole-db encryption), never a plaintext file. The Wallet client is built from the generated loopback URL, not from_env. - Readiness predicate: chain_ready() requires synchronized==true, height>0, height>=target_height; can_spend() and can_verify_receipts() gate on it. Unsynced -> receipts stay verified=0, spend refused with a clear message. - Backend-aware timeouts: local management calls keep 5s; chain-dependent calls (get_info, get_transfers, transfer) get 60s (CHAIN_RPC_TIMEOUT), because a first sync or a remote daemon outlasts 5s and a 5s cap there is what left receipts permanently unverified. - node.rs ingest_receipt gates on can_verify_receipts() instead of configured() alone. - docs/WALLET.md rewritten for the child lifecycle + chain source. Base: feat/wallet-create-import (PR #66). Do not rebase onto main. Co-Authored-By: Hermes Agent <agent@local>
2026-09-14 18:55:07 -04:00
### Readiness, and why it is not a guess
`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, never a silent pass. Until then:
- **receipt verification stays `verified=0`** (an unsynced wallet cannot see the
tx, so a `get_transfers` miss would be a lie), and
- **spend is refused** with `wallet is not synced — spend refused until the
daemon reaches the chain tip`.
`spend_ready()` is the stricter signal the spend UI reads: chain-ready *and*
holding an unlocked balance above zero.
That is the honest state, not a broken flow. Unsynced or unreachable → receipts
unverified and spend refused.
### Timeouts are the backend's, not a constant
Loopback management calls (`get_address`, `query_key`, create/import) get a 5s
budget — the child is on the same box. Calls that wait on the chain (`get_info`,
`get_transfers`, `transfer`) get 60s (`CHAIN_RPC_TIMEOUT`), because a first sync
or a remote daemon legitimately outlasts a loopback round trip; a 5s cap there is
what leaves receipts permanently unverified.
## Env vars
| Variable | Meaning |
|---|---|
wallet: app-owned child lifecycle + user-chosen ChainSource The app now owns monero-wallet-rpc (and monerod when the chain source is local) instead of requiring the user to start them and export ONIONWIRE_WALLET_RPC. - ChainSource enum: None / Local { monerod_bin, datadir } / Remote { host, port }. No default remote node; Remote is only constructed from explicit user input. A .onion Remote is refused without a SOCKS proxy (separate card). - WalletChild in src/wallet_child.rs spawns monero-wallet-rpc with --rpc-bind-ip 127.0.0.1, a random free loopback port, generated --rpc-login, and --wallet-dir /wallet; monerod too for a local source. --trusted-daemon is never passed. - Generated RPC creds are sealed in the encrypted SQLCipher store (wallet_child table, AEAD on top of whole-db encryption), never a plaintext file. The Wallet client is built from the generated loopback URL, not from_env. - Readiness predicate: chain_ready() requires synchronized==true, height>0, height>=target_height; can_spend() and can_verify_receipts() gate on it. Unsynced -> receipts stay verified=0, spend refused with a clear message. - Backend-aware timeouts: local management calls keep 5s; chain-dependent calls (get_info, get_transfers, transfer) get 60s (CHAIN_RPC_TIMEOUT), because a first sync or a remote daemon outlasts 5s and a 5s cap there is what left receipts permanently unverified. - node.rs ingest_receipt gates on can_verify_receipts() instead of configured() alone. - docs/WALLET.md rewritten for the child lifecycle + chain source. Base: feat/wallet-create-import (PR #66). Do not rebase onto main. Co-Authored-By: Hermes Agent <agent@local>
2026-09-14 18:55:07 -04:00
| `ONIONWIRE_WALLET_RPC` | `http://[user:pass@]host[:port][/path]` — for an **externally run** `monero-wallet-rpc`. Unset → no wallet; chat still works and `/pay` falls back to the profile `xmr_addr`. The app-owned wallet child does not use this variable. |
| `ONIONWIRE_WALLET_RPC_LOGIN` | `user:pass` when you do not want the password in the URL. Ignored if the URL carries userinfo. |
| `ONIONWIRE_WALLET_NO_SPEND` | `1` / `true` / `yes` / `on` → view-only deployment: `/tip` is refused locally, before any RPC dial. `/pay` and receipt verification keep working. |
wallet: stored config (F7), WalletStatus snapshot, pay/tip readiness guard The only input path for the wallet was env. Add the same three remote-mode fields as stored config so the F7 screen can set them and headless runs read one source of truth: - `wallet_config` table in the encrypted store (one row; the login is sealed with the store data key under `onionwire/wallet-config/v1`, on top of SQLCipher). Empty URL clears it. `Store::load_wallet_config` / `save_wallet_config`. - `WalletConfig { rpc_url, rpc_login: Zeroizing<String>, no_spend }` with a redacting `Debug`; `Wallet::from_config`, and `Wallet::for_boot` which prefers stored config, falls back to env, and refuses to dial a bad stored endpoint. Node::start* now reads the store before constructing the wallet. - `WalletStatus { configured, connected, last_error, balance_line, receive_address }`: `connected` only ever comes from a probe (`Wallet::status`, get_address + get_balance); config alone leaves it false. `Node::wallet_status` is the cheap draw-path read, `wallet_refresh` the probe that folds into it. - One-shot `Wallet::ping(rpc_url, rpc_login) -> PingResult { ok, status, error }` for the Test-connection button: same loopback/digest rules, errors redacted and capped. - `readiness(configured, connected, no_spend, is_tip) -> Readiness` plus `Node::wallet_readiness` (async, block_on-friendly): not configured → NOT_CONFIGURED_MSG; /tip on a no-spend wallet → VIEW_ONLY_MSG before any dial; configured but not connected → NOT_CONNECTED_MSG; else ready. - `Node::wallet_save_config` persists, validates first, then re-reads so the live wallet and snapshot follow a Save without a restart. - `Node::wallet` is now a Mutex<Wallet> (cloned out before each await) so the wallet can be re-pointed mid-session. Local-mode fields stay reserved: the child lifecycle is t_69ce8e46 and is not wired here. docs/WALLET.md documents the stored config, boot precedence and the exact guard copy. Tests: 38 in tests/wallet.rs including exact-refusal-copy, boot precedence, sealed-on-disk login, ping sanitization and connected-only-after-probe.
2026-09-14 23:39:57 -04:00
As of v0.2.2 these three are the **migration path**, not the only path: the
stored config set in **F7** wins at boot. See *Stored wallet config* below.
`README.md` carries the operator summary; this file is the long form.
wallet: stored config (F7), WalletStatus snapshot, pay/tip readiness guard The only input path for the wallet was env. Add the same three remote-mode fields as stored config so the F7 screen can set them and headless runs read one source of truth: - `wallet_config` table in the encrypted store (one row; the login is sealed with the store data key under `onionwire/wallet-config/v1`, on top of SQLCipher). Empty URL clears it. `Store::load_wallet_config` / `save_wallet_config`. - `WalletConfig { rpc_url, rpc_login: Zeroizing<String>, no_spend }` with a redacting `Debug`; `Wallet::from_config`, and `Wallet::for_boot` which prefers stored config, falls back to env, and refuses to dial a bad stored endpoint. Node::start* now reads the store before constructing the wallet. - `WalletStatus { configured, connected, last_error, balance_line, receive_address }`: `connected` only ever comes from a probe (`Wallet::status`, get_address + get_balance); config alone leaves it false. `Node::wallet_status` is the cheap draw-path read, `wallet_refresh` the probe that folds into it. - One-shot `Wallet::ping(rpc_url, rpc_login) -> PingResult { ok, status, error }` for the Test-connection button: same loopback/digest rules, errors redacted and capped. - `readiness(configured, connected, no_spend, is_tip) -> Readiness` plus `Node::wallet_readiness` (async, block_on-friendly): not configured → NOT_CONFIGURED_MSG; /tip on a no-spend wallet → VIEW_ONLY_MSG before any dial; configured but not connected → NOT_CONNECTED_MSG; else ready. - `Node::wallet_save_config` persists, validates first, then re-reads so the live wallet and snapshot follow a Save without a restart. - `Node::wallet` is now a Mutex<Wallet> (cloned out before each await) so the wallet can be re-pointed mid-session. Local-mode fields stay reserved: the child lifecycle is t_69ce8e46 and is not wired here. docs/WALLET.md documents the stored config, boot precedence and the exact guard copy. Tests: 38 in tests/wallet.rs including exact-refusal-copy, boot precedence, sealed-on-disk login, ping sanitization and connected-only-after-probe.
2026-09-14 23:39:57 -04:00
## Stored wallet config (no env required)
Editing env vars is a deployment step, not a UI step. The TUI's **F7** screen
(`draw_wallet_config`) sets the same three fields and stores them, so a desktop install never needs env
wallet: stored config (F7), WalletStatus snapshot, pay/tip readiness guard The only input path for the wallet was env. Add the same three remote-mode fields as stored config so the F7 screen can set them and headless runs read one source of truth: - `wallet_config` table in the encrypted store (one row; the login is sealed with the store data key under `onionwire/wallet-config/v1`, on top of SQLCipher). Empty URL clears it. `Store::load_wallet_config` / `save_wallet_config`. - `WalletConfig { rpc_url, rpc_login: Zeroizing<String>, no_spend }` with a redacting `Debug`; `Wallet::from_config`, and `Wallet::for_boot` which prefers stored config, falls back to env, and refuses to dial a bad stored endpoint. Node::start* now reads the store before constructing the wallet. - `WalletStatus { configured, connected, last_error, balance_line, receive_address }`: `connected` only ever comes from a probe (`Wallet::status`, get_address + get_balance); config alone leaves it false. `Node::wallet_status` is the cheap draw-path read, `wallet_refresh` the probe that folds into it. - One-shot `Wallet::ping(rpc_url, rpc_login) -> PingResult { ok, status, error }` for the Test-connection button: same loopback/digest rules, errors redacted and capped. - `readiness(configured, connected, no_spend, is_tip) -> Readiness` plus `Node::wallet_readiness` (async, block_on-friendly): not configured → NOT_CONFIGURED_MSG; /tip on a no-spend wallet → VIEW_ONLY_MSG before any dial; configured but not connected → NOT_CONNECTED_MSG; else ready. - `Node::wallet_save_config` persists, validates first, then re-reads so the live wallet and snapshot follow a Save without a restart. - `Node::wallet` is now a Mutex<Wallet> (cloned out before each await) so the wallet can be re-pointed mid-session. Local-mode fields stay reserved: the child lifecycle is t_69ce8e46 and is not wired here. docs/WALLET.md documents the stored config, boot precedence and the exact guard copy. Tests: 38 in tests/wallet.rs including exact-refusal-copy, boot precedence, sealed-on-disk login, ping sanitization and connected-only-after-probe.
2026-09-14 23:39:57 -04:00
at all:
| Field | Meaning |
|---|---|
| `rpc_url` | `http://host:port[/path]` for an **externally run** `monero-wallet-rpc`. **No** `user:pass` in the URL. Loopback only, same rule as env. |
| `rpc_login` | `user:pass`. Masked in the UI. Never logged, never in a status line, never on disk in the clear. |
| `no_spend` | View-only deployment. Same semantics as `ONIONWIRE_WALLET_NO_SPEND`. |
They live in the **encrypted SQLCipher store** (`wallet_config` table, one row:
the URL and the flag in the clear inside the encrypted db, the login sealed with
the store data key and a `onionwire/wallet-config/v1` AAD on top of whole-db
encryption — the same discipline as the wallet-child creds). Save replaces the
row; clearing the URL deletes it, which is how you turn the stored wallet off
again.
**Boot precedence is stored → env → disabled.** Stored config wins; the env vars
in the table above remain the pre-F7 migration path (and the only path for
headless / non-TUI runs). A stored config that cannot be used — non-loopback
host, `.onion`, missing login — is reported and then **falls back to env**
rather than dialling the bad endpoint. To override a stored config with env,
clear the stored one (F7, empty endpoint) first.
### Wallet status, and how fresh `connected` is
The app keeps one `WalletStatus` snapshot for the draw path —
`configured`, `connected`, `last_error`, `balance_line`, `receive_address` —
and the TUI only ever reads it; it never dials the wallet from the render path.
- `configured` is true when a stored **or** env config resolved to a usable
wallet. Config is not reachability: a freshly booted or freshly saved wallet
is `configured = true`, `connected = false`, with `—` readouts.
- `connected` only ever comes from a probe. One probe is `get_address` (cheap,
loopback, and the same call `/pay` invoices need) followed by `get_balance`
for the readout. A success clears `last_error`; a failure sets
`connected = false` and keeps `configured = true`. There is no background
refresh: `connected` is whatever the **last** probe said.
- `last_error` is display copy, not a log line: trimmed, capped at 120 chars,
and with the RPC password redacted (`<redacted>`) if a lower layer ever put it
in a message.
Two probes exist:
- `wallet_refresh` / the readiness guard probe the **configured** endpoint and
update the snapshot;
- **Test connection** on the F7 screen probes the endpoint you are *currently
typing* (`Wallet::ping`) and returns `{ok, status, error}` without touching
the live wallet or the snapshot — testing an untyped endpoint is not the
wallet the app is running.
### The pay/tip readiness guard
`/tip` and `/pay` run a pre-check before the send. It never dials Tor (wallet
RPC is loopback-only), and it never dials the wallet at all when the answer is
already known locally. The order is fixed and the copy is part of the contract:
1. **not configured** → `wallet not configured — open F7 to set it up, or set ONIONWIRE_WALLET_RPC`
2. **`/tip` on a no-spend / view-only wallet** → the existing view-only message
(`wallet is in view-only/no-spend mode — /tip is disabled; /pay and receipt
verification still work`), refused **before any dial** — this is the same rule
`transfer` applies, and it is the honest answer whether or not the wallet is
reachable.
3. **configured but not connected** → `wallet not connected — check endpoint, login, daemon`
4. otherwise ready. `/pay` is fine on a view-only wallet.
The check is cheap enough to run on Enter: steps 1 and 2 are local, and step 3
is one bounded probe (5s local budget). `wallet_readiness(is_tip)` is `async`
and the TUI calls it with `rt.block_on` from the key handler, the same pattern
`send_pay` / `send_tip` already use.
**Local mode is not wired yet.** Wallet-child fields (binary paths, wallet dir,
daemon address, chain backend, daemon sync state) are not part of this stored
config; the app-owned child keeps its own record (see *Where the RPC credentials
live* above). Until a screen sets them from the store, treat local mode as
not-yet-available rather than pretending a child is running.
## Create vs import
Create does **not** take a private key. `/wallet create` (TUI: F6 then `c`) asks
the RPC to generate a new spend-capable wallet (`create_wallet`), then shows the
seed **once** for backup (`query_key mnemonic`). Type `SPEND` to accept the
spend-authority warning, set a passphrase, write the seed down, type `SEEN`.
Import is the only path that takes an existing secret: `/wallet import` (F6 then
`i`) pastes the 25-word seed into `restore_deterministic_wallet`. Do not put the
seed on the composer line — it would sit in chat history.
The RPC must be started with `--wallet-dir` (not only `--wallet-file`) or create
and import fail. The in-app filename is `onionwire`.
## Recommended topology
```
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**. `.onion`
wallet-RPC URLs are rejected: there is no Arti dial for the wallet process, and
a remote wallet RPC would move spend authority off the box.
## Create a view-only wallet
Either path produces a wallet file with the view key only. Keep the seed /
spend key on a machine that is **not** running OnionWire.
With `monero-wallet-cli` (`--generate-from-view-key` prompts for the *standard*
address the view key belongs to, then the secret view key):
```bash
monero-wallet-cli --generate-from-view-key "$HOME/.onionwire-viewonly" \
--daemon-address "$YOUR_MONEROD:18089" --restore-height "$BIRTH_HEIGHT"
# Standard address: 4...
# Secret view key: <hex>
```
Or through a running RPC that was started with `--wallet-dir` (`generate_from_keys`
without `spendkey` writes a watch-only wallet):
```bash
curl -u onionwire:secret http://127.0.0.1:18083/json_rpc \
-H 'Content-Type: application/json' \
-d '{"jsonrpc":"2.0","id":"0","method":"generate_from_keys","params":{
"filename":"viewonly","password":"walletpass",
"address":"4...","viewkey":"<hex>","restore_height":<height>}}'
# → "Watch-only wallet has been generated successfully."
```
Then serve it:
```bash
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 the wallet from a height *at or before* its first incoming transaction
— a view-only wallet cannot rescan cheaply from height 0.
## What works, what does not
| Feature | View-only | Spend-capable |
|---|---|---|
| `/pay <xmr>` invoice subaddress (`create_address`) | works | works |
| Receipt verification (`get_transfers`) | works | works |
| Profile `xmr_addr` fallback when RPC is down | works | works |
| `/tip <xmr>` (`transfer`) | **cannot work** | works |
| OnionWire copies your spend key into its own process | never | never (it stays in the wallet file / RPC) |
With `ONIONWIRE_WALLET_NO_SPEND=1` a `/tip` is refused before the RPC is
contacted, with:
```
wallet is in view-only/no-spend mode — /tip is disabled; /pay and receipt verification still work
```
Without the flag, `/tip` against a view-only wallet fails at the wallet and
OnionWire then asks the wallet directly whether it can spend (see below), so you
get the same sentence instead of a raw RPC error.
## How OnionWire detects view-only over RPC
The signal people usually reach for is `query_key` with `key_type=mnemonic`. It
works, but it is the wrong key to ask for: on a spend-capable wallet it hands
over the whole seed (full spend ability) over loopback HTTP, and it answers
`-43` for wallets that have no mnemonic at all. The spend key is narrower and
just as unambiguous:
```
query_key {"key_type":"spend_key"}
spend-capable → result.key = <hex secret spend key>
view-only → error code -29, "The wallet is watch-only. Cannot retrieve spend key."
```
(`query_key key_type=mnemonic` returns `-29` for a view-only wallet too, so the
two agree — OnionWire asks for the spend key because it is the smaller secret.)
- Method: [`query_key`](https://www.getmonero.org/resources/developer-guides/wallet-rpc.html#query_key)
- `-29` is `WALLET_RPC_ERROR_CODE_WATCH_ONLY` in
[`wallet_rpc_server_error_codes.h`](https://github.com/monero-project/monero/blob/master/src/wallet/wallet_rpc_server_error_codes.h)
- The view-only branch is `on_query_key` in
[`wallet_rpc_server.cpp`](https://github.com/monero-project/monero/blob/master/src/wallet/wallet_rpc_server.cpp)
OnionWire only calls this **after** a `transfer` has already failed — it never
probes a healthy wallet — and it discards `result.key` immediately. There is no
RPC method that reports "view-only" as a plain field; `query_key` is the
documented signal and this is its only cost: a spend-capable wallet answers with
its spend key over loopback HTTP, which is one more reason to run view-only.
Fail-closed details: if the probe cannot answer (wallet down, `--restricted-rpc`
answers `-7 DENIED` instead), OnionWire surfaces the wallet's own error
unchanged. It never guesses "view-only" from an unrelated failure.
## 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 users or processes on the same machine. Any local process can
`connect(127.0.0.1:18083)`.
- OnionWire refuses an RPC that answers HTTP 200 without a Digest challenge, and
refuses URLs without credentials. Unset the credentials and the wallet is open
to every local process — with a spend-capable wallet file, that is a
one-curl drain of your balance.
- `--rpc-login` is HTTP Digest (MD5), so the password is not sent in cleartext,
but Digest gives no confidentiality: a local attacker who can sniff loopback
can replay it. Treat loopback as trusted-ish, not safe.
- Do not log the password, and do not put it in a shell history you share.
Prefer `ONIONWIRE_WALLET_RPC_LOGIN` over userinfo in the URL.
## 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:
- the wallet file holds no spend key, so a stolen wallet file cannot be used to
move funds;
- the RPC credentials grant only receive-address and history reads;
- `/tip` fails locally with a plain message, so nothing in the UI pretends the
spend path exists.
If you want tips to work, understand that you are deliberately making the
OnionWire process able to spend. Give it a **separate hot wallet with a small
balance**, not your savings wallet.
## References
- Monero Wallet RPC reference:
<https://www.getmonero.org/resources/developer-guides/wallet-rpc.html>
- `on_query_key` (view-only → `-29`):
<https://github.com/monero-project/monero/blob/master/src/wallet/wallet_rpc_server.cpp>
- `WALLET_RPC_ERROR_CODE_WATCH_ONLY = -29`:
<https://github.com/monero-project/monero/blob/master/src/wallet/wallet_rpc_server_error_codes.h>
- `--generate-from-view-key` (incoming-only wallet):
<https://github.com/monero-project/monero/blob/master/src/simplewallet/simplewallet.cpp>
- `generate_from_keys` (watch-only when `spendkey` is omitted):
<https://www.getmonero.org/resources/developer-guides/wallet-rpc.html#generate_from_keys>