aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contracts/src/utils
diff options
context:
space:
mode:
authorJacob Evans <jacob@dekz.net>2018-05-08 13:31:56 +0800
committerFabio Berger <me@fabioberger.com>2018-05-25 07:00:22 +0800
commit65676c22f92996feb0e3cb98daa3d8ce7b3854e9 (patch)
tree640f76ff3186b3360bad2806272b6aa4f5974f2a /packages/contracts/src/utils
parentbc550c3265cfcb92785d90c075a120d8c90d15f7 (diff)
downloaddexon-sol-tools-65676c22f92996feb0e3cb98daa3d8ce7b3854e9.tar
dexon-sol-tools-65676c22f92996feb0e3cb98daa3d8ce7b3854e9.tar.gz
dexon-sol-tools-65676c22f92996feb0e3cb98daa3d8ce7b3854e9.tar.bz2
dexon-sol-tools-65676c22f92996feb0e3cb98daa3d8ce7b3854e9.tar.lz
dexon-sol-tools-65676c22f92996feb0e3cb98daa3d8ce7b3854e9.tar.xz
dexon-sol-tools-65676c22f92996feb0e3cb98daa3d8ce7b3854e9.tar.zst
dexon-sol-tools-65676c22f92996feb0e3cb98daa3d8ce7b3854e9.zip
Update order hash to match latest eip712
Diffstat (limited to 'packages/contracts/src/utils')
-rw-r--r--packages/contracts/src/utils/order_utils.ts45
1 files changed, 26 insertions, 19 deletions
diff --git a/packages/contracts/src/utils/order_utils.ts b/packages/contracts/src/utils/order_utils.ts
index 8adc6b735..688259b6c 100644
--- a/packages/contracts/src/utils/order_utils.ts
+++ b/packages/contracts/src/utils/order_utils.ts
@@ -1,7 +1,5 @@
import { BigNumber } from '@0xproject/utils';
-import { Web3Wrapper } from '@0xproject/web3-wrapper';
import ethUtil = require('ethereumjs-util');
-import * as _ from 'lodash';
import { crypto } from './crypto';
import { CancelOrder, MatchOrder, OrderStruct, SignatureType, SignedOrder, UnsignedOrder } from './types';
@@ -39,22 +37,31 @@ export const orderUtils = {
};
return orderStruct;
},
- getOrderHashBuff(order: SignedOrder | UnsignedOrder): Buffer {
+ getOrderSchemaHex(): string {
const orderSchemaHashBuff = crypto.solSHA3([
- 'address exchangeAddress',
- 'address makerAddress',
- 'address takerAddress',
- 'address feeRecipientAddress',
- 'address senderAddress',
- 'uint256 makerAssetAmount',
- 'uint256 takerAssetAmount',
- 'uint256 makerFee',
- 'uint256 takerFee',
- 'uint256 expirationTimeSeconds',
- 'uint256 salt',
- 'bytes makerAssetData',
- 'bytes takerAssetData',
+ 'Order(',
+ 'address exchangeAddress,',
+ 'address makerAddress,',
+ 'address takerAddress,',
+ 'address feeRecipientAddress,',
+ 'address senderAddress,',
+ 'uint256 makerAssetAmount,',
+ 'uint256 takerAssetAmount,',
+ 'uint256 makerFee,',
+ 'uint256 takerFee,',
+ 'uint256 expirationTimeSeconds,',
+ 'uint256 salt,',
+ 'bytes makerAssetData,',
+ 'bytes takerAssetData,',
+ ')',
]);
+ const schemaHashHex = `0x${orderSchemaHashBuff.toString('hex')}`;
+ return schemaHashHex;
+ },
+ getOrderHashBuff(order: SignedOrder | UnsignedOrder): Buffer {
+ const makerAssetDataHash = crypto.solSHA3([ethUtil.toBuffer(order.makerAssetData)]);
+ const takerAssetDataHash = crypto.solSHA3([ethUtil.toBuffer(order.takerAssetData)]);
+
const orderParamsHashBuff = crypto.solSHA3([
order.exchangeAddress,
order.makerAddress,
@@ -67,11 +74,11 @@ export const orderUtils = {
order.takerFee,
order.expirationTimeSeconds,
order.salt,
- ethUtil.toBuffer(order.makerAssetData),
- ethUtil.toBuffer(order.takerAssetData),
+ makerAssetDataHash,
+ takerAssetDataHash,
]);
- const orderSchemaHashHex = `0x${orderSchemaHashBuff.toString('hex')}`;
const orderParamsHashHex = `0x${orderParamsHashBuff.toString('hex')}`;
+ const orderSchemaHashHex = orderUtils.getOrderSchemaHex();
const orderHashBuff = crypto.solSHA3([new BigNumber(orderSchemaHashHex), new BigNumber(orderParamsHashHex)]);
return orderHashBuff;
},