add #toEncryptedObj
This commit is contained in:
parent
e3107c85ac
commit
e1b9f4f859
3 changed files with 40 additions and 2 deletions
|
|
@ -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
|
||||
*
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
|
|
|
|||
|
|
@ -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',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue