Skip to content

Commit 9036e7a

Browse files
change the repository structure to contain multiple packages
1 parent 1b63f48 commit 9036e7a

File tree

17 files changed

+492
-362
lines changed

17 files changed

+492
-362
lines changed

CHANGELOG.md renamed to secp256k1-haskell/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

7+
## 0.7.1
8+
### Changed
9+
- Reworked the structure of the Internal modules to allow having add-on packages for optional libsecp256k1 features.
10+
11+
## 0.7.0
12+
### Changed
13+
- Bump base16 dependency version.
14+
715
## 0.6.1
816
### Changed
917
- Bump version and LTS Haskell.

secp256k1-haskell/LICENSE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../LICENSE

secp256k1-haskell/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../README.md
File renamed without changes.

package.yaml renamed to secp256k1-haskell/package.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ dependencies:
2323
- hashable >=1.2.6 && <1.5
2424
- QuickCheck >=2.9.2 && <2.15
2525
- string-conversions >=0.4 && <0.5
26-
- unliftio-core >=0.1.0 && <0.3
26+
- unliftio-core >=0.1.0 && <0.3
2727
library:
2828
source-dirs: src
2929
generated-exposed-modules:

secp256k1-haskell.cabal renamed to secp256k1-haskell/secp256k1-haskell.cabal

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cabal-version: 2.0
22

3-
-- This file has been generated from package.yaml by hpack version 0.35.1.
3+
-- This file has been generated from package.yaml by hpack version 0.35.2.
44
--
55
-- see: https://github.com/sol/hpack
66

@@ -28,7 +28,11 @@ source-repository head
2828
library
2929
exposed-modules:
3030
Crypto.Secp256k1
31-
Crypto.Secp256k1.Internal
31+
Crypto.Secp256k1.Internal.Base
32+
Crypto.Secp256k1.Internal.BaseOps
33+
Crypto.Secp256k1.Internal.Context
34+
Crypto.Secp256k1.Internal.ForeignTypes
35+
Crypto.Secp256k1.Internal.Util
3236
Paths_secp256k1_haskell
3337
autogen-modules:
3438
Paths_secp256k1_haskell
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
-- |
2+
-- Module : Crypto.Secp256k1
3+
-- License : UNLICENSE
4+
-- Maintainer : Jean-Pierre Rupp <[email protected]>
5+
-- Stability : experimental
6+
-- Portability : POSIX
7+
--
8+
-- Crytpographic functions from Bitcoin’s secp256k1 library.
9+
module Crypto.Secp256k1
10+
( -- * Messages
11+
Msg,
12+
msg,
13+
getMsg,
14+
15+
-- * Secret Keys
16+
SecKey,
17+
secKey,
18+
getSecKey,
19+
derivePubKey,
20+
21+
-- * Public Keys
22+
PubKey,
23+
importPubKey,
24+
exportPubKey,
25+
26+
-- * Signatures
27+
Sig,
28+
signMsg,
29+
verifySig,
30+
normalizeSig,
31+
32+
-- ** DER
33+
importSig,
34+
exportSig,
35+
36+
-- ** Compact
37+
CompactSig,
38+
getCompactSig,
39+
compactSig,
40+
exportCompactSig,
41+
importCompactSig,
42+
43+
-- * Addition & Multiplication
44+
Tweak,
45+
tweak,
46+
getTweak,
47+
tweakAddSecKey,
48+
tweakMulSecKey,
49+
tweakAddPubKey,
50+
tweakMulPubKey,
51+
combinePubKeys,
52+
tweakNegate,
53+
)
54+
where
55+
56+
import Crypto.Secp256k1.Internal.Base

src/Crypto/Secp256k1.hs renamed to secp256k1-haskell/src/Crypto/Secp256k1/Internal/Base.hs

Lines changed: 41 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{-# LANGUAGE DeriveGeneric #-}
22
{-# LANGUAGE FlexibleContexts #-}
33
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
4-
{-# LANGUAGE MultiParamTypeClasses #-}
54
{-# LANGUAGE ImportQualifiedPost #-}
5+
{-# LANGUAGE MultiParamTypeClasses #-}
66

77
-- |
88
-- Module : Crypto.Secp256k1
@@ -12,60 +12,46 @@
1212
-- Portability : POSIX
1313
--
1414
-- Crytpographic functions from Bitcoin’s secp256k1 library.
15-
module Crypto.Secp256k1
16-
( -- * Messages
17-
Msg,
18-
msg,
19-
getMsg,
20-
21-
-- * Secret Keys
22-
SecKey,
23-
secKey,
24-
getSecKey,
25-
derivePubKey,
26-
27-
-- * Public Keys
28-
PubKey,
29-
importPubKey,
30-
exportPubKey,
31-
32-
-- * Signatures
33-
Sig,
34-
signMsg,
35-
verifySig,
36-
normalizeSig,
37-
38-
-- ** DER
39-
importSig,
40-
exportSig,
41-
42-
-- ** Compact
43-
CompactSig,
44-
getCompactSig,
45-
compactSig,
46-
exportCompactSig,
47-
importCompactSig,
48-
49-
-- * Addition & Multiplication
50-
Tweak,
51-
tweak,
52-
getTweak,
53-
tweakAddSecKey,
54-
tweakMulSecKey,
55-
tweakAddPubKey,
56-
tweakMulPubKey,
57-
combinePubKeys,
58-
tweakNegate,
59-
)
60-
where
15+
--
16+
-- The API for this module may change at any time. This is an internal module only
17+
-- exposed for hacking and experimentation.
18+
module Crypto.Secp256k1.Internal.Base where
6119

6220
import Control.DeepSeq (NFData)
6321
import Control.Monad (replicateM, unless, (<=<))
64-
import Crypto.Secp256k1.Internal
65-
import Data.Base16.Types (assertBase16, extractBase16)
22+
import Crypto.Secp256k1.Internal.BaseOps
23+
( ecPubKeyCombine,
24+
ecPubKeyCreate,
25+
ecPubKeyParse,
26+
ecPubKeySerialize,
27+
ecPubKeyTweakAdd,
28+
ecPubKeyTweakMul,
29+
ecSecKeyTweakAdd,
30+
ecSecKeyTweakMul,
31+
ecTweakNegate,
32+
ecdsaSign,
33+
ecdsaSignatureNormalize,
34+
ecdsaSignatureParseCompact,
35+
ecdsaSignatureParseDer,
36+
ecdsaSignatureSerializeCompact,
37+
ecdsaSignatureSerializeDer,
38+
ecdsaVerify,
39+
)
40+
import Crypto.Secp256k1.Internal.Context (ctx)
41+
import Crypto.Secp256k1.Internal.ForeignTypes
42+
( compressed,
43+
isSuccess,
44+
uncompressed,
45+
)
46+
import Crypto.Secp256k1.Internal.Util
47+
( decodeHex,
48+
packByteString,
49+
showsHex,
50+
unsafePackByteString,
51+
unsafeUseByteString,
52+
)
6653
import Data.ByteString (ByteString)
6754
import Data.ByteString qualified as BS
68-
import Data.ByteString.Base16 (decodeBase16, encodeBase16, isBase16)
6955
import Data.Hashable (Hashable (..))
7056
import Data.Maybe (fromJust, fromMaybe, isJust)
7157
import Data.Serialize
@@ -74,7 +60,6 @@ import Data.Serialize
7460
putByteString,
7561
)
7662
import Data.String (IsString (..))
77-
import Data.String.Conversions (ConvertibleStrings, cs)
7863
import Foreign
7964
( alloca,
8065
allocaArray,
@@ -144,12 +129,6 @@ instance Serialize CompactSig where
144129
put (CompactSig bs) = putByteString bs
145130
get = CompactSig <$> getByteString 64
146131

147-
decodeHex :: (ConvertibleStrings a ByteString) => a -> Maybe ByteString
148-
decodeHex str =
149-
if isBase16 $ cs str
150-
then Just . decodeBase16 $ assertBase16 $ cs str
151-
else Nothing
152-
153132
instance Read PubKey where
154133
readPrec = do
155134
String str <- lexP
@@ -164,7 +143,7 @@ instance IsString PubKey where
164143
e = error "Could not decode public key from hex string"
165144

166145
instance Show PubKey where
167-
showsPrec _ = shows . extractBase16 . encodeBase16 . exportPubKey True
146+
showsPrec _ = showsHex . exportPubKey True
168147

169148
instance Read Msg where
170149
readPrec = parens $ do
@@ -180,7 +159,7 @@ instance IsString Msg where
180159
e = error "Could not decode message from hex string"
181160

182161
instance Show Msg where
183-
showsPrec _ = shows . extractBase16 . encodeBase16 . getMsg
162+
showsPrec _ = showsHex . getMsg
184163

185164
instance Read Sig where
186165
readPrec = parens $ do
@@ -196,7 +175,7 @@ instance Hashable Sig where
196175
i `hashWithSalt` s = i `hashWithSalt` exportSig s
197176

198177
instance Show Sig where
199-
showsPrec _ = shows . extractBase16 . encodeBase16 . exportSig
178+
showsPrec _ = showsHex . exportSig
200179

201180
instance Read SecKey where
202181
readPrec = parens $ do
@@ -212,7 +191,7 @@ instance IsString SecKey where
212191
e = error "Colud not decode secret key from hex string"
213192

214193
instance Show SecKey where
215-
showsPrec _ = shows . extractBase16 . encodeBase16 . getSecKey
194+
showsPrec _ = showsHex . getSecKey
216195

217196
instance Hashable Tweak where
218197
i `hashWithSalt` t = i `hashWithSalt` getTweak t
@@ -228,7 +207,7 @@ instance IsString Tweak where
228207
e = error "Could not decode tweak from hex string"
229208

230209
instance Show Tweak where
231-
showsPrec _ = shows . extractBase16 . encodeBase16 . getTweak
210+
showsPrec _ = showsHex . getTweak
232211

233212
-- | Import 32-byte 'ByteString' as 'Msg'.
234213
msg :: ByteString -> Maybe Msg

0 commit comments

Comments
 (0)