-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
[web3.js] Replace sha256 and secp256k1 impls #27390
[web3.js] Replace sha256 and secp256k1 impls #27390
Conversation
Codecov Report
@@ Coverage Diff @@
## master solana-labs/solana#27390 +/- ##
=========================================
- Coverage 76.9% 76.7% -0.2%
=========================================
Files 48 48
Lines 2505 2516 +11
Branches 355 359 +4
=========================================
+ Hits 1927 1931 +4
- Misses 448 456 +8
+ Partials 130 129 -1 |
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! thank you for the copious amounts of data backing up this change
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!
Problem
Notwithstanding the fact that the
web3.js
library arguably should not include theSecp256k1Program
utilities (they should be their own package) the dependency tree that utility pulls in is massive. This PR aims to replace the signing and hashing algorithms therein with smaller ones having fewer dependencies.Summary of Changes
@ethersproject/sha2
with@noble/hashes/sha256
secp256k1
with@noble/secp256k1
Bundle size
Published the development build to npm and compared it to the latest version using bundlephobia.
Bundle size is reduced by ~39% after gzip.
Dependency tree
Using NPMGraph:
Number of modules depended upon was reduced by ~14% and number of maintainers in the transitive dependency chain by ~13%.
Performance
Consider the performance of generating public keys using a seed. Use this script:
Before
After
Public keys get generated in ~63% less time.
Consider the performance of generating secp256k1 program instructions. Use this script:
Before
After
No change in runtime.
Compatibility notes
@noble/secp256k1
is incompatible with React Native because of a dependency onSubtleCrypto
, the particular codepaths that we use in theSecp256k1
program utils don't exercise any of those codepaths.Addresses solana-labs/solana-web3.js#1103.
Unintentionally fixes #26371.