haskoin-0.1.0.2: Implementation of the Bitcoin protocol.

Safe HaskellNone

Network.Haskoin.Internals

Contents

Description

This module expose haskoin internals. No guarantee is made on the stability of the interface of these internal modules.

Synopsis

Documentation

hash512 :: ByteString -> Word512Source

Computes SHA-512.

hash256 :: ByteString -> Word256Source

Computes SHA-256.

hashSha1 :: ByteString -> Word160Source

Computes SHA-160.

hash160 :: ByteString -> Word160Source

Computes RIPEMD-160.

hash512BS :: ByteString -> ByteStringSource

Computes SHA-512 and returns the result as a bytestring.

hash256BS :: ByteString -> ByteStringSource

Computes SHA-256 and returns the result as a bytestring.

hashSha1BS :: ByteString -> ByteStringSource

Computes SHA-160 and returns the result as a bytestring.

hash160BS :: ByteString -> ByteStringSource

Computes RIPEMD-160 and returns the result as a bytestring.

doubleHash256 :: ByteString -> Word256Source

Computes two rounds of SHA-256.

doubleHash256BS :: ByteString -> ByteStringSource

Computes two rounds of SHA-256 and returns the result as a bytestring.

chksum32 :: ByteString -> CheckSum32Source

Computes a 32 bit checksum.

hmac512 :: ByteString -> ByteString -> Word512Source

Computes HMAC over SHA-512.

hmac512BS :: ByteString -> ByteString -> ByteStringSource

Computes HMAC over SHA-512 and return the result as a bytestring.

hmac256 :: ByteString -> ByteString -> Word256Source

Computes HMAC over SHA-256.

hmac256BS :: ByteString -> ByteString -> ByteStringSource

Computes HMAC over SHA-256 and return the result as a bytestring.

hmacDRBGNew :: EntropyInput -> Nonce -> PersString -> WorkingStateSource

hmacDRBGRsd :: WorkingState -> EntropyInput -> AdditionalInput -> WorkingStateSource

murmurHash3 :: Word32 -> ByteString -> Word32Source

MurmurHash3 (x86_32). For more details, see http://code.google.com/p/smhasher/source/browse/trunk/MurmurHash3.cpp This code is used in the bloom filters of SPV nodes.

split512 :: Word512 -> (Word256, Word256)Source

Split a Word512 into a pair of Word256.

join512 :: (Word256, Word256) -> Word512Source

Join a pair of Word256 into a Word512.

decodeCompact :: Word32 -> IntegerSource

Decode the compact number used in the difficulty target of a block into an Integer.

As described in the Satoshi reference implementation srcbignum.h:

The compact format is a representation of a whole number N using an unsigned 32bit number similar to a floating point format. The most significant 8 bits are the unsigned exponent of base 256. This exponent can be thought of as number of bytes of N. The lower 23 bits are the mantissa. Bit number 24 (0x800000) represents the sign of N.

    N = (-1^sign) * mantissa * 256^(exponent-3)

encodeCompact :: Integer -> Word32Source

Encode an Integer to the compact number format used in the difficulty target of a block.

txHash :: Tx -> TxHashSource

Computes the hash of a transaction.

cbHash :: CoinbaseTx -> TxHashSource

Computes the hash of a coinbase transaction.

headerHash :: BlockHeader -> BlockHashSource

Compute the hash of a block header

type TxHash = BigWord Mod256TxSource

Type representing a transaction hash.

type BlockHash = BigWord Mod256BlockSource

Type representing a block hash.

type Word512 = BigWord Mod512Source

Data type representing a 512 bit unsigned integer. It is implemented as an Integer modulo 2^512.

type Word256 = BigWord Mod256Source

Data type representing a 256 bit unsigned integer. It is implemented as an Integer modulo 2^256.

type Word160 = BigWord Mod160Source

Data type representing a 160 bit unsigned integer. It is implemented as an Integer modulo 2^160.

type Word128 = BigWord Mod128Source

Data type representing a 128 bit unsigned integer. It is implemented as an Integer modulo 2^128.

type FieldP = BigWord ModPSource

Data type representing an Integer modulo coordinate field order P.

type FieldN = BigWord ModNSource

Data type representing an Integer modulo curve order N.

newtype BigWord n Source

Constructors

BigWord 

encodeTxHashLE :: TxHash -> StringSource

Encodes a TxHash as little endian in HEX format. This is mostly used for displaying transaction ids. Internally, these ids are handled as big endian but are transformed to little endian when displaying them.

decodeTxHashLE :: String -> Maybe TxHashSource

Decodes a little endian TxHash in HEX format.

encodeBlockHashLE :: BlockHash -> StringSource

Encodes a BlockHash as little endian in HEX format. This is mostly used for displaying Block hash ids. Internally, these ids are handled as big endian but are transformed to little endian when displaying them.

decodeBlockHashLE :: String -> Maybe BlockHashSource

Decodes a little endian BlockHash in HEX format.

data Point Source

Elliptic curves of the form y^2 = x^3 + 7 (mod p) Point on the elliptic curve in transformed Jacobian coordinates (X,Y,Z) such that (x,y) = (XZ^2, YZ^3) InfPoint is the point at infinity

Constructors

InfPoint 

data Address Source

Data type representing a Bitcoin address

Constructors

PubKeyAddress

Public Key Hash Address

Fields

getAddrHash :: Word160
 
ScriptAddress

Script Hash Address

Fields

getAddrHash :: Word160
 

addrToBase58 :: Address -> StringSource

Transforms an Address into a base58 encoded String

base58ToAddr :: String -> Maybe AddressSource

Decodes an Address from a base58 encoded String. This function can fail if the String is not properly encoded as base58 or the checksum fails.

encodeBase58 :: ByteString -> ByteStringSource

Encode a bytestring to a base 58 representation.

decodeBase58 :: ByteString -> Maybe ByteStringSource

Decode a base 58 encoded bytestring. This can fail if the input bytestring contains invalid base 58 characters such as 0,O,l,I

encodeBase58Check :: ByteString -> ByteStringSource

Computes a checksum for the input bytestring and encodes the input and the checksum to a base 58 representation.

decodeBase58Check :: ByteString -> Maybe ByteStringSource

Decode a base 58 encoded bytestring that contains a checksum. This function returns Nothing if the input bytestring contains invalid base 58 characters or if the checksum fails.

data PubKey Source

Elliptic curve public key type. Two constructors are provided for creating compressed and uncompressed public keys from a Point. The use of compressed keys is preferred as it produces shorter keys without compromising security. Uncompressed keys are supported for backwards compatibility.

Constructors

PubKey

Compressed public key

Fields

pubKeyPoint :: !Point
 
PubKeyU

Uncompressed public key

Fields

pubKeyPoint :: !Point
 

isValidPubKey :: PubKey -> BoolSource

Returns True if the public key is valid. This will check if the public key point lies on the curve.

isPubKeyU :: PubKey -> BoolSource

Returns True if the public key is uncompressed

derivePubKey :: PrvKey -> PubKeySource

Derives a public key from a private key. This function will preserve information on key compression (PrvKey becomes PubKey and PrvKeyU becomes PubKeyU)

pubKeyAddr :: PubKey -> AddressSource

Computes an Address value from a public key

data PrvKey Source

Elliptic curve private key type. Two constructors are provided for creating compressed or uncompressed private keys. Compression information is stored in private key WIF formats and needs to be preserved to generate the correct addresses from the corresponding public key.

Constructors

PrvKey

Compressed private key

Fields

prvKeyFieldN :: !FieldN
 
PrvKeyU

Uncompressed private key

Fields

prvKeyFieldN :: !FieldN
 

isValidPrvKey :: Integer -> BoolSource

Returns True if the private key is valid. This will check if the integer value representing the private key is greater than 0 and smaller than the curve order N.

makePrvKey :: Integer -> Maybe PrvKeySource

Builds a compressed private key from an Integer value. Returns Nothing if the Integer would not produce a valid private key. For security, the Integer needs to be generated from a random source with sufficient entropy.

makePrvKeyU :: Integer -> Maybe PrvKeySource

Builds an uncompressed private key from an Integer value. Returns Nothing if the Integer would not produce a valid private key. For security, the Integer needs to be generated from a random source with sufficient entropy.

fromPrvKey :: PrvKey -> IntegerSource

Returns the Integer value of a private key

isPrvKeyU :: PrvKey -> BoolSource

Returns True of the private key is uncompressed

putPrvKey :: PrvKey -> PutSource

Serialize a private key into the Data.Binary.Put monad as a 32 byte big endian ByteString. This is useful when a constant length serialization format for private keys is required

getPrvKey :: Get PrvKeySource

Deserializes a compressed private key from the Data.Binary.Get monad as a 32 byte big endian ByteString.

getPrvKeyU :: Get PrvKeySource

Deserializes an uncompressed private key from the Data.Binary.Get monad as a 32 byte big endian ByteString

fromWIF :: String -> Maybe PrvKeySource

Decodes a private key from a WIF encoded String. This function can fail if the input string does not decode correctly as a base 58 string or if the checksum fails. http://en.bitcoin.it/wiki/Wallet_import_format

toWIF :: PrvKey -> StringSource

Encodes a private key into WIF format

curveG :: PointSource

G parameter of the EC curve expressed as a Point

data XPubKey Source

Data type representing an extended BIP32 public key.

Constructors

XPubKey 

Fields

xPubDepth :: !Word8

Depth in the tree of key derivations.

xPubParent :: !Word32

Fingerprint of the parent key.

xPubIndex :: !Word32

Key derivation index.

xPubChain :: !ChainCode

Chain code.

xPubKey :: !PubKey

The public key of this extended key node.

data XPrvKey Source

Data type representing an extended BIP32 private key. An extended key is a node in a tree of key derivations. It has a depth in the tree, a parent node and an index to differentiate it from other siblings.

Constructors

XPrvKey 

Fields

xPrvDepth :: !Word8

Depth in the tree of key derivations.

xPrvParent :: !Word32

Fingerprint of the parent key.

xPrvIndex :: !Word32

Key derivation index.

xPrvChain :: !ChainCode

Chain code.

xPrvKey :: !PrvKey

The private key of this extended key node.

makeXPrvKey :: ByteString -> Maybe XPrvKeySource

Build a BIP32 compatible extended private key from a bytestring. This will produce a root node (depth=0 and parent=0).

deriveXPubKey :: XPrvKey -> XPubKeySource

Derive an extended public key from an extended private key. This function will preserve the depth, parent, index and chaincode fields of the extended private keys.

prvSubKeySource

Arguments

:: XPrvKey

Extended parent private key

-> Word32

Child derivation index

-> Maybe XPrvKey

Extended child private key

Compute a private, non-prime child key derivation. A private non-prime derivation will allow the equivalent extended public key to derive the public key for this child. Given a parent key m and a derivation index i, this function will compute m/i/.

Non-prime derivations allow for more flexibility such as read-only wallets. However, care must be taken not the leak both the parent extended public key and one of the extended child private keys as this would compromise the extended parent private key.

pubSubKeySource

Arguments

:: XPubKey

Extended Parent public key

-> Word32

Child derivation index

-> Maybe XPubKey

Extended child public key

Compute a public, non-prime child key derivation. Given a parent key M and a derivation index i, this function will compute M/i/.

primeSubKeySource

Arguments

:: XPrvKey

Extended Parent private key

-> Word32

Child derivation index

-> Maybe XPrvKey

Extended child private key

Compute a prime child key derivation. Prime derivations can only be computed for private keys. Prime derivations do not allow the parent public key to derive the child public keys. However, they are safer as a breach of the parent public key and child private keys does not lead to a breach of the parent private key. Given a parent key m and a derivation index i, this function will compute m/i'/.

prvSubKeys :: XPrvKey -> Word32 -> [(XPrvKey, Word32)]Source

Cyclic list of all private non-prime child key derivations of a parent key starting from an offset index.

pubSubKeys :: XPubKey -> Word32 -> [(XPubKey, Word32)]Source

Cyclic list of all public non-prime child key derivations of a parent key starting from an offset index.

primeSubKeys :: XPrvKey -> Word32 -> [(XPrvKey, Word32)]Source

Cyclic list of all prime child key derivations of a parent key starting from an offset index.

mulSigSubKeySource

Arguments

:: [XPubKey]

List of extended parent public keys

-> Word32

Child key derivation index

-> Maybe [XPubKey]

List of extended child public keys

Compute a public, non-prime subkey derivation for all of the parent public keys in the input. This function will succeed only if the child key derivations for all the parent keys are valid.

This function is intended to be used in the context of multisignature accounts. Parties exchanging their master public keys to create a multisignature account can then individually generate all the receiving multisignature addresses without further communication.

mulSigSubKeys :: [XPubKey] -> Word32 -> [([XPubKey], Word32)]Source

Cyclic list of all public, non-prime multisig key derivations of a list of parent keys starting from an offset index.

xPrvIsPrime :: XPrvKey -> BoolSource

Returns True if the extended private key was derived through a prime derivation.

xPubIsPrime :: XPubKey -> BoolSource

Returns True if the extended public key was derived through a prime derivation.

xPrvChild :: XPrvKey -> Word32Source

Returns the derivation index of this extended private key without the prime bit set.

xPubChild :: XPubKey -> Word32Source

Returns the derivation index of this extended public key without the prime bit set.

xPubID :: XPubKey -> Word160Source

Computes the key identifier of an extended public key.

xPrvID :: XPrvKey -> Word160Source

Computes the key identifier of an extended private key.

xPubFP :: XPubKey -> Word32Source

Computes the key fingerprint of an extended public key.

xPrvFP :: XPrvKey -> Word32Source

Computes the key fingerprint of an extended private key.

xPubAddr :: XPubKey -> AddressSource

Computer the Address of an extended public key.

xPubExport :: XPubKey -> StringSource

Exports an extended public key to the BIP32 key export format (base 58).

xPrvExport :: XPrvKey -> StringSource

Exports an extended private key to the BIP32 key export format (base 58).

xPubImport :: String -> Maybe XPubKeySource

Decodes a BIP32 encoded extended public key. This function will fail if invalid base 58 characters are detected or if the checksum fails.

xPrvImport :: String -> Maybe XPrvKeySource

Decodes a BIP32 encoded extended private key. This function will fail if invalid base 58 characters are detected or if the checksum fails.

xPrvWIF :: XPrvKey -> StringSource

Export an extended private key to WIF (Wallet Import Format).

newtype MasterKey Source

Data type representing an extended private key at the root of the derivation tree. Master keys have depth 0 and no parents. They are represented as m/ in BIP32 notation.

Constructors

MasterKey 

Fields

masterKey :: XPrvKey
 

newtype AccPrvKey Source

Data type representing a private account key. Account keys are generated from a MasterKey through prime derivation. This guarantees that the MasterKey will not be compromised if the account key is compromised. AccPrvKey is represented as m/i'/ in BIP32 notation.

Constructors

AccPrvKey 

newtype AccPubKey Source

Data type representing a public account key. It is computed through derivation from an AccPrvKey. It can not be derived from the MasterKey directly (property of prime derivation). It is represented as M/i'/ in BIP32 notation. AccPubKey is used for generating receiving payment addresses without the knowledge of the AccPrvKey.

Constructors

AccPubKey 

newtype AddrPrvKey Source

Data type representing a private address key. Private address keys are generated through a non-prime derivation from an AccPrvKey. Non-prime derivation is used so that the public account key can generate the receiving payment addresses without knowledge of the private account key. AccPrvKey is represented as m/i'/0/j/ in BIP32 notation if it is a regular receiving address. Internal (change) addresses are represented as m/i'/1/j/. Non-prime subtree 0 is used for regular receiving addresses and non-prime subtree 1 for internal (change) addresses.

Constructors

AddrPrvKey 

newtype AddrPubKey Source

Data type representing a public address key. They are generated through non-prime derivation from an AccPubKey. This is a useful feature for read-only wallets. They are represented as M/i'/0/j in BIP32 notation for regular receiving addresses and by M/i'/1/j for internal (change) addresses.

Constructors

AddrPubKey 

loadMasterKey :: XPrvKey -> Maybe MasterKeySource

Load a MasterKey from an XPrvKey. This function will fail if the extended private key does not have the properties of a MasterKey.

loadPrvAcc :: XPrvKey -> Maybe AccPrvKeySource

Load a private account key from an XPrvKey. This function will fail if the extended private key does not have the properties of a AccPrvKey.

loadPubAcc :: XPubKey -> Maybe AccPubKeySource

Load a public account key from an XPubKey. This function will fail if the extended public key does not have the properties of a AccPubKey.

addr :: AddrPubKey -> AddressSource

Computes an Address from an AddrPubKey.

accPrvKey :: MasterKey -> KeyIndex -> Maybe AccPrvKeySource

Computes an AccPrvKey from a MasterKey and a derivation index.

accPubKey :: MasterKey -> KeyIndex -> Maybe AccPubKeySource

Computes an AccPubKey from a MasterKey and a derivation index.

extPrvKey :: AccPrvKey -> KeyIndex -> Maybe AddrPrvKeySource

Computes an external AddrPrvKey from an AccPrvKey and a derivation index.

extPubKey :: AccPubKey -> KeyIndex -> Maybe AddrPubKeySource

Computes an external AddrPubKey from an AccPubKey and a derivation index.

intPrvKey :: AccPrvKey -> KeyIndex -> Maybe AddrPrvKeySource

Computes an internal AddrPrvKey from an AccPrvKey and a derivation index.

intPubKey :: AccPubKey -> KeyIndex -> Maybe AddrPubKeySource

Computes an internal AddrPubKey from an AccPubKey and a derivation index.

accPrvKeys :: MasterKey -> KeyIndex -> [(AccPrvKey, KeyIndex)]Source

Cyclic list of all valid AccPrvKey derived from a MasterKey and starting from an offset index.

accPubKeys :: MasterKey -> KeyIndex -> [(AccPubKey, KeyIndex)]Source

Cyclic list of all valid AccPubKey derived from a MasterKey and starting from an offset index.

extPrvKeys :: AccPrvKey -> KeyIndex -> [(AddrPrvKey, KeyIndex)]Source

Cyclic list of all valid external AddrPrvKey derived from a AccPrvKey and starting from an offset index.

extPubKeys :: AccPubKey -> KeyIndex -> [(AddrPubKey, KeyIndex)]Source

Cyclic list of all valid external AddrPubKey derived from a AccPubKey and starting from an offset index.

intPrvKeys :: AccPrvKey -> KeyIndex -> [(AddrPrvKey, KeyIndex)]Source

Cyclic list of all internal AddrPrvKey derived from a AccPrvKey and starting from an offset index.

intPubKeys :: AccPubKey -> KeyIndex -> [(AddrPubKey, KeyIndex)]Source

Cyclic list of all internal AddrPubKey derived from a AccPubKey and starting from an offset index.

extAddr :: AccPubKey -> KeyIndex -> Maybe AddressSource

Computes an external address from an AccPubKey and a derivation index.

intAddr :: AccPubKey -> KeyIndex -> Maybe AddressSource

Computes an internal addres from an AccPubKey and a derivation index.

extAddrs :: AccPubKey -> KeyIndex -> [(Address, KeyIndex)]Source

Cyclic list of all external addresses derived from a AccPubKey and starting from an offset index.

intAddrs :: AccPubKey -> KeyIndex -> [(Address, KeyIndex)]Source

Cyclic list of all internal addresses derived from a AccPubKey and starting from an offset index.

extAddrs' :: AccPubKey -> KeyIndex -> [(Address, KeyIndex)]Source

Same as extAddrs with the list reversed.

intAddrs' :: AccPubKey -> KeyIndex -> [(Address, KeyIndex)]Source

Same as intAddrs with the list reversed.

extMulSigKey :: AccPubKey -> [XPubKey] -> KeyIndex -> Maybe [AddrPubKey]Source

Computes a list of external AddrPubKey from an AccPubKey, a list of thirdparty multisig keys and a derivation index. This is useful for computing the public keys associated with a derivation index for multisig accounts.

intMulSigKey :: AccPubKey -> [XPubKey] -> KeyIndex -> Maybe [AddrPubKey]Source

Computes a list of internal AddrPubKey from an AccPubKey, a list of thirdparty multisig keys and a derivation index. This is useful for computing the public keys associated with a derivation index for multisig accounts.

extMulSigKeys :: AccPubKey -> [XPubKey] -> KeyIndex -> [([AddrPubKey], KeyIndex)]Source

Cyclic list of all external multisignature AddrPubKey derivations starting from an offset index.

intMulSigKeys :: AccPubKey -> [XPubKey] -> KeyIndex -> [([AddrPubKey], KeyIndex)]Source

Cyclic list of all internal multisignature AddrPubKey derivations starting from an offset index.

extMulSigAddr :: AccPubKey -> [XPubKey] -> Int -> KeyIndex -> Maybe AddressSource

Computes an external multisig address from an AccPubKey, a list of thirdparty multisig keys and a derivation index.

intMulSigAddr :: AccPubKey -> [XPubKey] -> Int -> KeyIndex -> Maybe AddressSource

Computes an internal multisig address from an AccPubKey, a list of thirdparty multisig keys and a derivation index.

extMulSigAddrs :: AccPubKey -> [XPubKey] -> Int -> KeyIndex -> [(Address, KeyIndex)]Source

Cyclic list of all external multisig addresses derived from an AccPubKey and a list of thirdparty multisig keys. The list starts at an offset index.

intMulSigAddrs :: AccPubKey -> [XPubKey] -> Int -> KeyIndex -> [(Address, KeyIndex)]Source

Cyclic list of all internal multisig addresses derived from an AccPubKey and a list of thirdparty multisig keys. The list starts at an offset index.

type SecretT m = StateT (SecretState m) mSource

StateT monad stack tracking the internal state of HMAC DRBG pseudo random number generator using SHA-256. The SecretT monad is run with the withSource function by providing it a source of entropy.

data Signature Source

Data type representing an ECDSA signature.

Constructors

Signature 

Fields

sigR :: !FieldN
 
sigS :: !FieldN
 

withSource :: Monad m => (Int -> m ByteString) -> SecretT m a -> m aSource

Run a SecretT monad by providing it a source of entropy. You can use devURandom, devRandom or provide your own entropy source function.

devURandom :: Int -> IO ByteStringSource

/dev/urandom entropy source. This is only available on machines supporting it. This function is meant to be used together with withSource.

devRandom :: Int -> IO ByteStringSource

/dev/random entropy source. This is only available on machines supporting it. This function is meant to be used together with withSource.

signMsg :: Monad m => Word256 -> PrvKey -> SecretT m SignatureSource

Safely sign a message inside the SecretT monad. The SecretT monad will generate a new nonce for each signature.

detSignMsg :: Word256 -> PrvKey -> SignatureSource

Sign a message using ECDSA deterministic signatures as defined by RFC 6979 http://tools.ietf.org/html/rfc6979

verifySig :: Word256 -> Signature -> PubKey -> BoolSource

Verify an ECDSA signature

genPrvKey :: Monad m => SecretT m PrvKeySource

Produce a new PrvKey randomly from the SecretT monad.

isCanonicalHalfOrder :: Signature -> BoolSource

Returns True if the S component of a Signature is <= order/2. Signatures need to pass this test to be canonical.

Data types

Entropy encoding and decoding

toMnemonic :: Entropy -> Either String MnemonicSource

Provide intial entropy as a ByteString of length multiple of 4 bytes. Output a mnemonic sentence.

fromMnemonic :: Mnemonic -> Either String EntropySource

Revert toMnemonic. Do not use this to generate seeds. Instead use mnemonicToSeed. This outputs the original entropy used to generate a mnemonic.

Generating 512-bit seeds

mnemonicToSeed :: Passphrase -> Mnemonic -> Either String SeedSource

Get a 512-bit seed from a mnemonic sentence. Will calculate checksum. Passphrase can be used to protect the mnemonic. Use an empty string as passphrase if none is required.

Helper functions

getBits :: Int -> ByteString -> ByteStringSource

Obtain Int bits from beginning of ByteString. Resulting ByteString will be smallest required to hold that many bits, padded with zeroes to the right.

calcTreeHeightSource

Arguments

:: Int

Number of transactions (leaf nodes).

-> Int

Height of the merkle tree.

Computes the height of a merkle tree.

calcTreeWidthSource

Arguments

:: Int

Number of transactions (leaf nodes).

-> Int

Height at which we want to compute the width.

-> Int

Width of the merkle tree.

Computes the width of a merkle tree at a specific height. The transactions are at height 0.

buildMerkleRootSource

Arguments

:: [TxHash]

List of transaction hashes (leaf nodes).

-> MerkleRoot

Root of the merkle tree.

Computes the root of a merkle tree from a list of leaf node hashes.

calcHashSource

Arguments

:: Int

Height of the node in the merkle tree.

-> Int

Position of the node (0 for the leftmost node).

-> [TxHash]

Transaction hashes of the merkle tree (leaf nodes).

-> Word256

Hash of the node at the specified position.

Computes the hash of a specific node in a merkle tree.

buildPartialMerkleSource

Arguments

:: [(TxHash, Bool)]

List of transactions hashes forming the leaves of the merkle tree and a bool indicating if that transaction should be included in the partial merkle tree.

-> (FlagBits, PartialMerkleTree)

Flag bits (used to parse the partial merkle tree) and the partial merkle tree.

Build a partial merkle tree.

extractMatchesSource

Arguments

:: FlagBits

Flag bits (produced by buildPartialMerkle).

-> PartialMerkleTree

Partial merkle tree.

-> Int

Number of transaction at height 0 (leaf nodes).

-> Either String (MerkleRoot, [TxHash])

Merkle root and the list of matching transaction hashes.

Extracts the matching hashes from a partial merkle tree. This will return the list of transaction hashes that have been included (set to True) in a call to buildPartialMerkle.

data BloomFilter Source

A bloom filter is a probabilistic data structure that SPV clients send to other peers to filter the set of transactions received from them. Bloom filters are probabilistic and have a false positive rate. Some transactions that pass the filter may not be relevant to the receiving peer. By controlling the false positive rate, SPV nodes can trade off bandwidth versus privacy.

Constructors

BloomFilter 

Fields

bloomData :: !(Seq Word8)

Bloom filter data

bloomHashFuncs :: !Word32

Number of hash functions for this filter

bloomTweak :: !Word32

Hash function random nonce

bloomFlags :: !BloomFlags

Bloom filter auto-update flags

data BloomFlags Source

The bloom flags are used to tell the remote peer how to auto-update the provided bloom filter.

Constructors

BloomUpdateNone

Never update

BloomUpdateAll

Auto-update on all outputs

BloomUpdateP2PubKeyOnly

Only auto-update on outputs that are pay-to-pubkey or pay-to-multisig. This is the default setting.

bloomCreateSource

Arguments

:: Int

Number of elements

-> Double

False positive rate

-> Word32

A random nonce (tweak) for the hash function. It should be a random number but the secureness of the random value is not of geat consequence.

-> BloomFlags

Bloom filter flags

-> BloomFilter

Bloom filter

Build a bloom filter that will provide the given false positive rate when the given number of elements have been inserted.

bloomInsertSource

Arguments

:: BloomFilter

Original bloom filter

-> ByteString

New data to insert

-> BloomFilter

Bloom filter containing the new data

Insert arbitrary data into a bloom filter. Returns the new bloom filter containing the new data.

bloomContainsSource

Arguments

:: BloomFilter

Bloom filter

-> ByteString

Data that will be checked against the given bloom filter

-> Bool

Returns True if the data matches the filter

Tests if some arbitrary data matches the filter. This can be either because the data was inserted into the filter or because it is a false positive.

isBloomValidSource

Arguments

:: BloomFilter

Bloom filter to test

-> Bool

True if the given filter is valid

Tests if a given bloom filter is valid.

isBloomEmpty :: BloomFilter -> BoolSource

Returns True if the filter is empty (all bytes set to 0x00)

isBloomFull :: BloomFilter -> BoolSource

Returns True if the filter is full (all bytes set to 0xff)

data Message Source

The Message type is used to identify all the valid messages that can be sent between bitcoin peers. Only values of type Message will be accepted by other bitcoin peers as bitcoin protocol messages need to be correctly serialized with message headers. Serializing a Message value will include the MessageHeader with the correct checksum value automatically. No need to add the MessageHeader separately.

data MessageHeader Source

Data type representing the header of a Message. All messages sent between nodes contain a message header.

Constructors

MessageHeader 

Fields

headMagic :: !Word32

Network magic bytes. It is used to differentiate messages meant for different bitcoin networks, such as prodnet and testnet.

headCmd :: !MessageCommand

Message command identifying the type of message. included in the payload.

headPayloadSize :: !Word32

Byte length of the payload.

headChecksum :: !CheckSum32

Checksum of the payload.

data Addr Source

Provides information on known nodes in the bitcoin network. An Addr type is sent inside a Message as a response to a GetAddr message.

Constructors

Addr 

type NetworkAddressTime = (Word32, NetworkAddress)Source

Network address with a timestamp

data Alert Source

Data type describing signed messages that can be sent between bitcoin nodes to display important notifications to end users about the health of the network.

Constructors

Alert 

Fields

alertPayload :: !VarString

Alert payload.

alertSignature :: !VarString

ECDSA signature of the payload

data Block Source

Data type describing a block in the bitcoin protocol. Blocks are sent in response to GetData messages that are requesting information from a block hash.

Constructors

Block 

Fields

blockHeader :: !BlockHeader

Header information for this block.

blockCoinbaseTx :: !CoinbaseTx

Coinbase transaction of this block.

blockTxns :: ![Tx]

List of transactions pertaining to this block.

data BlockHeader Source

Data type recording information on a Block. The hash of a block is defined as the hash of this data structure. The block mining process involves finding a partial hash collision by varying the nonce in the BlockHeader and/or additional randomness in the CoinbaseTx of this Block. Variations in the CoinbaseTx will result in different merkle roots in the BlockHeader.

Constructors

BlockHeader 

Fields

blockVersion :: !Word32

Block version information, based on the version of the software creating this block.

prevBlock :: !BlockHash

Hash of the previous block (parent) referenced by this block.

merkleRoot :: !Word256

Root of the merkle tree of all transactions pertaining to this block.

blockTimestamp :: !Word32

Unix timestamp recording when this block was created

blockBits :: !Word32

The difficulty target being used for this block

bhNonce :: !Word32

A random nonce used to generate this block. Additional randomness is included in the coinbase transaction of this block.

data BloomFlags Source

The bloom flags are used to tell the remote peer how to auto-update the provided bloom filter.

Constructors

BloomUpdateNone

Never update

BloomUpdateAll

Auto-update on all outputs

BloomUpdateP2PubKeyOnly

Only auto-update on outputs that are pay-to-pubkey or pay-to-multisig. This is the default setting.

data BloomFilter Source

A bloom filter is a probabilistic data structure that SPV clients send to other peers to filter the set of transactions received from them. Bloom filters are probabilistic and have a false positive rate. Some transactions that pass the filter may not be relevant to the receiving peer. By controlling the false positive rate, SPV nodes can trade off bandwidth versus privacy.

Constructors

BloomFilter 

Fields

bloomData :: !(Seq Word8)

Bloom filter data

bloomHashFuncs :: !Word32

Number of hash functions for this filter

bloomTweak :: !Word32

Hash function random nonce

bloomFlags :: !BloomFlags

Bloom filter auto-update flags

newtype FilterLoad Source

Set a new bloom filter on the peer connection.

Constructors

FilterLoad 

newtype FilterAdd Source

Add the given data element to the connections current filter without requiring a completely new one to be set.

Constructors

FilterAdd 

data GetBlocks Source

Data type representing a GetBlocks message request. It is used in the bitcoin protocol to retrieve blocks from a peer by providing it a BlockLocator object. The BlockLocator is a sparse list of block hashes from the caller node with the purpose of informing the receiving node about the state of the caller's blockchain. The receiver node will detect a wrong branch in the caller's main chain and send the caller appropriate Blocks. The response to a GetBlocks message is an Inv message containing the list of block hashes pertaining to the request.

Constructors

GetBlocks 

Fields

getBlocksVersion :: !Word32

The protocol version

getBlocksLocator :: !BlockLocator

Block locator object. It is a list of block hashes from the most recent block back to the genesis block. The list is dense at first and sparse towards the end.

getBlocksHashStop :: !BlockHash

Hash of the last desired block. If set to zero, the maximum number of block hashes is returned (500).

data GetData Source

The GetData type is used to retrieve information on a specific object (Block or Tx) identified by the objects hash. The payload of a GetData request is a list of InvVector which represent all the hashes for which a node wants to request information. The response to a GetBlock message wille be either a Block or a Tx message depending on the type of the object referenced by the hash. Usually, GetData messages are sent after a node receives an Inv message to obtain information on unknown object hashes.

Constructors

GetData 

Fields

getDataList :: ![InvVector]

List of object hashes

data GetHeaders Source

Similar to the GetBlocks message type but for retrieving block headers only. The response to a GetHeaders request is a Headers message containing a list of block headers pertaining to the request. A maximum of 2000 block headers can be returned. GetHeaders is used by thin (SPV) clients to exclude block contents when synchronizing the blockchain.

Constructors

GetHeaders 

Fields

getHeadersVersion :: !Word32

The protocol version

getHeadersBL :: !BlockLocator

Block locator object. It is a list of block hashes from the most recent block back to the Genesis block. The list is dense at first and sparse towards the end.

getHeadersHashStop :: !BlockHash

Hash of the last desired block header. When set to zero, the maximum number of block headers is returned (2000)

data Headers Source

The Headers type is used to return a list of block headers in response to a GetHeaders message.

Constructors

Headers 

Fields

headersList :: ![BlockHeaderCount]

List of block headers with respective transaction counts

type BlockHeaderCount = (BlockHeader, VarInt)Source

BlockHeader type with a transaction count as VarInt

data Inv Source

Inv messages are used by nodes to advertise their knowledge of new objects by publishing a list of hashes. Inv messages can be sent unsolicited or in response to a GetBlocks message.

Constructors

Inv 

Fields

invList :: ![InvVector]

Inventory vectors

data InvVector Source

Invectory vectors represent hashes identifying objects such as a Block or a Tx. They are sent inside messages to notify other peers about new data or data they have requested.

Constructors

InvVector 

Fields

invType :: !InvType

Type of the object referenced by this inventory vector

invHash :: !Word256

Hash of the object referenced by this inventory vector

data InvType Source

Data type identifying the type of an inventory vector.

Constructors

InvError

Error. Data containing this type can be ignored.

InvTx

InvVector hash is related to a transaction

InvBlock

InvVector hash is related to a block

InvMerkleBlock

InvVector has is related to a merkle block

data MerkleBlock Source

Constructors

MerkleBlock 

Fields

merkleHeader :: !BlockHeader

Header information for this merkle block.

merkleTotalTxns :: !Word32

Number of transactions in the block (including unmatched transactions).

mHashes :: ![Word256]

Hashes in depth-first order. They are used to rebuild a partial merkle tree.

mFlags :: ![Bool]

Flag bits, packed per 8 in a byte. Least significant bit first. Flag bits are used to rebuild a partial merkle tree.

data NetworkAddress Source

Data type describing a bitcoin network address. Addresses are stored in IPv6. IPv4 addresses are mapped to IPv6 using IPv4 mapped IPv6 addresses: http://en.wikipedia.org/wiki/IPv6#IPv4-mapped_IPv6_addresses. Sometimes, timestamps are sent together with the NetworkAddress such as in the Addr data type.

Constructors

NetworkAddress 

Fields

naServices :: !Word64

Bitmask of services available for this address

naAddress :: !(Word64, Word64)

IPv6 address serialized as big endian

naPort :: !Word16

Port number serialized as big endian

data NotFound Source

A NotFound message is returned as a response to a GetData message whe one of the requested objects could not be retrieved. This could happen, for example, if a tranasaction was requested and was not available in the memory pool of the receiving node.

Constructors

NotFound 

Fields

notFoundList :: ![InvVector]

Inventory vectors related to this request

newtype Ping Source

A Ping message is sent to bitcoin peers to check if a TCP/IP connection is still valid.

Constructors

Ping 

Fields

pingNonce :: Word64

A random nonce used to identify the recipient of the ping request once a Pong response is received.

newtype Pong Source

A Pong message is sent as a response to a ping message.

Constructors

Pong 

Fields

pongNonce :: Word64

When responding to a Ping request, the nonce from the Ping is copied in the Pong response.

data Reject Source

The reject message is sent when messages are rejected by a peer.

Constructors

Reject 

Fields

rejectMessage :: !MessageCommand

Type of message rejected

rejectCode :: !RejectCode

Code related to the rejected message

rejectReason :: !VarString

Text version of rejected reason

reject :: MessageCommand -> RejectCode -> String -> RejectSource

Convenience function to build a Reject message

data Tx Source

Data type representing a bitcoin transaction

Constructors

Tx 

Fields

txVersion :: !Word32

Transaction data format version

txIn :: ![TxIn]

List of transaction inputs

txOut :: ![TxOut]

List of transaction outputs

txLockTime :: !Word32

The block number of timestamp at which this transaction is locked

data TxIn Source

Data type representing a transaction input.

Constructors

TxIn 

Fields

prevOutput :: !OutPoint

Reference the previous transaction output (hash + position)

scriptInput :: !ByteString

Script providing the requirements of the previous transaction output to spend those coins.

txInSequence :: !Word32

Transaction version as defined by the sender of the transaction. The intended use is for replacing transactions with new information before the transaction is included in a block.

data TxOut Source

Data type representing a transaction output.

Constructors

TxOut 

Fields

outValue :: !Word64

Transaction output value.

scriptOutput :: !ByteString

Script specifying the conditions to spend this output.

data OutPoint Source

The OutPoint is used inside a transaction input to reference the previous transaction output that it is spending.

Constructors

OutPoint 

Fields

outPointHash :: !TxHash

The hash of the referenced transaction.

outPointIndex :: !Word32

The position of the specific output in the transaction. The first output position is 0.

data CoinbaseTx Source

Data type representing the coinbase transaction of a Block. Coinbase transactions are special types of transactions which are created by miners when they find a new block. Coinbase transactions have no inputs. They have outputs sending the newly generated bitcoins together with all the block's fees to a bitcoin address (usually the miners address). Data can be embedded in a Coinbase transaction which can be chosen by the miner of a block. This data also typically contains some randomness which is used, together with the nonce, to find a partial hash collision on the block's hash.

Constructors

CoinbaseTx 

Fields

cbVersion :: !Word32

Transaction data format version.

cbPrevOutput :: !OutPoint

Previous outpoint. This is ignored for coinbase transactions but preserved for computing the correct txid.

cbData :: !ByteString

Data embedded inside the coinbase transaction.

cbInSequence :: !Word32

Transaction sequence number. This is ignored for coinbase transactions but preserved for computing the correct txid.

cbOut :: ![TxOut]

List of transaction outputs.

cbLockTime :: !Word32

The block number of timestamp at which this transaction is locked.

newtype VarInt Source

Data type representing a variable length integer. The VarInt type usually precedes an array or a string that can vary in length.

Constructors

VarInt 

Fields

getVarInt :: Word64
 

newtype VarString Source

Data type for variable length strings. Variable length strings are serialized as a VarInt followed by a bytestring.

Constructors

VarString 

data Version Source

When a bitcoin node creates an outgoing connection to another node, the first message it will send is a Version message. The other node will similarly respond with it's own Version message.

Constructors

Version 

Fields

version :: !Word32

Protocol version being used by the node.

services :: !Word64

Bitmask of features to enable for this connection.

timestamp :: !Word64

UNIX timestamp

addrRecv :: !NetworkAddress

Network address of the node receiving this message.

addrSend :: !NetworkAddress

Network address of the node sending this message.

verNonce :: !Word64

Randomly generated identifying sent with every version message. This nonce is used to detect connection to self.

userAgent :: !VarString

User agent

startHeight :: !Word32

The height of the last block received by the sending node.

relay :: !Bool

Wether the remote peer should announce relaying transactions or not. This feature is enabled since version >= 70001. See BIP37 for more details.

data MessageCommand Source

A MessageCommand is included in a MessageHeader in order to identify the type of message present in the payload. This allows the message de-serialization code to know how to decode a particular message payload. Every valid Message constructor has a corresponding MessageCommand constructor.

data Script Source

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 the spending signatures in the input of a transaction

Constructors

Script 

Fields

scriptOps :: ![ScriptOp]

List of script operators defining this script

data PushDataType Source

Data type representing the type of an OP_PUSHDATA opcode.

Constructors

OPCODE

The next opcode bytes is data to be pushed onto the stack

OPDATA1

The next byte contains the number of bytes to be pushed onto the stack

OPDATA2

The next two bytes contains the number of bytes to be pushed onto the stack

OPDATA4

The next four bytes contains the number of bytes to be pushed onto the stack

isPushOp :: ScriptOp -> BoolSource

Check whether opcode is only data.

opPushData :: ByteString -> ScriptOpSource

Optimally encode data using one of the 4 types of data pushing opcodes

data ScriptOutput Source

Data type describing standard transaction output scripts. Output scripts provide the conditions that must be fulfilled for someone to spend the output coins.

Constructors

PayPK

Pay to a public key.

PayPKHash

Pay to a public key hash.

PayMulSig

Pay to multiple public keys.

PayScriptHash

Pay to a script hash.

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.

Constructors

SpendPK

Spend the coins of a PayPK output.

SpendPKHash

Spend the coins of a PayPKHash output.

SpendMulSig

Spend the coins of a PayMulSig output.

scriptAddr :: ScriptOutput -> AddressSource

Computes a script address from a script output. This address can be used in a pay to script hash output.

scriptRecipient :: Script -> Either String AddressSource

Computes the recipient address of a script. This function fails if the script could not be decoded as a pay to public key hash or pay to script hash.

scriptSender :: Script -> Either String AddressSource

Computes the sender address of a script. This function fails if the script could not be decoded as a spend public key hash or script hash input.

encodeInputBS :: ScriptInput -> ByteStringSource

Similar to encodeInput but encodes to a ByteString

decodeInput :: Script -> Either String ScriptInputSource

Decodes a ScriptInput from a Script. This function fails if the script can not be parsed as a standard script input.

decodeInputBS :: ByteString -> Either String ScriptInputSource

Similar to decodeInput but decodes from a ByteString

encodeOutput :: ScriptOutput -> ScriptSource

Computes a Script from a ScriptOutput. The Script is a list of ScriptOp can can be used to build a Tx.

encodeOutputBS :: ScriptOutput -> ByteStringSource

Similar to encodeOutput but encodes to a ByteString

decodeOutput :: Script -> Either String ScriptOutputSource

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 ScriptOutputSource

Similar to decodeOutput but decodes from a ByteString

sortMulSig :: ScriptOutput -> ScriptOutputSource

Sorts the public keys of a multisignature output in ascending order by comparing their serialized representations. This feature allows for easier multisignature account management as participants in a multisignature wallet will blindly agree on an ordering of the public keys without having to communicate.

intToScriptOp :: Int -> ScriptOpSource

Transforms integers [1 .. 16] to ScriptOp [OP_1 .. OP_16]

scriptOpToInt :: ScriptOp -> Either String IntSource

Decode ScriptOp [OP_1 .. OP_16] to integers [1 .. 16]. This functions fails for other values of ScriptOp

isPayPK :: ScriptOutput -> BoolSource

Returns True if the script is a pay to public key output.

isPayPKHash :: ScriptOutput -> BoolSource

Returns True if the script is a pay to public key hash output.

isPayMulSig :: ScriptOutput -> BoolSource

Returns True if the script is a pay to multiple public keys output.

isPayScriptHash :: ScriptOutput -> BoolSource

Returns true if the script is a pay to script hash output.

isSpendPK :: ScriptInput -> BoolSource

Returns True if the input script is spending a public key.

isSpendPKHash :: ScriptInput -> BoolSource

Returns True if the input script is spending a public key hash.

isSpendMulSig :: ScriptInput -> BoolSource

Returns True if the input script is spending a multisignature output.

data SigHash Source

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 anyoneCanPay flag is True, then only the current input is signed. Otherwise, all of the inputs of a transaction are signed. The default value for anyoneCanPay is False.

Constructors

SigAll

Sign all of the outputs of a transaction (This is the default value). Changing any of the outputs of the transaction will invalidate the signature.

Fields

anyoneCanPay :: !Bool
 
SigNone

Sign none of the outputs of a transaction. This allows anyone to change any of the outputs of the transaction.

Fields

anyoneCanPay :: !Bool
 
SigSingle

Sign only the output corresponding the the current transaction input. You care about your own output in the transaction but you don't care about any of the other outputs.

Fields

anyoneCanPay :: !Bool
 
SigUnknown

Unrecognized sighash types will decode to SigUnknown.

encodeSigHash32 :: SigHash -> ByteStringSource

Encodes a SigHash to a 32 bit-long bytestring.

isSigAll :: SigHash -> BoolSource

Returns True if the SigHash has the value SigAll.

isSigNone :: SigHash -> BoolSource

Returns True if the SigHash has the value SigNone.

isSigSingle :: SigHash -> BoolSource

Returns True if the SigHash has the value SigSingle.

isSigUnknown :: SigHash -> BoolSource

Returns True if the SigHash has the value SigUnknown.

txSigHashSource

Arguments

:: Tx

Transaction to sign.

-> Script

Output script that is being spent.

-> Int

Index of the input that is being signed.

-> SigHash

What parts of the transaction should be signed.

-> Word256

Result hash to be signed.

Computes the hash that will be used for signing a transaction.

data TxSignature Source

Data type representing a Signature together with a SigHash. The SigHash is serialized as one byte at the end of a regular ECDSA Signature. All signatures in transaction inputs are of type TxSignature.

Constructors

TxSignature 

encodeSig :: TxSignature -> ByteStringSource

Serialize a TxSignature to a ByteString.

decodeCanonicalSig :: ByteString -> Either String TxSignatureSource

Decode a TxSignature from a ByteString. This function will check if the signature is canonical and fail if it is not.

Script evaluation

verifySpendSource

Arguments

:: Tx

The spending transaction

-> Int

The input index

-> Script

The output script we are spending

-> Bool 

Uses evalScript to check that the input script of a spending transaction satisfies the output script.

type SigCheck = [ScriptOp] -> TxSignature -> PubKey -> BoolSource

Defines the type of function required by script evaluating functions to check transaction signatures.

Evaluation data types

data Program Source

Data type of the evaluation state.

Instances

type Stack = [StackValue]Source

Helper functions

encodeInt :: Int64 -> StackValueSource

Encoding function for the stack value format of integers. Most significant bit defines sign.

decodeInt :: StackValue -> Maybe Int64Source

Inverse of encodeInt.

encodeBool :: Bool -> StackValueSource

decodeBool :: StackValue -> BoolSource

Conversion of StackValue to Bool (true if non-zero).

execScriptSource

Arguments

:: Script

scriptSig ( redeemScript )

-> Script

scriptPubKey

-> SigCheck

signature verification Function

-> Either EvalError Program 

data Coin Source

A Coin is an output of a transaction that can be spent by another transaction.

Constructors

Coin 

Fields

coinValue :: !Word64

Value in satoshi

coinScript :: !ScriptOutput

Output script

coinOutPoint :: !OutPoint

Previous outpoint

coinRedeem :: !(Maybe RedeemScript)

Redeem script

buildTx :: [OutPoint] -> [(ScriptOutput, Word64)] -> Either String TxSource

Build a transaction by providing a list of outpoints as inputs and a list of ScriptOutput and amounts as outputs.

buildAddrTx :: [OutPoint] -> [(String, Word64)] -> Either String TxSource

Build a transaction by providing a list of outpoints as inputs and a list of recipients addresses and amounts as outputs.

data SigInput Source

Data type used to specify the signing parameters of a transaction input. To sign an input, the previous output script, outpoint and sighash are required. When signing a pay to script hash output, an additional redeem script is required.

Constructors

SigInput 

Fields

sigDataOut :: !ScriptOutput

Output script to spend.

sigDataOP :: !OutPoint

Spending tranasction OutPoint

sigDataSH :: !SigHash

Signature type.

sigDataRedeem :: !(Maybe RedeemScript)

Redeem script

signTxSource

Arguments

:: Monad m 
=> Tx

Transaction to sign

-> [SigInput]

SigInput signing parameters

-> [PrvKey]

List of private keys to use for signing

-> EitherT String (SecretT m) (Tx, Bool)

(Signed transaction, Status)

Sign a transaction by providing the SigInput signing parameters and a list of private keys. The signature is computed within the SecretT monad to generate the random signing nonce. This function returns a transaction completion status. If false, some of the inputs are not fully signed or are non-standard.

signInput :: Monad m => Tx -> Int -> SigInput -> PrvKey -> EitherT String (SecretT m) (Tx, Bool)Source

Sign a single input in a transaction within the SecretT monad. This function will return a completion status only for that input. If false, that input is either non-standard or not fully signed.

detSignTxSource

Arguments

:: Tx

Transaction to sign

-> [SigInput]

SigInput signing parameters

-> [PrvKey]

List of private keys to use for signing

-> Either String (Tx, Bool)

(Signed transaction, Status)

Sign a transaction by providing the SigInput signing paramters and a list of private keys. The signature is computed deterministically as defined in RFC-6979. This function returns a transaction completion status. If false, some of the inputs are not fully signed or are non-standard.

detSignInput :: Tx -> Int -> SigInput -> PrvKey -> Either String (Tx, Bool)Source

Sign a single input in a transaction deterministically (RFC-6979). This function will return a completion status only for that input. If false, that input is either non-standard or not fully signed.

verifyStdTx :: Tx -> [(ScriptOutput, OutPoint)] -> BoolSource

Verify if a transaction is valid and all of its inputs are standard.

verifyStdInput :: Tx -> Int -> ScriptOutput -> BoolSource

Verify if a transaction input is valid and standard.

guessTxSizeSource

Arguments

:: Int

Number of regular transaction inputs.

-> [(Int, Int)]

For every multisig input in the transaction, provide the multisig parameters m of n (m,n) for that input.

-> Int

Number of pay to public key hash outputs.

-> Int

Number of pay to script hash outputs.

-> Int

Upper bound on the transaction size.

Computes an upper bound on the size of a transaction based on some known properties of the transaction.

chooseCoinsSource

Arguments

:: Word64

Target price to pay.

-> Word64

Fee price per 1000 bytes.

-> [Coin]

List of coins to choose from.

-> Either String ([Coin], Word64)

Coin selection result and change amount.

Coin selection algorithm for normal (non-multisig) transactions. This function returns the selected coins together with the amount of change to send back to yourself, taking the fee into account.

chooseMSCoinsSource

Arguments

:: Word64

Target price to pay.

-> Word64

Fee price per 1000 bytes.

-> (Int, Int)

Multisig parameters m of n (m,n).

-> [Coin]

List of coins to choose from.

-> Either String ([Coin], Word64)

Coin selection result and change amount.

Coin selection algorithm for multisignature transactions. This function returns the selected coins together with the amount of change to send back to yourself, taking the fee into account. This function assumes all the coins are script hash outputs that send funds to a multisignature address.