diff options
author | Fabio Berger <me@fabioberger.com> | 2018-06-20 19:25:29 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2018-06-20 19:25:29 +0800 |
commit | 2ffab2218584fac5d3ea2b264a7c746d963083d9 (patch) | |
tree | f7558147b811c06300e2c7697591466ae7cf48ba /packages/contracts/src/utils | |
parent | 5541327968ad6f974a37c49057253746f738a709 (diff) | |
parent | 096eaa20d785baee07b06b3f0848797e470fbda0 (diff) | |
download | dexon-sol-tools-2ffab2218584fac5d3ea2b264a7c746d963083d9.tar.gz dexon-sol-tools-2ffab2218584fac5d3ea2b264a7c746d963083d9.tar.zst dexon-sol-tools-2ffab2218584fac5d3ea2b264a7c746d963083d9.zip |
Merge branch 'v2-prototype' into feature/combinatorial-testing
* v2-prototype: (22 commits)
Fix closing parens in liborder
Update after rebase
ERC721Proxy Always call safeTransferFrom
Rename makerEpoch => orderEpoch
Make cancelOrdersUpTo compatible with sender abstraction
Update PR template
Use Image component instead of img tag
Assembler orderHash function
Optimize and remove redundant encodePacked
Fix linting issue
Fix bug where we do fetch balances on wallet login
Check network state immediately instead of waiting for delay
Fix onboarding persisting when changing routes
Consolidate account state messaging logic
Only elevate wallet zIndex when onboarding is in progress
Rebase and update feedback
Run linter
Add Portal v2 logging
Simplified handling of source < 32 edge case
Basic EIP712 encoder
...
Diffstat (limited to 'packages/contracts/src/utils')
-rw-r--r-- | packages/contracts/src/utils/artifacts.ts | 2 | ||||
-rw-r--r-- | packages/contracts/src/utils/order_factory.ts | 2 | ||||
-rw-r--r-- | packages/contracts/src/utils/transaction_factory.ts | 27 |
3 files changed, 25 insertions, 6 deletions
diff --git a/packages/contracts/src/utils/artifacts.ts b/packages/contracts/src/utils/artifacts.ts index bf7221d6d..7ba467708 100644 --- a/packages/contracts/src/utils/artifacts.ts +++ b/packages/contracts/src/utils/artifacts.ts @@ -7,6 +7,7 @@ import * as DummyERC721Token from '../artifacts/DummyERC721Token.json'; import * as ERC20Proxy from '../artifacts/ERC20Proxy.json'; import * as ERC721Proxy from '../artifacts/ERC721Proxy.json'; import * as Exchange from '../artifacts/Exchange.json'; +import * as ExchangeWrapper from '../artifacts/ExchangeWrapper.json'; import * as MixinAuthorizable from '../artifacts/MixinAuthorizable.json'; import * as MultiSigWallet from '../artifacts/MultiSigWallet.json'; import * as MultiSigWalletWithTimeLock from '../artifacts/MultiSigWalletWithTimeLock.json'; @@ -29,6 +30,7 @@ export const artifacts = { ERC20Proxy: (ERC20Proxy as any) as ContractArtifact, ERC721Proxy: (ERC721Proxy as any) as ContractArtifact, Exchange: (Exchange as any) as ContractArtifact, + ExchangeWrapper: (ExchangeWrapper as any) as ContractArtifact, EtherToken: (EtherToken as any) as ContractArtifact, MixinAuthorizable: (MixinAuthorizable as any) as ContractArtifact, MultiSigWallet: (MultiSigWallet as any) as ContractArtifact, diff --git a/packages/contracts/src/utils/order_factory.ts b/packages/contracts/src/utils/order_factory.ts index 6e4c9a883..009dbc396 100644 --- a/packages/contracts/src/utils/order_factory.ts +++ b/packages/contracts/src/utils/order_factory.ts @@ -26,7 +26,7 @@ export class OrderFactory { ...this._defaultOrderParams, ...customOrderParams, } as any) as Order; - const orderHashBuff = orderHashUtils.getOrderHashBuff(order); + const orderHashBuff = orderHashUtils.getOrderHashBuffer(order); const signature = signingUtils.signMessage(orderHashBuff, this._privateKey, signatureType); const signedOrder = { ...order, diff --git a/packages/contracts/src/utils/transaction_factory.ts b/packages/contracts/src/utils/transaction_factory.ts index a060263b1..19ef4e1bf 100644 --- a/packages/contracts/src/utils/transaction_factory.ts +++ b/packages/contracts/src/utils/transaction_factory.ts @@ -1,10 +1,19 @@ -import { crypto, generatePseudoRandomSalt } from '@0xproject/order-utils'; +import { EIP712Schema, EIP712Types, EIP712Utils, generatePseudoRandomSalt } from '@0xproject/order-utils'; import { SignatureType } from '@0xproject/types'; import * as ethUtil from 'ethereumjs-util'; import { signingUtils } from './signing_utils'; import { SignedTransaction } from './types'; +const EIP712_ZEROEX_TRANSACTION_SCHEMA: EIP712Schema = { + name: 'ZeroExTransaction', + parameters: [ + { name: 'salt', type: EIP712Types.Uint256 }, + { name: 'signer', type: EIP712Types.Address }, + { name: 'data', type: EIP712Types.Bytes }, + ], +}; + export class TransactionFactory { private _signerBuff: Buffer; private _exchangeAddress: string; @@ -16,14 +25,22 @@ export class TransactionFactory { } public newSignedTransaction(data: string, signatureType: SignatureType = SignatureType.EthSign): SignedTransaction { const salt = generatePseudoRandomSalt(); - const txHash = crypto.solSHA3([this._exchangeAddress, this._signerBuff, salt, ethUtil.toBuffer(data)]); + const signer = `0x${this._signerBuff.toString('hex')}`; + const executeTransactionData = { + salt, + signer, + data, + }; + const executeTransactionHashBuff = EIP712Utils.structHash( + EIP712_ZEROEX_TRANSACTION_SCHEMA, + executeTransactionData, + ); + const txHash = EIP712Utils.createEIP712Message(executeTransactionHashBuff, this._exchangeAddress); const signature = signingUtils.signMessage(txHash, this._privateKey, signatureType); const signedTx = { exchangeAddress: this._exchangeAddress, - salt, - signer: `0x${this._signerBuff.toString('hex')}`, - data, signature: `0x${signature.toString('hex')}`, + ...executeTransactionData, }; return signedTx; } |