Pass exchangeAddress instead of SignatureOpts
This commit is contained in:
@@ -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();
|
||||
});
|
||||
|
||||
|
@@ -6,9 +6,6 @@ export {
|
||||
generatePseudoRandomSalt,
|
||||
orderHashUtils,
|
||||
transactionHashUtils,
|
||||
SignatureValidationOpts,
|
||||
ValidatorSignatureOpts,
|
||||
PresignedSignatureOpts,
|
||||
} from '@0x/order-utils';
|
||||
|
||||
export {
|
||||
|
@@ -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
|
||||
|
@@ -74,9 +74,6 @@ export {
|
||||
TypedDataError,
|
||||
TradeSide,
|
||||
TransferType,
|
||||
SignatureValidationOpts,
|
||||
ValidatorSignatureOpts,
|
||||
PresignedSignatureOpts,
|
||||
FindFeeOrdersThatCoverFeesForTargetOrdersOpts,
|
||||
FindOrdersThatCoverMakerAssetFillAmountOpts,
|
||||
FindOrdersThatCoverTakerAssetFillAmountOpts,
|
||||
|
@@ -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);
|
||||
|
@@ -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<boolean> {
|
||||
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);
|
||||
}
|
||||
|
||||
|
@@ -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.
|
||||
|
@@ -160,9 +160,13 @@ export class OrderWatcher {
|
||||
public async addOrderAsync(signedOrder: SignedOrder): Promise<void> {
|
||||
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);
|
||||
|
@@ -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<void> {
|
||||
const isValid = await signatureUtils.isValidSignatureAsync(
|
||||
supportedProvider,
|
||||
orderHash,
|
||||
signature,
|
||||
signerAddress,
|
||||
signatureValidationOpts,
|
||||
exchangeAddress,
|
||||
);
|
||||
assert.assert(isValid, `Expected order with hash '${orderHash}' to have a valid signature`);
|
||||
},
|
||||
|
Reference in New Issue
Block a user