libsecp256k1-0.1.0: Bindings for secp256k1
LicenseUNLICENSE
MaintainerKeagan McClelland <keagan.mcclelland@gmail.com>
Stabilityexperimental
PortabilityPOSIX
Safe HaskellSafe-Inferred
LanguageHaskell2010

Crypto.Secp256k1

Description

Crytpographic functions from Bitcoin’s secp256k1 library.

Synopsis

Core Types

data SecKey Source #

Secret Key

Instances

Instances details
Show SecKey Source # 
Instance details

Defined in Crypto.Secp256k1

Eq SecKey Source # 
Instance details

Defined in Crypto.Secp256k1

Methods

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

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

Ord SecKey Source # 
Instance details

Defined in Crypto.Secp256k1

data PubKeyXY Source #

Public Key with both X and Y coordinates

Instances

Instances details
Show PubKeyXY Source # 
Instance details

Defined in Crypto.Secp256k1

Eq PubKeyXY Source # 
Instance details

Defined in Crypto.Secp256k1

Ord PubKeyXY Source # 
Instance details

Defined in Crypto.Secp256k1

data PubKeyXO Source #

Public Key with only an X coordinate.

Instances

Instances details
Show PubKeyXO Source # 
Instance details

Defined in Crypto.Secp256k1

Eq PubKeyXO Source # 
Instance details

Defined in Crypto.Secp256k1

Ord PubKeyXO Source # 
Instance details

Defined in Crypto.Secp256k1

data KeyPair Source #

Structure containing information equivalent to SecKey and PubKeyXY

Instances

Instances details
Eq KeyPair Source # 
Instance details

Defined in Crypto.Secp256k1

Methods

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

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

data Signature Source #

Structure containing Signature (R,S) data.

Instances

Instances details
Show Signature Source # 
Instance details

Defined in Crypto.Secp256k1

Eq Signature Source # 
Instance details

Defined in Crypto.Secp256k1

data RecoverableSignature Source #

Structure containing Signature AND recovery ID

data Tweak Source #

Isomorphic to SecKey but specifically used for tweaking (EC Group operations) other keys

Instances

Instances details
Show Tweak Source # 
Instance details

Defined in Crypto.Secp256k1

Methods

showsPrec :: Int -> Tweak -> ShowS #

show :: Tweak -> String #

showList :: [Tweak] -> ShowS #

Eq Tweak Source # 
Instance details

Defined in Crypto.Secp256k1

Methods

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

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

Ord Tweak Source # 
Instance details

Defined in Crypto.Secp256k1

Methods

compare :: Tweak -> Tweak -> Ordering #

(<) :: Tweak -> Tweak -> Bool #

(<=) :: Tweak -> Tweak -> Bool #

(>) :: Tweak -> Tweak -> Bool #

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

max :: Tweak -> Tweak -> Tweak #

min :: Tweak -> Tweak -> Tweak #

Parsing and Serialization

importSecKey :: ByteString -> Maybe SecKey Source #

Parses SecKey, will be Nothing if the ByteString corresponds to 0{32} or is not 32 bytes in length

importPubKeyXY :: ByteString -> Maybe PubKeyXY Source #

Parses a 33 or 65 byte PubKeyXY, all other lengths will result in Nothing

exportPubKeyXY :: Bool -> PubKeyXY -> ByteString Source #

Serialize PubKeyXY. First argument True for compressed output (33 bytes), False for uncompressed (65 bytes).

importPubKeyXO :: ByteString -> Maybe PubKeyXO Source #

Parses PubKeyXO from ByteString, will be Nothing if the pubkey corresponds to the Point at Infinity or the the ByteString is not 32 bytes long

exportPubKeyXO :: PubKeyXO -> ByteString Source #

Serializes PubKeyXO to 32 byte ByteString

importSignature :: ByteString -> Maybe Signature Source #

Parses Signature from DER (71 | 72 | 73 bytes) or Compact (64 bytes) representations.

exportSignatureCompact :: Signature -> ByteString Source #

Serializes Signature to Compact (64 byte) representation

exportSignatureDer :: Signature -> ByteString Source #

Serializes Signature to DER (71 | 72 bytes) representation

exportRecoverableSignature :: RecoverableSignature -> ByteString Source #

Serializes RecoverableSignature to Compact (65 byte) representation

importTweak :: ByteString -> Maybe Tweak Source #

Parses Tweak from 32 byte ByteString. If the ByteString is an invalid SecKey then this will yield Nothing

ECDSA Operations

ecdsaVerify :: ByteString -> PubKeyXY -> Signature -> Bool Source #

Verify message signature. True means that the signature is correct.

ecdsaSign :: SecKey -> ByteString -> Maybe Signature Source #

Signs ByteString with SecKey only if ByteString is 32 bytes.

ecdsaSignRecoverable :: SecKey -> ByteString -> Maybe RecoverableSignature Source #

Signs ByteString with SecKey only if ByteString is 32 bytes. Retains ability to compute PubKeyXY from the RecoverableSignature and the original message (ByteString)

ecdsaRecover :: RecoverableSignature -> ByteString -> Maybe PubKeyXY Source #

Computes PubKeyXY from RecoverableSignature and the original message that was signed (must be 32 bytes).

Conversions

recSigToSig :: RecoverableSignature -> Signature Source #

Forgets the recovery id of a signature

derivePubKey :: SecKey -> PubKeyXY Source #

Use SecKey to compute the corresponding PubKeyXY

keyPairCreate :: SecKey -> KeyPair Source #

Compute KeyPair structure from SecKey

keyPairPubKeyXO :: KeyPair -> (PubKeyXO, Bool) Source #

Project PubKeyXO from KeyPair as well as parity bit. True indicates that the public key is the same as it would be if you had serialized the PubKeyXO and it was prefixed with flagsTagPubkeyOdd. False indicates it would be prefixed by flagsTagPubkeyEven

xyToXO :: PubKeyXY -> (PubKeyXO, Bool) Source #

Convert PubKeyXY to PubKeyXO. See keyPairPubKeyXO for more information on how to interpret the parity bit.

Tweaks

keyPairPubKeyXOTweakAdd :: KeyPair -> Tweak -> Maybe KeyPair Source #

Tweak a KeyPair with a Tweak. If the resulting KeyPair is invalid (0, Infinity), then the result is Nothing

pubKeyCombine :: [PubKeyXY] -> Maybe PubKeyXY Source #

Combine a list of PubKeyXYs into a single PubKeyXY. This will result in Nothing if the group operation results in the Point at Infinity

pubKeyTweakAdd :: PubKeyXY -> Tweak -> Maybe PubKeyXY Source #

Add Tweak to PubKeyXY. This will result in Nothing if the group operation results in the Point at Infinity

pubKeyTweakMul :: PubKeyXY -> Tweak -> Maybe PubKeyXY Source #

Multiply PubKeyXY by Tweak. This will result in Nothing if the group operation results in the Point at Infinity

pubKeyXOTweakAdd :: PubKeyXO -> Tweak -> Maybe PubKeyXY Source #

Add Tweak to PubKeyXO. This will result in Nothing if the group operation results in the Point at Infinity

pubKeyXOTweakAddCheck :: PubKeyXO -> Bool -> PubKeyXO -> Tweak -> Bool Source #

Check that a PubKeyXO is the result of the specified tweak operation. True means it was.

Schnorr Operations

schnorrSign :: KeyPair -> ByteString -> Maybe Signature Source #

Compute a schnorr signature using a KeyPair. The ByteString must be 32 bytes long to get a Just out of this function

schnorrVerify :: PubKeyXO -> ByteString -> Signature -> Bool Source #

Verify the authenticity of a schnorr signature. True means the Signature is correct.

Other

taggedSha256 :: ByteString -> ByteString -> SizedByteArray 32 ByteString Source #

Generate a tagged sha256 digest as specified in BIP340

ecdh :: SecKey -> PubKeyXY -> SizedByteArray 32 ByteString Source #

Compute a shared secret using ECDH and SHA256. This algorithm uses your own SecKey, your counterparty's PubKeyXY and results in a 32 byte SHA256 Digest.