aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contracts/src/utils
diff options
context:
space:
mode:
authorJacob Evans <jacob@dekz.net>2018-05-24 08:27:49 +0800
committerFabio Berger <me@fabioberger.com>2018-05-25 07:00:22 +0800
commit3cc8af819c9f62f42e7cb3d03f896b35cfc10d05 (patch)
treea03f912c39990d7925390d02cdef73b8ef1b3ea9 /packages/contracts/src/utils
parentfcf4a958c3daa4dd7911de48001a8e235c9eb5ac (diff)
downloaddexon-sol-tools-3cc8af819c9f62f42e7cb3d03f896b35cfc10d05.tar
dexon-sol-tools-3cc8af819c9f62f42e7cb3d03f896b35cfc10d05.tar.gz
dexon-sol-tools-3cc8af819c9f62f42e7cb3d03f896b35cfc10d05.tar.bz2
dexon-sol-tools-3cc8af819c9f62f42e7cb3d03f896b35cfc10d05.tar.lz
dexon-sol-tools-3cc8af819c9f62f42e7cb3d03f896b35cfc10d05.tar.xz
dexon-sol-tools-3cc8af819c9f62f42e7cb3d03f896b35cfc10d05.tar.zst
dexon-sol-tools-3cc8af819c9f62f42e7cb3d03f896b35cfc10d05.zip
Use domain separator for exchange address
Diffstat (limited to 'packages/contracts/src/utils')
-rw-r--r--packages/contracts/src/utils/order_utils.ts23
1 files changed, 19 insertions, 4 deletions
diff --git a/packages/contracts/src/utils/order_utils.ts b/packages/contracts/src/utils/order_utils.ts
index 688259b6c..969d43dd1 100644
--- a/packages/contracts/src/utils/order_utils.ts
+++ b/packages/contracts/src/utils/order_utils.ts
@@ -2,7 +2,7 @@ import { BigNumber } from '@0xproject/utils';
import ethUtil = require('ethereumjs-util');
import { crypto } from './crypto';
-import { CancelOrder, MatchOrder, OrderStruct, SignatureType, SignedOrder, UnsignedOrder } from './types';
+import { CancelOrder, MatchOrder, OrderStruct, SignedOrder, UnsignedOrder } from './types';
export const orderUtils = {
createFill: (signedOrder: SignedOrder, takerAssetFillAmount?: BigNumber) => {
@@ -37,10 +37,19 @@ export const orderUtils = {
};
return orderStruct;
},
+ getDomainSeparatorSchemaHex(): string {
+ const domainSeparatorSchemaHashBuff = crypto.solSHA3(['DomainSeparator(address contract)']);
+ const schemaHashHex = `0x${domainSeparatorSchemaHashBuff.toString('hex')}`;
+ return schemaHashHex;
+ },
+ getDomainSeparatorHashHex(exchangeAddress: string): string {
+ const domainSeparatorHashBuff = crypto.solSHA3([exchangeAddress]);
+ const domainSeparatorHashHex = `0x${domainSeparatorHashBuff.toString('hex')}`;
+ return domainSeparatorHashHex;
+ },
getOrderSchemaHex(): string {
const orderSchemaHashBuff = crypto.solSHA3([
'Order(',
- 'address exchangeAddress,',
'address makerAddress,',
'address takerAddress,',
'address feeRecipientAddress,',
@@ -63,7 +72,6 @@ export const orderUtils = {
const takerAssetDataHash = crypto.solSHA3([ethUtil.toBuffer(order.takerAssetData)]);
const orderParamsHashBuff = crypto.solSHA3([
- order.exchangeAddress,
order.makerAddress,
order.takerAddress,
order.feeRecipientAddress,
@@ -79,7 +87,14 @@ export const orderUtils = {
]);
const orderParamsHashHex = `0x${orderParamsHashBuff.toString('hex')}`;
const orderSchemaHashHex = orderUtils.getOrderSchemaHex();
- const orderHashBuff = crypto.solSHA3([new BigNumber(orderSchemaHashHex), new BigNumber(orderParamsHashHex)]);
+ const domainSeparatorHashHex = this.getDomainSeparatorHashHex(order.exchangeAddress);
+ const domainSeparatorSchemaHex = this.getDomainSeparatorSchemaHex();
+ const orderHashBuff = crypto.solSHA3([
+ new BigNumber(domainSeparatorSchemaHex),
+ new BigNumber(domainSeparatorHashHex),
+ new BigNumber(orderSchemaHashHex),
+ new BigNumber(orderParamsHashHex),
+ ]);
return orderHashBuff;
},
getOrderHashHex(order: SignedOrder | UnsignedOrder): string {