wallet: unlocked balance, restore height, outgoing rows, send, view-only import
All checks were successful
ci / test (pull_request) Successful in 6m39s
ci / sdk (pull_request) Successful in 1m31s
android-ci / android (pull_request) Successful in 12m57s
ci / fuzz (pull_request) Successful in 5m3s

`get_balance` carries two numbers and the wallet screen only showed one:
`Node::wallet_balance_line` now reads both out of a single answer
(`balance {total} XMR · unlocked {unlocked} XMR`, the `balance 0 XMR` prefix
kept, total-only when the RPC reports no unlocked half), and
`Node::wallet_unlocked_balance` reports the unlocked half on its own with
`wallet_balance`'s `off` / `err` sentinels. `wallet_balance` keeps its shape.

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

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

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

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

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

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

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

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

No new crate, no Cargo change, no android/ change.
This commit is contained in:
agent 2026-09-25 02:23:09 -04:00
commit 93deaa5309
No known key found for this signature in database
9 changed files with 1891 additions and 58 deletions

View file

@ -299,6 +299,30 @@ now one of the places a spending secret can be read from.
Treat any screen that shows a seed or a private key the way you treat the
wallet file itself.
## A view key entered at import is a secret, and a view-only file cannot spend
Importing an address to watch means typing that address's **private view key**
into OnionWire. It is a secret of a different kind from a seed: it cannot spend,
but anyone holding it *and* the address sees every incoming transfer — amounts,
timing, and which outputs belong to the wallet.
- It is entered on a hidden entry (the TUI asks for it twice; a mismatch is
`view keys do not match` and never dials), travels in the `generate_from_keys`
request body, and is kept nowhere else: never sealed, never in the wallet
catalogue, never logged, never on an argv. The core wipes its own copy when the
call returns and the screen wipes the typed buffer on every exit, `Esc`
included.
- The request carries **no `spendkey` field**, so the file the RPC writes is not
a spend authority: `transfer` on it is the RPC's own `-29` watch-only refusal.
- The file **passphrase** is still sealed, exactly as for a created or
seed-imported wallet — that is what reopens the file on the next start, and an
attacker with the store passphrase and a spend-capable file can move the
balance. The seal protects the file passphrase; it is not a protection for the
view key, and a view-only file is not a spend authority either way.
- What this does **not** stop: a view key pasted from a clipboard, a shoulder
surfer, a screen recorder, or a compromised wallet host. Import a view key only
on a machine you would trust with your incoming-transfer history.
## Backup file is the identity
`/backup` writes the identity and Noise static secrets. Treat the file like `onionwire.db`. Restore overwrites self keys and does **not** rewrite the friends table.

View file

@ -24,7 +24,7 @@ ASCII chrome.
| `ConfirmKeys` / `Passphrase` | `/backup`, `/restore` | Type `BACKUP`/`RESTORE`, then passphrase |
| `Wallet` | `F6` | Receive QR, balance, transfers, child, chain source |
| `WalletSelect` | `F6` `w` | Saved wallets, pick one or create one |
| `WalletSetup` | `F6` `c` / `i`, or `/wallet create` / `import` | Spend warning, seed, optional seed-offset passphrase, import |
| `WalletSetup` | `F6` `c` / `i` / `n` / `v`, or `/wallet create` / `import` | Spend warning, seed, optional seed-offset passphrase, restore height, import, send, view-only import |
| `WalletsSettings` | `F9` or `/settings` | Discovery menu (does not replace F-keys) |
| `PeerPayments` | F9 then `p` | Peer-scoped `/pay` / `/tip` history |
| `Quit` | `Ctrl-Q` | Type `CLEAR` or `QUIT` |
@ -110,7 +110,7 @@ Pane-specific (`pane_footer_hints`):
Footer:
```
c create i import r qr w wallets s/x child 1 pruned 2 full 3 testnet Esc back ? help
c create i import v view-only y copy n send r qr w wallets s/x child 1 pruned 2 full 3 testnet Esc back ? help
```
| Key | Effect |
@ -118,7 +118,10 @@ c create i import r qr w wallets s/x child 1 pruned 2 full 3 testnet Esc
| `r` or Enter | Toggle receive-address QR |
| `w` | Saved wallets (`WalletSelect`) |
| `c` | Create wallet (`SPEND` then seed once, type `SEEN`) |
| `i` | Import 25-word seed |
| `i` | Import 25-word seed (then an optional seed-offset passphrase and restore height) |
| `v` | Import an address to **watch** (address, view key twice, restore height, file passphrase) |
| `y` | Copy the receive address (OSC 52). Never a seed, never a view key |
| `n` | Send to a pasted address (address, amount, then `SEND`) — a local `transfer`, not a `/tip` |
| `s` | Start app-owned wallet child |
| `x` | Stop child (idempotent) |
| `p` | Probe child (RPC answering? chain at tip?) |
@ -132,8 +135,20 @@ The chain line for an in-process source always carries
Cuprate needs `--features cuprate-daemon`; without it, start fails with that
feature name.
`F6` shows one balance line — `balance 0.9 XMR · unlocked 0.45 XMR`, the total
and the part a spend can use out of a single `get_balance` (`wallet off` when no
wallet RPC is configured, `balance —` when the RPC did not answer with a total).
Create/import require the wallet RPC started with `--wallet-dir`. Filename:
`onionwire`. Seed is never collected on the composer.
`onionwire`. Seed is never collected on the composer, and never copied.
The import's two optional steps have their own footers: the offset step says
`blank Enter skips Esc cancel ? help`, the restore-height step says
`blank Enter scans from 0 Esc cancel ? help` (blank means "scan from 0"; a
height after your first receive hides the older funds and this version has no
rescan). The send confirmation says `type SEND Esc cancel ? help`, and `Esc`
there spends nothing. The view-only import has no seed, so it has no `SEEN`
step.
## Saved wallets (`F6` then `w`)

View file

@ -289,10 +289,57 @@ wallet actually holds (the derived seed), so a later seed backup restores this
wallet **without** the offset; the original words plus the offset are the other
backup, and the app keeps neither.
The import asks for an optional **restore height** after the offset step. Blank
`Enter` scans from block 0, which is what a plain import wants. A height *after*
your first receive **hides the older funds** — the wallet never scans below it —
and this version has **no rescan** to undo that, so set a height at or before the
first incoming transfer or leave it blank. The request carries a `restore_height`
field only when you typed one (a typed `0` is sent as `0`); a height that is not
a block number is refused locally with `restore height must be a block number`.
`F6` then `v` imports an address to **watch** instead: `generate_from_keys` with
the address and its private **view key**, and no `spendkey` in the request at
all. The file it writes can see incoming transfers and cannot spend — `transfer`
on it is the RPC's own `-29`, surfaced as the view-only message. The view key is
a secret (anyone holding it and the address sees the incoming transfers): it is
typed into a hidden entry (twice — a mismatch is `view keys do not match` with no
dial), goes to the RPC, and is kept nowhere else — not sealed, not in the
catalogue, not logged, never on an argv. What *is* sealed is the wallet-file
passphrase, exactly as for a created or seed-imported wallet, so the file reopens
on the next start. There is no seed on this path, so there is no `SEEN` step.
RPC must be started with `--wallet-dir` (not only `--wallet-file`). A created
wallet gets its own file name (`onionwire-1`, `onionwire-2`, …): `wallet_filename`
is UNIQUE in the catalogue, so a second create must not reuse the first file.
## Balance: total and unlocked
`get_balance` answers with two numbers and OnionWire exposes both: the **total**
(`wallet_balance`, everything the wallet has scanned, including amounts still
locked behind confirmations or immature) and the **unlocked** part
(`wallet_unlocked_balance`), the funds a spend can use right now. The wallet
screen shows them on one line, from one request:
balance 0.9 XMR · unlocked 0.45 XMR
`Node::wallet_balance_line` builds it, and the two sentinels are its own:
`wallet off` when no wallet RPC is configured, `balance —` when the RPC did not
answer with a total. (`wallet_balance` and `wallet_unlocked_balance` keep the
bare `off` / `err` words the WALLETS & SETTINGS menu tones and the SDK read.) A
wallet that shows a balance but refuses to spend is usually this distinction: the
incoming transfer is still confirming. Both numbers come out of one `get_balance`
request, never two.
## Send to a pasted address (`F6` then `n`)
A **local** `transfer` on the wallet this install has configured: an address, an
amount, then `SEND` to confirm. There is no friend, no `tip` frame, no chat line
and no payment row — the wallet's own outgoing transfer list is the record, so
`n` works with no peer online and leaves nothing in a conversation. A view-only
or unsynced wallet is refused with the same strings `/tip` uses. The receive
address has its own key, `y`, which copies it through the terminal's clipboard
(OSC 52); the seed path stays clipboard-free.
## Recommended topology (view-only)
```
@ -340,6 +387,7 @@ Restore from a height at or before the first incoming transaction.
| Receipt verification (`get_transfers`) | works, if daemon is synced | works, if daemon is synced |
| Profile `xmr_addr` fallback when RPC is down | works | works |
| `/tip <xmr>` (`transfer`) | **cannot work** | works |
| send to a pasted address (`F6` `n`, `transfer`) | **cannot work** | works |
| OnionWire copies your spend key into its own process | never | never (it stays in the wallet file / RPC) |
| Show the backup (seed via `query_key mnemonic`) | **no seed to show** (the RPC answers `-29`) | works |
| Show the private keys (`wallet_keys`) | view key only, `spend_key` is `None` | view + spend key |