From 50aa9b4dcb70c6c17a85ade5325f9b87edf3a7b5 Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Wed, 7 Jun 2023 10:21:29 +0200 Subject: [PATCH] ensure canonical ordering of key expressions in multisig descriptor qr --- .../sparrowwallet/sparrow/wallet/SettingsController.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/sparrowwallet/sparrow/wallet/SettingsController.java b/src/main/java/com/sparrowwallet/sparrow/wallet/SettingsController.java index b058810e..9bb40611 100644 --- a/src/main/java/com/sparrowwallet/sparrow/wallet/SettingsController.java +++ b/src/main/java/com/sparrowwallet/sparrow/wallet/SettingsController.java @@ -356,7 +356,11 @@ public class SettingsController extends WalletFormController implements Initiali if(wallet.getPolicyType() == PolicyType.SINGLE) { cryptoOutput = new CryptoOutput(scriptExpressions, getCryptoHDKey(wallet.getKeystores().get(0))); } else if(wallet.getPolicyType() == PolicyType.MULTI) { - List cryptoHDKeys = wallet.getKeystores().stream().map(this::getCryptoHDKey).collect(Collectors.toList()); + WalletNode firstReceive = new WalletNode(wallet, KeyPurpose.RECEIVE, 0); + Utils.LexicographicByteArrayComparator lexicographicByteArrayComparator = new Utils.LexicographicByteArrayComparator(); + List cryptoHDKeys = wallet.getKeystores().stream().sorted((keystore1, keystore2) -> { + return lexicographicByteArrayComparator.compare(keystore1.getPubKey(firstReceive).getPubKey(), keystore2.getPubKey(firstReceive).getPubKey()); + }).map(this::getCryptoHDKey).collect(Collectors.toList()); MultiKey multiKey = new MultiKey(wallet.getDefaultPolicy().getNumSignaturesRequired(), null, cryptoHDKeys); List multiScriptExpressions = new ArrayList<>(scriptExpressions); multiScriptExpressions.add(ScriptExpression.SORTED_MULTISIG);