parent
862e221a9b
commit
ca3e3a4595
|
@ -48,7 +48,7 @@ zcash_proofs = { version = "0.5", path = "../zcash_proofs" }
|
|||
|
||||
[features]
|
||||
transparent-inputs = ["ripemd160", "secp256k1"]
|
||||
test-dependencies = ["proptest", "zcash_primitives/test-dependencies"]
|
||||
test-dependencies = ["proptest", "zcash_primitives/test-dependencies", "hdwallet"]
|
||||
|
||||
[badges]
|
||||
maintenance = { status = "actively-developed" }
|
||||
|
|
|
@ -412,6 +412,7 @@ pub mod testing {
|
|||
Ok(Vec::new())
|
||||
}
|
||||
|
||||
#[cfg(feature = "transparent-inputs")]
|
||||
fn get_spendable_transparent_utxos(
|
||||
&self,
|
||||
_address: &TransparentAddress,
|
||||
|
|
|
@ -308,6 +308,7 @@ where
|
|||
|
||||
let mut builder = Builder::new(params.clone(), latest_scanned_height);
|
||||
|
||||
#[cfg(feature = "transparent-inputs")]
|
||||
for utxo in &utxos {
|
||||
let coin = TxOut {
|
||||
value: utxo.value,
|
||||
|
|
|
@ -5,9 +5,9 @@ use zcash_primitives::zip32::{ChildIndex, ExtendedSpendingKey};
|
|||
#[cfg(feature = "transparent-inputs")]
|
||||
use {
|
||||
crate::wallet::AccountId,
|
||||
bs58::decode::Error as Bs58Error,
|
||||
bs58::{self, decode::Error as Bs58Error},
|
||||
hdwallet::{ExtendedPrivKey, KeyIndex},
|
||||
secp256k1::{key::PublicKey, Secp256k1, SecretKey},
|
||||
secp256k1::{key::PublicKey, key::SecretKey, Secp256k1},
|
||||
sha2::{Digest, Sha256},
|
||||
std::convert::TryInto,
|
||||
zcash_primitives::{consensus, legacy::TransparentAddress},
|
||||
|
@ -109,9 +109,55 @@ impl TryInto<SecretKey> for Wif {
|
|||
mod tests {
|
||||
use super::spending_key;
|
||||
|
||||
#[cfg(feature = "transparent-inputs")]
|
||||
use {
|
||||
super::{derive_secret_key_from_seed, derive_transparent_address_from_secret_key, Wif},
|
||||
crate::{encoding::AddressCodec, wallet::AccountId},
|
||||
secp256k1::key::SecretKey,
|
||||
std::convert::TryInto,
|
||||
zcash_primitives::consensus::MAIN_NETWORK,
|
||||
};
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn spending_key_panics_on_short_seed() {
|
||||
let _ = spending_key(&[0; 31][..], 0, 0);
|
||||
}
|
||||
|
||||
#[cfg(feature = "transparent-inputs")]
|
||||
#[test]
|
||||
fn sk_to_wif() {
|
||||
let seed_hex = "6ef5f84def6f4b9d38f466586a8380a38593bd47c8cda77f091856176da47f26b5bd1c8d097486e5635df5a66e820d28e1d73346f499801c86228d43f390304f";
|
||||
let seed = hex::decode(&seed_hex).unwrap();
|
||||
let sk = derive_secret_key_from_seed(&MAIN_NETWORK, &seed, AccountId(0), 0).unwrap();
|
||||
assert_eq!(
|
||||
Wif::from_secret_key(&sk, true).0,
|
||||
"L4BvDC33yLjMRxipZvdiUmdYeRfZmR8viziwsVwe72zJdGbiJPv2".to_string()
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg(feature = "transparent-inputs")]
|
||||
#[test]
|
||||
fn sk_to_taddr() {
|
||||
let seed_hex = "6ef5f84def6f4b9d38f466586a8380a38593bd47c8cda77f091856176da47f26b5bd1c8d097486e5635df5a66e820d28e1d73346f499801c86228d43f390304f";
|
||||
let seed = hex::decode(&seed_hex).unwrap();
|
||||
let sk = derive_secret_key_from_seed(&MAIN_NETWORK, &seed, AccountId(0), 0).unwrap();
|
||||
let taddr = derive_transparent_address_from_secret_key(sk);
|
||||
assert_eq!(
|
||||
taddr.encode(&MAIN_NETWORK),
|
||||
"t1PKtYdJJHhc3Pxowmznkg7vdTwnhEsCvR4".to_string()
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg(feature = "transparent-inputs")]
|
||||
#[test]
|
||||
fn sk_wif_to_taddr() {
|
||||
let sk_wif = Wif("L4BvDC33yLjMRxipZvdiUmdYeRfZmR8viziwsVwe72zJdGbiJPv2".to_string());
|
||||
let sk: SecretKey = sk_wif.try_into().expect("invalid wif");
|
||||
let taddr = derive_transparent_address_from_secret_key(sk);
|
||||
assert_eq!(
|
||||
taddr.encode(&MAIN_NETWORK),
|
||||
"t1PKtYdJJHhc3Pxowmznkg7vdTwnhEsCvR4".to_string()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue