Class: HDPrivateKey

HDPrivateKey

new HDPrivateKey(arg)

Represents an instance of an hierarchically derived private key.

More info on https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki

Parameters:
Name Type Description
arg string | Buffer | Object
Source:

Methods

<static> fromSeed(hexa, network)

Generate a private key from a seed, as described in BIP32

Parameters:
Name Type Description
hexa string | Buffer
network *
Source:
Returns:

HDPrivateKey

<static> getSerializedError(data, network) → {errors.InvalidArgument|null}

Checks what's the error that causes the validation of a serialized private key in base58 with checksum to fail.

Parameters:
Name Type Description
data string | Buffer

the serialized private key

network string | Network

optional, if present, checks that the network provided matches the network serialized.

Source:
Returns:
Type
errors.InvalidArgument | null

<static> isValidSerialized(data, network) → {boolean}

Verifies that a given serialized private key in base58 with checksum format is valid.

Parameters:
Name Type Description
data string | Buffer

the serialized private key

network string | Network

optional, if present, checks that the network provided matches the network serialized.

Source:
Returns:
Type
boolean

_buildFromBuffers(arg) → {HDPrivateKey}

Receives a object with buffers in all the properties and populates the internal structure

Parameters:
Name Type Description
arg Object
Properties
Name Type Argument Description
version buffer.Buffer
depth buffer.Buffer
parentFingerPrint buffer.Buffer
childIndex buffer.Buffer
chainCode buffer.Buffer
privateKey buffer.Buffer
checksum buffer.Buffer
xprivkey string <optional>

if set, don't recalculate the base58 representation

Source:
Returns:

this

Type
HDPrivateKey

derive(arg, hardened)

Get a derivated child based on a string or number.

If the first argument is a string, it's parsed as the full path of derivation. Valid values for this argument include "m" (which returns the same private key), "m/0/1/40/2'/1000", where the ' quote means a hardened derivation.

If the first argument is a number, the child with that index will be derived. If the second argument is truthy, the hardened version will be derived. See the example usage for clarification.

Parameters:
Name Type Argument Description
arg string | number
hardened boolean <nullable>
Source:
Example
var parent = new HDPrivateKey('xprv...');
var child_0_1_2h = parent.derive(0).derive(1).derive(2, true);
var copy_of_child_0_1_2h = parent.derive("m/0/1/2'");
assert(child_0_1_2h.xprivkey === copy_of_child_0_1_2h);

inspect()

Returns the console representation of this extended private key.

Source:
Returns:

string

toObject() → {Object}

Returns a plain object with a representation of this private key.

Fields include:

  • network: either 'livenet' or 'testnet'

  • depth: a number ranging from 0 to 255

  • fingerPrint: a number ranging from 0 to 2^32-1, taken from the hash of the

  • associated public key

  • parentFingerPrint: a number ranging from 0 to 2^32-1, taken from the hash

  • of this parent's associated public key or zero.

  • childIndex: the index from which this child was derived (or zero)

  • chainCode: an hexa string representing a number used in the derivation

  • privateKey: the private key associated, in hexa representation

  • xprivkey: the representation of this extended private key in checksum

  • base58 format

  • checksum: the base58 checksum of xprivkey

Source:
Returns:
Type
Object

toString()

Returns the string representation of this private key (a string starting with "xprv..."

Source:
Returns:

string