Skip to content

@aldea/sdk / Exports / HDPrivKey

Class: HDPrivKey

Hierarchical deterministic private key

Implements BIP32-ed25519 with hashing primitives swapped out for BLAKE3.

To use with BIP39, we recommend using @scure/bip39.

ts
import { generateMnemonic, mnemonicToSeedSync } from '@scure/bip39'
import { wordlist } from '@scure/bip39/wordlists/english'
import { HDPrivKey } from '@aldea/core'

const mnemonic = generateMnemonic(wordlist)
const seed = mnemonicToSeedSync(mnemonic)
const rootKey = HDPrivKey.fromSeed(seed)
const childKey = rootKey.derive('m/1/2/3')

Table of contents

Constructors

Properties

Methods

Constructors

constructor

new HDPrivKey(k, chainCode): HDPrivKey

Parameters

NameType
kUint8Array
chainCodeUint8Array

Returns

HDPrivKey

Defined in

packages/core/dist/hd-privkey.d.ts:24

Properties

chainCode

Readonly chainCode: Uint8Array

Defined in

packages/core/dist/hd-privkey.d.ts:23


k

Private k: any

Defined in

packages/core/dist/hd-privkey.d.ts:22


pubkeyBytes

Private pubkeyBytes: any

Defined in

packages/core/dist/hd-privkey.d.ts:89

Methods

derive

derive(path): HDPrivKey | HDPubKey

Derives a new HD key from the given derivation path. Returns either a HDPrivKey or HDPubKey.

The derivation path must of the format described in BIP-32. All of the following examples are valid derivation paths:

text
m/1/2/3 - derives HDPrivkey
M/1/2/3 - derives HDPubkey
m/1'/200 - derives hardened HDPrivkey
m/1h/200 - equivalent
m/1H/200 - equivalent

Parameters

NameType
pathstring

Returns

HDPrivKey | HDPubKey

Defined in

packages/core/dist/hd-privkey.d.ts:62


deriveChild

deriveChild(idx): HDPrivKey

Derives new HDPrivKey from the given index integer.

Parameters

NameType
idxnumber

Returns

HDPrivKey

Defined in

packages/core/dist/hd-privkey.d.ts:66


toBytes

toBytes(): Uint8Array

Returns the HDPrivKey as bytes.

HD Private Keys are 96 bytes.

Returns

Uint8Array

Defined in

packages/core/dist/hd-privkey.d.ts:72


toHDPubKey

toHDPubKey(): HDPubKey

Returns the HDPrivKey's corresponding HDPubKey.

Returns

HDPubKey

Defined in

packages/core/dist/hd-privkey.d.ts:84


toHex

toHex(): string

Returns the HDPrivKey as hex-encoded string.

Returns

string

Defined in

packages/core/dist/hd-privkey.d.ts:76


toPubKey

toPubKey(): PubKey

Returns the HDPrivKey's corresponding normal PubKey.

Returns

PubKey

Defined in

packages/core/dist/hd-privkey.d.ts:88


toString

toString(): string

Returns the HDPrivKey as bech32m-encoded string.

Returns

string

Defined in

packages/core/dist/hd-privkey.d.ts:80


fromBytes

fromBytes(bytes): HDPrivKey

Returns a HDPrivKey from the given bytes.

HD Private Keys are 96 bytes.

Parameters

NameType
bytesUint8Array

Returns

HDPrivKey

Defined in

packages/core/dist/hd-privkey.d.ts:30


fromHex

fromHex(str): HDPrivKey

Returns a HDPrivKey from the given hex-encoded string.

Parameters

NameType
strstring

Returns

HDPrivKey

Defined in

packages/core/dist/hd-privkey.d.ts:34


fromRandom

fromRandom(): HDPrivKey

Generates and returns a new random HDPrivKey.

Returns

HDPrivKey

Defined in

packages/core/dist/hd-privkey.d.ts:42


fromSeed

fromSeed(seed): HDPrivKey

Generates and returns an HDPrivKey from the given seed bytes.

Parameters

NameType
seedUint8Array

Returns

HDPrivKey

Defined in

packages/core/dist/hd-privkey.d.ts:46


fromString

fromString(str): HDPrivKey

Returns a HDPrivKey from the given bech32m-encoded string.

Parameters

NameType
strstring

Returns

HDPrivKey

Defined in

packages/core/dist/hd-privkey.d.ts:38