starting with encrypted storage
This commit is contained in:
parent
c19e99a99d
commit
f84180e76c
4 changed files with 54 additions and 12 deletions
|
|
@ -13,6 +13,7 @@
|
|||
"peerjs": "~0.3.8",
|
||||
"angular-mocks": "~1.2.14",
|
||||
"mocha": "~1.18.2",
|
||||
"chai": "~1.9.1"
|
||||
"chai": "~1.9.1",
|
||||
"crypto-js": "http://crypto-js.googlecode.com/files/CryptoJS%20v3.1.2.zip"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -271,6 +271,7 @@
|
|||
<script src="lib/angular-foundation/mm-foundation-tpls.min.js"></script>
|
||||
<script src="lib/peerjs/peer.js"></script>
|
||||
<script src="lib/bitcore.js"></script>
|
||||
<script src="lib/cyrpto-js/rollups/aes.js"></script>
|
||||
<script src="js/copayBundle.js"></script>
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -3,27 +3,68 @@
|
|||
var imports = require('soop').imports();
|
||||
|
||||
function Storage() {
|
||||
// TODO
|
||||
}
|
||||
|
||||
Storage.prototype._getPwd = function() {
|
||||
var pwd = prompt('Please enter your password');
|
||||
return pwd;
|
||||
}
|
||||
|
||||
Storage.prototype._encrypt = function(data) {
|
||||
return CryptoJS.AES.encrypt("Message", "Secret Passphrase");
|
||||
};
|
||||
|
||||
Storage.prototype._decrypt = function(encrypted) {
|
||||
return CryptoJS.AES.decrypt(encrypted, "Secret Passphrase");
|
||||
};
|
||||
|
||||
Storage.prototype._read = function(k) {
|
||||
var ret;
|
||||
try {
|
||||
ret = JSON.parse(localStorage.getItem(k));
|
||||
} catch (e) {};
|
||||
return ret;
|
||||
};
|
||||
|
||||
|
||||
// get value by key
|
||||
Storage.prototype.get = function(k) {
|
||||
// TODO
|
||||
Storage.prototype.getGlobal = function(k) {
|
||||
return this._read(k);
|
||||
};
|
||||
|
||||
// set value for key
|
||||
Storage.prototype.set = function(k,v) {
|
||||
// TODO
|
||||
Storage.prototype.setGlobal = function(k,v) {
|
||||
localStorage.setItem(k, JSON.stringify(v));
|
||||
};
|
||||
|
||||
// remove value for key
|
||||
Storage.prototype.remove = function(k) {
|
||||
// TODO
|
||||
Storage.prototype.removeGlobal = function(k) {
|
||||
localStorage.removeItem(k);
|
||||
};
|
||||
|
||||
|
||||
|
||||
Storage.prototype._key = function(walletId, k) {
|
||||
return walletId + '::' + k;
|
||||
};
|
||||
// get value by key
|
||||
Storage.prototype.get = function(walletId, k) {
|
||||
return this._read(localStorage.getItem(this._key(walletId,k)));
|
||||
};
|
||||
|
||||
// set value for key
|
||||
Storage.prototype.set = function(walletId, k,v) {
|
||||
this.setGlobal(this._key(walletId,k), v);
|
||||
};
|
||||
|
||||
// remove value for key
|
||||
Storage.prototype.remove = function(walletId, k) {
|
||||
localStorage.removeItem(this._key(walletId,k));
|
||||
};
|
||||
|
||||
// remove all values
|
||||
Storage.prototype.clearAll = function() {
|
||||
// TODO
|
||||
localStorage.clear();
|
||||
};
|
||||
|
||||
module.exports = require('soop')(Storage);
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
var imports = require('soop').imports();
|
||||
|
||||
function Storage() {
|
||||
this.data = {};
|
||||
}
|
||||
|
||||
Storage.prototype._read = function(k) {
|
||||
|
|
@ -42,12 +41,12 @@ Storage.prototype.get = function(walletId, k) {
|
|||
|
||||
// set value for key
|
||||
Storage.prototype.set = function(walletId, k,v) {
|
||||
localStorage.setItem(this._key(walletId,k), JSON.stringify(v));
|
||||
this.setGlobal(this._key(walletId,k), v);
|
||||
};
|
||||
|
||||
// remove value for key
|
||||
Storage.prototype.remove = function(walletId, k) {
|
||||
localStorage.removeItem(this._key(walletId,k));
|
||||
this.removeGlobal(this._key(walletId,k));
|
||||
};
|
||||
|
||||
// remove all values
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue