aboutsummaryrefslogtreecommitdiffstats
path: root/packages/0x.js
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2018-01-30 19:38:44 +0800
committerFabio Berger <me@fabioberger.com>2018-01-30 19:38:44 +0800
commit1cadbeed88d2e5f413c8f7e39aaee6efcff89831 (patch)
tree3cede90b64c1b9f85feda80b7564526615ca7b24 /packages/0x.js
parentad52a82190259580f00b3a06b06ef1e950ccdc68 (diff)
downloaddexon-0x-contracts-1cadbeed88d2e5f413c8f7e39aaee6efcff89831.tar.gz
dexon-0x-contracts-1cadbeed88d2e5f413c8f7e39aaee6efcff89831.tar.zst
dexon-0x-contracts-1cadbeed88d2e5f413c8f7e39aaee6efcff89831.zip
Add shouldAddPersonalMessagePrefix param to signOrderHashAsync instead of trying to infer whether to add it or not from the nodeVersion
Diffstat (limited to 'packages/0x.js')
-rw-r--r--packages/0x.js/CHANGELOG.md15
-rw-r--r--packages/0x.js/src/0x.ts20
-rw-r--r--packages/0x.js/src/utils/utils.ts6
-rw-r--r--packages/0x.js/test/0x.js_test.ts20
-rw-r--r--packages/0x.js/test/utils/order_factory.ts4
5 files changed, 44 insertions, 21 deletions
diff --git a/packages/0x.js/CHANGELOG.md b/packages/0x.js/CHANGELOG.md
index ec44bfc16..1acc202e2 100644
--- a/packages/0x.js/CHANGELOG.md
+++ b/packages/0x.js/CHANGELOG.md
@@ -1,10 +1,21 @@
# CHANGELOG
-## v0.30.1 - _TBD, 2018_
+## v0.31.0 - _January 30, 2018_
+
+ * Add the `shouldAddPersonalMessagePrefix` parameter to `signOrderHashAsync` so that the
+ caller can decide on whether to add the personalMessage prefix before relaying the request
+ to the signer. Parity Signer, Ledger and TestRPC add the prefix themselves, Metamask expects
+ it to have already been added.
+
+## v0.30.2 - _January 29, 2018_
+
+ * Add Rinkeby testnet addresses to artifacts (#337)
+ * Move @0xproject/types to dependencies from devDependencies fixing missing type errors
+
+## v0.30.1 - _January 24, 2018_
* Fix a bug allowing negative fill values (#212)
* Fix a bug that made it impossible to pass a custom ZRX address (#341)
- * Add Rinkeby testnet addresses to artifacts (#337)
## v0.30.0 - _January 17, 2018_
diff --git a/packages/0x.js/src/0x.ts b/packages/0x.js/src/0x.ts
index 503a937c4..f8a484c5d 100644
--- a/packages/0x.js/src/0x.ts
+++ b/packages/0x.js/src/0x.ts
@@ -240,20 +240,22 @@ export class ZeroEx {
* @param orderHash Hex encoded orderHash to sign.
* @param signerAddress The hex encoded Ethereum address you wish to sign it with. This address
* must be available via the Web3.Provider supplied to 0x.js.
+ * @param shouldAddPersonalMessagePrefix Some signers add the personal message prefix `\x19Ethereum Signed Message`
+ * themselves (e.g Parity Signer, Ledger, TestRPC) and others expect it to already be done by the client
+ * (e.g Metamask). Depending on which signer this request is going to, decide on whether to add the prefix
+ * before sending the request.
* @return An object containing the Elliptic curve signature parameters generated by signing the orderHash.
*/
- public async signOrderHashAsync(orderHash: string, signerAddress: string): Promise<ECSignature> {
+ public async signOrderHashAsync(
+ orderHash: string,
+ signerAddress: string,
+ shouldAddPersonalMessagePrefix: boolean,
+ ): Promise<ECSignature> {
assert.isHexString('orderHash', orderHash);
await assert.isSenderAddressAsync('signerAddress', signerAddress, this._web3Wrapper);
- let msgHashHex;
- const nodeVersion = await this._web3Wrapper.getNodeVersionAsync();
- const isParityNode = utils.isParityNode(nodeVersion);
- const isTestRpc = utils.isTestRpc(nodeVersion);
- if (isParityNode || isTestRpc) {
- // Parity and TestRpc nodes add the personalMessage prefix itself
- msgHashHex = orderHash;
- } else {
+ let msgHashHex = orderHash;
+ if (shouldAddPersonalMessagePrefix) {
const orderHashBuff = ethUtil.toBuffer(orderHash);
const msgHashBuff = ethUtil.hashPersonalMessage(orderHashBuff);
msgHashHex = ethUtil.bufferToHex(msgHashBuff);
diff --git a/packages/0x.js/src/utils/utils.ts b/packages/0x.js/src/utils/utils.ts
index e42a1a853..42cf5d956 100644
--- a/packages/0x.js/src/utils/utils.ts
+++ b/packages/0x.js/src/utils/utils.ts
@@ -20,12 +20,6 @@ export const utils = {
// tslint:disable-next-line: no-console
console.log(message);
},
- isParityNode(nodeVersion: string): boolean {
- return _.includes(nodeVersion, 'Parity');
- },
- isTestRpc(nodeVersion: string): boolean {
- return _.includes(nodeVersion, 'TestRPC');
- },
spawnSwitchErr(name: string, value: any): Error {
return new Error(`Unexpected switch value: ${value} encountered for ${name}`);
},
diff --git a/packages/0x.js/test/0x.js_test.ts b/packages/0x.js/test/0x.js_test.ts
index 5bc2c149c..927fe20be 100644
--- a/packages/0x.js/test/0x.js_test.ts
+++ b/packages/0x.js/test/0x.js_test.ts
@@ -16,6 +16,8 @@ const blockchainLifecycle = new BlockchainLifecycle(constants.RPC_URL);
chaiSetup.configure();
const expect = chai.expect;
+const SHOULD_ADD_PERSONAL_MESSAGE_PREFIX = false;
+
describe('ZeroEx library', () => {
const web3 = web3Factory.create();
const config = {
@@ -198,7 +200,11 @@ describe('ZeroEx library', () => {
r: '0x61a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351bc33',
s: '0x40349190569279751135161d22529dc25add4f6069af05be04cacbda2ace2254',
};
- const ecSignature = await zeroEx.signOrderHashAsync(orderHash, makerAddress);
+ const ecSignature = await zeroEx.signOrderHashAsync(
+ orderHash,
+ makerAddress,
+ SHOULD_ADD_PERSONAL_MESSAGE_PREFIX,
+ );
expect(ecSignature).to.deep.equal(expectedECSignature);
});
it('should return the correct ECSignature for signatureHex concatenated as R + S + V', async () => {
@@ -215,7 +221,11 @@ describe('ZeroEx library', () => {
Sinon.stub(ZeroEx, 'isValidSignature').returns(true),
];
- const ecSignature = await zeroEx.signOrderHashAsync(orderHash, makerAddress);
+ const ecSignature = await zeroEx.signOrderHashAsync(
+ orderHash,
+ makerAddress,
+ SHOULD_ADD_PERSONAL_MESSAGE_PREFIX,
+ );
expect(ecSignature).to.deep.equal(expectedECSignature);
});
it('should return the correct ECSignature for signatureHex concatenated as V + R + S', async () => {
@@ -232,7 +242,11 @@ describe('ZeroEx library', () => {
Sinon.stub(ZeroEx, 'isValidSignature').returns(true),
];
- const ecSignature = await zeroEx.signOrderHashAsync(orderHash, makerAddress);
+ const ecSignature = await zeroEx.signOrderHashAsync(
+ orderHash,
+ makerAddress,
+ SHOULD_ADD_PERSONAL_MESSAGE_PREFIX,
+ );
expect(ecSignature).to.deep.equal(expectedECSignature);
});
});
diff --git a/packages/0x.js/test/utils/order_factory.ts b/packages/0x.js/test/utils/order_factory.ts
index 60a7c5fb2..08f2081a4 100644
--- a/packages/0x.js/test/utils/order_factory.ts
+++ b/packages/0x.js/test/utils/order_factory.ts
@@ -3,6 +3,8 @@ import * as _ from 'lodash';
import { SignedOrder, ZeroEx } from '../../src';
+const SHOULD_ADD_PERSONAL_MESSAGE_PREFIX = false;
+
export const orderFactory = {
async createSignedOrderAsync(
zeroEx: ZeroEx,
@@ -37,7 +39,7 @@ export const orderFactory = {
expirationUnixTimestampSec,
};
const orderHash = ZeroEx.getOrderHashHex(order);
- const ecSignature = await zeroEx.signOrderHashAsync(orderHash, maker);
+ const ecSignature = await zeroEx.signOrderHashAsync(orderHash, maker, SHOULD_ADD_PERSONAL_MESSAGE_PREFIX);
const signedOrder: SignedOrder = _.assign(order, { ecSignature });
return signedOrder;
},