-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
crypto: alias webcrypto.subtle and webcrypto.getRandomValues on crypto #41266
Conversation
The aliases allow code written to assume that `crypto.subtle` and `crypto.getRandomValues()` exist on the `crypto` global to just work. Signed-off-by: James M Snell <jasnell@gmail.com>
Review requested:
|
A code like that will likely expect crypto to be on a globalThis, window, global, or similar in the first place. Nevertheless, I don't mind this change if it means some libraries will work. It's worth pointing out that webcrypto is still experimental and there's no runtime warning about it being so. |
Yep once this lands, I plan to open a PR to expose |
Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com>
This comment has been minimized.
This comment has been minimized.
What is the plan for doing that? I am unsure if this change makes sense without exposing Would the global |
Not exactly incompatible, thanks to import maps: <script type="importmap">
{
"imports": {
"node:crypto": "data:text/javascript,export%20default%20globalThis.crypto"
}
}
</script>
<script type="module">import crypto from 'node:crypto'; console.log(crypto.subtle);</script> |
@aduh95 I don't see how that helps. In browsers, there is already a |
It would be |
Co-authored-by: Michaël Zasso <targos@protonmail.com>
why don't we put |
@jasnell one thing I'm curious about: let webcrypto;
function lazyWebCrypto() {
webcrypto ??= require('internal/crypto/webcrypto');
return webcrypto;
} does
|
My concern is that globalThis.crypto === require('crypto') implies globalThis.crypto !== require('crypto').webcrypto unless require('crypto') === require('crypto').webcrypto which has implications such as globalThis.crypto.constructor.name === 'Object'
globalThis.crypto.webcrypto.constructor.name === 'Crypto' I get that we want to improve compatibility with code that uses web APIs, even if those weren't designed for Node.js, but exposing non-standard features through the standard Conversely, we could expose only Web Crypto as |
We can't really. That would create an inconsistency with the Node.js REPL where
Yes, there's a small risk there but I think it's manageable and I think the benefits here outweigh the risks. You are right, tho, the risks are non-zero. |
@tniessen ... I just want to clarify, is your concern here blocking or can this PR go ahead and land? |
It's not blocking :) I haven't given this enough thought one way or the other to have an opinion here, I'm just wary of convenience changes with potentially significant API implications. |
Commit Queue failed- Loading data for nodejs/node/pull/41266 ✔ Done loading data for nodejs/node/pull/41266 ----------------------------------- PR info ------------------------------------ Title crypto: alias webcrypto.subtle and webcrypto.getRandomValues on crypto (#41266) Author James M Snell (@jasnell) Branch jasnell:webcrypto-aliases -> nodejs:master Labels crypto, semver-minor, author ready, needs-ci, webcrypto, commit-queue-squash Commits 3 - crypto: alias webcrypto.subtle and webcrypto.getRandomValues on crypto - [Squash] nits - [Squash] nit Committers 2 - James M Snell - GitHub PR-URL: https://github.com/nodejs/node/pull/41266 Reviewed-By: Filip Skokan Reviewed-By: Michaël Zasso ------------------------------ Generated metadata ------------------------------ PR-URL: https://github.com/nodejs/node/pull/41266 Reviewed-By: Filip Skokan Reviewed-By: Michaël Zasso -------------------------------------------------------------------------------- ⚠ Commits were pushed since the last review: ⚠ - [Squash] nit ℹ This PR was created on Tue, 21 Dec 2021 18:40:38 GMT ✔ Approvals: 2 ✔ - Filip Skokan (@panva): https://github.com/nodejs/node/pull/41266#pullrequestreview-837777172 ✔ - Michaël Zasso (@targos) (TSC): https://github.com/nodejs/node/pull/41266#pullrequestreview-838130176 ✔ Last GitHub CI successful ℹ Last Full PR CI on 2021-12-23T01:16:25Z: https://ci.nodejs.org/job/node-test-pull-request/41621/ - Querying data for job/node-test-pull-request/41621/ ✔ Last Jenkins CI successful -------------------------------------------------------------------------------- ✔ Aborted `git node land` session in /home/runner/work/node/node/.ncuhttps://github.com/nodejs/node/actions/runs/1627255427 |
Landed in 353532b |
The aliases allow code written to assume that `crypto.subtle` and `crypto.getRandomValues()` exist on the `crypto` global to just work. Signed-off-by: James M Snell <jasnell@gmail.com> PR-URL: #41266 Reviewed-By: Filip Skokan <panva.ip@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Notable changes: crypto: * (SEMVER-MINOR) alias webcrypto.subtle and webcrypto.getRandomValues on crypto (James M Snell) #41266 doc: * add Mesteery to collaborators (Mestery) #41543 events: * (SEMVER-MINOR) graduate capturerejections to supported (James M Snell) #41267 * (SEMVER-MINOR) add EventEmitterAsyncResource to core (James M Snell) #41246 loader: * (SEMVER-MINOR) return package format from defaultResolve if known (Gabriel Bota) #40980 perf_hooks: * (SEMVER-MINOR) multiple fixes for Histogram (James M Snell) #41153 stream: * add filter method to readable (Benjamin Gruenbaum) #41354 * add map method to Readable (Benjamin Gruenbaum) #40815 PR-URL: TODO
Notable changes: crypto: * (SEMVER-MINOR) alias webcrypto.subtle and webcrypto.getRandomValues on crypto (James M Snell) #41266 doc: * add Mesteery to collaborators (Mestery) #41543 events: * (SEMVER-MINOR) graduate capturerejections to supported (James M Snell) #41267 * (SEMVER-MINOR) add EventEmitterAsyncResource to core (James M Snell) #41246 loader: * (SEMVER-MINOR) return package format from defaultResolve if known (Gabriel Bota) #40980 perf_hooks: * (SEMVER-MINOR) multiple fixes for Histogram (James M Snell) #41153 stream: * add filter method to readable (Benjamin Gruenbaum) #41354 * add map method to Readable (Benjamin Gruenbaum) #40815 PR-URL: #41557
Notable changes: child_process: * (SEMVER-MINOR) add support for URL to `cp.fork` (Antoine du Hamel) #41225 crypto: * (SEMVER-MINOR) alias webcrypto.subtle and webcrypto.getRandomValues on crypto (James M Snell) #41266 doc: * add Mesteery to collaborators (Mestery) #41543 events: * (SEMVER-MINOR) graduate capturerejections to supported (James M Snell) #41267 * (SEMVER-MINOR) add EventEmitterAsyncResource to core (James M Snell) #41246 loader: * (SEMVER-MINOR) return package format from defaultResolve if known (Gabriel Bota) #40980 perf_hooks: * (SEMVER-MINOR) multiple fixes for Histogram (James M Snell) #41153 stream: * (SEMVER-MINOR) add filter method to readable (Benjamin Gruenbaum, Robert Nagy) #41354 * (SEMVER-MINOR) add isReadable helper (Robert Nagy) #41199 * (SEMVER-MINOR) add map method to Readable (Benjamin Gruenbaum, Robert Nagy) #40815 PR-URL: #41557
Notable changes: child_process: * (SEMVER-MINOR) add support for URL to `cp.fork` (Antoine du Hamel) #41225 crypto: * (SEMVER-MINOR) alias webcrypto.subtle and webcrypto.getRandomValues on crypto (James M Snell) #41266 doc: * add Mesteery to collaborators (Mestery) #41543 events: * (SEMVER-MINOR) graduate capturerejections to supported (James M Snell) #41267 * (SEMVER-MINOR) add EventEmitterAsyncResource to core (James M Snell) #41246 loader: * (SEMVER-MINOR) return package format from defaultResolve if known (Gabriel Bota) #40980 perf_hooks: * (SEMVER-MINOR) multiple fixes for Histogram (James M Snell) #41153 stream: * (SEMVER-MINOR) add filter method to readable (Benjamin Gruenbaum, Robert Nagy) #41354 * (SEMVER-MINOR) add isReadable helper (Robert Nagy) #41199 * (SEMVER-MINOR) add map method to Readable (Benjamin Gruenbaum, Robert Nagy) #40815 PR-URL: #41557
Notable changes: child_process: * (SEMVER-MINOR) add support for URL to `cp.fork` (Antoine du Hamel) #41225 crypto: * (SEMVER-MINOR) alias webcrypto.subtle and webcrypto.getRandomValues on crypto (James M Snell) #41266 doc: * add Mesteery to collaborators (Mestery) #41543 events: * (SEMVER-MINOR) graduate capturerejections to supported (James M Snell) #41267 * (SEMVER-MINOR) add EventEmitterAsyncResource to core (James M Snell) #41246 loader: * (SEMVER-MINOR) return package format from defaultResolve if known (Gabriel Bota) #40980 perf_hooks: * (SEMVER-MINOR) multiple fixes for Histogram (James M Snell) #41153 stream: * (SEMVER-MINOR) add filter method to readable (Benjamin Gruenbaum, Robert Nagy) #41354 * (SEMVER-MINOR) add isReadable helper (Robert Nagy) #41199 * (SEMVER-MINOR) add map method to Readable (Benjamin Gruenbaum, Robert Nagy) #40815 PR-URL: #41557
Notable changes: child_process: * (SEMVER-MINOR) add support for URL to `cp.fork` (Antoine du Hamel) nodejs#41225 crypto: * (SEMVER-MINOR) alias webcrypto.subtle and webcrypto.getRandomValues on crypto (James M Snell) nodejs#41266 doc: * add Mesteery to collaborators (Mestery) nodejs#41543 events: * (SEMVER-MINOR) graduate capturerejections to supported (James M Snell) nodejs#41267 * (SEMVER-MINOR) add EventEmitterAsyncResource to core (James M Snell) nodejs#41246 loader: * (SEMVER-MINOR) return package format from defaultResolve if known (Gabriel Bota) nodejs#40980 perf_hooks: * (SEMVER-MINOR) multiple fixes for Histogram (James M Snell) nodejs#41153 stream: * (SEMVER-MINOR) add filter method to readable (Benjamin Gruenbaum, Robert Nagy) nodejs#41354 * (SEMVER-MINOR) add isReadable helper (Robert Nagy) nodejs#41199 * (SEMVER-MINOR) add map method to Readable (Benjamin Gruenbaum, Robert Nagy) nodejs#40815 PR-URL: nodejs#41557
I don't think the |
The aliases allow code written to assume that `crypto.subtle` and `crypto.getRandomValues()` exist on the `crypto` global to just work. Signed-off-by: James M Snell <jasnell@gmail.com> PR-URL: nodejs#41266 Reviewed-By: Filip Skokan <panva.ip@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Notable changes: child_process: * (SEMVER-MINOR) add support for URL to `cp.fork` (Antoine du Hamel) nodejs#41225 crypto: * (SEMVER-MINOR) alias webcrypto.subtle and webcrypto.getRandomValues on crypto (James M Snell) nodejs#41266 doc: * add Mesteery to collaborators (Mestery) nodejs#41543 events: * (SEMVER-MINOR) graduate capturerejections to supported (James M Snell) nodejs#41267 * (SEMVER-MINOR) add EventEmitterAsyncResource to core (James M Snell) nodejs#41246 loader: * (SEMVER-MINOR) return package format from defaultResolve if known (Gabriel Bota) nodejs#40980 perf_hooks: * (SEMVER-MINOR) multiple fixes for Histogram (James M Snell) nodejs#41153 stream: * (SEMVER-MINOR) add filter method to readable (Benjamin Gruenbaum, Robert Nagy) nodejs#41354 * (SEMVER-MINOR) add isReadable helper (Robert Nagy) nodejs#41199 * (SEMVER-MINOR) add map method to Readable (Benjamin Gruenbaum, Robert Nagy) nodejs#40815 PR-URL: nodejs#41557
The aliases allow code written to assume that
crypto.subtle
andcrypto.getRandomValues()
exist on thecrypto
global to just work.Signed-off-by: James M Snell jasnell@gmail.com