-
Notifications
You must be signed in to change notification settings - Fork 314
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
Offload bn.js
#1150
Offload bn.js
#1150
Conversation
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/blockstack/stacks-js/8ymHvhN88uJ8HHh5WMX4rteUD65G |
Codecov Report
@@ Coverage Diff @@
## master #1150 +/- ##
==========================================
+ Coverage 62.03% 62.13% +0.10%
==========================================
Files 122 122
Lines 8315 8377 +62
Branches 1534 1553 +19
==========================================
+ Hits 5158 5205 +47
- Misses 3052 3065 +13
- Partials 105 107 +2
Continue to review full report at Codecov.
|
@ahsan-javaid amazing to see some work to improve the bundle size, much needed 🙏 |
5b9cc14
to
c3ccc1e
Compare
@zone117x Share your thoughts on this pr as well. Thanks 🙏 |
packages/common/src/utils.ts
Outdated
return hexOctets.join(''); | ||
} | ||
|
||
export class BN { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is a goal of this PR to avoid breaking changes? If so, this new class is a breaking change. It prevents other libraries from passing a bn.js
lib instance of BN
because the class types are different, and the functionality is different.
If we don't care about breaking changes, then I'm not sure why we'd try to replicate the bn.js structure when everything can use a bigint
instance, and call any of these helper functions when needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
c3ccc1e
to
d02c945
Compare
Codecov Report
@@ Coverage Diff @@
## master #1150 +/- ##
==========================================
+ Coverage 64.39% 64.54% +0.15%
==========================================
Files 124 124
Lines 8603 8629 +26
Branches 1834 1849 +15
==========================================
+ Hits 5540 5570 +30
- Misses 2818 2822 +4
+ Partials 245 237 -8
Continue to review full report at Codecov.
|
d02c945
to
c4ee99b
Compare
@zone117x Requesting the review on this pr 🙏. |
c4ee99b
to
12b7fbd
Compare
@zone117x Any further thoughts on this pr 🙏 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good so far — but I'll need some more time to examine in detail 😊
12b7fbd
to
b84a9ba
Compare
b84a9ba
to
b003dd1
Compare
d36e465
to
99de1b5
Compare
Note that this specific PR is a relatively minor move towards native We should not hold back from merging this PR due to react native support, as that's already been thrown out the window. Facebook's react native js runtimes are embarrassingly outdated, but looks like they are making progress towards Alternatively, @aulneau and I have had discussions around this topic, and found offloading certain operations to native webviews as a potential viable solution, e.g. https://github.com/webview-crypto/react-native-webview-crypto. @aulneau do you have any updates around this issue? |
If packages are moving towards more native bigint usage -- they simply cannot be used in react-native as it stands currently. I've explored ways to create a messaging bridge between the native webview and react native which then makes it possible to use something like micro-stacks or noble-secp256k1 in react native. This however has a large overhead and burden of complexity. If stacks.js is already using the noble packages, this change in this PR will not make it so react native users can't use stacks.js, it would have already been the case because of the heavy usage of bigint in the noble packages.
An alternative would be to use a different big int package that has a smaller footprint than bn.js. I've thought a lot about how this would be possible in the context of micro-stacks. What I've landed on currently is to take an approach where consumers of the lib could pass in their own versions of things like a secp256k1 package or other encoding libs, which have the same signature. That way you can pass a more performant secp256k1 package that is built for react native, rather than using what is best for the web. Additionally, I think using native Hope that helps. I'm planning on having an example implementation for react native and micro-stacks in the coming months. |
Thanks for the insight and research @aulneau! We should consider a similar approach in stacks.js if we prioritize react-native support. Keep in mind one of their maintainers mentioned upcoming support for bigints just a week or so ago. |
99de1b5
to
eaac032
Compare
eaac032
to
39ba154
Compare
39ba154
to
9e7fc54
Compare
9e7fc54
to
93b17d3
Compare
93b17d3
to
aef0235
Compare
aef0235
to
e8ba663
Compare
Description
This PR removes
bn.js
dependency from stacks.js packages.bn.js
minified size is around43kb
. This will help to reduce the bundle size. In the subsequent pr, further dependencies can be removed to reduce the bundle size further.For details refer to issue #1120
Type of Change
Does this introduce a breaking change?
No
Are documentation updates required?
No
Testing information
npm run test
Checklist
npm run test
passes