diff --git a/README.md b/README.md index 5545d90..1ffa795 100644 --- a/README.md +++ b/README.md @@ -322,10 +322,7 @@ Prefer `ONIONWIRE_WALLET_NO_SPEND=1` until you actually want `/tip`. Details: Peer onion down → `/pay` and `/tip` fail. A queued invoice does not exist. `F6` then `c` / `/wallet create` generates a spend-capable wallet and shows the -25-word seed **once**. `F6` then `i` / `/wallet import` restores from a seed, and -takes an optional Monero seed-offset passphrase (a second spend secret, not the -wallet-file passphrase; blank skips it, a wrong one opens a different wallet and -does not fail). +25-word seed **once**. `F6` then `i` / `/wallet import` restores from a seed. Type `SPEND` then `SEEN` on create. Each wallet gets its own file name (`onionwire-1`, `onionwire-2`, …); the RPC must be started with `--wallet-dir`. diff --git a/crates/onionwire-sdk/src/lib.rs b/crates/onionwire-sdk/src/lib.rs index 35d4b70..711901d 100644 --- a/crates/onionwire-sdk/src/lib.rs +++ b/crates/onionwire-sdk/src/lib.rs @@ -764,43 +764,9 @@ impl Wire { /// Import a wallet from an existing 25-word seed. This is the only path /// that takes a user-supplied secret. Like a create, the core records the /// imported wallet in its catalogue. - /// - /// This is the plain import: the request carries no seed offset. Use - /// [`Wire::import_wallet_with_offset`] when the words were mixed with a - /// seed-offset passphrase. pub async fn import_wallet(&self, password: String, seed: String) -> WResult<()> { self.node()? - .wallet_restore(&password, &seed, None) - .await - .map_err(WireError::new) - .map(|_| ()) - } - - /// Import a wallet from an existing 25-word seed plus its optional seed - /// offset passphrase (`restore_deterministic_wallet`'s `seed_offset`). - /// - /// The offset is **not** the wallet-file passphrase: it is a second spend - /// secret mixed into the seed at restore time, so the same words with a - /// different offset open a different wallet. It is never logged, never - /// stored and never sealed, and a wrong offset does not fail — the RPC - /// succeeds and the wallet is simply a different one. - /// - /// Blank or whitespace-only `seed_offset` behaves exactly like - /// [`Wire::import_wallet`]: the request carries no `seed_offset` field. - pub async fn import_wallet_with_offset( - &self, - password: String, - seed: String, - seed_offset: String, - ) -> WResult<()> { - let offset = seed_offset.trim(); - let offset = if offset.is_empty() { - None - } else { - Some(offset) - }; - self.node()? - .wallet_restore(&password, &seed, offset) + .wallet_restore(&password, &seed) .await .map_err(WireError::new) .map(|_| ()) diff --git a/docs/THREAT_MODEL.md b/docs/THREAT_MODEL.md index 8075e96..d1aa600 100644 --- a/docs/THREAT_MODEL.md +++ b/docs/THREAT_MODEL.md @@ -193,19 +193,6 @@ already runs, or one the app spawns. Wallet RPC is never dialed over clearnet or over `.onion` — a remote wallet RPC would move spend authority off the box through a channel the messenger’s `--password` gate does not cover. -**The seed-offset passphrase is a second spend secret, and it is not stored.** -An import may be given Monero's optional `seed_offset`: a phrase mixed into the -25 words at restore time, so the same words with a different offset open a -different wallet (plausible deniability). It is typed once, travels only in the -JSON-RPC body (never argv, never logged, never an error string), is never sealed -and never persisted — storing it would defeat the point. It is also not a second -gate on an already-imported wallet: whoever can unlock the store can still spend -the opened file, because the wallet file's own passphrase *is* sealed (previous -paragraph). A wrong offset is silent — the RPC succeeds and the wallet is -simply a different one — so the app cannot warn about it, and after such an -import a later seed backup is the *derived* mnemonic, which opens the wallet -without the offset. - ### Chain source is the user’s choice Scan, receipt verification, and spend need a Monero daemon. The user picks one; diff --git a/docs/TUI.md b/docs/TUI.md index a5ea38d..a763944 100644 --- a/docs/TUI.md +++ b/docs/TUI.md @@ -24,7 +24,7 @@ ASCII chrome. | `ConfirmKeys` / `Passphrase` | `/backup`, `/restore` | Type `BACKUP`/`RESTORE`, then passphrase | | `Wallet` | `F6` | Receive QR, balance, transfers, child, chain source | | `WalletSelect` | `F6` `w` | Saved wallets, pick one or create one | -| `WalletSetup` | `F6` `c` / `i`, or `/wallet create` / `import` | Spend warning, seed, optional seed-offset passphrase, import | +| `WalletSetup` | `F6` `c` / `i`, or `/wallet create` / `import` | Spend warning, seed, import | | `WalletsSettings` | `F9` or `/settings` | Discovery menu (does not replace F-keys) | | `PeerPayments` | F9 then `p` | Peer-scoped `/pay` / `/tip` history | | `Quit` | `Ctrl-Q` | Type `CLEAR` or `QUIT` | diff --git a/docs/WALLET.md b/docs/WALLET.md index 457e4d5..50b27ac 100644 --- a/docs/WALLET.md +++ b/docs/WALLET.md @@ -279,15 +279,7 @@ are displayable on demand". reopens on the next start without asking for it again. `/wallet import` (`F6` then `i`) → `restore_deterministic_wallet` from a -25-word seed. Do not put the seed on the composer. The import also takes an -optional **seed-offset passphrase** — a second spend secret mixed into the words -at restore time, not the wallet-file passphrase. It is never sealed, never -stored, never logged and never on an argv: blank `Enter` skips it, and a wrong -offset is *not* an error — the RPC succeeds and opens a different wallet. After -an import that used one, `query_key mnemonic` is the mnemonic of the keys the -wallet actually holds (the derived seed), so a later seed backup restores this -wallet **without** the offset; the original words plus the offset are the other -backup, and the app keeps neither. +25-word seed. Do not put the seed on the composer. RPC must be started with `--wallet-dir` (not only `--wallet-file`). A created wallet gets its own file name (`onionwire-1`, `onionwire-2`, …): `wallet_filename` diff --git a/src/node.rs b/src/node.rs index 6b128c9..a886545 100644 --- a/src/node.rs +++ b/src/node.rs @@ -1473,25 +1473,13 @@ impl Node { /// 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. - /// - /// `seed_offset` is Monero's optional seed-offset passphrase (a second spend - /// secret mixed into the seed at restore time, not the file passphrase). It - /// is forwarded to the RPC and nothing else: never sealed, never stored, - /// never logged, never on the argv, and a wrong one is not an error — the - /// RPC succeeds and the wallet is a different one. Only `password` is sealed - /// here, into the same record the next start opens the file with. - pub async fn wallet_restore( - &self, - password: &str, - seed: &str, - seed_offset: Option<&str>, - ) -> Result { + pub async fn wallet_restore(&self, password: &str, seed: &str) -> Result { let w = self.wallet_snapshot(); if !w.configured() { return Err(wallet::NOT_CONFIGURED_MSG.into()); } let filename = self.next_wallet_filename()?; - w.restore_wallet(&filename, password, seed, seed_offset) + w.restore_wallet(&filename, password, seed) .await .map_err(|e| e.to_string())?; let record = self @@ -3712,7 +3700,7 @@ pub(crate) mod tests { ); let imported = node - .wallet_restore("hunter2", "lumber tacit lemon ivory risk", None) + .wallet_restore("hunter2", "lumber tacit lemon ivory risk") .await .expect("restore wallet"); diff --git a/src/tui.rs b/src/tui.rs index 34a8843..90ba37e 100644 --- a/src/tui.rs +++ b/src/tui.rs @@ -1306,29 +1306,7 @@ enum WalletSetup { CreatePass { entry: PassphraseEntry }, CreateSeed { seed: Zeroizing, typed: String }, ImportSeed { buf: Zeroizing }, - /// The optional seed offset passphrase, asked between the seed and the - /// wallet-file passphrase. It is a second spend secret mixed into the seed - /// at restore time, so it needs its own two-prompt entry (not the file - /// passphrase's) and is never drawn. - ImportOffset { - seed: Zeroizing, - entry: PassphraseEntry, - }, - /// Import, carrying the offset (empty means none) through both file - /// passphrase prompts, including the mismatch path, which zeroizes both - /// secrets. - ImportPass { - seed: Zeroizing, - offset: Zeroizing, - entry: PassphraseEntry, - }, - /// A restore that used an offset: the app keeps neither the offset nor a - /// copy of the pasted words, so this one notice is all the user gets. The - /// wallet file already exists; `Esc` does not leave this screen and only - /// `SEEN` opens the wallet. - ImportOffsetSeen { - typed: String, - }, + ImportPass { seed: Zeroizing, entry: PassphraseEntry }, /// The wallet file the child is pointed at is not open because this install /// has no passphrase for it. Same prompt idiom as the create path: one /// hidden entry, `Enter` submits, `Esc` cancels, and the buffer is zeroized @@ -2409,26 +2387,11 @@ impl App { }; if key.code == KeyCode::Esc { match setup { - // The wallet file already exists at this point, and the offset - // is not saved anywhere: Esc must not silently drop the one - // notice that says so. Only `SEEN` leaves this screen. - WalletSetup::ImportOffsetSeen { .. } => return Ok(()), - WalletSetup::CreatePass { entry } | WalletSetup::UnlockPass { entry, .. } => { + WalletSetup::CreatePass { entry } + | WalletSetup::ImportPass { entry, .. } + | WalletSetup::UnlockPass { entry, .. } => { entry.close(); } - WalletSetup::ImportPass { - seed, - offset, - entry, - } => { - entry.close(); - seed.zeroize(); - offset.zeroize(); - } - WalletSetup::ImportOffset { seed, entry } => { - entry.close(); - seed.zeroize(); - } WalletSetup::CreateSeed { seed, .. } => seed.zeroize(), WalletSetup::ImportSeed { buf } => buf.zeroize(), WalletSetup::CreateWarn { .. } => {} @@ -2514,59 +2477,14 @@ impl App { self.screen = Screen::Main; return Ok(()); } - self.screen = Screen::WalletSetup(WalletSetup::ImportOffset { + self.screen = Screen::WalletSetup(WalletSetup::ImportPass { seed, entry: PassphraseEntry::new(), }); } _ => {} }, - WalletSetup::ImportOffset { seed, entry } => match key.code { - KeyCode::Backspace => entry.backspace(), - KeyCode::Char(c) if !key.modifiers.contains(KeyModifiers::CONTROL) => { - entry.push(c); - } - KeyCode::Enter => { - let first = entry.take_first(); - let offset = entry.take_buf(); - if let Some(first) = first { - if first.as_str() != offset.as_str() { - entry.close(); - seed.zeroize(); - self.alert = Some("offset passphrases do not match".into()); - self.screen = Screen::Main; - return Ok(()); - } - entry.close(); - let seed = std::mem::replace(seed, Zeroizing::new(String::new())); - self.screen = Screen::WalletSetup(WalletSetup::ImportPass { - seed, - offset, - entry: PassphraseEntry::new(), - }); - } else if offset.trim().is_empty() { - // Blank Enter skips the offset: no confirm, no RPC field. - entry.close(); - let seed = std::mem::replace(seed, Zeroizing::new(String::new())); - self.screen = Screen::WalletSetup(WalletSetup::ImportPass { - seed, - offset: Zeroizing::new(String::new()), - entry: PassphraseEntry::new(), - }); - } else { - self.screen = Screen::WalletSetup(WalletSetup::ImportOffset { - seed: std::mem::replace(seed, Zeroizing::new(String::new())), - entry: PassphraseEntry::with_first(offset.as_str()), - }); - } - } - _ => {} - }, - WalletSetup::ImportPass { - entry, - seed, - offset, - } => match key.code { + WalletSetup::ImportPass { entry, seed } => match key.code { KeyCode::Backspace => entry.backspace(), KeyCode::Char(c) if !key.modifiers.contains(KeyModifiers::CONTROL) => { entry.push(c); @@ -2578,37 +2496,17 @@ impl App { if first.as_str() != pass.as_str() { entry.close(); seed.zeroize(); - offset.zeroize(); self.alert = Some("passphrases do not match".into()); self.screen = Screen::Main; return Ok(()); } - // Empty or whitespace-only means "no offset", and the - // core then leaves the field out of the request. - let offset_arg = match offset.trim() { - "" => None, - other => Some(other), - }; - let used_offset = offset_arg.is_some(); - let result = self.rt.block_on(self.node.wallet_restore( - pass.as_str(), - seed.as_str(), - offset_arg, - )); + let result = self + .rt + .block_on(self.node.wallet_restore(pass.as_str(), seed.as_str())); seed.zeroize(); - offset.zeroize(); match result { Ok(_) => { self.status_note = Some("wallet imported".into()); - if used_offset { - // The offset is not saved anywhere: hold on - // the notice until the user types SEEN. - self.screen = - Screen::WalletSetup(WalletSetup::ImportOffsetSeen { - typed: String::new(), - }); - return Ok(()); - } return self.open_wallet(); } Err(e) => { @@ -2618,28 +2516,14 @@ impl App { } } else { let seed = std::mem::replace(seed, Zeroizing::new(String::new())); - let offset = std::mem::replace(offset, Zeroizing::new(String::new())); self.screen = Screen::WalletSetup(WalletSetup::ImportPass { seed, - offset, entry: PassphraseEntry::with_first(pass.as_str()), }); } } _ => {} }, - WalletSetup::ImportOffsetSeen { typed } => match key.code { - KeyCode::Char(c) if c.is_ascii_alphabetic() => { - typed.push(c); - if typed.eq_ignore_ascii_case("SEEN") { - return self.open_wallet(); - } - } - KeyCode::Backspace => { - typed.pop(); - } - _ => {} - }, WalletSetup::UnlockPass { filename, entry } => match key.code { KeyCode::Backspace => entry.backspace(), KeyCode::Char(c) if !key.modifiers.contains(KeyModifiers::CONTROL) => { @@ -3517,18 +3401,13 @@ match screen { "c create i import r qr w wallets s/x child 1 pruned 2 full 3 testnet Esc back ? help" } Screen::WalletSetup(WalletSetup::CreateWarn { .. }) => "type SPEND Esc cancel ? help", - Screen::WalletSetup(WalletSetup::CreatePass { .. } | WalletSetup::UnlockPass { .. }) => { + Screen::WalletSetup( + WalletSetup::CreatePass { .. } + | WalletSetup::ImportPass { .. } + | WalletSetup::UnlockPass { .. }, + ) => { "Enter submit Esc cancel ? help" } - Screen::WalletSetup(WalletSetup::ImportOffset { entry, .. }) => { - if entry.first().is_some() { - "Enter submit Esc cancel ? help" - } else { - "blank Enter skips Esc cancel ? help" - } - } - Screen::WalletSetup(WalletSetup::ImportPass { .. }) => "Enter submit Esc cancel ? help", - Screen::WalletSetup(WalletSetup::ImportOffsetSeen { .. }) => "type SEEN ? help", Screen::WalletSetup(WalletSetup::CreateSeed { .. }) => "type SEEN Esc cancel ? help", Screen::WalletSetup(WalletSetup::ImportSeed { .. }) => "paste seed Enter Esc ? help", Screen::WalletsSettings { .. } => wallets_settings_footer_hint(), @@ -5422,23 +5301,6 @@ fn draw_wallet_setup(f: &mut Frame, setup: &WalletSetup) { "passphrase for the imported wallet file\n\nEnter continues Esc cancels".into() }, ), - WalletSetup::ImportOffset { entry, .. } => ( - "seed offset passphrase", - if entry.first().is_some() { - "re-type offset passphrase\n\nEnter submits Esc cancels".into() - } else { - "optional. not the wallet file passphrase. blank Enter skips. a wrong offset \ - opens a different wallet and does not error.\n\nEnter continues Esc cancels" - .into() - }, - ), - WalletSetup::ImportOffsetSeen { typed } => ( - "offset not saved", - format!( - "this offset was not saved. write it down. a later seed backup is a different \ - 25 words that open this wallet without the offset. type SEEN\n{typed}" - ), - ), WalletSetup::UnlockPass { filename, .. } => ( "wallet passphrase", format!( @@ -5795,219 +5657,3 @@ mod wallet_store_tests { assert_eq!(app.status_note.as_deref(), Some("opened wallet fresh")); } } - -/// The optional seed-offset step sits between the pasted seed and the wallet-file -/// passphrase, and the notice it ends on is the only copy of a secret the app -/// deliberately does not keep. -#[cfg(test)] -mod wallet_offset_tests { - use super::*; - use crate::node::test_node_with_wallets; - - /// The wallet is off in this harness (`test_node_with_wallets` uses - /// `Wallet::disabled()`), so the RPC step is not reachable here: these tests - /// pin the screen transitions, the locked footer strings, and the fact that a - /// mismatch never reaches the node. The request bytes are `tests/wallet.rs`. - fn app(home: &std::path::Path) -> (App, tokio::runtime::Runtime) { - let rt = tokio::runtime::Runtime::new().expect("tokio runtime"); - let _guard = rt.enter(); - let node = test_node_with_wallets(home, &[]); - let app = App::new(node, rt.handle().clone()).expect("app"); - (app, rt) - } - - fn key(code: KeyCode) -> KeyEvent { - KeyEvent::new(code, KeyModifiers::NONE) - } - - fn type_str(app: &mut App, s: &str) { - for c in s.chars() { - app.handle_key(key(KeyCode::Char(c))).expect("typed key"); - } - } - - fn offset_screen(seed: &str) -> Screen { - Screen::WalletSetup(WalletSetup::ImportOffset { - seed: Zeroizing::new(seed.to_string()), - entry: PassphraseEntry::new(), - }) - } - - /// The seed step is untouched and leads to the offset, whose first prompt - /// advertises exactly the blank-Enter skip. - #[test] - fn the_seed_step_leads_to_the_offset_step() { - let dir = tempfile::tempdir().unwrap(); - let (mut app, _rt) = app(&dir.path().join("home")); - app.screen = Screen::WalletSetup(WalletSetup::ImportSeed { - buf: Zeroizing::new("lumber tacit lemon ivory risk".into()), - }); - assert_eq!(footer_hints(&app.screen), "paste seed Enter Esc ? help"); - - app.handle_key(key(KeyCode::Enter)).expect("enter"); - - assert!( - matches!( - app.screen, - Screen::WalletSetup(WalletSetup::ImportOffset { .. }) - ), - "the seed goes to the offset prompt, not straight to the passphrase" - ); - assert_eq!( - footer_hints(&app.screen), - "blank Enter skips Esc cancel ? help" - ); - } - - /// A blank (or whitespace-only) offset is skipped without a confirm, and the - /// passphrase step carries an empty offset — which means "no field" later. - #[test] - fn a_blank_offset_enter_skips_the_confirm() { - for blank in ["", " "] { - let dir = tempfile::tempdir().unwrap(); - let (mut app, _rt) = app(&dir.path().join("home")); - app.screen = offset_screen("lumber tacit lemon ivory risk"); - type_str(&mut app, blank); - - app.handle_key(key(KeyCode::Enter)).expect("enter"); - - let Screen::WalletSetup(WalletSetup::ImportPass { offset, entry, .. }) = &app.screen - else { - panic!("a blank offset must go straight to the file passphrase"); - }; - assert!(offset.is_empty(), "blank {blank:?} became {offset:?}"); - assert!( - entry.first().is_none(), - "a blank offset must not be confirmed" - ); - } - } - - /// A real offset is asked twice; the second prompt offers submit and Esc. - #[test] - fn a_non_empty_offset_is_confirmed() { - let dir = tempfile::tempdir().unwrap(); - let (mut app, _rt) = app(&dir.path().join("home")); - app.screen = offset_screen("lumber tacit lemon ivory risk"); - type_str(&mut app, "harbor-offset"); - - app.handle_key(key(KeyCode::Enter)).expect("enter"); - - let Screen::WalletSetup(WalletSetup::ImportOffset { entry, .. }) = &app.screen else { - panic!("a non-empty offset must be confirmed"); - }; - assert_eq!(entry.first(), Some("harbor-offset")); - assert_eq!( - footer_hints(&app.screen), - "Enter submit Esc cancel ? help" - ); - } - - /// A mismatch returns to the main view with the locked alert and never asks - /// the node for anything. - #[test] - fn a_mismatched_offset_never_reaches_the_node() { - let dir = tempfile::tempdir().unwrap(); - let (mut app, _rt) = app(&dir.path().join("home")); - app.screen = offset_screen("lumber tacit lemon ivory risk"); - type_str(&mut app, "harbor-offset"); - app.handle_key(key(KeyCode::Enter)).expect("enter"); - type_str(&mut app, "harbor-offse"); - - app.handle_key(key(KeyCode::Enter)).expect("enter"); - - assert!(matches!(app.screen, Screen::Main)); - assert_eq!( - app.alert.as_deref(), - Some("offset passphrases do not match") - ); - } - - /// The offset prompt does not echo what was typed, the same way the file - /// passphrase does not. - #[test] - fn the_offset_is_not_drawn() { - let mut entry = PassphraseEntry::new(); - for c in "harbor-offset".chars() { - entry.push(c); - } - let setup = WalletSetup::ImportOffset { - seed: Zeroizing::new("lumber tacit lemon ivory risk".to_string()), - entry, - }; - let mut term = ratatui::Terminal::new(ratatui::backend::TestBackend::new(80, 24)) - .expect("test terminal"); - term.draw(|f| draw_wallet_setup(f, &setup)).expect("draw"); - let frame = term.backend().buffer().clone(); - let mut drawn = String::new(); - for y in 0..frame.area.height { - for x in 0..frame.area.width { - drawn.push_str(frame[(x, y)].symbol()); - } - } - assert!( - !drawn.contains("harbor-offset"), - "the offset must never be drawn: {drawn}" - ); - assert!( - drawn.contains("seed offset passphrase"), - "the prompt itself is shown: {drawn}" - ); - } - - /// The notice is the one thing Esc cannot dismiss: the wallet file exists, - /// and neither the offset nor the pasted words are stored anywhere. - #[test] - fn esc_does_not_leave_the_offset_notice() { - let dir = tempfile::tempdir().unwrap(); - let (mut app, _rt) = app(&dir.path().join("home")); - app.screen = Screen::WalletSetup(WalletSetup::ImportOffsetSeen { - typed: String::new(), - }); - assert_eq!(footer_hints(&app.screen), "type SEEN ? help"); - - app.handle_key(key(KeyCode::Esc)).expect("esc"); - - assert!( - matches!( - app.screen, - Screen::WalletSetup(WalletSetup::ImportOffsetSeen { .. }) - ), - "Esc must not leave the offset notice" - ); - } - - /// Only `SEEN` (case-insensitively, like the create path) moves on, and it - /// moves on by opening the wallet. - #[test] - fn only_seen_leaves_the_offset_notice_for_the_wallet() { - let dir = tempfile::tempdir().unwrap(); - let (mut app, _rt) = app(&dir.path().join("home")); - app.screen = Screen::WalletSetup(WalletSetup::ImportOffsetSeen { - typed: String::new(), - }); - type_str(&mut app, "see"); - assert!( - matches!( - app.screen, - Screen::WalletSetup(WalletSetup::ImportOffsetSeen { .. }) - ), - "a prefix is not the word" - ); - - // The fourth letter is the one that proceeds: it opens the wallet, and - // this install has none, so the open is what fails. Nothing before the - // full word gets that far. - assert!( - app.status_note.is_none(), - "a prefix must not run any import side effect" - ); - let err = app - .handle_key(key(KeyCode::Char('n'))) - .expect_err("SEEN must attempt to open the wallet"); - assert!( - err.contains("receive address") || err.to_ascii_lowercase().contains("not configured"), - "expected the open to fail on the missing wallet, got {err}" - ); - } -} diff --git a/src/wallet.rs b/src/wallet.rs index a31990a..e40fca0 100644 --- a/src/wallet.rs +++ b/src/wallet.rs @@ -958,24 +958,7 @@ impl Wallet { /// Import an existing wallet from its 25-word seed. This is the only path /// that takes a user-supplied secret. - /// - /// `seed_offset` is Monero's optional seed-offset passphrase: a second spend - /// secret mixed into the seed at restore time, so the same words with a - /// different offset open a different wallet. It is **not** the wallet-file - /// `password`; it is never sealed, never stored and never written to an error - /// string, and the app cannot tell a "wrong" offset from a right one — the - /// RPC succeeds and the wallet is simply a different one. - /// - /// `None`, empty or whitespace-only leaves `seed_offset` out of the request - /// entirely (never `"seed_offset":""`). Otherwise the ends are trimmed and - /// the value is sent beside the seed; interior spaces are kept. - pub async fn restore_wallet( - &self, - filename: &str, - password: &str, - seed: &str, - seed_offset: Option<&str>, - ) -> Result<()> { + pub async fn restore_wallet(&self, filename: &str, password: &str, seed: &str) -> Result<()> { let filename = filename.trim(); if filename.is_empty() { return Err(Error("wallet filename required".into())); @@ -987,16 +970,16 @@ impl Wallet { if seed.is_empty() { return Err(Error("seed required to import a wallet".into())); } - let mut params = serde_json::json!({ - "filename": filename, - "password": password, - "seed": seed, - "language": "English" - }); - if let Some(offset) = seed_offset.map(str::trim).filter(|s| !s.is_empty()) { - params["seed_offset"] = serde_json::Value::String(offset.to_string()); - } - self.rpc("restore_deterministic_wallet", params).await?; + self.rpc( + "restore_deterministic_wallet", + serde_json::json!({ + "filename": filename, + "password": password, + "seed": seed, + "language": "English" + }), + ) + .await?; Ok(()) } diff --git a/tests/wallet.rs b/tests/wallet.rs index 1337439..de6f02e 100644 --- a/tests/wallet.rs +++ b/tests/wallet.rs @@ -618,7 +618,6 @@ fn create_wallet_empty_filename_or_password_is_local_error() { } /// Import is the only path that takes an existing secret (the 25-word seed). -/// An absent seed offset is not a field: the request must not carry one. #[tokio::test] async fn restore_wallet_sends_seed_to_restore_deterministic_wallet() { let listener = TcpListener::bind("127.0.0.1:0").await.unwrap(); @@ -635,12 +634,7 @@ async fn restore_wallet_sends_seed_to_restore_deterministic_wallet() { }), )); recording_wallet(port) - .restore_wallet( - "onionwire", - "hunter2", - "lumber tacit lemon ivory risk", - None, - ) + .restore_wallet("onionwire", "hunter2", "lumber tacit lemon ivory risk") .await .expect("restore_wallet"); let seen = log.lock().expect("log").clone(); @@ -652,148 +646,6 @@ async fn restore_wallet_sends_seed_to_restore_deterministic_wallet() { restore.contains("lumber tacit lemon ivory risk"), "seed missing: {restore}" ); - assert!( - !restore.contains("seed_offset"), - "an absent offset must not become a field: {restore}" - ); -} - -/// The seed offset is a second spend secret, sent beside the seed when present. -#[tokio::test] -async fn restore_wallet_sends_a_non_empty_seed_offset() { - let listener = TcpListener::bind("127.0.0.1:0").await.unwrap(); - let port = listener.local_addr().unwrap().port(); - let log = Arc::new(Mutex::new(Vec::new())); - tokio::spawn(serve_recording( - listener, - Arc::clone(&log), - Arc::new(|method| match method { - "restore_deterministic_wallet" => rpc_result( - r#"{"address":"4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA","seed":"lumber tacit lemon ivory risk"}"#, - ), - _ => rpc_error(-1, "unexpected method"), - }), - )); - recording_wallet(port) - .restore_wallet( - "onionwire", - "hunter2", - "lumber tacit lemon ivory risk", - Some("harbor-offset"), - ) - .await - .expect("restore_wallet"); - let seen = log.lock().expect("log").clone(); - let restore = seen - .iter() - .find(|r| r.contains(r#""method":"restore_deterministic_wallet""#)) - .expect("restore RPC"); - assert!( - restore.contains(r#""seed_offset":"harbor-offset""#), - "offset missing: {restore}" - ); - assert!( - restore.contains("lumber tacit lemon ivory risk"), - "seed missing: {restore}" - ); -} - -/// Blank or whitespace-only is the same as none: no `seed_offset` field at all, -/// never `"seed_offset":""`. -#[tokio::test] -async fn restore_wallet_omits_a_whitespace_only_seed_offset() { - let listener = TcpListener::bind("127.0.0.1:0").await.unwrap(); - let port = listener.local_addr().unwrap().port(); - let log = Arc::new(Mutex::new(Vec::new())); - tokio::spawn(serve_recording( - listener, - Arc::clone(&log), - Arc::new(|method| match method { - "restore_deterministic_wallet" => rpc_result( - r#"{"address":"4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA","seed":"lumber tacit lemon ivory risk"}"#, - ), - _ => rpc_error(-1, "unexpected method"), - }), - )); - recording_wallet(port) - .restore_wallet( - "onionwire", - "hunter2", - "lumber tacit lemon ivory risk", - Some(" "), - ) - .await - .expect("blank offset restore"); - let seen = log.lock().expect("log").clone(); - assert!( - seen.iter() - .filter(|r| r.contains(r#""method":"restore_deterministic_wallet""#)) - .all(|r| !r.contains("seed_offset")), - "a blank offset must not become a field: {seen:?}" - ); -} - -/// Only the ends trim: an offset with interior spaces is sent as typed. -#[tokio::test] -async fn restore_wallet_trims_the_ends_of_a_seed_offset() { - let listener = TcpListener::bind("127.0.0.1:0").await.unwrap(); - let port = listener.local_addr().unwrap().port(); - let log = Arc::new(Mutex::new(Vec::new())); - tokio::spawn(serve_recording( - listener, - Arc::clone(&log), - Arc::new(|method| match method { - "restore_deterministic_wallet" => rpc_result( - r#"{"address":"4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA","seed":"lumber tacit lemon ivory risk"}"#, - ), - _ => rpc_error(-1, "unexpected method"), - }), - )); - recording_wallet(port) - .restore_wallet( - "onionwire", - "hunter2", - "lumber tacit lemon ivory risk", - Some(" harbor offset "), - ) - .await - .expect("trimmed offset restore"); - let seen = log.lock().expect("log").clone(); - assert!( - seen.iter() - .any(|r| r.contains(r#""seed_offset":"harbor offset""#)), - "ends trim, interior spaces stay: {seen:?}" - ); -} - -/// The offset is a spend secret: an RPC refusal must not echo it back. -#[tokio::test] -async fn a_failed_restore_does_not_echo_the_seed_offset() { - let listener = TcpListener::bind("127.0.0.1:0").await.unwrap(); - let port = listener.local_addr().unwrap().port(); - tokio::spawn(serve_recording( - listener, - Arc::new(Mutex::new(Vec::new())), - Arc::new(|_method| rpc_error(-1, "restore refused")), - )); - let err = recording_wallet(port) - .restore_wallet( - "onionwire", - "hunter2", - "lumber tacit lemon ivory risk", - Some("harbor-offset"), - ) - .await - .unwrap_err() - .to_string(); - assert!( - !err.contains("harbor-offset"), - "offset leaked in the error string: {err}" - ); - assert!( - !err.contains("lumber tacit lemon ivory risk"), - "seed leaked in the error string: {err}" - ); } #[test] @@ -803,7 +655,7 @@ fn restore_wallet_empty_seed_is_local_error() { .enable_all() .build() .unwrap() - .block_on(w.restore_wallet("onionwire", "pw", " ", None)) + .block_on(w.restore_wallet("onionwire", "pw", " ")) .unwrap_err() .to_string(); assert!(err.to_ascii_lowercase().contains("seed"), "got {err}");