Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove zcash_keys dependency on zcash_primitives. #1658

Merged
merged 1 commit into from
Dec 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion zcash_keys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -37,6 +36,7 @@ bs58.workspace = true

# - Transparent protocols
bip32 = { workspace = true, optional = true }
transparent.workspace = true

# - Logging and metrics
memuse.workspace = true
Expand Down
6 changes: 3 additions & 3 deletions zcash_keys/src/address.rs
Original file line number Diff line number Diff line change
@@ -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")]
Expand Down Expand Up @@ -433,15 +433,15 @@ 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};

use super::{Address, UnifiedAddress};

#[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,
Expand Down
18 changes: 8 additions & 10 deletions zcash_keys/src/encoding.rs
Original file line number Diff line number Diff line change
@@ -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")]
Expand Down Expand Up @@ -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],
Expand Down Expand Up @@ -481,8 +481,6 @@ pub fn encode_transparent_address_p<P: consensus::Parameters>(
/// ),
/// Ok(Some(TransparentAddress::ScriptHash([0; 20]))),
/// );
/// ```
/// [`TransparentAddress`]: zcash_primitives::legacy::TransparentAddress
pub fn decode_transparent_address(
pubkey_version: &[u8],
script_version: &[u8],
Expand Down
47 changes: 25 additions & 22 deletions zcash_keys/src/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@ 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 {
byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt},
std::convert::TryFrom,
std::io::{Read, Write},
zcash_encoding::CompactSize,
zcash_primitives::consensus::BranchId,
zcash_protocol::consensus::BranchId,
};

#[cfg(feature = "orchard")]
Expand Down Expand Up @@ -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")]
Expand All @@ -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),
Expand All @@ -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<UnifiedSpendingKey, DerivationError> {
Expand Down Expand Up @@ -272,7 +272,7 @@ impl UnifiedSpendingKey {
/// Returns the transparent component of the unified key at the
/// BIP44 path `m/44'/<coin_type>'/<account>'`.
#[cfg(feature = "transparent-inputs")]
pub fn transparent(&self) -> &legacy::AccountPrivKey {
pub fn transparent(&self) -> &transparent::keys::AccountPrivKey {
&self.transparent
}

Expand Down Expand Up @@ -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))?,
);
}
Expand Down Expand Up @@ -631,7 +631,7 @@ impl From<bip32::Error> for DerivationError {
#[derive(Clone, Debug)]
pub struct UnifiedFullViewingKey {
#[cfg(feature = "transparent-inputs")]
transparent: Option<legacy::AccountPubKey>,
transparent: Option<transparent::keys::AccountPubKey>,
#[cfg(feature = "sapling")]
sapling: Option<sapling::DiversifiableFullViewingKey>,
#[cfg(feature = "orchard")]
Expand All @@ -647,7 +647,9 @@ impl UnifiedFullViewingKey {
/// be used instead.
#[cfg(any(test, feature = "test-dependencies"))]
pub fn new(
#[cfg(feature = "transparent-inputs")] transparent: Option<legacy::AccountPubKey>,
#[cfg(feature = "transparent-inputs")] transparent: Option<
transparent::keys::AccountPubKey,
>,
#[cfg(feature = "sapling")] sapling: Option<sapling::DiversifiableFullViewingKey>,
#[cfg(feature = "orchard")] orchard: Option<orchard::keys::FullViewingKey>,
// TODO: Implement construction of UFVKs with metadata items.
Expand Down Expand Up @@ -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<legacy::AccountPubKey>,
#[cfg(feature = "transparent-inputs")] transparent: Option<
transparent::keys::AccountPubKey,
>,
#[cfg(feature = "sapling")] sapling: Option<sapling::DiversifiableFullViewingKey>,
#[cfg(feature = "orchard")] orchard: Option<orchard::keys::FullViewingKey>,
unknown: Vec<(u32, Vec<u8>)>,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -874,7 +878,7 @@ impl UnifiedFullViewingKey {
/// Returns the transparent component of the unified key at the
/// BIP44 path `m/44'/<coin_type>'/<account>'`.
#[cfg(feature = "transparent-inputs")]
pub fn transparent(&self) -> Option<&legacy::AccountPubKey> {
pub fn transparent(&self) -> Option<&transparent::keys::AccountPubKey> {
self.transparent.as_ref()
}

Expand Down Expand Up @@ -937,7 +941,7 @@ impl UnifiedFullViewingKey {
#[derive(Clone, Debug)]
pub struct UnifiedIncomingViewingKey {
#[cfg(feature = "transparent-inputs")]
transparent: Option<zcash_primitives::legacy::keys::ExternalIvk>,
transparent: Option<transparent::keys::ExternalIvk>,
#[cfg(feature = "sapling")]
sapling: Option<::sapling::zip32::IncomingViewingKey>,
#[cfg(feature = "orchard")]
Expand All @@ -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<transparent::keys::ExternalIvk>,
#[cfg(feature = "sapling")] sapling: Option<::sapling::zip32::IncomingViewingKey>,
#[cfg(feature = "orchard")] orchard: Option<orchard::keys::IncomingViewingKey>,
// TODO: Implement construction of UIVKs with metadata items.
Expand Down Expand Up @@ -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))?,
);
}
Expand Down Expand Up @@ -1099,7 +1101,7 @@ impl UnifiedIncomingViewingKey {

/// Returns the Transparent external IVK, if present.
#[cfg(feature = "transparent-inputs")]
pub fn transparent(&self) -> &Option<zcash_primitives::legacy::keys::ExternalIvk> {
pub fn transparent(&self) -> &Option<transparent::keys::ExternalIvk> {
&self.transparent
}

Expand Down Expand Up @@ -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<Value = UnifiedSpendingKey> {
prop::array::uniform32(prop::num::u8::ANY).prop_flat_map(move |seed| {
Expand Down Expand Up @@ -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,
};

Expand All @@ -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()
Expand Down
7 changes: 5 additions & 2 deletions zcash_transparent/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down
Loading