bitcoin-hs-0.0.1: Partial implementation of the Bitcoin protocol (as of 2013)

Safe HaskellNone




Encoding/decoding of public and private keys


private keys

newtype PrivKey Source #

The private key is a random number in the interval [1,n-1] (n being secp256k1_n)




generatePrivKeyIO :: IO PrivKey Source #

Generates a private key with the built-in random generator.

WARNING: this probably doesn't have enough entropy, use only for testing!

generatePrivKey :: RandomGen gen => gen -> (PrivKey, gen) Source #

Generates a private key using the supplied random generator.

WARNING! You are responsible for the random generator having enough entropy! (be careful not to have a constant seed, for example...)

encodePrivKey32 :: PrivKey -> ByteString Source #

Simple 32 byte big-endian integer format

decodePrivKey32 :: ByteString -> PrivKey Source #

Simple 32 byte big-endian integer format

wallet import format for private keys

newtype WIF Source #

Wallet Import Format





Eq WIF Source # 


(==) :: WIF -> WIF -> Bool #

(/=) :: WIF -> WIF -> Bool #

Show WIF Source # 


showsPrec :: Int -> WIF -> ShowS #

show :: WIF -> String #

showList :: [WIF] -> ShowS #

privKeyWIFEncode :: PubKeyFormat -> PrivKey -> WIF Source #

Encode to Wallet Import Format (WIF)

privKeyWIFDecode :: WIF -> Maybe (PubKeyFormat, PrivKey) Source #

Decode from Wallet Import Format (WIF)

public keys

data PubKey Source #

The public key (which is the point priv*G on the curve, G being the generator), either in long format (both coordinates) or short format (x coordinate plus parity of y)


FullPubKey !Integer !Integer

x y

ComprPubKey !Word8 !Integer

only x; the single byte encodes the parity of y (then we have the curve equation)


decodePubKey :: OctetStream a => a -> Maybe PubKey Source #

Decode public key from 3365 bytes long (compresseduncompressed) octet streams

encodePubKeyNative :: PubKey -> ByteString Source #

Encodes the public key as it is represented (either compressed 33 bytes or uncompressed 65 bytes)

encodePubKey' :: PubKeyFormat -> PubKey -> ByteString Source #

Encodes a public key according to the specified format

encodePubKeyLong :: PubKey -> ByteString Source #

Encodes a public key as a 65 byte ByteString (uncompressed)

encodePubKeyShort :: PubKey -> ByteString Source #

Encodes a public key as a 33 byte ByteString (compressed)

computations on keys

computePubKey :: PubKeyFormat -> PrivKey -> PubKey Source #

Computes the public key in the given format

formatPubKey :: PubKeyFormat -> PubKey -> PubKey Source #

Changes a pubkey to the given format

uncompressPubKey :: PubKey -> Maybe PubKey Source #

Uncompresses a public key. This may actually fail if there is no point (x,y) on the curve for any y.

compressPubKey :: PubKey -> PubKey Source #

Compresses a public key