From 5418813ed146630cf2a84da2d9537955771e4d62 Mon Sep 17 00:00:00 2001 From: kumavis Date: Tue, 8 Aug 2017 21:05:59 -0700 Subject: [PATCH] util - sufficientBalance - validate input --- app/scripts/lib/util.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/scripts/lib/util.js b/app/scripts/lib/util.js index 70390e95c..6dee9edf0 100644 --- a/app/scripts/lib/util.js +++ b/app/scripts/lib/util.js @@ -1,5 +1,6 @@ const ethUtil = require('ethereumjs-util') -const BN = ethUtil.BN +const assert = require('assert') +const BN = require('bn.js') module.exports = { getStack, @@ -15,6 +16,10 @@ function getStack () { } function sufficientBalance (txParams, hexBalance) { + // validate hexBalance is a hex string + assert.equal(typeof hexBalance, 'string', 'sufficientBalance - hexBalance is not a hex string') + assert.equal(hexBalance.slice(0, 2), '0x', 'sufficientBalance - hexBalance is not a hex string') + const balance = hexToBn(hexBalance) const value = hexToBn(txParams.value) const gasLimit = hexToBn(txParams.gas)