sdk: expose the wallet catalogue, the open wallet's keys, and the self profile
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:
parent
a9117b8991
commit
5f19a56be3
7 changed files with 784 additions and 3 deletions
142
tests/wallet.rs
142
tests/wallet.rs
|
|
@ -1,5 +1,6 @@
|
|||
//! M8: optional monero-wallet-rpc JSON client. Mock TCP only — no live monerod.
|
||||
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use ed25519_dalek::SigningKey;
|
||||
|
|
@ -893,6 +894,147 @@ fn mnemonic_on_an_unconfigured_wallet_is_a_refusal_not_a_dial() {
|
|||
assert_eq!(err.to_string(), NOT_CONFIGURED_MSG);
|
||||
}
|
||||
|
||||
/// The two private keys come from the open wallet file, in two `query_key`
|
||||
/// calls: `view_key` first (always available), `spend_key` second (absent on a
|
||||
/// view-only wallet). A wallet that can spend answers both.
|
||||
#[tokio::test]
|
||||
async fn keys_returns_the_view_and_spend_keys_of_the_open_wallet() {
|
||||
const VIEW: &str = "0f0e0d0c0b0a09080706050403020100";
|
||||
const SPEND: &str = "0102030405060708090a0b0c0d0e0f10";
|
||||
let listener = TcpListener::bind("127.0.0.1:0").await.unwrap();
|
||||
let port = listener.local_addr().unwrap().port();
|
||||
let calls = Arc::new(AtomicUsize::new(0));
|
||||
let seen = Arc::clone(&calls);
|
||||
tokio::spawn(serve_rpc_conns(
|
||||
listener,
|
||||
Arc::new(move |method: &str| match method {
|
||||
"query_key" => match seen.fetch_add(1, Ordering::SeqCst) {
|
||||
0 => rpc_result(&format!(r#"{{"key":"{VIEW}"}}"#)),
|
||||
_ => rpc_result(&format!(r#"{{"key":"{SPEND}"}}"#)),
|
||||
},
|
||||
other => panic!("keys must only ask query_key, saw {other}"),
|
||||
}),
|
||||
None,
|
||||
None,
|
||||
));
|
||||
let keys = recording_wallet(port).keys().await.expect("keys");
|
||||
assert_eq!(keys.view_key, VIEW);
|
||||
assert_eq!(keys.spend_key.as_deref(), Some(SPEND));
|
||||
assert_eq!(calls.load(Ordering::SeqCst), 2, "one call per key");
|
||||
}
|
||||
|
||||
/// A view-only wallet has no spend key: the RPC answers `-29`
|
||||
/// (`WALLET_RPC_ERROR_CODE_WATCH_ONLY`). That is the wallet's answer, so it must
|
||||
/// come back as `spend_key: None` — not as an error, which would leave the
|
||||
/// backup screen unable to show the view key.
|
||||
#[tokio::test]
|
||||
async fn keys_of_a_view_only_wallet_have_no_spend_key_and_no_error() {
|
||||
const VIEW: &str = "aabbccddeeff00112233445566778899";
|
||||
let listener = TcpListener::bind("127.0.0.1:0").await.unwrap();
|
||||
let port = listener.local_addr().unwrap().port();
|
||||
let calls = Arc::new(AtomicUsize::new(0));
|
||||
let seen = Arc::clone(&calls);
|
||||
tokio::spawn(serve_rpc_conns(
|
||||
listener,
|
||||
Arc::new(move |method: &str| match method {
|
||||
"query_key" => match seen.fetch_add(1, Ordering::SeqCst) {
|
||||
0 => rpc_result(&format!(r#"{{"key":"{VIEW}"}}"#)),
|
||||
_ => rpc_error(-29, "The wallet is watch-only. Cannot retrieve spend key."),
|
||||
},
|
||||
other => panic!("keys must only ask query_key, saw {other}"),
|
||||
}),
|
||||
None,
|
||||
None,
|
||||
));
|
||||
let keys = recording_wallet(port)
|
||||
.keys()
|
||||
.await
|
||||
.expect("a view-only wallet");
|
||||
assert_eq!(keys.view_key, VIEW);
|
||||
assert_eq!(
|
||||
keys.spend_key, None,
|
||||
"view-only means no spend key to hand out"
|
||||
);
|
||||
}
|
||||
|
||||
/// Any *other* RPC failure is a real failure: a view-only `-29` is the only
|
||||
/// error `keys` turns into `None`.
|
||||
#[tokio::test]
|
||||
async fn keys_surfaces_an_rpc_error_that_is_not_the_view_only_answer() {
|
||||
let listener = TcpListener::bind("127.0.0.1:0").await.unwrap();
|
||||
let port = listener.local_addr().unwrap().port();
|
||||
let calls = Arc::new(AtomicUsize::new(0));
|
||||
let seen = Arc::clone(&calls);
|
||||
tokio::spawn(serve_rpc_conns(
|
||||
listener,
|
||||
Arc::new(move |_: &str| {
|
||||
if seen.fetch_add(1, Ordering::SeqCst) == 0 {
|
||||
rpc_result(r#"{"key":"aabbccdd"}"#)
|
||||
} else {
|
||||
rpc_error(-1, "wallet file is not open")
|
||||
}
|
||||
}),
|
||||
None,
|
||||
None,
|
||||
));
|
||||
let err = recording_wallet(port)
|
||||
.keys()
|
||||
.await
|
||||
.expect_err("a spend-key error that is not -29 must not read as view-only");
|
||||
let msg = err.to_string();
|
||||
assert!(msg.contains("wallet file is not open"), "got {err}");
|
||||
assert!(!msg.contains("secret"), "password leaked: {err}");
|
||||
}
|
||||
|
||||
/// No endpoint, no dial: the refusal is the configured-guard copy the rest of
|
||||
/// the wallet uses, not a connection error.
|
||||
#[test]
|
||||
fn keys_on_an_unconfigured_wallet_is_a_refusal_not_a_dial() {
|
||||
let w = Wallet::disabled();
|
||||
let err = tokio::runtime::Builder::new_current_thread()
|
||||
.enable_all()
|
||||
.build()
|
||||
.unwrap()
|
||||
.block_on(w.keys())
|
||||
.unwrap_err();
|
||||
assert_eq!(err.to_string(), NOT_CONFIGURED_MSG);
|
||||
}
|
||||
|
||||
/// The keys are spend secrets. `WalletKeys` is the value the whole path carries,
|
||||
/// so its `Debug` must not print either key — a stray `{:?}` in a log is how a
|
||||
/// key leaks.
|
||||
#[test]
|
||||
fn wallet_keys_debug_never_prints_a_private_key() {
|
||||
let keys = wallet::WalletKeys {
|
||||
view_key: "VIEWKEYMATERIAL".to_string(),
|
||||
spend_key: Some("SPENDKEYMATERIAL".to_string()),
|
||||
};
|
||||
let printed = format!("{keys:?}");
|
||||
assert!(
|
||||
!printed.contains("VIEWKEYMATERIAL"),
|
||||
"view key leaked: {printed}"
|
||||
);
|
||||
assert!(
|
||||
!printed.contains("SPENDKEYMATERIAL"),
|
||||
"spend key leaked: {printed}"
|
||||
);
|
||||
assert!(printed.contains("redacted"), "got {printed}");
|
||||
|
||||
let only_view = wallet::WalletKeys {
|
||||
view_key: "VIEWKEYMATERIAL".to_string(),
|
||||
spend_key: None,
|
||||
};
|
||||
let printed = format!("{only_view:?}");
|
||||
assert!(
|
||||
!printed.contains("VIEWKEYMATERIAL"),
|
||||
"view key leaked: {printed}"
|
||||
);
|
||||
assert!(
|
||||
printed.contains("None"),
|
||||
"a view-only wallet must read as None: {printed}"
|
||||
);
|
||||
}
|
||||
|
||||
/// Answers the Digest challenge, then holds the reply for `delay`. Lets a test
|
||||
/// prove which call classes get which budget.
|
||||
async fn serve_delayed(listener: TcpListener, delay: std::time::Duration) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue