Compare commits

..

No commits in common. "6ea8698ccb5e44f9900ba0e61c6ffe6cba900139" and "d5728525cea47a79caf7f527c7195c795c629ec7" have entirely different histories.

7 changed files with 88 additions and 68 deletions

View file

@ -145,21 +145,16 @@ impl HshieldedOutput {
}
}
#[derive(BorshSerialize, BorshDeserialize)]
pub struct Hhex {
bytes: Vec<u8>
}
#[derive(BorshSerialize, BorshDeserialize)]
pub struct Haction {
nf: Hhex,
rk: Hhex,
cmx: Hhex,
eph_key: Hhex,
enc_txt: Hhex,
out_txt: Hhex,
cv: Hhex,
auth: Hhex
nf: Vec<u8>,
rk: Vec<u8>,
cmx: Vec<u8>,
eph_key: Vec<u8>,
enc_txt: Vec<u8>,
out_txt: Vec<u8>,
cv: Vec<u8>,
auth: Vec<u8>
}
impl<RW> FromHaskell<RW> for Haction {
@ -503,12 +498,12 @@ pub extern "C" fn rust_wrapper_orchard_note_decrypt(
let fvk_input: Vec<u8> = marshall_from_haskell_var(key, key_len, RW);
let note_input: Haction = marshall_from_haskell_var(note, note_len, RW);
let action: Action<Signature<SpendAuth>> = Action::from_parts(
Nullifier::from_bytes(&to_array(note_input.nf.bytes)).unwrap(),
VerificationKey::try_from(to_array(note_input.rk.bytes)).unwrap(),
ExtractedNoteCommitment::from_bytes(&to_array(note_input.cmx.bytes)).unwrap(),
TransmittedNoteCiphertext {epk_bytes: to_array(note_input.eph_key.bytes), enc_ciphertext: to_array(note_input.enc_txt.bytes), out_ciphertext: to_array(note_input.out_txt.bytes)},
ValueCommitment::from_bytes(&to_array(note_input.cv.bytes)).unwrap(),
Signature::from(to_array(note_input.auth.bytes)));
Nullifier::from_bytes(&to_array(note_input.nf)).unwrap(),
VerificationKey::try_from(to_array(note_input.rk)).unwrap(),
ExtractedNoteCommitment::from_bytes(&to_array(note_input.cmx)).unwrap(),
TransmittedNoteCiphertext {epk_bytes: to_array(note_input.eph_key), enc_ciphertext: to_array(note_input.enc_txt), out_ciphertext: to_array(note_input.out_txt)},
ValueCommitment::from_bytes(&to_array(note_input.cv)).unwrap(),
Signature::from(to_array(note_input.auth)));
let fvk_array = to_array(fvk_input);
let domain = OrchardDomain::for_nullifier(*action.nullifier());
let dec_fvk = FullViewingKey::from_bytes(&fvk_array);

View file

@ -36,7 +36,6 @@ library:
- base58-bytestring
- cryptonite
- memory
- hexstring
pkg-config-dependencies:
- rustzcash_wrapper-uninstalled
@ -55,4 +54,3 @@ tests:
- text
- aeson
- haskoin-core
- hexstring

View file

@ -26,7 +26,6 @@ import C.Zcash
)
import Data.Aeson
import qualified Data.ByteString as BS
import Data.HexString (HexString(..), toBytes)
import Foreign.Rust.Marshall.Variable (withPureBorshVarBuffer)
import ZcashHaskell.Types
( DecodedNote(..)
@ -41,8 +40,8 @@ import ZcashHaskell.Utils (decodeBech32)
isValidShieldedAddress :: BS.ByteString -> Bool
isValidShieldedAddress = rustWrapperIsShielded
getShieldedOutputs :: HexString -> [BS.ByteString]
getShieldedOutputs t = withPureBorshVarBuffer $ rustWrapperTxParse $ toBytes t
getShieldedOutputs :: BS.ByteString -> [BS.ByteString]
getShieldedOutputs t = withPureBorshVarBuffer $ rustWrapperTxParse t
-- | Check if given bytestring is a valid Sapling viewing key
isValidSaplingViewingKey :: BS.ByteString -> Bool
@ -77,7 +76,24 @@ instance FromJSON RawTxResponse where
c <- obj .: "confirmations"
b <- obj .: "blocktime"
case o of
Nothing -> pure $ RawTxResponse i h (getShieldedOutputs h) [] ht c b
Nothing ->
pure $
RawTxResponse
i
(decodeHexText h)
(getShieldedOutputs (decodeHexText h))
[]
ht
c
b
Just o' -> do
a <- o' .: "actions"
pure $ RawTxResponse i h (getShieldedOutputs h) a ht c b
pure $
RawTxResponse
i
(decodeHexText h)
(getShieldedOutputs (decodeHexText h))
a
ht
c
b

View file

@ -28,7 +28,6 @@ import Data.Aeson
import qualified Data.ByteArray as BA
import qualified Data.ByteString as BS
import qualified Data.ByteString.Char8 as C
import Data.HexString
import Data.Int
import Data.Structured
import qualified Data.Text as T
@ -45,6 +44,7 @@ type Seed = C.ByteString
-- | A mnemonic phrase used to derive seeds
type Phrase = BS.ByteString
--
-- | Type to represent data after Bech32 decoding
data RawData = RawData
{ hrp :: BS.ByteString -- ^ Human-readable part of the Bech32 encoding
@ -116,8 +116,8 @@ instance FromJSON BlockResponse where
-- | Type to represent response from the `zcashd` RPC `getrawtransaction`
data RawTxResponse = RawTxResponse
{ rt_id :: !HexString
, rt_hex :: !HexString
{ rt_id :: T.Text
, rt_hex :: BS.ByteString
, rt_shieldedOutputs :: [BS.ByteString]
, rt_orchardActions :: [OrchardAction]
, rt_blockheight :: Integer
@ -148,12 +148,12 @@ data TransparentAddress = TransparentAddress
-- * Sapling
-- | Type to represent a Sapling Shielded Output as provided by the @getrawtransaction@ RPC method of @zcashd@.
data ShieldedOutput = ShieldedOutput
{ s_cv :: HexString -- ^ Value commitment to the input note
, s_cmu :: HexString -- ^ The u-coordinate of the note commitment for the output note
, s_ephKey :: HexString -- ^ Ephemeral Jubjub public key
, s_encCipherText :: HexString -- ^ The output note encrypted to the recipient
, s_outCipherText :: HexString -- ^ A ciphertext enabling the sender to recover the output note
, s_proof :: HexString -- ^ Zero-knowledge proof using the Sapling Output circuit
{ s_cv :: BS.ByteString -- ^ Value commitment to the input note
, s_cmu :: BS.ByteString -- ^ The u-coordinate of the note commitment for the output note
, s_ephKey :: BS.ByteString -- ^ Ephemeral Jubjub public key
, s_encCipherText :: BS.ByteString -- ^ The output note encrypted to the recipient
, s_outCipherText :: BS.ByteString -- ^ A ciphertext enabling the sender to recover the output note
, s_proof :: BS.ByteString -- ^ Zero-knowledge proof using the Sapling Output circuit
} deriving stock (Eq, Prelude.Show, GHC.Generic)
deriving anyclass (SOP.Generic, SOP.HasDatatypeInfo)
deriving anyclass (Data.Structured.Show)
@ -168,7 +168,14 @@ instance FromJSON ShieldedOutput where
encText <- obj .: "encCiphertext"
outText <- obj .: "outCiphertext"
p <- obj .: "proof"
pure $ ShieldedOutput cv cmu ephKey encText outText p
pure $
ShieldedOutput
(decodeHexText cv)
(decodeHexText cmu)
(decodeHexText ephKey)
(decodeHexText encText)
(decodeHexText outText)
(decodeHexText p)
-- * Orchard
-- | Type to represent a Unified Address
@ -204,14 +211,14 @@ data UnifiedFullViewingKey = UnifiedFullViewingKey
-- | Type to represent an Orchard Action as provided by the @getrawtransaction@ RPC method of @zcashd@, and defined in the [Zcash Protocol](https://zips.z.cash/protocol/protocol.pdf)
data OrchardAction = OrchardAction
{ nf :: HexString -- ^ The nullifier of the input note
, rk :: HexString -- ^ The randomized validating key for @auth@
, cmx :: HexString -- ^ The x-coordinate of the note commitment for the output note
, eph_key :: HexString -- ^ An encoding of an ephemeral Pallas public key
, enc_ciphertext :: HexString -- ^ The output note encrypted to the recipient
, out_ciphertext :: HexString -- ^ A ciphertext enabling the sender to recover the output note
, cv :: HexString -- ^ A value commitment to the net value of the input note minus the output note
, auth :: HexString -- ^ A signature authorizing the spend in this Action
{ nf :: BS.ByteString -- ^ The nullifier of the input note
, rk :: BS.ByteString -- ^ The randomized validating key for @auth@
, cmx :: BS.ByteString -- ^ The x-coordinate of the note commitment for the output note
, eph_key :: BS.ByteString -- ^ An encoding of an ephemeral Pallas public key
, enc_ciphertext :: BS.ByteString -- ^ The output note encrypted to the recipient
, out_ciphertext :: BS.ByteString -- ^ A ciphertext enabling the sender to recover the output note
, cv :: BS.ByteString -- ^ A value commitment to the net value of the input note minus the output note
, auth :: BS.ByteString -- ^ A signature authorizing the spend in this Action
} deriving stock (Eq, Prelude.Show, GHC.Generic)
deriving anyclass (SOP.Generic, SOP.HasDatatypeInfo)
deriving anyclass (Data.Structured.Show)
@ -228,7 +235,16 @@ instance FromJSON OrchardAction where
outText <- obj .: "outCiphertext"
cval <- obj .: "cv"
a <- obj .: "spendAuthSig"
pure $ OrchardAction n r c ephKey encText outText cval a
pure $
OrchardAction
(decodeHexText n)
(decodeHexText r)
(decodeHexText c)
(decodeHexText ephKey)
(decodeHexText encText)
(decodeHexText outText)
(decodeHexText cval)
(decodeHexText a)
-- | Type to represent a decoded note
data DecodedNote = DecodedNote

View file

@ -40,8 +40,6 @@ extra-deps:
commit: 787c2e813eb3a5d16c375d4b37dfefbd2adcdf05
- git: https://github.com/well-typed/borsh.git
commit: d2fcfa159e0a844b1ec5e8ed3e232d4b380fa831
- git: https://git.vergara.tech/Vergara_Tech/haskell-hexstring.git
commit: fe2df6f7d63272ac147911c1573550bed1d38a37
- vector-0.13.0.0@sha256:fa5cac81a17a5af388716792e8b99c24b3b66770086756d0d8b23f8272a0244c,9112
- aeson-2.1.2.1@sha256:f10f3c661bd5cf57aee46b94420e47736240b8e209ac15f4bfc1a4e4d55831fa,6344
- generically-0.1.1

File diff suppressed because one or more lines are too long

View file

@ -48,7 +48,6 @@ library
, cryptonite
, foreign-rust
, generics-sop
, hexstring
, http-conduit
, memory
, text
@ -67,7 +66,6 @@ test-suite zcash-haskell-test
, base >=4.7 && <5
, bytestring
, haskoin-core
, hexstring
, hspec
, text
, zcash-haskell