add eckey arithmetic functions

This commit is contained in:
Craig Raw 2024-10-31 17:02:26 +02:00
parent dba1a9a2be
commit 4564c5d25a
2 changed files with 13 additions and 1 deletions

View file

@ -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;
}

View file

@ -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).