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
|
|
@ -788,6 +788,25 @@ impl Wallet {
|
|||
json_str(&v, "key")
|
||||
}
|
||||
|
||||
/// Re-read the seed of the wallet file the RPC has open (`query_key
|
||||
/// mnemonic`). After `create_wallet` this is the **only** way to recover a
|
||||
/// created wallet's seed, so the UI can offer a backup action instead of
|
||||
/// showing it once. It needs an open, spend-capable wallet file; a
|
||||
/// watch-only one answers the RPC's `-29` and surfaces as the view-only
|
||||
/// refusal.
|
||||
///
|
||||
/// The returned words are a spend key: never log them, never store them,
|
||||
/// and never put them in an error string.
|
||||
pub async fn mnemonic(&self) -> Result<String> {
|
||||
if !self.configured() {
|
||||
return Err(Error(NOT_CONFIGURED_MSG.into()));
|
||||
}
|
||||
let v = self
|
||||
.rpc("query_key", serde_json::json!({"key_type": "mnemonic"}))
|
||||
.await?;
|
||||
json_str(&v, "key")
|
||||
}
|
||||
|
||||
/// Import an existing wallet from its 25-word seed. This is the only path
|
||||
/// that takes a user-supplied secret.
|
||||
pub async fn restore_wallet(&self, filename: &str, password: &str, seed: &str) -> Result<()> {
|
||||
|
|
|
|||
Loading…
Reference in a new issue