wallet: optional seed-offset passphrase on import #156
9 changed files with 623 additions and 34 deletions
|
|
@ -322,7 +322,10 @@ 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.
|
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
|
`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.
|
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).
|
||||||
Type `SPEND` then `SEEN` on create. Each wallet gets its own file name
|
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`.
|
(`onionwire-1`, `onionwire-2`, …); the RPC must be started with `--wallet-dir`.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -764,9 +764,43 @@ impl Wire {
|
||||||
/// Import a wallet from an existing 25-word seed. This is the only path
|
/// 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
|
/// that takes a user-supplied secret. Like a create, the core records the
|
||||||
/// imported wallet in its catalogue.
|
/// 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<()> {
|
pub async fn import_wallet(&self, password: String, seed: String) -> WResult<()> {
|
||||||
self.node()?
|
self.node()?
|
||||||
.wallet_restore(&password, &seed)
|
.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)
|
||||||
.await
|
.await
|
||||||
.map_err(WireError::new)
|
.map_err(WireError::new)
|
||||||
.map(|_| ())
|
.map(|_| ())
|
||||||
|
|
|
||||||
|
|
@ -193,6 +193,19 @@ 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
|
over `.onion` — a remote wallet RPC would move spend authority off the box
|
||||||
through a channel the messenger’s `--password` gate does not cover.
|
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
|
### Chain source is the user’s choice
|
||||||
|
|
||||||
Scan, receipt verification, and spend need a Monero daemon. The user picks one;
|
Scan, receipt verification, and spend need a Monero daemon. The user picks one;
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ ASCII chrome.
|
||||||
| `ConfirmKeys` / `Passphrase` | `/backup`, `/restore` | Type `BACKUP`/`RESTORE`, then passphrase |
|
| `ConfirmKeys` / `Passphrase` | `/backup`, `/restore` | Type `BACKUP`/`RESTORE`, then passphrase |
|
||||||
| `Wallet` | `F6` | Receive QR, balance, transfers, child, chain source |
|
| `Wallet` | `F6` | Receive QR, balance, transfers, child, chain source |
|
||||||
| `WalletSelect` | `F6` `w` | Saved wallets, pick one or create one |
|
| `WalletSelect` | `F6` `w` | Saved wallets, pick one or create one |
|
||||||
| `WalletSetup` | `F6` `c` / `i`, or `/wallet create` / `import` | Spend warning, seed, import |
|
| `WalletSetup` | `F6` `c` / `i`, or `/wallet create` / `import` | Spend warning, seed, optional seed-offset passphrase, import |
|
||||||
| `WalletsSettings` | `F9` or `/settings` | Discovery menu (does not replace F-keys) |
|
| `WalletsSettings` | `F9` or `/settings` | Discovery menu (does not replace F-keys) |
|
||||||
| `PeerPayments` | F9 then `p` | Peer-scoped `/pay` / `/tip` history |
|
| `PeerPayments` | F9 then `p` | Peer-scoped `/pay` / `/tip` history |
|
||||||
| `Quit` | `Ctrl-Q` | Type `CLEAR` or `QUIT` |
|
| `Quit` | `Ctrl-Q` | Type `CLEAR` or `QUIT` |
|
||||||
|
|
|
||||||
|
|
@ -279,7 +279,15 @@ are displayable on demand".
|
||||||
reopens on the next start without asking for it again.
|
reopens on the next start without asking for it again.
|
||||||
|
|
||||||
`/wallet import` (`F6` then `i`) → `restore_deterministic_wallet` from a
|
`/wallet import` (`F6` then `i`) → `restore_deterministic_wallet` from a
|
||||||
25-word seed. Do not put the seed on the composer.
|
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.
|
||||||
|
|
||||||
RPC must be started with `--wallet-dir` (not only `--wallet-file`). A created
|
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`
|
wallet gets its own file name (`onionwire-1`, `onionwire-2`, …): `wallet_filename`
|
||||||
|
|
|
||||||
18
src/node.rs
18
src/node.rs
|
|
@ -1473,13 +1473,25 @@ impl Node {
|
||||||
/// Import a wallet from an existing 25-word seed. This is the only path
|
/// 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
|
/// that takes a user-supplied secret — and, like a create, it is remembered
|
||||||
/// in the catalogue under its own file name.
|
/// in the catalogue under its own file name.
|
||||||
pub async fn wallet_restore(&self, password: &str, seed: &str) -> Result<WalletRecord, String> {
|
///
|
||||||
|
/// `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<WalletRecord, String> {
|
||||||
let w = self.wallet_snapshot();
|
let w = self.wallet_snapshot();
|
||||||
if !w.configured() {
|
if !w.configured() {
|
||||||
return Err(wallet::NOT_CONFIGURED_MSG.into());
|
return Err(wallet::NOT_CONFIGURED_MSG.into());
|
||||||
}
|
}
|
||||||
let filename = self.next_wallet_filename()?;
|
let filename = self.next_wallet_filename()?;
|
||||||
w.restore_wallet(&filename, password, seed)
|
w.restore_wallet(&filename, password, seed, seed_offset)
|
||||||
.await
|
.await
|
||||||
.map_err(|e| e.to_string())?;
|
.map_err(|e| e.to_string())?;
|
||||||
let record = self
|
let record = self
|
||||||
|
|
@ -3700,7 +3712,7 @@ pub(crate) mod tests {
|
||||||
);
|
);
|
||||||
|
|
||||||
let imported = node
|
let imported = node
|
||||||
.wallet_restore("hunter2", "lumber tacit lemon ivory risk")
|
.wallet_restore("hunter2", "lumber tacit lemon ivory risk", None)
|
||||||
.await
|
.await
|
||||||
.expect("restore wallet");
|
.expect("restore wallet");
|
||||||
|
|
||||||
|
|
|
||||||
382
src/tui.rs
382
src/tui.rs
|
|
@ -1306,7 +1306,29 @@ enum WalletSetup {
|
||||||
CreatePass { entry: PassphraseEntry },
|
CreatePass { entry: PassphraseEntry },
|
||||||
CreateSeed { seed: Zeroizing<String>, typed: String },
|
CreateSeed { seed: Zeroizing<String>, typed: String },
|
||||||
ImportSeed { buf: Zeroizing<String> },
|
ImportSeed { buf: Zeroizing<String> },
|
||||||
ImportPass { seed: Zeroizing<String>, entry: PassphraseEntry },
|
/// 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<String>,
|
||||||
|
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<String>,
|
||||||
|
offset: Zeroizing<String>,
|
||||||
|
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,
|
||||||
|
},
|
||||||
/// The wallet file the child is pointed at is not open because this install
|
/// 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
|
/// has no passphrase for it. Same prompt idiom as the create path: one
|
||||||
/// hidden entry, `Enter` submits, `Esc` cancels, and the buffer is zeroized
|
/// hidden entry, `Enter` submits, `Esc` cancels, and the buffer is zeroized
|
||||||
|
|
@ -2387,11 +2409,26 @@ impl App {
|
||||||
};
|
};
|
||||||
if key.code == KeyCode::Esc {
|
if key.code == KeyCode::Esc {
|
||||||
match setup {
|
match setup {
|
||||||
WalletSetup::CreatePass { entry }
|
// The wallet file already exists at this point, and the offset
|
||||||
| WalletSetup::ImportPass { entry, .. }
|
// is not saved anywhere: Esc must not silently drop the one
|
||||||
| WalletSetup::UnlockPass { entry, .. } => {
|
// notice that says so. Only `SEEN` leaves this screen.
|
||||||
|
WalletSetup::ImportOffsetSeen { .. } => return Ok(()),
|
||||||
|
WalletSetup::CreatePass { entry } | WalletSetup::UnlockPass { entry, .. } => {
|
||||||
entry.close();
|
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::CreateSeed { seed, .. } => seed.zeroize(),
|
||||||
WalletSetup::ImportSeed { buf } => buf.zeroize(),
|
WalletSetup::ImportSeed { buf } => buf.zeroize(),
|
||||||
WalletSetup::CreateWarn { .. } => {}
|
WalletSetup::CreateWarn { .. } => {}
|
||||||
|
|
@ -2477,14 +2514,59 @@ impl App {
|
||||||
self.screen = Screen::Main;
|
self.screen = Screen::Main;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
self.screen = Screen::WalletSetup(WalletSetup::ImportPass {
|
self.screen = Screen::WalletSetup(WalletSetup::ImportOffset {
|
||||||
seed,
|
seed,
|
||||||
entry: PassphraseEntry::new(),
|
entry: PassphraseEntry::new(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
},
|
},
|
||||||
WalletSetup::ImportPass { entry, seed } => match key.code {
|
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 {
|
||||||
KeyCode::Backspace => entry.backspace(),
|
KeyCode::Backspace => entry.backspace(),
|
||||||
KeyCode::Char(c) if !key.modifiers.contains(KeyModifiers::CONTROL) => {
|
KeyCode::Char(c) if !key.modifiers.contains(KeyModifiers::CONTROL) => {
|
||||||
entry.push(c);
|
entry.push(c);
|
||||||
|
|
@ -2496,17 +2578,37 @@ impl App {
|
||||||
if first.as_str() != pass.as_str() {
|
if first.as_str() != pass.as_str() {
|
||||||
entry.close();
|
entry.close();
|
||||||
seed.zeroize();
|
seed.zeroize();
|
||||||
|
offset.zeroize();
|
||||||
self.alert = Some("passphrases do not match".into());
|
self.alert = Some("passphrases do not match".into());
|
||||||
self.screen = Screen::Main;
|
self.screen = Screen::Main;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
let result = self
|
// Empty or whitespace-only means "no offset", and the
|
||||||
.rt
|
// core then leaves the field out of the request.
|
||||||
.block_on(self.node.wallet_restore(pass.as_str(), seed.as_str()));
|
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,
|
||||||
|
));
|
||||||
seed.zeroize();
|
seed.zeroize();
|
||||||
|
offset.zeroize();
|
||||||
match result {
|
match result {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
self.status_note = Some("wallet imported".into());
|
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();
|
return self.open_wallet();
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
|
|
@ -2516,14 +2618,28 @@ impl App {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let seed = std::mem::replace(seed, Zeroizing::new(String::new()));
|
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 {
|
self.screen = Screen::WalletSetup(WalletSetup::ImportPass {
|
||||||
seed,
|
seed,
|
||||||
|
offset,
|
||||||
entry: PassphraseEntry::with_first(pass.as_str()),
|
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 {
|
WalletSetup::UnlockPass { filename, entry } => match key.code {
|
||||||
KeyCode::Backspace => entry.backspace(),
|
KeyCode::Backspace => entry.backspace(),
|
||||||
KeyCode::Char(c) if !key.modifiers.contains(KeyModifiers::CONTROL) => {
|
KeyCode::Char(c) if !key.modifiers.contains(KeyModifiers::CONTROL) => {
|
||||||
|
|
@ -3401,13 +3517,18 @@ match screen {
|
||||||
"c create i import r qr w wallets s/x child 1 pruned 2 full 3 testnet Esc back ? help"
|
"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::CreateWarn { .. }) => "type SPEND Esc cancel ? help",
|
||||||
Screen::WalletSetup(
|
Screen::WalletSetup(WalletSetup::CreatePass { .. } | WalletSetup::UnlockPass { .. }) => {
|
||||||
WalletSetup::CreatePass { .. }
|
|
||||||
| WalletSetup::ImportPass { .. }
|
|
||||||
| WalletSetup::UnlockPass { .. },
|
|
||||||
) => {
|
|
||||||
"Enter submit Esc cancel ? help"
|
"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::CreateSeed { .. }) => "type SEEN Esc cancel ? help",
|
||||||
Screen::WalletSetup(WalletSetup::ImportSeed { .. }) => "paste seed Enter Esc ? help",
|
Screen::WalletSetup(WalletSetup::ImportSeed { .. }) => "paste seed Enter Esc ? help",
|
||||||
Screen::WalletsSettings { .. } => wallets_settings_footer_hint(),
|
Screen::WalletsSettings { .. } => wallets_settings_footer_hint(),
|
||||||
|
|
@ -5301,6 +5422,23 @@ fn draw_wallet_setup(f: &mut Frame, setup: &WalletSetup) {
|
||||||
"passphrase for the imported wallet file\n\nEnter continues Esc cancels".into()
|
"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, .. } => (
|
WalletSetup::UnlockPass { filename, .. } => (
|
||||||
"wallet passphrase",
|
"wallet passphrase",
|
||||||
format!(
|
format!(
|
||||||
|
|
@ -5657,3 +5795,219 @@ mod wallet_store_tests {
|
||||||
assert_eq!(app.status_note.as_deref(), Some("opened wallet fresh"));
|
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}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -958,7 +958,24 @@ impl Wallet {
|
||||||
|
|
||||||
/// Import an existing wallet from its 25-word seed. This is the only path
|
/// Import an existing wallet from its 25-word seed. This is the only path
|
||||||
/// that takes a user-supplied secret.
|
/// that takes a user-supplied secret.
|
||||||
pub async fn restore_wallet(&self, filename: &str, password: &str, seed: &str) -> Result<()> {
|
///
|
||||||
|
/// `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<()> {
|
||||||
let filename = filename.trim();
|
let filename = filename.trim();
|
||||||
if filename.is_empty() {
|
if filename.is_empty() {
|
||||||
return Err(Error("wallet filename required".into()));
|
return Err(Error("wallet filename required".into()));
|
||||||
|
|
@ -970,16 +987,16 @@ impl Wallet {
|
||||||
if seed.is_empty() {
|
if seed.is_empty() {
|
||||||
return Err(Error("seed required to import a wallet".into()));
|
return Err(Error("seed required to import a wallet".into()));
|
||||||
}
|
}
|
||||||
self.rpc(
|
let mut params = serde_json::json!({
|
||||||
"restore_deterministic_wallet",
|
"filename": filename,
|
||||||
serde_json::json!({
|
"password": password,
|
||||||
"filename": filename,
|
"seed": seed,
|
||||||
"password": password,
|
"language": "English"
|
||||||
"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());
|
||||||
)
|
}
|
||||||
.await?;
|
self.rpc("restore_deterministic_wallet", params).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
152
tests/wallet.rs
152
tests/wallet.rs
|
|
@ -618,6 +618,7 @@ fn create_wallet_empty_filename_or_password_is_local_error() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Import is the only path that takes an existing secret (the 25-word seed).
|
/// 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]
|
#[tokio::test]
|
||||||
async fn restore_wallet_sends_seed_to_restore_deterministic_wallet() {
|
async fn restore_wallet_sends_seed_to_restore_deterministic_wallet() {
|
||||||
let listener = TcpListener::bind("127.0.0.1:0").await.unwrap();
|
let listener = TcpListener::bind("127.0.0.1:0").await.unwrap();
|
||||||
|
|
@ -634,7 +635,12 @@ async fn restore_wallet_sends_seed_to_restore_deterministic_wallet() {
|
||||||
}),
|
}),
|
||||||
));
|
));
|
||||||
recording_wallet(port)
|
recording_wallet(port)
|
||||||
.restore_wallet("onionwire", "hunter2", "lumber tacit lemon ivory risk")
|
.restore_wallet(
|
||||||
|
"onionwire",
|
||||||
|
"hunter2",
|
||||||
|
"lumber tacit lemon ivory risk",
|
||||||
|
None,
|
||||||
|
)
|
||||||
.await
|
.await
|
||||||
.expect("restore_wallet");
|
.expect("restore_wallet");
|
||||||
let seen = log.lock().expect("log").clone();
|
let seen = log.lock().expect("log").clone();
|
||||||
|
|
@ -646,6 +652,148 @@ async fn restore_wallet_sends_seed_to_restore_deterministic_wallet() {
|
||||||
restore.contains("lumber tacit lemon ivory risk"),
|
restore.contains("lumber tacit lemon ivory risk"),
|
||||||
"seed missing: {restore}"
|
"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]
|
#[test]
|
||||||
|
|
@ -655,7 +803,7 @@ fn restore_wallet_empty_seed_is_local_error() {
|
||||||
.enable_all()
|
.enable_all()
|
||||||
.build()
|
.build()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.block_on(w.restore_wallet("onionwire", "pw", " "))
|
.block_on(w.restore_wallet("onionwire", "pw", " ", None))
|
||||||
.unwrap_err()
|
.unwrap_err()
|
||||||
.to_string();
|
.to_string();
|
||||||
assert!(err.to_ascii_lowercase().contains("seed"), "got {err}");
|
assert!(err.to_ascii_lowercase().contains("seed"), "got {err}");
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue