aboutsummaryrefslogtreecommitdiffstats
path: root/packages/order-utils/src/order_hash.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/order-utils/src/order_hash.ts')
-rw-r--r--packages/order-utils/src/order_hash.ts33
1 files changed, 6 insertions, 27 deletions
diff --git a/packages/order-utils/src/order_hash.ts b/packages/order-utils/src/order_hash.ts
index 8e98f8767..b523a3523 100644
--- a/packages/order-utils/src/order_hash.ts
+++ b/packages/order-utils/src/order_hash.ts
@@ -1,31 +1,13 @@
import { schemas, SchemaValidator } from '@0xproject/json-schemas';
import { Order, SignedOrder } from '@0xproject/types';
+import { signTypedDataUtils } from '@0xproject/utils';
import * as _ from 'lodash';
import { assert } from './assert';
import { eip712Utils } from './eip712_utils';
-import { EIP712Schema, EIP712Types } from './types';
const INVALID_TAKER_FORMAT = 'instance.takerAddress is not of a type(s) string';
-const EIP712_ORDER_SCHEMA: EIP712Schema = {
- name: 'Order',
- parameters: [
- { name: 'makerAddress', type: EIP712Types.Address },
- { name: 'takerAddress', type: EIP712Types.Address },
- { name: 'feeRecipientAddress', type: EIP712Types.Address },
- { name: 'senderAddress', type: EIP712Types.Address },
- { name: 'makerAssetAmount', type: EIP712Types.Uint256 },
- { name: 'takerAssetAmount', type: EIP712Types.Uint256 },
- { name: 'makerFee', type: EIP712Types.Uint256 },
- { name: 'takerFee', type: EIP712Types.Uint256 },
- { name: 'expirationTimeSeconds', type: EIP712Types.Uint256 },
- { name: 'salt', type: EIP712Types.Uint256 },
- { name: 'makerAssetData', type: EIP712Types.Bytes },
- { name: 'takerAssetData', type: EIP712Types.Bytes },
- ],
-};
-
export const orderHashUtils = {
/**
* Checks if the supplied hex encoded order hash is valid.
@@ -45,7 +27,7 @@ export const orderHashUtils = {
/**
* Computes the orderHash for a supplied order.
* @param order An object that conforms to the Order or SignedOrder interface definitions.
- * @return The resulting orderHash from hashing the supplied order.
+ * @return Hex encoded string orderHash from hashing the supplied order.
*/
getOrderHashHex(order: SignedOrder | Order): string {
try {
@@ -64,16 +46,13 @@ export const orderHashUtils = {
return orderHashHex;
},
/**
- * Computes the orderHash for a supplied order and returns it as a Buffer
+ * Computes the orderHash for a supplied order
* @param order An object that conforms to the Order or SignedOrder interface definitions.
- * @return The resulting orderHash from hashing the supplied order as a Buffer
+ * @return A Buffer containing the resulting orderHash from hashing the supplied order
*/
getOrderHashBuffer(order: SignedOrder | Order): Buffer {
- const orderParamsHashBuff = eip712Utils.structHash(EIP712_ORDER_SCHEMA, order);
- const orderHashBuff = eip712Utils.createEIP712Message(orderParamsHashBuff, order.exchangeAddress);
+ const typedData = eip712Utils.createOrderTypedData(order);
+ const orderHashBuff = signTypedDataUtils.generateTypedDataHash(typedData);
return orderHashBuff;
},
- _getOrderSchemaBuffer(): Buffer {
- return eip712Utils.compileSchema(EIP712_ORDER_SCHEMA);
- },
};