diff options
author | frankiebee <frankie.diamond@gmail.com> | 2017-03-08 09:59:21 +0800 |
---|---|---|
committer | frankiebee <frankie.diamond@gmail.com> | 2017-03-08 09:59:21 +0800 |
commit | af5ad218e21096b499e7dc264c4dad4f7d8dbdde (patch) | |
tree | 5c25c606956e223c4a8e66797f25e735cd81b76a /app/scripts/lib/personal-message-manager.js | |
parent | 3e8b584c9811b06526e69203a5e03f8eb82e8211 (diff) | |
parent | 22785a4cf1007904594cc486678d3ce119146e2f (diff) | |
download | tangerine-wallet-browser-af5ad218e21096b499e7dc264c4dad4f7d8dbdde.tar tangerine-wallet-browser-af5ad218e21096b499e7dc264c4dad4f7d8dbdde.tar.gz tangerine-wallet-browser-af5ad218e21096b499e7dc264c4dad4f7d8dbdde.tar.bz2 tangerine-wallet-browser-af5ad218e21096b499e7dc264c4dad4f7d8dbdde.tar.lz tangerine-wallet-browser-af5ad218e21096b499e7dc264c4dad4f7d8dbdde.tar.xz tangerine-wallet-browser-af5ad218e21096b499e7dc264c4dad4f7d8dbdde.tar.zst tangerine-wallet-browser-af5ad218e21096b499e7dc264c4dad4f7d8dbdde.zip |
Merge branch 'master' into i#1032
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')) } + } + |