aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/transaction-manager.js
diff options
context:
space:
mode:
authorDan Finlay <dan@danfinlay.com>2017-01-03 06:38:04 +0800
committerDan Finlay <dan@danfinlay.com>2017-01-03 06:38:04 +0800
commit9c6c277b8b5d33568d81a81c3e13fc06b0f7241a (patch)
tree91ad436cc85c614b697b6bcea6142039e350fc95 /app/scripts/transaction-manager.js
parentfb002dc44eae82e0471b8b52acecc61ba5f39332 (diff)
downloadtangerine-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.
Diffstat (limited to 'app/scripts/transaction-manager.js')
-rw-r--r--app/scripts/transaction-manager.js47
1 files changed, 27 insertions, 20 deletions
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