{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}

-- | Mock implementation of digital signatures.
module Cardano.Crypto.DSIGN.Mock (
  MockDSIGN,
  SignKeyDSIGN (..),
  VerKeyDSIGN (..),
  SigDSIGN (..),
  mockSign,
)
where

import Control.DeepSeq (NFData)
import Data.Proxy (Proxy (..))
import Data.Word (Word64)
import GHC.Generics (Generic)
import GHC.Stack
import GHC.TypeLits (type (+))
import NoThunks.Class (NoThunks)

import Cardano.Binary (FromCBOR (..), ToCBOR (..))

import Cardano.Crypto.DSIGN.Class
import Cardano.Crypto.Hash
import Cardano.Crypto.Seed
import Cardano.Crypto.Util

data MockDSIGN

instance DSIGNAlgorithm MockDSIGN where
  type SeedSizeDSIGN MockDSIGN = 8
  type SizeVerKeyDSIGN MockDSIGN = 8 -- for 64 bit int
  type SizeSignKeyDSIGN MockDSIGN = 8
  type SizeSigDSIGN MockDSIGN = SizeHash ShortHash + 8

  --
  -- Key and signature types
  --

  newtype VerKeyDSIGN MockDSIGN = VerKeyMockDSIGN Word64
    deriving stock (Int -> VerKeyDSIGN MockDSIGN -> ShowS
[VerKeyDSIGN MockDSIGN] -> ShowS
VerKeyDSIGN MockDSIGN -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [VerKeyDSIGN MockDSIGN] -> ShowS
$cshowList :: [VerKeyDSIGN MockDSIGN] -> ShowS
show :: VerKeyDSIGN MockDSIGN -> String
$cshow :: VerKeyDSIGN MockDSIGN -> String
showsPrec :: Int -> VerKeyDSIGN MockDSIGN -> ShowS
$cshowsPrec :: Int -> VerKeyDSIGN MockDSIGN -> ShowS
Show, VerKeyDSIGN MockDSIGN -> VerKeyDSIGN MockDSIGN -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: VerKeyDSIGN MockDSIGN -> VerKeyDSIGN MockDSIGN -> Bool
$c/= :: VerKeyDSIGN MockDSIGN -> VerKeyDSIGN MockDSIGN -> Bool
== :: VerKeyDSIGN MockDSIGN -> VerKeyDSIGN MockDSIGN -> Bool
$c== :: VerKeyDSIGN MockDSIGN -> VerKeyDSIGN MockDSIGN -> Bool
Eq, forall x. Rep (VerKeyDSIGN MockDSIGN) x -> VerKeyDSIGN MockDSIGN
forall x. VerKeyDSIGN MockDSIGN -> Rep (VerKeyDSIGN MockDSIGN) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep (VerKeyDSIGN MockDSIGN) x -> VerKeyDSIGN MockDSIGN
$cfrom :: forall x. VerKeyDSIGN MockDSIGN -> Rep (VerKeyDSIGN MockDSIGN) x
Generic)
    deriving newtype (Integer -> VerKeyDSIGN MockDSIGN
VerKeyDSIGN MockDSIGN -> VerKeyDSIGN MockDSIGN
VerKeyDSIGN MockDSIGN
-> VerKeyDSIGN MockDSIGN -> VerKeyDSIGN MockDSIGN
forall a.
(a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (Integer -> a)
-> Num a
fromInteger :: Integer -> VerKeyDSIGN MockDSIGN
$cfromInteger :: Integer -> VerKeyDSIGN MockDSIGN
signum :: VerKeyDSIGN MockDSIGN -> VerKeyDSIGN MockDSIGN
$csignum :: VerKeyDSIGN MockDSIGN -> VerKeyDSIGN MockDSIGN
abs :: VerKeyDSIGN MockDSIGN -> VerKeyDSIGN MockDSIGN
$cabs :: VerKeyDSIGN MockDSIGN -> VerKeyDSIGN MockDSIGN
negate :: VerKeyDSIGN MockDSIGN -> VerKeyDSIGN MockDSIGN
$cnegate :: VerKeyDSIGN MockDSIGN -> VerKeyDSIGN MockDSIGN
* :: VerKeyDSIGN MockDSIGN
-> VerKeyDSIGN MockDSIGN -> VerKeyDSIGN MockDSIGN
$c* :: VerKeyDSIGN MockDSIGN
-> VerKeyDSIGN MockDSIGN -> VerKeyDSIGN MockDSIGN
- :: VerKeyDSIGN MockDSIGN
-> VerKeyDSIGN MockDSIGN -> VerKeyDSIGN MockDSIGN
$c- :: VerKeyDSIGN MockDSIGN
-> VerKeyDSIGN MockDSIGN -> VerKeyDSIGN MockDSIGN
+ :: VerKeyDSIGN MockDSIGN
-> VerKeyDSIGN MockDSIGN -> VerKeyDSIGN MockDSIGN
$c+ :: VerKeyDSIGN MockDSIGN
-> VerKeyDSIGN MockDSIGN -> VerKeyDSIGN MockDSIGN
Num, Context -> VerKeyDSIGN MockDSIGN -> IO (Maybe ThunkInfo)
Proxy (VerKeyDSIGN MockDSIGN) -> String
forall a.
(Context -> a -> IO (Maybe ThunkInfo))
-> (Context -> a -> IO (Maybe ThunkInfo))
-> (Proxy a -> String)
-> NoThunks a
showTypeOf :: Proxy (VerKeyDSIGN MockDSIGN) -> String
$cshowTypeOf :: Proxy (VerKeyDSIGN MockDSIGN) -> String
wNoThunks :: Context -> VerKeyDSIGN MockDSIGN -> IO (Maybe ThunkInfo)
$cwNoThunks :: Context -> VerKeyDSIGN MockDSIGN -> IO (Maybe ThunkInfo)
noThunks :: Context -> VerKeyDSIGN MockDSIGN -> IO (Maybe ThunkInfo)
$cnoThunks :: Context -> VerKeyDSIGN MockDSIGN -> IO (Maybe ThunkInfo)
NoThunks, VerKeyDSIGN MockDSIGN -> ()
forall a. (a -> ()) -> NFData a
rnf :: VerKeyDSIGN MockDSIGN -> ()
$crnf :: VerKeyDSIGN MockDSIGN -> ()
NFData)

  newtype SignKeyDSIGN MockDSIGN = SignKeyMockDSIGN Word64
    deriving stock (Int -> SignKeyDSIGN MockDSIGN -> ShowS
[SignKeyDSIGN MockDSIGN] -> ShowS
SignKeyDSIGN MockDSIGN -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SignKeyDSIGN MockDSIGN] -> ShowS
$cshowList :: [SignKeyDSIGN MockDSIGN] -> ShowS
show :: SignKeyDSIGN MockDSIGN -> String
$cshow :: SignKeyDSIGN MockDSIGN -> String
showsPrec :: Int -> SignKeyDSIGN MockDSIGN -> ShowS
$cshowsPrec :: Int -> SignKeyDSIGN MockDSIGN -> ShowS
Show, SignKeyDSIGN MockDSIGN -> SignKeyDSIGN MockDSIGN -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SignKeyDSIGN MockDSIGN -> SignKeyDSIGN MockDSIGN -> Bool
$c/= :: SignKeyDSIGN MockDSIGN -> SignKeyDSIGN MockDSIGN -> Bool
== :: SignKeyDSIGN MockDSIGN -> SignKeyDSIGN MockDSIGN -> Bool
$c== :: SignKeyDSIGN MockDSIGN -> SignKeyDSIGN MockDSIGN -> Bool
Eq, forall x. Rep (SignKeyDSIGN MockDSIGN) x -> SignKeyDSIGN MockDSIGN
forall x. SignKeyDSIGN MockDSIGN -> Rep (SignKeyDSIGN MockDSIGN) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep (SignKeyDSIGN MockDSIGN) x -> SignKeyDSIGN MockDSIGN
$cfrom :: forall x. SignKeyDSIGN MockDSIGN -> Rep (SignKeyDSIGN MockDSIGN) x
Generic)
    deriving newtype (Integer -> SignKeyDSIGN MockDSIGN
SignKeyDSIGN MockDSIGN -> SignKeyDSIGN MockDSIGN
SignKeyDSIGN MockDSIGN
-> SignKeyDSIGN MockDSIGN -> SignKeyDSIGN MockDSIGN
forall a.
(a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (Integer -> a)
-> Num a
fromInteger :: Integer -> SignKeyDSIGN MockDSIGN
$cfromInteger :: Integer -> SignKeyDSIGN MockDSIGN
signum :: SignKeyDSIGN MockDSIGN -> SignKeyDSIGN MockDSIGN
$csignum :: SignKeyDSIGN MockDSIGN -> SignKeyDSIGN MockDSIGN
abs :: SignKeyDSIGN MockDSIGN -> SignKeyDSIGN MockDSIGN
$cabs :: SignKeyDSIGN MockDSIGN -> SignKeyDSIGN MockDSIGN
negate :: SignKeyDSIGN MockDSIGN -> SignKeyDSIGN MockDSIGN
$cnegate :: SignKeyDSIGN MockDSIGN -> SignKeyDSIGN MockDSIGN
* :: SignKeyDSIGN MockDSIGN
-> SignKeyDSIGN MockDSIGN -> SignKeyDSIGN MockDSIGN
$c* :: SignKeyDSIGN MockDSIGN
-> SignKeyDSIGN MockDSIGN -> SignKeyDSIGN MockDSIGN
- :: SignKeyDSIGN MockDSIGN
-> SignKeyDSIGN MockDSIGN -> SignKeyDSIGN MockDSIGN
$c- :: SignKeyDSIGN MockDSIGN
-> SignKeyDSIGN MockDSIGN -> SignKeyDSIGN MockDSIGN
+ :: SignKeyDSIGN MockDSIGN
-> SignKeyDSIGN MockDSIGN -> SignKeyDSIGN MockDSIGN
$c+ :: SignKeyDSIGN MockDSIGN
-> SignKeyDSIGN MockDSIGN -> SignKeyDSIGN MockDSIGN
Num, Context -> SignKeyDSIGN MockDSIGN -> IO (Maybe ThunkInfo)
Proxy (SignKeyDSIGN MockDSIGN) -> String
forall a.
(Context -> a -> IO (Maybe ThunkInfo))
-> (Context -> a -> IO (Maybe ThunkInfo))
-> (Proxy a -> String)
-> NoThunks a
showTypeOf :: Proxy (SignKeyDSIGN MockDSIGN) -> String
$cshowTypeOf :: Proxy (SignKeyDSIGN MockDSIGN) -> String
wNoThunks :: Context -> SignKeyDSIGN MockDSIGN -> IO (Maybe ThunkInfo)
$cwNoThunks :: Context -> SignKeyDSIGN MockDSIGN -> IO (Maybe ThunkInfo)
noThunks :: Context -> SignKeyDSIGN MockDSIGN -> IO (Maybe ThunkInfo)
$cnoThunks :: Context -> SignKeyDSIGN MockDSIGN -> IO (Maybe ThunkInfo)
NoThunks, SignKeyDSIGN MockDSIGN -> ()
forall a. (a -> ()) -> NFData a
rnf :: SignKeyDSIGN MockDSIGN -> ()
$crnf :: SignKeyDSIGN MockDSIGN -> ()
NFData)

  data SigDSIGN MockDSIGN = SigMockDSIGN !(Hash ShortHash ()) !Word64
    deriving stock (Int -> SigDSIGN MockDSIGN -> ShowS
[SigDSIGN MockDSIGN] -> ShowS
SigDSIGN MockDSIGN -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SigDSIGN MockDSIGN] -> ShowS
$cshowList :: [SigDSIGN MockDSIGN] -> ShowS
show :: SigDSIGN MockDSIGN -> String
$cshow :: SigDSIGN MockDSIGN -> String
showsPrec :: Int -> SigDSIGN MockDSIGN -> ShowS
$cshowsPrec :: Int -> SigDSIGN MockDSIGN -> ShowS
Show, SigDSIGN MockDSIGN -> SigDSIGN MockDSIGN -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SigDSIGN MockDSIGN -> SigDSIGN MockDSIGN -> Bool
$c/= :: SigDSIGN MockDSIGN -> SigDSIGN MockDSIGN -> Bool
== :: SigDSIGN MockDSIGN -> SigDSIGN MockDSIGN -> Bool
$c== :: SigDSIGN MockDSIGN -> SigDSIGN MockDSIGN -> Bool
Eq, Eq (SigDSIGN MockDSIGN)
SigDSIGN MockDSIGN -> SigDSIGN MockDSIGN -> Bool
SigDSIGN MockDSIGN -> SigDSIGN MockDSIGN -> Ordering
SigDSIGN MockDSIGN -> SigDSIGN MockDSIGN -> SigDSIGN MockDSIGN
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 :: SigDSIGN MockDSIGN -> SigDSIGN MockDSIGN -> SigDSIGN MockDSIGN
$cmin :: SigDSIGN MockDSIGN -> SigDSIGN MockDSIGN -> SigDSIGN MockDSIGN
max :: SigDSIGN MockDSIGN -> SigDSIGN MockDSIGN -> SigDSIGN MockDSIGN
$cmax :: SigDSIGN MockDSIGN -> SigDSIGN MockDSIGN -> SigDSIGN MockDSIGN
>= :: SigDSIGN MockDSIGN -> SigDSIGN MockDSIGN -> Bool
$c>= :: SigDSIGN MockDSIGN -> SigDSIGN MockDSIGN -> Bool
> :: SigDSIGN MockDSIGN -> SigDSIGN MockDSIGN -> Bool
$c> :: SigDSIGN MockDSIGN -> SigDSIGN MockDSIGN -> Bool
<= :: SigDSIGN MockDSIGN -> SigDSIGN MockDSIGN -> Bool
$c<= :: SigDSIGN MockDSIGN -> SigDSIGN MockDSIGN -> Bool
< :: SigDSIGN MockDSIGN -> SigDSIGN MockDSIGN -> Bool
$c< :: SigDSIGN MockDSIGN -> SigDSIGN MockDSIGN -> Bool
compare :: SigDSIGN MockDSIGN -> SigDSIGN MockDSIGN -> Ordering
$ccompare :: SigDSIGN MockDSIGN -> SigDSIGN MockDSIGN -> Ordering
Ord, forall x. Rep (SigDSIGN MockDSIGN) x -> SigDSIGN MockDSIGN
forall x. SigDSIGN MockDSIGN -> Rep (SigDSIGN MockDSIGN) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep (SigDSIGN MockDSIGN) x -> SigDSIGN MockDSIGN
$cfrom :: forall x. SigDSIGN MockDSIGN -> Rep (SigDSIGN MockDSIGN) x
Generic)
    deriving anyclass (Context -> SigDSIGN MockDSIGN -> IO (Maybe ThunkInfo)
Proxy (SigDSIGN MockDSIGN) -> String
forall a.
(Context -> a -> IO (Maybe ThunkInfo))
-> (Context -> a -> IO (Maybe ThunkInfo))
-> (Proxy a -> String)
-> NoThunks a
showTypeOf :: Proxy (SigDSIGN MockDSIGN) -> String
$cshowTypeOf :: Proxy (SigDSIGN MockDSIGN) -> String
wNoThunks :: Context -> SigDSIGN MockDSIGN -> IO (Maybe ThunkInfo)
$cwNoThunks :: Context -> SigDSIGN MockDSIGN -> IO (Maybe ThunkInfo)
noThunks :: Context -> SigDSIGN MockDSIGN -> IO (Maybe ThunkInfo)
$cnoThunks :: Context -> SigDSIGN MockDSIGN -> IO (Maybe ThunkInfo)
NoThunks, SigDSIGN MockDSIGN -> ()
forall a. (a -> ()) -> NFData a
rnf :: SigDSIGN MockDSIGN -> ()
$crnf :: SigDSIGN MockDSIGN -> ()
NFData)

  --
  -- Metadata and basic key operations
  --

  algorithmNameDSIGN :: forall (proxy :: * -> *). proxy MockDSIGN -> String
algorithmNameDSIGN proxy MockDSIGN
_ = String
"mock"

  deriveVerKeyDSIGN :: SignKeyDSIGN MockDSIGN -> VerKeyDSIGN MockDSIGN
deriveVerKeyDSIGN (SignKeyMockDSIGN Word64
n) = Word64 -> VerKeyDSIGN MockDSIGN
VerKeyMockDSIGN Word64
n

  --
  -- Core algorithm operations
  --

  type Signable MockDSIGN = SignableRepresentation

  signDSIGN :: forall a.
(Signable MockDSIGN a, HasCallStack) =>
ContextDSIGN MockDSIGN
-> a -> SignKeyDSIGN MockDSIGN -> SigDSIGN MockDSIGN
signDSIGN () a
a SignKeyDSIGN MockDSIGN
sk = forall a.
SignableRepresentation a =>
a -> SignKeyDSIGN MockDSIGN -> SigDSIGN MockDSIGN
mockSign a
a SignKeyDSIGN MockDSIGN
sk

  verifyDSIGN :: forall a.
(Signable MockDSIGN a, HasCallStack) =>
ContextDSIGN MockDSIGN
-> VerKeyDSIGN MockDSIGN
-> a
-> SigDSIGN MockDSIGN
-> Either String ()
verifyDSIGN () (VerKeyMockDSIGN Word64
n) a
a SigDSIGN MockDSIGN
s =
    if SigDSIGN MockDSIGN
s forall a. Eq a => a -> a -> Bool
== forall a.
SignableRepresentation a =>
a -> SignKeyDSIGN MockDSIGN -> SigDSIGN MockDSIGN
mockSign a
a (Word64 -> SignKeyDSIGN MockDSIGN
SignKeyMockDSIGN Word64
n)
      then forall a b. b -> Either a b
Right ()
      else
        forall a b. a -> Either a b
Left forall a b. (a -> b) -> a -> b
$
          forall a. Show a => a -> String
show forall a b. (a -> b) -> a -> b
$
            MockVerificationFailure
              { vErrVerKey :: VerKeyDSIGN MockDSIGN
vErrVerKey = Word64 -> VerKeyDSIGN MockDSIGN
VerKeyMockDSIGN Word64
n
              , vErrSignature :: SigDSIGN MockDSIGN
vErrSignature = SigDSIGN MockDSIGN
s
              , vErrCallStack :: String
vErrCallStack = CallStack -> String
prettyCallStack HasCallStack => CallStack
callStack
              }

  --
  -- Key generation
  --

  genKeyDSIGN :: Seed -> SignKeyDSIGN MockDSIGN
genKeyDSIGN Seed
seed =
    Word64 -> SignKeyDSIGN MockDSIGN
SignKeyMockDSIGN (forall a. Seed -> (forall (m :: * -> *). MonadRandom m => m a) -> a
runMonadRandomWithSeed Seed
seed forall (m :: * -> *). MonadRandom m => m Word64
getRandomWord64)

  --
  -- raw serialise/deserialise
  --

  rawSerialiseVerKeyDSIGN :: VerKeyDSIGN MockDSIGN -> ByteString
rawSerialiseVerKeyDSIGN (VerKeyMockDSIGN Word64
k) = Word64 -> ByteString
writeBinaryWord64 Word64
k
  rawSerialiseSignKeyDSIGN :: SignKeyDSIGN MockDSIGN -> ByteString
rawSerialiseSignKeyDSIGN (SignKeyMockDSIGN Word64
k) = Word64 -> ByteString
writeBinaryWord64 Word64
k
  rawSerialiseSigDSIGN :: SigDSIGN MockDSIGN -> ByteString
rawSerialiseSigDSIGN (SigMockDSIGN Hash ShortHash ()
h Word64
k) =
    forall h a. Hash h a -> ByteString
hashToBytes Hash ShortHash ()
h
      forall a. Semigroup a => a -> a -> a
<> Word64 -> ByteString
writeBinaryWord64 Word64
k

  rawDeserialiseVerKeyDSIGN :: ByteString -> Maybe (VerKeyDSIGN MockDSIGN)
rawDeserialiseVerKeyDSIGN ByteString
bs
    | [ByteString
kb] <- [Int] -> ByteString -> [ByteString]
splitsAt [Int
8] ByteString
bs
    , let k :: Word64
k = ByteString -> Word64
readBinaryWord64 ByteString
kb =
        forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$! Word64 -> VerKeyDSIGN MockDSIGN
VerKeyMockDSIGN Word64
k
    | Bool
otherwise =
        forall a. Maybe a
Nothing

  rawDeserialiseSignKeyDSIGN :: ByteString -> Maybe (SignKeyDSIGN MockDSIGN)
rawDeserialiseSignKeyDSIGN ByteString
bs
    | [ByteString
kb] <- [Int] -> ByteString -> [ByteString]
splitsAt [Int
8] ByteString
bs
    , let k :: Word64
k = ByteString -> Word64
readBinaryWord64 ByteString
kb =
        forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$! Word64 -> SignKeyDSIGN MockDSIGN
SignKeyMockDSIGN Word64
k
    | Bool
otherwise =
        forall a. Maybe a
Nothing

  rawDeserialiseSigDSIGN :: ByteString -> Maybe (SigDSIGN MockDSIGN)
rawDeserialiseSigDSIGN ByteString
bs
    | [ByteString
hb, ByteString
kb] <- [Int] -> ByteString -> [ByteString]
splitsAt [forall a b. (Integral a, Num b) => a -> b
fromIntegral forall a b. (a -> b) -> a -> b
$ forall h (proxy :: * -> *). HashAlgorithm h => proxy h -> Word
sizeHash (forall {k} (t :: k). Proxy t
Proxy :: Proxy ShortHash), Int
8] ByteString
bs
    , Just Hash ShortHash ()
h <- forall h a. HashAlgorithm h => ByteString -> Maybe (Hash h a)
hashFromBytes ByteString
hb
    , let k :: Word64
k = ByteString -> Word64
readBinaryWord64 ByteString
kb =
        forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$! Hash ShortHash () -> Word64 -> SigDSIGN MockDSIGN
SigMockDSIGN Hash ShortHash ()
h Word64
k
    | Bool
otherwise =
        forall a. Maybe a
Nothing

instance ToCBOR (VerKeyDSIGN MockDSIGN) where
  toCBOR :: VerKeyDSIGN MockDSIGN -> Encoding
toCBOR = forall v. DSIGNAlgorithm v => VerKeyDSIGN v -> Encoding
encodeVerKeyDSIGN
  encodedSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size)
-> Proxy (VerKeyDSIGN MockDSIGN) -> Size
encodedSizeExpr forall t. ToCBOR t => Proxy t -> Size
_ = forall v. DSIGNAlgorithm v => Proxy (VerKeyDSIGN v) -> Size
encodedVerKeyDSIGNSizeExpr

instance FromCBOR (VerKeyDSIGN MockDSIGN) where
  fromCBOR :: forall s. Decoder s (VerKeyDSIGN MockDSIGN)
fromCBOR = forall v s. DSIGNAlgorithm v => Decoder s (VerKeyDSIGN v)
decodeVerKeyDSIGN

instance ToCBOR (SignKeyDSIGN MockDSIGN) where
  toCBOR :: SignKeyDSIGN MockDSIGN -> Encoding
toCBOR = forall v. DSIGNAlgorithm v => SignKeyDSIGN v -> Encoding
encodeSignKeyDSIGN
  encodedSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size)
-> Proxy (SignKeyDSIGN MockDSIGN) -> Size
encodedSizeExpr forall t. ToCBOR t => Proxy t -> Size
_ = forall v. DSIGNAlgorithm v => Proxy (SignKeyDSIGN v) -> Size
encodedSignKeyDSIGNSizeExpr

instance FromCBOR (SignKeyDSIGN MockDSIGN) where
  fromCBOR :: forall s. Decoder s (SignKeyDSIGN MockDSIGN)
fromCBOR = forall v s. DSIGNAlgorithm v => Decoder s (SignKeyDSIGN v)
decodeSignKeyDSIGN

instance ToCBOR (SigDSIGN MockDSIGN) where
  toCBOR :: SigDSIGN MockDSIGN -> Encoding
toCBOR = forall v. DSIGNAlgorithm v => SigDSIGN v -> Encoding
encodeSigDSIGN
  encodedSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size)
-> Proxy (SigDSIGN MockDSIGN) -> Size
encodedSizeExpr forall t. ToCBOR t => Proxy t -> Size
_ = forall v. DSIGNAlgorithm v => Proxy (SigDSIGN v) -> Size
encodedSigDSIGNSizeExpr

instance FromCBOR (SigDSIGN MockDSIGN) where
  fromCBOR :: forall s. Decoder s (SigDSIGN MockDSIGN)
fromCBOR = forall v s. DSIGNAlgorithm v => Decoder s (SigDSIGN v)
decodeSigDSIGN

-- | Debugging: provide information about the verification failure
--
-- We don't include the actual value here as that would require propagating a
-- 'Show' constraint.
data VerificationFailure
  = MockVerificationFailure
  { VerificationFailure -> VerKeyDSIGN MockDSIGN
vErrVerKey :: VerKeyDSIGN MockDSIGN
  , VerificationFailure -> SigDSIGN MockDSIGN
vErrSignature :: SigDSIGN MockDSIGN
  , VerificationFailure -> String
vErrCallStack :: String
  }
  deriving (Int -> VerificationFailure -> ShowS
[VerificationFailure] -> ShowS
VerificationFailure -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [VerificationFailure] -> ShowS
$cshowList :: [VerificationFailure] -> ShowS
show :: VerificationFailure -> String
$cshow :: VerificationFailure -> String
showsPrec :: Int -> VerificationFailure -> ShowS
$cshowsPrec :: Int -> VerificationFailure -> ShowS
Show)

mockSign ::
  SignableRepresentation a =>
  a -> SignKeyDSIGN MockDSIGN -> SigDSIGN MockDSIGN
mockSign :: forall a.
SignableRepresentation a =>
a -> SignKeyDSIGN MockDSIGN -> SigDSIGN MockDSIGN
mockSign a
a (SignKeyMockDSIGN Word64
n) =
  Hash ShortHash () -> Word64 -> SigDSIGN MockDSIGN
SigMockDSIGN (forall h a b. Hash h a -> Hash h b
castHash (forall h a. HashAlgorithm h => (a -> ByteString) -> a -> Hash h a
hashWith forall a. SignableRepresentation a => a -> ByteString
getSignableRepresentation a
a)) Word64
n