-- |
-- Module      :  Crypto.Ethereum.Utils
-- Copyright   :  Aleksandr Krupenkin 2016-2021
-- License     :  Apache-2.0
--
-- Maintainer  :  mail@akru.me
-- Stability   :  experimental
-- Portability :  portable
--
-- Ethereum crypto module helper functions.
--

module Crypto.Ethereum.Utils where

import           Crypto.Hash    (Keccak_256 (..), hashWith)
import           Data.ByteArray (ByteArray, ByteArrayAccess, convert)

-- | Keccak 256 hash function.
keccak256 :: (ByteArrayAccess bin, ByteArray bout) => bin -> bout
{-# INLINE keccak256 #-}
keccak256 :: bin -> bout
keccak256 = Digest Keccak_256 -> bout
forall bin bout.
(ByteArrayAccess bin, ByteArray bout) =>
bin -> bout
convert (Digest Keccak_256 -> bout)
-> (bin -> Digest Keccak_256) -> bin -> bout
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Keccak_256 -> bin -> Digest Keccak_256
forall ba alg.
(ByteArrayAccess ba, HashAlgorithm alg) =>
alg -> ba -> Digest alg
hashWith Keccak_256
Keccak_256