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

Commit

Permalink
Fix eth_sign (#1716)
Browse files Browse the repository at this point in the history
* remove chainId from eth_sign

* remove chainId retreival
  • Loading branch information
MicaiahReid authored Dec 3, 2021
1 parent fd31f6b commit e806822
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 17 deletions.
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

0 comments on commit e806822

Please # to comment.