module Cardano.Crypto.Signing.KeyGen (
keyGen,
deterministicKeyGen,
)
where
import Cardano.Crypto.Signing.SigningKey (SigningKey (..))
import Cardano.Crypto.Signing.VerificationKey (VerificationKey (..))
import qualified Cardano.Crypto.Wallet as CC
import Cardano.Prelude
import Crypto.Random (MonadRandom, getRandomBytes)
import Data.ByteArray (ScrubbedBytes)
import qualified Data.ByteString as BS
createKeypairFromSeed :: BS.ByteString -> (CC.XPub, CC.XPrv)
createKeypairFromSeed :: ByteString -> (XPub, XPrv)
createKeypairFromSeed ByteString
seed =
let prv :: XPrv
prv = forall passPhrase seed.
(ByteArrayAccess passPhrase, ByteArrayAccess seed) =>
seed -> passPhrase -> XPrv
CC.generate ByteString
seed (forall a. Monoid a => a
mempty :: ScrubbedBytes) in (HasCallStack => XPrv -> XPub
CC.toXPub XPrv
prv, XPrv
prv)
keyGen :: MonadRandom m => m (VerificationKey, SigningKey)
keyGen :: forall (m :: * -> *).
MonadRandom m =>
m (VerificationKey, SigningKey)
keyGen = do
ByteString
seed <- forall (m :: * -> *) byteArray.
(MonadRandom m, ByteArray byteArray) =>
Int -> m byteArray
getRandomBytes Int
32
let (XPub
vk, XPrv
sk) = ByteString -> (XPub, XPrv)
createKeypairFromSeed ByteString
seed
forall (m :: * -> *) a. Monad m => a -> m a
return (XPub -> VerificationKey
VerificationKey XPub
vk, XPrv -> SigningKey
SigningKey XPrv
sk)
deterministicKeyGen :: BS.ByteString -> (VerificationKey, SigningKey)
deterministicKeyGen :: ByteString -> (VerificationKey, SigningKey)
deterministicKeyGen ByteString
seed =
forall (p :: * -> * -> *) a b c d.
Bifunctor p =>
(a -> b) -> (c -> d) -> p a c -> p b d
bimap XPub -> VerificationKey
VerificationKey XPrv -> SigningKey
SigningKey (ByteString -> (XPub, XPrv)
createKeypairFromSeed ByteString
seed)