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 dd = d.toBigInt();
  final tt = tweak.toBigInt();
  var dt = ((dd + tt) % Bip32._secp256k1.n).toUin8List();

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

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

  return dt;
}