scale method

Scales the projective point's coordinates.

If the current z-coordinate is already one, there's no need to scale the point.

currentX, currentY, and currentZ represent the current coordinates. primeField is the prime field value of the curve. zInverse is the modular inverse of the current z-coordinate. zInverseSquared is the square of the z-inverse.

The x and y coordinates are scaled using zInverseSquared.

The coordinates are updated to the scaled values, and the scaled point is returned.

Implementation

ProjectiveECCPoint scale() {
  final currentZ = _coords[2];

  /// If the current z-coordinate is already one, no need to scale
  if (currentZ == BigInt.one) {
    return this;
  }
  final currentY = _coords[1];
  final currentX = _coords[0];

  /// Get the prime field value
  final primeField = curve.p;

  /// Calculate the modular inverse of z
  final zInverse = BigintUtils.inverseMod(currentZ, primeField);

  /// Calculate z-inverse squared
  final zInverseSquared = (zInverse * zInverse) % primeField;

  /// Scale the x and y coordinates
  final scaledX = (currentX * zInverseSquared) % primeField;
  final scaledY = (currentY * zInverseSquared * zInverse) % primeField;

  /// Update the coordinates to the scaled values
  _coords = [scaledX, scaledY, BigInt.one];

  return this;
}