From acb1d767e8ca0e575d1777f872aaec483ff4bbe8 Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Tue, 8 Oct 2024 10:31:23 +0200 Subject: [PATCH] add helper method to multiply a public key --- .../java/com/sparrowwallet/drongo/OutputDescriptor.java | 2 +- src/main/java/com/sparrowwallet/drongo/crypto/ECKey.java | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/sparrowwallet/drongo/OutputDescriptor.java b/src/main/java/com/sparrowwallet/drongo/OutputDescriptor.java index f222d98..490dc69 100644 --- a/src/main/java/com/sparrowwallet/drongo/OutputDescriptor.java +++ b/src/main/java/com/sparrowwallet/drongo/OutputDescriptor.java @@ -575,7 +575,7 @@ public class OutputDescriptor { return builder.toString(); } - private List sortExtendedPubKeys(Collection keys) { + public List sortExtendedPubKeys(Collection keys) { List sortedKeys = new ArrayList<>(keys); if(mapChildrenDerivations == null || mapChildrenDerivations.isEmpty() || mapChildrenDerivations.containsKey(null)) { return sortedKeys; diff --git a/src/main/java/com/sparrowwallet/drongo/crypto/ECKey.java b/src/main/java/com/sparrowwallet/drongo/crypto/ECKey.java index 676e193..9db942a 100644 --- a/src/main/java/com/sparrowwallet/drongo/crypto/ECKey.java +++ b/src/main/java/com/sparrowwallet/drongo/crypto/ECKey.java @@ -326,6 +326,12 @@ public class ECKey { return pub.get(); } + /** Multiply the public point by the provided private key */ + public ECKey multiply(BigInteger privKey) { + ECPoint point = pub.get().multiply(privKey); + return ECKey.fromPublicOnly(point, false); + } + /** * Gets the private key in the form of an integer field element. The public key is derived by performing EC * point addition this number of times (i.e. point multiplying).