fix sign message

pull/4108/head
yann300 1 year ago
parent b93a417936
commit 2d1b0f7c33
  1. 3
      apps/remix-ide/src/blockchain/providers/injected.ts
  2. 3
      apps/remix-ide/src/blockchain/providers/node.ts
  3. 3
      apps/remix-ide/src/blockchain/providers/vm.ts

@ -1,5 +1,5 @@
import Web3 from 'web3'
import { hashPersonalMessage } from '@ethereumjs/util'
import { hashPersonalMessage, isHexString } from '@ethereumjs/util'
import { ExecutionContext } from '../execution-context'
export class InjectedProvider {
@ -35,6 +35,7 @@ export class InjectedProvider {
signMessage (message, account, _passphrase, cb) {
const messageHash = hashPersonalMessage(Buffer.from(message))
try {
message = isHexString(message) ? message : Web3.utils.utf8ToHex(message)
this.executionContext.web3().eth.personal.sign(message, account, (error, signedData) => {
cb(error, '0x' + messageHash.toString('hex'), signedData)
})

@ -1,5 +1,5 @@
import Web3 from 'web3'
import { hashPersonalMessage } from '@ethereumjs/util'
import { hashPersonalMessage, isHexString } from '@ethereumjs/util'
import { Personal } from 'web3-eth-personal'
import { ExecutionContext } from '../execution-context'
import Config from '../../config'
@ -46,6 +46,7 @@ export class NodeProvider {
const messageHash = hashPersonalMessage(Buffer.from(message))
try {
const personal = new Personal(this.executionContext.web3().currentProvider)
message = isHexString(message) ? message : Web3.utils.utf8ToHex(message)
personal.sign(message, account, passphrase)
.then(signedData => cb(undefined, '0x' + messageHash.toString('hex'), signedData))
.catch(error => cb(error, '0x' + messageHash.toString('hex'), undefined))

@ -1,6 +1,6 @@
import Web3, { FMT_BYTES, FMT_NUMBER, LegacySendAsyncProvider } from 'web3'
import { fromWei, toBigInt } from 'web3-utils'
import { privateToAddress, hashPersonalMessage } from '@ethereumjs/util'
import { privateToAddress, hashPersonalMessage, isHexString } from '@ethereumjs/util'
import { extend, JSONRPCRequestPayload, JSONRPCResponseCallback } from '@remix-project/remix-simulator'
import { ExecutionContext } from '../execution-context'
@ -105,6 +105,7 @@ export class VMProvider {
signMessage (message, account, _passphrase, cb) {
const messageHash = hashPersonalMessage(Buffer.from(message))
message = isHexString(message) ? message : Web3.utils.utf8ToHex(message)
this.web3.eth.sign(message, account)
.then(signedData => cb(null, '0x' + messageHash.toString('hex'), signedData))
.catch(error => cb(error))

Loading…
Cancel
Save