add #toEncryptedObj

This commit is contained in:
Matias Alejo Garcia 2014-10-15 16:24:21 -03:00
commit e1b9f4f859
3 changed files with 40 additions and 2 deletions

View file

@ -333,9 +333,24 @@ Identity.prototype.closeWallet = function(wid, cb) {
};
Identity.prototype.toObj = function(wid, cb) {
/**
* @desc Return a base64 encrypted version of the wallet
* @return {string} base64 encoded string
*/
Identity.prototype.toEncryptedObj = function() {
var ret = {};
ret.iterations = this.storage.iterations;
ret.wallets = {};
_.each(this.openWallets, function(w){
ret.wallets[w.getId()] = w.toEncryptedObj();
});
return ret;
};
/**
* @desc This method prepares options for a new Wallet
*

View file

@ -64,7 +64,6 @@ Storage.prototype.restorePassphrase = function() {
throw new Error('NOSTOREDPASSPHRASE: No stored passphrase');
this._setPassphrase(this.savedPassphrase[this.__uniqueid].pps, this.savedPassphrase[this.__uniqueid].iterations);
this.savedPassphrase[this.__uniqueid] = undefined;
};
Storage.prototype.hasPassphrase = function() {

View file

@ -353,6 +353,30 @@ describe('Identity model', function() {
});
});
describe('#toEncryptedObj', function() {
beforeEach(function() {
var ws = [];
_.each([0, 1, 2, 3, 4], function(i) {
var w = sinon.stub();
w.toEncryptedObj = sinon.stub().returns('enc' + i);
w.getId = sinon.stub().returns('wid' + i);
ws.push(w);
});
iden.openWallets = ws;
iden.storage.iterations = 13;
});
it('should create an encrypted object', function() {
var ret = iden.toEncryptedObj();
ret.iterations.should.equal(13);
_.each([0, 1, 2, 3, 4], function(i) {
ret.wallets['wid' + i].should.equal('enc' + i);
});
});
});
describe('#joinWallet', function() {
var opts = {
secret: '8WtTuiFTkhP5ao7AF2QErSwV39Cbur6pdMebKzQXFqL59RscXM',