signBip340 method
Signs a given digest using the BIP-340 (Schnorr) signature scheme.
This method follows the BIP-340 specification for creating Schnorr
signatures. It ensures that the provided digest has the correct length
and applies private key tweaking if a tapTweakHash
is provided.
digest
: The 32-byte message digest to be signed. It must be exactlyBitcoinSignerUtils.baselen
bytes in length.tapTweakHash
: (Optional) A tweak applied to the private key for Taproot-related signatures.aux
: (Optional) Auxiliary random data used to add entropy to the signature for security against side-channel attacks.
Implementation
List<int> signBip340(
{required List<int> digest, List<int>? tapTweakHash, List<int>? aux}) {
final signature = _signingKey.signBip340(
digest: digest, aux: aux, tapTweakHash: tapTweakHash);
if (verifierKey.verifyBip340Signature(
digest: digest, signature: signature, tapTweakHash: tapTweakHash)) {
return signature;
}
throw const CryptoSignException(
'The created signature does not pass verification.');
}