diff options
author | Jacob Evans <jacob@dekz.net> | 2018-10-04 15:32:54 +0800 |
---|---|---|
committer | Jacob Evans <jacob@dekz.net> | 2018-10-05 10:02:09 +0800 |
commit | 3e2fe40a11919f09f1f454c71f02aaa147b46b0c (patch) | |
tree | 0ff88e480944cfab0cefd211f5623f2870462351 /packages/contracts | |
parent | 2a82ff48c061eacb3b6f9fb36eeae7f515b6d11d (diff) | |
download | dexon-sol-tools-3e2fe40a11919f09f1f454c71f02aaa147b46b0c.tar dexon-sol-tools-3e2fe40a11919f09f1f454c71f02aaa147b46b0c.tar.gz dexon-sol-tools-3e2fe40a11919f09f1f454c71f02aaa147b46b0c.tar.bz2 dexon-sol-tools-3e2fe40a11919f09f1f454c71f02aaa147b46b0c.tar.lz dexon-sol-tools-3e2fe40a11919f09f1f454c71f02aaa147b46b0c.tar.xz dexon-sol-tools-3e2fe40a11919f09f1f454c71f02aaa147b46b0c.tar.zst dexon-sol-tools-3e2fe40a11919f09f1f454c71f02aaa147b46b0c.zip |
Add eth_signTypedData support to our wallet subproviders
Diffstat (limited to 'packages/contracts')
-rw-r--r-- | packages/contracts/test/exchange/libs.ts | 18 | ||||
-rw-r--r-- | packages/contracts/test/utils/transaction_factory.ts | 40 |
2 files changed, 29 insertions, 29 deletions
diff --git a/packages/contracts/test/exchange/libs.ts b/packages/contracts/test/exchange/libs.ts index 37234489e..049b7f37a 100644 --- a/packages/contracts/test/exchange/libs.ts +++ b/packages/contracts/test/exchange/libs.ts @@ -1,5 +1,5 @@ import { BlockchainLifecycle } from '@0xproject/dev-utils'; -import { assetDataUtils, eip712Utils, orderHashUtils } from '@0xproject/order-utils'; +import { assetDataUtils, orderHashUtils } from '@0xproject/order-utils'; import { SignedOrder } from '@0xproject/types'; import { BigNumber } from '@0xproject/utils'; import * as chai from 'chai'; @@ -126,22 +126,6 @@ describe('Exchange libs', () => { }); describe('LibOrder', () => { - describe('getOrderSchema', () => { - it('should output the correct order schema hash', async () => { - const orderSchema = await libs.getOrderSchemaHash.callAsync(); - const schemaHashBuffer = orderHashUtils._getOrderSchemaBuffer(); - const schemaHashHex = `0x${schemaHashBuffer.toString('hex')}`; - expect(schemaHashHex).to.be.equal(orderSchema); - }); - }); - describe('getDomainSeparatorSchema', () => { - it('should output the correct domain separator schema hash', async () => { - const domainSeparatorSchema = await libs.getDomainSeparatorSchemaHash.callAsync(); - const domainSchemaBuffer = eip712Utils._getDomainSeparatorSchemaBuffer(); - const schemaHashHex = `0x${domainSchemaBuffer.toString('hex')}`; - expect(schemaHashHex).to.be.equal(domainSeparatorSchema); - }); - }); describe('getOrderHash', () => { it('should output the correct orderHash', async () => { signedOrder = await orderFactory.newSignedOrderAsync(); diff --git a/packages/contracts/test/utils/transaction_factory.ts b/packages/contracts/test/utils/transaction_factory.ts index 8465a6a30..47880cca5 100644 --- a/packages/contracts/test/utils/transaction_factory.ts +++ b/packages/contracts/test/utils/transaction_factory.ts @@ -1,16 +1,22 @@ -import { EIP712Schema, EIP712Types, eip712Utils, generatePseudoRandomSalt } from '@0xproject/order-utils'; +import { + EIP712_DOMAIN_NAME, + EIP712_DOMAIN_SCHEMA, + EIP712_DOMAIN_VERSION, + generatePseudoRandomSalt, +} from '@0xproject/order-utils'; import { SignatureType } from '@0xproject/types'; +import { signTypedDataUtils } from '@0xproject/utils'; import * as ethUtil from 'ethereumjs-util'; import { signingUtils } from './signing_utils'; import { SignedTransaction } from './types'; -const EIP712_ZEROEX_TRANSACTION_SCHEMA: EIP712Schema = { +const EIP712_ZEROEX_TRANSACTION_SCHEMA = { name: 'ZeroExTransaction', parameters: [ - { name: 'salt', type: EIP712Types.Uint256 }, - { name: 'signerAddress', type: EIP712Types.Address }, - { name: 'data', type: EIP712Types.Bytes }, + { name: 'salt', type: 'uint256' }, + { name: 'signerAddress', type: 'address' }, + { name: 'data', type: 'bytes' }, ], }; @@ -27,20 +33,30 @@ export class TransactionFactory { const salt = generatePseudoRandomSalt(); const signerAddress = `0x${this._signerBuff.toString('hex')}`; const executeTransactionData = { - salt, + salt: salt.toString(), signerAddress, 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 typedData = { + types: { + EIP712Domain: EIP712_DOMAIN_SCHEMA.parameters, + ZeroExTransaction: EIP712_ZEROEX_TRANSACTION_SCHEMA.parameters, + }, + domain: { + name: EIP712_DOMAIN_NAME, + version: EIP712_DOMAIN_VERSION, + verifyingContract: this._exchangeAddress, + }, + message: executeTransactionData, + primaryType: EIP712_ZEROEX_TRANSACTION_SCHEMA.name, + }; + const eip712MessageBuffer = signTypedDataUtils.signTypedDataHash(typedData); + const signature = signingUtils.signMessage(eip712MessageBuffer, this._privateKey, signatureType); const signedTx = { exchangeAddress: this._exchangeAddress, signature: `0x${signature.toString('hex')}`, ...executeTransactionData, + salt, }; return signedTx; } |