diff --git a/mutiny-wasm/src/indexed_db.rs b/mutiny-wasm/src/indexed_db.rs index 5ab597602..cc0732b57 100644 --- a/mutiny-wasm/src/indexed_db.rs +++ b/mutiny-wasm/src/indexed_db.rs @@ -114,7 +114,7 @@ impl IndexedDbStorage { // if we hae an override mnemonic, then we need to check that it matches the one in indexed db if override_mnemonic.is_some_and(|m| m != seed) { - panic!("Mnemonic already exists in indexed db, cannot override"); + return Err(MutinyError::InvalidMnemonic); } seed diff --git a/mutiny-wasm/src/lib.rs b/mutiny-wasm/src/lib.rs index 504ace2b9..e557fc9cd 100644 --- a/mutiny-wasm/src/lib.rs +++ b/mutiny-wasm/src/lib.rs @@ -163,8 +163,7 @@ impl MutinyWallet { let mnemonic = IndexedDbStorage::get_mnemonic(override_mnemonic, password.as_deref(), cipher.clone()) - .await - .map_err(|_| MutinyJsError::IncorrectPassword)?; + .await?; let seed = mnemonic.to_seed(""); let xprivkey = ExtendedPrivKey::new_master(network, &seed).unwrap(); @@ -1601,6 +1600,61 @@ mod tests { uninit().await; } + #[test] + async fn fail_to_create_wallet_different_seed() { + MutinyWallet::new( + None, + None, + None, + Some("regtest".to_owned()), + None, + None, + None, + None, + None, + None, + None, + None, + None, + None, + ) + .await + .expect("mutiny wallet should initialize"); + super::utils::sleep(1_000).await; + assert!(MutinyWallet::has_node_manager(None).await); + uninit().await; + + let seed = mutiny_core::generate_seed(12).unwrap(); + let result = MutinyWallet::new( + None, + Some(seed.to_string()), + None, + Some("regtest".to_owned()), + None, + None, + None, + None, + None, + None, + None, + None, + None, + None, + ) + .await; + + match result { + Err(MutinyJsError::InvalidMnemonic) => {} + Err(e) => panic!("should have failed to create wallet with different seed {e:?}"), + Ok(_) => panic!("should have failed to create wallet with different seed"), + } + + IndexedDbStorage::clear() + .await + .expect("failed to clear storage"); + uninit().await; + } + #[test] async fn fail_to_create_2_mutiny_wallets() { log!("trying to create 2 mutiny wallets!");