|
|
@ -4,30 +4,18 @@ var constants = require('./constants'); |
|
|
|
var base58check = require('./base58check'); |
|
|
|
|
|
|
|
var Privkey = function(n, network, compressed) { |
|
|
|
if (typeof n !== 'undefined') |
|
|
|
this.setNumber(n); |
|
|
|
if (typeof network !== 'undefined') |
|
|
|
this.setNetwork(network); |
|
|
|
if (typeof compressed !== 'undefined') |
|
|
|
this.setCompressed(compressed); |
|
|
|
}; |
|
|
|
|
|
|
|
Privkey.prototype.setNumber = function(n) { |
|
|
|
if (!n.lt(point.getN())) |
|
|
|
throw new Error('privkey: Number must be less than N'); |
|
|
|
this.n = n; |
|
|
|
}; |
|
|
|
|
|
|
|
Privkey.prototype.setNetwork = function(network) { |
|
|
|
if (typeof constants[network] === undefined) |
|
|
|
throw new Error('privkey: Must specify the network ("mainnet" or "testnet")'); |
|
|
|
this.network = network; |
|
|
|
this.compressed = compressed; |
|
|
|
}; |
|
|
|
|
|
|
|
Privkey.prototype.setCompressed = function(compressed) { |
|
|
|
if (typeof compressed !== 'boolean') |
|
|
|
Privkey.prototype.validate = function() { |
|
|
|
if (!this.n.lt(point.getN())) |
|
|
|
throw new Error('privkey: Number must be less than N'); |
|
|
|
if (typeof constants[this.network] === undefined) |
|
|
|
throw new Error('privkey: Must specify the network ("mainnet" or "testnet")'); |
|
|
|
if (typeof this.compressed !== 'boolean') |
|
|
|
throw new Error('privkey: Must specify whether the corresponding public key is compressed or not (true or false)'); |
|
|
|
this.compressed = compressed; |
|
|
|
}; |
|
|
|
|
|
|
|
Privkey.prototype.toWIF = function() { |
|
|
|