Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Fix eth_sign #1716

Merged
merged 2 commits into from
Dec 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/chains/ethereum/ethereum/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
16 changes: 2 additions & 14 deletions src/chains/ethereum/ethereum/tests/api/eth/sign.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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());
Expand Down