secp256k1 0.1.2 → 0.1.3
raw patch · 2 files changed
+77/−7 lines, 2 filesdep +string-conversions
Dependencies added: string-conversions
Files
- secp256k1.cabal +3/−1
- src/Crypto/Secp256k1.hs +74/−6
secp256k1.cabal view
@@ -1,5 +1,5 @@ name: secp256k1-version: 0.1.2+version: 0.1.3 synopsis: secp256k1 bindings for Haskell description: Please see README.md homepage: http://github.com/haskoin/secp256k1#readme@@ -21,6 +21,8 @@ , bytestring , mtl , entropy+ , string-conversions+ , base16-bytestring default-language: Haskell2010 ghc-options: -Wall extra-libraries: secp256k1
src/Crypto/Secp256k1.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE FlexibleContexts #-} {-| Module : Crypto.Secp256k1 Description : Public SECP256K1 cryptographic functions@@ -26,12 +27,18 @@ , combinePubKeys ) where -import Control.Monad.Reader+import Control.Applicative+import Control.Monad import Crypto.Secp256k1.Internal import Data.ByteString (ByteString) import qualified Data.ByteString as BS+import qualified Data.ByteString.Base16 as B16+import Data.Maybe+import Data.String+import Data.String.Conversions import Foreign import System.IO.Unsafe+import Text.Read -- | Internal public key data type. newtype PubKey = PubKey (ForeignPtr PubKey64)@@ -48,20 +55,81 @@ -- | Internal tweak data type for addition and multiplication. newtype Tweak = Tweak (ForeignPtr Tweak32) +decodeHex :: ConvertibleStrings a ByteString => a -> Maybe ByteString+decodeHex str = if BS.null r then Just bs else Nothing where+ (bs, r) = B16.decode $ cs str++-- TODO: Test+instance Read PubKey where+ readPrec = parens $ do+ String str <- lexP+ maybe pfail return $ importPubKey =<< decodeHex str++-- TODO: Test+instance IsString PubKey where+ fromString = fromJust . (importPubKey <=< decodeHex)++-- TODO: Test instance Show PubKey where- show = show . exportPubKey True+ show = show . B16.encode . exportPubKey True +-- TODO: Test+instance Read Msg where+ readPrec = parens $ do+ String str <- lexP+ maybe pfail return $ msg =<< decodeHex str++-- TODO: Test+instance IsString Msg where+ fromString = fromJust . msg . cs++-- TODO: Test instance Show Msg where- show = show . getMsg+ show = show . B16.encode . getMsg +-- TODO: Test+instance Read Sig where+ readPrec = parens $ do+ String str <- lexP+ maybe pfail return $ importSig =<< decodeHex str++-- TODO: Test+instance IsString Sig where+ fromString = fromJust . (importSig <=< decodeHex)++-- TODO: Test instance Show Sig where- show = show . exportSig+ show = show . B16.encode . exportSig +-- TODO: Test+instance Read SecKey where+ readPrec = parens $ do+ String str <- lexP+ maybe pfail return $+ (secKey =<< decodeHex str) <|> (importSecKey =<< decodeHex str)++-- TODO: Test+instance IsString SecKey where+ fromString str = fromJust $+ (secKey =<< decodeHex str) <|> (importSecKey =<< decodeHex str)++-- TODO: Test instance Show SecKey where- show = show . getSecKey+ show = show . B16.encode . getSecKey +-- TODO: Test+instance Read Tweak where+ readPrec = parens $ do+ String str <- lexP+ maybe pfail return $ tweak =<< decodeHex str++-- TODO: Test+instance IsString Tweak where+ fromString = fromJust . (tweak <=< decodeHex)++-- TODO: Test instance Show Tweak where- show = show . getTweak+ show = show . B16.encode . getTweak instance Eq PubKey where fp1 == fp2 = getPubKey fp1 == getPubKey fp2