unenv icon indicating copy to clipboard operation
unenv copied to clipboard

Implement `cypto.createHash`

Open clangenb opened this issue 1 year ago โ€ข 7 comments

Describe the feature

This is currently a showstopper for our project

Additional information

  • [ ] Would you be willing to help implement this feature?

clangenb avatar Apr 30 '24 13:04 clangenb

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

pi0 avatar Apr 30 '24 18:04 pi0

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 avatar Apr 30 '24 20:04 clangenb

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...

clangenb avatar Apr 30 '24 20:04 clangenb

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.

pi0 avatar May 01 '24 07:05 pi0

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.

clangenb avatar May 01 '24 09:05 clangenb

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.

pi0 avatar May 01 '24 09:05 pi0

I'm encountering the same issue here. I'm trying to use ecies-js (with Nuxt 3.13 and nuxthub/cloudflare), and during the decrypt function, I receive the error: Error: [unenv] crypto.createDecipheriv is not implemented yet!

angelorc avatar Sep 07 '24 10:09 angelorc

Yep +1

FutureExcited avatar Oct 03 '24 22:10 FutureExcited

I was lucky that I had access to the library depending on nodes' crypto. So I was able to rewrite the crypto with the webcrypto api, https://github.com/encointer/encointer-js/pull/101. Not sure if this helps anybody.

clangenb avatar Oct 04 '24 06:10 clangenb