From e1b9f4f859345f967cad14ea246cf2f9f58bcad0 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Wed, 15 Oct 2014 16:24:21 -0300 Subject: [PATCH] add #toEncryptedObj --- js/models/Identity.js | 17 ++++++++++++++++- js/models/Storage.js | 1 - test/Identity.js | 24 ++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/js/models/Identity.js b/js/models/Identity.js index e4ce528a5..2bd2d4c7b 100644 --- a/js/models/Identity.js +++ b/js/models/Identity.js @@ -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 * diff --git a/js/models/Storage.js b/js/models/Storage.js index 6f1e83a7b..7714bb2fa 100644 --- a/js/models/Storage.js +++ b/js/models/Storage.js @@ -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() { diff --git a/test/Identity.js b/test/Identity.js index 7098a3572..45f1ec141 100644 --- a/test/Identity.js +++ b/test/Identity.js @@ -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',