Trait SparkSignerDerivationPath

Source
pub trait SparkSignerDerivationPath {
    // Required methods
    fn get_deposit_signing_key(
        &self,
        network: Network,
    ) -> Result<PublicKey, SparkSdkError>;
    fn derive_spark_key(
        leaf_id: Option<String>,
        account: u32,
        seed_bytes: &[u8],
        key_type: SparkKeyType,
        network: Network,
    ) -> Result<SecretKey, SparkSdkError>;
    fn get_identity_derivation_path(
        account_index: u32,
    ) -> Result<SparkDerivationPath, SparkSdkError>;
}
Expand description

Trait for key derivation operations in the Spark wallet.

This trait defines the methods required to derive keys according to the Spark-specific derivation path scheme. Implementors must ensure they follow the exact derivation path structure to maintain compatibility with the Spark ecosystem.

The Spark derivation scheme follows:

  • m/8797555’/account’/key_type’ for main keys
  • m/8797555’/account’/1’/hash(leaf_id)’ for leaf-specific keys

Where:

  • 8797555’ is the purpose value (derived from “spark”)
  • account’ is the account index (starting from 0)
  • key_type’ is the key type (0’ for identity, 1’ for base signing, 2’ for temporary)
  • hash(leaf_id)’ is a hardened index derived from the leaf ID

Required Methods§

Source

fn get_deposit_signing_key( &self, network: Network, ) -> Result<PublicKey, SparkSdkError>

Derives the deposit signing key for the user.

In Spark, users always have a single deposit key derived deterministically from their seed. This method returns the public key corresponding to the derived deposit signing key.

The deposit signing key uses the TemporarySigning key type (path index 2’) in the derivation path.

§Arguments
  • network - The Bitcoin network to use for the key derivation
§Returns

The public key for deposit operations or an error if derivation fails

Source

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

Derives a Spark key for the specified key type, account, and optionally leaf ID.

This is a core method for the Spark derivation path system. It handles the derivation of all types of keys used in the Spark wallet, including identity keys, base signing keys, temporary signing keys, and leaf-specific keys.

§Arguments
  • leaf_id - Optional leaf ID for leaf-specific keys. If provided, the key will be derived using the leaf-specific path: m/8797555’/account’/1’/hash(leaf_id)’
  • account - Account index to use in the derivation path
  • seed_bytes - The seed bytes to derive the key from
  • key_type - The type of key to derive (Identity, BaseSigning, or TemporarySigning)
  • network - The Bitcoin network to use for the key derivation
§Returns

The derived secret key or an error if derivation fails

Source

fn get_identity_derivation_path( account_index: u32, ) -> Result<SparkDerivationPath, SparkSdkError>

Returns the derivation path for the identity key.

The identity key has the path: m/8797555’/account’/0’ This method constructs and returns this path for the specified account.

§Arguments
  • account_index - The account index to use in the derivation path
§Returns

A SparkDerivationPath containing the identity key path components or an error if path construction fails

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§