mirror of https://github.com/BTCPrivate/copay.git
Encrypted local storage plugin
This commit is contained in:
parent
50b771680c
commit
cf2615bb88
|
@ -55,9 +55,10 @@ var defaultConfig = {
|
|||
|
||||
plugins: {
|
||||
//LocalStorage: true,
|
||||
EncryptedLocalStorage: true,
|
||||
//GoogleDrive: true,
|
||||
//InsightStorage: true
|
||||
EncryptedInsightStorage: true
|
||||
//EncryptedInsightStorage: true
|
||||
},
|
||||
|
||||
EncryptedInsightStorage: {
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
var cryptoUtil = require('../util/crypto');
|
||||
var LocalStorage = require('./LocalStorage');
|
||||
var inherits = require('inherits');
|
||||
|
||||
function EncryptedLocalStorage(config) {
|
||||
LocalStorage.apply(this, [config]);
|
||||
}
|
||||
inherits(EncryptedLocalStorage, LocalStorage);
|
||||
|
||||
EncryptedLocalStorage.prototype.getItem = function(name, callback) {
|
||||
var key = cryptoUtil.kdf(this.password, this.email);
|
||||
LocalStorage.prototype.getItem.apply(this, [name, function(err, body) {
|
||||
var decryptedJson = cryptoUtil.decrypt(key, body);
|
||||
if (!decryptedJson) {
|
||||
return callback('Internal Error');
|
||||
}
|
||||
return callback(null, decryptedJson);
|
||||
}]);
|
||||
};
|
||||
|
||||
EncryptedLocalStorage.prototype.setItem = function(name, value, callback) {
|
||||
var key = cryptoUtil.kdf(this.password, this.email);
|
||||
if (!_.isString(value)) {
|
||||
value = JSON.stringify(value);
|
||||
}
|
||||
var record = cryptoUtil.encrypt(key, value);
|
||||
LocalStorage.prototype.setItem.apply(this, [name, record, callback]);
|
||||
};
|
||||
|
||||
module.exports = EncryptedLocalStorage;
|
|
@ -8,6 +8,8 @@ LocalStorage.prototype.init = function() {
|
|||
};
|
||||
|
||||
LocalStorage.prototype.setCredentials = function(email, password, opts) {
|
||||
this.email = email;
|
||||
this.password = password;
|
||||
};
|
||||
|
||||
LocalStorage.prototype.getItem = function(k,cb) {
|
||||
|
|
|
@ -101,6 +101,9 @@ var createBundle = function(opts) {
|
|||
b.require('./js/plugins/EncryptedInsightStorage', {
|
||||
expose: '../plugins/EncryptedInsightStorage'
|
||||
});
|
||||
b.require('./js/plugins/EncryptedLocalStorage', {
|
||||
expose: '../plugins/EncryptedLocalStorage'
|
||||
});
|
||||
}
|
||||
|
||||
b.require('./config', {
|
||||
|
|
Loading…
Reference in New Issue