Skip to content
Cive

Hierarchical Deterministic (HD) Account

A Hierarchical Deterministic (HD) Account is derived from a HD Key and an optional HD path.

It has the ability to sign transactions and messages with the private key derived from the HD Node.

Import

import { ,  } from "cive/accounts";

Note: cive re-exports HDKey from @scure/bip32.

Usage

To initialize a HD Account, you will need to pass a HDKey instance to hdKeyToAccount.

The HDKey instance comes with a few static methods to derive a HD Key:

  • fromMasterSeed
  • fromExtendedKey
  • fromJSON
import { ,  } from "cive";
import { ,  } from "cive/accounts";
import {  } from "cive/chains";
import {  } from "cive/utils";
 
const  = .(
  ("0x000102030405060708090a0b0c0d0e0f")
); 
// const hdKey = HDKey.fromExtendedKey(...)
// const hdKey = HDKey.fromJSON({ xpriv: ... })
 
const  = (, { : . }); 
 
const  = ({
  ,
  : ,
  : (),
});

Parameters

hdKey

  • Type: string

The BIP-39 mnemonic phrase.

const  = HDKey.fromMasterSeed(...)
 
const  = (
  , //,
  {: . }
)

options.accountIndex

  • Type: number
  • Default: 0

The account index to use in the path ("m/44'/503'/${accountIndex}'/0/0") to derive a private key.

const  = HDKey.fromMasterSeed(...)
 
const  = (
  ,
  {
    : 1, 
    : .
  }
)

options.addressIndex

  • Type: number
  • Default: 0

The address index to use in the path ("m/44'/503'/0'/0/${addressIndex}") to derive a private key.

const  = HDKey.fromMasterSeed(...)
 
const  = (
  ,
  {
    : 1,
    : 6, 
    : .
  }
)

options.changeIndex

  • Type: number
  • Default: 0

The change index to use in the path ("m/44'/503'/0'/${changeIndex}/0") to derive a private key.

const  = HDKey.fromMasterSeed(...)
 
const  = (
  ,
  {
    : 1,
    : 6,
    : 2, 
    : .
  }
)

options.path

  • Type: "m/44'/503'/${string}"

The HD path to use to derive a private key.

const  = HDKey.fromMasterSeed(...)
 
const  = (
  ,
  {
    : "m/44'/503'/5'/0/2"
  }
)