sdk: expose the wallet catalogue, the open wallet's keys, and the self profile over UniFFI #145

Merged
sirius merged 1 commit from onionwire/t_c9e48c46-onionwire-sdk-expose-the-wallet-catalogu into main 2026-09-22 04:30:21 +00:00
Owner

What

Extends the UniFFI surface so the Android app can (a) list the saved wallets, select one, and read the open wallet's recovery phrase and private keys, and (b) read/edit its own profile and push it to friends. All the core work already existed; the SDK exposed none of it except the seed.

Base: origin/main @ a9117b8 (PR #144). state=open was 0 PRs when this card started, so nothing is stacked.

New symbols

Core (src/wallet.rs, src/node.rs):

  • Wallet::keys(&self) -> Result<WalletKeys> — two query_key calls (view_key, then spend_key) against the file the RPC has open. A view-only wallet's -29 becomes spend_key: None, not an error. WalletKeys has a hand-written redacting Debug.
  • Node::wallet_keys(&self) -> Result<wallet::WalletKeys, String> — mirrors wallet_create/wallet_seed; refuses locally with NOT_CONFIGURED_MSG before any dial.
  • Node::active_wallet_filename(&self) -> Result<Option<String>, String> — the file the child is pointed at (ChildConfig.wallet_filename); None until a wallet-child settings record exists (a fresh install), and None for a creds-only record written before the settings were persisted.

SDK (crates/onionwire-sdk/src/lib.rs):

  • pub struct WalletRow (Record): id: i64, name: Option<String>, wallet_filename: String, onion_locator: String, identity_pubkey_hex: String, created_at: i64
  • pub struct WalletKeys (Record): view_key: String, spend_key: Option<String> (redacting Debug, no Debug derive)
  • pub struct SelfProfile (Record): display_name: String, bio: String, xmr_addr: String
  • pub async fn wallets(&self) -> WResult<Vec<WalletRow>>
  • pub async fn open_wallet(&self, filename: String) -> WResult<()>
  • pub async fn active_wallet_filename(&self) -> WResult<Option<String>>
  • pub async fn wallet_keys(&self) -> WResult<WalletKeys>
  • pub async fn self_profile(&self) -> WResult<SelfProfile>
  • pub async fn set_self_profile(&self, display_name: String, bio: String, xmr_addr: String) -> WResult<()>
  • pub async fn push_self_profile(&self, pubkey_hex: String) -> WResult<()>

Every new pub fn carries the file's existing doc-comment discipline: what it dials, what it refuses, what it returns. crates/onionwire-sdk/Cargo.toml and Cargo.lock are untouched (no dependency changed).

The rule the clients must express

The seed and the private keys come from query_key against the wallet file the child has open, so they always belong to the row active_wallet_filename() names. There is deliberately no accessor that reads another catalogue wallet's seed or keys without opening it: open_wallet(...) first, and the UI says which wallet it is showing. A Kotlin picker pairs the two calls — wallets() for the list, activeWalletFilename() to mark the open row, openWallet(row.walletFilename) to switch (which may restart a running wallet child), then walletSeed() / walletKeys().

Kotlin reachability (generated, not assumed)

cargo build --lib then uniffi-bindgen generate --library libonionwire_sdk.so --language kotlin produces:

suspend fun activeWalletFilename(): kotlin.String?
suspend fun openWallet(filename: kotlin.String)
suspend fun pushSelfProfile(pubkeyHex: kotlin.String)
suspend fun selfProfile(): SelfProfile
suspend fun setSelfProfile(displayName: kotlin.String, bio: kotlin.String, xmrAddr: kotlin.String)
suspend fun walletKeys(): WalletKeys
suspend fun wallets(): List<WalletRow>
data class WalletRow(id: kotlin.Long, name: kotlin.String?, walletFilename: kotlin.String, onionLocator: kotlin.String, identityPubkeyHex: kotlin.String, createdAt: kotlin.Long)
data class WalletKeys(viewKey: kotlin.String, spendKey: kotlin.String?)
data class SelfProfile(displayName: kotlin.String, bio: kotlin.String, xmrAddr: kotlin.String)

Tests

Core (tests/wallet.rs, mock wallet RPC over loopback):

  • keys_returns_the_view_and_spend_keys_of_the_open_wallet — two query_key calls, in order.
  • keys_of_a_view_only_wallet_have_no_spend_key_and_no_error — -29 becomes spend_key: None.
  • keys_surfaces_an_rpc_error_that_is_not_the_view_only_answer — any other error is surfaced, and the RPC login does not ride along.
  • keys_on_an_unconfigured_wallet_is_a_refusal_not_a_dial.
  • wallet_keys_debug_never_prints_a_private_key.

Core (src/node.rs #[cfg(test)] mod tests; tests/*.rs cannot build a Node):

  • active_wallet_filename_is_none_until_the_child_has_been_pointed — None on a fresh install, None for a creds-only record, None for a catalogue row alone, Some after open_wallet.
  • wallet_keys_without_a_wallet_refuses_without_dialing.
  • wallet_keys_of_a_view_only_wallet_returns_no_spend_key — the node-level path a Kotlin caller takes.

SDK (own #[cfg(test)] mod tests):

  • one stopped-handle WireError.Stopped test per new async accessor, mirroring wallet_receive_address_on_stopped_handle_is_stopped_error;
  • push_self_profile_rejects_a_pubkey_that_is_not_hex_before_any_work;
  • wallet_rows_carry_the_catalogue_verbatim (store-backed: two rows through WalletRow, label None vs named, empty locator, pubkey hex);
  • keys_mapping_carries_both_halves_and_the_view_only_answer, wallet_keys_debug_never_prints_a_private_key, self_profile_mapping_carries_the_three_editable_fields.

open_wallet with a filename outside the catalogue being refused is already covered on main by open_wallet_refuses_a_file_the_catalogue_does_not_hold (src/node.rs); the SDK accessor is a one-line delegation of that call, and the SDK cannot build a Node (its only constructor bootstraps Arti over the network), so it is covered at the core and by the stopped-handle test at the SDK.

Docs (same commit)

  • docs/WALLET.md: the catalogue accessors and which wallet is open, a new "Secrets belong to the open wallet" section, and two rows in the view-only/spend-capable table.
  • docs/THREAT_MODEL.md: a new "The recovery phrase and the private keys are displayable on demand" section — the phone screen is now one of the places a spending secret can be read from; the values are never logged, never persisted, and shown only from an explicit action; a shoulder-surfer, a screen recorder or a screenshot is not stopped by any of that.
  • crates/onionwire-sdk/README.md: the Kotlin snippet for the catalogue + active wallet + keys + profile.

Verification run here

Root: cargo test --locked --target x86_64-unknown-linux-gnu and cargo clippy --locked --all-targets --target x86_64-unknown-linux-gnu -- -D warnings — both green.
SDK (separate workspace, own target dir): cargo test --locked (51 + 2 integration tests pass) and cargo clippy --locked --all-targets -- -D warnings — both green.
TMPDIR and both CARGO_TARGET_DIRs are on /home (the host root fs is at 99%).

Not verified: nothing runs on a device/emulator here — the Android cards consume these generated names, and the AAR build (Gradle + NDK) is theirs; no NDK build was run.

No core trust boundary changed: the private keys and the seed travel only over the existing loopback Digest RPC to the wallet child, which is the only source for them.

## What Extends the UniFFI surface so the Android app can (a) list the saved wallets, select one, and read the **open** wallet's recovery phrase and private keys, and (b) read/edit **its own profile** and push it to friends. All the core work already existed; the SDK exposed none of it except the seed. Base: `origin/main` @ a9117b8 (PR #144). `state=open` was **0 PRs** when this card started, so nothing is stacked. ## New symbols Core (`src/wallet.rs`, `src/node.rs`): - `Wallet::keys(&self) -> Result<WalletKeys>` — two `query_key` calls (`view_key`, then `spend_key`) against the file the RPC has **open**. A view-only wallet's `-29` becomes `spend_key: None`, not an error. `WalletKeys` has a hand-written redacting `Debug`. - `Node::wallet_keys(&self) -> Result<wallet::WalletKeys, String>` — mirrors `wallet_create`/`wallet_seed`; refuses locally with `NOT_CONFIGURED_MSG` before any dial. - `Node::active_wallet_filename(&self) -> Result<Option<String>, String>` — the file the child is pointed at (`ChildConfig.wallet_filename`); `None` until a wallet-child settings record exists (a fresh install), and `None` for a creds-only record written before the settings were persisted. SDK (`crates/onionwire-sdk/src/lib.rs`): - `pub struct WalletRow` (Record): `id: i64`, `name: Option<String>`, `wallet_filename: String`, `onion_locator: String`, `identity_pubkey_hex: String`, `created_at: i64` - `pub struct WalletKeys` (Record): `view_key: String`, `spend_key: Option<String>` (redacting `Debug`, no `Debug` derive) - `pub struct SelfProfile` (Record): `display_name: String`, `bio: String`, `xmr_addr: String` - `pub async fn wallets(&self) -> WResult<Vec<WalletRow>>` - `pub async fn open_wallet(&self, filename: String) -> WResult<()>` - `pub async fn active_wallet_filename(&self) -> WResult<Option<String>>` - `pub async fn wallet_keys(&self) -> WResult<WalletKeys>` - `pub async fn self_profile(&self) -> WResult<SelfProfile>` - `pub async fn set_self_profile(&self, display_name: String, bio: String, xmr_addr: String) -> WResult<()>` - `pub async fn push_self_profile(&self, pubkey_hex: String) -> WResult<()>` Every new `pub fn` carries the file's existing doc-comment discipline: what it dials, what it refuses, what it returns. `crates/onionwire-sdk/Cargo.toml` and `Cargo.lock` are untouched (no dependency changed). ## The rule the clients must express The seed and the private keys come from `query_key` against the wallet file the child has **open**, so they always belong to the row `active_wallet_filename()` names. There is deliberately **no** accessor that reads another catalogue wallet's seed or keys without opening it: `open_wallet(...)` first, and the UI says which wallet it is showing. A Kotlin picker pairs the two calls — `wallets()` for the list, `activeWalletFilename()` to mark the open row, `openWallet(row.walletFilename)` to switch (which may restart a running wallet child), then `walletSeed()` / `walletKeys()`. ## Kotlin reachability (generated, not assumed) `cargo build --lib` then `uniffi-bindgen generate --library libonionwire_sdk.so --language kotlin` produces: ``` suspend fun activeWalletFilename(): kotlin.String? suspend fun openWallet(filename: kotlin.String) suspend fun pushSelfProfile(pubkeyHex: kotlin.String) suspend fun selfProfile(): SelfProfile suspend fun setSelfProfile(displayName: kotlin.String, bio: kotlin.String, xmrAddr: kotlin.String) suspend fun walletKeys(): WalletKeys suspend fun wallets(): List<WalletRow> data class WalletRow(id: kotlin.Long, name: kotlin.String?, walletFilename: kotlin.String, onionLocator: kotlin.String, identityPubkeyHex: kotlin.String, createdAt: kotlin.Long) data class WalletKeys(viewKey: kotlin.String, spendKey: kotlin.String?) data class SelfProfile(displayName: kotlin.String, bio: kotlin.String, xmrAddr: kotlin.String) ``` ## Tests Core (`tests/wallet.rs`, mock wallet RPC over loopback): - `keys_returns_the_view_and_spend_keys_of_the_open_wallet` — two `query_key` calls, in order. - `keys_of_a_view_only_wallet_have_no_spend_key_and_no_error` — `-29` becomes `spend_key: None`. - `keys_surfaces_an_rpc_error_that_is_not_the_view_only_answer` — any other error is surfaced, and the RPC login does not ride along. - `keys_on_an_unconfigured_wallet_is_a_refusal_not_a_dial`. - `wallet_keys_debug_never_prints_a_private_key`. Core (`src/node.rs` `#[cfg(test)] mod tests`; `tests/*.rs` cannot build a `Node`): - `active_wallet_filename_is_none_until_the_child_has_been_pointed` — `None` on a fresh install, `None` for a creds-only record, `None` for a catalogue row alone, `Some` after `open_wallet`. - `wallet_keys_without_a_wallet_refuses_without_dialing`. - `wallet_keys_of_a_view_only_wallet_returns_no_spend_key` — the node-level path a Kotlin caller takes. SDK (own `#[cfg(test)] mod tests`): - one stopped-handle `WireError.Stopped` test per new async accessor, mirroring `wallet_receive_address_on_stopped_handle_is_stopped_error`; - `push_self_profile_rejects_a_pubkey_that_is_not_hex_before_any_work`; - `wallet_rows_carry_the_catalogue_verbatim` (store-backed: two rows through `WalletRow`, label `None` vs named, empty locator, pubkey hex); - `keys_mapping_carries_both_halves_and_the_view_only_answer`, `wallet_keys_debug_never_prints_a_private_key`, `self_profile_mapping_carries_the_three_editable_fields`. `open_wallet` with a filename outside the catalogue being refused is already covered on `main` by `open_wallet_refuses_a_file_the_catalogue_does_not_hold` (`src/node.rs`); the SDK accessor is a one-line delegation of that call, and the SDK cannot build a `Node` (its only constructor bootstraps Arti over the network), so it is covered at the core and by the stopped-handle test at the SDK. ## Docs (same commit) - `docs/WALLET.md`: the catalogue accessors and which wallet is open, a new "Secrets belong to the open wallet" section, and two rows in the view-only/spend-capable table. - `docs/THREAT_MODEL.md`: a new "The recovery phrase and the private keys are displayable on demand" section — the phone screen is now one of the places a spending secret can be read from; the values are never logged, never persisted, and shown only from an explicit action; a shoulder-surfer, a screen recorder or a screenshot is not stopped by any of that. - `crates/onionwire-sdk/README.md`: the Kotlin snippet for the catalogue + active wallet + keys + profile. ## Verification run here Root: `cargo test --locked --target x86_64-unknown-linux-gnu` and `cargo clippy --locked --all-targets --target x86_64-unknown-linux-gnu -- -D warnings` — both green. SDK (separate workspace, own target dir): `cargo test --locked` (51 + 2 integration tests pass) and `cargo clippy --locked --all-targets -- -D warnings` — both green. `TMPDIR` and both `CARGO_TARGET_DIR`s are on `/home` (the host root fs is at 99%). Not verified: nothing runs on a device/emulator here — the Android cards consume these generated names, and the AAR build (Gradle + NDK) is theirs; no NDK build was run. No core trust boundary changed: the private keys and the seed travel only over the existing loopback Digest RPC to the wallet child, which is the only source for them.
sdk: expose the wallet catalogue, the open wallet's keys, and the self profile
Some checks failed
ci / test (pull_request) Successful in 5m59s
ci / sdk (pull_request) Successful in 1m35s
android-ci / android (pull_request) Successful in 12m42s
ci / fuzz (pull_request) Has been cancelled
5f19a56be3
The Android wallet/profile screens had nothing to call: the core could list
wallets, switch the child onto one, read its keys and read/write the self
profile, but none of it crossed UniFFI.

Core:
- Wallet::keys() -> WalletKeys { view_key, spend_key: Option<String> }: two
  query_key calls against the file the RPC has open. A view-only wallet's -29
  is spend_key: None, not an error. WalletKeys' Debug redacts both halves.
- Node::wallet_keys() mirrors wallet_create/wallet_seed; refuses locally when
  no wallet is configured.
- Node::active_wallet_filename() -> Option<String>: the file the child is
  pointed at, None until wallet-child settings exist, so a client can mark the
  open row.

SDK (UniFFI):
- records WalletRow / WalletKeys / SelfProfile, and Wire::{wallets,
  open_wallet, active_wallet_filename, wallet_keys, self_profile,
  set_self_profile, push_self_profile}.
- The rule the clients must express is in the docs: the seed and the private
  keys come from the OPEN wallet, so there is deliberately no accessor that
  reads another saved wallet's secrets without opening it.

docs/WALLET.md (catalogue + 'secrets belong to the open wallet'),
docs/THREAT_MODEL.md (the new on-demand-display exposure surface) and the SDK
README are updated in the same commit.
sirius merged commit 0e866c096a into main 2026-09-22 04:30:21 +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!145
No description provided.