aboutsummaryrefslogtreecommitdiffstats
path: root/src/ts/0x.js.ts
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2017-05-25 19:57:40 +0800
committerGitHub <noreply@github.com>2017-05-25 19:57:40 +0800
commitf7b8378a6eb4b4c6c3461ff677723869c67a4753 (patch)
treeacd0984b53d3e47c094784e39cd24cbdd75b2b04 /src/ts/0x.js.ts
parentdfb7b039f15d572ddf2e417f71ecb069114100a8 (diff)
parentf3cfd3e708608cc88f61fcb9c6c8b56fcfa9d030 (diff)
downloaddexon-sol-tools-f7b8378a6eb4b4c6c3461ff677723869c67a4753.tar
dexon-sol-tools-f7b8378a6eb4b4c6c3461ff677723869c67a4753.tar.gz
dexon-sol-tools-f7b8378a6eb4b4c6c3461ff677723869c67a4753.tar.bz2
dexon-sol-tools-f7b8378a6eb4b4c6c3461ff677723869c67a4753.tar.lz
dexon-sol-tools-f7b8378a6eb4b4c6c3461ff677723869c67a4753.tar.xz
dexon-sol-tools-f7b8378a6eb4b4c6c3461ff677723869c67a4753.tar.zst
dexon-sol-tools-f7b8378a6eb4b4c6c3461ff677723869c67a4753.zip
Merge pull request #11 from 0xProject/isValidOrderHash
Port isValidOrderHash and tests
Diffstat (limited to 'src/ts/0x.js.ts')
-rw-r--r--src/ts/0x.js.ts19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/ts/0x.js.ts b/src/ts/0x.js.ts
index b71c691d5..ead1f56df 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';
@@ -17,14 +18,14 @@ const MAX_DIGITS_IN_UNSIGNED_256_INT = 78;
export class ZeroEx {
/**
* Verifies that the elliptic curve signature `signature` was generated
- * by signing `data` with the private key corresponding to the `signer` address.
+ * by signing `data` with the private key corresponding to the `signerAddressHex` address.
*/
- public static isValidSignature(data: string, signature: ECSignature, signer: ETHAddressHex): boolean {
- assert.isString('data', data);
+ public static isValidSignature(dataHex: string, signature: ECSignature, signerAddressHex: string): boolean {
+ assert.isHexString('dataHex', dataHex);
assert.doesConformToSchema('signature', signature, ECSignatureSchema);
- assert.isETHAddressHex('signer', signer);
+ assert.isETHAddressHex('signerAddressHex', signerAddressHex);
- 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 === signerAddressHex;
} catch (err) {
return false;
}
@@ -50,6 +51,12 @@ 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]{64}$/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