This repository has been archived by the owner on Jul 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 52
feat: use web crypto for Ed25519 keys in node.js if available #211
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Node.js 15 added support for Ed25519 keys in web crypto so let's use that instead of pure js implementations which are slow. I've also added a benchmark suite so we can compare implementations: ```console $ node ed25519.js native ed25519 x 4,584 ops/sec ±2.09% (79 runs sampled) noble ed25519 x 193 ops/sec ±33.95% (79 runs sampled) node-forge ed25519 x 60.75 ops/sec ±3.36% (68 runs sampled) node.js ed25519 x 3,320 ops/sec ±2.33% (78 runs sampled) ``` Note the [ed25519 module](https://www.npmjs.com/package/ed25519) actually comes out on top but it's API is synchronous - this is probably why it's faster but will likely impede performance elsewhere. BREAKING CHANGE: requires node 15+
Added a few more competing implementations to the benchmarks. The wasm version is quite the eye-opener: $ node ed25519.js
@noble/ed25519 x 125 ops/sec ±32.00% (55 runs sampled)
@stablelib/ed25519 x 48.78 ops/sec ±8.33% (63 runs sampled)
node-forge/ed25519 x 54.44 ops/sec ±5.54% (69 runs sampled)
supercop.wasm x 3,651 ops/sec ±1.33% (83 runs sampled)
ed25519 (native module) x 4,813 ops/sec ±0.86% (86 runs sampled)
node.js web-crypto x 3,466 ops/sec ±2.04% (80 runs sampled) |
3 tasks
achingbrain
added a commit
that referenced
this pull request
Nov 29, 2021
Pulls the benchmark suite out of #211 so it can be merged independently.
achingbrain
added a commit
that referenced
this pull request
Nov 29, 2021
Pulls the benchmark suite out of #211 so it can be merged independently.
achingbrain
added a commit
that referenced
this pull request
Nov 29, 2021
Pulls the benchmark suite out of #211 so it can be merged independently.
Superseded by #215 |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Node.js 15 added support for Ed25519 keys in web crypto so let's use that instead of pure js implementations which are slow.
I've also added a benchmark suite so we can compare implementations:
Note the ed25519 module actually comes out on top but it's API is synchronous - this is probably why it's faster but will likely impede performance elsewhere.
Falls back to the pure-js implementation when Ed25519 is not available (e.g. node < 15, electron, etc).