{-# LANGUAGE CPP #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE NumericUnderscores #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
{- FOURMOLU_DISABLE -}
module Test.Crypto.DSIGN
  ( tests
  )
where

{- HLINT ignore "Use <$>" -}
{- HLINT ignore "Reduce duplication" -}

import Test.QuickCheck (
  (=/=),
  (===),
  (==>),
  Arbitrary(..),
  Gen,
  Property,
  Testable,
  forAllShow,
  ioProperty,
  counterexample,
  withMaxSuccess,
  )
import Test.Hspec (Spec, describe)
import Test.Hspec.QuickCheck (prop, modifyMaxSuccess)

import qualified Data.ByteString as BS
import Cardano.Crypto.Libsodium

import Text.Show.Pretty (ppShow)

#ifdef SECP256K1_ENABLED
import qualified GHC.Exts as GHC
#endif

import qualified Test.QuickCheck.Gen as Gen
import Data.Kind (Type)
import Data.Proxy (Proxy (..))
import Data.Maybe (fromJust)

import Control.Exception (evaluate, bracket)
import Control.Monad (replicateM, when)

import Cardano.Crypto.DSIGN (
  MockDSIGN,
  Ed25519DSIGN,
  Ed448DSIGN,
  aggregateVerKeysDSIGN,
  verKeySizeDSIGN,
  signKeySizeDSIGN,
  sigSizeDSIGN,
  encodeVerKeyDSIGN,
  decodeVerKeyDSIGN,
  encodeSignKeyDSIGN,
  decodeSignKeyDSIGN,
  encodeSigDSIGN,
  decodeSigDSIGN,
  seedSizeDSIGN,

  DSIGNMAlgorithm (..),
  UnsoundDSIGNMAlgorithm,
  rawSerialiseSignKeyDSIGNM,
  rawDeserialiseSignKeyDSIGNM,
  signDSIGNM,
  genKeyDSIGNM,

  getSeedDSIGNM,
  forgetSignKeyDSIGNM,
  BLS12381DSIGN,

  DSIGNAggregatable (..),
  BLS12381SignContext (..),
  possessionProofSizeDSIGN,
  encodePossessionProofDSIGN,
  decodePossessionProofDSIGN
  )
import Cardano.Binary (FromCBOR, ToCBOR)
import Cardano.Crypto.EllipticCurve.BLS12_381 (Curve1, Curve2)
import Cardano.Crypto.PinnedSizedBytes (PinnedSizedBytes)
import Cardano.Crypto.DirectSerialise
import Test.Crypto.Util (
  BadInputFor,
  genBadInputFor,
  shrinkBadInputFor,
  Message,
  prop_keygen_context_changes_verkey,
  prop_raw_serialise,
  prop_raw_deserialise,
  prop_size_serialise,
  prop_bad_cbor_bytes,
  prop_cbor_with,
  prop_cbor,
  prop_cbor_size,
  prop_cbor_direct_vs_class,
  prop_no_thunks,
  prop_no_thunks_IO,
  arbitrarySeedOfSize,
  Lock,
  withLock,
  directSerialiseToBS,
  directDeserialiseFromBS,
  hexBS,
  )
import Cardano.Crypto.Libsodium.MLockedSeed

import Test.Crypto.Instances (withMLockedSeedFromPSB)
import Test.Crypto.EqST (EqST (..), (==!))

#ifdef SECP256K1_ENABLED
import Cardano.Crypto.DSIGN (
  EcdsaSecp256k1DSIGN,
  SchnorrSecp256k1DSIGN,
  MessageHash,
  toMessageHash,
  hashAndPack,
  )
import Test.Crypto.Util (
  Message (messageBytes),
  )
import Cardano.Crypto.SECP256K1.Constants (SECP256K1_ECDSA_MESSAGE_BYTES)
import GHC.TypeLits (natVal)
import Cardano.Crypto.Hash (SHA3_256, HashAlgorithm (HashSize), Blake2b_256, SHA256, Keccak256)
import Cardano.Crypto.DSIGN.Class (DSIGNAlgorithm(..))
import Cardano.Crypto.DSIGN.BLS12381 (BLS12381MinSigDSIGN)
import Cardano.Crypto.DSIGN.BLS12381 (BLS12381MinVerKeyDSIGN)
#endif

blsGenKeyWithContextGen :: Gen (Maybe BS.ByteString)
blsGenKeyWithContextGen :: Gen (Maybe ByteString)
blsGenKeyWithContextGen =
  [(Int, Gen (Maybe ByteString))] -> Gen (Maybe ByteString)
forall a. HasCallStack => [(Int, Gen a)] -> Gen a
Gen.frequency
    [ (Int
1, Maybe ByteString -> Gen (Maybe ByteString)
forall a. a -> Gen a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe ByteString
forall a. Maybe a
Nothing)
    , (Int
100, ByteString -> Maybe ByteString
forall a. a -> Maybe a
Just (ByteString -> Maybe ByteString)
-> Gen ByteString -> Gen (Maybe ByteString)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen ByteString
genNonEmptyBS)
    ]
  where
    -- note that the context Nothing and Just "" are considered the same.
    genNonEmptyBS :: Gen ByteString
genNonEmptyBS = Gen ByteString -> (ByteString -> Bool) -> Gen ByteString
forall a. Gen a -> (a -> Bool) -> Gen a
Gen.suchThat ([Word8] -> ByteString
BS.pack ([Word8] -> ByteString) -> Gen [Word8] -> Gen ByteString
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen [Word8]
forall a. Arbitrary a => Gen a
arbitrary) (Bool -> Bool
not (Bool -> Bool) -> (ByteString -> Bool) -> ByteString -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Bool
BS.null)


blsSignContextGen :: Gen BLS12381SignContext
blsSignContextGen :: Gen BLS12381SignContext
blsSignContextGen = do
  Maybe ByteString
dst <- [(Int, Gen (Maybe ByteString))] -> Gen (Maybe ByteString)
forall a. HasCallStack => [(Int, Gen a)] -> Gen a
Gen.frequency [(Int
1, Maybe ByteString -> Gen (Maybe ByteString)
forall a. a -> Gen a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe ByteString
forall a. Maybe a
Nothing), (Int
100, ByteString -> Maybe ByteString
forall a. a -> Maybe a
Just (ByteString -> Maybe ByteString)
-> ([Word8] -> ByteString) -> [Word8] -> Maybe ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Word8] -> ByteString
BS.pack ([Word8] -> Maybe ByteString)
-> Gen [Word8] -> Gen (Maybe ByteString)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen [Word8]
forall a. Arbitrary a => Gen a
arbitrary)]
  Maybe ByteString
aug <- [(Int, Gen (Maybe ByteString))] -> Gen (Maybe ByteString)
forall a. HasCallStack => [(Int, Gen a)] -> Gen a
Gen.frequency [(Int
1, Maybe ByteString -> Gen (Maybe ByteString)
forall a. a -> Gen a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe ByteString
forall a. Maybe a
Nothing), (Int
100, ByteString -> Maybe ByteString
forall a. a -> Maybe a
Just (ByteString -> Maybe ByteString)
-> ([Word8] -> ByteString) -> [Word8] -> Maybe ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Word8] -> ByteString
BS.pack ([Word8] -> Maybe ByteString)
-> Gen [Word8] -> Gen (Maybe ByteString)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen [Word8]
forall a. Arbitrary a => Gen a
arbitrary)]
  BLS12381SignContext -> Gen BLS12381SignContext
forall a. a -> Gen a
forall (f :: * -> *) a. Applicative f => a -> f a
pure BLS12381SignContext {blsSignContextAug :: Maybe ByteString
blsSignContextAug = Maybe ByteString
aug, blsSignContextDst :: Maybe ByteString
blsSignContextDst = Maybe ByteString
dst}


#ifdef SECP256K1_ENABLED
genEcdsaMsg :: Gen MessageHash
genEcdsaMsg :: Gen MessageHash
genEcdsaMsg =
  Gen ByteString
-> (ByteString -> Maybe MessageHash) -> Gen MessageHash
forall a b. Gen a -> (a -> Maybe b) -> Gen b
Gen.suchThatMap (Int -> [Item ByteString] -> ByteString
forall l. IsList l => Int -> [Item l] -> l
GHC.fromListN Int
32 ([Word8] -> ByteString) -> Gen [Word8] -> Gen ByteString
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> Gen Word8 -> Gen [Word8]
forall (m :: * -> *) a. Applicative m => Int -> m a -> m [a]
replicateM Int
32 Gen Word8
forall a. Arbitrary a => Gen a
arbitrary)
                  ByteString -> Maybe MessageHash
toMessageHash
#endif

defaultSignKeyWithContextGen
  :: forall (v :: Type).
     DSIGNAlgorithm v
  => Gen (KeyGenContextDSIGN v)
  -> Gen (SignKeyDSIGN v)
defaultSignKeyWithContextGen :: forall v.
DSIGNAlgorithm v =>
Gen (KeyGenContextDSIGN v) -> Gen (SignKeyDSIGN v)
defaultSignKeyWithContextGen Gen (KeyGenContextDSIGN v)
genKeyCtx = do
  KeyGenContextDSIGN v
keyCtx <- Gen (KeyGenContextDSIGN v)
genKeyCtx
  Seed
seed   <- Word -> Gen Seed
arbitrarySeedOfSize (Proxy v -> Word
forall v (proxy :: * -> *). DSIGNAlgorithm v => proxy v -> Word
seedSizeDSIGN (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @v))
  SignKeyDSIGN v -> Gen (SignKeyDSIGN v)
forall a. a -> Gen a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (SignKeyDSIGN v -> Gen (SignKeyDSIGN v))
-> SignKeyDSIGN v -> Gen (SignKeyDSIGN v)
forall a b. (a -> b) -> a -> b
$ forall v.
DSIGNAlgorithm v =>
KeyGenContextDSIGN v -> Seed -> SignKeyDSIGN v
genKeyDSIGNWithContext @v KeyGenContextDSIGN v
keyCtx Seed
seed

defaultSignKeyGen
  :: forall (v :: Type).
     ( DSIGNAlgorithm v
     , KeyGenContextDSIGN v ~ ()
     )
  => Gen (SignKeyDSIGN v)
defaultSignKeyGen :: forall v.
(DSIGNAlgorithm v, KeyGenContextDSIGN v ~ ()) =>
Gen (SignKeyDSIGN v)
defaultSignKeyGen =
  forall v.
DSIGNAlgorithm v =>
Gen (KeyGenContextDSIGN v) -> Gen (SignKeyDSIGN v)
defaultSignKeyWithContextGen @v (() -> Gen ()
forall a. a -> Gen a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ())

defaultPossessionProofGen
  :: forall v.
     DSIGNAggregatable v
  => Gen (ContextDSIGN v)
  -> Gen (KeyGenContextDSIGN v)
  -> Gen (PossessionProofDSIGN v)
defaultPossessionProofGen :: forall v.
DSIGNAggregatable v =>
Gen (ContextDSIGN v)
-> Gen (KeyGenContextDSIGN v) -> Gen (PossessionProofDSIGN v)
defaultPossessionProofGen Gen (ContextDSIGN v)
genContext Gen (KeyGenContextDSIGN v)
genKeyCtx = do
  ContextDSIGN v
ctx <- Gen (ContextDSIGN v)
genContext
  SignKeyDSIGN v
sk  <- forall v.
DSIGNAlgorithm v =>
Gen (KeyGenContextDSIGN v) -> Gen (SignKeyDSIGN v)
defaultSignKeyWithContextGen @v Gen (KeyGenContextDSIGN v)
genKeyCtx
  PossessionProofDSIGN v -> Gen (PossessionProofDSIGN v)
forall a. a -> Gen a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (PossessionProofDSIGN v -> Gen (PossessionProofDSIGN v))
-> PossessionProofDSIGN v -> Gen (PossessionProofDSIGN v)
forall a b. (a -> b) -> a -> b
$ ContextDSIGN v -> SignKeyDSIGN v -> PossessionProofDSIGN v
forall v.
(DSIGNAggregatable v, HasCallStack) =>
ContextDSIGN v -> SignKeyDSIGN v -> PossessionProofDSIGN v
createPossessionProofDSIGN ContextDSIGN v
ctx SignKeyDSIGN v
sk

-- Used for adjusting no of quick check tests
-- By default up to 100 tests are performed which may not be enough to catch hidden bugs
testEnough :: Spec -> Spec
testEnough :: Spec -> Spec
testEnough = (Int -> Int) -> Spec -> Spec
forall a. (Int -> Int) -> SpecWith a -> SpecWith a
modifyMaxSuccess (Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
10_000)

{- HLINT ignore "Use <$>" -}
{- HLINT ignore "Reduce duplication" -}

--
-- The list of all tests
--
tests :: Lock -> Spec
tests :: Lock -> Spec
tests Lock
lock =
  String -> Spec -> Spec
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"Crypto.DSIGN" (Spec -> Spec) -> Spec -> Spec
forall a b. (a -> b) -> a -> b
$ do
     String -> Spec -> Spec
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"Pure" (Spec -> Spec) -> Spec -> Spec
forall a b. (a -> b) -> a -> b
$ do
       Proxy MockDSIGN -> Gen Message -> String -> Spec
forall v a.
(DSIGNAlgorithm v, Signable v a, ContextDSIGN v ~ (),
 KeyGenContextDSIGN v ~ (), Show a, Eq (SignKeyDSIGN v), Eq a,
 ToCBOR (VerKeyDSIGN v), FromCBOR (VerKeyDSIGN v),
 ToCBOR (SignKeyDSIGN v), FromCBOR (SignKeyDSIGN v),
 ToCBOR (SigDSIGN v), FromCBOR (SigDSIGN v)) =>
Proxy v -> Gen a -> String -> Spec
testDSIGNAlgorithm (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @MockDSIGN) (forall a. Arbitrary a => Gen a
arbitrary @Message) String
"MockDSIGN"
       Proxy Ed25519DSIGN -> Gen Message -> String -> Spec
forall v a.
(DSIGNAlgorithm v, Signable v a, ContextDSIGN v ~ (),
 KeyGenContextDSIGN v ~ (), Show a, Eq (SignKeyDSIGN v), Eq a,
 ToCBOR (VerKeyDSIGN v), FromCBOR (VerKeyDSIGN v),
 ToCBOR (SignKeyDSIGN v), FromCBOR (SignKeyDSIGN v),
 ToCBOR (SigDSIGN v), FromCBOR (SigDSIGN v)) =>
Proxy v -> Gen a -> String -> Spec
testDSIGNAlgorithm (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @Ed25519DSIGN) (forall a. Arbitrary a => Gen a
arbitrary @Message) String
"Ed25519DSIGN"
       Proxy Ed448DSIGN -> Gen Message -> String -> Spec
forall v a.
(DSIGNAlgorithm v, Signable v a, ContextDSIGN v ~ (),
 KeyGenContextDSIGN v ~ (), Show a, Eq (SignKeyDSIGN v), Eq a,
 ToCBOR (VerKeyDSIGN v), FromCBOR (VerKeyDSIGN v),
 ToCBOR (SignKeyDSIGN v), FromCBOR (SignKeyDSIGN v),
 ToCBOR (SigDSIGN v), FromCBOR (SigDSIGN v)) =>
Proxy v -> Gen a -> String -> Spec
testDSIGNAlgorithm (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @Ed448DSIGN) (forall a. Arbitrary a => Gen a
arbitrary @Message) String
"Ed448DSIGN"
       Proxy BLS12381MinVerKeyDSIGN
-> Bool
-> Gen (ContextDSIGN BLS12381MinVerKeyDSIGN)
-> Gen (KeyGenContextDSIGN BLS12381MinVerKeyDSIGN)
-> Gen Message
-> String
-> Spec
forall v a.
(DSIGNAlgorithm v, Eq (KeyGenContextDSIGN v),
 Show (KeyGenContextDSIGN v), Signable v a, Show a,
 Show (ContextDSIGN v), Eq (SignKeyDSIGN v), Eq a,
 ToCBOR (VerKeyDSIGN v), FromCBOR (VerKeyDSIGN v),
 ToCBOR (SignKeyDSIGN v), FromCBOR (SignKeyDSIGN v),
 ToCBOR (SigDSIGN v), FromCBOR (SigDSIGN v)) =>
Proxy v
-> Bool
-> Gen (ContextDSIGN v)
-> Gen (KeyGenContextDSIGN v)
-> Gen a
-> String
-> Spec
testDSIGNAlgorithmWithContext (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @BLS12381MinVerKeyDSIGN) Bool
True Gen (ContextDSIGN BLS12381MinVerKeyDSIGN)
Gen BLS12381SignContext
blsSignContextGen Gen (Maybe ByteString)
Gen (KeyGenContextDSIGN BLS12381MinVerKeyDSIGN)
blsGenKeyWithContextGen (forall a. Arbitrary a => Gen a
arbitrary @Message) String
"BLS12381MinVerKeyDSIGN"
       Proxy BLS12381MinSigDSIGN
-> Bool
-> Gen (ContextDSIGN BLS12381MinSigDSIGN)
-> Gen (KeyGenContextDSIGN BLS12381MinSigDSIGN)
-> Gen Message
-> String
-> Spec
forall v a.
(DSIGNAlgorithm v, Eq (KeyGenContextDSIGN v),
 Show (KeyGenContextDSIGN v), Signable v a, Show a,
 Show (ContextDSIGN v), Eq (SignKeyDSIGN v), Eq a,
 ToCBOR (VerKeyDSIGN v), FromCBOR (VerKeyDSIGN v),
 ToCBOR (SignKeyDSIGN v), FromCBOR (SignKeyDSIGN v),
 ToCBOR (SigDSIGN v), FromCBOR (SigDSIGN v)) =>
Proxy v
-> Bool
-> Gen (ContextDSIGN v)
-> Gen (KeyGenContextDSIGN v)
-> Gen a
-> String
-> Spec
testDSIGNAlgorithmWithContext (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @BLS12381MinSigDSIGN) Bool
True Gen (ContextDSIGN BLS12381MinSigDSIGN)
Gen BLS12381SignContext
blsSignContextGen Gen (Maybe ByteString)
Gen (KeyGenContextDSIGN BLS12381MinSigDSIGN)
blsGenKeyWithContextGen (forall a. Arbitrary a => Gen a
arbitrary @Message) String
"BLS12381MinSigDSIGN"
#ifdef SECP256K1_ENABLED
       Proxy EcdsaSecp256k1DSIGN -> Gen MessageHash -> String -> Spec
forall v a.
(DSIGNAlgorithm v, Signable v a, ContextDSIGN v ~ (),
 KeyGenContextDSIGN v ~ (), Show a, Eq (SignKeyDSIGN v), Eq a,
 ToCBOR (VerKeyDSIGN v), FromCBOR (VerKeyDSIGN v),
 ToCBOR (SignKeyDSIGN v), FromCBOR (SignKeyDSIGN v),
 ToCBOR (SigDSIGN v), FromCBOR (SigDSIGN v)) =>
Proxy v -> Gen a -> String -> Spec
testDSIGNAlgorithm (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @EcdsaSecp256k1DSIGN) Gen MessageHash
genEcdsaMsg String
"EcdsaSecp256k1DSIGN"
       Proxy SchnorrSecp256k1DSIGN -> Gen Message -> String -> Spec
forall v a.
(DSIGNAlgorithm v, Signable v a, ContextDSIGN v ~ (),
 KeyGenContextDSIGN v ~ (), Show a, Eq (SignKeyDSIGN v), Eq a,
 ToCBOR (VerKeyDSIGN v), FromCBOR (VerKeyDSIGN v),
 ToCBOR (SignKeyDSIGN v), FromCBOR (SignKeyDSIGN v),
 ToCBOR (SigDSIGN v), FromCBOR (SigDSIGN v)) =>
Proxy v -> Gen a -> String -> Spec
testDSIGNAlgorithm (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @SchnorrSecp256k1DSIGN) (forall a. Arbitrary a => Gen a
arbitrary @Message) String
"SchnorrSecp256k1DSIGN"
       -- Specific tests related only to ecdsa
       String -> Spec
testEcdsaInvalidMessageHash String
"EcdsaSecp256k1InvalidMessageHash"
       Proxy SHA3_256 -> String -> Spec
forall h.
(HashAlgorithm h, HashSize h ~ SECP256K1_ECDSA_MESSAGE_BYTES) =>
Proxy h -> String -> Spec
testEcdsaWithHashAlgorithm (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @SHA3_256) String
"EcdsaSecp256k1WithSHA3_256"
       Proxy Blake2b_256 -> String -> Spec
forall h.
(HashAlgorithm h, HashSize h ~ SECP256K1_ECDSA_MESSAGE_BYTES) =>
Proxy h -> String -> Spec
testEcdsaWithHashAlgorithm (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @Blake2b_256) String
"EcdsaSecp256k1WithBlake2b_256"
       Proxy SHA256 -> String -> Spec
forall h.
(HashAlgorithm h, HashSize h ~ SECP256K1_ECDSA_MESSAGE_BYTES) =>
Proxy h -> String -> Spec
testEcdsaWithHashAlgorithm (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @SHA256) String
"EcdsaSecp256k1WithSHA256"
       Proxy Keccak256 -> String -> Spec
forall h.
(HashAlgorithm h, HashSize h ~ SECP256K1_ECDSA_MESSAGE_BYTES) =>
Proxy h -> String -> Spec
testEcdsaWithHashAlgorithm (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @Keccak256) String
"EcdsaSecp256k1WithKeccak256"
#endif
     String -> Spec -> Spec
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"MLocked" (Spec -> Spec) -> Spec -> Spec
forall a b. (a -> b) -> a -> b
$ do
      Lock -> Proxy Ed25519DSIGN -> String -> Spec
forall v.
(UnsoundDSIGNMAlgorithm v, ToCBOR (VerKeyDSIGN v),
 FromCBOR (VerKeyDSIGN v), EqST (SignKeyDSIGNM v),
 ToCBOR (SigDSIGN v), FromCBOR (SigDSIGN v), ContextDSIGN v ~ (),
 Signable v Message, DirectSerialise (SignKeyDSIGNM v),
 DirectDeserialise (SignKeyDSIGNM v),
 DirectSerialise (VerKeyDSIGN v),
 DirectDeserialise (VerKeyDSIGN v)) =>
Lock -> Proxy v -> String -> Spec
testDSIGNMAlgorithm Lock
lock (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @Ed25519DSIGN) String
"Ed25519DSIGN"
     String -> Spec -> Spec
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"Aggregatable" (Spec -> Spec) -> Spec -> Spec
forall a b. (a -> b) -> a -> b
$ do
      Proxy BLS12381MinVerKeyDSIGN
-> Gen (ContextDSIGN BLS12381MinVerKeyDSIGN)
-> Gen (KeyGenContextDSIGN BLS12381MinVerKeyDSIGN)
-> Gen Message
-> String
-> Spec
forall v.
(DSIGNAggregatable v, Signable v Message, Show (ContextDSIGN v),
 ToCBOR (PossessionProofDSIGN v),
 FromCBOR (PossessionProofDSIGN v)) =>
Proxy v
-> Gen (ContextDSIGN v)
-> Gen (KeyGenContextDSIGN v)
-> Gen Message
-> String
-> Spec
testDSIGNAggregatableWithContext (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @(BLS12381DSIGN Curve1)) Gen (ContextDSIGN BLS12381MinVerKeyDSIGN)
Gen BLS12381SignContext
blsSignContextGen Gen (Maybe ByteString)
Gen (KeyGenContextDSIGN BLS12381MinVerKeyDSIGN)
blsGenKeyWithContextGen (forall a. Arbitrary a => Gen a
arbitrary @Message) String
"BLS12381MinVerKeyDSIGN"
      Proxy BLS12381MinSigDSIGN
-> Gen (ContextDSIGN BLS12381MinSigDSIGN)
-> Gen (KeyGenContextDSIGN BLS12381MinSigDSIGN)
-> Gen Message
-> String
-> Spec
forall v.
(DSIGNAggregatable v, Signable v Message, Show (ContextDSIGN v),
 ToCBOR (PossessionProofDSIGN v),
 FromCBOR (PossessionProofDSIGN v)) =>
Proxy v
-> Gen (ContextDSIGN v)
-> Gen (KeyGenContextDSIGN v)
-> Gen Message
-> String
-> Spec
testDSIGNAggregatableWithContext (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @(BLS12381DSIGN Curve2)) Gen (ContextDSIGN BLS12381MinSigDSIGN)
Gen BLS12381SignContext
blsSignContextGen Gen (Maybe ByteString)
Gen (KeyGenContextDSIGN BLS12381MinSigDSIGN)
blsGenKeyWithContextGen (forall a. Arbitrary a => Gen a
arbitrary @Message) String
"BLS12381MinSigDSIGN"

testDSIGNAlgorithmWithContext :: forall (v :: Type) (a :: Type).
  (DSIGNAlgorithm v,
   Eq (KeyGenContextDSIGN v),
   Show (KeyGenContextDSIGN v),
   Signable v a,
   Show a,
   Show (ContextDSIGN v),
   Eq (SignKeyDSIGN v),
   Eq a,
   ToCBOR (VerKeyDSIGN v),
   FromCBOR (VerKeyDSIGN v),
   ToCBOR (SignKeyDSIGN v),
   FromCBOR (SignKeyDSIGN v),
   ToCBOR (SigDSIGN v),
   FromCBOR (SigDSIGN v)) =>
  Proxy v ->
  Bool ->
  Gen (ContextDSIGN v) ->
  Gen (KeyGenContextDSIGN v) ->
  Gen a ->
  String ->
  Spec
testDSIGNAlgorithmWithContext :: forall v a.
(DSIGNAlgorithm v, Eq (KeyGenContextDSIGN v),
 Show (KeyGenContextDSIGN v), Signable v a, Show a,
 Show (ContextDSIGN v), Eq (SignKeyDSIGN v), Eq a,
 ToCBOR (VerKeyDSIGN v), FromCBOR (VerKeyDSIGN v),
 ToCBOR (SignKeyDSIGN v), FromCBOR (SignKeyDSIGN v),
 ToCBOR (SigDSIGN v), FromCBOR (SigDSIGN v)) =>
Proxy v
-> Bool
-> Gen (ContextDSIGN v)
-> Gen (KeyGenContextDSIGN v)
-> Gen a
-> String
-> Spec
testDSIGNAlgorithmWithContext Proxy v
proxy Bool
ctxMatters Gen (ContextDSIGN v)
genContext Gen (KeyGenContextDSIGN v)
genKeyCtx Gen a
genMsg String
name = Spec -> Spec
testEnough (Spec -> Spec) -> (Spec -> Spec) -> Spec -> Spec
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Spec -> Spec
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
name (Spec -> Spec) -> Spec -> Spec
forall a b. (a -> b) -> a -> b
$ do
  Bool -> Spec -> Spec
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when Bool
ctxMatters (Spec -> Spec) -> Spec -> Spec
forall a b. (a -> b) -> a -> b
$
    String -> Spec -> Spec
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"keygen context" (Spec -> Spec) -> Spec -> Spec
forall a b. (a -> b) -> a -> b
$ do
      String -> (SizedSeed (SeedSizeDSIGN v) -> Property) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"same seed, different keygen contexts results in different ver keys" ((SizedSeed (SeedSizeDSIGN v) -> Property) -> Spec)
-> (SizedSeed (SeedSizeDSIGN v) -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$
        Proxy v
-> Gen (KeyGenContextDSIGN v)
-> SizedSeed (SeedSizeDSIGN v)
-> Property
forall v.
(DSIGNAlgorithm v, Eq (KeyGenContextDSIGN v),
 Show (KeyGenContextDSIGN v)) =>
Proxy v
-> Gen (KeyGenContextDSIGN v)
-> SizedSeed (SeedSizeDSIGN v)
-> Property
prop_keygen_context_changes_verkey Proxy v
proxy Gen (KeyGenContextDSIGN v)
genKeyCtx
  -- describe "keygen context" $ do
  --   prop "same seed, different keygen contexts results in different ver keys" $
  --     prop_keygen_context_changes_verkey proxy genKeyCtx
  String -> Spec -> Spec
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"serialization" (Spec -> Spec) -> Spec -> Spec
forall a b. (a -> b) -> a -> b
$ do
    String -> Spec -> Spec
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"raw" (Spec -> Spec) -> Spec -> Spec
forall a b. (a -> b) -> a -> b
$ do
      String -> Property -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"VerKey serialization" (Property -> Spec)
-> ((VerKeyDSIGN v -> Property) -> Property)
-> (VerKeyDSIGN v -> Property)
-> Spec
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
        Gen (VerKeyDSIGN v)
-> (VerKeyDSIGN v -> String)
-> (VerKeyDSIGN v -> Property)
-> Property
forall prop a.
Testable prop =>
Gen a -> (a -> String) -> (a -> prop) -> Property
forAllShow Gen (VerKeyDSIGN v)
genVerKey
                   VerKeyDSIGN v -> String
forall a. Show a => a -> String
ppShow ((VerKeyDSIGN v -> Property) -> Spec)
-> (VerKeyDSIGN v -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$
                   (VerKeyDSIGN v -> ByteString)
-> (ByteString -> Maybe (VerKeyDSIGN v))
-> VerKeyDSIGN v
-> Property
forall a.
(Eq a, Show a) =>
(a -> ByteString) -> (ByteString -> Maybe a) -> a -> Property
prop_raw_serialise VerKeyDSIGN v -> ByteString
forall v. DSIGNAlgorithm v => VerKeyDSIGN v -> ByteString
rawSerialiseVerKeyDSIGN ByteString -> Maybe (VerKeyDSIGN v)
forall v. DSIGNAlgorithm v => ByteString -> Maybe (VerKeyDSIGN v)
rawDeserialiseVerKeyDSIGN
      String -> (BadInputFor (VerKeyDSIGN v) -> Property) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"VerKey deserialization (wrong length)" ((BadInputFor (VerKeyDSIGN v) -> Property) -> Spec)
-> (BadInputFor (VerKeyDSIGN v) -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$ (ByteString -> Maybe (VerKeyDSIGN v))
-> BadInputFor (VerKeyDSIGN v) -> Property
forall a.
Show a =>
(ByteString -> Maybe a) -> BadInputFor a -> Property
prop_raw_deserialise (forall v. DSIGNAlgorithm v => ByteString -> Maybe (VerKeyDSIGN v)
rawDeserialiseVerKeyDSIGN @v)
      String -> (BadInputFor (VerKeyDSIGN v) -> Property) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"VerKey fail fromCBOR" ((BadInputFor (VerKeyDSIGN v) -> Property) -> Spec)
-> (BadInputFor (VerKeyDSIGN v) -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$ forall a. (Show a, FromCBOR a) => BadInputFor a -> Property
prop_bad_cbor_bytes @(VerKeyDSIGN v)
      String -> Property -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"SignKey serialization" (Property -> Spec)
-> ((SignKeyDSIGN v -> Property) -> Property)
-> (SignKeyDSIGN v -> Property)
-> Spec
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
        Gen (SignKeyDSIGN v)
-> (SignKeyDSIGN v -> String)
-> (SignKeyDSIGN v -> Property)
-> Property
forall prop a.
Testable prop =>
Gen a -> (a -> String) -> (a -> prop) -> Property
forAllShow (forall v.
DSIGNAlgorithm v =>
Gen (KeyGenContextDSIGN v) -> Gen (SignKeyDSIGN v)
defaultSignKeyWithContextGen @v Gen (KeyGenContextDSIGN v)
genKeyCtx)
                   SignKeyDSIGN v -> String
forall a. Show a => a -> String
ppShow ((SignKeyDSIGN v -> Property) -> Spec)
-> (SignKeyDSIGN v -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$
                   (SignKeyDSIGN v -> ByteString)
-> (ByteString -> Maybe (SignKeyDSIGN v))
-> SignKeyDSIGN v
-> Property
forall a.
(Eq a, Show a) =>
(a -> ByteString) -> (ByteString -> Maybe a) -> a -> Property
prop_raw_serialise SignKeyDSIGN v -> ByteString
forall v. DSIGNAlgorithm v => SignKeyDSIGN v -> ByteString
rawSerialiseSignKeyDSIGN ByteString -> Maybe (SignKeyDSIGN v)
forall v. DSIGNAlgorithm v => ByteString -> Maybe (SignKeyDSIGN v)
rawDeserialiseSignKeyDSIGN
      String -> (BadInputFor (SignKeyDSIGN v) -> Property) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"SignKey deserialization (wrong length)" ((BadInputFor (SignKeyDSIGN v) -> Property) -> Spec)
-> (BadInputFor (SignKeyDSIGN v) -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$ (ByteString -> Maybe (SignKeyDSIGN v))
-> BadInputFor (SignKeyDSIGN v) -> Property
forall a.
Show a =>
(ByteString -> Maybe a) -> BadInputFor a -> Property
prop_raw_deserialise (forall v. DSIGNAlgorithm v => ByteString -> Maybe (SignKeyDSIGN v)
rawDeserialiseSignKeyDSIGN @v)
      String -> (BadInputFor (SignKeyDSIGN v) -> Property) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"SignKey fail fromCBOR" ((BadInputFor (SignKeyDSIGN v) -> Property) -> Spec)
-> (BadInputFor (SignKeyDSIGN v) -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$ forall a. (Show a, FromCBOR a) => BadInputFor a -> Property
prop_bad_cbor_bytes @(SignKeyDSIGN v)
      String -> Property -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"Sig serialization" (Property -> Spec)
-> ((SigDSIGN v -> Property) -> Property)
-> (SigDSIGN v -> Property)
-> Spec
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
        Gen (SigDSIGN v)
-> (SigDSIGN v -> String) -> (SigDSIGN v -> Property) -> Property
forall prop a.
Testable prop =>
Gen a -> (a -> String) -> (a -> prop) -> Property
forAllShow Gen (SigDSIGN v)
genSig
                   SigDSIGN v -> String
forall a. Show a => a -> String
ppShow ((SigDSIGN v -> Property) -> Spec)
-> (SigDSIGN v -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$
                   (SigDSIGN v -> ByteString)
-> (ByteString -> Maybe (SigDSIGN v)) -> SigDSIGN v -> Property
forall a.
(Eq a, Show a) =>
(a -> ByteString) -> (ByteString -> Maybe a) -> a -> Property
prop_raw_serialise SigDSIGN v -> ByteString
forall v. DSIGNAlgorithm v => SigDSIGN v -> ByteString
rawSerialiseSigDSIGN ByteString -> Maybe (SigDSIGN v)
forall v. DSIGNAlgorithm v => ByteString -> Maybe (SigDSIGN v)
rawDeserialiseSigDSIGN
      String -> (BadInputFor (SigDSIGN v) -> Property) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"Sig deserialization (wrong length)" ((BadInputFor (SigDSIGN v) -> Property) -> Spec)
-> (BadInputFor (SigDSIGN v) -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$ (ByteString -> Maybe (SigDSIGN v))
-> BadInputFor (SigDSIGN v) -> Property
forall a.
Show a =>
(ByteString -> Maybe a) -> BadInputFor a -> Property
prop_raw_deserialise (forall v. DSIGNAlgorithm v => ByteString -> Maybe (SigDSIGN v)
rawDeserialiseSigDSIGN @v)
      String -> (BadInputFor (SigDSIGN v) -> Property) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"VerKey fail fromCBOR" ((BadInputFor (SigDSIGN v) -> Property) -> Spec)
-> (BadInputFor (SigDSIGN v) -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$ forall a. (Show a, FromCBOR a) => BadInputFor a -> Property
prop_bad_cbor_bytes @(SigDSIGN v)
    String -> Spec -> Spec
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"size" (Spec -> Spec) -> Spec -> Spec
forall a b. (a -> b) -> a -> b
$ do
      String -> Property -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"VerKey" (Property -> Spec)
-> ((VerKeyDSIGN v -> Property) -> Property)
-> (VerKeyDSIGN v -> Property)
-> Spec
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
        Gen (VerKeyDSIGN v)
-> (VerKeyDSIGN v -> String)
-> (VerKeyDSIGN v -> Property)
-> Property
forall prop a.
Testable prop =>
Gen a -> (a -> String) -> (a -> prop) -> Property
forAllShow Gen (VerKeyDSIGN v)
genVerKey
                   VerKeyDSIGN v -> String
forall a. Show a => a -> String
ppShow ((VerKeyDSIGN v -> Property) -> Spec)
-> (VerKeyDSIGN v -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$
                   (VerKeyDSIGN v -> ByteString) -> Word -> VerKeyDSIGN v -> Property
forall a. (a -> ByteString) -> Word -> a -> Property
prop_size_serialise VerKeyDSIGN v -> ByteString
forall v. DSIGNAlgorithm v => VerKeyDSIGN v -> ByteString
rawSerialiseVerKeyDSIGN (Proxy v -> Word
forall v (proxy :: * -> *). DSIGNAlgorithm v => proxy v -> Word
verKeySizeDSIGN (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @v))
      String -> Property -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"SignKey" (Property -> Spec)
-> ((SignKeyDSIGN v -> Property) -> Property)
-> (SignKeyDSIGN v -> Property)
-> Spec
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
        Gen (SignKeyDSIGN v)
-> (SignKeyDSIGN v -> String)
-> (SignKeyDSIGN v -> Property)
-> Property
forall prop a.
Testable prop =>
Gen a -> (a -> String) -> (a -> prop) -> Property
forAllShow (forall v.
DSIGNAlgorithm v =>
Gen (KeyGenContextDSIGN v) -> Gen (SignKeyDSIGN v)
defaultSignKeyWithContextGen @v Gen (KeyGenContextDSIGN v)
genKeyCtx)
                   SignKeyDSIGN v -> String
forall a. Show a => a -> String
ppShow ((SignKeyDSIGN v -> Property) -> Spec)
-> (SignKeyDSIGN v -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$
                   (SignKeyDSIGN v -> ByteString)
-> Word -> SignKeyDSIGN v -> Property
forall a. (a -> ByteString) -> Word -> a -> Property
prop_size_serialise SignKeyDSIGN v -> ByteString
forall v. DSIGNAlgorithm v => SignKeyDSIGN v -> ByteString
rawSerialiseSignKeyDSIGN (Proxy v -> Word
forall v (proxy :: * -> *). DSIGNAlgorithm v => proxy v -> Word
signKeySizeDSIGN (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @v))
      String -> Property -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"Sig" (Property -> Spec)
-> ((SigDSIGN v -> Property) -> Property)
-> (SigDSIGN v -> Property)
-> Spec
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
        Gen (SigDSIGN v)
-> (SigDSIGN v -> String) -> (SigDSIGN v -> Property) -> Property
forall prop a.
Testable prop =>
Gen a -> (a -> String) -> (a -> prop) -> Property
forAllShow Gen (SigDSIGN v)
genSig
                   SigDSIGN v -> String
forall a. Show a => a -> String
ppShow ((SigDSIGN v -> Property) -> Spec)
-> (SigDSIGN v -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$
                   (SigDSIGN v -> ByteString) -> Word -> SigDSIGN v -> Property
forall a. (a -> ByteString) -> Word -> a -> Property
prop_size_serialise SigDSIGN v -> ByteString
forall v. DSIGNAlgorithm v => SigDSIGN v -> ByteString
rawSerialiseSigDSIGN (Proxy v -> Word
forall v (proxy :: * -> *). DSIGNAlgorithm v => proxy v -> Word
sigSizeDSIGN (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @v))
    String -> Spec -> Spec
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"direct CBOR" (Spec -> Spec) -> Spec -> Spec
forall a b. (a -> b) -> a -> b
$ do
      String -> Property -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"VerKey" (Property -> Spec)
-> ((VerKeyDSIGN v -> Property) -> Property)
-> (VerKeyDSIGN v -> Property)
-> Spec
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
        Gen (VerKeyDSIGN v)
-> (VerKeyDSIGN v -> String)
-> (VerKeyDSIGN v -> Property)
-> Property
forall prop a.
Testable prop =>
Gen a -> (a -> String) -> (a -> prop) -> Property
forAllShow Gen (VerKeyDSIGN v)
genVerKey
                   VerKeyDSIGN v -> String
forall a. Show a => a -> String
ppShow ((VerKeyDSIGN v -> Property) -> Spec)
-> (VerKeyDSIGN v -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$
                   (VerKeyDSIGN v -> Encoding)
-> (forall s. Decoder s (VerKeyDSIGN v))
-> VerKeyDSIGN v
-> Property
forall a.
(Eq a, Show a) =>
(a -> Encoding) -> (forall s. Decoder s a) -> a -> Property
prop_cbor_with VerKeyDSIGN v -> Encoding
forall v. DSIGNAlgorithm v => VerKeyDSIGN v -> Encoding
encodeVerKeyDSIGN Decoder s (VerKeyDSIGN v)
forall s. Decoder s (VerKeyDSIGN v)
forall v s. DSIGNAlgorithm v => Decoder s (VerKeyDSIGN v)
decodeVerKeyDSIGN
      String -> Property -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"SignKey" (Property -> Spec)
-> ((SignKeyDSIGN v -> Property) -> Property)
-> (SignKeyDSIGN v -> Property)
-> Spec
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
        Gen (SignKeyDSIGN v)
-> (SignKeyDSIGN v -> String)
-> (SignKeyDSIGN v -> Property)
-> Property
forall prop a.
Testable prop =>
Gen a -> (a -> String) -> (a -> prop) -> Property
forAllShow (forall v.
DSIGNAlgorithm v =>
Gen (KeyGenContextDSIGN v) -> Gen (SignKeyDSIGN v)
defaultSignKeyWithContextGen @v Gen (KeyGenContextDSIGN v)
genKeyCtx)
                   SignKeyDSIGN v -> String
forall a. Show a => a -> String
ppShow ((SignKeyDSIGN v -> Property) -> Spec)
-> (SignKeyDSIGN v -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$
                   (SignKeyDSIGN v -> Encoding)
-> (forall s. Decoder s (SignKeyDSIGN v))
-> SignKeyDSIGN v
-> Property
forall a.
(Eq a, Show a) =>
(a -> Encoding) -> (forall s. Decoder s a) -> a -> Property
prop_cbor_with SignKeyDSIGN v -> Encoding
forall v. DSIGNAlgorithm v => SignKeyDSIGN v -> Encoding
encodeSignKeyDSIGN Decoder s (SignKeyDSIGN v)
forall s. Decoder s (SignKeyDSIGN v)
forall v s. DSIGNAlgorithm v => Decoder s (SignKeyDSIGN v)
decodeSignKeyDSIGN
      String -> Property -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"Sig" (Property -> Spec)
-> ((SigDSIGN v -> Property) -> Property)
-> (SigDSIGN v -> Property)
-> Spec
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
        Gen (SigDSIGN v)
-> (SigDSIGN v -> String) -> (SigDSIGN v -> Property) -> Property
forall prop a.
Testable prop =>
Gen a -> (a -> String) -> (a -> prop) -> Property
forAllShow Gen (SigDSIGN v)
genSig
                   SigDSIGN v -> String
forall a. Show a => a -> String
ppShow ((SigDSIGN v -> Property) -> Spec)
-> (SigDSIGN v -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$
                   (SigDSIGN v -> Encoding)
-> (forall s. Decoder s (SigDSIGN v)) -> SigDSIGN v -> Property
forall a.
(Eq a, Show a) =>
(a -> Encoding) -> (forall s. Decoder s a) -> a -> Property
prop_cbor_with SigDSIGN v -> Encoding
forall v. DSIGNAlgorithm v => SigDSIGN v -> Encoding
encodeSigDSIGN Decoder s (SigDSIGN v)
forall s. Decoder s (SigDSIGN v)
forall v s. DSIGNAlgorithm v => Decoder s (SigDSIGN v)
decodeSigDSIGN
    String -> Spec -> Spec
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"To/FromCBOR class" (Spec -> Spec) -> Spec -> Spec
forall a b. (a -> b) -> a -> b
$ do
      String -> Property -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"VerKey" (Property -> Spec)
-> ((VerKeyDSIGN v -> Property) -> Property)
-> (VerKeyDSIGN v -> Property)
-> Spec
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Gen (VerKeyDSIGN v)
-> (VerKeyDSIGN v -> String)
-> (VerKeyDSIGN v -> Property)
-> Property
forall prop a.
Testable prop =>
Gen a -> (a -> String) -> (a -> prop) -> Property
forAllShow Gen (VerKeyDSIGN v)
genVerKey VerKeyDSIGN v -> String
forall a. Show a => a -> String
ppShow ((VerKeyDSIGN v -> Property) -> Spec)
-> (VerKeyDSIGN v -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$ VerKeyDSIGN v -> Property
forall a. (ToCBOR a, FromCBOR a, Eq a, Show a) => a -> Property
prop_cbor
      String -> Property -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"SignKey" (Property -> Spec)
-> ((SignKeyDSIGN v -> Property) -> Property)
-> (SignKeyDSIGN v -> Property)
-> Spec
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Gen (SignKeyDSIGN v)
-> (SignKeyDSIGN v -> String)
-> (SignKeyDSIGN v -> Property)
-> Property
forall prop a.
Testable prop =>
Gen a -> (a -> String) -> (a -> prop) -> Property
forAllShow (forall v.
DSIGNAlgorithm v =>
Gen (KeyGenContextDSIGN v) -> Gen (SignKeyDSIGN v)
defaultSignKeyWithContextGen @v Gen (KeyGenContextDSIGN v)
genKeyCtx) SignKeyDSIGN v -> String
forall a. Show a => a -> String
ppShow ((SignKeyDSIGN v -> Property) -> Spec)
-> (SignKeyDSIGN v -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$ SignKeyDSIGN v -> Property
forall a. (ToCBOR a, FromCBOR a, Eq a, Show a) => a -> Property
prop_cbor
      String -> Property -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"Sig" (Property -> Spec)
-> ((SigDSIGN v -> Property) -> Property)
-> (SigDSIGN v -> Property)
-> Spec
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Gen (SigDSIGN v)
-> (SigDSIGN v -> String) -> (SigDSIGN v -> Property) -> Property
forall prop a.
Testable prop =>
Gen a -> (a -> String) -> (a -> prop) -> Property
forAllShow Gen (SigDSIGN v)
genSig SigDSIGN v -> String
forall a. Show a => a -> String
ppShow ((SigDSIGN v -> Property) -> Spec)
-> (SigDSIGN v -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$ SigDSIGN v -> Property
forall a. (ToCBOR a, FromCBOR a, Eq a, Show a) => a -> Property
prop_cbor
    String -> Spec -> Spec
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"ToCBOR size" (Spec -> Spec) -> Spec -> Spec
forall a b. (a -> b) -> a -> b
$ do
      String -> Property -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"VerKey" (Property -> Spec)
-> ((VerKeyDSIGN v -> Property) -> Property)
-> (VerKeyDSIGN v -> Property)
-> Spec
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Gen (VerKeyDSIGN v)
-> (VerKeyDSIGN v -> String)
-> (VerKeyDSIGN v -> Property)
-> Property
forall prop a.
Testable prop =>
Gen a -> (a -> String) -> (a -> prop) -> Property
forAllShow Gen (VerKeyDSIGN v)
genVerKey VerKeyDSIGN v -> String
forall a. Show a => a -> String
ppShow ((VerKeyDSIGN v -> Property) -> Spec)
-> (VerKeyDSIGN v -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$ VerKeyDSIGN v -> Property
forall a. ToCBOR a => a -> Property
prop_cbor_size
      String -> Property -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"SignKey" (Property -> Spec)
-> ((SignKeyDSIGN v -> Property) -> Property)
-> (SignKeyDSIGN v -> Property)
-> Spec
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Gen (SignKeyDSIGN v)
-> (SignKeyDSIGN v -> String)
-> (SignKeyDSIGN v -> Property)
-> Property
forall prop a.
Testable prop =>
Gen a -> (a -> String) -> (a -> prop) -> Property
forAllShow (forall v.
DSIGNAlgorithm v =>
Gen (KeyGenContextDSIGN v) -> Gen (SignKeyDSIGN v)
defaultSignKeyWithContextGen @v Gen (KeyGenContextDSIGN v)
genKeyCtx) SignKeyDSIGN v -> String
forall a. Show a => a -> String
ppShow ((SignKeyDSIGN v -> Property) -> Spec)
-> (SignKeyDSIGN v -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$ SignKeyDSIGN v -> Property
forall a. ToCBOR a => a -> Property
prop_cbor_size
      String -> Property -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"Sig" (Property -> Spec)
-> ((SigDSIGN v -> Property) -> Property)
-> (SigDSIGN v -> Property)
-> Spec
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Gen (SigDSIGN v)
-> (SigDSIGN v -> String) -> (SigDSIGN v -> Property) -> Property
forall prop a.
Testable prop =>
Gen a -> (a -> String) -> (a -> prop) -> Property
forAllShow Gen (SigDSIGN v)
genSig SigDSIGN v -> String
forall a. Show a => a -> String
ppShow ((SigDSIGN v -> Property) -> Spec)
-> (SigDSIGN v -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$ SigDSIGN v -> Property
forall a. ToCBOR a => a -> Property
prop_cbor_size
    String -> Spec -> Spec
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"direct matches class" (Spec -> Spec) -> Spec -> Spec
forall a b. (a -> b) -> a -> b
$ do
      String -> Property -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"VerKey" (Property -> Spec)
-> ((VerKeyDSIGN v -> Property) -> Property)
-> (VerKeyDSIGN v -> Property)
-> Spec
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
        Gen (VerKeyDSIGN v)
-> (VerKeyDSIGN v -> String)
-> (VerKeyDSIGN v -> Property)
-> Property
forall prop a.
Testable prop =>
Gen a -> (a -> String) -> (a -> prop) -> Property
forAllShow Gen (VerKeyDSIGN v)
genVerKey VerKeyDSIGN v -> String
forall a. Show a => a -> String
ppShow ((VerKeyDSIGN v -> Property) -> Spec)
-> (VerKeyDSIGN v -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$
        (VerKeyDSIGN v -> Encoding) -> VerKeyDSIGN v -> Property
forall a. ToCBOR a => (a -> Encoding) -> a -> Property
prop_cbor_direct_vs_class VerKeyDSIGN v -> Encoding
forall v. DSIGNAlgorithm v => VerKeyDSIGN v -> Encoding
encodeVerKeyDSIGN
      String -> Property -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"SignKey" (Property -> Spec)
-> ((SignKeyDSIGN v -> Property) -> Property)
-> (SignKeyDSIGN v -> Property)
-> Spec
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
        Gen (SignKeyDSIGN v)
-> (SignKeyDSIGN v -> String)
-> (SignKeyDSIGN v -> Property)
-> Property
forall prop a.
Testable prop =>
Gen a -> (a -> String) -> (a -> prop) -> Property
forAllShow (forall v.
DSIGNAlgorithm v =>
Gen (KeyGenContextDSIGN v) -> Gen (SignKeyDSIGN v)
defaultSignKeyWithContextGen @v Gen (KeyGenContextDSIGN v)
genKeyCtx) SignKeyDSIGN v -> String
forall a. Show a => a -> String
ppShow ((SignKeyDSIGN v -> Property) -> Spec)
-> (SignKeyDSIGN v -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$
        (SignKeyDSIGN v -> Encoding) -> SignKeyDSIGN v -> Property
forall a. ToCBOR a => (a -> Encoding) -> a -> Property
prop_cbor_direct_vs_class SignKeyDSIGN v -> Encoding
forall v. DSIGNAlgorithm v => SignKeyDSIGN v -> Encoding
encodeSignKeyDSIGN
      String -> Property -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"Sig" (Property -> Spec)
-> ((SigDSIGN v -> Property) -> Property)
-> (SigDSIGN v -> Property)
-> Spec
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
        Gen (SigDSIGN v)
-> (SigDSIGN v -> String) -> (SigDSIGN v -> Property) -> Property
forall prop a.
Testable prop =>
Gen a -> (a -> String) -> (a -> prop) -> Property
forAllShow Gen (SigDSIGN v)
genSig SigDSIGN v -> String
forall a. Show a => a -> String
ppShow ((SigDSIGN v -> Property) -> Spec)
-> (SigDSIGN v -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$
        (SigDSIGN v -> Encoding) -> SigDSIGN v -> Property
forall a. ToCBOR a => (a -> Encoding) -> a -> Property
prop_cbor_direct_vs_class SigDSIGN v -> Encoding
forall v. DSIGNAlgorithm v => SigDSIGN v -> Encoding
encodeSigDSIGN
    String -> Spec -> Spec
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"verify" (Spec -> Spec) -> Spec -> Spec
forall a b. (a -> b) -> a -> b
$ do
      String -> Property -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"signing and verifying with matching keys" (Property -> Spec)
-> (((ContextDSIGN v, a, SignKeyDSIGN v) -> Property) -> Property)
-> ((ContextDSIGN v, a, SignKeyDSIGN v) -> Property)
-> Spec
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
        Gen (ContextDSIGN v, a, SignKeyDSIGN v)
-> ((ContextDSIGN v, a, SignKeyDSIGN v) -> String)
-> ((ContextDSIGN v, a, SignKeyDSIGN v) -> Property)
-> Property
forall prop a.
Testable prop =>
Gen a -> (a -> String) -> (a -> prop) -> Property
forAllShow ((,,) (ContextDSIGN v
 -> a -> SignKeyDSIGN v -> (ContextDSIGN v, a, SignKeyDSIGN v))
-> Gen (ContextDSIGN v)
-> Gen (a -> SignKeyDSIGN v -> (ContextDSIGN v, a, SignKeyDSIGN v))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen (ContextDSIGN v)
genContext Gen (a -> SignKeyDSIGN v -> (ContextDSIGN v, a, SignKeyDSIGN v))
-> Gen a
-> Gen (SignKeyDSIGN v -> (ContextDSIGN v, a, SignKeyDSIGN v))
forall a b. Gen (a -> b) -> Gen a -> Gen b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen a
genMsg Gen (SignKeyDSIGN v -> (ContextDSIGN v, a, SignKeyDSIGN v))
-> Gen (SignKeyDSIGN v) -> Gen (ContextDSIGN v, a, SignKeyDSIGN v)
forall a b. Gen (a -> b) -> Gen a -> Gen b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall v.
DSIGNAlgorithm v =>
Gen (KeyGenContextDSIGN v) -> Gen (SignKeyDSIGN v)
defaultSignKeyWithContextGen @v Gen (KeyGenContextDSIGN v)
genKeyCtx) (ContextDSIGN v, a, SignKeyDSIGN v) -> String
forall a. Show a => a -> String
ppShow (((ContextDSIGN v, a, SignKeyDSIGN v) -> Property) -> Spec)
-> ((ContextDSIGN v, a, SignKeyDSIGN v) -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$
        (ContextDSIGN v, a, SignKeyDSIGN v) -> Property
forall v a.
(DSIGNAlgorithm v, Signable v a) =>
(ContextDSIGN v, a, SignKeyDSIGN v) -> Property
prop_dsign_verify
      String -> Property -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"verifying with wrong key" (Property -> Spec)
-> (((ContextDSIGN v, a, SignKeyDSIGN v, SignKeyDSIGN v)
     -> Property)
    -> Property)
-> ((ContextDSIGN v, a, SignKeyDSIGN v, SignKeyDSIGN v)
    -> Property)
-> Spec
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
        Gen (ContextDSIGN v, a, SignKeyDSIGN v, SignKeyDSIGN v)
-> ((ContextDSIGN v, a, SignKeyDSIGN v, SignKeyDSIGN v) -> String)
-> ((ContextDSIGN v, a, SignKeyDSIGN v, SignKeyDSIGN v)
    -> Property)
-> Property
forall prop a.
Testable prop =>
Gen a -> (a -> String) -> (a -> prop) -> Property
forAllShow Gen (ContextDSIGN v, a, SignKeyDSIGN v, SignKeyDSIGN v)
genWrongKey (ContextDSIGN v, a, SignKeyDSIGN v, SignKeyDSIGN v) -> String
forall a. Show a => a -> String
ppShow (((ContextDSIGN v, a, SignKeyDSIGN v, SignKeyDSIGN v) -> Property)
 -> Spec)
-> ((ContextDSIGN v, a, SignKeyDSIGN v, SignKeyDSIGN v)
    -> Property)
-> Spec
forall a b. (a -> b) -> a -> b
$
        (ContextDSIGN v, a, SignKeyDSIGN v, SignKeyDSIGN v) -> Property
forall v a.
(DSIGNAlgorithm v, Signable v a) =>
(ContextDSIGN v, a, SignKeyDSIGN v, SignKeyDSIGN v) -> Property
prop_dsign_verify_wrong_key
      String -> Property -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"verifying wrong message" (Property -> Spec)
-> (((ContextDSIGN v, a, a, SignKeyDSIGN v) -> Property)
    -> Property)
-> ((ContextDSIGN v, a, a, SignKeyDSIGN v) -> Property)
-> Spec
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
        Gen (ContextDSIGN v, a, a, SignKeyDSIGN v)
-> ((ContextDSIGN v, a, a, SignKeyDSIGN v) -> String)
-> ((ContextDSIGN v, a, a, SignKeyDSIGN v) -> Property)
-> Property
forall prop a.
Testable prop =>
Gen a -> (a -> String) -> (a -> prop) -> Property
forAllShow Gen (ContextDSIGN v, a, a, SignKeyDSIGN v)
genWrongMsg (ContextDSIGN v, a, a, SignKeyDSIGN v) -> String
forall a. Show a => a -> String
ppShow (((ContextDSIGN v, a, a, SignKeyDSIGN v) -> Property) -> Spec)
-> ((ContextDSIGN v, a, a, SignKeyDSIGN v) -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$
        (ContextDSIGN v, a, a, SignKeyDSIGN v) -> Property
forall v a.
(DSIGNAlgorithm v, Signable v a) =>
(ContextDSIGN v, a, a, SignKeyDSIGN v) -> Property
prop_dsign_verify_wrong_msg
    String -> Spec -> Spec
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"NoThunks" (Spec -> Spec) -> Spec -> Spec
forall a b. (a -> b) -> a -> b
$ do
      String -> Property -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"VerKey" (Property -> Spec)
-> ((VerKeyDSIGN v -> Property) -> Property)
-> (VerKeyDSIGN v -> Property)
-> Spec
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Gen (VerKeyDSIGN v)
-> (VerKeyDSIGN v -> String)
-> (VerKeyDSIGN v -> Property)
-> Property
forall prop a.
Testable prop =>
Gen a -> (a -> String) -> (a -> prop) -> Property
forAllShow Gen (VerKeyDSIGN v)
genVerKey VerKeyDSIGN v -> String
forall a. Show a => a -> String
ppShow ((VerKeyDSIGN v -> Property) -> Spec)
-> (VerKeyDSIGN v -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$ VerKeyDSIGN v -> Property
forall a. NoThunks a => a -> Property
prop_no_thunks
      String -> Property -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"SignKey" (Property -> Spec)
-> ((SignKeyDSIGN v -> Property) -> Property)
-> (SignKeyDSIGN v -> Property)
-> Spec
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Gen (SignKeyDSIGN v)
-> (SignKeyDSIGN v -> String)
-> (SignKeyDSIGN v -> Property)
-> Property
forall prop a.
Testable prop =>
Gen a -> (a -> String) -> (a -> prop) -> Property
forAllShow (forall v.
DSIGNAlgorithm v =>
Gen (KeyGenContextDSIGN v) -> Gen (SignKeyDSIGN v)
defaultSignKeyWithContextGen @v Gen (KeyGenContextDSIGN v)
genKeyCtx) SignKeyDSIGN v -> String
forall a. Show a => a -> String
ppShow ((SignKeyDSIGN v -> Property) -> Spec)
-> (SignKeyDSIGN v -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$ SignKeyDSIGN v -> Property
forall a. NoThunks a => a -> Property
prop_no_thunks
      String -> Property -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"Sig" (Property -> Spec)
-> ((SigDSIGN v -> Property) -> Property)
-> (SigDSIGN v -> Property)
-> Spec
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Gen (SigDSIGN v)
-> (SigDSIGN v -> String) -> (SigDSIGN v -> Property) -> Property
forall prop a.
Testable prop =>
Gen a -> (a -> String) -> (a -> prop) -> Property
forAllShow Gen (SigDSIGN v)
genSig SigDSIGN v -> String
forall a. Show a => a -> String
ppShow ((SigDSIGN v -> Property) -> Spec)
-> (SigDSIGN v -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$ SigDSIGN v -> Property
forall a. NoThunks a => a -> Property
prop_no_thunks
      String -> Property -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"VerKey rawSerialise" (Property -> Spec)
-> ((VerKeyDSIGN v -> Property) -> Property)
-> (VerKeyDSIGN v -> Property)
-> Spec
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Gen (VerKeyDSIGN v)
-> (VerKeyDSIGN v -> String)
-> (VerKeyDSIGN v -> Property)
-> Property
forall prop a.
Testable prop =>
Gen a -> (a -> String) -> (a -> prop) -> Property
forAllShow Gen (VerKeyDSIGN v)
genVerKey VerKeyDSIGN v -> String
forall a. Show a => a -> String
ppShow ((VerKeyDSIGN v -> Property) -> Spec)
-> (VerKeyDSIGN v -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$ \VerKeyDSIGN v
vk ->
        ByteString -> Property
forall a. NoThunks a => a -> Property
prop_no_thunks (VerKeyDSIGN v -> ByteString
forall v. DSIGNAlgorithm v => VerKeyDSIGN v -> ByteString
rawSerialiseVerKeyDSIGN VerKeyDSIGN v
vk)
      String -> Property -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"VerKey rawDeserialise" (Property -> Spec)
-> ((VerKeyDSIGN v -> Property) -> Property)
-> (VerKeyDSIGN v -> Property)
-> Spec
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Gen (VerKeyDSIGN v)
-> (VerKeyDSIGN v -> String)
-> (VerKeyDSIGN v -> Property)
-> Property
forall prop a.
Testable prop =>
Gen a -> (a -> String) -> (a -> prop) -> Property
forAllShow Gen (VerKeyDSIGN v)
genVerKey VerKeyDSIGN v -> String
forall a. Show a => a -> String
ppShow ((VerKeyDSIGN v -> Property) -> Spec)
-> (VerKeyDSIGN v -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$ \VerKeyDSIGN v
vk ->
        VerKeyDSIGN v -> Property
forall a. NoThunks a => a -> Property
prop_no_thunks (Maybe (VerKeyDSIGN v) -> VerKeyDSIGN v
forall a. HasCallStack => Maybe a -> a
fromJust (Maybe (VerKeyDSIGN v) -> VerKeyDSIGN v)
-> Maybe (VerKeyDSIGN v) -> VerKeyDSIGN v
forall a b. (a -> b) -> a -> b
$! forall v. DSIGNAlgorithm v => ByteString -> Maybe (VerKeyDSIGN v)
rawDeserialiseVerKeyDSIGN @v (ByteString -> Maybe (VerKeyDSIGN v))
-> (VerKeyDSIGN v -> ByteString)
-> VerKeyDSIGN v
-> Maybe (VerKeyDSIGN v)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. VerKeyDSIGN v -> ByteString
forall v. DSIGNAlgorithm v => VerKeyDSIGN v -> ByteString
rawSerialiseVerKeyDSIGN (VerKeyDSIGN v -> Maybe (VerKeyDSIGN v))
-> VerKeyDSIGN v -> Maybe (VerKeyDSIGN v)
forall a b. (a -> b) -> a -> b
$ VerKeyDSIGN v
vk)
  where
    genWrongKey :: Gen (ContextDSIGN v, a, SignKeyDSIGN v, SignKeyDSIGN v)
    genWrongKey :: Gen (ContextDSIGN v, a, SignKeyDSIGN v, SignKeyDSIGN v)
genWrongKey = do
      ContextDSIGN v
ctx <- Gen (ContextDSIGN v)
genContext
      SignKeyDSIGN v
sk1 <- Gen (KeyGenContextDSIGN v) -> Gen (SignKeyDSIGN v)
forall v.
DSIGNAlgorithm v =>
Gen (KeyGenContextDSIGN v) -> Gen (SignKeyDSIGN v)
defaultSignKeyWithContextGen Gen (KeyGenContextDSIGN v)
genKeyCtx
      SignKeyDSIGN v
sk2 <- Gen (SignKeyDSIGN v)
-> (SignKeyDSIGN v -> Bool) -> Gen (SignKeyDSIGN v)
forall a. Gen a -> (a -> Bool) -> Gen a
Gen.suchThat (Gen (KeyGenContextDSIGN v) -> Gen (SignKeyDSIGN v)
forall v.
DSIGNAlgorithm v =>
Gen (KeyGenContextDSIGN v) -> Gen (SignKeyDSIGN v)
defaultSignKeyWithContextGen Gen (KeyGenContextDSIGN v)
genKeyCtx) (SignKeyDSIGN v -> SignKeyDSIGN v -> Bool
forall a. Eq a => a -> a -> Bool
/= SignKeyDSIGN v
sk1)
      a
msg <- Gen a
genMsg
      (ContextDSIGN v, a, SignKeyDSIGN v, SignKeyDSIGN v)
-> Gen (ContextDSIGN v, a, SignKeyDSIGN v, SignKeyDSIGN v)
forall a. a -> Gen a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ContextDSIGN v
ctx, a
msg, SignKeyDSIGN v
sk1, SignKeyDSIGN v
sk2)
    genWrongMsg :: Gen (ContextDSIGN v, a, a, SignKeyDSIGN v)
    genWrongMsg :: Gen (ContextDSIGN v, a, a, SignKeyDSIGN v)
genWrongMsg = do
      ContextDSIGN v
ctx <- Gen (ContextDSIGN v)
genContext
      a
msg1 <- Gen a
genMsg
      a
msg2 <- Gen a -> (a -> Bool) -> Gen a
forall a. Gen a -> (a -> Bool) -> Gen a
Gen.suchThat Gen a
genMsg (a -> a -> Bool
forall a. Eq a => a -> a -> Bool
/= a
msg1)
      SignKeyDSIGN v
sk <- Gen (KeyGenContextDSIGN v) -> Gen (SignKeyDSIGN v)
forall v.
DSIGNAlgorithm v =>
Gen (KeyGenContextDSIGN v) -> Gen (SignKeyDSIGN v)
defaultSignKeyWithContextGen Gen (KeyGenContextDSIGN v)
genKeyCtx
      (ContextDSIGN v, a, a, SignKeyDSIGN v)
-> Gen (ContextDSIGN v, a, a, SignKeyDSIGN v)
forall a. a -> Gen a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ContextDSIGN v
ctx, a
msg1, a
msg2, SignKeyDSIGN v
sk)
    genSignKey :: Gen (SignKeyDSIGN v)
    genSignKey :: Gen (SignKeyDSIGN v)
genSignKey = forall v.
DSIGNAlgorithm v =>
Gen (KeyGenContextDSIGN v) -> Gen (SignKeyDSIGN v)
defaultSignKeyWithContextGen @v Gen (KeyGenContextDSIGN v)
genKeyCtx
    genVerKey :: Gen (VerKeyDSIGN v)
    genVerKey :: Gen (VerKeyDSIGN v)
genVerKey = SignKeyDSIGN v -> VerKeyDSIGN v
forall v. DSIGNAlgorithm v => SignKeyDSIGN v -> VerKeyDSIGN v
deriveVerKeyDSIGN (SignKeyDSIGN v -> VerKeyDSIGN v)
-> Gen (SignKeyDSIGN v) -> Gen (VerKeyDSIGN v)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen (SignKeyDSIGN v)
genSignKey
    genSig :: Gen (SigDSIGN v)
    genSig :: Gen (SigDSIGN v)
genSig = do
      ContextDSIGN v
ctx <- Gen (ContextDSIGN v)
genContext
      a
msg <- Gen a
genMsg
      SignKeyDSIGN v
sk  <- Gen (SignKeyDSIGN v)
genSignKey
      SigDSIGN v -> Gen (SigDSIGN v)
forall a. a -> Gen a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (SigDSIGN v -> Gen (SigDSIGN v)) -> SigDSIGN v -> Gen (SigDSIGN v)
forall a b. (a -> b) -> a -> b
$ forall v a.
(DSIGNAlgorithm v, Signable v a, HasCallStack) =>
ContextDSIGN v -> a -> SignKeyDSIGN v -> SigDSIGN v
signDSIGN @v ContextDSIGN v
ctx a
msg SignKeyDSIGN v
sk

testDSIGNAlgorithm :: forall v a.
  ( DSIGNAlgorithm v
  , Signable v a
  , ContextDSIGN v ~ ()
  , KeyGenContextDSIGN v ~ ()
  , Show a
  , Eq (SignKeyDSIGN v)
  , Eq a
  , ToCBOR (VerKeyDSIGN v)
  , FromCBOR (VerKeyDSIGN v)
  , ToCBOR (SignKeyDSIGN v)
  , FromCBOR (SignKeyDSIGN v)
  , ToCBOR (SigDSIGN v)
  , FromCBOR (SigDSIGN v)
  ) =>
  Proxy v ->
  Gen a ->
  String ->
  Spec
testDSIGNAlgorithm :: forall v a.
(DSIGNAlgorithm v, Signable v a, ContextDSIGN v ~ (),
 KeyGenContextDSIGN v ~ (), Show a, Eq (SignKeyDSIGN v), Eq a,
 ToCBOR (VerKeyDSIGN v), FromCBOR (VerKeyDSIGN v),
 ToCBOR (SignKeyDSIGN v), FromCBOR (SignKeyDSIGN v),
 ToCBOR (SigDSIGN v), FromCBOR (SigDSIGN v)) =>
Proxy v -> Gen a -> String -> Spec
testDSIGNAlgorithm Proxy v
proxy = forall v a.
(DSIGNAlgorithm v, Eq (KeyGenContextDSIGN v),
 Show (KeyGenContextDSIGN v), Signable v a, Show a,
 Show (ContextDSIGN v), Eq (SignKeyDSIGN v), Eq a,
 ToCBOR (VerKeyDSIGN v), FromCBOR (VerKeyDSIGN v),
 ToCBOR (SignKeyDSIGN v), FromCBOR (SignKeyDSIGN v),
 ToCBOR (SigDSIGN v), FromCBOR (SigDSIGN v)) =>
Proxy v
-> Bool
-> Gen (ContextDSIGN v)
-> Gen (KeyGenContextDSIGN v)
-> Gen a
-> String
-> Spec
testDSIGNAlgorithmWithContext @v Proxy v
proxy Bool
False (() -> Gen ()
forall a. a -> Gen a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()) (() -> Gen ()
forall a. a -> Gen a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ())


testDSIGNMAlgorithm
  :: forall v. ( -- change back to DSIGNMAlgorithm when unsound API is phased out
                 UnsoundDSIGNMAlgorithm v
               , ToCBOR (VerKeyDSIGN v)
               , FromCBOR (VerKeyDSIGN v)
               -- DSIGNM cannot satisfy To/FromCBOR (not even with
               -- UnsoundDSIGNMAlgorithm), because those typeclasses assume
               -- that a non-monadic encoding/decoding exists. Hence, we only
               -- test direct encoding/decoding for 'SignKeyDSIGNM'.
               -- , ToCBOR (SignKeyDSIGNM v)
               -- , FromCBOR (SignKeyDSIGNM v)
               , EqST (SignKeyDSIGNM v)   -- only monadic EqST for signing keys
               , ToCBOR (SigDSIGN v)
               , FromCBOR (SigDSIGN v)
               , ContextDSIGN v ~ ()
               , Signable v Message
               , DirectSerialise (SignKeyDSIGNM v)
               , DirectDeserialise (SignKeyDSIGNM v)
               , DirectSerialise (VerKeyDSIGN v)
               , DirectDeserialise (VerKeyDSIGN v)
               )
  => Lock
  -> Proxy v
  -> String
  -> Spec
testDSIGNMAlgorithm :: forall v.
(UnsoundDSIGNMAlgorithm v, ToCBOR (VerKeyDSIGN v),
 FromCBOR (VerKeyDSIGN v), EqST (SignKeyDSIGNM v),
 ToCBOR (SigDSIGN v), FromCBOR (SigDSIGN v), ContextDSIGN v ~ (),
 Signable v Message, DirectSerialise (SignKeyDSIGNM v),
 DirectDeserialise (SignKeyDSIGNM v),
 DirectSerialise (VerKeyDSIGN v),
 DirectDeserialise (VerKeyDSIGN v)) =>
Lock -> Proxy v -> String -> Spec
testDSIGNMAlgorithm Lock
lock Proxy v
_ String
n =
  String -> Spec -> Spec
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
n (Spec -> Spec) -> Spec -> Spec
forall a b. (a -> b) -> a -> b
$ do
     String -> Spec -> Spec
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"serialisation" (Spec -> Spec) -> Spec -> Spec
forall a b. (a -> b) -> a -> b
$ do
       String -> Spec -> Spec
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"raw" (Spec -> Spec) -> Spec -> Spec
forall a b. (a -> b) -> a -> b
$ do
         String -> (PinnedSizedBytes (SeedSizeDSIGN v) -> Property) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"VerKey" ((PinnedSizedBytes (SeedSizeDSIGN v) -> Property) -> Spec)
-> (PinnedSizedBytes (SeedSizeDSIGN v) -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$
            forall v a.
(Testable a, DSIGNMAlgorithm v) =>
Lock
-> (SignKeyDSIGNM v -> IO a)
-> PinnedSizedBytes (SeedSizeDSIGN v)
-> Property
ioPropertyWithSK @v Lock
lock ((SignKeyDSIGNM v -> IO Property)
 -> PinnedSizedBytes (SeedSizeDSIGN v) -> Property)
-> (SignKeyDSIGNM v -> IO Property)
-> PinnedSizedBytes (SeedSizeDSIGN v)
-> Property
forall a b. (a -> b) -> a -> b
$ \SignKeyDSIGNM v
sk -> do
              VerKeyDSIGN v
vk <- SignKeyDSIGNM v -> IO (VerKeyDSIGN v)
forall v (m :: * -> *).
(DSIGNMAlgorithm v, MonadThrow m, MonadST m) =>
SignKeyDSIGNM v -> m (VerKeyDSIGN v)
forall (m :: * -> *).
(MonadThrow m, MonadST m) =>
SignKeyDSIGNM v -> m (VerKeyDSIGN v)
deriveVerKeyDSIGNM SignKeyDSIGNM v
sk
              Property -> IO Property
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Property -> IO Property) -> Property -> IO Property
forall a b. (a -> b) -> a -> b
$ (ByteString -> Maybe (VerKeyDSIGN v)
forall v. DSIGNAlgorithm v => ByteString -> Maybe (VerKeyDSIGN v)
rawDeserialiseVerKeyDSIGN (ByteString -> Maybe (VerKeyDSIGN v))
-> (VerKeyDSIGN v -> ByteString)
-> VerKeyDSIGN v
-> Maybe (VerKeyDSIGN v)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. VerKeyDSIGN v -> ByteString
forall v. DSIGNAlgorithm v => VerKeyDSIGN v -> ByteString
rawSerialiseVerKeyDSIGN (VerKeyDSIGN v -> Maybe (VerKeyDSIGN v))
-> VerKeyDSIGN v -> Maybe (VerKeyDSIGN v)
forall a b. (a -> b) -> a -> b
$ VerKeyDSIGN v
vk) Maybe (VerKeyDSIGN v) -> Maybe (VerKeyDSIGN v) -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=== VerKeyDSIGN v -> Maybe (VerKeyDSIGN v)
forall a. a -> Maybe a
Just VerKeyDSIGN v
vk
         String -> (PinnedSizedBytes (SeedSizeDSIGN v) -> Property) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"SignKey" ((PinnedSizedBytes (SeedSizeDSIGN v) -> Property) -> Spec)
-> (PinnedSizedBytes (SeedSizeDSIGN v) -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$
            forall v a.
(Testable a, DSIGNMAlgorithm v) =>
Lock
-> (SignKeyDSIGNM v -> IO a)
-> PinnedSizedBytes (SeedSizeDSIGN v)
-> Property
ioPropertyWithSK @v Lock
lock ((SignKeyDSIGNM v -> IO Bool)
 -> PinnedSizedBytes (SeedSizeDSIGN v) -> Property)
-> (SignKeyDSIGNM v -> IO Bool)
-> PinnedSizedBytes (SeedSizeDSIGN v)
-> Property
forall a b. (a -> b) -> a -> b
$ \SignKeyDSIGNM v
sk -> do
              ByteString
serialized <- SignKeyDSIGNM v -> IO ByteString
forall v (m :: * -> *).
(UnsoundDSIGNMAlgorithm v, MonadST m, MonadThrow m) =>
SignKeyDSIGNM v -> m ByteString
forall (m :: * -> *).
(MonadST m, MonadThrow m) =>
SignKeyDSIGNM v -> m ByteString
rawSerialiseSignKeyDSIGNM SignKeyDSIGNM v
sk
              IO (Maybe (SignKeyDSIGNM v))
-> (Maybe (SignKeyDSIGNM v) -> IO ())
-> (Maybe (SignKeyDSIGNM v) -> IO Bool)
-> IO Bool
forall a b c. IO a -> (a -> IO b) -> (a -> IO c) -> IO c
bracket
                (ByteString -> IO (Maybe (SignKeyDSIGNM v))
forall v (m :: * -> *).
(UnsoundDSIGNMAlgorithm v, MonadST m, MonadThrow m) =>
ByteString -> m (Maybe (SignKeyDSIGNM v))
rawDeserialiseSignKeyDSIGNM ByteString
serialized)
                (IO ()
-> (SignKeyDSIGNM v -> IO ()) -> Maybe (SignKeyDSIGNM v) -> IO ()
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (() -> IO ()
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ()) SignKeyDSIGNM v -> IO ()
forall v (m :: * -> *).
(DSIGNMAlgorithm v, MonadST m, MonadThrow m) =>
SignKeyDSIGNM v -> m ()
forgetSignKeyDSIGNM)
                (\Maybe (SignKeyDSIGNM v)
msk' -> SignKeyDSIGNM v -> Maybe (SignKeyDSIGNM v)
forall a. a -> Maybe a
Just SignKeyDSIGNM v
sk Maybe (SignKeyDSIGNM v) -> Maybe (SignKeyDSIGNM v) -> IO Bool
forall (m :: * -> *) a. (MonadST m, EqST a) => a -> a -> m Bool
==! Maybe (SignKeyDSIGNM v)
msk')
         String
-> (Message -> PinnedSizedBytes (SeedSizeDSIGN v) -> Property)
-> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"Sig" ((Message -> PinnedSizedBytes (SeedSizeDSIGN v) -> Property)
 -> Spec)
-> (Message -> PinnedSizedBytes (SeedSizeDSIGN v) -> Property)
-> Spec
forall a b. (a -> b) -> a -> b
$ \(Message
msg :: Message) ->
            forall v a.
(Testable a, DSIGNMAlgorithm v) =>
Lock
-> (SignKeyDSIGNM v -> IO a)
-> PinnedSizedBytes (SeedSizeDSIGN v)
-> Property
ioPropertyWithSK @v Lock
lock ((SignKeyDSIGNM v -> IO Property)
 -> PinnedSizedBytes (SeedSizeDSIGN v) -> Property)
-> (SignKeyDSIGNM v -> IO Property)
-> PinnedSizedBytes (SeedSizeDSIGN v)
-> Property
forall a b. (a -> b) -> a -> b
$ \SignKeyDSIGNM v
sk -> do
              SigDSIGN v
sig <- ContextDSIGN v -> Message -> SignKeyDSIGNM v -> IO (SigDSIGN v)
forall v a (m :: * -> *).
(DSIGNMAlgorithm v, Signable v a, MonadST m, MonadThrow m) =>
ContextDSIGN v -> a -> SignKeyDSIGNM v -> m (SigDSIGN v)
forall a (m :: * -> *).
(Signable v a, MonadST m, MonadThrow m) =>
ContextDSIGN v -> a -> SignKeyDSIGNM v -> m (SigDSIGN v)
signDSIGNM () Message
msg SignKeyDSIGNM v
sk
              Property -> IO Property
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Property -> IO Property) -> Property -> IO Property
forall a b. (a -> b) -> a -> b
$ (ByteString -> Maybe (SigDSIGN v)
forall v. DSIGNAlgorithm v => ByteString -> Maybe (SigDSIGN v)
rawDeserialiseSigDSIGN (ByteString -> Maybe (SigDSIGN v))
-> (SigDSIGN v -> ByteString) -> SigDSIGN v -> Maybe (SigDSIGN v)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SigDSIGN v -> ByteString
forall v. DSIGNAlgorithm v => SigDSIGN v -> ByteString
rawSerialiseSigDSIGN (SigDSIGN v -> Maybe (SigDSIGN v))
-> SigDSIGN v -> Maybe (SigDSIGN v)
forall a b. (a -> b) -> a -> b
$ SigDSIGN v
sig) Maybe (SigDSIGN v) -> Maybe (SigDSIGN v) -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=== SigDSIGN v -> Maybe (SigDSIGN v)
forall a. a -> Maybe a
Just SigDSIGN v
sig
       String -> Spec -> Spec
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"size" (Spec -> Spec) -> Spec -> Spec
forall a b. (a -> b) -> a -> b
$ do
         String -> (PinnedSizedBytes (SeedSizeDSIGN v) -> Property) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"VerKey" ((PinnedSizedBytes (SeedSizeDSIGN v) -> Property) -> Spec)
-> (PinnedSizedBytes (SeedSizeDSIGN v) -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$
            forall v a.
(Testable a, DSIGNMAlgorithm v) =>
Lock
-> (SignKeyDSIGNM v -> IO a)
-> PinnedSizedBytes (SeedSizeDSIGN v)
-> Property
ioPropertyWithSK @v Lock
lock ((SignKeyDSIGNM v -> IO Property)
 -> PinnedSizedBytes (SeedSizeDSIGN v) -> Property)
-> (SignKeyDSIGNM v -> IO Property)
-> PinnedSizedBytes (SeedSizeDSIGN v)
-> Property
forall a b. (a -> b) -> a -> b
$ \SignKeyDSIGNM v
sk -> do
              VerKeyDSIGN v
vk <- SignKeyDSIGNM v -> IO (VerKeyDSIGN v)
forall v (m :: * -> *).
(DSIGNMAlgorithm v, MonadThrow m, MonadST m) =>
SignKeyDSIGNM v -> m (VerKeyDSIGN v)
forall (m :: * -> *).
(MonadThrow m, MonadST m) =>
SignKeyDSIGNM v -> m (VerKeyDSIGN v)
deriveVerKeyDSIGNM SignKeyDSIGNM v
sk
              Property -> IO Property
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Property -> IO Property) -> Property -> IO Property
forall a b. (a -> b) -> a -> b
$ (forall a b. (Integral a, Num b) => a -> b
fromIntegral @Int @Word (Int -> Word) -> (VerKeyDSIGN v -> Int) -> VerKeyDSIGN v -> Word
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Int
BS.length (ByteString -> Int)
-> (VerKeyDSIGN v -> ByteString) -> VerKeyDSIGN v -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. VerKeyDSIGN v -> ByteString
forall v. DSIGNAlgorithm v => VerKeyDSIGN v -> ByteString
rawSerialiseVerKeyDSIGN (VerKeyDSIGN v -> Word) -> VerKeyDSIGN v -> Word
forall a b. (a -> b) -> a -> b
$ VerKeyDSIGN v
vk) Word -> Word -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=== Proxy v -> Word
forall v (proxy :: * -> *). DSIGNAlgorithm v => proxy v -> Word
verKeySizeDSIGN (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @v)
         String -> (PinnedSizedBytes (SeedSizeDSIGN v) -> Property) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"SignKey" ((PinnedSizedBytes (SeedSizeDSIGN v) -> Property) -> Spec)
-> (PinnedSizedBytes (SeedSizeDSIGN v) -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$
            forall v a.
(Testable a, DSIGNMAlgorithm v) =>
Lock
-> (SignKeyDSIGNM v -> IO a)
-> PinnedSizedBytes (SeedSizeDSIGN v)
-> Property
ioPropertyWithSK @v Lock
lock ((SignKeyDSIGNM v -> IO Bool)
 -> PinnedSizedBytes (SeedSizeDSIGN v) -> Property)
-> (SignKeyDSIGNM v -> IO Bool)
-> PinnedSizedBytes (SeedSizeDSIGN v)
-> Property
forall a b. (a -> b) -> a -> b
$ \SignKeyDSIGNM v
sk -> do
              ByteString
serialized <- SignKeyDSIGNM v -> IO ByteString
forall v (m :: * -> *).
(UnsoundDSIGNMAlgorithm v, MonadST m, MonadThrow m) =>
SignKeyDSIGNM v -> m ByteString
forall (m :: * -> *).
(MonadST m, MonadThrow m) =>
SignKeyDSIGNM v -> m ByteString
rawSerialiseSignKeyDSIGNM SignKeyDSIGNM v
sk
              Bool -> IO Bool
forall a. a -> IO a
evaluate ((forall a b. (Integral a, Num b) => a -> b
fromIntegral @Int @Word (Int -> Word) -> (ByteString -> Int) -> ByteString -> Word
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Int
BS.length (ByteString -> Word) -> ByteString -> Word
forall a b. (a -> b) -> a -> b
$ ByteString
serialized) Word -> Word -> Bool
forall a. Eq a => a -> a -> Bool
== Proxy v -> Word
forall v (proxy :: * -> *). DSIGNAlgorithm v => proxy v -> Word
signKeySizeDSIGN (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @v))
         String
-> (Message -> PinnedSizedBytes (SeedSizeDSIGN v) -> Property)
-> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"Sig" ((Message -> PinnedSizedBytes (SeedSizeDSIGN v) -> Property)
 -> Spec)
-> (Message -> PinnedSizedBytes (SeedSizeDSIGN v) -> Property)
-> Spec
forall a b. (a -> b) -> a -> b
$ \(Message
msg :: Message) ->
            forall v a.
(Testable a, DSIGNMAlgorithm v) =>
Lock
-> (SignKeyDSIGNM v -> IO a)
-> PinnedSizedBytes (SeedSizeDSIGN v)
-> Property
ioPropertyWithSK @v Lock
lock ((SignKeyDSIGNM v -> IO Property)
 -> PinnedSizedBytes (SeedSizeDSIGN v) -> Property)
-> (SignKeyDSIGNM v -> IO Property)
-> PinnedSizedBytes (SeedSizeDSIGN v)
-> Property
forall a b. (a -> b) -> a -> b
$ \SignKeyDSIGNM v
sk -> do
              SigDSIGN v
sig :: SigDSIGN v <- ContextDSIGN v -> Message -> SignKeyDSIGNM v -> IO (SigDSIGN v)
forall v a (m :: * -> *).
(DSIGNMAlgorithm v, Signable v a, MonadST m, MonadThrow m) =>
ContextDSIGN v -> a -> SignKeyDSIGNM v -> m (SigDSIGN v)
forall a (m :: * -> *).
(Signable v a, MonadST m, MonadThrow m) =>
ContextDSIGN v -> a -> SignKeyDSIGNM v -> m (SigDSIGN v)
signDSIGNM () Message
msg SignKeyDSIGNM v
sk
              Property -> IO Property
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Property -> IO Property) -> Property -> IO Property
forall a b. (a -> b) -> a -> b
$ (forall a b. (Integral a, Num b) => a -> b
fromIntegral @Int @Word (Int -> Word) -> (SigDSIGN v -> Int) -> SigDSIGN v -> Word
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Int
BS.length (ByteString -> Int)
-> (SigDSIGN v -> ByteString) -> SigDSIGN v -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SigDSIGN v -> ByteString
forall v. DSIGNAlgorithm v => SigDSIGN v -> ByteString
rawSerialiseSigDSIGN (SigDSIGN v -> Word) -> SigDSIGN v -> Word
forall a b. (a -> b) -> a -> b
$ SigDSIGN v
sig) Word -> Word -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=== Proxy v -> Word
forall v (proxy :: * -> *). DSIGNAlgorithm v => proxy v -> Word
sigSizeDSIGN (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @v)

       String -> Spec -> Spec
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"direct CBOR" (Spec -> Spec) -> Spec -> Spec
forall a b. (a -> b) -> a -> b
$ do
         String -> (PinnedSizedBytes (SeedSizeDSIGN v) -> Property) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"VerKey" ((PinnedSizedBytes (SeedSizeDSIGN v) -> Property) -> Spec)
-> (PinnedSizedBytes (SeedSizeDSIGN v) -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$
            forall v a.
(Testable a, DSIGNMAlgorithm v) =>
Lock
-> (SignKeyDSIGNM v -> IO a)
-> PinnedSizedBytes (SeedSizeDSIGN v)
-> Property
ioPropertyWithSK @v Lock
lock ((SignKeyDSIGNM v -> IO Property)
 -> PinnedSizedBytes (SeedSizeDSIGN v) -> Property)
-> (SignKeyDSIGNM v -> IO Property)
-> PinnedSizedBytes (SeedSizeDSIGN v)
-> Property
forall a b. (a -> b) -> a -> b
$ \SignKeyDSIGNM v
sk -> do
              VerKeyDSIGN v
vk :: VerKeyDSIGN v <- SignKeyDSIGNM v -> IO (VerKeyDSIGN v)
forall v (m :: * -> *).
(DSIGNMAlgorithm v, MonadThrow m, MonadST m) =>
SignKeyDSIGNM v -> m (VerKeyDSIGN v)
forall (m :: * -> *).
(MonadThrow m, MonadST m) =>
SignKeyDSIGNM v -> m (VerKeyDSIGN v)
deriveVerKeyDSIGNM SignKeyDSIGNM v
sk
              Property -> IO Property
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Property -> IO Property) -> Property -> IO Property
forall a b. (a -> b) -> a -> b
$ (VerKeyDSIGN v -> Encoding)
-> (forall s. Decoder s (VerKeyDSIGN v))
-> VerKeyDSIGN v
-> Property
forall a.
(Eq a, Show a) =>
(a -> Encoding) -> (forall s. Decoder s a) -> a -> Property
prop_cbor_with VerKeyDSIGN v -> Encoding
forall v. DSIGNAlgorithm v => VerKeyDSIGN v -> Encoding
encodeVerKeyDSIGN Decoder s (VerKeyDSIGN v)
forall s. Decoder s (VerKeyDSIGN v)
forall v s. DSIGNAlgorithm v => Decoder s (VerKeyDSIGN v)
decodeVerKeyDSIGN VerKeyDSIGN v
vk
        -- No CBOR testing for SignKey: sign keys are stored in MLocked memory
        -- and require IO for access.
         String
-> (Message -> PinnedSizedBytes (SeedSizeDSIGN v) -> Property)
-> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"Sig" ((Message -> PinnedSizedBytes (SeedSizeDSIGN v) -> Property)
 -> Spec)
-> (Message -> PinnedSizedBytes (SeedSizeDSIGN v) -> Property)
-> Spec
forall a b. (a -> b) -> a -> b
$ \(Message
msg :: Message) -> do
            forall v a.
(Testable a, DSIGNMAlgorithm v) =>
Lock
-> (SignKeyDSIGNM v -> IO a)
-> PinnedSizedBytes (SeedSizeDSIGN v)
-> Property
ioPropertyWithSK @v Lock
lock ((SignKeyDSIGNM v -> IO Property)
 -> PinnedSizedBytes (SeedSizeDSIGN v) -> Property)
-> (SignKeyDSIGNM v -> IO Property)
-> PinnedSizedBytes (SeedSizeDSIGN v)
-> Property
forall a b. (a -> b) -> a -> b
$ \SignKeyDSIGNM v
sk -> do
              SigDSIGN v
sig :: SigDSIGN v <- ContextDSIGN v -> Message -> SignKeyDSIGNM v -> IO (SigDSIGN v)
forall v a (m :: * -> *).
(DSIGNMAlgorithm v, Signable v a, MonadST m, MonadThrow m) =>
ContextDSIGN v -> a -> SignKeyDSIGNM v -> m (SigDSIGN v)
forall a (m :: * -> *).
(Signable v a, MonadST m, MonadThrow m) =>
ContextDSIGN v -> a -> SignKeyDSIGNM v -> m (SigDSIGN v)
signDSIGNM () Message
msg SignKeyDSIGNM v
sk
              Property -> IO Property
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Property -> IO Property) -> Property -> IO Property
forall a b. (a -> b) -> a -> b
$ (SigDSIGN v -> Encoding)
-> (forall s. Decoder s (SigDSIGN v)) -> SigDSIGN v -> Property
forall a.
(Eq a, Show a) =>
(a -> Encoding) -> (forall s. Decoder s a) -> a -> Property
prop_cbor_with SigDSIGN v -> Encoding
forall v. DSIGNAlgorithm v => SigDSIGN v -> Encoding
encodeSigDSIGN Decoder s (SigDSIGN v)
forall s. Decoder s (SigDSIGN v)
forall v s. DSIGNAlgorithm v => Decoder s (SigDSIGN v)
decodeSigDSIGN SigDSIGN v
sig

       String -> Spec -> Spec
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"To/FromCBOR class" (Spec -> Spec) -> Spec -> Spec
forall a b. (a -> b) -> a -> b
$ do
         String -> (PinnedSizedBytes (SeedSizeDSIGN v) -> Property) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"VerKey"  ((PinnedSizedBytes (SeedSizeDSIGN v) -> Property) -> Spec)
-> (PinnedSizedBytes (SeedSizeDSIGN v) -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$
            forall v a.
(Testable a, DSIGNMAlgorithm v) =>
Lock
-> (SignKeyDSIGNM v -> IO a)
-> PinnedSizedBytes (SeedSizeDSIGN v)
-> Property
ioPropertyWithSK @v Lock
lock ((SignKeyDSIGNM v -> IO Property)
 -> PinnedSizedBytes (SeedSizeDSIGN v) -> Property)
-> (SignKeyDSIGNM v -> IO Property)
-> PinnedSizedBytes (SeedSizeDSIGN v)
-> Property
forall a b. (a -> b) -> a -> b
$ \SignKeyDSIGNM v
sk -> do
              VerKeyDSIGN v
vk :: VerKeyDSIGN v <- SignKeyDSIGNM v -> IO (VerKeyDSIGN v)
forall v (m :: * -> *).
(DSIGNMAlgorithm v, MonadThrow m, MonadST m) =>
SignKeyDSIGNM v -> m (VerKeyDSIGN v)
forall (m :: * -> *).
(MonadThrow m, MonadST m) =>
SignKeyDSIGNM v -> m (VerKeyDSIGN v)
deriveVerKeyDSIGNM SignKeyDSIGNM v
sk
              Property -> IO Property
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Property -> IO Property) -> Property -> IO Property
forall a b. (a -> b) -> a -> b
$ VerKeyDSIGN v -> Property
forall a. (ToCBOR a, FromCBOR a, Eq a, Show a) => a -> Property
prop_cbor VerKeyDSIGN v
vk
        -- No To/FromCBOR for 'SignKeyDSIGNM', see above.
         String
-> (Message -> PinnedSizedBytes (SeedSizeDSIGN v) -> Property)
-> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"Sig" ((Message -> PinnedSizedBytes (SeedSizeDSIGN v) -> Property)
 -> Spec)
-> (Message -> PinnedSizedBytes (SeedSizeDSIGN v) -> Property)
-> Spec
forall a b. (a -> b) -> a -> b
$ \(Message
msg :: Message) ->
            forall v a.
(Testable a, DSIGNMAlgorithm v) =>
Lock
-> (SignKeyDSIGNM v -> IO a)
-> PinnedSizedBytes (SeedSizeDSIGN v)
-> Property
ioPropertyWithSK @v Lock
lock ((SignKeyDSIGNM v -> IO Property)
 -> PinnedSizedBytes (SeedSizeDSIGN v) -> Property)
-> (SignKeyDSIGNM v -> IO Property)
-> PinnedSizedBytes (SeedSizeDSIGN v)
-> Property
forall a b. (a -> b) -> a -> b
$ \SignKeyDSIGNM v
sk -> do
              SigDSIGN v
sig :: SigDSIGN v <- ContextDSIGN v -> Message -> SignKeyDSIGNM v -> IO (SigDSIGN v)
forall v a (m :: * -> *).
(DSIGNMAlgorithm v, Signable v a, MonadST m, MonadThrow m) =>
ContextDSIGN v -> a -> SignKeyDSIGNM v -> m (SigDSIGN v)
forall a (m :: * -> *).
(Signable v a, MonadST m, MonadThrow m) =>
ContextDSIGN v -> a -> SignKeyDSIGNM v -> m (SigDSIGN v)
signDSIGNM () Message
msg SignKeyDSIGNM v
sk
              Property -> IO Property
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Property -> IO Property) -> Property -> IO Property
forall a b. (a -> b) -> a -> b
$ SigDSIGN v -> Property
forall a. (ToCBOR a, FromCBOR a, Eq a, Show a) => a -> Property
prop_cbor SigDSIGN v
sig

       String -> Spec -> Spec
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"ToCBOR size" (Spec -> Spec) -> Spec -> Spec
forall a b. (a -> b) -> a -> b
$ do
         String -> (PinnedSizedBytes (SeedSizeDSIGN v) -> Property) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"VerKey"  ((PinnedSizedBytes (SeedSizeDSIGN v) -> Property) -> Spec)
-> (PinnedSizedBytes (SeedSizeDSIGN v) -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$
            forall v a.
(Testable a, DSIGNMAlgorithm v) =>
Lock
-> (SignKeyDSIGNM v -> IO a)
-> PinnedSizedBytes (SeedSizeDSIGN v)
-> Property
ioPropertyWithSK @v Lock
lock ((SignKeyDSIGNM v -> IO Property)
 -> PinnedSizedBytes (SeedSizeDSIGN v) -> Property)
-> (SignKeyDSIGNM v -> IO Property)
-> PinnedSizedBytes (SeedSizeDSIGN v)
-> Property
forall a b. (a -> b) -> a -> b
$ \SignKeyDSIGNM v
sk -> do
              VerKeyDSIGN v
vk :: VerKeyDSIGN v <- SignKeyDSIGNM v -> IO (VerKeyDSIGN v)
forall v (m :: * -> *).
(DSIGNMAlgorithm v, MonadThrow m, MonadST m) =>
SignKeyDSIGNM v -> m (VerKeyDSIGN v)
forall (m :: * -> *).
(MonadThrow m, MonadST m) =>
SignKeyDSIGNM v -> m (VerKeyDSIGN v)
deriveVerKeyDSIGNM SignKeyDSIGNM v
sk
              Property -> IO Property
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Property -> IO Property) -> Property -> IO Property
forall a b. (a -> b) -> a -> b
$ VerKeyDSIGN v -> Property
forall a. ToCBOR a => a -> Property
prop_cbor_size VerKeyDSIGN v
vk
        -- No To/FromCBOR for 'SignKeyDSIGNM', see above.
         String
-> (Message -> PinnedSizedBytes (SeedSizeDSIGN v) -> Property)
-> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"Sig" ((Message -> PinnedSizedBytes (SeedSizeDSIGN v) -> Property)
 -> Spec)
-> (Message -> PinnedSizedBytes (SeedSizeDSIGN v) -> Property)
-> Spec
forall a b. (a -> b) -> a -> b
$ \(Message
msg :: Message) ->
            forall v a.
(Testable a, DSIGNMAlgorithm v) =>
Lock
-> (SignKeyDSIGNM v -> IO a)
-> PinnedSizedBytes (SeedSizeDSIGN v)
-> Property
ioPropertyWithSK @v Lock
lock ((SignKeyDSIGNM v -> IO Property)
 -> PinnedSizedBytes (SeedSizeDSIGN v) -> Property)
-> (SignKeyDSIGNM v -> IO Property)
-> PinnedSizedBytes (SeedSizeDSIGN v)
-> Property
forall a b. (a -> b) -> a -> b
$ \SignKeyDSIGNM v
sk -> do
              SigDSIGN v
sig :: SigDSIGN v <- ContextDSIGN v -> Message -> SignKeyDSIGNM v -> IO (SigDSIGN v)
forall v a (m :: * -> *).
(DSIGNMAlgorithm v, Signable v a, MonadST m, MonadThrow m) =>
ContextDSIGN v -> a -> SignKeyDSIGNM v -> m (SigDSIGN v)
forall a (m :: * -> *).
(Signable v a, MonadST m, MonadThrow m) =>
ContextDSIGN v -> a -> SignKeyDSIGNM v -> m (SigDSIGN v)
signDSIGNM () Message
msg SignKeyDSIGNM v
sk
              Property -> IO Property
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Property -> IO Property) -> Property -> IO Property
forall a b. (a -> b) -> a -> b
$ SigDSIGN v -> Property
forall a. ToCBOR a => a -> Property
prop_cbor_size SigDSIGN v
sig

       String -> Spec -> Spec
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"direct matches class" (Spec -> Spec) -> Spec -> Spec
forall a b. (a -> b) -> a -> b
$ do
         String -> (PinnedSizedBytes (SeedSizeDSIGN v) -> Property) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"VerKey" ((PinnedSizedBytes (SeedSizeDSIGN v) -> Property) -> Spec)
-> (PinnedSizedBytes (SeedSizeDSIGN v) -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$
            forall v a.
(Testable a, DSIGNMAlgorithm v) =>
Lock
-> (SignKeyDSIGNM v -> IO a)
-> PinnedSizedBytes (SeedSizeDSIGN v)
-> Property
ioPropertyWithSK @v Lock
lock ((SignKeyDSIGNM v -> IO Property)
 -> PinnedSizedBytes (SeedSizeDSIGN v) -> Property)
-> (SignKeyDSIGNM v -> IO Property)
-> PinnedSizedBytes (SeedSizeDSIGN v)
-> Property
forall a b. (a -> b) -> a -> b
$ \SignKeyDSIGNM v
sk -> do
              VerKeyDSIGN v
vk :: VerKeyDSIGN v <- SignKeyDSIGNM v -> IO (VerKeyDSIGN v)
forall v (m :: * -> *).
(DSIGNMAlgorithm v, MonadThrow m, MonadST m) =>
SignKeyDSIGNM v -> m (VerKeyDSIGN v)
forall (m :: * -> *).
(MonadThrow m, MonadST m) =>
SignKeyDSIGNM v -> m (VerKeyDSIGN v)
deriveVerKeyDSIGNM SignKeyDSIGNM v
sk
              Property -> IO Property
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Property -> IO Property) -> Property -> IO Property
forall a b. (a -> b) -> a -> b
$ (VerKeyDSIGN v -> Encoding) -> VerKeyDSIGN v -> Property
forall a. ToCBOR a => (a -> Encoding) -> a -> Property
prop_cbor_direct_vs_class VerKeyDSIGN v -> Encoding
forall v. DSIGNAlgorithm v => VerKeyDSIGN v -> Encoding
encodeVerKeyDSIGN VerKeyDSIGN v
vk
        -- No CBOR testing for SignKey: sign keys are stored in MLocked memory
        -- and require IO for access.
         String
-> (Message -> PinnedSizedBytes (SeedSizeDSIGN v) -> Property)
-> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"Sig" ((Message -> PinnedSizedBytes (SeedSizeDSIGN v) -> Property)
 -> Spec)
-> (Message -> PinnedSizedBytes (SeedSizeDSIGN v) -> Property)
-> Spec
forall a b. (a -> b) -> a -> b
$ \(Message
msg :: Message) ->
            forall v a.
(Testable a, DSIGNMAlgorithm v) =>
Lock
-> (SignKeyDSIGNM v -> IO a)
-> PinnedSizedBytes (SeedSizeDSIGN v)
-> Property
ioPropertyWithSK @v Lock
lock ((SignKeyDSIGNM v -> IO Property)
 -> PinnedSizedBytes (SeedSizeDSIGN v) -> Property)
-> (SignKeyDSIGNM v -> IO Property)
-> PinnedSizedBytes (SeedSizeDSIGN v)
-> Property
forall a b. (a -> b) -> a -> b
$ \SignKeyDSIGNM v
sk -> do
              SigDSIGN v
sig :: SigDSIGN v <- ContextDSIGN v -> Message -> SignKeyDSIGNM v -> IO (SigDSIGN v)
forall v a (m :: * -> *).
(DSIGNMAlgorithm v, Signable v a, MonadST m, MonadThrow m) =>
ContextDSIGN v -> a -> SignKeyDSIGNM v -> m (SigDSIGN v)
forall a (m :: * -> *).
(Signable v a, MonadST m, MonadThrow m) =>
ContextDSIGN v -> a -> SignKeyDSIGNM v -> m (SigDSIGN v)
signDSIGNM () Message
msg SignKeyDSIGNM v
sk
              Property -> IO Property
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Property -> IO Property) -> Property -> IO Property
forall a b. (a -> b) -> a -> b
$ (SigDSIGN v -> Encoding) -> SigDSIGN v -> Property
forall a. ToCBOR a => (a -> Encoding) -> a -> Property
prop_cbor_direct_vs_class SigDSIGN v -> Encoding
forall v. DSIGNAlgorithm v => SigDSIGN v -> Encoding
encodeSigDSIGN SigDSIGN v
sig
       String -> Spec -> Spec
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"DirectSerialise" (Spec -> Spec) -> Spec -> Spec
forall a b. (a -> b) -> a -> b
$ do
         String -> (PinnedSizedBytes (SeedSizeDSIGN v) -> Property) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"VerKey" ((PinnedSizedBytes (SeedSizeDSIGN v) -> Property) -> Spec)
-> (PinnedSizedBytes (SeedSizeDSIGN v) -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$
            forall v a.
(Testable a, DSIGNMAlgorithm v) =>
Lock
-> (SignKeyDSIGNM v -> IO a)
-> PinnedSizedBytes (SeedSizeDSIGN v)
-> Property
ioPropertyWithSK @v Lock
lock ((SignKeyDSIGNM v -> IO Property)
 -> PinnedSizedBytes (SeedSizeDSIGN v) -> Property)
-> (SignKeyDSIGNM v -> IO Property)
-> PinnedSizedBytes (SeedSizeDSIGN v)
-> Property
forall a b. (a -> b) -> a -> b
$ \SignKeyDSIGNM v
sk -> do
              VerKeyDSIGN v
vk :: VerKeyDSIGN v <- SignKeyDSIGNM v -> IO (VerKeyDSIGN v)
forall v (m :: * -> *).
(DSIGNMAlgorithm v, MonadThrow m, MonadST m) =>
SignKeyDSIGNM v -> m (VerKeyDSIGN v)
forall (m :: * -> *).
(MonadThrow m, MonadST m) =>
SignKeyDSIGNM v -> m (VerKeyDSIGN v)
deriveVerKeyDSIGNM SignKeyDSIGNM v
sk
              ByteString
serialized <- Int -> VerKeyDSIGN v -> IO ByteString
forall (m :: * -> *) a.
(DirectSerialise a, MonadST m, MonadThrow m) =>
Int -> a -> m ByteString
directSerialiseToBS (forall a b. (Integral a, Num b) => a -> b
fromIntegral @Word @Int (Word -> Int) -> Word -> Int
forall a b. (a -> b) -> a -> b
$ Proxy v -> Word
forall v (proxy :: * -> *). DSIGNAlgorithm v => proxy v -> Word
verKeySizeDSIGN (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @v)) VerKeyDSIGN v
vk
              VerKeyDSIGN v
vk' <- ByteString -> IO (VerKeyDSIGN v)
forall (m :: * -> *) a.
(DirectDeserialise a, MonadST m, MonadThrow m) =>
ByteString -> m a
directDeserialiseFromBS ByteString
serialized
              Property -> IO Property
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Property -> IO Property) -> Property -> IO Property
forall a b. (a -> b) -> a -> b
$ VerKeyDSIGN v
vk VerKeyDSIGN v -> VerKeyDSIGN v -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=== VerKeyDSIGN v
vk'
         String -> (PinnedSizedBytes (SeedSizeDSIGN v) -> Property) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"SignKey" ((PinnedSizedBytes (SeedSizeDSIGN v) -> Property) -> Spec)
-> (PinnedSizedBytes (SeedSizeDSIGN v) -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$
            forall v a.
(Testable a, DSIGNMAlgorithm v) =>
Lock
-> (SignKeyDSIGNM v -> IO a)
-> PinnedSizedBytes (SeedSizeDSIGN v)
-> Property
ioPropertyWithSK @v Lock
lock ((SignKeyDSIGNM v -> IO Property)
 -> PinnedSizedBytes (SeedSizeDSIGN v) -> Property)
-> (SignKeyDSIGNM v -> IO Property)
-> PinnedSizedBytes (SeedSizeDSIGN v)
-> Property
forall a b. (a -> b) -> a -> b
$ \SignKeyDSIGNM v
sk -> do
              ByteString
serialized <- Int -> SignKeyDSIGNM v -> IO ByteString
forall (m :: * -> *) a.
(DirectSerialise a, MonadST m, MonadThrow m) =>
Int -> a -> m ByteString
directSerialiseToBS (forall a b. (Integral a, Num b) => a -> b
fromIntegral @Word @Int (Word -> Int) -> Word -> Int
forall a b. (a -> b) -> a -> b
$ Proxy v -> Word
forall v (proxy :: * -> *). DSIGNAlgorithm v => proxy v -> Word
signKeySizeDSIGN (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @v)) SignKeyDSIGNM v
sk
              SignKeyDSIGNM v
sk' <- ByteString -> IO (SignKeyDSIGNM v)
forall (m :: * -> *) a.
(DirectDeserialise a, MonadST m, MonadThrow m) =>
ByteString -> m a
directDeserialiseFromBS ByteString
serialized
              Bool
equals <- SignKeyDSIGNM v
sk SignKeyDSIGNM v -> SignKeyDSIGNM v -> IO Bool
forall (m :: * -> *) a. (MonadST m, EqST a) => a -> a -> m Bool
==! SignKeyDSIGNM v
sk'
              SignKeyDSIGNM v -> IO ()
forall v (m :: * -> *).
(DSIGNMAlgorithm v, MonadST m, MonadThrow m) =>
SignKeyDSIGNM v -> m ()
forgetSignKeyDSIGNM SignKeyDSIGNM v
sk'
              Property -> IO Property
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Property -> IO Property) -> Property -> IO Property
forall a b. (a -> b) -> a -> b
$
                String -> Bool -> Property
forall prop. Testable prop => String -> prop -> Property
counterexample (String
"Serialized: " String -> String -> String
forall a. [a] -> [a] -> [a]
++ ByteString -> String
hexBS ByteString
serialized String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
" (length: " String -> String -> String
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show (ByteString -> Int
BS.length ByteString
serialized) String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
")") Bool
equals
       String -> Spec -> Spec
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"DirectSerialise matches raw" (Spec -> Spec) -> Spec -> Spec
forall a b. (a -> b) -> a -> b
$ do
         String -> (PinnedSizedBytes (SeedSizeDSIGN v) -> Property) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"VerKey" ((PinnedSizedBytes (SeedSizeDSIGN v) -> Property) -> Spec)
-> (PinnedSizedBytes (SeedSizeDSIGN v) -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$
            forall v a.
(Testable a, DSIGNMAlgorithm v) =>
Lock
-> (SignKeyDSIGNM v -> IO a)
-> PinnedSizedBytes (SeedSizeDSIGN v)
-> Property
ioPropertyWithSK @v Lock
lock ((SignKeyDSIGNM v -> IO Property)
 -> PinnedSizedBytes (SeedSizeDSIGN v) -> Property)
-> (SignKeyDSIGNM v -> IO Property)
-> PinnedSizedBytes (SeedSizeDSIGN v)
-> Property
forall a b. (a -> b) -> a -> b
$ \SignKeyDSIGNM v
sk -> do
              VerKeyDSIGN v
vk :: VerKeyDSIGN v <- SignKeyDSIGNM v -> IO (VerKeyDSIGN v)
forall v (m :: * -> *).
(DSIGNMAlgorithm v, MonadThrow m, MonadST m) =>
SignKeyDSIGNM v -> m (VerKeyDSIGN v)
forall (m :: * -> *).
(MonadThrow m, MonadST m) =>
SignKeyDSIGNM v -> m (VerKeyDSIGN v)
deriveVerKeyDSIGNM SignKeyDSIGNM v
sk
              ByteString
direct <- Int -> VerKeyDSIGN v -> IO ByteString
forall (m :: * -> *) a.
(DirectSerialise a, MonadST m, MonadThrow m) =>
Int -> a -> m ByteString
directSerialiseToBS (forall a b. (Integral a, Num b) => a -> b
fromIntegral @Word @Int (Word -> Int) -> Word -> Int
forall a b. (a -> b) -> a -> b
$ Proxy v -> Word
forall v (proxy :: * -> *). DSIGNAlgorithm v => proxy v -> Word
verKeySizeDSIGN (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @v)) VerKeyDSIGN v
vk
              let raw :: ByteString
raw = VerKeyDSIGN v -> ByteString
forall v. DSIGNAlgorithm v => VerKeyDSIGN v -> ByteString
rawSerialiseVerKeyDSIGN VerKeyDSIGN v
vk
              Property -> IO Property
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Property -> IO Property) -> Property -> IO Property
forall a b. (a -> b) -> a -> b
$ ByteString
direct ByteString -> ByteString -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=== ByteString
raw
         String -> (PinnedSizedBytes (SeedSizeDSIGN v) -> Property) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"SignKey" ((PinnedSizedBytes (SeedSizeDSIGN v) -> Property) -> Spec)
-> (PinnedSizedBytes (SeedSizeDSIGN v) -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$
            forall v a.
(Testable a, DSIGNMAlgorithm v) =>
Lock
-> (SignKeyDSIGNM v -> IO a)
-> PinnedSizedBytes (SeedSizeDSIGN v)
-> Property
ioPropertyWithSK @v Lock
lock ((SignKeyDSIGNM v -> IO Property)
 -> PinnedSizedBytes (SeedSizeDSIGN v) -> Property)
-> (SignKeyDSIGNM v -> IO Property)
-> PinnedSizedBytes (SeedSizeDSIGN v)
-> Property
forall a b. (a -> b) -> a -> b
$ \SignKeyDSIGNM v
sk -> do
              ByteString
direct <- Int -> SignKeyDSIGNM v -> IO ByteString
forall (m :: * -> *) a.
(DirectSerialise a, MonadST m, MonadThrow m) =>
Int -> a -> m ByteString
directSerialiseToBS (forall a b. (Integral a, Num b) => a -> b
fromIntegral @Word @Int (Word -> Int) -> Word -> Int
forall a b. (a -> b) -> a -> b
$ Proxy v -> Word
forall v (proxy :: * -> *). DSIGNAlgorithm v => proxy v -> Word
signKeySizeDSIGN (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @v)) SignKeyDSIGNM v
sk
              ByteString
raw <- SignKeyDSIGNM v -> IO ByteString
forall v (m :: * -> *).
(UnsoundDSIGNMAlgorithm v, MonadST m, MonadThrow m) =>
SignKeyDSIGNM v -> m ByteString
forall (m :: * -> *).
(MonadST m, MonadThrow m) =>
SignKeyDSIGNM v -> m ByteString
rawSerialiseSignKeyDSIGNM SignKeyDSIGNM v
sk
              Property -> IO Property
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Property -> IO Property) -> Property -> IO Property
forall a b. (a -> b) -> a -> b
$ ByteString
direct ByteString -> ByteString -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=== ByteString
raw

     String -> Spec -> Spec
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"verify" (Spec -> Spec) -> Spec -> Spec
forall a b. (a -> b) -> a -> b
$ do
       String
-> (Message -> PinnedSizedBytes (SeedSizeDSIGN v) -> Property)
-> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"verify positive" ((Message -> PinnedSizedBytes (SeedSizeDSIGN v) -> Property)
 -> Spec)
-> (Message -> PinnedSizedBytes (SeedSizeDSIGN v) -> Property)
-> Spec
forall a b. (a -> b) -> a -> b
$
          Lock
-> Proxy v
-> Message
-> PinnedSizedBytes (SeedSizeDSIGN v)
-> Property
forall v.
(DSIGNMAlgorithm v, ContextDSIGN v ~ (), Signable v Message) =>
Lock
-> Proxy v
-> Message
-> PinnedSizedBytes (SeedSizeDSIGN v)
-> Property
prop_dsignm_verify_pos Lock
lock (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @v)
       String
-> (Message
    -> PinnedSizedBytes (SeedSizeDSIGN v)
    -> PinnedSizedBytes (SeedSizeDSIGN v)
    -> Property)
-> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"verify negative (wrong key)" ((Message
  -> PinnedSizedBytes (SeedSizeDSIGN v)
  -> PinnedSizedBytes (SeedSizeDSIGN v)
  -> Property)
 -> Spec)
-> (Message
    -> PinnedSizedBytes (SeedSizeDSIGN v)
    -> PinnedSizedBytes (SeedSizeDSIGN v)
    -> Property)
-> Spec
forall a b. (a -> b) -> a -> b
$
          Lock
-> Proxy v
-> Message
-> PinnedSizedBytes (SeedSizeDSIGN v)
-> PinnedSizedBytes (SeedSizeDSIGN v)
-> Property
forall v.
(DSIGNMAlgorithm v, ContextDSIGN v ~ (), Signable v Message) =>
Lock
-> Proxy v
-> Message
-> PinnedSizedBytes (SeedSizeDSIGN v)
-> PinnedSizedBytes (SeedSizeDSIGN v)
-> Property
prop_dsignm_verify_neg_key Lock
lock (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @v)
       String
-> (Message
    -> Message -> PinnedSizedBytes (SeedSizeDSIGN v) -> Property)
-> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"verify negative (wrong message)" ((Message
  -> Message -> PinnedSizedBytes (SeedSizeDSIGN v) -> Property)
 -> Spec)
-> (Message
    -> Message -> PinnedSizedBytes (SeedSizeDSIGN v) -> Property)
-> Spec
forall a b. (a -> b) -> a -> b
$
          Lock
-> Proxy v
-> Message
-> Message
-> PinnedSizedBytes (SeedSizeDSIGN v)
-> Property
forall v.
(DSIGNMAlgorithm v, ContextDSIGN v ~ (), Signable v Message) =>
Lock
-> Proxy v
-> Message
-> Message
-> PinnedSizedBytes (SeedSizeDSIGN v)
-> Property
prop_dsignm_verify_neg_msg Lock
lock (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @v)

     String -> Spec -> Spec
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"seed extraction" (Spec -> Spec) -> Spec -> Spec
forall a b. (a -> b) -> a -> b
$ do
       String -> (PinnedSizedBytes (SeedSizeDSIGN v) -> Property) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"extracted seed equals original seed" ((PinnedSizedBytes (SeedSizeDSIGN v) -> Property) -> Spec)
-> (PinnedSizedBytes (SeedSizeDSIGN v) -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$ Proxy v -> PinnedSizedBytes (SeedSizeDSIGN v) -> Property
forall v.
DSIGNMAlgorithm v =>
Proxy v -> PinnedSizedBytes (SeedSizeDSIGN v) -> Property
prop_dsignm_seed_roundtrip (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @v)

     String -> Spec -> Spec
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"forgetting" (Spec -> Spec) -> Spec -> Spec
forall a b. (a -> b) -> a -> b
$ do
       String -> (PinnedSizedBytes (SeedSizeDSIGN v) -> Property) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"key overwritten after forget" ((PinnedSizedBytes (SeedSizeDSIGN v) -> Property) -> Spec)
-> (PinnedSizedBytes (SeedSizeDSIGN v) -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$ Proxy v -> PinnedSizedBytes (SeedSizeDSIGN v) -> Property
forall v.
DSIGNMAlgorithm v =>
Proxy v -> PinnedSizedBytes (SeedSizeDSIGN v) -> Property
prop_key_overwritten_after_forget (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @v)

     String -> Spec -> Spec
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"NoThunks" (Spec -> Spec) -> Spec -> Spec
forall a b. (a -> b) -> a -> b
$ do
       String -> (PinnedSizedBytes (SeedSizeDSIGN v) -> Property) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"VerKey" ((PinnedSizedBytes (SeedSizeDSIGN v) -> Property) -> Spec)
-> (PinnedSizedBytes (SeedSizeDSIGN v) -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$
          forall v a.
(Testable a, DSIGNMAlgorithm v) =>
Lock
-> (SignKeyDSIGNM v -> IO a)
-> PinnedSizedBytes (SeedSizeDSIGN v)
-> Property
ioPropertyWithSK @v Lock
lock ((SignKeyDSIGNM v -> IO Property)
 -> PinnedSizedBytes (SeedSizeDSIGN v) -> Property)
-> (SignKeyDSIGNM v -> IO Property)
-> PinnedSizedBytes (SeedSizeDSIGN v)
-> Property
forall a b. (a -> b) -> a -> b
$ \SignKeyDSIGNM v
sk -> IO (VerKeyDSIGN v) -> IO Property
forall a. NoThunks a => IO a -> IO Property
prop_no_thunks_IO (SignKeyDSIGNM v -> IO (VerKeyDSIGN v)
forall v (m :: * -> *).
(DSIGNMAlgorithm v, MonadThrow m, MonadST m) =>
SignKeyDSIGNM v -> m (VerKeyDSIGN v)
forall (m :: * -> *).
(MonadThrow m, MonadST m) =>
SignKeyDSIGNM v -> m (VerKeyDSIGN v)
deriveVerKeyDSIGNM SignKeyDSIGNM v
sk)
       String -> (PinnedSizedBytes (SeedSizeDSIGN v) -> Property) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"SignKey" ((PinnedSizedBytes (SeedSizeDSIGN v) -> Property) -> Spec)
-> (PinnedSizedBytes (SeedSizeDSIGN v) -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$
          forall v a.
(Testable a, DSIGNMAlgorithm v) =>
Lock
-> (SignKeyDSIGNM v -> IO a)
-> PinnedSizedBytes (SeedSizeDSIGN v)
-> Property
ioPropertyWithSK @v Lock
lock ((SignKeyDSIGNM v -> IO Property)
 -> PinnedSizedBytes (SeedSizeDSIGN v) -> Property)
-> (SignKeyDSIGNM v -> IO Property)
-> PinnedSizedBytes (SeedSizeDSIGN v)
-> Property
forall a b. (a -> b) -> a -> b
$ IO (SignKeyDSIGNM v) -> IO Property
forall a. NoThunks a => IO a -> IO Property
prop_no_thunks_IO (IO (SignKeyDSIGNM v) -> IO Property)
-> (SignKeyDSIGNM v -> IO (SignKeyDSIGNM v))
-> SignKeyDSIGNM v
-> IO Property
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SignKeyDSIGNM v -> IO (SignKeyDSIGNM v)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return
       String
-> (Message -> PinnedSizedBytes (SeedSizeDSIGN v) -> Property)
-> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"Sig"     ((Message -> PinnedSizedBytes (SeedSizeDSIGN v) -> Property)
 -> Spec)
-> (Message -> PinnedSizedBytes (SeedSizeDSIGN v) -> Property)
-> Spec
forall a b. (a -> b) -> a -> b
$ \(Message
msg :: Message) ->
          forall v a.
(Testable a, DSIGNMAlgorithm v) =>
Lock
-> (SignKeyDSIGNM v -> IO a)
-> PinnedSizedBytes (SeedSizeDSIGN v)
-> Property
ioPropertyWithSK @v Lock
lock ((SignKeyDSIGNM v -> IO Property)
 -> PinnedSizedBytes (SeedSizeDSIGN v) -> Property)
-> (SignKeyDSIGNM v -> IO Property)
-> PinnedSizedBytes (SeedSizeDSIGN v)
-> Property
forall a b. (a -> b) -> a -> b
$ IO (SigDSIGN v) -> IO Property
forall a. NoThunks a => IO a -> IO Property
prop_no_thunks_IO (IO (SigDSIGN v) -> IO Property)
-> (SignKeyDSIGNM v -> IO (SigDSIGN v))
-> SignKeyDSIGNM v
-> IO Property
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ContextDSIGN v -> Message -> SignKeyDSIGNM v -> IO (SigDSIGN v)
forall v a (m :: * -> *).
(DSIGNMAlgorithm v, Signable v a, MonadST m, MonadThrow m) =>
ContextDSIGN v -> a -> SignKeyDSIGNM v -> m (SigDSIGN v)
forall a (m :: * -> *).
(Signable v a, MonadST m, MonadThrow m) =>
ContextDSIGN v -> a -> SignKeyDSIGNM v -> m (SigDSIGN v)
signDSIGNM () Message
msg
       String -> (PinnedSizedBytes (SeedSizeDSIGN v) -> Property) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"SignKey DirectSerialise" ((PinnedSizedBytes (SeedSizeDSIGN v) -> Property) -> Spec)
-> (PinnedSizedBytes (SeedSizeDSIGN v) -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$
          forall v a.
(Testable a, DSIGNMAlgorithm v) =>
Lock
-> (SignKeyDSIGNM v -> IO a)
-> PinnedSizedBytes (SeedSizeDSIGN v)
-> Property
ioPropertyWithSK @v Lock
lock ((SignKeyDSIGNM v -> IO Property)
 -> PinnedSizedBytes (SeedSizeDSIGN v) -> Property)
-> (SignKeyDSIGNM v -> IO Property)
-> PinnedSizedBytes (SeedSizeDSIGN v)
-> Property
forall a b. (a -> b) -> a -> b
$ \SignKeyDSIGNM v
sk -> do
            ByteString
direct <- Int -> SignKeyDSIGNM v -> IO ByteString
forall (m :: * -> *) a.
(DirectSerialise a, MonadST m, MonadThrow m) =>
Int -> a -> m ByteString
directSerialiseToBS (forall a b. (Integral a, Num b) => a -> b
fromIntegral @Word @Int (Word -> Int) -> Word -> Int
forall a b. (a -> b) -> a -> b
$ Proxy v -> Word
forall v (proxy :: * -> *). DSIGNAlgorithm v => proxy v -> Word
signKeySizeDSIGN (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @v)) SignKeyDSIGNM v
sk
            IO ByteString -> IO Property
forall a. NoThunks a => IO a -> IO Property
prop_no_thunks_IO (ByteString -> IO ByteString
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (ByteString -> IO ByteString) -> ByteString -> IO ByteString
forall a b. (a -> b) -> a -> b
$! ByteString
direct)
       String -> (PinnedSizedBytes (SeedSizeDSIGN v) -> Property) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"SignKey DirectDeserialise" ((PinnedSizedBytes (SeedSizeDSIGN v) -> Property) -> Spec)
-> (PinnedSizedBytes (SeedSizeDSIGN v) -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$
          forall v a.
(Testable a, DSIGNMAlgorithm v) =>
Lock
-> (SignKeyDSIGNM v -> IO a)
-> PinnedSizedBytes (SeedSizeDSIGN v)
-> Property
ioPropertyWithSK @v Lock
lock ((SignKeyDSIGNM v -> IO Property)
 -> PinnedSizedBytes (SeedSizeDSIGN v) -> Property)
-> (SignKeyDSIGNM v -> IO Property)
-> PinnedSizedBytes (SeedSizeDSIGN v)
-> Property
forall a b. (a -> b) -> a -> b
$ \SignKeyDSIGNM v
sk -> do
            ByteString
direct <- Int -> SignKeyDSIGNM v -> IO ByteString
forall (m :: * -> *) a.
(DirectSerialise a, MonadST m, MonadThrow m) =>
Int -> a -> m ByteString
directSerialiseToBS (forall a b. (Integral a, Num b) => a -> b
fromIntegral @Word @Int (Word -> Int) -> Word -> Int
forall a b. (a -> b) -> a -> b
$ Proxy v -> Word
forall v (proxy :: * -> *). DSIGNAlgorithm v => proxy v -> Word
signKeySizeDSIGN (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @v)) SignKeyDSIGNM v
sk
            IO (SignKeyDSIGNM v) -> IO Property
forall a. NoThunks a => IO a -> IO Property
prop_no_thunks_IO (forall (m :: * -> *) a.
(DirectDeserialise a, MonadST m, MonadThrow m) =>
ByteString -> m a
directDeserialiseFromBS @IO @(SignKeyDSIGNM v) (ByteString -> IO (SignKeyDSIGNM v))
-> ByteString -> IO (SignKeyDSIGNM v)
forall a b. (a -> b) -> a -> b
$! ByteString
direct)
       String -> (PinnedSizedBytes (SeedSizeDSIGN v) -> Property) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"VerKey DirectSerialise" ((PinnedSizedBytes (SeedSizeDSIGN v) -> Property) -> Spec)
-> (PinnedSizedBytes (SeedSizeDSIGN v) -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$
          forall v a.
(Testable a, DSIGNMAlgorithm v) =>
Lock
-> (SignKeyDSIGNM v -> IO a)
-> PinnedSizedBytes (SeedSizeDSIGN v)
-> Property
ioPropertyWithSK @v Lock
lock ((SignKeyDSIGNM v -> IO Property)
 -> PinnedSizedBytes (SeedSizeDSIGN v) -> Property)
-> (SignKeyDSIGNM v -> IO Property)
-> PinnedSizedBytes (SeedSizeDSIGN v)
-> Property
forall a b. (a -> b) -> a -> b
$ \SignKeyDSIGNM v
sk -> do
            VerKeyDSIGN v
vk <- SignKeyDSIGNM v -> IO (VerKeyDSIGN v)
forall v (m :: * -> *).
(DSIGNMAlgorithm v, MonadThrow m, MonadST m) =>
SignKeyDSIGNM v -> m (VerKeyDSIGN v)
forall (m :: * -> *).
(MonadThrow m, MonadST m) =>
SignKeyDSIGNM v -> m (VerKeyDSIGN v)
deriveVerKeyDSIGNM SignKeyDSIGNM v
sk
            ByteString
direct <- Int -> VerKeyDSIGN v -> IO ByteString
forall (m :: * -> *) a.
(DirectSerialise a, MonadST m, MonadThrow m) =>
Int -> a -> m ByteString
directSerialiseToBS (forall a b. (Integral a, Num b) => a -> b
fromIntegral @Word @Int (Word -> Int) -> Word -> Int
forall a b. (a -> b) -> a -> b
$ Proxy v -> Word
forall v (proxy :: * -> *). DSIGNAlgorithm v => proxy v -> Word
verKeySizeDSIGN (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @v)) VerKeyDSIGN v
vk
            IO ByteString -> IO Property
forall a. NoThunks a => IO a -> IO Property
prop_no_thunks_IO (ByteString -> IO ByteString
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (ByteString -> IO ByteString) -> ByteString -> IO ByteString
forall a b. (a -> b) -> a -> b
$! ByteString
direct)
       String -> (PinnedSizedBytes (SeedSizeDSIGN v) -> Property) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"VerKey DirectDeserialise" ((PinnedSizedBytes (SeedSizeDSIGN v) -> Property) -> Spec)
-> (PinnedSizedBytes (SeedSizeDSIGN v) -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$
          forall v a.
(Testable a, DSIGNMAlgorithm v) =>
Lock
-> (SignKeyDSIGNM v -> IO a)
-> PinnedSizedBytes (SeedSizeDSIGN v)
-> Property
ioPropertyWithSK @v Lock
lock ((SignKeyDSIGNM v -> IO Property)
 -> PinnedSizedBytes (SeedSizeDSIGN v) -> Property)
-> (SignKeyDSIGNM v -> IO Property)
-> PinnedSizedBytes (SeedSizeDSIGN v)
-> Property
forall a b. (a -> b) -> a -> b
$ \SignKeyDSIGNM v
sk -> do
            VerKeyDSIGN v
vk <- SignKeyDSIGNM v -> IO (VerKeyDSIGN v)
forall v (m :: * -> *).
(DSIGNMAlgorithm v, MonadThrow m, MonadST m) =>
SignKeyDSIGNM v -> m (VerKeyDSIGN v)
forall (m :: * -> *).
(MonadThrow m, MonadST m) =>
SignKeyDSIGNM v -> m (VerKeyDSIGN v)
deriveVerKeyDSIGNM SignKeyDSIGNM v
sk
            ByteString
direct <- Int -> VerKeyDSIGN v -> IO ByteString
forall (m :: * -> *) a.
(DirectSerialise a, MonadST m, MonadThrow m) =>
Int -> a -> m ByteString
directSerialiseToBS (forall a b. (Integral a, Num b) => a -> b
fromIntegral @Word @Int (Word -> Int) -> Word -> Int
forall a b. (a -> b) -> a -> b
$ Proxy v -> Word
forall v (proxy :: * -> *). DSIGNAlgorithm v => proxy v -> Word
verKeySizeDSIGN (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @v)) VerKeyDSIGN v
vk
            IO (VerKeyDSIGN v) -> IO Property
forall a. NoThunks a => IO a -> IO Property
prop_no_thunks_IO (forall (m :: * -> *) a.
(DirectDeserialise a, MonadST m, MonadThrow m) =>
ByteString -> m a
directDeserialiseFromBS @IO @(VerKeyDSIGN v) (ByteString -> IO (VerKeyDSIGN v))
-> ByteString -> IO (VerKeyDSIGN v)
forall a b. (a -> b) -> a -> b
$! ByteString
direct)

-- | Wrap an IO action that requires a 'SignKeyDSIGNM' into one that takes an
-- mlocked seed to generate the key from. The key is bracketed off to ensure
-- timely forgetting. Special care must be taken to not leak the key outside of
-- the wrapped action (be particularly mindful of thunks and unsafe key access
-- here).
withSK :: (DSIGNMAlgorithm v) => PinnedSizedBytes (SeedSizeDSIGN v) -> (SignKeyDSIGNM v -> IO b) -> IO b
withSK :: forall v b.
DSIGNMAlgorithm v =>
PinnedSizedBytes (SeedSizeDSIGN v)
-> (SignKeyDSIGNM v -> IO b) -> IO b
withSK PinnedSizedBytes (SeedSizeDSIGN v)
seedPSB SignKeyDSIGNM v -> IO b
action =
  PinnedSizedBytes (SeedSizeDSIGN v)
-> (MLockedSeed (SeedSizeDSIGN v) -> IO b) -> IO b
forall (m :: * -> *) (n :: Nat) a.
(MonadST m, MonadThrow m, KnownNat n) =>
PinnedSizedBytes n -> (MLockedSeed n -> m a) -> m a
withMLockedSeedFromPSB PinnedSizedBytes (SeedSizeDSIGN v)
seedPSB ((MLockedSeed (SeedSizeDSIGN v) -> IO b) -> IO b)
-> (MLockedSeed (SeedSizeDSIGN v) -> IO b) -> IO b
forall a b. (a -> b) -> a -> b
$ \MLockedSeed (SeedSizeDSIGN v)
seed ->
    IO (SignKeyDSIGNM v)
-> (SignKeyDSIGNM v -> IO ()) -> (SignKeyDSIGNM v -> IO b) -> IO b
forall a b c. IO a -> (a -> IO b) -> (a -> IO c) -> IO c
bracket
      (MLockedSeed (SeedSizeDSIGN v) -> IO (SignKeyDSIGNM v)
forall v (m :: * -> *).
(DSIGNMAlgorithm v, MonadST m, MonadThrow m) =>
MLockedSeed (SeedSizeDSIGN v) -> m (SignKeyDSIGNM v)
genKeyDSIGNM MLockedSeed (SeedSizeDSIGN v)
seed)
      SignKeyDSIGNM v -> IO ()
forall v (m :: * -> *).
(DSIGNMAlgorithm v, MonadST m, MonadThrow m) =>
SignKeyDSIGNM v -> m ()
forgetSignKeyDSIGNM
      SignKeyDSIGNM v -> IO b
action

-- | Wrap an IO action that requires a 'SignKeyDSIGNM' into a 'Property' that
-- takes a non-mlocked seed (provided as a 'PinnedSizedBytes' of the
-- appropriate size). The key, and the mlocked seed necessary to generate it,
-- are bracketed off, to ensure timely forgetting and avoid leaking mlocked
-- memory. Special care must be taken to not leak the key outside of the
-- wrapped action (be particularly mindful of thunks and unsafe key access
-- here).
ioPropertyWithSK :: forall v a. (Testable a, DSIGNMAlgorithm v)
                 => Lock
                 -> (SignKeyDSIGNM v -> IO a)
                 -> PinnedSizedBytes (SeedSizeDSIGN v)
                 -> Property
ioPropertyWithSK :: forall v a.
(Testable a, DSIGNMAlgorithm v) =>
Lock
-> (SignKeyDSIGNM v -> IO a)
-> PinnedSizedBytes (SeedSizeDSIGN v)
-> Property
ioPropertyWithSK Lock
lock SignKeyDSIGNM v -> IO a
action PinnedSizedBytes (SeedSizeDSIGN v)
seedPSB =
  IO a -> Property
forall prop. Testable prop => IO prop -> Property
ioProperty (IO a -> Property) -> (IO a -> IO a) -> IO a -> Property
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Lock -> IO a -> IO a
forall a. Lock -> IO a -> IO a
withLock Lock
lock (IO a -> Property) -> IO a -> Property
forall a b. (a -> b) -> a -> b
$ PinnedSizedBytes (SeedSizeDSIGN v)
-> (SignKeyDSIGNM v -> IO a) -> IO a
forall v b.
DSIGNMAlgorithm v =>
PinnedSizedBytes (SeedSizeDSIGN v)
-> (SignKeyDSIGNM v -> IO b) -> IO b
withSK PinnedSizedBytes (SeedSizeDSIGN v)
seedPSB SignKeyDSIGNM v -> IO a
action

prop_key_overwritten_after_forget
  :: forall v.
     (DSIGNMAlgorithm v
     )
  => Proxy v
  -> PinnedSizedBytes (SeedSizeDSIGN v)
  -> Property
prop_key_overwritten_after_forget :: forall v.
DSIGNMAlgorithm v =>
Proxy v -> PinnedSizedBytes (SeedSizeDSIGN v) -> Property
prop_key_overwritten_after_forget Proxy v
p PinnedSizedBytes (SeedSizeDSIGN v)
seedPSB =
  IO Property -> Property
forall prop. Testable prop => IO prop -> Property
ioProperty (IO Property -> Property)
-> ((MLockedSeed (SeedSizeDSIGN v) -> IO Property) -> IO Property)
-> (MLockedSeed (SeedSizeDSIGN v) -> IO Property)
-> Property
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PinnedSizedBytes (SeedSizeDSIGN v)
-> (MLockedSeed (SeedSizeDSIGN v) -> IO Property) -> IO Property
forall (m :: * -> *) (n :: Nat) a.
(MonadST m, MonadThrow m, KnownNat n) =>
PinnedSizedBytes n -> (MLockedSeed n -> m a) -> m a
withMLockedSeedFromPSB PinnedSizedBytes (SeedSizeDSIGN v)
seedPSB ((MLockedSeed (SeedSizeDSIGN v) -> IO Property) -> Property)
-> (MLockedSeed (SeedSizeDSIGN v) -> IO Property) -> Property
forall a b. (a -> b) -> a -> b
$ \MLockedSeed (SeedSizeDSIGN v)
seed -> do
    SignKeyDSIGNM v
sk <- MLockedSeed (SeedSizeDSIGN v) -> IO (SignKeyDSIGNM v)
forall v (m :: * -> *).
(DSIGNMAlgorithm v, MonadST m, MonadThrow m) =>
MLockedSeed (SeedSizeDSIGN v) -> m (SignKeyDSIGNM v)
genKeyDSIGNM MLockedSeed (SeedSizeDSIGN v)
seed
    MLockedSeed (SeedSizeDSIGN v) -> IO ()
forall (m :: * -> *) (n :: Nat). MonadST m => MLockedSeed n -> m ()
mlockedSeedFinalize MLockedSeed (SeedSizeDSIGN v)
seed

    MLockedSeed (SeedSizeDSIGN v)
seedBefore <- Proxy v -> SignKeyDSIGNM v -> IO (MLockedSeed (SeedSizeDSIGN v))
forall v (m :: * -> *).
(DSIGNMAlgorithm v, MonadST m, MonadThrow m) =>
Proxy v -> SignKeyDSIGNM v -> m (MLockedSeed (SeedSizeDSIGN v))
getSeedDSIGNM Proxy v
p SignKeyDSIGNM v
sk
    ByteString
bsBefore <- MLockedSizedBytes (SeedSizeDSIGN v) -> IO ByteString
forall (n :: Nat) (m :: * -> *).
(KnownNat n, MonadST m) =>
MLockedSizedBytes n -> m ByteString
mlsbToByteString (MLockedSizedBytes (SeedSizeDSIGN v) -> IO ByteString)
-> (MLockedSeed (SeedSizeDSIGN v)
    -> MLockedSizedBytes (SeedSizeDSIGN v))
-> MLockedSeed (SeedSizeDSIGN v)
-> IO ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MLockedSeed (SeedSizeDSIGN v)
-> MLockedSizedBytes (SeedSizeDSIGN v)
forall (n :: Nat). MLockedSeed n -> MLockedSizedBytes n
mlockedSeedMLSB (MLockedSeed (SeedSizeDSIGN v) -> IO ByteString)
-> MLockedSeed (SeedSizeDSIGN v) -> IO ByteString
forall a b. (a -> b) -> a -> b
$ MLockedSeed (SeedSizeDSIGN v)
seedBefore
    MLockedSeed (SeedSizeDSIGN v) -> IO ()
forall (m :: * -> *) (n :: Nat). MonadST m => MLockedSeed n -> m ()
mlockedSeedFinalize MLockedSeed (SeedSizeDSIGN v)
seedBefore

    SignKeyDSIGNM v -> IO ()
forall v (m :: * -> *).
(DSIGNMAlgorithm v, MonadST m, MonadThrow m) =>
SignKeyDSIGNM v -> m ()
forgetSignKeyDSIGNM SignKeyDSIGNM v
sk

    MLockedSeed (SeedSizeDSIGN v)
seedAfter <- Proxy v -> SignKeyDSIGNM v -> IO (MLockedSeed (SeedSizeDSIGN v))
forall v (m :: * -> *).
(DSIGNMAlgorithm v, MonadST m, MonadThrow m) =>
Proxy v -> SignKeyDSIGNM v -> m (MLockedSeed (SeedSizeDSIGN v))
getSeedDSIGNM Proxy v
p SignKeyDSIGNM v
sk
    ByteString
bsAfter <- MLockedSizedBytes (SeedSizeDSIGN v) -> IO ByteString
forall (n :: Nat) (m :: * -> *).
(KnownNat n, MonadST m) =>
MLockedSizedBytes n -> m ByteString
mlsbToByteString (MLockedSizedBytes (SeedSizeDSIGN v) -> IO ByteString)
-> (MLockedSeed (SeedSizeDSIGN v)
    -> MLockedSizedBytes (SeedSizeDSIGN v))
-> MLockedSeed (SeedSizeDSIGN v)
-> IO ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MLockedSeed (SeedSizeDSIGN v)
-> MLockedSizedBytes (SeedSizeDSIGN v)
forall (n :: Nat). MLockedSeed n -> MLockedSizedBytes n
mlockedSeedMLSB (MLockedSeed (SeedSizeDSIGN v) -> IO ByteString)
-> MLockedSeed (SeedSizeDSIGN v) -> IO ByteString
forall a b. (a -> b) -> a -> b
$ MLockedSeed (SeedSizeDSIGN v)
seedAfter
    MLockedSeed (SeedSizeDSIGN v) -> IO ()
forall (m :: * -> *) (n :: Nat). MonadST m => MLockedSeed n -> m ()
mlockedSeedFinalize MLockedSeed (SeedSizeDSIGN v)
seedAfter

    Property -> IO Property
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (ByteString
bsBefore ByteString -> ByteString -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=/= ByteString
bsAfter)

prop_dsignm_seed_roundtrip
  :: forall v.
     ( DSIGNMAlgorithm v
     )
  => Proxy v
  -> PinnedSizedBytes (SeedSizeDSIGN v)
  -> Property
prop_dsignm_seed_roundtrip :: forall v.
DSIGNMAlgorithm v =>
Proxy v -> PinnedSizedBytes (SeedSizeDSIGN v) -> Property
prop_dsignm_seed_roundtrip Proxy v
p PinnedSizedBytes (SeedSizeDSIGN v)
seedPSB = IO Property -> Property
forall prop. Testable prop => IO prop -> Property
ioProperty (IO Property -> Property)
-> ((MLockedSeed (SeedSizeDSIGN v) -> IO Property) -> IO Property)
-> (MLockedSeed (SeedSizeDSIGN v) -> IO Property)
-> Property
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PinnedSizedBytes (SeedSizeDSIGN v)
-> (MLockedSeed (SeedSizeDSIGN v) -> IO Property) -> IO Property
forall (m :: * -> *) (n :: Nat) a.
(MonadST m, MonadThrow m, KnownNat n) =>
PinnedSizedBytes n -> (MLockedSeed n -> m a) -> m a
withMLockedSeedFromPSB PinnedSizedBytes (SeedSizeDSIGN v)
seedPSB ((MLockedSeed (SeedSizeDSIGN v) -> IO Property) -> Property)
-> (MLockedSeed (SeedSizeDSIGN v) -> IO Property) -> Property
forall a b. (a -> b) -> a -> b
$ \MLockedSeed (SeedSizeDSIGN v)
seed -> do
  SignKeyDSIGNM v
sk <- MLockedSeed (SeedSizeDSIGN v) -> IO (SignKeyDSIGNM v)
forall v (m :: * -> *).
(DSIGNMAlgorithm v, MonadST m, MonadThrow m) =>
MLockedSeed (SeedSizeDSIGN v) -> m (SignKeyDSIGNM v)
genKeyDSIGNM MLockedSeed (SeedSizeDSIGN v)
seed
  MLockedSeed (SeedSizeDSIGN v)
seed' <- Proxy v -> SignKeyDSIGNM v -> IO (MLockedSeed (SeedSizeDSIGN v))
forall v (m :: * -> *).
(DSIGNMAlgorithm v, MonadST m, MonadThrow m) =>
Proxy v -> SignKeyDSIGNM v -> m (MLockedSeed (SeedSizeDSIGN v))
getSeedDSIGNM Proxy v
p SignKeyDSIGNM v
sk
  ByteString
bs <- MLockedSizedBytes (SeedSizeDSIGN v) -> IO ByteString
forall (n :: Nat) (m :: * -> *).
(KnownNat n, MonadST m) =>
MLockedSizedBytes n -> m ByteString
mlsbToByteString (MLockedSizedBytes (SeedSizeDSIGN v) -> IO ByteString)
-> (MLockedSeed (SeedSizeDSIGN v)
    -> MLockedSizedBytes (SeedSizeDSIGN v))
-> MLockedSeed (SeedSizeDSIGN v)
-> IO ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MLockedSeed (SeedSizeDSIGN v)
-> MLockedSizedBytes (SeedSizeDSIGN v)
forall (n :: Nat). MLockedSeed n -> MLockedSizedBytes n
mlockedSeedMLSB (MLockedSeed (SeedSizeDSIGN v) -> IO ByteString)
-> MLockedSeed (SeedSizeDSIGN v) -> IO ByteString
forall a b. (a -> b) -> a -> b
$ MLockedSeed (SeedSizeDSIGN v)
seed
  ByteString
bs' <- MLockedSizedBytes (SeedSizeDSIGN v) -> IO ByteString
forall (n :: Nat) (m :: * -> *).
(KnownNat n, MonadST m) =>
MLockedSizedBytes n -> m ByteString
mlsbToByteString (MLockedSizedBytes (SeedSizeDSIGN v) -> IO ByteString)
-> (MLockedSeed (SeedSizeDSIGN v)
    -> MLockedSizedBytes (SeedSizeDSIGN v))
-> MLockedSeed (SeedSizeDSIGN v)
-> IO ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MLockedSeed (SeedSizeDSIGN v)
-> MLockedSizedBytes (SeedSizeDSIGN v)
forall (n :: Nat). MLockedSeed n -> MLockedSizedBytes n
mlockedSeedMLSB (MLockedSeed (SeedSizeDSIGN v) -> IO ByteString)
-> MLockedSeed (SeedSizeDSIGN v) -> IO ByteString
forall a b. (a -> b) -> a -> b
$ MLockedSeed (SeedSizeDSIGN v)
seed'
  SignKeyDSIGNM v -> IO ()
forall v (m :: * -> *).
(DSIGNMAlgorithm v, MonadST m, MonadThrow m) =>
SignKeyDSIGNM v -> m ()
forgetSignKeyDSIGNM SignKeyDSIGNM v
sk
  MLockedSeed (SeedSizeDSIGN v) -> IO ()
forall (m :: * -> *) (n :: Nat). MonadST m => MLockedSeed n -> m ()
mlockedSeedFinalize MLockedSeed (SeedSizeDSIGN v)
seed'
  Property -> IO Property
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (ByteString
bs ByteString -> ByteString -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=== ByteString
bs')

-- If we sign a message with the key, we can verify the signature with the
-- corresponding verification key.
prop_dsign_verify
  :: forall (v :: Type) (a :: Type) .
     ( DSIGNAlgorithm v
     , Signable v a
     )
  => (ContextDSIGN v,a, SignKeyDSIGN v)
  -> Property
prop_dsign_verify :: forall v a.
(DSIGNAlgorithm v, Signable v a) =>
(ContextDSIGN v, a, SignKeyDSIGN v) -> Property
prop_dsign_verify (ContextDSIGN v
ctx, a
msg, SignKeyDSIGN v
sk) =
  let signed :: SigDSIGN v
signed = ContextDSIGN v -> a -> SignKeyDSIGN v -> SigDSIGN v
forall v a.
(DSIGNAlgorithm v, Signable v a, HasCallStack) =>
ContextDSIGN v -> a -> SignKeyDSIGN v -> SigDSIGN v
forall a.
(Signable v a, HasCallStack) =>
ContextDSIGN v -> a -> SignKeyDSIGN v -> SigDSIGN v
signDSIGN ContextDSIGN v
ctx a
msg SignKeyDSIGN v
sk
      vk :: VerKeyDSIGN v
vk = SignKeyDSIGN v -> VerKeyDSIGN v
forall v. DSIGNAlgorithm v => SignKeyDSIGN v -> VerKeyDSIGN v
deriveVerKeyDSIGN SignKeyDSIGN v
sk
    in ContextDSIGN v
-> VerKeyDSIGN v -> a -> SigDSIGN v -> Either String ()
forall v a.
(DSIGNAlgorithm v, Signable v a, HasCallStack) =>
ContextDSIGN v
-> VerKeyDSIGN v -> a -> SigDSIGN v -> Either String ()
forall a.
(Signable v a, HasCallStack) =>
ContextDSIGN v
-> VerKeyDSIGN v -> a -> SigDSIGN v -> Either String ()
verifyDSIGN ContextDSIGN v
ctx VerKeyDSIGN v
vk a
msg SigDSIGN v
signed Either String () -> Either String () -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=== () -> Either String ()
forall a b. b -> Either a b
Right ()

-- If we sign a message with one key, and try to verify with another, then
-- verification fails.
prop_dsign_verify_wrong_key
  :: forall (v :: Type) (a :: Type) .
     ( DSIGNAlgorithm v
     , Signable v a
     )
  => (ContextDSIGN v, a, SignKeyDSIGN v, SignKeyDSIGN v)
  -> Property
prop_dsign_verify_wrong_key :: forall v a.
(DSIGNAlgorithm v, Signable v a) =>
(ContextDSIGN v, a, SignKeyDSIGN v, SignKeyDSIGN v) -> Property
prop_dsign_verify_wrong_key (ContextDSIGN v
ctx, a
msg, SignKeyDSIGN v
sk, SignKeyDSIGN v
sk') =
  let signed :: SigDSIGN v
signed = ContextDSIGN v -> a -> SignKeyDSIGN v -> SigDSIGN v
forall v a.
(DSIGNAlgorithm v, Signable v a, HasCallStack) =>
ContextDSIGN v -> a -> SignKeyDSIGN v -> SigDSIGN v
forall a.
(Signable v a, HasCallStack) =>
ContextDSIGN v -> a -> SignKeyDSIGN v -> SigDSIGN v
signDSIGN ContextDSIGN v
ctx a
msg SignKeyDSIGN v
sk
      vk' :: VerKeyDSIGN v
vk' = SignKeyDSIGN v -> VerKeyDSIGN v
forall v. DSIGNAlgorithm v => SignKeyDSIGN v -> VerKeyDSIGN v
deriveVerKeyDSIGN SignKeyDSIGN v
sk'
    in ContextDSIGN v
-> VerKeyDSIGN v -> a -> SigDSIGN v -> Either String ()
forall v a.
(DSIGNAlgorithm v, Signable v a, HasCallStack) =>
ContextDSIGN v
-> VerKeyDSIGN v -> a -> SigDSIGN v -> Either String ()
forall a.
(Signable v a, HasCallStack) =>
ContextDSIGN v
-> VerKeyDSIGN v -> a -> SigDSIGN v -> Either String ()
verifyDSIGN ContextDSIGN v
ctx VerKeyDSIGN v
vk' a
msg SigDSIGN v
signed Either String () -> Either String () -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=/= () -> Either String ()
forall a b. b -> Either a b
Right ()

prop_dsignm_verify_pos
  :: forall v. (DSIGNMAlgorithm v, ContextDSIGN v ~ (), Signable v Message)
  => Lock
  -> Proxy v
  -> Message
  -> PinnedSizedBytes (SeedSizeDSIGN v)
  -> Property
prop_dsignm_verify_pos :: forall v.
(DSIGNMAlgorithm v, ContextDSIGN v ~ (), Signable v Message) =>
Lock
-> Proxy v
-> Message
-> PinnedSizedBytes (SeedSizeDSIGN v)
-> Property
prop_dsignm_verify_pos Lock
lock Proxy v
_ Message
msg =
  forall v a.
(Testable a, DSIGNMAlgorithm v) =>
Lock
-> (SignKeyDSIGNM v -> IO a)
-> PinnedSizedBytes (SeedSizeDSIGN v)
-> Property
ioPropertyWithSK @v Lock
lock ((SignKeyDSIGNM v -> IO Property)
 -> PinnedSizedBytes (SeedSizeDSIGN v) -> Property)
-> (SignKeyDSIGNM v -> IO Property)
-> PinnedSizedBytes (SeedSizeDSIGN v)
-> Property
forall a b. (a -> b) -> a -> b
$ \SignKeyDSIGNM v
sk -> do
    SigDSIGN v
sig <- ContextDSIGN v -> Message -> SignKeyDSIGNM v -> IO (SigDSIGN v)
forall v a (m :: * -> *).
(DSIGNMAlgorithm v, Signable v a, MonadST m, MonadThrow m) =>
ContextDSIGN v -> a -> SignKeyDSIGNM v -> m (SigDSIGN v)
forall a (m :: * -> *).
(Signable v a, MonadST m, MonadThrow m) =>
ContextDSIGN v -> a -> SignKeyDSIGNM v -> m (SigDSIGN v)
signDSIGNM () Message
msg SignKeyDSIGNM v
sk
    VerKeyDSIGN v
vk <- SignKeyDSIGNM v -> IO (VerKeyDSIGN v)
forall v (m :: * -> *).
(DSIGNMAlgorithm v, MonadThrow m, MonadST m) =>
SignKeyDSIGNM v -> m (VerKeyDSIGN v)
forall (m :: * -> *).
(MonadThrow m, MonadST m) =>
SignKeyDSIGNM v -> m (VerKeyDSIGN v)
deriveVerKeyDSIGNM SignKeyDSIGNM v
sk
    Property -> IO Property
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Property -> IO Property) -> Property -> IO Property
forall a b. (a -> b) -> a -> b
$ ContextDSIGN v
-> VerKeyDSIGN v -> Message -> SigDSIGN v -> Either String ()
forall v a.
(DSIGNAlgorithm v, Signable v a, HasCallStack) =>
ContextDSIGN v
-> VerKeyDSIGN v -> a -> SigDSIGN v -> Either String ()
forall a.
(Signable v a, HasCallStack) =>
ContextDSIGN v
-> VerKeyDSIGN v -> a -> SigDSIGN v -> Either String ()
verifyDSIGN () VerKeyDSIGN v
vk Message
msg SigDSIGN v
sig Either String () -> Either String () -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=== () -> Either String ()
forall a b. b -> Either a b
Right ()

-- | If we sign a message @a@ with one signing key, if we try to verify the
-- signature (and message @a@) using a verification key corresponding to a
-- different signing key, then the verification fails.
--
prop_dsignm_verify_neg_key
  :: forall v. (DSIGNMAlgorithm v, ContextDSIGN v ~ (), Signable v Message)
  => Lock
  -> Proxy v
  -> Message
  -> PinnedSizedBytes (SeedSizeDSIGN v)
  -> PinnedSizedBytes (SeedSizeDSIGN v)
  -> Property
prop_dsignm_verify_neg_key :: forall v.
(DSIGNMAlgorithm v, ContextDSIGN v ~ (), Signable v Message) =>
Lock
-> Proxy v
-> Message
-> PinnedSizedBytes (SeedSizeDSIGN v)
-> PinnedSizedBytes (SeedSizeDSIGN v)
-> Property
prop_dsignm_verify_neg_key Lock
lock Proxy v
_ Message
msg PinnedSizedBytes (SeedSizeDSIGN v)
seedPSB PinnedSizedBytes (SeedSizeDSIGN v)
seedPSB' =
  IO Property -> Property
forall prop. Testable prop => IO prop -> Property
ioProperty (IO Property -> Property)
-> (IO Property -> IO Property) -> IO Property -> Property
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Lock -> IO Property -> IO Property
forall a. Lock -> IO a -> IO a
withLock Lock
lock (IO Property -> Property) -> IO Property -> Property
forall a b. (a -> b) -> a -> b
$ do
    SigDSIGN v
sig <- forall v b.
DSIGNMAlgorithm v =>
PinnedSizedBytes (SeedSizeDSIGN v)
-> (SignKeyDSIGNM v -> IO b) -> IO b
withSK @v PinnedSizedBytes (SeedSizeDSIGN v)
seedPSB ((SignKeyDSIGNM v -> IO (SigDSIGN v)) -> IO (SigDSIGN v))
-> (SignKeyDSIGNM v -> IO (SigDSIGN v)) -> IO (SigDSIGN v)
forall a b. (a -> b) -> a -> b
$ ContextDSIGN v -> Message -> SignKeyDSIGNM v -> IO (SigDSIGN v)
forall v a (m :: * -> *).
(DSIGNMAlgorithm v, Signable v a, MonadST m, MonadThrow m) =>
ContextDSIGN v -> a -> SignKeyDSIGNM v -> m (SigDSIGN v)
forall a (m :: * -> *).
(Signable v a, MonadST m, MonadThrow m) =>
ContextDSIGN v -> a -> SignKeyDSIGNM v -> m (SigDSIGN v)
signDSIGNM () Message
msg
    VerKeyDSIGN v
vk' <- forall v b.
DSIGNMAlgorithm v =>
PinnedSizedBytes (SeedSizeDSIGN v)
-> (SignKeyDSIGNM v -> IO b) -> IO b
withSK @v PinnedSizedBytes (SeedSizeDSIGN v)
seedPSB' SignKeyDSIGNM v -> IO (VerKeyDSIGN v)
forall v (m :: * -> *).
(DSIGNMAlgorithm v, MonadThrow m, MonadST m) =>
SignKeyDSIGNM v -> m (VerKeyDSIGN v)
forall (m :: * -> *).
(MonadThrow m, MonadST m) =>
SignKeyDSIGNM v -> m (VerKeyDSIGN v)
deriveVerKeyDSIGNM
    Property -> IO Property
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Property -> IO Property) -> Property -> IO Property
forall a b. (a -> b) -> a -> b
$
      PinnedSizedBytes (SeedSizeDSIGN v)
seedPSB PinnedSizedBytes (SeedSizeDSIGN v)
-> PinnedSizedBytes (SeedSizeDSIGN v) -> Bool
forall a. Eq a => a -> a -> Bool
/= PinnedSizedBytes (SeedSizeDSIGN v)
seedPSB' Bool -> Property -> Property
forall prop. Testable prop => Bool -> prop -> Property
==> ContextDSIGN v
-> VerKeyDSIGN v -> Message -> SigDSIGN v -> Either String ()
forall v a.
(DSIGNAlgorithm v, Signable v a, HasCallStack) =>
ContextDSIGN v
-> VerKeyDSIGN v -> a -> SigDSIGN v -> Either String ()
forall a.
(Signable v a, HasCallStack) =>
ContextDSIGN v
-> VerKeyDSIGN v -> a -> SigDSIGN v -> Either String ()
verifyDSIGN () VerKeyDSIGN v
vk' Message
msg SigDSIGN v
sig Either String () -> Either String () -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=/= () -> Either String ()
forall a b. b -> Either a b
Right ()

-- If we sign a message with a key, but then try to verify with a different
-- message, then verification fails.
prop_dsign_verify_wrong_msg
  :: forall (v :: Type) (a :: Type) .
  (DSIGNAlgorithm v, Signable v a)
  => (ContextDSIGN v ,a, a, SignKeyDSIGN v)
  -> Property
prop_dsign_verify_wrong_msg :: forall v a.
(DSIGNAlgorithm v, Signable v a) =>
(ContextDSIGN v, a, a, SignKeyDSIGN v) -> Property
prop_dsign_verify_wrong_msg (ContextDSIGN v
ctx, a
msg, a
msg', SignKeyDSIGN v
sk) =
  let signed :: SigDSIGN v
signed = ContextDSIGN v -> a -> SignKeyDSIGN v -> SigDSIGN v
forall v a.
(DSIGNAlgorithm v, Signable v a, HasCallStack) =>
ContextDSIGN v -> a -> SignKeyDSIGN v -> SigDSIGN v
forall a.
(Signable v a, HasCallStack) =>
ContextDSIGN v -> a -> SignKeyDSIGN v -> SigDSIGN v
signDSIGN ContextDSIGN v
ctx a
msg SignKeyDSIGN v
sk
      vk :: VerKeyDSIGN v
vk = SignKeyDSIGN v -> VerKeyDSIGN v
forall v. DSIGNAlgorithm v => SignKeyDSIGN v -> VerKeyDSIGN v
deriveVerKeyDSIGN SignKeyDSIGN v
sk
    in ContextDSIGN v
-> VerKeyDSIGN v -> a -> SigDSIGN v -> Either String ()
forall v a.
(DSIGNAlgorithm v, Signable v a, HasCallStack) =>
ContextDSIGN v
-> VerKeyDSIGN v -> a -> SigDSIGN v -> Either String ()
forall a.
(Signable v a, HasCallStack) =>
ContextDSIGN v
-> VerKeyDSIGN v -> a -> SigDSIGN v -> Either String ()
verifyDSIGN ContextDSIGN v
ctx VerKeyDSIGN v
vk a
msg' SigDSIGN v
signed Either String () -> Either String () -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=/= () -> Either String ()
forall a b. b -> Either a b
Right ()

#ifdef SECP256K1_ENABLED
instance Arbitrary (BadInputFor MessageHash) where
  arbitrary :: Gen (BadInputFor MessageHash)
arbitrary = Int -> Gen (BadInputFor MessageHash)
forall a. Int -> Gen (BadInputFor a)
genBadInputFor (forall a b. (Integral a, Num b) => a -> b
fromIntegral @Integer @Int (Proxy SECP256K1_ECDSA_MESSAGE_BYTES -> Integer
forall (n :: Nat) (proxy :: Nat -> *).
KnownNat n =>
proxy n -> Integer
natVal (Proxy SECP256K1_ECDSA_MESSAGE_BYTES -> Integer)
-> Proxy SECP256K1_ECDSA_MESSAGE_BYTES -> Integer
forall a b. (a -> b) -> a -> b
$ forall (t :: Nat). Proxy t
forall {k} (t :: k). Proxy t
Proxy @SECP256K1_ECDSA_MESSAGE_BYTES))
  shrink :: BadInputFor MessageHash -> [BadInputFor MessageHash]
shrink = BadInputFor MessageHash -> [BadInputFor MessageHash]
forall a. BadInputFor a -> [BadInputFor a]
shrinkBadInputFor

testEcdsaInvalidMessageHash :: String -> Spec
testEcdsaInvalidMessageHash :: String -> Spec
testEcdsaInvalidMessageHash String
name = Spec -> Spec
testEnough (Spec -> Spec) -> (Spec -> Spec) -> Spec -> Spec
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Spec -> Spec
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
name (Spec -> Spec) -> Spec -> Spec
forall a b. (a -> b) -> a -> b
$ do
    String -> (BadInputFor MessageHash -> Property) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"MessageHash deserialization (wrong length)" ((BadInputFor MessageHash -> Property) -> Spec)
-> (BadInputFor MessageHash -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$
      (ByteString -> Maybe MessageHash)
-> BadInputFor MessageHash -> Property
forall a.
Show a =>
(ByteString -> Maybe a) -> BadInputFor a -> Property
prop_raw_deserialise ByteString -> Maybe MessageHash
toMessageHash
    String -> (BadInputFor MessageHash -> Property) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"MessageHash fail fromCBOR" ((BadInputFor MessageHash -> Property) -> Spec)
-> (BadInputFor MessageHash -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$ forall a. (Show a, FromCBOR a) => BadInputFor a -> Property
prop_bad_cbor_bytes @MessageHash

testEcdsaWithHashAlgorithm ::
  forall (h :: Type).
  (HashAlgorithm h, HashSize h ~ SECP256K1_ECDSA_MESSAGE_BYTES) =>
  Proxy h -> String -> Spec
testEcdsaWithHashAlgorithm :: forall h.
(HashAlgorithm h, HashSize h ~ SECP256K1_ECDSA_MESSAGE_BYTES) =>
Proxy h -> String -> Spec
testEcdsaWithHashAlgorithm Proxy h
_ String
name = Spec -> Spec
testEnough (Spec -> Spec) -> (Spec -> Spec) -> Spec -> Spec
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Spec -> Spec
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
name (Spec -> Spec) -> Spec -> Spec
forall a b. (a -> b) -> a -> b
$ do
  String -> Property -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"Ecdsa sign and verify" (Property -> Spec)
-> ((((), MessageHash, SignKeyDSIGN EcdsaSecp256k1DSIGN)
     -> Property)
    -> Property)
-> (((), MessageHash, SignKeyDSIGN EcdsaSecp256k1DSIGN)
    -> Property)
-> Spec
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
    Gen ((), MessageHash, SignKeyDSIGN EcdsaSecp256k1DSIGN)
-> (((), MessageHash, SignKeyDSIGN EcdsaSecp256k1DSIGN) -> String)
-> (((), MessageHash, SignKeyDSIGN EcdsaSecp256k1DSIGN)
    -> Property)
-> Property
forall prop a.
Testable prop =>
Gen a -> (a -> String) -> (a -> prop) -> Property
forAllShow ((,,) (()
 -> MessageHash
 -> SignKeyDSIGN EcdsaSecp256k1DSIGN
 -> ((), MessageHash, SignKeyDSIGN EcdsaSecp256k1DSIGN))
-> Gen ()
-> Gen
     (MessageHash
      -> SignKeyDSIGN EcdsaSecp256k1DSIGN
      -> ((), MessageHash, SignKeyDSIGN EcdsaSecp256k1DSIGN))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen ()
Gen (ContextDSIGN EcdsaSecp256k1DSIGN)
genContext Gen
  (MessageHash
   -> SignKeyDSIGN EcdsaSecp256k1DSIGN
   -> ((), MessageHash, SignKeyDSIGN EcdsaSecp256k1DSIGN))
-> Gen MessageHash
-> Gen
     (SignKeyDSIGN EcdsaSecp256k1DSIGN
      -> ((), MessageHash, SignKeyDSIGN EcdsaSecp256k1DSIGN))
forall a b. Gen (a -> b) -> Gen a -> Gen b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen MessageHash
genMsg Gen
  (SignKeyDSIGN EcdsaSecp256k1DSIGN
   -> ((), MessageHash, SignKeyDSIGN EcdsaSecp256k1DSIGN))
-> Gen (SignKeyDSIGN EcdsaSecp256k1DSIGN)
-> Gen ((), MessageHash, SignKeyDSIGN EcdsaSecp256k1DSIGN)
forall a b. Gen (a -> b) -> Gen a -> Gen b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall v.
(DSIGNAlgorithm v, KeyGenContextDSIGN v ~ ()) =>
Gen (SignKeyDSIGN v)
defaultSignKeyGen @EcdsaSecp256k1DSIGN) ((), MessageHash, SignKeyDSIGN EcdsaSecp256k1DSIGN) -> String
forall a. Show a => a -> String
ppShow ((((), MessageHash, SignKeyDSIGN EcdsaSecp256k1DSIGN) -> Property)
 -> Spec)
-> (((), MessageHash, SignKeyDSIGN EcdsaSecp256k1DSIGN)
    -> Property)
-> Spec
forall a b. (a -> b) -> a -> b
$
      ((), MessageHash, SignKeyDSIGN EcdsaSecp256k1DSIGN) -> Property
(ContextDSIGN EcdsaSecp256k1DSIGN, MessageHash,
 SignKeyDSIGN EcdsaSecp256k1DSIGN)
-> Property
forall v a.
(DSIGNAlgorithm v, Signable v a) =>
(ContextDSIGN v, a, SignKeyDSIGN v) -> Property
prop_dsign_verify
  where
    genMsg :: Gen MessageHash
    genMsg :: Gen MessageHash
genMsg = Proxy h -> ByteString -> MessageHash
forall h.
(HashAlgorithm h, HashSize h ~ SECP256K1_ECDSA_MESSAGE_BYTES) =>
Proxy h -> ByteString -> MessageHash
hashAndPack (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @h) (ByteString -> MessageHash)
-> (Message -> ByteString) -> Message -> MessageHash
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Message -> ByteString
messageBytes (Message -> MessageHash) -> Gen Message -> Gen MessageHash
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Message
forall a. Arbitrary a => Gen a
arbitrary
    genContext :: Gen (ContextDSIGN EcdsaSecp256k1DSIGN)
    genContext :: Gen (ContextDSIGN EcdsaSecp256k1DSIGN)
genContext = () -> Gen ()
forall a. a -> Gen a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()

#endif

prop_dsignm_verify_neg_msg
  :: forall v. (DSIGNMAlgorithm v, ContextDSIGN v ~ (), Signable v Message)
  => Lock
  -> Proxy v
  -> Message
  -> Message
  -> PinnedSizedBytes (SeedSizeDSIGN v)
  -> Property
prop_dsignm_verify_neg_msg :: forall v.
(DSIGNMAlgorithm v, ContextDSIGN v ~ (), Signable v Message) =>
Lock
-> Proxy v
-> Message
-> Message
-> PinnedSizedBytes (SeedSizeDSIGN v)
-> Property
prop_dsignm_verify_neg_msg Lock
lock Proxy v
_ Message
a Message
a' =
  forall v a.
(Testable a, DSIGNMAlgorithm v) =>
Lock
-> (SignKeyDSIGNM v -> IO a)
-> PinnedSizedBytes (SeedSizeDSIGN v)
-> Property
ioPropertyWithSK @v Lock
lock ((SignKeyDSIGNM v -> IO Property)
 -> PinnedSizedBytes (SeedSizeDSIGN v) -> Property)
-> (SignKeyDSIGNM v -> IO Property)
-> PinnedSizedBytes (SeedSizeDSIGN v)
-> Property
forall a b. (a -> b) -> a -> b
$ \SignKeyDSIGNM v
sk -> do
    SigDSIGN v
sig <- ContextDSIGN v -> Message -> SignKeyDSIGNM v -> IO (SigDSIGN v)
forall v a (m :: * -> *).
(DSIGNMAlgorithm v, Signable v a, MonadST m, MonadThrow m) =>
ContextDSIGN v -> a -> SignKeyDSIGNM v -> m (SigDSIGN v)
forall a (m :: * -> *).
(Signable v a, MonadST m, MonadThrow m) =>
ContextDSIGN v -> a -> SignKeyDSIGNM v -> m (SigDSIGN v)
signDSIGNM () Message
a SignKeyDSIGNM v
sk
    VerKeyDSIGN v
vk <- SignKeyDSIGNM v -> IO (VerKeyDSIGN v)
forall v (m :: * -> *).
(DSIGNMAlgorithm v, MonadThrow m, MonadST m) =>
SignKeyDSIGNM v -> m (VerKeyDSIGN v)
forall (m :: * -> *).
(MonadThrow m, MonadST m) =>
SignKeyDSIGNM v -> m (VerKeyDSIGN v)
deriveVerKeyDSIGNM SignKeyDSIGNM v
sk
    Property -> IO Property
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Property -> IO Property) -> Property -> IO Property
forall a b. (a -> b) -> a -> b
$
      Message
a Message -> Message -> Bool
forall a. Eq a => a -> a -> Bool
/= Message
a' Bool -> Property -> Property
forall prop. Testable prop => Bool -> prop -> Property
==> ContextDSIGN v
-> VerKeyDSIGN v -> Message -> SigDSIGN v -> Either String ()
forall v a.
(DSIGNAlgorithm v, Signable v a, HasCallStack) =>
ContextDSIGN v
-> VerKeyDSIGN v -> a -> SigDSIGN v -> Either String ()
forall a.
(Signable v a, HasCallStack) =>
ContextDSIGN v
-> VerKeyDSIGN v -> a -> SigDSIGN v -> Either String ()
verifyDSIGN () VerKeyDSIGN v
vk Message
a' SigDSIGN v
sig Either String () -> Either String () -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=/= () -> Either String ()
forall a b. b -> Either a b
Right ()

-- TODO: verify that DSIGN and DSIGNM implementations match (see #363)

-- Tests and instances for DSIGNAggregatable v

instance DSIGNAggregatable v => Arbitrary (BadInputFor (PossessionProofDSIGN v)) where
  arbitrary :: Gen (BadInputFor (PossessionProofDSIGN v))
arbitrary =
    Int -> Gen (BadInputFor (PossessionProofDSIGN v))
forall a. Int -> Gen (BadInputFor a)
genBadInputFor (forall a b. (Integral a, Num b) => a -> b
fromIntegral @Word @Int (Word -> Int) -> Word -> Int
forall a b. (a -> b) -> a -> b
$ Proxy v -> Word
forall v (proxy :: * -> *). DSIGNAggregatable v => proxy v -> Word
possessionProofSizeDSIGN (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @v))
  shrink :: BadInputFor (PossessionProofDSIGN v)
-> [BadInputFor (PossessionProofDSIGN v)]
shrink = BadInputFor (PossessionProofDSIGN v)
-> [BadInputFor (PossessionProofDSIGN v)]
forall a. BadInputFor a -> [BadInputFor a]
shrinkBadInputFor

testDSIGNAggregatableWithContext
  :: forall (v :: Type).
     ( DSIGNAggregatable v
     , Signable v Message
     , Show (ContextDSIGN v)
     , ToCBOR (PossessionProofDSIGN v)
     , FromCBOR (PossessionProofDSIGN v)
     )
  => Proxy v
  -> Gen (ContextDSIGN v)
  -> Gen (KeyGenContextDSIGN v)
  -> Gen Message
  -> String
  -> Spec
testDSIGNAggregatableWithContext :: forall v.
(DSIGNAggregatable v, Signable v Message, Show (ContextDSIGN v),
 ToCBOR (PossessionProofDSIGN v),
 FromCBOR (PossessionProofDSIGN v)) =>
Proxy v
-> Gen (ContextDSIGN v)
-> Gen (KeyGenContextDSIGN v)
-> Gen Message
-> String
-> Spec
testDSIGNAggregatableWithContext Proxy v
_ Gen (ContextDSIGN v)
genContext Gen (KeyGenContextDSIGN v)
genKeyCtx Gen Message
genMsg String
name = Spec -> Spec
testEnough (Spec -> Spec) -> (Spec -> Spec) -> Spec -> Spec
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Spec -> Spec
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
name (Spec -> Spec) -> Spec -> Spec
forall a b. (a -> b) -> a -> b
$ do
  String -> Spec -> Spec
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"serialization" (Spec -> Spec) -> Spec -> Spec
forall a b. (a -> b) -> a -> b
$ do
    String -> Spec -> Spec
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"raw" (Spec -> Spec) -> Spec -> Spec
forall a b. (a -> b) -> a -> b
$ do
      String -> Property -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"PoP serialization" (Property -> Spec)
-> ((PossessionProofDSIGN v -> Property) -> Property)
-> (PossessionProofDSIGN v -> Property)
-> Spec
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
        (PossessionProofDSIGN v -> Property) -> Property
forall prop.
Testable prop =>
(PossessionProofDSIGN v -> prop) -> Property
forAllPoP ((PossessionProofDSIGN v -> Property) -> Spec)
-> (PossessionProofDSIGN v -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$ (PossessionProofDSIGN v -> ByteString)
-> (ByteString -> Maybe (PossessionProofDSIGN v))
-> PossessionProofDSIGN v
-> Property
forall a.
(Eq a, Show a) =>
(a -> ByteString) -> (ByteString -> Maybe a) -> a -> Property
prop_raw_serialise PossessionProofDSIGN v -> ByteString
forall v.
DSIGNAggregatable v =>
PossessionProofDSIGN v -> ByteString
rawSerialisePossessionProofDSIGN ByteString -> Maybe (PossessionProofDSIGN v)
forall v.
DSIGNAggregatable v =>
ByteString -> Maybe (PossessionProofDSIGN v)
rawDeserialisePossessionProofDSIGN
      String
-> (BadInputFor (PossessionProofDSIGN v) -> Property) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"PoP deserialization (wrong length)" ((BadInputFor (PossessionProofDSIGN v) -> Property) -> Spec)
-> (BadInputFor (PossessionProofDSIGN v) -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$ (ByteString -> Maybe (PossessionProofDSIGN v))
-> BadInputFor (PossessionProofDSIGN v) -> Property
forall a.
Show a =>
(ByteString -> Maybe a) -> BadInputFor a -> Property
prop_raw_deserialise (forall v.
DSIGNAggregatable v =>
ByteString -> Maybe (PossessionProofDSIGN v)
rawDeserialisePossessionProofDSIGN @v)
      String
-> (BadInputFor (PossessionProofDSIGN v) -> Property) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"PoP fail fromCBOR" ((BadInputFor (PossessionProofDSIGN v) -> Property) -> Spec)
-> (BadInputFor (PossessionProofDSIGN v) -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$ forall a. (Show a, FromCBOR a) => BadInputFor a -> Property
prop_bad_cbor_bytes @(PossessionProofDSIGN v)
    String -> Spec -> Spec
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"size" (Spec -> Spec) -> Spec -> Spec
forall a b. (a -> b) -> a -> b
$ do
      String -> Property -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"PoP" (Property -> Spec)
-> ((PossessionProofDSIGN v -> Property) -> Property)
-> (PossessionProofDSIGN v -> Property)
-> Spec
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
        (PossessionProofDSIGN v -> Property) -> Property
forall prop.
Testable prop =>
(PossessionProofDSIGN v -> prop) -> Property
forAllPoP ((PossessionProofDSIGN v -> Property) -> Spec)
-> (PossessionProofDSIGN v -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$ (PossessionProofDSIGN v -> ByteString)
-> Word -> PossessionProofDSIGN v -> Property
forall a. (a -> ByteString) -> Word -> a -> Property
prop_size_serialise PossessionProofDSIGN v -> ByteString
forall v.
DSIGNAggregatable v =>
PossessionProofDSIGN v -> ByteString
rawSerialisePossessionProofDSIGN (Proxy v -> Word
forall v (proxy :: * -> *). DSIGNAggregatable v => proxy v -> Word
possessionProofSizeDSIGN (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @v))
    String -> Spec -> Spec
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"direct CBOR" (Spec -> Spec) -> Spec -> Spec
forall a b. (a -> b) -> a -> b
$ do
      String -> Property -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"PoP" (Property -> Spec)
-> ((PossessionProofDSIGN v -> Property) -> Property)
-> (PossessionProofDSIGN v -> Property)
-> Spec
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
        (PossessionProofDSIGN v -> Property) -> Property
forall prop.
Testable prop =>
(PossessionProofDSIGN v -> prop) -> Property
forAllPoP ((PossessionProofDSIGN v -> Property) -> Spec)
-> (PossessionProofDSIGN v -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$ (PossessionProofDSIGN v -> Encoding)
-> (forall s. Decoder s (PossessionProofDSIGN v))
-> PossessionProofDSIGN v
-> Property
forall a.
(Eq a, Show a) =>
(a -> Encoding) -> (forall s. Decoder s a) -> a -> Property
prop_cbor_with PossessionProofDSIGN v -> Encoding
forall v. DSIGNAggregatable v => PossessionProofDSIGN v -> Encoding
encodePossessionProofDSIGN Decoder s (PossessionProofDSIGN v)
forall s. Decoder s (PossessionProofDSIGN v)
forall v s.
DSIGNAggregatable v =>
Decoder s (PossessionProofDSIGN v)
decodePossessionProofDSIGN
    String -> Spec -> Spec
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"To/FromCBOR class" (Spec -> Spec) -> Spec -> Spec
forall a b. (a -> b) -> a -> b
$ do
      String -> Property -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"PoP" (Property -> Spec)
-> ((PossessionProofDSIGN v -> Property) -> Property)
-> (PossessionProofDSIGN v -> Property)
-> Spec
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (PossessionProofDSIGN v -> Property) -> Property
forall prop.
Testable prop =>
(PossessionProofDSIGN v -> prop) -> Property
forAllPoP ((PossessionProofDSIGN v -> Property) -> Spec)
-> (PossessionProofDSIGN v -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$ PossessionProofDSIGN v -> Property
forall a. (ToCBOR a, FromCBOR a, Eq a, Show a) => a -> Property
prop_cbor
    String -> Spec -> Spec
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"ToCBOR size" (Spec -> Spec) -> Spec -> Spec
forall a b. (a -> b) -> a -> b
$ do
      String -> Property -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"PoP" (Property -> Spec)
-> ((PossessionProofDSIGN v -> Property) -> Property)
-> (PossessionProofDSIGN v -> Property)
-> Spec
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (PossessionProofDSIGN v -> Property) -> Property
forall prop.
Testable prop =>
(PossessionProofDSIGN v -> prop) -> Property
forAllPoP ((PossessionProofDSIGN v -> Property) -> Spec)
-> (PossessionProofDSIGN v -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$ PossessionProofDSIGN v -> Property
forall a. ToCBOR a => a -> Property
prop_cbor_size
    String -> Spec -> Spec
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"direct matches class" (Spec -> Spec) -> Spec -> Spec
forall a b. (a -> b) -> a -> b
$ do
      String -> Property -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"PoP" (Property -> Spec)
-> ((PossessionProofDSIGN v -> Property) -> Property)
-> (PossessionProofDSIGN v -> Property)
-> Spec
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
        (PossessionProofDSIGN v -> Property) -> Property
forall prop.
Testable prop =>
(PossessionProofDSIGN v -> prop) -> Property
forAllPoP ((PossessionProofDSIGN v -> Property) -> Spec)
-> (PossessionProofDSIGN v -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$ (PossessionProofDSIGN v -> Encoding)
-> PossessionProofDSIGN v -> Property
forall a. ToCBOR a => (a -> Encoding) -> a -> Property
prop_cbor_direct_vs_class PossessionProofDSIGN v -> Encoding
forall v. DSIGNAggregatable v => PossessionProofDSIGN v -> Encoding
encodePossessionProofDSIGN
  String -> Spec -> Spec
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"aggregate" (Spec -> Spec) -> Spec -> Spec
forall a b. (a -> b) -> a -> b
$ do
    String -> Property -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"aggregate verify positive" (Property -> Spec) -> Property -> Spec
forall a b. (a -> b) -> a -> b
$
      Int -> Property -> Property
forall prop. Testable prop => Int -> prop -> Property
withMaxSuccess Int
1000 (Property -> Property)
-> (((ContextDSIGN v, Message,
      [(VerKeyDSIGN v, PossessionProofDSIGN v)], [SigDSIGN v])
     -> Property)
    -> Property)
-> ((ContextDSIGN v, Message,
     [(VerKeyDSIGN v, PossessionProofDSIGN v)], [SigDSIGN v])
    -> Property)
-> Property
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
      Gen
  (ContextDSIGN v, Message,
   [(VerKeyDSIGN v, PossessionProofDSIGN v)], [SigDSIGN v])
-> ((ContextDSIGN v, Message,
     [(VerKeyDSIGN v, PossessionProofDSIGN v)], [SigDSIGN v])
    -> String)
-> ((ContextDSIGN v, Message,
     [(VerKeyDSIGN v, PossessionProofDSIGN v)], [SigDSIGN v])
    -> Property)
-> Property
forall prop a.
Testable prop =>
Gen a -> (a -> String) -> (a -> prop) -> Property
forAllShow (Gen (ContextDSIGN v)
-> Gen Message
-> Gen
     (ContextDSIGN v, Message,
      [(VerKeyDSIGN v, PossessionProofDSIGN v)], [SigDSIGN v])
genAggregateCase Gen (ContextDSIGN v)
genContext Gen Message
genMsg) (ContextDSIGN v, Message,
 [(VerKeyDSIGN v, PossessionProofDSIGN v)], [SigDSIGN v])
-> String
forall a. Show a => a -> String
ppShow (((ContextDSIGN v, Message,
   [(VerKeyDSIGN v, PossessionProofDSIGN v)], [SigDSIGN v])
  -> Property)
 -> Property)
-> ((ContextDSIGN v, Message,
     [(VerKeyDSIGN v, PossessionProofDSIGN v)], [SigDSIGN v])
    -> Property)
-> Property
forall a b. (a -> b) -> a -> b
$
          \(ContextDSIGN v
ctx, Message
msg, [(VerKeyDSIGN v, PossessionProofDSIGN v)]
vksPops, [SigDSIGN v]
sigs) -> (Either String () -> Either String () -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=== () -> Either String ()
forall a b. b -> Either a b
Right ()) (Either String () -> Property) -> Either String () -> Property
forall a b. (a -> b) -> a -> b
$ do
            SigDSIGN v
sig <- forall v.
(DSIGNAggregatable v, HasCallStack) =>
[SigDSIGN v] -> Either String (SigDSIGN v)
aggregateSigsDSIGN @v [SigDSIGN v]
sigs
            VerKeyDSIGN v
aggVk <- ContextDSIGN v
-> [(VerKeyDSIGN v, PossessionProofDSIGN v)]
-> Either String (VerKeyDSIGN v)
forall v.
(HasCallStack, DSIGNAggregatable v) =>
ContextDSIGN v
-> [(VerKeyDSIGN v, PossessionProofDSIGN v)]
-> Either String (VerKeyDSIGN v)
aggregateVerKeysDSIGN ContextDSIGN v
ctx [(VerKeyDSIGN v, PossessionProofDSIGN v)]
vksPops
            forall v a.
(DSIGNAlgorithm v, Signable v a, HasCallStack) =>
ContextDSIGN v
-> VerKeyDSIGN v -> a -> SigDSIGN v -> Either String ()
verifyDSIGN @v ContextDSIGN v
ctx VerKeyDSIGN v
aggVk Message
msg SigDSIGN v
sig
    String -> Property -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"aggregate verify negative (wrong message)" (Property -> Spec) -> Property -> Spec
forall a b. (a -> b) -> a -> b
$
      Int -> Property -> Property
forall prop. Testable prop => Int -> prop -> Property
withMaxSuccess Int
1000 (Property -> Property)
-> (((ContextDSIGN v, Message,
      [(VerKeyDSIGN v, PossessionProofDSIGN v)], [SigDSIGN v])
     -> Property)
    -> Property)
-> ((ContextDSIGN v, Message,
     [(VerKeyDSIGN v, PossessionProofDSIGN v)], [SigDSIGN v])
    -> Property)
-> Property
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
      Gen
  (ContextDSIGN v, Message,
   [(VerKeyDSIGN v, PossessionProofDSIGN v)], [SigDSIGN v])
-> ((ContextDSIGN v, Message,
     [(VerKeyDSIGN v, PossessionProofDSIGN v)], [SigDSIGN v])
    -> String)
-> ((ContextDSIGN v, Message,
     [(VerKeyDSIGN v, PossessionProofDSIGN v)], [SigDSIGN v])
    -> Property)
-> Property
forall prop a.
Testable prop =>
Gen a -> (a -> String) -> (a -> prop) -> Property
forAllShow (Gen (ContextDSIGN v)
-> Gen Message
-> Gen
     (ContextDSIGN v, Message,
      [(VerKeyDSIGN v, PossessionProofDSIGN v)], [SigDSIGN v])
genAggregateCase Gen (ContextDSIGN v)
genContext Gen Message
genMsg) (ContextDSIGN v, Message,
 [(VerKeyDSIGN v, PossessionProofDSIGN v)], [SigDSIGN v])
-> String
forall a. Show a => a -> String
ppShow (((ContextDSIGN v, Message,
   [(VerKeyDSIGN v, PossessionProofDSIGN v)], [SigDSIGN v])
  -> Property)
 -> Property)
-> ((ContextDSIGN v, Message,
     [(VerKeyDSIGN v, PossessionProofDSIGN v)], [SigDSIGN v])
    -> Property)
-> Property
forall a b. (a -> b) -> a -> b
$ \(ContextDSIGN v
ctx, Message
msg, [(VerKeyDSIGN v, PossessionProofDSIGN v)]
vksPops, [SigDSIGN v]
sigs) ->
          Gen Message
-> (Message -> String) -> (Message -> Property) -> Property
forall prop a.
Testable prop =>
Gen a -> (a -> String) -> (a -> prop) -> Property
forAllShow Gen Message
forall a. Arbitrary a => Gen a
arbitrary Message -> String
forall a. Show a => a -> String
ppShow ((Message -> Property) -> Property)
-> (Message -> Property) -> Property
forall a b. (a -> b) -> a -> b
$ \Message
msg' ->
            Message
msg Message -> Message -> Bool
forall a. Eq a => a -> a -> Bool
/= Message
msg' Bool -> Property -> Property
forall prop. Testable prop => Bool -> prop -> Property
==> (Either String () -> Either String () -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=/= () -> Either String ()
forall a b. b -> Either a b
Right ()) (Either String () -> Property) -> Either String () -> Property
forall a b. (a -> b) -> a -> b
$ do
                SigDSIGN v
sig <- forall v.
(DSIGNAggregatable v, HasCallStack) =>
[SigDSIGN v] -> Either String (SigDSIGN v)
aggregateSigsDSIGN @v [SigDSIGN v]
sigs
                VerKeyDSIGN v
aggVk <- ContextDSIGN v
-> [(VerKeyDSIGN v, PossessionProofDSIGN v)]
-> Either String (VerKeyDSIGN v)
forall v.
(HasCallStack, DSIGNAggregatable v) =>
ContextDSIGN v
-> [(VerKeyDSIGN v, PossessionProofDSIGN v)]
-> Either String (VerKeyDSIGN v)
aggregateVerKeysDSIGN ContextDSIGN v
ctx [(VerKeyDSIGN v, PossessionProofDSIGN v)]
vksPops
                forall v a.
(DSIGNAlgorithm v, Signable v a, HasCallStack) =>
ContextDSIGN v
-> VerKeyDSIGN v -> a -> SigDSIGN v -> Either String ()
verifyDSIGN @v ContextDSIGN v
ctx VerKeyDSIGN v
aggVk Message
msg' SigDSIGN v
sig
    String -> Property -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"aggregate verify negative (wrong PoP)" (Property -> Spec) -> Property -> Spec
forall a b. (a -> b) -> a -> b
$
        Gen
  (ContextDSIGN v, Message,
   [(VerKeyDSIGN v, PossessionProofDSIGN v)], [SigDSIGN v])
-> ((ContextDSIGN v, Message,
     [(VerKeyDSIGN v, PossessionProofDSIGN v)], [SigDSIGN v])
    -> String)
-> ((ContextDSIGN v, Message,
     [(VerKeyDSIGN v, PossessionProofDSIGN v)], [SigDSIGN v])
    -> Property)
-> Property
forall prop a.
Testable prop =>
Gen a -> (a -> String) -> (a -> prop) -> Property
forAllShow (Gen (ContextDSIGN v)
-> Gen Message
-> Gen
     (ContextDSIGN v, Message,
      [(VerKeyDSIGN v, PossessionProofDSIGN v)], [SigDSIGN v])
genAggregateCaseAtLeast2 Gen (ContextDSIGN v)
genContext Gen Message
genMsg) (ContextDSIGN v, Message,
 [(VerKeyDSIGN v, PossessionProofDSIGN v)], [SigDSIGN v])
-> String
forall a. Show a => a -> String
ppShow (((ContextDSIGN v, Message,
   [(VerKeyDSIGN v, PossessionProofDSIGN v)], [SigDSIGN v])
  -> Property)
 -> Property)
-> ((ContextDSIGN v, Message,
     [(VerKeyDSIGN v, PossessionProofDSIGN v)], [SigDSIGN v])
    -> Property)
-> Property
forall a b. (a -> b) -> a -> b
$
          \(ContextDSIGN v
ctx, Message
msg, [(VerKeyDSIGN v, PossessionProofDSIGN v)]
vksPops, [SigDSIGN v]
sigs) ->
            case [(VerKeyDSIGN v, PossessionProofDSIGN v)]
vksPops of
              ((VerKeyDSIGN v, PossessionProofDSIGN v)
a:(VerKeyDSIGN v, PossessionProofDSIGN v)
b:[(VerKeyDSIGN v, PossessionProofDSIGN v)]
rest) -> (Either String () -> Either String () -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=/= () -> Either String ()
forall a b. b -> Either a b
Right ()) (Either String () -> Property) -> Either String () -> Property
forall a b. (a -> b) -> a -> b
$ do
                let vksPops' :: [(VerKeyDSIGN v, PossessionProofDSIGN v)]
vksPops' = ((VerKeyDSIGN v, PossessionProofDSIGN v) -> VerKeyDSIGN v
forall a b. (a, b) -> a
fst (VerKeyDSIGN v, PossessionProofDSIGN v)
a, (VerKeyDSIGN v, PossessionProofDSIGN v) -> PossessionProofDSIGN v
forall a b. (a, b) -> b
snd (VerKeyDSIGN v, PossessionProofDSIGN v)
b) (VerKeyDSIGN v, PossessionProofDSIGN v)
-> [(VerKeyDSIGN v, PossessionProofDSIGN v)]
-> [(VerKeyDSIGN v, PossessionProofDSIGN v)]
forall a. a -> [a] -> [a]
: ((VerKeyDSIGN v, PossessionProofDSIGN v) -> VerKeyDSIGN v
forall a b. (a, b) -> a
fst (VerKeyDSIGN v, PossessionProofDSIGN v)
b, (VerKeyDSIGN v, PossessionProofDSIGN v) -> PossessionProofDSIGN v
forall a b. (a, b) -> b
snd (VerKeyDSIGN v, PossessionProofDSIGN v)
a) (VerKeyDSIGN v, PossessionProofDSIGN v)
-> [(VerKeyDSIGN v, PossessionProofDSIGN v)]
-> [(VerKeyDSIGN v, PossessionProofDSIGN v)]
forall a. a -> [a] -> [a]
: [(VerKeyDSIGN v, PossessionProofDSIGN v)]
rest
                SigDSIGN v
sig <- forall v.
(DSIGNAggregatable v, HasCallStack) =>
[SigDSIGN v] -> Either String (SigDSIGN v)
aggregateSigsDSIGN @v [SigDSIGN v]
sigs
                VerKeyDSIGN v
aggVk <- ContextDSIGN v
-> [(VerKeyDSIGN v, PossessionProofDSIGN v)]
-> Either String (VerKeyDSIGN v)
forall v.
(HasCallStack, DSIGNAggregatable v) =>
ContextDSIGN v
-> [(VerKeyDSIGN v, PossessionProofDSIGN v)]
-> Either String (VerKeyDSIGN v)
aggregateVerKeysDSIGN ContextDSIGN v
ctx [(VerKeyDSIGN v, PossessionProofDSIGN v)]
vksPops'
                forall v a.
(DSIGNAlgorithm v, Signable v a, HasCallStack) =>
ContextDSIGN v
-> VerKeyDSIGN v -> a -> SigDSIGN v -> Either String ()
verifyDSIGN @v ContextDSIGN v
ctx VerKeyDSIGN v
aggVk Message
msg SigDSIGN v
sig
              [(VerKeyDSIGN v, PossessionProofDSIGN v)]
_ ->
                String -> Bool -> Property
forall prop. Testable prop => String -> prop -> Property
counterexample String
"genAggregateCaseAtLeast2 produced <2 entries (bug in generator)" Bool
False
    String -> Spec -> Spec
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"NoThunks" (Spec -> Spec) -> Spec -> Spec
forall a b. (a -> b) -> a -> b
$ do
      String -> Property -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"PoP" (Property -> Spec)
-> ((PossessionProofDSIGN v -> Property) -> Property)
-> (PossessionProofDSIGN v -> Property)
-> Spec
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (PossessionProofDSIGN v -> Property) -> Property
forall prop.
Testable prop =>
(PossessionProofDSIGN v -> prop) -> Property
forAllPoP ((PossessionProofDSIGN v -> Property) -> Spec)
-> (PossessionProofDSIGN v -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$ PossessionProofDSIGN v -> Property
forall a. NoThunks a => a -> Property
prop_no_thunks
      String -> Property -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"PoP rawSerialise" (Property -> Spec)
-> ((PossessionProofDSIGN v -> Property) -> Property)
-> (PossessionProofDSIGN v -> Property)
-> Spec
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (PossessionProofDSIGN v -> Property) -> Property
forall prop.
Testable prop =>
(PossessionProofDSIGN v -> prop) -> Property
forAllPoP ((PossessionProofDSIGN v -> Property) -> Spec)
-> (PossessionProofDSIGN v -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$ \PossessionProofDSIGN v
pop ->
        ByteString -> Property
forall a. NoThunks a => a -> Property
prop_no_thunks (PossessionProofDSIGN v -> ByteString
forall v.
DSIGNAggregatable v =>
PossessionProofDSIGN v -> ByteString
rawSerialisePossessionProofDSIGN PossessionProofDSIGN v
pop)
      String -> Property -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"PoP rawDeserialise" (Property -> Spec)
-> ((PossessionProofDSIGN v -> Property) -> Property)
-> (PossessionProofDSIGN v -> Property)
-> Spec
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (PossessionProofDSIGN v -> Property) -> Property
forall prop.
Testable prop =>
(PossessionProofDSIGN v -> prop) -> Property
forAllPoP ((PossessionProofDSIGN v -> Property) -> Spec)
-> (PossessionProofDSIGN v -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$ \PossessionProofDSIGN v
pop ->
        PossessionProofDSIGN v -> Property
forall a. NoThunks a => a -> Property
prop_no_thunks (Maybe (PossessionProofDSIGN v) -> PossessionProofDSIGN v
forall a. HasCallStack => Maybe a -> a
fromJust (Maybe (PossessionProofDSIGN v) -> PossessionProofDSIGN v)
-> Maybe (PossessionProofDSIGN v) -> PossessionProofDSIGN v
forall a b. (a -> b) -> a -> b
$! forall v.
DSIGNAggregatable v =>
ByteString -> Maybe (PossessionProofDSIGN v)
rawDeserialisePossessionProofDSIGN @v (ByteString -> Maybe (PossessionProofDSIGN v))
-> (PossessionProofDSIGN v -> ByteString)
-> PossessionProofDSIGN v
-> Maybe (PossessionProofDSIGN v)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PossessionProofDSIGN v -> ByteString
forall v.
DSIGNAggregatable v =>
PossessionProofDSIGN v -> ByteString
rawSerialisePossessionProofDSIGN (PossessionProofDSIGN v -> Maybe (PossessionProofDSIGN v))
-> PossessionProofDSIGN v -> Maybe (PossessionProofDSIGN v)
forall a b. (a -> b) -> a -> b
$ PossessionProofDSIGN v
pop)
  where
    forAllPoP
      :: Testable prop
      => (PossessionProofDSIGN v -> prop)
      -> Property
    forAllPoP :: forall prop.
Testable prop =>
(PossessionProofDSIGN v -> prop) -> Property
forAllPoP =
      Gen (PossessionProofDSIGN v)
-> (PossessionProofDSIGN v -> String)
-> (PossessionProofDSIGN v -> prop)
-> Property
forall prop a.
Testable prop =>
Gen a -> (a -> String) -> (a -> prop) -> Property
forAllShow (forall v.
DSIGNAggregatable v =>
Gen (ContextDSIGN v)
-> Gen (KeyGenContextDSIGN v) -> Gen (PossessionProofDSIGN v)
defaultPossessionProofGen @v Gen (ContextDSIGN v)
genContext Gen (KeyGenContextDSIGN v)
genKeyCtx) PossessionProofDSIGN v -> String
forall a. Show a => a -> String
ppShow
    genAggregateCase :: Gen (ContextDSIGN v)
-> Gen Message
-> Gen
     (ContextDSIGN v, Message,
      [(VerKeyDSIGN v, PossessionProofDSIGN v)], [SigDSIGN v])
genAggregateCase Gen (ContextDSIGN v)
genCtx Gen Message
genMsg' = do
      ContextDSIGN v
ctx <- Gen (ContextDSIGN v)
genCtx
      Message
msg <- Gen Message
genMsg'
      -- These crypto operations can be expensive, so limit the number of
      -- signatures to a reasonable number for testing.
      Int
n   <- (Int, Int) -> Gen Int
Gen.chooseInt (Int
1, Int
8)
      [SignKeyDSIGN v]
sks <- Int -> Gen (SignKeyDSIGN v) -> Gen [SignKeyDSIGN v]
forall (m :: * -> *) a. Applicative m => Int -> m a -> m [a]
replicateM Int
n (forall v.
DSIGNAlgorithm v =>
Gen (KeyGenContextDSIGN v) -> Gen (SignKeyDSIGN v)
defaultSignKeyWithContextGen @v Gen (KeyGenContextDSIGN v)
genKeyCtx)
      let vksPops :: [(VerKeyDSIGN v, PossessionProofDSIGN v)]
vksPops = [ ( SignKeyDSIGN v -> VerKeyDSIGN v
forall v. DSIGNAlgorithm v => SignKeyDSIGN v -> VerKeyDSIGN v
deriveVerKeyDSIGN SignKeyDSIGN v
sk
                     , ContextDSIGN v -> SignKeyDSIGN v -> PossessionProofDSIGN v
forall v.
(DSIGNAggregatable v, HasCallStack) =>
ContextDSIGN v -> SignKeyDSIGN v -> PossessionProofDSIGN v
createPossessionProofDSIGN ContextDSIGN v
ctx SignKeyDSIGN v
sk
                     )
                   | SignKeyDSIGN v
sk <- [SignKeyDSIGN v]
sks
                   ]
          sigs :: [SigDSIGN v]
sigs = [ ContextDSIGN v -> Message -> SignKeyDSIGN v -> SigDSIGN v
forall v a.
(DSIGNAlgorithm v, Signable v a, HasCallStack) =>
ContextDSIGN v -> a -> SignKeyDSIGN v -> SigDSIGN v
forall a.
(Signable v a, HasCallStack) =>
ContextDSIGN v -> a -> SignKeyDSIGN v -> SigDSIGN v
signDSIGN ContextDSIGN v
ctx Message
msg SignKeyDSIGN v
sk | SignKeyDSIGN v
sk <- [SignKeyDSIGN v]
sks ]
      (ContextDSIGN v, Message,
 [(VerKeyDSIGN v, PossessionProofDSIGN v)], [SigDSIGN v])
-> Gen
     (ContextDSIGN v, Message,
      [(VerKeyDSIGN v, PossessionProofDSIGN v)], [SigDSIGN v])
forall a. a -> Gen a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ContextDSIGN v
ctx, Message
msg, [(VerKeyDSIGN v, PossessionProofDSIGN v)]
vksPops, [SigDSIGN v]
sigs)

    genAggregateCaseAtLeast2 :: Gen (ContextDSIGN v)
-> Gen Message
-> Gen
     (ContextDSIGN v, Message,
      [(VerKeyDSIGN v, PossessionProofDSIGN v)], [SigDSIGN v])
genAggregateCaseAtLeast2 Gen (ContextDSIGN v)
genCtx Gen Message
genMsg' = do
      ContextDSIGN v
ctx <- Gen (ContextDSIGN v)
genCtx
      Message
msg <- Gen Message
genMsg'
      -- These crypto operations can be expensive, so limit the number of
      -- signatures to a reasonable number for testing.
      Int
n   <- (Int, Int) -> Gen Int
Gen.chooseInt (Int
2, Int
8)
      [SignKeyDSIGN v]
sks <- Int -> Gen (SignKeyDSIGN v) -> Gen [SignKeyDSIGN v]
forall (m :: * -> *) a. Applicative m => Int -> m a -> m [a]
replicateM Int
n (forall v.
DSIGNAlgorithm v =>
Gen (KeyGenContextDSIGN v) -> Gen (SignKeyDSIGN v)
defaultSignKeyWithContextGen @v Gen (KeyGenContextDSIGN v)
genKeyCtx)
      let vksPops :: [(VerKeyDSIGN v, PossessionProofDSIGN v)]
vksPops = [ ( SignKeyDSIGN v -> VerKeyDSIGN v
forall v. DSIGNAlgorithm v => SignKeyDSIGN v -> VerKeyDSIGN v
deriveVerKeyDSIGN SignKeyDSIGN v
sk
                     , ContextDSIGN v -> SignKeyDSIGN v -> PossessionProofDSIGN v
forall v.
(DSIGNAggregatable v, HasCallStack) =>
ContextDSIGN v -> SignKeyDSIGN v -> PossessionProofDSIGN v
createPossessionProofDSIGN ContextDSIGN v
ctx SignKeyDSIGN v
sk
                     )
                   | SignKeyDSIGN v
sk <- [SignKeyDSIGN v]
sks
                   ]
          sigs :: [SigDSIGN v]
sigs = [ ContextDSIGN v -> Message -> SignKeyDSIGN v -> SigDSIGN v
forall v a.
(DSIGNAlgorithm v, Signable v a, HasCallStack) =>
ContextDSIGN v -> a -> SignKeyDSIGN v -> SigDSIGN v
forall a.
(Signable v a, HasCallStack) =>
ContextDSIGN v -> a -> SignKeyDSIGN v -> SigDSIGN v
signDSIGN ContextDSIGN v
ctx Message
msg SignKeyDSIGN v
sk | SignKeyDSIGN v
sk <- [SignKeyDSIGN v]
sks ]
      (ContextDSIGN v, Message,
 [(VerKeyDSIGN v, PossessionProofDSIGN v)], [SigDSIGN v])
-> Gen
     (ContextDSIGN v, Message,
      [(VerKeyDSIGN v, PossessionProofDSIGN v)], [SigDSIGN v])
forall a. a -> Gen a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ContextDSIGN v
ctx, Message
msg, [(VerKeyDSIGN v, PossessionProofDSIGN v)]
vksPops, [SigDSIGN v]
sigs)