Function derive_spark_key

Source
pub fn derive_spark_key(
    leaf_id: Option<String>,
    account: u32,
    seed_bytes: &[u8],
    key_type: SparkKeyType,
    network: Network,
) -> Result<SecretKey, SparkCryptographyError>
Expand description

Derives a Spark key from a seed and derivation path.

This function constructs a complete derivation path for a Spark key, including the purpose index, account index, key type index, and optional leaf index. It then uses the seed to derive the key using the secp256k1 library.

§Arguments

  • leaf_id: The leaf ID to derive the key for.
  • account: The account index to derive the key for.
  • seed_bytes: The seed bytes to derive the key from.
  • key_type: The key type to derive the key for.
  • network: The network to derive the key for.

§Returns

A SecretKey representing the derived key, or an error if the derivation fails.

§Errors

  • InvalidSeed: If the seed is invalid.
  • InvalidDerivationPath: If the derivation path is invalid.
  • InvalidLeaf: If the leaf index is invalid.
  • InvalidKeyType: If the key type is invalid.
  • InvalidNetwork: If the network is invalid.

§Example

use spark_cryptography::derivation_path::{derive_spark_key, SparkKeyType};
use bitcoin::Network;

let seed_bytes = "0x0000000000000000000000000000000000000000000000000000000000000000".as_bytes();
let key_type = SparkKeyType::Identity;
let network = Network::Bitcoin;

let key = derive_spark_key(None, 0, seed_bytes, key_type, network).unwrap();
let key_bytes = key.secret_bytes();