unjs / unenv

๐Ÿ•Š๏ธ Convert javaScript code to be runtime agnostic
MIT License
348 stars 18 forks source link

Implement `cypto.createHash` #177

Open clangenb opened 2 months ago

clangenb commented 2 months ago

Describe the feature

This is currently a showstopper for our project

Additional information

pi0 commented 2 months ago

Hi. What is your deployment/runtime that does not support crypto.createHash?

clangenb commented 2 months ago

Hi there, thanks for the quick response! I am not a pro when it comes to the JS world, so I am not sure if this is the correct piece of information. Essentially, it is this tiny nuxt project that I am working on: https://github.com/integritee-network/incognitee-campaign-page/pull/10.

Frramework: Nuxt 3.11.2 with Nitro 2.9.6

 โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€Preview Modeโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
 โ”‚                                                                                              โ”‚
 โ”‚  You are running Nuxt production build in preview mode.                                      โ”‚
 โ”‚  For production deployments, please directly use node ./server/index.mjs command.            โ”‚
 โ”‚                                                                                              โ”‚
 โ”‚  Node.js:           v21.7.3                                                                  โ”‚
 โ”‚  Nitro Preset:      node-server                                                              โ”‚
 โ”‚  Working directory: .output                                                                  โ”‚
 โ”‚                                                                                              โ”‚
 โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ
clangenb commented 2 months ago

Unfortunately, I just realized that I will probably need more than only this function as an RSA library needs this polyfill, so I guess unenv is probably not the right solution as most of the crypto polyfills are not implemented...

pi0 commented 2 months ago

Thanks but i still didn't get what you mean. Node.js 21.7 implements crypto you probably don't need any polyfill unless I'm wrong but if it is not part of crypto subtle, feel free to raise an issue in uncrypto we can introduce them in there.

clangenb commented 2 months ago

Thanks again for the swift answer!

I mean the crypto is running in the browser, and I was checking the code in node/modules/unenv/runtime/node/crypto/node.mjs and I see those lines, which is why I thought it is unimplemented.

export const createDecipheriv = notImplemented("crypto.createDecipheriv");
export const createDiffieHellman = notImplemented("crypto.createDiffieHellman");
export const createDiffieHellmanGroup = notImplemented("crypto.createDiffieHellmanGroup");
export const createECDH = notImplemented("crypto.createECDH");
export const createHash = notImplemented("crypto.createHash");
export const createHmac = notImplemented("crypto.createHmac");
export const createPrivateKey = notImplemented("crypto.createPrivateKey");
export const createPublicKey = notImplemented("crypto.createPublicKey");
export const createSecretKey = notImplemented("crypto.createSecretKey");

This is the log that I saw in the browser that made me think that I am on the right track:

image

Am I doing something wrong? Any pointer would be appreciated.

pi0 commented 2 months ago

Oh right. Yes, they are node.js specific APIs we didn't implement in the browser let me to reopen to investigate how hard it would be to support them.