Uh oh!
There was an error while loading. Please reload this page.
crypto: expose Web Crypto API under crypto/web - #40462
Conversation
Mesteery
commented
Oct 14, 2021
Personally I think it should be exported as |
I personally would probably just deprecate the |
f5c5e35 to
703c072CompareBy the way, why not export directly the content of webcrypto in Currently, this is not really practical in my opinion in ESM in addition to not being consistent with other builtins exports. import{crypto}from'crypto/web',const{ ... }=crypto;
Yes but most builtins export their submodules ( |
Mesteery
commented
Oct 15, 2021
Oups, sorry |
if you mean why not using a "default" export, it would make it infeasible for exporting any additional functionality under that name if needed. if you mean the
the difference is that the |
tniessen
commented
Oct 15, 2021
cc @jasnell |
| const { ObjectDefineProperty } = primordials; | ||
| ObjectDefineProperty(module.exports, 'crypto', { |
There was a problem hiding this comment.
I would more expect it to directly export the crypto object...
import{subtle,randomUUID}from'crypto/web'There was a problem hiding this comment.
my initial thought was the same, but I thought it would make it harder to export any additional (future) functionality under this export since it's a web api with any potential future additions.
named imports such as import { subtle, randomUUID } from 'crypto/web' would (should) not work, as those methods sit on the prototype of crypto, not on the module namespace.
There was a problem hiding this comment.
As a developer I do not have the expectation of finding Web APIs in ${module}/web and so I feel this addition doesn't do much.
This also rolls back on the use of import() function in ESM examples previously discussed and added 1.
I think we should be thinking of advancing WebCrypto forward in terms of
deciding whether to keep all the proprietary algs or not 2(done)fixing or documenting (non)-conformance 3(done)- graduating from experimental status 4
- exposing crypto as a global for universal javascript libraries to use 5
Footnotes
aduh95
commented
Sep 8, 2022
I'd prefer to expose it as a global, like it is on browsers. However, until this happens,
In general web APIs don't let you destructure them and would throw |
Not just browsers, WinterCG compatible runtimes as well. Anyway, I agree.
What would be the improvement over this which works already? import{webcryptoascrypto}from'node:crypto'; |
panva
commented
Sep 19, 2022
With |
this PR makes the
Web Crypto APIeasier accessible undercrypto/web, similar tofs/promisesand also consistent withstream/web. I think it's also better and consistent with the naming ofcryptowhennode.jsmakes it globally accessible, otherwise I think it would add confusion.currently still missing:
Regarding the current docs, the Web Crypto API docs don't show examples for
cjsandesmas the other modules do. I'm wondering if the examples for cjs should really use the destructuring syntax, as the functionality is sitting on the prototype ofcrypto(subtle, randomUUID, getRandomValues).I took the liberty to change the docs from:
to:
as opposed to: