wallet: expose an on-demand seed accessor over core + UniFFI #138

Merged
sirius merged 1 commit from onionwire/t_2142490d-wallet-seed-expose-an-on-demand-seed-acc into main 2026-09-20 16:13:28 +00:00
Owner

Goal

Expose the wallet's BIP39 seed on demand so the Android wallet screen can offer a "Back up seed" action and re-show the seed of an already-open wallet. Wallet::create_wallet returned the seed exactly once; after that it was unreachable.

What landed

  1. src/wallet.rs — pub async fn mnemonic(&self) -> Result<String>: one query_key mnemonic call on the wallet file the RPC has open, returning the words verbatim. Doc-commented as the only recovery path, and as a secret that must never be logged, stored, or put in an error string.
  2. src/node.rs — pub async fn wallet_seed(&self) -> Result<String, String>, mirroring wallet_create: NOT_CONFIGURED_MSG with no dial when unconfigured, .map_err(|e| e.to_string()) otherwise.
  3. crates/onionwire-sdk/src/lib.rs — additive pub async fn wallet_seed(&self) -> WResult<String>.

Kotlin-visible binding name (for the apk-dev child card)

    onionwire_sdk.Wire.walletSeed(): kotlin.String        // suspend fun

Verified by generating the bindings from the built cdylib (cargo build --lib, then uniffi-bindgen generate --library .../libonionwire_sdk.so --language kotlin); the generated onionwire_sdk.kt declares suspend fun walletSeed(): kotlin.String. That is the 0.32 UniFFI camelCase of wallet_seed.

Strictly additive: no existing SDK signature changed shape, and crates/onionwire-sdk/Cargo.lock is untouched (no new dependencies).

Failure shapes (all without leaking the login)

  • unconfigured wallet → NOT_CONFIGURED_MSG, no dial;
  • watch-only wallet → the RPC's -29 still maps to the existing view-only refusal (same parse_json_rpc path as view_only());
  • JSON-RPC error → the RPC's own message, with neither the password, the login, nor the endpoint in the string.

Tests (TDD: RED first, no method named mnemonic at all four call sites, then GREEN)

tests/wallet.rs, on the existing per-connection Digest mock (serve_one_conn / serve_rpc_conns), no new mock:

  • mnemonic_returns_the_words_the_rpc_answers — the 25 words come back verbatim, and the mock panics if any method other than query_key is dialed;
  • mnemonic_surfaces_an_rpc_error_without_leaking_the_login — the RPC message surfaces; the error carries neither the password nor http://;
  • mnemonic_refuses_a_rejected_digest_without_leaking_the_login — the 401 refusal names the login in prose but never the credential;
  • mnemonic_on_an_unconfigured_wallet_is_a_refusal_not_a_dial — Wallet::disabled() gets exactly NOT_CONFIGURED_MSG.

Verification (real output)

Root:

    cargo clippy --locked --all-targets --target x86_64-unknown-linux-gnu -- -D warnings
    Finished dev profile in 21.42s     (exit 0)

    cargo test --locked --target x86_64-unknown-linux-gnu
    all suites ok: 5+5+2+9+9+8+26+1+18+12+12+37+46+9+8 passed, 0 failed

    cargo test --locked --target x86_64-unknown-linux-gnu --test wallet mnemonic
    running 5 tests ... test result: ok. 5 passed; 0 failed

SDK (separate workspace, own target dir):

    cd crates/onionwire-sdk && cargo test --locked
    test result: ok. 39 passed; 0 failed   (lib)
    test sdk_installs_the_process_default_provider ... ok
    test rustls_default_provider_resolves_without_manual_install ... ok

    cargo clippy --locked --all-targets -- -D warnings
    Finished dev profile in 59.62s     (exit 0)

Scope

Only src/wallet.rs, src/node.rs, tests/wallet.rs, crates/onionwire-sdk/src/lib.rs. TUI, android, docs, Cargo.toml and CI untouched. rustfmt hunk counts on all four files equal their HEAD counts (inherited churn only; no new formatting diffs).

Base: main (3769bd9). PR body braces are written with parens/dashes because Forgejo's template parser eats {{ }}.

## Goal Expose the wallet's BIP39 seed **on demand** so the Android wallet screen can offer a "Back up seed" action and re-show the seed of an already-open wallet. `Wallet::create_wallet` returned the seed exactly once; after that it was unreachable. ## What landed 1. `src/wallet.rs` — `pub async fn mnemonic(&self) -> Result<String>`: one `query_key mnemonic` call on the wallet file the RPC has open, returning the words verbatim. Doc-commented as the only recovery path, and as a secret that must never be logged, stored, or put in an error string. 2. `src/node.rs` — `pub async fn wallet_seed(&self) -> Result<String, String>`, mirroring `wallet_create`: `NOT_CONFIGURED_MSG` with no dial when unconfigured, `.map_err(|e| e.to_string())` otherwise. 3. `crates/onionwire-sdk/src/lib.rs` — additive `pub async fn wallet_seed(&self) -> WResult<String>`. ## Kotlin-visible binding name (for the apk-dev child card) onionwire_sdk.Wire.walletSeed(): kotlin.String // suspend fun Verified by generating the bindings from the built cdylib (`cargo build --lib`, then `uniffi-bindgen generate --library .../libonionwire_sdk.so --language kotlin`); the generated `onionwire_sdk.kt` declares `suspend fun walletSeed(): kotlin.String`. That is the 0.32 UniFFI camelCase of `wallet_seed`. **Strictly additive**: no existing SDK signature changed shape, and `crates/onionwire-sdk/Cargo.lock` is untouched (no new dependencies). ## Failure shapes (all without leaking the login) - unconfigured wallet → `NOT_CONFIGURED_MSG`, no dial; - watch-only wallet → the RPC's `-29` still maps to the existing view-only refusal (same `parse_json_rpc` path as `view_only()`); - JSON-RPC error → the RPC's own message, with neither the password, the login, nor the endpoint in the string. ## Tests (TDD: RED first, `no method named mnemonic` at all four call sites, then GREEN) `tests/wallet.rs`, on the existing per-connection Digest mock (`serve_one_conn` / `serve_rpc_conns`), no new mock: - `mnemonic_returns_the_words_the_rpc_answers` — the 25 words come back verbatim, and the mock panics if any method other than `query_key` is dialed; - `mnemonic_surfaces_an_rpc_error_without_leaking_the_login` — the RPC message surfaces; the error carries neither the password nor `http://`; - `mnemonic_refuses_a_rejected_digest_without_leaking_the_login` — the 401 refusal names the login in prose but never the credential; - `mnemonic_on_an_unconfigured_wallet_is_a_refusal_not_a_dial` — `Wallet::disabled()` gets exactly `NOT_CONFIGURED_MSG`. ## Verification (real output) Root: cargo clippy --locked --all-targets --target x86_64-unknown-linux-gnu -- -D warnings Finished dev profile in 21.42s (exit 0) cargo test --locked --target x86_64-unknown-linux-gnu all suites ok: 5+5+2+9+9+8+26+1+18+12+12+37+46+9+8 passed, 0 failed cargo test --locked --target x86_64-unknown-linux-gnu --test wallet mnemonic running 5 tests ... test result: ok. 5 passed; 0 failed SDK (separate workspace, own target dir): cd crates/onionwire-sdk && cargo test --locked test result: ok. 39 passed; 0 failed (lib) test sdk_installs_the_process_default_provider ... ok test rustls_default_provider_resolves_without_manual_install ... ok cargo clippy --locked --all-targets -- -D warnings Finished dev profile in 59.62s (exit 0) ## Scope Only `src/wallet.rs`, `src/node.rs`, `tests/wallet.rs`, `crates/onionwire-sdk/src/lib.rs`. TUI, android, docs, Cargo.toml and CI untouched. rustfmt hunk counts on all four files equal their `HEAD` counts (inherited churn only; no new formatting diffs). Base: `main` (3769bd9). PR body braces are written with parens/dashes because Forgejo's template parser eats `{{ }}`.
wallet: expose an on-demand seed accessor over core + UniFFI
All checks were successful
ci / test (pull_request) Successful in 5m43s
ci / sdk (pull_request) Successful in 1m21s
android-ci / android (pull_request) Successful in 11m53s
ci / fuzz (pull_request) Successful in 4m53s
145036fda8
Wallet::create_wallet returned the 25-word seed exactly once and nothing
could reach it afterwards, so a seed that was never backed up at creation
was unrecoverable. Add Wallet::mnemonic() (one query_key mnemonic call on
the open wallet file), Node::wallet_seed() mirroring wallet_create, and the
additive UniFFI export Wire::wallet_seed() -> Kotlin Wire.walletSeed().

No existing signature changes. The refusals stay leak-free: an unconfigured
wallet gets NOT_CONFIGURED_MSG without a dial, a watch-only wallet keeps the
RPC's -29 view-only mapping, and no error string carries the RPC login.

Tests (tests/wallet.rs) drive the per-connection Digest mock: the words come
back verbatim, a JSON-RPC error surfaces without the login or endpoint, a
rejected digest refusal does not leak the password, and an unconfigured
wallet is refused without dialing.
sirius merged commit 94d29b8354 into main 2026-09-20 16:13:28 +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!138
No description provided.