[#CKey-SignSchnorr] = xref:CKey.adoc[CKey]::SignSchnorr :relfileprefix: ../ :mrdocs: Create a BIP‐340 Schnorr signature, for the xonly‐pubkey corresponding to *this, optionally tweaked by *merkle_root. Additional nonce entropy is provided through aux. == Synopsis Declared in `<key.h>` [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- bool SignSchnorr( xref:uint256.adoc[uint256] const& hash, std::span<unsigned char> sig, xref:uint256.adoc[uint256] const* merkle_root, xref:uint256.adoc[uint256] const& aux) const; ---- == Description merkle_root is used to optionally perform tweaking of the private key, as specified in BIP341: * If merkle_root == nullptr: no tweaking is done, sign with key directly (this is used for signatures in BIP342 script). * If merkle_root‐>IsNull(): sign with key + H_TapTweak(pubkey) (this is used for key path spending when no scripts are present). * Otherwise: sign with key + H_TapTweak(pubkey || *merkle_root) (this is used for key path spending, with specific Merkle root of the script tree). == Return Value true if signing succeeded. == Parameters [cols="1,4"] |=== | Name| Description | *hash* | The 32‐byte message hash to sign. | *sig* | Output span (64 bytes) receiving the Schnorr signature. | *merkle_root* | Optional Merkle root controlling BIP341 tweaking (see above). | *aux* | Additional nonce entropy. |=== [.small]#Created with https://www.mrdocs.com[MrDocs]#