liftX static method
Lift the x-coordinate of a public key for P2TR.
Parameters:
x: the x-coordinate of public key.
Throws:
- AddressConverterException if the x-coordinate cannot be lifted.
Implementation
static ProjectiveECCPoint liftX(BigInt x) {
final BigInt p = Curves.curveSecp256k1.p;
if (x >= p) {
throw AddressConverterException.addressKeyValidationFailed(
reason: "Invalid public key.",
);
}
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 AddressConverterException.addressKeyValidationFailed(
reason: "Invalid public key.",
);
}
final BigInt result = (y & BigInt.one) == BigInt.zero ? y : p - y;
return ProjectiveECCPoint(
curve: Curves.curveSecp256k1,
x: x,
y: result,
z: BigInt.one,
);
}