calculatePrivateTweek static method

List<int> calculatePrivateTweek(
  1. List<int> secret,
  2. BigInt tweek
)

Calculates a private tweak for a given secret and tweak value.

The tweak is applied to the negation of the secret key, and the result is adjusted based on the parity of the corresponding public key.

Implementation

static List<int> calculatePrivateTweek(List<int> secret, BigInt tweek) {
  BigInt negatedKey = BigintUtils.fromBytes(secret);
  final publicBytes =
      (_generator * negatedKey).toBytes(EncodeType.uncompressed);
  final toBigInt = BigintUtils.fromBytes(publicBytes.sublist(33));
  if (toBigInt.isOdd) {
    negatedKey = _order - negatedKey;
  }
  final tw = (negatedKey + tweek) % _order;
  return BigintUtils.toBytes(tw, length: baselen);
}