mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Fixed encoding
This commit is contained in:
parent
6253885e28
commit
fba7a50e1b
@ -118,21 +118,8 @@ module.exports = class PersonalMessageManager extends EventEmitter{
|
|||||||
log.debug(`Message was not hex encoded, interpreting as utf8.`)
|
log.debug(`Message was not hex encoded, interpreting as utf8.`)
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.hexEncode(data)
|
return ethUtil.bufferToHex(new Buffer(data, 'utf8'))
|
||||||
}
|
|
||||||
|
|
||||||
hexEncode(text){
|
|
||||||
var hex, i
|
|
||||||
|
|
||||||
var result = ''
|
|
||||||
for (i = 0; i < text.length; i++) {
|
|
||||||
hex = text.charCodeAt(i).toString(16)
|
|
||||||
result += ('000' + hex).slice(-4)
|
|
||||||
}
|
|
||||||
return '0x' + result
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -91,7 +91,7 @@ describe('Personal Message Manager', function() {
|
|||||||
it('converts text to a utf8 hex string', function() {
|
it('converts text to a utf8 hex string', function() {
|
||||||
var input = 'hello'
|
var input = 'hello'
|
||||||
var output = messageManager.normalizeMsgData(input)
|
var output = messageManager.normalizeMsgData(input)
|
||||||
assert.equal(output, '0x00680065006c006c006f', 'predictably hex encoded')
|
assert.equal(output, '0x68656c6c6f', 'predictably hex encoded')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('tolerates a hex prefix', function() {
|
it('tolerates a hex prefix', function() {
|
||||||
|
Loading…
Reference in New Issue
Block a user