From 5be5debdf1122d7f9767fa7e5cd23a23d91bf93c Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Thu, 25 May 2017 12:08:54 +0200 Subject: Port isValidOrderHash and tests --- src/ts/0x.js.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/ts/0x.js.ts') diff --git a/src/ts/0x.js.ts b/src/ts/0x.js.ts index 4b9680a18..1f9ea5f9b 100644 --- a/src/ts/0x.js.ts +++ b/src/ts/0x.js.ts @@ -12,13 +12,14 @@ export interface ECSignature { } const MAX_DIGITS_IN_UNSIGNED_256_INT = 78; +const ORDER_HASH_LENGTH = 66; 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 { + public static isValidSignature(data: HexString, signature: ECSignature, signer: ETHAddressHex): boolean { assert.isString('data', data); assert.isObject('signature', signature); assert.isETHAddressHex('signer', signer); @@ -49,4 +50,9 @@ export class ZeroEx { const salt = randomNumber.times(factor).round(); return salt; } + /** Checks if order hash is valid */ + public static isValidOrderHash(orderHash: HexString): boolean { + assert.isHexString('orderHash', orderHash); + return orderHash.length === ORDER_HASH_LENGTH; + } } -- cgit v1.2.3 From 00a16b37e0bd3a394285cd887e8678fb7eb19149 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Thu, 25 May 2017 12:28:28 +0200 Subject: Remove HexString type --- src/ts/0x.js.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/ts/0x.js.ts') diff --git a/src/ts/0x.js.ts b/src/ts/0x.js.ts index 1f9ea5f9b..89d049bec 100644 --- a/src/ts/0x.js.ts +++ b/src/ts/0x.js.ts @@ -19,12 +19,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: HexString, signature: ECSignature, signer: ETHAddressHex): boolean { - assert.isString('data', data); + public static isValidSignature(dataHex: string, signature: ECSignature, signer: ETHAddressHex): boolean { + assert.isHexString('dataHex', dataHex); assert.isObject('signature', signature); assert.isETHAddressHex('signer', signer); - const dataBuff = ethUtil.toBuffer(data); + const dataBuff = ethUtil.toBuffer(dataHex); const msgHashBuff = ethUtil.hashPersonalMessage(dataBuff); try { const pubKey = ethUtil.ecrecover(msgHashBuff, @@ -51,7 +51,7 @@ export class ZeroEx { return salt; } /** Checks if order hash is valid */ - public static isValidOrderHash(orderHash: HexString): boolean { + public static isValidOrderHash(orderHash: string): boolean { assert.isHexString('orderHash', orderHash); return orderHash.length === ORDER_HASH_LENGTH; } -- cgit v1.2.3 From 74a80c28d348da6e4050e43e713113c4c0df87df Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Thu, 25 May 2017 13:00:56 +0200 Subject: Remove type aliases --- src/ts/0x.js.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/ts/0x.js.ts') diff --git a/src/ts/0x.js.ts b/src/ts/0x.js.ts index d189b48b1..a3a83670d 100644 --- a/src/ts/0x.js.ts +++ b/src/ts/0x.js.ts @@ -20,10 +20,10 @@ 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(dataHex: string, signature: ECSignature, signer: ETHAddressHex): boolean { + public static isValidSignature(dataHex: string, signature: ECSignature, signerAddress: string): boolean { assert.isHexString('dataHex', dataHex); assert.doesConformToSchema('signature', signature, ECSignatureSchema); - assert.isETHAddressHex('signer', signer); + assert.isETHAddressHex('signerAddress', signerAddress); const dataBuff = ethUtil.toBuffer(dataHex); const msgHashBuff = ethUtil.hashPersonalMessage(dataBuff); @@ -33,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 === signerAddress; } catch (err) { return false; } -- cgit v1.2.3 From eee06e0cc97333891a84aff22196849105846eb4 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Thu, 25 May 2017 13:42:53 +0200 Subject: Address feedback --- src/ts/0x.js.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'src/ts/0x.js.ts') diff --git a/src/ts/0x.js.ts b/src/ts/0x.js.ts index a3a83670d..bd0ce80e2 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'; @@ -13,17 +14,16 @@ export interface ECSignature { } const MAX_DIGITS_IN_UNSIGNED_256_INT = 78; -const ORDER_HASH_LENGTH = 66; 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(dataHex: string, signature: ECSignature, signerAddress: string): boolean { + public static isValidSignature(dataHex: string, signature: ECSignature, signerETHAddressHex: string): boolean { assert.isHexString('dataHex', dataHex); assert.doesConformToSchema('signature', signature, ECSignatureSchema); - assert.isETHAddressHex('signerAddress', signerAddress); + assert.isETHAddressHex('signerAddress', signerETHAddressHex); const dataBuff = ethUtil.toBuffer(dataHex); const msgHashBuff = ethUtil.hashPersonalMessage(dataBuff); @@ -33,7 +33,7 @@ export class ZeroEx { ethUtil.toBuffer(signature.r), ethUtil.toBuffer(signature.s)); const retrievedAddress = ethUtil.bufferToHex(ethUtil.pubToAddress(pubKey)); - return retrievedAddress === signerAddress; + return retrievedAddress === signerETHAddressHex; } catch (err) { return false; } @@ -53,7 +53,8 @@ export class ZeroEx { } /** Checks if order hash is valid */ public static isValidOrderHash(orderHash: string): boolean { - assert.isHexString('orderHash', orderHash); - return orderHash.length === ORDER_HASH_LENGTH; + assert.isString('orderHash', orderHash); + const isValid = /^0x[0-9A-F]{66}$/i.test(orderHash); + return isValid; } } -- cgit v1.2.3 From 00b64014525b4aabd82a61c1330a3f126554016a Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Thu, 25 May 2017 13:47:04 +0200 Subject: Fix braces --- src/ts/0x.js.ts | 1 + 1 file changed, 1 insertion(+) (limited to 'src/ts/0x.js.ts') diff --git a/src/ts/0x.js.ts b/src/ts/0x.js.ts index cc2adca33..5e500b481 100644 --- a/src/ts/0x.js.ts +++ b/src/ts/0x.js.ts @@ -56,6 +56,7 @@ export class ZeroEx { 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 -- cgit v1.2.3 From 3fe582d94c587cf3c38b6c42988890dcd6d54659 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Thu, 25 May 2017 13:50:05 +0200 Subject: Fix tests --- src/ts/0x.js.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/ts/0x.js.ts') diff --git a/src/ts/0x.js.ts b/src/ts/0x.js.ts index 5e500b481..f52750eb6 100644 --- a/src/ts/0x.js.ts +++ b/src/ts/0x.js.ts @@ -54,7 +54,7 @@ export class ZeroEx { /** 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); + const isValid = /^0x[0-9A-F]{64}$/i.test(orderHash); return isValid; } /* -- cgit v1.2.3 From 612019f5e7c75210ecdb3d81f4337a5bf16b45e5 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Thu, 25 May 2017 13:53:54 +0200 Subject: Fix comment --- src/ts/0x.js.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/ts/0x.js.ts') diff --git a/src/ts/0x.js.ts b/src/ts/0x.js.ts index f52750eb6..c0aaa06fa 100644 --- a/src/ts/0x.js.ts +++ b/src/ts/0x.js.ts @@ -18,7 +18,7 @@ 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 `signerETHAddressHex` address. */ public static isValidSignature(dataHex: string, signature: ECSignature, signerETHAddressHex: string): boolean { assert.isHexString('dataHex', dataHex); -- cgit v1.2.3 From f3cfd3e708608cc88f61fcb9c6c8b56fcfa9d030 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Thu, 25 May 2017 13:54:56 +0200 Subject: Get rid of ETH --- src/ts/0x.js.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/ts/0x.js.ts') diff --git a/src/ts/0x.js.ts b/src/ts/0x.js.ts index c0aaa06fa..ead1f56df 100644 --- a/src/ts/0x.js.ts +++ b/src/ts/0x.js.ts @@ -18,12 +18,12 @@ 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 `signerETHAddressHex` address. + * by signing `data` with the private key corresponding to the `signerAddressHex` address. */ - public static isValidSignature(dataHex: string, signature: ECSignature, signerETHAddressHex: string): boolean { + public static isValidSignature(dataHex: string, signature: ECSignature, signerAddressHex: string): boolean { assert.isHexString('dataHex', dataHex); assert.doesConformToSchema('signature', signature, ECSignatureSchema); - assert.isETHAddressHex('signerAddress', signerETHAddressHex); + assert.isETHAddressHex('signerAddressHex', signerAddressHex); const dataBuff = ethUtil.toBuffer(dataHex); const msgHashBuff = ethUtil.hashPersonalMessage(dataBuff); @@ -33,7 +33,7 @@ export class ZeroEx { ethUtil.toBuffer(signature.r), ethUtil.toBuffer(signature.s)); const retrievedAddress = ethUtil.bufferToHex(ethUtil.pubToAddress(pubKey)); - return retrievedAddress === signerETHAddressHex; + return retrievedAddress === signerAddressHex; } catch (err) { return false; } -- cgit v1.2.3