{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeApplications #-}
module Plutus.Contract.Secrets(
Secret
, SecretArgument (..)
, mkSecret
, secretArg
, extractSecret
, escape_sha2_256
, unsafe_escape_secret
) where
import Control.Monad
import Data.Aeson as Aeson (FromJSON (..), ToJSON (..), Value (..))
import Data.Aeson.Encoding.Internal (string)
import Data.String
import PlutusTx.Prelude as PlutusTx
import Prelude qualified as Haskell
newtype Secret a = MkSecret a
data SecretArgument a = UserSide a
| EndpointSide (Secret a)
deriving Int -> SecretArgument a -> ShowS
[SecretArgument a] -> ShowS
SecretArgument a -> String
(Int -> SecretArgument a -> ShowS)
-> (SecretArgument a -> String)
-> ([SecretArgument a] -> ShowS)
-> Show (SecretArgument a)
forall a. Show a => Int -> SecretArgument a -> ShowS
forall a. Show a => [SecretArgument a] -> ShowS
forall a. Show a => SecretArgument a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SecretArgument a] -> ShowS
$cshowList :: forall a. Show a => [SecretArgument a] -> ShowS
show :: SecretArgument a -> String
$cshow :: forall a. Show a => SecretArgument a -> String
showsPrec :: Int -> SecretArgument a -> ShowS
$cshowsPrec :: forall a. Show a => Int -> SecretArgument a -> ShowS
Haskell.Show
instance ToJSON a => ToJSON (SecretArgument a) where
toJSON :: SecretArgument a -> Value
toJSON (UserSide a
a) = a -> Value
forall a. ToJSON a => a -> Value
toJSON a
a
toJSON (EndpointSide Secret a
_) = Text -> Value
Aeson.String Text
"EndpointSide *****"
toEncoding :: SecretArgument a -> Encoding
toEncoding (UserSide a
a) = a -> Encoding
forall a. ToJSON a => a -> Encoding
toEncoding a
a
toEncoding (EndpointSide Secret a
_) = String -> Encoding
forall a. String -> Encoding' a
string String
"EndpointSide *****"
instance FromJSON a => FromJSON (SecretArgument a) where
parseJSON :: Value -> Parser (SecretArgument a)
parseJSON = (a -> SecretArgument a) -> Parser a -> Parser (SecretArgument a)
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM (Secret a -> SecretArgument a
forall a. Secret a -> SecretArgument a
EndpointSide (Secret a -> SecretArgument a)
-> (a -> Secret a) -> a -> SecretArgument a
forall b c a. (b -> c) -> (a -> b) -> a -> c
Haskell.. a -> Secret a
forall a. a -> Secret a
mkSecret) (Parser a -> Parser (SecretArgument a))
-> (Value -> Parser a) -> Value -> Parser (SecretArgument a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
Haskell.. Value -> Parser a
forall a. FromJSON a => Value -> Parser a
parseJSON
instance Haskell.Show (Secret a) where
show :: Secret a -> String
show (MkSecret a
_) = String
"*****"
instance Haskell.Functor Secret where
fmap :: (a -> b) -> Secret a -> Secret b
fmap a -> b
f (MkSecret a
a) = b -> Secret b
forall a. a -> Secret a
MkSecret (a -> b
f a
a)
instance PlutusTx.Functor Secret where
fmap :: (a -> b) -> Secret a -> Secret b
fmap a -> b
f (MkSecret a
a) = b -> Secret b
forall a. a -> Secret a
MkSecret (a -> b
f a
a)
instance Haskell.Applicative Secret where
pure :: a -> Secret a
pure = a -> Secret a
forall a. a -> Secret a
mkSecret
(MkSecret a -> b
f) <*> :: Secret (a -> b) -> Secret a -> Secret b
<*> (MkSecret a
a) = b -> Secret b
forall a. a -> Secret a
MkSecret (a -> b
f a
a)
instance PlutusTx.Applicative Secret where
pure :: a -> Secret a
pure = a -> Secret a
forall a. a -> Secret a
MkSecret
(MkSecret a -> b
f) <*> :: Secret (a -> b) -> Secret a -> Secret b
<*> (MkSecret a
a) = b -> Secret b
forall a. a -> Secret a
MkSecret (a -> b
f a
a)
instance Monad Secret where
MkSecret a
a >>= :: Secret a -> (a -> Secret b) -> Secret b
>>= a -> Secret b
f = a -> Secret b
f a
a
instance IsString s => IsString (Secret s) where
fromString :: String -> Secret s
fromString = s -> Secret s
forall a. a -> Secret a
MkSecret (s -> Secret s) -> (String -> s) -> String -> Secret s
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> s
forall a. IsString a => String -> a
fromString
instance IsString s => IsString (SecretArgument s) where
fromString :: String -> SecretArgument s
fromString = s -> SecretArgument s
forall a. a -> SecretArgument a
UserSide (s -> SecretArgument s)
-> (String -> s) -> String -> SecretArgument s
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> s
forall a. IsString a => String -> a
fromString
mkSecret :: a -> Secret a
mkSecret :: a -> Secret a
mkSecret = a -> Secret a
forall a. a -> Secret a
MkSecret
secretArg :: a -> SecretArgument a
secretArg :: a -> SecretArgument a
secretArg = a -> SecretArgument a
forall a. a -> SecretArgument a
UserSide
extractSecret :: SecretArgument a -> Secret a
(UserSide a
a) = a -> Secret a
forall a. a -> Secret a
mkSecret a
a
extractSecret (EndpointSide Secret a
s) = Secret a
s
{-# INLINABLE escape_sha2_256 #-}
escape_sha2_256 :: Secret BuiltinByteString -> BuiltinByteString
escape_sha2_256 :: Secret BuiltinByteString -> BuiltinByteString
escape_sha2_256 = BuiltinByteString -> BuiltinByteString
sha2_256 (BuiltinByteString -> BuiltinByteString)
-> (Secret BuiltinByteString -> BuiltinByteString)
-> Secret BuiltinByteString
-> BuiltinByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Secret BuiltinByteString -> BuiltinByteString
forall a. Secret a -> a
unsafe_escape_secret
{-# WARNING unsafe_escape_secret "[Requires Review] An escape hatch is being created. This should only be used in trusted code." #-}
unsafe_escape_secret :: Secret a -> a
unsafe_escape_secret :: Secret a -> a
unsafe_escape_secret (MkSecret a
a) = a
a