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

Commit

Permalink
fix: make web3_sha encode data correctly (#1593)
Browse files Browse the repository at this point in the history
fixes #1375
  • Loading branch information
davidmurdoch authored Nov 17, 2021
1 parent 41c2b97 commit 194ecbe
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/chains/ethereum/ethereum/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ export default class EthereumApi implements Api {
*/
@assertArgLength(1)
async web3_sha3(data: DATA) {
return Data.from(keccak(Buffer.from(data)));
return Data.from(keccak(Data.from(data).toBuffer()));
}
//#endregion

Expand Down
6 changes: 3 additions & 3 deletions src/chains/ethereum/ethereum/tests/api/web3/web3.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ describe("api", () => {
});

it("web3_sha should hash the given input", async () => {
const input = "Tim is a swell guy.";
const result = await provider.send("web3_sha3", [input]);
const input = Buffer.from("hello world", "utf-8").toString("hex");
const result = await provider.send("web3_sha3", [`0x${input}`]);

assert.strictEqual(
result,
"0xee80d4ac03202e2246d51a596c76a18e1a6d899bed9f05246d998fb656d9bd1f"
"0x47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad"
);
});
});
Expand Down

0 comments on commit 194ecbe

Please sign in to comment.