From 574ca4e180ea216cb855ad823fe8ca267c2766cd Mon Sep 17 00:00:00 2001 From: Kris Nuttycombe Date: Fri, 21 Jan 2022 18:20:12 -0700 Subject: [PATCH] Add accessors to UnifiedSpendingKey --- zcash_client_backend/src/keys.rs | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/zcash_client_backend/src/keys.rs b/zcash_client_backend/src/keys.rs index 263d42f47..b159ad101 100644 --- a/zcash_client_backend/src/keys.rs +++ b/zcash_client_backend/src/keys.rs @@ -1,13 +1,10 @@ //! Helper functions for managing light client key material. use crate::wallet::AccountId; -use zcash_primitives::{ - consensus, - zip32::{ExtendedFullViewingKey, ExtendedSpendingKey}, -}; +use zcash_primitives::consensus; pub mod sapling { - pub use zcash_primitives::zip32::ExtendedFullViewingKey; - use zcash_primitives::zip32::{ChildIndex, ExtendedSpendingKey}; + use zcash_primitives::zip32::ChildIndex; + pub use zcash_primitives::zip32::{ExtendedFullViewingKey, ExtendedSpendingKey}; use crate::wallet::AccountId; @@ -239,7 +236,7 @@ pub struct UnifiedSpendingKey { account: AccountId, #[cfg(feature = "transparent-inputs")] transparent: transparent::AccountPrivKey, - sapling: ExtendedSpendingKey, + sapling: sapling::ExtendedSpendingKey, } impl UnifiedSpendingKey { @@ -269,9 +266,26 @@ impl UnifiedSpendingKey { account: self.account, #[cfg(feature = "transparent-inputs")] transparent: Some(self.transparent.to_account_pubkey()), - sapling: Some(ExtendedFullViewingKey::from(&self.sapling)), + sapling: Some(sapling::ExtendedFullViewingKey::from(&self.sapling)), } } + + pub fn account(&self) -> AccountId { + self.account + } + + /// Returns the transparent component of the unified key at the + /// BIP44 path `m/44'/'/'`. + #[cfg(feature = "transparent-inputs")] + pub fn transparent(&self) -> Option<&transparent::AccountPrivKey> { + Some(&self.transparent) + } + + /// Returns the Sapling extended full viewing key component of this + /// unified key. + pub fn sapling(&self) -> Option<&sapling::ExtendedSpendingKey> { + Some(&self.sapling) + } } /// A set of viewing keys that are all associated with a single