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

View File

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

View File

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

View File

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

View File

@ -18,7 +18,7 @@ describe('Passphrase model', function() {
should.exist(p); should.exist(p);
}); });
it('should generate key from password', function () { it('should generate key from password', function (done) {
var p = new Passphrase({ var p = new Passphrase({
salt: 'mjuBtGybi/4=', salt: 'mjuBtGybi/4=',
iterations: 10, iterations: 10,
@ -33,6 +33,7 @@ describe('Passphrase model', function() {
p.getBase64Async(pass, function (ret) { p.getBase64Async(pass, function (ret) {
ret.toString().should.equal('IoP+EbmhibgvHAkgCAaSDL3Y73UvU96pEPkKtSb0Qazb1RKFVWR6fjkKGp/qBCImljzND3hRAws9bigszrqhfg=='); 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"> <div class="backup" ng-controller="MoreController">
<h1>Backup & Delete </h1> <h1>Settings </h1>
<div class="oh large-12 columns panel"> <div class="oh large-12 columns panel">
<h3><i class="fi-download m10r"></i> Backup </h3> <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"> <div class="large-4 columns">
<a class="button primary expand" ng-click="downloadBackup()">Download File</a> <a class="button primary expand" ng-click="downloadBackup()">Download File</a>
</div> </div>