operator + method

Point addition with another JubJub point.

Implementation

@override
JubJubNativePoint operator +(BaseRedJubJubPoint<JubJubNativeFr> rhs) {
  switch (rhs) {
    case final JubJubNielsNativePoint point:
      final a = (v - u) * point.vMinusU;
      final b = (v + u) * point.vPlusU;
      final c = t1 * t2 * point.t2d;
      final d = (z * point.z).double();
      return _JubjubCompletedNativePoint(
        u: b - a,
        v: b + a,
        z: d + c,
        t: d - c,
      ).toExtended();
    case final JubJubAffineNielsNativePoint point:
      final a = (v - u) * point.vMinusU;
      final b = (v + u) * point.vPlusU;
      final c = t1 * t2 * point.t2d;
      final d = z.double();
      return _JubjubCompletedNativePoint(
        u: b - a,
        v: b + a,
        z: d + c,
        t: d - c,
      ).toExtended();
    case final JubJubNativePoint point:
      return this + point.toNiels();
    case final JubJubAffineNativePoint point:
      return this + point.toNiels();
    default:
      throw CryptoException.operationNotSupported;
  }
}