Browse Source

make importCompressed static

activeAddress
Ivan Socolsky 10 years ago
parent
commit
d6ac0e4105
  1. 3
      lib/client/api.js
  2. 17
      lib/client/credentials.js

3
lib/client/api.js

@ -350,8 +350,7 @@ API.prototype.export = function() {
API.prototype.import = function(str) { API.prototype.import = function(str) {
this.credentials = new Credentials(); this.credentials = Credentials.importCompressed(str);
this.credentials.importCompressed(str);
}; };
/** /**

17
lib/client/credentials.js

@ -129,27 +129,28 @@ Credentials.prototype.exportCompressed = function() {
return JSON.stringify(values); return JSON.stringify(values);
}; };
Credentials.prototype.importCompressed = function(compressed) { Credentials.importCompressed = function(compressed) {
var self = this;
var list; var list;
try { try {
list = JSON.parse(compressed); list = JSON.parse(compressed);
} catch (ex) { } catch (ex) {
throw new Error('Invalid string'); throw new Error('Invalid compressed format');
} }
var x = new Credentials();
// Remove version // Remove version
var version = list[0]; var version = list[0];
list = _.rest(list); list = _.rest(list);
_.each(EXPORTABLE_FIELDS, function(field, i) { _.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'; x.network = x.xPubKey.substr(0, 4) == 'tpub' ? 'testnet' : 'livenet';
self.publicKeyRing.push(self.xPubKey); x.publicKeyRing.push(x.xPubKey);
return x;
}; };
module.exports = Credentials; module.exports = Credentials;

Loading…
Cancel
Save