{-# LANGUAGE EmptyDataDecls #-}
{-# LANGUAGE RankNTypes #-}
module Singular.Registry.Evidence
( SessionId (..)
, SessionBinding (..)
, Evidenced (..)
, NoWitness
, Endorsement
, Reason (..)
, Verdict (..)
, Verifier (..)
, unverifiedVerifier
) where
import Data.ByteString (ByteString)
import Data.Text (Text)
newtype SessionId = SessionId Text deriving stock (SessionId -> SessionId -> Bool
(SessionId -> SessionId -> Bool)
-> (SessionId -> SessionId -> Bool) -> Eq SessionId
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SessionId -> SessionId -> Bool
== :: SessionId -> SessionId -> Bool
$c/= :: SessionId -> SessionId -> Bool
/= :: SessionId -> SessionId -> Bool
Eq, Eq SessionId
Eq SessionId =>
(SessionId -> SessionId -> Ordering)
-> (SessionId -> SessionId -> Bool)
-> (SessionId -> SessionId -> Bool)
-> (SessionId -> SessionId -> Bool)
-> (SessionId -> SessionId -> Bool)
-> (SessionId -> SessionId -> SessionId)
-> (SessionId -> SessionId -> SessionId)
-> Ord SessionId
SessionId -> SessionId -> Bool
SessionId -> SessionId -> Ordering
SessionId -> SessionId -> SessionId
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: SessionId -> SessionId -> Ordering
compare :: SessionId -> SessionId -> Ordering
$c< :: SessionId -> SessionId -> Bool
< :: SessionId -> SessionId -> Bool
$c<= :: SessionId -> SessionId -> Bool
<= :: SessionId -> SessionId -> Bool
$c> :: SessionId -> SessionId -> Bool
> :: SessionId -> SessionId -> Bool
$c>= :: SessionId -> SessionId -> Bool
>= :: SessionId -> SessionId -> Bool
$cmax :: SessionId -> SessionId -> SessionId
max :: SessionId -> SessionId -> SessionId
$cmin :: SessionId -> SessionId -> SessionId
min :: SessionId -> SessionId -> SessionId
Ord, Int -> SessionId -> ShowS
[SessionId] -> ShowS
SessionId -> String
(Int -> SessionId -> ShowS)
-> (SessionId -> String)
-> ([SessionId] -> ShowS)
-> Show SessionId
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SessionId -> ShowS
showsPrec :: Int -> SessionId -> ShowS
$cshow :: SessionId -> String
show :: SessionId -> String
$cshowList :: [SessionId] -> ShowS
showList :: [SessionId] -> ShowS
Show)
data SessionBinding = Unbound | Bound Integer ByteString
deriving stock (SessionBinding -> SessionBinding -> Bool
(SessionBinding -> SessionBinding -> Bool)
-> (SessionBinding -> SessionBinding -> Bool) -> Eq SessionBinding
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SessionBinding -> SessionBinding -> Bool
== :: SessionBinding -> SessionBinding -> Bool
$c/= :: SessionBinding -> SessionBinding -> Bool
/= :: SessionBinding -> SessionBinding -> Bool
Eq, Int -> SessionBinding -> ShowS
[SessionBinding] -> ShowS
SessionBinding -> String
(Int -> SessionBinding -> ShowS)
-> (SessionBinding -> String)
-> ([SessionBinding] -> ShowS)
-> Show SessionBinding
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SessionBinding -> ShowS
showsPrec :: Int -> SessionBinding -> ShowS
$cshow :: SessionBinding -> String
show :: SessionBinding -> String
$cshowList :: [SessionBinding] -> ShowS
showList :: [SessionBinding] -> ShowS
Show)
data Evidenced w a = Evidenced
{ forall w a. Evidenced w a -> a
value :: a
, forall w a. Evidenced w a -> Maybe w
witness :: Maybe w
}
data NoWitness
data Endorsement
data Reason = NoVerifierConfigured deriving stock (Reason -> Reason -> Bool
(Reason -> Reason -> Bool)
-> (Reason -> Reason -> Bool) -> Eq Reason
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Reason -> Reason -> Bool
== :: Reason -> Reason -> Bool
$c/= :: Reason -> Reason -> Bool
/= :: Reason -> Reason -> Bool
Eq, Int -> Reason -> ShowS
[Reason] -> ShowS
Reason -> String
(Int -> Reason -> ShowS)
-> (Reason -> String) -> ([Reason] -> ShowS) -> Show Reason
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Reason -> ShowS
showsPrec :: Int -> Reason -> ShowS
$cshow :: Reason -> String
show :: Reason -> String
$cshowList :: [Reason] -> ShowS
showList :: [Reason] -> ShowS
Show)
data Verdict a = Verified a Endorsement | Unverified a Reason
newtype Verifier w m = Verifier
{ forall w (m :: * -> *).
Verifier w m -> forall a. Evidenced w a -> m (Verdict a)
verifyFact :: forall a. Evidenced w a -> m (Verdict a)
}
unverifiedVerifier :: (Applicative m) => Verifier NoWitness m
unverifiedVerifier :: forall (m :: * -> *). Applicative m => Verifier NoWitness m
unverifiedVerifier =
(forall a. Evidenced NoWitness a -> m (Verdict a))
-> Verifier NoWitness m
forall w (m :: * -> *).
(forall a. Evidenced w a -> m (Verdict a)) -> Verifier w m
Verifier
(\Evidenced NoWitness a
fact -> Verdict a -> m (Verdict a)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (a -> Reason -> Verdict a
forall a. a -> Reason -> Verdict a
Unverified (Evidenced NoWitness a -> a
forall w a. Evidenced w a -> a
value Evidenced NoWitness a
fact) Reason
NoVerifierConfigured))