From af525797ff57b9bbe37fcf987f380acc9c2e3385 Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Fri, 21 Aug 2020 09:59:11 +0200 Subject: [PATCH] improvements to importing and exporting --- .../control/TitledDescriptionPane.java | 2 +- .../com/sparrowwallet/sparrow/io/Bip39.java | 2 +- .../sparrow/io/ColdcardMultisig.java | 6 ++-- .../sparrow/io/ColdcardSinglesig.java | 2 +- .../sparrowwallet/sparrow/io/Electrum.java | 33 ++++++++++++------- 5 files changed, 28 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/sparrowwallet/sparrow/control/TitledDescriptionPane.java b/src/main/java/com/sparrowwallet/sparrow/control/TitledDescriptionPane.java index 25bba22d..f2aab341 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/TitledDescriptionPane.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/TitledDescriptionPane.java @@ -133,7 +133,7 @@ public class TitledDescriptionPane extends TitledPane { numLines += 1.0; } - double height = Math.max(60, numLines * 40); + double height = Math.max(60, numLines * 20); contentBox.setPrefHeight(height); return contentBox; diff --git a/src/main/java/com/sparrowwallet/sparrow/io/Bip39.java b/src/main/java/com/sparrowwallet/sparrow/io/Bip39.java index 3273fea0..cda0e7d5 100644 --- a/src/main/java/com/sparrowwallet/sparrow/io/Bip39.java +++ b/src/main/java/com/sparrowwallet/sparrow/io/Bip39.java @@ -21,7 +21,7 @@ public class Bip39 implements KeystoreMnemonicImport { @Override public String getKeystoreImportDescription() { - return "Import or generate your 12 to 24 word mnemonic and optional passphrase"; + return "Import or generate your 12 to 24 word mnemonic and optional passphrase."; } @Override diff --git a/src/main/java/com/sparrowwallet/sparrow/io/ColdcardMultisig.java b/src/main/java/com/sparrowwallet/sparrow/io/ColdcardMultisig.java index fe19d0a3..ede49697 100644 --- a/src/main/java/com/sparrowwallet/sparrow/io/ColdcardMultisig.java +++ b/src/main/java/com/sparrowwallet/sparrow/io/ColdcardMultisig.java @@ -68,7 +68,7 @@ public class ColdcardMultisig implements WalletImport, KeystoreFileImport, Walle @Override public String getKeystoreImportDescription() { - return "Import file created by using the Settings > Multisig Wallets > Export XPUB feature on your Coldcard"; + return "Import file created by using the Settings > Multisig Wallets > Export XPUB feature on your Coldcard."; } @Override @@ -143,7 +143,7 @@ public class ColdcardMultisig implements WalletImport, KeystoreFileImport, Walle @Override public String getWalletImportDescription() { - return "Import file created by using the Settings > Multisig Wallets > [Wallet Detail] > Coldcard Export feature on your Coldcard"; + return "Import file created by using the Settings > Multisig Wallets > [Wallet Detail] > Coldcard Export feature on your Coldcard."; } @Override @@ -196,7 +196,7 @@ public class ColdcardMultisig implements WalletImport, KeystoreFileImport, Walle @Override public String getWalletExportDescription() { - return "Export file that can be read by your Coldcard using the Settings > Multisig Wallets > Import from SD feature"; + return "Export file that can be read by your Coldcard using the Settings > Multisig Wallets > Import from SD feature."; } @Override diff --git a/src/main/java/com/sparrowwallet/sparrow/io/ColdcardSinglesig.java b/src/main/java/com/sparrowwallet/sparrow/io/ColdcardSinglesig.java index e7f0f092..f016b066 100644 --- a/src/main/java/com/sparrowwallet/sparrow/io/ColdcardSinglesig.java +++ b/src/main/java/com/sparrowwallet/sparrow/io/ColdcardSinglesig.java @@ -24,7 +24,7 @@ public class ColdcardSinglesig implements KeystoreFileImport { @Override public String getKeystoreImportDescription() { - return "Import file created by using the Advanced > MicroSD > Export Wallet > Generic JSON feature on your Coldcard"; + return "Import file created by using the Advanced > MicroSD > Export Wallet > Generic JSON feature on your Coldcard. Note this requires firmware version 3.1.3 or later."; } @Override diff --git a/src/main/java/com/sparrowwallet/sparrow/io/Electrum.java b/src/main/java/com/sparrowwallet/sparrow/io/Electrum.java index 2a15fd70..6a6e675e 100644 --- a/src/main/java/com/sparrowwallet/sparrow/io/Electrum.java +++ b/src/main/java/com/sparrowwallet/sparrow/io/Electrum.java @@ -14,10 +14,7 @@ import com.sparrowwallet.drongo.wallet.*; import java.io.*; import java.lang.reflect.Type; import java.nio.charset.StandardCharsets; -import java.util.Arrays; -import java.util.Base64; -import java.util.LinkedHashMap; -import java.util.Map; +import java.util.*; import java.util.zip.InflaterInputStream; public class Electrum implements KeystoreFileImport, WalletImport, WalletExport { @@ -33,7 +30,7 @@ public class Electrum implements KeystoreFileImport, WalletImport, WalletExport @Override public String getKeystoreImportDescription() { - return "Import a single keystore from an Electrum wallet (use File > Import > Electrum to import a multisig wallet)"; + return "Import a single keystore from an Electrum wallet (use File > Import > Electrum to import a multisig wallet)."; } @Override @@ -46,7 +43,7 @@ public class Electrum implements KeystoreFileImport, WalletImport, WalletExport if(!wallet.getScriptType().equals(scriptType)) { //TODO: Derive appropriate ScriptType keystore from xprv if present - throw new ImportException("Wallet has an incompatible script type of " + wallet.getScriptType() + ", and the correct script type cannot be derived without the master private key"); + throw new ImportException("Wallet has an incompatible script type of " + wallet.getScriptType() + ", and the correct script type cannot be derived without the master private key."); } return wallet.getKeystores().get(0); @@ -105,11 +102,12 @@ public class Electrum implements KeystoreFileImport, WalletImport, WalletExport keystore.setSource(KeystoreSource.HW_USB); keystore.setWalletModel(WalletModel.fromType(ek.hw_type)); if(keystore.getWalletModel() == null) { - throw new ImportException("Wallet has keystore of unknown hardware wallet type \"" + ek.hw_type + "\""); + throw new ImportException("Wallet has keystore of unknown hardware wallet type \"" + ek.hw_type + "\"."); } } else if("bip32".equals(ek.type)) { if(ek.xprv != null && ek.seed == null) { - throw new ImportException("Electrum does not support exporting BIP39 derived seeds."); + throw new ImportException("Electrum does not support exporting BIP39 derived seeds, as it does not store the mnemonic words. Only seeds created with its native Electrum Seed Version System are exportable. " + + "If you have the mnemonic words, create a new wallet with a BIP39 keystore."); } else if(ek.seed != null) { keystore.setSource(KeystoreSource.SW_SEED); String mnemonic = ek.seed; @@ -181,7 +179,7 @@ public class Electrum implements KeystoreFileImport, WalletImport, WalletExport @Override public String getWalletImportDescription() { - return "Import an Electrum wallet"; + return "Import an Electrum wallet."; } @Override @@ -268,12 +266,25 @@ public class Electrum implements KeystoreFileImport, WalletImport, WalletExport @Override public boolean isEncrypted(File file) { - return FileType.BINARY.equals(IOUtils.getFileType(file)); + if(FileType.BINARY.equals(IOUtils.getFileType(file))) { + try { + try(Scanner s = new Scanner(file)) { + if(s.hasNextLine() && s.nextLine().equals("{")) { + return false; + } + } + return true; + } catch(FileNotFoundException e) { + //Can't happen + } + } + + return false; } @Override public String getWalletExportDescription() { - return "Export this wallet as an Electrum wallet file"; + return "Export this wallet as an Electrum wallet file."; } private static class ElectrumJsonWallet {