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) {
this.credentials = new Credentials();
this.credentials.importCompressed(str);
this.credentials = Credentials.importCompressed(str);
};
/**

17
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;

Loading…
Cancel
Save