diff options
-rw-r--r-- | packages/0x.js/package.json | 2 | ||||
-rw-r--r-- | packages/contract-wrappers/test/exchange_wrapper_test.ts | 19 | ||||
-rw-r--r-- | packages/order-utils/CHANGELOG.json | 4 | ||||
-rw-r--r-- | packages/order-utils/package.json | 1 | ||||
-rw-r--r-- | packages/order-utils/src/signature_utils.ts | 10 | ||||
-rw-r--r-- | packages/order-utils/test/signature_utils_test.ts | 11 |
6 files changed, 44 insertions, 3 deletions
diff --git a/packages/0x.js/package.json b/packages/0x.js/package.json index 9c7adbbcd..58cd439fd 100644 --- a/packages/0x.js/package.json +++ b/packages/0x.js/package.json @@ -24,7 +24,7 @@ "test:coverage": "nyc npm run test --all && yarn coverage:report:lcov", "coverage:report:lcov": "nyc report --reporter=text-lcov > coverage/lcov.info", "clean": "shx rm -rf _bundles lib test_temp src/generated_contract_wrappers generated_docs", - "build:umd:prod": "NODE_ENV=production webpack", + "build:umd:prod": "NODE_ENV=production node --max_old_space_size=8192 ../../node_modules/.bin/webpack --mode production", "build:commonjs": "tsc -b", "docs:json": "typedoc --excludePrivate --excludeExternals --target ES5 --tsconfig typedoc-tsconfig.json --json $JSON_FILE_PATH $PROJECT_FILES" }, diff --git a/packages/contract-wrappers/test/exchange_wrapper_test.ts b/packages/contract-wrappers/test/exchange_wrapper_test.ts index a1d60dc6e..acd30495b 100644 --- a/packages/contract-wrappers/test/exchange_wrapper_test.ts +++ b/packages/contract-wrappers/test/exchange_wrapper_test.ts @@ -1,6 +1,6 @@ import { BlockchainLifecycle, callbackErrorReporter } from '@0x/dev-utils'; import { FillScenarios } from '@0x/fill-scenarios'; -import { assetDataUtils, orderHashUtils } from '@0x/order-utils'; +import { assetDataUtils, orderHashUtils, signatureUtils } from '@0x/order-utils'; import { DoneCallback, RevertReason, SignedOrder } from '@0x/types'; import { BigNumber } from '@0x/utils'; import * as chai from 'chai'; @@ -368,6 +368,23 @@ describe('ExchangeWrapper', () => { await web3Wrapper.awaitTransactionSuccessAsync(txHash, constants.AWAIT_TRANSACTION_MINED_MS); isPreSigned = await contractWrappers.exchange.isPreSignedAsync(hash, signerAddress); expect(isPreSigned).to.be.true(); + + const preSignedSignature = '0x06'; + const isValidSignature = await contractWrappers.exchange.isValidSignatureAsync( + hash, + signerAddress, + preSignedSignature, + ); + expect(isValidSignature).to.be.true(); + + // Test our TS implementation of signature validation + const isValidSignatureInTs = await signatureUtils.isValidSignatureAsync( + provider, + hash, + preSignedSignature, + signerAddress, + ); + expect(isValidSignatureInTs).to.be.true(); }); }); describe('#getVersionAsync', () => { diff --git a/packages/order-utils/CHANGELOG.json b/packages/order-utils/CHANGELOG.json index 8a104c8ef..8fa0b358c 100644 --- a/packages/order-utils/CHANGELOG.json +++ b/packages/order-utils/CHANGELOG.json @@ -5,6 +5,10 @@ { "note": "Upgrade the bignumber.js to v8.0.2", "pr": 1517 + }, + { + "note": "Fix preSigned isSignatureValidAsync check", + "pr": 1580 } ], "timestamp": 1549373905 diff --git a/packages/order-utils/package.json b/packages/order-utils/package.json index b4b33d6e6..3f14cea5f 100644 --- a/packages/order-utils/package.json +++ b/packages/order-utils/package.json @@ -57,6 +57,7 @@ "@0x/assert": "^2.0.0", "@0x/base-contract": "^4.0.0", "@0x/contract-artifacts": "^1.3.0", + "@0x/contract-addresses": "^2.2.0", "@0x/json-schemas": "^3.0.0", "@0x/types": "^2.0.0", "@0x/typescript-typings": "^4.0.0", diff --git a/packages/order-utils/src/signature_utils.ts b/packages/order-utils/src/signature_utils.ts index 131144d48..efcc146bf 100644 --- a/packages/order-utils/src/signature_utils.ts +++ b/packages/order-utils/src/signature_utils.ts @@ -1,4 +1,5 @@ import { ExchangeContract, IValidatorContract, IWalletContract } from '@0x/abi-gen-wrappers'; +import { getContractAddressesForNetworkOrThrow } from '@0x/contract-addresses'; import * as artifacts from '@0x/contract-artifacts'; import { schemas } from '@0x/json-schemas'; import { ECSignature, Order, SignatureType, SignedOrder, ValidatorSignature } from '@0x/types'; @@ -92,7 +93,14 @@ export const signatureUtils = { assert.isWeb3Provider('provider', provider); assert.isHexString('data', data); assert.isETHAddressHex('signerAddress', signerAddress); - const exchangeContract = new ExchangeContract(artifacts.Exchange.compilerOutput.abi, signerAddress, provider); + const web3Wrapper = new Web3Wrapper(provider); + const networkId = await web3Wrapper.getNetworkIdAsync(); + const addresses = getContractAddressesForNetworkOrThrow(networkId); + const exchangeContract = new ExchangeContract( + artifacts.Exchange.compilerOutput.abi, + addresses.exchange, + provider, + ); const isValid = await exchangeContract.preSigned.callAsync(data, signerAddress); return isValid; }, diff --git a/packages/order-utils/test/signature_utils_test.ts b/packages/order-utils/test/signature_utils_test.ts index 937382056..44aa729b3 100644 --- a/packages/order-utils/test/signature_utils_test.ts +++ b/packages/order-utils/test/signature_utils_test.ts @@ -99,6 +99,17 @@ describe('Signature utils', () => { ); expect(isValidSignatureLocal).to.be.true(); }); + + it('should return false if entry not found in `preSigned` mapping', async () => { + const preSignedSignature = '0x06'; + const isValidPreSignature = await signatureUtils.isValidSignatureAsync( + provider, + dataHex, + preSignedSignature, + address, + ); + expect(isValidPreSignature).to.be.false(); + }); }); describe('#isValidECSignature', () => { const signature = { |