node: remember a created wallet in the store catalogue #143

Merged
sirius merged 1 commit from wt/t_511023b6 into wt/t_64c9ba3c 2026-09-21 15:10:36 +00:00
Owner

Stacked on #141 (wt/t_64c9ba3c, base main, not yet merged): this branch needs the wallets table and Store::{create_wallet,list_wallets}, so the base here is wt/t_64c9ba3c, not main. Please retarget to main after #141 lands.

The bug

Node::wallet_create created the wallet on the RPC and returned the seed — nothing else. The file name was the one hardcoded wallet::DEFAULT_WALLET_FILENAME (onionwire), and the child's stored config defaults to that same name, so the first create worked by accident. A second create reused onionwire, the RPC refused it (the file exists), and no row was ever written: the app could not create another wallet and remembered nothing across restarts (issue #140).

The fix

Creation and import now go through the store catalogue.

  • Node::wallet_create(password) -> Result<CreatedWallet, String>, where CreatedWallet is record: WalletRecord plus seed: String. record is the stored row (id and created_at assigned by the store); seed is the one-time backup phrase the UI already shows. CreatedWallet has a hand-written Debug that redacts the seed.
  • Node::wallet_restore(password, seed) -> Result<WalletRecord, String> — import is a creation path too and had the same hardcoded name.
  • Node::list_wallets() -> Result<Vec<WalletRecord>, String> — a store read, no dial, works with the wallet off.
  • Each create/import gets its own file name: onionwire-<n> for the first n the catalogue does not already hold, so several wallets coexist.
  • The child config is re-pointed at the new file by a read-modify-write of the sealed record (set_wallet_child_config, which preserves the generated RPC creds). A row the child never opens would still be a broken wallet. The change applies on the next start_wallet_child; a running child is not restarted.

identity_pubkey is this node's identity (not unique — identity is the roster key, a wallet is a file) and onion_locator is read at creation time (a locator, allowed to be empty before the HS publishes). Neither is a key.

Surface changes

  • src/tui.rs create screen destructures CreatedWallet for the seed.
  • crates/onionwire-sdk/src/lib.rs: the UniFFI signatures are unchanged (create_wallet -> String, import_wallet -> ()), so there is no Kotlin change — the SDK unwraps .seed and maps the record to (). Verified with cargo test and cargo clippy inside crates/onionwire-sdk.

Verification

  • TDD, RED first: error[E0599] no method named list_wallets and E0609 field access on the old String return, then green. The child-repoint test was RED at left: "onionwire" / right: "onionwire-1".
  • 5 new cases in the src/node.rs test module (no tests/*.rs can build a Node): row + identity + locator + seed in the catalogue; a second wallet gets its own file and both survive a reopen; import records a row; a wallet-off install lists an empty catalogue and still refuses to create; the child is re-pointed and the first wallet keeps its file.
  • cargo test --locked exit 0; cargo clippy --locked --all-targets -- -D warnings clean; both clean in crates/onionwire-sdk too. Cargo.lock untouched (no new dependency).
  • rustfmt --edition 2024 --check src/node.rs reports the same 2 inherited hunks as the base; no new ones.

Not in this PR: the wallet-selection screen (t_14ac0a3f) and the selection-to-load wiring (t_895853ad) — loading an existing wallet means reading the row and re-pointing the child, which is that card's job.

Stacked on #141 (`wt/t_64c9ba3c`, base `main`, not yet merged): this branch needs the `wallets` table and `Store::{create_wallet,list_wallets}`, so the base here is `wt/t_64c9ba3c`, not `main`. Please retarget to `main` after #141 lands. ## The bug `Node::wallet_create` created the wallet on the RPC and returned the seed — nothing else. The file name was the one hardcoded `wallet::DEFAULT_WALLET_FILENAME` (onionwire), and the child's stored config defaults to that same name, so the *first* create worked by accident. A second create reused `onionwire`, the RPC refused it (the file exists), and no row was ever written: the app could not create another wallet and remembered nothing across restarts (issue #140). ## The fix Creation and import now go through the store catalogue. - `Node::wallet_create(password) -> Result<CreatedWallet, String>`, where `CreatedWallet` is `record: WalletRecord` plus `seed: String`. `record` is the stored row (id and `created_at` assigned by the store); `seed` is the one-time backup phrase the UI already shows. `CreatedWallet` has a hand-written `Debug` that redacts the seed. - `Node::wallet_restore(password, seed) -> Result<WalletRecord, String>` — import is a creation path too and had the same hardcoded name. - `Node::list_wallets() -> Result<Vec<WalletRecord>, String>` — a store read, no dial, works with the wallet off. - Each create/import gets its own file name: `onionwire-<n>` for the first `n` the catalogue does not already hold, so several wallets coexist. - The child config is re-pointed at the new file by a read-modify-write of the sealed record (`set_wallet_child_config`, which preserves the generated RPC creds). A row the child never opens would still be a broken wallet. The change applies on the next `start_wallet_child`; a running child is not restarted. `identity_pubkey` is this node's identity (not unique — identity is the roster key, a wallet is a file) and `onion_locator` is read at creation time (a locator, allowed to be empty before the HS publishes). Neither is a key. ## Surface changes - `src/tui.rs` create screen destructures `CreatedWallet` for the seed. - `crates/onionwire-sdk/src/lib.rs`: the UniFFI signatures are unchanged (`create_wallet -> String`, `import_wallet -> ()`), so there is no Kotlin change — the SDK unwraps `.seed` and maps the record to `()`. Verified with `cargo test` and `cargo clippy` inside `crates/onionwire-sdk`. ## Verification - TDD, RED first: `error[E0599] no method named list_wallets` and `E0609` field access on the old `String` return, then green. The child-repoint test was RED at `left: "onionwire"` / `right: "onionwire-1"`. - 5 new cases in the `src/node.rs` test module (no `tests/*.rs` can build a `Node`): row + identity + locator + seed in the catalogue; a second wallet gets its own file and both survive a reopen; import records a row; a wallet-off install lists an empty catalogue and still refuses to create; the child is re-pointed and the first wallet keeps its file. - `cargo test --locked` exit 0; `cargo clippy --locked --all-targets -- -D warnings` clean; both clean in `crates/onionwire-sdk` too. `Cargo.lock` untouched (no new dependency). - `rustfmt --edition 2024 --check src/node.rs` reports the same 2 inherited hunks as the base; no new ones. Not in this PR: the wallet-selection screen (t_14ac0a3f) and the selection-to-load wiring (t_895853ad) — loading an existing wallet means reading the row and re-pointing the child, which is that card's job.
node: remember a created wallet in the store's catalogue
All checks were successful
ci / test (pull_request) Successful in 5m53s
ci / sdk (pull_request) Successful in 1m35s
android-ci / android (pull_request) Successful in 12m30s
ci / fuzz (pull_request) Successful in 4m55s
0043fa0b34
A wallet created in-app was never remembered: `Node::wallet_create` called
the RPC and returned the seed, and the wallet file name was the one
hardcoded `wallet::DEFAULT_WALLET_FILENAME` ("onionwire"). A second create
reused that name, so the RPC refused it (or opened the first wallet's
file) and no row was ever written — the "cannot create a new wallet, and
nothing survives a restart" report.

Creation and import now go through the catalogue (t_64c9ba3c's
`Store::{create_wallet,list_wallets}`):

- each create/import gets its own file name, `onionwire-<n>` for the first
  `n` the catalogue does not hold, so several wallets coexist;
- the stored row (id, identity, locator, file, created_at) is returned:
  `Node::wallet_create` -> `CreatedWallet` (row + the one-time seed, with a
  redacting `Debug`), `Node::wallet_restore` -> `WalletRecord`;
- `Node::list_wallets` reads the catalogue without dialing;
- the child config is re-pointed at the new file (read-modify-write, so the
  sealed RPC creds survive) — a row the child never opens would still be a
  broken wallet.

The SDK keeps its UniFFI signature (`create_wallet -> String` seed,
`import_wallet -> ()`), so no Kotlin change: it unwraps `.seed`.

TDD: 5 new `src/node.rs` cases (row + list, two wallets + reopen, import,
wallet-off empty list, child re-pointed) over a loopback wallet-RPC mock.
`cargo test --locked` exit 0, `cargo clippy --locked --all-targets -- -D
warnings` clean, and the same two commands are clean in
`crates/onionwire-sdk`.
sirius merged commit dd7c749373 into wt/t_64c9ba3c 2026-09-21 15:10:36 +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!143
No description provided.