Merge pull request #1264 from maraoz/refactor/settings

Small refactors and new test
This commit is contained in:
Esteban Ordano 2014-09-02 17:39:17 -03:00
commit 9ba2d0975b
7 changed files with 82 additions and 80 deletions

View File

@ -4,7 +4,7 @@ angular.module('copayApp.controllers').controller('SidebarController', function(
$scope.menu = [{
'title': 'Receive',
'icon': 'fi-arrow-left',
'icon': 'fi-download',
'link': 'receive'
}, {
'title': 'Send',
@ -15,8 +15,8 @@ angular.module('copayApp.controllers').controller('SidebarController', function(
'icon': 'fi-clipboard-pencil',
'link': 'history'
}, {
'title': 'More',
'icon': 'fi-download',
'title': 'Settings',
'icon': 'fi-widget',
'link': 'more'
}];

View File

@ -15,14 +15,12 @@ Passphrase.prototype.get = function(password) {
keySize: 512 / 32,
iterations: this.iterations
});
return key512;
};
Passphrase.prototype.getBase64 = function(password) {
var key512 = this.get(password);
var keyBase64 = key512.toString(CryptoJS.enc.Base64);
return keyBase64;
};

View File

@ -4,6 +4,7 @@ var TxProposals = require('./TxProposals');
var PublicKeyRing = require('./PublicKeyRing');
var PrivateKey = require('./PrivateKey');
var Wallet = require('./Wallet');
var preconditions = require('preconditions').instance();
var log = require('../../log');
@ -13,7 +14,6 @@ var StorageLocalEncrypted = module.exports.StorageLocalEncrypted = require('../s
/*
* WalletFactory
*
*/
function WalletFactory(config, version) {

View File

@ -2,6 +2,7 @@
var CryptoJS = require('node-cryptojs-aes').CryptoJS;
var bitcore = require('bitcore');
var preconditions = require('preconditions').instance();
var id = 0;
function Storage(opts) {
@ -11,15 +12,12 @@ function Storage(opts) {
if (opts.password)
this._setPassphrase(opts.password);
try{
try {
this.localStorage = opts.localStorage || localStorage;
this.sessionStorage = opts.sessionStorage || sessionStorage;
} catch (e) {};
if (!this.localStorage)
throw new Error('no localStorage');
if (!this.sessionStorage)
throw new Error('no sessionStorage');
} catch (e) {}
preconditions.checkState(this.localStorage, 'No localstorage found');
preconditions.checkState(this.sessionStorage, 'No sessionStorage found');
}
var pps = {};
@ -40,11 +38,6 @@ Storage.prototype._encrypt = function(string) {
return encryptedBase64;
};
Storage.prototype._encryptObj = function(obj) {
var string = JSON.stringify(obj);
return this._encrypt(string);
};
Storage.prototype._decrypt = function(base64) {
var decryptedStr = null;
try {
@ -58,10 +51,6 @@ Storage.prototype._decrypt = function(base64) {
return decryptedStr;
};
Storage.prototype._decryptObj = function(base64) {
var decryptedStr = this._decrypt(base64);
return JSON.parse(decryptedStr);
};
Storage.prototype._read = function(k) {
var ret;
@ -98,7 +87,7 @@ Storage.prototype.removeGlobal = function(k) {
};
Storage.prototype.getSessionId = function() {
var sessionId = this.sessionStorage.getItem('sessionId');
var sessionId = this.sessionStorage.getItem('sessionId');
if (!sessionId) {
sessionId = bitcore.SecureRandom.getRandomBuffer(8).toString('hex');
this.sessionStorage.setItem('sessionId', sessionId);
@ -131,7 +120,6 @@ Storage.prototype.setName = function(walletId, name) {
Storage.prototype.getName = function(walletId) {
var ret = this.getGlobal('nameFor::' + walletId);
return ret;
};
@ -145,7 +133,7 @@ Storage.prototype.getWalletIds = function() {
if (split.length == 2) {
var walletId = split[0];
if (!walletId || walletId === 'nameFor' || walletId ==='lock')
if (!walletId || walletId === 'nameFor' || walletId === 'lock')
continue;
if (typeof uniq[walletId] === 'undefined') {
@ -207,14 +195,14 @@ Storage.prototype.clearAll = function() {
this.localStorage.clear();
};
Storage.prototype.export = function(obj) {
var encryptedObj = this._encryptObj(obj);
return encryptedObj;
Storage.prototype.import = function(base64) {
var decryptedStr = this._decrypt(base64);
return JSON.parse(decryptedStr);
};
Storage.prototype.import = function(base64) {
var decryptedObj = this._decryptObj(base64);
return decryptedObj;
Storage.prototype.export = function(obj) {
var string = JSON.stringify(obj);
return this._encrypt(string);
};
module.exports = Storage;

View File

@ -18,7 +18,7 @@ describe('Passphrase model', function() {
should.exist(p);
});
it('should generate key from password', function () {
it('should generate key from password', function (done) {
var p = new Passphrase({
salt: 'mjuBtGybi/4=',
iterations: 10,
@ -33,6 +33,7 @@ describe('Passphrase model', function() {
p.getBase64Async(pass, function (ret) {
ret.toString().should.equal('IoP+EbmhibgvHAkgCAaSDL3Y73UvU96pEPkKtSb0Qazb1RKFVWR6fjkKGp/qBCImljzND3hRAws9bigszrqhfg==');
done();
});
});

File diff suppressed because one or more lines are too long

View File

@ -1,8 +1,8 @@
<div class="backup" ng-controller="MoreController">
<h1>Backup & Delete </h1>
<h1>Settings </h1>
<div class="oh large-12 columns panel">
<h3><i class="fi-download m10r"></i> Backup </h3>
<p class="large-8 columns text-gray"> Its important to back up your wallet so that you can recover your wallet in case of disaster </p>
<p class="large-8 columns text-gray"> It's important to backup your wallet so that you can recover it in case of disaster</p>
<div class="large-4 columns">
<a class="button primary expand" ng-click="downloadBackup()">Download File</a>
</div>