[web3.js] Replace tweetnacl impl #27435
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
This PR aims to replace the ed25519 keygen, signing, and verifying algorithms with smaller ones having fewer dependencies.
Summary of Changes
tweetnacl
with@noble/ed25519
Bundle size
Used
package-build-stats
to analyze the size change locally.tl;dr a ~4% reduction in bundle size after gzip.
Dependency tree
Replaced
tweetnacl
for@noble/ed25519
, dropping about 4K gzipped.Produced using https://npmgraph.js.org/
Performance
Consider this keypair generation code:
Take 10 trials:
Results
No change.
Consider this transaction signing code:
Take 10 trials:
Results:
~6% slower.
Compatibility notes
Together, this, #27390, and #27127 make
@solana/web3.js
incompatible with React Native because of their use of:BigInt
BigInt
bigint
literalsBecause this team is small, we're likely to recommend that folks upgrade their React Native apps to 0.70 and convert them to run using the Hermes JavaScript engine, which in that version supports all of the above. Support for big integers is critical to most crypto apps, and React Native has now made Hermes the default engine. We would be best advised to skate where the puck is going.
Addresses solana-labs/solana-web3.js#1103
Fixes #26933.