-
Notifications
You must be signed in to change notification settings - Fork 25
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
Replace noble-ed25519 with tweetnacl #277
Conversation
What exactly are these issues? |
I was just wondering about performance differences. This is from the noble-ed25519 readme: # noble-ed25519
[...]
sign x 3,247 ops/sec @ 307μs/op
[...]
# tweetnacl-fast@1.0.3
[...]
sign x 519 ops/sec @ 2ms/op No comparison for
In tweetnacl's readme, but the numbers on noble's readme are from an Apple M1:
|
Thinking about it some more, these problems might be the result of how I am testing this locally. Let me explain a bit about how I am testing this with SvelteKit. SvelteKit has this notion of adapters that are meant to target different environments like import adapter from '@sveltejs/adapter-static';
/** @type {import('@sveltejs/kit').Config} */
const config = {
kit: {
adapter: adapter({
// default options are shown
pages: 'build',
assets: 'build',
fallback: null
}),
ssr: false,
// hydrate the <div id="svelte"> element in src/app.html
target: '#svelte'
}
};
export default config; To get a similar setup npm init svelte@next my-app
cd my-app
npm install
npm i -D @sveltejs/adapter-static@next select the "SvelteKit demo app", "no" to the remaining questions, and the replace Import <script>
import * as wn from 'webnative'
import Header from '$lib/header/Header.svelte';
import '../app.css';
</script> When I install my local build of webnative with
I see |
Yeah, Do you have a sense for how many verify operations we might be doing? Would this lead to a performance issue for us? |
Hmm, looks like this didn't work out in our GH action test
|
Adding a comparison of webntative bundle sizes using
The |
We want to support environments that do not support es2020 build target. noble-ed25519 uses big integer literals which mandates es2020. tweetnacl supports older environments.
6fc05a4
to
c281c04
Compare
Fixed a few things on this PR to get it ready. Merging this PR does not fulfill the original motivation of supporting Create React App because we have other bundler issues that prevent it. But this change is still worthwhile because:
The tradeoffs are basically larger bundle size as noted in a comment above. Note that Our |
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.
Looking good! Quite a simple change for what we get out of it. Ship it :) 🚢
resolved "https://registry.yarnpkg.com/@assemblyscript/loader/-/loader-0.9.4.tgz#a483c54c1253656bb33babd464e3154a173e1577" | ||
resolved "https://registry.npmjs.org/@assemblyscript/loader/-/loader-0.9.4.tgz" |
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 wonder whats up with these changes. Most likely nothing to worry about, though! (And definitely doesn't prevent merging :)
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.
Yeah, that's odd. I sometimes use npm
instead of yarn
out of habit, but doesn't seem like that would update yarn.lock
. 🤔
"target": "ES2020", | ||
"target": "ES2018", |
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.
🎉
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 agree with @matheus23 nice wins for a relatively minor change 👍
Summary
This PR fixes/implements the following bugs/features
noble-ed25519
withtweetnacl
tsconfig
target toES2018
Explain the motivation for making this change. What existing problem does the pull request solve?
The
noble-ed25519
library uses big integer literals which only work ines2020
or newer environments. This PR replacesnoble-ed25519
withtweetnacl
to support older environments. See #276 for more details.We use the verify method from
noble-ed25519
. This PR replaces it with sign.detached.verify fromtweetnacl
.The function signatures are nearly the same.
noble-ed25519
permits more types andtweetnacl
requiresUint8Array
s. This is enforced here:https://github.com/dchest/tweetnacl-js/blob/3389b7c9f00545e516a0fdafb324b7857cf1527d/nacl.js#L949-L954
In any case, our wrapper function enforces
Uint8Array
s so we should be fine for types.noble-ed25519
returnsPromise<bool>
andtweetnacl
returnsbool
. Thetweetnacl
result is wrapped in a promise here to keep the original behavior.Test plan (required)
The two environments that lack
es2020
support that we are aware of are Create React App and SvelteKit. See sveltejs/kit#2220 for a discussion regarding SvelteKit.There are bundler issues with SvelteKit that make this difficult to test. Create React App can be tested as follows:
create-react-app my-app cd my-app npm install webnative
Import
webnative
insrc/App.js
Build and run the app locally (with
http-server
or something else)This should fail with a
Uncaught TypeError: can't convert BigInt to number
runtime error.Now replace webnative with the version from this PR, build again, and run it. The app should run without an error.
Edit: These changes pass in our test suites, and beyond that we can rely on these libraries to work equivalently. See #277 (comment) for a summary of where this PR stands.
Closing issues
Closes #276
After Merge