module Gen.Cardano.Crypto.Seed
  ( genSeed
  , genSeedForKey
  ) where

import           Cardano.Api (AsType, Key)
import           Cardano.Crypto.Seed (Seed)
import           Data.Functor ((<$>))
import           Data.Int (Int)
import           Hedgehog (MonadGen, Range)
import           Prelude (fromIntegral)

import qualified Cardano.Api as API
import qualified Cardano.Crypto.Seed as C
import qualified Hedgehog.Gen as G
import qualified Hedgehog.Range as R

genSeed :: MonadGen m => Range Int -> m Seed
genSeed :: Range Int -> m Seed
genSeed Range Int
r = ByteString -> Seed
C.mkSeedFromBytes (ByteString -> Seed) -> m ByteString -> m Seed
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Range Int -> m ByteString
forall (m :: * -> *). MonadGen m => Range Int -> m ByteString
G.bytes Range Int
r

genSeedForKey :: (Key key, MonadGen m) => AsType key -> m Seed
genSeedForKey :: AsType key -> m Seed
genSeedForKey AsType key
keyRole = Range Int -> m Seed
forall (m :: * -> *). MonadGen m => Range Int -> m Seed
genSeed (Int -> Range Int
forall a. a -> Range a
R.singleton (Word -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (AsType key -> Word
forall keyrole. Key keyrole => AsType keyrole -> Word
API.deterministicSigningKeySeedSize AsType key
keyRole)))