-
Notifications
You must be signed in to change notification settings - Fork 71
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: Replace @stablelib/ with noble-crypto #280
Conversation
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.
That sounds like pretty significant performance gains!
Is impact on package size also positive?
The best way to gauge size is a bundle prepared by webpack. It contains all the dependencies included as far as I can see. According to the bundle size, current upstream is 236K, changes in the PR reduce it to 133K. Looks like ~40% reduction. |
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.
I can give a solid +1 for these noble libraries. They're well tested and audited crypto libraries that weren't around when a lot of this was originally implemented. Noting I've not reviewed the code throughly just providing approval on behalf of the dependency changes. It's worth noting that this change bumps a lot of unrelated packages as well because of the usage of ^
. To minimize the number of updates to the yarn.lock file it's probably worth version locking those to see only the affected changes from replacing the dependencies.
multiformat libraries are using unaudited garbage dependencies
true, so what's needed is switching multiformats to noble - unfortunately they don't seem to care much, i've tried an issue one time and they mentioned it ain't really needed: multiformats/js-sha3#48 but open to pull requests
padding is easily adjustable in code. we have an open issue for the native features paulmillr/scure-base#4 |
Okay, I am going to try minimising changes to yarn.lock. |
@paulmillr I am aware I can create proper Anyway, encoding/decoding I believe is a slightly separate topic. Let's do with crypto libs first. |
if it ain't breaking backwards compat, sure thing. breaking will need a new breaking release, not optimal rn |
Very nice work! I haven't done a proper review, but one thing I did notice is that the e256kSigner test is producing different signatures for the same inputs/keys. What is the reason for those? |
@nklomp Copied from the PR description :)
If you look closer to the changed signatures in the tests, you'll see that they begin the same. The second part encoding "s" is different. |
Hehehe, thanks. Guess I was too excited about these changes, to read that ;) |
There is a However, the old behavior (your current) is not safe and introduces signature malleability. |
@kdenhartog Now yarn.lock should be fine. One could easily see scope of the changes there. |
@mirceanis Hey, is there anything I can do to move the PR forward? The gains are pretty significant:
|
I'm reviewing it now. This looks great so far 🚀 |
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 wonderful, thank you!
I'll mark this as a BREAKING CHANGE since the weierstrass signer outputs are changing and it's likely going to cause test failures for dependents.
# [7.0.0](6.11.6...7.0.0) (2023-04-19) ### Features * **deps:** replace @stablelib/ with noble-crypto ([#280](#280)) ([0f6221a](0f6221a)), closes [#270](#270) ### BREAKING CHANGES * **deps:** `ES256*` signers are now enforcing canonical signatures (s-value less than or equal to half the curve order). This will likely break some expectations for dependents that were using the previous versions.
🎉 This PR is included in version 7.0.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Yahoo!! |
This PR replaces @StableLib dependencies with noble-crypto wherever it makes sense, i.e. only
@stablelib/xchacha20poly1305
is still used.Code difference:
@stablelib/sha256
->@noble/hashes
js-sha3
->@noble/hashes
@stablelib/random
->@noble/hashes
as@noble/hashes/utils
elliptic
,@stablelib/ed25519
,@stablelib/x25519
->@noble/curves
@noble/hashes
jwe-vectors.js
turned into TSjwe-vectors.ts
Important note regarding different signatures previously created by
elliptic
package you could see in the test cases. Apparently,elliptic
created signature with high value "s".@noble/curves
signature gets lower "s" value, being the same fully valid signature.Another issue: for
EdDSASigner
a private key is expected to contain 64 bytes. Really, private key is only 32 bytes. The second 32 bytes are a public key. Maybe at some point, a constraint should be relieved.One benefit apart relying on a solid cryptography libraries, is speed. Tests in the upstream take 22s on my machine. After changes in PR, the same test suite takes 4s.
Re:
@scure/base
for text encoding/decoding: I am conflicted.uint8arrays
andmultiformats
are quite often used alongsidedid-jwt
, so adding@scure/base
would add to the end application size, rather than reduce it. And, @paulmillr names you use likebase64url
andbase64
are quite misleading if compared tomultiformats
analogs because of padding.