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

render messages to sign if utf-8 encoded #631

Merged
merged 1 commit into from
Nov 24, 2021
Merged
Changes from all commits
Commits
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
11 changes: 4 additions & 7 deletions app/App/Panel/Main/Account/Requests/SignatureRequest/index.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import React from 'react'
import Restore from 'react-restore'
import { fromWei, toAscii, isHex } from 'web3-utils'
import { addHexPrefix } from 'ethereumjs-util'
import { fromWei, isHex } from 'web3-utils'
import { stripHexPrefix } from 'ethereumjs-util'
import svg from '../../../../../../../resources/svg'
import link from '../../../../../../../resources/link'

const DISPLAYABLE = /^[\x20-\x7E]*$/

function decodeMessage (rawMessage) {
if (isHex(rawMessage)) {
// attempt to decode plaintext (unhashed) hex messages to ASCII for display
const ascii = toAscii(addHexPrefix(rawMessage))
return ascii.match(DISPLAYABLE) ? ascii : rawMessage
const buff = Buffer.from(stripHexPrefix(rawMessage), 'hex')
return buff.length === 32 ? rawMessage : buff.toString('utf8')
}

return rawMessage
Expand Down