diff --git a/src/ZcashHaskell/Transparent.hs b/src/ZcashHaskell/Transparent.hs index 6de9200..b7bac10 100644 --- a/src/ZcashHaskell/Transparent.hs +++ b/src/ZcashHaskell/Transparent.hs @@ -26,19 +26,12 @@ import ZcashHaskell.Types ( TransparentAddress(..) , TransparentType(..) , ZcashNet(..) + , getTransparentPrefix ) encodeTransparent :: TransparentAddress -> T.Text encodeTransparent t = - case ta_type t of - P2SH -> - case ta_net t of - MainNet -> encodeTransparent' (0x1c, 0xbd) $ ta_bytes t - _ -> encodeTransparent' (0x1c, 0xba) $ ta_bytes t - P2PKH -> - case ta_net t of - MainNet -> encodeTransparent' (0x1c, 0xb8) $ ta_bytes t - _ -> encodeTransparent' (0x1d, 0x25) $ ta_bytes t + encodeTransparent' (getTransparentPrefix (ta_net t) (ta_type t)) $ ta_bytes t where encodeTransparent' :: (Word8, Word8) -> BS.ByteString -> T.Text encodeTransparent' (a, b) h = diff --git a/src/ZcashHaskell/Types.hs b/src/ZcashHaskell/Types.hs index 11668d1..374474d 100644 --- a/src/ZcashHaskell/Types.hs +++ b/src/ZcashHaskell/Types.hs @@ -64,7 +64,7 @@ data ZcashNet type AccountId = Int -- ** Constants --- | Types for coin types on the different networks +-- | Type for coin types on the different networks data CoinType = MainNetCoin | TestNetCoin @@ -77,6 +77,57 @@ getValue c = TestNetCoin -> 1 RegTestNetCoin -> 1 +-- | Type for Sapling Human-readable part +data SaplingHrp + = SapExtSpendingKey + | SapExtFullViewingKey + | SapPaymentAddress + | SapTestExtSpendingKey + | SapTestExtFullViewingKey + | SapTestPaymentAddress + +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" + +-- | Type for Unified Human-readable part +data UnifiedHrp + = UniPaymentAddress + | UniFullViewingKey + | UniIncomingViewingKey + | UniTestPaymentAddress + | UniTestFullViewingKey + | UniTestIncomingViewingKey + +getUnifiedHrp :: UnifiedHrp -> String +getUnifiedHrp s = + case s of + UniPaymentAddress -> "u" + UniFullViewingKey -> "uview" + UniIncomingViewingKey -> "uivk" + UniTestPaymentAddress -> "utest" + UniTestFullViewingKey -> "uviewtest" + UniTestIncomingViewingKey -> "uivktest" + +-- | Function to get the Base58 prefix for encoding a 'TransparentAddress' +getTransparentPrefix :: ZcashNet -> TransparentType -> (Word8, Word8) +getTransparentPrefix n t = + case t of + P2SH -> + case n of + MainNet -> (0x1c, 0xbd) + _ -> (0x1c, 0xba) + P2PKH -> + case n of + MainNet -> (0x1c, 0xb8) + _ -> (0x1d, 0x25) + -- * RPC -- | A type to model Zcash RPC calls data RpcCall = RpcCall