refactor privkey
This commit is contained in:
parent
304210c132
commit
cd6c2b2410
|
@ -4,30 +4,18 @@ var constants = require('./constants');
|
||||||
var base58check = require('./base58check');
|
var base58check = require('./base58check');
|
||||||
|
|
||||||
var Privkey = function(n, network, compressed) {
|
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;
|
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.network = network;
|
||||||
|
this.compressed = compressed;
|
||||||
};
|
};
|
||||||
|
|
||||||
Privkey.prototype.setCompressed = function(compressed) {
|
Privkey.prototype.validate = function() {
|
||||||
if (typeof compressed !== 'boolean')
|
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)');
|
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() {
|
Privkey.prototype.toWIF = function() {
|
||||||
|
|
Loading…
Reference in New Issue