From bc074d0386a1560cd923f6399a362739a2c9ca49 Mon Sep 17 00:00:00 2001 From: Rene Vergara Date: Wed, 1 May 2024 14:24:18 -0500 Subject: [PATCH] Add transparent key derivation --- CHANGELOG.md | 1 + src/ZcashHaskell/Transparent.hs | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e315c8..cf7b6d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Type for transaction creation errors - Types for Sapling circuit parameters - Function to create transaction +- Function to derive distinct transparent spending keys ### Changed diff --git a/src/ZcashHaskell/Transparent.hs b/src/ZcashHaskell/Transparent.hs index afe09e3..878a7d8 100644 --- a/src/ZcashHaskell/Transparent.hs +++ b/src/ZcashHaskell/Transparent.hs @@ -101,7 +101,22 @@ genTransparentReceiver i scope xprvk = do ScriptAddress j -> return $ TransparentReceiver P2SH $ fromBinary j _anyOtherKind -> throwIO $ userError "Unsupported transparent address type" --- } decode a Transparent Address in HRF and return a TransparentAddress object +-- | Generate a transparent receiver +genTransparentSecretKey :: + Int -- ^ The index of the address to be created + -> Scope -- ^ `External` for wallet addresses or `Internal` for change addresses + -> XPrvKey -- ^ The transparent private key + -> IO TransparentSpendingKey +genTransparentSecretKey i scope xprvk = do + ioCtx <- createContext + let s = + case scope of + External -> 0 + Internal -> 1 + let path = Deriv :/ s :/ fromIntegral i :: DerivPath + return $ derivePath ioCtx path xprvk + +-- | decode a Transparent Address in HRF and return a TransparentAddress object decodeTransparentAddress :: BS.ByteString -> Maybe TransparentAddress decodeTransparentAddress taddress = do if BS.length taddress < 34 -- 2.34.1