Skip to main content

Core Concepts

The derivation path is our recommendation to the client wallets so that user could easily migrate between different wallet apps. But the scheme is just a recommendation. You could implement a different scheme but then it will lose the ability to migrate to/from other apps.
This hierarchical deterministic (HD) key derivation scheme is purpose-built for the Spark Wallet and follows the general principles of BIP43. It uses a custom purpose field (8797555’), derived from the last 3 bytes of the SHA256 hash of the string “spark” (0x863d73), to define a new domain of application-specific key derivations.

Scheme

  • m/8797555’/accountNumber’/0’ - Identity Key
  • m/8797555’/accountNumber’/1’ - Base signing key - As leaf key
  • m/8797555’/accountNumber’/2’ - Temporary signing key - As deposit key
  • m/8797555’/accountNumber’/3’ - Static deposit key

Account

The accountNumber should start from 0 and use hardened derivation.

Leaf key derivation

To accept a transfer, there will always be a leaf ID provided by the spark entity. The derivation path for a given leaf id is hash = sha256(leaf_id) From base signing key, the leaf key should be m/8797555’/accountNumber’/1’/hash(leaf_id)%0x80000000 + 0x80000000 (hash(leaf_id)%0x80000000’)

Deposit address key derivation

For user deposit, there’s no leaf id because the leaf is generated after the tree is created. So user deposit should always use m/8797555’/accountNumber’/2’ And once a deposit tree is created, the user should perform a self transfer to the leaf key.

Usage in the Spark SDK

initialize

Initializes your spark wallet
If no account number is provided, our JS-SDK defaults accountNumber to 1 to support backwards compatability for mainnet wallets created with earlier versions of the SDK.

Parameters

  • mnemonicOrSeed: optional mnemonic or seed
  • accountNumber: optional account number
  • options: wallet configuration parameters

Usage

// import the SparkWallet spark-sdk
import { SparkWallet } from "@buildonspark/spark-sdk";

// Initialize a new wallet instance
const { wallet, mnemonic } = await SparkWallet.initialize({
  mnemonicOrSeed: "optional-mnemonic-or-seed",
  accountNumber: "optional-account-number",
  options: {
    network: "REGTEST",
  },
});
console.log("Wallet initialized successfully:", mnemonic);
I