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

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.
This commit is contained in:
sirius 2026-09-22 00:25:33 -04:00
commit 5f19a56be3
No known key found for this signature in database
7 changed files with 784 additions and 3 deletions

View file

@ -1232,6 +1232,43 @@ impl Node {
w.mnemonic().await.map_err(|e| e.to_string())
}
/// The private view key and, when the wallet can spend, the private spend
/// key of the wallet file the child currently has **open** (`query_key`).
///
/// Secrets therefore belong to the open wallet: viewing another saved
/// wallet's keys means opening it first. A view-only wallet answers `None`
/// for `spend_key` instead of an error (the RPC's `-29`). An unconfigured
/// wallet is refused locally, before any dial; a configured but unreachable
/// child surfaces the RPC error.
///
/// The values are spend secrets: never log them and never persist them.
pub async fn wallet_keys(&self) -> Result<wallet::WalletKeys, String> {
let w = self.wallet_snapshot();
if !w.configured() {
return Err(wallet::NOT_CONFIGURED_MSG.into());
}
w.keys().await.map_err(|e| e.to_string())
}
/// The wallet file the child is currently pointed at, so a client can mark
/// the open row in the catalogue. `None` when no wallet-child settings have
/// ever been stored (a fresh install): a receive-only install has no open
/// wallet file, and the child never points at one until a wallet is created,
/// imported, or opened.
///
/// The name is what the child would spawn with, not a message from the
/// running process, and it may not match a catalogue row (an install whose
/// wallet predates the catalogue). Match it against
/// [`Node::list_wallets`] rather than assuming it is there.
pub fn active_wallet_filename(&self) -> Result<Option<String>, String> {
let store = self.store.lock().map_err(|e| e.to_string())?;
let Some(raw) = store.load_wallet_child().map_err(|e| e.to_string())? else {
return Ok(None);
};
let cfg = ChildConfig::from_record(&raw).map_err(|e| e.to_string())?;
Ok(cfg.map(|cfg| cfg.wallet_filename))
}
/// Import a wallet from an existing 25-word seed. This is the only path
/// that takes a user-supplied secret — and, like a create, it is remembered
/// in the catalogue under its own file name.
@ -3374,4 +3411,91 @@ pub(crate) mod tests {
"a refused switch must leave the child where it was"
);
}
/// The active wallet is a child-config fact, not a catalogue fact: a row in
/// the catalogue that the child was never pointed at is not open, and a
/// fresh install has no open wallet at all.
#[tokio::test]
async fn active_wallet_filename_is_none_until_the_child_has_been_pointed() {
let dir = tempfile::tempdir().unwrap();
let node = offline_node(&dir.path().join("bob"), Arc::new(NoDial));
assert_eq!(
node.active_wallet_filename().expect("read"),
None,
"a fresh install has no open wallet file"
);
// A record written before the settings were persisted (creds, no
// source block) is not an open wallet either.
node.store
.lock()
.unwrap()
.save_wallet_child(r#"{"user":"owuser","pass":"ow-pass"}"#)
.unwrap();
assert_eq!(
node.active_wallet_filename().expect("read"),
None,
"a creds-only record does not name a wallet file"
);
test_record_wallet(&node.store.lock().unwrap(), "onionwire-1", "savings");
assert_eq!(
node.active_wallet_filename().expect("read"),
None,
"a catalogue row alone does not open the wallet"
);
node.open_wallet("onionwire-1")
.expect("open a saved wallet");
assert_eq!(
node.active_wallet_filename().expect("read").as_deref(),
Some("onionwire-1"),
"the open wallet is the file the child was pointed at"
);
}
/// No wallet, no dial: the refusal is the configured-guard copy, not a
/// connection error, and it happens before any socket is opened.
#[tokio::test]
async fn wallet_keys_without_a_wallet_refuses_without_dialing() {
let dir = tempfile::tempdir().unwrap();
let node = offline_node(&dir.path().join("bob"), Arc::new(NoDial));
let err = node.wallet_keys().await.expect_err("no wallet configured");
assert_eq!(err, wallet::NOT_CONFIGURED_MSG);
}
/// The node-level path a Kotlin caller takes: two `query_key` calls against
/// the open wallet's RPC, with the view-only `-29` arriving as
/// `spend_key: None` rather than as an error.
#[tokio::test]
async fn wallet_keys_of_a_view_only_wallet_returns_no_spend_key() {
let listener = tokio::net::TcpListener::bind("127.0.0.1:0")
.await
.expect("bind mock wallet");
let port = listener.local_addr().expect("mock wallet addr").port();
let reply: Arc<dyn Fn(&str) -> String + Send + Sync> = Arc::new(|req: &str| {
if req.contains("spend_key") {
r#"{"jsonrpc":"2.0","id":"0","error":{"code":-29,"message":"The wallet is watch-only. Cannot retrieve spend key."}}"#
.to_string()
} else {
r#"{"jsonrpc":"2.0","id":"0","result":{"key":"aabbccdd"}}"#.to_string()
}
});
tokio::spawn(serve_mock_rpc(listener, reply));
let dir = tempfile::tempdir().unwrap();
let node = offline_node_with_wallet(
&dir.path().join("bob"),
Arc::new(NoDial),
Wallet::from_url(&format!("http://ow:[email protected]:{port}")).expect("wallet url"),
);
let keys = node.wallet_keys().await.expect("keys");
assert_eq!(keys.view_key, "aabbccdd");
assert_eq!(
keys.spend_key, None,
"the RPC's -29 is the wallet's answer, not a failure"
);
}
}