diff --git a/CHANGELOG.md b/CHANGELOG.md index fe73f0a..31c81c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Types for Spending Keys and Receivers for Sapling and Orchard - Function to generate an Orchard receiver - Function to generate a Sapling receiver +- Function to generate a Transparent receiver ### Changed diff --git a/src/ZcashHaskell/Orchard.hs b/src/ZcashHaskell/Orchard.hs index 3021234..a810114 100644 --- a/src/ZcashHaskell/Orchard.hs +++ b/src/ZcashHaskell/Orchard.hs @@ -37,7 +37,10 @@ import ZcashHaskell.Utils (encodeBech32m, f4Jumble) -- | Derives an Orchard spending key for the given seed and account ID genOrchardSpendingKey :: - Seed -> CoinType -> AccountId -> Maybe OrchardSpendingKey + Seed -- ^ The cryptographic seed for the wallet + -> CoinType -- ^ The coin type constant + -> AccountId -- ^ The index of the account to be used + -> Maybe OrchardSpendingKey genOrchardSpendingKey s coinType accountId = if BS.length k /= 32 then Nothing @@ -52,7 +55,10 @@ genOrchardSpendingKey s coinType accountId = -- | Derives an Orchard receiver for the given spending key and index genOrchardReceiver :: - Int -> Scope -> OrchardSpendingKey -> Maybe OrchardReceiver + Int -- ^ The index of the address to be created + -> Scope -- ^ `External` for wallet addresses, `Internal` for change addresses + -> OrchardSpendingKey -- ^ The spending key + -> Maybe OrchardReceiver genOrchardReceiver i scope osk = if BS.length k /= 43 then Nothing diff --git a/src/ZcashHaskell/Transparent.hs b/src/ZcashHaskell/Transparent.hs index 52bc469..690fa4c 100644 --- a/src/ZcashHaskell/Transparent.hs +++ b/src/ZcashHaskell/Transparent.hs @@ -41,7 +41,11 @@ import ZcashHaskell.Types , getValue ) -encodeTransparent :: ZcashNet -> TransparentAddress -> T.Text +-- | Encodes a `TransparentAddress` into the human-readable format per the Zcash Protocol section 5.6.1.1 +encodeTransparent :: + ZcashNet -- ^ The network, `MainNet` or `TestNet` + -> TransparentAddress -- ^ The address to encode + -> T.Text encodeTransparent zNet t = encodeTransparent' (getTransparentPrefix zNet (ta_type t)) $ toBytes $ ta_bytes t @@ -56,7 +60,11 @@ encodeTransparent zNet t = checksum = sha256 $ sha256 digest -- | Generate an Extended Private Key from a known HDSeed. -genTransparentPrvKey :: Seed -> CoinType -> AccountId -> IO XPrvKey +genTransparentPrvKey :: + Seed -- ^ The cryptographic seed of the wallet + -> CoinType -- ^ The coin type constant to be used + -> AccountId -- ^ The index of the account to be used + -> IO XPrvKey genTransparentPrvKey hdseed ctype accid = do let coin = getValue ctype ioCtx <- createContext @@ -64,18 +72,12 @@ genTransparentPrvKey hdseed ctype accid = do let prvKey = makeXPrvKey $ getBytes hdseed return $ derivePath ioCtx path prvKey -genTransparentPubKey :: XPrvKey -> IO XPubKey -genTransparentPubKey xPrvKey = do - ioCtx <- createContext - return $ deriveXPubKey ioCtx xPrvKey - -genTransparentPubAddress :: XPubKey -> IO Address -genTransparentPubAddress xPubKey = do - ioCtx <- createContext - return $ xPubAddr ioCtx xPubKey - -- | Generate a transparent receiver -genTransparentReceiver :: Int -> Scope -> XPrvKey -> IO TransparentAddress +genTransparentReceiver :: + 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 TransparentAddress genTransparentReceiver i scope xprvk = do ioCtx <- createContext let s = diff --git a/src/ZcashHaskell/Types.hs b/src/ZcashHaskell/Types.hs index 2e6cd5c..12a27a2 100644 --- a/src/ZcashHaskell/Types.hs +++ b/src/ZcashHaskell/Types.hs @@ -65,8 +65,8 @@ instance ToBytes Phrase where -- | Scope for addresses/receivers data Scope - = External - | Internal + = External -- ^ Addresses used publically to receive payments + | Internal -- ^ Addresses used internally by wallets for change and shielding deriving (Eq, Prelude.Show, Read) -- | Type to represent data after Bech32 decoding diff --git a/zcash-haskell.cabal b/zcash-haskell.cabal index d7d33d9..646d810 100644 --- a/zcash-haskell.cabal +++ b/zcash-haskell.cabal @@ -5,7 +5,7 @@ cabal-version: 3.0 -- see: https://github.com/sol/hpack name: zcash-haskell -version: 0.5.0.0 +version: 0.5.0.1 synopsis: Utilities to interact with the Zcash blockchain description: Please see the README on the repo at category: Blockchain