wallet: expose an on-demand seed accessor over core + UniFFI
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.
This commit is contained in:
parent
3769bd9a42
commit
145036fda8
4 changed files with 116 additions and 0 deletions
|
|
@ -819,6 +819,80 @@ async fn mock_digest_auth_accepted() {
|
|||
assert!(got.starts_with('4'), "got {got}");
|
||||
}
|
||||
|
||||
/// The seed is a spend key: `mnemonic` must be one `query_key mnemonic` call
|
||||
/// and nothing else, so the caller sees exactly what the open wallet answers.
|
||||
#[tokio::test]
|
||||
async fn mnemonic_returns_the_words_the_rpc_answers() {
|
||||
const WORDS: &str = "one two three four five six seven eight nine ten eleven twelve \
|
||||
thirteen fourteen fifteen sixteen seventeen eighteen nineteen twenty twentyone \
|
||||
twentytwo twentythree twentyfour twentyfive";
|
||||
let listener = TcpListener::bind("127.0.0.1:0").await.unwrap();
|
||||
let port = listener.local_addr().unwrap().port();
|
||||
tokio::spawn(serve_rpc_conns(
|
||||
listener,
|
||||
Arc::new(|method: &str| match method {
|
||||
"query_key" => rpc_result(&format!(r#"{{"key":"{WORDS}"}}"#)),
|
||||
other => panic!("mnemonic must make one query_key call, saw {other}"),
|
||||
}),
|
||||
None,
|
||||
None,
|
||||
));
|
||||
let got = recording_wallet(port).mnemonic().await.expect("mnemonic");
|
||||
assert_eq!(got, WORDS);
|
||||
}
|
||||
|
||||
/// A wallet with no open file answers a JSON-RPC error. It must surface as the
|
||||
/// wallet's error, and the RPC login from the URL must not ride along with it.
|
||||
#[tokio::test]
|
||||
async fn mnemonic_surfaces_an_rpc_error_without_leaking_the_login() {
|
||||
let listener = TcpListener::bind("127.0.0.1:0").await.unwrap();
|
||||
let port = listener.local_addr().unwrap().port();
|
||||
tokio::spawn(serve_rpc_conns(
|
||||
listener,
|
||||
Arc::new(|_: &str| rpc_error(-1, "wallet file is not open")),
|
||||
None,
|
||||
None,
|
||||
));
|
||||
let err = recording_wallet(port).mnemonic().await.unwrap_err();
|
||||
let msg = err.to_string();
|
||||
assert!(msg.contains("wallet file is not open"), "got {err}");
|
||||
assert!(!msg.contains("secret"), "password leaked: {err}");
|
||||
assert!(!msg.contains("http://"), "endpoint leaked: {err}");
|
||||
}
|
||||
|
||||
/// The refused-digest refusal names the login in prose ("the login does not
|
||||
/// match"), which is exactly the copy that must not carry the credential.
|
||||
#[tokio::test]
|
||||
async fn mnemonic_refuses_a_rejected_digest_without_leaking_the_login() {
|
||||
let listener = TcpListener::bind("127.0.0.1:0").await.unwrap();
|
||||
let port = listener.local_addr().unwrap().port();
|
||||
tokio::spawn(serve_rpc_conns_with(
|
||||
listener,
|
||||
Arc::new(|_: &str| "HTTP/1.1 401 Unauthorized\r\nContent-Length: 0\r\n\r\n".to_string()),
|
||||
None,
|
||||
None,
|
||||
true,
|
||||
));
|
||||
let err = recording_wallet(port).mnemonic().await.unwrap_err();
|
||||
let msg = err.to_string();
|
||||
assert!(msg.contains("digest rejected"), "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 mnemonic_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.mnemonic())
|
||||
.unwrap_err();
|
||||
assert_eq!(err.to_string(), NOT_CONFIGURED_MSG);
|
||||
}
|
||||
|
||||
/// 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