THAMER
Sovereign Bitcoin Wallet

WALLET AI BITCOIN

Your Bitcoin Wallet. Your Keys. Your Engine.

Self-hosted Bitcoin software built for developers, applications, and AI agents.

CREATE WALLET

Bitcoin Taproot Signing Explained: BIP341 Sighash and Schnorr

permalink THAMER
#bip340#bip341#bitcoin-taproot-sighash#schnorr

Taproot outputs use Schnorr signatures specified by BIP340, but the transaction signature message is defined by BIP341. Taproot signing must distinguish key-path spends from script-path spends and include the correct input, output, and extension commitments.

Taproot key-path signatures

A key-path spend proves authorization under the Taproot output key. The signing key may need a TapTweak adjustment from an internal key; signing with an untweaked internal private key is generally not equivalent to signing for the output key. BIP341 constructs a tagged TapSighash message, which is then signed using BIP340 Schnorr.

What data is committed?

Depending on the hash type, the signature message commits to transaction version and locktime; prevout identifiers, amounts, scriptPubKeys and sequences; output data; and information about the specific input. The spend type also reflects whether an annex is present and whether a script-path extension is used.

For ANYONECANPAY, the current input's prevout information is included directly instead of committing to the aggregate input hashes. For SINGLE, the matching output hash is required.

Taproot script-path extensions

Tapscript signatures extend the BIP341 message with additional data such as the tapleaf hash, key version, and code-separator position. A valid key-path signature cannot simply be reused as a script-path signature. The annex, when present, also changes the signed message.

Signature encodings and verification

A default-hash-type Taproot signature is 64 bytes. Explicit nondefault hash types produce 65-byte signatures. A 65-byte signature with an explicit 0x00 hash type is invalid. BIP340 public keys and signatures have fixed-size encodings, and verifiers must enforce the specified validity rules.

Developer precautions

Confirm the actual UTXO scriptPubKey, amount, tapleaf and control-block data when relevant. Never reuse a SegWit v0 digest routine for Taproot. Test key-path and script-path signatures separately.

Primary references

BIP143 — Transaction Signature Verification for Version 0 Witness Program: https://github.com/bitcoin/bips/blob/master/bip-0143.mediawiki
BIP341 — Taproot: https://github.com/bitcoin/bips/blob/master/bip-0341.mediawiki
BIP342 — Validation of Taproot Scripts: https://github.com/bitcoin/bips/blob/master/bip-0342.mediawiki

BIP340 — Schnorr Signatures: https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki

Questions & Answers

Explore all questions →

Latest from the Lab

THAMER illustrated developer portrait and signature

ABOUT THE DEVELOPER

Independent Software Developer specializing in Bitcoin Script, Golang, and AI Agents.

Software engineering · Independent research · Open-source projects