onionwire/docs/WALLET.md
agent c45b008e97
All checks were successful
ci / test (pull_request) Successful in 5m6s
ci / sdk (pull_request) Successful in 1m18s
android-ci / android (pull_request) Successful in 8m32s
monerod: spawn a pruned local monerod as the chain source
docs/WALLET.md §Chain source offered "spawn a local monerod (pruned
on-device)" but nothing implemented it. Add src/monerod.rs: find monerod
on PATH, mkdir $ONIONWIRE_HOME/monero at 0700, spawn it with
--prune-blockchain --non-interactive and its RPC bound to 127.0.0.1:18089,
poll the port for readiness, and stop it with SIGTERM (SIGKILL after 10s).

Locks held: loopback-only RPC, no --trusted-daemon, no SOCKS, no C-tor,
no clearnet default, no UDP, no new dependency (std only — SIGTERM goes
through kill(1) because the crate takes no libc). A missing binary or a
port that never answers is an Err the node logs and shrugs off: no local
chain is the honest state, not a crash.

Node wires it opt-in via ONIONWIRE_MONEROD=1: start_monerod spawns on a
blocking task during start_with_passphrase, shutdown() takes the daemon
and stops it off the reactor, and monerod_rpc_addr() reports where the
wallet child should point --daemon-address.

Tests (7, in-module): argv is pruned/loopback and carries no forbidden
flag; PATH lookup needs an executable; empty PATH and a missing binary
both Err with a clear message (and the data dir is 0700); default addr is
127.0.0.1:18089; wait_for_ready times out against a dead port; a fake
daemon spawns, reports its addr, and stops via SIGTERM (its pid is gone).
2026-09-16 21:00:28 -04:00

12 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. The threat-model write-up is THREAT_MODEL.md.

The app talks to monero-wallet-rpc over loopback HTTP Digest only, whether that process is one you already run or one the app spawns:

  • 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.

Env vars

Variable Meaning
ONIONWIRE_WALLET_RPC http://[user:pass@]host[:port][/path]. Unset → no wallet; chat still works and /pay falls back to the profile xmr_addr.
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.
ONIONWIRE_MONEROD 1 / true / yes / on → OnionWire spawns a pruned local monerod as the chain source (option 1 below). Unset → no local chain; the wallet child uses whatever daemon you gave it.

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.

 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.

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.

  1. Spawn a local monerod (pruned on-device). 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 — --daemon-address on the wallet child. Loopback if you already run monerod. .onion if you want chain traffic over Tor (wallet child --proxy to a localhost SOCKS listener; the daemon operator still sees addresses). Clearnet only if you type it — ISP sees Monero-node traffic; not a default.

Remote daemons are untrusted (--trusted-daemon off). Unsynced or unreachable → receipts stay unverified and spend is refused. That is the honest state.

Option 1 in practice: the in-app spawn

Set ONIONWIRE_MONEROD=1 and the app starts the daemon itself — you do not run monerod by hand. It looks for monerod on PATH, keeps its chain data in $ONIONWIRE_HOME/monero/ (mode 0700, never /tmp and never a shared location), and starts it with --prune-blockchain --non-interactive, its RPC bound to loopback only (--rpc-bind-ip 127.0.0.1 --rpc-bind-port 18089), logging to $ONIONWIRE_HOME/monero/monerod.log. The wallet child is pointed at that RPC with --daemon-address 127.0.0.1:18089; which process runs the wallet RPC (and how it is started) is separate from this and unchanged.

Zero trust is not optional here either: the spawn never passes --trusted-daemon, and the daemon's RPC is loopback so only this machine can talk to it. p2p is untouched (monerod's own defaults, port 18081): a pruned node still dials peers on the Monero network to sync, so "local daemon" means you are not handing your addresses to someone else's node — it does not mean the sync is offline.

On start the app waits up to 5s for the RPC port to answer. A missing binary or a port that never comes up is not fatal: it is logged, no local chain is assumed, and the wallet reports the unsynced state above. On shutdown the daemon is SIGTERMed (SIGKILL after 10s). If you stop the app with SIGKILL, monerod keeps running and keeps syncing; kill it yourself or leave it — the next start reuses the same data dir.

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):

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):

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:

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.)

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