diff --git a/src/main/java/com/sparrowwallet/drongo/crypto/ECKey.java b/src/main/java/com/sparrowwallet/drongo/crypto/ECKey.java index 72c4ef7..c262caf 100644 --- a/src/main/java/com/sparrowwallet/drongo/crypto/ECKey.java +++ b/src/main/java/com/sparrowwallet/drongo/crypto/ECKey.java @@ -348,6 +348,11 @@ public class ECKey { return ECKey.fromPublicOnly(point, compressed); } + /** Negate the provided public key */ + public ECKey negate() { + return ECKey.fromPublicOnly(getPubKeyPoint().negate().normalize(), isCompressed()); + } + /** Add to the private key by the provided private key using modular arithmetic */ public ECKey addPrivate(ECKey privKey) { if(this.priv == null || privKey.priv == null) { @@ -358,7 +363,7 @@ public class ECKey { } /** Negate the provided private key */ - public ECKey negate() { + public ECKey negatePrivate() { if(priv == null) { throw new IllegalStateException("Key did not contain a private key"); } diff --git a/src/main/java/com/sparrowwallet/drongo/silentpayments/SilentPaymentUtils.java b/src/main/java/com/sparrowwallet/drongo/silentpayments/SilentPaymentUtils.java index 8b67f65..e30f4bc 100644 --- a/src/main/java/com/sparrowwallet/drongo/silentpayments/SilentPaymentUtils.java +++ b/src/main/java/com/sparrowwallet/drongo/silentpayments/SilentPaymentUtils.java @@ -241,7 +241,7 @@ public class SilentPaymentUtils { try { ECKey privateKey = walletNode.getWallet().getKeystores().getFirst().getKey(walletNode); if(walletNode.getWallet().getScriptType() == P2TR && !privateKey.getPubKeyPoint().getYCoord().toBigInteger().mod(BigInteger.TWO).equals(BigInteger.ZERO)) { - privateKey = privateKey.negate(); + privateKey = privateKey.negatePrivate(); } if(summedPrivateKey == null) { summedPrivateKey = privateKey; @@ -266,8 +266,7 @@ public class SilentPaymentUtils { public static byte[] getSmallestOutpoint(Set outpoints) { return outpoints.stream().map(outpoint -> new TransactionOutPoint(outpoint.getHash(), outpoint.getIndex())).map(TransactionOutPoint::bitcoinSerialize) - .sorted(new Utils.LexicographicByteArrayComparator()) - .findFirst().orElseThrow(() -> new IllegalArgumentException("No inputs provided to calculate silent payments input hash")); + .min(new Utils.LexicographicByteArrayComparator()).orElseThrow(() -> new IllegalArgumentException("No inputs provided to calculate silent payments input hash")); } public static ECKey getLabelledSpendKey(ECKey scanPrivateKey, ECKey spendPublicKey, int labelIndex) {