From b42344d4912ab19f0a5a8b6c175f664aa25532e1 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Wed, 24 Aug 2022 14:56:58 +0000 Subject: [PATCH] zcash_client_backend: Generate Orchard component for USKs This ensures that the resulting UFVKs and UAs also contain Orchard components. --- zcash_client_backend/src/keys.rs | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/zcash_client_backend/src/keys.rs b/zcash_client_backend/src/keys.rs index d6289dadc..dc052c8d4 100644 --- a/zcash_client_backend/src/keys.rs +++ b/zcash_client_backend/src/keys.rs @@ -69,6 +69,7 @@ fn to_transparent_child_index(j: DiversifierIndex) -> Option { #[derive(Debug)] #[doc(hidden)] pub enum DerivationError { + Orchard(orchard::zip32::Error), #[cfg(feature = "transparent-inputs")] Transparent(hdwallet::error::Error), } @@ -82,6 +83,7 @@ pub struct UnifiedSpendingKey { #[cfg(feature = "transparent-inputs")] transparent: legacy::AccountPrivKey, sapling: sapling::ExtendedSpendingKey, + orchard: orchard::keys::SpendingKey, } #[doc(hidden)] @@ -95,6 +97,10 @@ impl UnifiedSpendingKey { panic!("ZIP 32 seeds MUST be at least 32 bytes"); } + let orchard = + orchard::keys::SpendingKey::from_zip32_seed(seed, params.coin_type(), account.into()) + .map_err(DerivationError::Orchard)?; + #[cfg(feature = "transparent-inputs")] let transparent = legacy::AccountPrivKey::from_seed(params, seed, account) .map_err(DerivationError::Transparent)?; @@ -104,6 +110,7 @@ impl UnifiedSpendingKey { #[cfg(feature = "transparent-inputs")] transparent, sapling: sapling::spending_key(seed, params.coin_type(), account), + orchard, }) } @@ -112,7 +119,7 @@ impl UnifiedSpendingKey { #[cfg(feature = "transparent-inputs")] transparent: Some(self.transparent.to_account_pubkey()), sapling: Some(sapling::ExtendedFullViewingKey::from(&self.sapling).into()), - orchard: None, + orchard: Some((&self.orchard).into()), unknown: vec![], } } @@ -128,11 +135,15 @@ impl UnifiedSpendingKey { &self.transparent } - /// Returns the Sapling extended full viewing key component of this - /// unified key. + /// Returns the Sapling extended spending key component of this unified spending key. pub fn sapling(&self) -> &sapling::ExtendedSpendingKey { &self.sapling } + + /// Returns the Orchard spending key component of this unified spending key. + pub fn orchard(&self) -> &orchard::keys::SpendingKey { + &self.orchard + } } /// A set of viewing keys that are all associated with a single @@ -283,6 +294,11 @@ impl UnifiedFullViewingKey { self.sapling.as_ref() } + /// Returns the Orchard full viewing key component of this unified key. + pub fn orchard(&self) -> Option<&orchard::keys::FullViewingKey> { + self.orchard.as_ref() + } + /// Attempts to derive the Unified Address for the given diversifier index. /// /// Returns `None` if the specified index does not produce a valid diversifier.