2023-08-17 15:02:32 +00:00
|
|
|
-- |
|
|
|
|
-- Module : ZcashHaskell.Orchard
|
|
|
|
-- Copyright : Vergara Technologies 2023
|
|
|
|
-- License : BOSL
|
|
|
|
--
|
|
|
|
-- Maintainer : rene@vergara.network
|
|
|
|
-- Stability : experimental
|
|
|
|
-- Portability : unknown
|
|
|
|
--
|
|
|
|
-- Functions to interact with the Orchard shielded pool of the Zcash blockchain.
|
|
|
|
--
|
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
|
|
|
|
2023-08-17 15:02:32 +00:00
|
|
|
-- | Checks if given bytestring is a valid encoded unified address
|
2023-05-04 20:26:49 +00:00
|
|
|
isValidUnifiedAddress :: BS.ByteString -> Bool
|
|
|
|
isValidUnifiedAddress = rustWrapperIsUA
|
|
|
|
|
2023-08-17 15:02:32 +00:00
|
|
|
-- | Attempts to decode the given bytestring into a Unified Full Viewing Key
|
2023-05-04 20:26:49 +00:00
|
|
|
decodeUfvk :: BS.ByteString -> Maybe UnifiedFullViewingKey
|
|
|
|
decodeUfvk str =
|
|
|
|
case net decodedKey of
|
|
|
|
0 -> Nothing
|
|
|
|
_ -> Just decodedKey
|
|
|
|
where
|
|
|
|
decodedKey = (withPureBorshVarBuffer . rustWrapperUfvkDecode) str
|
|
|
|
|
2023-08-17 15:02:32 +00:00
|
|
|
-- | Attempts to decode the given @OrchardAction@ using the given @UnifiedFullViewingKey@.
|
2023-05-04 20:26:49 +00:00
|
|
|
decryptOrchardAction ::
|
2023-09-26 20:24:18 +00:00
|
|
|
UnifiedFullViewingKey -> OrchardAction -> Maybe DecodedNote
|
|
|
|
decryptOrchardAction key encAction =
|
2023-05-04 20:26:49 +00:00
|
|
|
case a_value decodedAction of
|
|
|
|
0 -> Nothing
|
|
|
|
_ -> Just decodedAction
|
|
|
|
where
|
|
|
|
decodedAction =
|
|
|
|
withPureBorshVarBuffer $
|
|
|
|
rustWrapperOrchardNoteDecode (o_key key) encAction
|