From 50fc87e8ec705613326449cb8f9f2b80155aa2da Mon Sep 17 00:00:00 2001 From: Neurone Date: Wed, 4 Jul 2018 20:51:32 +0200 Subject: [PATCH 1/3] Fixed signature to comply to Geth and Parity (see #131) --- index.js | 3 +-- test/index.js | 6 +++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index c98d54f3..daacf14b 100644 --- a/index.js +++ b/index.js @@ -416,11 +416,10 @@ exports.toRpcSig = function (v, r, s) { } // geth (and the RPC eth_sign method) uses the 65 byte format used by Bitcoin - // FIXME: this might change in the future - https://github.com/ethereum/go-ethereum/issues/2053 return exports.bufferToHex(Buffer.concat([ exports.setLengthLeft(r, 32), exports.setLengthLeft(s, 32), - exports.toBuffer(v - 27) + exports.toBuffer(v) ])) } diff --git a/test/index.js b/test/index.js index e24048eb..88df4c32 100644 --- a/test/index.js +++ b/test/index.js @@ -604,8 +604,8 @@ describe('message sig', function () { const s = Buffer.from('129ff05af364204442bdb53ab6f18a99ab48acc9326fa689f228040429e3ca66', 'hex') it('should return hex strings that the RPC can use', function () { - assert.equal(ethUtils.toRpcSig(27, r, s), '0x99e71a99cb2270b8cac5254f9e99b6210c6c10224a1579cf389ef88b20a1abe9129ff05af364204442bdb53ab6f18a99ab48acc9326fa689f228040429e3ca6600') - assert.deepEqual(ethUtils.fromRpcSig('0x99e71a99cb2270b8cac5254f9e99b6210c6c10224a1579cf389ef88b20a1abe9129ff05af364204442bdb53ab6f18a99ab48acc9326fa689f228040429e3ca6600'), { + assert.equal(ethUtils.toRpcSig(27, r, s), '0x99e71a99cb2270b8cac5254f9e99b6210c6c10224a1579cf389ef88b20a1abe9129ff05af364204442bdb53ab6f18a99ab48acc9326fa689f228040429e3ca661b') + assert.deepEqual(ethUtils.fromRpcSig('0x99e71a99cb2270b8cac5254f9e99b6210c6c10224a1579cf389ef88b20a1abe9129ff05af364204442bdb53ab6f18a99ab48acc9326fa689f228040429e3ca661b'), { v: 27, r: r, s: s @@ -622,7 +622,7 @@ describe('message sig', function () { }) it('pad short r and s values', function () { - assert.equal(ethUtils.toRpcSig(27, r.slice(20), s.slice(20)), '0x00000000000000000000000000000000000000004a1579cf389ef88b20a1abe90000000000000000000000000000000000000000326fa689f228040429e3ca6600') + assert.equal(ethUtils.toRpcSig(27, r.slice(20), s.slice(20)), '0x00000000000000000000000000000000000000004a1579cf389ef88b20a1abe90000000000000000000000000000000000000000326fa689f228040429e3ca661b') }) it('should throw on invalid v value', function () { From 1ca1c950b8e5c5bf04fe70477e51cb5f8eec3bcc Mon Sep 17 00:00:00 2001 From: Neurone Date: Thu, 5 Jul 2018 13:32:11 +0200 Subject: [PATCH 2/3] Test to verify `fromRpcSig` compatibility with old signatures (ending with 01 or 00); --- test/index.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/index.js b/test/index.js index 88df4c32..6bd8ea62 100644 --- a/test/index.js +++ b/test/index.js @@ -610,6 +610,11 @@ describe('message sig', function () { r: r, s: s }) + assert.deepEqual(ethUtils.fromRpcSig('0x99e71a99cb2270b8cac5254f9e99b6210c6c10224a1579cf389ef88b20a1abe9129ff05af364204442bdb53ab6f18a99ab48acc9326fa689f228040429e3ca6600'), { + v: 27, + r: r, + s: s + }) }) it('should throw on invalid length', function () { From 64b662ed960fe637e8dd6a907f3828a58f5436a1 Mon Sep 17 00:00:00 2001 From: Neurone Date: Thu, 5 Jul 2018 16:13:14 +0200 Subject: [PATCH 3/3] Fixed linter errors; --- test/index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/index.js b/test/index.js index 6bd8ea62..e0866dbc 100644 --- a/test/index.js +++ b/test/index.js @@ -611,10 +611,10 @@ describe('message sig', function () { s: s }) assert.deepEqual(ethUtils.fromRpcSig('0x99e71a99cb2270b8cac5254f9e99b6210c6c10224a1579cf389ef88b20a1abe9129ff05af364204442bdb53ab6f18a99ab48acc9326fa689f228040429e3ca6600'), { - v: 27, - r: r, - s: s - }) + v: 27, + r: r, + s: s + }) }) it('should throw on invalid length', function () {