From 38cc933bc6b6ca321d88e354114fb08e5000ebdf Mon Sep 17 00:00:00 2001 From: barakman Date: Sun, 13 Oct 2019 06:30:27 +0300 Subject: [PATCH] Ensure the immutability of function `signTransaction` input parameter (#3119) * Ensure the immutability of function `signTransaction` input parameter * Replace `JSON.parse(JSON.stringify(tx))` with `_.clone(tx)` * Update CHANGELOG.md --- CHANGELOG.md | 1 + packages/web3-eth-accounts/src/index.js | 12 +++++------- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c1539139dc6..5086a1bdcb6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -69,4 +69,5 @@ Released with 1.0.0-beta.37 code base. - Fix accessing event.name where event is undefined (#3014) - Fix bubbling up tx signing errors (#2063, #3105) - HttpProvider: CORS issue with Firefox and Safari (#2978) +- Ensure the immutability of the `tx` object passed to function `signTransaction` (#2190) - Gas check fixed (#2381) diff --git a/packages/web3-eth-accounts/src/index.js b/packages/web3-eth-accounts/src/index.js index b45e830c9d9..211e2925ae5 100644 --- a/packages/web3-eth-accounts/src/index.js +++ b/packages/web3-eth-accounts/src/index.js @@ -162,13 +162,11 @@ Accounts.prototype.signTransaction = function signTransaction(tx, privateKey, ca } try { - tx = helpers.formatters.inputCallFormatter(tx); - - var transaction = tx; - transaction.to = tx.to || '0x'; - transaction.data = tx.data || '0x'; - transaction.value = tx.value || '0x'; - transaction.chainId = utils.numberToHex(tx.chainId); + var transaction = helpers.formatters.inputCallFormatter(_.clone(tx)); + transaction.to = transaction.to || '0x'; + transaction.data = transaction.data || '0x'; + transaction.value = transaction.value || '0x'; + transaction.chainId = utils.numberToHex(transaction.chainId); var rlpEncoded = RLP.encode([ Bytes.fromNat(transaction.nonce),