{-# 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,
  )
import Test.Hspec (Spec, describe)
import Test.Hspec.QuickCheck (prop, modifyMaxSize)

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

import Text.Show.Pretty (ppShow)

#ifdef SECP256K1_ENABLED
import Control.Monad (replicateM)
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 Cardano.Crypto.DSIGN (
  MockDSIGN,
  Ed25519DSIGN,
  Ed448DSIGN,
  DSIGNAlgorithm (
    SeedSizeDSIGN,
    VerKeyDSIGN,
    SignKeyDSIGN,
    SigDSIGN,
    ContextDSIGN,
    Signable,
    rawSerialiseVerKeyDSIGN,
    rawDeserialiseVerKeyDSIGN,
    rawSerialiseSignKeyDSIGN,
    rawDeserialiseSignKeyDSIGN,
    rawSerialiseSigDSIGN,
    rawDeserialiseSigDSIGN
    ),
  sizeVerKeyDSIGN,
  sizeSignKeyDSIGN,
  sizeSigDSIGN,
  encodeVerKeyDSIGN,
  decodeVerKeyDSIGN,
  encodeSignKeyDSIGN,
  decodeSignKeyDSIGN,
  encodeSigDSIGN,
  decodeSigDSIGN,
  signDSIGN,
  deriveVerKeyDSIGN,
  verifyDSIGN,
  genKeyDSIGN,
  seedSizeDSIGN,

  DSIGNMAlgorithm (SignKeyDSIGNM, deriveVerKeyDSIGNM),
  UnsoundDSIGNMAlgorithm,
  rawSerialiseSignKeyDSIGNM,
  rawDeserialiseSignKeyDSIGNM,
  signDSIGNM,
  deriveVerKeyDSIGN,
  genKeyDSIGNM,

  getSeedDSIGNM,
  forgetSignKeyDSIGNM
  )
import Cardano.Binary (FromCBOR, ToCBOR)
import Cardano.Crypto.PinnedSizedBytes (PinnedSizedBytes)
import Cardano.Crypto.DirectSerialise
import Test.Crypto.Util (
#if SECP256K1_ENABLED
  BadInputFor,
  genBadInputFor,
  shrinkBadInputFor,
#endif
  Message,
  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 (SizeHash), Blake2b_256, SHA256, Keccak256)
#endif

mockSigGen :: Gen (SigDSIGN MockDSIGN)
mockSigGen :: Gen (SigDSIGN MockDSIGN)
mockSigGen = Gen (SigDSIGN MockDSIGN)
forall a.
(DSIGNAlgorithm a, ContextDSIGN a ~ (), Signable a Message) =>
Gen (SigDSIGN a)
defaultSigGen

ed25519SigGen :: Gen (SigDSIGN Ed25519DSIGN)
ed25519SigGen :: Gen (SigDSIGN Ed25519DSIGN)
ed25519SigGen = Gen (SigDSIGN Ed25519DSIGN)
forall a.
(DSIGNAlgorithm a, ContextDSIGN a ~ (), Signable a Message) =>
Gen (SigDSIGN a)
defaultSigGen

ed448SigGen :: Gen (SigDSIGN Ed448DSIGN)
ed448SigGen :: Gen (SigDSIGN Ed448DSIGN)
ed448SigGen = Gen (SigDSIGN Ed448DSIGN)
forall a.
(DSIGNAlgorithm a, ContextDSIGN a ~ (), Signable a Message) =>
Gen (SigDSIGN a)
defaultSigGen

#ifdef SECP256K1_ENABLED
ecdsaSigGen :: Gen (SigDSIGN EcdsaSecp256k1DSIGN)
ecdsaSigGen :: Gen (SigDSIGN EcdsaSecp256k1DSIGN)
ecdsaSigGen = do
  MessageHash
msg <- Gen MessageHash
genEcdsaMsg
  ContextDSIGN EcdsaSecp256k1DSIGN
-> MessageHash
-> SignKeyDSIGN EcdsaSecp256k1DSIGN
-> SigDSIGN EcdsaSecp256k1DSIGN
forall v a.
(DSIGNAlgorithm v, Signable v a, HasCallStack) =>
ContextDSIGN v -> a -> SignKeyDSIGN v -> SigDSIGN v
forall a.
(Signable EcdsaSecp256k1DSIGN a, HasCallStack) =>
ContextDSIGN EcdsaSecp256k1DSIGN
-> a
-> SignKeyDSIGN EcdsaSecp256k1DSIGN
-> SigDSIGN EcdsaSecp256k1DSIGN
signDSIGN () MessageHash
msg (SignKeyDSIGN EcdsaSecp256k1DSIGN -> SigDSIGN EcdsaSecp256k1DSIGN)
-> Gen (SignKeyDSIGN EcdsaSecp256k1DSIGN)
-> Gen (SigDSIGN EcdsaSecp256k1DSIGN)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen (SignKeyDSIGN EcdsaSecp256k1DSIGN)
forall a. DSIGNAlgorithm a => Gen (SignKeyDSIGN a)
defaultSignKeyGen

schnorrSigGen :: Gen (SigDSIGN SchnorrSecp256k1DSIGN)
schnorrSigGen :: Gen (SigDSIGN SchnorrSecp256k1DSIGN)
schnorrSigGen = Gen (SigDSIGN SchnorrSecp256k1DSIGN)
forall a.
(DSIGNAlgorithm a, ContextDSIGN a ~ (), Signable a Message) =>
Gen (SigDSIGN a)
defaultSigGen

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

defaultVerKeyGen :: forall (a :: Type) .
  (DSIGNAlgorithm a) => Gen (VerKeyDSIGN a)
defaultVerKeyGen :: forall a. DSIGNAlgorithm a => Gen (VerKeyDSIGN a)
defaultVerKeyGen = SignKeyDSIGN a -> VerKeyDSIGN a
forall v. DSIGNAlgorithm v => SignKeyDSIGN v -> VerKeyDSIGN v
deriveVerKeyDSIGN (SignKeyDSIGN a -> VerKeyDSIGN a)
-> Gen (SignKeyDSIGN a) -> Gen (VerKeyDSIGN a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. DSIGNAlgorithm a => Gen (SignKeyDSIGN a)
defaultSignKeyGen @a

defaultSignKeyGen :: forall (a :: Type).
  (DSIGNAlgorithm a) => Gen (SignKeyDSIGN a)
defaultSignKeyGen :: forall a. DSIGNAlgorithm a => Gen (SignKeyDSIGN a)
defaultSignKeyGen =
  Seed -> SignKeyDSIGN a
forall v. DSIGNAlgorithm v => Seed -> SignKeyDSIGN v
genKeyDSIGN (Seed -> SignKeyDSIGN a) -> Gen Seed -> Gen (SignKeyDSIGN a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Word -> Gen Seed
arbitrarySeedOfSize (Proxy a -> Word
forall v (proxy :: * -> *). DSIGNAlgorithm v => proxy v -> Word
seedSizeDSIGN (Proxy a
forall {k} (t :: k). Proxy t
Proxy :: Proxy a))

defaultSigGen :: forall (a :: Type) .
  (DSIGNAlgorithm a, ContextDSIGN a ~ (), Signable a Message) =>
  Gen (SigDSIGN a)
defaultSigGen :: forall a.
(DSIGNAlgorithm a, ContextDSIGN a ~ (), Signable a Message) =>
Gen (SigDSIGN a)
defaultSigGen = do
  Message
msg :: Message <- Gen Message
forall a. Arbitrary a => Gen a
arbitrary
  ContextDSIGN a -> Message -> SignKeyDSIGN a -> SigDSIGN a
forall v a.
(DSIGNAlgorithm v, Signable v a, HasCallStack) =>
ContextDSIGN v -> a -> SignKeyDSIGN v -> SigDSIGN v
forall a.
(Signable a a, HasCallStack) =>
ContextDSIGN a -> a -> SignKeyDSIGN a -> SigDSIGN a
signDSIGN () Message
msg (SignKeyDSIGN a -> SigDSIGN a)
-> Gen (SignKeyDSIGN a) -> Gen (SigDSIGN a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen (SignKeyDSIGN a)
forall a. DSIGNAlgorithm a => Gen (SignKeyDSIGN a)
defaultSignKeyGen

-- 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
modifyMaxSize (Int -> Int -> Int
forall a b. a -> b -> a
const 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
       Gen (SigDSIGN MockDSIGN) -> Gen Message -> String -> Spec
forall v a.
(DSIGNAlgorithm v, Signable v a, ContextDSIGN 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)) =>
Gen (SigDSIGN v) -> Gen a -> String -> Spec
testDSIGNAlgorithm Gen (SigDSIGN MockDSIGN)
mockSigGen (forall a. Arbitrary a => Gen a
arbitrary @Message) String
"MockDSIGN"
       Gen (SigDSIGN Ed25519DSIGN) -> Gen Message -> String -> Spec
forall v a.
(DSIGNAlgorithm v, Signable v a, ContextDSIGN 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)) =>
Gen (SigDSIGN v) -> Gen a -> String -> Spec
testDSIGNAlgorithm Gen (SigDSIGN Ed25519DSIGN)
ed25519SigGen (forall a. Arbitrary a => Gen a
arbitrary @Message) String
"Ed25519DSIGN"
       Gen (SigDSIGN Ed448DSIGN) -> Gen Message -> String -> Spec
forall v a.
(DSIGNAlgorithm v, Signable v a, ContextDSIGN 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)) =>
Gen (SigDSIGN v) -> Gen a -> String -> Spec
testDSIGNAlgorithm Gen (SigDSIGN Ed448DSIGN)
ed448SigGen (forall a. Arbitrary a => Gen a
arbitrary @Message) String
"Ed448DSIGN"
#ifdef SECP256K1_ENABLED
       Gen (SigDSIGN EcdsaSecp256k1DSIGN)
-> Gen MessageHash -> String -> Spec
forall v a.
(DSIGNAlgorithm v, Signable v a, ContextDSIGN 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)) =>
Gen (SigDSIGN v) -> Gen a -> String -> Spec
testDSIGNAlgorithm Gen (SigDSIGN EcdsaSecp256k1DSIGN)
ecdsaSigGen Gen MessageHash
genEcdsaMsg String
"EcdsaSecp256k1DSIGN"
       Gen (SigDSIGN SchnorrSecp256k1DSIGN)
-> Gen Message -> String -> Spec
forall v a.
(DSIGNAlgorithm v, Signable v a, ContextDSIGN 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)) =>
Gen (SigDSIGN v) -> Gen a -> String -> Spec
testDSIGNAlgorithm Gen (SigDSIGN SchnorrSecp256k1DSIGN)
schnorrSigGen (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, SizeHash 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, SizeHash 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, SizeHash 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, SizeHash 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"

testDSIGNAlgorithm :: forall (v :: Type) (a :: Type).
  (DSIGNAlgorithm v,
   Signable v a,
   ContextDSIGN 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)) =>
  Gen (SigDSIGN v) ->
  Gen a ->
  String ->
  Spec
testDSIGNAlgorithm :: forall v a.
(DSIGNAlgorithm v, Signable v a, ContextDSIGN 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)) =>
Gen (SigDSIGN v) -> Gen a -> String -> Spec
testDSIGNAlgorithm Gen (SigDSIGN v)
genSig 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
  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 (forall a. DSIGNAlgorithm a => Gen (VerKeyDSIGN a)
defaultVerKeyGen @v)
                   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 a. DSIGNAlgorithm a => Gen (SignKeyDSIGN a)
defaultSignKeyGen @v)
                   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 (forall a. DSIGNAlgorithm a => Gen (VerKeyDSIGN a)
defaultVerKeyGen @v)
                   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
sizeVerKeyDSIGN (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 a. DSIGNAlgorithm a => Gen (SignKeyDSIGN a)
defaultSignKeyGen @v)
                   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
sizeSignKeyDSIGN (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
sizeSigDSIGN (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 (forall a. DSIGNAlgorithm a => Gen (VerKeyDSIGN a)
defaultVerKeyGen @v)
                   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 a. DSIGNAlgorithm a => Gen (SignKeyDSIGN a)
defaultSignKeyGen @v)
                   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 (forall a. DSIGNAlgorithm a => Gen (VerKeyDSIGN a)
defaultVerKeyGen @v) 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 a. DSIGNAlgorithm a => Gen (SignKeyDSIGN a)
defaultSignKeyGen @v) 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 (forall a. DSIGNAlgorithm a => Gen (VerKeyDSIGN a)
defaultVerKeyGen @v) 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 a. DSIGNAlgorithm a => Gen (SignKeyDSIGN a)
defaultSignKeyGen @v) 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 (forall a. DSIGNAlgorithm a => Gen (VerKeyDSIGN a)
defaultVerKeyGen @v) 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 a. DSIGNAlgorithm a => Gen (SignKeyDSIGN a)
defaultSignKeyGen @v) 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)
-> (((a, SignKeyDSIGN v) -> Property) -> Property)
-> ((a, SignKeyDSIGN v) -> Property)
-> Spec
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
        Gen (a, SignKeyDSIGN v)
-> ((a, SignKeyDSIGN v) -> String)
-> ((a, SignKeyDSIGN v) -> Property)
-> Property
forall prop a.
Testable prop =>
Gen a -> (a -> String) -> (a -> prop) -> Property
forAllShow ((,) (a -> SignKeyDSIGN v -> (a, SignKeyDSIGN v))
-> Gen a -> Gen (SignKeyDSIGN v -> (a, SignKeyDSIGN v))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen a
genMsg Gen (SignKeyDSIGN v -> (a, SignKeyDSIGN v))
-> Gen (SignKeyDSIGN v) -> Gen (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 a. DSIGNAlgorithm a => Gen (SignKeyDSIGN a)
defaultSignKeyGen @v) (a, SignKeyDSIGN v) -> String
forall a. Show a => a -> String
ppShow (((a, SignKeyDSIGN v) -> Property) -> Spec)
-> ((a, SignKeyDSIGN v) -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$
        (a, SignKeyDSIGN v) -> Property
forall v a.
(DSIGNAlgorithm v, ContextDSIGN v ~ (), Signable v a) =>
(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)
-> (((a, SignKeyDSIGN v, SignKeyDSIGN v) -> Property) -> Property)
-> ((a, SignKeyDSIGN v, SignKeyDSIGN v) -> Property)
-> Spec
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
        Gen (a, SignKeyDSIGN v, SignKeyDSIGN v)
-> ((a, SignKeyDSIGN v, SignKeyDSIGN v) -> String)
-> ((a, SignKeyDSIGN v, SignKeyDSIGN v) -> Property)
-> Property
forall prop a.
Testable prop =>
Gen a -> (a -> String) -> (a -> prop) -> Property
forAllShow Gen (a, SignKeyDSIGN v, SignKeyDSIGN v)
genWrongKey (a, SignKeyDSIGN v, SignKeyDSIGN v) -> String
forall a. Show a => a -> String
ppShow (((a, SignKeyDSIGN v, SignKeyDSIGN v) -> Property) -> Spec)
-> ((a, SignKeyDSIGN v, SignKeyDSIGN v) -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$
        (a, SignKeyDSIGN v, SignKeyDSIGN v) -> Property
forall v a.
(DSIGNAlgorithm v, ContextDSIGN v ~ (), Signable v a) =>
(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)
-> (((a, a, SignKeyDSIGN v) -> Property) -> Property)
-> ((a, a, SignKeyDSIGN v) -> Property)
-> Spec
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
        Gen (a, a, SignKeyDSIGN v)
-> ((a, a, SignKeyDSIGN v) -> String)
-> ((a, a, SignKeyDSIGN v) -> Property)
-> Property
forall prop a.
Testable prop =>
Gen a -> (a -> String) -> (a -> prop) -> Property
forAllShow Gen (a, a, SignKeyDSIGN v)
genWrongMsg (a, a, SignKeyDSIGN v) -> String
forall a. Show a => a -> String
ppShow (((a, a, SignKeyDSIGN v) -> Property) -> Spec)
-> ((a, a, SignKeyDSIGN v) -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$
        (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 (forall a. DSIGNAlgorithm a => Gen (VerKeyDSIGN a)
defaultVerKeyGen @v) 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 a. DSIGNAlgorithm a => Gen (SignKeyDSIGN a)
defaultSignKeyGen @v) 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 (forall a. DSIGNAlgorithm a => Gen (VerKeyDSIGN a)
defaultVerKeyGen @v) 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 (forall a. DSIGNAlgorithm a => Gen (VerKeyDSIGN a)
defaultVerKeyGen @v) 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 (a, SignKeyDSIGN v, SignKeyDSIGN v)
    genWrongKey :: Gen (a, SignKeyDSIGN v, SignKeyDSIGN v)
genWrongKey = do
      SignKeyDSIGN v
sk1 <- Gen (SignKeyDSIGN v)
forall a. DSIGNAlgorithm a => Gen (SignKeyDSIGN a)
defaultSignKeyGen
      SignKeyDSIGN v
sk2 <- Gen (SignKeyDSIGN v)
-> (SignKeyDSIGN v -> Bool) -> Gen (SignKeyDSIGN v)
forall a. Gen a -> (a -> Bool) -> Gen a
Gen.suchThat Gen (SignKeyDSIGN v)
forall a. DSIGNAlgorithm a => Gen (SignKeyDSIGN a)
defaultSignKeyGen (SignKeyDSIGN v -> SignKeyDSIGN v -> Bool
forall a. Eq a => a -> a -> Bool
/= SignKeyDSIGN v
sk1)
      a
msg <- Gen a
genMsg
      (a, SignKeyDSIGN v, SignKeyDSIGN v)
-> Gen (a, SignKeyDSIGN v, SignKeyDSIGN v)
forall a. a -> Gen a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (a
msg, SignKeyDSIGN v
sk1, SignKeyDSIGN v
sk2)
    genWrongMsg :: Gen (a, a, SignKeyDSIGN v)
    genWrongMsg :: Gen (a, a, SignKeyDSIGN v)
genWrongMsg = do
      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 (SignKeyDSIGN v)
forall a. DSIGNAlgorithm a => Gen (SignKeyDSIGN a)
defaultSignKeyGen
      (a, a, SignKeyDSIGN v) -> Gen (a, a, SignKeyDSIGN v)
forall a. a -> Gen a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (a
msg1, a
msg2, SignKeyDSIGN v
sk)

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
$ (Int -> Word
forall a b. (Integral a, Num b) => a -> b
fromIntegral (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
sizeVerKeyDSIGN (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 ((Int -> Word
forall a b. (Integral a, Num b) => a -> b
fromIntegral (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
sizeSignKeyDSIGN (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
$ (Int -> Word
forall a b. (Integral a, Num b) => a -> b
fromIntegral (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
sizeSigDSIGN (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 (Word -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word -> Int) -> Word -> Int
forall a b. (a -> b) -> a -> b
$ Proxy v -> Word
forall v (proxy :: * -> *). DSIGNAlgorithm v => proxy v -> Word
sizeVerKeyDSIGN (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 (Word -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word -> Int) -> Word -> Int
forall a b. (a -> b) -> a -> b
$ Proxy v -> Word
forall v (proxy :: * -> *). DSIGNAlgorithm v => proxy v -> Word
sizeSignKeyDSIGN (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 -> Property) -> Bool -> Property
forall a b. (a -> b) -> a -> b
$
                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 (Word -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word -> Int) -> Word -> Int
forall a b. (a -> b) -> a -> b
$ Proxy v -> Word
forall v (proxy :: * -> *). DSIGNAlgorithm v => proxy v -> Word
sizeVerKeyDSIGN (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 (Word -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word -> Int) -> Word -> Int
forall a b. (a -> b) -> a -> b
$ Proxy v -> Word
forall v (proxy :: * -> *). DSIGNAlgorithm v => proxy v -> Word
sizeSignKeyDSIGN (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 (Word -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word -> Int) -> Word -> Int
forall a b. (a -> b) -> a -> b
$ Proxy v -> Word
forall v (proxy :: * -> *). DSIGNAlgorithm v => proxy v -> Word
sizeSignKeyDSIGN (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 (Word -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word -> Int) -> Word -> Int
forall a b. (a -> b) -> a -> b
$ Proxy v -> Word
forall v (proxy :: * -> *). DSIGNAlgorithm v => proxy v -> Word
sizeSignKeyDSIGN (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 (Word -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word -> Int) -> Word -> Int
forall a b. (a -> b) -> a -> b
$ Proxy v -> Word
forall v (proxy :: * -> *). DSIGNAlgorithm v => proxy v -> Word
sizeVerKeyDSIGN (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 (Word -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word -> Int) -> Word -> Int
forall a b. (a -> b) -> a -> b
$ Proxy v -> Word
forall v (proxy :: * -> *). DSIGNAlgorithm v => proxy v -> Word
sizeVerKeyDSIGN (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
     , ContextDSIGN v ~ ()
     , Signable v a
     )
  => (a, SignKeyDSIGN v)
  -> Property
prop_dsign_verify :: forall v a.
(DSIGNAlgorithm v, ContextDSIGN v ~ (), Signable v a) =>
(a, SignKeyDSIGN v) -> Property
prop_dsign_verify (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 () 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 () 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
     , ContextDSIGN v ~ ()
     , Signable v a
     )
  => (a, SignKeyDSIGN v, SignKeyDSIGN v)
  -> Property
prop_dsign_verify_wrong_key :: forall v a.
(DSIGNAlgorithm v, ContextDSIGN v ~ (), Signable v a) =>
(a, SignKeyDSIGN v, SignKeyDSIGN v) -> Property
prop_dsign_verify_wrong_key (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 () 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 () 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 (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 () 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 () 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 (Integer -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (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, SizeHash h ~ SECP256K1_ECDSA_MESSAGE_BYTES) =>
  Proxy h -> String -> Spec
testEcdsaWithHashAlgorithm :: forall h.
(HashAlgorithm h, SizeHash 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 MessageHash
-> Gen
     (SignKeyDSIGN EcdsaSecp256k1DSIGN
      -> (MessageHash, SignKeyDSIGN EcdsaSecp256k1DSIGN))
forall (f :: * -> *) a b. Functor 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 a. DSIGNAlgorithm a => Gen (SignKeyDSIGN a)
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
forall v a.
(DSIGNAlgorithm v, ContextDSIGN v ~ (), Signable v a) =>
(a, SignKeyDSIGN v) -> Property
prop_dsign_verify
  where
    genMsg :: Gen MessageHash
    genMsg :: Gen MessageHash
genMsg = Proxy h -> ByteString -> MessageHash
forall h.
(HashAlgorithm h, SizeHash 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
#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)