Signing & Sighash
When you build a transaction, each input must be signed so that the script spending condition is satisfied. The sighash type controls which parts of the transaction are committed to when signing. This page covers how to choose and use sighash types in code, signing order for multisig, and how signing fits into PSBT workflows. For the protocol definition of sighash types, see Sighash Types.
- SIGHASH_ALL (0x01) or SIGHASH_DEFAULT (0x00) for Taproot: Normal payments. Signer commits to all inputs and all outputs. Use this unless you need a contract pattern.
- SIGHASH_ALL | SIGHASH_ANYONECANPAY (0x81): CoinJoin and similar: signer commits to all outputs and only this input; other inputs can be added later.
- SIGHASH_NONE or SIGHASH_SINGLE: Used in some smart contracts; rarely needed in wallet code.
Libraries usually default to SIGHASH_ALL (or SIGHASH_DEFAULT for Taproot). Only set another type when you explicitly need it.
For M-of-N multisig, each of the M signers must sign the same transaction (or PSBT). Order does not matter for validity: any M signers can sign in any order. The resulting witness is a stack of M signatures (and possibly a script); the script verifies that M of N pubkeys signed. When using PSBT, each signer adds their signature to the PSBT; the finalizer combines them into the correct witness order required by the script.
For a single-sig input, you compute the sighash for that input (using the chosen sighash type), sign it with the private key, and place the signature (and public key if needed) in the witness or scriptSig. Libraries (e.g. rust-bitcoin, bitcoinjs-lib, btcsuite) do this when you call “sign input” or “sign transaction.”
- Creator builds an unsigned PSBT (inputs, outputs, optional descriptors).
- Signers each call “sign” for the inputs they control; the PSBT stores partial signatures.
- Finalizer combines partial signatures into the witness (and checks that required M-of-N are present).
- Extract the final transaction and broadcast.
See PSBT for structure and Transaction Construction for building the underlying transaction.
- Sighash Types - Protocol definition of sighash types
- Transaction Construction - Building and signing transactions
- PSBT - Partially signed transactions and multi-party signing
- Key Management - Private keys and signing
- Script Patterns - Multisig and contract scripts
- Smart Contracts - When to use non-default sighash types