{-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE TypeFamilies #-} module Cardano.Api.Hash ( Hash , CastHash (..) , AsType (AsHash) , renderSafeHashAsHex ) where import Cardano.Api.HasTypeProxy import qualified Cardano.Crypto.Hash as Hash import qualified Cardano.Ledger.SafeHash as Ledger import Data.Kind (Type) import qualified Data.Text 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 c tag -> Text.Text renderSafeHashAsHex :: forall c tag. SafeHash c tag -> Text renderSafeHashAsHex = Hash (HASH c) tag -> Text forall h a. Hash h a -> Text Hash.hashToTextAsHex (Hash (HASH c) tag -> Text) -> (SafeHash c tag -> Hash (HASH c) tag) -> SafeHash c tag -> Text forall b c a. (b -> c) -> (a -> b) -> a -> c . SafeHash c tag -> Hash (HASH c) tag forall c i. SafeHash c i -> Hash (HASH c) i Ledger.extractHash