Skip to content

Commit

Permalink
EthereumJsWalletProviderr: fix signature chain mismatch
Browse files Browse the repository at this point in the history
  • Loading branch information
monokh committed Dec 6, 2019
1 parent 273709a commit f180faa
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { BigNumber } from 'bignumber.js'
import { fromMasterSeed } from 'hdkey'
import * as ethUtil from 'ethereumjs-util'
import { Transaction } from 'ethereumjs-tx'
import Common from 'ethereumjs-common'

import { version } from '../package.json'

Expand Down Expand Up @@ -76,8 +77,7 @@ export default class EthereumJsWalletProvider extends Provider {
to: to ? ensure0x(to) : null,
from: ensure0x(from),
value: ensure0x(BigNumber(value).toString(16)),
data: data ? ensure0x(data) : undefined,
chainId: ensure0x(BigNumber(this._network.chainId).toString(16))
data: data ? ensure0x(data) : undefined
}

const [ nonce, gasPrice, gasLimit ] = await Promise.all([
Expand All @@ -90,7 +90,17 @@ export default class EthereumJsWalletProvider extends Provider {
txData.gasPrice = gasPrice
txData.gasLimit = gasLimit

const tx = new Transaction(txData)
let common
if (!(this._network.name === 'local')) {
const baseChain = this._network.name
common = Common.forCustomChain(baseChain, {
name: this._network.name,
chainId: this._network.chainId,
networkId: this._network.networkId
}, 'istanbul')
}

const tx = new Transaction(txData, { common })
tx.sign(hdKey._privateKey)
const serializedTx = tx.serialize().toString('hex')

Expand Down
70 changes: 66 additions & 4 deletions packages/ethereum-js-wallet-provider/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/ethereum-js-wallet-provider/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"bitcoinjs-lib": "^5.1.5",
"bitcoinjs-message": "^2.1.0",
"coinselect": "^3.1.11",
"ethereumjs-common": "^1.4.0",
"ethereumjs-tx": "^2.1.1",
"ethereumjs-util": "^6.1.0",
"hdkey": "^1.1.1"
Expand Down

0 comments on commit f180faa

Please sign in to comment.