-- Copyright 2022-2024 Vergara Technologies LLC -- This file is part of Zcash-Haskell. -- -- | -- Module : ZcashHaskell.Keys -- Copyright : 2022-2024 Vergara Technologies -- License : MIT -- -- Maintainer : pitmutt@vergara.tech -- Stability : experimental -- Portability : unknown -- -- Functions to generate keys for the Zcash blockchain -- module ZcashHaskell.Keys where import C.Zcash (rustWrapperGenSeedPhrase, rustWrapperGetSeed) import qualified Data.ByteString as BS import qualified Data.Text as T import Foreign.Rust.Marshall.Variable ( withBorshVarBuffer , withPureBorshVarBuffer ) import ZcashHaskell.Types (Phrase, Seed(..), ToBytes(..)) -- | Generate a random seed that can be used to generate private keys for shielded addresses and transparent addresses. generateWalletSeedPhrase :: IO Phrase generateWalletSeedPhrase = withBorshVarBuffer rustWrapperGenSeedPhrase -- | Derive a cryptographic seed from the given seed phrase. getWalletSeed :: Phrase -> Maybe Seed getWalletSeed p = if BS.length (getBytes result) > 0 then Just result else Nothing where result :: Seed result = (withPureBorshVarBuffer . rustWrapperGetSeed) p