Addition of functinality for manipulating Unified Addresses and Viewing Keys #1
2 changed files with 9 additions and 2 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue