diff options
author | Fabio Berger <me@fabioberger.com> | 2018-11-10 07:14:48 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2018-11-10 07:14:48 +0800 |
commit | 1f0ac47bd97b88071a6380a728cfdb1457c2590c (patch) | |
tree | 7e8382598010265306d282e3aa1330d636bbf22f /packages/order-utils/src | |
parent | 773cf3cd143769a93cea66b30d46cb9f4620b74d (diff) | |
download | dexon-sol-tools-1f0ac47bd97b88071a6380a728cfdb1457c2590c.tar dexon-sol-tools-1f0ac47bd97b88071a6380a728cfdb1457c2590c.tar.gz dexon-sol-tools-1f0ac47bd97b88071a6380a728cfdb1457c2590c.tar.bz2 dexon-sol-tools-1f0ac47bd97b88071a6380a728cfdb1457c2590c.tar.lz dexon-sol-tools-1f0ac47bd97b88071a6380a728cfdb1457c2590c.tar.xz dexon-sol-tools-1f0ac47bd97b88071a6380a728cfdb1457c2590c.tar.zst dexon-sol-tools-1f0ac47bd97b88071a6380a728cfdb1457c2590c.zip |
Move signature validation into OrderValidationUtils.validateOrderFillableOrThrowAsync
Diffstat (limited to 'packages/order-utils/src')
-rw-r--r-- | packages/order-utils/src/order_validation_utils.ts | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/packages/order-utils/src/order_validation_utils.ts b/packages/order-utils/src/order_validation_utils.ts index 2150e643f..ca4c32543 100644 --- a/packages/order-utils/src/order_validation_utils.ts +++ b/packages/order-utils/src/order_validation_utils.ts @@ -17,6 +17,7 @@ import { utils } from './utils'; */ export class OrderValidationUtils { private readonly _orderFilledCancelledFetcher: AbstractOrderFilledCancelledFetcher; + private readonly _provider: Provider; /** * A Typescript implementation mirroring the implementation of isRoundingError in the * Exchange smart contract @@ -116,8 +117,9 @@ export class OrderValidationUtils { * @param orderFilledCancelledFetcher A module that implements the AbstractOrderFilledCancelledFetcher * @return An instance of OrderValidationUtils */ - constructor(orderFilledCancelledFetcher: AbstractOrderFilledCancelledFetcher) { + constructor(orderFilledCancelledFetcher: AbstractOrderFilledCancelledFetcher, provider: Provider) { this._orderFilledCancelledFetcher = orderFilledCancelledFetcher; + this._provider = provider; } // TODO(fabio): remove this method once the smart contracts have been refactored // to return helpful revert reasons instead of ORDER_UNFILLABLE. Instruct devs @@ -137,6 +139,16 @@ export class OrderValidationUtils { expectedFillTakerTokenAmount?: BigNumber, ): Promise<void> { const orderHash = orderHashUtils.getOrderHashHex(signedOrder); + const isValidSignature = await signatureUtils.isValidSignatureAsync( + this._provider, + orderHash, + signedOrder.signature, + signedOrder.makerAddress, + ); + if (!isValidSignature) { + throw new Error('INVALID_ORDER_SIGNATURE'); + } + const isCancelled = await this._orderFilledCancelledFetcher.isOrderCancelledAsync(signedOrder); if (isCancelled) { throw new Error('CANCELLED'); |