Compare commits
No commits in common. "c5feb10fbcbb91344ec5d8416f4941083e41cfb9" and "4f20160c36c60f3df5a3d24c8e3711320e8cead2" have entirely different histories.
c5feb10fbc
...
4f20160c36
4 changed files with 30 additions and 30 deletions
|
@ -59,12 +59,11 @@ use zcash_address::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use zcash_client_backend::keys::sapling::{
|
use zcash_client_backend::keys::sapling::{
|
||||||
spending_key,
|
|
||||||
ExtendedFullViewingKey,
|
ExtendedFullViewingKey,
|
||||||
ExtendedSpendingKey
|
ExtendedSpendingKey
|
||||||
};
|
};
|
||||||
|
|
||||||
use zcash_primitives::zip32::DiversifierIndex;
|
use zcash_primitives::zip32::{ AccountId, DiversifierIndex };
|
||||||
|
|
||||||
use orchard::{
|
use orchard::{
|
||||||
Action,
|
Action,
|
||||||
|
@ -628,16 +627,23 @@ 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(
|
||||||
seed: *const u8,
|
iseed: *const u8,
|
||||||
seed_len: usize,
|
iseed_len: usize,
|
||||||
coin_type: u32,
|
ix: u32,
|
||||||
acc_id: u32,
|
|
||||||
out: *mut u8,
|
out: *mut u8,
|
||||||
out_len: &mut usize
|
out_len: &mut usize
|
||||||
){
|
){
|
||||||
let s: Vec<u8> = marshall_from_haskell_var(seed, seed_len, RW);
|
let seed: Vec<u8> = marshall_from_haskell_var(iseed, iseed_len, RW);
|
||||||
let sk = spending_key(&s, coin_type, zcash_primitives::zip32::AccountId::try_from(acc_id).unwrap());
|
let su8 = &seed;
|
||||||
marshall_to_haskell_var(&sk.to_bytes().to_vec(), out, out_len, RW);
|
let seedu8 : &[u8] = &su8;
|
||||||
|
let extsk: ExtendedSpendingKey = ExtendedSpendingKey::master(&seedu8);
|
||||||
|
if ix == 0 {
|
||||||
|
let extsk_bytes = extsk.to_bytes().to_vec();
|
||||||
|
marshall_to_haskell_var(&extsk_bytes, out, out_len, RW);
|
||||||
|
} else {
|
||||||
|
let child_sk = extsk.derive_child(ChildIndex::from_index(ix + (1 << 31)));
|
||||||
|
marshall_to_haskell_var(&child_sk.to_bytes().to_vec(), out, out_len, RW);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
|
|
|
@ -137,7 +137,6 @@ import ZcashHaskell.Types
|
||||||
{# fun unsafe rust_wrapper_sapling_spendingkey as rustWrapperSaplingSpendingkey
|
{# fun unsafe rust_wrapper_sapling_spendingkey as rustWrapperSaplingSpendingkey
|
||||||
{ toBorshVar* `BS.ByteString'&
|
{ toBorshVar* `BS.ByteString'&
|
||||||
, `Word32'
|
, `Word32'
|
||||||
, `Word32'
|
|
||||||
, getVarBuffer `Buffer (BS.ByteString)'&
|
, getVarBuffer `Buffer (BS.ByteString)'&
|
||||||
}
|
}
|
||||||
-> `()'
|
-> `()'
|
||||||
|
|
|
@ -46,7 +46,6 @@ import ZcashHaskell.Types
|
||||||
, Seed(..)
|
, Seed(..)
|
||||||
, ShieldedOutput(..)
|
, ShieldedOutput(..)
|
||||||
, decodeHexText
|
, decodeHexText
|
||||||
, getValue
|
|
||||||
)
|
)
|
||||||
import ZcashHaskell.Utils (decodeBech32)
|
import ZcashHaskell.Utils (decodeBech32)
|
||||||
|
|
||||||
|
@ -96,18 +95,15 @@ instance FromJSON RawTxResponse where
|
||||||
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 SpendingKey using a HDSeed
|
-- | Attempts to obtain a sapling SpendingKey using a HDSeed
|
||||||
genSaplingSpendingKey :: Seed -> CoinType -> Int -> Maybe SaplingSpendingKey
|
genSaplingSpendingKey :: Seed -> Int -> Maybe SaplingSpendingKey
|
||||||
genSaplingSpendingKey seed c i = do
|
genSaplingSpendingKey seed i = do
|
||||||
if BS.length res == 169
|
if BS.length res == 169
|
||||||
then Just res
|
then Just res
|
||||||
else Nothing
|
else Nothing
|
||||||
where
|
where
|
||||||
res =
|
res =
|
||||||
withPureBorshVarBuffer
|
withPureBorshVarBuffer
|
||||||
(rustWrapperSaplingSpendingkey
|
(rustWrapperSaplingSpendingkey seed (fromIntegral i))
|
||||||
seed
|
|
||||||
(fromIntegral $ getValue c)
|
|
||||||
(fromIntegral i))
|
|
||||||
|
|
||||||
-- | Attempts to generate a sapling Payment Address using an ExtendedSpendingKey and a Diversifier Index
|
-- | Attempts to generate a sapling Payment Address using an ExtendedSpendingKey and a Diversifier Index
|
||||||
genSaplingPaymentAddress :: Int -> SaplingSpendingKey -> Maybe SaplingReceiver
|
genSaplingPaymentAddress :: Int -> SaplingSpendingKey -> Maybe SaplingReceiver
|
||||||
|
|
25
test/Spec.hs
25
test/Spec.hs
|
@ -604,7 +604,7 @@ main = do
|
||||||
Nothing -> return $ expectationFailure "Failed to generate seed"
|
Nothing -> return $ expectationFailure "Failed to generate seed"
|
||||||
Just s' -> do
|
Just s' -> do
|
||||||
let oK = genOrchardSpendingKey s' MainNetCoin 0
|
let oK = genOrchardSpendingKey s' MainNetCoin 0
|
||||||
let sK = genSaplingSpendingKey s' MainNetCoin 0
|
let sK = genSaplingSpendingKey s' 0
|
||||||
let tK = genTransparentPrvKey s'
|
let tK = genTransparentPrvKey s'
|
||||||
let oR = genOrchardReceiver 0 =<< oK
|
let oR = genOrchardReceiver 0 =<< oK
|
||||||
let sR = genSaplingPaymentAddress 0 =<< sK
|
let sR = genSaplingPaymentAddress 0 =<< sK
|
||||||
|
@ -623,7 +623,7 @@ main = do
|
||||||
Nothing -> return $ expectationFailure "Failed to generate seed"
|
Nothing -> return $ expectationFailure "Failed to generate seed"
|
||||||
Just s' -> do
|
Just s' -> do
|
||||||
let oK = genOrchardSpendingKey s' MainNetCoin 0
|
let oK = genOrchardSpendingKey s' MainNetCoin 0
|
||||||
let sK = genSaplingSpendingKey s' MainNetCoin 0
|
let sK = genSaplingSpendingKey s' 0
|
||||||
let tK = genTransparentPrvKey s'
|
let tK = genTransparentPrvKey s'
|
||||||
let oR = genOrchardReceiver 0 =<< oK
|
let oR = genOrchardReceiver 0 =<< oK
|
||||||
let sR = genSaplingPaymentAddress 0 =<< sK
|
let sR = genSaplingPaymentAddress 0 =<< sK
|
||||||
|
@ -654,20 +654,19 @@ prop_OrchardReceiver ::
|
||||||
prop_OrchardReceiver s c (NonNegative i) (NonNegative j) =
|
prop_OrchardReceiver s c (NonNegative i) (NonNegative j) =
|
||||||
genOrchardReceiver j (fromMaybe "" $ genOrchardSpendingKey s c i) =/= Nothing
|
genOrchardReceiver j (fromMaybe "" $ genOrchardSpendingKey s c i) =/= Nothing
|
||||||
|
|
||||||
prop_SaplingSpendingKey :: Seed -> CoinType -> NonNegative Int -> Property
|
prop_SaplingSpendingKey :: Seed -> NonNegative Int -> Property
|
||||||
prop_SaplingSpendingKey s c (NonNegative i) =
|
prop_SaplingSpendingKey s (NonNegative i) =
|
||||||
genSaplingSpendingKey s c i =/= Nothing
|
genSaplingSpendingKey s i =/= Nothing
|
||||||
|
|
||||||
prop_SaplingReceiver ::
|
prop_SaplingReceiver :: Seed -> NonNegative Int -> NonNegative Int -> Property
|
||||||
Seed -> CoinType -> NonNegative Int -> NonNegative Int -> Property
|
prop_SaplingReceiver s (NonNegative i) (NonNegative j) =
|
||||||
prop_SaplingReceiver s c (NonNegative i) (NonNegative j) =
|
genSaplingPaymentAddress i (fromMaybe "" $ genSaplingSpendingKey s j) =/=
|
||||||
genSaplingPaymentAddress i (fromMaybe "" $ genSaplingSpendingKey s c j) =/=
|
|
||||||
Nothing
|
Nothing
|
||||||
|
|
||||||
prop_SaplingRecRepeated :: Seed -> CoinType -> NonNegative Int -> Property
|
prop_SaplingRecRepeated :: Seed -> NonNegative Int -> Property
|
||||||
prop_SaplingRecRepeated s c (NonNegative i) =
|
prop_SaplingRecRepeated s (NonNegative i) =
|
||||||
genSaplingPaymentAddress i (fromMaybe "" $ genSaplingSpendingKey s c 1) =/=
|
genSaplingPaymentAddress i (fromMaybe "" $ genSaplingSpendingKey s 1) =/=
|
||||||
genSaplingPaymentAddress (i + 1) (fromMaybe "" $ genSaplingSpendingKey s c 1)
|
genSaplingPaymentAddress (i + 1) (fromMaybe "" $ genSaplingSpendingKey s 1)
|
||||||
|
|
||||||
prop_OrchardRecRepeated ::
|
prop_OrchardRecRepeated ::
|
||||||
Seed -> CoinType -> NonNegative Int -> NonNegative Int -> Property
|
Seed -> CoinType -> NonNegative Int -> NonNegative Int -> Property
|
||||||
|
|
Loading…
Reference in a new issue