Class: HDPublicKey

HDPublicKey

new HDPublicKey(arg)

The representation of an hierarchically derived public key.

See https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki

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

Methods

<static> getSerializedError(data, network) → {errors|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 | 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) → {HDPublicKey}

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
publicKey buffer.Buffer
checksum buffer.Buffer
xpubkey string <optional>

if set, don't recalculate the base58 representation

Source:
Returns:

this

Type
HDPublicKey

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".

Note that hardened keys can't be derived from a public extended key.

If the first argument is a number, the child with that index 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 HDPublicKey('xpub...');
var child_0_1_2 = parent.derive(0).derive(1).derive(2);
var copy_of_child_0_1_2 = parent.derive("m/0/1/2");
assert(child_0_1_2.xprivkey === copy_of_child_0_1_2);

inspect()

Returns the console representation of this extended public key.

Source:
Returns:

string

toJSON() → {string}

Serializes this object into a JSON string

Source:
Returns:
Type
string

toObject()

Returns a plain javascript object with information to reconstruct a key.

Fields are:

  • network: 'livenet' or 'testnet'
  • depth: a number from 0 to 255, the depth to the master extended key
  • fingerPrint: a number of 32 bits taken from the hash of the public key
  • fingerPrint: a number of 32 bits taken from the hash of this key's
  • parent's public key
  • childIndex: index with which this key was derived
  • chainCode: string in hexa encoding used for derivation
  • publicKey: string, hexa encoded, in compressed key format
  • checksum: BufferUtil.integerFromBuffer(this._buffers.checksum),
  • xpubkey: the string with the base58 representation of this extended key
  • checksum: the base58 checksum of xpubkey

Source:

toString() → {string}

Returns the base58 checked representation of the public key

Source:
Returns:

a string starting with "xpub..." in livenet

Type
string