47 lines
1.4 KiB
Haskell
47 lines
1.4 KiB
Haskell
-- |
|
|
-- 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.
|
|
--
|
|
module ZcashHaskell.Orchard where
|
|
|
|
import C.Zcash
|
|
( rustWrapperIsUA
|
|
, rustWrapperOrchardNoteDecode
|
|
, rustWrapperUfvkDecode
|
|
)
|
|
import qualified Data.ByteString as BS
|
|
import Foreign.Rust.Marshall.Variable
|
|
import ZcashHaskell.Types
|
|
|
|
-- | Checks if given bytestring is a valid encoded unified address
|
|
isValidUnifiedAddress :: BS.ByteString -> Bool
|
|
isValidUnifiedAddress = rustWrapperIsUA
|
|
|
|
-- | Attempts 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
|
|
|
|
-- | Attempts to decode the given @OrchardAction@ using the given @UnifiedFullViewingKey@.
|
|
decryptOrchardAction ::
|
|
OrchardAction -> UnifiedFullViewingKey -> Maybe DecodedNote
|
|
decryptOrchardAction encAction key =
|
|
case a_value decodedAction of
|
|
0 -> Nothing
|
|
_ -> Just decodedAction
|
|
where
|
|
decodedAction =
|
|
withPureBorshVarBuffer $
|
|
rustWrapperOrchardNoteDecode (o_key key) encAction
|