diff options
author | kumavis <kumavis@users.noreply.github.com> | 2017-03-07 08:51:16 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-07 08:51:16 +0800 |
commit | 2acf991b67bc42fb904ff77af6ff6a7ca3a683fd (patch) | |
tree | e2c21a396f4cbb4653693082d1a6d2a6bc4e8696 /app/scripts/lib/personal-message-manager.js | |
parent | e91ddfcacc37c0b45289a6df017c32e803b55d88 (diff) | |
parent | 51aa95a65cf0a12d273fc3655b5407d3e23f1997 (diff) | |
download | tangerine-wallet-browser-2acf991b67bc42fb904ff77af6ff6a7ca3a683fd.tar tangerine-wallet-browser-2acf991b67bc42fb904ff77af6ff6a7ca3a683fd.tar.gz tangerine-wallet-browser-2acf991b67bc42fb904ff77af6ff6a7ca3a683fd.tar.bz2 tangerine-wallet-browser-2acf991b67bc42fb904ff77af6ff6a7ca3a683fd.tar.lz tangerine-wallet-browser-2acf991b67bc42fb904ff77af6ff6a7ca3a683fd.tar.xz tangerine-wallet-browser-2acf991b67bc42fb904ff77af6ff6a7ca3a683fd.tar.zst tangerine-wallet-browser-2acf991b67bc42fb904ff77af6ff6a7ca3a683fd.zip |
Merge pull request #1177 from MetaMask/i1173-ShowPersonalMessage
Render personal_sign messages as utf-8 text
Diffstat (limited to 'app/scripts/lib/personal-message-manager.js')
-rw-r--r-- | app/scripts/lib/personal-message-manager.js | 22 |
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..bbc978446 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 ethUtil.addHexPrefix(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')) } + } + |