diff options
author | Dan Finlay <dan@danfinlay.com> | 2017-01-03 06:38:04 +0800 |
---|---|---|
committer | Dan Finlay <dan@danfinlay.com> | 2017-01-03 06:38:04 +0800 |
commit | 9c6c277b8b5d33568d81a81c3e13fc06b0f7241a (patch) | |
tree | 91ad436cc85c614b697b6bcea6142039e350fc95 | |
parent | fb002dc44eae82e0471b8b52acecc61ba5f39332 (diff) | |
download | tangerine-wallet-browser-9c6c277b8b5d33568d81a81c3e13fc06b0f7241a.tar tangerine-wallet-browser-9c6c277b8b5d33568d81a81c3e13fc06b0f7241a.tar.gz tangerine-wallet-browser-9c6c277b8b5d33568d81a81c3e13fc06b0f7241a.tar.bz2 tangerine-wallet-browser-9c6c277b8b5d33568d81a81c3e13fc06b0f7241a.tar.lz tangerine-wallet-browser-9c6c277b8b5d33568d81a81c3e13fc06b0f7241a.tar.xz tangerine-wallet-browser-9c6c277b8b5d33568d81a81c3e13fc06b0f7241a.tar.zst tangerine-wallet-browser-9c6c277b8b5d33568d81a81c3e13fc06b0f7241a.zip |
Add replay protection to Transaction Manager
Fixes #897
Needs tests.
-rw-r--r-- | app/scripts/metamask-controller.js | 6 | ||||
-rw-r--r-- | app/scripts/transaction-manager.js | 47 |
2 files changed, 30 insertions, 23 deletions
diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index 5df10672a..31bb4a9c2 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -177,8 +177,8 @@ module.exports = class MetamaskController { // tx signing approveTransaction: this.newUnsignedTransaction.bind(this), signTransaction: (...args) => { - this.setupSigningListners(...args) - this.txManager.formatTxForSigining(...args) + this.setupSigningListeners(...args) + this.txManager.formatTxForSigning(...args) this.sendUpdate() }, @@ -257,7 +257,7 @@ module.exports = class MetamaskController { }) } - setupSigningListners (txParams) { + setupSigningListeners (txParams) { var txId = txParams.metamaskId // apply event listeners for signing and formating events this.txManager.once(`${txId}:formatted`, this.keyringController.signTransaction.bind(this.keyringController)) diff --git a/app/scripts/transaction-manager.js b/app/scripts/transaction-manager.js index fd136a51b..3cf12b016 100644 --- a/app/scripts/transaction-manager.js +++ b/app/scripts/transaction-manager.js @@ -137,26 +137,33 @@ module.exports = class TransactionManager extends EventEmitter { } // formats txParams so the keyringController can sign it - formatTxForSigining (txParams, cb) { - var address = txParams.from - var metaTx = this.getTx(txParams.metamaskId) - var gasMultiplier = metaTx.gasMultiplier - var gasPrice = new BN(ethUtil.stripHexPrefix(txParams.gasPrice), 16) - gasPrice = gasPrice.mul(new BN(gasMultiplier * 100, 10)).div(new BN(100, 10)) - txParams.gasPrice = ethUtil.intToHex(gasPrice.toNumber()) - - // normalize values - txParams.to = normalize(txParams.to) - txParams.from = normalize(txParams.from) - txParams.value = normalize(txParams.value) - txParams.data = normalize(txParams.data) - txParams.gasLimit = normalize(txParams.gasLimit || txParams.gas) - txParams.nonce = normalize(txParams.nonce) - const ethTx = new Transaction(txParams) - - // listener is assigned in metamaskController - this.emit(`${txParams.metamaskId}:formatted`, ethTx, address, txParams.metamaskId, cb) - } + formatTxForSigning (txParams, cb) { + this.getNetwork((err, networkId) => { + if (err) { + return cb(err) + } + + var address = txParams.from + var metaTx = this.getTx(txParams.metamaskId) + var gasMultiplier = metaTx.gasMultiplier + var gasPrice = new BN(ethUtil.stripHexPrefix(txParams.gasPrice), 16) + gasPrice = gasPrice.mul(new BN(gasMultiplier * 100, 10)).div(new BN(100, 10)) + txParams.gasPrice = ethUtil.intToHex(gasPrice.toNumber()) + + // normalize values + txParams.to = normalize(txParams.to) + txParams.from = normalize(txParams.from) + txParams.value = normalize(txParams.value) + txParams.data = normalize(txParams.data) + txParams.gasLimit = normalize(txParams.gasLimit || txParams.gas) + txParams.nonce = normalize(txParams.nonce) + + const ethTx = new Transaction(txParams, parseInt(networkId)) + + // listener is assigned in metamaskController + this.emit(`${txParams.metamaskId}:formatted`, ethTx, address, txParams.metamaskId, cb) + }) + } // receives a signed tx object and updates the tx hash // and pass it to the cb to be sent off |