module Cardano.Chain.Common.AddressHash (
  AddressHash,
  addressHash,
  unsafeAddressHash,
)
where

import Cardano.Crypto.Hashing (AbstractHash, abstractHashFromDigest)
import Cardano.Ledger.Binary (EncCBOR, byronProtVer, serialize)
import Cardano.Prelude
import Crypto.Hash (Blake2b_224, Digest, SHA3_256)
import qualified Crypto.Hash as CryptoHash

-- | Hash used to identify address.
type AddressHash = AbstractHash Blake2b_224

unsafeAddressHash :: EncCBOR a => a -> AddressHash b
unsafeAddressHash :: forall a b. EncCBOR a => a -> AddressHash b
unsafeAddressHash = forall algo a. Digest algo -> AbstractHash algo a
abstractHashFromDigest forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Digest SHA3_256 -> Digest Blake2b_224
secondHash forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall a. EncCBOR a => a -> Digest SHA3_256
firstHash
  where
    firstHash :: EncCBOR a => a -> Digest SHA3_256
    firstHash :: forall a. EncCBOR a => a -> Digest SHA3_256
firstHash = forall a. HashAlgorithm a => ByteString -> Digest a
CryptoHash.hashlazy forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall a. EncCBOR a => Version -> a -> ByteString
serialize Version
byronProtVer
    secondHash :: Digest SHA3_256 -> Digest Blake2b_224
    secondHash :: Digest SHA3_256 -> Digest Blake2b_224
secondHash = forall ba a.
(ByteArrayAccess ba, HashAlgorithm a) =>
ba -> Digest a
CryptoHash.hash

addressHash :: EncCBOR a => a -> AddressHash a
addressHash :: forall a. EncCBOR a => a -> AddressHash a
addressHash = forall a b. EncCBOR a => a -> AddressHash b
unsafeAddressHash