diff --git a/Cargo.lock b/Cargo.lock index c6cbb1959..71f7616d5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6336,6 +6336,7 @@ dependencies = [ "zcash_encoding", "zcash_primitives", "zcash_protocol", + "zcash_transparent", "zip32", ] diff --git a/zcash_keys/Cargo.toml b/zcash_keys/Cargo.toml index aa8699710..52a8e3c62 100644 --- a/zcash_keys/Cargo.toml +++ b/zcash_keys/Cargo.toml @@ -21,7 +21,6 @@ rustdoc-args = ["--cfg", "docsrs"] [dependencies] zcash_address.workspace = true zcash_encoding.workspace = true -zcash_primitives.workspace = true zcash_protocol.workspace = true zip32.workspace = true @@ -37,6 +36,7 @@ bs58.workspace = true # - Transparent protocols bip32 = { workspace = true, optional = true } +transparent.workspace = true # - Logging and metrics memuse.workspace = true diff --git a/zcash_keys/src/address.rs b/zcash_keys/src/address.rs index 265280ee6..29eea7f07 100644 --- a/zcash_keys/src/address.rs +++ b/zcash_keys/src/address.rs @@ -1,10 +1,10 @@ //! Structs for handling supported address types. +use transparent::address::TransparentAddress; use zcash_address::{ unified::{self, Container, Encoding, Typecode}, ConversionError, ToAddress, TryFromRawAddress, ZcashAddress, }; -use zcash_primitives::legacy::TransparentAddress; use zcash_protocol::consensus::{self, NetworkType}; #[cfg(feature = "sapling")] @@ -433,7 +433,7 @@ impl Address { ))] pub mod testing { use proptest::prelude::*; - use zcash_primitives::consensus::Network; + use zcash_protocol::consensus::Network; use crate::keys::{testing::arb_unified_spending_key, UnifiedAddressRequest}; @@ -441,7 +441,7 @@ pub mod testing { #[cfg(feature = "sapling")] use sapling::testing::arb_payment_address; - use zcash_primitives::legacy::testing::arb_transparent_addr; + use transparent::address::testing::arb_transparent_addr; pub fn arb_unified_addr( params: Network, diff --git a/zcash_keys/src/encoding.rs b/zcash_keys/src/encoding.rs index 93d282fdb..09f1bd0fe 100644 --- a/zcash_keys/src/encoding.rs +++ b/zcash_keys/src/encoding.rs @@ -1,23 +1,25 @@ //! Encoding and decoding functions for Zcash key and address structs. //! //! Human-Readable Prefixes (HRPs) for Bech32 encodings are located in the -//! [zcash_primitives::constants] module. +//! [zcash_protocol::constants] module. use crate::address::UnifiedAddress; -use bech32::primitives::decode::CheckedHrpstringError; use bs58::{self, decode::Error as Bs58Error}; use std::fmt; -use zcash_primitives::consensus::NetworkConstants; +use transparent::address::TransparentAddress; use zcash_address::unified::{self, Encoding}; -use zcash_primitives::{consensus, legacy::TransparentAddress}; +use zcash_protocol::consensus::{self, NetworkConstants}; #[cfg(feature = "sapling")] use { - bech32::{primitives::decode::CheckedHrpstring, Bech32, Hrp}, + bech32::{ + primitives::decode::{CheckedHrpstring, CheckedHrpstringError}, + Bech32, Hrp, + }, sapling::zip32::{ExtendedFullViewingKey, ExtendedSpendingKey}, std::io::{self, Write}, - zcash_primitives::consensus::NetworkType, + zcash_protocol::consensus::NetworkType, }; #[cfg(feature = "sapling")] @@ -413,8 +415,6 @@ pub fn decode_payment_address( /// ), /// "t26YoyZ1iPgiMEWL4zGUm74eVWfhyDMXzY2", /// ); -/// ``` -/// [`TransparentAddress`]: zcash_primitives::legacy::TransparentAddress pub fn encode_transparent_address( pubkey_version: &[u8], script_version: &[u8], @@ -481,8 +481,6 @@ pub fn encode_transparent_address_p( /// ), /// Ok(Some(TransparentAddress::ScriptHash([0; 20]))), /// ); -/// ``` -/// [`TransparentAddress`]: zcash_primitives::legacy::TransparentAddress pub fn decode_transparent_address( pubkey_version: &[u8], script_version: &[u8], diff --git a/zcash_keys/src/keys.rs b/zcash_keys/src/keys.rs index 698294a5f..3b6ea90c0 100644 --- a/zcash_keys/src/keys.rs +++ b/zcash_keys/src/keys.rs @@ -16,14 +16,14 @@ use zcash_protocol::consensus::NetworkConstants; #[cfg(feature = "transparent-inputs")] use { std::convert::TryInto, - zcash_primitives::legacy::keys::{self as legacy, IncomingViewingKey, NonHardenedChildIndex}, + transparent::keys::{IncomingViewingKey, NonHardenedChildIndex}, }; #[cfg(all( feature = "transparent-inputs", any(test, feature = "test-dependencies") ))] -use zcash_primitives::legacy::TransparentAddress; +use transparent::address::TransparentAddress; #[cfg(feature = "unstable")] use { @@ -31,7 +31,7 @@ use { std::convert::TryFrom, std::io::{Read, Write}, zcash_encoding::CompactSize, - zcash_primitives::consensus::BranchId, + zcash_protocol::consensus::BranchId, }; #[cfg(feature = "orchard")] @@ -206,7 +206,7 @@ impl Era { #[derive(Clone, Debug)] pub struct UnifiedSpendingKey { #[cfg(feature = "transparent-inputs")] - transparent: legacy::AccountPrivKey, + transparent: transparent::keys::AccountPrivKey, #[cfg(feature = "sapling")] sapling: sapling::ExtendedSpendingKey, #[cfg(feature = "orchard")] @@ -225,7 +225,7 @@ impl UnifiedSpendingKey { UnifiedSpendingKey::from_checked_parts( #[cfg(feature = "transparent-inputs")] - legacy::AccountPrivKey::from_seed(_params, seed, _account) + transparent::keys::AccountPrivKey::from_seed(_params, seed, _account) .map_err(DerivationError::Transparent)?, #[cfg(feature = "sapling")] sapling::spending_key(seed, _params.coin_type(), _account), @@ -238,7 +238,7 @@ impl UnifiedSpendingKey { /// Construct a USK from its constituent parts, after verifying that UIVK derivation can /// succeed. fn from_checked_parts( - #[cfg(feature = "transparent-inputs")] transparent: legacy::AccountPrivKey, + #[cfg(feature = "transparent-inputs")] transparent: transparent::keys::AccountPrivKey, #[cfg(feature = "sapling")] sapling: sapling::ExtendedSpendingKey, #[cfg(feature = "orchard")] orchard: orchard::keys::SpendingKey, ) -> Result { @@ -272,7 +272,7 @@ impl UnifiedSpendingKey { /// Returns the transparent component of the unified key at the /// BIP44 path `m/44'/'/'`. #[cfg(feature = "transparent-inputs")] - pub fn transparent(&self) -> &legacy::AccountPrivKey { + pub fn transparent(&self) -> &transparent::keys::AccountPrivKey { &self.transparent } @@ -417,7 +417,7 @@ impl UnifiedSpendingKey { #[cfg(feature = "transparent-inputs")] { transparent = Some( - legacy::AccountPrivKey::from_bytes(&key) + transparent::keys::AccountPrivKey::from_bytes(&key) .ok_or(DecodingError::KeyDataInvalid(Typecode::P2pkh))?, ); } @@ -631,7 +631,7 @@ impl From for DerivationError { #[derive(Clone, Debug)] pub struct UnifiedFullViewingKey { #[cfg(feature = "transparent-inputs")] - transparent: Option, + transparent: Option, #[cfg(feature = "sapling")] sapling: Option, #[cfg(feature = "orchard")] @@ -647,7 +647,9 @@ impl UnifiedFullViewingKey { /// be used instead. #[cfg(any(test, feature = "test-dependencies"))] pub fn new( - #[cfg(feature = "transparent-inputs")] transparent: Option, + #[cfg(feature = "transparent-inputs")] transparent: Option< + transparent::keys::AccountPubKey, + >, #[cfg(feature = "sapling")] sapling: Option, #[cfg(feature = "orchard")] orchard: Option, // TODO: Implement construction of UFVKs with metadata items. @@ -702,7 +704,9 @@ impl UnifiedFullViewingKey { /// Construct a UFVK from its constituent parts, after verifying that UIVK derivation can /// succeed. fn from_checked_parts( - #[cfg(feature = "transparent-inputs")] transparent: Option, + #[cfg(feature = "transparent-inputs")] transparent: Option< + transparent::keys::AccountPubKey, + >, #[cfg(feature = "sapling")] sapling: Option, #[cfg(feature = "orchard")] orchard: Option, unknown: Vec<(u32, Vec)>, @@ -788,7 +792,7 @@ impl UnifiedFullViewingKey { data.to_vec(), ))), #[cfg(feature = "transparent-inputs")] - unified::Fvk::P2pkh(data) => legacy::AccountPubKey::deserialize(data) + unified::Fvk::P2pkh(data) => transparent::keys::AccountPubKey::deserialize(data) .map_err(|_| DecodingError::KeyDataInvalid(Typecode::P2pkh)) .map(|tfvk| { transparent = Some(tfvk); @@ -874,7 +878,7 @@ impl UnifiedFullViewingKey { /// Returns the transparent component of the unified key at the /// BIP44 path `m/44'/'/'`. #[cfg(feature = "transparent-inputs")] - pub fn transparent(&self) -> Option<&legacy::AccountPubKey> { + pub fn transparent(&self) -> Option<&transparent::keys::AccountPubKey> { self.transparent.as_ref() } @@ -937,7 +941,7 @@ impl UnifiedFullViewingKey { #[derive(Clone, Debug)] pub struct UnifiedIncomingViewingKey { #[cfg(feature = "transparent-inputs")] - transparent: Option, + transparent: Option, #[cfg(feature = "sapling")] sapling: Option<::sapling::zip32::IncomingViewingKey>, #[cfg(feature = "orchard")] @@ -954,9 +958,7 @@ impl UnifiedIncomingViewingKey { /// be used instead. #[cfg(any(test, feature = "test-dependencies"))] pub fn new( - #[cfg(feature = "transparent-inputs")] transparent: Option< - zcash_primitives::legacy::keys::ExternalIvk, - >, + #[cfg(feature = "transparent-inputs")] transparent: Option, #[cfg(feature = "sapling")] sapling: Option<::sapling::zip32::IncomingViewingKey>, #[cfg(feature = "orchard")] orchard: Option, // TODO: Implement construction of UIVKs with metadata items. @@ -1033,7 +1035,7 @@ impl UnifiedIncomingViewingKey { #[cfg(feature = "transparent-inputs")] { transparent = Some( - legacy::ExternalIvk::deserialize(data) + transparent::keys::ExternalIvk::deserialize(data) .map_err(|_| DecodingError::KeyDataInvalid(Typecode::P2pkh))?, ); } @@ -1099,7 +1101,7 @@ impl UnifiedIncomingViewingKey { /// Returns the Transparent external IVK, if present. #[cfg(feature = "transparent-inputs")] - pub fn transparent(&self) -> &Option { + pub fn transparent(&self) -> &Option { &self.transparent } @@ -1286,7 +1288,8 @@ pub mod testing { use proptest::prelude::*; use super::UnifiedSpendingKey; - use zcash_primitives::{consensus::Network, zip32::AccountId}; + use zcash_protocol::consensus::Network; + use zip32::AccountId; pub fn arb_unified_spending_key(params: Network) -> impl Strategy { prop::array::uniform32(prop::num::u8::ANY).prop_flat_map(move |seed| { @@ -1326,8 +1329,8 @@ mod tests { #[cfg(feature = "transparent-inputs")] use { crate::{address::Address, encoding::AddressCodec}, + transparent::keys::{AccountPrivKey, IncomingViewingKey}, zcash_address::test_vectors, - zcash_primitives::legacy::keys::{AccountPrivKey, IncomingViewingKey}, zip32::DiversifierIndex, }; @@ -1353,7 +1356,7 @@ mod tests { #[cfg(feature = "transparent-inputs")] #[test] fn pk_to_taddr() { - use zcash_primitives::legacy::keys::NonHardenedChildIndex; + use transparent::keys::NonHardenedChildIndex; let taddr = AccountPrivKey::from_seed(&MAIN_NETWORK, &seed(), AccountId::ZERO) .unwrap() diff --git a/zcash_transparent/src/builder.rs b/zcash_transparent/src/builder.rs index 78d04aad9..c4392b4e4 100644 --- a/zcash_transparent/src/builder.rs +++ b/zcash_transparent/src/builder.rs @@ -9,12 +9,15 @@ use crate::{ address::{Script, TransparentAddress}, bundle::{Authorization, Authorized, Bundle, TxIn, TxOut}, pczt, - sighash::{SighashType, SignableInput, TransparentAuthorizingContext}, + sighash::{SignableInput, TransparentAuthorizingContext}, }; #[cfg(feature = "transparent-inputs")] use { - crate::{bundle::OutPoint, sighash::SIGHASH_ALL}, + crate::{ + bundle::OutPoint, + sighash::{SighashType, SIGHASH_ALL}, + }, sha2::Digest, };