| Safe Haskell | None |
|---|
Network.Haskoin.Internals
Contents
Description
This module expose haskoin internals. No guarantee is made on the stability of the interface of these internal modules.
- extendedModGCD :: Integer -> Integer -> Integer -> (Integer, Integer)
- mulInverse :: Integer -> Integer -> Integer
- pairG :: (Integer, Integer)
- curveP :: Integer
- curveN :: Integer
- integerB :: Integer
- integerA :: Integer
- type CheckSum32 = Word32
- hash512 :: ByteString -> Word512
- hash256 :: ByteString -> Word256
- hashSha1 :: ByteString -> Word160
- hash160 :: ByteString -> Word160
- hash512BS :: ByteString -> ByteString
- hash256BS :: ByteString -> ByteString
- hashSha1BS :: ByteString -> ByteString
- hash160BS :: ByteString -> ByteString
- doubleHash256 :: ByteString -> Word256
- doubleHash256BS :: ByteString -> ByteString
- chksum32 :: ByteString -> CheckSum32
- hmac512 :: ByteString -> ByteString -> Word512
- hmac512BS :: ByteString -> ByteString -> ByteString
- hmac256 :: ByteString -> ByteString -> Word256
- hmac256BS :: ByteString -> ByteString -> ByteString
- hmacDRBGNew :: EntropyInput -> Nonce -> PersString -> WorkingState
- hmacDRBGUpd :: ProvidedData -> ByteString -> ByteString -> (ByteString, ByteString)
- hmacDRBGRsd :: WorkingState -> EntropyInput -> AdditionalInput -> WorkingState
- hmacDRBGGen :: WorkingState -> Word16 -> AdditionalInput -> (WorkingState, Maybe ByteString)
- type WorkingState = (ByteString, ByteString, Word16)
- murmurHash3 :: Word32 -> ByteString -> Word32
- split512 :: Word512 -> (Word256, Word256)
- join512 :: (Word256, Word256) -> Word512
- decodeCompact :: Word32 -> Integer
- encodeCompact :: Integer -> Word32
- txHash :: Tx -> TxHash
- cbHash :: CoinbaseTx -> TxHash
- headerHash :: BlockHeader -> BlockHash
- type TxHash = BigWord Mod256Tx
- type BlockHash = BigWord Mod256Block
- type Word512 = BigWord Mod512
- type Word256 = BigWord Mod256
- type Word160 = BigWord Mod160
- type Word128 = BigWord Mod128
- type FieldP = BigWord ModP
- type FieldN = BigWord ModN
- newtype BigWord n = BigWord {}
- class BigWordMod a where
- inverseP :: FieldP -> FieldP
- inverseN :: FieldN -> FieldN
- quadraticResidue :: FieldP -> [FieldP]
- isIntegerValidKey :: Integer -> Bool
- encodeTxHashLE :: TxHash -> String
- decodeTxHashLE :: String -> Maybe TxHash
- encodeBlockHashLE :: BlockHash -> String
- decodeBlockHashLE :: String -> Maybe BlockHash
- data Point = InfPoint
- makePoint :: FieldP -> FieldP -> Maybe Point
- makeInfPoint :: Point
- getAffine :: Point -> Maybe (FieldP, FieldP)
- getX :: Point -> Maybe FieldP
- getY :: Point -> Maybe FieldP
- validatePoint :: Point -> Bool
- isInfPoint :: Point -> Bool
- addPoint :: Point -> Point -> Point
- doublePoint :: Point -> Point
- mulPoint :: FieldN -> Point -> Point
- shamirsTrick :: FieldN -> Point -> FieldN -> Point -> Point
- curveB :: FieldP
- curveA :: FieldP
- data Address
- = PubKeyAddress { }
- | ScriptAddress { }
- addrToBase58 :: Address -> String
- base58ToAddr :: String -> Maybe Address
- encodeBase58 :: ByteString -> ByteString
- decodeBase58 :: ByteString -> Maybe ByteString
- encodeBase58Check :: ByteString -> ByteString
- decodeBase58Check :: ByteString -> Maybe ByteString
- data PubKey
- = PubKey {
- pubKeyPoint :: !Point
- | PubKeyU {
- pubKeyPoint :: !Point
- = PubKey {
- isValidPubKey :: PubKey -> Bool
- isPubKeyU :: PubKey -> Bool
- derivePubKey :: PrvKey -> PubKey
- pubKeyAddr :: PubKey -> Address
- data PrvKey
- = PrvKey {
- prvKeyFieldN :: !FieldN
- | PrvKeyU {
- prvKeyFieldN :: !FieldN
- = PrvKey {
- isValidPrvKey :: Integer -> Bool
- makePrvKey :: Integer -> Maybe PrvKey
- makePrvKeyU :: Integer -> Maybe PrvKey
- fromPrvKey :: PrvKey -> Integer
- isPrvKeyU :: PrvKey -> Bool
- putPrvKey :: PrvKey -> Put
- getPrvKey :: Get PrvKey
- getPrvKeyU :: Get PrvKey
- fromWIF :: String -> Maybe PrvKey
- toWIF :: PrvKey -> String
- curveG :: Point
- data XPubKey = XPubKey {}
- data XPrvKey = XPrvKey {}
- type ChainCode = Word256
- makeXPrvKey :: ByteString -> Maybe XPrvKey
- deriveXPubKey :: XPrvKey -> XPubKey
- prvSubKey :: XPrvKey -> Word32 -> Maybe XPrvKey
- pubSubKey :: XPubKey -> Word32 -> Maybe XPubKey
- primeSubKey :: XPrvKey -> Word32 -> Maybe XPrvKey
- prvSubKeys :: XPrvKey -> Word32 -> [(XPrvKey, Word32)]
- pubSubKeys :: XPubKey -> Word32 -> [(XPubKey, Word32)]
- primeSubKeys :: XPrvKey -> Word32 -> [(XPrvKey, Word32)]
- mulSigSubKey :: [XPubKey] -> Word32 -> Maybe [XPubKey]
- mulSigSubKeys :: [XPubKey] -> Word32 -> [([XPubKey], Word32)]
- xPrvIsPrime :: XPrvKey -> Bool
- xPubIsPrime :: XPubKey -> Bool
- xPrvChild :: XPrvKey -> Word32
- xPubChild :: XPubKey -> Word32
- xPubID :: XPubKey -> Word160
- xPrvID :: XPrvKey -> Word160
- xPubFP :: XPubKey -> Word32
- xPrvFP :: XPrvKey -> Word32
- xPubAddr :: XPubKey -> Address
- xPubExport :: XPubKey -> String
- xPrvExport :: XPrvKey -> String
- xPubImport :: String -> Maybe XPubKey
- xPrvImport :: String -> Maybe XPrvKey
- xPrvWIF :: XPrvKey -> String
- cycleIndex :: Word32 -> [Word32]
- cycleIndex' :: Word32 -> [Word32]
- addPubKeys :: PubKey -> Word256 -> Maybe PubKey
- addPrvKeys :: PrvKey -> Word256 -> Maybe PrvKey
- newtype MasterKey = MasterKey {}
- newtype AccPrvKey = AccPrvKey {}
- newtype AccPubKey = AccPubKey {}
- newtype AddrPrvKey = AddrPrvKey {}
- newtype AddrPubKey = AddrPubKey {}
- type KeyIndex = Word32
- makeMasterKey :: ByteString -> Maybe MasterKey
- loadMasterKey :: XPrvKey -> Maybe MasterKey
- loadPrvAcc :: XPrvKey -> Maybe AccPrvKey
- loadPubAcc :: XPubKey -> Maybe AccPubKey
- addr :: AddrPubKey -> Address
- accPrvKey :: MasterKey -> KeyIndex -> Maybe AccPrvKey
- accPubKey :: MasterKey -> KeyIndex -> Maybe AccPubKey
- extPrvKey :: AccPrvKey -> KeyIndex -> Maybe AddrPrvKey
- extPubKey :: AccPubKey -> KeyIndex -> Maybe AddrPubKey
- intPrvKey :: AccPrvKey -> KeyIndex -> Maybe AddrPrvKey
- intPubKey :: AccPubKey -> KeyIndex -> Maybe AddrPubKey
- accPrvKeys :: MasterKey -> KeyIndex -> [(AccPrvKey, KeyIndex)]
- accPubKeys :: MasterKey -> KeyIndex -> [(AccPubKey, KeyIndex)]
- extPrvKeys :: AccPrvKey -> KeyIndex -> [(AddrPrvKey, KeyIndex)]
- extPubKeys :: AccPubKey -> KeyIndex -> [(AddrPubKey, KeyIndex)]
- intPrvKeys :: AccPrvKey -> KeyIndex -> [(AddrPrvKey, KeyIndex)]
- intPubKeys :: AccPubKey -> KeyIndex -> [(AddrPubKey, KeyIndex)]
- extAddr :: AccPubKey -> KeyIndex -> Maybe Address
- intAddr :: AccPubKey -> KeyIndex -> Maybe Address
- extAddrs :: AccPubKey -> KeyIndex -> [(Address, KeyIndex)]
- intAddrs :: AccPubKey -> KeyIndex -> [(Address, KeyIndex)]
- extAddrs' :: AccPubKey -> KeyIndex -> [(Address, KeyIndex)]
- intAddrs' :: AccPubKey -> KeyIndex -> [(Address, KeyIndex)]
- extMulSigKey :: AccPubKey -> [XPubKey] -> KeyIndex -> Maybe [AddrPubKey]
- intMulSigKey :: AccPubKey -> [XPubKey] -> KeyIndex -> Maybe [AddrPubKey]
- extMulSigKeys :: AccPubKey -> [XPubKey] -> KeyIndex -> [([AddrPubKey], KeyIndex)]
- intMulSigKeys :: AccPubKey -> [XPubKey] -> KeyIndex -> [([AddrPubKey], KeyIndex)]
- extMulSigAddr :: AccPubKey -> [XPubKey] -> Int -> KeyIndex -> Maybe Address
- intMulSigAddr :: AccPubKey -> [XPubKey] -> Int -> KeyIndex -> Maybe Address
- extMulSigAddrs :: AccPubKey -> [XPubKey] -> Int -> KeyIndex -> [(Address, KeyIndex)]
- intMulSigAddrs :: AccPubKey -> [XPubKey] -> Int -> KeyIndex -> [(Address, KeyIndex)]
- type SecretT m = StateT (SecretState m) m
- data Signature = Signature {}
- withSource :: Monad m => (Int -> m ByteString) -> SecretT m a -> m a
- devURandom :: Int -> IO ByteString
- devRandom :: Int -> IO ByteString
- signMsg :: Monad m => Word256 -> PrvKey -> SecretT m Signature
- detSignMsg :: Word256 -> PrvKey -> Signature
- unsafeSignMsg :: Word256 -> FieldN -> (FieldN, Point) -> Maybe Signature
- verifySig :: Word256 -> Signature -> PubKey -> Bool
- genPrvKey :: Monad m => SecretT m PrvKey
- isCanonicalHalfOrder :: Signature -> Bool
- type Entropy = ByteString
- type Mnemonic = String
- type Passphrase = String
- type Seed = ByteString
- toMnemonic :: Entropy -> Either String Mnemonic
- fromMnemonic :: Mnemonic -> Either String Entropy
- mnemonicToSeed :: Passphrase -> Mnemonic -> Either String Seed
- getBits :: Int -> ByteString -> ByteString
- calcTreeHeight :: Int -> Int
- calcTreeWidth :: Int -> Int -> Int
- buildMerkleRoot :: [TxHash] -> MerkleRoot
- calcHash :: Int -> Int -> [TxHash] -> Word256
- buildPartialMerkle :: [(TxHash, Bool)] -> (FlagBits, PartialMerkleTree)
- extractMatches :: FlagBits -> PartialMerkleTree -> Int -> Either String (MerkleRoot, [TxHash])
- data BloomFilter = BloomFilter {
- bloomData :: !(Seq Word8)
- bloomHashFuncs :: !Word32
- bloomTweak :: !Word32
- bloomFlags :: !BloomFlags
- data BloomFlags
- bloomCreate :: Int -> Double -> Word32 -> BloomFlags -> BloomFilter
- bloomInsert :: BloomFilter -> ByteString -> BloomFilter
- bloomContains :: BloomFilter -> ByteString -> Bool
- isBloomValid :: BloomFilter -> Bool
- isBloomEmpty :: BloomFilter -> Bool
- isBloomFull :: BloomFilter -> Bool
- data Message
- = MVersion !Version
- | MVerAck
- | MAddr !Addr
- | MInv !Inv
- | MGetData !GetData
- | MNotFound !NotFound
- | MGetBlocks !GetBlocks
- | MGetHeaders !GetHeaders
- | MTx !Tx
- | MBlock !Block
- | MMerkleBlock !MerkleBlock
- | MHeaders !Headers
- | MGetAddr
- | MFilterLoad !FilterLoad
- | MFilterAdd !FilterAdd
- | MFilterClear
- | MPing !Ping
- | MPong !Pong
- | MAlert !Alert
- | MReject Reject
- data MessageHeader = MessageHeader {
- headMagic :: !Word32
- headCmd :: !MessageCommand
- headPayloadSize :: !Word32
- headChecksum :: !CheckSum32
- data Addr = Addr {
- addrList :: ![NetworkAddressTime]
- type NetworkAddressTime = (Word32, NetworkAddress)
- data Alert = Alert {}
- data Block = Block {
- blockHeader :: !BlockHeader
- blockCoinbaseTx :: !CoinbaseTx
- blockTxns :: ![Tx]
- data BlockHeader = BlockHeader {
- blockVersion :: !Word32
- prevBlock :: !BlockHash
- merkleRoot :: !Word256
- blockTimestamp :: !Word32
- blockBits :: !Word32
- bhNonce :: !Word32
- data BloomFlags
- data BloomFilter = BloomFilter {
- bloomData :: !(Seq Word8)
- bloomHashFuncs :: !Word32
- bloomTweak :: !Word32
- bloomFlags :: !BloomFlags
- newtype FilterLoad = FilterLoad {}
- newtype FilterAdd = FilterAdd {}
- data GetBlocks = GetBlocks {}
- type BlockLocator = [BlockHash]
- data GetData = GetData {
- getDataList :: ![InvVector]
- data GetHeaders = GetHeaders {}
- data Headers = Headers {
- headersList :: ![BlockHeaderCount]
- type BlockHeaderCount = (BlockHeader, VarInt)
- data Inv = Inv {}
- data InvVector = InvVector {}
- data InvType
- = InvError
- | InvTx
- | InvBlock
- | InvMerkleBlock
- data MerkleBlock = MerkleBlock {
- merkleHeader :: !BlockHeader
- merkleTotalTxns :: !Word32
- mHashes :: ![Word256]
- mFlags :: ![Bool]
- data NetworkAddress = NetworkAddress {}
- data NotFound = NotFound {
- notFoundList :: ![InvVector]
- newtype Ping = Ping {}
- newtype Pong = Pong {}
- data Reject = Reject {}
- data RejectCode
- reject :: MessageCommand -> RejectCode -> String -> Reject
- data Tx = Tx {}
- data TxIn = TxIn {
- prevOutput :: !OutPoint
- scriptInput :: !ByteString
- txInSequence :: !Word32
- data TxOut = TxOut {
- outValue :: !Word64
- scriptOutput :: !ByteString
- data OutPoint = OutPoint {
- outPointHash :: !TxHash
- outPointIndex :: !Word32
- data CoinbaseTx = CoinbaseTx {
- cbVersion :: !Word32
- cbPrevOutput :: !OutPoint
- cbData :: !ByteString
- cbInSequence :: !Word32
- cbOut :: ![TxOut]
- cbLockTime :: !Word32
- newtype VarInt = VarInt {}
- newtype VarString = VarString {}
- data Version = Version {}
- data MessageCommand
- = MCVersion
- | MCVerAck
- | MCAddr
- | MCInv
- | MCGetData
- | MCNotFound
- | MCGetBlocks
- | MCGetHeaders
- | MCTx
- | MCBlock
- | MCMerkleBlock
- | MCHeaders
- | MCGetAddr
- | MCFilterLoad
- | MCFilterAdd
- | MCFilterClear
- | MCPing
- | MCPong
- | MCAlert
- | MCReject
- 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
- data Script = Script {}
- data PushDataType
- isPushOp :: ScriptOp -> Bool
- opPushData :: ByteString -> ScriptOp
- data ScriptOutput
- = PayPK { }
- | PayPKHash { }
- | PayMulSig { }
- | PayScriptHash { }
- data ScriptInput
- data SimpleInput
- = SpendPK { }
- | SpendPKHash {
- getInputSig :: !TxSignature
- getInputKey :: !PubKey
- | SpendMulSig { }
- type RedeemScript = ScriptOutput
- scriptAddr :: ScriptOutput -> Address
- scriptRecipient :: Script -> Either String Address
- scriptSender :: Script -> Either String Address
- encodeInput :: ScriptInput -> Script
- encodeInputBS :: ScriptInput -> ByteString
- decodeInput :: Script -> Either String ScriptInput
- decodeInputBS :: ByteString -> Either String ScriptInput
- encodeOutput :: ScriptOutput -> Script
- encodeOutputBS :: ScriptOutput -> ByteString
- decodeOutput :: Script -> Either String ScriptOutput
- decodeOutputBS :: ByteString -> Either String ScriptOutput
- sortMulSig :: ScriptOutput -> ScriptOutput
- intToScriptOp :: Int -> ScriptOp
- scriptOpToInt :: ScriptOp -> Either String Int
- isPayPK :: ScriptOutput -> Bool
- isPayPKHash :: ScriptOutput -> Bool
- isPayMulSig :: ScriptOutput -> Bool
- isPayScriptHash :: ScriptOutput -> Bool
- isSpendPK :: ScriptInput -> Bool
- isSpendPKHash :: ScriptInput -> Bool
- isSpendMulSig :: ScriptInput -> Bool
- isScriptHashInput :: ScriptInput -> Bool
- data SigHash
- = SigAll {
- anyoneCanPay :: !Bool
- | SigNone {
- anyoneCanPay :: !Bool
- | SigSingle {
- anyoneCanPay :: !Bool
- | SigUnknown {
- anyoneCanPay :: !Bool
- getSigCode :: !Word8
- = SigAll {
- encodeSigHash32 :: SigHash -> ByteString
- isSigAll :: SigHash -> Bool
- isSigNone :: SigHash -> Bool
- isSigSingle :: SigHash -> Bool
- isSigUnknown :: SigHash -> Bool
- txSigHash :: Tx -> Script -> Int -> SigHash -> Word256
- data TxSignature = TxSignature {
- txSignature :: !Signature
- sigHashType :: !SigHash
- encodeSig :: TxSignature -> ByteString
- decodeSig :: ByteString -> Either String TxSignature
- decodeCanonicalSig :: ByteString -> Either String TxSignature
- verifySpend :: Tx -> Int -> Script -> Bool
- evalScript :: Script -> Script -> SigCheck -> Bool
- type SigCheck = [ScriptOp] -> TxSignature -> PubKey -> Bool
- data Program
- type Stack = [StackValue]
- encodeInt :: Int64 -> StackValue
- decodeInt :: StackValue -> Maybe Int64
- encodeBool :: Bool -> StackValue
- decodeBool :: StackValue -> Bool
- runStack :: Program -> Stack
- checkStack :: Stack -> Bool
- dumpScript :: [ScriptOp] -> String
- dumpStack :: Stack -> String
- execScript :: Script -> Script -> SigCheck -> Either EvalError Program
- data Coin = Coin {
- coinValue :: !Word64
- coinScript :: !ScriptOutput
- coinOutPoint :: !OutPoint
- coinRedeem :: !(Maybe RedeemScript)
- buildTx :: [OutPoint] -> [(ScriptOutput, Word64)] -> Either String Tx
- buildAddrTx :: [OutPoint] -> [(String, Word64)] -> Either String Tx
- data SigInput = SigInput {
- sigDataOut :: !ScriptOutput
- sigDataOP :: !OutPoint
- sigDataSH :: !SigHash
- sigDataRedeem :: !(Maybe RedeemScript)
- signTx :: Monad m => Tx -> [SigInput] -> [PrvKey] -> EitherT String (SecretT m) (Tx, Bool)
- signInput :: Monad m => Tx -> Int -> SigInput -> PrvKey -> EitherT String (SecretT m) (Tx, Bool)
- detSignTx :: Tx -> [SigInput] -> [PrvKey] -> Either String (Tx, Bool)
- detSignInput :: Tx -> Int -> SigInput -> PrvKey -> Either String (Tx, Bool)
- verifyStdTx :: Tx -> [(ScriptOutput, OutPoint)] -> Bool
- verifyStdInput :: Tx -> Int -> ScriptOutput -> Bool
- guessTxSize :: Int -> [(Int, Int)] -> Int -> Int -> Int
- chooseCoins :: Word64 -> Word64 -> [Coin] -> Either String ([Coin], Word64)
- chooseMSCoins :: Word64 -> Word64 -> (Int, Int) -> [Coin] -> Either String ([Coin], Word64)
- getFee :: Word64 -> Int -> Word64
- getMSFee :: Word64 -> (Int, Int) -> Int -> Word64
Documentation
mulInverse :: Integer -> Integer -> IntegerSource
type CheckSum32 = Word32Source
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
hmacDRBGUpd :: ProvidedData -> ByteString -> ByteString -> (ByteString, ByteString)Source
hmacDRBGRsd :: WorkingState -> EntropyInput -> AdditionalInput -> WorkingStateSource
hmacDRBGGen :: WorkingState -> Word16 -> AdditionalInput -> (WorkingState, Maybe ByteString)Source
type WorkingState = (ByteString, ByteString, Word16)Source
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.
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.
cbHash :: CoinbaseTx -> TxHashSource
Computes the hash of a coinbase transaction.
headerHash :: BlockHeader -> BlockHashSource
Compute the hash of a block header
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.
Constructors
| BigWord | |
Fields | |
Instances
| BigWordMod n => Bounded (BigWord n) | |
| BigWordMod n => Enum (BigWord n) | |
| Eq (BigWord n) | |
| BigWordMod n => Integral (BigWord n) | |
| BigWordMod n => Num (BigWord n) | |
| Ord (BigWord n) | |
| Read (BigWord n) | |
| BigWordMod n => Real (BigWord n) | |
| Show (BigWord n) | |
| BigWordMod n => Bits (BigWord n) | |
| NFData (BigWord n) |
class BigWordMod a whereSource
quadraticResidue :: FieldP -> [FieldP]Source
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.
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.
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 |
validatePoint :: Point -> BoolSource
isInfPoint :: Point -> BoolSource
doublePoint :: Point -> PointSource
Data type representing a Bitcoin address
Constructors
| PubKeyAddress | Public Key Hash Address |
Fields | |
| ScriptAddress | Script Hash Address |
Fields | |
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.
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
| |
| PubKeyU | Uncompressed public key |
Fields
| |
isValidPubKey :: PubKey -> BoolSource
Returns True if the public key is valid. This will check if the public key point lies on the curve.
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
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
| |
| PrvKeyU | Uncompressed private key |
Fields
| |
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
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
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
Data type representing an extended BIP32 public key.
Constructors
| XPubKey | |
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 | |
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.
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.
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/.
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.
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.
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.
cycleIndex :: Word32 -> [Word32]Source
cycleIndex' :: Word32 -> [Word32]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.
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 | |
Fields | |
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 | |
Fields | |
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 | |
Fields | |
Instances
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 | |
Fields | |
Instances
makeMasterKey :: ByteString -> Maybe MasterKeySource
Create a MasterKey from a seed.
addr :: AddrPubKey -> AddressSource
Computes an Address from an AddrPubKey.
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.
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 type representing an ECDSA signature.
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.
detSignMsg :: Word256 -> PrvKey -> SignatureSource
Sign a message using ECDSA deterministic signatures as defined by RFC 6979 http://tools.ietf.org/html/rfc6979
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
type Entropy = ByteStringSource
type Passphrase = StringSource
type Seed = ByteStringSource
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.
Computes the height of a merkle tree.
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.
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.
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.
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.
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
| |
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. |
Instances
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.
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.
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.
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)
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.
Constructors
data MessageHeader Source
Data type representing the header of a Message. All messages sent between
nodes contain a message header.
Constructors
| MessageHeader | |
Fields
| |
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 | |
Fields
| |
type NetworkAddressTime = (Word32, NetworkAddress)Source
Network address with a timestamp
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
| |
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
| |
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
| |
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. |
Instances
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
| |
newtype FilterLoad Source
Set a new bloom filter on the peer connection.
Constructors
| FilterLoad | |
Fields | |
Instances
Add the given data element to the connections current filter without requiring a completely new one to be set.
Constructors
| FilterAdd | |
Fields | |
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
| |
type BlockLocator = [BlockHash]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
| |
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
| |
Instances
The Headers type is used to return a list of block headers in
response to a GetHeaders message.
Constructors
| Headers | |
Fields
| |
type BlockHeaderCount = (BlockHeader, VarInt)Source
BlockHeader type with a transaction count as VarInt
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 | |
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
| |
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 | |
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
| |
A Ping message is sent to bitcoin peers to check if a TCP/IP connection is still valid.
Constructors
| Ping | |
A Pong message is sent as a response to a ping message.
Constructors
| Pong | |
The reject message is sent when messages are rejected by a peer.
Constructors
| Reject | |
Fields
| |
data RejectCode Source
Constructors
| RejectMalformed | |
| RejectInvalid | |
| RejectObsolete | |
| RejectDuplicate | |
| RejectNonStandard | |
| RejectDust | |
| RejectInsufficientFee | |
| RejectCheckpoint |
Instances
reject :: MessageCommand -> RejectCode -> String -> RejectSource
Convenience function to build a Reject message
Data type representing a bitcoin transaction
Constructors
| Tx | |
Data type representing a transaction input.
Constructors
| TxIn | |
Fields
| |
Data type representing a transaction output.
Constructors
| TxOut | |
Fields
| |
The OutPoint is used inside a transaction input to reference the previous transaction output that it is spending.
Constructors
| OutPoint | |
Fields
| |
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
| |
Instances
Data type representing a variable length integer. The VarInt type
usually precedes an array or a string that can vary in length.
Data type for variable length strings. Variable length strings are
serialized as a VarInt followed by a bytestring.
Constructors
| VarString | |
Fields | |
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
| |
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 type representing all of the operators allowed inside a Script.
Constructors
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
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 |
Instances
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. |
Fields | |
| PayPKHash | Pay to a public key hash. |
Fields | |
| PayMulSig | Pay to multiple public keys. |
Fields
| |
| PayScriptHash | Pay to a script hash. |
Fields | |
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. |
Fields | |
| SpendPKHash | Spend the coins of a PayPKHash output. |
Fields
| |
| SpendMulSig | Spend the coins of a PayMulSig output. |
Fields | |
Instances
type RedeemScript = ScriptOutputSource
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]
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 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
| |
| SigNone | Sign none of the outputs of a transaction. This allows anyone to change any of the outputs of the transaction. |
Fields
| |
| 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
| |
| SigUnknown | Unrecognized sighash types will decode to SigUnknown. |
Fields
| |
encodeSigHash32 :: SigHash -> ByteStringSource
Encodes a SigHash to a 32 bit-long bytestring.
isSigSingle :: SigHash -> BoolSource
Returns True if the SigHash has the value SigSingle.
isSigUnknown :: SigHash -> BoolSource
Returns True if the SigHash has the value SigUnknown.
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 | |
Fields
| |
Instances
encodeSig :: TxSignature -> ByteStringSource
Serialize a TxSignature to a ByteString.
decodeSig :: ByteString -> Either String TxSignatureSource
Decode a TxSignature from 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
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
Helper functions
encodeInt :: Int64 -> StackValueSource
Encoding function for the stack value format of integers. Most significant bit defines sign.
encodeBool :: Bool -> StackValueSource
decodeBool :: StackValue -> BoolSource
Conversion of StackValue to Bool (true if non-zero).
checkStack :: Stack -> BoolSource
dumpScript :: [ScriptOp] -> StringSource
A Coin is an output of a transaction that can be spent by another transaction.
Constructors
| Coin | |
Fields
| |
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 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
| |
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.
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.
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.
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.
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.