Skip to content

Commit 4fa6d3b

Browse files
authored
Merge pull request #449 from zcash/pczt-improvements
PCZT improvements
2 parents fe389a1 + aa0891d commit 4fa6d3b

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ and this project adheres to Rust's notion of
77

88
## [Unreleased]
99

10+
### Added
11+
- `orchard::pczt::Zip32Derivation::extract_account_index`
12+
1013
### Changed
1114
- Migrated to `nonempty 0.11`.
1215

src/pczt.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,35 @@ pub struct Zip32Derivation {
301301
derivation_path: Vec<ChildIndex>,
302302
}
303303

304+
impl Zip32Derivation {
305+
/// Extracts the ZIP 32 account index from this derivation path.
306+
///
307+
/// Returns `None` if the seed fingerprints don't match, or if this is a non-standard
308+
/// derivation path.
309+
pub fn extract_account_index(
310+
&self,
311+
seed_fp: &zip32::fingerprint::SeedFingerprint,
312+
expected_coin_type: zip32::ChildIndex,
313+
) -> Option<zip32::AccountId> {
314+
if self.seed_fingerprint == seed_fp.to_bytes() {
315+
match &self.derivation_path[..] {
316+
[purpose, coin_type, account_index]
317+
if purpose == &zip32::ChildIndex::hardened(32)
318+
&& coin_type == &expected_coin_type =>
319+
{
320+
Some(
321+
zip32::AccountId::try_from(account_index.index() - (1 << 31))
322+
.expect("zip32::ChildIndex only supports hardened"),
323+
)
324+
}
325+
_ => None,
326+
}
327+
} else {
328+
None
329+
}
330+
}
331+
}
332+
304333
#[cfg(test)]
305334
mod tests {
306335
use bridgetree::BridgeTree;

src/pczt/verify.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,10 @@ impl super::Spend {
5656
/// - `rho`
5757
/// - `rseed`
5858
///
59+
/// In addition, at least one of the `fvk` field or `expected_fvk` must be provided.
60+
///
5961
/// The provided [`FullViewingKey`] is ignored if the spent note is a dummy note.
60-
/// Otherwise, it will be checked against the `fvk` field (if set).
62+
/// Otherwise, it will be checked against the `fvk` field (if both are set).
6163
pub fn verify_nullifier(
6264
&self,
6365
expected_fvk: Option<&FullViewingKey>,

0 commit comments

Comments
 (0)