-
-
Notifications
You must be signed in to change notification settings - Fork 23
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
Simplify crypto usage #178
Conversation
55fd0f5
to
e35f879
Compare
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 don't think we need all of @noble/hashes, rather, I think we can just use webcrypto directly.
eg:
export function randomBytes(length: number): Uint8Array {
const getRandomValues = globalThis.crypto.getRandomValues;
if (getRandomValues) {
return getRandomValues(new Uint8Array(length));
} else {
throw new Error("no supported WebCrypto#getRandomValues found");
}
}
That's the approach I started with in #159 but unfortunately |
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.
Just the question about moving from dep to devDep. Also a small conflict in webpack config. Otherwise LGTM! 🚀
10b6b33
to
889e1ec
Compare
889e1ec
to
e36077f
Compare
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!!! 🎸
Doesn't seem to be the case for the latest 18 (the ones supported via LTS)
|
It is in 18+ for sure... |
I remember some issues when running benchmarks, so would need to investigate that. |
@matthewkeil @wemeetagain It is only available by default starting |
So nodejs The docs mention |
As seen in benchmarks it fails due to undefined A quick test though: ❯ cat crypto.js
console.log(crypto.getRandomValues(new Uint32Array(10)));
❯ nvm use 18
Now using node v18.20.2 (npm v10.5.0)
❯ node crypto.js
console.log(crypto.getRandomValues(new Uint32Array(10)));
^
ReferenceError: crypto is not defined
at Object.<anonymous> (/Users/julien/Documents/Projects/chainsafe/lodestar/crypto.js:1:13)
at Module._compile (node:internal/modules/cjs/loader:1364:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1422:10)
at Module.load (node:internal/modules/cjs/loader:1203:32)
at Module._load (node:internal/modules/cjs/loader:1019:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:128:12)
at node:internal/main/run_main_module:28:49
Node.js v18.20.2
❯ nvm use 20
Now using node v20.10.0 (npm v10.2.3)
❯ node crypto.js
Uint32Array(10) [
571407740, 599494301,
2559257699, 2926223660,
1819057593, 1184599816,
1069392847, 2779221017,
3060504880, 2988982603
] So there's probably something else to it. |
Ok, yeah I see that now. So strange that the repl is different than running a script. |
Rely on noble-hashes to simplify
crypto
usage and make sure no polyfills are required.