test various possible derivation paths when electrum seed is provided

This commit is contained in:
Craig Raw 2021-02-25 11:54:47 +02:00
parent 27f4b3b3ae
commit 47fc0e11eb

View file

@ -161,8 +161,18 @@ public class Electrum implements KeystoreFileImport, WalletImport, WalletExport
} }
keystore.setSeed(new DeterministicSeed(mnemonic, passphrase, 0, DeterministicSeed.Type.ELECTRUM)); keystore.setSeed(new DeterministicSeed(mnemonic, passphrase, 0, DeterministicSeed.Type.ELECTRUM));
if(derivationPath.equals("m/0")) {
derivationPath = "m/0'"; //Ensure the derivation path from the seed matches the provided xpub
String[] possibleDerivations = {"m", "m/0", "m/0'"};
for(String possibleDerivation : possibleDerivations) {
List<ChildNumber> derivation = KeyDerivation.parsePath(possibleDerivation);
DeterministicKey derivedKey = keystore.getExtendedMasterPrivateKey().getKey(derivation);
DeterministicKey derivedKeyPublicOnly = derivedKey.dropPrivateBytes().dropParent();
ExtendedKey xpub = new ExtendedKey(derivedKeyPublicOnly, derivedKey.getParentFingerprint(), derivation.isEmpty() ? ChildNumber.ZERO : derivation.get(derivation.size() - 1));
if(xpub.equals(xPub)) {
derivationPath = possibleDerivation;
break;
}
} }
} else { } else {
keystore.setSource(KeystoreSource.SW_WATCH); keystore.setSource(KeystoreSource.SW_WATCH);