From cc2dfbf7bf1f40a4d9d1aeb731537568bab61164 Mon Sep 17 00:00:00 2001 From: Kris Nuttycombe Date: Thu, 5 Dec 2024 15:46:58 -0700 Subject: [PATCH] zcash_client_backend: Add AccountSource::key_derivation --- zcash_client_backend/CHANGELOG.md | 3 +++ zcash_client_backend/src/data_api.rs | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/zcash_client_backend/CHANGELOG.md b/zcash_client_backend/CHANGELOG.md index e55b14989..e0ad6c724 100644 --- a/zcash_client_backend/CHANGELOG.md +++ b/zcash_client_backend/CHANGELOG.md @@ -7,6 +7,9 @@ and this library adheres to Rust's notion of ## [Unreleased] +### Added +- `zcash_client_backend::data_api::AccountSource::key_derivation` + ### Changed - `zcash_client_backend::data_api::WalletRead`: - The `create_account`, `import_account_hd`, and `import_account_ufvk` diff --git a/zcash_client_backend/src/data_api.rs b/zcash_client_backend/src/data_api.rs index 2512c409d..3b3ab351b 100644 --- a/zcash_client_backend/src/data_api.rs +++ b/zcash_client_backend/src/data_api.rs @@ -385,6 +385,28 @@ pub enum AccountSource { }, } +impl AccountSource { + /// Returns the key derivation metadata for the account source, if any is available. + pub fn key_derivation(&self) -> Option<&Zip32Derivation> { + match self { + AccountSource::Derived { derivation, .. } => Some(derivation), + AccountSource::Imported { + purpose: AccountPurpose::Spending { derivation }, + .. + } => derivation.as_ref(), + _ => None, + } + } + + /// Returns the application-level key source identifier. + pub fn key_source(&self) -> Option<&str> { + match self { + AccountSource::Derived { key_source, .. } => key_source.as_ref().map(|s| s.as_str()), + AccountSource::Imported { key_source, .. } => key_source.as_ref().map(|s| s.as_str()), + } + } +} + /// A set of capabilities that a client account must provide. pub trait Account { type AccountId: Copy;