ToTweak method

ECPair ToTweak()

Implementation

ECPair ToTweak() {
  if (publicKey == null) throw Exception('Public key missed');

  final key = taggedHash('TapTweak', toXOnly(publicKey!));
  final hasOddY = publicKey![0] == 3 || (publicKey![0] == 4 && (publicKey![64] & 1) == 1);
  final private = hasOddY ? _privateNegate() : privateKey;

  final sum = bigFromBytes(private!) + bigFromBytes(key);
  final r = sum % secp256k1.n;
  final mod = r >= BigInt.zero ? r : secp256k1.n + r;
  final result = Uint8List.fromList(bigToBytes(mod));

  return ECPair.fromPrivateKey(result, network: network, compressed: compressed);
}