aboutsummaryrefslogtreecommitdiffstats
path: root/src/0x.ts
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2017-07-08 08:43:52 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2017-07-08 08:43:52 +0800
commit305b98ee21bcfa733390b157c187d2ab88e122b2 (patch)
tree84b6d381d63f046fdc14047195250856c7ef5dae /src/0x.ts
parent39daf6f963a3abd5086007e38818f3af087e220b (diff)
parent6b80134f481d7496884d12d2a76fa8cf4f6f2875 (diff)
downloaddexon-sol-tools-305b98ee21bcfa733390b157c187d2ab88e122b2.tar
dexon-sol-tools-305b98ee21bcfa733390b157c187d2ab88e122b2.tar.gz
dexon-sol-tools-305b98ee21bcfa733390b157c187d2ab88e122b2.tar.bz2
dexon-sol-tools-305b98ee21bcfa733390b157c187d2ab88e122b2.tar.lz
dexon-sol-tools-305b98ee21bcfa733390b157c187d2ab88e122b2.tar.xz
dexon-sol-tools-305b98ee21bcfa733390b157c187d2ab88e122b2.tar.zst
dexon-sol-tools-305b98ee21bcfa733390b157c187d2ab88e122b2.zip
Merge branch 'master' of github.com:0xProject/0x.js
Diffstat (limited to 'src/0x.ts')
-rw-r--r--src/0x.ts48
1 files changed, 19 insertions, 29 deletions
diff --git a/src/0x.ts b/src/0x.ts
index 95935c258..92a892336 100644
--- a/src/0x.ts
+++ b/src/0x.ts
@@ -9,6 +9,7 @@ import compareVersions = require('compare-versions');
import {Web3Wrapper} from './web3_wrapper';
import {constants} from './utils/constants';
import {utils} from './utils/utils';
+import {signatureUtils} from './utils/signature_utils';
import {assert} from './utils/assert';
import {ExchangeWrapper} from './contract_wrappers/exchange_wrapper';
import {TokenRegistryWrapper} from './contract_wrappers/token_registry_wrapper';
@@ -221,39 +222,28 @@ export class ZeroEx {
const signature = await this._web3Wrapper.signTransactionAsync(signerAddress, msgHashHex);
- let signatureData;
- const [nodeVersionNumber] = findVersions(nodeVersion);
- // Parity v1.6.6 and earlier returns the signatureData as vrs instead of rsv as Geth does
- // Later versions return rsv but for the time being we still want to support version < 1.6.6
- // Date: May 23rd 2017
- const latestParityVersionWithVRS = '1.6.6';
- const isVersionBeforeParityFix = compareVersions(nodeVersionNumber, latestParityVersionWithVRS) <= 0;
- if (isParityNode && isVersionBeforeParityFix) {
- const signatureBuffer = ethUtil.toBuffer(signature);
- let v = signatureBuffer[0];
- if (v < 27) {
- v += 27;
+ // HACK: There is no consensus on whether the signatureHex string should be formatted as
+ // 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.
+ const validVParamValues = [27, 28];
+ const ecSignatureVRS = signatureUtils.parseSignatureHexAsVRS(signature);
+ if (_.includes(validVParamValues, ecSignatureVRS.v)) {
+ const isValidVRSSignature = ZeroEx.isValidSignature(orderHash, ecSignatureVRS, signerAddress);
+ if (isValidVRSSignature) {
+ return ecSignatureVRS;
}
- signatureData = {
- v,
- r: signatureBuffer.slice(1, 33),
- s: signatureBuffer.slice(33, 65),
- };
- } else {
- signatureData = ethUtil.fromRpcSig(signature);
}
- const {v, r, s} = signatureData;
- const ecSignature: ECSignature = {
- v,
- r: ethUtil.bufferToHex(r),
- s: ethUtil.bufferToHex(s),
- };
- const isValidSignature = ZeroEx.isValidSignature(orderHash, ecSignature, signerAddress);
- if (!isValidSignature) {
- throw new Error(ZeroExError.INVALID_SIGNATURE);
+ const ecSignatureRSV = signatureUtils.parseSignatureHexAsRSV(signature);
+ if (_.includes(validVParamValues, ecSignatureRSV.v)) {
+ const isValidRSVSignature = ZeroEx.isValidSignature(orderHash, ecSignatureRSV, signerAddress);
+ if (isValidRSVSignature) {
+ return ecSignatureRSV;
+ }
}
- return ecSignature;
+
+ throw new Error(ZeroExError.INVALID_SIGNATURE);
}
/**
* Returns the ethereum addresses of all available exchange contracts