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

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

Merged
merged 2 commits into from
Oct 25, 2024

Conversation

legobeat
Copy link
Contributor

@legobeat legobeat commented Oct 24, 2024

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

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

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've highlighted breaking changes using the "BREAKING" category above as appropriate
  • I've prepared draft pull requests for clients and consumer packages to resolve any breaking changes

Copy link

socket-security bot commented Oct 24, 2024

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

Package New capabilities Transitives Size Publisher
npm/@types/bn.js@4.11.6 None 0 13.9 kB types

View full report↗︎

@legobeat legobeat force-pushed the utils-bn4-input-support branch 4 times, most recently from 31a26c3 to 5603e03 Compare October 24, 2024 02:45
@legobeat legobeat marked this pull request as ready for review October 24, 2024 02:45
@legobeat legobeat requested review from a team as code owners October 24, 2024 02:45
@legobeat legobeat force-pushed the utils-bn4-input-support branch 3 times, most recently from adaf327 to 5e5dfd5 Compare October 24, 2024 17:23
Affected functions:
- BNToHex
- fractionBN
- fromHex
- toHex

If input is v4 instance, return as v4. Otherwise use v5, as previously.
@legobeat legobeat merged commit a8ca323 into MetaMask:main Oct 25, 2024
119 checks passed
@legobeat legobeat deleted the utils-bn4-input-support branch October 25, 2024 22:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants