improvements to importing and exporting

This commit is contained in:
Craig Raw 2020-08-21 09:59:11 +02:00
parent e9e10de266
commit af525797ff
5 changed files with 28 additions and 17 deletions

View file

@ -133,7 +133,7 @@ public class TitledDescriptionPane extends TitledPane {
numLines += 1.0; numLines += 1.0;
} }
double height = Math.max(60, numLines * 40); double height = Math.max(60, numLines * 20);
contentBox.setPrefHeight(height); contentBox.setPrefHeight(height);
return contentBox; return contentBox;

View file

@ -21,7 +21,7 @@ public class Bip39 implements KeystoreMnemonicImport {
@Override @Override
public String getKeystoreImportDescription() { 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 @Override

View file

@ -68,7 +68,7 @@ public class ColdcardMultisig implements WalletImport, KeystoreFileImport, Walle
@Override @Override
public String getKeystoreImportDescription() { 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 @Override
@ -143,7 +143,7 @@ public class ColdcardMultisig implements WalletImport, KeystoreFileImport, Walle
@Override @Override
public String getWalletImportDescription() { 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 @Override
@ -196,7 +196,7 @@ public class ColdcardMultisig implements WalletImport, KeystoreFileImport, Walle
@Override @Override
public String getWalletExportDescription() { 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 @Override

View file

@ -24,7 +24,7 @@ public class ColdcardSinglesig implements KeystoreFileImport {
@Override @Override
public String getKeystoreImportDescription() { 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 @Override

View file

@ -14,10 +14,7 @@ import com.sparrowwallet.drongo.wallet.*;
import java.io.*; import java.io.*;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.Arrays; import java.util.*;
import java.util.Base64;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.zip.InflaterInputStream; import java.util.zip.InflaterInputStream;
public class Electrum implements KeystoreFileImport, WalletImport, WalletExport { public class Electrum implements KeystoreFileImport, WalletImport, WalletExport {
@ -33,7 +30,7 @@ public class Electrum implements KeystoreFileImport, WalletImport, WalletExport
@Override @Override
public String getKeystoreImportDescription() { 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 @Override
@ -46,7 +43,7 @@ public class Electrum implements KeystoreFileImport, WalletImport, WalletExport
if(!wallet.getScriptType().equals(scriptType)) { if(!wallet.getScriptType().equals(scriptType)) {
//TODO: Derive appropriate ScriptType keystore from xprv if present //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); return wallet.getKeystores().get(0);
@ -105,11 +102,12 @@ public class Electrum implements KeystoreFileImport, WalletImport, WalletExport
keystore.setSource(KeystoreSource.HW_USB); keystore.setSource(KeystoreSource.HW_USB);
keystore.setWalletModel(WalletModel.fromType(ek.hw_type)); keystore.setWalletModel(WalletModel.fromType(ek.hw_type));
if(keystore.getWalletModel() == null) { 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)) { } else if("bip32".equals(ek.type)) {
if(ek.xprv != null && ek.seed == null) { 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) { } else if(ek.seed != null) {
keystore.setSource(KeystoreSource.SW_SEED); keystore.setSource(KeystoreSource.SW_SEED);
String mnemonic = ek.seed; String mnemonic = ek.seed;
@ -181,7 +179,7 @@ public class Electrum implements KeystoreFileImport, WalletImport, WalletExport
@Override @Override
public String getWalletImportDescription() { public String getWalletImportDescription() {
return "Import an Electrum wallet"; return "Import an Electrum wallet.";
} }
@Override @Override
@ -268,12 +266,25 @@ public class Electrum implements KeystoreFileImport, WalletImport, WalletExport
@Override @Override
public boolean isEncrypted(File file) { 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 @Override
public String getWalletExportDescription() { 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 { private static class ElectrumJsonWallet {