From 7228cbfe92ff6fee4bc59681fba1789bec85c4f9 Mon Sep 17 00:00:00 2001 From: Jan-Gerrit Harms Date: Fri, 9 Aug 2019 09:36:32 +0200 Subject: [PATCH] Pass exchangeAddress instead of SignatureOpts --- contracts/exchange/test/signature_validator.ts | 14 +++++++++----- packages/0x.js/src/index.ts | 3 --- .../src/generated-wrappers/forwarder.ts | 8 ++++---- packages/order-utils/src/index.ts | 3 --- packages/order-utils/src/order_validation_utils.ts | 3 ++- packages/order-utils/src/signature_utils.ts | 10 +++------- packages/order-utils/src/types.ts | 9 --------- .../src/order_watcher/order_watcher.ts | 10 +++++++--- packages/order-watcher/src/utils/assert.ts | 6 +++--- 9 files changed, 28 insertions(+), 38 deletions(-) diff --git a/contracts/exchange/test/signature_validator.ts b/contracts/exchange/test/signature_validator.ts index 9de34abcea..d68229f031 100644 --- a/contracts/exchange/test/signature_validator.ts +++ b/contracts/exchange/test/signature_validator.ts @@ -377,7 +377,7 @@ describe('MixinSignatureValidator', () => { orderHashHex, signatureHex, signerAddress, - { exchangeAddress: signatureValidator.address }, + signatureValidator.address, ); expect(isValidSignatureTs).to.be.true(); }); @@ -402,7 +402,7 @@ describe('MixinSignatureValidator', () => { orderHashHex, signatureHex, notSignerAddress, - { exchangeAddress: signatureValidator.address }, + signatureValidator.address, ); expect(isValidSignatureTs).to.be.false(); }); @@ -442,9 +442,13 @@ describe('MixinSignatureValidator', () => { expect(isValidSignature).to.be.false(); expect( - signatureUtils.isValidSignatureAsync(provider, orderHashHex, signatureHex, signerAddress, { - exchangeAddress: signatureValidator.address, - }), + signatureUtils.isValidSignatureAsync( + provider, + orderHashHex, + signatureHex, + signerAddress, + signatureValidator.address, + ), ).to.be.rejected(); }); diff --git a/packages/0x.js/src/index.ts b/packages/0x.js/src/index.ts index c3dec46d52..d6d2c5d6b8 100644 --- a/packages/0x.js/src/index.ts +++ b/packages/0x.js/src/index.ts @@ -6,9 +6,6 @@ export { generatePseudoRandomSalt, orderHashUtils, transactionHashUtils, - SignatureValidationOpts, - ValidatorSignatureOpts, - PresignedSignatureOpts, } from '@0x/order-utils'; export { diff --git a/packages/abi-gen-wrappers/src/generated-wrappers/forwarder.ts b/packages/abi-gen-wrappers/src/generated-wrappers/forwarder.ts index 868a0f198a..6ecd195fb5 100644 --- a/packages/abi-gen-wrappers/src/generated-wrappers/forwarder.ts +++ b/packages/abi-gen-wrappers/src/generated-wrappers/forwarder.ts @@ -297,7 +297,7 @@ export class ForwarderContract extends BaseContract { takerAssetFilledAmount: BigNumber; makerFeePaid: BigNumber; takerFeePaid: BigNumber; - } + }, ] > { assert.isArray('orders', orders); @@ -359,7 +359,7 @@ export class ForwarderContract extends BaseContract { takerAssetFilledAmount: BigNumber; makerFeePaid: BigNumber; takerFeePaid: BigNumber; - } + }, ] >(rawCallResult); // tslint:enable boolean-naming @@ -828,7 +828,7 @@ export class ForwarderContract extends BaseContract { takerAssetFilledAmount: BigNumber; makerFeePaid: BigNumber; takerFeePaid: BigNumber; - } + }, ] > { assert.isArray('orders', orders); @@ -881,7 +881,7 @@ export class ForwarderContract extends BaseContract { takerAssetFilledAmount: BigNumber; makerFeePaid: BigNumber; takerFeePaid: BigNumber; - } + }, ] >(rawCallResult); // tslint:enable boolean-naming diff --git a/packages/order-utils/src/index.ts b/packages/order-utils/src/index.ts index 071c9e3b45..dcddf418a3 100644 --- a/packages/order-utils/src/index.ts +++ b/packages/order-utils/src/index.ts @@ -74,9 +74,6 @@ export { TypedDataError, TradeSide, TransferType, - SignatureValidationOpts, - ValidatorSignatureOpts, - PresignedSignatureOpts, FindFeeOrdersThatCoverFeesForTargetOrdersOpts, FindOrdersThatCoverMakerAssetFillAmountOpts, FindOrdersThatCoverTakerAssetFillAmountOpts, diff --git a/packages/order-utils/src/order_validation_utils.ts b/packages/order-utils/src/order_validation_utils.ts index a8ce0a0d02..9c5309e264 100644 --- a/packages/order-utils/src/order_validation_utils.ts +++ b/packages/order-utils/src/order_validation_utils.ts @@ -194,7 +194,7 @@ export class OrderValidationUtils { orderHash, signedOrder.signature, signedOrder.makerAddress, - { exchangeAddress: signedOrder.exchangeAddress }, + signedOrder.exchangeAddress, ); if (!isValidSignature) { throw new Error(RevertReason.InvalidOrderSignature); @@ -255,6 +255,7 @@ export class OrderValidationUtils { orderHash, signedOrder.signature, signedOrder.makerAddress, + signedOrder.exchangeAddress, ); if (!isValid) { throw new Error(TypedDataError.InvalidSignature); diff --git a/packages/order-utils/src/signature_utils.ts b/packages/order-utils/src/signature_utils.ts index aaba0b9944..0a68482ba9 100644 --- a/packages/order-utils/src/signature_utils.ts +++ b/packages/order-utils/src/signature_utils.ts @@ -20,7 +20,7 @@ import { assert } from './assert'; import { eip712Utils } from './eip712_utils'; import { orderHashUtils } from './order_hash'; import { transactionHashUtils } from './transaction_hash'; -import { PresignedSignatureOpts, SignatureValidationOpts, TypedDataError, ValidatorSignatureOpts } from './types'; +import { TypedDataError } from './types'; import { utils } from './utils'; export const signatureUtils = { @@ -31,7 +31,7 @@ export const signatureUtils = { * @param signature A hex encoded 0x Protocol signature made up of: [TypeSpecificData][SignatureType]. * E.g [vrs][SignatureType.EIP712] * @param signerAddress The hex encoded address that signed the data, producing the supplied signature. - * @param signatureValidationOpts Optional additional information to pass to signature validation functions. + * @param exchangeAddress Optional address of the Exchange contract to validate the signature against. * @return Whether the signature is valid for the supplied signerAddress and data. */ async isValidSignatureAsync( @@ -39,7 +39,7 @@ export const signatureUtils = { data: string, signature: string, signerAddress: string, - signatureValidationOpts?: SignatureValidationOpts, + exchangeAddress?: string, ): Promise { const provider = providerUtils.standardizeOrThrow(supportedProvider); assert.isHexString('data', data); @@ -77,8 +77,6 @@ export const signatureUtils = { } case SignatureType.Validator: { - const exchangeAddress = - signatureValidationOpts && (signatureValidationOpts as ValidatorSignatureOpts).exchangeAddress; const isValid = await signatureUtils.isValidValidatorSignatureAsync( provider, data, @@ -90,8 +88,6 @@ export const signatureUtils = { } case SignatureType.PreSigned: { - const exchangeAddress = - signatureValidationOpts && (signatureValidationOpts as PresignedSignatureOpts).exchangeAddress; return signatureUtils.isValidPresignedSignatureAsync(provider, data, signerAddress, exchangeAddress); } diff --git a/packages/order-utils/src/types.ts b/packages/order-utils/src/types.ts index 94947f708b..c58eafe036 100644 --- a/packages/order-utils/src/types.ts +++ b/packages/order-utils/src/types.ts @@ -25,15 +25,6 @@ export interface CreateOrderOpts { expirationTimeSeconds?: BigNumber; } -export type SignatureValidationOpts = ValidatorSignatureOpts | PresignedSignatureOpts; - -export interface ValidatorSignatureOpts { - exchangeAddress: string; -} - -export interface PresignedSignatureOpts { - exchangeAddress: string; -} /** * remainingFillableMakerAssetAmount: An array of BigNumbers corresponding to the `orders` parameter. * You can use `OrderStateUtils` `@0x/order-utils` to perform blockchain lookups for these values. diff --git a/packages/order-watcher/src/order_watcher/order_watcher.ts b/packages/order-watcher/src/order_watcher/order_watcher.ts index 4162a4deae..fb6d659c4f 100644 --- a/packages/order-watcher/src/order_watcher/order_watcher.ts +++ b/packages/order-watcher/src/order_watcher/order_watcher.ts @@ -160,9 +160,13 @@ export class OrderWatcher { public async addOrderAsync(signedOrder: SignedOrder): Promise { assert.doesConformToSchema('signedOrder', signedOrder, schemas.signedOrderSchema); const orderHash = orderHashUtils.getOrderHashHex(signedOrder); - await assert.isValidSignatureAsync(this._provider, orderHash, signedOrder.signature, signedOrder.makerAddress, { - exchangeAddress: signedOrder.exchangeAddress, - }); + await assert.isValidSignatureAsync( + this._provider, + orderHash, + signedOrder.signature, + signedOrder.makerAddress, + signedOrder.exchangeAddress, + ); const expirationUnixTimestampMs = signedOrder.expirationTimeSeconds.times(MILLISECONDS_IN_A_SECOND); this._expirationWatcher.addOrder(orderHash, expirationUnixTimestampMs); diff --git a/packages/order-watcher/src/utils/assert.ts b/packages/order-watcher/src/utils/assert.ts index 8bc1554a10..efd2873f45 100644 --- a/packages/order-watcher/src/utils/assert.ts +++ b/packages/order-watcher/src/utils/assert.ts @@ -7,7 +7,7 @@ import { BigNumber } from '@0x/utils'; // tslint:enable:no-unused-variable import { SupportedProvider } from 'ethereum-types'; -import { signatureUtils, SignatureValidationOpts } from '@0x/order-utils'; +import { signatureUtils } from '@0x/order-utils'; export const assert = { ...sharedAssert, @@ -16,14 +16,14 @@ export const assert = { orderHash: string, signature: string, signerAddress: string, - signatureValidationOpts: SignatureValidationOpts, + exchangeAddress?: string, ): Promise { const isValid = await signatureUtils.isValidSignatureAsync( supportedProvider, orderHash, signature, signerAddress, - signatureValidationOpts, + exchangeAddress, ); assert.assert(isValid, `Expected order with hash '${orderHash}' to have a valid signature`); },