| Copyright | (c) 2025 Jared Tobin |
|---|---|
| License | MIT |
| Maintainer | Jared Tobin <jared@ppad.tech> |
| Safe Haskell | None |
| Language | Haskell2010 |
Bitcoin.Prim.Tx.Sighash
Description
Sighash computation for legacy and BIP143 segwit transactions.
Synopsis
- data SighashType
- sighash_legacy :: Tx -> Int -> ByteString -> SighashType -> ByteString
- sighash_segwit :: Tx -> Int -> ByteString -> Word64 -> SighashType -> Maybe ByteString
Sighash Types
data SighashType Source #
Sighash type flags.
Constructors
| SIGHASH_ALL | |
| SIGHASH_NONE | |
| SIGHASH_SINGLE | |
| SIGHASH_ALL_ANYONECANPAY | |
| SIGHASH_NONE_ANYONECANPAY | |
| SIGHASH_SINGLE_ANYONECANPAY |
Instances
| Generic SighashType Source # | |||||
Defined in Bitcoin.Prim.Tx.Sighash Associated Types
| |||||
| Show SighashType Source # | |||||
Defined in Bitcoin.Prim.Tx.Sighash Methods showsPrec :: Int -> SighashType -> ShowS # show :: SighashType -> String # showList :: [SighashType] -> ShowS # | |||||
| Eq SighashType Source # | |||||
Defined in Bitcoin.Prim.Tx.Sighash | |||||
| type Rep SighashType Source # | |||||
Defined in Bitcoin.Prim.Tx.Sighash type Rep SighashType = D1 ('MetaData "SighashType" "Bitcoin.Prim.Tx.Sighash" "ppad-tx-0.1.0-55gH9IEpqyC9H1txhCYBkH" 'False) ((C1 ('MetaCons "SIGHASH_ALL" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "SIGHASH_NONE" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "SIGHASH_SINGLE" 'PrefixI 'False) (U1 :: Type -> Type))) :+: (C1 ('MetaCons "SIGHASH_ALL_ANYONECANPAY" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "SIGHASH_NONE_ANYONECANPAY" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "SIGHASH_SINGLE_ANYONECANPAY" 'PrefixI 'False) (U1 :: Type -> Type)))) | |||||
Legacy Sighash
Arguments
| :: Tx | |
| -> Int | input index |
| -> ByteString | scriptPubKey being spent |
| -> SighashType | |
| -> ByteString | 32-byte hash |
Compute legacy sighash for P2PKH/P2SH inputs.
Modifies a copy of the transaction based on sighash flags, appends the sighash type as 4-byte little-endian, and double SHA256s.
-- sign input 0 with SIGHASH_ALL let hash = sighash_legacy tx 0 scriptPubKey SIGHASH_ALL -- use hash with ECDSA signing
For SIGHASH_SINGLE with input index >= output count, returns the special "sighash single bug" value (0x01 followed by 31 zero bytes).
BIP143 Segwit Sighash
Arguments
| :: Tx | |
| -> Int | input index |
| -> ByteString | scriptCode |
| -> Word64 | value being spent (satoshis) |
| -> SighashType | |
| -> Maybe ByteString | 32-byte hash, or Nothing if index invalid |
Compute BIP143 segwit sighash.
Required for signing segwit inputs (P2WPKH, P2WSH). Unlike legacy sighash, this commits to the value being spent, preventing fee manipulation attacks.
Returns Nothing if the input index is out of range.
-- sign P2WPKH input 0 let scriptCode = ... -- P2WPKH scriptCode let hash = sighash_segwit tx 0 scriptCode inputValue SIGHASH_ALL -- use hash with ECDSA signing (after checking Just)