diff options
author | Jacob Evans <jacob@dekz.net> | 2018-05-30 08:11:33 +0800 |
---|---|---|
committer | Jacob Evans <jacob@dekz.net> | 2018-06-05 08:41:00 +0800 |
commit | 4670cc1a5f04d61045a82b4a3bbcf56e009afd56 (patch) | |
tree | c66321deb69c78a85f7a5c907fac62cc95eae14d /packages/contracts/src/utils/transaction_factory.ts | |
parent | 70858603ed37de24ae47978a191b3f188f450182 (diff) | |
download | dexon-sol-tools-4670cc1a5f04d61045a82b4a3bbcf56e009afd56.tar dexon-sol-tools-4670cc1a5f04d61045a82b4a3bbcf56e009afd56.tar.gz dexon-sol-tools-4670cc1a5f04d61045a82b4a3bbcf56e009afd56.tar.bz2 dexon-sol-tools-4670cc1a5f04d61045a82b4a3bbcf56e009afd56.tar.lz dexon-sol-tools-4670cc1a5f04d61045a82b4a3bbcf56e009afd56.tar.xz dexon-sol-tools-4670cc1a5f04d61045a82b4a3bbcf56e009afd56.tar.zst dexon-sol-tools-4670cc1a5f04d61045a82b4a3bbcf56e009afd56.zip |
Add missing EIP191 prefix for EIP712
Diffstat (limited to 'packages/contracts/src/utils/transaction_factory.ts')
-rw-r--r-- | packages/contracts/src/utils/transaction_factory.ts | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/packages/contracts/src/utils/transaction_factory.ts b/packages/contracts/src/utils/transaction_factory.ts index 434611908..1c1029d62 100644 --- a/packages/contracts/src/utils/transaction_factory.ts +++ b/packages/contracts/src/utils/transaction_factory.ts @@ -2,9 +2,22 @@ import { crypto, generatePseudoRandomSalt } from '@0xproject/order-utils'; import { SignatureType } from '@0xproject/types'; import { BigNumber } from '@0xproject/utils'; import * as ethUtil from 'ethereumjs-util'; +import * as _ from 'lodash'; +import { crypto } from './crypto'; +import { EIP712Utils } from './eip712_utils'; +import { orderUtils } from './order_utils'; import { signingUtils } from './signing_utils'; -import { SignedTransaction } from './types'; +import { EIP712Schema, SignatureType, SignedTransaction } from './types'; + +const EIP712_EXECUTE_TRANSACTION_SCHEMA: EIP712Schema = { + name: 'ExecuteTransaction', + parameters: [ + { name: 'salt', type: 'uint256' }, + { name: 'signer', type: 'address' }, + { name: 'data', type: 'bytes' }, + ], +}; export class TransactionFactory { private _signerBuff: Buffer; @@ -16,8 +29,21 @@ export class TransactionFactory { this._signerBuff = ethUtil.privateToAddress(this._privateKey); } public newSignedTransaction(data: string, signatureType: SignatureType = SignatureType.EthSign): SignedTransaction { + const executeTransactionSchemaHashBuff = EIP712Utils.compileSchema(EIP712_EXECUTE_TRANSACTION_SCHEMA); + const salt = generatePseudoRandomSalt(); - const txHash = crypto.solSHA3([this._exchangeAddress, this._signerBuff, salt, ethUtil.toBuffer(data)]); + const dataHash = crypto.solSHA3([ethUtil.toBuffer(data)]); + + const executeTransactionDataHash = crypto.solSHA3([ + executeTransactionSchemaHashBuff, + salt, + EIP712Utils.pad32Buffer(this._signerBuff), + dataHash, + ]); + + const executeTransactionMessageHex = `0x${executeTransactionDataHash.toString('hex')}`; + + const txHash = EIP712Utils.createEIP712Message(executeTransactionMessageHex, this._exchangeAddress); const signature = signingUtils.signMessage(txHash, this._privateKey, signatureType); const signedTx = { exchangeAddress: this._exchangeAddress, |