Addition of functinality for manipulating Unified Addresses and Viewing Keys #1
4 changed files with 32 additions and 26 deletions
|
@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
|
- Rearranged modules for cleaner dependencies.
|
||||||
- Upgrade to Haskell LTS 21.6
|
- Upgrade to Haskell LTS 21.6
|
||||||
|
|
||||||
## [0.1.0] - 2023-06-14
|
## [0.1.0] - 2023-06-14
|
||||||
|
|
|
@ -97,12 +97,12 @@ instance FromJSON ShieldedOutput where
|
||||||
p <- obj .: "proof"
|
p <- obj .: "proof"
|
||||||
pure $
|
pure $
|
||||||
ShieldedOutput
|
ShieldedOutput
|
||||||
(C.pack cv)
|
(decodeHexText cv)
|
||||||
(C.pack cmu)
|
(decodeHexText cmu)
|
||||||
(C.pack ephKey)
|
(decodeHexText ephKey)
|
||||||
(C.pack encText)
|
(decodeHexText encText)
|
||||||
(C.pack outText)
|
(decodeHexText outText)
|
||||||
(C.pack p)
|
(decodeHexText p)
|
||||||
|
|
||||||
-- * Orchard
|
-- * Orchard
|
||||||
-- | Type to represent a Unified Full Viewing Key
|
-- | Type to represent a Unified Full Viewing Key
|
||||||
|
@ -144,14 +144,14 @@ instance FromJSON OrchardAction where
|
||||||
a <- obj .: "spendAuthSig"
|
a <- obj .: "spendAuthSig"
|
||||||
pure $
|
pure $
|
||||||
OrchardAction
|
OrchardAction
|
||||||
(C.pack n)
|
(decodeHexText n)
|
||||||
(C.pack r)
|
(decodeHexText r)
|
||||||
(C.pack c)
|
(decodeHexText c)
|
||||||
(C.pack ephKey)
|
(decodeHexText ephKey)
|
||||||
(C.pack encText)
|
(decodeHexText encText)
|
||||||
(C.pack outText)
|
(decodeHexText outText)
|
||||||
(C.pack cval)
|
(decodeHexText cval)
|
||||||
(C.pack a)
|
(decodeHexText a)
|
||||||
|
|
||||||
-- | Type to represent a decoded Orchard Action
|
-- | Type to represent a decoded Orchard Action
|
||||||
data OrchardDecodedAction = OrchardDecodedAction
|
data OrchardDecodedAction = OrchardDecodedAction
|
||||||
|
@ -162,3 +162,15 @@ data OrchardDecodedAction = OrchardDecodedAction
|
||||||
deriving anyclass (SOP.Generic, SOP.HasDatatypeInfo)
|
deriving anyclass (SOP.Generic, SOP.HasDatatypeInfo)
|
||||||
deriving anyclass (Data.Structured.Show)
|
deriving anyclass (Data.Structured.Show)
|
||||||
deriving (BorshSize, ToBorsh, FromBorsh) via AsStruct OrchardDecodedAction
|
deriving (BorshSize, ToBorsh, FromBorsh) via AsStruct OrchardDecodedAction
|
||||||
|
|
||||||
|
-- * Helpers
|
||||||
|
-- | Helper function to turn a hex-encoded string to bytestring
|
||||||
|
decodeHexText :: String -> BS.ByteString
|
||||||
|
decodeHexText h = BS.pack $ hexRead h
|
||||||
|
where
|
||||||
|
hexRead hexText
|
||||||
|
| null chunk = []
|
||||||
|
| otherwise =
|
||||||
|
fromIntegral (read ("0x" <> chunk)) : hexRead (drop 2 hexText)
|
||||||
|
where
|
||||||
|
chunk = take 2 hexText
|
||||||
|
|
|
@ -16,22 +16,10 @@ import C.Zcash
|
||||||
, rustWrapperF4Jumble
|
, rustWrapperF4Jumble
|
||||||
, rustWrapperF4UnJumble
|
, rustWrapperF4UnJumble
|
||||||
)
|
)
|
||||||
|
|
||||||
import qualified Data.ByteString as BS
|
import qualified Data.ByteString as BS
|
||||||
import Foreign.Rust.Marshall.Variable
|
import Foreign.Rust.Marshall.Variable
|
||||||
import ZcashHaskell.Types
|
import ZcashHaskell.Types
|
||||||
|
|
||||||
-- | Helper function to turn a hex-encoded string to bytestring
|
|
||||||
decodeHexText :: String -> BS.ByteString
|
|
||||||
decodeHexText h = BS.pack $ hexRead h
|
|
||||||
where
|
|
||||||
hexRead hexText
|
|
||||||
| null chunk = []
|
|
||||||
| otherwise =
|
|
||||||
fromIntegral (read ("0x" <> chunk)) : hexRead (drop 2 hexText)
|
|
||||||
where
|
|
||||||
chunk = take 2 hexText
|
|
||||||
|
|
||||||
-- | Decode the given bytestring using Bech32
|
-- | Decode the given bytestring using Bech32
|
||||||
decodeBech32 :: BS.ByteString -> RawData
|
decodeBech32 :: BS.ByteString -> RawData
|
||||||
decodeBech32 = withPureBorshVarBuffer . rustWrapperBech32Decode
|
decodeBech32 = withPureBorshVarBuffer . rustWrapperBech32Decode
|
||||||
|
|
|
@ -23,6 +23,7 @@ import ZcashHaskell.Types
|
||||||
, RawTxResponse(..)
|
, RawTxResponse(..)
|
||||||
, ShieldedOutput(s_cmu)
|
, ShieldedOutput(s_cmu)
|
||||||
, UnifiedFullViewingKey(..)
|
, UnifiedFullViewingKey(..)
|
||||||
|
, decodeHexText
|
||||||
)
|
)
|
||||||
import ZcashHaskell.Utils
|
import ZcashHaskell.Utils
|
||||||
|
|
||||||
|
@ -309,6 +310,10 @@ main = do
|
||||||
let fakeUvk =
|
let fakeUvk =
|
||||||
"uview1u83changinga987bundchofch4ract3r5x8hqsw6vzw63n24atxpcatws82z092kryazuu6d7rayyut8m36wm4wpjy2z8r9hj48fx5pf49gw4sjrq8503qpz3vqj5hg0vg9vsqeasg5qjuyh94uyfm7v76udqcm2m0wfc25hcyqswcn56xxduq3xkgxkr0l73cjy88fdvf90eq5fda9g6x7yv7d0uckpevxg6540wc76xrc4axxvlt03ptaa2a0rektglmdy68656f3uzcdgqqyu0t7wk5cvwghyyvgqc0rp3vgu5ye4nd236ml57rjh083a2755qemf6dk6pw0qrnfm7246s8eg2hhzkzpf9h73chhng7xhmyem2sjh8rs2m9nhfcslsgenm"
|
"uview1u83changinga987bundchofch4ract3r5x8hqsw6vzw63n24atxpcatws82z092kryazuu6d7rayyut8m36wm4wpjy2z8r9hj48fx5pf49gw4sjrq8503qpz3vqj5hg0vg9vsqeasg5qjuyh94uyfm7v76udqcm2m0wfc25hcyqswcn56xxduq3xkgxkr0l73cjy88fdvf90eq5fda9g6x7yv7d0uckpevxg6540wc76xrc4axxvlt03ptaa2a0rektglmdy68656f3uzcdgqqyu0t7wk5cvwghyyvgqc0rp3vgu5ye4nd236ml57rjh083a2755qemf6dk6pw0qrnfm7246s8eg2hhzkzpf9h73chhng7xhmyem2sjh8rs2m9nhfcslsgenm"
|
||||||
decodeUfvk fakeUvk `shouldBe` Nothing
|
decodeUfvk fakeUvk `shouldBe` Nothing
|
||||||
|
describe "Decode Sapling tx" $ do
|
||||||
|
let svk =
|
||||||
|
"zxviews1qvapd723qqqqpqq09ldgykvyusthmkky2w062esx5xg3nz4m29qxcvndyx6grrhrdepu4ns88sjr3u6mfp2hhwj5hfd6y24r0f64uwq65vjrmsh9mr568kenk33fcumag6djcjywkm5v295egjuk3qdd47atprs0j33nhaaqep3uqspzp5kg4mthugvug0sc3gc83atkrgmguw9g7gkvh82tugrntf66lnvyeh6ufh4j2xt0xr2r4zujtm3qvrmd3vvnulycuwqtetg2jk384"
|
||||||
|
it "succeeds with correct key" pending
|
||||||
describe "Decode Orchard tx" $ do
|
describe "Decode Orchard tx" $ do
|
||||||
let uvk =
|
let uvk =
|
||||||
"uview1u833rp8yykd7h4druwht6xp6k8krle45fx8hqsw6vzw63n24atxpcatws82z092kryazuu6d7rayyut8m36wm4wpjy2z8r9hj48fx5pf49gw4sjrq8503qpz3vqj5hg0vg9vsqeasg5qjuyh94uyfm7v76udqcm2m0wfc25hcyqswcn56xxduq3xkgxkr0l73cjy88fdvf90eq5fda9g6x7yv7d0uckpevxg6540wc76xrc4axxvlt03ptaa2a0rektglmdy68656f3uzcdgqqyu0t7wk5cvwghyyvgqc0rp3vgu5ye4nd236ml57rjh083a2755qemf6dk6pw0qrnfm7246s8eg2hhzkzpf9h73chhng7xhmyem2sjh8rs2m9nhfcslsgenm"
|
"uview1u833rp8yykd7h4druwht6xp6k8krle45fx8hqsw6vzw63n24atxpcatws82z092kryazuu6d7rayyut8m36wm4wpjy2z8r9hj48fx5pf49gw4sjrq8503qpz3vqj5hg0vg9vsqeasg5qjuyh94uyfm7v76udqcm2m0wfc25hcyqswcn56xxduq3xkgxkr0l73cjy88fdvf90eq5fda9g6x7yv7d0uckpevxg6540wc76xrc4axxvlt03ptaa2a0rektglmdy68656f3uzcdgqqyu0t7wk5cvwghyyvgqc0rp3vgu5ye4nd236ml57rjh083a2755qemf6dk6pw0qrnfm7246s8eg2hhzkzpf9h73chhng7xhmyem2sjh8rs2m9nhfcslsgenm"
|
||||||
|
|
Loading…
Reference in a new issue