Skip to content

Commit

Permalink
Add convenience function registered::SecretKey::derive_child.
Browse files Browse the repository at this point in the history
Signed-off-by: Daira-Emma Hopwood <daira@jacaranda.org>
  • Loading branch information
daira committed Feb 20, 2025
1 parent bd769d9 commit ebf809c
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/registered.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,14 @@ impl SecretKey {
})
}

/// Derives a child key from a parent key at a given index and empty tag.
///
/// This is a convenience function equivalent to
/// `self.derive_child_with_tag(index, &[])`.
pub fn derive_child(&self, index: ChildIndex) -> Self {
self.derive_child_with_tag(index, &[])
}

/// Derives a child key from a parent key at a given index and (possibly empty) tag.
///
/// Defined in [ZIP 32: Registered child key derivation][regckd].
Expand Down Expand Up @@ -167,7 +175,7 @@ pub fn cryptovalue_from_subpath(
assert!(!subpath.is_empty());

let mut xsk = SecretKey::master(context_string, seed)
.derive_child_with_tag(ChildIndex::hardened(u32::from(zip_number)), &[]);
.derive_child(ChildIndex::hardened(u32::from(zip_number)));

for (i, tag) in subpath.iter().take(subpath.len() - 1) {
xsk = xsk.derive_child_with_tag(*i, tag);
Expand Down

0 comments on commit ebf809c

Please sign in to comment.