{-# LANGUAGE DataKinds         #-}
{-# LANGUAGE DeriveAnyClass    #-}
{-# LANGUAGE DeriveGeneric     #-}
{-# LANGUAGE DerivingVia       #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell   #-}
{-# LANGUAGE TypeApplications  #-}

{-# OPTIONS_GHC -fno-omit-interface-pragmas #-}

module Plutus.V1.Ledger.Crypto(
    PubKey(..)
    , PubKeyHash(..)
    , PrivateKey(..)
    , Signature(..)
    ) where

import Codec.Serialise.Class (Serialise)
import Control.DeepSeq (NFData)
import Control.Newtype.Generics (Newtype)
import Data.Aeson (FromJSON (parseJSON), FromJSONKey, FromJSONKeyFunction (FromJSONKeyValue), ToJSON (toJSON),
                   ToJSONKey, ToJSONKeyFunction (ToJSONKeyValue), genericParseJSON, genericToJSON, (.:))
import Data.Aeson qualified as JSON
import Data.Aeson.Extras qualified as JSON
import Data.Hashable (Hashable)
import Data.String
import GHC.Generics (Generic)
import Plutus.V1.Ledger.Bytes (LedgerBytes (..))
import Plutus.V1.Ledger.Orphans ()
import PlutusTx qualified
import PlutusTx.Lift (makeLift)
import PlutusTx.Prelude qualified as PlutusTx
import Prettyprinter

-- | A cryptographic public key.
newtype PubKey = PubKey { PubKey -> LedgerBytes
getPubKey :: LedgerBytes }
    deriving stock (PubKey -> PubKey -> Bool
(PubKey -> PubKey -> Bool)
-> (PubKey -> PubKey -> Bool) -> Eq PubKey
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PubKey -> PubKey -> Bool
$c/= :: PubKey -> PubKey -> Bool
== :: PubKey -> PubKey -> Bool
$c== :: PubKey -> PubKey -> Bool
Eq, Eq PubKey
Eq PubKey
-> (PubKey -> PubKey -> Ordering)
-> (PubKey -> PubKey -> Bool)
-> (PubKey -> PubKey -> Bool)
-> (PubKey -> PubKey -> Bool)
-> (PubKey -> PubKey -> Bool)
-> (PubKey -> PubKey -> PubKey)
-> (PubKey -> PubKey -> PubKey)
-> Ord PubKey
PubKey -> PubKey -> Bool
PubKey -> PubKey -> Ordering
PubKey -> PubKey -> PubKey
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
min :: PubKey -> PubKey -> PubKey
$cmin :: PubKey -> PubKey -> PubKey
max :: PubKey -> PubKey -> PubKey
$cmax :: PubKey -> PubKey -> PubKey
>= :: PubKey -> PubKey -> Bool
$c>= :: PubKey -> PubKey -> Bool
> :: PubKey -> PubKey -> Bool
$c> :: PubKey -> PubKey -> Bool
<= :: PubKey -> PubKey -> Bool
$c<= :: PubKey -> PubKey -> Bool
< :: PubKey -> PubKey -> Bool
$c< :: PubKey -> PubKey -> Bool
compare :: PubKey -> PubKey -> Ordering
$ccompare :: PubKey -> PubKey -> Ordering
$cp1Ord :: Eq PubKey
Ord, (forall x. PubKey -> Rep PubKey x)
-> (forall x. Rep PubKey x -> PubKey) -> Generic PubKey
forall x. Rep PubKey x -> PubKey
forall x. PubKey -> Rep PubKey x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PubKey x -> PubKey
$cfrom :: forall x. PubKey -> Rep PubKey x
Generic)
    deriving anyclass (O PubKey -> PubKey
PubKey -> O PubKey
(O PubKey -> PubKey) -> (PubKey -> O PubKey) -> Newtype PubKey
forall n. (O n -> n) -> (n -> O n) -> Newtype n
unpack :: PubKey -> O PubKey
$cunpack :: PubKey -> O PubKey
pack :: O PubKey -> PubKey
$cpack :: O PubKey -> PubKey
Newtype, [PubKey] -> Encoding
[PubKey] -> Value
PubKey -> Encoding
PubKey -> Value
(PubKey -> Value)
-> (PubKey -> Encoding)
-> ([PubKey] -> Value)
-> ([PubKey] -> Encoding)
-> ToJSON PubKey
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
toEncodingList :: [PubKey] -> Encoding
$ctoEncodingList :: [PubKey] -> Encoding
toJSONList :: [PubKey] -> Value
$ctoJSONList :: [PubKey] -> Value
toEncoding :: PubKey -> Encoding
$ctoEncoding :: PubKey -> Encoding
toJSON :: PubKey -> Value
$ctoJSON :: PubKey -> Value
ToJSON, Value -> Parser [PubKey]
Value -> Parser PubKey
(Value -> Parser PubKey)
-> (Value -> Parser [PubKey]) -> FromJSON PubKey
forall a.
(Value -> Parser a) -> (Value -> Parser [a]) -> FromJSON a
parseJSONList :: Value -> Parser [PubKey]
$cparseJSONList :: Value -> Parser [PubKey]
parseJSON :: Value -> Parser PubKey
$cparseJSON :: Value -> Parser PubKey
FromJSON, PubKey -> ()
(PubKey -> ()) -> NFData PubKey
forall a. (a -> ()) -> NFData a
rnf :: PubKey -> ()
$crnf :: PubKey -> ()
NFData)
    deriving newtype (PubKey -> PubKey -> Bool
(PubKey -> PubKey -> Bool) -> Eq PubKey
forall a. (a -> a -> Bool) -> Eq a
== :: PubKey -> PubKey -> Bool
$c== :: PubKey -> PubKey -> Bool
PlutusTx.Eq, Eq PubKey
Eq PubKey
-> (PubKey -> PubKey -> Ordering)
-> (PubKey -> PubKey -> Bool)
-> (PubKey -> PubKey -> Bool)
-> (PubKey -> PubKey -> Bool)
-> (PubKey -> PubKey -> Bool)
-> (PubKey -> PubKey -> PubKey)
-> (PubKey -> PubKey -> PubKey)
-> Ord PubKey
PubKey -> PubKey -> Bool
PubKey -> PubKey -> Ordering
PubKey -> PubKey -> PubKey
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
min :: PubKey -> PubKey -> PubKey
$cmin :: PubKey -> PubKey -> PubKey
max :: PubKey -> PubKey -> PubKey
$cmax :: PubKey -> PubKey -> PubKey
>= :: PubKey -> PubKey -> Bool
$c>= :: PubKey -> PubKey -> Bool
> :: PubKey -> PubKey -> Bool
$c> :: PubKey -> PubKey -> Bool
<= :: PubKey -> PubKey -> Bool
$c<= :: PubKey -> PubKey -> Bool
< :: PubKey -> PubKey -> Bool
$c< :: PubKey -> PubKey -> Bool
compare :: PubKey -> PubKey -> Ordering
$ccompare :: PubKey -> PubKey -> Ordering
$cp1Ord :: Eq PubKey
PlutusTx.Ord, Decoder s PubKey
Decoder s [PubKey]
[PubKey] -> Encoding
PubKey -> Encoding
(PubKey -> Encoding)
-> (forall s. Decoder s PubKey)
-> ([PubKey] -> Encoding)
-> (forall s. Decoder s [PubKey])
-> Serialise PubKey
forall s. Decoder s [PubKey]
forall s. Decoder s PubKey
forall a.
(a -> Encoding)
-> (forall s. Decoder s a)
-> ([a] -> Encoding)
-> (forall s. Decoder s [a])
-> Serialise a
decodeList :: Decoder s [PubKey]
$cdecodeList :: forall s. Decoder s [PubKey]
encodeList :: [PubKey] -> Encoding
$cencodeList :: [PubKey] -> Encoding
decode :: Decoder s PubKey
$cdecode :: forall s. Decoder s PubKey
encode :: PubKey -> Encoding
$cencode :: PubKey -> Encoding
Serialise, PubKey -> BuiltinData
(PubKey -> BuiltinData) -> ToData PubKey
forall a. (a -> BuiltinData) -> ToData a
toBuiltinData :: PubKey -> BuiltinData
$ctoBuiltinData :: PubKey -> BuiltinData
PlutusTx.ToData, BuiltinData -> Maybe PubKey
(BuiltinData -> Maybe PubKey) -> FromData PubKey
forall a. (BuiltinData -> Maybe a) -> FromData a
fromBuiltinData :: BuiltinData -> Maybe PubKey
$cfromBuiltinData :: BuiltinData -> Maybe PubKey
PlutusTx.FromData, BuiltinData -> PubKey
(BuiltinData -> PubKey) -> UnsafeFromData PubKey
forall a. (BuiltinData -> a) -> UnsafeFromData a
unsafeFromBuiltinData :: BuiltinData -> PubKey
$cunsafeFromBuiltinData :: BuiltinData -> PubKey
PlutusTx.UnsafeFromData)
    deriving String -> PubKey
(String -> PubKey) -> IsString PubKey
forall a. (String -> a) -> IsString a
fromString :: String -> PubKey
$cfromString :: String -> PubKey
IsString via LedgerBytes
    deriving (Int -> PubKey -> ShowS
[PubKey] -> ShowS
PubKey -> String
(Int -> PubKey -> ShowS)
-> (PubKey -> String) -> ([PubKey] -> ShowS) -> Show PubKey
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PubKey] -> ShowS
$cshowList :: [PubKey] -> ShowS
show :: PubKey -> String
$cshow :: PubKey -> String
showsPrec :: Int -> PubKey -> ShowS
$cshowsPrec :: Int -> PubKey -> ShowS
Show, [PubKey] -> Doc ann
PubKey -> Doc ann
(forall ann. PubKey -> Doc ann)
-> (forall ann. [PubKey] -> Doc ann) -> Pretty PubKey
forall ann. [PubKey] -> Doc ann
forall ann. PubKey -> Doc ann
forall a.
(forall ann. a -> Doc ann)
-> (forall ann. [a] -> Doc ann) -> Pretty a
prettyList :: [PubKey] -> Doc ann
$cprettyList :: forall ann. [PubKey] -> Doc ann
pretty :: PubKey -> Doc ann
$cpretty :: forall ann. PubKey -> Doc ann
Pretty) via LedgerBytes
makeLift ''PubKey

instance ToJSONKey PubKey where
  toJSONKey :: ToJSONKeyFunction PubKey
toJSONKey = (PubKey -> Value)
-> (PubKey -> Encoding) -> ToJSONKeyFunction PubKey
forall a. (a -> Value) -> (a -> Encoding) -> ToJSONKeyFunction a
ToJSONKeyValue (Options -> PubKey -> Value
forall a.
(Generic a, GToJSON' Value Zero (Rep a)) =>
Options -> a -> Value
genericToJSON Options
JSON.defaultOptions) PubKey -> Encoding
forall a. ToJSON a => a -> Encoding
JSON.toEncoding

instance FromJSONKey PubKey where
  fromJSONKey :: FromJSONKeyFunction PubKey
fromJSONKey = (Value -> Parser PubKey) -> FromJSONKeyFunction PubKey
forall a. (Value -> Parser a) -> FromJSONKeyFunction a
FromJSONKeyValue (Options -> Value -> Parser PubKey
forall a.
(Generic a, GFromJSON Zero (Rep a)) =>
Options -> Value -> Parser a
genericParseJSON Options
JSON.defaultOptions)

-- | The hash of a public key. This is frequently used to identify the public key, rather than the key itself.
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
/= :: PubKeyHash -> PubKeyHash -> Bool
$c/= :: PubKeyHash -> PubKeyHash -> Bool
== :: PubKeyHash -> PubKeyHash -> Bool
$c== :: 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
min :: PubKeyHash -> PubKeyHash -> PubKeyHash
$cmin :: PubKeyHash -> PubKeyHash -> PubKeyHash
max :: PubKeyHash -> PubKeyHash -> PubKeyHash
$cmax :: PubKeyHash -> PubKeyHash -> PubKeyHash
>= :: PubKeyHash -> PubKeyHash -> Bool
$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
compare :: PubKeyHash -> PubKeyHash -> Ordering
$ccompare :: PubKeyHash -> PubKeyHash -> Ordering
$cp1Ord :: Eq 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
$cto :: forall x. Rep PubKeyHash x -> PubKeyHash
$cfrom :: forall x. PubKeyHash -> Rep PubKeyHash x
Generic)
    deriving anyclass ([PubKeyHash] -> Encoding
[PubKeyHash] -> Value
PubKeyHash -> Encoding
PubKeyHash -> Value
(PubKeyHash -> Value)
-> (PubKeyHash -> Encoding)
-> ([PubKeyHash] -> Value)
-> ([PubKeyHash] -> Encoding)
-> ToJSON PubKeyHash
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
toEncodingList :: [PubKeyHash] -> Encoding
$ctoEncodingList :: [PubKeyHash] -> Encoding
toJSONList :: [PubKeyHash] -> Value
$ctoJSONList :: [PubKeyHash] -> Value
toEncoding :: PubKeyHash -> Encoding
$ctoEncoding :: PubKeyHash -> Encoding
toJSON :: PubKeyHash -> Value
$ctoJSON :: PubKeyHash -> Value
ToJSON, Value -> Parser [PubKeyHash]
Value -> Parser PubKeyHash
(Value -> Parser PubKeyHash)
-> (Value -> Parser [PubKeyHash]) -> FromJSON PubKeyHash
forall a.
(Value -> Parser a) -> (Value -> Parser [a]) -> FromJSON a
parseJSONList :: Value -> Parser [PubKeyHash]
$cparseJSONList :: Value -> Parser [PubKeyHash]
parseJSON :: Value -> Parser PubKeyHash
$cparseJSON :: Value -> Parser PubKeyHash
FromJSON, O PubKeyHash -> PubKeyHash
PubKeyHash -> O PubKeyHash
(O PubKeyHash -> PubKeyHash)
-> (PubKeyHash -> O PubKeyHash) -> Newtype PubKeyHash
forall n. (O n -> n) -> (n -> O n) -> Newtype n
unpack :: PubKeyHash -> O PubKeyHash
$cunpack :: PubKeyHash -> O PubKeyHash
pack :: O PubKeyHash -> PubKeyHash
$cpack :: O PubKeyHash -> PubKeyHash
Newtype, ToJSONKeyFunction [PubKeyHash]
ToJSONKeyFunction PubKeyHash
ToJSONKeyFunction PubKeyHash
-> ToJSONKeyFunction [PubKeyHash] -> ToJSONKey PubKeyHash
forall a.
ToJSONKeyFunction a -> ToJSONKeyFunction [a] -> ToJSONKey a
toJSONKeyList :: ToJSONKeyFunction [PubKeyHash]
$ctoJSONKeyList :: ToJSONKeyFunction [PubKeyHash]
toJSONKey :: ToJSONKeyFunction PubKeyHash
$ctoJSONKey :: ToJSONKeyFunction PubKeyHash
ToJSONKey, FromJSONKeyFunction [PubKeyHash]
FromJSONKeyFunction PubKeyHash
FromJSONKeyFunction PubKeyHash
-> FromJSONKeyFunction [PubKeyHash] -> FromJSONKey PubKeyHash
forall a.
FromJSONKeyFunction a -> FromJSONKeyFunction [a] -> FromJSONKey a
fromJSONKeyList :: FromJSONKeyFunction [PubKeyHash]
$cfromJSONKeyList :: FromJSONKeyFunction [PubKeyHash]
fromJSONKey :: FromJSONKeyFunction PubKeyHash
$cfromJSONKey :: FromJSONKeyFunction PubKeyHash
FromJSONKey, PubKeyHash -> ()
(PubKeyHash -> ()) -> NFData PubKeyHash
forall a. (a -> ()) -> NFData a
rnf :: PubKeyHash -> ()
$crnf :: PubKeyHash -> ()
NFData)
    deriving newtype (PubKeyHash -> PubKeyHash -> Bool
(PubKeyHash -> PubKeyHash -> Bool) -> Eq PubKeyHash
forall a. (a -> a -> Bool) -> Eq a
== :: PubKeyHash -> PubKeyHash -> Bool
$c== :: 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
min :: PubKeyHash -> PubKeyHash -> PubKeyHash
$cmin :: PubKeyHash -> PubKeyHash -> PubKeyHash
max :: PubKeyHash -> PubKeyHash -> PubKeyHash
$cmax :: PubKeyHash -> PubKeyHash -> PubKeyHash
>= :: PubKeyHash -> PubKeyHash -> Bool
$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
compare :: PubKeyHash -> PubKeyHash -> Ordering
$ccompare :: PubKeyHash -> PubKeyHash -> Ordering
$cp1Ord :: Eq PubKeyHash
PlutusTx.Ord, Decoder s PubKeyHash
Decoder s [PubKeyHash]
[PubKeyHash] -> Encoding
PubKeyHash -> Encoding
(PubKeyHash -> Encoding)
-> (forall s. Decoder s PubKeyHash)
-> ([PubKeyHash] -> Encoding)
-> (forall s. Decoder s [PubKeyHash])
-> Serialise PubKeyHash
forall s. Decoder s [PubKeyHash]
forall s. Decoder s PubKeyHash
forall a.
(a -> Encoding)
-> (forall s. Decoder s a)
-> ([a] -> Encoding)
-> (forall s. Decoder s [a])
-> Serialise a
decodeList :: Decoder s [PubKeyHash]
$cdecodeList :: forall s. Decoder s [PubKeyHash]
encodeList :: [PubKeyHash] -> Encoding
$cencodeList :: [PubKeyHash] -> Encoding
decode :: Decoder s PubKeyHash
$cdecode :: forall s. Decoder s PubKeyHash
encode :: PubKeyHash -> Encoding
$cencode :: PubKeyHash -> Encoding
Serialise, Int -> PubKeyHash -> Int
PubKeyHash -> Int
(Int -> PubKeyHash -> Int)
-> (PubKeyHash -> Int) -> Hashable PubKeyHash
forall a. (Int -> a -> Int) -> (a -> Int) -> Hashable a
hash :: PubKeyHash -> Int
$chash :: PubKeyHash -> Int
hashWithSalt :: Int -> PubKeyHash -> Int
$chashWithSalt :: Int -> PubKeyHash -> Int
Hashable, PubKeyHash -> BuiltinData
(PubKeyHash -> BuiltinData) -> ToData PubKeyHash
forall a. (a -> BuiltinData) -> ToData a
toBuiltinData :: PubKeyHash -> BuiltinData
$ctoBuiltinData :: PubKeyHash -> BuiltinData
PlutusTx.ToData, BuiltinData -> Maybe PubKeyHash
(BuiltinData -> Maybe PubKeyHash) -> FromData PubKeyHash
forall a. (BuiltinData -> Maybe a) -> FromData a
fromBuiltinData :: BuiltinData -> Maybe PubKeyHash
$cfromBuiltinData :: BuiltinData -> Maybe PubKeyHash
PlutusTx.FromData, BuiltinData -> PubKeyHash
(BuiltinData -> PubKeyHash) -> UnsafeFromData PubKeyHash
forall a. (BuiltinData -> a) -> UnsafeFromData a
unsafeFromBuiltinData :: BuiltinData -> PubKeyHash
$cunsafeFromBuiltinData :: BuiltinData -> PubKeyHash
PlutusTx.UnsafeFromData)
    deriving String -> PubKeyHash
(String -> PubKeyHash) -> IsString PubKeyHash
forall a. (String -> a) -> IsString a
fromString :: String -> PubKeyHash
$cfromString :: String -> PubKeyHash
IsString via LedgerBytes
    deriving (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
showList :: [PubKeyHash] -> ShowS
$cshowList :: [PubKeyHash] -> ShowS
show :: PubKeyHash -> String
$cshow :: PubKeyHash -> String
showsPrec :: Int -> PubKeyHash -> ShowS
$cshowsPrec :: Int -> PubKeyHash -> ShowS
Show, [PubKeyHash] -> Doc ann
PubKeyHash -> Doc ann
(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
prettyList :: [PubKeyHash] -> Doc ann
$cprettyList :: forall ann. [PubKeyHash] -> Doc ann
pretty :: PubKeyHash -> Doc ann
$cpretty :: forall ann. PubKeyHash -> Doc ann
Pretty) via LedgerBytes
makeLift ''PubKeyHash

-- | A cryptographic private key.
newtype PrivateKey = PrivateKey { PrivateKey -> LedgerBytes
getPrivateKey :: LedgerBytes }
    deriving stock (PrivateKey -> PrivateKey -> Bool
(PrivateKey -> PrivateKey -> Bool)
-> (PrivateKey -> PrivateKey -> Bool) -> Eq PrivateKey
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PrivateKey -> PrivateKey -> Bool
$c/= :: PrivateKey -> PrivateKey -> Bool
== :: PrivateKey -> PrivateKey -> Bool
$c== :: PrivateKey -> PrivateKey -> Bool
Eq, Eq PrivateKey
Eq PrivateKey
-> (PrivateKey -> PrivateKey -> Ordering)
-> (PrivateKey -> PrivateKey -> Bool)
-> (PrivateKey -> PrivateKey -> Bool)
-> (PrivateKey -> PrivateKey -> Bool)
-> (PrivateKey -> PrivateKey -> Bool)
-> (PrivateKey -> PrivateKey -> PrivateKey)
-> (PrivateKey -> PrivateKey -> PrivateKey)
-> Ord PrivateKey
PrivateKey -> PrivateKey -> Bool
PrivateKey -> PrivateKey -> Ordering
PrivateKey -> PrivateKey -> PrivateKey
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
min :: PrivateKey -> PrivateKey -> PrivateKey
$cmin :: PrivateKey -> PrivateKey -> PrivateKey
max :: PrivateKey -> PrivateKey -> PrivateKey
$cmax :: PrivateKey -> PrivateKey -> PrivateKey
>= :: PrivateKey -> PrivateKey -> Bool
$c>= :: PrivateKey -> PrivateKey -> Bool
> :: PrivateKey -> PrivateKey -> Bool
$c> :: PrivateKey -> PrivateKey -> Bool
<= :: PrivateKey -> PrivateKey -> Bool
$c<= :: PrivateKey -> PrivateKey -> Bool
< :: PrivateKey -> PrivateKey -> Bool
$c< :: PrivateKey -> PrivateKey -> Bool
compare :: PrivateKey -> PrivateKey -> Ordering
$ccompare :: PrivateKey -> PrivateKey -> Ordering
$cp1Ord :: Eq PrivateKey
Ord, (forall x. PrivateKey -> Rep PrivateKey x)
-> (forall x. Rep PrivateKey x -> PrivateKey) -> Generic PrivateKey
forall x. Rep PrivateKey x -> PrivateKey
forall x. PrivateKey -> Rep PrivateKey x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PrivateKey x -> PrivateKey
$cfrom :: forall x. PrivateKey -> Rep PrivateKey x
Generic)
    deriving anyclass ([PrivateKey] -> Encoding
[PrivateKey] -> Value
PrivateKey -> Encoding
PrivateKey -> Value
(PrivateKey -> Value)
-> (PrivateKey -> Encoding)
-> ([PrivateKey] -> Value)
-> ([PrivateKey] -> Encoding)
-> ToJSON PrivateKey
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
toEncodingList :: [PrivateKey] -> Encoding
$ctoEncodingList :: [PrivateKey] -> Encoding
toJSONList :: [PrivateKey] -> Value
$ctoJSONList :: [PrivateKey] -> Value
toEncoding :: PrivateKey -> Encoding
$ctoEncoding :: PrivateKey -> Encoding
toJSON :: PrivateKey -> Value
$ctoJSON :: PrivateKey -> Value
ToJSON, Value -> Parser [PrivateKey]
Value -> Parser PrivateKey
(Value -> Parser PrivateKey)
-> (Value -> Parser [PrivateKey]) -> FromJSON PrivateKey
forall a.
(Value -> Parser a) -> (Value -> Parser [a]) -> FromJSON a
parseJSONList :: Value -> Parser [PrivateKey]
$cparseJSONList :: Value -> Parser [PrivateKey]
parseJSON :: Value -> Parser PrivateKey
$cparseJSON :: Value -> Parser PrivateKey
FromJSON, O PrivateKey -> PrivateKey
PrivateKey -> O PrivateKey
(O PrivateKey -> PrivateKey)
-> (PrivateKey -> O PrivateKey) -> Newtype PrivateKey
forall n. (O n -> n) -> (n -> O n) -> Newtype n
unpack :: PrivateKey -> O PrivateKey
$cunpack :: PrivateKey -> O PrivateKey
pack :: O PrivateKey -> PrivateKey
$cpack :: O PrivateKey -> PrivateKey
Newtype, ToJSONKeyFunction [PrivateKey]
ToJSONKeyFunction PrivateKey
ToJSONKeyFunction PrivateKey
-> ToJSONKeyFunction [PrivateKey] -> ToJSONKey PrivateKey
forall a.
ToJSONKeyFunction a -> ToJSONKeyFunction [a] -> ToJSONKey a
toJSONKeyList :: ToJSONKeyFunction [PrivateKey]
$ctoJSONKeyList :: ToJSONKeyFunction [PrivateKey]
toJSONKey :: ToJSONKeyFunction PrivateKey
$ctoJSONKey :: ToJSONKeyFunction PrivateKey
ToJSONKey, FromJSONKeyFunction [PrivateKey]
FromJSONKeyFunction PrivateKey
FromJSONKeyFunction PrivateKey
-> FromJSONKeyFunction [PrivateKey] -> FromJSONKey PrivateKey
forall a.
FromJSONKeyFunction a -> FromJSONKeyFunction [a] -> FromJSONKey a
fromJSONKeyList :: FromJSONKeyFunction [PrivateKey]
$cfromJSONKeyList :: FromJSONKeyFunction [PrivateKey]
fromJSONKey :: FromJSONKeyFunction PrivateKey
$cfromJSONKey :: FromJSONKeyFunction PrivateKey
FromJSONKey)
    deriving newtype (PrivateKey -> PrivateKey -> Bool
(PrivateKey -> PrivateKey -> Bool) -> Eq PrivateKey
forall a. (a -> a -> Bool) -> Eq a
== :: PrivateKey -> PrivateKey -> Bool
$c== :: PrivateKey -> PrivateKey -> Bool
PlutusTx.Eq, Eq PrivateKey
Eq PrivateKey
-> (PrivateKey -> PrivateKey -> Ordering)
-> (PrivateKey -> PrivateKey -> Bool)
-> (PrivateKey -> PrivateKey -> Bool)
-> (PrivateKey -> PrivateKey -> Bool)
-> (PrivateKey -> PrivateKey -> Bool)
-> (PrivateKey -> PrivateKey -> PrivateKey)
-> (PrivateKey -> PrivateKey -> PrivateKey)
-> Ord PrivateKey
PrivateKey -> PrivateKey -> Bool
PrivateKey -> PrivateKey -> Ordering
PrivateKey -> PrivateKey -> PrivateKey
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
min :: PrivateKey -> PrivateKey -> PrivateKey
$cmin :: PrivateKey -> PrivateKey -> PrivateKey
max :: PrivateKey -> PrivateKey -> PrivateKey
$cmax :: PrivateKey -> PrivateKey -> PrivateKey
>= :: PrivateKey -> PrivateKey -> Bool
$c>= :: PrivateKey -> PrivateKey -> Bool
> :: PrivateKey -> PrivateKey -> Bool
$c> :: PrivateKey -> PrivateKey -> Bool
<= :: PrivateKey -> PrivateKey -> Bool
$c<= :: PrivateKey -> PrivateKey -> Bool
< :: PrivateKey -> PrivateKey -> Bool
$c< :: PrivateKey -> PrivateKey -> Bool
compare :: PrivateKey -> PrivateKey -> Ordering
$ccompare :: PrivateKey -> PrivateKey -> Ordering
$cp1Ord :: Eq PrivateKey
PlutusTx.Ord, Decoder s PrivateKey
Decoder s [PrivateKey]
[PrivateKey] -> Encoding
PrivateKey -> Encoding
(PrivateKey -> Encoding)
-> (forall s. Decoder s PrivateKey)
-> ([PrivateKey] -> Encoding)
-> (forall s. Decoder s [PrivateKey])
-> Serialise PrivateKey
forall s. Decoder s [PrivateKey]
forall s. Decoder s PrivateKey
forall a.
(a -> Encoding)
-> (forall s. Decoder s a)
-> ([a] -> Encoding)
-> (forall s. Decoder s [a])
-> Serialise a
decodeList :: Decoder s [PrivateKey]
$cdecodeList :: forall s. Decoder s [PrivateKey]
encodeList :: [PrivateKey] -> Encoding
$cencodeList :: [PrivateKey] -> Encoding
decode :: Decoder s PrivateKey
$cdecode :: forall s. Decoder s PrivateKey
encode :: PrivateKey -> Encoding
$cencode :: PrivateKey -> Encoding
Serialise, PrivateKey -> BuiltinData
(PrivateKey -> BuiltinData) -> ToData PrivateKey
forall a. (a -> BuiltinData) -> ToData a
toBuiltinData :: PrivateKey -> BuiltinData
$ctoBuiltinData :: PrivateKey -> BuiltinData
PlutusTx.ToData, BuiltinData -> Maybe PrivateKey
(BuiltinData -> Maybe PrivateKey) -> FromData PrivateKey
forall a. (BuiltinData -> Maybe a) -> FromData a
fromBuiltinData :: BuiltinData -> Maybe PrivateKey
$cfromBuiltinData :: BuiltinData -> Maybe PrivateKey
PlutusTx.FromData, BuiltinData -> PrivateKey
(BuiltinData -> PrivateKey) -> UnsafeFromData PrivateKey
forall a. (BuiltinData -> a) -> UnsafeFromData a
unsafeFromBuiltinData :: BuiltinData -> PrivateKey
$cunsafeFromBuiltinData :: BuiltinData -> PrivateKey
PlutusTx.UnsafeFromData)
    deriving (Int -> PrivateKey -> ShowS
[PrivateKey] -> ShowS
PrivateKey -> String
(Int -> PrivateKey -> ShowS)
-> (PrivateKey -> String)
-> ([PrivateKey] -> ShowS)
-> Show PrivateKey
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PrivateKey] -> ShowS
$cshowList :: [PrivateKey] -> ShowS
show :: PrivateKey -> String
$cshow :: PrivateKey -> String
showsPrec :: Int -> PrivateKey -> ShowS
$cshowsPrec :: Int -> PrivateKey -> ShowS
Show, [PrivateKey] -> Doc ann
PrivateKey -> Doc ann
(forall ann. PrivateKey -> Doc ann)
-> (forall ann. [PrivateKey] -> Doc ann) -> Pretty PrivateKey
forall ann. [PrivateKey] -> Doc ann
forall ann. PrivateKey -> Doc ann
forall a.
(forall ann. a -> Doc ann)
-> (forall ann. [a] -> Doc ann) -> Pretty a
prettyList :: [PrivateKey] -> Doc ann
$cprettyList :: forall ann. [PrivateKey] -> Doc ann
pretty :: PrivateKey -> Doc ann
$cpretty :: forall ann. PrivateKey -> Doc ann
Pretty) via LedgerBytes
    deriving Int -> PrivateKey -> Int
PrivateKey -> Int
(Int -> PrivateKey -> Int)
-> (PrivateKey -> Int) -> Hashable PrivateKey
forall a. (Int -> a -> Int) -> (a -> Int) -> Hashable a
hash :: PrivateKey -> Int
$chash :: PrivateKey -> Int
hashWithSalt :: Int -> PrivateKey -> Int
$chashWithSalt :: Int -> PrivateKey -> Int
Hashable via PlutusTx.BuiltinByteString

makeLift ''PrivateKey

-- | A message with a cryptographic signature.
newtype Signature = Signature { Signature -> BuiltinByteString
getSignature :: PlutusTx.BuiltinByteString }
    deriving stock (Signature -> Signature -> Bool
(Signature -> Signature -> Bool)
-> (Signature -> Signature -> Bool) -> Eq Signature
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Signature -> Signature -> Bool
$c/= :: Signature -> Signature -> Bool
== :: Signature -> Signature -> Bool
$c== :: Signature -> Signature -> Bool
Eq, Eq Signature
Eq Signature
-> (Signature -> Signature -> Ordering)
-> (Signature -> Signature -> Bool)
-> (Signature -> Signature -> Bool)
-> (Signature -> Signature -> Bool)
-> (Signature -> Signature -> Bool)
-> (Signature -> Signature -> Signature)
-> (Signature -> Signature -> Signature)
-> Ord Signature
Signature -> Signature -> Bool
Signature -> Signature -> Ordering
Signature -> Signature -> Signature
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
min :: Signature -> Signature -> Signature
$cmin :: Signature -> Signature -> Signature
max :: Signature -> Signature -> Signature
$cmax :: Signature -> Signature -> Signature
>= :: Signature -> Signature -> Bool
$c>= :: Signature -> Signature -> Bool
> :: Signature -> Signature -> Bool
$c> :: Signature -> Signature -> Bool
<= :: Signature -> Signature -> Bool
$c<= :: Signature -> Signature -> Bool
< :: Signature -> Signature -> Bool
$c< :: Signature -> Signature -> Bool
compare :: Signature -> Signature -> Ordering
$ccompare :: Signature -> Signature -> Ordering
$cp1Ord :: Eq Signature
Ord, (forall x. Signature -> Rep Signature x)
-> (forall x. Rep Signature x -> Signature) -> Generic Signature
forall x. Rep Signature x -> Signature
forall x. Signature -> Rep Signature x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Signature x -> Signature
$cfrom :: forall x. Signature -> Rep Signature x
Generic)
    deriving newtype (Signature -> Signature -> Bool
(Signature -> Signature -> Bool) -> Eq Signature
forall a. (a -> a -> Bool) -> Eq a
== :: Signature -> Signature -> Bool
$c== :: Signature -> Signature -> Bool
PlutusTx.Eq, Eq Signature
Eq Signature
-> (Signature -> Signature -> Ordering)
-> (Signature -> Signature -> Bool)
-> (Signature -> Signature -> Bool)
-> (Signature -> Signature -> Bool)
-> (Signature -> Signature -> Bool)
-> (Signature -> Signature -> Signature)
-> (Signature -> Signature -> Signature)
-> Ord Signature
Signature -> Signature -> Bool
Signature -> Signature -> Ordering
Signature -> Signature -> Signature
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
min :: Signature -> Signature -> Signature
$cmin :: Signature -> Signature -> Signature
max :: Signature -> Signature -> Signature
$cmax :: Signature -> Signature -> Signature
>= :: Signature -> Signature -> Bool
$c>= :: Signature -> Signature -> Bool
> :: Signature -> Signature -> Bool
$c> :: Signature -> Signature -> Bool
<= :: Signature -> Signature -> Bool
$c<= :: Signature -> Signature -> Bool
< :: Signature -> Signature -> Bool
$c< :: Signature -> Signature -> Bool
compare :: Signature -> Signature -> Ordering
$ccompare :: Signature -> Signature -> Ordering
$cp1Ord :: Eq Signature
PlutusTx.Ord, Decoder s Signature
Decoder s [Signature]
[Signature] -> Encoding
Signature -> Encoding
(Signature -> Encoding)
-> (forall s. Decoder s Signature)
-> ([Signature] -> Encoding)
-> (forall s. Decoder s [Signature])
-> Serialise Signature
forall s. Decoder s [Signature]
forall s. Decoder s Signature
forall a.
(a -> Encoding)
-> (forall s. Decoder s a)
-> ([a] -> Encoding)
-> (forall s. Decoder s [a])
-> Serialise a
decodeList :: Decoder s [Signature]
$cdecodeList :: forall s. Decoder s [Signature]
encodeList :: [Signature] -> Encoding
$cencodeList :: [Signature] -> Encoding
decode :: Decoder s Signature
$cdecode :: forall s. Decoder s Signature
encode :: Signature -> Encoding
$cencode :: Signature -> Encoding
Serialise, Signature -> ()
(Signature -> ()) -> NFData Signature
forall a. (a -> ()) -> NFData a
rnf :: Signature -> ()
$crnf :: Signature -> ()
NFData, Signature -> BuiltinData
(Signature -> BuiltinData) -> ToData Signature
forall a. (a -> BuiltinData) -> ToData a
toBuiltinData :: Signature -> BuiltinData
$ctoBuiltinData :: Signature -> BuiltinData
PlutusTx.ToData, BuiltinData -> Maybe Signature
(BuiltinData -> Maybe Signature) -> FromData Signature
forall a. (BuiltinData -> Maybe a) -> FromData a
fromBuiltinData :: BuiltinData -> Maybe Signature
$cfromBuiltinData :: BuiltinData -> Maybe Signature
PlutusTx.FromData, BuiltinData -> Signature
(BuiltinData -> Signature) -> UnsafeFromData Signature
forall a. (BuiltinData -> a) -> UnsafeFromData a
unsafeFromBuiltinData :: BuiltinData -> Signature
$cunsafeFromBuiltinData :: BuiltinData -> Signature
PlutusTx.UnsafeFromData)
    deriving (Int -> Signature -> ShowS
[Signature] -> ShowS
Signature -> String
(Int -> Signature -> ShowS)
-> (Signature -> String)
-> ([Signature] -> ShowS)
-> Show Signature
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Signature] -> ShowS
$cshowList :: [Signature] -> ShowS
show :: Signature -> String
$cshow :: Signature -> String
showsPrec :: Int -> Signature -> ShowS
$cshowsPrec :: Int -> Signature -> ShowS
Show, [Signature] -> Doc ann
Signature -> Doc ann
(forall ann. Signature -> Doc ann)
-> (forall ann. [Signature] -> Doc ann) -> Pretty Signature
forall ann. [Signature] -> Doc ann
forall ann. Signature -> Doc ann
forall a.
(forall ann. a -> Doc ann)
-> (forall ann. [a] -> Doc ann) -> Pretty a
prettyList :: [Signature] -> Doc ann
$cprettyList :: forall ann. [Signature] -> Doc ann
pretty :: Signature -> Doc ann
$cpretty :: forall ann. Signature -> Doc ann
Pretty) via LedgerBytes

instance ToJSON Signature where
  toJSON :: Signature -> Value
toJSON Signature
signature =
    [Pair] -> Value
JSON.object
      [ ( Text
"getSignature"
        , Text -> Value
JSON.String (Text -> Value) -> (Signature -> Text) -> Signature -> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
          ByteString -> Text
JSON.encodeByteString (ByteString -> Text)
-> (Signature -> ByteString) -> Signature -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
          BuiltinByteString -> ByteString
forall arep a. FromBuiltin arep a => arep -> a
PlutusTx.fromBuiltin (BuiltinByteString -> ByteString)
-> (Signature -> BuiltinByteString) -> Signature -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
          Signature -> BuiltinByteString
getSignature (Signature -> Value) -> Signature -> Value
forall a b. (a -> b) -> a -> b
$
          Signature
signature)
      ]

instance FromJSON Signature where
  parseJSON :: Value -> Parser Signature
parseJSON =
    String -> (Object -> Parser Signature) -> Value -> Parser Signature
forall a. String -> (Object -> Parser a) -> Value -> Parser a
JSON.withObject String
"Signature" ((Object -> Parser Signature) -> Value -> Parser Signature)
-> (Object -> Parser Signature) -> Value -> Parser Signature
forall a b. (a -> b) -> a -> b
$ \Object
object -> do
      Value
raw <- Object
object Object -> Text -> Parser Value
forall a. FromJSON a => Object -> Text -> Parser a
.: Text
"getSignature"
      ByteString
bytes <- Value -> Parser ByteString
JSON.decodeByteString Value
raw
      Signature -> Parser Signature
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Signature -> Parser Signature)
-> (BuiltinByteString -> Signature)
-> BuiltinByteString
-> Parser Signature
forall b c a. (b -> c) -> (a -> b) -> a -> c
. BuiltinByteString -> Signature
Signature (BuiltinByteString -> Parser Signature)
-> BuiltinByteString -> Parser Signature
forall a b. (a -> b) -> a -> b
$ ByteString -> BuiltinByteString
forall a arep. ToBuiltin a arep => a -> arep
PlutusTx.toBuiltin (ByteString -> BuiltinByteString)
-> ByteString -> BuiltinByteString
forall a b. (a -> b) -> a -> b
$ ByteString
bytes

makeLift ''Signature