mirror of https://github.com/BTCPrivate/copay.git
mv Passphrase logic to Storage
This commit is contained in:
parent
70d306242e
commit
74129a6923
|
@ -113,7 +113,6 @@ Identity.create = function(email, password, opts, cb) {
|
|||
Identity._createProfile(email, password, iden.storage, function(err, profile) {
|
||||
if (err) return cb(err);
|
||||
iden.profile = profile;
|
||||
console.log('[Identity.js.115:profile:]',profile); //TODO
|
||||
|
||||
if (opts.noWallets)
|
||||
cb(null, iden);
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
var preconditions = require('preconditions').singleton();
|
||||
var CryptoJS = require('node-cryptojs-aes').CryptoJS;
|
||||
var bitcore = require('bitcore');
|
||||
var Passphrase = require('./Passphrase');
|
||||
var preconditions = require('preconditions').instance();
|
||||
var _ = require('underscore');
|
||||
var CACHE_DURATION = 1000 * 60 * 5;
|
||||
|
@ -17,11 +18,15 @@ var id = 0;
|
|||
function Storage(opts) {
|
||||
preconditions.checkArgument(opts);
|
||||
preconditions.checkArgument(opts.password);
|
||||
opts = opts || {};
|
||||
|
||||
this.wListCache = {};
|
||||
this.__uniqueid = ++id;
|
||||
this.setPassphrase(opts.password);
|
||||
this.passphraseConfig = {
|
||||
salt: opts.salt,
|
||||
iterations: opts.iterations,
|
||||
};
|
||||
|
||||
this.setPassword(opts.password);
|
||||
|
||||
try {
|
||||
this.db = opts.db || localStorage;
|
||||
|
@ -48,8 +53,15 @@ Storage.prototype.hasPassphrase = function() {
|
|||
return pps[this.__uniqueid] ? true : false;
|
||||
};
|
||||
|
||||
Storage.prototype.setPassphrase = function(password) {
|
||||
pps[this.__uniqueid] = password;
|
||||
|
||||
Storage.prototype._setPassphrase = function(passphrase) {
|
||||
pps[this.__uniqueid] = passphrase;
|
||||
};
|
||||
|
||||
Storage.prototype.setPassword = function(password, config) {
|
||||
var passphraseConfig = _.extend(this.passphraseConfig, config);
|
||||
var p = new Passphrase(passphraseConfig);
|
||||
this._setPassphrase(p.getBase64(password));
|
||||
}
|
||||
|
||||
Storage.prototype._encrypt = function(string) {
|
||||
|
|
|
@ -9,7 +9,7 @@ describe('Storage model', function() {
|
|||
var s;
|
||||
beforeEach(function(done) {
|
||||
s = new Storage(requireMock('FakeLocalStorage').storageParams);
|
||||
s.setPassphrase('mysupercoolpassword');
|
||||
s.setPassword('mysupercoolpassword');
|
||||
s.clearAll(done);
|
||||
});
|
||||
|
||||
|
@ -415,13 +415,13 @@ describe('Storage model', function() {
|
|||
|
||||
describe('#decrypt', function() {
|
||||
it('should not be able to decrypt with wrong password', function() {
|
||||
s.setPassphrase('xxx');
|
||||
s.setPassword('xxx');
|
||||
var wo = s.decrypt(encryptedLegacy1);
|
||||
should.not.exist(wo);
|
||||
});
|
||||
|
||||
it('should be able to decrypt an old backup', function() {
|
||||
s.setPassphrase(legacyPassword1);
|
||||
s._setPassphrase(legacyPassword1);
|
||||
var wo = s.decrypt(encryptedLegacy1);
|
||||
should.exist(wo);
|
||||
wo.opts.id.should.equal('48ba2f1ffdfe9708');
|
||||
|
|
|
@ -32,4 +32,5 @@ module.exports.storageParams = {
|
|||
password: '123',
|
||||
db: new FakeLocalStorage(),
|
||||
sessionStorage: new FakeLocalStorage(),
|
||||
iterations: 1,
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue