zcash_client_backend: Add AccountSource::key_derivation

This commit is contained in:
Kris Nuttycombe 2024-12-05 15:46:58 -07:00
parent 2da2b3e9fe
commit cc2dfbf7bf
2 changed files with 25 additions and 0 deletions

View File

@ -7,6 +7,9 @@ and this library adheres to Rust's notion of
## [Unreleased] ## [Unreleased]
### Added
- `zcash_client_backend::data_api::AccountSource::key_derivation`
### Changed ### Changed
- `zcash_client_backend::data_api::WalletRead`: - `zcash_client_backend::data_api::WalletRead`:
- The `create_account`, `import_account_hd`, and `import_account_ufvk` - The `create_account`, `import_account_hd`, and `import_account_ufvk`

View File

@ -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. /// A set of capabilities that a client account must provide.
pub trait Account { pub trait Account {
type AccountId: Copy; type AccountId: Copy;