This repository has been archived by the owner on Jul 9, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 465
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Return SignedOrder from signing utils.
Create a helper back in EIP712Utils for code cleanup. Moved constants in order-utils into the constants object
- Loading branch information
Showing
25 changed files
with
380 additions
and
192 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { EIP712Object, EIP712TypedData, EIP712Types, Order, ZeroExTransaction } from '@0xproject/types'; | ||
import * as _ from 'lodash'; | ||
|
||
import { constants } from './constants'; | ||
|
||
export const eip712Utils = { | ||
/** | ||
* Creates a EIP712TypedData object specific to the 0x protocol for use with signTypedData. | ||
* @param primaryType The primary type found in message | ||
* @param types The additional types for the data in message | ||
* @param message The contents of the message | ||
* @param exchangeAddress The address of the exchange contract | ||
* @return A typed data object | ||
*/ | ||
createTypedData: ( | ||
primaryType: string, | ||
types: EIP712Types, | ||
message: EIP712Object, | ||
exchangeAddress: string, | ||
): EIP712TypedData => { | ||
const typedData = { | ||
types: { | ||
EIP712Domain: constants.EIP712_DOMAIN_SCHEMA.parameters, | ||
...types, | ||
}, | ||
domain: { | ||
name: constants.EIP712_DOMAIN_NAME, | ||
version: constants.EIP712_DOMAIN_VERSION, | ||
verifyingContract: exchangeAddress, | ||
}, | ||
message, | ||
primaryType, | ||
}; | ||
return typedData; | ||
}, | ||
/** | ||
* Creates an Order EIP712TypedData object for use with signTypedData. | ||
* @param Order the order | ||
* @return A typed data object | ||
*/ | ||
createOrderTypedData: (order: Order): EIP712TypedData => { | ||
const normalizedOrder = _.mapValues(order, value => { | ||
return !_.isString(value) ? value.toString() : value; | ||
}); | ||
const typedData = eip712Utils.createTypedData( | ||
constants.EIP712_ORDER_SCHEMA.name, | ||
{ Order: constants.EIP712_ORDER_SCHEMA.parameters }, | ||
normalizedOrder, | ||
order.exchangeAddress, | ||
); | ||
return typedData; | ||
}, | ||
/** | ||
* Creates an ExecuteTransaction EIP712TypedData object for use with signTypedData and | ||
* 0x Exchange executeTransaction. | ||
* @param ZeroExTransaction the 0x transaction | ||
* @param exchangeAddress The address of the exchange contract | ||
* @return A typed data object | ||
*/ | ||
createZeroExTransactionTypedData: ( | ||
zeroExTransaction: ZeroExTransaction, | ||
exchangeAddress: string, | ||
): EIP712TypedData => { | ||
const normalizedTransaction = _.mapValues(zeroExTransaction, value => { | ||
return !_.isString(value) ? value.toString() : value; | ||
}); | ||
const typedData = eip712Utils.createTypedData( | ||
constants.EIP712_ZEROEX_TRANSACTION_SCHEMA.name, | ||
{ ZeroExTransaction: constants.EIP712_ZEROEX_TRANSACTION_SCHEMA.parameters }, | ||
normalizedTransaction, | ||
exchangeAddress, | ||
); | ||
return typedData; | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.