Addition of functinality for manipulating Unified Addresses and Viewing Keys #1
3 changed files with 16 additions and 15 deletions
|
@ -1,7 +1,10 @@
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
marker::PhantomData,
|
marker::PhantomData,
|
||||||
io::Write,
|
io::{
|
||||||
|
Write,
|
||||||
|
Cursor
|
||||||
|
},
|
||||||
fmt::{Debug, Display, Formatter}
|
fmt::{Debug, Display, Formatter}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -34,7 +37,9 @@ use zcash_primitives::{
|
||||||
PaymentAddress,
|
PaymentAddress,
|
||||||
note::ExtractedNoteCommitment as SaplingExtractedNoteCommitment
|
note::ExtractedNoteCommitment as SaplingExtractedNoteCommitment
|
||||||
},
|
},
|
||||||
|
transaction::Transaction,
|
||||||
consensus::{
|
consensus::{
|
||||||
|
BranchId::Nu5,
|
||||||
MainNetwork,
|
MainNetwork,
|
||||||
BlockHeight
|
BlockHeight
|
||||||
}
|
}
|
||||||
|
@ -325,22 +330,18 @@ pub extern "C" fn rust_wrapper_sapling_note_decrypt(
|
||||||
out_len: &mut usize
|
out_len: &mut usize
|
||||||
){
|
){
|
||||||
let evk: Vec<u8> = marshall_from_haskell_var(key, key_len, RW);
|
let evk: Vec<u8> = marshall_from_haskell_var(key, key_len, RW);
|
||||||
let note_input: HshieldedOutput = marshall_from_haskell_var(note,note_len,RW);
|
let note_input: Vec<u8> = marshall_from_haskell_var(note,note_len,RW);
|
||||||
|
let mut note_reader = Cursor::new(note_input);
|
||||||
let svk = ExtendedFullViewingKey::read(&*evk);
|
let svk = ExtendedFullViewingKey::read(&*evk);
|
||||||
match svk {
|
match svk {
|
||||||
Ok(k) => {
|
Ok(k) => {
|
||||||
let domain = SaplingDomain::for_height(MainNetwork, BlockHeight::from_u32(2000000));
|
let domain = SaplingDomain::for_height(MainNetwork, BlockHeight::from_u32(2000000));
|
||||||
let mut action_bytes = vec![0];
|
let action2: Transaction = Transaction::read(&mut note_reader, Nu5).unwrap();
|
||||||
action_bytes.extend(¬e_input.cv);
|
let bundle = action2.sapling_bundle().unwrap();
|
||||||
action_bytes.extend(¬e_input.cmu);
|
let sh_out = bundle.shielded_outputs();
|
||||||
action_bytes.extend(¬e_input.eph_key);
|
|
||||||
action_bytes.extend(¬e_input.enc_txt);
|
|
||||||
action_bytes.extend(¬e_input.out_txt);
|
|
||||||
action_bytes.extend(¬e_input.proof);
|
|
||||||
let action2 = OutputDescription::read(&mut action_bytes.as_slice()).unwrap();
|
|
||||||
let fvk = k.to_diversifiable_full_viewing_key().to_ivk(SaplingScope::External);
|
let fvk = k.to_diversifiable_full_viewing_key().to_ivk(SaplingScope::External);
|
||||||
let pivk = SaplingPreparedIncomingViewingKey::new(&fvk);
|
let pivk = SaplingPreparedIncomingViewingKey::new(&fvk);
|
||||||
let result = zcash_note_encryption::try_note_decryption(&domain, &pivk, &action2);
|
let result = zcash_note_encryption::try_note_decryption(&domain, &pivk, &sh_out[0]);
|
||||||
match result {
|
match result {
|
||||||
Some((n, r, m)) => {
|
Some((n, r, m)) => {
|
||||||
let hn = Hnote {note: n.value().inner(), recipient: r.to_bytes().to_vec(), memo: m.as_slice().to_vec() };
|
let hn = Hnote {note: n.value().inner(), recipient: r.to_bytes().to_vec(), memo: m.as_slice().to_vec() };
|
||||||
|
|
|
@ -74,7 +74,7 @@ import ZcashHaskell.Types
|
||||||
|
|
||||||
{# fun unsafe rust_wrapper_sapling_note_decrypt as rustWrapperSaplingNoteDecode
|
{# fun unsafe rust_wrapper_sapling_note_decrypt as rustWrapperSaplingNoteDecode
|
||||||
{ toBorshVar* `BS.ByteString'&
|
{ toBorshVar* `BS.ByteString'&
|
||||||
, toBorshVar* `ShieldedOutput'&
|
, toBorshVar* `BS.ByteString'&
|
||||||
, getVarBuffer `Buffer DecodedNote'&
|
, getVarBuffer `Buffer DecodedNote'&
|
||||||
}
|
}
|
||||||
-> `()'
|
-> `()'
|
||||||
|
|
|
@ -8,7 +8,7 @@ import C.Zcash
|
||||||
)
|
)
|
||||||
import qualified Data.ByteString as BS
|
import qualified Data.ByteString as BS
|
||||||
import Foreign.Rust.Marshall.Variable (withPureBorshVarBuffer)
|
import Foreign.Rust.Marshall.Variable (withPureBorshVarBuffer)
|
||||||
import ZcashHaskell.Types (DecodedNote(..), ShieldedOutput)
|
import ZcashHaskell.Types (DecodedNote(..), ShieldedOutput(..))
|
||||||
|
|
||||||
-- | Check if given bytesting is a valid encoded shielded address
|
-- | Check if given bytesting is a valid encoded shielded address
|
||||||
isValidShieldedAddress :: BS.ByteString -> Bool
|
isValidShieldedAddress :: BS.ByteString -> Bool
|
||||||
|
@ -22,8 +22,8 @@ isValidSaplingViewingKey = rustWrapperSaplingVkDecode
|
||||||
matchSaplingAddress :: BS.ByteString -> BS.ByteString -> Bool
|
matchSaplingAddress :: BS.ByteString -> BS.ByteString -> Bool
|
||||||
matchSaplingAddress = rustWrapperSaplingCheck
|
matchSaplingAddress = rustWrapperSaplingCheck
|
||||||
|
|
||||||
-- | Attempt to decode the given Sapling raw output with the given Sapling viewing key
|
-- | Attempt to decode the given raw tx with the given Sapling viewing key
|
||||||
decodeSaplingOutput :: BS.ByteString -> ShieldedOutput -> Maybe DecodedNote
|
decodeSaplingOutput :: BS.ByteString -> BS.ByteString -> Maybe DecodedNote
|
||||||
decodeSaplingOutput key out =
|
decodeSaplingOutput key out =
|
||||||
case a_value decodedAction of
|
case a_value decodedAction of
|
||||||
0 -> Nothing
|
0 -> Nothing
|
||||||
|
|
Loading…
Reference in a new issue