From 5ff999c23a8e4c92eda25e43056c13ba0cca1410 Mon Sep 17 00:00:00 2001 From: cb-jake <95890768+cb-jake@users.noreply.github.com> Date: Tue, 24 Sep 2024 12:29:20 -0600 Subject: [PATCH] fix noble hash keccak256 usage (#1406) * fix noble hash keccak256 usage * fix test and implementation --- .../wallet-sdk/src/sign/walletlink/WalletLinkSigner.test.ts | 2 +- packages/wallet-sdk/src/vendor-js/eth-eip712-util/index.js | 3 +++ packages/wallet-sdk/src/vendor-js/eth-eip712-util/util.js | 6 ++++-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/wallet-sdk/src/sign/walletlink/WalletLinkSigner.test.ts b/packages/wallet-sdk/src/sign/walletlink/WalletLinkSigner.test.ts index 1df3ef3aaa..3bd9452cba 100644 --- a/packages/wallet-sdk/src/sign/walletlink/WalletLinkSigner.test.ts +++ b/packages/wallet-sdk/src/sign/walletlink/WalletLinkSigner.test.ts @@ -208,7 +208,7 @@ describe('LegacyProvider', () => { const sendRequestSpy = jest.spyOn(relay, 'sendRequest'); const provider = createAdapter({ relay }); - const ENCODED_MESSAGE = '0xb7845733ba102a68c6eb21c3cd2feafafd1130de581d7e73be60b76d775b6704'; + const ENCODED_MESSAGE = '0x421b6e328c574f0ee83a68d51d01be3597d8b5391c7725dfa80247a60b5cd390'; const ENCODED_TYPED_DATA_JSON = JSON.stringify(MOCK_TYPED_DATA); beforeEach(() => { diff --git a/packages/wallet-sdk/src/vendor-js/eth-eip712-util/index.js b/packages/wallet-sdk/src/vendor-js/eth-eip712-util/index.js index 7b3cc4c3f2..d0a56b44d2 100644 --- a/packages/wallet-sdk/src/vendor-js/eth-eip712-util/index.js +++ b/packages/wallet-sdk/src/vendor-js/eth-eip712-util/index.js @@ -1,3 +1,6 @@ +/* eslint-disable */ +//prettier-ignore + const util = require('./util') const abi = require('./abi') diff --git a/packages/wallet-sdk/src/vendor-js/eth-eip712-util/util.js b/packages/wallet-sdk/src/vendor-js/eth-eip712-util/util.js index 7d24b0f80a..47755cb8d1 100644 --- a/packages/wallet-sdk/src/vendor-js/eth-eip712-util/util.js +++ b/packages/wallet-sdk/src/vendor-js/eth-eip712-util/util.js @@ -138,8 +138,10 @@ function bufferToHex (buf) { function keccak (a, bits) { a = toBuffer(a) if (!bits) bits = 256 - - return Buffer.from(keccak_256('keccak' + bits)) + if (bits !== 256) { + throw new Error('unsupported') + } + return Buffer.from(keccak_256(new Uint8Array(a))) } function padToEven (str) {