Refactor parser utility to use keccak hash from ethers.js #103
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
When signing a message in the browser for certain frontend frameworks, a reference error
keccak.js:41 Uncaught ReferenceError: Buffer is not defined in the browser console
is thrown. This happens because thekeccak
package uses a global Node API (Buffer
) that isn't available in the browser.Frameworks
Next.js
This isn't a problem in Next.js because Next.js shims with a browser implementation of
Buffer
. SIWE can be implemented with no problems.Remix
Remix prefers not to shim Node globals into the browser. As a result, using
keccak
produces anReferenceError
forBuffer
and requires developers to hack around in order to get SIWE to work.Solution
This pull request refactors the
isEIP55Address
utility to compute the keccak256 hash using the@ethersproject/hash
package which doesn't depend on Node globals. It also removes thekeccak
peer dependency because it is no longer used. There should be no changes to the current behavior.The
isEIP55Address
utility now works in both browser and Node environments ✅ .