derivePrivateKeyByType
Derives a private key for a specific account using either the Wallet (STX) or Data derivation path, based on the given DerivationType.
Usage
import { derivePrivateKeyByType, DerivationType } from '@stacks/wallet-sdk';
import { HDKey } from '@scure/bip32';
import { mnemonicToSeed } from '@scure/bip39';
const seed = await mnemonicToSeed('your 24-word seed phrase ...');
const rootNode = HDKey.fromMasterSeed(seed);
// Derive using the STX/Wallet path
const stxKey = derivePrivateKeyByType({
rootNode,
index: 0,
derivationType: DerivationType.Wallet,
});
// Derive using the Data path
const dataKey = derivePrivateKeyByType({
rootNode,
index: 0,
derivationType: DerivationType.Data,
});Notes
When
derivationTypeisDerivationType.Wallet, callsderiveStxPrivateKeyinternally.When
derivationTypeisDerivationType.Data, callsderiveDataPrivateKeyinternally.
Signature
Returns
string
A compressed hex-encoded private key string.
Parameters
opts (required)
Property
Type
Description
rootNode
HDKey
The root HD key derived from the wallet's seed phrase.
index
number
The account index (0-based).
derivationType
DerivationType
Which derivation path to use (Wallet or Data).
Last updated
Was this helpful?