x property

  1. @override
BigInt get x
override

Get the x-coordinate of this point in the projective elliptic curve coordinates.

If the point's z-coordinate is already one, this returns the x-coordinate directly. Otherwise, it computes the x-coordinate as x * zInverse^2 % p.

Returns: The x-coordinate of the point in the elliptic curve coordinates.

Note:

  • The value is computed modulo the prime field 'p' of the curve.
  • This property is used for coordinate transformation and point retrieval.
  • If the z-coordinate is not one, the result is the normalized x-coordinate.

See also:

  • y, z, t properties for other coordinates of the point.

Implementation

@override
BigInt get x {
  /// Extract the x-coordinate and z-coordinate from the point's coordinates.
  final xCoordinate = _coords[0];
  final zCoordinate = _coords[2];

  /// If z-coordinate is one, return the x-coordinate as it is.
  if (zCoordinate == BigInt.one) {
    return xCoordinate;
  }

  /// Get the prime field modulus from the curve.
  final p = curve.p;

  /// Calculate the inverse of z-coordinate modulo p.
  final zInverse = BigintUtils.inverseMod(zCoordinate, p);

  /// Compute and return the x-coordinate in projective coordinates.
  final result = (xCoordinate * zInverse * zInverse) % p;
  return result;
}