new PrivateKey(data, network) → {PrivateKey}
Instantiate a PrivateKey from a BN, Buffer and WIF.
Parameters:
| Name | Type | Argument | Description |
|---|---|---|---|
data |
String | The encoded data in various formats |
|
network |
String |
<optional> |
Either "livenet" or "testnet" |
- Source:
Returns:
A new valid instance of an PrivateKey
- Type
- PrivateKey
Example
// generate a new random key var key = PrivateKey(); // get the associated address var address = key.toAddress(); // encode into wallet export format var exported = key.toWIF(); // instantiate from the exported (and saved) private key var imported = PrivateKey.fromWIF(exported);
Members
-
<static> fromString
-
Instantiate a PrivateKey from a WIF string
- Source:
-
toString
-
Will output the PrivateKey to a WIF string
- Source:
Methods
-
<private, static> _getRandomBN() → {BN}
-
Internal function to get a random BN
- Source:
Returns:
A new randomly generated BN
- Type
- BN
-
<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> _transformBuffer(buf, network) → {Object}
-
Internal function to transform a WIF Buffer into a private key
Parameters:
Name Type Argument Description bufBuffer An WIF string
networkString <optional>
Either "livenet" or "testnet"
- Source:
Returns:
An object with keys: bn, network and compressed
- Type
- Object
-
<private, static> _transformJSON(json) → {Object}
-
Internal function to transform a JSON string on plain object into a private key
Parameters:
Name Type Description jsonString A JSON string or plain object
- Source:
Returns:
An object with keys: bn, network and compressed
- Type
- Object
-
<private, static> _transformWIF(buf) → {Object}
-
Internal function to transform a WIF string into a private key
Parameters:
Name Type Description bufString An WIF string
- Source:
Returns:
An object with keys: bn, network and compressed
- Type
- Object
-
<static> fromJSON(json) → {PrivateKey}
-
Instantiate a PrivateKey from a JSON string
Parameters:
Name Type Description jsonString The JSON encoded private key string
- Source:
Returns:
A new valid instance of PrivateKey
- Type
- PrivateKey
-
<static> fromRandom(network) → {PrivateKey}
-
Instantiate a PrivateKey from random bytes
Parameters:
Name Type Argument Description networkString <optional>
Either "livenet" or "testnet"
- Source:
Returns:
A new valid instance of PrivateKey
- Type
- PrivateKey
-
<static> getValidationError(data, network) → {null|Error}
-
Check if there would be any errors when initializing a PrivateKey
Parameters:
Name Type Argument Description dataString The encoded data in various formats
networkString <optional>
Either "livenet" or "testnet"
- Source:
Returns:
An error if exists
- Type
- null | Error
-
<static> isValid(data, network) → {Boolean}
-
Check if the parameters are valid
Parameters:
Name Type Argument Description dataString The encoded data in various formats
networkString <optional>
Either "livenet" or "testnet"
- Source:
Returns:
If the private key is would be valid
- Type
- Boolean
-
inspect() → {String}
-
Will return a string formatted for the console
- Source:
Returns:
Private key
- Type
- String
-
toAddress() → {Address}
-
Will return an address for the private key
- Source:
Returns:
An address generated from the private key
- Type
- Address
-
toBigNumber() → {BN}
-
Will return the private key as a BN instance
- Source:
Returns:
A BN instance of the private key
- Type
- BN
-
toBuffer() → {Buffer}
-
Will return the private key as a BN buffer
- Source:
Returns:
A buffer of the private key
- Type
- Buffer
-
toObject() → {Object}
-
- Source:
Returns:
A plain object representation
- Type
- Object
-
toPublicKey() → {PublicKey}
-
Will return the corresponding public key
- Source:
Returns:
A public key generated from the private key
- Type
- PublicKey