CKey::SignSchnorr

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>

bool
SignSchnorr(
    uint256 const& hash,
    std::span<unsigned char> sig,
    uint256 const* merkle_root,
    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

NameDescription
hashThe 32-byte message hash to sign.
sigOutput span (64 bytes) receiving the Schnorr signature.
merkle_rootOptional Merkle root controlling BIP341 tweaking (see above).
auxAdditional nonce entropy.