From cd6c2b241067721b6362e1f058b6455d2bc01720 Mon Sep 17 00:00:00 2001 From: "Ryan X. Charles" Date: Sat, 9 Aug 2014 19:58:48 -0700 Subject: [PATCH] refactor privkey --- lib/privkey.js | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/lib/privkey.js b/lib/privkey.js index ed580bf20..dac93e5d6 100644 --- a/lib/privkey.js +++ b/lib/privkey.js @@ -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() {