Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Daira-Emma Hopwood <[email protected]>
  • Loading branch information
nuttycom and daira committed Dec 9, 2024
1 parent bf69a2a commit 678b941
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
7 changes: 4 additions & 3 deletions zcash_client_sqlite/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,14 +287,15 @@ pub(crate) fn seed_matches_derived_account<P: consensus::Parameters>(
)
})? == seed_fingerprint;

// Keys are not comparable with `Eq`, but addresses are, so we derive what should
// be equivalent addresses for each key and use those to check for key equality.
// `UnifiedIncomingViewingKey`s are not comparable with `Eq`, but Unified Address
// components are, so we derive corresponding addresses for each key and use
// those to check whether any components match.
let uivk_match = {
let usk = UnifiedSpendingKey::from_seed(params, &seed.expose_secret()[..], account_index)
.map_err(|_| SqliteClientError::KeyDerivationError(account_index))?;

let (seed_addr, _) = usk.to_unified_full_viewing_key().default_address(Some(
UnifiedAddressRequest::all().expect("At least one supported pool feature ie enabled."),
UnifiedAddressRequest::all().expect("At least one supported pool feature is enabled."),
))?;

let (uivk_addr, _) = uivk.default_address(None)?;
Expand Down
18 changes: 11 additions & 7 deletions zcash_keys/src/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -903,9 +903,10 @@ impl UnifiedFullViewingKey {
self.to_unified_incoming_viewing_key().address(j, request)
}

/// Searches the diversifier space starting at diversifier index `j` for one which will
/// produce a valid diversifier, and return the Unified Address constructed using that
/// diversifier along with the index at which the valid diversifier was found.
/// Searches the diversifier space starting at diversifier index `j` for one which will produce
/// a valid diversifier, and return the Unified Address constructed using that diversifier
/// along with the index at which the valid diversifier was found. If `request` is None, the
/// address should be derived to contain a receiver for each item in this UFVK.
///
/// Returns an `Err(AddressGenerationError)` if no valid diversifier exists or if the features
/// required to satisfy the unified address request are not properly enabled.
Expand All @@ -919,7 +920,8 @@ impl UnifiedFullViewingKey {
}

/// Find the Unified Address corresponding to the smallest valid diversifier index, along with
/// that index.
/// that index. If `request` is None, the address should be derived to contain a receiver for
/// each item in this UFVK.
///
/// Returns an `Err(AddressGenerationError)` if no valid diversifier exists or if the features
/// required to satisfy the unified address request are not properly enabled.
Expand Down Expand Up @@ -1113,8 +1115,9 @@ impl UnifiedIncomingViewingKey {
&self.orchard
}

/// Attempts to derive the Unified Address for the given diversifier index and
/// receiver types.
/// Attempts to derive the Unified Address for the given diversifier index and receiver types.
/// If `request` is None, the address should be derived to contain a receiver for each item in
/// this UFVK.
///
/// Returns `None` if the specified index does not produce a valid diversifier.
pub fn address(
Expand Down Expand Up @@ -1245,7 +1248,8 @@ impl UnifiedIncomingViewingKey {
}

/// Find the Unified Address corresponding to the smallest valid diversifier index, along with
/// that index.
/// that index. If `request` is None, the address should be derived to contain a receiver for
/// each item in this UFVK.
///
/// Returns an `Err(AddressGenerationError)` if no valid diversifier exists or if the features
/// required to satisfy the unified address request are not properly enabled.
Expand Down

0 comments on commit 678b941

Please sign in to comment.