-- editorconfig-checker-disable-file
{-# LANGUAGE DeriveAnyClass       #-}
{-# LANGUAGE DerivingVia          #-}
{-# LANGUAGE TemplateHaskell      #-}
{-# LANGUAGE UndecidableInstances #-}

{-# OPTIONS_GHC -fno-omit-interface-pragmas #-}
{-# LANGUAGE DataKinds            #-}
{-# LANGUAGE FlexibleInstances    #-}
{-# LANGUAGE TypeApplications     #-}
{-# LANGUAGE TypeFamilies         #-}

module PlutusLedgerApi.V1.Crypto
  ( PubKeyHash (..)
  ) where

import Control.DeepSeq (NFData)
import Data.String
import Data.Typeable (Typeable)
import GHC.Generics (Generic)
import PlutusLedgerApi.V1.Bytes (LedgerBytes (..))
import PlutusTx qualified
import PlutusTx.Blueprint.Class (HasBlueprintSchema (..))
import PlutusTx.Blueprint.Definition (HasBlueprintDefinition (Unroll))
import PlutusTx.Blueprint.Schema (Schema (..), emptyBytesSchema)
import PlutusTx.Blueprint.Schema.Annotation (SchemaInfo (..), emptySchemaInfo)
import PlutusTx.Lift (makeLift)
import PlutusTx.Prelude qualified as PlutusTx
import PlutusTx.Show qualified as PlutusTx
import Prettyprinter

{- | The hash of a public key. This is frequently used to identify the public key,
rather than the key itself. Hashed with /BLAKE2b-224/. 28 bytes.

This is a simple type without any validation, __use with caution__.
You may want to add checks for its invariants. See the
 [Shelley ledger specification](https://github.com/IntersectMBO/cardano-ledger/releases/download/cardano-ledger-spec-2023-04-03/shelley-ledger.pdf).
-}
newtype PubKeyHash = PubKeyHash {PubKeyHash -> BuiltinByteString
getPubKeyHash :: PlutusTx.BuiltinByteString}
  deriving stock (PubKeyHash -> PubKeyHash -> Bool
(PubKeyHash -> PubKeyHash -> Bool)
-> (PubKeyHash -> PubKeyHash -> Bool) -> Eq PubKeyHash
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PubKeyHash -> PubKeyHash -> Bool
== :: PubKeyHash -> PubKeyHash -> Bool
$c/= :: PubKeyHash -> PubKeyHash -> Bool
/= :: PubKeyHash -> PubKeyHash -> Bool
Eq, Eq PubKeyHash
Eq PubKeyHash =>
(PubKeyHash -> PubKeyHash -> Ordering)
-> (PubKeyHash -> PubKeyHash -> Bool)
-> (PubKeyHash -> PubKeyHash -> Bool)
-> (PubKeyHash -> PubKeyHash -> Bool)
-> (PubKeyHash -> PubKeyHash -> Bool)
-> (PubKeyHash -> PubKeyHash -> PubKeyHash)
-> (PubKeyHash -> PubKeyHash -> PubKeyHash)
-> Ord PubKeyHash
PubKeyHash -> PubKeyHash -> Bool
PubKeyHash -> PubKeyHash -> Ordering
PubKeyHash -> PubKeyHash -> PubKeyHash
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: PubKeyHash -> PubKeyHash -> Ordering
compare :: PubKeyHash -> PubKeyHash -> Ordering
$c< :: PubKeyHash -> PubKeyHash -> Bool
< :: PubKeyHash -> PubKeyHash -> Bool
$c<= :: PubKeyHash -> PubKeyHash -> Bool
<= :: PubKeyHash -> PubKeyHash -> Bool
$c> :: PubKeyHash -> PubKeyHash -> Bool
> :: PubKeyHash -> PubKeyHash -> Bool
$c>= :: PubKeyHash -> PubKeyHash -> Bool
>= :: PubKeyHash -> PubKeyHash -> Bool
$cmax :: PubKeyHash -> PubKeyHash -> PubKeyHash
max :: PubKeyHash -> PubKeyHash -> PubKeyHash
$cmin :: PubKeyHash -> PubKeyHash -> PubKeyHash
min :: PubKeyHash -> PubKeyHash -> PubKeyHash
Ord, (forall x. PubKeyHash -> Rep PubKeyHash x)
-> (forall x. Rep PubKeyHash x -> PubKeyHash) -> Generic PubKeyHash
forall x. Rep PubKeyHash x -> PubKeyHash
forall x. PubKeyHash -> Rep PubKeyHash x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. PubKeyHash -> Rep PubKeyHash x
from :: forall x. PubKeyHash -> Rep PubKeyHash x
$cto :: forall x. Rep PubKeyHash x -> PubKeyHash
to :: forall x. Rep PubKeyHash x -> PubKeyHash
Generic, Typeable)
  deriving anyclass (PubKeyHash -> ()
(PubKeyHash -> ()) -> NFData PubKeyHash
forall a. (a -> ()) -> NFData a
$crnf :: PubKeyHash -> ()
rnf :: PubKeyHash -> ()
NFData)
  deriving newtype
    ( PubKeyHash -> PubKeyHash -> Bool
(PubKeyHash -> PubKeyHash -> Bool) -> Eq PubKeyHash
forall a. (a -> a -> Bool) -> Eq a
$c== :: PubKeyHash -> PubKeyHash -> Bool
== :: PubKeyHash -> PubKeyHash -> Bool
PlutusTx.Eq
    , Eq PubKeyHash
Eq PubKeyHash =>
(PubKeyHash -> PubKeyHash -> Ordering)
-> (PubKeyHash -> PubKeyHash -> Bool)
-> (PubKeyHash -> PubKeyHash -> Bool)
-> (PubKeyHash -> PubKeyHash -> Bool)
-> (PubKeyHash -> PubKeyHash -> Bool)
-> (PubKeyHash -> PubKeyHash -> PubKeyHash)
-> (PubKeyHash -> PubKeyHash -> PubKeyHash)
-> Ord PubKeyHash
PubKeyHash -> PubKeyHash -> Bool
PubKeyHash -> PubKeyHash -> Ordering
PubKeyHash -> PubKeyHash -> PubKeyHash
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: PubKeyHash -> PubKeyHash -> Ordering
compare :: PubKeyHash -> PubKeyHash -> Ordering
$c< :: PubKeyHash -> PubKeyHash -> Bool
< :: PubKeyHash -> PubKeyHash -> Bool
$c<= :: PubKeyHash -> PubKeyHash -> Bool
<= :: PubKeyHash -> PubKeyHash -> Bool
$c> :: PubKeyHash -> PubKeyHash -> Bool
> :: PubKeyHash -> PubKeyHash -> Bool
$c>= :: PubKeyHash -> PubKeyHash -> Bool
>= :: PubKeyHash -> PubKeyHash -> Bool
$cmax :: PubKeyHash -> PubKeyHash -> PubKeyHash
max :: PubKeyHash -> PubKeyHash -> PubKeyHash
$cmin :: PubKeyHash -> PubKeyHash -> PubKeyHash
min :: PubKeyHash -> PubKeyHash -> PubKeyHash
PlutusTx.Ord
    , Integer -> PubKeyHash -> ShowS
PubKeyHash -> BuiltinString
(Integer -> PubKeyHash -> ShowS)
-> (PubKeyHash -> BuiltinString) -> Show PubKeyHash
forall a. (Integer -> a -> ShowS) -> (a -> BuiltinString) -> Show a
$cshowsPrec :: Integer -> PubKeyHash -> ShowS
showsPrec :: Integer -> PubKeyHash -> ShowS
$cshow :: PubKeyHash -> BuiltinString
show :: PubKeyHash -> BuiltinString
PlutusTx.Show
    , PubKeyHash -> BuiltinData
(PubKeyHash -> BuiltinData) -> ToData PubKeyHash
forall a. (a -> BuiltinData) -> ToData a
$ctoBuiltinData :: PubKeyHash -> BuiltinData
toBuiltinData :: PubKeyHash -> BuiltinData
PlutusTx.ToData
    , BuiltinData -> Maybe PubKeyHash
(BuiltinData -> Maybe PubKeyHash) -> FromData PubKeyHash
forall a. (BuiltinData -> Maybe a) -> FromData a
$cfromBuiltinData :: BuiltinData -> Maybe PubKeyHash
fromBuiltinData :: BuiltinData -> Maybe PubKeyHash
PlutusTx.FromData
    , BuiltinData -> PubKeyHash
(BuiltinData -> PubKeyHash) -> UnsafeFromData PubKeyHash
forall a. (BuiltinData -> a) -> UnsafeFromData a
$cunsafeFromBuiltinData :: BuiltinData -> PubKeyHash
unsafeFromBuiltinData :: BuiltinData -> PubKeyHash
PlutusTx.UnsafeFromData
    )
  deriving
    ( String -> PubKeyHash
(String -> PubKeyHash) -> IsString PubKeyHash
forall a. (String -> a) -> IsString a
$cfromString :: String -> PubKeyHash
fromString :: String -> PubKeyHash
IsString
      -- ^ from hex encoding
    , Int -> PubKeyHash -> ShowS
[PubKeyHash] -> ShowS
PubKeyHash -> String
(Int -> PubKeyHash -> ShowS)
-> (PubKeyHash -> String)
-> ([PubKeyHash] -> ShowS)
-> Show PubKeyHash
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PubKeyHash -> ShowS
showsPrec :: Int -> PubKeyHash -> ShowS
$cshow :: PubKeyHash -> String
show :: PubKeyHash -> String
$cshowList :: [PubKeyHash] -> ShowS
showList :: [PubKeyHash] -> ShowS
Show
      -- ^ using hex encoding
    , (forall ann. PubKeyHash -> Doc ann)
-> (forall ann. [PubKeyHash] -> Doc ann) -> Pretty PubKeyHash
forall ann. [PubKeyHash] -> Doc ann
forall ann. PubKeyHash -> Doc ann
forall a.
(forall ann. a -> Doc ann)
-> (forall ann. [a] -> Doc ann) -> Pretty a
$cpretty :: forall ann. PubKeyHash -> Doc ann
pretty :: forall ann. PubKeyHash -> Doc ann
$cprettyList :: forall ann. [PubKeyHash] -> Doc ann
prettyList :: forall ann. [PubKeyHash] -> Doc ann
Pretty
      -- ^ using hex encoding
    )
    via LedgerBytes

instance HasBlueprintSchema PubKeyHash referenedTypes where
  {-# INLINABLE schema #-}
  schema :: Schema referenedTypes
schema = SchemaInfo -> BytesSchema -> Schema referenedTypes
forall (referencedTypes :: [*]).
SchemaInfo -> BytesSchema -> Schema referencedTypes
SchemaBytes SchemaInfo
emptySchemaInfo { title = Just "PubKeyHash" } BytesSchema
emptyBytesSchema

instance HasBlueprintDefinition PubKeyHash where
  type Unroll PubKeyHash = '[PubKeyHash]

----------------------------------------------------------------------------------------------------
-- TH Splices --------------------------------------------------------------------------------------

$(makeLift ''PubKeyHash)