calculateTweek static method

List<int> calculateTweek(
  1. ProjectiveECCPoint pubPoint, {
  2. List? script,
})

_calculateTweek computes and returns the TapTweak value based on the ECPublic key and an optional script. It uses the key's x-coordinate and the Merkle root of the script (if provided) to calculate the tweak.

Implementation

static List<int> calculateTweek(ProjectiveECCPoint pubPoint,
    {List<dynamic>? script}) {
  final keyX =
      BigintUtils.toBytes(pubPoint.x, length: pubPoint.curve.baselen);
  if (script == null) {
    final tweek = taggedHash("TapTweak", keyX);
    return tweek;
  }
  final merkleRoot = _getTagHashedMerkleRoot(script);
  final tweek = taggedHash("TapTweak", [...keyX, ...merkleRoot]);
  return tweek;
}