diff --git a/src/ZcashHaskell/Sapling.hs b/src/ZcashHaskell/Sapling.hs index f5a7c43..ac583cd 100644 --- a/src/ZcashHaskell/Sapling.hs +++ b/src/ZcashHaskell/Sapling.hs @@ -14,10 +14,12 @@ import qualified Data.ByteString as BS import Foreign.Rust.Marshall.Variable (withPureBorshVarBuffer) import ZcashHaskell.Types ( DecodedNote(..) + , RawData(..) , RawTxResponse(..) , ShieldedOutput(..) , decodeHexText ) +import ZcashHaskell.Utils (decodeBech32) -- | Check if given bytesting is a valid encoded shielded address isValidShieldedAddress :: BS.ByteString -> Bool @@ -28,7 +30,12 @@ getShieldedOutputs t = withPureBorshVarBuffer $ rustWrapperTxParse t -- | Check if given bytestring is a valid Sapling viewing key isValidSaplingViewingKey :: BS.ByteString -> Bool -isValidSaplingViewingKey = rustWrapperSaplingVkDecode +isValidSaplingViewingKey k = + case hrp decodedKey of + "zxviews" -> rustWrapperSaplingVkDecode $ bytes decodedKey + _ -> False + where + decodedKey = decodeBech32 k -- | Check if the given bytestring for the Sapling viewing key matches the second bytestring for the address matchSaplingAddress :: BS.ByteString -> BS.ByteString -> Bool diff --git a/test/Spec.hs b/test/Spec.hs index 831bde4..660d342 100644 --- a/test/Spec.hs +++ b/test/Spec.hs @@ -279,7 +279,7 @@ main = do let rawSa' = decodeBech32 sa' it "is mainnet" $ do hrp rawKey `shouldBe` "zxviews" it "is valid Sapling extended full viewing key" $ do - isValidSaplingViewingKey (bytes rawKey) `shouldBe` True + isValidSaplingViewingKey vk `shouldBe` True it "matches the right Sapling address" $ do matchSaplingAddress (bytes rawKey) (bytes rawSa) `shouldBe` True it "doesn't match the wrong Sapling address" $ do