pointAddScalar function
This method performs point addition with a scalar value and optional compression. It takes a point 'p', a tweak 'tweak', and a boolean 'compress' flag as input. If the inputs are valid, it returns the result of the point addition as a Uint8List. If any input is invalid or if the result is infinity, it returns null.
Implementation
Uint8List? pointAddScalar(Uint8List p, Uint8List tweak, bool compress) {
/// Check if 'p' is a valid ECPoint; if not, raise an error.
if (!isPoint(p)) {
throw ArgumentError("Bad Point");
}
/// Check if 'tweak' is a valid scalar value; if not, raise an error.
if (!isOrderScalar(tweak)) {
throw ArgumentError("Bad Tweek");
}
/// Decode the input 'p' into an ECPoint.
ECPoint? pp = _decodeFrom(p);
/// If 'tweak' is zero, return the original point 'p' with optional compression.
if (_compare(tweak, Uint8List(32)) == 0) {
return pp!.getEncoded(compress);
}
/// Decode the 'tweak' into a BigInt.
BigInt tt = decodeBigInt(tweak);
/// Calculate the new point 'qq' as 'G * tt', where 'G' is a predefined generator point.
ECPoint qq = (G * tt) as ECPoint;
/// Calculate the result point 'uu' as 'pp + qq'.
ECPoint uu = (pp! + qq) as ECPoint;
/// Check if 'uu' is infinity (an invalid result); if so, return null.
if (uu.isInfinity) {
return null;
}
/// Return the encoded representation of the result point 'uu' with optional compression.
return uu.getEncoded(compress);
}