diff options
author | Brandon Millman <brandon.millman@gmail.com> | 2018-05-24 05:16:32 +0800 |
---|---|---|
committer | Brandon Millman <brandon.millman@gmail.com> | 2018-05-24 05:16:32 +0800 |
commit | 3fe94891d3569a4615f4aa32d47f0065b5957fe9 (patch) | |
tree | 83d4e4ccf7748d2100aa935c457de0a893eaec9c /packages/order-utils | |
parent | d0abc60176dba3116cb3986d298ab5164c1fe49c (diff) | |
parent | f6b81f588d98e09e7a5806902d94e2892d029481 (diff) | |
download | dexon-sol-tools-3fe94891d3569a4615f4aa32d47f0065b5957fe9.tar dexon-sol-tools-3fe94891d3569a4615f4aa32d47f0065b5957fe9.tar.gz dexon-sol-tools-3fe94891d3569a4615f4aa32d47f0065b5957fe9.tar.bz2 dexon-sol-tools-3fe94891d3569a4615f4aa32d47f0065b5957fe9.tar.lz dexon-sol-tools-3fe94891d3569a4615f4aa32d47f0065b5957fe9.tar.xz dexon-sol-tools-3fe94891d3569a4615f4aa32d47f0065b5957fe9.tar.zst dexon-sol-tools-3fe94891d3569a4615f4aa32d47f0065b5957fe9.zip |
Merge branch 'v2-prototype' into feature/website/wallet-flex-box
* v2-prototype: (95 commits)
Add missing dep to website
Upgrade solidity parser
Fix trace test
Fix linter issues
Move contract utils
Fix prettier
Fix NameResolver
Fix prettier
Remove 0x.js as a dependency from website
Enable 0x.js tests
Fix small bug in order-utils
Address feedback
Fix Tslint error caused by "PromiseLike" value
Fix Tslint error caused by "PromiseLike" value
Update dogfood url
fix contract-wrappers version
Parse compiler.json in SolCompilerArtifactsAdapter
Fix TokenTransferProxy artifact name since it's now suffixed with _v1
Update yarn.lock
Fix signature verification test
...
Diffstat (limited to 'packages/order-utils')
-rw-r--r-- | packages/order-utils/CHANGELOG.json | 6 | ||||
-rw-r--r-- | packages/order-utils/CHANGELOG.md | 6 | ||||
-rw-r--r-- | packages/order-utils/package.json | 20 | ||||
-rw-r--r-- | packages/order-utils/src/order_hash.ts | 3 | ||||
-rw-r--r-- | packages/order-utils/src/signature_utils.ts | 17 | ||||
-rw-r--r-- | packages/order-utils/test/signature_utils_test.ts | 12 | ||||
-rw-r--r-- | packages/order-utils/test/utils/web3_wrapper.ts | 5 |
7 files changed, 42 insertions, 27 deletions
diff --git a/packages/order-utils/CHANGELOG.json b/packages/order-utils/CHANGELOG.json index 9399379fa..1bdb25347 100644 --- a/packages/order-utils/CHANGELOG.json +++ b/packages/order-utils/CHANGELOG.json @@ -3,13 +3,11 @@ "version": "0.0.5", "changes": [ { - "note": "Add formatters package for converting signedOrder to orderAddresses & orderValues", - "note": "Add RemainingFillableCalculator to calculate the remaining fillable amount of an order", - "note": "Add AbstractBalanceAndProxyAllowanceFetcher and AbstractOrderFilledCancelledFetcher", "note": "Add orderStateUtils, a module for computing order state needed to decide if an order is still valid" } - ] + ], + "timestamp": 1527008794 }, { "timestamp": 1525477860, diff --git a/packages/order-utils/CHANGELOG.md b/packages/order-utils/CHANGELOG.md index d0bb706aa..5b10c13bc 100644 --- a/packages/order-utils/CHANGELOG.md +++ b/packages/order-utils/CHANGELOG.md @@ -5,7 +5,11 @@ Edit the package's CHANGELOG.json file only. CHANGELOG -## v0.0.4 - _May 5, 2018_ +## v0.0.5 - _May 22, 2018_ + + * Add orderStateUtils, a module for computing order state needed to decide if an order is still valid + +## v0.0.4 - _May 4, 2018_ * Dependencies updated diff --git a/packages/order-utils/package.json b/packages/order-utils/package.json index 63caaec34..117b57f45 100644 --- a/packages/order-utils/package.json +++ b/packages/order-utils/package.json @@ -1,6 +1,6 @@ { "name": "@0xproject/order-utils", - "version": "0.0.4", + "version": "0.0.5", "engines": { "node": ">=6.12" }, @@ -43,9 +43,9 @@ }, "homepage": "https://github.com/0xProject/0x-monorepo/packages/order-utils/README.md", "devDependencies": { - "@0xproject/dev-utils": "^0.4.1", - "@0xproject/monorepo-scripts": "^0.1.19", - "@0xproject/tslint-config": "^0.4.17", + "@0xproject/dev-utils": "^0.4.2", + "@0xproject/monorepo-scripts": "^0.1.20", + "@0xproject/tslint-config": "^0.4.18", "@types/lodash": "4.14.104", "chai": "^4.0.1", "chai-as-promised": "^7.1.0", @@ -62,12 +62,12 @@ "typescript": "2.7.1" }, "dependencies": { - "@0xproject/assert": "^0.2.9", - "@0xproject/json-schemas": "^0.7.23", - "@0xproject/types": "^0.6.3", - "@0xproject/typescript-typings": "^0.3.1", - "@0xproject/utils": "^0.6.1", - "@0xproject/web3-wrapper": "^0.6.3", + "@0xproject/assert": "^0.2.10", + "@0xproject/json-schemas": "^0.7.24", + "@0xproject/types": "^0.7.0", + "@0xproject/typescript-typings": "^0.3.2", + "@0xproject/utils": "^0.6.2", + "@0xproject/web3-wrapper": "^0.6.4", "@types/node": "^8.0.53", "bn.js": "^4.11.8", "ethereumjs-abi": "^0.6.4", diff --git a/packages/order-utils/src/order_hash.ts b/packages/order-utils/src/order_hash.ts index 1cde72a73..108344a04 100644 --- a/packages/order-utils/src/order_hash.ts +++ b/packages/order-utils/src/order_hash.ts @@ -17,7 +17,8 @@ const INVALID_TAKER_FORMAT = 'instance.taker is not of a type(s) string'; * We do not use BN anywhere else in the codebase. */ function bigNumberToBN(value: BigNumber): BN { - return new BN(value.toString(), 10); + const base = 10; + return new BN(value.toString(), base); } /** diff --git a/packages/order-utils/src/signature_utils.ts b/packages/order-utils/src/signature_utils.ts index b511573a8..ebd636b20 100644 --- a/packages/order-utils/src/signature_utils.ts +++ b/packages/order-utils/src/signature_utils.ts @@ -72,6 +72,7 @@ export async function signOrderHashAsync( // v + r + s OR r + s + v, and different clients (even different versions of the same client) // return the signature params in different orders. In order to support all client implementations, // we parse the signature in both ways, and evaluate if either one is a valid signature. + // tslint:disable-next-line:custom-no-magic-numbers const validVParamValues = [27, 28]; const ecSignatureVRS = parseSignatureHexAsVRS(signature); if (_.includes(validVParamValues, ecSignatureVRS.v)) { @@ -95,11 +96,19 @@ export async function signOrderHashAsync( function parseSignatureHexAsVRS(signatureHex: string): ECSignature { const signatureBuffer = ethUtil.toBuffer(signatureHex); let v = signatureBuffer[0]; - if (v < 27) { - v += 27; + // HACK: Sometimes v is returned as [0, 1] and sometimes as [27, 28] + // If it is returned as [0, 1], add 27 to both so it becomes [27, 28] + const lowestValidV = 27; + const isProperlyFormattedV = v >= lowestValidV; + if (!isProperlyFormattedV) { + v += lowestValidV; } - const r = signatureBuffer.slice(1, 33); - const s = signatureBuffer.slice(33, 65); + // signatureBuffer contains vrs + const vEndIndex = 1; + const rsIndex = 33; + const r = signatureBuffer.slice(vEndIndex, rsIndex); + const sEndIndex = 65; + const s = signatureBuffer.slice(rsIndex, sEndIndex); const ecSignature: ECSignature = { v, r: ethUtil.bufferToHex(r), diff --git a/packages/order-utils/test/signature_utils_test.ts b/packages/order-utils/test/signature_utils_test.ts index 4b4de9217..e24fa0ce5 100644 --- a/packages/order-utils/test/signature_utils_test.ts +++ b/packages/order-utils/test/signature_utils_test.ts @@ -47,12 +47,13 @@ describe('Signature utils', () => { }); describe('#generateSalt', () => { it('generates different salts', () => { - const equal = generatePseudoRandomSalt().eq(generatePseudoRandomSalt()); - expect(equal).to.be.false(); + const isEqual = generatePseudoRandomSalt().eq(generatePseudoRandomSalt()); + expect(isEqual).to.be.false(); }); it('generates salt in range [0..2^256)', () => { const salt = generatePseudoRandomSalt(); expect(salt.greaterThanOrEqualTo(0)).to.be.true(); + // tslint:disable-next-line:custom-no-magic-numbers const twoPow256 = new BigNumber(2).pow(256); expect(salt.lessThan(twoPow256)).to.be.true(); }); @@ -67,7 +68,8 @@ describe('Signature utils', () => { expect(isValid).to.be.false(); }); it('returns true if order hash is correct', () => { - const isValid = isValidOrderHash('0x' + Array(65).join('0')); + const orderHashLength = 65; + const isValid = isValidOrderHash('0x' + Array(orderHashLength).join('0')); expect(isValid).to.be.true(); }); }); @@ -111,10 +113,12 @@ describe('Signature utils', () => { if (payload.method === 'eth_sign') { const [address, message] = payload.params; const signature = await web3Wrapper.signMessageAsync(address, message); + // tslint:disable-next-line:custom-no-magic-numbers + const rsvHex = `0x${signature.substr(130)}${signature.substr(2, 128)}`; callback(null, { id: 42, jsonrpc: '2.0', - result: `0x${signature.substr(130)}${signature.substr(2, 128)}`, + result: rsvHex, }); } else { callback(null, { id: 42, jsonrpc: '2.0', result: [makerAddress] }); diff --git a/packages/order-utils/test/utils/web3_wrapper.ts b/packages/order-utils/test/utils/web3_wrapper.ts index b0ccfa546..71a0dc1c2 100644 --- a/packages/order-utils/test/utils/web3_wrapper.ts +++ b/packages/order-utils/test/utils/web3_wrapper.ts @@ -2,8 +2,7 @@ import { devConstants, web3Factory } from '@0xproject/dev-utils'; import { Provider } from '@0xproject/types'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; -const web3 = web3Factory.create({ shouldUseInProcessGanache: true }); -const provider: Provider = web3.currentProvider; -const web3Wrapper = new Web3Wrapper(web3.currentProvider); +const provider: Provider = web3Factory.getRpcProvider({ shouldUseInProcessGanache: true }); +const web3Wrapper = new Web3Wrapper(provider); export { provider, web3Wrapper }; |