mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-12-24 12:46:45 +00:00
test various possible derivation paths when electrum seed is provided
This commit is contained in:
parent
27f4b3b3ae
commit
47fc0e11eb
1 changed files with 12 additions and 2 deletions
|
@ -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);
|
||||||
|
|
Loading…
Reference in a new issue