liftX static method

ProjectiveECCPoint liftX(
  1. ProjectiveECCPoint pubKeyPoint
)

Lift the x-coordinate of a public key for P2TR.

This method lifts the x-coordinate to obtain a ProjectiveECCPoint object, ensuring that it is within the curve's range.

Parameters:

  • pubKey: The public key to lift the x-coordinate for.

Returns: A ProjectiveECCPoint object with the lifted x-coordinate.

Throws:

  • Exception if the x-coordinate cannot be lifted.

Implementation

static ProjectiveECCPoint liftX(ProjectiveECCPoint pubKeyPoint) {
  final BigInt p = Curves.curveSecp256k1.p;
  final BigInt x = pubKeyPoint.x;
  if (x >= p) {
    throw MessageException("Unable to compute LiftX point");
  }
  final ySq = (x.modPow(BigInt.from(3), p) + BigInt.from(7)) % p;
  final y = ySq.modPow((p + BigInt.one) ~/ BigInt.from(4), p);
  if (y.modPow(BigInt.two, p) != ySq) {
    throw MessageException("Unable to compute LiftX point");
  }
  BigInt result = (y & BigInt.one) == BigInt.zero ? y : p - y;
  return ProjectiveECCPoint(
      curve: Curves.curveSecp256k1, x: x, y: result, z: BigInt.one);
}