From fb436f1499a42beda525367c8cb578ae6c96f127 Mon Sep 17 00:00:00 2001 From: Rene Vergara Date: Wed, 27 Sep 2023 13:18:16 -0500 Subject: [PATCH] Add full validation of Sapling address to parser --- src/ZGoTx.hs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/ZGoTx.hs b/src/ZGoTx.hs index 30e7ef7..bf7b3d8 100644 --- a/src/ZGoTx.hs +++ b/src/ZGoTx.hs @@ -17,6 +17,7 @@ import GHC.Generics import Text.Megaparsec hiding (State) import Text.Megaparsec.Char import ZcashHaskell.Orchard +import ZcashHaskell.Sapling (isValidShieldedAddress) -- | Type to model a ZGo transaction data ZGoTx = ZGoTx @@ -133,9 +134,9 @@ pSaplingAddress :: Parser MemoToken pSaplingAddress = do string "zs" a <- some alphaNumChar - if length a /= 76 - then fail "Failed to parse Sapling address" - else pure $ Address $ T.pack ("zs" <> a) + if isValidShieldedAddress (E.encodeUtf8 $ "zs" <> T.pack a) + then pure $ Address $ T.pack ("zs" <> a) + else fail "Failed to parse Sapling address" pUnifiedAddress :: Parser MemoToken pUnifiedAddress = do