diff options
author | Fabio Berger <me@fabioberger.com> | 2018-01-30 19:38:44 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2018-01-30 19:38:44 +0800 |
commit | 1cadbeed88d2e5f413c8f7e39aaee6efcff89831 (patch) | |
tree | 3cede90b64c1b9f85feda80b7564526615ca7b24 /packages/0x.js/src | |
parent | ad52a82190259580f00b3a06b06ef1e950ccdc68 (diff) | |
download | dexon-sol-tools-1cadbeed88d2e5f413c8f7e39aaee6efcff89831.tar dexon-sol-tools-1cadbeed88d2e5f413c8f7e39aaee6efcff89831.tar.gz dexon-sol-tools-1cadbeed88d2e5f413c8f7e39aaee6efcff89831.tar.bz2 dexon-sol-tools-1cadbeed88d2e5f413c8f7e39aaee6efcff89831.tar.lz dexon-sol-tools-1cadbeed88d2e5f413c8f7e39aaee6efcff89831.tar.xz dexon-sol-tools-1cadbeed88d2e5f413c8f7e39aaee6efcff89831.tar.zst dexon-sol-tools-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/src')
-rw-r--r-- | packages/0x.js/src/0x.ts | 20 | ||||
-rw-r--r-- | packages/0x.js/src/utils/utils.ts | 6 |
2 files changed, 11 insertions, 15 deletions
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}`); }, |