Skip to content

Commit

Permalink
zcash_keys: Make unified key construction APIs consistent with one an…
Browse files Browse the repository at this point in the history
…other.
  • Loading branch information
nuttycom committed Dec 20, 2024
1 parent 4741e44 commit 2f37293
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 11 deletions.
8 changes: 8 additions & 0 deletions zcash_client_sqlite/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2066,6 +2066,10 @@ mod tests {
ufvk.sapling().cloned(),
#[cfg(feature = "orchard")]
ufvk.orchard().cloned(),
vec![],
None,
None,
vec![],
)
.unwrap();
assert_matches!(
Expand All @@ -2090,6 +2094,10 @@ mod tests {
ufvk.transparent().cloned(),
ufvk.sapling().cloned(),
None,
vec![],
None,
None,
vec![],
)
.unwrap();
assert_matches!(
Expand Down
5 changes: 5 additions & 0 deletions zcash_keys/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ and this library adheres to Rust's notion of
- `zcash_keys::keys::UnifiedFullViewingKey::new`
- `zcash_keys::keys::UnifiedFullViewingKey::from_orchard_fvk`
- `zcash_keys::keys::UnifiedFullViewingKey::from_sapling_extended_full_viewing_key`
- `zcash_keys::keys::UnifiedFullViewingKey::new` has been modified to allow
construction that includes unknown data as well as metadata fields.
- `zcash_keys::keys::UnifiedIncomingViewingKey::new` now returns a
`Result<UnifiedIncomingViewingKey, UnifiedKeyError>` instead of a
potentially invalid value.

### Removed
- `zcash_keys::address::UnifiedAddress::unknown` (use `unknown_data` instead.)
Expand Down
28 changes: 17 additions & 11 deletions zcash_keys/src/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,10 @@ impl UnifiedFullViewingKey {
>,
#[cfg(feature = "sapling")] sapling: Option<sapling::DiversifiableFullViewingKey>,
#[cfg(feature = "orchard")] orchard: Option<orchard::keys::FullViewingKey>,
// TODO: Implement construction of UFVKs with metadata items.
unknown_data: Vec<(u32, Vec<u8>)>,
expiry_height: Option<BlockHeight>,
expiry_time: Option<u64>,
unknown_metadata: Vec<(u32, Vec<u8>)>,
) -> Result<UnifiedFullViewingKey, UnifiedKeyError> {
Self::from_checked_parts(
#[cfg(feature = "transparent-inputs")]
Expand All @@ -734,12 +737,10 @@ impl UnifiedFullViewingKey {
sapling,
#[cfg(feature = "orchard")]
orchard,
// We don't currently allow constructing new UFVKs with unknown items, but we store
// this to allow parsing such UFVKs.
vec![],
None,
None,
vec![],
unknown_data,
expiry_height,
expiry_time,
unknown_metadata,
)
}

Expand Down Expand Up @@ -1178,8 +1179,8 @@ impl UnifiedIncomingViewingKey {
expiry_height: Option<BlockHeight>,
expiry_time: Option<u64>,
unknown_metadata: Vec<(u32, Vec<u8>)>,
) -> UnifiedIncomingViewingKey {
UnifiedIncomingViewingKey {
) -> Result<UnifiedIncomingViewingKey, UnifiedKeyError> {
Self::from_checked_parts(
#[cfg(feature = "transparent-inputs")]
transparent,
#[cfg(feature = "sapling")]
Expand All @@ -1190,7 +1191,7 @@ impl UnifiedIncomingViewingKey {
expiry_height,
expiry_time,
unknown_metadata,
}
)
}

fn from_checked_parts(
Expand Down Expand Up @@ -1761,6 +1762,10 @@ mod tests {
sapling,
#[cfg(feature = "orchard")]
orchard,
vec![],
None,
None,
vec![],
);

let ufvk = ufvk.expect("Orchard or Sapling fvk is present.");
Expand Down Expand Up @@ -1954,7 +1959,8 @@ mod tests {
None,
None,
vec![],
);
)
.unwrap();

let encoded = uivk.render().encode(&NetworkType::Main);

Expand Down

0 comments on commit 2f37293

Please sign in to comment.