aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/lib
diff options
context:
space:
mode:
authorDan Finlay <dan@danfinlay.com>2017-03-07 07:03:49 +0800
committerDan Finlay <dan@danfinlay.com>2017-03-07 07:04:11 +0800
commit9bd8c5f723abef25b8864457df7207eb361be8e3 (patch)
tree93ba58224b857f2db55b75caff3ad3159e17dedd /app/scripts/lib
parentf9b2c12dc34992deb1ef95f4a1f7572aac4aa1af (diff)
downloadtangerine-wallet-browser-9bd8c5f723abef25b8864457df7207eb361be8e3.tar
tangerine-wallet-browser-9bd8c5f723abef25b8864457df7207eb361be8e3.tar.gz
tangerine-wallet-browser-9bd8c5f723abef25b8864457df7207eb361be8e3.tar.bz2
tangerine-wallet-browser-9bd8c5f723abef25b8864457df7207eb361be8e3.tar.lz
tangerine-wallet-browser-9bd8c5f723abef25b8864457df7207eb361be8e3.tar.xz
tangerine-wallet-browser-9bd8c5f723abef25b8864457df7207eb361be8e3.tar.zst
tangerine-wallet-browser-9bd8c5f723abef25b8864457df7207eb361be8e3.zip
Render personal_sign messages as utf-8 text
Calls to `personal_sign` are now: - When hex encoded, preserved as hex encoded, but displayed as utf-8 text. - When not hex encoded, decoded as utf-8 text as hex for signing. - The messages proposed for signing are displayed as UTF-8 text. - When the message cannot be rendered as UTF-8 text, it is displayed as hexadecimal. Fixes #1173
Diffstat (limited to 'app/scripts/lib')
-rw-r--r--app/scripts/lib/personal-message-manager.js22
1 files changed, 14 insertions, 8 deletions
diff --git a/app/scripts/lib/personal-message-manager.js b/app/scripts/lib/personal-message-manager.js
index 3b8510767..04dba4a90 100644
--- a/app/scripts/lib/personal-message-manager.js
+++ b/app/scripts/lib/personal-message-manager.js
@@ -2,6 +2,7 @@ const EventEmitter = require('events')
const ObservableStore = require('obs-store')
const ethUtil = require('ethereumjs-util')
const createId = require('./random-id')
+const hexRe = /^[0-9A-Fa-f]+$/g
module.exports = class PersonalMessageManager extends EventEmitter{
@@ -24,7 +25,8 @@ module.exports = class PersonalMessageManager extends EventEmitter{
}
addUnapprovedMessage (msgParams) {
- msgParams.data = normalizeMsgData(msgParams.data)
+ log.debug(`PersonalMessageManager addUnapprovedMessage: ${JSON.stringify(msgParams)}`)
+ msgParams.data = this.normalizeMsgData(msgParams.data)
// create txData obj with parameters and meta data
var time = (new Date()).getTime()
var msgId = createId()
@@ -106,14 +108,18 @@ module.exports = class PersonalMessageManager extends EventEmitter{
this.emit('updateBadge')
}
-}
+ normalizeMsgData(data) {
+ try {
+ const stripped = ethUtil.stripHexPrefix(data)
+ if (stripped.match(hexRe)) {
+ return stripped
+ }
+ } catch (e) {
+ log.debug(`Message was not hex encoded, interpreting as utf8.`)
+ }
-function normalizeMsgData(data) {
- if (data.slice(0, 2) === '0x') {
- // data is already hex
- return data
- } else {
- // data is unicode, convert to hex
return ethUtil.bufferToHex(new Buffer(data, 'utf8'))
}
+
}
+