Skip to content

Commit 02ea63b

Browse files
committed
removes cereal and binary
1 parent da81e9a commit 02ea63b

File tree

14 files changed

+558
-660
lines changed

14 files changed

+558
-660
lines changed

bitcoin.cabal

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,8 @@ library
9696
, array >=0.5.4.0
9797
, base >=4.9 && <5
9898
, base16 >=0.3.0.1
99-
, binary >=0.8.8
10099
, bytes >=0.17
101100
, bytestring >=0.10.10.0
102-
, cereal >=0.5.8
103101
, containers >=0.6.2.1
104102
, cryptonite >=0.26
105103
, deepseq >=1.4.4.0
@@ -149,11 +147,9 @@ test-suite spec
149147
, base >=4.9 && <5
150148
, base16 >=0.3.0.1
151149
, base64 ==0.4.*
152-
, binary >=0.8.8
153150
, bitcoin
154151
, bytes >=0.17
155152
, bytestring >=0.10.10.0
156-
, cereal >=0.5.8
157153
, containers >=0.6.2.1
158154
, cryptonite >=0.26
159155
, deepseq >=1.4.4.0

package.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ dependencies:
2222
- array >= 0.5.4.0
2323
- base >=4.9 && <5
2424
- base16 >= 0.3.0.1
25-
- binary >= 0.8.8
25+
# - binary >= 0.8.8
2626
- bytes >= 0.17
2727
- bytestring >= 0.10.10.0
28-
- cereal >= 0.5.8
28+
# - cereal >= 0.5.8
2929
- containers >= 0.6.2.1
3030
- cryptonite >= 0.26
3131
- deepseq >= 1.4.4.0

src/Haskoin/Address.hs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,13 @@ import Control.Applicative
5151
import Control.Arrow (second)
5252
import Control.DeepSeq
5353
import Control.Monad
54-
import Data.Binary (Binary (..))
5554
import Data.ByteString (ByteString)
5655
import qualified Data.ByteString as B
5756
import Data.Bytes.Get
5857
import Data.Bytes.Put
5958
import Data.Bytes.Serial
6059
import Data.Hashable
6160
import Data.Maybe
62-
import Data.Serialize (Serialize (..))
6361
import Data.Text (Text)
6462
import qualified Data.Text as T
6563
import Data.Word (Word8)

src/Haskoin/Constants.hs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,12 @@ module Haskoin.Constants (
2222
) where
2323

2424
import Control.DeepSeq
25-
import Data.Binary (Binary (..))
2625
import Data.ByteString (ByteString)
2726
import Data.Bytes.Get
2827
import Data.Bytes.Put
2928
import Data.Bytes.Serial
3029
import Data.List
3130
import Data.Maybe
32-
import Data.Serialize (Serialize (..))
3331
import Data.String
3432
import Data.Text (Text)
3533
import Data.Word (Word32, Word64, Word8)

src/Haskoin/Crypto/Hash.hs

Lines changed: 46 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,16 @@
22
{-# LANGUAGE DeriveGeneric #-}
33
{-# LANGUAGE TypeApplications #-}
44

5-
{- |
6-
Module : Haskoin.Crypto.Hash
7-
Copyright : No rights reserved
8-
License : MIT
9-
Maintainer : [email protected]
10-
Stability : experimental
11-
Portability : POSIX
12-
13-
Hashing functions and corresponding data types. Uses functions from the
14-
cryptonite library.
15-
-}
5+
-- |
6+
--Module : Haskoin.Crypto.Hash
7+
--Copyright : No rights reserved
8+
--License : MIT
9+
--Maintainer : [email protected]
10+
--Stability : experimental
11+
--Portability : POSIX
12+
--
13+
--Hashing functions and corresponding data types. Uses functions from the
14+
--cryptonite library.
1615
module Haskoin.Crypto.Hash (
1716
-- * Hashes
1817
Hash512 (getHash512),
@@ -45,7 +44,6 @@ import Crypto.Hash (
4544
hashWith,
4645
)
4746
import Crypto.MAC.HMAC (HMAC, hmac)
48-
import Data.Binary (Binary (..))
4947
import Data.ByteArray (ByteArrayAccess)
5048
import qualified Data.ByteArray as BA
5149
import Data.ByteString (ByteString)
@@ -57,64 +55,66 @@ import qualified Data.Bytes.Put as Put
5755
import Data.Bytes.Serial (Serial (..))
5856
import Data.Either (fromRight)
5957
import Data.Hashable (Hashable)
60-
import Data.Serialize (Serialize (..))
6158
import Data.String (IsString, fromString)
6259
import Data.String.Conversions (cs)
6360
import Data.Word (Word32)
6461
import GHC.Generics (Generic)
6562
import Haskoin.Util
6663
import Text.Read as R
6764

65+
6866
-- | 'Word32' wrapped for type-safe 32-bit checksums.
6967
newtype CheckSum32 = CheckSum32
7068
{ getCheckSum32 :: Word32
7169
}
7270
deriving (Eq, Ord, Serial, Show, Read, Hashable, Generic, NFData)
7371

74-
instance Serialize CheckSum32 where
75-
put = serialize
76-
get = deserialize
77-
78-
instance Binary CheckSum32 where
79-
put = serialize
80-
get = deserialize
8172

8273
-- | Type for 512-bit hashes.
8374
newtype Hash512 = Hash512 {getHash512 :: ShortByteString}
8475
deriving (Eq, Ord, Hashable, Generic, NFData)
8576

77+
8678
-- | Type for 256-bit hashes.
8779
newtype Hash256 = Hash256 {getHash256 :: ShortByteString}
8880
deriving (Eq, Ord, Hashable, Generic, NFData)
8981

82+
9083
-- | Type for 160-bit hashes.
9184
newtype Hash160 = Hash160 {getHash160 :: ShortByteString}
9285
deriving (Eq, Ord, Hashable, Generic, NFData)
9386

87+
9488
instance Show Hash512 where
9589
showsPrec _ = shows . encodeHex . BSS.fromShort . getHash512
9690

91+
9792
instance Read Hash512 where
9893
readPrec = do
9994
R.String str <- lexP
10095
maybe pfail return $ Hash512 . BSS.toShort <$> decodeHex (cs str)
10196

97+
10298
instance Show Hash256 where
10399
showsPrec _ = shows . encodeHex . BSS.fromShort . getHash256
104100

101+
105102
instance Read Hash256 where
106103
readPrec = do
107104
R.String str <- lexP
108105
maybe pfail return $ Hash256 . BSS.toShort <$> decodeHex (cs str)
109106

107+
110108
instance Show Hash160 where
111109
showsPrec _ = shows . encodeHex . BSS.fromShort . getHash160
112110

111+
113112
instance Read Hash160 where
114113
readPrec = do
115114
R.String str <- lexP
116115
maybe pfail return $ Hash160 . BSS.toShort <$> decodeHex (cs str)
117116

117+
118118
instance IsString Hash512 where
119119
fromString str =
120120
case decodeHex $ cs str of
@@ -123,20 +123,14 @@ instance IsString Hash512 where
123123
case BS.length bs of
124124
64 -> Hash512 (BSS.toShort bs)
125125
_ -> e
126-
where
127-
e = error "Could not decode hash from hex string"
126+
where
127+
e = error "Could not decode hash from hex string"
128+
128129

129130
instance Serial Hash512 where
130131
deserialize = Hash512 . BSS.toShort <$> Get.getByteString 64
131132
serialize = Put.putByteString . BSS.fromShort . getHash512
132133

133-
instance Serialize Hash512 where
134-
put = serialize
135-
get = deserialize
136-
137-
instance Binary Hash512 where
138-
put = serialize
139-
get = deserialize
140134

141135
instance IsString Hash256 where
142136
fromString str =
@@ -146,20 +140,14 @@ instance IsString Hash256 where
146140
case BS.length bs of
147141
32 -> Hash256 (BSS.toShort bs)
148142
_ -> e
149-
where
150-
e = error "Could not decode hash from hex string"
143+
where
144+
e = error "Could not decode hash from hex string"
145+
151146

152147
instance Serial Hash256 where
153148
deserialize = Hash256 . BSS.toShort <$> Get.getByteString 32
154149
serialize = Put.putByteString . BSS.fromShort . getHash256
155150

156-
instance Serialize Hash256 where
157-
put = serialize
158-
get = deserialize
159-
160-
instance Binary Hash256 where
161-
put = serialize
162-
get = deserialize
163151

164152
instance IsString Hash160 where
165153
fromString str =
@@ -169,47 +157,47 @@ instance IsString Hash160 where
169157
case BS.length bs of
170158
20 -> Hash160 (BSS.toShort bs)
171159
_ -> e
172-
where
173-
e = error "Could not decode hash from hex string"
160+
where
161+
e = error "Could not decode hash from hex string"
162+
174163

175164
instance Serial Hash160 where
176165
deserialize = Hash160 . BSS.toShort <$> Get.getByteString 20
177166
serialize = Put.putByteString . BSS.fromShort . getHash160
178167

179-
instance Serialize Hash160 where
180-
put = serialize
181-
get = deserialize
182-
183-
instance Binary Hash160 where
184-
put = serialize
185-
get = deserialize
186168

187169
-- | Calculate SHA512 hash.
188170
sha512 :: ByteArrayAccess b => b -> Hash512
189171
sha512 = Hash512 . BSS.toShort . BA.convert . hashWith SHA512
190172

173+
191174
-- | Calculate SHA256 hash.
192175
sha256 :: ByteArrayAccess b => b -> Hash256
193176
sha256 = Hash256 . BSS.toShort . BA.convert . hashWith SHA256
194177

178+
195179
-- | Calculate RIPEMD160 hash.
196180
ripemd160 :: ByteArrayAccess b => b -> Hash160
197181
ripemd160 = Hash160 . BSS.toShort . BA.convert . hashWith RIPEMD160
198182

183+
199184
-- | Claculate SHA1 hash.
200185
sha1 :: ByteArrayAccess b => b -> Hash160
201186
sha1 = Hash160 . BSS.toShort . BA.convert . hashWith SHA1
202187

188+
203189
-- | Compute two rounds of SHA-256.
204190
doubleSHA256 :: ByteArrayAccess b => b -> Hash256
205191
doubleSHA256 =
206192
Hash256 . BSS.toShort . BA.convert . hashWith SHA256 . hashWith SHA256
207193

194+
208195
-- | Compute SHA-256 followed by RIPMED-160.
209196
addressHash :: ByteArrayAccess b => b -> Hash160
210197
addressHash =
211198
Hash160 . BSS.toShort . BA.convert . hashWith RIPEMD160 . hashWith SHA256
212199

200+
213201
{- CheckSum -}
214202

215203
-- | Computes a 32 bit checksum.
@@ -222,24 +210,28 @@ checkSum32 =
222210
. hashWith SHA256
223211
. hashWith SHA256
224212

213+
225214
{- HMAC -}
226215

227216
-- | Computes HMAC over SHA-512.
228217
hmac512 :: ByteString -> ByteString -> Hash512
229218
hmac512 key msg =
230219
Hash512 $ BSS.toShort $ BA.convert (hmac key msg :: HMAC SHA512)
231220

221+
232222
-- | Computes HMAC over SHA-256.
233223
hmac256 :: (ByteArrayAccess k, ByteArrayAccess m) => k -> m -> Hash256
234224
hmac256 key msg =
235225
Hash256 $ BSS.toShort $ BA.convert (hmac key msg :: HMAC SHA256)
236226

227+
237228
-- | Split a 'Hash512' into a pair of 'Hash256'.
238229
split512 :: Hash512 -> (Hash256, Hash256)
239230
split512 h =
240231
(Hash256 (BSS.toShort a), Hash256 (BSS.toShort b))
241-
where
242-
(a, b) = BS.splitAt 32 . BSS.fromShort $ getHash512 h
232+
where
233+
(a, b) = BS.splitAt 32 . BSS.fromShort $ getHash512 h
234+
243235

244236
-- | Join a pair of 'Hash256' into a 'Hash512'.
245237
join512 :: (Hash256, Hash256) -> Hash512
@@ -248,16 +240,16 @@ join512 (a, b) =
248240
. BSS.toShort
249241
$ BSS.fromShort (getHash256 a) `BS.append` BSS.fromShort (getHash256 b)
250242

251-
{- | Initialize tagged hash specified in BIP340
252243

253-
@since 0.21.0
254-
-}
244+
-- | Initialize tagged hash specified in BIP340
245+
--
246+
--@since 0.21.0
255247
initTaggedHash ::
256248
-- | Hash tag
257249
ByteString ->
258250
Context SHA256
259251
initTaggedHash tag =
260252
(`hashUpdates` [hashedTag, hashedTag]) $
261253
hashInit @SHA256
262-
where
263-
hashedTag = hashWith SHA256 tag
254+
where
255+
hashedTag = hashWith SHA256 tag

0 commit comments

Comments
 (0)