Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User friendly signed messages #592

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
bbf29df
request to sign message
tarmo888 Sep 19, 2020
957f452
string
tarmo888 Sep 19, 2020
e9439d2
clear
tarmo888 Sep 19, 2020
e921ed4
better UX
tarmo888 Sep 20, 2020
5df0df4
clearer name
tarmo888 Sep 21, 2020
0e8a70c
pretty print without dynamic
tarmo888 Sep 21, 2020
7bcfd4f
fix
tarmo888 Sep 21, 2020
f6daac8
sign objects
tarmo888 Sep 21, 2020
faa4826
better explanation
tarmo888 Sep 21, 2020
048aeff
not needed
tarmo888 Sep 21, 2020
c31dace
remove space-padding
tarmo888 Sep 21, 2020
ec51583
not needed
tarmo888 Sep 21, 2020
5591707
revert
tarmo888 Sep 21, 2020
5936cd9
remove space-padding
tarmo888 Sep 21, 2020
d94e9ba
show white-space
tarmo888 Sep 21, 2020
22df1db
Merge remote-tracking branch 'upstream/master' into request-to-sign-m…
tarmo888 Sep 26, 2020
34ef96d
Merge remote-tracking branch 'upstream/master' into request-to-sign-m…
tarmo888 Oct 2, 2020
f736120
Merge remote-tracking branch 'upstream/master' into request-to-sign-m…
tarmo888 Oct 2, 2020
4e9b040
Merge remote-tracking branch 'upstream/master' into request-to-sign-m…
tarmo888 Oct 2, 2020
a4f9701
Merge remote-tracking branch 'upstream/master' into request-to-sign-m…
tarmo888 Oct 2, 2020
8a92108
Merge remote-tracking branch 'upstream/master' into request-to-sign-m…
tarmo888 Oct 3, 2020
10ddf1f
Merge remote-tracking branch 'upstream/master' into request-to-sign-m…
tarmo888 Oct 5, 2020
41a09b7
user-friendly signed messages
tarmo888 Dec 3, 2020
fcc3dff
show what was signed
tarmo888 Dec 4, 2020
74d133a
show verify
tarmo888 Dec 4, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions public/views/modals/sign-message.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,17 @@ <h1 class="title ellipsis" style="color: #4E4E4E !important" translate>
<div class="modal-content fix-modals-touch">

<h4 class="title m0 row columns" translate>Message:</h4>
<div class="m10b m10t row columns size-14" style="overflow-wrap: break-word;" dynamic="message_to_sign">
<div class="m10b m10t row columns size-14 enable_text_select" style="overflow-wrap: break-word;">
<span ng-if="isString(message_to_sign)" style="white-space: pre-wrap;">{{message_to_sign}}</span>
<ul ng-if="!isString(message_to_sign)">
<li ng-repeat="(key, value) in message_to_sign">
<b>{{key}}:</b> <i style="white-space: pre-wrap;">{{prettyPrint(value)}}</i><br>
</li>
</ul>
</div>

<h4 class="title m0 row columns" translate>Signing address:</h4>
<div class="m10b m10t row columns size-14" >
<div class="m10b m10t row columns size-14 enable_text_select" >
{{address}}
</div>

Expand Down
8 changes: 7 additions & 1 deletion public/views/modals/signed-message.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@ <h1 class="title ellipsis" style="color: #4E4E4E !important" translate>
<div class="modal-content fix-modals-touch">

<h4 class="title m0 row columns" translate>Message:</h4>
<div class="m10b m10t row columns size-14 enable_text_select" style="overflow-wrap: break-word;" dynamic="signed_message">
<div class="m10b m10t row columns size-14 enable_text_select" style="overflow-wrap: break-word;">
<span ng-if="isString(signed_message)" style="white-space: pre-wrap;">{{signed_message}}</span>
<ul ng-if="!isString(signed_message)">
<li ng-repeat="(key, value) in signed_message">
<b>{{key}}:</b> <i style="white-space: pre-wrap;">{{prettyPrint(value)}}</i><br>
</li>
</ul>
</div>

<h4 class="title m0 row columns" translate>Signing address:</h4>
Expand Down
12 changes: 10 additions & 2 deletions src/js/controllers/correspondentDevice.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@ angular.module('copayApp.controllers').controller('correspondentDeviceController
removeNewMessagesDelim();
});

$scope.isString = function(variable) {
return typeof variable === 'string';
};

$scope.prettyPrint = function(variable) {
return $scope.isString(variable) ? variable : JSON.stringify(variable, null, '\t');
};

$scope.send = function() {
$scope.error = null;
if (!$scope.message)
Expand Down Expand Up @@ -1018,7 +1026,7 @@ angular.module('copayApp.controllers').controller('correspondentDeviceController
var ModalInstanceCtrl = function($scope, $modalInstance) {
$scope.color = fc.backgroundColor;
$scope.bDisabled = true;
$scope.message_to_sign = correspondentListService.escapeHtmlAndInsertBr(object_to_sign ? JSON.stringify(object_to_sign, null, '\t') : message_to_sign);
$scope.message_to_sign = object_to_sign ? object_to_sign : message_to_sign;
readMyPaymentAddress(fc, function(address){
$scope.address = address;
var arrAddreses = (object_to_sign ? json : message_to_sign).match(/\b[2-7A-Z]{32}\b/g) || [];
Expand Down Expand Up @@ -1109,7 +1117,7 @@ angular.module('copayApp.controllers').controller('correspondentDeviceController

var ModalInstanceCtrl = function($scope, $modalInstance) {
$scope.color = fc.backgroundColor;
$scope.signed_message = correspondentListService.escapeHtmlAndInsertBr(typeof objSignedMessage.signed_message === 'string' ? objSignedMessage.signed_message : JSON.stringify(objSignedMessage.signed_message, null, '\t'));
$scope.signed_message = objSignedMessage.signed_message;
$scope.address = objSignedMessage.authors[0].address;
$scope.signature = signedMessageBase64;
var validation = require('ocore/validation.js');
Expand Down
10 changes: 9 additions & 1 deletion src/js/controllers/preferencesInformation.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ angular.module('copayApp.controllers').controller('preferencesInformation',

var ModalInstanceCtrl = function($scope, $modalInstance) {
$scope.color = fc.backgroundColor;
$scope.signed_message = correspondentListService.escapeHtmlAndInsertBr(typeof objSignedMessage.signed_message === 'string' ? objSignedMessage.signed_message : JSON.stringify(objSignedMessage.signed_message, null, '\t'));
$scope.signed_message = objSignedMessage.signed_message;
$scope.address = objSignedMessage.authors[0].address;
$scope.signature = signedMessageBase64;
var validation = require('ocore/validation.js');
Expand Down Expand Up @@ -126,6 +126,14 @@ angular.module('copayApp.controllers').controller('preferencesInformation',

}; // verifySignedMessage

$scope.isString = function(variable) {
return typeof variable === 'string';
};

$scope.prettyPrint = function(variable) {
return $scope.isString(variable) ? variable : JSON.stringify(variable, null, '\t');
};

$scope.hasListOfBalances = function() {
return !!Object.keys($scope.assocListOfBalances || {}).length;
};
Expand Down
19 changes: 10 additions & 9 deletions src/js/services/correspondentListService.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,15 +225,15 @@ angular.module('copayApp.services').factory('correspondentListService', function
if (!info)
return '<i>[invalid signed message]</i>';
var objSignedMessage = info.objSignedMessage;
var displayed_signed_message = (typeof objSignedMessage.signed_message === 'string') ? objSignedMessage.signed_message : JSON.stringify(objSignedMessage.signed_message, null, '\t');
var displayed_signed_message = (typeof objSignedMessage.signed_message === 'string') ? objSignedMessage.signed_message : JSON.stringify(objSignedMessage.signed_message);
var text = 'Message signed by '+objSignedMessage.authors[0].address+': '+escapeHtml(displayed_signed_message);
if (info.bValid)
text += " (valid)";
else if (info.bValid === false)
text += " (invalid)";
else
text += ' (<a ng-click="verifySignedMessage(\''+signedMessageBase64+'\')">verify</a>)';
return toDelayedReplacement('<i>['+text+']</i>');
text += ' (verify)';
return toDelayedReplacement('<a ng-click="verifySignedMessage(\''+signedMessageBase64+'\')"><i>['+text+']</i></a>');
}).replace(url_regexp, function(str){
param_index++;
params[param_index] = str;
Expand Down Expand Up @@ -381,7 +381,8 @@ angular.module('copayApp.services').factory('correspondentListService', function
catch(e){
return str; // it is already escapeHtml'd
}
return escapeHtml(JSON.stringify(obj, null, '\t'));
//return escapeHtml(JSON.stringify(obj, null, '\t'));
return escapeHtml(JSON.stringify(obj));
}

function getPaymentsByAsset(objMultiPaymentRequest){
Expand Down Expand Up @@ -445,21 +446,21 @@ angular.module('copayApp.services').factory('correspondentListService', function
}).replace(/\[(.+?)\]\(profile-request:([\w,]+?)\)/g, function(str, description, fields_list){
return toDelayedReplacement('[Request for profile fields '+fields_list+']');
}).replace(/\[(.+?)\]\(sign-message-request:(.+?)\)/g, function(str, description, message_to_sign){
return toDelayedReplacement('<i>[Request to sign message: '+message_to_sign+']</i>');
return toDelayedReplacement('<i>[Request to sign message: '+tryParseBase64(message_to_sign)+']</i>');
}).replace(/\[(.+?)\]\(signed-message:([\w\/+=]+?)\)/g, function(str, description, signedMessageBase64){
var info = getSignedMessageInfoFromJsonBase64(signedMessageBase64);
if (!info)
return '<i>[invalid signed message]</i>';
var objSignedMessage = info.objSignedMessage;
var displayed_signed_message = (typeof objSignedMessage.signed_message === 'string') ? objSignedMessage.signed_message : JSON.stringify(objSignedMessage.signed_message, null, '\t');
var text = 'Message signed by '+objSignedMessage.authors[0].address+': '+escapeHtmlAndInsertBr(displayed_signed_message);
var displayed_signed_message = (typeof objSignedMessage.signed_message === 'string') ? objSignedMessage.signed_message : JSON.stringify(objSignedMessage.signed_message);
var text = 'Message signed by '+objSignedMessage.authors[0].address+': '+escapeHtml(displayed_signed_message);
if (info.bValid)
text += " (valid)";
else if (info.bValid === false)
text += " (invalid)";
else
text += ' (<a ng-click="verifySignedMessage(\''+signedMessageBase64+'\')">verify</a>)';
return toDelayedReplacement('<i>['+text+']</i>');
text += ' (verify)';
return toDelayedReplacement('<a ng-click="verifySignedMessage(\''+signedMessageBase64+'\')"><i>['+text+']</i></a>');
}).replace(url_regexp, function(str){
param_index++;
params[param_index] = str;
Expand Down