operator + method
Point addition
Implementation
ECPoint operator +(ECPoint other) {
if (isInfinity) return other;
if (other.isInfinity) return this;
if (x == other.x && y != other.y) {
return ECPoint.infinity;
}
BigInt lambda;
if (x == other.x && y == other.y) {
// Point doubling
lambda =
((BigInt.from(3) * x * x + ECDSACurve.a) *
_modInverse(BigInt.from(2) * y, ECDSACurve.p)) %
ECDSACurve.p;
} else {
// Point addition
lambda =
((other.y - y) * _modInverse(other.x - x, ECDSACurve.p)) %
ECDSACurve.p;
}
final x3 = (lambda * lambda - x - other.x) % ECDSACurve.p;
final y3 = (lambda * (x - x3) - y) % ECDSACurve.p;
return ECPoint(x3, y3);
}