{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TypeFamilies #-}
module Cardano.Api.Hash
(
Hash
, CastHash (..)
, AsType (AsHash)
, renderSafeHashAsHex
, HasTypeProxy (proxyToAsType)
, asType
, Proxy (..)
, FromSomeType (..)
)
where
import Cardano.Api.HasTypeProxy
import Cardano.Crypto.Hash qualified as Hash
import Cardano.Ledger.Hashes qualified as Ledger
import Data.Kind (Type)
import Data.Text qualified as Text
data family Hash keyrole :: Type
class CastHash roleA roleB where
castHash :: Hash roleA -> Hash roleB
instance HasTypeProxy a => HasTypeProxy (Hash a) where
data AsType (Hash a) = AsHash (AsType a)
proxyToAsType :: Proxy (Hash a) -> AsType (Hash a)
proxyToAsType Proxy (Hash a)
_ = AsType a -> AsType (Hash a)
forall a. AsType a -> AsType (Hash a)
AsHash (Proxy a -> AsType a
forall t. HasTypeProxy t => Proxy t -> AsType t
proxyToAsType (Proxy a
forall {a}. Proxy a
forall {k} (t :: k). Proxy t
Proxy :: Proxy a))
renderSafeHashAsHex :: Ledger.SafeHash tag -> Text.Text
renderSafeHashAsHex :: forall tag. SafeHash tag -> Text
renderSafeHashAsHex = Hash HASH tag -> Text
forall h a. Hash h a -> Text
Hash.hashToTextAsHex (Hash HASH tag -> Text)
-> (SafeHash tag -> Hash HASH tag) -> SafeHash tag -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SafeHash tag -> Hash HASH tag
forall i. SafeHash i -> Hash HASH i
Ledger.extractHash