add method
Point addition: P+Q, complete, exception
Implementation
Point add(Point other) {
final (BigInt X1, BigInt Y1, BigInt Z1) = (px, py, pz);
final (BigInt X2, BigInt Y2, BigInt Z2) = (other.px, other.py, other.pz);
final a = Curve.secp256k1.a;
final b = Curve.secp256k1.b;
var X3 = BigInt.zero, Y3 = BigInt.zero, Z3 = BigInt.zero;
final b3 = Utilities.mod(b * BigInt.from(3));
// step 1
var t0 = Utilities.mod(X1 * X2),
t1 = Utilities.mod(Y1 * Y2),
t2 = Utilities.mod(Z1 * Z2),
t3 = Utilities.mod(X1 + Y1),
t4 = Utilities.mod(X2 + Y2); // step 5
t3 = Utilities.mod(t3 * t4);
t4 = Utilities.mod(t0 + t1);
t3 = Utilities.mod(t3 - t4);
t4 = Utilities.mod(X1 + Z1);
// step 10
var t5 = Utilities.mod(X2 + Z2);
t4 = Utilities.mod(t4 * t5);
t5 = Utilities.mod(t0 + t2);
t4 = Utilities.mod(t4 - t5);
t5 = Utilities.mod(Y1 + Z1);
// step 15
X3 = Utilities.mod(Y2 + Z2);
t5 = Utilities.mod(t5 * X3);
X3 = Utilities.mod(t1 + t2);
t5 = Utilities.mod(t5 - X3);
Z3 = Utilities.mod(a * t4);
// step 20
X3 = Utilities.mod(b3 * t2);
Z3 = Utilities.mod(X3 + Z3);
X3 = Utilities.mod(t1 - Z3);
Z3 = Utilities.mod(t1 + Z3);
Y3 = Utilities.mod(X3 * Z3);
// step 25
t1 = Utilities.mod(t0 + t0);
t1 = Utilities.mod(t1 + t0);
t2 = Utilities.mod(a * t2);
t4 = Utilities.mod(b3 * t4);
t1 = Utilities.mod(t1 + t2);
// step 30
t2 = Utilities.mod(t0 - t2);
t2 = Utilities.mod(a * t2);
t4 = Utilities.mod(t4 + t2);
t0 = Utilities.mod(t1 * t4);
Y3 = Utilities.mod(Y3 + t0);
// step 35
t0 = Utilities.mod(t5 * t4);
X3 = Utilities.mod(t3 * X3);
X3 = Utilities.mod(X3 - t0);
t0 = Utilities.mod(t3 * t1);
Z3 = Utilities.mod(t5 * Z3);
// step 40
Z3 = Utilities.mod(Z3 + t0);
return Point(X3, Y3, Z3);
}