-- | Custom cryptographic hash constructions used by Bitcoin.
module Bitcoin.Hash
  ( -- * Bitcoin constructions
    check32
  , I.hash160
  , I.hash256
  ) where

import qualified Data.ByteString as B
import qualified Bitcoin.Hash.Internal as I

--------------------------------------------------------------------------------

-- | @'check32' == 'B.take' 4 . 'I.hash256'@
check32
  :: B.ByteString  -- ^ Data to hash.
  -> B.ByteString  -- ^ 32-bit long digest.
check32 :: ByteString -> ByteString
check32 = Int -> ByteString -> ByteString
B.take 4 (ByteString -> ByteString)
-> (ByteString -> ByteString) -> ByteString -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> ByteString
I.hash256
{-# INLINE check32 #-}