core
core copied to clipboard
feat(controller-utils): support bn.js v4 input to BN functions
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.
-
fractionBNnow uses the original BN implementation when passed a v4 BN instance
- Affected functions:
- 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.jsis imported downstream. Making this support explicit facilitates resolving the type issue without requiring a prior full migration off bn.js v4.
- Note that these functions are already used with v4 input but this was not caught due to the way
- #4827
- https://github.com/ethereumjs/ethereumjs-util/issues/250
Changelog
@metamask/controller-utils
-
CHANGED: The following functions now accept input from
bn.jsv4 library:-
BNToHex -
fractionBN -
fromHex -
toHex
-
-
FIXED:
fractionToBNnow returns output using the samebn.jslibrary 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
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 |