Sapling Spending keys and receivers #27

Merged
pitmutt merged 12 commits from rvv040 into dev040 2024-03-10 15:07:10 +00:00
5 changed files with 40 additions and 30 deletions
Showing only changes of commit 0e6f7503d4 - Show all commits

View file

@ -1314,6 +1314,7 @@ dependencies = [
"borsh 0.10.3", "borsh 0.10.3",
"f4jumble", "f4jumble",
"haskell-ffi", "haskell-ffi",
"nom",
"orchard 0.7.1", "orchard 0.7.1",
"proc-macro2", "proc-macro2",
"zcash_address 0.2.0", "zcash_address 0.2.0",

View file

@ -17,6 +17,7 @@ zcash_primitives = "0.13.0"
zcash_client_backend = "0.10.0" zcash_client_backend = "0.10.0"
zip32 = "0.1.0" zip32 = "0.1.0"
proc-macro2 = "1.0.66" proc-macro2 = "1.0.66"
nom = "7.1.3"
[features] [features]
capi = [] capi = []

View file

@ -49,7 +49,11 @@ use zcash_address::{
ZcashAddress ZcashAddress
}; };
use zcash_client_backend::keys::{sapling, sapling::ExtendedFullViewingKey}; use zcash_client_backend::keys::{
sapling,
sapling::ExtendedFullViewingKey,
sapling::ExtendedSpendingKey};
use zcash_primitives::zip32::AccountId; use zcash_primitives::zip32::AccountId;
use std::slice; use std::slice;
@ -615,24 +619,27 @@ pub extern "C" fn rust_wrapper_recover_seed(
#[no_mangle] #[no_mangle]
pub extern "C" fn rust_wrapper_sapling_spendingkey( pub extern "C" fn rust_wrapper_sapling_spendingkey(
in_seed: *const u8, iseed: *const u8,
seed_len: usize, iseed_len: usize,
coin_type: u32, coin_type: u32,
acc_id: u32, acc_id: u32,
out: *mut u8, out: *mut u8,
out_len: &mut usize out_len: &mut usize
){ ){
let seed: Vec<u8> = marshall_from_haskell_var(in_seed, input_len, RW); println!("From Rust\n=========");
let fake_response = "It's working"; let seed: Vec<u8> = marshall_from_haskell_var(iseed, iseed_len, RW);
marshall_to_haskell_var(&fake_response.as_bytes().to_vec(), out, out_len, RW); if ( seed.len() <= 0 ) {
println!("Seed error, returning a null vector...");
// let extsk = sapling::spending_key(&seed[0..32], marshall_to_haskell_var(&vec![0], out, out_len, RW);
// cointype, } else {
// accountid); println!("Seed in rust : {:?}\n", seed);
// println!("SpendingKey -> {:?}", extsk); println!("Coin Type -> {}\nAccount Id -> {}",coin_type,acc_id);
// let s = extsk.to_bytes(); let su8 = &seed;
// let xsk : Vec<u8> = s.iter().cloned().collect(); let seedu8 : &[u8] = &su8;
// marshall_to_haskell_var(&xsk, out, out_len, RW); let extsk: ExtendedSpendingKey = sapling::ExtendedSpendingKey::master(&seedu8);
let extsk_bytes = extsk.to_bytes().to_vec();
marshall_to_haskell_var(&extsk_bytes, out, out_len, RW);
}
} }
#[no_mangle] #[no_mangle]

View file

@ -41,6 +41,8 @@ import ZcashHaskell.Types
, SaplingSKeyParams(..) , SaplingSKeyParams(..)
, ShieldedOutput(..) , ShieldedOutput(..)
, decodeHexText , decodeHexText
, AccountId
, CoinType
) )
import ZcashHaskell.Utils import ZcashHaskell.Utils
@ -88,14 +90,9 @@ instance FromJSON RawTxResponse where
Just o' -> do Just o' -> do
a <- o' .: "actions" a <- o' .: "actions"
pure $ RawTxResponse i h (getShieldedOutputs h) a ht c b pure $ RawTxResponse i h (getShieldedOutputs h) a ht c b
--
-- | Attempts to obtain a sapling SpendinKey using a HDSeed, a Coin Type and an Account ID -- | Attempts to obtain a sapling SpendinKey using a HDSeed, a Coin Type and an Account ID
genSaplingSpendingKey :: BS.ByteString -> Word32 -> Word32 -> Maybe BS.ByteString genSaplingSpendingKey :: BS.ByteString -> Word32-> AccountId -> BS.ByteString
genSaplingSpendingKey seed coin_type account_id = do genSaplingSpendingKey seed coin_type account_id = do
if BS.length res > 0 let res = withPureBorshVarBuffer (rustWrapperSaplingSpendingkey seed (fromIntegral coin_type) (fromIntegral account_id) )
then Just res res
else Nothing
where
res =
withPureBorshVarBuffer
(rustWrapperSaplingSpendingkey seed coin_type account_id)

View file

@ -57,6 +57,9 @@ import ZcashHaskell.Types
, UnifiedAddress(..) , UnifiedAddress(..)
, UnifiedFullViewingKey(..) , UnifiedFullViewingKey(..)
, decodeHexText , decodeHexText
, AccountId
, CoinType
, getValue
) )
import ZcashHaskell.Utils import ZcashHaskell.Utils
@ -528,10 +531,11 @@ main = do
241, 243, 172, 178, 241, 243, 172, 178,
104, 81, 159, 144 104, 81, 159, 144
] :: [Word8] ] :: [Word8]
let coin = 1 :: Word32 let cointype = getValue TestNetCoin
let account = 0 :: Word32 let account = 0 :: AccountId
let msg = genSaplingSpendingKey (word8ArrayToByteString hdseed) coin account let msg = genSaplingSpendingKey (word8ArrayToByteString hdseed) cointype account
case msg of let msgArr = BS.unpack msg
Nothing -> "Bad response from genSapingSpendingKey" if (length msgArr) == 169
Just msg -> fromMaybe "BadResponse" msg then True
"mm " `shouldBe` "genSaplingSpendingKey Function called." else False
-- msgArr `shouldBe` "It's working."