diff --git a/src/main/java/com/sparrowwallet/sparrow/io/Electrum.java b/src/main/java/com/sparrowwallet/sparrow/io/Electrum.java index f91ded5e..caa36fa6 100644 --- a/src/main/java/com/sparrowwallet/sparrow/io/Electrum.java +++ b/src/main/java/com/sparrowwallet/sparrow/io/Electrum.java @@ -161,8 +161,18 @@ public class Electrum implements KeystoreFileImport, WalletImport, WalletExport } 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 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 { keystore.setSource(KeystoreSource.SW_WATCH);