csecp256k1

secp256k1 bindings.
Log | Files | Refs | README | LICENSE

commit 2dc59b85e598c87fbd09f58887a5d2fa48c755c5
parent 5b6783ba0247bbdf09f4cf99e5c03b2cb80781ef
Author: Jared Tobin <jared@jtobin.io>
Date:   Sun, 25 Feb 2024 19:25:29 +0400

secp256k1-sys: export size constants

Diffstat:
Msecp256k1-sys/lib/Crypto/Secp256k1/Internal.hs | 56+++++++++++++++++++++++++++++++++++++++++++++++++++++++-
Msecp256k1-sys/test/Main.hs | 32--------------------------------
2 files changed, 55 insertions(+), 33 deletions(-)

diff --git a/secp256k1-sys/lib/Crypto/Secp256k1/Internal.hs b/secp256k1-sys/lib/Crypto/Secp256k1/Internal.hs @@ -1,8 +1,20 @@ {-# LANGUAGE CApiFFI #-} module Crypto.Secp256k1.Internal ( + -- constants + _DER_BYTES + , _PUB_BYTES_INTERNAL + , _PUB_BYTES_COMPRESSED + , _PUB_BYTES_UNCOMPRESSED + , _PUB_BYTES_XONLY + , _SEC_BYTES + , _SIG_BYTES + , _KEYPAIR_BYTES + , _COMPRESSED_FLAG + , _UNCOMPRESSED_FLAG + -- context - _SECP256K1_CONTEXT_NONE + , _SECP256K1_CONTEXT_NONE , Context , Seed32 , secp256k1_context_create @@ -45,6 +57,48 @@ module Crypto.Secp256k1.Internal ( import Foreign.Ptr (Ptr) import Foreign.C.Types (CUChar(..), CInt(..), CUInt(..), CSize(..)) +-- size constants + +-- bytesize of a DER-encoded signature +_DER_BYTES :: Int +_DER_BYTES = 72 + +-- bytesize of an x-only pubkey +_PUB_BYTES_XONLY :: Int +_PUB_BYTES_XONLY = 32 + +-- bytesize of a compressed pubkey +_PUB_BYTES_COMPRESSED :: Int +_PUB_BYTES_COMPRESSED = 33 + +-- bytesize of an uncompressed pubkey +_PUB_BYTES_UNCOMPRESSED :: Int +_PUB_BYTES_UNCOMPRESSED = 65 + +-- bytesize of a secp256k1-internal pubkey +_PUB_BYTES_INTERNAL :: Int +_PUB_BYTES_INTERNAL = 64 + +-- bytesize of a secret key +_SEC_BYTES :: Int +_SEC_BYTES = 32 + +-- bytesize of a secp256k1-internal signature +_SIG_BYTES :: Int +_SIG_BYTES = 64 + +-- bytesize of a secp256k1-internal keypair +_KEYPAIR_BYTES :: Int +_KEYPAIR_BYTES = 96 + +-- flag to indicate a compressed pubkey when parsing +_COMPRESSED_FLAG :: CUInt +_COMPRESSED_FLAG = 0x0102 + +-- flag to indicate an uncompressed pubkey when parsing +_UNCOMPRESSED_FLAG :: CUInt +_UNCOMPRESSED_FLAG = 0x0002 + -- context -- secp256k1 context diff --git a/secp256k1-sys/test/Main.hs b/secp256k1-sys/test/Main.hs @@ -1,5 +1,4 @@ {-# LANGUAGE OverloadedStrings #-} -{-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE ViewPatterns #-} module Main where @@ -8,7 +7,6 @@ import Control.Monad (when) import Control.Exception (Exception, bracket, throwIO) import Crypto.Secp256k1.Internal import qualified Data.ByteString as BS -import Foreign.C.Types (CUInt) import Foreign.Ptr (Ptr) import qualified Foreign.Ptr as F (nullPtr, castPtr) import qualified Foreign.Marshal.Alloc as A (alloca, allocaBytes) @@ -22,36 +20,6 @@ data Secp256k1Error = Secp256k1Error instance Exception Secp256k1Error -_DER_BYTES :: Int -_DER_BYTES = 72 - -_PUB_BYTES_XONLY :: Int -_PUB_BYTES_XONLY = 32 - -_PUB_BYTES_COMPRESSED :: Int -_PUB_BYTES_COMPRESSED = 33 - -_PUB_BYTES_UNCOMPRESSED :: Int -_PUB_BYTES_UNCOMPRESSED = 65 - -_PUB_BYTES_INTERNAL :: Int -_PUB_BYTES_INTERNAL = 64 - -_SEC_BYTES :: Int -_SEC_BYTES = 32 - -_SIG_BYTES :: Int -_SIG_BYTES = 64 - -_KEYPAIR_BYTES :: Int -_KEYPAIR_BYTES = 96 - -_COMPRESSED_FLAG :: CUInt -_COMPRESSED_FLAG = 0x0102 - -_UNCOMPRESSED_FLAG :: CUInt -_UNCOMPRESSED_FLAG = 0x0002 - main :: IO () main = defaultMain units