From 8a6d2da5c911b3f63426c9e5331c55a36c27befc Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Mon, 25 Jul 2022 14:46:54 +0200 Subject: [PATCH] disallow duplicate xpubs in multisig wallet keystores --- .../java/com/sparrowwallet/drongo/wallet/Wallet.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/main/java/com/sparrowwallet/drongo/wallet/Wallet.java b/src/main/java/com/sparrowwallet/drongo/wallet/Wallet.java index 76eff7e..fe48d3e 100644 --- a/src/main/java/com/sparrowwallet/drongo/wallet/Wallet.java +++ b/src/main/java/com/sparrowwallet/drongo/wallet/Wallet.java @@ -1710,6 +1710,10 @@ public class Wallet extends Persistable implements Comparable { 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) { @@ -1732,6 +1736,14 @@ public class Wallet extends Persistable implements Comparable { 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) { makeLabelsUnique(newKeystore, false); }