aboutsummaryrefslogtreecommitdiffstats
path: root/src/ts/utils
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2017-05-25 18:08:54 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2017-05-25 18:08:54 +0800
commit5be5debdf1122d7f9767fa7e5cd23a23d91bf93c (patch)
tree66c7a8c97350b198d3cc12dbd2a968e9a5953d4e /src/ts/utils
parent334d2f175fd9dcb3f9e336250d21c7916a2671ae (diff)
downloaddexon-sol-tools-5be5debdf1122d7f9767fa7e5cd23a23d91bf93c.tar
dexon-sol-tools-5be5debdf1122d7f9767fa7e5cd23a23d91bf93c.tar.gz
dexon-sol-tools-5be5debdf1122d7f9767fa7e5cd23a23d91bf93c.tar.bz2
dexon-sol-tools-5be5debdf1122d7f9767fa7e5cd23a23d91bf93c.tar.lz
dexon-sol-tools-5be5debdf1122d7f9767fa7e5cd23a23d91bf93c.tar.xz
dexon-sol-tools-5be5debdf1122d7f9767fa7e5cd23a23d91bf93c.tar.zst
dexon-sol-tools-5be5debdf1122d7f9767fa7e5cd23a23d91bf93c.zip
Port isValidOrderHash and tests
Diffstat (limited to 'src/ts/utils')
-rw-r--r--src/ts/utils/assert.ts6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/ts/utils/assert.ts b/src/ts/utils/assert.ts
index a29ae922d..602361233 100644
--- a/src/ts/utils/assert.ts
+++ b/src/ts/utils/assert.ts
@@ -2,6 +2,8 @@ import * as _ from 'lodash';
import * as BigNumber from 'bignumber.js';
import Web3 = require('web3');
+const HEX_REGEX = /^0x([0-9A-F]{2})*$/i;
+
export const assert = {
isBigNumber(variableName: string, value: BigNumber.BigNumber) {
const isBigNumber = _.isObject(value) && value.isBigNumber;
@@ -10,6 +12,10 @@ export const assert = {
isString(variableName: string, value: string) {
this.assert(_.isString(value), this.typeAssertionMessage(variableName, 'string', value));
},
+ isHexString(variableName: string, value: string) {
+ this.assert(_.isString(value) && HEX_REGEX.test(value),
+ this.typeAssertionMessage(variableName, 'HexString', value));
+ },
isETHAddressHex(variableName: string, value: ETHAddressHex) {
const web3 = new Web3();
this.assert(web3.isAddress(value), this.typeAssertionMessage(variableName, 'ETHAddressHex', value));