Class: PublicKey

PublicKey

new PublicKey(data, extra) → {PublicKey}

Instantiate a PublicKey from a 'PrivateKey', 'Point', 'string', 'Buffer'.

Parameters:
Name Type Description
data String

The encoded data in various formats

extra Object

additional options

Properties
Name Type Argument Description
network Network <optional>

Which network should the address for this public key be for

compressed String <optional>

If the public key is compressed

Source:
Returns:

A new valid instance of an PublicKey

Type
PublicKey
Example
// instantiate from a private key
var key = PublicKey(privateKey, true);

// export to as a DER hex encoded string
var exported = key.toString();

// import the public key
var imported = PublicKey.fromString(exported);

Members

<static> fromDER

Instantiate a PublicKey from a Buffer

Source:

toBuffer

Will output the PublicKey to a DER Buffer

Source:

Methods

<private, static> _isBuffer(param) → {boolean}

Internal function to detect if an object is a Buffer

Parameters:
Name Type Description
param *

object to test

Source:
Returns:
Type
boolean

<private, static> _isJSON(param) → {boolean}

Internal function to detect if a param is a JSON string or plain object

Parameters:
Name Type Description
param *

value to test

Source:
Returns:
Type
boolean

<private, static> _isPrivateKey(param) → {boolean}

Internal function to detect if an object is a PrivateKey

Parameters:
Name Type Description
param *

object to test

Source:
Returns:
Type
boolean

<private, static> _transformDER(buf) → {Object}

Internal function to transform DER into a public key point

Parameters:
Name Type Description
buf Buffer

An hex encoded buffer

Source:
Returns:

An object with keys: point and compressed

Type
Object

<private, static> _transformJSON(buf) → {Object}

Internal function to transform a JSON into a public key point

Parameters:
Name Type Description
buf Buffer

a JSON string or plain object

Source:
Returns:

An object with keys: point and compressed

Type
Object

<private, static> _transformPrivateKey(privkey) → {Object}

Internal function to transform a private key into a public key point

Parameters:
Name Type Description
privkey PrivateKey

An instance of PrivateKey

Source:
Returns:

An object with keys: point and compressed

Type
Object

<private, static> _transformX(odd, x) → {Object}

Internal function to transform X into a public key point

Parameters:
Name Type Description
odd Boolean

If the point is above or below the x axis

x Point

The x point

Source:
Returns:

An object with keys: point and compressed

Type
Object

<static> fromJSON(json) → {PublicKey}

Instantiate a PublicKey from JSON

Parameters:
Name Type Description
json String

A JSON string

Source:
Returns:

A new valid instance of PublicKey

Type
PublicKey

<static> fromPoint(point, compressed) → {PublicKey}

Instantiate a PublicKey from a Point

Parameters:
Name Type Argument Description
point Point

A Point instance

compressed boolean <optional>

whether to store this public key as compressed format

Source:
Returns:

A new valid instance of PublicKey

Type
PublicKey

<static> fromPrivateKey(privkey) → {PublicKey}

Instantiate a PublicKey from a PrivateKey

Parameters:
Name Type Description
privkey PrivateKey

An instance of PrivateKey

Source:
Returns:

A new valid instance of PublicKey

Type
PublicKey

<static> fromString(str, encoding) → {PublicKey}

Instantiate a PublicKey from a DER hex encoded string

Parameters:
Name Type Argument Description
str String

A DER hex string

encoding String <optional>

The type of string encoding

Source:
Returns:

A new valid instance of PublicKey

Type
PublicKey

<static> fromX(odd, x) → {PublicKey}

Instantiate a PublicKey from an X Point

Parameters:
Name Type Description
odd Boolean

If the point is above or below the x axis

x Point

The x point

Source:
Returns:

A new valid instance of PublicKey

Type
PublicKey

<static> getValidationError(data, compressed) → {null|Error}

Check if there would be any errors when initializing a PublicKey

Parameters:
Name Type Argument Description
data String

The encoded data in various formats

compressed String <optional>

If the public key is compressed

Source:
Returns:

An error if exists

Type
null | Error

<static> isValid(data, compressed) → {Boolean}

Check if the parameters are valid

Parameters:
Name Type Argument Description
data String

The encoded data in various formats

compressed String <optional>

If the public key is compressed

Source:
Returns:

If the public key would be valid

Type
Boolean

inspect() → {String}

Will return a string formatted for the console

Source:
Returns:

Public key

Type
String

toAddress() → {Address}

Will return an address for the public key

Source:
Returns:

An address generated from the public key

Type
Address

toObject() → {Object}

Source:
Returns:

A plain object of the PublicKey

Type
Object

toString() → {String}

Will output the PublicKey to a DER encoded hex string

Source:
Returns:

A DER hex encoded string

Type
String