-
Notifications
You must be signed in to change notification settings - Fork 465
[0x.js][order-utils][web3-wrapper] Expose eth_signTypedData functionality for order signing #1102
Changes from 7 commits
adcfaa2
07926de
2a82ff4
3e2fe40
6e462b7
75d274f
e1236a4
9e8031d
7f55430
75b9e63
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,13 @@ | ||
import { schemas } from '@0xproject/json-schemas'; | ||
import { EIP712Schema, EIP712Types, eip712Utils } from '@0xproject/order-utils'; | ||
import { eip712Utils } 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 = { | ||
name: 'ZeroExTransaction', | ||
parameters: [ | ||
{ name: 'salt', type: EIP712Types.Uint256 }, | ||
{ name: 'signerAddress', type: EIP712Types.Address }, | ||
{ name: 'data', type: EIP712Types.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 | ||
|
@@ -41,12 +32,9 @@ export class TransactionEncoder { | |
signerAddress, | ||
data, | ||
}; | ||
const executeTransactionHashBuff = eip712Utils.structHash( | ||
EIP712_ZEROEX_TRANSACTION_SCHEMA, | ||
executeTransactionData, | ||
); | ||
const eip721MessageBuffer = eip712Utils.createEIP712Message(executeTransactionHashBuff, exchangeAddress); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why did we get rid of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. EIP712 sign typed data was moved to
Our original implementation was 0x specific and didn't support nested types. The latest version in utils can be used by other developers. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok, it can be used by external devs but not by us? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Order-utils is exporting (and using) 0x specific EIP712 message creation. Which uses the EIP712 generic implementation in the utils package. |
||
const messageHex = `0x${eip721MessageBuffer.toString('hex')}`; | ||
const typedData = eip712Utils.createZeroExTransactionTypedData(executeTransactionData, exchangeAddress); | ||
const eip712MessageBuffer = signTypedDataUtils.signTypedDataHash(typedData); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rename |
||
const messageHex = `0x${eip712MessageBuffer.toString('hex')}`; | ||
return messageHex; | ||
} | ||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
export const eip712TypedData = { | ||
id: '/eip712TypedData', | ||
type: 'object', | ||
properties: { | ||
types: { | ||
type: 'object', | ||
properties: { | ||
EIP712Domain: { type: 'array' }, | ||
}, | ||
additionalProperties: { | ||
type: 'array', | ||
items: { | ||
type: 'object', | ||
properties: { | ||
name: { type: 'string' }, | ||
type: { type: 'string' }, | ||
}, | ||
required: ['name', 'type'], | ||
}, | ||
}, | ||
required: ['EIP712Domain'], | ||
}, | ||
primaryType: { type: 'string' }, | ||
domain: { type: 'object' }, | ||
message: { type: 'object' }, | ||
}, | ||
required: ['types', 'primaryType', 'domain', 'message'], | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,21 @@ | ||
[ | ||
{ | ||
"version": "2.0.0", | ||
"changes": [ | ||
{ | ||
"note": "Added `ecSignOrderAsync` to first sign an order as EIP712 and fallback to EthSign", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's replace |
||
"pr": 1102 | ||
}, | ||
{ | ||
"note": "Added `ecSignTypedDataOrderAsync` to sign an order exclusively as EIP712", | ||
"pr": 1102 | ||
}, | ||
{ | ||
"note": "Rename `ecSignOrderHashAsync` to `ecSignHashAsync` removing `SignerType` parameter", | ||
"pr": 1102 | ||
} | ||
] | ||
}, | ||
{ | ||
"version": "1.0.7", | ||
"changes": [ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
inconsistencies in Metamask's signing JSON RPC endpoints