Safe Haskell | None |
---|---|
Language | Haskell98 |
Encoding/decoding of public and private keys
- newtype PrivKey = PrivKey {}
- generatePrivKeyIO :: IO PrivKey
- generatePrivKey :: RandomGen gen => gen -> (PrivKey, gen)
- encodePrivKey32 :: PrivKey -> ByteString
- decodePrivKey32 :: ByteString -> PrivKey
- newtype WIF = WIF {}
- privKeyWIFEncode :: PubKeyFormat -> PrivKey -> WIF
- privKeyWIFDecode :: WIF -> Maybe (PubKeyFormat, PrivKey)
- data PubKey
- = FullPubKey !Integer !Integer
- | ComprPubKey !Word8 !Integer
- data PubKeyFormat
- pubKeyFormat :: PubKey -> PubKeyFormat
- newtype PubKeyHash = PubKeyHash {}
- pubKeyHash :: PubKey -> PubKeyHash
- decodePubKey :: OctetStream a => a -> Maybe PubKey
- encodePubKeyNative :: PubKey -> ByteString
- encodePubKey' :: PubKeyFormat -> PubKey -> ByteString
- encodePubKeyLong :: PubKey -> ByteString
- encodePubKeyShort :: PubKey -> ByteString
- computePubKey :: PubKeyFormat -> PrivKey -> PubKey
- computeFullPubKey :: PrivKey -> PubKey
- isValidPubKey :: PubKey -> Bool
- formatPubKey :: PubKeyFormat -> PubKey -> PubKey
- uncompressPubKey :: PubKey -> Maybe PubKey
- compressPubKey :: PubKey -> PubKey
private keys
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
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
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 | |
ComprPubKey !Word8 !Integer | only x; the single byte encodes the parity of |
data PubKeyFormat Source #
Unfortunately there is this mess with compressed/uncompressed formats :(
pubKeyFormat :: PubKey -> PubKeyFormat Source #
newtype PubKeyHash Source #
The 160-bit hash of a public key
pubKeyHash :: PubKey -> PubKeyHash Source #
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
computeFullPubKey :: PrivKey -> PubKey Source #
isValidPubKey :: PubKey -> Bool Source #
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