53 lines
1.7 KiB
Haskell
53 lines
1.7 KiB
Haskell
|
{- Copyright 2022-2024 Vergara Technologies LLC
|
||
|
|
||
|
This file is part of Zcash-Haskell.
|
||
|
|
||
|
Zcash-Haskell is free software: you can redistribute it and/or modify it
|
||
|
under the terms of the GNU Lesser General Public License as published by the Free
|
||
|
Software Foundation, either version 3 of the License, or (at your option) any
|
||
|
later version.
|
||
|
|
||
|
Zcash-Haskell is distributed in the hope that it will be useful, but WITHOUT
|
||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||
|
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||
|
details.
|
||
|
|
||
|
You should have received a copy of the GNU Lesser General Public License along with
|
||
|
Zcash-Haskell. If not, see <https://www.gnu.org/licenses/>.
|
||
|
-}
|
||
|
-- |
|
||
|
-- Module : ZcashHaskell.Keys
|
||
|
-- Copyright : 2022-2024 Vergara Technologies
|
||
|
-- License : LGPL-3
|
||
|
--
|
||
|
-- 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)
|
||
|
|
||
|
-- | Generate a random seed that can be used to generate private keys for shielded addresses and transparent addresses.
|
||
|
generateWalletSeedPhrase :: IO Phrase
|
||
|
generateWalletSeedPhrase = withBorshVarBuffer rustWrapperGenSeedPhrase
|
||
|
|
||
|
-- | Get
|
||
|
getWalletSeed :: Phrase -> Maybe Seed
|
||
|
getWalletSeed p =
|
||
|
if BS.length result > 0
|
||
|
then Just result
|
||
|
else Nothing
|
||
|
where
|
||
|
result :: Seed
|
||
|
result = (withPureBorshVarBuffer . rustWrapperGetSeed) p
|