From 4564c5d25a460a91c1219e3056374862cd17e49f Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Thu, 31 Oct 2024 17:02:26 +0200 Subject: [PATCH] add eckey arithmetic functions --- .../com/sparrowwallet/drongo/crypto/ChildNumber.java | 2 +- .../java/com/sparrowwallet/drongo/crypto/ECKey.java | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/sparrowwallet/drongo/crypto/ChildNumber.java b/src/main/java/com/sparrowwallet/drongo/crypto/ChildNumber.java index 90d591c..fe5ecf0 100644 --- a/src/main/java/com/sparrowwallet/drongo/crypto/ChildNumber.java +++ b/src/main/java/com/sparrowwallet/drongo/crypto/ChildNumber.java @@ -30,7 +30,7 @@ public class ChildNumber { this.i = i; } - private static boolean hasHardenedBit(int a) { + public static boolean hasHardenedBit(int a) { return (a & HARDENED_BIT) != 0; } diff --git a/src/main/java/com/sparrowwallet/drongo/crypto/ECKey.java b/src/main/java/com/sparrowwallet/drongo/crypto/ECKey.java index 9db942a..4c9cb0f 100644 --- a/src/main/java/com/sparrowwallet/drongo/crypto/ECKey.java +++ b/src/main/java/com/sparrowwallet/drongo/crypto/ECKey.java @@ -332,6 +332,18 @@ public class ECKey { return ECKey.fromPublicOnly(point, false); } + /** Add to the public point by the provided public key */ + public ECKey add(ECKey pubKey) { + ECPoint point = pub.get().add(pubKey.getPubKeyPoint()); + return ECKey.fromPublicOnly(point, false); + } + + /** Calculate the value of the public key point modulo the secp256k1 curve order */ + public BigInteger moduloCurveOrder() { + BigInteger xCoordinate = pub.get().normalize().getAffineXCoord().toBigInteger(); + return xCoordinate.mod(CURVE_PARAMS.getCurve().getOrder()); + } + /** * 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).