disallow duplicate xpubs in multisig wallet keystores

This commit is contained in:
Craig Raw 2022-07-25 14:46:54 +02:00
parent ce90e29284
commit 8a6d2da5c9

View file

@ -1710,6 +1710,10 @@ public class Wallet extends Persistable implements Comparable<Wallet> {
throw new InvalidWalletException("Keystore " + keystore.getLabel() + " derivation of " + keystore.getKeyDerivation().getDerivationPath() + " in " + scriptType.getName() + " wallet matches another default script type."); throw new InvalidWalletException("Keystore " + keystore.getLabel() + " derivation of " + keystore.getKeyDerivation().getDerivationPath() + " in " + scriptType.getName() + " wallet matches another default script type.");
} }
} }
if(containsDuplicateExtendedKeys()) {
throw new InvalidWalletException("Wallet keystores have duplicate extended public keys");
}
} }
public boolean derivationMatchesAnotherScriptType(String derivationPath) { public boolean derivationMatchesAnotherScriptType(String derivationPath) {
@ -1732,6 +1736,14 @@ public class Wallet extends Persistable implements Comparable<Wallet> {
return !keystores.stream().map(Keystore::getLabel).allMatch(new HashSet<>()::add); return !keystores.stream().map(Keystore::getLabel).allMatch(new HashSet<>()::add);
} }
public boolean containsDuplicateExtendedKeys() {
if(keystores.size() <= 1) {
return false;
}
return !keystores.stream().map(Keystore::getExtendedPublicKey).allMatch(new HashSet<>()::add);
}
public void makeLabelsUnique(Keystore newKeystore) { public void makeLabelsUnique(Keystore newKeystore) {
makeLabelsUnique(newKeystore, false); makeLabelsUnique(newKeystore, false);
} }