fix signing messages

pull/1/head
yann300 5 years ago
parent 06e5bd7abc
commit d4112432ed
  1. 4
      src/blockchain/providers/injected.js
  2. 2
      src/blockchain/providers/node.js
  3. 4
      src/blockchain/providers/vm.js

@ -37,8 +37,8 @@ class InjectedProvider {
signMessage (message, account, _passphrase, cb) { signMessage (message, account, _passphrase, cb) {
const hashedMsg = Web3.utils.sha3(message) const hashedMsg = Web3.utils.sha3(message)
try { try {
this.executionContext.web3().eth.sign(account, hashedMsg, (error, signedData) => { this.executionContext.web3().eth.sign(hashedMsg, account, (error, signedData) => {
cb(error.message, hashedMsg, signedData) cb(error, hashedMsg, signedData)
}) })
} catch (e) { } catch (e) {
cb(e.message) cb(e.message)

@ -47,7 +47,7 @@ class NodeProvider {
try { try {
const personal = new Personal(this.executionContext.web3().currentProvider) const personal = new Personal(this.executionContext.web3().currentProvider)
personal.sign(hashedMsg, account, passphrase, (error, signedData) => { personal.sign(hashedMsg, account, passphrase, (error, signedData) => {
cb(error.message, hashedMsg, signedData) cb(error, hashedMsg, signedData)
}) })
} catch (e) { } catch (e) {
cb(e.message) cb(e.message)

@ -57,7 +57,7 @@ class VMProvider {
do { do {
privateKey = crypto.randomBytes(32) privateKey = crypto.randomBytes(32)
} while (!isValidPrivate(privateKey)) } while (!isValidPrivate(privateKey))
this.providers.vm._addAccount(privateKey, '0x56BC75E2D63100000') this._addAccount(privateKey, '0x56BC75E2D63100000')
return cb(null, '0x' + privateToAddress(privateKey).toString('hex')) return cb(null, '0x' + privateToAddress(privateKey).toString('hex'))
} }
@ -78,7 +78,7 @@ class VMProvider {
signMessage (message, account, _passphrase, cb) { signMessage (message, account, _passphrase, cb) {
const personalMsg = ethJSUtil.hashPersonalMessage(Buffer.from(message)) const personalMsg = ethJSUtil.hashPersonalMessage(Buffer.from(message))
const privKey = this.providers.vm.accounts[account].privateKey const privKey = this.accounts[account].privateKey
try { try {
const rsv = ethJSUtil.ecsign(personalMsg, privKey) const rsv = ethJSUtil.ecsign(personalMsg, privKey)
const signedData = ethJSUtil.toRpcSig(rsv.v, rsv.r, rsv.s) const signedData = ethJSUtil.toRpcSig(rsv.v, rsv.r, rsv.s)

Loading…
Cancel
Save