core icon indicating copy to clipboard operation
core copied to clipboard

fix(accounts): fix normal account indexing naming with index gap

Open ccharly opened this issue 11 months ago • 0 comments

Explanation

While reading the implementation of the AccountsController, I spotted a unsafe access in the function generating the next account ID.

It seems this code path was never really used, but there still one problem left, the account id generation was wrong when there's a "gap" in between accounts:

accounts = ["Account 1", "Account 2"]
`-> next account ID would be: "Account 3"

accounts = ["Account 1", "Account 3"]
`-> next account ID **SHOULD BE**: "Account 4", but current
    implementation will generate "Account 3" (since we fallback to: accounts.length + 1 -> "Account 3")

References

N/A

Changelog

@metamask/accounts-controller

  • FIXED: Fixed normal accounts ID generation when there was a "index gap" between accounts.

Checklist

  • [x] I've updated the test suite for new or updated code as appropriate
  • [x] I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • [x] I've highlighted breaking changes using the "BREAKING" category above as appropriate

ccharly avatar Mar 20 '24 09:03 ccharly