Addition of functinality for manipulating Unified Addresses and Viewing Keys #1
4 changed files with 30 additions and 44 deletions
|
@ -349,7 +349,7 @@ pub extern "C" fn rust_wrapper_ufvk_decode(
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn rust_wrapper_sapling_note_decrypt(
|
pub extern "C" fn rust_wrapper_sapling_note_decrypt_v2(
|
||||||
key: *const u8,
|
key: *const u8,
|
||||||
key_len: usize,
|
key_len: usize,
|
||||||
note: *const u8,
|
note: *const u8,
|
||||||
|
@ -364,12 +364,10 @@ pub extern "C" fn rust_wrapper_sapling_note_decrypt(
|
||||||
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 action2: Transaction = Transaction::read(&mut note_reader, Nu5).unwrap();
|
let action2 = OutputDescription::read(&mut note_reader).unwrap();
|
||||||
let bundle = action2.sapling_bundle().unwrap();
|
|
||||||
let sh_out = bundle.shielded_outputs();
|
|
||||||
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, &sh_out[0]);
|
let result = zcash_note_encryption::try_note_decryption(&domain, &pivk, &action2);
|
||||||
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() };
|
||||||
|
@ -447,41 +445,15 @@ pub extern "C" fn rust_wrapper_tx_parse(
|
||||||
let parsed_tx = Transaction::read(&mut tx_reader, Nu5);
|
let parsed_tx = Transaction::read(&mut tx_reader, Nu5);
|
||||||
match parsed_tx {
|
match parsed_tx {
|
||||||
Ok(t) => {
|
Ok(t) => {
|
||||||
let s_bundle = t.sapling_bundle();
|
let s_bundle = t.sapling_bundle().unwrap().shielded_outputs();
|
||||||
let o_bundle = t.orchard_bundle();
|
let mut s_output = Vec::new();
|
||||||
match s_bundle {
|
for s_each_out in s_bundle.iter() {
|
||||||
Some(sb) => {
|
let mut out_bytes = Vec::new();
|
||||||
let s_o = true;
|
let _ = s_each_out.write_v4(&mut out_bytes);
|
||||||
match o_bundle {
|
s_output.push(out_bytes);
|
||||||
Some(ob) => {
|
|
||||||
let o_a = true;
|
|
||||||
let x = HrawTx { bytes: tx_bytes, s: s_o, o: o_a};
|
|
||||||
marshall_to_haskell_var(&x, out, out_len, RW);
|
|
||||||
},
|
|
||||||
None => {
|
|
||||||
let o_a = false;
|
|
||||||
let x = HrawTx { bytes: tx_bytes, s: s_o, o: o_a};
|
|
||||||
marshall_to_haskell_var(&x, out, out_len, RW);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
},
|
|
||||||
None => {
|
|
||||||
let s_o = false;
|
|
||||||
match o_bundle {
|
|
||||||
Some(ob) => {
|
|
||||||
let o_a = true;
|
|
||||||
let x = HrawTx { bytes: tx_bytes, s: s_o, o: o_a};
|
|
||||||
marshall_to_haskell_var(&x, out, out_len, RW);
|
|
||||||
},
|
|
||||||
None => {
|
|
||||||
let o_a = false;
|
|
||||||
let x = HrawTx { bytes: tx_bytes, s: s_o, o: o_a};
|
|
||||||
marshall_to_haskell_var(&x, out, out_len, RW);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
marshall_to_haskell_var(&s_output, out, out_len, RW);
|
||||||
|
//TODO: write array of bytes
|
||||||
|
|
||||||
},
|
},
|
||||||
Err(_e) => {
|
Err(_e) => {
|
||||||
|
|
|
@ -72,7 +72,7 @@ import ZcashHaskell.Types
|
||||||
-> `Bool'
|
-> `Bool'
|
||||||
#}
|
#}
|
||||||
|
|
||||||
{# fun unsafe rust_wrapper_sapling_note_decrypt as rustWrapperSaplingNoteDecode
|
{# fun unsafe rust_wrapper_sapling_note_decrypt_v2 as rustWrapperSaplingNoteDecode
|
||||||
{ toBorshVar* `BS.ByteString'&
|
{ toBorshVar* `BS.ByteString'&
|
||||||
, toBorshVar* `BS.ByteString'&
|
, toBorshVar* `BS.ByteString'&
|
||||||
, getVarBuffer `Buffer DecodedNote'&
|
, getVarBuffer `Buffer DecodedNote'&
|
||||||
|
@ -95,3 +95,9 @@ import ZcashHaskell.Types
|
||||||
-> `()'
|
-> `()'
|
||||||
#}
|
#}
|
||||||
|
|
||||||
|
{# fun unsafe rust_wrapper_tx_parse as rustWrapperTxParse
|
||||||
|
{ toBorshVar* `BS.ByteString'&
|
||||||
|
, getVarBuffer `Buffer [BS.ByteString]'&
|
||||||
|
}
|
||||||
|
-> `()'
|
||||||
|
#}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import C.Zcash
|
||||||
, rustWrapperSaplingCheck
|
, rustWrapperSaplingCheck
|
||||||
, rustWrapperSaplingNoteDecode
|
, rustWrapperSaplingNoteDecode
|
||||||
, rustWrapperSaplingVkDecode
|
, rustWrapperSaplingVkDecode
|
||||||
|
, rustWrapperTxParse
|
||||||
)
|
)
|
||||||
import qualified Data.ByteString as BS
|
import qualified Data.ByteString as BS
|
||||||
import Foreign.Rust.Marshall.Variable (withPureBorshVarBuffer)
|
import Foreign.Rust.Marshall.Variable (withPureBorshVarBuffer)
|
||||||
|
@ -22,6 +23,9 @@ isValidSaplingViewingKey = rustWrapperSaplingVkDecode
|
||||||
matchSaplingAddress :: BS.ByteString -> BS.ByteString -> Bool
|
matchSaplingAddress :: BS.ByteString -> BS.ByteString -> Bool
|
||||||
matchSaplingAddress = rustWrapperSaplingCheck
|
matchSaplingAddress = rustWrapperSaplingCheck
|
||||||
|
|
||||||
|
getShieldedOutputs :: BS.ByteString -> [BS.ByteString]
|
||||||
|
getShieldedOutputs tx = withPureBorshVarBuffer $ rustWrapperTxParse tx
|
||||||
|
|
||||||
-- | Attempt to decode the given raw tx with the given Sapling viewing key
|
-- | Attempt to decode the given raw tx with the given Sapling viewing key
|
||||||
decodeSaplingOutput :: BS.ByteString -> BS.ByteString -> Maybe DecodedNote
|
decodeSaplingOutput :: BS.ByteString -> BS.ByteString -> Maybe DecodedNote
|
||||||
decodeSaplingOutput key out =
|
decodeSaplingOutput key out =
|
||||||
|
|
12
test/Spec.hs
12
test/Spec.hs
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue