2023-06-14 15:53:29 +00:00
|
|
|
module ZcashHaskell.Orchard where
|
2023-05-04 20:26:49 +00:00
|
|
|
|
|
|
|
import C.Zcash
|
|
|
|
( rustWrapperIsUA
|
|
|
|
, rustWrapperOrchardNoteDecode
|
|
|
|
, rustWrapperUfvkDecode
|
|
|
|
)
|
|
|
|
import qualified Data.ByteString as BS
|
|
|
|
import Foreign.Rust.Marshall.Variable
|
2023-06-14 15:53:29 +00:00
|
|
|
import ZcashHaskell.Types
|
2023-05-04 20:26:49 +00:00
|
|
|
|
|
|
|
-- | Check if given bytestring is a valid encoded unified address
|
|
|
|
isValidUnifiedAddress :: BS.ByteString -> Bool
|
|
|
|
isValidUnifiedAddress = rustWrapperIsUA
|
|
|
|
|
|
|
|
-- | Attempt to decode the given bytestring into a Unified Full Viewing Key
|
|
|
|
decodeUfvk :: BS.ByteString -> Maybe UnifiedFullViewingKey
|
|
|
|
decodeUfvk str =
|
|
|
|
case net decodedKey of
|
|
|
|
0 -> Nothing
|
|
|
|
_ -> Just decodedKey
|
|
|
|
where
|
|
|
|
decodedKey = (withPureBorshVarBuffer . rustWrapperUfvkDecode) str
|
|
|
|
|
|
|
|
decryptOrchardAction ::
|
|
|
|
OrchardAction -> UnifiedFullViewingKey -> Maybe OrchardDecodedAction
|
|
|
|
decryptOrchardAction encAction key =
|
|
|
|
case a_value decodedAction of
|
|
|
|
0 -> Nothing
|
|
|
|
_ -> Just decodedAction
|
|
|
|
where
|
|
|
|
decodedAction =
|
|
|
|
withPureBorshVarBuffer $
|
|
|
|
rustWrapperOrchardNoteDecode (o_key key) encAction
|