signTapRoot method

String signTapRoot(
  1. Uint8List txDigest, {
  2. dynamic sighash = TAPROOT_SIGHASH_ALL,
  3. List scripts = const [],
  4. bool tweak = true,
})

sign taproot transaction digest and returns the signature.

Implementation

String signTapRoot(Uint8List txDigest,
    {sighash = TAPROOT_SIGHASH_ALL,
    List<dynamic> scripts = const [],
    bool tweak = true}) {
  Uint8List byteKey = Uint8List(0);
  if (tweak) {
    final ECPublic publicKey = ECPublic.fromHex(_publicHex);
    final t = publicKey.calculateTweek(script: scripts);
    byteKey = ec.tweekTapprotPrivate(hexToBytes(_priveHex), t);
  } else {
    byteKey = hexToBytes(_priveHex);
  }
  final randAux = singleHash(Uint8List.fromList([...txDigest, ...byteKey]));
  Uint8List signatur = ec.schnorrSign(txDigest, byteKey, randAux);
  if (sighash != TAPROOT_SIGHASH_ALL) {
    signatur = Uint8List.fromList([...signatur, sighash]);
  }
  return bytesToHex(signatur);
}