From e8068222602131c9ee87a1a0ac19c87753035443 Mon Sep 17 00:00:00 2001 From: Micaiah Reid Date: Fri, 3 Dec 2021 11:33:09 -0500 Subject: [PATCH] Fix `eth_sign` (#1716) * remove chainId from eth_sign * remove chainId retreival --- src/chains/ethereum/ethereum/src/api.ts | 5 ++--- .../ethereum/ethereum/tests/api/eth/sign.test.ts | 16 ++-------------- 2 files changed, 4 insertions(+), 17 deletions(-) diff --git a/src/chains/ethereum/ethereum/src/api.ts b/src/chains/ethereum/ethereum/src/api.ts index 58ae4cda06..61a1c3ce0a 100644 --- a/src/chains/ethereum/ethereum/src/api.ts +++ b/src/chains/ethereum/ethereum/src/api.ts @@ -1821,10 +1821,9 @@ export default class EthereumApi implements Api { throw new Error("cannot sign data; no private key"); } - const chainId = this.#options.chain.chainId; const messageHash = hashPersonalMessage(Data.from(message).toBuffer()); - const { v, r, s } = ecsign(messageHash, privateKey.toBuffer(), chainId); - return toRpcSig(v, r, s, chainId); + const { v, r, s } = ecsign(messageHash, privateKey.toBuffer()); + return toRpcSig(v, r, s); } /** diff --git a/src/chains/ethereum/ethereum/tests/api/eth/sign.test.ts b/src/chains/ethereum/ethereum/tests/api/eth/sign.test.ts index be8db14351..10240b8739 100644 --- a/src/chains/ethereum/ethereum/tests/api/eth/sign.test.ts +++ b/src/chains/ethereum/ethereum/tests/api/eth/sign.test.ts @@ -45,13 +45,7 @@ describe("api", () => { const r = Buffer.from(sgn.slice(0, 64), "hex"); const s = Buffer.from(sgn.slice(64, 128), "hex"); const v = parseInt(sgn.slice(128), 16); - const pub = ecrecover( - msgHash, - v, - r, - s, - provider.getOptions().chain.chainId - ); + const pub = ecrecover(msgHash, v, r, s); const addr = fromSigned(pubToAddress(pub)); const strAddr = "0x" + addr.toString("hex"); assert.strictEqual(strAddr, accounts[0].toLowerCase()); @@ -71,13 +65,7 @@ describe("api", () => { const r = Buffer.from(sgn.slice(0, 64), "hex"); const s = Buffer.from(sgn.slice(64, 128), "hex"); const v = parseInt(sgn.slice(128), 16); - const pub = ecrecover( - msgHash, - v, - r, - s, - provider.getOptions().chain.chainId - ); + const pub = ecrecover(msgHash, v, r, s); const addr = fromSigned(pubToAddress(pub)); const strAddr = "0x" + addr.toString("hex"); assert.deepStrictEqual(strAddr, accounts[0].toLowerCase());