This repository has been archived by the owner on Apr 15, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'development' into 21-support-second-passphrase
- Loading branch information
Showing
15 changed files
with
374 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} | ||
}, | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')), | ||
}); | ||
}, | ||
})); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); | ||
|
Oops, something went wrong.