Skip to content

KeyDerivationService

Source

BIP-32/BIP-44 hierarchical deterministic key derivation.

Interface Bip44PathOptions:

FieldTypeRequiredDescription
coinTypenumberYesBIP-44 coin type.
accountnumberNoAccount index. Defaults to 0.
changenumberNo0 = external chain, 1 = internal. Defaults to 0.
indexnumberNoAddress index. Defaults to 0.

buildBip44Path

ts
buildBip44Path(options: Bip44PathOptions): string

Constructs a BIP-44 derivation path string from the provided options.

Parameters:

NameTypeRequiredDescription
optionsBip44PathOptionsYesPath components (coinType, account, change, index).

Returns: string — derivation path in the format m/44'/coinType'/account'/change/index.

derivePrivateKey

ts
derivePrivateKey(masterNode: BIP32Interface, path: string): Uint8Array

Derives a private key from a BIP-32 master node along the specified path.

Parameters:

NameTypeRequiredDescription
masterNodeBIP32InterfaceYesMaster BIP-32 node.
pathstringYesBIP-32 derivation path.

Returns: Uint8Array — private key (32 bytes).

Throws: Error("No private key at derived node") — if the derived node does not contain a private key.

mnemonicToSeed

ts
mnemonicToSeed(mnemonicWords: string[] | string, passphrase?: string): Promise<Uint8Array>

Converts a mnemonic to a 64-byte BIP-39 seed using PBKDF2-HMAC-SHA512.

Parameters:

NameTypeRequiredDescription
mnemonicWordsstring[] | stringYesMnemonic as array or space-separated string.
passphrasestringNoOptional BIP-39 passphrase. Defaults to "".

Returns: Promise<Uint8Array> — seed bytes (64 bytes).

seedToMasterNode

ts
seedToMasterNode(seed: Uint8Array): BIP32Interface

Creates a BIP-32 master node from a seed using tiny-secp256k1 and the bip32 factory.

Parameters:

NameTypeRequiredDescription
seedUint8ArrayYesSeed bytes (typically 64 bytes from mnemonicToSeed).

Returns: BIP32Interface — master node for key derivation.

deriveKeyFromMnemonic

ts
deriveKeyFromMnemonic(mnemonicWords: string[], options?: Bip44PathOptions): Promise<Uint8Array>

Full derivation pipeline: mnemonic → seed → master node → private key.

Parameters:

NameTypeRequiredDescription
mnemonicWordsstring[]YesMnemonic word array.
optionsBip44PathOptionsNoBIP-44 path options. Uses defaults if omitted.

Returns: Promise<Uint8Array> — derived private key (32 bytes).

deriveNextKeyFromMnemonic

ts
deriveNextKeyFromMnemonic(
  mnemonicWords: string[],
  currentIndex: number,
  options?: Omit<Bip44PathOptions, 'index'>
): Promise<Uint8Array>

Derives the key at currentIndex + 1 from the mnemonic.

Parameters:

NameTypeRequiredDescription
mnemonicWordsstring[]YesMnemonic word array.
currentIndexnumberYesCurrent derivation index. The next key is derived at currentIndex + 1.
optionsOmit<Bip44PathOptions, 'index'>NoBIP-44 path options (without index).

Returns: Promise<Uint8Array> — private key at the next index.

ASI:Chain DevNet - Development Network