Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: throw correct error on empty or invalid address #238

Merged
merged 5 commits into from
Jul 12, 2023

Conversation

mikesposito
Copy link
Member

@mikesposito mikesposito commented Jul 5, 2023

Description

Since @metamask/utils has been updated to the latest version, normalize method does not return undefined for empty strings anymore.

getKeyringForAccount checks if the provided address is an empty string (or undefined) and returns an error in case. But as all the other methods of the controller normalize the address before calling getKeyringForAccount what we check in there is 0x, which is not seen as invalid/empty by the function.

To fix the problem and provide a correct error message, this PR uses isValidHexAddress from @metamask/utils to check if the string passed to getKeyringForAccount is a valid address.

Changes

  • FIXED: getKeyringForAccount provides a correct error message when an address is invalid

References

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation for new or updated code as appropriate (note: this will usually be JSDoc)
  • I've highlighted breaking changes using the "BREAKING" category above as appropriate

@mikesposito mikesposito changed the title fix: return error on empty or invalid address fix: throw correct error on empty or invalid address Jul 5, 2023
@socket-security
Copy link

socket-security bot commented Jul 5, 2023

No top level dependency changes detected. Learn more about Socket for GitHub ↗︎

@socket-security
Copy link

socket-security bot commented Jul 5, 2023

👍 Dependency issues cleared. Learn more about Socket for GitHub ↗︎

This PR previously contained dependency changes with security issues that have been resolved, removed, or ignored.

@mikesposito
Copy link
Member Author

Could be worth waiting for MetaMask/utils#112 to be merged and released as @metamask/controller-utils will not be needed anymore

@mikesposito mikesposito marked this pull request as ready for review July 11, 2023 19:26
@mikesposito mikesposito requested a review from a team as a code owner July 11, 2023 19:26
@legobeat
Copy link
Contributor

legobeat commented Jul 12, 2023

Added minor bump of @ethereumjs/tx to keep transitive dependency versions consolidated.

legobeat

This comment was marked as resolved.

@mikesposito
Copy link
Member Author

LGTM but can we add a test-case for at least one empty/falsey case (ie covering for when the previous !address on line 719 would hold)?

Shouldn't it be still covered by the test case throws error when address is not provided (L715)?

@mikesposito mikesposito force-pushed the fix/return-error-on-empty-address branch from 6fbeccc to de2bdd1 Compare July 12, 2023 11:30
@legobeat
Copy link
Contributor

LGTM but can we add a test-case for at least one empty/falsey case (ie covering for when the previous !address on line 719 would hold)?

Shouldn't it be still covered by the test case throws error when address is not provided (L715)?

My bad, overlooked it. LGTM then!

@mikesposito mikesposito merged commit a813e00 into main Jul 12, 2023
16 checks passed
@mikesposito mikesposito deleted the fix/return-error-on-empty-address branch July 12, 2023 11:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants