Safe Haskell | None |
---|---|
Language | Haskell2010 |
This package provides functions for parsing and evaluating bitcoin transaction scripts. Data types are provided for building and deconstructing all of the standard input and output script types.
Synopsis
- data ScriptInput
- data SimpleInput
- = SpendPK { }
- | SpendPKHash {
- getInputSig :: !TxSignature
- getInputKey :: !PubKeyI
- | SpendMulSig { }
- type RedeemScript = ScriptOutput
- p2shAddr :: Network -> ScriptOutput -> Address
- p2wshAddr :: Network -> ScriptOutput -> Maybe Address
- outputAddress :: Network -> ScriptOutput -> Either String Address
- inputAddress :: Network -> ScriptInput -> Either String Address
- encodeInput :: ScriptInput -> Script
- encodeInputBS :: ScriptInput -> ByteString
- decodeInput :: Network -> Script -> Either String ScriptInput
- decodeInputBS :: Network -> ByteString -> Either String ScriptInput
- addressToOutput :: Address -> Maybe ScriptOutput
- addressToScript :: Address -> Maybe Script
- addressToScriptBS :: Address -> Maybe ByteString
- scriptToAddress :: Network -> Script -> Maybe Address
- scriptToAddressBS :: Network -> ByteString -> Maybe Address
- sortMulSig :: ScriptOutput -> ScriptOutput
- scriptOpToInt :: ScriptOp -> Either String Int
- isSpendPK :: ScriptInput -> Bool
- isSpendPKHash :: ScriptInput -> Bool
- isSpendMulSig :: ScriptInput -> Bool
- isScriptHashInput :: ScriptInput -> Bool
- data SigHash
- data SigHashFlag
- sigHashAll :: SigHash
- sigHashNone :: SigHash
- sigHashSingle :: SigHash
- hasAnyoneCanPayFlag :: SigHash -> Bool
- hasForkIdFlag :: SigHash -> Bool
- setAnyoneCanPayFlag :: SigHash -> SigHash
- setForkIdFlag :: SigHash -> SigHash
- isSigHashAll :: SigHash -> Bool
- isSigHashNone :: SigHash -> Bool
- isSigHashSingle :: SigHash -> Bool
- isSigHashUnknown :: SigHash -> Bool
- sigHashAddForkId :: SigHash -> Word32 -> SigHash
- sigHashGetForkId :: SigHash -> Word32
- sigHashAddNetworkId :: Network -> SigHash -> SigHash
- txSigHash :: Network -> Tx -> Script -> Word64 -> Int -> SigHash -> Hash256
- txSigHashForkId :: Network -> Tx -> Script -> Word64 -> Int -> SigHash -> Hash256
- data TxSignature
- = TxSignature {
- txSignature :: !Sig
- txSignatureSigHash :: !SigHash
- | TxSignatureEmpty
- = TxSignature {
- encodeTxSig :: TxSignature -> ByteString
- decodeTxSig :: Network -> ByteString -> Either String TxSignature
- data ScriptOp
- = OP_PUSHDATA !ByteString !PushDataType
- | OP_0
- | OP_1NEGATE
- | OP_RESERVED
- | OP_1
- | OP_2
- | OP_3
- | OP_4
- | OP_5
- | OP_6
- | OP_7
- | OP_8
- | OP_9
- | OP_10
- | OP_11
- | OP_12
- | OP_13
- | OP_14
- | OP_15
- | OP_16
- | OP_NOP
- | OP_VER
- | OP_IF
- | OP_NOTIF
- | OP_VERIF
- | OP_VERNOTIF
- | OP_ELSE
- | OP_ENDIF
- | OP_VERIFY
- | OP_RETURN
- | OP_TOALTSTACK
- | OP_FROMALTSTACK
- | OP_IFDUP
- | OP_DEPTH
- | OP_DROP
- | OP_DUP
- | OP_NIP
- | OP_OVER
- | OP_PICK
- | OP_ROLL
- | OP_ROT
- | OP_SWAP
- | OP_TUCK
- | OP_2DROP
- | OP_2DUP
- | OP_3DUP
- | OP_2OVER
- | OP_2ROT
- | OP_2SWAP
- | OP_CAT
- | OP_SUBSTR
- | OP_LEFT
- | OP_RIGHT
- | OP_SIZE
- | OP_INVERT
- | OP_AND
- | OP_OR
- | OP_XOR
- | OP_EQUAL
- | OP_EQUALVERIFY
- | OP_RESERVED1
- | OP_RESERVED2
- | OP_1ADD
- | OP_1SUB
- | OP_2MUL
- | OP_2DIV
- | OP_NEGATE
- | OP_ABS
- | OP_NOT
- | OP_0NOTEQUAL
- | OP_ADD
- | OP_SUB
- | OP_MUL
- | OP_DIV
- | OP_MOD
- | OP_LSHIFT
- | OP_RSHIFT
- | OP_BOOLAND
- | OP_BOOLOR
- | OP_NUMEQUAL
- | OP_NUMEQUALVERIFY
- | OP_NUMNOTEQUAL
- | OP_LESSTHAN
- | OP_GREATERTHAN
- | OP_LESSTHANOREQUAL
- | OP_GREATERTHANOREQUAL
- | OP_MIN
- | OP_MAX
- | OP_WITHIN
- | OP_RIPEMD160
- | OP_SHA1
- | OP_SHA256
- | OP_HASH160
- | OP_HASH256
- | OP_CODESEPARATOR
- | OP_CHECKSIG
- | OP_CHECKSIGVERIFY
- | OP_CHECKMULTISIG
- | OP_CHECKMULTISIGVERIFY
- | OP_NOP1
- | OP_NOP2
- | OP_NOP3
- | OP_NOP4
- | OP_NOP5
- | OP_NOP6
- | OP_NOP7
- | OP_NOP8
- | OP_NOP9
- | OP_NOP10
- | OP_PUBKEYHASH
- | OP_PUBKEY
- | OP_INVALIDOPCODE !Word8
- newtype Script = Script {}
- data PushDataType
- data ScriptOutput
- = PayPK { }
- | PayPKHash {
- getOutputHash :: !Hash160
- | PayMulSig { }
- | PayScriptHash {
- getOutputHash :: !Hash160
- | PayWitnessPKHash {
- getOutputHash :: !Hash160
- | PayWitnessScriptHash {
- getScriptHash :: !Hash256
- | DataCarrier { }
- isPayPK :: ScriptOutput -> Bool
- isPayPKHash :: ScriptOutput -> Bool
- isPayMulSig :: ScriptOutput -> Bool
- isPayScriptHash :: ScriptOutput -> Bool
- isPayWitnessPKHash :: ScriptOutput -> Bool
- isPayWitnessScriptHash :: ScriptOutput -> Bool
- isDataCarrier :: ScriptOutput -> Bool
- encodeOutput :: ScriptOutput -> Script
- encodeOutputBS :: ScriptOutput -> ByteString
- decodeOutput :: Script -> Either String ScriptOutput
- decodeOutputBS :: ByteString -> Either String ScriptOutput
- isPushOp :: ScriptOp -> Bool
- opPushData :: ByteString -> ScriptOp
- intToScriptOp :: Int -> ScriptOp
- scriptOpToInt :: ScriptOp -> Either String Int
Documentation
data ScriptInput Source #
Instances
Eq ScriptInput Source # | |
Defined in Network.Haskoin.Script.Standard (==) :: ScriptInput -> ScriptInput -> Bool # (/=) :: ScriptInput -> ScriptInput -> Bool # | |
Show ScriptInput Source # | |
Defined in Network.Haskoin.Script.Standard showsPrec :: Int -> ScriptInput -> ShowS # show :: ScriptInput -> String # showList :: [ScriptInput] -> ShowS # | |
NFData ScriptInput Source # | |
Defined in Network.Haskoin.Script.Standard rnf :: ScriptInput -> () # |
data SimpleInput Source #
Data type describing standard transaction input scripts. Input scripts provide the signing data required to unlock the coins of the output they are trying to spend, except in pay-to-witness-public-key-hash and pay-to-script-hash transactions.
SpendPK | spend pay-to-public-key output |
SpendPKHash | spend pay-to-public-key-hash output |
| |
SpendMulSig | spend multisig output |
Instances
Eq SimpleInput Source # | |
Defined in Network.Haskoin.Script.Standard (==) :: SimpleInput -> SimpleInput -> Bool # (/=) :: SimpleInput -> SimpleInput -> Bool # | |
Show SimpleInput Source # | |
Defined in Network.Haskoin.Script.Standard showsPrec :: Int -> SimpleInput -> ShowS # show :: SimpleInput -> String # showList :: [SimpleInput] -> ShowS # | |
NFData SimpleInput Source # | |
Defined in Network.Haskoin.Script.Standard rnf :: SimpleInput -> () # |
type RedeemScript = ScriptOutput Source #
A redeem script is the output script serialized into the spending input script. It must be included in inputs that spend pay-to-script-hash outputs.
p2shAddr :: Network -> ScriptOutput -> Address Source #
Compute a pay-to-script-hash address for an output script.
p2wshAddr :: Network -> ScriptOutput -> Maybe Address Source #
Compute a pay-to-witness-script-hash address for an output script. Only on SegWit networks.
outputAddress :: Network -> ScriptOutput -> Either String Address Source #
Get the Address
of a ScriptOutput
.
inputAddress :: Network -> ScriptInput -> Either String Address Source #
Infer the address of a ScriptInput
encodeInput :: ScriptInput -> Script Source #
Encode a standard input into a script.
encodeInputBS :: ScriptInput -> ByteString Source #
Similar to encodeInput
but encodes directly to a serialized script
ByteString
.
decodeInput :: Network -> Script -> Either String ScriptInput Source #
Heuristic to decode a ScriptInput
from a Script
. This function fails if
the script can not be parsed as a standard script input.
decodeInputBS :: Network -> ByteString -> Either String ScriptInput Source #
Like decodeInput
but decodes directly from a serialized script
ByteString
.
addressToOutput :: Address -> Maybe ScriptOutput Source #
Encode an output script from an address. Will fail if using a pay-to-witness address on a non-SegWit network.
addressToScriptBS :: Address -> Maybe ByteString Source #
Encode address as output script in ByteString
form.
scriptToAddress :: Network -> Script -> Maybe Address Source #
Decode an output script into an Address
if it has such representation.
scriptToAddressBS :: Network -> ByteString -> Maybe Address Source #
Decode a serialized script into an Address
.
sortMulSig :: ScriptOutput -> ScriptOutput Source #
Sort the public keys of a multisig output in ascending order by comparing their compressed serialized representations. Refer to BIP-67.
isSpendPK :: ScriptInput -> Bool Source #
Returns true if the input script is spending from a pay-to-public-key output.
isSpendPKHash :: ScriptInput -> Bool Source #
Returns true if the input script is spending from a pay-to-public-key-hash output.
isSpendMulSig :: ScriptInput -> Bool Source #
Returns true if the input script is spending a multisig output.
isScriptHashInput :: ScriptInput -> Bool Source #
Returns true if the input script is spending a pay-to-script-hash output.
Data type representing the different ways a transaction can be signed.
When producing a signature, a hash of the transaction is used as the message
to be signed. The SigHash
parameter controls which parts of the
transaction are used or ignored to produce the transaction hash. The idea is
that if some part of a transaction is not used to produce the transaction
hash, then you can change that part of the transaction after producing a
signature without invalidating that signature.
If the SIGHASH_ANYONECANPAY
flag is set (true), then only the current input
is signed. Otherwise, all of the inputs of a transaction are signed. The
default value for SIGHASH_ANYONECANPAY
is unset (false).
Instances
data SigHashFlag Source #
Instances
sigHashAll :: SigHash Source #
hasAnyoneCanPayFlag :: SigHash -> Bool Source #
hasForkIdFlag :: SigHash -> Bool Source #
setAnyoneCanPayFlag :: SigHash -> SigHash Source #
setForkIdFlag :: SigHash -> SigHash Source #
isSigHashAll :: SigHash -> Bool Source #
Returns True if the SigHash
has the value SIGHASH_ALL
.
isSigHashNone :: SigHash -> Bool Source #
Returns True if the SigHash
has the value SIGHASH_NONE
.
isSigHashSingle :: SigHash -> Bool Source #
Returns True if the SigHash
has the value SIGHASH_SINGLE
.
isSigHashUnknown :: SigHash -> Bool Source #
Returns True if the SigHash
has the value SIGHASH_UNKNOWN
.
sigHashGetForkId :: SigHash -> Word32 Source #
:: Network | |
-> Tx | transaction to sign |
-> Script | csript from output being spent |
-> Word64 | value of output being spent |
-> Int | index of input being signed |
-> SigHash | what to sign |
-> Hash256 | hash to be signed |
Computes the hash that will be used for signing a transaction.
:: Network | |
-> Tx | transaction to sign |
-> Script | script from output being spent |
-> Word64 | value of output being spent |
-> Int | index of input being signed |
-> SigHash | what to sign |
-> Hash256 | hash to be signed |
Compute the hash that will be used for signing a transaction. This
function is used when the SIGHASH_FORKID
flag is set.
data TxSignature Source #
Data type representing a signature together with a SigHash
. The SigHash
is serialized as one byte at the end of an ECDSA Sig
. All signatures in
transaction inputs are of type TxSignature
.
Instances
Eq TxSignature Source # | |
Defined in Network.Haskoin.Script.SigHash (==) :: TxSignature -> TxSignature -> Bool # (/=) :: TxSignature -> TxSignature -> Bool # | |
Show TxSignature Source # | |
Defined in Network.Haskoin.Script.SigHash showsPrec :: Int -> TxSignature -> ShowS # show :: TxSignature -> String # showList :: [TxSignature] -> ShowS # | |
NFData TxSignature Source # | |
Defined in Network.Haskoin.Script.SigHash rnf :: TxSignature -> () # |
encodeTxSig :: TxSignature -> ByteString Source #
Serialize a TxSignature
.
decodeTxSig :: Network -> ByteString -> Either String TxSignature Source #
Deserialize a TxSignature
.
Data type representing an operator allowed inside a Script
.
Data type representing a transaction script. Scripts are defined as lists
of script operators ScriptOp
. Scripts are used to:
- Define the spending conditions in the output of a transaction.
- Provide signatures in the input of a transaction (except SegWit).
SigWit only: the segregated witness data structure, and not the input script, contains signatures and redeem script for pay-to-witness-script and pay-to-witness-public-key-hash transactions.
data PushDataType Source #
Data type representing the type of an OP_PUSHDATA opcode.
OPCODE | next opcode bytes is data to be pushed |
OPDATA1 | next byte contains number of bytes of data to be pushed |
OPDATA2 | next two bytes contains number of bytes to be pushed |
OPDATA4 | next four bytes contains the number of bytes to be pushed |
Instances
Eq PushDataType Source # | |
Defined in Network.Haskoin.Script.Common (==) :: PushDataType -> PushDataType -> Bool # (/=) :: PushDataType -> PushDataType -> Bool # | |
Read PushDataType Source # | |
Defined in Network.Haskoin.Script.Common readsPrec :: Int -> ReadS PushDataType # readList :: ReadS [PushDataType] # | |
Show PushDataType Source # | |
Defined in Network.Haskoin.Script.Common showsPrec :: Int -> PushDataType -> ShowS # show :: PushDataType -> String # showList :: [PushDataType] -> ShowS # | |
NFData PushDataType Source # | |
Defined in Network.Haskoin.Script.Common rnf :: PushDataType -> () # |
data ScriptOutput Source #
Data type describing standard transaction output scripts. Output scripts provide the conditions that must be fulfilled for someone to spend the funds in a transaction output.
PayPK | pay to public key |
PayPKHash | pay to public key hash |
| |
PayMulSig | multisig |
| |
PayScriptHash | pay to a script hash |
| |
PayWitnessPKHash | pay to witness public key hash |
| |
PayWitnessScriptHash | pay to witness script hash |
| |
DataCarrier | provably unspendable data carrier |
Instances
Eq ScriptOutput Source # | |
Defined in Network.Haskoin.Script.Common (==) :: ScriptOutput -> ScriptOutput -> Bool # (/=) :: ScriptOutput -> ScriptOutput -> Bool # | |
Show ScriptOutput Source # | |
Defined in Network.Haskoin.Script.Common showsPrec :: Int -> ScriptOutput -> ShowS # show :: ScriptOutput -> String # showList :: [ScriptOutput] -> ShowS # | |
ToJSON ScriptOutput Source # | |
Defined in Network.Haskoin.Script.Common toJSON :: ScriptOutput -> Value # toEncoding :: ScriptOutput -> Encoding # toJSONList :: [ScriptOutput] -> Value # toEncodingList :: [ScriptOutput] -> Encoding # | |
FromJSON ScriptOutput Source # | |
Defined in Network.Haskoin.Script.Common parseJSON :: Value -> Parser ScriptOutput # parseJSONList :: Value -> Parser [ScriptOutput] # | |
NFData ScriptOutput Source # | |
Defined in Network.Haskoin.Script.Common rnf :: ScriptOutput -> () # |
isPayPK :: ScriptOutput -> Bool Source #
Returns True if the script is a pay to public key output.
isPayPKHash :: ScriptOutput -> Bool Source #
Returns True if the script is a pay to public key hash output.
isPayMulSig :: ScriptOutput -> Bool Source #
Returns True if the script is a multisig output.
isPayScriptHash :: ScriptOutput -> Bool Source #
Returns true if the script is a pay to script hash output.
isPayWitnessPKHash :: ScriptOutput -> Bool Source #
Returns true if the script is a pay to witness public key hash output.
isDataCarrier :: ScriptOutput -> Bool Source #
Returns True if the script is an OP_RETURN
"datacarrier" output
encodeOutput :: ScriptOutput -> Script Source #
Computes a Script
from a standard ScriptOutput
.
encodeOutputBS :: ScriptOutput -> ByteString Source #
Similar to encodeOutput
but encodes to a ByteString
decodeOutput :: Script -> Either String ScriptOutput Source #
Tries to decode a ScriptOutput
from a Script
. This can fail if the
script is not recognized as any of the standard output types.
decodeOutputBS :: ByteString -> Either String ScriptOutput Source #
Similar to decodeOutput
but decodes from a ByteString
.
opPushData :: ByteString -> ScriptOp Source #
Optimally encode data using one of the 4 types of data pushing opcodes.