From d6ac0e4105dde69f67f3393445931af296fb3f2c Mon Sep 17 00:00:00 2001 From: Ivan Socolsky Date: Sun, 1 Mar 2015 12:45:10 -0300 Subject: [PATCH] make importCompressed static --- lib/client/api.js | 3 +-- lib/client/credentials.js | 17 +++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/client/api.js b/lib/client/api.js index 33346c3..452c9a1 100644 --- a/lib/client/api.js +++ b/lib/client/api.js @@ -350,8 +350,7 @@ API.prototype.export = function() { API.prototype.import = function(str) { - this.credentials = new Credentials(); - this.credentials.importCompressed(str); + this.credentials = Credentials.importCompressed(str); }; /** diff --git a/lib/client/credentials.js b/lib/client/credentials.js index 2798b8b..e16d9fe 100644 --- a/lib/client/credentials.js +++ b/lib/client/credentials.js @@ -129,27 +129,28 @@ Credentials.prototype.exportCompressed = function() { return JSON.stringify(values); }; -Credentials.prototype.importCompressed = function(compressed) { - var self = this; - +Credentials.importCompressed = function(compressed) { var list; try { list = JSON.parse(compressed); } catch (ex) { - throw new Error('Invalid string'); + throw new Error('Invalid compressed format'); } + var x = new Credentials(); + // Remove version var version = list[0]; list = _.rest(list); _.each(EXPORTABLE_FIELDS, function(field, i) { - self[field] = list[i]; + x[field] = list[i]; }); - self._expand(); + x._expand(); - self.network = self.xPubKey.substr(0, 4) == 'tpub' ? 'testnet' : 'livenet'; - self.publicKeyRing.push(self.xPubKey); + x.network = x.xPubKey.substr(0, 4) == 'tpub' ? 'testnet' : 'livenet'; + x.publicKeyRing.push(x.xPubKey); + return x; }; module.exports = Credentials;