Skip to content
This repository has been archived by the owner on Apr 15, 2019. It is now read-only.

Commit

Permalink
Merge branch 'development' into 21-support-second-passphrase
Browse files Browse the repository at this point in the history
  • Loading branch information
reyraa authored Apr 26, 2017
2 parents 919c727 + 126b197 commit e602f9e
Show file tree
Hide file tree
Showing 15 changed files with 374 additions and 23 deletions.
82 changes: 67 additions & 15 deletions app/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,63 @@ function createWindow() {
},
],
},
{
label: 'View',
submenu: [
{
role: 'reload',
},
{
role: 'togglefullscreen',
}
],
},
{
label: 'Window',
submenu: [
{
role: 'minimize',
},
],
},
{
label: 'Help',
submenu: [
{
label: 'Lisk Website',
click: function () {
electron.shell.openExternal('https://lisk.io');
}
},
{
label: 'Lisk Chat',
click: function () {
electron.shell.openExternal('https://lisk.chat');
}
},
{
label: 'Lisk Forum',
click: function () {
electron.shell.openExternal('https://forum.lisk.io');
}
},
{
type: 'separator',
},
{
label: 'Report Issue...',
click: function () {
electron.shell.openExternal('https://github.com/LiskHQ/lisk-nano/issues/new');
}
},
{
label: 'What\'s New...',
click: function () {
electron.shell.openExternal('https://github.com/LiskHQ/lisk-nano/releases');
}
},
],
},
];

if (process.platform === 'darwin') {
Expand All @@ -60,23 +117,18 @@ function createWindow() {
],
});
} else {
template.push({
label: "Help",
submenu: [
{
label: 'About',
click: function (item, focusedWindow) {
if (focusedWindow) {
const options = {
buttons: ['OK'],
icon: `${__dirname}/assets/lisk.png`,
message: `Lisk Nano\nVersion ${app.getVersion()}\nCopyright © 2017 Lisk Foundation`,
}
electron.dialog.showMessageBox(focusedWindow, options, function () {})
}
template[template.length - 1].submenu.push({
label: 'About',
click: function (item, focusedWindow) {
if (focusedWindow) {
const options = {
buttons: ['OK'],
icon: `${__dirname}/assets/lisk.png`,
message: `Lisk Nano\nVersion ${app.getVersion()}\nCopyright © 2017 Lisk Foundation`,
}
electron.dialog.showMessageBox(focusedWindow, options, function () {})
}
]
}
});
}

Expand Down
4 changes: 2 additions & 2 deletions src/app/components/delegates/delegates.pug
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ div.offline-hide
i.material-icons list
span Input Names
md-menu.pull-right.right-action-buttons
md-button.pull-right(ng-click='$mdOpenMenu()')
md-button.pull-right(ng-click='$mdOpenMenu()', ng-disabled='$ctrl.votedList.length == 0')
i.material-icons visibility
span My votes ({{$ctrl.votedList.length}})
md-menu-content(width='4')
Expand All @@ -38,7 +38,7 @@ div.offline-hide
md-button.md-icon-button.lsk-vote-remove-button(ng-click='$ctrl.unselect(username)')
i.material-icons close
span.pull-right.right-action-buttons
md-button(ng-click='$ctrl.openVoteDialog()')
md-button(ng-click='$ctrl.openVoteDialog()', ng-disabled='$ctrl.voteList.length + $ctrl.unvoteList.length == 0')
i.material-icons done
span Vote
span(ng-if='$ctrl.voteList.length || $ctrl.unvoteList.length')
Expand Down
3 changes: 2 additions & 1 deletion src/app/components/main/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ const UPDATE_INTERVAL_BALANCE = 10000;
app.component('main', {
template: require('./main.pug')(),
controller: class main {
constructor($scope, $rootScope, $timeout, $q, $peers, error, SendModal) {
constructor($scope, $rootScope, $timeout, $q, $peers, error, SendModal, signVerify) {
this.$scope = $scope;
this.$rootScope = $rootScope;
this.$timeout = $timeout;
this.$q = $q;
this.$peers = $peers;
this.error = error;
this.signVerify = signVerify;
this.sendModal = SendModal;

this.$scope.$on('login', this.login.bind(this));
Expand Down
4 changes: 0 additions & 4 deletions src/app/components/main/main.less
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ main {
min-width: 128px;
max-width: 256px;
}

.logout {
margin-right: 0;
}

md-tabs-wrapper {
margin: 0 10px;
Expand Down
13 changes: 12 additions & 1 deletion src/app/components/main/main.pug
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,18 @@ md-content(layout='row', id="main")
data-account='{{$ctrl.account.publicKey}}', data-passphrase='{{$ctrl.passphrase}}') Set 2nd passphrase
md-button.md-raised.md-primary.send(data-show-send-modal, ng-if='$ctrl.logged') Send
md-button.md-raised.md-secondary.logout(ng-click='$ctrl.logout()', ng-if='$ctrl.logged') Logout

md-menu.top-menu(ng-if='$ctrl.logged', md-position-mode='target-right target', md-offset='14 0')
md-button.md-icon-button(ng-click='$mdOpenMenu()')
i.material-icons more_vert
md-menu-content(width='2')
md-menu-item
md-button(ng-click='$ctrl.signVerify.openSignMessageDialog($ctrl.account, $ctrl.passphrase)')
div(layout='row', flex='')
p(flex='') Sign message
md-menu-item
md-button(ng-click='$ctrl.signVerify.openVerifyMessageDialog()')
div(layout='row', flex='')
p(flex='') Verify message
div(layout='row', layout-align='space-around', ng-show='$ctrl.prelogged')
md-progress-circular.md-warn(md-mode='indeterminate', md-diameter='80')
div(ng-show='!$ctrl.prelogged && !$ctrl.logged')
Expand Down
20 changes: 20 additions & 0 deletions src/app/components/sign-verify/sign-message.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import lisk from 'lisk-js';

app.component('signMessage', {
template: require('./sign-message.pug')(),
bindings: {
account: '=',
passphrase: '=',
},
controller: class signMessage {
constructor($mdDialog) {
this.$mdDialog = $mdDialog;
}

sign() {
const signnedMessage = lisk.crypto.signMessageWithSecret(this.message, this.passphrase);
this.result = lisk.crypto.printSignedMessage(
this.message, signnedMessage, this.account.publicKey);
}
},
});
16 changes: 16 additions & 0 deletions src/app/components/sign-verify/sign-message.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
div
md-toolbar
.md-toolbar-tools
h2 Sign message
span(flex='')
md-button.md-icon-button(ng-click='$ctrl.$mdDialog.hide()', aria-label='Close dialog')
i.material-icons close
div(layout-padding)
form
md-input-container.md-block
label Message
textarea(name='message', ng-model='$ctrl.message', ng-change='$ctrl.sign()', md-autofocus)
div
md-input-container.md-block
label Result
textarea(name='result', ng-model='$ctrl.result')
38 changes: 38 additions & 0 deletions src/app/components/sign-verify/verify-message.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import lisk from 'lisk-js';

app.component('verifyMessage', {
template: require('./verify-message.pug')(),
controller: class verifyMessage {
constructor($mdDialog) {
this.$mdDialog = $mdDialog;

this.publicKey = {
error: {
},
value: '',
};
this.signature = {
error: {
},
value: '',
};
}

verify() {
this.publicKey.error = {};
this.signature.error = {};
this.result = '';
try {
this.result = lisk.crypto.verifyMessageWithPublicKey(
this.signature.value, this.publicKey.value);
} catch (e) {
if (e.message.substring(0, 4) === 'nacl' && this.publicKey.value) {
this.publicKey.error.invalid = true;
} else if (e.message.indexOf('length') !== -1 && this.signature.value) {
this.signature.error.invalid = true;
}
}
}
},
});

24 changes: 24 additions & 0 deletions src/app/components/sign-verify/verify-message.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
div
md-toolbar
.md-toolbar-tools
h2 Verify message
span(flex='')
md-button.md-icon-button(ng-click='$ctrl.$mdDialog.hide()', aria-label='Close dialog')
i.material-icons close
div(layout-padding)
form
md-input-container.md-block(ng-class='{"md-input-invalid": $ctrl.publicKey.error.invalid}')
label Public key
input(type='text', name='publicKey', ng-model='$ctrl.publicKey.value', ng-change='$ctrl.verify()', md-autofocus)
div(ng-messages='$ctrl.publicKey.error')
div(ng-message='invalid') Invalid
md-input-container.md-block(ng-class='{"md-input-invalid": $ctrl.signature.error.invalid}')
label Signature
textarea(name='signature', ng-model='$ctrl.signature.value', ng-change='$ctrl.verify()')
div(ng-messages='$ctrl.signature.error')
div(ng-message='invalid') Invalid
div
md-input-container.md-block
label Original Message
textarea(name='result', ng-model='$ctrl.result')

3 changes: 3 additions & 0 deletions src/app/lisk-nano.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@ import './components/lsk/lsk';
import './components/forging/forging';
import './components/delegates/delegates';
import './components/delegates/vote';
import './components/sign-verify/sign-message';
import './components/sign-verify/verify-message';

import './services/peers/peers';
import './services/lsk';
import './services/success';
import './services/error';
import './services/passphrase';
import './services/sign-verify';

import './filters/lsk';
35 changes: 35 additions & 0 deletions src/app/services/sign-verify.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
app.factory('signVerify', ($mdDialog, $mdMedia) => ({
openSignMessageDialog(_account, _passphrase) {
return $mdDialog.show({
controllerAs: '$ctrl',
controller: class signMessageDialog {
constructor($scope, account, passphrase) {
this.$scope = $scope;
this.$scope.account = account;
this.$scope.passphrase = passphrase;
}
},
template:
'<md-dialog flex="80" >' +
'<sign-message account="account" passphrase="passphrase">' +
'</sign-message>' +
'</md-dialog>',
fullscreen: ($mdMedia('sm') || $mdMedia('xs')),
locals: {
account: _account,
passphrase: _passphrase,
},
});
},

openVerifyMessageDialog() {
return $mdDialog.show({
template:
'<md-dialog flex="80" >' +
'<verify-message></verify-message>' +
'</md-dialog>',
fullscreen: ($mdMedia('sm') || $mdMedia('xs')),
});
},
}));

49 changes: 49 additions & 0 deletions src/test/components/sign-verify/sign-message.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
const chai = require('chai');

const expect = chai.expect;

describe('Sign message component', () => {
let $compile;
let $rootScope;
let element;
let $scope;

beforeEach(angular.mock.module('app'));

beforeEach(inject((_$compile_, _$rootScope_) => {
$compile = _$compile_;
$rootScope = _$rootScope_;
}));

beforeEach(() => {
$scope = $rootScope.$new();
$scope.passphrase = 'robust swift grocery peasant forget share enable convince deputy road keep cheap';
$scope.account = {
address: '8273455169423958419L',
publicKey: '9d3058175acab969f41ad9b86f7a2926c74258670fe56b37c429c01fca9f2f0f',
};
element = $compile('<sign-message passphrase="passphrase" account="account"></sign-message>')($scope);
$scope.$digest();
});

const DIALOG_TITLE = 'Sign message';
it(`should contain a title saying "${DIALOG_TITLE}"`, () => {
expect(element.find('h2').text()).to.equal(DIALOG_TITLE);
});

it('should output signed message into textarea[name="result"] if there is input in textarea[name="message"]', () => {
const message = 'Hello world';
const result =
'-----BEGIN LISK SIGNED MESSAGE-----\n' +
'Hello world\n' +
'-----BEGIN SIGNATURE-----\n' +
'9d3058175acab969f41ad9b86f7a2926c74258670fe56b37c429c01fca9f2f0f\n' +
'dd01775ec30225b24a74ee2ff9578ed3515371ddf32ba50540dc79a5dab66252081d0a345be3ad5d' +
'fcb939f018d3dd911d9eacfe8998784879cc37fdfde1200448656c6c6f20776f726c64\n' +
'-----END LISK SIGNED MESSAGE-----';
const ngModelController = element.find('textarea[name="message"]').controller('ngModel');
ngModelController.$setViewValue(message);
expect(element.find('textarea[name="result"]').val()).to.equal(result);
});
});

Loading

0 comments on commit e602f9e

Please sign in to comment.