affinePoint method

AffinePoint affinePoint()

Convert point to 2d xy affine point.

Implementation

AffinePoint affinePoint() {
  final (BigInt x, BigInt y, BigInt z) = (px, py, pz);
  if (equals(I)) {
    return AffinePoint(BigInt.zero, BigInt.zero);
  }
  if (z == BigInt.one) {
    return AffinePoint(x, y);
  }
  // z^-1: invert z
  final iz = Utilities.inverse(z);
  if (Utilities.mod(z * iz) != BigInt.one) {
    // (z * z^-1) must be 1, otherwise bad math
    throw Exception('invalid inverse');
  }
  return AffinePoint(
      Utilities.mod(x * iz), Utilities.mod(y * iz)); // x = x*z^-1; y = y*z^-1
}