Anyone willing to give some hints on adding stuff to librustzcash ? I’m finding the Rust part really hard & could use some help.
So far I have :-
- built librustzcash
- got FFI working from Perl
- built a Perl-librustzcash thing that gets the zaddr from a full viewkey (yaay!! Hello World!)
- I can also get ‘ak’ & ‘nk’ from the viewkey, other simple stuff
The part I’m stuck on is adding a function to rustzcash.rs to call try_sapling_note_decryption() (in librustzcash/zcash_primatives/src/note_encryption.rs) & accessing its return values.
Very basic Rust stuff that has me horribly confused - functions with Types, functions with Some/None
Here’s what I have so far :-
// ChileBob’s failing attempt to be clever
//
#[no_mangle]
pub extern “C” fn librustzcash_decrypt_note (
height: u32,
ivk: *const [c_uchar; 32],
epk: *const [c_uchar; 32],
cmu: *const [c_uchar; 32],
enc_ciphertext: *const [c_uchar; 580],
ret_addr: *mut [c_uchar; 43],
ret_value: *mut [c_uchar; 8],
ret_memo: *mut [c_uchar; 512],
) → u32 {// NOTE: Added to ‘use’ section at top to import function from zcash_primatives::note_encryption
// note_encryption::{sapling_ka_agree, try_sapling_note_decryption},// try_sapling_note_decryption(
// height,
// &jubjub::Scalar::from_bytes(&*ivk).unwrap(),
// &jubjub::SubgroupPoint::from_bytes(&*epk).unwrap(),
// &bls12_381::Scalar::from_bytes(&*cmu).unwrap(),
// &*enc_ciphertext
// );
//
// Pain points :-
//
// - function has a Type, where does that come from?
// <P: consensus::Parameters>
// not a function arg (compiler objects to 6 args, expecting 5)
//
// - values returned as a tuple within Option - ‘Some’, how to access?
// try_sapling_note_decrypt() : Option<(Note, PaymentAddress, MemoBytes)>// if the decrypt works, update FFI values for :-
// - ret_addr (43-byte array, sapling address)
// - ret_value (8-bytes, value in zatoshis, convert from u64?)
// - ret_memo (512-bytes, memo contents, null padded)0 // set/clear return value, 1 = success, 0 = fail
}