Function get_leaf_index

Source
pub fn get_leaf_index(
    leaf_id: &str,
) -> Result<ChildNumber, SparkCryptographyError>
Expand description

Calculates the derivation path component for a leaf key based on a leaf ID.

This function hashes the leaf ID using SHA-256 and processes the hash to derive a hardened index for use in leaf key derivation paths.

The index is calculated by:

  1. Computing SHA-256 hash of the leaf ID
  2. Interpreting the first 4 bytes of the hash as u32 value
  3. Modulo the u32 value with 0x80000000 to ensure it fits within valid index range
  4. Converting to a hardened ChildNumber

§Arguments

  • leaf_id: The leaf ID in &str format to derive the index for.

§Returns

A ChildNumber representing the derived index, or an error if the derivation fails.