From 3d7bcd7ecbd586e3c78e94b9cfc3d1a004ad86dd Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Fri, 29 Jun 2018 16:17:25 +0300 Subject: Add isSubscriptionToken assertion --- .../contract-wrappers/src/contract_wrappers/erc20_token_wrapper.ts | 1 + .../contract-wrappers/src/contract_wrappers/erc721_token_wrapper.ts | 1 + .../contract-wrappers/src/contract_wrappers/ether_token_wrapper.ts | 1 + packages/contract-wrappers/src/utils/assert.ts | 5 +++++ 4 files changed, 8 insertions(+) (limited to 'packages/contract-wrappers') diff --git a/packages/contract-wrappers/src/contract_wrappers/erc20_token_wrapper.ts b/packages/contract-wrappers/src/contract_wrappers/erc20_token_wrapper.ts index a6e5d8765..f393e4ed1 100644 --- a/packages/contract-wrappers/src/contract_wrappers/erc20_token_wrapper.ts +++ b/packages/contract-wrappers/src/contract_wrappers/erc20_token_wrapper.ts @@ -379,6 +379,7 @@ export class ERC20TokenWrapper extends ContractWrapper { * @param subscriptionToken Subscription token returned by `subscribe()` */ public unsubscribe(subscriptionToken: string): void { + assert.isValidSubscriptionToken('subscriptionToken', subscriptionToken); this._unsubscribe(subscriptionToken); } /** diff --git a/packages/contract-wrappers/src/contract_wrappers/erc721_token_wrapper.ts b/packages/contract-wrappers/src/contract_wrappers/erc721_token_wrapper.ts index 8867fd35d..415415fd7 100644 --- a/packages/contract-wrappers/src/contract_wrappers/erc721_token_wrapper.ts +++ b/packages/contract-wrappers/src/contract_wrappers/erc721_token_wrapper.ts @@ -411,6 +411,7 @@ export class ERC721TokenWrapper extends ContractWrapper { * @param subscriptionToken Subscription token returned by `subscribe()` */ public unsubscribe(subscriptionToken: string): void { + assert.isValidSubscriptionToken('subscriptionToken', subscriptionToken); this._unsubscribe(subscriptionToken); } /** diff --git a/packages/contract-wrappers/src/contract_wrappers/ether_token_wrapper.ts b/packages/contract-wrappers/src/contract_wrappers/ether_token_wrapper.ts index f8e4a683c..97872c247 100644 --- a/packages/contract-wrappers/src/contract_wrappers/ether_token_wrapper.ts +++ b/packages/contract-wrappers/src/contract_wrappers/ether_token_wrapper.ts @@ -168,6 +168,7 @@ export class EtherTokenWrapper extends ContractWrapper { * @param subscriptionToken Subscription token returned by `subscribe()` */ public unsubscribe(subscriptionToken: string): void { + assert.isValidSubscriptionToken('subscriptionToken', subscriptionToken); this._unsubscribe(subscriptionToken); } /** diff --git a/packages/contract-wrappers/src/utils/assert.ts b/packages/contract-wrappers/src/utils/assert.ts index 76ad06e91..da6697b08 100644 --- a/packages/contract-wrappers/src/utils/assert.ts +++ b/packages/contract-wrappers/src/utils/assert.ts @@ -18,6 +18,11 @@ export const assert = { const isValid = await isValidSignatureAsync(provider, orderHash, signature, signerAddress); this.assert(isValid, `Expected order with hash '${orderHash}' to have a valid signature`); }, + isValidSubscriptionToken(variableName: string, subscriptionToken: string): void { + const uuidRegex = new RegExp('^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$'); + const isValid = uuidRegex.test(subscriptionToken); + this.assert(isValid, `Expected ${variableName} to be a valid subscription token`); + }, async isSenderAddressAsync( variableName: string, senderAddressHex: string, -- cgit