diff options
Diffstat (limited to 'src/ts/0x.js.ts')
-rw-r--r-- | src/ts/0x.js.ts | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/src/ts/0x.js.ts b/src/ts/0x.js.ts index b71c691d5..cc2adca33 100644 --- a/src/ts/0x.js.ts +++ b/src/ts/0x.js.ts @@ -1,5 +1,6 @@ import * as BigNumber from 'bignumber.js'; import * as ethUtil from 'ethereumjs-util'; +import * as _ from 'lodash'; import {assert} from './utils/assert'; import {ECSignatureSchema} from './schemas/ec_signature_schema'; @@ -19,12 +20,12 @@ export class ZeroEx { * Verifies that the elliptic curve signature `signature` was generated * by signing `data` with the private key corresponding to the `signer` address. */ - public static isValidSignature(data: string, signature: ECSignature, signer: ETHAddressHex): boolean { - assert.isString('data', data); + public static isValidSignature(dataHex: string, signature: ECSignature, signerETHAddressHex: string): boolean { + assert.isHexString('dataHex', dataHex); assert.doesConformToSchema('signature', signature, ECSignatureSchema); - assert.isETHAddressHex('signer', signer); + assert.isETHAddressHex('signerAddress', signerETHAddressHex); - const dataBuff = ethUtil.toBuffer(data); + const dataBuff = ethUtil.toBuffer(dataHex); const msgHashBuff = ethUtil.hashPersonalMessage(dataBuff); try { const pubKey = ethUtil.ecrecover(msgHashBuff, @@ -32,7 +33,7 @@ export class ZeroEx { ethUtil.toBuffer(signature.r), ethUtil.toBuffer(signature.s)); const retrievedAddress = ethUtil.bufferToHex(ethUtil.pubToAddress(pubKey)); - return retrievedAddress === signer; + return retrievedAddress === signerETHAddressHex; } catch (err) { return false; } @@ -50,6 +51,11 @@ export class ZeroEx { const salt = randomNumber.times(factor).round(); return salt; } + /** Checks if order hash is valid */ + public static isValidOrderHash(orderHash: string): boolean { + assert.isString('orderHash', orderHash); + const isValid = /^0x[0-9A-F]{66}$/i.test(orderHash); + return isValid; /* * A unit amount is defined as the amount of a token above the specified decimal places (integer part). * E.g: If a currency has 18 decimal places, 1e18 or one quintillion of the currency is equivalent |