-- editorconfig-checker-disable-file
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE KindSignatures     #-}
{-# LANGUAGE OverloadedStrings  #-}
{-# LANGUAGE TypeApplications   #-}

-- This ensures that we don't put *anything* about these functions into the interface
-- file, otherwise GHC can be clever about the ones that are always error, even though
-- they're OPAQUE!
{-# OPTIONS_GHC -O0 #-}

{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-}
{-# HLINT ignore "Use newtype instead of data" #-} -- See Note [Opaque builtin types]

-- | This module contains the special Haskell names that are used to map to builtin types or functions
-- in Plutus Core.
--
-- Most users should not use this module directly, but rather use 'PlutusTx.Builtins'.
module PlutusTx.Builtins.Internal where

import Codec.Serialise
import Control.DeepSeq (NFData (..))
import Data.ByteArray qualified as BA
import Data.ByteString qualified as BS
import Data.ByteString.Lazy qualified as BSL
import Data.Coerce (coerce)
import Data.Data (Data)
import Data.Foldable qualified as Foldable
import Data.Hashable (Hashable (..))
import Data.Kind (Type)
import Data.Text as Text (Text, empty)
import Data.Text.Encoding as Text (decodeUtf8, encodeUtf8)
import GHC.Generics (Generic)
import PlutusCore.Bitwise qualified as Bitwise
import PlutusCore.Builtin (BuiltinResult (..))
import PlutusCore.Crypto.BLS12_381.G1 qualified as BLS12_381.G1
import PlutusCore.Crypto.BLS12_381.G2 qualified as BLS12_381.G2
import PlutusCore.Crypto.BLS12_381.Pairing qualified as BLS12_381.Pairing
import PlutusCore.Crypto.Ed25519 qualified
import PlutusCore.Crypto.ExpMod as ExpMod
import PlutusCore.Crypto.Hash qualified as Hash
import PlutusCore.Crypto.Secp256k1 qualified
import PlutusCore.Data qualified as PLC
import PlutusCore.Pretty (Pretty (..), display)
import Prettyprinter (viaShow)

{-
We do not use qualified import because the whole module contains off-chain code
which is replaced later with on-chain implementations by the plutus-tx-plugin.
-}
import Prelude as Haskell

{- Note [Builtin name definitions]
The builtins here have definitions so they can be used in off-chain code too.

However they *must* be replaced by the compiler when used in Plutus Tx code, so
in particular they must *not* be inlined, otherwise we can't spot them to replace
them.
-}

{- Note [Delaying error]
The Plutus Core 'error' builtin is of type 'forall a . a', but the
one we expose here is of type 'forall a . () -> a'.

This is because it's hard to get the evaluation order right with
the non-delayed version - it's easy to end up with it getting thrown
unconditionally, or before some other effect (e.g. tracing). On the other
hand, it's much easier to work with the delayed version.

But why not just define that in the library? i.e.

    error = \_ -> Builtins.error

The answer is that GHC is eager to inline and reduce this function, which
does the Wrong Thing. We can't stop GHC doing this (at the moment), but
for most of our functions it's not a *semantic* problem. Here, however,
it is a problem. So we just expose the delayed version as the builtin.
-}

{- Note [Opaque builtin types]
We have some opaque types that we use to represent the Plutus builtin types
in Haskell.

We want them to be opaque so that our users don't do anything with them that
we can't handle, but also so that GHC doesn't look inside and try and get clever.

In particular, we need to use 'data' rather than 'newtype' even for simple wrappers,
otherwise GHC gets very keen to optimize through the newtype and e.g. our users
see 'Addr#' popping up everywhere.
-}

{-# OPAQUE error #-}
error :: BuiltinUnit -> a
error :: forall a. BuiltinUnit -> a
error = [Char] -> BuiltinUnit -> a
forall a. HasCallStack => [Char] -> a
Haskell.error [Char]
"PlutusTx.Builtins.Internal.error"

{-
BOOL
-}

-- See Note [Opaque builtin types]
data BuiltinBool = BuiltinBool ~Bool deriving stock Typeable BuiltinBool
Typeable BuiltinBool =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> BuiltinBool -> c BuiltinBool)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c BuiltinBool)
-> (BuiltinBool -> Constr)
-> (BuiltinBool -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c BuiltinBool))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c BuiltinBool))
-> ((forall b. Data b => b -> b) -> BuiltinBool -> BuiltinBool)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> BuiltinBool -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> BuiltinBool -> r)
-> (forall u. (forall d. Data d => d -> u) -> BuiltinBool -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> BuiltinBool -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> BuiltinBool -> m BuiltinBool)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> BuiltinBool -> m BuiltinBool)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> BuiltinBool -> m BuiltinBool)
-> Data BuiltinBool
BuiltinBool -> Constr
BuiltinBool -> DataType
(forall b. Data b => b -> b) -> BuiltinBool -> BuiltinBool
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> BuiltinBool -> u
forall u. (forall d. Data d => d -> u) -> BuiltinBool -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinBool -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinBool -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> BuiltinBool -> m BuiltinBool
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> BuiltinBool -> m BuiltinBool
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c BuiltinBool
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> BuiltinBool -> c BuiltinBool
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c BuiltinBool)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c BuiltinBool)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> BuiltinBool -> c BuiltinBool
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> BuiltinBool -> c BuiltinBool
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c BuiltinBool
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c BuiltinBool
$ctoConstr :: BuiltinBool -> Constr
toConstr :: BuiltinBool -> Constr
$cdataTypeOf :: BuiltinBool -> DataType
dataTypeOf :: BuiltinBool -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c BuiltinBool)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c BuiltinBool)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c BuiltinBool)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c BuiltinBool)
$cgmapT :: (forall b. Data b => b -> b) -> BuiltinBool -> BuiltinBool
gmapT :: (forall b. Data b => b -> b) -> BuiltinBool -> BuiltinBool
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinBool -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinBool -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinBool -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinBool -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> BuiltinBool -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> BuiltinBool -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> BuiltinBool -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> BuiltinBool -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> BuiltinBool -> m BuiltinBool
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> BuiltinBool -> m BuiltinBool
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> BuiltinBool -> m BuiltinBool
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> BuiltinBool -> m BuiltinBool
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> BuiltinBool -> m BuiltinBool
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> BuiltinBool -> m BuiltinBool
Data

{-# OPAQUE true #-}
true :: BuiltinBool
true :: BuiltinBool
true = Bool -> BuiltinBool
BuiltinBool Bool
True

{-# OPAQUE false #-}
false :: BuiltinBool
false :: BuiltinBool
false = Bool -> BuiltinBool
BuiltinBool Bool
False

{-# OPAQUE ifThenElse #-}
ifThenElse :: BuiltinBool -> a -> a -> a
ifThenElse :: forall a. BuiltinBool -> a -> a -> a
ifThenElse (BuiltinBool Bool
b) a
x a
y = if Bool
b then a
x else a
y

{-
UNIT
-}

-- See Note [Opaque builtin types]
data BuiltinUnit = BuiltinUnit ~() deriving stock Typeable BuiltinUnit
Typeable BuiltinUnit =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> BuiltinUnit -> c BuiltinUnit)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c BuiltinUnit)
-> (BuiltinUnit -> Constr)
-> (BuiltinUnit -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c BuiltinUnit))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c BuiltinUnit))
-> ((forall b. Data b => b -> b) -> BuiltinUnit -> BuiltinUnit)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> BuiltinUnit -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> BuiltinUnit -> r)
-> (forall u. (forall d. Data d => d -> u) -> BuiltinUnit -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> BuiltinUnit -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> BuiltinUnit -> m BuiltinUnit)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> BuiltinUnit -> m BuiltinUnit)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> BuiltinUnit -> m BuiltinUnit)
-> Data BuiltinUnit
BuiltinUnit -> Constr
BuiltinUnit -> DataType
(forall b. Data b => b -> b) -> BuiltinUnit -> BuiltinUnit
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> BuiltinUnit -> u
forall u. (forall d. Data d => d -> u) -> BuiltinUnit -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinUnit -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinUnit -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> BuiltinUnit -> m BuiltinUnit
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> BuiltinUnit -> m BuiltinUnit
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c BuiltinUnit
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> BuiltinUnit -> c BuiltinUnit
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c BuiltinUnit)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c BuiltinUnit)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> BuiltinUnit -> c BuiltinUnit
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> BuiltinUnit -> c BuiltinUnit
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c BuiltinUnit
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c BuiltinUnit
$ctoConstr :: BuiltinUnit -> Constr
toConstr :: BuiltinUnit -> Constr
$cdataTypeOf :: BuiltinUnit -> DataType
dataTypeOf :: BuiltinUnit -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c BuiltinUnit)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c BuiltinUnit)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c BuiltinUnit)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c BuiltinUnit)
$cgmapT :: (forall b. Data b => b -> b) -> BuiltinUnit -> BuiltinUnit
gmapT :: (forall b. Data b => b -> b) -> BuiltinUnit -> BuiltinUnit
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinUnit -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinUnit -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinUnit -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinUnit -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> BuiltinUnit -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> BuiltinUnit -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> BuiltinUnit -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> BuiltinUnit -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> BuiltinUnit -> m BuiltinUnit
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> BuiltinUnit -> m BuiltinUnit
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> BuiltinUnit -> m BuiltinUnit
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> BuiltinUnit -> m BuiltinUnit
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> BuiltinUnit -> m BuiltinUnit
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> BuiltinUnit -> m BuiltinUnit
Data

{-# OPAQUE unitval #-}
unitval :: BuiltinUnit
unitval :: BuiltinUnit
unitval = () -> BuiltinUnit
BuiltinUnit ()

{-# OPAQUE chooseUnit #-}
chooseUnit :: BuiltinUnit -> a -> a
chooseUnit :: forall a. BuiltinUnit -> a -> a
chooseUnit (BuiltinUnit ()) a
a = a
a

{-
INTEGER
-}

-- I'm somewhat surprised that this works despite not being opaque! GHC doesn't seem to
-- mess with 'Integer', which is suspicious to me. Probably we *should* make 'BuiltinInteger'
-- opaque, but that's going to really mess with our users' code...
type BuiltinInteger = Integer

{-# OPAQUE addInteger #-}
addInteger :: BuiltinInteger -> BuiltinInteger -> BuiltinInteger
addInteger :: BuiltinInteger -> BuiltinInteger -> BuiltinInteger
addInteger = (BuiltinInteger -> BuiltinInteger -> BuiltinInteger)
-> BuiltinInteger -> BuiltinInteger -> BuiltinInteger
forall a b. Coercible a b => a -> b
coerce (forall a. Num a => a -> a -> a
(+) @Integer)

{-# OPAQUE subtractInteger #-}
subtractInteger :: BuiltinInteger -> BuiltinInteger -> BuiltinInteger
subtractInteger :: BuiltinInteger -> BuiltinInteger -> BuiltinInteger
subtractInteger = (BuiltinInteger -> BuiltinInteger -> BuiltinInteger)
-> BuiltinInteger -> BuiltinInteger -> BuiltinInteger
forall a b. Coercible a b => a -> b
coerce ((-) @Integer)

{-# OPAQUE multiplyInteger #-}
multiplyInteger :: BuiltinInteger -> BuiltinInteger -> BuiltinInteger
multiplyInteger :: BuiltinInteger -> BuiltinInteger -> BuiltinInteger
multiplyInteger = (BuiltinInteger -> BuiltinInteger -> BuiltinInteger)
-> BuiltinInteger -> BuiltinInteger -> BuiltinInteger
forall a b. Coercible a b => a -> b
coerce (forall a. Num a => a -> a -> a
(*) @Integer)

{-# OPAQUE divideInteger #-}
divideInteger :: BuiltinInteger -> BuiltinInteger -> BuiltinInteger
divideInteger :: BuiltinInteger -> BuiltinInteger -> BuiltinInteger
divideInteger = (BuiltinInteger -> BuiltinInteger -> BuiltinInteger)
-> BuiltinInteger -> BuiltinInteger -> BuiltinInteger
forall a b. Coercible a b => a -> b
coerce (forall a. Integral a => a -> a -> a
div @Integer)

{-# OPAQUE modInteger #-}
modInteger :: BuiltinInteger -> BuiltinInteger -> BuiltinInteger
modInteger :: BuiltinInteger -> BuiltinInteger -> BuiltinInteger
modInteger = (BuiltinInteger -> BuiltinInteger -> BuiltinInteger)
-> BuiltinInteger -> BuiltinInteger -> BuiltinInteger
forall a b. Coercible a b => a -> b
coerce (forall a. Integral a => a -> a -> a
mod @Integer)

{-# OPAQUE quotientInteger #-}
quotientInteger :: BuiltinInteger -> BuiltinInteger -> BuiltinInteger
quotientInteger :: BuiltinInteger -> BuiltinInteger -> BuiltinInteger
quotientInteger = (BuiltinInteger -> BuiltinInteger -> BuiltinInteger)
-> BuiltinInteger -> BuiltinInteger -> BuiltinInteger
forall a b. Coercible a b => a -> b
coerce (forall a. Integral a => a -> a -> a
quot @Integer)

{-# OPAQUE remainderInteger #-}
remainderInteger :: BuiltinInteger -> BuiltinInteger -> BuiltinInteger
remainderInteger :: BuiltinInteger -> BuiltinInteger -> BuiltinInteger
remainderInteger = (BuiltinInteger -> BuiltinInteger -> BuiltinInteger)
-> BuiltinInteger -> BuiltinInteger -> BuiltinInteger
forall a b. Coercible a b => a -> b
coerce (forall a. Integral a => a -> a -> a
rem @Integer)

{-# OPAQUE lessThanInteger #-}
lessThanInteger :: BuiltinInteger -> BuiltinInteger -> BuiltinBool
lessThanInteger :: BuiltinInteger -> BuiltinInteger -> BuiltinBool
lessThanInteger BuiltinInteger
x BuiltinInteger
y = Bool -> BuiltinBool
BuiltinBool (Bool -> BuiltinBool) -> Bool -> BuiltinBool
forall a b. (a -> b) -> a -> b
$ (BuiltinInteger -> BuiltinInteger -> Bool)
-> BuiltinInteger -> BuiltinInteger -> Bool
forall a b. Coercible a b => a -> b
coerce (forall a. Ord a => a -> a -> Bool
(<) @Integer) BuiltinInteger
x  BuiltinInteger
y

{-# OPAQUE lessThanEqualsInteger #-}
lessThanEqualsInteger :: BuiltinInteger -> BuiltinInteger -> BuiltinBool
lessThanEqualsInteger :: BuiltinInteger -> BuiltinInteger -> BuiltinBool
lessThanEqualsInteger BuiltinInteger
x BuiltinInteger
y = Bool -> BuiltinBool
BuiltinBool (Bool -> BuiltinBool) -> Bool -> BuiltinBool
forall a b. (a -> b) -> a -> b
$ (BuiltinInteger -> BuiltinInteger -> Bool)
-> BuiltinInteger -> BuiltinInteger -> Bool
forall a b. Coercible a b => a -> b
coerce (forall a. Ord a => a -> a -> Bool
(<=) @Integer) BuiltinInteger
x BuiltinInteger
y

{-# OPAQUE equalsInteger #-}
equalsInteger :: BuiltinInteger -> BuiltinInteger -> BuiltinBool
equalsInteger :: BuiltinInteger -> BuiltinInteger -> BuiltinBool
equalsInteger BuiltinInteger
x BuiltinInteger
y = Bool -> BuiltinBool
BuiltinBool (Bool -> BuiltinBool) -> Bool -> BuiltinBool
forall a b. (a -> b) -> a -> b
$ (BuiltinInteger -> BuiltinInteger -> Bool)
-> BuiltinInteger -> BuiltinInteger -> Bool
forall a b. Coercible a b => a -> b
coerce (forall a. Eq a => a -> a -> Bool
(==) @Integer) BuiltinInteger
x BuiltinInteger
y

{-
BYTESTRING
-}

-- See Note [Opaque builtin types]
-- | An opaque type representing Plutus Core ByteStrings.
data BuiltinByteString = BuiltinByteString ~BS.ByteString deriving stock Typeable BuiltinByteString
Typeable BuiltinByteString =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g)
 -> BuiltinByteString
 -> c BuiltinByteString)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c BuiltinByteString)
-> (BuiltinByteString -> Constr)
-> (BuiltinByteString -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c BuiltinByteString))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c BuiltinByteString))
-> ((forall b. Data b => b -> b)
    -> BuiltinByteString -> BuiltinByteString)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> BuiltinByteString -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> BuiltinByteString -> r)
-> (forall u.
    (forall d. Data d => d -> u) -> BuiltinByteString -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> BuiltinByteString -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d)
    -> BuiltinByteString -> m BuiltinByteString)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d)
    -> BuiltinByteString -> m BuiltinByteString)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d)
    -> BuiltinByteString -> m BuiltinByteString)
-> Data BuiltinByteString
BuiltinByteString -> Constr
BuiltinByteString -> DataType
(forall b. Data b => b -> b)
-> BuiltinByteString -> BuiltinByteString
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u.
Int -> (forall d. Data d => d -> u) -> BuiltinByteString -> u
forall u. (forall d. Data d => d -> u) -> BuiltinByteString -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinByteString -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinByteString -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> BuiltinByteString -> m BuiltinByteString
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> BuiltinByteString -> m BuiltinByteString
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c BuiltinByteString
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> BuiltinByteString -> c BuiltinByteString
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c BuiltinByteString)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c BuiltinByteString)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> BuiltinByteString -> c BuiltinByteString
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> BuiltinByteString -> c BuiltinByteString
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c BuiltinByteString
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c BuiltinByteString
$ctoConstr :: BuiltinByteString -> Constr
toConstr :: BuiltinByteString -> Constr
$cdataTypeOf :: BuiltinByteString -> DataType
dataTypeOf :: BuiltinByteString -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c BuiltinByteString)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c BuiltinByteString)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c BuiltinByteString)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c BuiltinByteString)
$cgmapT :: (forall b. Data b => b -> b)
-> BuiltinByteString -> BuiltinByteString
gmapT :: (forall b. Data b => b -> b)
-> BuiltinByteString -> BuiltinByteString
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinByteString -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinByteString -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinByteString -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinByteString -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> BuiltinByteString -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> BuiltinByteString -> [u]
$cgmapQi :: forall u.
Int -> (forall d. Data d => d -> u) -> BuiltinByteString -> u
gmapQi :: forall u.
Int -> (forall d. Data d => d -> u) -> BuiltinByteString -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> BuiltinByteString -> m BuiltinByteString
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> BuiltinByteString -> m BuiltinByteString
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> BuiltinByteString -> m BuiltinByteString
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> BuiltinByteString -> m BuiltinByteString
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> BuiltinByteString -> m BuiltinByteString
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> BuiltinByteString -> m BuiltinByteString
Data

instance Haskell.Show BuiltinByteString where
    show :: BuiltinByteString -> [Char]
show (BuiltinByteString ByteString
bs) = ByteString -> [Char]
forall a. Show a => a -> [Char]
show ByteString
bs
instance Haskell.Eq BuiltinByteString where
    == :: BuiltinByteString -> BuiltinByteString -> Bool
(==) (BuiltinByteString ByteString
bs) (BuiltinByteString ByteString
bs') = ByteString -> ByteString -> Bool
forall a. Eq a => a -> a -> Bool
(==) ByteString
bs ByteString
bs'
instance Haskell.Ord BuiltinByteString where
    compare :: BuiltinByteString -> BuiltinByteString -> Ordering
compare (BuiltinByteString ByteString
bs) (BuiltinByteString ByteString
bs') = ByteString -> ByteString -> Ordering
forall a. Ord a => a -> a -> Ordering
compare ByteString
bs ByteString
bs'
instance Haskell.Semigroup BuiltinByteString where
    <> :: BuiltinByteString -> BuiltinByteString -> BuiltinByteString
(<>) (BuiltinByteString ByteString
bs) (BuiltinByteString ByteString
bs') = ByteString -> BuiltinByteString
BuiltinByteString (ByteString -> BuiltinByteString)
-> ByteString -> BuiltinByteString
forall a b. (a -> b) -> a -> b
$ ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
(<>) ByteString
bs ByteString
bs'
instance Haskell.Monoid BuiltinByteString where
    mempty :: BuiltinByteString
mempty = ByteString -> BuiltinByteString
BuiltinByteString ByteString
forall a. Monoid a => a
mempty
instance Hashable BuiltinByteString where
    hashWithSalt :: Int -> BuiltinByteString -> Int
hashWithSalt Int
s (BuiltinByteString ByteString
bs )= Int -> ByteString -> Int
forall a. Hashable a => Int -> a -> Int
hashWithSalt Int
s ByteString
bs
instance Serialise BuiltinByteString where
    encode :: BuiltinByteString -> Encoding
encode (BuiltinByteString ByteString
bs) = ByteString -> Encoding
forall a. Serialise a => a -> Encoding
encode ByteString
bs
    decode :: forall s. Decoder s BuiltinByteString
decode = ByteString -> BuiltinByteString
BuiltinByteString (ByteString -> BuiltinByteString)
-> Decoder s ByteString -> Decoder s BuiltinByteString
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s ByteString
forall s. Decoder s ByteString
forall a s. Serialise a => Decoder s a
decode
instance NFData BuiltinByteString where
    rnf :: BuiltinByteString -> ()
rnf (BuiltinByteString ByteString
bs) = ByteString -> ()
forall a. NFData a => a -> ()
rnf ByteString
bs
instance BA.ByteArrayAccess BuiltinByteString where
    length :: BuiltinByteString -> Int
length (BuiltinByteString ByteString
bs) = ByteString -> Int
forall ba. ByteArrayAccess ba => ba -> Int
BA.length ByteString
bs
    withByteArray :: forall p a. BuiltinByteString -> (Ptr p -> IO a) -> IO a
withByteArray (BuiltinByteString ByteString
bs) = ByteString -> (Ptr p -> IO a) -> IO a
forall ba p a. ByteArrayAccess ba => ba -> (Ptr p -> IO a) -> IO a
forall p a. ByteString -> (Ptr p -> IO a) -> IO a
BA.withByteArray ByteString
bs
instance BA.ByteArray BuiltinByteString where
    allocRet :: forall p a. Int -> (Ptr p -> IO a) -> IO (a, BuiltinByteString)
allocRet Int
i Ptr p -> IO a
p = ((a, ByteString) -> (a, BuiltinByteString))
-> IO (a, ByteString) -> IO (a, BuiltinByteString)
forall a b. (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((ByteString -> BuiltinByteString)
-> (a, ByteString) -> (a, BuiltinByteString)
forall a b. (a -> b) -> (a, a) -> (a, b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ByteString -> BuiltinByteString
BuiltinByteString) (IO (a, ByteString) -> IO (a, BuiltinByteString))
-> IO (a, ByteString) -> IO (a, BuiltinByteString)
forall a b. (a -> b) -> a -> b
$ Int -> (Ptr p -> IO a) -> IO (a, ByteString)
forall ba p a. ByteArray ba => Int -> (Ptr p -> IO a) -> IO (a, ba)
forall p a. Int -> (Ptr p -> IO a) -> IO (a, ByteString)
BA.allocRet Int
i Ptr p -> IO a
p

instance Pretty BuiltinByteString where
    pretty :: forall ann. BuiltinByteString -> Doc ann
pretty = BuiltinByteString -> Doc ann
forall a ann. Show a => a -> Doc ann
viaShow

{-# OPAQUE appendByteString #-}
appendByteString :: BuiltinByteString -> BuiltinByteString -> BuiltinByteString
appendByteString :: BuiltinByteString -> BuiltinByteString -> BuiltinByteString
appendByteString (BuiltinByteString ByteString
b1) (BuiltinByteString ByteString
b2) = ByteString -> BuiltinByteString
BuiltinByteString (ByteString -> BuiltinByteString)
-> ByteString -> BuiltinByteString
forall a b. (a -> b) -> a -> b
$ ByteString -> ByteString -> ByteString
BS.append ByteString
b1 ByteString
b2

{-# OPAQUE consByteString #-}
consByteString :: BuiltinInteger -> BuiltinByteString -> BuiltinByteString
consByteString :: BuiltinInteger -> BuiltinByteString -> BuiltinByteString
consByteString BuiltinInteger
n (BuiltinByteString ByteString
b) = ByteString -> BuiltinByteString
BuiltinByteString (ByteString -> BuiltinByteString)
-> ByteString -> BuiltinByteString
forall a b. (a -> b) -> a -> b
$ Word8 -> ByteString -> ByteString
BS.cons (BuiltinInteger -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral BuiltinInteger
n) ByteString
b

{-# OPAQUE sliceByteString #-}
sliceByteString :: BuiltinInteger -> BuiltinInteger -> BuiltinByteString -> BuiltinByteString
sliceByteString :: BuiltinInteger
-> BuiltinInteger -> BuiltinByteString -> BuiltinByteString
sliceByteString BuiltinInteger
start BuiltinInteger
n (BuiltinByteString ByteString
b) = ByteString -> BuiltinByteString
BuiltinByteString (ByteString -> BuiltinByteString)
-> ByteString -> BuiltinByteString
forall a b. (a -> b) -> a -> b
$ Int -> ByteString -> ByteString
BS.take (BuiltinInteger -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral BuiltinInteger
n) (Int -> ByteString -> ByteString
BS.drop (BuiltinInteger -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral BuiltinInteger
start) ByteString
b)

{-# OPAQUE lengthOfByteString #-}
lengthOfByteString :: BuiltinByteString -> BuiltinInteger
lengthOfByteString :: BuiltinByteString -> BuiltinInteger
lengthOfByteString (BuiltinByteString ByteString
b) = Int -> BuiltinInteger
forall a. Integral a => a -> BuiltinInteger
toInteger (Int -> BuiltinInteger) -> Int -> BuiltinInteger
forall a b. (a -> b) -> a -> b
$ ByteString -> Int
BS.length ByteString
b

{-# OPAQUE indexByteString #-}
indexByteString :: BuiltinByteString -> BuiltinInteger -> BuiltinInteger
indexByteString :: BuiltinByteString -> BuiltinInteger -> BuiltinInteger
indexByteString (BuiltinByteString ByteString
b) BuiltinInteger
i = Word8 -> BuiltinInteger
forall a. Integral a => a -> BuiltinInteger
toInteger (Word8 -> BuiltinInteger) -> Word8 -> BuiltinInteger
forall a b. (a -> b) -> a -> b
$ HasCallStack => ByteString -> Int -> Word8
ByteString -> Int -> Word8
BS.index ByteString
b (BuiltinInteger -> Int
forall a. Num a => BuiltinInteger -> a
fromInteger BuiltinInteger
i)

{-# OPAQUE emptyByteString #-}
emptyByteString :: BuiltinByteString
emptyByteString :: BuiltinByteString
emptyByteString = ByteString -> BuiltinByteString
BuiltinByteString ByteString
BS.empty

{-# OPAQUE sha2_256 #-}
sha2_256 :: BuiltinByteString -> BuiltinByteString
sha2_256 :: BuiltinByteString -> BuiltinByteString
sha2_256 (BuiltinByteString ByteString
b) = ByteString -> BuiltinByteString
BuiltinByteString (ByteString -> BuiltinByteString)
-> ByteString -> BuiltinByteString
forall a b. (a -> b) -> a -> b
$ ByteString -> ByteString
Hash.sha2_256 ByteString
b

{-# OPAQUE sha3_256 #-}
sha3_256 :: BuiltinByteString -> BuiltinByteString
sha3_256 :: BuiltinByteString -> BuiltinByteString
sha3_256 (BuiltinByteString ByteString
b) = ByteString -> BuiltinByteString
BuiltinByteString (ByteString -> BuiltinByteString)
-> ByteString -> BuiltinByteString
forall a b. (a -> b) -> a -> b
$ ByteString -> ByteString
Hash.sha3_256 ByteString
b

{-# OPAQUE blake2b_224 #-}
blake2b_224 :: BuiltinByteString -> BuiltinByteString
blake2b_224 :: BuiltinByteString -> BuiltinByteString
blake2b_224 (BuiltinByteString ByteString
b) = ByteString -> BuiltinByteString
BuiltinByteString (ByteString -> BuiltinByteString)
-> ByteString -> BuiltinByteString
forall a b. (a -> b) -> a -> b
$ ByteString -> ByteString
Hash.blake2b_224 ByteString
b

{-# OPAQUE blake2b_256 #-}
blake2b_256 :: BuiltinByteString -> BuiltinByteString
blake2b_256 :: BuiltinByteString -> BuiltinByteString
blake2b_256 (BuiltinByteString ByteString
b) = ByteString -> BuiltinByteString
BuiltinByteString (ByteString -> BuiltinByteString)
-> ByteString -> BuiltinByteString
forall a b. (a -> b) -> a -> b
$ ByteString -> ByteString
Hash.blake2b_256 ByteString
b

{-# OPAQUE keccak_256 #-}
keccak_256 :: BuiltinByteString -> BuiltinByteString
keccak_256 :: BuiltinByteString -> BuiltinByteString
keccak_256 (BuiltinByteString ByteString
b) = ByteString -> BuiltinByteString
BuiltinByteString (ByteString -> BuiltinByteString)
-> ByteString -> BuiltinByteString
forall a b. (a -> b) -> a -> b
$ ByteString -> ByteString
Hash.keccak_256 ByteString
b

{-# OPAQUE ripemd_160 #-}
ripemd_160 :: BuiltinByteString -> BuiltinByteString
ripemd_160 :: BuiltinByteString -> BuiltinByteString
ripemd_160 (BuiltinByteString ByteString
b) = ByteString -> BuiltinByteString
BuiltinByteString (ByteString -> BuiltinByteString)
-> ByteString -> BuiltinByteString
forall a b. (a -> b) -> a -> b
$ ByteString -> ByteString
Hash.ripemd_160 ByteString
b

{-# OPAQUE verifyEd25519Signature #-}
verifyEd25519Signature :: BuiltinByteString -> BuiltinByteString -> BuiltinByteString -> BuiltinBool
verifyEd25519Signature :: BuiltinByteString
-> BuiltinByteString -> BuiltinByteString -> BuiltinBool
verifyEd25519Signature (BuiltinByteString ByteString
vk) (BuiltinByteString ByteString
msg) (BuiltinByteString ByteString
sig) =
  case ByteString -> ByteString -> ByteString -> BuiltinResult Bool
PlutusCore.Crypto.Ed25519.verifyEd25519Signature_V1 ByteString
vk ByteString
msg ByteString
sig of
    BuiltinSuccess Bool
b              -> Bool -> BuiltinBool
BuiltinBool Bool
b
    BuiltinSuccessWithLogs DList Text
logs Bool
b -> DList Text -> BuiltinBool -> BuiltinBool
forall a (f :: * -> *). Foldable f => f Text -> a -> a
traceAll DList Text
logs (BuiltinBool -> BuiltinBool) -> BuiltinBool -> BuiltinBool
forall a b. (a -> b) -> a -> b
$ Bool -> BuiltinBool
BuiltinBool Bool
b
    BuiltinFailure DList Text
logs BuiltinError
err       -> DList Text -> BuiltinBool -> BuiltinBool
forall a (f :: * -> *). Foldable f => f Text -> a -> a
traceAll (DList Text
logs DList Text -> DList Text -> DList Text
forall a. Semigroup a => a -> a -> a
<> Text -> DList Text
forall a. a -> DList a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (BuiltinError -> Text
forall str a. (Pretty a, Render str) => a -> str
display BuiltinError
err)) (BuiltinBool -> BuiltinBool) -> BuiltinBool -> BuiltinBool
forall a b. (a -> b) -> a -> b
$
        [Char] -> BuiltinBool
forall a. HasCallStack => [Char] -> a
Haskell.error [Char]
"Ed25519 signature verification errored."

{-# OPAQUE verifyEcdsaSecp256k1Signature #-}
verifyEcdsaSecp256k1Signature ::
  BuiltinByteString ->
  BuiltinByteString ->
  BuiltinByteString ->
  BuiltinBool
verifyEcdsaSecp256k1Signature :: BuiltinByteString
-> BuiltinByteString -> BuiltinByteString -> BuiltinBool
verifyEcdsaSecp256k1Signature (BuiltinByteString ByteString
vk) (BuiltinByteString ByteString
msg) (BuiltinByteString ByteString
sig) =
  case ByteString -> ByteString -> ByteString -> BuiltinResult Bool
PlutusCore.Crypto.Secp256k1.verifyEcdsaSecp256k1Signature ByteString
vk ByteString
msg ByteString
sig of
    BuiltinSuccess Bool
b              -> Bool -> BuiltinBool
BuiltinBool Bool
b
    BuiltinSuccessWithLogs DList Text
logs Bool
b -> DList Text -> BuiltinBool -> BuiltinBool
forall a (f :: * -> *). Foldable f => f Text -> a -> a
traceAll DList Text
logs (BuiltinBool -> BuiltinBool) -> BuiltinBool -> BuiltinBool
forall a b. (a -> b) -> a -> b
$ Bool -> BuiltinBool
BuiltinBool Bool
b
    BuiltinFailure DList Text
logs BuiltinError
err       -> DList Text -> BuiltinBool -> BuiltinBool
forall a (f :: * -> *). Foldable f => f Text -> a -> a
traceAll (DList Text
logs DList Text -> DList Text -> DList Text
forall a. Semigroup a => a -> a -> a
<> Text -> DList Text
forall a. a -> DList a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (BuiltinError -> Text
forall str a. (Pretty a, Render str) => a -> str
display BuiltinError
err)) (BuiltinBool -> BuiltinBool) -> BuiltinBool -> BuiltinBool
forall a b. (a -> b) -> a -> b
$
        [Char] -> BuiltinBool
forall a. HasCallStack => [Char] -> a
Haskell.error [Char]
"ECDSA SECP256k1 signature verification errored."

{-# OPAQUE verifySchnorrSecp256k1Signature #-}
verifySchnorrSecp256k1Signature ::
  BuiltinByteString ->
  BuiltinByteString ->
  BuiltinByteString ->
  BuiltinBool
verifySchnorrSecp256k1Signature :: BuiltinByteString
-> BuiltinByteString -> BuiltinByteString -> BuiltinBool
verifySchnorrSecp256k1Signature (BuiltinByteString ByteString
vk) (BuiltinByteString ByteString
msg) (BuiltinByteString ByteString
sig) =
  case ByteString -> ByteString -> ByteString -> BuiltinResult Bool
PlutusCore.Crypto.Secp256k1.verifySchnorrSecp256k1Signature ByteString
vk ByteString
msg ByteString
sig of
    BuiltinSuccess Bool
b              -> Bool -> BuiltinBool
BuiltinBool Bool
b
    BuiltinSuccessWithLogs DList Text
logs Bool
b -> DList Text -> BuiltinBool -> BuiltinBool
forall a (f :: * -> *). Foldable f => f Text -> a -> a
traceAll DList Text
logs (BuiltinBool -> BuiltinBool) -> BuiltinBool -> BuiltinBool
forall a b. (a -> b) -> a -> b
$ Bool -> BuiltinBool
BuiltinBool Bool
b
    BuiltinFailure DList Text
logs BuiltinError
err       -> DList Text -> BuiltinBool -> BuiltinBool
forall a (f :: * -> *). Foldable f => f Text -> a -> a
traceAll (DList Text
logs DList Text -> DList Text -> DList Text
forall a. Semigroup a => a -> a -> a
<> Text -> DList Text
forall a. a -> DList a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (BuiltinError -> Text
forall str a. (Pretty a, Render str) => a -> str
display BuiltinError
err)) (BuiltinBool -> BuiltinBool) -> BuiltinBool -> BuiltinBool
forall a b. (a -> b) -> a -> b
$
        [Char] -> BuiltinBool
forall a. HasCallStack => [Char] -> a
Haskell.error [Char]
"Schnorr SECP256k1 signature verification errored."

traceAll :: forall (a :: Type) (f :: Type -> Type) .
  (Foldable f) => f Text -> a -> a
traceAll :: forall a (f :: * -> *). Foldable f => f Text -> a -> a
traceAll f Text
logs a
x = (a -> Text -> a) -> a -> f Text -> a
forall b a. (b -> a -> b) -> b -> f a -> b
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
Foldable.foldl' (\a
acc Text
t -> BuiltinString -> a -> a
forall a. BuiltinString -> a -> a
trace (Text -> BuiltinString
BuiltinString Text
t) a
acc) a
x f Text
logs

{-# OPAQUE equalsByteString #-}
equalsByteString :: BuiltinByteString -> BuiltinByteString -> BuiltinBool
equalsByteString :: BuiltinByteString -> BuiltinByteString -> BuiltinBool
equalsByteString (BuiltinByteString ByteString
b1) (BuiltinByteString ByteString
b2) = Bool -> BuiltinBool
BuiltinBool (Bool -> BuiltinBool) -> Bool -> BuiltinBool
forall a b. (a -> b) -> a -> b
$ ByteString
b1 ByteString -> ByteString -> Bool
forall a. Eq a => a -> a -> Bool
== ByteString
b2

{-# OPAQUE lessThanByteString #-}
lessThanByteString :: BuiltinByteString -> BuiltinByteString -> BuiltinBool
lessThanByteString :: BuiltinByteString -> BuiltinByteString -> BuiltinBool
lessThanByteString (BuiltinByteString ByteString
b1) (BuiltinByteString ByteString
b2) = Bool -> BuiltinBool
BuiltinBool (Bool -> BuiltinBool) -> Bool -> BuiltinBool
forall a b. (a -> b) -> a -> b
$ ByteString
b1 ByteString -> ByteString -> Bool
forall a. Ord a => a -> a -> Bool
< ByteString
b2

{-# OPAQUE lessThanEqualsByteString #-}
lessThanEqualsByteString :: BuiltinByteString -> BuiltinByteString -> BuiltinBool
lessThanEqualsByteString :: BuiltinByteString -> BuiltinByteString -> BuiltinBool
lessThanEqualsByteString (BuiltinByteString ByteString
b1) (BuiltinByteString ByteString
b2) = Bool -> BuiltinBool
BuiltinBool (Bool -> BuiltinBool) -> Bool -> BuiltinBool
forall a b. (a -> b) -> a -> b
$ ByteString
b1 ByteString -> ByteString -> Bool
forall a. Ord a => a -> a -> Bool
<= ByteString
b2

{-# OPAQUE decodeUtf8 #-}
decodeUtf8 :: BuiltinByteString -> BuiltinString
decodeUtf8 :: BuiltinByteString -> BuiltinString
decodeUtf8 (BuiltinByteString ByteString
b) = Text -> BuiltinString
BuiltinString (Text -> BuiltinString) -> Text -> BuiltinString
forall a b. (a -> b) -> a -> b
$ ByteString -> Text
Text.decodeUtf8 ByteString
b

{-
STRING
-}

-- See Note [Opaque builtin types]
data BuiltinString = BuiltinString ~Text deriving stock Typeable BuiltinString
Typeable BuiltinString =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> BuiltinString -> c BuiltinString)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c BuiltinString)
-> (BuiltinString -> Constr)
-> (BuiltinString -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c BuiltinString))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c BuiltinString))
-> ((forall b. Data b => b -> b) -> BuiltinString -> BuiltinString)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> BuiltinString -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> BuiltinString -> r)
-> (forall u. (forall d. Data d => d -> u) -> BuiltinString -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> BuiltinString -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> BuiltinString -> m BuiltinString)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> BuiltinString -> m BuiltinString)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> BuiltinString -> m BuiltinString)
-> Data BuiltinString
BuiltinString -> Constr
BuiltinString -> DataType
(forall b. Data b => b -> b) -> BuiltinString -> BuiltinString
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> BuiltinString -> u
forall u. (forall d. Data d => d -> u) -> BuiltinString -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinString -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinString -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> BuiltinString -> m BuiltinString
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> BuiltinString -> m BuiltinString
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c BuiltinString
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> BuiltinString -> c BuiltinString
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c BuiltinString)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c BuiltinString)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> BuiltinString -> c BuiltinString
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> BuiltinString -> c BuiltinString
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c BuiltinString
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c BuiltinString
$ctoConstr :: BuiltinString -> Constr
toConstr :: BuiltinString -> Constr
$cdataTypeOf :: BuiltinString -> DataType
dataTypeOf :: BuiltinString -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c BuiltinString)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c BuiltinString)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c BuiltinString)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c BuiltinString)
$cgmapT :: (forall b. Data b => b -> b) -> BuiltinString -> BuiltinString
gmapT :: (forall b. Data b => b -> b) -> BuiltinString -> BuiltinString
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinString -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinString -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinString -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinString -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> BuiltinString -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> BuiltinString -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> BuiltinString -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> BuiltinString -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> BuiltinString -> m BuiltinString
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> BuiltinString -> m BuiltinString
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> BuiltinString -> m BuiltinString
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> BuiltinString -> m BuiltinString
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> BuiltinString -> m BuiltinString
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> BuiltinString -> m BuiltinString
Data

instance Haskell.Show BuiltinString where
    show :: BuiltinString -> [Char]
show (BuiltinString Text
t) = Text -> [Char]
forall a. Show a => a -> [Char]
show Text
t
instance Haskell.Eq BuiltinString where
    == :: BuiltinString -> BuiltinString -> Bool
(==) (BuiltinString Text
t) (BuiltinString Text
t') = Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
(==) Text
t Text
t'
instance Haskell.Ord BuiltinString where
    compare :: BuiltinString -> BuiltinString -> Ordering
compare (BuiltinString Text
t) (BuiltinString Text
t') = Text -> Text -> Ordering
forall a. Ord a => a -> a -> Ordering
compare Text
t Text
t'

{-# OPAQUE appendString #-}
appendString :: BuiltinString -> BuiltinString -> BuiltinString
appendString :: BuiltinString -> BuiltinString -> BuiltinString
appendString (BuiltinString Text
s1) (BuiltinString Text
s2) = Text -> BuiltinString
BuiltinString (Text
s1 Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
s2)

{-# OPAQUE emptyString #-}
emptyString :: BuiltinString
emptyString :: BuiltinString
emptyString = Text -> BuiltinString
BuiltinString Text
Text.empty

{-# OPAQUE equalsString #-}
equalsString :: BuiltinString -> BuiltinString -> BuiltinBool
equalsString :: BuiltinString -> BuiltinString -> BuiltinBool
equalsString (BuiltinString Text
s1) (BuiltinString Text
s2) = Bool -> BuiltinBool
BuiltinBool (Bool -> BuiltinBool) -> Bool -> BuiltinBool
forall a b. (a -> b) -> a -> b
$ Text
s1 Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text
s2

{-# OPAQUE trace #-}
trace :: BuiltinString -> a -> a
trace :: forall a. BuiltinString -> a -> a
trace BuiltinString
_ a
x = a
x

{-# OPAQUE encodeUtf8 #-}
encodeUtf8 :: BuiltinString -> BuiltinByteString
encodeUtf8 :: BuiltinString -> BuiltinByteString
encodeUtf8 (BuiltinString Text
s) = ByteString -> BuiltinByteString
BuiltinByteString (ByteString -> BuiltinByteString)
-> ByteString -> BuiltinByteString
forall a b. (a -> b) -> a -> b
$ Text -> ByteString
Text.encodeUtf8 Text
s

{-
PAIR
-}

-- See Note [Opaque builtin types]
data BuiltinPair a b = BuiltinPair ~(a, b) deriving stock Typeable (BuiltinPair a b)
Typeable (BuiltinPair a b) =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> BuiltinPair a b -> c (BuiltinPair a b))
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (BuiltinPair a b))
-> (BuiltinPair a b -> Constr)
-> (BuiltinPair a b -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c (BuiltinPair a b)))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c (BuiltinPair a b)))
-> ((forall b. Data b => b -> b)
    -> BuiltinPair a b -> BuiltinPair a b)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> BuiltinPair a b -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> BuiltinPair a b -> r)
-> (forall u.
    (forall d. Data d => d -> u) -> BuiltinPair a b -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> BuiltinPair a b -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d)
    -> BuiltinPair a b -> m (BuiltinPair a b))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d)
    -> BuiltinPair a b -> m (BuiltinPair a b))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d)
    -> BuiltinPair a b -> m (BuiltinPair a b))
-> Data (BuiltinPair a b)
BuiltinPair a b -> Constr
BuiltinPair a b -> DataType
(forall b. Data b => b -> b) -> BuiltinPair a b -> BuiltinPair a b
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u.
Int -> (forall d. Data d => d -> u) -> BuiltinPair a b -> u
forall u. (forall d. Data d => d -> u) -> BuiltinPair a b -> [u]
forall a b. (Data a, Data b) => Typeable (BuiltinPair a b)
forall a b. (Data a, Data b) => BuiltinPair a b -> Constr
forall a b. (Data a, Data b) => BuiltinPair a b -> DataType
forall a b.
(Data a, Data b) =>
(forall b. Data b => b -> b) -> BuiltinPair a b -> BuiltinPair a b
forall a b u.
(Data a, Data b) =>
Int -> (forall d. Data d => d -> u) -> BuiltinPair a b -> u
forall a b u.
(Data a, Data b) =>
(forall d. Data d => d -> u) -> BuiltinPair a b -> [u]
forall a b r r'.
(Data a, Data b) =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinPair a b -> r
forall a b r r'.
(Data a, Data b) =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinPair a b -> r
forall a b (m :: * -> *).
(Data a, Data b, Monad m) =>
(forall d. Data d => d -> m d)
-> BuiltinPair a b -> m (BuiltinPair a b)
forall a b (m :: * -> *).
(Data a, Data b, MonadPlus m) =>
(forall d. Data d => d -> m d)
-> BuiltinPair a b -> m (BuiltinPair a b)
forall a b (c :: * -> *).
(Data a, Data b) =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (BuiltinPair a b)
forall a b (c :: * -> *).
(Data a, Data b) =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> BuiltinPair a b -> c (BuiltinPair a b)
forall a b (t :: * -> *) (c :: * -> *).
(Data a, Data b, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (BuiltinPair a b))
forall a b (t :: * -> * -> *) (c :: * -> *).
(Data a, Data b, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (BuiltinPair a b))
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinPair a b -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinPair a b -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> BuiltinPair a b -> m (BuiltinPair a b)
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> BuiltinPair a b -> m (BuiltinPair a b)
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (BuiltinPair a b)
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> BuiltinPair a b -> c (BuiltinPair a b)
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (BuiltinPair a b))
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (BuiltinPair a b))
$cgfoldl :: forall a b (c :: * -> *).
(Data a, Data b) =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> BuiltinPair a b -> c (BuiltinPair a b)
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> BuiltinPair a b -> c (BuiltinPair a b)
$cgunfold :: forall a b (c :: * -> *).
(Data a, Data b) =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (BuiltinPair a b)
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (BuiltinPair a b)
$ctoConstr :: forall a b. (Data a, Data b) => BuiltinPair a b -> Constr
toConstr :: BuiltinPair a b -> Constr
$cdataTypeOf :: forall a b. (Data a, Data b) => BuiltinPair a b -> DataType
dataTypeOf :: BuiltinPair a b -> DataType
$cdataCast1 :: forall a b (t :: * -> *) (c :: * -> *).
(Data a, Data b, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (BuiltinPair a b))
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (BuiltinPair a b))
$cdataCast2 :: forall a b (t :: * -> * -> *) (c :: * -> *).
(Data a, Data b, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (BuiltinPair a b))
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (BuiltinPair a b))
$cgmapT :: forall a b.
(Data a, Data b) =>
(forall b. Data b => b -> b) -> BuiltinPair a b -> BuiltinPair a b
gmapT :: (forall b. Data b => b -> b) -> BuiltinPair a b -> BuiltinPair a b
$cgmapQl :: forall a b r r'.
(Data a, Data b) =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinPair a b -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinPair a b -> r
$cgmapQr :: forall a b r r'.
(Data a, Data b) =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinPair a b -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinPair a b -> r
$cgmapQ :: forall a b u.
(Data a, Data b) =>
(forall d. Data d => d -> u) -> BuiltinPair a b -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> BuiltinPair a b -> [u]
$cgmapQi :: forall a b u.
(Data a, Data b) =>
Int -> (forall d. Data d => d -> u) -> BuiltinPair a b -> u
gmapQi :: forall u.
Int -> (forall d. Data d => d -> u) -> BuiltinPair a b -> u
$cgmapM :: forall a b (m :: * -> *).
(Data a, Data b, Monad m) =>
(forall d. Data d => d -> m d)
-> BuiltinPair a b -> m (BuiltinPair a b)
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> BuiltinPair a b -> m (BuiltinPair a b)
$cgmapMp :: forall a b (m :: * -> *).
(Data a, Data b, MonadPlus m) =>
(forall d. Data d => d -> m d)
-> BuiltinPair a b -> m (BuiltinPair a b)
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> BuiltinPair a b -> m (BuiltinPair a b)
$cgmapMo :: forall a b (m :: * -> *).
(Data a, Data b, MonadPlus m) =>
(forall d. Data d => d -> m d)
-> BuiltinPair a b -> m (BuiltinPair a b)
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> BuiltinPair a b -> m (BuiltinPair a b)
Data

instance (Haskell.Show a, Haskell.Show b) => Haskell.Show (BuiltinPair a b) where
    show :: BuiltinPair a b -> [Char]
show (BuiltinPair (a, b)
p) = (a, b) -> [Char]
forall a. Show a => a -> [Char]
show (a, b)
p
instance (Haskell.Eq a, Haskell.Eq b) => Haskell.Eq (BuiltinPair a b) where
    == :: BuiltinPair a b -> BuiltinPair a b -> Bool
(==) (BuiltinPair (a, b)
p) (BuiltinPair (a, b)
p') = (a, b) -> (a, b) -> Bool
forall a. Eq a => a -> a -> Bool
(==) (a, b)
p (a, b)
p'
instance (Haskell.Ord a, Haskell.Ord b) => Haskell.Ord (BuiltinPair a b) where
    compare :: BuiltinPair a b -> BuiltinPair a b -> Ordering
compare (BuiltinPair (a, b)
p) (BuiltinPair (a, b)
p') = (a, b) -> (a, b) -> Ordering
forall a. Ord a => a -> a -> Ordering
compare (a, b)
p (a, b)
p'

{-# OPAQUE fst #-}
fst :: BuiltinPair a b -> a
fst :: forall a b. BuiltinPair a b -> a
fst (BuiltinPair (a
a, b
_)) = a
a

{-# OPAQUE snd #-}
snd :: BuiltinPair a b -> b
snd :: forall a b. BuiltinPair a b -> b
snd (BuiltinPair (a
_, b
b)) = b
b

{-# OPAQUE mkPairData #-}
mkPairData :: BuiltinData -> BuiltinData -> BuiltinPair BuiltinData BuiltinData
mkPairData :: BuiltinData -> BuiltinData -> BuiltinPair BuiltinData BuiltinData
mkPairData BuiltinData
d1 BuiltinData
d2 = (BuiltinData, BuiltinData) -> BuiltinPair BuiltinData BuiltinData
forall a b. (a, b) -> BuiltinPair a b
BuiltinPair (BuiltinData
d1, BuiltinData
d2)

{-
LIST
-}

-- See Note [Opaque builtin types]
data BuiltinList a = BuiltinList ~[a] deriving stock Typeable (BuiltinList a)
Typeable (BuiltinList a) =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> BuiltinList a -> c (BuiltinList a))
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (BuiltinList a))
-> (BuiltinList a -> Constr)
-> (BuiltinList a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c (BuiltinList a)))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c (BuiltinList a)))
-> ((forall b. Data b => b -> b) -> BuiltinList a -> BuiltinList a)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> BuiltinList a -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> BuiltinList a -> r)
-> (forall u. (forall d. Data d => d -> u) -> BuiltinList a -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> BuiltinList a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d)
    -> BuiltinList a -> m (BuiltinList a))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d)
    -> BuiltinList a -> m (BuiltinList a))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d)
    -> BuiltinList a -> m (BuiltinList a))
-> Data (BuiltinList a)
BuiltinList a -> Constr
BuiltinList a -> DataType
(forall b. Data b => b -> b) -> BuiltinList a -> BuiltinList a
forall a. Data a => Typeable (BuiltinList a)
forall a. Data a => BuiltinList a -> Constr
forall a. Data a => BuiltinList a -> DataType
forall a.
Data a =>
(forall b. Data b => b -> b) -> BuiltinList a -> BuiltinList a
forall a u.
Data a =>
Int -> (forall d. Data d => d -> u) -> BuiltinList a -> u
forall a u.
Data a =>
(forall d. Data d => d -> u) -> BuiltinList a -> [u]
forall a r r'.
Data a =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinList a -> r
forall a r r'.
Data a =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinList a -> r
forall a (m :: * -> *).
(Data a, Monad m) =>
(forall d. Data d => d -> m d)
-> BuiltinList a -> m (BuiltinList a)
forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d)
-> BuiltinList a -> m (BuiltinList a)
forall a (c :: * -> *).
Data a =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (BuiltinList a)
forall a (c :: * -> *).
Data a =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> BuiltinList a -> c (BuiltinList a)
forall a (t :: * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (BuiltinList a))
forall a (t :: * -> * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (BuiltinList a))
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> BuiltinList a -> u
forall u. (forall d. Data d => d -> u) -> BuiltinList a -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinList a -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinList a -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> BuiltinList a -> m (BuiltinList a)
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> BuiltinList a -> m (BuiltinList a)
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (BuiltinList a)
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> BuiltinList a -> c (BuiltinList a)
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (BuiltinList a))
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (BuiltinList a))
$cgfoldl :: forall a (c :: * -> *).
Data a =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> BuiltinList a -> c (BuiltinList a)
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> BuiltinList a -> c (BuiltinList a)
$cgunfold :: forall a (c :: * -> *).
Data a =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (BuiltinList a)
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (BuiltinList a)
$ctoConstr :: forall a. Data a => BuiltinList a -> Constr
toConstr :: BuiltinList a -> Constr
$cdataTypeOf :: forall a. Data a => BuiltinList a -> DataType
dataTypeOf :: BuiltinList a -> DataType
$cdataCast1 :: forall a (t :: * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (BuiltinList a))
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (BuiltinList a))
$cdataCast2 :: forall a (t :: * -> * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (BuiltinList a))
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (BuiltinList a))
$cgmapT :: forall a.
Data a =>
(forall b. Data b => b -> b) -> BuiltinList a -> BuiltinList a
gmapT :: (forall b. Data b => b -> b) -> BuiltinList a -> BuiltinList a
$cgmapQl :: forall a r r'.
Data a =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinList a -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinList a -> r
$cgmapQr :: forall a r r'.
Data a =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinList a -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinList a -> r
$cgmapQ :: forall a u.
Data a =>
(forall d. Data d => d -> u) -> BuiltinList a -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> BuiltinList a -> [u]
$cgmapQi :: forall a u.
Data a =>
Int -> (forall d. Data d => d -> u) -> BuiltinList a -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> BuiltinList a -> u
$cgmapM :: forall a (m :: * -> *).
(Data a, Monad m) =>
(forall d. Data d => d -> m d)
-> BuiltinList a -> m (BuiltinList a)
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> BuiltinList a -> m (BuiltinList a)
$cgmapMp :: forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d)
-> BuiltinList a -> m (BuiltinList a)
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> BuiltinList a -> m (BuiltinList a)
$cgmapMo :: forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d)
-> BuiltinList a -> m (BuiltinList a)
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> BuiltinList a -> m (BuiltinList a)
Data

instance Haskell.Show a => Haskell.Show (BuiltinList a) where
    show :: BuiltinList a -> [Char]
show (BuiltinList [a]
l) = [a] -> [Char]
forall a. Show a => a -> [Char]
show [a]
l
instance Haskell.Eq a => Haskell.Eq (BuiltinList a) where
    == :: BuiltinList a -> BuiltinList a -> Bool
(==) (BuiltinList [a]
l) (BuiltinList [a]
l') = [a] -> [a] -> Bool
forall a. Eq a => a -> a -> Bool
(==) [a]
l [a]
l'
instance Haskell.Ord a => Haskell.Ord (BuiltinList a) where
    compare :: BuiltinList a -> BuiltinList a -> Ordering
compare (BuiltinList [a]
l) (BuiltinList [a]
l') = [a] -> [a] -> Ordering
forall a. Ord a => a -> a -> Ordering
compare [a]
l [a]
l'

{-# OPAQUE null #-}
null :: BuiltinList a -> BuiltinBool
null :: forall a. BuiltinList a -> BuiltinBool
null (BuiltinList (a
_:[a]
_)) = Bool -> BuiltinBool
BuiltinBool Bool
False
null (BuiltinList [])    = Bool -> BuiltinBool
BuiltinBool Bool
True

{-# OPAQUE head #-}
head :: BuiltinList a -> a
head :: forall a. BuiltinList a -> a
head (BuiltinList (a
x:[a]
_)) = a
x
head (BuiltinList [])    = [Char] -> a
forall a. HasCallStack => [Char] -> a
Haskell.error [Char]
"empty list"

{-# OPAQUE tail #-}
tail :: BuiltinList a -> BuiltinList a
tail :: forall a. BuiltinList a -> BuiltinList a
tail (BuiltinList (a
_:[a]
xs)) = [a] -> BuiltinList a
forall a. [a] -> BuiltinList a
BuiltinList [a]
xs
tail (BuiltinList [])     = [Char] -> BuiltinList a
forall a. HasCallStack => [Char] -> a
Haskell.error [Char]
"empty list"

{-# OPAQUE chooseList #-}
chooseList :: BuiltinList a -> b -> b -> b
chooseList :: forall a b. BuiltinList a -> b -> b -> b
chooseList (BuiltinList [])    b
b1 b
_ = b
b1
chooseList (BuiltinList (a
_:[a]
_)) b
_ b
b2 = b
b2

{-# OPAQUE mkNilData #-}
mkNilData :: BuiltinUnit -> BuiltinList BuiltinData
mkNilData :: BuiltinUnit -> BuiltinList BuiltinData
mkNilData BuiltinUnit
_ = [BuiltinData] -> BuiltinList BuiltinData
forall a. [a] -> BuiltinList a
BuiltinList []

{-# OPAQUE mkNilPairData #-}
mkNilPairData :: BuiltinUnit -> BuiltinList (BuiltinPair BuiltinData BuiltinData)
mkNilPairData :: BuiltinUnit -> BuiltinList (BuiltinPair BuiltinData BuiltinData)
mkNilPairData BuiltinUnit
_ = [BuiltinPair BuiltinData BuiltinData]
-> BuiltinList (BuiltinPair BuiltinData BuiltinData)
forall a. [a] -> BuiltinList a
BuiltinList []

{-# OPAQUE mkCons #-}
mkCons :: a -> BuiltinList a -> BuiltinList a
mkCons :: forall a. a -> BuiltinList a -> BuiltinList a
mkCons a
a (BuiltinList [a]
as) = [a] -> BuiltinList a
forall a. [a] -> BuiltinList a
BuiltinList (a
aa -> [a] -> [a]
forall a. a -> [a] -> [a]
:[a]
as)

{-
DATA
-}

{-|
A type corresponding to the Plutus Core builtin equivalent of 'PLC.Data'.

The point of this type is to be an opaque equivalent of 'PLC.Data', so as to
ensure that it is only used in ways that the compiler can handle.

As such, you should use this type in your on-chain code, and in any data structures
that you want to be representable on-chain.

For off-chain usage, there are conversion functions 'builtinDataToData' and
'dataToBuiltinData', but note that these will not work on-chain.
-}
data BuiltinData = BuiltinData ~PLC.Data
    deriving stock (Typeable BuiltinData
Typeable BuiltinData =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> BuiltinData -> c BuiltinData)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c BuiltinData)
-> (BuiltinData -> Constr)
-> (BuiltinData -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c BuiltinData))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c BuiltinData))
-> ((forall b. Data b => b -> b) -> BuiltinData -> BuiltinData)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> BuiltinData -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> BuiltinData -> r)
-> (forall u. (forall d. Data d => d -> u) -> BuiltinData -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> BuiltinData -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> BuiltinData -> m BuiltinData)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> BuiltinData -> m BuiltinData)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> BuiltinData -> m BuiltinData)
-> Data BuiltinData
BuiltinData -> Constr
BuiltinData -> DataType
(forall b. Data b => b -> b) -> BuiltinData -> BuiltinData
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> BuiltinData -> u
forall u. (forall d. Data d => d -> u) -> BuiltinData -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinData -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinData -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> BuiltinData -> m BuiltinData
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> BuiltinData -> m BuiltinData
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c BuiltinData
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> BuiltinData -> c BuiltinData
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c BuiltinData)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c BuiltinData)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> BuiltinData -> c BuiltinData
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> BuiltinData -> c BuiltinData
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c BuiltinData
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c BuiltinData
$ctoConstr :: BuiltinData -> Constr
toConstr :: BuiltinData -> Constr
$cdataTypeOf :: BuiltinData -> DataType
dataTypeOf :: BuiltinData -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c BuiltinData)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c BuiltinData)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c BuiltinData)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c BuiltinData)
$cgmapT :: (forall b. Data b => b -> b) -> BuiltinData -> BuiltinData
gmapT :: (forall b. Data b => b -> b) -> BuiltinData -> BuiltinData
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinData -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinData -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinData -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> BuiltinData -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> BuiltinData -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> BuiltinData -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> BuiltinData -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> BuiltinData -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> BuiltinData -> m BuiltinData
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> BuiltinData -> m BuiltinData
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> BuiltinData -> m BuiltinData
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> BuiltinData -> m BuiltinData
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> BuiltinData -> m BuiltinData
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> BuiltinData -> m BuiltinData
Data, (forall x. BuiltinData -> Rep BuiltinData x)
-> (forall x. Rep BuiltinData x -> BuiltinData)
-> Generic BuiltinData
forall x. Rep BuiltinData x -> BuiltinData
forall x. BuiltinData -> Rep BuiltinData x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. BuiltinData -> Rep BuiltinData x
from :: forall x. BuiltinData -> Rep BuiltinData x
$cto :: forall x. Rep BuiltinData x -> BuiltinData
to :: forall x. Rep BuiltinData x -> BuiltinData
Generic)

instance Haskell.Show BuiltinData where
    show :: BuiltinData -> [Char]
show (BuiltinData Data
d) = Data -> [Char]
forall a. Show a => a -> [Char]
show Data
d
instance Haskell.Eq BuiltinData where
    == :: BuiltinData -> BuiltinData -> Bool
(==) (BuiltinData Data
d) (BuiltinData Data
d') = Data -> Data -> Bool
forall a. Eq a => a -> a -> Bool
(==) Data
d Data
d'
instance Haskell.Ord BuiltinData where
    compare :: BuiltinData -> BuiltinData -> Ordering
compare (BuiltinData Data
d) (BuiltinData Data
d') = Data -> Data -> Ordering
forall a. Ord a => a -> a -> Ordering
compare Data
d Data
d'
instance NFData BuiltinData where
    rnf :: BuiltinData -> ()
rnf (BuiltinData Data
d) = Data -> ()
forall a. NFData a => a -> ()
rnf Data
d
instance Pretty BuiltinData where
    pretty :: forall ann. BuiltinData -> Doc ann
pretty (BuiltinData Data
d) = Data -> Doc ann
forall a ann. Pretty a => a -> Doc ann
forall ann. Data -> Doc ann
pretty Data
d

-- NOT a builtin, only safe off-chain, hence the OPAQUE
{-# OPAQUE builtinDataToData #-}
-- | Convert a 'BuiltinData' into a 'PLC.Data'. Only works off-chain.
builtinDataToData :: BuiltinData -> PLC.Data
builtinDataToData :: BuiltinData -> Data
builtinDataToData (BuiltinData Data
d) = Data
d

-- NOT a builtin, only safe off-chain, hence the OPAQUE
{-# OPAQUE dataToBuiltinData #-}
-- | Convert a 'PLC.Data' into a 'BuiltinData'. Only works off-chain.
dataToBuiltinData :: PLC.Data -> BuiltinData
dataToBuiltinData :: Data -> BuiltinData
dataToBuiltinData = Data -> BuiltinData
BuiltinData

{-# OPAQUE chooseData #-}
chooseData :: forall a . BuiltinData -> a -> a -> a -> a -> a -> a
chooseData :: forall a. BuiltinData -> a -> a -> a -> a -> a -> a
chooseData (BuiltinData Data
d) a
constrCase a
mapCase a
listCase a
iCase a
bCase = case Data
d of
    PLC.Constr{} -> a
constrCase
    PLC.Map{}    -> a
mapCase
    PLC.List{}   -> a
listCase
    PLC.I{}      -> a
iCase
    PLC.B{}      -> a
bCase

{-# OPAQUE mkConstr #-}
mkConstr :: BuiltinInteger -> BuiltinList BuiltinData -> BuiltinData
mkConstr :: BuiltinInteger -> BuiltinList BuiltinData -> BuiltinData
mkConstr BuiltinInteger
i (BuiltinList [BuiltinData]
args) = Data -> BuiltinData
BuiltinData (BuiltinInteger -> [Data] -> Data
PLC.Constr BuiltinInteger
i ((BuiltinData -> Data) -> [BuiltinData] -> [Data]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap BuiltinData -> Data
builtinDataToData [BuiltinData]
args))

{-# OPAQUE mkMap #-}
mkMap :: BuiltinList (BuiltinPair BuiltinData BuiltinData) -> BuiltinData
mkMap :: BuiltinList (BuiltinPair BuiltinData BuiltinData) -> BuiltinData
mkMap (BuiltinList [BuiltinPair BuiltinData BuiltinData]
es) = Data -> BuiltinData
BuiltinData ([(Data, Data)] -> Data
PLC.Map ((BuiltinPair BuiltinData BuiltinData -> (Data, Data))
-> [BuiltinPair BuiltinData BuiltinData] -> [(Data, Data)]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap BuiltinPair BuiltinData BuiltinData -> (Data, Data)
p2p [BuiltinPair BuiltinData BuiltinData]
es))
  where
      p2p :: BuiltinPair BuiltinData BuiltinData -> (Data, Data)
p2p (BuiltinPair (BuiltinData
d, BuiltinData
d')) = (BuiltinData -> Data
builtinDataToData BuiltinData
d, BuiltinData -> Data
builtinDataToData BuiltinData
d')

{-# OPAQUE mkList #-}
mkList :: BuiltinList BuiltinData -> BuiltinData
mkList :: BuiltinList BuiltinData -> BuiltinData
mkList (BuiltinList [BuiltinData]
l) = Data -> BuiltinData
BuiltinData ([Data] -> Data
PLC.List ((BuiltinData -> Data) -> [BuiltinData] -> [Data]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap BuiltinData -> Data
builtinDataToData [BuiltinData]
l))

{-# OPAQUE mkI #-}
mkI :: BuiltinInteger -> BuiltinData
mkI :: BuiltinInteger -> BuiltinData
mkI BuiltinInteger
i = Data -> BuiltinData
BuiltinData (BuiltinInteger -> Data
PLC.I BuiltinInteger
i)

{-# OPAQUE mkB #-}
mkB :: BuiltinByteString -> BuiltinData
mkB :: BuiltinByteString -> BuiltinData
mkB (BuiltinByteString ByteString
b) = Data -> BuiltinData
BuiltinData (ByteString -> Data
PLC.B ByteString
b)

{-# OPAQUE unsafeDataAsConstr #-}
unsafeDataAsConstr :: BuiltinData -> BuiltinPair BuiltinInteger (BuiltinList BuiltinData)
unsafeDataAsConstr :: BuiltinData -> BuiltinPair BuiltinInteger (BuiltinList BuiltinData)
unsafeDataAsConstr (BuiltinData (PLC.Constr BuiltinInteger
i [Data]
args)) = (BuiltinInteger, BuiltinList BuiltinData)
-> BuiltinPair BuiltinInteger (BuiltinList BuiltinData)
forall a b. (a, b) -> BuiltinPair a b
BuiltinPair (BuiltinInteger
i, [BuiltinData] -> BuiltinList BuiltinData
forall a. [a] -> BuiltinList a
BuiltinList ([BuiltinData] -> BuiltinList BuiltinData)
-> [BuiltinData] -> BuiltinList BuiltinData
forall a b. (a -> b) -> a -> b
$ (Data -> BuiltinData) -> [Data] -> [BuiltinData]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Data -> BuiltinData
dataToBuiltinData [Data]
args)
unsafeDataAsConstr BuiltinData
_                                 = [Char] -> BuiltinPair BuiltinInteger (BuiltinList BuiltinData)
forall a. HasCallStack => [Char] -> a
Haskell.error [Char]
"not a Constr"

{-# OPAQUE unsafeDataAsMap #-}
unsafeDataAsMap :: BuiltinData -> BuiltinList (BuiltinPair BuiltinData BuiltinData)
unsafeDataAsMap :: BuiltinData -> BuiltinList (BuiltinPair BuiltinData BuiltinData)
unsafeDataAsMap (BuiltinData (PLC.Map [(Data, Data)]
m)) = [BuiltinPair BuiltinData BuiltinData]
-> BuiltinList (BuiltinPair BuiltinData BuiltinData)
forall a. [a] -> BuiltinList a
BuiltinList (((Data, Data) -> BuiltinPair BuiltinData BuiltinData)
-> [(Data, Data)] -> [BuiltinPair BuiltinData BuiltinData]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Data, Data) -> BuiltinPair BuiltinData BuiltinData
p2p [(Data, Data)]
m)
  where
      p2p :: (Data, Data) -> BuiltinPair BuiltinData BuiltinData
p2p (Data
d, Data
d') = (BuiltinData, BuiltinData) -> BuiltinPair BuiltinData BuiltinData
forall a b. (a, b) -> BuiltinPair a b
BuiltinPair (Data -> BuiltinData
dataToBuiltinData Data
d, Data -> BuiltinData
dataToBuiltinData Data
d')
unsafeDataAsMap BuiltinData
_                         = [Char] -> BuiltinList (BuiltinPair BuiltinData BuiltinData)
forall a. HasCallStack => [Char] -> a
Haskell.error [Char]
"not a Map"

{-# OPAQUE unsafeDataAsList #-}
unsafeDataAsList :: BuiltinData -> BuiltinList BuiltinData
unsafeDataAsList :: BuiltinData -> BuiltinList BuiltinData
unsafeDataAsList (BuiltinData (PLC.List [Data]
l)) = [BuiltinData] -> BuiltinList BuiltinData
forall a. [a] -> BuiltinList a
BuiltinList ((Data -> BuiltinData) -> [Data] -> [BuiltinData]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Data -> BuiltinData
dataToBuiltinData [Data]
l)
unsafeDataAsList BuiltinData
_                          = [Char] -> BuiltinList BuiltinData
forall a. HasCallStack => [Char] -> a
Haskell.error [Char]
"not a List"

{-# OPAQUE unsafeDataAsI #-}
unsafeDataAsI :: BuiltinData -> BuiltinInteger
unsafeDataAsI :: BuiltinData -> BuiltinInteger
unsafeDataAsI (BuiltinData (PLC.I BuiltinInteger
i)) = BuiltinInteger
i
unsafeDataAsI BuiltinData
_                       = [Char] -> BuiltinInteger
forall a. HasCallStack => [Char] -> a
Haskell.error [Char]
"not an I"

{-# OPAQUE unsafeDataAsB #-}
unsafeDataAsB :: BuiltinData -> BuiltinByteString
unsafeDataAsB :: BuiltinData -> BuiltinByteString
unsafeDataAsB (BuiltinData (PLC.B ByteString
b)) = ByteString -> BuiltinByteString
BuiltinByteString ByteString
b
unsafeDataAsB BuiltinData
_                       = [Char] -> BuiltinByteString
forall a. HasCallStack => [Char] -> a
Haskell.error [Char]
"not a B"

{-# OPAQUE equalsData #-}
equalsData :: BuiltinData -> BuiltinData -> BuiltinBool
equalsData :: BuiltinData -> BuiltinData -> BuiltinBool
equalsData (BuiltinData Data
b1) (BuiltinData Data
b2) = Bool -> BuiltinBool
BuiltinBool (Bool -> BuiltinBool) -> Bool -> BuiltinBool
forall a b. (a -> b) -> a -> b
$ Data
b1 Data -> Data -> Bool
forall a. Eq a => a -> a -> Bool
Haskell.== Data
b2

{-# OPAQUE serialiseData #-}
serialiseData :: BuiltinData -> BuiltinByteString
serialiseData :: BuiltinData -> BuiltinByteString
serialiseData (BuiltinData Data
b) = ByteString -> BuiltinByteString
BuiltinByteString (ByteString -> BuiltinByteString)
-> ByteString -> BuiltinByteString
forall a b. (a -> b) -> a -> b
$ ByteString -> ByteString
BSL.toStrict (ByteString -> ByteString) -> ByteString -> ByteString
forall a b. (a -> b) -> a -> b
$ Data -> ByteString
forall a. Serialise a => a -> ByteString
serialise Data
b


{-
BLS12_381
-}

{- Note [Wrapping the BLS12-381 types in PlutusTx]

As explained in Note [Wrapping the BLS12-381 types in Plutus Core], the types
exported by the Haskell bindings for the `blst` library are ForeignPtrs which
have to be wrapped in newtypes to keep the PLC builtin machinery happy.
However, there's a further complication in PlutusTx: if you try to use the
newtypes directly then the plugin sees through the newtypes to the foreign
pointers and fails because it doesn't know how to handle them.  To avoid this we
further wrap the newtypes in datatypes here.  We could have done this in Plutus
Core by using `data` instead of `newtype`, but then the code here dealing with
BLS types and builtins doesn't look like the code for the other builtins.
Because of this it seemed safer and more uniform to add the datatype wrapper
here rather than in the Plutus Core code.
-}

---------------- G1 ----------------

data BuiltinBLS12_381_G1_Element = BuiltinBLS12_381_G1_Element ~BLS12_381.G1.Element

instance Haskell.Show BuiltinBLS12_381_G1_Element where
    show :: BuiltinBLS12_381_G1_Element -> [Char]
show (BuiltinBLS12_381_G1_Element Element
a) = Element -> [Char]
forall a. Show a => a -> [Char]
show Element
a
instance Haskell.Eq BuiltinBLS12_381_G1_Element where
    == :: BuiltinBLS12_381_G1_Element -> BuiltinBLS12_381_G1_Element -> Bool
(==) (BuiltinBLS12_381_G1_Element Element
a) (BuiltinBLS12_381_G1_Element Element
b) = Element -> Element -> Bool
forall a. Eq a => a -> a -> Bool
(==) Element
a Element
b
instance NFData BuiltinBLS12_381_G1_Element where
     rnf :: BuiltinBLS12_381_G1_Element -> ()
rnf (BuiltinBLS12_381_G1_Element Element
d) = Element -> ()
forall a. NFData a => a -> ()
rnf Element
d
instance Pretty BuiltinBLS12_381_G1_Element where
    pretty :: forall ann. BuiltinBLS12_381_G1_Element -> Doc ann
pretty (BuiltinBLS12_381_G1_Element Element
a) = Element -> Doc ann
forall ann. Element -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty Element
a

{-# OPAQUE bls12_381_G1_equals #-}
bls12_381_G1_equals :: BuiltinBLS12_381_G1_Element -> BuiltinBLS12_381_G1_Element -> BuiltinBool
bls12_381_G1_equals :: BuiltinBLS12_381_G1_Element
-> BuiltinBLS12_381_G1_Element -> BuiltinBool
bls12_381_G1_equals BuiltinBLS12_381_G1_Element
a BuiltinBLS12_381_G1_Element
b = Bool -> BuiltinBool
BuiltinBool (Bool -> BuiltinBool) -> Bool -> BuiltinBool
forall a b. (a -> b) -> a -> b
$ (BuiltinBLS12_381_G1_Element
 -> BuiltinBLS12_381_G1_Element -> Bool)
-> BuiltinBLS12_381_G1_Element
-> BuiltinBLS12_381_G1_Element
-> Bool
forall a b. Coercible a b => a -> b
coerce (forall a. Eq a => a -> a -> Bool
(==) @BuiltinBLS12_381_G1_Element) BuiltinBLS12_381_G1_Element
a BuiltinBLS12_381_G1_Element
b

{-# OPAQUE bls12_381_G1_add #-}
bls12_381_G1_add :: BuiltinBLS12_381_G1_Element -> BuiltinBLS12_381_G1_Element -> BuiltinBLS12_381_G1_Element
bls12_381_G1_add :: BuiltinBLS12_381_G1_Element
-> BuiltinBLS12_381_G1_Element -> BuiltinBLS12_381_G1_Element
bls12_381_G1_add (BuiltinBLS12_381_G1_Element Element
a) (BuiltinBLS12_381_G1_Element Element
b) = Element -> BuiltinBLS12_381_G1_Element
BuiltinBLS12_381_G1_Element (Element -> Element -> Element
BLS12_381.G1.add Element
a Element
b)

{-# OPAQUE bls12_381_G1_neg #-}
bls12_381_G1_neg :: BuiltinBLS12_381_G1_Element -> BuiltinBLS12_381_G1_Element
bls12_381_G1_neg :: BuiltinBLS12_381_G1_Element -> BuiltinBLS12_381_G1_Element
bls12_381_G1_neg (BuiltinBLS12_381_G1_Element Element
a) = Element -> BuiltinBLS12_381_G1_Element
BuiltinBLS12_381_G1_Element (Element -> Element
BLS12_381.G1.neg Element
a)

{-# OPAQUE bls12_381_G1_scalarMul #-}
bls12_381_G1_scalarMul :: BuiltinInteger -> BuiltinBLS12_381_G1_Element -> BuiltinBLS12_381_G1_Element
bls12_381_G1_scalarMul :: BuiltinInteger
-> BuiltinBLS12_381_G1_Element -> BuiltinBLS12_381_G1_Element
bls12_381_G1_scalarMul BuiltinInteger
n (BuiltinBLS12_381_G1_Element Element
a) = Element -> BuiltinBLS12_381_G1_Element
BuiltinBLS12_381_G1_Element (BuiltinInteger -> Element -> Element
BLS12_381.G1.scalarMul BuiltinInteger
n Element
a)

{-# OPAQUE bls12_381_G1_compress #-}
bls12_381_G1_compress :: BuiltinBLS12_381_G1_Element -> BuiltinByteString
bls12_381_G1_compress :: BuiltinBLS12_381_G1_Element -> BuiltinByteString
bls12_381_G1_compress (BuiltinBLS12_381_G1_Element Element
a) = ByteString -> BuiltinByteString
BuiltinByteString (Element -> ByteString
BLS12_381.G1.compress Element
a)

{-# OPAQUE bls12_381_G1_uncompress #-}
bls12_381_G1_uncompress :: BuiltinByteString -> BuiltinBLS12_381_G1_Element
bls12_381_G1_uncompress :: BuiltinByteString -> BuiltinBLS12_381_G1_Element
bls12_381_G1_uncompress (BuiltinByteString ByteString
b) =
    case ByteString -> Either BLSTError Element
BLS12_381.G1.uncompress ByteString
b of
      Left BLSTError
err -> [Char] -> BuiltinBLS12_381_G1_Element
forall a. HasCallStack => [Char] -> a
Haskell.error ([Char] -> BuiltinBLS12_381_G1_Element)
-> [Char] -> BuiltinBLS12_381_G1_Element
forall a b. (a -> b) -> a -> b
$ [Char]
"BSL12_381 G1 uncompression error: " [Char] -> ShowS
forall a. [a] -> [a] -> [a]
++ BLSTError -> [Char]
forall a. Show a => a -> [Char]
show BLSTError
err
      Right Element
a  -> Element -> BuiltinBLS12_381_G1_Element
BuiltinBLS12_381_G1_Element Element
a

{-# OPAQUE bls12_381_G1_hashToGroup #-}
bls12_381_G1_hashToGroup ::  BuiltinByteString -> BuiltinByteString -> BuiltinBLS12_381_G1_Element
bls12_381_G1_hashToGroup :: BuiltinByteString
-> BuiltinByteString -> BuiltinBLS12_381_G1_Element
bls12_381_G1_hashToGroup (BuiltinByteString ByteString
msg) (BuiltinByteString ByteString
dst) =
    case ByteString -> ByteString -> Either BLS12_381_Error Element
BLS12_381.G1.hashToGroup ByteString
msg ByteString
dst of
      Left BLS12_381_Error
err -> [Char] -> BuiltinBLS12_381_G1_Element
forall a. HasCallStack => [Char] -> a
Haskell.error ([Char] -> BuiltinBLS12_381_G1_Element)
-> [Char] -> BuiltinBLS12_381_G1_Element
forall a b. (a -> b) -> a -> b
$ BLS12_381_Error -> [Char]
forall a. Show a => a -> [Char]
show BLS12_381_Error
err
      Right Element
p  -> Element -> BuiltinBLS12_381_G1_Element
BuiltinBLS12_381_G1_Element Element
p

{-# OPAQUE bls12_381_G1_compressed_zero #-}
bls12_381_G1_compressed_zero :: BuiltinByteString
bls12_381_G1_compressed_zero :: BuiltinByteString
bls12_381_G1_compressed_zero = ByteString -> BuiltinByteString
BuiltinByteString ByteString
BLS12_381.G1.compressed_zero

{-# OPAQUE bls12_381_G1_compressed_generator #-}
bls12_381_G1_compressed_generator :: BuiltinByteString
bls12_381_G1_compressed_generator :: BuiltinByteString
bls12_381_G1_compressed_generator = ByteString -> BuiltinByteString
BuiltinByteString ByteString
BLS12_381.G1.compressed_generator

---------------- G2 ----------------

data BuiltinBLS12_381_G2_Element = BuiltinBLS12_381_G2_Element ~BLS12_381.G2.Element

instance Haskell.Show BuiltinBLS12_381_G2_Element where
    show :: BuiltinBLS12_381_G2_Element -> [Char]
show (BuiltinBLS12_381_G2_Element Element
a) = Element -> [Char]
forall a. Show a => a -> [Char]
show Element
a
instance Haskell.Eq BuiltinBLS12_381_G2_Element where
    == :: BuiltinBLS12_381_G2_Element -> BuiltinBLS12_381_G2_Element -> Bool
(==) (BuiltinBLS12_381_G2_Element Element
a) (BuiltinBLS12_381_G2_Element Element
b) = Element -> Element -> Bool
forall a. Eq a => a -> a -> Bool
(==) Element
a Element
b
instance NFData BuiltinBLS12_381_G2_Element where
     rnf :: BuiltinBLS12_381_G2_Element -> ()
rnf (BuiltinBLS12_381_G2_Element Element
d) = Element -> ()
forall a. NFData a => a -> ()
rnf Element
d
instance Pretty BuiltinBLS12_381_G2_Element where
    pretty :: forall ann. BuiltinBLS12_381_G2_Element -> Doc ann
pretty (BuiltinBLS12_381_G2_Element Element
a) = Element -> Doc ann
forall a ann. Pretty a => a -> Doc ann
forall ann. Element -> Doc ann
pretty Element
a

{-# OPAQUE bls12_381_G2_equals #-}
bls12_381_G2_equals :: BuiltinBLS12_381_G2_Element -> BuiltinBLS12_381_G2_Element -> BuiltinBool
bls12_381_G2_equals :: BuiltinBLS12_381_G2_Element
-> BuiltinBLS12_381_G2_Element -> BuiltinBool
bls12_381_G2_equals BuiltinBLS12_381_G2_Element
a BuiltinBLS12_381_G2_Element
b = Bool -> BuiltinBool
BuiltinBool (Bool -> BuiltinBool) -> Bool -> BuiltinBool
forall a b. (a -> b) -> a -> b
$ (BuiltinBLS12_381_G2_Element
 -> BuiltinBLS12_381_G2_Element -> Bool)
-> BuiltinBLS12_381_G2_Element
-> BuiltinBLS12_381_G2_Element
-> Bool
forall a b. Coercible a b => a -> b
coerce (forall a. Eq a => a -> a -> Bool
(==) @BuiltinBLS12_381_G2_Element) BuiltinBLS12_381_G2_Element
a BuiltinBLS12_381_G2_Element
b

{-# OPAQUE bls12_381_G2_add #-}
bls12_381_G2_add :: BuiltinBLS12_381_G2_Element -> BuiltinBLS12_381_G2_Element -> BuiltinBLS12_381_G2_Element
bls12_381_G2_add :: BuiltinBLS12_381_G2_Element
-> BuiltinBLS12_381_G2_Element -> BuiltinBLS12_381_G2_Element
bls12_381_G2_add (BuiltinBLS12_381_G2_Element Element
a) (BuiltinBLS12_381_G2_Element Element
b) = Element -> BuiltinBLS12_381_G2_Element
BuiltinBLS12_381_G2_Element (Element -> Element -> Element
BLS12_381.G2.add Element
a Element
b)

{-# OPAQUE bls12_381_G2_neg #-}
bls12_381_G2_neg :: BuiltinBLS12_381_G2_Element -> BuiltinBLS12_381_G2_Element
bls12_381_G2_neg :: BuiltinBLS12_381_G2_Element -> BuiltinBLS12_381_G2_Element
bls12_381_G2_neg (BuiltinBLS12_381_G2_Element Element
a) = Element -> BuiltinBLS12_381_G2_Element
BuiltinBLS12_381_G2_Element (Element -> Element
BLS12_381.G2.neg Element
a)

{-# OPAQUE bls12_381_G2_scalarMul #-}
bls12_381_G2_scalarMul :: BuiltinInteger -> BuiltinBLS12_381_G2_Element -> BuiltinBLS12_381_G2_Element
bls12_381_G2_scalarMul :: BuiltinInteger
-> BuiltinBLS12_381_G2_Element -> BuiltinBLS12_381_G2_Element
bls12_381_G2_scalarMul BuiltinInteger
n (BuiltinBLS12_381_G2_Element Element
a) = Element -> BuiltinBLS12_381_G2_Element
BuiltinBLS12_381_G2_Element (BuiltinInteger -> Element -> Element
BLS12_381.G2.scalarMul BuiltinInteger
n Element
a)

{-# OPAQUE bls12_381_G2_compress #-}
bls12_381_G2_compress :: BuiltinBLS12_381_G2_Element -> BuiltinByteString
bls12_381_G2_compress :: BuiltinBLS12_381_G2_Element -> BuiltinByteString
bls12_381_G2_compress (BuiltinBLS12_381_G2_Element Element
a) = ByteString -> BuiltinByteString
BuiltinByteString (Element -> ByteString
BLS12_381.G2.compress Element
a)

{-# OPAQUE bls12_381_G2_uncompress #-}
bls12_381_G2_uncompress :: BuiltinByteString -> BuiltinBLS12_381_G2_Element
bls12_381_G2_uncompress :: BuiltinByteString -> BuiltinBLS12_381_G2_Element
bls12_381_G2_uncompress (BuiltinByteString ByteString
b) =
    case ByteString -> Either BLSTError Element
BLS12_381.G2.uncompress ByteString
b of
      Left BLSTError
err -> [Char] -> BuiltinBLS12_381_G2_Element
forall a. HasCallStack => [Char] -> a
Haskell.error ([Char] -> BuiltinBLS12_381_G2_Element)
-> [Char] -> BuiltinBLS12_381_G2_Element
forall a b. (a -> b) -> a -> b
$ [Char]
"BSL12_381 G2 uncompression error: " [Char] -> ShowS
forall a. [a] -> [a] -> [a]
++ BLSTError -> [Char]
forall a. Show a => a -> [Char]
show BLSTError
err
      Right Element
a  -> Element -> BuiltinBLS12_381_G2_Element
BuiltinBLS12_381_G2_Element Element
a

{-# OPAQUE bls12_381_G2_hashToGroup #-}
bls12_381_G2_hashToGroup ::  BuiltinByteString -> BuiltinByteString -> BuiltinBLS12_381_G2_Element
bls12_381_G2_hashToGroup :: BuiltinByteString
-> BuiltinByteString -> BuiltinBLS12_381_G2_Element
bls12_381_G2_hashToGroup (BuiltinByteString ByteString
msg) (BuiltinByteString ByteString
dst) =
    case ByteString -> ByteString -> Either BLS12_381_Error Element
BLS12_381.G2.hashToGroup ByteString
msg ByteString
dst of
      Left BLS12_381_Error
err -> [Char] -> BuiltinBLS12_381_G2_Element
forall a. HasCallStack => [Char] -> a
Haskell.error ([Char] -> BuiltinBLS12_381_G2_Element)
-> [Char] -> BuiltinBLS12_381_G2_Element
forall a b. (a -> b) -> a -> b
$ BLS12_381_Error -> [Char]
forall a. Show a => a -> [Char]
show BLS12_381_Error
err
      Right Element
p  -> Element -> BuiltinBLS12_381_G2_Element
BuiltinBLS12_381_G2_Element Element
p

{-# OPAQUE bls12_381_G2_compressed_zero #-}
bls12_381_G2_compressed_zero :: BuiltinByteString
bls12_381_G2_compressed_zero :: BuiltinByteString
bls12_381_G2_compressed_zero = ByteString -> BuiltinByteString
BuiltinByteString ByteString
BLS12_381.G2.compressed_zero

{-# OPAQUE bls12_381_G2_compressed_generator #-}
bls12_381_G2_compressed_generator :: BuiltinByteString
bls12_381_G2_compressed_generator :: BuiltinByteString
bls12_381_G2_compressed_generator = ByteString -> BuiltinByteString
BuiltinByteString ByteString
BLS12_381.G2.compressed_generator


---------------- Pairing ----------------

data BuiltinBLS12_381_MlResult = BuiltinBLS12_381_MlResult ~BLS12_381.Pairing.MlResult

instance Haskell.Show BuiltinBLS12_381_MlResult where
    show :: BuiltinBLS12_381_MlResult -> [Char]
show (BuiltinBLS12_381_MlResult MlResult
a) = MlResult -> [Char]
forall a. Show a => a -> [Char]
show MlResult
a
instance Haskell.Eq BuiltinBLS12_381_MlResult where
    == :: BuiltinBLS12_381_MlResult -> BuiltinBLS12_381_MlResult -> Bool
(==) (BuiltinBLS12_381_MlResult MlResult
a) (BuiltinBLS12_381_MlResult MlResult
b) = MlResult -> MlResult -> Bool
forall a. Eq a => a -> a -> Bool
(==) MlResult
a MlResult
b
instance NFData BuiltinBLS12_381_MlResult where
     rnf :: BuiltinBLS12_381_MlResult -> ()
rnf (BuiltinBLS12_381_MlResult MlResult
a) = MlResult -> ()
forall a. NFData a => a -> ()
rnf MlResult
a
instance Pretty BuiltinBLS12_381_MlResult where
    pretty :: forall ann. BuiltinBLS12_381_MlResult -> Doc ann
pretty (BuiltinBLS12_381_MlResult MlResult
a) = MlResult -> Doc ann
forall a ann. Pretty a => a -> Doc ann
forall ann. MlResult -> Doc ann
pretty MlResult
a

{-# OPAQUE bls12_381_millerLoop #-}
bls12_381_millerLoop :: BuiltinBLS12_381_G1_Element -> BuiltinBLS12_381_G2_Element -> BuiltinBLS12_381_MlResult
bls12_381_millerLoop :: BuiltinBLS12_381_G1_Element
-> BuiltinBLS12_381_G2_Element -> BuiltinBLS12_381_MlResult
bls12_381_millerLoop (BuiltinBLS12_381_G1_Element Element
a) (BuiltinBLS12_381_G2_Element Element
b) =
    MlResult -> BuiltinBLS12_381_MlResult
BuiltinBLS12_381_MlResult (MlResult -> BuiltinBLS12_381_MlResult)
-> MlResult -> BuiltinBLS12_381_MlResult
forall a b. (a -> b) -> a -> b
$ Element -> Element -> MlResult
BLS12_381.Pairing.millerLoop Element
a Element
b

{-# OPAQUE bls12_381_mulMlResult #-}
bls12_381_mulMlResult :: BuiltinBLS12_381_MlResult -> BuiltinBLS12_381_MlResult -> BuiltinBLS12_381_MlResult
bls12_381_mulMlResult :: BuiltinBLS12_381_MlResult
-> BuiltinBLS12_381_MlResult -> BuiltinBLS12_381_MlResult
bls12_381_mulMlResult (BuiltinBLS12_381_MlResult MlResult
a) (BuiltinBLS12_381_MlResult MlResult
b)
    = MlResult -> BuiltinBLS12_381_MlResult
BuiltinBLS12_381_MlResult (MlResult -> BuiltinBLS12_381_MlResult)
-> MlResult -> BuiltinBLS12_381_MlResult
forall a b. (a -> b) -> a -> b
$ MlResult -> MlResult -> MlResult
BLS12_381.Pairing.mulMlResult MlResult
a MlResult
b

{-# OPAQUE bls12_381_finalVerify #-}
bls12_381_finalVerify ::  BuiltinBLS12_381_MlResult ->  BuiltinBLS12_381_MlResult -> BuiltinBool
bls12_381_finalVerify :: BuiltinBLS12_381_MlResult
-> BuiltinBLS12_381_MlResult -> BuiltinBool
bls12_381_finalVerify (BuiltinBLS12_381_MlResult MlResult
a) (BuiltinBLS12_381_MlResult MlResult
b)
    = Bool -> BuiltinBool
BuiltinBool (Bool -> BuiltinBool) -> Bool -> BuiltinBool
forall a b. (a -> b) -> a -> b
$ MlResult -> MlResult -> Bool
BLS12_381.Pairing.finalVerify MlResult
a MlResult
b

{-
CONVERSION
-}

{-# OPAQUE integerToByteString #-}
integerToByteString
    :: BuiltinBool
    -> BuiltinInteger
    -> BuiltinInteger
    -> BuiltinByteString
integerToByteString :: BuiltinBool
-> BuiltinInteger -> BuiltinInteger -> BuiltinByteString
integerToByteString (BuiltinBool Bool
endiannessArg) BuiltinInteger
paddingArg BuiltinInteger
input =
  case Bool
-> BuiltinInteger -> BuiltinInteger -> BuiltinResult ByteString
Bitwise.integerToByteString Bool
endiannessArg BuiltinInteger
paddingArg BuiltinInteger
input of
    BuiltinSuccess ByteString
bs              -> ByteString -> BuiltinByteString
BuiltinByteString ByteString
bs
    BuiltinSuccessWithLogs DList Text
logs ByteString
bs -> DList Text -> BuiltinByteString -> BuiltinByteString
forall a (f :: * -> *). Foldable f => f Text -> a -> a
traceAll DList Text
logs (BuiltinByteString -> BuiltinByteString)
-> BuiltinByteString -> BuiltinByteString
forall a b. (a -> b) -> a -> b
$ ByteString -> BuiltinByteString
BuiltinByteString ByteString
bs
    BuiltinFailure DList Text
logs BuiltinError
err        -> DList Text -> BuiltinByteString -> BuiltinByteString
forall a (f :: * -> *). Foldable f => f Text -> a -> a
traceAll (DList Text
logs DList Text -> DList Text -> DList Text
forall a. Semigroup a => a -> a -> a
<> Text -> DList Text
forall a. a -> DList a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (BuiltinError -> Text
forall str a. (Pretty a, Render str) => a -> str
display BuiltinError
err)) (BuiltinByteString -> BuiltinByteString)
-> BuiltinByteString -> BuiltinByteString
forall a b. (a -> b) -> a -> b
$
        [Char] -> BuiltinByteString
forall a. HasCallStack => [Char] -> a
Haskell.error [Char]
"Integer to ByteString conversion errored."

{-# OPAQUE byteStringToInteger #-}
byteStringToInteger
    :: BuiltinBool
    -> BuiltinByteString
    -> BuiltinInteger
byteStringToInteger :: BuiltinBool -> BuiltinByteString -> BuiltinInteger
byteStringToInteger (BuiltinBool Bool
statedEndianness) (BuiltinByteString ByteString
input) =
  Bool -> ByteString -> BuiltinInteger
Bitwise.byteStringToInteger Bool
statedEndianness ByteString
input

{-
BITWISE
-}

{-# OPAQUE shiftByteString #-}
shiftByteString ::
  BuiltinByteString ->
  BuiltinInteger ->
  BuiltinByteString
shiftByteString :: BuiltinByteString -> BuiltinInteger -> BuiltinByteString
shiftByteString (BuiltinByteString ByteString
bs) =
  ByteString -> BuiltinByteString
BuiltinByteString (ByteString -> BuiltinByteString)
-> (BuiltinInteger -> ByteString)
-> BuiltinInteger
-> BuiltinByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> BuiltinInteger -> ByteString
Bitwise.shiftByteString ByteString
bs

{-# OPAQUE rotateByteString #-}
rotateByteString ::
  BuiltinByteString ->
  BuiltinInteger ->
  BuiltinByteString
rotateByteString :: BuiltinByteString -> BuiltinInteger -> BuiltinByteString
rotateByteString (BuiltinByteString ByteString
bs) =
  ByteString -> BuiltinByteString
BuiltinByteString (ByteString -> BuiltinByteString)
-> (BuiltinInteger -> ByteString)
-> BuiltinInteger
-> BuiltinByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> BuiltinInteger -> ByteString
Bitwise.rotateByteString ByteString
bs

{-# OPAQUE countSetBits #-}
countSetBits ::
  BuiltinByteString ->
  BuiltinInteger
countSetBits :: BuiltinByteString -> BuiltinInteger
countSetBits (BuiltinByteString ByteString
bs) = Int -> BuiltinInteger
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> BuiltinInteger)
-> (ByteString -> Int) -> ByteString -> BuiltinInteger
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Int
Bitwise.countSetBits (ByteString -> BuiltinInteger) -> ByteString -> BuiltinInteger
forall a b. (a -> b) -> a -> b
$ ByteString
bs

{-# OPAQUE findFirstSetBit #-}
findFirstSetBit ::
  BuiltinByteString ->
  BuiltinInteger
findFirstSetBit :: BuiltinByteString -> BuiltinInteger
findFirstSetBit (BuiltinByteString ByteString
bs) =
  Int -> BuiltinInteger
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> BuiltinInteger)
-> (ByteString -> Int) -> ByteString -> BuiltinInteger
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Int
Bitwise.findFirstSetBit (ByteString -> BuiltinInteger) -> ByteString -> BuiltinInteger
forall a b. (a -> b) -> a -> b
$ ByteString
bs

{-
LOGICAL
-}

{-# OPAQUE andByteString #-}
andByteString ::
  BuiltinBool ->
  BuiltinByteString ->
  BuiltinByteString ->
  BuiltinByteString
andByteString :: BuiltinBool
-> BuiltinByteString -> BuiltinByteString -> BuiltinByteString
andByteString (BuiltinBool Bool
isPaddingSemantics) (BuiltinByteString ByteString
data1) (BuiltinByteString ByteString
data2) =
  ByteString -> BuiltinByteString
BuiltinByteString (ByteString -> BuiltinByteString)
-> (ByteString -> ByteString) -> ByteString -> BuiltinByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool -> ByteString -> ByteString -> ByteString
Bitwise.andByteString Bool
isPaddingSemantics ByteString
data1 (ByteString -> BuiltinByteString)
-> ByteString -> BuiltinByteString
forall a b. (a -> b) -> a -> b
$ ByteString
data2

{-# OPAQUE orByteString #-}
orByteString ::
  BuiltinBool ->
  BuiltinByteString ->
  BuiltinByteString ->
  BuiltinByteString
orByteString :: BuiltinBool
-> BuiltinByteString -> BuiltinByteString -> BuiltinByteString
orByteString (BuiltinBool Bool
isPaddingSemantics) (BuiltinByteString ByteString
data1) (BuiltinByteString ByteString
data2) =
  ByteString -> BuiltinByteString
BuiltinByteString (ByteString -> BuiltinByteString)
-> (ByteString -> ByteString) -> ByteString -> BuiltinByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool -> ByteString -> ByteString -> ByteString
Bitwise.orByteString Bool
isPaddingSemantics ByteString
data1 (ByteString -> BuiltinByteString)
-> ByteString -> BuiltinByteString
forall a b. (a -> b) -> a -> b
$ ByteString
data2

{-# OPAQUE xorByteString #-}
xorByteString ::
  BuiltinBool ->
  BuiltinByteString ->
  BuiltinByteString ->
  BuiltinByteString
xorByteString :: BuiltinBool
-> BuiltinByteString -> BuiltinByteString -> BuiltinByteString
xorByteString (BuiltinBool Bool
isPaddingSemantics) (BuiltinByteString ByteString
data1) (BuiltinByteString ByteString
data2) =
  ByteString -> BuiltinByteString
BuiltinByteString (ByteString -> BuiltinByteString)
-> (ByteString -> ByteString) -> ByteString -> BuiltinByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool -> ByteString -> ByteString -> ByteString
Bitwise.xorByteString Bool
isPaddingSemantics ByteString
data1 (ByteString -> BuiltinByteString)
-> ByteString -> BuiltinByteString
forall a b. (a -> b) -> a -> b
$ ByteString
data2

{-# OPAQUE complementByteString #-}
complementByteString ::
  BuiltinByteString ->
  BuiltinByteString
complementByteString :: BuiltinByteString -> BuiltinByteString
complementByteString (BuiltinByteString ByteString
bs) =
  ByteString -> BuiltinByteString
BuiltinByteString (ByteString -> BuiltinByteString)
-> (ByteString -> ByteString) -> ByteString -> BuiltinByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> ByteString
Bitwise.complementByteString (ByteString -> BuiltinByteString)
-> ByteString -> BuiltinByteString
forall a b. (a -> b) -> a -> b
$ ByteString
bs

{-# OPAQUE readBit #-}
readBit ::
  BuiltinByteString ->
  BuiltinInteger ->
  BuiltinBool
readBit :: BuiltinByteString -> BuiltinInteger -> BuiltinBool
readBit (BuiltinByteString ByteString
bs) BuiltinInteger
i =
  case ByteString -> Int -> BuiltinResult Bool
Bitwise.readBit ByteString
bs (BuiltinInteger -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral BuiltinInteger
i) of
    BuiltinFailure DList Text
logs BuiltinError
err -> DList Text -> BuiltinBool -> BuiltinBool
forall a (f :: * -> *). Foldable f => f Text -> a -> a
traceAll (DList Text
logs DList Text -> DList Text -> DList Text
forall a. Semigroup a => a -> a -> a
<> Text -> DList Text
forall a. a -> DList a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (BuiltinError -> Text
forall str a. (Pretty a, Render str) => a -> str
display BuiltinError
err)) (BuiltinBool -> BuiltinBool) -> BuiltinBool -> BuiltinBool
forall a b. (a -> b) -> a -> b
$
      [Char] -> BuiltinBool
forall a. HasCallStack => [Char] -> a
Haskell.error [Char]
"readBit errored."
    BuiltinSuccess Bool
b -> Bool -> BuiltinBool
BuiltinBool Bool
b
    BuiltinSuccessWithLogs DList Text
logs Bool
b -> DList Text -> BuiltinBool -> BuiltinBool
forall a (f :: * -> *). Foldable f => f Text -> a -> a
traceAll DList Text
logs (BuiltinBool -> BuiltinBool) -> BuiltinBool -> BuiltinBool
forall a b. (a -> b) -> a -> b
$ Bool -> BuiltinBool
BuiltinBool Bool
b

{-# OPAQUE writeBits #-}
writeBits ::
  BuiltinByteString ->
  BuiltinList BuiltinInteger ->
  BuiltinBool ->
  BuiltinByteString
writeBits :: BuiltinByteString
-> BuiltinList BuiltinInteger -> BuiltinBool -> BuiltinByteString
writeBits (BuiltinByteString ByteString
bs) (BuiltinList [BuiltinInteger]
ixes) (BuiltinBool Bool
bit) =
  case ByteString -> [BuiltinInteger] -> Bool -> BuiltinResult ByteString
Bitwise.writeBits ByteString
bs [BuiltinInteger]
ixes Bool
bit of
    BuiltinFailure DList Text
logs BuiltinError
err -> DList Text -> BuiltinByteString -> BuiltinByteString
forall a (f :: * -> *). Foldable f => f Text -> a -> a
traceAll (DList Text
logs DList Text -> DList Text -> DList Text
forall a. Semigroup a => a -> a -> a
<> Text -> DList Text
forall a. a -> DList a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (BuiltinError -> Text
forall str a. (Pretty a, Render str) => a -> str
display BuiltinError
err)) (BuiltinByteString -> BuiltinByteString)
-> BuiltinByteString -> BuiltinByteString
forall a b. (a -> b) -> a -> b
$
      [Char] -> BuiltinByteString
forall a. HasCallStack => [Char] -> a
Haskell.error [Char]
"writeBits errored."
    BuiltinSuccess ByteString
bs' -> ByteString -> BuiltinByteString
BuiltinByteString ByteString
bs'
    BuiltinSuccessWithLogs DList Text
logs ByteString
bs' -> DList Text -> BuiltinByteString -> BuiltinByteString
forall a (f :: * -> *). Foldable f => f Text -> a -> a
traceAll DList Text
logs (BuiltinByteString -> BuiltinByteString)
-> BuiltinByteString -> BuiltinByteString
forall a b. (a -> b) -> a -> b
$ ByteString -> BuiltinByteString
BuiltinByteString ByteString
bs'

{-# OPAQUE replicateByte #-}
replicateByte ::
  BuiltinInteger ->
  BuiltinInteger ->
  BuiltinByteString
replicateByte :: BuiltinInteger -> BuiltinInteger -> BuiltinByteString
replicateByte BuiltinInteger
n BuiltinInteger
w8 =
  case BuiltinInteger -> Word8 -> BuiltinResult ByteString
Bitwise.replicateByte BuiltinInteger
n (BuiltinInteger -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral BuiltinInteger
w8) of
    BuiltinFailure DList Text
logs BuiltinError
err -> DList Text -> BuiltinByteString -> BuiltinByteString
forall a (f :: * -> *). Foldable f => f Text -> a -> a
traceAll (DList Text
logs DList Text -> DList Text -> DList Text
forall a. Semigroup a => a -> a -> a
<> Text -> DList Text
forall a. a -> DList a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (BuiltinError -> Text
forall str a. (Pretty a, Render str) => a -> str
display BuiltinError
err)) (BuiltinByteString -> BuiltinByteString)
-> BuiltinByteString -> BuiltinByteString
forall a b. (a -> b) -> a -> b
$
      [Char] -> BuiltinByteString
forall a. HasCallStack => [Char] -> a
Haskell.error [Char]
"byteStringReplicate errored."
    BuiltinSuccess ByteString
bs -> ByteString -> BuiltinByteString
BuiltinByteString ByteString
bs
    BuiltinSuccessWithLogs DList Text
logs ByteString
bs -> DList Text -> BuiltinByteString -> BuiltinByteString
forall a (f :: * -> *). Foldable f => f Text -> a -> a
traceAll DList Text
logs (BuiltinByteString -> BuiltinByteString)
-> BuiltinByteString -> BuiltinByteString
forall a b. (a -> b) -> a -> b
$ ByteString -> BuiltinByteString
BuiltinByteString ByteString
bs

{-# OPAQUE expModInteger #-}
expModInteger ::
  BuiltinInteger ->
  BuiltinInteger ->
  BuiltinInteger ->
  BuiltinInteger
expModInteger :: BuiltinInteger
-> BuiltinInteger -> BuiltinInteger -> BuiltinInteger
expModInteger BuiltinInteger
b BuiltinInteger
e BuiltinInteger
m =
  -- (fromInteger @Rational) correctly throws an underflow exception upon negative integer
  -- both for GHC8.10 and GHC>=9
  case BuiltinInteger
-> BuiltinInteger -> Natural -> BuiltinResult Natural
ExpMod.expMod BuiltinInteger
b BuiltinInteger
e (BuiltinInteger -> Natural
forall a. Num a => BuiltinInteger -> a
fromInteger BuiltinInteger
m) of
    BuiltinFailure DList Text
logs BuiltinError
err -> DList Text -> BuiltinInteger -> BuiltinInteger
forall a (f :: * -> *). Foldable f => f Text -> a -> a
traceAll (DList Text
logs DList Text -> DList Text -> DList Text
forall a. Semigroup a => a -> a -> a
<> Text -> DList Text
forall a. a -> DList a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (BuiltinError -> Text
forall str a. (Pretty a, Render str) => a -> str
display BuiltinError
err)) (BuiltinInteger -> BuiltinInteger)
-> BuiltinInteger -> BuiltinInteger
forall a b. (a -> b) -> a -> b
$
      [Char] -> BuiltinInteger
forall a. HasCallStack => [Char] -> a
Haskell.error [Char]
"expModInteger errored."
    BuiltinSuccess Natural
bs -> Natural -> BuiltinInteger
forall a. Integral a => a -> BuiltinInteger
toInteger Natural
bs
    BuiltinSuccessWithLogs DList Text
logs Natural
bs -> DList Text -> BuiltinInteger -> BuiltinInteger
forall a (f :: * -> *). Foldable f => f Text -> a -> a
traceAll DList Text
logs (BuiltinInteger -> BuiltinInteger)
-> BuiltinInteger -> BuiltinInteger
forall a b. (a -> b) -> a -> b
$ Natural -> BuiltinInteger
forall a. Integral a => a -> BuiltinInteger
toInteger Natural
bs