core icon indicating copy to clipboard operation
core copied to clipboard

feat(controller-utils): support bn.js v4 input to BN functions

Open legobeat opened this issue 1 year ago • 1 comments

Explanation

  • Extend types to indicate support for passing in bn.js v4 instances to BN.js utility functions
    • Affected functions:
      • BNToHex
      • fractionBN
      • fromHex
      • toHex
    • If input is v4 instance, return as v4. Otherwise use v5, as previously.
    • fractionBN now uses the original BN implementation when passed a v4 BN instance
  • Use overload signatures to more specifically type BN-related util functions

References

  • Context: https://github.com/MetaMask/metamask-mobile/pull/11972
    • Note that these functions are already used with v4 input but this was not caught due to the way bn.js is imported downstream. Making this support explicit facilitates resolving the type issue without requiring a prior full migration off bn.js v4.
  • #4827
  • https://github.com/ethereumjs/ethereumjs-util/issues/250

Changelog

@metamask/controller-utils

  • CHANGED: The following functions now accept input from bn.js v4 library:
    • BNToHex
    • fractionBN
    • fromHex
    • toHex
  • FIXED: fractionToBN now returns output using the same bn.js library version that created the input

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
  • [x] I've prepared draft pull requests for clients and consumer packages to resolve any breaking changes

legobeat avatar Oct 24 '24 02:10 legobeat

New dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/@types/[email protected] None 0 13.9 kB types

View full report↗︎

socket-security[bot] avatar Oct 24 '24 02:10 socket-security[bot]