privateAdd method

Uint8List? privateAdd(
  1. Uint8List d,
  2. Uint8List tweak
)

Implementation

Uint8List? privateAdd(Uint8List d, Uint8List tweak) {
  if (!isPrivate(d)) {
    throw ArgumentError('d is not a Private Key');
  }

  if (!isOrderScalar(tweak)) {
    throw ArgumentError('Expected a tweak');
  }

  final secp256k1 = ECCSecp256k1();
  const bigIntEndian = BigIntBigEndian();

  final dd = bigIntEndian.decode(d);
  final tt = bigIntEndian.decode(tweak);
  var dt = bigIntEndian.encode((dd + tt) % secp256k1.n);

  if (dt.length < 32) {
    final padLeadingZero = Uint8List(32 - dt.length);
    dt = Uint8List.fromList(padLeadingZero + dt);
  }

  if (!isPrivate(dt)) {
    return null;
  }

  return dt;
}