From 977f4e791d0f2f8a3579bbcd760850e61931e9a9 Mon Sep 17 00:00:00 2001 From: Rene Vergara Date: Wed, 6 Mar 2024 15:10:26 -0600 Subject: [PATCH] Implement Unified HRP constants --- src/ZcashHaskell/Orchard.hs | 4 +-- src/ZcashHaskell/Types.hs | 56 +++++++++++++++---------------------- zcash-haskell.cabal | 2 +- 3 files changed, 25 insertions(+), 37 deletions(-) diff --git a/src/ZcashHaskell/Orchard.hs b/src/ZcashHaskell/Orchard.hs index 9d33959..d71ce64 100644 --- a/src/ZcashHaskell/Orchard.hs +++ b/src/ZcashHaskell/Orchard.hs @@ -77,8 +77,8 @@ encodeUnifiedAddress ua = encodeBech32m (E.encodeUtf8 hr) b where hr = case ua_net ua of - MainNet -> "u" - TestNet -> "utest" + MainNet -> uniPaymentAddressHrp + TestNet -> uniTestPaymentAddressHrp b = f4Jumble $ tReceiver <> sReceiver <> oReceiver <> padding tReceiver = case t_rec ua of diff --git a/src/ZcashHaskell/Types.hs b/src/ZcashHaskell/Types.hs index 374474d..f9fe6f2 100644 --- a/src/ZcashHaskell/Types.hs +++ b/src/ZcashHaskell/Types.hs @@ -77,43 +77,31 @@ getValue c = TestNetCoin -> 1 RegTestNetCoin -> 1 --- | Type for Sapling Human-readable part -data SaplingHrp - = SapExtSpendingKey - | SapExtFullViewingKey - | SapPaymentAddress - | SapTestExtSpendingKey - | SapTestExtFullViewingKey - | SapTestPaymentAddress +-- | Constants for Sapling Human-readable part +sapExtSpendingKeyHrp = "secret-extended-key-main" :: String -getSaplingHrp :: SaplingHrp -> String -getSaplingHrp s = - case s of - SapExtSpendingKey -> "secret-extended-key-main" - SapExtFullViewingKey -> "zxviews" - SapPaymentAddress -> "zs" - SapTestExtSpendingKey -> "secret-extended-key-test" - SapTestExtFullViewingKey -> "zxviewtestsapling" - SapTestPaymentAddress -> "ztestsapling" +sapExtFullViewingKeyHrp = "zxviews" :: String --- | Type for Unified Human-readable part -data UnifiedHrp - = UniPaymentAddress - | UniFullViewingKey - | UniIncomingViewingKey - | UniTestPaymentAddress - | UniTestFullViewingKey - | UniTestIncomingViewingKey +sapPaymentAddressHrp = "zs" :: String -getUnifiedHrp :: UnifiedHrp -> String -getUnifiedHrp s = - case s of - UniPaymentAddress -> "u" - UniFullViewingKey -> "uview" - UniIncomingViewingKey -> "uivk" - UniTestPaymentAddress -> "utest" - UniTestFullViewingKey -> "uviewtest" - UniTestIncomingViewingKey -> "uivktest" +sapTestExtSpendingKeyHrp = "secret-extended-key-test" :: String + +sapTestExtFullViewingKeyHrp = "zxviewtestsapling" :: String + +sapTestPaymentAddressHrp = "ztestsapling" :: String + +-- | Constants for Unified Human-readable part +uniPaymentAddressHrp = "u" :: T.Text + +uniFullViewingKeyHrp = "uview" :: T.Text + +uniIncomingViewingKeyHrp = "uivk" :: T.Text + +uniTestPaymentAddressHrp = "utest" :: T.Text + +uniTestFullViewingKeyHrp = "uviewtest" :: T.Text + +uniTestIncomingViewingKeyHrp = "uivktest" :: T.Text -- | Function to get the Base58 prefix for encoding a 'TransparentAddress' getTransparentPrefix :: ZcashNet -> TransparentType -> (Word8, Word8) diff --git a/zcash-haskell.cabal b/zcash-haskell.cabal index e4a2f3b..d6d04ea 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.4.3.0 +version: 0.4.3.1 synopsis: Utilities to interact with the Zcash blockchain description: Please see the README on the repo at category: Blockchain