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
|
- 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 bufBuffer 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 bufBuffer 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 privkeyPrivateKey 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 oddBoolean If the point is above or below the x axis
xPoint 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 jsonString 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 pointPoint A Point instance
compressedboolean <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 privkeyPrivateKey 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 strString A DER hex string
encodingString <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 oddBoolean If the point is above or below the x axis
xPoint 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 dataString The encoded data in various formats
compressedString <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 dataString The encoded data in various formats
compressedString <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