{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
module Cardano.Crypto.VRF.Mock
( MockVRF
, VerKeyVRF (..)
, SignKeyVRF (..)
)
where
import Data.Word (Word64)
import Data.Proxy (Proxy (..))
import GHC.Generics (Generic)
import NoThunks.Class (NoThunks)
import Cardano.Binary (FromCBOR, ToCBOR (..), FromCBOR(..))
import Cardano.Crypto.Hash
import Cardano.Crypto.Util
import Cardano.Crypto.Seed
import Cardano.Crypto.VRF.Class
data MockVRF
instance VRFAlgorithm MockVRF where
newtype VerKeyVRF MockVRF = VerKeyMockVRF Word64
deriving (Int -> VerKeyVRF MockVRF -> ShowS
[VerKeyVRF MockVRF] -> ShowS
VerKeyVRF MockVRF -> String
(Int -> VerKeyVRF MockVRF -> ShowS)
-> (VerKeyVRF MockVRF -> String)
-> ([VerKeyVRF MockVRF] -> ShowS)
-> Show (VerKeyVRF MockVRF)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [VerKeyVRF MockVRF] -> ShowS
$cshowList :: [VerKeyVRF MockVRF] -> ShowS
show :: VerKeyVRF MockVRF -> String
$cshow :: VerKeyVRF MockVRF -> String
showsPrec :: Int -> VerKeyVRF MockVRF -> ShowS
$cshowsPrec :: Int -> VerKeyVRF MockVRF -> ShowS
Show, VerKeyVRF MockVRF -> VerKeyVRF MockVRF -> Bool
(VerKeyVRF MockVRF -> VerKeyVRF MockVRF -> Bool)
-> (VerKeyVRF MockVRF -> VerKeyVRF MockVRF -> Bool)
-> Eq (VerKeyVRF MockVRF)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: VerKeyVRF MockVRF -> VerKeyVRF MockVRF -> Bool
$c/= :: VerKeyVRF MockVRF -> VerKeyVRF MockVRF -> Bool
== :: VerKeyVRF MockVRF -> VerKeyVRF MockVRF -> Bool
$c== :: VerKeyVRF MockVRF -> VerKeyVRF MockVRF -> Bool
Eq, Eq (VerKeyVRF MockVRF)
Eq (VerKeyVRF MockVRF)
-> (VerKeyVRF MockVRF -> VerKeyVRF MockVRF -> Ordering)
-> (VerKeyVRF MockVRF -> VerKeyVRF MockVRF -> Bool)
-> (VerKeyVRF MockVRF -> VerKeyVRF MockVRF -> Bool)
-> (VerKeyVRF MockVRF -> VerKeyVRF MockVRF -> Bool)
-> (VerKeyVRF MockVRF -> VerKeyVRF MockVRF -> Bool)
-> (VerKeyVRF MockVRF -> VerKeyVRF MockVRF -> VerKeyVRF MockVRF)
-> (VerKeyVRF MockVRF -> VerKeyVRF MockVRF -> VerKeyVRF MockVRF)
-> Ord (VerKeyVRF MockVRF)
VerKeyVRF MockVRF -> VerKeyVRF MockVRF -> Bool
VerKeyVRF MockVRF -> VerKeyVRF MockVRF -> Ordering
VerKeyVRF MockVRF -> VerKeyVRF MockVRF -> VerKeyVRF MockVRF
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: VerKeyVRF MockVRF -> VerKeyVRF MockVRF -> VerKeyVRF MockVRF
$cmin :: VerKeyVRF MockVRF -> VerKeyVRF MockVRF -> VerKeyVRF MockVRF
max :: VerKeyVRF MockVRF -> VerKeyVRF MockVRF -> VerKeyVRF MockVRF
$cmax :: VerKeyVRF MockVRF -> VerKeyVRF MockVRF -> VerKeyVRF MockVRF
>= :: VerKeyVRF MockVRF -> VerKeyVRF MockVRF -> Bool
$c>= :: VerKeyVRF MockVRF -> VerKeyVRF MockVRF -> Bool
> :: VerKeyVRF MockVRF -> VerKeyVRF MockVRF -> Bool
$c> :: VerKeyVRF MockVRF -> VerKeyVRF MockVRF -> Bool
<= :: VerKeyVRF MockVRF -> VerKeyVRF MockVRF -> Bool
$c<= :: VerKeyVRF MockVRF -> VerKeyVRF MockVRF -> Bool
< :: VerKeyVRF MockVRF -> VerKeyVRF MockVRF -> Bool
$c< :: VerKeyVRF MockVRF -> VerKeyVRF MockVRF -> Bool
compare :: VerKeyVRF MockVRF -> VerKeyVRF MockVRF -> Ordering
$ccompare :: VerKeyVRF MockVRF -> VerKeyVRF MockVRF -> Ordering
$cp1Ord :: Eq (VerKeyVRF MockVRF)
Ord, (forall x. VerKeyVRF MockVRF -> Rep (VerKeyVRF MockVRF) x)
-> (forall x. Rep (VerKeyVRF MockVRF) x -> VerKeyVRF MockVRF)
-> Generic (VerKeyVRF MockVRF)
forall x. Rep (VerKeyVRF MockVRF) x -> VerKeyVRF MockVRF
forall x. VerKeyVRF MockVRF -> Rep (VerKeyVRF MockVRF) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep (VerKeyVRF MockVRF) x -> VerKeyVRF MockVRF
$cfrom :: forall x. VerKeyVRF MockVRF -> Rep (VerKeyVRF MockVRF) x
Generic, Context -> VerKeyVRF MockVRF -> IO (Maybe ThunkInfo)
Proxy (VerKeyVRF MockVRF) -> String
(Context -> VerKeyVRF MockVRF -> IO (Maybe ThunkInfo))
-> (Context -> VerKeyVRF MockVRF -> IO (Maybe ThunkInfo))
-> (Proxy (VerKeyVRF MockVRF) -> String)
-> NoThunks (VerKeyVRF MockVRF)
forall a.
(Context -> a -> IO (Maybe ThunkInfo))
-> (Context -> a -> IO (Maybe ThunkInfo))
-> (Proxy a -> String)
-> NoThunks a
showTypeOf :: Proxy (VerKeyVRF MockVRF) -> String
$cshowTypeOf :: Proxy (VerKeyVRF MockVRF) -> String
wNoThunks :: Context -> VerKeyVRF MockVRF -> IO (Maybe ThunkInfo)
$cwNoThunks :: Context -> VerKeyVRF MockVRF -> IO (Maybe ThunkInfo)
noThunks :: Context -> VerKeyVRF MockVRF -> IO (Maybe ThunkInfo)
$cnoThunks :: Context -> VerKeyVRF MockVRF -> IO (Maybe ThunkInfo)
NoThunks)
newtype SignKeyVRF MockVRF = SignKeyMockVRF Word64
deriving (Int -> SignKeyVRF MockVRF -> ShowS
[SignKeyVRF MockVRF] -> ShowS
SignKeyVRF MockVRF -> String
(Int -> SignKeyVRF MockVRF -> ShowS)
-> (SignKeyVRF MockVRF -> String)
-> ([SignKeyVRF MockVRF] -> ShowS)
-> Show (SignKeyVRF MockVRF)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SignKeyVRF MockVRF] -> ShowS
$cshowList :: [SignKeyVRF MockVRF] -> ShowS
show :: SignKeyVRF MockVRF -> String
$cshow :: SignKeyVRF MockVRF -> String
showsPrec :: Int -> SignKeyVRF MockVRF -> ShowS
$cshowsPrec :: Int -> SignKeyVRF MockVRF -> ShowS
Show, SignKeyVRF MockVRF -> SignKeyVRF MockVRF -> Bool
(SignKeyVRF MockVRF -> SignKeyVRF MockVRF -> Bool)
-> (SignKeyVRF MockVRF -> SignKeyVRF MockVRF -> Bool)
-> Eq (SignKeyVRF MockVRF)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SignKeyVRF MockVRF -> SignKeyVRF MockVRF -> Bool
$c/= :: SignKeyVRF MockVRF -> SignKeyVRF MockVRF -> Bool
== :: SignKeyVRF MockVRF -> SignKeyVRF MockVRF -> Bool
$c== :: SignKeyVRF MockVRF -> SignKeyVRF MockVRF -> Bool
Eq, Eq (SignKeyVRF MockVRF)
Eq (SignKeyVRF MockVRF)
-> (SignKeyVRF MockVRF -> SignKeyVRF MockVRF -> Ordering)
-> (SignKeyVRF MockVRF -> SignKeyVRF MockVRF -> Bool)
-> (SignKeyVRF MockVRF -> SignKeyVRF MockVRF -> Bool)
-> (SignKeyVRF MockVRF -> SignKeyVRF MockVRF -> Bool)
-> (SignKeyVRF MockVRF -> SignKeyVRF MockVRF -> Bool)
-> (SignKeyVRF MockVRF -> SignKeyVRF MockVRF -> SignKeyVRF MockVRF)
-> (SignKeyVRF MockVRF -> SignKeyVRF MockVRF -> SignKeyVRF MockVRF)
-> Ord (SignKeyVRF MockVRF)
SignKeyVRF MockVRF -> SignKeyVRF MockVRF -> Bool
SignKeyVRF MockVRF -> SignKeyVRF MockVRF -> Ordering
SignKeyVRF MockVRF -> SignKeyVRF MockVRF -> SignKeyVRF MockVRF
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: SignKeyVRF MockVRF -> SignKeyVRF MockVRF -> SignKeyVRF MockVRF
$cmin :: SignKeyVRF MockVRF -> SignKeyVRF MockVRF -> SignKeyVRF MockVRF
max :: SignKeyVRF MockVRF -> SignKeyVRF MockVRF -> SignKeyVRF MockVRF
$cmax :: SignKeyVRF MockVRF -> SignKeyVRF MockVRF -> SignKeyVRF MockVRF
>= :: SignKeyVRF MockVRF -> SignKeyVRF MockVRF -> Bool
$c>= :: SignKeyVRF MockVRF -> SignKeyVRF MockVRF -> Bool
> :: SignKeyVRF MockVRF -> SignKeyVRF MockVRF -> Bool
$c> :: SignKeyVRF MockVRF -> SignKeyVRF MockVRF -> Bool
<= :: SignKeyVRF MockVRF -> SignKeyVRF MockVRF -> Bool
$c<= :: SignKeyVRF MockVRF -> SignKeyVRF MockVRF -> Bool
< :: SignKeyVRF MockVRF -> SignKeyVRF MockVRF -> Bool
$c< :: SignKeyVRF MockVRF -> SignKeyVRF MockVRF -> Bool
compare :: SignKeyVRF MockVRF -> SignKeyVRF MockVRF -> Ordering
$ccompare :: SignKeyVRF MockVRF -> SignKeyVRF MockVRF -> Ordering
$cp1Ord :: Eq (SignKeyVRF MockVRF)
Ord, (forall x. SignKeyVRF MockVRF -> Rep (SignKeyVRF MockVRF) x)
-> (forall x. Rep (SignKeyVRF MockVRF) x -> SignKeyVRF MockVRF)
-> Generic (SignKeyVRF MockVRF)
forall x. Rep (SignKeyVRF MockVRF) x -> SignKeyVRF MockVRF
forall x. SignKeyVRF MockVRF -> Rep (SignKeyVRF MockVRF) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep (SignKeyVRF MockVRF) x -> SignKeyVRF MockVRF
$cfrom :: forall x. SignKeyVRF MockVRF -> Rep (SignKeyVRF MockVRF) x
Generic, Context -> SignKeyVRF MockVRF -> IO (Maybe ThunkInfo)
Proxy (SignKeyVRF MockVRF) -> String
(Context -> SignKeyVRF MockVRF -> IO (Maybe ThunkInfo))
-> (Context -> SignKeyVRF MockVRF -> IO (Maybe ThunkInfo))
-> (Proxy (SignKeyVRF MockVRF) -> String)
-> NoThunks (SignKeyVRF MockVRF)
forall a.
(Context -> a -> IO (Maybe ThunkInfo))
-> (Context -> a -> IO (Maybe ThunkInfo))
-> (Proxy a -> String)
-> NoThunks a
showTypeOf :: Proxy (SignKeyVRF MockVRF) -> String
$cshowTypeOf :: Proxy (SignKeyVRF MockVRF) -> String
wNoThunks :: Context -> SignKeyVRF MockVRF -> IO (Maybe ThunkInfo)
$cwNoThunks :: Context -> SignKeyVRF MockVRF -> IO (Maybe ThunkInfo)
noThunks :: Context -> SignKeyVRF MockVRF -> IO (Maybe ThunkInfo)
$cnoThunks :: Context -> SignKeyVRF MockVRF -> IO (Maybe ThunkInfo)
NoThunks)
newtype CertVRF MockVRF = CertMockVRF Word64
deriving (Int -> CertVRF MockVRF -> ShowS
[CertVRF MockVRF] -> ShowS
CertVRF MockVRF -> String
(Int -> CertVRF MockVRF -> ShowS)
-> (CertVRF MockVRF -> String)
-> ([CertVRF MockVRF] -> ShowS)
-> Show (CertVRF MockVRF)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CertVRF MockVRF] -> ShowS
$cshowList :: [CertVRF MockVRF] -> ShowS
show :: CertVRF MockVRF -> String
$cshow :: CertVRF MockVRF -> String
showsPrec :: Int -> CertVRF MockVRF -> ShowS
$cshowsPrec :: Int -> CertVRF MockVRF -> ShowS
Show, CertVRF MockVRF -> CertVRF MockVRF -> Bool
(CertVRF MockVRF -> CertVRF MockVRF -> Bool)
-> (CertVRF MockVRF -> CertVRF MockVRF -> Bool)
-> Eq (CertVRF MockVRF)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CertVRF MockVRF -> CertVRF MockVRF -> Bool
$c/= :: CertVRF MockVRF -> CertVRF MockVRF -> Bool
== :: CertVRF MockVRF -> CertVRF MockVRF -> Bool
$c== :: CertVRF MockVRF -> CertVRF MockVRF -> Bool
Eq, Eq (CertVRF MockVRF)
Eq (CertVRF MockVRF)
-> (CertVRF MockVRF -> CertVRF MockVRF -> Ordering)
-> (CertVRF MockVRF -> CertVRF MockVRF -> Bool)
-> (CertVRF MockVRF -> CertVRF MockVRF -> Bool)
-> (CertVRF MockVRF -> CertVRF MockVRF -> Bool)
-> (CertVRF MockVRF -> CertVRF MockVRF -> Bool)
-> (CertVRF MockVRF -> CertVRF MockVRF -> CertVRF MockVRF)
-> (CertVRF MockVRF -> CertVRF MockVRF -> CertVRF MockVRF)
-> Ord (CertVRF MockVRF)
CertVRF MockVRF -> CertVRF MockVRF -> Bool
CertVRF MockVRF -> CertVRF MockVRF -> Ordering
CertVRF MockVRF -> CertVRF MockVRF -> CertVRF MockVRF
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: CertVRF MockVRF -> CertVRF MockVRF -> CertVRF MockVRF
$cmin :: CertVRF MockVRF -> CertVRF MockVRF -> CertVRF MockVRF
max :: CertVRF MockVRF -> CertVRF MockVRF -> CertVRF MockVRF
$cmax :: CertVRF MockVRF -> CertVRF MockVRF -> CertVRF MockVRF
>= :: CertVRF MockVRF -> CertVRF MockVRF -> Bool
$c>= :: CertVRF MockVRF -> CertVRF MockVRF -> Bool
> :: CertVRF MockVRF -> CertVRF MockVRF -> Bool
$c> :: CertVRF MockVRF -> CertVRF MockVRF -> Bool
<= :: CertVRF MockVRF -> CertVRF MockVRF -> Bool
$c<= :: CertVRF MockVRF -> CertVRF MockVRF -> Bool
< :: CertVRF MockVRF -> CertVRF MockVRF -> Bool
$c< :: CertVRF MockVRF -> CertVRF MockVRF -> Bool
compare :: CertVRF MockVRF -> CertVRF MockVRF -> Ordering
$ccompare :: CertVRF MockVRF -> CertVRF MockVRF -> Ordering
$cp1Ord :: Eq (CertVRF MockVRF)
Ord, (forall x. CertVRF MockVRF -> Rep (CertVRF MockVRF) x)
-> (forall x. Rep (CertVRF MockVRF) x -> CertVRF MockVRF)
-> Generic (CertVRF MockVRF)
forall x. Rep (CertVRF MockVRF) x -> CertVRF MockVRF
forall x. CertVRF MockVRF -> Rep (CertVRF MockVRF) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep (CertVRF MockVRF) x -> CertVRF MockVRF
$cfrom :: forall x. CertVRF MockVRF -> Rep (CertVRF MockVRF) x
Generic, Context -> CertVRF MockVRF -> IO (Maybe ThunkInfo)
Proxy (CertVRF MockVRF) -> String
(Context -> CertVRF MockVRF -> IO (Maybe ThunkInfo))
-> (Context -> CertVRF MockVRF -> IO (Maybe ThunkInfo))
-> (Proxy (CertVRF MockVRF) -> String)
-> NoThunks (CertVRF MockVRF)
forall a.
(Context -> a -> IO (Maybe ThunkInfo))
-> (Context -> a -> IO (Maybe ThunkInfo))
-> (Proxy a -> String)
-> NoThunks a
showTypeOf :: Proxy (CertVRF MockVRF) -> String
$cshowTypeOf :: Proxy (CertVRF MockVRF) -> String
wNoThunks :: Context -> CertVRF MockVRF -> IO (Maybe ThunkInfo)
$cwNoThunks :: Context -> CertVRF MockVRF -> IO (Maybe ThunkInfo)
noThunks :: Context -> CertVRF MockVRF -> IO (Maybe ThunkInfo)
$cnoThunks :: Context -> CertVRF MockVRF -> IO (Maybe ThunkInfo)
NoThunks)
algorithmNameVRF :: proxy MockVRF -> String
algorithmNameVRF proxy MockVRF
_ = String
"mock"
deriveVerKeyVRF :: SignKeyVRF MockVRF -> VerKeyVRF MockVRF
deriveVerKeyVRF (SignKeyMockVRF n) = Word64 -> VerKeyVRF MockVRF
VerKeyMockVRF Word64
n
type Signable MockVRF = SignableRepresentation
evalVRF :: ContextVRF MockVRF
-> a -> SignKeyVRF MockVRF -> (OutputVRF MockVRF, CertVRF MockVRF)
evalVRF () a
a SignKeyVRF MockVRF
sk = a -> SignKeyVRF MockVRF -> (OutputVRF MockVRF, CertVRF MockVRF)
forall a.
SignableRepresentation a =>
a -> SignKeyVRF MockVRF -> (OutputVRF MockVRF, CertVRF MockVRF)
evalVRF' a
a SignKeyVRF MockVRF
sk
verifyVRF :: ContextVRF MockVRF
-> VerKeyVRF MockVRF
-> a
-> (OutputVRF MockVRF, CertVRF MockVRF)
-> Bool
verifyVRF () (VerKeyMockVRF n) a
a (OutputVRF MockVRF, CertVRF MockVRF)
c = a -> SignKeyVRF MockVRF -> (OutputVRF MockVRF, CertVRF MockVRF)
forall a.
SignableRepresentation a =>
a -> SignKeyVRF MockVRF -> (OutputVRF MockVRF, CertVRF MockVRF)
evalVRF' a
a (Word64 -> SignKeyVRF MockVRF
SignKeyMockVRF Word64
n) (OutputVRF MockVRF, CertVRF MockVRF)
-> (OutputVRF MockVRF, CertVRF MockVRF) -> Bool
forall a. Eq a => a -> a -> Bool
== (OutputVRF MockVRF, CertVRF MockVRF)
c
sizeOutputVRF :: proxy MockVRF -> Word
sizeOutputVRF proxy MockVRF
_ = Proxy ShortHash -> Word
forall h (proxy :: * -> *). HashAlgorithm h => proxy h -> Word
sizeHash (Proxy ShortHash
forall k (t :: k). Proxy t
Proxy :: Proxy ShortHash)
seedSizeVRF :: proxy MockVRF -> Word
seedSizeVRF proxy MockVRF
_ = Word
8
genKeyVRF :: Seed -> SignKeyVRF MockVRF
genKeyVRF Seed
seed = Word64 -> SignKeyVRF MockVRF
SignKeyMockVRF Word64
sk
where
sk :: Word64
sk = Seed -> (forall (m :: * -> *). MonadRandom m => m Word64) -> Word64
forall a. Seed -> (forall (m :: * -> *). MonadRandom m => m a) -> a
runMonadRandomWithSeed Seed
seed forall (m :: * -> *). MonadRandom m => m Word64
getRandomWord64
sizeVerKeyVRF :: proxy MockVRF -> Word
sizeVerKeyVRF proxy MockVRF
_ = Word
8
sizeSignKeyVRF :: proxy MockVRF -> Word
sizeSignKeyVRF proxy MockVRF
_ = Word
8
sizeCertVRF :: proxy MockVRF -> Word
sizeCertVRF proxy MockVRF
_ = Word
8
rawSerialiseVerKeyVRF :: VerKeyVRF MockVRF -> ByteString
rawSerialiseVerKeyVRF (VerKeyMockVRF k) = Word64 -> ByteString
writeBinaryWord64 Word64
k
rawSerialiseSignKeyVRF :: SignKeyVRF MockVRF -> ByteString
rawSerialiseSignKeyVRF (SignKeyMockVRF k) = Word64 -> ByteString
writeBinaryWord64 Word64
k
rawSerialiseCertVRF :: CertVRF MockVRF -> ByteString
rawSerialiseCertVRF (CertMockVRF k) = Word64 -> ByteString
writeBinaryWord64 Word64
k
rawDeserialiseVerKeyVRF :: ByteString -> Maybe (VerKeyVRF MockVRF)
rawDeserialiseVerKeyVRF ByteString
bs
| [ByteString
kb] <- [Int] -> ByteString -> [ByteString]
splitsAt [Int
8] ByteString
bs
, let k :: Word64
k = ByteString -> Word64
readBinaryWord64 ByteString
kb
= VerKeyVRF MockVRF -> Maybe (VerKeyVRF MockVRF)
forall a. a -> Maybe a
Just (VerKeyVRF MockVRF -> Maybe (VerKeyVRF MockVRF))
-> VerKeyVRF MockVRF -> Maybe (VerKeyVRF MockVRF)
forall a b. (a -> b) -> a -> b
$! Word64 -> VerKeyVRF MockVRF
VerKeyMockVRF Word64
k
| Bool
otherwise
= Maybe (VerKeyVRF MockVRF)
forall a. Maybe a
Nothing
rawDeserialiseSignKeyVRF :: ByteString -> Maybe (SignKeyVRF MockVRF)
rawDeserialiseSignKeyVRF ByteString
bs
| [ByteString
kb] <- [Int] -> ByteString -> [ByteString]
splitsAt [Int
8] ByteString
bs
, let k :: Word64
k = ByteString -> Word64
readBinaryWord64 ByteString
kb
= SignKeyVRF MockVRF -> Maybe (SignKeyVRF MockVRF)
forall a. a -> Maybe a
Just (SignKeyVRF MockVRF -> Maybe (SignKeyVRF MockVRF))
-> SignKeyVRF MockVRF -> Maybe (SignKeyVRF MockVRF)
forall a b. (a -> b) -> a -> b
$! Word64 -> SignKeyVRF MockVRF
SignKeyMockVRF Word64
k
| Bool
otherwise
= Maybe (SignKeyVRF MockVRF)
forall a. Maybe a
Nothing
rawDeserialiseCertVRF :: ByteString -> Maybe (CertVRF MockVRF)
rawDeserialiseCertVRF ByteString
bs
| [ByteString
kb] <- [Int] -> ByteString -> [ByteString]
splitsAt [Int
8] ByteString
bs
, let k :: Word64
k = ByteString -> Word64
readBinaryWord64 ByteString
kb
= CertVRF MockVRF -> Maybe (CertVRF MockVRF)
forall a. a -> Maybe a
Just (CertVRF MockVRF -> Maybe (CertVRF MockVRF))
-> CertVRF MockVRF -> Maybe (CertVRF MockVRF)
forall a b. (a -> b) -> a -> b
$! Word64 -> CertVRF MockVRF
CertMockVRF Word64
k
| Bool
otherwise
= Maybe (CertVRF MockVRF)
forall a. Maybe a
Nothing
instance ToCBOR (VerKeyVRF MockVRF) where
toCBOR :: VerKeyVRF MockVRF -> Encoding
toCBOR = VerKeyVRF MockVRF -> Encoding
forall v. VRFAlgorithm v => VerKeyVRF v -> Encoding
encodeVerKeyVRF
encodedSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size)
-> Proxy (VerKeyVRF MockVRF) -> Size
encodedSizeExpr forall t. ToCBOR t => Proxy t -> Size
_size = Proxy (VerKeyVRF MockVRF) -> Size
forall v. VRFAlgorithm v => Proxy (VerKeyVRF v) -> Size
encodedVerKeyVRFSizeExpr
instance FromCBOR (VerKeyVRF MockVRF) where
fromCBOR :: Decoder s (VerKeyVRF MockVRF)
fromCBOR = Decoder s (VerKeyVRF MockVRF)
forall v s. VRFAlgorithm v => Decoder s (VerKeyVRF v)
decodeVerKeyVRF
instance ToCBOR (SignKeyVRF MockVRF) where
toCBOR :: SignKeyVRF MockVRF -> Encoding
toCBOR = SignKeyVRF MockVRF -> Encoding
forall v. VRFAlgorithm v => SignKeyVRF v -> Encoding
encodeSignKeyVRF
encodedSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size)
-> Proxy (SignKeyVRF MockVRF) -> Size
encodedSizeExpr forall t. ToCBOR t => Proxy t -> Size
_size = Proxy (SignKeyVRF MockVRF) -> Size
forall v. VRFAlgorithm v => Proxy (SignKeyVRF v) -> Size
encodedSignKeyVRFSizeExpr
instance FromCBOR (SignKeyVRF MockVRF) where
fromCBOR :: Decoder s (SignKeyVRF MockVRF)
fromCBOR = Decoder s (SignKeyVRF MockVRF)
forall v s. VRFAlgorithm v => Decoder s (SignKeyVRF v)
decodeSignKeyVRF
instance ToCBOR (CertVRF MockVRF) where
toCBOR :: CertVRF MockVRF -> Encoding
toCBOR = CertVRF MockVRF -> Encoding
forall v. VRFAlgorithm v => CertVRF v -> Encoding
encodeCertVRF
encodedSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size)
-> Proxy (CertVRF MockVRF) -> Size
encodedSizeExpr forall t. ToCBOR t => Proxy t -> Size
_size = Proxy (CertVRF MockVRF) -> Size
forall v. VRFAlgorithm v => Proxy (CertVRF v) -> Size
encodedCertVRFSizeExpr
instance FromCBOR (CertVRF MockVRF) where
fromCBOR :: Decoder s (CertVRF MockVRF)
fromCBOR = Decoder s (CertVRF MockVRF)
forall v s. VRFAlgorithm v => Decoder s (CertVRF v)
decodeCertVRF
evalVRF' :: SignableRepresentation a
=> a
-> SignKeyVRF MockVRF
-> (OutputVRF MockVRF, CertVRF MockVRF)
evalVRF' :: a -> SignKeyVRF MockVRF -> (OutputVRF MockVRF, CertVRF MockVRF)
evalVRF' a
a sk :: SignKeyVRF MockVRF
sk@(SignKeyMockVRF n) =
let y :: ByteString
y = Hash ShortHash Encoding -> ByteString
forall h a. Hash h a -> ByteString
hashToBytes (Hash ShortHash Encoding -> ByteString)
-> Hash ShortHash Encoding -> ByteString
forall a b. (a -> b) -> a -> b
$ (Encoding -> Encoding) -> Encoding -> Hash ShortHash Encoding
forall h a. HashAlgorithm h => (a -> Encoding) -> a -> Hash h a
hashWithSerialiser @ShortHash Encoding -> Encoding
forall a. a -> a
id (Encoding -> Hash ShortHash Encoding)
-> Encoding -> Hash ShortHash Encoding
forall a b. (a -> b) -> a -> b
$
ByteString -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR (a -> ByteString
forall a. SignableRepresentation a => a -> ByteString
getSignableRepresentation a
a) Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> SignKeyVRF MockVRF -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR SignKeyVRF MockVRF
sk
in (ByteString -> OutputVRF MockVRF
forall v. ByteString -> OutputVRF v
OutputVRF ByteString
y, Word64 -> CertVRF MockVRF
CertMockVRF Word64
n)