Skip to content

Commit

Permalink
Add unstable `UnifiedFullViewingKey::from_sapling_extended_full_viewi…
Browse files Browse the repository at this point in the history
…ng_key`
  • Loading branch information
nuttycom committed Aug 30, 2024
1 parent 897018a commit 7c05fcb
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
2 changes: 2 additions & 0 deletions zcash_keys/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ and this library adheres to Rust's notion of

### Added
- `zcash_keys::encoding::decode_extfvk_with_network`
- `impl std::error::Error for DecodingError`
- `impl std::error::Error for Bech32DecodeError`

## [0.3.0] - 2024-08-19
### Notable changes
Expand Down
10 changes: 10 additions & 0 deletions zcash_keys/src/encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@ impl fmt::Display for Bech32DecodeError {
}
}

#[cfg(feature = "sapling")]
impl std::error::Error for Bech32DecodeError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match &self {
Bech32DecodeError::Bech32Error(e) => Some(e),
_ => None,
}
}
}

#[cfg(feature = "sapling")]
fn bech32_decode<T, F>(hrp: &str, s: &str, read: F) -> Result<T, Bech32DecodeError>
where
Expand Down
23 changes: 23 additions & 0 deletions zcash_keys/src/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ use {
#[cfg(feature = "orchard")]
use orchard::{self, keys::Scope};

#[cfg(all(feature = "sapling", feature = "unstable"))]
use ::sapling::zip32::ExtendedFullViewingKey;

#[cfg(feature = "sapling")]
pub mod sapling {
pub use sapling::zip32::{
Expand Down Expand Up @@ -176,6 +179,8 @@ impl std::fmt::Display for DecodingError {
}
}

impl std::error::Error for DecodingError {}

#[cfg(feature = "unstable")]
impl Era {
/// Returns the unique identifier for the era.
Expand Down Expand Up @@ -674,6 +679,24 @@ impl UnifiedFullViewingKey {
vec![],
)
}

#[cfg(all(feature = "sapling", feature = "unstable"))]
pub fn from_sapling_extended_full_viewing_key(
sapling: ExtendedFullViewingKey,
) -> Result<UnifiedFullViewingKey, DerivationError> {
Self::from_checked_parts(
#[cfg(feature = "transparent-inputs")]
None,
#[cfg(feature = "sapling")]
Some(sapling.to_diversifiable_full_viewing_key()),
#[cfg(feature = "orchard")]
None,
// We don't currently allow constructing new UFVKs with unknown items, but we store
// this to allow parsing such UFVKs.
vec![],
)
}

/// Construct a UFVK from its constituent parts, after verifying that UIVK derivation can
/// succeed.
fn from_checked_parts(
Expand Down

0 comments on commit 7c05fcb

Please sign in to comment.