From 194ecbef4debf233d162b6fe1def6edb03bcb18a Mon Sep 17 00:00:00 2001 From: David Murdoch <187813+davidmurdoch@users.noreply.github.com> Date: Wed, 17 Nov 2021 13:48:54 -0500 Subject: [PATCH] fix: make web3_sha encode data correctly (#1593) fixes #1375 --- src/chains/ethereum/ethereum/src/api.ts | 2 +- src/chains/ethereum/ethereum/tests/api/web3/web3.test.ts | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/chains/ethereum/ethereum/src/api.ts b/src/chains/ethereum/ethereum/src/api.ts index 0ffb4c3b35..83a8ca9c0e 100644 --- a/src/chains/ethereum/ethereum/src/api.ts +++ b/src/chains/ethereum/ethereum/src/api.ts @@ -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 diff --git a/src/chains/ethereum/ethereum/tests/api/web3/web3.test.ts b/src/chains/ethereum/ethereum/tests/api/web3/web3.test.ts index 8ac8da5260..54b28f8da5 100644 --- a/src/chains/ethereum/ethereum/tests/api/web3/web3.test.ts +++ b/src/chains/ethereum/ethereum/tests/api/web3/web3.test.ts @@ -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" ); }); });