Class: PublicKey

hd.PublicKey(optionsopt)

HDPublicKey

Constructor

new PublicKey(optionsopt)

Create an HD public key.

Parameters:
Name Type Attributes Description
options HDPublicKeyOptions <optional>
Properties:
Name Type Description
depth Number
parentFingerPrint Number
childIndex Number
chainCode Buffer
publicKey Buffer
Source:

Methods

(static) fromBase58(xkey, networkopt, nullable) → {HDPublicKey}

Instantiate an HD public key from a base58 string.

Parameters:
Name Type Attributes Description
xkey Base58String
network Network | NetworkType <optional>
<nullable>
Source:
Returns:
Type
HDPublicKey

(static) isBase58(data, networknullable) → {Boolean}

Test whether an object is in the form of a base58 xpubkey.

Parameters:
Name Type Attributes Description
data String
network Network | NetworkType <nullable>
Source:
Returns:
Type
Boolean

(static) isHDPublicKey(obj) → {Boolean}

Test whether an object is a HDPublicKey.

Parameters:
Name Type Description
obj Object
Source:
Returns:
Type
Boolean

(static) isRaw(data, networkopt, nullable) → {Boolean}

Test whether a buffer has a valid network prefix.

Parameters:
Name Type Attributes Description
data Buffer
network Network | NetworkType <optional>
<nullable>
Source:
Returns:
Type
Boolean

(static) isValidPath(path) → {Boolean}

Test whether a string is a valid path.

Parameters:
Name Type Description
path String
Source:
Returns:
Type
Boolean

compare(key) → {Number}

Compare a key against an object.

Parameters:
Name Type Description
key HDPublicKey
Source:
Returns:
Type
Number

derive(index, hardenedopt, nullable) → {HDPublicKey}

Derive a child key.

Parameters:
Name Type Attributes Description
index Number

Derivation index.

hardened Boolean <optional>
<nullable>

Whether the derivation should be hardened (throws if true).

Source:
Throws:

on hardened

Returns:
Type
HDPublicKey

deriveAccount(purpose, type, account) → {HDPublicKey}

Derive a BIP44 account key (does not derive, only ensures account key).

Parameters:
Name Type Description
purpose Number
type Number
account Number
Source:
Throws:

Error if key is not already an account key.

Returns:
Type
HDPublicKey

derivePath(path) → {HDPublicKey}

Derive a key from a derivation path.

Parameters:
Name Type Description
path String
Source:
Throws:
  • Error if path is not a valid path.

  • Error if hardened.

Returns:
Type
HDPublicKey

destroy()

Destroy the key (zeroes chain code and pubkey).

Source:

equals(obj) → {Boolean}

Compare a key against an object.

Parameters:
Name Type Description
obj HDPublicKey
Source:
Returns:
Type
Boolean

fromBase58(xkey, networkopt, nullable)

Inject properties from a base58 key.

Parameters:
Name Type Attributes Description
xkey Base58String
network Network | NetworkType <optional>
<nullable>
Source:

fromJSON(json, networkopt, nullable)

Inject properties from json object.

Parameters:
Name Type Attributes Description
json Object
network Network | NetworkType <optional>
<nullable>
Source:

fromOptions(options)

Inject properties from options object.

Parameters:
Name Type Description
options HDPublicKeyOptions
Source:

(private) getID(index) → {String}

Unique HD key ID.

Parameters:
Name Type Description
index Number
Source:
Returns:
Type
String

getJSON(networkopt, nullable) → {Object}

Convert key to a more json-friendly object.

Parameters:
Name Type Attributes Description
network Network | NetworkType <optional>
<nullable>
Source:
Returns:
Type
Object

getSize() → {Number}

Calculate serialization size.

Source:
Returns:
Type
Number

isAccount(accountnullable) → {Boolean}

Test whether the key is (most likely) a BIP44 account key.

Parameters:
Name Type Attributes Description
account Number <nullable>
Source:
Returns:
Type
Boolean

isMaster() → {Boolean}

Test whether the key is a master key.

Source:
Returns:
Type
Boolean

read(br, networknullable)

Inject properties from serialized data.

Parameters:
Name Type Attributes Description
br bio.BufferReader
network Network | NetworkType <nullable>
Source:

toBase58(networknullable) → {Base58String}

Serialize key data to base58 extended key.

Parameters:
Name Type Attributes Description
network Network | NetworkType <nullable>
Source:
Returns:
Type
Base58String

toPublic() → {HDPublicKey}

Get HD public key (self).

Source:
Returns:
Type
HDPublicKey

write(bw, networkopt, nullable) → {BufioWriter}

Write the key to a buffer writer.

Parameters:
Name Type Attributes Description
bw BufioWriter
network Network | NetworkType <optional>
<nullable>
Source:
Returns:
Type
BufioWriter

xprivkey(networkopt, nullable) → {null}

Get cached base58 xprivkey (always null here).

Parameters:
Name Type Attributes Description
network NetworkType | Network <optional>
<nullable>
Source:
Returns:
Type
null

xpubkey() → {Base58String}

Get cached base58 xpubkey.

Source:
Returns:
Type
Base58String