# 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). 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. ## 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 --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 does not pick a public remote node for you. The three shapes are: ``` ChainSource::None receive-only; no child, no daemon ChainSource::Local { monerod_bin, datadir } the app spawns monerod on this box 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. 2. **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 — 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. ### 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 | |---|---| | `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. | `README.md` carries the operator summary; this file is the long form. ## 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: ``` 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":"","restore_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 ` invoice subaddress (`create_address`) | works | works | | Receipt verification (`get_transfers`) | works | works | | Profile `xmr_addr` fallback when RPC is down | works | works | | `/tip ` (`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 = 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//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: - `on_query_key` (view-only → `-29`): - `WALLET_RPC_ERROR_CODE_WATCH_ONLY = -29`: - `--generate-from-view-key` (incoming-only wallet): - `generate_from_keys` (watch-only when `spendkey` is omitted):