operator + method

  1. @override
ECPoint? operator +(
  1. covariant ECPoint? b
)
override

Implementation

@override
ECPoint? operator +(ECPoint? b) {
  if (isInfinity) {
    return b;
  }

  if (b!.isInfinity) {
    return this;
  }

  // Check if b = this or b = -this
  if (x == b.x) {
    if (y == b.y) {
      // this = b, i.e. this must be doubled
      return twice();
    }

    // this = -b, i.e. the result is the point at infinity
    return curve.infinity as ECPoint?;
  }

  var gamma = (b.y! - y!) / (b.x! - x!);

  var x3 = (gamma.square() - x!) - b.x!;
  var y3 = (gamma * (x! - x3)) - y!;

  return ECPoint(curve as ECCurve, x3 as ECFieldElement?,
      y3 as ECFieldElement?, isCompressed);
}