From 07926ded6ef194969ffe26e3879d6e86a0eb9c50 Mon Sep 17 00:00:00 2001 From: Jacob Evans Date: Tue, 2 Oct 2018 17:32:28 +1000 Subject: Introduce Metamask Subprovider. MM has a number of inconsistencies with other providers when implementing the JSON RPC interface. This subprovider wraps those nuances so they do not leak into the rest of our code --- packages/contract-wrappers/test/transaction_encoder_test.ts | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'packages/contract-wrappers') diff --git a/packages/contract-wrappers/test/transaction_encoder_test.ts b/packages/contract-wrappers/test/transaction_encoder_test.ts index a397e43a8..9da8fe2ca 100644 --- a/packages/contract-wrappers/test/transaction_encoder_test.ts +++ b/packages/contract-wrappers/test/transaction_encoder_test.ts @@ -1,7 +1,7 @@ import { BlockchainLifecycle } from '@0xproject/dev-utils'; import { FillScenarios } from '@0xproject/fill-scenarios'; import { assetDataUtils, generatePseudoRandomSalt, orderHashUtils, signatureUtils } from '@0xproject/order-utils'; -import { SignedOrder, SignerType } from '@0xproject/types'; +import { SignedOrder } from '@0xproject/types'; import { BigNumber } from '@0xproject/utils'; import 'mocha'; @@ -80,12 +80,7 @@ describe('TransactionEncoder', () => { ): Promise => { const salt = generatePseudoRandomSalt(); const encodedTransaction = encoder.getTransactionHex(data, salt, signerAddress); - const signature = await signatureUtils.ecSignOrderHashAsync( - provider, - encodedTransaction, - signerAddress, - SignerType.Default, - ); + const signature = await signatureUtils.ecSignHashAsync(provider, encodedTransaction, signerAddress); txHash = await contractWrappers.exchange.executeTransactionAsync( salt, signerAddress, -- cgit v1.2.3 From 3e2fe40a11919f09f1f454c71f02aaa147b46b0c Mon Sep 17 00:00:00 2001 From: Jacob Evans Date: Thu, 4 Oct 2018 17:32:54 +1000 Subject: Add eth_signTypedData support to our wallet subproviders --- .../src/utils/transaction_encoder.ts | 35 ++++++++++++++-------- 1 file changed, 22 insertions(+), 13 deletions(-) (limited to 'packages/contract-wrappers') diff --git a/packages/contract-wrappers/src/utils/transaction_encoder.ts b/packages/contract-wrappers/src/utils/transaction_encoder.ts index 87cbb43fd..1800f49ad 100644 --- a/packages/contract-wrappers/src/utils/transaction_encoder.ts +++ b/packages/contract-wrappers/src/utils/transaction_encoder.ts @@ -1,19 +1,19 @@ import { schemas } from '@0xproject/json-schemas'; -import { EIP712Schema, EIP712Types, eip712Utils } from '@0xproject/order-utils'; +import { EIP712_DOMAIN_NAME, EIP712_DOMAIN_SCHEMA, EIP712_DOMAIN_VERSION } from '@0xproject/order-utils'; import { Order, SignedOrder } from '@0xproject/types'; -import { BigNumber } from '@0xproject/utils'; +import { BigNumber, signTypedDataUtils } from '@0xproject/utils'; import _ = require('lodash'); import { ExchangeContract } from '../contract_wrappers/generated/exchange'; import { assert } from './assert'; -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' }, ], }; @@ -37,16 +37,25 @@ export class TransactionEncoder { public getTransactionHex(data: string, salt: BigNumber, signerAddress: string): string { const exchangeAddress = this._getExchangeContract().address; const executeTransactionData = { - salt, + salt: salt.toString(), signerAddress, data, }; - const executeTransactionHashBuff = eip712Utils.structHash( - EIP712_ZEROEX_TRANSACTION_SCHEMA, - executeTransactionData, - ); - const eip721MessageBuffer = eip712Utils.createEIP712Message(executeTransactionHashBuff, exchangeAddress); - const messageHex = `0x${eip721MessageBuffer.toString('hex')}`; + const typedData = { + types: { + EIP712Domain: EIP712_DOMAIN_SCHEMA.parameters, + ZeroExTransaction: EIP712_ZEROEX_TRANSACTION_SCHEMA.parameters, + }, + domain: { + name: EIP712_DOMAIN_NAME, + version: EIP712_DOMAIN_VERSION, + verifyingContract: exchangeAddress, + }, + message: executeTransactionData, + primaryType: EIP712_ZEROEX_TRANSACTION_SCHEMA.name, + }; + const eip712MessageBuffer = signTypedDataUtils.signTypedDataHash(typedData); + const messageHex = `0x${eip712MessageBuffer.toString('hex')}`; return messageHex; } /** -- cgit v1.2.3 From 75d274f330dc0c18577e764ca77ffb36d5a3f27e Mon Sep 17 00:00:00 2001 From: Jacob Evans Date: Fri, 5 Oct 2018 11:45:53 +1000 Subject: Return SignedOrder from signing utils. Create a helper back in EIP712Utils for code cleanup. Moved constants in order-utils into the constants object --- .../src/utils/transaction_encoder.ts | 27 +++------------------- 1 file changed, 3 insertions(+), 24 deletions(-) (limited to 'packages/contract-wrappers') diff --git a/packages/contract-wrappers/src/utils/transaction_encoder.ts b/packages/contract-wrappers/src/utils/transaction_encoder.ts index 1800f49ad..d9735778e 100644 --- a/packages/contract-wrappers/src/utils/transaction_encoder.ts +++ b/packages/contract-wrappers/src/utils/transaction_encoder.ts @@ -1,5 +1,5 @@ import { schemas } from '@0xproject/json-schemas'; -import { EIP712_DOMAIN_NAME, EIP712_DOMAIN_SCHEMA, EIP712_DOMAIN_VERSION } from '@0xproject/order-utils'; +import { eip712Utils } from '@0xproject/order-utils'; import { Order, SignedOrder } from '@0xproject/types'; import { BigNumber, signTypedDataUtils } from '@0xproject/utils'; import _ = require('lodash'); @@ -8,15 +8,6 @@ import { ExchangeContract } from '../contract_wrappers/generated/exchange'; import { assert } from './assert'; -const EIP712_ZEROEX_TRANSACTION_SCHEMA = { - name: 'ZeroExTransaction', - parameters: [ - { name: 'salt', type: 'uint256' }, - { name: 'signerAddress', type: 'address' }, - { name: 'data', type: 'bytes' }, - ], -}; - /** * Transaction Encoder. Transaction messages exist for the purpose of calling methods on the Exchange contract * in the context of another address. For example, UserA can encode and sign a fillOrder transaction and UserB @@ -37,23 +28,11 @@ export class TransactionEncoder { public getTransactionHex(data: string, salt: BigNumber, signerAddress: string): string { const exchangeAddress = this._getExchangeContract().address; const executeTransactionData = { - salt: salt.toString(), + salt, signerAddress, data, }; - const typedData = { - types: { - EIP712Domain: EIP712_DOMAIN_SCHEMA.parameters, - ZeroExTransaction: EIP712_ZEROEX_TRANSACTION_SCHEMA.parameters, - }, - domain: { - name: EIP712_DOMAIN_NAME, - version: EIP712_DOMAIN_VERSION, - verifyingContract: exchangeAddress, - }, - message: executeTransactionData, - primaryType: EIP712_ZEROEX_TRANSACTION_SCHEMA.name, - }; + const typedData = eip712Utils.createZeroExTransactionTypedData(executeTransactionData, exchangeAddress); const eip712MessageBuffer = signTypedDataUtils.signTypedDataHash(typedData); const messageHex = `0x${eip712MessageBuffer.toString('hex')}`; return messageHex; -- cgit v1.2.3 From 9e8031d5e3cf94cabe07685be510397367e90413 Mon Sep 17 00:00:00 2001 From: Jacob Evans Date: Tue, 9 Oct 2018 18:26:13 +1100 Subject: Throw and handle errors from Providers. In web3 wrapper when a response contains an error field we throw this rather than return response.result which is often undefined. In Signature Utils we handle the error thrown when a user rejects the signing dialogue to prevent double signing. Exposed the ZeroExTransaction JSON schema. In Website only use the MetamaskSubprovider if we can detect the provider is Metamask --- packages/contract-wrappers/src/utils/transaction_encoder.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages/contract-wrappers') diff --git a/packages/contract-wrappers/src/utils/transaction_encoder.ts b/packages/contract-wrappers/src/utils/transaction_encoder.ts index d9735778e..33086944b 100644 --- a/packages/contract-wrappers/src/utils/transaction_encoder.ts +++ b/packages/contract-wrappers/src/utils/transaction_encoder.ts @@ -33,7 +33,7 @@ export class TransactionEncoder { data, }; const typedData = eip712Utils.createZeroExTransactionTypedData(executeTransactionData, exchangeAddress); - const eip712MessageBuffer = signTypedDataUtils.signTypedDataHash(typedData); + const eip712MessageBuffer = signTypedDataUtils.generateTypedDataHash(typedData); const messageHex = `0x${eip712MessageBuffer.toString('hex')}`; return messageHex; } -- cgit v1.2.3 From 7f554303b4333b083102eb17cd9acb6f6b73cc75 Mon Sep 17 00:00:00 2001 From: Jacob Evans Date: Tue, 9 Oct 2018 20:29:41 +1100 Subject: Update the exported types for the packages which touch RPC providers --- packages/contract-wrappers/src/index.ts | 1 + 1 file changed, 1 insertion(+) (limited to 'packages/contract-wrappers') diff --git a/packages/contract-wrappers/src/index.ts b/packages/contract-wrappers/src/index.ts index 2fcdd2ddb..e8a53170e 100644 --- a/packages/contract-wrappers/src/index.ts +++ b/packages/contract-wrappers/src/index.ts @@ -39,6 +39,7 @@ export { JSONRPCRequestPayload, JSONRPCResponsePayload, JSONRPCErrorCallback, + JSONRPCResponseError, AbiDefinition, LogWithDecodedArgs, FunctionAbi, -- cgit v1.2.3 From 31ee8870b80579caf3762c1178043bb5bb6fe4fb Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 9 Oct 2018 12:15:42 +0200 Subject: Upgrade ethers.js version --- packages/contract-wrappers/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages/contract-wrappers') diff --git a/packages/contract-wrappers/package.json b/packages/contract-wrappers/package.json index e83caad97..35f27d77c 100644 --- a/packages/contract-wrappers/package.json +++ b/packages/contract-wrappers/package.json @@ -84,7 +84,7 @@ "ethereum-types": "^1.0.11", "ethereumjs-blockstream": "6.0.0", "ethereumjs-util": "^5.1.1", - "ethers": "4.0.0-beta.14", + "ethers": "~4.0.4", "js-sha3": "^0.7.0", "lodash": "^4.17.5", "uuid": "^3.1.0" -- cgit v1.2.3