assertValidity method
Checks if the point is valid and on-curve
Implementation
Point assertValidity() {
// convert to 2d xy affine point.
final affinePointValue = affinePoint();
// convert to 2d xy affine point.
final (BigInt x, BigInt y) = (affinePointValue.x, affinePointValue.y);
if (!Utilities.fe(x) || !Utilities.fe(y)) {
// x and y must be in range 0 < n < P
throw Exception('Point invalid: x or y');
}
// y² = x³ + ax + b, must be equal
if (Utilities.mod(y * y) == Utilities.crv(x)) {
return this;
}
throw Exception('Point invalid: not on curve');
}