aboutsummaryrefslogtreecommitdiffstats
path: root/packages/order-utils/src/order_hash.ts
diff options
context:
space:
mode:
authorAmir Bandeali <abandeali1@gmail.com>2019-02-06 02:03:30 +0800
committerGitHub <noreply@github.com>2019-02-06 02:03:30 +0800
commitb5eb47f60930d040b94177023cd147834f98db1d (patch)
tree62ea668a6bbb6394b472e5433756e052e447b682 /packages/order-utils/src/order_hash.ts
parent69c7c03fb34b3f21f65c40b73baa21184a296fb2 (diff)
parentaf4ed0f39c9eb3e314a6b05de9cedab98e7cb233 (diff)
downloaddexon-0x-contracts-b5eb47f60930d040b94177023cd147834f98db1d.tar
dexon-0x-contracts-b5eb47f60930d040b94177023cd147834f98db1d.tar.gz
dexon-0x-contracts-b5eb47f60930d040b94177023cd147834f98db1d.tar.bz2
dexon-0x-contracts-b5eb47f60930d040b94177023cd147834f98db1d.tar.lz
dexon-0x-contracts-b5eb47f60930d040b94177023cd147834f98db1d.tar.xz
dexon-0x-contracts-b5eb47f60930d040b94177023cd147834f98db1d.tar.zst
dexon-0x-contracts-b5eb47f60930d040b94177023cd147834f98db1d.zip
Merge pull request #1576 from 0xProject/feat/transaction-hash
Add transactionHashUtils to order-utils package
Diffstat (limited to 'packages/order-utils/src/order_hash.ts')
-rw-r--r--packages/order-utils/src/order_hash.ts17
1 files changed, 15 insertions, 2 deletions
diff --git a/packages/order-utils/src/order_hash.ts b/packages/order-utils/src/order_hash.ts
index c8e9be71e..ce7e6d85f 100644
--- a/packages/order-utils/src/order_hash.ts
+++ b/packages/order-utils/src/order_hash.ts
@@ -4,6 +4,7 @@ import { signTypedDataUtils } from '@0x/utils';
import * as _ from 'lodash';
import { assert } from './assert';
+import { constants } from './constants';
import { eip712Utils } from './eip712_utils';
const INVALID_TAKER_FORMAT = 'instance.takerAddress is not of a type(s) string';
@@ -34,8 +35,9 @@ export const orderHashUtils = {
assert.doesConformToSchema('order', order, schemas.orderSchema, [schemas.hexSchema]);
} catch (error) {
if (_.includes(error.message, INVALID_TAKER_FORMAT)) {
- const errMsg =
- 'Order taker must be of type string. If you want anyone to be able to fill an order - pass ZeroEx.NULL_ADDRESS';
+ const errMsg = `Order taker must be of type string. If you want anyone to be able to fill an order - pass ${
+ constants.NULL_ADDRESS
+ }`;
throw new Error(errMsg);
}
throw error;
@@ -51,6 +53,17 @@ export const orderHashUtils = {
* @return A Buffer containing the resulting orderHash from hashing the supplied order
*/
getOrderHashBuffer(order: SignedOrder | Order): Buffer {
+ try {
+ assert.doesConformToSchema('order', order, schemas.orderSchema, [schemas.hexSchema]);
+ } catch (error) {
+ if (_.includes(error.message, INVALID_TAKER_FORMAT)) {
+ const errMsg = `Order taker must be of type string. If you want anyone to be able to fill an order - pass ${
+ constants.NULL_ADDRESS
+ }`;
+ throw new Error(errMsg);
+ }
+ throw error;
+ }
const typedData = eip712Utils.createOrderTypedData(order);
const orderHashBuff = signTypedDataUtils.generateTypedDataHash(typedData);
return orderHashBuff;