From 8fba0477a69317c19b3446c76a17cb3adbf447d7 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Wed, 7 Feb 2018 20:58:19 +0100 Subject: Remove hash from signatureData --- packages/website/ts/blockchain.ts | 13 +++++-------- packages/website/ts/components/fill_order.tsx | 11 ++++------- packages/website/ts/components/fill_order_json.tsx | 5 ++--- .../components/generate_order/generate_order_form.tsx | 17 ++++------------- packages/website/ts/components/order_json.tsx | 9 +++++---- packages/website/ts/containers/generate_order_form.tsx | 5 +++-- packages/website/ts/redux/dispatcher.ts | 8 ++++---- packages/website/ts/redux/reducer.ts | 11 +++++------ packages/website/ts/schemas/signature_data_schema.ts | 3 +-- packages/website/ts/types.ts | 4 ++-- packages/website/ts/utils/utils.ts | 4 ++-- 11 files changed, 37 insertions(+), 53 deletions(-) diff --git a/packages/website/ts/blockchain.ts b/packages/website/ts/blockchain.ts index 099efb405..697ff4f10 100644 --- a/packages/website/ts/blockchain.ts +++ b/packages/website/ts/blockchain.ts @@ -2,6 +2,7 @@ import { BlockParam, BlockRange, DecodedLogEvent, + ECSignature, ExchangeContractEventArgs, ExchangeEvents, IndexedFilterValues, @@ -299,10 +300,9 @@ export class Blockchain { takerFee: BigNumber, expirationUnixTimestampSec: BigNumber, feeRecipient: string, - signatureData: SignatureData, + ecSignature: ECSignature, salt: BigNumber, ): SignedOrder { - const ecSignature = signatureData; const exchangeContractAddress = this.getExchangeContractAddressIfExists(); const takerOrNullAddress = _.isEmpty(taker) ? constants.NULL_ADDRESS : taker; const signedOrder = { @@ -413,7 +413,7 @@ export class Blockchain { return newTokenBalancePromise; } - public async signOrderHashAsync(orderHash: string): Promise { + public async signOrderHashAsync(orderHash: string): Promise { utils.assert(!_.isUndefined(this._zeroEx), 'ZeroEx must be instantiated.'); const makerAddress = this._userAddress; // If makerAddress is undefined, this means they have a web3 instance injected into their browser @@ -436,11 +436,8 @@ export class Blockchain { makerAddress, shouldAddPersonalMessagePrefix, ); - const signatureData = _.extend({}, ecSignature, { - hash: orderHash, - }); - this._dispatcher.updateSignatureData(signatureData); - return signatureData; + this._dispatcher.updateECSignature(ecSignature); + return ecSignature; } public async mintTestTokensAsync(token: Token) { utils.assert(this._doesUserAddressExist(), BlockchainCallErrs.UserHasNoAssociatedAddresses); diff --git a/packages/website/ts/components/fill_order.tsx b/packages/website/ts/components/fill_order.tsx index d2c36ff0c..4252747ec 100644 --- a/packages/website/ts/components/fill_order.tsx +++ b/packages/website/ts/components/fill_order.tsx @@ -404,6 +404,7 @@ export class FillOrder extends React.Component { private async _validateFillOrderFireAndForgetAsync(orderJSON: string) { let orderJSONErrMsg = ''; let parsedOrder: Order; + let orderHash: string; try { const order = JSON.parse(orderJSON); const validationResult = this._validator.validate(order, orderSchema); @@ -438,16 +439,13 @@ export class FillOrder extends React.Component { takerTokenAddress: parsedOrder.signedOrder.takerTokenAddress, takerTokenAmount: takerAmount, }; - const orderHash = ZeroEx.getOrderHashHex(zeroExOrder); + orderHash = ZeroEx.getOrderHashHex(zeroExOrder); const signature = parsedOrder.signedOrder.ecSignature; - const isValidSignature = ZeroEx.isValidSignature(signature.hash, signature, parsedOrder.signedOrder.maker); + const isValidSignature = ZeroEx.isValidSignature(orderHash, signature, parsedOrder.signedOrder.maker); if (exchangeContractAddr !== parsedOrder.signedOrder.exchangeContractAddress) { orderJSONErrMsg = 'This order was made on another network or using a deprecated Exchange contract'; parsedOrder = undefined; - } else if (orderHash !== signature.hash) { - orderJSONErrMsg = 'Order hash does not match supplied plaintext values'; - parsedOrder = undefined; } else if (!isValidSignature) { orderJSONErrMsg = 'Order signature is invalid'; parsedOrder = undefined; @@ -477,7 +475,6 @@ export class FillOrder extends React.Component { // Clear cache entry if user updates orderJSON to invalid entry this.props.dispatcher.updateUserSuppliedOrderCache(undefined); } else { - const orderHash = parsedOrder.signedOrder.ecSignature.hash; unavailableTakerAmount = await this.props.blockchain.getUnavailableTakerAmountAsync(orderHash); const isMakerTokenAddressInRegistry = await this.props.blockchain.isAddressInTokenRegistryAsync( parsedOrder.signedOrder.makerTokenAddress, @@ -617,7 +614,6 @@ export class FillOrder extends React.Component { }); const parsedOrder = this.state.parsedOrder; - const orderHash = parsedOrder.signedOrder.ecSignature.hash; const takerAddress = this.props.userAddress; if (_.isUndefined(takerAddress)) { @@ -645,6 +641,7 @@ export class FillOrder extends React.Component { parsedOrder.signedOrder.ecSignature, new BigNumber(parsedOrder.signedOrder.salt), ); + const orderHash = ZeroEx.getOrderHashHex(signedOrder); const unavailableTakerAmount = await this.props.blockchain.getUnavailableTakerAmountAsync(orderHash); const availableTakerTokenAmount = takerTokenAmount.minus(unavailableTakerAmount); try { diff --git a/packages/website/ts/components/fill_order_json.tsx b/packages/website/ts/components/fill_order_json.tsx index 877b65116..7d5351ec4 100644 --- a/packages/website/ts/components/fill_order_json.tsx +++ b/packages/website/ts/components/fill_order_json.tsx @@ -33,8 +33,7 @@ export class FillOrderJSON extends React.Component { this.props.orderMakerFee, this.props.orderTakerFee, this.props.orderFeeRecipient, - this.props.orderSignatureData, + this.props.orderECSignature, this.props.tokenByAddress, this.props.orderSalt, ); @@ -168,7 +169,7 @@ You can see and fill it here: ${this.state.shareLink}`); this.props.orderMakerFee, this.props.orderTakerFee, this.props.orderFeeRecipient, - this.props.orderSignatureData, + this.props.orderECSignature, this.props.tokenByAddress, this.props.orderSalt, ); diff --git a/packages/website/ts/containers/generate_order_form.tsx b/packages/website/ts/containers/generate_order_form.tsx index 57863dbae..2cdb7b810 100644 --- a/packages/website/ts/containers/generate_order_form.tsx +++ b/packages/website/ts/containers/generate_order_form.tsx @@ -1,3 +1,4 @@ +import { ECSignature } from '0x.js'; import { BigNumber } from '@0xproject/utils'; import * as _ from 'lodash'; import * as React from 'react'; @@ -18,7 +19,7 @@ interface ConnectedState { blockchainErr: BlockchainErrs; blockchainIsLoaded: boolean; orderExpiryTimestamp: BigNumber; - orderSignatureData: SignatureData; + orderECSignature: ECSignature; userAddress: string; orderTakerAddress: string; orderSalt: BigNumber; @@ -32,7 +33,7 @@ const mapStateToProps = (state: State, ownProps: GenerateOrderFormProps): Connec blockchainErr: state.blockchainErr, blockchainIsLoaded: state.blockchainIsLoaded, orderExpiryTimestamp: state.orderExpiryTimestamp, - orderSignatureData: state.orderSignatureData, + orderECSignature: state.orderECSignature, orderTakerAddress: state.orderTakerAddress, orderSalt: state.orderSalt, networkId: state.networkId, diff --git a/packages/website/ts/redux/dispatcher.ts b/packages/website/ts/redux/dispatcher.ts index 87415b285..925f2aa29 100644 --- a/packages/website/ts/redux/dispatcher.ts +++ b/packages/website/ts/redux/dispatcher.ts @@ -1,3 +1,4 @@ +import { ECSignature } from '0x.js'; import { BigNumber } from '@0xproject/utils'; import { Dispatch } from 'redux'; import { State } from 'ts/redux/reducer'; @@ -10,7 +11,6 @@ import { ScreenWidths, Side, SideToAssetToken, - SignatureData, Token, TokenByAddress, } from 'ts/types'; @@ -148,10 +148,10 @@ export class Dispatcher { type: ActionTypes.ForceTokenStateRefetch, }); } - public updateSignatureData(signatureData: SignatureData) { + public updateECSignature(ecSignature: ECSignature) { this._dispatch({ - data: signatureData, - type: ActionTypes.UpdateOrderSignatureData, + data: ecSignature, + type: ActionTypes.UpdateOrderECSignature, }); } public updateUserEtherBalance(balance: BigNumber) { diff --git a/packages/website/ts/redux/reducer.ts b/packages/website/ts/redux/reducer.ts index 7b0b03dae..cab8cbfe6 100644 --- a/packages/website/ts/redux/reducer.ts +++ b/packages/website/ts/redux/reducer.ts @@ -1,4 +1,4 @@ -import { ZeroEx } from '0x.js'; +import { ECSignature, ZeroEx } from '0x.js'; import { BigNumber } from '@0xproject/utils'; import * as _ from 'lodash'; import * as moment from 'moment'; @@ -29,7 +29,7 @@ export interface State { orderExpiryTimestamp: BigNumber; orderFillAmount: BigNumber; orderTakerAddress: string; - orderSignatureData: SignatureData; + orderECSignature: ECSignature; orderSalt: BigNumber; nodeVersion: string; screenWidth: ScreenWidths; @@ -59,8 +59,7 @@ const INITIAL_STATE: State = { networkId: undefined, orderExpiryTimestamp: utils.initialOrderExpiryUnixTimestampSec(), orderFillAmount: undefined, - orderSignatureData: { - hash: '', + orderECSignature: { r: '', s: '', v: 27, @@ -188,10 +187,10 @@ export function reducer(state: State = INITIAL_STATE, action: Action) { lastForceTokenStateRefetch: moment().unix(), }; - case ActionTypes.UpdateOrderSignatureData: { + case ActionTypes.UpdateOrderECSignature: { return { ...state, - orderSignatureData: action.data, + orderECSignature: action.data, }; } diff --git a/packages/website/ts/schemas/signature_data_schema.ts b/packages/website/ts/schemas/signature_data_schema.ts index 8d3f15926..7852abfef 100644 --- a/packages/website/ts/schemas/signature_data_schema.ts +++ b/packages/website/ts/schemas/signature_data_schema.ts @@ -1,11 +1,10 @@ export const signatureDataSchema = { id: '/SignatureData', properties: { - hash: { type: 'string' }, r: { type: 'string' }, s: { type: 'string' }, v: { type: 'number' }, }, - required: ['hash', 'r', 's', 'v'], + required: ['r', 's', 'v'], type: 'object', }; diff --git a/packages/website/ts/types.ts b/packages/website/ts/types.ts index a628ebec1..2b255f523 100644 --- a/packages/website/ts/types.ts +++ b/packages/website/ts/types.ts @@ -71,7 +71,7 @@ export interface SignedOrder { expirationUnixTimestampSec: string; feeRecipient: string; salt: string; - ecSignature: SignatureData; + ecSignature: ECSignature; exchangeContractAddress: string; } @@ -123,7 +123,7 @@ export enum ActionTypes { UpdateChosenAssetTokenAddress = 'UPDATE_CHOSEN_ASSET_TOKEN_ADDRESS', UpdateOrderTakerAddress = 'UPDATE_ORDER_TAKER_ADDRESS', UpdateOrderSalt = 'UPDATE_ORDER_SALT', - UpdateOrderSignatureData = 'UPDATE_ORDER_SIGNATURE_DATA', + UpdateOrderECSignature = 'UPDATE_ORDER_EC_SIGNATURE', UpdateTokenByAddress = 'UPDATE_TOKEN_BY_ADDRESS', RemoveTokenFromTokenByAddress = 'REMOVE_TOKEN_FROM_TOKEN_BY_ADDRESS', ForceTokenStateRefetch = 'FORCE_TOKEN_STATE_REFETCH', diff --git a/packages/website/ts/utils/utils.ts b/packages/website/ts/utils/utils.ts index eaff5c658..bf6b70f84 100644 --- a/packages/website/ts/utils/utils.ts +++ b/packages/website/ts/utils/utils.ts @@ -1,4 +1,4 @@ -import { ExchangeContractErrs, ZeroExError } from '0x.js'; +import { ECSignature, ExchangeContractErrs, ZeroExError } from '0x.js'; import { BigNumber } from '@0xproject/utils'; import deepEqual = require('deep-equal'); import isMobile = require('is-mobile'); @@ -67,7 +67,7 @@ export const utils = { makerFee: BigNumber, takerFee: BigNumber, feeRecipient: string, - ecSignature: SignatureData, + ecSignature: ECSignature, tokenByAddress: TokenByAddress, orderSalt: BigNumber, ): Order { -- cgit v1.2.3