Skip to content

Commit 773d363

Browse files
ProofOfKeagstochicool
authored andcommitted
wip
1 parent 43f505b commit 773d363

File tree

5 files changed

+18
-19
lines changed

5 files changed

+18
-19
lines changed

bitcoin.cabal

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,12 @@ library
113113
, entropy >=0.4.1.5
114114
, hashable >=1.3.0.0
115115
, hspec >=2.7.1
116+
, libsecp256k1 >=0.1.0
116117
, memory >=0.15.0
117118
, murmur3 >=1.0.3
118119
, network >=3.1.1.1
119120
, safe >=0.3.18
120121
, scientific >=0.3.6.2
121-
, secp256k1-haskell >=0.4.0
122122
, split >=0.2.3.3
123123
, string-conversions >=0.4.0.1
124124
, text >=1.2.3.0
@@ -171,12 +171,12 @@ test-suite spec
171171
, hspec >=2.7.1
172172
, lens >=4.18.1
173173
, lens-aeson >=1.1
174+
, libsecp256k1 >=0.1.0
174175
, memory >=0.15.0
175176
, murmur3 >=1.0.3
176177
, network >=3.1.1.1
177178
, safe >=0.3.18
178179
, scientific >=0.3.6.2
179-
, secp256k1-haskell >=0.4.0
180180
, split >=0.2.3.3
181181
, string-conversions >=0.4.0.1
182182
, text >=1.2.3.0

package.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ dependencies:
4040
- split >= 0.2.3.3
4141
- safe >= 0.3.18
4242
- scientific >= 0.3.6.2
43-
- secp256k1-haskell >= 0.4.0
43+
- libsecp256k1 >= 0.1.0
4444
- string-conversions >= 0.4.0.1
4545
- text >= 1.2.3.0
4646
- time >= 1.9.3

src/Bitcoin/Crypto/Signature.hs

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ module Bitcoin.Crypto.Signature (
1414
verifyHashSig,
1515
isCanonicalHalfOrder,
1616
decodeStrictSig,
17-
exportSig,
1817
) where
1918

2019
import Bitcoin.Crypto.Hash
@@ -31,28 +30,20 @@ import Data.Serialize (Serialize (..))
3130
import Numeric (showHex)
3231

3332

34-
-- | Convert 256-bit hash into a 'Msg' for signing or verification.
35-
hashToMsg :: Hash256 -> Msg
36-
hashToMsg =
37-
fromMaybe e . msg . runPutS . serialize
38-
where
39-
e = error "Could not convert 32-byte hash to secp256k1 message"
40-
41-
4233
-- | Sign a 256-bit hash using secp256k1 elliptic curve.
43-
signHash :: SecKey -> Hash256 -> Sig
44-
signHash k = signMsg k . hashToMsg
34+
signHash :: SecKey -> Hash256 -> Signature
35+
signHash k = ecdsaSign k . fromShort . getHash256
4536

4637

4738
-- | Verify an ECDSA signature for a 256-bit hash.
48-
verifyHashSig :: Hash256 -> Sig -> PubKey -> Bool
39+
verifyHashSig :: Hash256 -> Signature -> PubKeyXY -> Bool
4940
verifyHashSig h s p = verifySig p norm (hashToMsg h)
5041
where
5142
norm = fromMaybe s (normalizeSig s)
5243

5344

5445
-- | Deserialize an ECDSA signature as commonly encoded in Bitcoin.
55-
getSig :: MonadGet m => m Sig
46+
getSig :: MonadGet m => m Signature
5647
getSig = do
5748
l <-
5849
lookAhead $ do
@@ -72,17 +63,17 @@ getSig = do
7263

7364

7465
-- | Serialize an ECDSA signature for Bitcoin use.
75-
putSig :: MonadPut m => Sig -> m ()
66+
putSig :: MonadPut m => Signature -> m ()
7667
putSig s = putByteString $ exportSig s
7768

7869

7970
-- | Is canonical half order.
80-
isCanonicalHalfOrder :: Sig -> Bool
71+
isCanonicalHalfOrder :: Signature -> Bool
8172
isCanonicalHalfOrder = isNothing . normalizeSig
8273

8374

8475
-- | Decode signature strictly.
85-
decodeStrictSig :: ByteString -> Maybe Sig
76+
decodeStrictSig :: ByteString -> Maybe Signature
8677
decodeStrictSig bs = do
8778
g <- importSig bs
8879
-- <http://www.secg.org/sec1-v2.pdf Section 4.1.4>

stack.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ nix:
66
- pkg-config
77
extra-deps:
88
- fourmolu-0.8.2.0
9+
- libsecp256k1-0.1.0

stack.yaml.lock

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ packages:
1111
size: 143718
1212
original:
1313
hackage: fourmolu-0.8.2.0
14+
- completed:
15+
hackage: libsecp256k1-0.1.0@sha256:c8de65c640e2e36b14947db00366228d550881640f5e61f496aeb2249966039c,1898
16+
pantry-tree:
17+
size: 901
18+
sha256: 9713733dbf509b8af64449ea9b4b3d1ee518cb1e7e61c03a8a9297fa29c3b274
19+
original:
20+
hackage: libsecp256k1-0.1.0
1421
snapshots:
1522
- completed:
1623
sha256: 1ecad1f0bd2c27de88dbff6572446cfdf647c615d58a7e2e2085c6b7dfc04176

0 commit comments

Comments
 (0)