refactor privkey

This commit is contained in:
Ryan X. Charles 2014-08-09 19:58:48 -07:00
parent 304210c132
commit cd6c2b2410
1 changed files with 7 additions and 19 deletions

View File

@ -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() {