Use domain separator for exchange address
This commit is contained in:
committed by
Fabio Berger
parent
fcf4a958c3
commit
3cc8af819c
@@ -20,9 +20,12 @@ pragma solidity ^0.4.24;
|
||||
|
||||
contract LibOrder {
|
||||
|
||||
bytes32 constant DOMAIN_SEPARATOR_SCHEMA_HASH = keccak256(
|
||||
"DomainSeparator(address contract)"
|
||||
);
|
||||
|
||||
bytes32 constant ORDER_SCHEMA_HASH = keccak256(
|
||||
"Order(",
|
||||
"address exchangeAddress,",
|
||||
"address makerAddress,",
|
||||
"address takerAddress,",
|
||||
"address feeRecipientAddress,",
|
||||
@@ -73,9 +76,10 @@ contract LibOrder {
|
||||
// TODO: EIP712 is not finalized yet
|
||||
// Source: https://github.com/ethereum/EIPs/pull/712
|
||||
orderHash = keccak256(
|
||||
DOMAIN_SEPARATOR_SCHEMA_HASH,
|
||||
keccak256(address(this)),
|
||||
ORDER_SCHEMA_HASH,
|
||||
keccak256(
|
||||
address(this),
|
||||
order.makerAddress,
|
||||
order.takerAddress,
|
||||
order.feeRecipientAddress,
|
||||
|
@@ -77,6 +77,14 @@ contract TestLibs is
|
||||
return ORDER_SCHEMA_HASH;
|
||||
}
|
||||
|
||||
function getDomainSeparatorSchemaHash()
|
||||
public
|
||||
view
|
||||
returns (bytes32)
|
||||
{
|
||||
return DOMAIN_SEPARATOR_SCHEMA_HASH;
|
||||
}
|
||||
|
||||
function publicAddFillResults(FillResults memory totalFillResults, FillResults memory singleFillResults)
|
||||
public
|
||||
pure
|
||||
|
@@ -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 {
|
||||
|
Reference in New Issue
Block a user