wallet: no-spend (view-only) mode + RPC view-only detection + docs/WALLET.md #41

Merged
sirius merged 1 commit from feat/wallet-no-spend-view-only into main 2026-09-12 20:08:09 +00:00
Owner

What

/tip needs monero-wallet-rpc method transfer, which a view-only wallet cannot serve. This PR makes that explicit instead of leaving the user with a raw wallet error:

  1. ONIONWIRE_WALLET_NO_SPEND=1 (1/true/yes/on) — /tip returns
    wallet is in view-only/no-spend mode — /tip is disabled; /pay and receipt verification still work
    and no socket is ever opened (the guard is the first statement in Wallet::transfer, before the endpoint lookup). /pay (subaddress), receipt verification (get_transfers) and the profile fallback are untouched.
  2. View-only detection over RPC — see the method section below.
  3. docs/WALLET.md (new): view-only setup, --rpc-login/Digest, what breaks, why loopback still needs auth, and the spend-authority warning. Linked from docs/THREAT_MODEL.md.

Refused before dialing (flag), or mapped to the same sentence after a failed transfer (RPC signal). Fail closed: if the probe cannot answer, the wallet's own error is surfaced unchanged — no fabricated detection.

Which RPC method reveals view-only (acceptance criterion)

query_key with key_type=spend_key is the documented signal:

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

Source of truth (read, not guessed):

query_key key_type=mnemonic also answers -29 for a view-only wallet, but on a spend-capable wallet it hands over the whole seed and it answers -43 for non-deterministic wallets, so OnionWire asks for the single spend key instead.

Trade-off, stated honestly: query_key is a key-export method. On a spend-capable wallet it returns the spend key over loopback HTTP, which OnionWire immediately discards; that is exactly why the probe only runs after a transfer has already failed (never on a healthy tip), and why view-only + ONIONWIRE_WALLET_NO_SPEND=1 is the recommended default. --restricted-rpc answers -7 DENIED to both methods; that is surfaced as the wallet's own error, not as "view-only".

Tests (all new in tests/wallet.rs, TDD — each failed first)

Test Proves
no_spend_mode_refuses_transfer_with_no_rpc_request flag → clear error, and the recorded request log is empty (asserted on the log, plus a positive control that the recorder works)
no_spend_mode_keeps_invoice_and_receipt_paths_working create_address + get_transfers + transfers_match still work with the flag on; no transfer request recorded
view_only_wallet_maps_transfer_failure_to_clear_message transfer → -18, probe query_key → -29 ⇒ the same clear sentence; log shows both methods
spend_capable_wallet_keeps_the_original_transfer_error probe answers with a key ⇒ the wallet's real error survives (no fabricated detection)
open_rpc_without_digest_challenge_is_still_refused F5 no-regression: HTTP 200 with no Digest challenge is still refused
from_env_reads_no_spend_flag ONIONWIRE_WALLET_NO_SPEND plumbing (1/true/0/no/off/unset)

Mutation check on the headline assertion: with the if self.no_spend guard neutralised, no_spend_mode_refuses_transfer_with_no_rpc_request fails (called Result::unwrap_err() on an Ok value: "abc123" — i.e. it really did reach the mock wallet); the guard restored, it passes.

Evidence (commands actually run, real output)

$ cargo test
test result: ok. 186 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out   # 25 suites
EXIT=0

$ cargo test --test wallet
test result: ok. 21 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.42s

$ cargo clippy --all-targets -- -D warnings
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.43s

(3 ignored = the Arti/onion-service tests that need a live Tor network.)

Scope notes

  • src/node.rs is untouched. tip() reaches the RPC only through Wallet::transfer, so the guard and the mapping live at the single choke point (testable with the existing mock TCP doubles; a Node needs Arti bootstrap). The Node surface and its error plumbing are unchanged.
  • Docs env-var table: docs/ had no env-var table (only prose in docs/THREAT_MODEL.md); docs/WALLET.md now carries one for ONIONWIRE_WALLET_RPC, ONIONWIRE_WALLET_RPC_LOGIN and ONIONWIRE_WALLET_NO_SPEND.
  • docs/README.md (docs index) was not touched — it is outside this card's allowed list. Optional one-line addition for you to apply if you want it: under item 2, Wallet sidecar: [WALLET.md](WALLET.md).

README (deferred)

README.md is owned by open PR #38 — not touched. Exact proposed wording, to apply inside ## Monero sidecar (after the existing export block and the "Loopback only, HTTP Digest…" paragraph):

**Run it view-only.** A `monero-wallet-rpc` opened on a view-only wallet (no
spend key) serves `/pay` and receipt verification; `/tip` is refused locally,
before any RPC call:

export ONIONWIRE_WALLET_NO_SPEND=1

`/tip` then says `wallet is in view-only/no-spend mode — /tip is disabled; /pay and receipt verification still work`. Without the flag, a view-only wallet is detected over RPC (`query_key` `key_type=spend_key`) and gets the same message. `/tip` needs a **spend-capable** wallet, which makes OnionWire a local spend authority: any process that can read the RPC credentials can move the balance. Setup, view-only wallet creation and the full trade-off: [docs/WALLET.md](docs/WALLET.md).

And the flag list line, if you keep the /pay /tip bullets: - ONIONWIRE_WALLET_NO_SPEND=1— view-only:/tiprefuses locally;/pay and receipts keep working. Recommended.

## What `/tip` needs `monero-wallet-rpc` method `transfer`, which a view-only wallet cannot serve. This PR makes that explicit instead of leaving the user with a raw wallet error: 1. **`ONIONWIRE_WALLET_NO_SPEND=1`** (`1`/`true`/`yes`/`on`) — `/tip` returns `wallet is in view-only/no-spend mode — /tip is disabled; /pay and receipt verification still work` and **no socket is ever opened** (the guard is the first statement in `Wallet::transfer`, before the endpoint lookup). `/pay` (subaddress), receipt verification (`get_transfers`) and the profile fallback are untouched. 2. **View-only detection over RPC** — see the method section below. 3. **`docs/WALLET.md`** (new): view-only setup, `--rpc-login`/Digest, what breaks, why loopback still needs auth, and the spend-authority warning. Linked from `docs/THREAT_MODEL.md`. Refused before dialing (flag), or mapped to the same sentence after a failed `transfer` (RPC signal). Fail closed: if the probe cannot answer, the wallet's own error is surfaced unchanged — no fabricated detection. ## Which RPC method reveals view-only (acceptance criterion) **`query_key` with `key_type=spend_key`** is the documented signal: ``` 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." ``` Source of truth (read, not guessed): - `on_query_key`, view-only branch: <https://github.com/monero-project/monero/blob/master/src/wallet/wallet_rpc_server.cpp> (lines 2364-2375) - `#define WALLET_RPC_ERROR_CODE_WATCH_ONLY -29`: <https://github.com/monero-project/monero/blob/master/src/wallet/wallet_rpc_server_error_codes.h> - docs: <https://www.getmonero.org/resources/developer-guides/wallet-rpc.html#query_key> `query_key key_type=mnemonic` also answers `-29` for a view-only wallet, but on a spend-capable wallet it hands over the whole seed and it answers `-43` for non-deterministic wallets, so OnionWire asks for the single spend key instead. **Trade-off, stated honestly:** `query_key` is a *key-export* method. On a spend-capable wallet it returns the spend key over loopback HTTP, which OnionWire immediately discards; that is exactly why the probe only runs **after** a `transfer` has already failed (never on a healthy tip), and why view-only + `ONIONWIRE_WALLET_NO_SPEND=1` is the recommended default. `--restricted-rpc` answers `-7 DENIED` to both methods; that is surfaced as the wallet's own error, not as "view-only". ## Tests (all new in `tests/wallet.rs`, TDD — each failed first) | Test | Proves | |---|---| | `no_spend_mode_refuses_transfer_with_no_rpc_request` | flag → clear error, and the **recorded request log is empty** (asserted on the log, plus a positive control that the recorder works) | | `no_spend_mode_keeps_invoice_and_receipt_paths_working` | `create_address` + `get_transfers` + `transfers_match` still work with the flag on; no `transfer` request recorded | | `view_only_wallet_maps_transfer_failure_to_clear_message` | `transfer` → `-18`, probe `query_key` → `-29` ⇒ the same clear sentence; log shows both methods | | `spend_capable_wallet_keeps_the_original_transfer_error` | probe answers with a key ⇒ the wallet's real error survives (no fabricated detection) | | `open_rpc_without_digest_challenge_is_still_refused` | F5 no-regression: HTTP 200 with no Digest challenge is still refused | | `from_env_reads_no_spend_flag` | `ONIONWIRE_WALLET_NO_SPEND` plumbing (1/true/0/no/off/unset) | Mutation check on the headline assertion: with the `if self.no_spend` guard neutralised, `no_spend_mode_refuses_transfer_with_no_rpc_request` fails (`called Result::unwrap_err() on an Ok value: "abc123"` — i.e. it really did reach the mock wallet); the guard restored, it passes. ## Evidence (commands actually run, real output) ``` $ cargo test test result: ok. 186 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out # 25 suites EXIT=0 $ cargo test --test wallet test result: ok. 21 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.42s $ cargo clippy --all-targets -- -D warnings Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.43s ``` (3 ignored = the Arti/onion-service tests that need a live Tor network.) ## Scope notes - **`src/node.rs` is untouched.** `tip()` reaches the RPC only through `Wallet::transfer`, so the guard and the mapping live at the single choke point (testable with the existing mock TCP doubles; a `Node` needs Arti bootstrap). The `Node` surface and its error plumbing are unchanged. - **Docs env-var table:** `docs/` had no env-var table (only prose in `docs/THREAT_MODEL.md`); `docs/WALLET.md` now carries one for `ONIONWIRE_WALLET_RPC`, `ONIONWIRE_WALLET_RPC_LOGIN` and `ONIONWIRE_WALLET_NO_SPEND`. - `docs/README.md` (docs index) was **not** touched — it is outside this card's allowed list. Optional one-line addition for you to apply if you want it: under item 2, ` Wallet sidecar: [WALLET.md](WALLET.md).` ## README (deferred) `README.md` is owned by open PR #38 — not touched. Exact proposed wording, to apply inside `## Monero sidecar` (after the existing `export` block and the "Loopback only, HTTP Digest…" paragraph): ```markdown **Run it view-only.** A `monero-wallet-rpc` opened on a view-only wallet (no spend key) serves `/pay` and receipt verification; `/tip` is refused locally, before any RPC call: export ONIONWIRE_WALLET_NO_SPEND=1 `/tip` then says `wallet is in view-only/no-spend mode — /tip is disabled; /pay and receipt verification still work`. Without the flag, a view-only wallet is detected over RPC (`query_key` `key_type=spend_key`) and gets the same message. `/tip` needs a **spend-capable** wallet, which makes OnionWire a local spend authority: any process that can read the RPC credentials can move the balance. Setup, view-only wallet creation and the full trade-off: [docs/WALLET.md](docs/WALLET.md). ``` And the flag list line, if you keep the `/pay` `/tip` bullets: `- `ONIONWIRE_WALLET_NO_SPEND=1` — view-only: `/tip` refuses locally; `/pay` and receipts keep working. Recommended.`
wallet: no-spend mode + view-only detection over RPC
All checks were successful
ci / test (pull_request) Successful in 3m1s
a28a3ceb75
/tip needs monero-wallet-rpc `transfer`, which a view-only wallet cannot do.
With ONIONWIRE_WALLET_NO_SPEND=1 (`1`/`true`/`yes`/`on`) `Wallet::transfer`
refuses locally, before any RPC dial, and /pay + receipt verification are
unchanged.

When a transfer does fail, ask the documented signal before surfacing the raw
wallet error: `query_key` key_type=spend_key answers
WALLET_RPC_ERROR_CODE_WATCH_ONLY (-29) on a view-only wallet
(wallet_rpc_server.cpp on_query_key). Both paths return one sentence —
"wallet is in view-only/no-spend mode — /tip is disabled; /pay and receipt
verification still work". Fail closed: if the probe cannot answer, the wallet's
own error stands; no fabricated detection.

New docs/WALLET.md: --generate-from-view-key / generate_from_keys watch-only
setup, --rpc-login Digest, why loopback still needs auth, the local
spend-authority warning, and the detection trade-off (a spend-capable wallet
answers the probe with its spend key, which is discarded). Linked from
docs/THREAT_MODEL.md.
sirius force-pushed feat/wallet-no-spend-view-only from a28a3ceb75
All checks were successful
ci / test (pull_request) Successful in 3m1s
to 01b63c4968
All checks were successful
ci / test (pull_request) Successful in 3m10s
2026-09-12 17:53:36 +00:00
Compare
sirius left a comment

Merge order 3 of 7: #38 -> #42 -> #41 -> #44 -> #43 -> #45 -> #46

Goes before #46, which also rewrites src/wallet.rs — that is the only overlap. Rebase-clean.

Note: Forgejo refuses a formal approval from this token ("approve your own pull is not allowed" — the PRs were pushed by account sirius, which is also the token's user). This review records the sign-off and the merge position; a human approval click is still needed. Rebased onto current main before this review, diff verified byte-identical.

**Merge order 3 of 7:** #38 -> #42 -> #41 -> #44 -> #43 -> #45 -> #46 Goes before #46, which also rewrites `src/wallet.rs` — that is the only overlap. Rebase-clean. Note: Forgejo refuses a formal approval from this token ("approve your own pull is not allowed" — the PRs were pushed by account `sirius`, which is also the token's user). This review records the sign-off and the merge position; a human approval click is still needed. Rebased onto current `main` before this review, diff verified byte-identical.
sirius force-pushed feat/wallet-no-spend-view-only from 01b63c4968
All checks were successful
ci / test (pull_request) Successful in 3m10s
to 323100b162
All checks were successful
ci / test (pull_request) Successful in 4m11s
2026-09-12 19:39:53 +00:00
Compare
sirius merged commit beb523bdde into main 2026-09-12 20:08:09 +00:00
sirius deleted branch feat/wallet-no-spend-view-only 2026-09-12 20:14:59 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
sirius/onionwire!41
No description provided.