2023-06-14 15:53:29 +00:00
|
|
|
module ZcashHaskell.Sapling where
|
2023-05-04 20:26:49 +00:00
|
|
|
|
2023-06-14 15:53:29 +00:00
|
|
|
import C.Zcash
|
|
|
|
( rustWrapperIsShielded
|
|
|
|
, rustWrapperSaplingCheck
|
2023-08-22 20:05:40 +00:00
|
|
|
, rustWrapperSaplingNoteDecode
|
2023-06-14 15:53:29 +00:00
|
|
|
, rustWrapperSaplingVkDecode
|
|
|
|
)
|
2023-05-04 20:26:49 +00:00
|
|
|
import qualified Data.ByteString as BS
|
2023-08-22 20:05:40 +00:00
|
|
|
import Foreign.Rust.Marshall.Variable (withPureBorshVarBuffer)
|
|
|
|
import ZcashHaskell.Types (DecodedNote(..), ShieldedOutput)
|
2023-05-04 20:26:49 +00:00
|
|
|
|
|
|
|
-- | Check if given bytesting is a valid encoded shielded address
|
|
|
|
isValidShieldedAddress :: BS.ByteString -> Bool
|
|
|
|
isValidShieldedAddress = rustWrapperIsShielded
|
2023-06-14 14:55:52 +00:00
|
|
|
|
|
|
|
-- | Check if given bytestring is a valid Sapling viewing key
|
|
|
|
isValidSaplingViewingKey :: BS.ByteString -> Bool
|
|
|
|
isValidSaplingViewingKey = rustWrapperSaplingVkDecode
|
2023-06-14 15:53:29 +00:00
|
|
|
|
|
|
|
-- | Check if the given bytestring for the Sapling viewing key matches the second bytestring for the address
|
|
|
|
matchSaplingAddress :: BS.ByteString -> BS.ByteString -> Bool
|
|
|
|
matchSaplingAddress = rustWrapperSaplingCheck
|
2023-08-22 20:05:40 +00:00
|
|
|
|
|
|
|
-- | Attempt to decode the given Sapling raw output with the given Sapling viewing key
|
|
|
|
decodeSaplingOutput :: BS.ByteString -> ShieldedOutput -> Maybe DecodedNote
|
|
|
|
decodeSaplingOutput key out =
|
|
|
|
case a_value decodedAction of
|
|
|
|
0 -> Nothing
|
|
|
|
_ -> Just decodedAction
|
|
|
|
where
|
|
|
|
decodedAction =
|
|
|
|
withPureBorshVarBuffer $ rustWrapperSaplingNoteDecode key out
|