{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE InstanceSigs #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}

-- | Praos consensus key types and their 'Key' class instances
--
module Cardano.Api.KeysPraos (

    -- * Key types
    KesKey,
    VrfKey,

    -- * Data family instances
    AsType(..),
    Hash(..),
    VerificationKey(..),
    SigningKey(..),
  ) where

import           Prelude

import           Data.String (IsString (..))

import qualified Cardano.Crypto.DSIGN.Class as Crypto
import qualified Cardano.Crypto.Hash.Class as Crypto
import qualified Cardano.Crypto.KES.Class as Crypto
import qualified Cardano.Crypto.VRF.Class as Crypto
import qualified Cardano.Ledger.Crypto as Shelley (KES, VRF)
import qualified Cardano.Ledger.Keys as Shelley
import           Cardano.Ledger.Crypto (StandardCrypto)

import           Cardano.Api.HasTypeProxy
import           Cardano.Api.Hash
import           Cardano.Api.Key
import           Cardano.Api.SerialiseBech32
import           Cardano.Api.SerialiseCBOR
import           Cardano.Api.SerialiseRaw
import           Cardano.Api.SerialiseTextEnvelope
import           Cardano.Api.SerialiseUsing


--
-- KES keys
--

data KesKey

instance HasTypeProxy KesKey where
    data AsType KesKey = AsKesKey
    proxyToAsType :: Proxy KesKey -> AsType KesKey
proxyToAsType Proxy KesKey
_ = AsType KesKey
AsKesKey

instance Key KesKey where

    newtype VerificationKey KesKey =
        KesVerificationKey (Shelley.VerKeyKES StandardCrypto)
      deriving stock (VerificationKey KesKey -> VerificationKey KesKey -> Bool
(VerificationKey KesKey -> VerificationKey KesKey -> Bool)
-> (VerificationKey KesKey -> VerificationKey KesKey -> Bool)
-> Eq (VerificationKey KesKey)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: VerificationKey KesKey -> VerificationKey KesKey -> Bool
$c/= :: VerificationKey KesKey -> VerificationKey KesKey -> Bool
== :: VerificationKey KesKey -> VerificationKey KesKey -> Bool
$c== :: VerificationKey KesKey -> VerificationKey KesKey -> Bool
Eq)
      deriving (Int -> VerificationKey KesKey -> ShowS
[VerificationKey KesKey] -> ShowS
VerificationKey KesKey -> String
(Int -> VerificationKey KesKey -> ShowS)
-> (VerificationKey KesKey -> String)
-> ([VerificationKey KesKey] -> ShowS)
-> Show (VerificationKey KesKey)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [VerificationKey KesKey] -> ShowS
$cshowList :: [VerificationKey KesKey] -> ShowS
show :: VerificationKey KesKey -> String
$cshow :: VerificationKey KesKey -> String
showsPrec :: Int -> VerificationKey KesKey -> ShowS
$cshowsPrec :: Int -> VerificationKey KesKey -> ShowS
Show, String -> VerificationKey KesKey
(String -> VerificationKey KesKey)
-> IsString (VerificationKey KesKey)
forall a. (String -> a) -> IsString a
fromString :: String -> VerificationKey KesKey
$cfromString :: String -> VerificationKey KesKey
IsString) via UsingRawBytesHex (VerificationKey KesKey)
      deriving newtype (Typeable (VerificationKey KesKey)
Typeable (VerificationKey KesKey)
-> (VerificationKey KesKey -> Encoding)
-> ((forall t. ToCBOR t => Proxy t -> Size)
    -> Proxy (VerificationKey KesKey) -> Size)
-> ((forall t. ToCBOR t => Proxy t -> Size)
    -> Proxy [VerificationKey KesKey] -> Size)
-> ToCBOR (VerificationKey KesKey)
VerificationKey KesKey -> Encoding
(forall t. ToCBOR t => Proxy t -> Size)
-> Proxy [VerificationKey KesKey] -> Size
(forall t. ToCBOR t => Proxy t -> Size)
-> Proxy (VerificationKey KesKey) -> Size
forall a.
Typeable a
-> (a -> Encoding)
-> ((forall t. ToCBOR t => Proxy t -> Size) -> Proxy a -> Size)
-> ((forall t. ToCBOR t => Proxy t -> Size) -> Proxy [a] -> Size)
-> ToCBOR a
encodedListSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size)
-> Proxy [VerificationKey KesKey] -> Size
$cencodedListSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size)
-> Proxy [VerificationKey KesKey] -> Size
encodedSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size)
-> Proxy (VerificationKey KesKey) -> Size
$cencodedSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size)
-> Proxy (VerificationKey KesKey) -> Size
toCBOR :: VerificationKey KesKey -> Encoding
$ctoCBOR :: VerificationKey KesKey -> Encoding
$cp1ToCBOR :: Typeable (VerificationKey KesKey)
ToCBOR, Typeable (VerificationKey KesKey)
Decoder s (VerificationKey KesKey)
Typeable (VerificationKey KesKey)
-> (forall s. Decoder s (VerificationKey KesKey))
-> (Proxy (VerificationKey KesKey) -> Text)
-> FromCBOR (VerificationKey KesKey)
Proxy (VerificationKey KesKey) -> Text
forall s. Decoder s (VerificationKey KesKey)
forall a.
Typeable a
-> (forall s. Decoder s a) -> (Proxy a -> Text) -> FromCBOR a
label :: Proxy (VerificationKey KesKey) -> Text
$clabel :: Proxy (VerificationKey KesKey) -> Text
fromCBOR :: Decoder s (VerificationKey KesKey)
$cfromCBOR :: forall s. Decoder s (VerificationKey KesKey)
$cp1FromCBOR :: Typeable (VerificationKey KesKey)
FromCBOR)
      deriving anyclass HasTypeProxy (VerificationKey KesKey)
HasTypeProxy (VerificationKey KesKey)
-> (VerificationKey KesKey -> ByteString)
-> (AsType (VerificationKey KesKey)
    -> ByteString -> Either DecoderError (VerificationKey KesKey))
-> SerialiseAsCBOR (VerificationKey KesKey)
AsType (VerificationKey KesKey)
-> ByteString -> Either DecoderError (VerificationKey KesKey)
VerificationKey KesKey -> ByteString
forall a.
HasTypeProxy a
-> (a -> ByteString)
-> (AsType a -> ByteString -> Either DecoderError a)
-> SerialiseAsCBOR a
deserialiseFromCBOR :: AsType (VerificationKey KesKey)
-> ByteString -> Either DecoderError (VerificationKey KesKey)
$cdeserialiseFromCBOR :: AsType (VerificationKey KesKey)
-> ByteString -> Either DecoderError (VerificationKey KesKey)
serialiseToCBOR :: VerificationKey KesKey -> ByteString
$cserialiseToCBOR :: VerificationKey KesKey -> ByteString
$cp1SerialiseAsCBOR :: HasTypeProxy (VerificationKey KesKey)
SerialiseAsCBOR

    newtype SigningKey KesKey =
        KesSigningKey (Shelley.SignKeyKES StandardCrypto)
      deriving (Int -> SigningKey KesKey -> ShowS
[SigningKey KesKey] -> ShowS
SigningKey KesKey -> String
(Int -> SigningKey KesKey -> ShowS)
-> (SigningKey KesKey -> String)
-> ([SigningKey KesKey] -> ShowS)
-> Show (SigningKey KesKey)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SigningKey KesKey] -> ShowS
$cshowList :: [SigningKey KesKey] -> ShowS
show :: SigningKey KesKey -> String
$cshow :: SigningKey KesKey -> String
showsPrec :: Int -> SigningKey KesKey -> ShowS
$cshowsPrec :: Int -> SigningKey KesKey -> ShowS
Show, String -> SigningKey KesKey
(String -> SigningKey KesKey) -> IsString (SigningKey KesKey)
forall a. (String -> a) -> IsString a
fromString :: String -> SigningKey KesKey
$cfromString :: String -> SigningKey KesKey
IsString) via UsingRawBytesHex (SigningKey KesKey)
      deriving newtype (Typeable (SigningKey KesKey)
Typeable (SigningKey KesKey)
-> (SigningKey KesKey -> Encoding)
-> ((forall t. ToCBOR t => Proxy t -> Size)
    -> Proxy (SigningKey KesKey) -> Size)
-> ((forall t. ToCBOR t => Proxy t -> Size)
    -> Proxy [SigningKey KesKey] -> Size)
-> ToCBOR (SigningKey KesKey)
SigningKey KesKey -> Encoding
(forall t. ToCBOR t => Proxy t -> Size)
-> Proxy [SigningKey KesKey] -> Size
(forall t. ToCBOR t => Proxy t -> Size)
-> Proxy (SigningKey KesKey) -> Size
forall a.
Typeable a
-> (a -> Encoding)
-> ((forall t. ToCBOR t => Proxy t -> Size) -> Proxy a -> Size)
-> ((forall t. ToCBOR t => Proxy t -> Size) -> Proxy [a] -> Size)
-> ToCBOR a
encodedListSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size)
-> Proxy [SigningKey KesKey] -> Size
$cencodedListSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size)
-> Proxy [SigningKey KesKey] -> Size
encodedSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size)
-> Proxy (SigningKey KesKey) -> Size
$cencodedSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size)
-> Proxy (SigningKey KesKey) -> Size
toCBOR :: SigningKey KesKey -> Encoding
$ctoCBOR :: SigningKey KesKey -> Encoding
$cp1ToCBOR :: Typeable (SigningKey KesKey)
ToCBOR, Typeable (SigningKey KesKey)
Decoder s (SigningKey KesKey)
Typeable (SigningKey KesKey)
-> (forall s. Decoder s (SigningKey KesKey))
-> (Proxy (SigningKey KesKey) -> Text)
-> FromCBOR (SigningKey KesKey)
Proxy (SigningKey KesKey) -> Text
forall s. Decoder s (SigningKey KesKey)
forall a.
Typeable a
-> (forall s. Decoder s a) -> (Proxy a -> Text) -> FromCBOR a
label :: Proxy (SigningKey KesKey) -> Text
$clabel :: Proxy (SigningKey KesKey) -> Text
fromCBOR :: Decoder s (SigningKey KesKey)
$cfromCBOR :: forall s. Decoder s (SigningKey KesKey)
$cp1FromCBOR :: Typeable (SigningKey KesKey)
FromCBOR)
      deriving anyclass HasTypeProxy (SigningKey KesKey)
HasTypeProxy (SigningKey KesKey)
-> (SigningKey KesKey -> ByteString)
-> (AsType (SigningKey KesKey)
    -> ByteString -> Either DecoderError (SigningKey KesKey))
-> SerialiseAsCBOR (SigningKey KesKey)
AsType (SigningKey KesKey)
-> ByteString -> Either DecoderError (SigningKey KesKey)
SigningKey KesKey -> ByteString
forall a.
HasTypeProxy a
-> (a -> ByteString)
-> (AsType a -> ByteString -> Either DecoderError a)
-> SerialiseAsCBOR a
deserialiseFromCBOR :: AsType (SigningKey KesKey)
-> ByteString -> Either DecoderError (SigningKey KesKey)
$cdeserialiseFromCBOR :: AsType (SigningKey KesKey)
-> ByteString -> Either DecoderError (SigningKey KesKey)
serialiseToCBOR :: SigningKey KesKey -> ByteString
$cserialiseToCBOR :: SigningKey KesKey -> ByteString
$cp1SerialiseAsCBOR :: HasTypeProxy (SigningKey KesKey)
SerialiseAsCBOR

    --This loses the mlock safety of the seed, since it starts from a normal in-memory seed.
    deterministicSigningKey :: AsType KesKey -> Crypto.Seed -> SigningKey KesKey
    deterministicSigningKey :: AsType KesKey -> Seed -> SigningKey KesKey
deterministicSigningKey AsType KesKey
AsKesKey =
        SignKeyKES (Sum6KES Ed25519DSIGN Blake2b_256) -> SigningKey KesKey
SignKeyKES StandardCrypto -> SigningKey KesKey
KesSigningKey (SignKeyKES (Sum6KES Ed25519DSIGN Blake2b_256)
 -> SigningKey KesKey)
-> (Seed -> SignKeyKES (Sum6KES Ed25519DSIGN Blake2b_256))
-> Seed
-> SigningKey KesKey
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Seed -> SignKeyKES (Sum6KES Ed25519DSIGN Blake2b_256)
forall v. KESAlgorithm v => Seed -> SignKeyKES v
Crypto.genKeyKES

    deterministicSigningKeySeedSize :: AsType KesKey -> Word
    deterministicSigningKeySeedSize :: AsType KesKey -> Word
deterministicSigningKeySeedSize AsType KesKey
AsKesKey =
        Proxy (Sum6KES Ed25519DSIGN Blake2b_256) -> Word
forall v (proxy :: * -> *). KESAlgorithm v => proxy v -> Word
Crypto.seedSizeKES Proxy (Sum6KES Ed25519DSIGN Blake2b_256)
Proxy (KES StandardCrypto)
proxy
      where
        proxy :: Proxy (Shelley.KES StandardCrypto)
        proxy :: Proxy (KES StandardCrypto)
proxy = Proxy (KES StandardCrypto)
forall k (t :: k). Proxy t
Proxy

    getVerificationKey :: SigningKey KesKey -> VerificationKey KesKey
    getVerificationKey :: SigningKey KesKey -> VerificationKey KesKey
getVerificationKey (KesSigningKey sk) =
        VerKeyKES StandardCrypto -> VerificationKey KesKey
KesVerificationKey (SignKeyKES (Sum6KES Ed25519DSIGN Blake2b_256)
-> VerKeyKES (Sum6KES Ed25519DSIGN Blake2b_256)
forall v. KESAlgorithm v => SignKeyKES v -> VerKeyKES v
Crypto.deriveVerKeyKES SignKeyKES (Sum6KES Ed25519DSIGN Blake2b_256)
SignKeyKES StandardCrypto
sk)

    verificationKeyHash :: VerificationKey KesKey -> Hash KesKey
    verificationKeyHash :: VerificationKey KesKey -> Hash KesKey
verificationKeyHash (KesVerificationKey vkey) =
        Hash StandardCrypto (VerKeyKES StandardCrypto) -> Hash KesKey
KesKeyHash (VerKeyKES (Sum6KES Ed25519DSIGN Blake2b_256)
-> Hash Blake2b_256 (VerKeyKES (Sum6KES Ed25519DSIGN Blake2b_256))
forall v h.
(KESAlgorithm v, HashAlgorithm h) =>
VerKeyKES v -> Hash h (VerKeyKES v)
Crypto.hashVerKeyKES VerKeyKES (Sum6KES Ed25519DSIGN Blake2b_256)
VerKeyKES StandardCrypto
vkey)


instance SerialiseAsRawBytes (VerificationKey KesKey) where
    serialiseToRawBytes :: VerificationKey KesKey -> ByteString
serialiseToRawBytes (KesVerificationKey vk) =
      VerKeyKES (Sum6KES Ed25519DSIGN Blake2b_256) -> ByteString
forall v. KESAlgorithm v => VerKeyKES v -> ByteString
Crypto.rawSerialiseVerKeyKES VerKeyKES (Sum6KES Ed25519DSIGN Blake2b_256)
VerKeyKES StandardCrypto
vk

    deserialiseFromRawBytes :: AsType (VerificationKey KesKey)
-> ByteString -> Maybe (VerificationKey KesKey)
deserialiseFromRawBytes (AsVerificationKey AsKesKey) ByteString
bs =
      VerKeyKES (Sum6KES Ed25519DSIGN Blake2b_256)
-> VerificationKey KesKey
VerKeyKES StandardCrypto -> VerificationKey KesKey
KesVerificationKey (VerKeyKES (Sum6KES Ed25519DSIGN Blake2b_256)
 -> VerificationKey KesKey)
-> Maybe (VerKeyKES (Sum6KES Ed25519DSIGN Blake2b_256))
-> Maybe (VerificationKey KesKey)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
        ByteString -> Maybe (VerKeyKES (Sum6KES Ed25519DSIGN Blake2b_256))
forall v. KESAlgorithm v => ByteString -> Maybe (VerKeyKES v)
Crypto.rawDeserialiseVerKeyKES ByteString
bs

instance SerialiseAsRawBytes (SigningKey KesKey) where
    serialiseToRawBytes :: SigningKey KesKey -> ByteString
serialiseToRawBytes (KesSigningKey sk) =
      SignKeyKES (Sum6KES Ed25519DSIGN Blake2b_256) -> ByteString
forall v. KESAlgorithm v => SignKeyKES v -> ByteString
Crypto.rawSerialiseSignKeyKES SignKeyKES (Sum6KES Ed25519DSIGN Blake2b_256)
SignKeyKES StandardCrypto
sk

    deserialiseFromRawBytes :: AsType (SigningKey KesKey)
-> ByteString -> Maybe (SigningKey KesKey)
deserialiseFromRawBytes (AsSigningKey AsKesKey) ByteString
bs =
      SignKeyKES (Sum6KES Ed25519DSIGN Blake2b_256) -> SigningKey KesKey
SignKeyKES StandardCrypto -> SigningKey KesKey
KesSigningKey (SignKeyKES (Sum6KES Ed25519DSIGN Blake2b_256)
 -> SigningKey KesKey)
-> Maybe (SignKeyKES (Sum6KES Ed25519DSIGN Blake2b_256))
-> Maybe (SigningKey KesKey)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ByteString -> Maybe (SignKeyKES (Sum6KES Ed25519DSIGN Blake2b_256))
forall v. KESAlgorithm v => ByteString -> Maybe (SignKeyKES v)
Crypto.rawDeserialiseSignKeyKES ByteString
bs

instance SerialiseAsBech32 (VerificationKey KesKey) where
    bech32PrefixFor :: VerificationKey KesKey -> Text
bech32PrefixFor         VerificationKey KesKey
_ =  Text
"kes_vk"
    bech32PrefixesPermitted :: AsType (VerificationKey KesKey) -> [Text]
bech32PrefixesPermitted AsType (VerificationKey KesKey)
_ = [Text
"kes_vk"]

instance SerialiseAsBech32 (SigningKey KesKey) where
    bech32PrefixFor :: SigningKey KesKey -> Text
bech32PrefixFor         SigningKey KesKey
_ =  Text
"kes_sk"
    bech32PrefixesPermitted :: AsType (SigningKey KesKey) -> [Text]
bech32PrefixesPermitted AsType (SigningKey KesKey)
_ = [Text
"kes_sk"]


newtype instance Hash KesKey =
    KesKeyHash (Shelley.Hash StandardCrypto
                             (Shelley.VerKeyKES StandardCrypto))
  deriving stock (Hash KesKey -> Hash KesKey -> Bool
(Hash KesKey -> Hash KesKey -> Bool)
-> (Hash KesKey -> Hash KesKey -> Bool) -> Eq (Hash KesKey)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Hash KesKey -> Hash KesKey -> Bool
$c/= :: Hash KesKey -> Hash KesKey -> Bool
== :: Hash KesKey -> Hash KesKey -> Bool
$c== :: Hash KesKey -> Hash KesKey -> Bool
Eq, Eq (Hash KesKey)
Eq (Hash KesKey)
-> (Hash KesKey -> Hash KesKey -> Ordering)
-> (Hash KesKey -> Hash KesKey -> Bool)
-> (Hash KesKey -> Hash KesKey -> Bool)
-> (Hash KesKey -> Hash KesKey -> Bool)
-> (Hash KesKey -> Hash KesKey -> Bool)
-> (Hash KesKey -> Hash KesKey -> Hash KesKey)
-> (Hash KesKey -> Hash KesKey -> Hash KesKey)
-> Ord (Hash KesKey)
Hash KesKey -> Hash KesKey -> Bool
Hash KesKey -> Hash KesKey -> Ordering
Hash KesKey -> Hash KesKey -> Hash KesKey
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 :: Hash KesKey -> Hash KesKey -> Hash KesKey
$cmin :: Hash KesKey -> Hash KesKey -> Hash KesKey
max :: Hash KesKey -> Hash KesKey -> Hash KesKey
$cmax :: Hash KesKey -> Hash KesKey -> Hash KesKey
>= :: Hash KesKey -> Hash KesKey -> Bool
$c>= :: Hash KesKey -> Hash KesKey -> Bool
> :: Hash KesKey -> Hash KesKey -> Bool
$c> :: Hash KesKey -> Hash KesKey -> Bool
<= :: Hash KesKey -> Hash KesKey -> Bool
$c<= :: Hash KesKey -> Hash KesKey -> Bool
< :: Hash KesKey -> Hash KesKey -> Bool
$c< :: Hash KesKey -> Hash KesKey -> Bool
compare :: Hash KesKey -> Hash KesKey -> Ordering
$ccompare :: Hash KesKey -> Hash KesKey -> Ordering
$cp1Ord :: Eq (Hash KesKey)
Ord)
  deriving (Int -> Hash KesKey -> ShowS
[Hash KesKey] -> ShowS
Hash KesKey -> String
(Int -> Hash KesKey -> ShowS)
-> (Hash KesKey -> String)
-> ([Hash KesKey] -> ShowS)
-> Show (Hash KesKey)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Hash KesKey] -> ShowS
$cshowList :: [Hash KesKey] -> ShowS
show :: Hash KesKey -> String
$cshow :: Hash KesKey -> String
showsPrec :: Int -> Hash KesKey -> ShowS
$cshowsPrec :: Int -> Hash KesKey -> ShowS
Show, String -> Hash KesKey
(String -> Hash KesKey) -> IsString (Hash KesKey)
forall a. (String -> a) -> IsString a
fromString :: String -> Hash KesKey
$cfromString :: String -> Hash KesKey
IsString) via UsingRawBytesHex (Hash KesKey)
  deriving (Typeable (Hash KesKey)
Typeable (Hash KesKey)
-> (Hash KesKey -> Encoding)
-> ((forall t. ToCBOR t => Proxy t -> Size)
    -> Proxy (Hash KesKey) -> Size)
-> ((forall t. ToCBOR t => Proxy t -> Size)
    -> Proxy [Hash KesKey] -> Size)
-> ToCBOR (Hash KesKey)
Hash KesKey -> Encoding
(forall t. ToCBOR t => Proxy t -> Size)
-> Proxy [Hash KesKey] -> Size
(forall t. ToCBOR t => Proxy t -> Size)
-> Proxy (Hash KesKey) -> Size
forall a.
Typeable a
-> (a -> Encoding)
-> ((forall t. ToCBOR t => Proxy t -> Size) -> Proxy a -> Size)
-> ((forall t. ToCBOR t => Proxy t -> Size) -> Proxy [a] -> Size)
-> ToCBOR a
encodedListSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size)
-> Proxy [Hash KesKey] -> Size
$cencodedListSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size)
-> Proxy [Hash KesKey] -> Size
encodedSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size)
-> Proxy (Hash KesKey) -> Size
$cencodedSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size)
-> Proxy (Hash KesKey) -> Size
toCBOR :: Hash KesKey -> Encoding
$ctoCBOR :: Hash KesKey -> Encoding
$cp1ToCBOR :: Typeable (Hash KesKey)
ToCBOR, Typeable (Hash KesKey)
Decoder s (Hash KesKey)
Typeable (Hash KesKey)
-> (forall s. Decoder s (Hash KesKey))
-> (Proxy (Hash KesKey) -> Text)
-> FromCBOR (Hash KesKey)
Proxy (Hash KesKey) -> Text
forall s. Decoder s (Hash KesKey)
forall a.
Typeable a
-> (forall s. Decoder s a) -> (Proxy a -> Text) -> FromCBOR a
label :: Proxy (Hash KesKey) -> Text
$clabel :: Proxy (Hash KesKey) -> Text
fromCBOR :: Decoder s (Hash KesKey)
$cfromCBOR :: forall s. Decoder s (Hash KesKey)
$cp1FromCBOR :: Typeable (Hash KesKey)
FromCBOR) via UsingRawBytes (Hash KesKey)
  deriving anyclass HasTypeProxy (Hash KesKey)
HasTypeProxy (Hash KesKey)
-> (Hash KesKey -> ByteString)
-> (AsType (Hash KesKey)
    -> ByteString -> Either DecoderError (Hash KesKey))
-> SerialiseAsCBOR (Hash KesKey)
AsType (Hash KesKey)
-> ByteString -> Either DecoderError (Hash KesKey)
Hash KesKey -> ByteString
forall a.
HasTypeProxy a
-> (a -> ByteString)
-> (AsType a -> ByteString -> Either DecoderError a)
-> SerialiseAsCBOR a
deserialiseFromCBOR :: AsType (Hash KesKey)
-> ByteString -> Either DecoderError (Hash KesKey)
$cdeserialiseFromCBOR :: AsType (Hash KesKey)
-> ByteString -> Either DecoderError (Hash KesKey)
serialiseToCBOR :: Hash KesKey -> ByteString
$cserialiseToCBOR :: Hash KesKey -> ByteString
$cp1SerialiseAsCBOR :: HasTypeProxy (Hash KesKey)
SerialiseAsCBOR

instance SerialiseAsRawBytes (Hash KesKey) where
    serialiseToRawBytes :: Hash KesKey -> ByteString
serialiseToRawBytes (KesKeyHash vkh) =
      Hash Blake2b_256 (VerKeyKES (Sum6KES Ed25519DSIGN Blake2b_256))
-> ByteString
forall h a. Hash h a -> ByteString
Crypto.hashToBytes Hash Blake2b_256 (VerKeyKES (Sum6KES Ed25519DSIGN Blake2b_256))
Hash StandardCrypto (VerKeyKES StandardCrypto)
vkh

    deserialiseFromRawBytes :: AsType (Hash KesKey) -> ByteString -> Maybe (Hash KesKey)
deserialiseFromRawBytes (AsHash AsKesKey) ByteString
bs =
      Hash Blake2b_256 (VerKeyKES (Sum6KES Ed25519DSIGN Blake2b_256))
-> Hash KesKey
Hash StandardCrypto (VerKeyKES StandardCrypto) -> Hash KesKey
KesKeyHash (Hash Blake2b_256 (VerKeyKES (Sum6KES Ed25519DSIGN Blake2b_256))
 -> Hash KesKey)
-> Maybe
     (Hash Blake2b_256 (VerKeyKES (Sum6KES Ed25519DSIGN Blake2b_256)))
-> Maybe (Hash KesKey)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ByteString
-> Maybe
     (Hash Blake2b_256 (VerKeyKES (Sum6KES Ed25519DSIGN Blake2b_256)))
forall h a. HashAlgorithm h => ByteString -> Maybe (Hash h a)
Crypto.hashFromBytes ByteString
bs

instance HasTextEnvelope (VerificationKey KesKey) where
    textEnvelopeType :: AsType (VerificationKey KesKey) -> TextEnvelopeType
textEnvelopeType AsType (VerificationKey KesKey)
_ = TextEnvelopeType
"KesVerificationKey_"
                      TextEnvelopeType -> TextEnvelopeType -> TextEnvelopeType
forall a. Semigroup a => a -> a -> a
<> String -> TextEnvelopeType
forall a. IsString a => String -> a
fromString (Proxy (Sum6KES Ed25519DSIGN Blake2b_256) -> String
forall v (proxy :: * -> *). KESAlgorithm v => proxy v -> String
Crypto.algorithmNameKES Proxy (Sum6KES Ed25519DSIGN Blake2b_256)
Proxy (KES StandardCrypto)
proxy)
      where
        proxy :: Proxy (Shelley.KES StandardCrypto)
        proxy :: Proxy (KES StandardCrypto)
proxy = Proxy (KES StandardCrypto)
forall k (t :: k). Proxy t
Proxy

instance HasTextEnvelope (SigningKey KesKey) where
    textEnvelopeType :: AsType (SigningKey KesKey) -> TextEnvelopeType
textEnvelopeType AsType (SigningKey KesKey)
_ = TextEnvelopeType
"KesSigningKey_"
                      TextEnvelopeType -> TextEnvelopeType -> TextEnvelopeType
forall a. Semigroup a => a -> a -> a
<> String -> TextEnvelopeType
forall a. IsString a => String -> a
fromString (Proxy (Sum6KES Ed25519DSIGN Blake2b_256) -> String
forall v (proxy :: * -> *). KESAlgorithm v => proxy v -> String
Crypto.algorithmNameKES Proxy (Sum6KES Ed25519DSIGN Blake2b_256)
Proxy (KES StandardCrypto)
proxy)
      where
        proxy :: Proxy (Shelley.KES StandardCrypto)
        proxy :: Proxy (KES StandardCrypto)
proxy = Proxy (KES StandardCrypto)
forall k (t :: k). Proxy t
Proxy


--
-- VRF keys
--

data VrfKey

instance HasTypeProxy VrfKey where
    data AsType VrfKey = AsVrfKey
    proxyToAsType :: Proxy VrfKey -> AsType VrfKey
proxyToAsType Proxy VrfKey
_ = AsType VrfKey
AsVrfKey

instance Key VrfKey where

    newtype VerificationKey VrfKey =
        VrfVerificationKey (Shelley.VerKeyVRF StandardCrypto)
      deriving stock (VerificationKey VrfKey -> VerificationKey VrfKey -> Bool
(VerificationKey VrfKey -> VerificationKey VrfKey -> Bool)
-> (VerificationKey VrfKey -> VerificationKey VrfKey -> Bool)
-> Eq (VerificationKey VrfKey)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: VerificationKey VrfKey -> VerificationKey VrfKey -> Bool
$c/= :: VerificationKey VrfKey -> VerificationKey VrfKey -> Bool
== :: VerificationKey VrfKey -> VerificationKey VrfKey -> Bool
$c== :: VerificationKey VrfKey -> VerificationKey VrfKey -> Bool
Eq)
      deriving (Int -> VerificationKey VrfKey -> ShowS
[VerificationKey VrfKey] -> ShowS
VerificationKey VrfKey -> String
(Int -> VerificationKey VrfKey -> ShowS)
-> (VerificationKey VrfKey -> String)
-> ([VerificationKey VrfKey] -> ShowS)
-> Show (VerificationKey VrfKey)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [VerificationKey VrfKey] -> ShowS
$cshowList :: [VerificationKey VrfKey] -> ShowS
show :: VerificationKey VrfKey -> String
$cshow :: VerificationKey VrfKey -> String
showsPrec :: Int -> VerificationKey VrfKey -> ShowS
$cshowsPrec :: Int -> VerificationKey VrfKey -> ShowS
Show, String -> VerificationKey VrfKey
(String -> VerificationKey VrfKey)
-> IsString (VerificationKey VrfKey)
forall a. (String -> a) -> IsString a
fromString :: String -> VerificationKey VrfKey
$cfromString :: String -> VerificationKey VrfKey
IsString) via UsingRawBytesHex (VerificationKey VrfKey)
      deriving newtype (Typeable (VerificationKey VrfKey)
Typeable (VerificationKey VrfKey)
-> (VerificationKey VrfKey -> Encoding)
-> ((forall t. ToCBOR t => Proxy t -> Size)
    -> Proxy (VerificationKey VrfKey) -> Size)
-> ((forall t. ToCBOR t => Proxy t -> Size)
    -> Proxy [VerificationKey VrfKey] -> Size)
-> ToCBOR (VerificationKey VrfKey)
VerificationKey VrfKey -> Encoding
(forall t. ToCBOR t => Proxy t -> Size)
-> Proxy [VerificationKey VrfKey] -> Size
(forall t. ToCBOR t => Proxy t -> Size)
-> Proxy (VerificationKey VrfKey) -> Size
forall a.
Typeable a
-> (a -> Encoding)
-> ((forall t. ToCBOR t => Proxy t -> Size) -> Proxy a -> Size)
-> ((forall t. ToCBOR t => Proxy t -> Size) -> Proxy [a] -> Size)
-> ToCBOR a
encodedListSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size)
-> Proxy [VerificationKey VrfKey] -> Size
$cencodedListSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size)
-> Proxy [VerificationKey VrfKey] -> Size
encodedSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size)
-> Proxy (VerificationKey VrfKey) -> Size
$cencodedSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size)
-> Proxy (VerificationKey VrfKey) -> Size
toCBOR :: VerificationKey VrfKey -> Encoding
$ctoCBOR :: VerificationKey VrfKey -> Encoding
$cp1ToCBOR :: Typeable (VerificationKey VrfKey)
ToCBOR, Typeable (VerificationKey VrfKey)
Decoder s (VerificationKey VrfKey)
Typeable (VerificationKey VrfKey)
-> (forall s. Decoder s (VerificationKey VrfKey))
-> (Proxy (VerificationKey VrfKey) -> Text)
-> FromCBOR (VerificationKey VrfKey)
Proxy (VerificationKey VrfKey) -> Text
forall s. Decoder s (VerificationKey VrfKey)
forall a.
Typeable a
-> (forall s. Decoder s a) -> (Proxy a -> Text) -> FromCBOR a
label :: Proxy (VerificationKey VrfKey) -> Text
$clabel :: Proxy (VerificationKey VrfKey) -> Text
fromCBOR :: Decoder s (VerificationKey VrfKey)
$cfromCBOR :: forall s. Decoder s (VerificationKey VrfKey)
$cp1FromCBOR :: Typeable (VerificationKey VrfKey)
FromCBOR)
      deriving anyclass HasTypeProxy (VerificationKey VrfKey)
HasTypeProxy (VerificationKey VrfKey)
-> (VerificationKey VrfKey -> ByteString)
-> (AsType (VerificationKey VrfKey)
    -> ByteString -> Either DecoderError (VerificationKey VrfKey))
-> SerialiseAsCBOR (VerificationKey VrfKey)
AsType (VerificationKey VrfKey)
-> ByteString -> Either DecoderError (VerificationKey VrfKey)
VerificationKey VrfKey -> ByteString
forall a.
HasTypeProxy a
-> (a -> ByteString)
-> (AsType a -> ByteString -> Either DecoderError a)
-> SerialiseAsCBOR a
deserialiseFromCBOR :: AsType (VerificationKey VrfKey)
-> ByteString -> Either DecoderError (VerificationKey VrfKey)
$cdeserialiseFromCBOR :: AsType (VerificationKey VrfKey)
-> ByteString -> Either DecoderError (VerificationKey VrfKey)
serialiseToCBOR :: VerificationKey VrfKey -> ByteString
$cserialiseToCBOR :: VerificationKey VrfKey -> ByteString
$cp1SerialiseAsCBOR :: HasTypeProxy (VerificationKey VrfKey)
SerialiseAsCBOR

    newtype SigningKey VrfKey =
        VrfSigningKey (Shelley.SignKeyVRF StandardCrypto)
      deriving (Int -> SigningKey VrfKey -> ShowS
[SigningKey VrfKey] -> ShowS
SigningKey VrfKey -> String
(Int -> SigningKey VrfKey -> ShowS)
-> (SigningKey VrfKey -> String)
-> ([SigningKey VrfKey] -> ShowS)
-> Show (SigningKey VrfKey)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SigningKey VrfKey] -> ShowS
$cshowList :: [SigningKey VrfKey] -> ShowS
show :: SigningKey VrfKey -> String
$cshow :: SigningKey VrfKey -> String
showsPrec :: Int -> SigningKey VrfKey -> ShowS
$cshowsPrec :: Int -> SigningKey VrfKey -> ShowS
Show, String -> SigningKey VrfKey
(String -> SigningKey VrfKey) -> IsString (SigningKey VrfKey)
forall a. (String -> a) -> IsString a
fromString :: String -> SigningKey VrfKey
$cfromString :: String -> SigningKey VrfKey
IsString) via UsingRawBytesHex (SigningKey VrfKey)
      deriving newtype (Typeable (SigningKey VrfKey)
Typeable (SigningKey VrfKey)
-> (SigningKey VrfKey -> Encoding)
-> ((forall t. ToCBOR t => Proxy t -> Size)
    -> Proxy (SigningKey VrfKey) -> Size)
-> ((forall t. ToCBOR t => Proxy t -> Size)
    -> Proxy [SigningKey VrfKey] -> Size)
-> ToCBOR (SigningKey VrfKey)
SigningKey VrfKey -> Encoding
(forall t. ToCBOR t => Proxy t -> Size)
-> Proxy [SigningKey VrfKey] -> Size
(forall t. ToCBOR t => Proxy t -> Size)
-> Proxy (SigningKey VrfKey) -> Size
forall a.
Typeable a
-> (a -> Encoding)
-> ((forall t. ToCBOR t => Proxy t -> Size) -> Proxy a -> Size)
-> ((forall t. ToCBOR t => Proxy t -> Size) -> Proxy [a] -> Size)
-> ToCBOR a
encodedListSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size)
-> Proxy [SigningKey VrfKey] -> Size
$cencodedListSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size)
-> Proxy [SigningKey VrfKey] -> Size
encodedSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size)
-> Proxy (SigningKey VrfKey) -> Size
$cencodedSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size)
-> Proxy (SigningKey VrfKey) -> Size
toCBOR :: SigningKey VrfKey -> Encoding
$ctoCBOR :: SigningKey VrfKey -> Encoding
$cp1ToCBOR :: Typeable (SigningKey VrfKey)
ToCBOR, Typeable (SigningKey VrfKey)
Decoder s (SigningKey VrfKey)
Typeable (SigningKey VrfKey)
-> (forall s. Decoder s (SigningKey VrfKey))
-> (Proxy (SigningKey VrfKey) -> Text)
-> FromCBOR (SigningKey VrfKey)
Proxy (SigningKey VrfKey) -> Text
forall s. Decoder s (SigningKey VrfKey)
forall a.
Typeable a
-> (forall s. Decoder s a) -> (Proxy a -> Text) -> FromCBOR a
label :: Proxy (SigningKey VrfKey) -> Text
$clabel :: Proxy (SigningKey VrfKey) -> Text
fromCBOR :: Decoder s (SigningKey VrfKey)
$cfromCBOR :: forall s. Decoder s (SigningKey VrfKey)
$cp1FromCBOR :: Typeable (SigningKey VrfKey)
FromCBOR)
      deriving anyclass HasTypeProxy (SigningKey VrfKey)
HasTypeProxy (SigningKey VrfKey)
-> (SigningKey VrfKey -> ByteString)
-> (AsType (SigningKey VrfKey)
    -> ByteString -> Either DecoderError (SigningKey VrfKey))
-> SerialiseAsCBOR (SigningKey VrfKey)
AsType (SigningKey VrfKey)
-> ByteString -> Either DecoderError (SigningKey VrfKey)
SigningKey VrfKey -> ByteString
forall a.
HasTypeProxy a
-> (a -> ByteString)
-> (AsType a -> ByteString -> Either DecoderError a)
-> SerialiseAsCBOR a
deserialiseFromCBOR :: AsType (SigningKey VrfKey)
-> ByteString -> Either DecoderError (SigningKey VrfKey)
$cdeserialiseFromCBOR :: AsType (SigningKey VrfKey)
-> ByteString -> Either DecoderError (SigningKey VrfKey)
serialiseToCBOR :: SigningKey VrfKey -> ByteString
$cserialiseToCBOR :: SigningKey VrfKey -> ByteString
$cp1SerialiseAsCBOR :: HasTypeProxy (SigningKey VrfKey)
SerialiseAsCBOR

    deterministicSigningKey :: AsType VrfKey -> Crypto.Seed -> SigningKey VrfKey
    deterministicSigningKey :: AsType VrfKey -> Seed -> SigningKey VrfKey
deterministicSigningKey AsType VrfKey
AsVrfKey Seed
seed =
        SignKeyVRF StandardCrypto -> SigningKey VrfKey
VrfSigningKey (Seed -> SignKeyVRF PraosVRF
forall v. VRFAlgorithm v => Seed -> SignKeyVRF v
Crypto.genKeyVRF Seed
seed)

    deterministicSigningKeySeedSize :: AsType VrfKey -> Word
    deterministicSigningKeySeedSize :: AsType VrfKey -> Word
deterministicSigningKeySeedSize AsType VrfKey
AsVrfKey =
        Proxy PraosVRF -> Word
forall v (proxy :: * -> *). VRFAlgorithm v => proxy v -> Word
Crypto.seedSizeVRF Proxy PraosVRF
Proxy (VRF StandardCrypto)
proxy
      where
        proxy :: Proxy (Shelley.VRF StandardCrypto)
        proxy :: Proxy (VRF StandardCrypto)
proxy = Proxy (VRF StandardCrypto)
forall k (t :: k). Proxy t
Proxy

    getVerificationKey :: SigningKey VrfKey -> VerificationKey VrfKey
    getVerificationKey :: SigningKey VrfKey -> VerificationKey VrfKey
getVerificationKey (VrfSigningKey sk) =
        VerKeyVRF StandardCrypto -> VerificationKey VrfKey
VrfVerificationKey (SignKeyVRF PraosVRF -> VerKeyVRF PraosVRF
forall v. VRFAlgorithm v => SignKeyVRF v -> VerKeyVRF v
Crypto.deriveVerKeyVRF SignKeyVRF PraosVRF
SignKeyVRF StandardCrypto
sk)

    verificationKeyHash :: VerificationKey VrfKey -> Hash VrfKey
    verificationKeyHash :: VerificationKey VrfKey -> Hash VrfKey
verificationKeyHash (VrfVerificationKey vkey) =
        Hash StandardCrypto (VerKeyVRF StandardCrypto) -> Hash VrfKey
VrfKeyHash (VerKeyVRF PraosVRF -> Hash Blake2b_256 (VerKeyVRF PraosVRF)
forall v h.
(VRFAlgorithm v, HashAlgorithm h) =>
VerKeyVRF v -> Hash h (VerKeyVRF v)
Shelley.hashVerKeyVRF VerKeyVRF PraosVRF
VerKeyVRF StandardCrypto
vkey)

instance SerialiseAsRawBytes (VerificationKey VrfKey) where
    serialiseToRawBytes :: VerificationKey VrfKey -> ByteString
serialiseToRawBytes (VrfVerificationKey vk) =
      VerKeyVRF PraosVRF -> ByteString
forall v. VRFAlgorithm v => VerKeyVRF v -> ByteString
Crypto.rawSerialiseVerKeyVRF VerKeyVRF PraosVRF
VerKeyVRF StandardCrypto
vk

    deserialiseFromRawBytes :: AsType (VerificationKey VrfKey)
-> ByteString -> Maybe (VerificationKey VrfKey)
deserialiseFromRawBytes (AsVerificationKey AsVrfKey) ByteString
bs =
      VerKeyVRF PraosVRF -> VerificationKey VrfKey
VerKeyVRF StandardCrypto -> VerificationKey VrfKey
VrfVerificationKey (VerKeyVRF PraosVRF -> VerificationKey VrfKey)
-> Maybe (VerKeyVRF PraosVRF) -> Maybe (VerificationKey VrfKey)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ByteString -> Maybe (VerKeyVRF PraosVRF)
forall v. VRFAlgorithm v => ByteString -> Maybe (VerKeyVRF v)
Crypto.rawDeserialiseVerKeyVRF ByteString
bs

instance SerialiseAsRawBytes (SigningKey VrfKey) where
    serialiseToRawBytes :: SigningKey VrfKey -> ByteString
serialiseToRawBytes (VrfSigningKey sk) =
      SignKeyVRF PraosVRF -> ByteString
forall v. VRFAlgorithm v => SignKeyVRF v -> ByteString
Crypto.rawSerialiseSignKeyVRF SignKeyVRF PraosVRF
SignKeyVRF StandardCrypto
sk

    deserialiseFromRawBytes :: AsType (SigningKey VrfKey)
-> ByteString -> Maybe (SigningKey VrfKey)
deserialiseFromRawBytes (AsSigningKey AsVrfKey) ByteString
bs =
      SignKeyVRF PraosVRF -> SigningKey VrfKey
SignKeyVRF StandardCrypto -> SigningKey VrfKey
VrfSigningKey (SignKeyVRF PraosVRF -> SigningKey VrfKey)
-> Maybe (SignKeyVRF PraosVRF) -> Maybe (SigningKey VrfKey)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ByteString -> Maybe (SignKeyVRF PraosVRF)
forall v. VRFAlgorithm v => ByteString -> Maybe (SignKeyVRF v)
Crypto.rawDeserialiseSignKeyVRF ByteString
bs

instance SerialiseAsBech32 (VerificationKey VrfKey) where
    bech32PrefixFor :: VerificationKey VrfKey -> Text
bech32PrefixFor         VerificationKey VrfKey
_ =  Text
"vrf_vk"
    bech32PrefixesPermitted :: AsType (VerificationKey VrfKey) -> [Text]
bech32PrefixesPermitted AsType (VerificationKey VrfKey)
_ = [Text
"vrf_vk"]

instance SerialiseAsBech32 (SigningKey VrfKey) where
    bech32PrefixFor :: SigningKey VrfKey -> Text
bech32PrefixFor         SigningKey VrfKey
_ =  Text
"vrf_sk"
    bech32PrefixesPermitted :: AsType (SigningKey VrfKey) -> [Text]
bech32PrefixesPermitted AsType (SigningKey VrfKey)
_ = [Text
"vrf_sk"]

newtype instance Hash VrfKey =
    VrfKeyHash (Shelley.Hash StandardCrypto
                             (Shelley.VerKeyVRF StandardCrypto))
  deriving stock (Hash VrfKey -> Hash VrfKey -> Bool
(Hash VrfKey -> Hash VrfKey -> Bool)
-> (Hash VrfKey -> Hash VrfKey -> Bool) -> Eq (Hash VrfKey)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Hash VrfKey -> Hash VrfKey -> Bool
$c/= :: Hash VrfKey -> Hash VrfKey -> Bool
== :: Hash VrfKey -> Hash VrfKey -> Bool
$c== :: Hash VrfKey -> Hash VrfKey -> Bool
Eq, Eq (Hash VrfKey)
Eq (Hash VrfKey)
-> (Hash VrfKey -> Hash VrfKey -> Ordering)
-> (Hash VrfKey -> Hash VrfKey -> Bool)
-> (Hash VrfKey -> Hash VrfKey -> Bool)
-> (Hash VrfKey -> Hash VrfKey -> Bool)
-> (Hash VrfKey -> Hash VrfKey -> Bool)
-> (Hash VrfKey -> Hash VrfKey -> Hash VrfKey)
-> (Hash VrfKey -> Hash VrfKey -> Hash VrfKey)
-> Ord (Hash VrfKey)
Hash VrfKey -> Hash VrfKey -> Bool
Hash VrfKey -> Hash VrfKey -> Ordering
Hash VrfKey -> Hash VrfKey -> Hash VrfKey
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 :: Hash VrfKey -> Hash VrfKey -> Hash VrfKey
$cmin :: Hash VrfKey -> Hash VrfKey -> Hash VrfKey
max :: Hash VrfKey -> Hash VrfKey -> Hash VrfKey
$cmax :: Hash VrfKey -> Hash VrfKey -> Hash VrfKey
>= :: Hash VrfKey -> Hash VrfKey -> Bool
$c>= :: Hash VrfKey -> Hash VrfKey -> Bool
> :: Hash VrfKey -> Hash VrfKey -> Bool
$c> :: Hash VrfKey -> Hash VrfKey -> Bool
<= :: Hash VrfKey -> Hash VrfKey -> Bool
$c<= :: Hash VrfKey -> Hash VrfKey -> Bool
< :: Hash VrfKey -> Hash VrfKey -> Bool
$c< :: Hash VrfKey -> Hash VrfKey -> Bool
compare :: Hash VrfKey -> Hash VrfKey -> Ordering
$ccompare :: Hash VrfKey -> Hash VrfKey -> Ordering
$cp1Ord :: Eq (Hash VrfKey)
Ord)
  deriving (Int -> Hash VrfKey -> ShowS
[Hash VrfKey] -> ShowS
Hash VrfKey -> String
(Int -> Hash VrfKey -> ShowS)
-> (Hash VrfKey -> String)
-> ([Hash VrfKey] -> ShowS)
-> Show (Hash VrfKey)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Hash VrfKey] -> ShowS
$cshowList :: [Hash VrfKey] -> ShowS
show :: Hash VrfKey -> String
$cshow :: Hash VrfKey -> String
showsPrec :: Int -> Hash VrfKey -> ShowS
$cshowsPrec :: Int -> Hash VrfKey -> ShowS
Show, String -> Hash VrfKey
(String -> Hash VrfKey) -> IsString (Hash VrfKey)
forall a. (String -> a) -> IsString a
fromString :: String -> Hash VrfKey
$cfromString :: String -> Hash VrfKey
IsString) via UsingRawBytesHex (Hash VrfKey)
  deriving (Typeable (Hash VrfKey)
Typeable (Hash VrfKey)
-> (Hash VrfKey -> Encoding)
-> ((forall t. ToCBOR t => Proxy t -> Size)
    -> Proxy (Hash VrfKey) -> Size)
-> ((forall t. ToCBOR t => Proxy t -> Size)
    -> Proxy [Hash VrfKey] -> Size)
-> ToCBOR (Hash VrfKey)
Hash VrfKey -> Encoding
(forall t. ToCBOR t => Proxy t -> Size)
-> Proxy [Hash VrfKey] -> Size
(forall t. ToCBOR t => Proxy t -> Size)
-> Proxy (Hash VrfKey) -> Size
forall a.
Typeable a
-> (a -> Encoding)
-> ((forall t. ToCBOR t => Proxy t -> Size) -> Proxy a -> Size)
-> ((forall t. ToCBOR t => Proxy t -> Size) -> Proxy [a] -> Size)
-> ToCBOR a
encodedListSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size)
-> Proxy [Hash VrfKey] -> Size
$cencodedListSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size)
-> Proxy [Hash VrfKey] -> Size
encodedSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size)
-> Proxy (Hash VrfKey) -> Size
$cencodedSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size)
-> Proxy (Hash VrfKey) -> Size
toCBOR :: Hash VrfKey -> Encoding
$ctoCBOR :: Hash VrfKey -> Encoding
$cp1ToCBOR :: Typeable (Hash VrfKey)
ToCBOR, Typeable (Hash VrfKey)
Decoder s (Hash VrfKey)
Typeable (Hash VrfKey)
-> (forall s. Decoder s (Hash VrfKey))
-> (Proxy (Hash VrfKey) -> Text)
-> FromCBOR (Hash VrfKey)
Proxy (Hash VrfKey) -> Text
forall s. Decoder s (Hash VrfKey)
forall a.
Typeable a
-> (forall s. Decoder s a) -> (Proxy a -> Text) -> FromCBOR a
label :: Proxy (Hash VrfKey) -> Text
$clabel :: Proxy (Hash VrfKey) -> Text
fromCBOR :: Decoder s (Hash VrfKey)
$cfromCBOR :: forall s. Decoder s (Hash VrfKey)
$cp1FromCBOR :: Typeable (Hash VrfKey)
FromCBOR) via UsingRawBytes (Hash VrfKey)
  deriving anyclass HasTypeProxy (Hash VrfKey)
HasTypeProxy (Hash VrfKey)
-> (Hash VrfKey -> ByteString)
-> (AsType (Hash VrfKey)
    -> ByteString -> Either DecoderError (Hash VrfKey))
-> SerialiseAsCBOR (Hash VrfKey)
AsType (Hash VrfKey)
-> ByteString -> Either DecoderError (Hash VrfKey)
Hash VrfKey -> ByteString
forall a.
HasTypeProxy a
-> (a -> ByteString)
-> (AsType a -> ByteString -> Either DecoderError a)
-> SerialiseAsCBOR a
deserialiseFromCBOR :: AsType (Hash VrfKey)
-> ByteString -> Either DecoderError (Hash VrfKey)
$cdeserialiseFromCBOR :: AsType (Hash VrfKey)
-> ByteString -> Either DecoderError (Hash VrfKey)
serialiseToCBOR :: Hash VrfKey -> ByteString
$cserialiseToCBOR :: Hash VrfKey -> ByteString
$cp1SerialiseAsCBOR :: HasTypeProxy (Hash VrfKey)
SerialiseAsCBOR

instance SerialiseAsRawBytes (Hash VrfKey) where
    serialiseToRawBytes :: Hash VrfKey -> ByteString
serialiseToRawBytes (VrfKeyHash vkh) =
      Hash Blake2b_256 (VerKeyVRF PraosVRF) -> ByteString
forall h a. Hash h a -> ByteString
Crypto.hashToBytes Hash Blake2b_256 (VerKeyVRF PraosVRF)
Hash StandardCrypto (VerKeyVRF StandardCrypto)
vkh

    deserialiseFromRawBytes :: AsType (Hash VrfKey) -> ByteString -> Maybe (Hash VrfKey)
deserialiseFromRawBytes (AsHash AsVrfKey) ByteString
bs =
      Hash Blake2b_256 (VerKeyVRF PraosVRF) -> Hash VrfKey
Hash StandardCrypto (VerKeyVRF StandardCrypto) -> Hash VrfKey
VrfKeyHash (Hash Blake2b_256 (VerKeyVRF PraosVRF) -> Hash VrfKey)
-> Maybe (Hash Blake2b_256 (VerKeyVRF PraosVRF))
-> Maybe (Hash VrfKey)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ByteString -> Maybe (Hash Blake2b_256 (VerKeyVRF PraosVRF))
forall h a. HashAlgorithm h => ByteString -> Maybe (Hash h a)
Crypto.hashFromBytes ByteString
bs

instance HasTextEnvelope (VerificationKey VrfKey) where
    textEnvelopeType :: AsType (VerificationKey VrfKey) -> TextEnvelopeType
textEnvelopeType AsType (VerificationKey VrfKey)
_ = TextEnvelopeType
"VrfVerificationKey_" TextEnvelopeType -> TextEnvelopeType -> TextEnvelopeType
forall a. Semigroup a => a -> a -> a
<> String -> TextEnvelopeType
forall a. IsString a => String -> a
fromString (Proxy PraosVRF -> String
forall v (proxy :: * -> *). VRFAlgorithm v => proxy v -> String
Crypto.algorithmNameVRF Proxy PraosVRF
Proxy (VRF StandardCrypto)
proxy)
      where
        proxy :: Proxy (Shelley.VRF StandardCrypto)
        proxy :: Proxy (VRF StandardCrypto)
proxy = Proxy (VRF StandardCrypto)
forall k (t :: k). Proxy t
Proxy

instance HasTextEnvelope (SigningKey VrfKey) where
    textEnvelopeType :: AsType (SigningKey VrfKey) -> TextEnvelopeType
textEnvelopeType AsType (SigningKey VrfKey)
_ = TextEnvelopeType
"VrfSigningKey_" TextEnvelopeType -> TextEnvelopeType -> TextEnvelopeType
forall a. Semigroup a => a -> a -> a
<> String -> TextEnvelopeType
forall a. IsString a => String -> a
fromString (Proxy PraosVRF -> String
forall v (proxy :: * -> *). VRFAlgorithm v => proxy v -> String
Crypto.algorithmNameVRF Proxy PraosVRF
Proxy (VRF StandardCrypto)
proxy)
      where
        proxy :: Proxy (Shelley.VRF StandardCrypto)
        proxy :: Proxy (VRF StandardCrypto)
proxy = Proxy (VRF StandardCrypto)
forall k (t :: k). Proxy t
Proxy