From b9d6cb17d476ea2e6e804b0244d84a0849615b4f Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Wed, 6 Oct 2021 08:23:08 +0200 Subject: [PATCH] indicate when entered seed is of unsupported electrum type --- drongo | 2 +- .../sparrowwallet/sparrow/control/DateLabel.java | 4 ++++ .../control/MnemonicKeystoreImportPane.java | 8 +++++++- .../java/com/sparrowwallet/sparrow/io/Bip39.java | 14 ++++++++++---- 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/drongo b/drongo index e0302cef..2fd7e8e7 160000 --- a/drongo +++ b/drongo @@ -1 +1 @@ -Subproject commit e0302cef22a3dd9401f9070318fec5ea15543bd7 +Subproject commit 2fd7e8e7e417212c7b6555a463f25004650d3a01 diff --git a/src/main/java/com/sparrowwallet/sparrow/control/DateLabel.java b/src/main/java/com/sparrowwallet/sparrow/control/DateLabel.java index d0619b70..629bf999 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/DateLabel.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/DateLabel.java @@ -17,6 +17,10 @@ public class DateLabel extends CopyableLabel { } public static String getShortDateFormat(Date date) { + if(date == null) { + return "Unknown"; + } + Date now = new Date(); long elapsed = (now.getTime() - date.getTime()) / 1000; diff --git a/src/main/java/com/sparrowwallet/sparrow/control/MnemonicKeystoreImportPane.java b/src/main/java/com/sparrowwallet/sparrow/control/MnemonicKeystoreImportPane.java index c2710b8e..ff13c7ad 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/MnemonicKeystoreImportPane.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/MnemonicKeystoreImportPane.java @@ -262,7 +262,13 @@ public class MnemonicKeystoreImportPane extends TitledDescriptionPane { importer.getKeystore(wallet.getScriptType().getDefaultDerivation(), wordEntriesProperty.get(), passphraseProperty.get()); validChecksum = true; } catch(ImportException e) { - //ignore + if(e.getCause() instanceof MnemonicException.MnemonicTypeException) { + invalidLabel.setText("Unsupported Electrum seed"); + invalidLabel.setTooltip(new Tooltip("Seeds created in Electrum do not follow the BIP39 standard. Import the Electrum wallet file directly.")); + } else { + invalidLabel.setText("Invalid checksum"); + invalidLabel.setTooltip(null); + } } } diff --git a/src/main/java/com/sparrowwallet/sparrow/io/Bip39.java b/src/main/java/com/sparrowwallet/sparrow/io/Bip39.java index cda0e7d5..e8b43f2c 100644 --- a/src/main/java/com/sparrowwallet/sparrow/io/Bip39.java +++ b/src/main/java/com/sparrowwallet/sparrow/io/Bip39.java @@ -1,10 +1,7 @@ package com.sparrowwallet.sparrow.io; import com.sparrowwallet.drongo.crypto.ChildNumber; -import com.sparrowwallet.drongo.wallet.Bip39MnemonicCode; -import com.sparrowwallet.drongo.wallet.DeterministicSeed; -import com.sparrowwallet.drongo.wallet.Keystore; -import com.sparrowwallet.drongo.wallet.WalletModel; +import com.sparrowwallet.drongo.wallet.*; import java.util.List; @@ -31,6 +28,15 @@ public class Bip39 implements KeystoreMnemonicImport { DeterministicSeed seed = new DeterministicSeed(mnemonicWords, passphrase, System.currentTimeMillis(), DeterministicSeed.Type.BIP39); return Keystore.fromSeed(seed, derivation); } catch (Exception e) { + try { + ElectrumMnemonicCode.INSTANCE.check(mnemonicWords); + throw new ImportException(new MnemonicException.MnemonicTypeException(DeterministicSeed.Type.ELECTRUM)); + } catch(Exception ex) { + if(ex instanceof ImportException && ex.getCause() instanceof MnemonicException.MnemonicTypeException) { + throw (ImportException)ex; + } + } + throw new ImportException(e); } }