ensure keystore source and wallet model is always filled in

This commit is contained in:
Craig Raw 2020-04-29 15:44:18 +02:00
parent 728b6efbdf
commit ae03da257a
5 changed files with 36 additions and 3 deletions

2
drongo

@ -1 +1 @@
Subproject commit d740895bd68f0ded97e382e5944feb26fa759875 Subproject commit cbffaf3e416e0d94a01a9c00c99d9f2d61018d1e

View file

@ -9,6 +9,7 @@ import com.sparrowwallet.drongo.policy.Policy;
import com.sparrowwallet.drongo.policy.PolicyType; import com.sparrowwallet.drongo.policy.PolicyType;
import com.sparrowwallet.drongo.protocol.ScriptType; import com.sparrowwallet.drongo.protocol.ScriptType;
import com.sparrowwallet.drongo.wallet.Keystore; import com.sparrowwallet.drongo.wallet.Keystore;
import com.sparrowwallet.drongo.wallet.KeystoreSource;
import com.sparrowwallet.drongo.wallet.Wallet; import com.sparrowwallet.drongo.wallet.Wallet;
import com.sparrowwallet.drongo.wallet.WalletModel; import com.sparrowwallet.drongo.wallet.WalletModel;
import com.sparrowwallet.sparrow.storage.Storage; import com.sparrowwallet.sparrow.storage.Storage;
@ -42,6 +43,8 @@ public class ColdcardMultisig implements MultisigWalletImport, KeystoreFileImpor
ColdcardKeystore cck = Storage.getStorage().getGson().fromJson(reader, ColdcardKeystore.class); ColdcardKeystore cck = Storage.getStorage().getGson().fromJson(reader, ColdcardKeystore.class);
Keystore keystore = new Keystore("Coldcard " + cck.xfp); Keystore keystore = new Keystore("Coldcard " + cck.xfp);
keystore.setSource(KeystoreSource.HW_AIRGAPPED);
keystore.setWalletModel(WalletModel.COLDCARD);
if(scriptType.equals(ScriptType.P2SH)) { if(scriptType.equals(ScriptType.P2SH)) {
keystore.setKeyDerivation(new KeyDerivation(cck.xfp, cck.p2sh_deriv)); keystore.setKeyDerivation(new KeyDerivation(cck.xfp, cck.p2sh_deriv));
@ -113,6 +116,8 @@ public class ColdcardMultisig implements MultisigWalletImport, KeystoreFileImpor
default: default:
if (key.length() == 8 && Utils.isHex(key)) { if (key.length() == 8 && Utils.isHex(key)) {
Keystore keystore = new Keystore("Coldcard " + key); Keystore keystore = new Keystore("Coldcard " + key);
keystore.setSource(KeystoreSource.HW_AIRGAPPED);
keystore.setWalletModel(WalletModel.COLDCARD);
keystore.setKeyDerivation(new KeyDerivation(key, derivation)); keystore.setKeyDerivation(new KeyDerivation(key, derivation));
keystore.setExtendedPublicKey(ExtendedPublicKey.fromDescriptor(value)); keystore.setExtendedPublicKey(ExtendedPublicKey.fromDescriptor(value));
wallet.getKeystores().add(keystore); wallet.getKeystores().add(keystore);

View file

@ -8,6 +8,7 @@ import com.sparrowwallet.drongo.policy.Policy;
import com.sparrowwallet.drongo.policy.PolicyType; import com.sparrowwallet.drongo.policy.PolicyType;
import com.sparrowwallet.drongo.protocol.ScriptType; import com.sparrowwallet.drongo.protocol.ScriptType;
import com.sparrowwallet.drongo.wallet.Keystore; import com.sparrowwallet.drongo.wallet.Keystore;
import com.sparrowwallet.drongo.wallet.KeystoreSource;
import com.sparrowwallet.drongo.wallet.Wallet; import com.sparrowwallet.drongo.wallet.Wallet;
import com.sparrowwallet.drongo.wallet.WalletModel; import com.sparrowwallet.drongo.wallet.WalletModel;
@ -82,6 +83,8 @@ public class ColdcardSinglesig implements KeystoreFileImport, SinglesigWalletImp
if(!key.equals("m") && scriptType.getDefaultDerivationPath().startsWith(key)) { if(!key.equals("m") && scriptType.getDefaultDerivationPath().startsWith(key)) {
ExtendedPublicKey extPubKey = ExtendedPublicKey.fromDescriptor(value); ExtendedPublicKey extPubKey = ExtendedPublicKey.fromDescriptor(value);
Keystore keystore = new Keystore(); Keystore keystore = new Keystore();
keystore.setSource(KeystoreSource.HW_AIRGAPPED);
keystore.setWalletModel(WalletModel.COLDCARD);
keystore.setKeyDerivation(new KeyDerivation(masterFingerprint, key)); keystore.setKeyDerivation(new KeyDerivation(masterFingerprint, key));
keystore.setExtendedPublicKey(extPubKey); keystore.setExtendedPublicKey(extPubKey);
wallet.getKeystores().add(keystore); wallet.getKeystores().add(keystore);

View file

@ -9,6 +9,7 @@ import com.sparrowwallet.drongo.policy.Policy;
import com.sparrowwallet.drongo.policy.PolicyType; import com.sparrowwallet.drongo.policy.PolicyType;
import com.sparrowwallet.drongo.protocol.ScriptType; import com.sparrowwallet.drongo.protocol.ScriptType;
import com.sparrowwallet.drongo.wallet.Keystore; import com.sparrowwallet.drongo.wallet.Keystore;
import com.sparrowwallet.drongo.wallet.KeystoreSource;
import com.sparrowwallet.drongo.wallet.Wallet; import com.sparrowwallet.drongo.wallet.Wallet;
import com.sparrowwallet.drongo.wallet.WalletModel; import com.sparrowwallet.drongo.wallet.WalletModel;
@ -83,6 +84,20 @@ public class Electrum implements KeystoreFileImport, SinglesigWalletImport, Mult
for(ElectrumKeystore ek : ew.keystores.values()) { for(ElectrumKeystore ek : ew.keystores.values()) {
Keystore keystore = new Keystore(ek.label); Keystore keystore = new Keystore(ek.label);
if("hardware".equals(ek.type)) {
keystore.setSource(KeystoreSource.HW_USB);
keystore.setWalletModel(WalletModel.fromType(ek.hw_type));
if(keystore.getWalletModel() == null) {
throw new ImportException("Unknown hardware wallet type " + ek.hw_type);
}
} else if("bip32".equals(ek.type)) {
if(ek.xprv != null) {
keystore.setSource(KeystoreSource.SW_SEED);
} else {
keystore.setSource(KeystoreSource.SW_WATCH);
}
keystore.setWalletModel(WalletModel.ELECTRUM);
}
keystore.setKeyDerivation(new KeyDerivation(ek.root_fingerprint, ek.derivation)); keystore.setKeyDerivation(new KeyDerivation(ek.root_fingerprint, ek.derivation));
keystore.setExtendedPublicKey(ExtendedPublicKey.fromDescriptor(ek.xpub)); keystore.setExtendedPublicKey(ExtendedPublicKey.fromDescriptor(ek.xpub));
wallet.getKeystores().add(keystore); wallet.getKeystores().add(keystore);
@ -185,6 +200,7 @@ public class Electrum implements KeystoreFileImport, SinglesigWalletImport, Mult
public static class ElectrumKeystore { public static class ElectrumKeystore {
public String xpub; public String xpub;
public String xprv;
public String hw_type; public String hw_type;
public String ckcc_xfp; public String ckcc_xfp;
public String root_fingerprint; public String root_fingerprint;
@ -192,5 +208,6 @@ public class Electrum implements KeystoreFileImport, SinglesigWalletImport, Mult
public String soft_device_id; public String soft_device_id;
public String type; public String type;
public String derivation; public String derivation;
public String seed;
} }
} }

View file

@ -6,7 +6,9 @@ import com.sparrowwallet.drongo.policy.Policy;
import com.sparrowwallet.drongo.policy.PolicyType; import com.sparrowwallet.drongo.policy.PolicyType;
import com.sparrowwallet.drongo.protocol.ScriptType; import com.sparrowwallet.drongo.protocol.ScriptType;
import com.sparrowwallet.drongo.wallet.Keystore; import com.sparrowwallet.drongo.wallet.Keystore;
import com.sparrowwallet.drongo.wallet.KeystoreSource;
import com.sparrowwallet.drongo.wallet.Wallet; import com.sparrowwallet.drongo.wallet.Wallet;
import com.sparrowwallet.drongo.wallet.WalletModel;
import com.sparrowwallet.sparrow.AppController; import com.sparrowwallet.sparrow.AppController;
import com.sparrowwallet.sparrow.EventManager; import com.sparrowwallet.sparrow.EventManager;
import com.sparrowwallet.sparrow.control.CopyableLabel; import com.sparrowwallet.sparrow.control.CopyableLabel;
@ -120,7 +122,10 @@ public class SettingsController extends WalletFormController implements Initiali
while(walletForm.getWallet().getKeystores().stream().map(Keystore::getLabel).collect(Collectors.toList()).contains(name)) { while(walletForm.getWallet().getKeystores().stream().map(Keystore::getLabel).collect(Collectors.toList()).contains(name)) {
name = "Keystore " + (++keystoreNameCount); name = "Keystore " + (++keystoreNameCount);
} }
walletForm.getWallet().getKeystores().add(new Keystore(name)); Keystore keystore = new Keystore(name);
keystore.setSource(KeystoreSource.SW_WATCH);
keystore.setWalletModel(WalletModel.SPARROW);
walletForm.getWallet().getKeystores().add(keystore);
} }
walletForm.getWallet().setKeystores(walletForm.getWallet().getKeystores().subList(0, numCosigners.intValue())); walletForm.getWallet().setKeystores(walletForm.getWallet().getKeystores().subList(0, numCosigners.intValue()));
@ -170,7 +175,10 @@ public class SettingsController extends WalletFormController implements Initiali
if(wallet.getPolicyType() == null) { if(wallet.getPolicyType() == null) {
wallet.setPolicyType(PolicyType.SINGLE); wallet.setPolicyType(PolicyType.SINGLE);
wallet.setScriptType(ScriptType.P2WPKH); wallet.setScriptType(ScriptType.P2WPKH);
wallet.getKeystores().add(new Keystore("Keystore 1")); Keystore keystore = new Keystore("Keystore 1");
keystore.setSource(KeystoreSource.SW_WATCH);
keystore.setWalletModel(WalletModel.SPARROW);
wallet.getKeystores().add(keystore);
wallet.setDefaultPolicy(Policy.getPolicy(wallet.getPolicyType(), wallet.getScriptType(), wallet.getKeystores(), 1)); wallet.setDefaultPolicy(Policy.getPolicy(wallet.getPolicyType(), wallet.getScriptType(), wallet.getKeystores(), 1));
} }