-
Notifications
You must be signed in to change notification settings - Fork 22
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
fix(node:crypto): properly call web crypto methods #122
Conversation
@@ -5,10 +5,16 @@ import type nodeCrypto from "node:crypto"; | |||
export const CryptoKey = | |||
globalThis.CryptoKey as unknown as typeof nodeCrypto.webcrypto.CryptoKey; | |||
|
|||
export const webcrypto: Crypto & typeof nodeCrypto.webcrypto = { | |||
CryptoKey, |
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.
Maybe we can simply bind CryptoKey in L5 to avoid proxy?
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 haven't tried that, and I don't think I fully understand what you mean to be honest. Can you show me a code example so I can try locally?
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.
const CryptoKey = globalThis.CryptoKey.bind(globalThis.CryptoKey)
. Please try it on your repo (if you have a reproduction that would be amazing too!)
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'm using Nuxt with Deno Deploy, so the issue is somewhat nested in the dependency chain, but I'll try to create a minimal sample.
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.
https://github.com/AaronDewes/unenv-bug-demo There's also some more explanation of the bug in this repo. I hope this shows the issue well enough. Nitro is probably not needed, but was the easiest for me to set up as a demo.
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.
Thank you for nice reproduction! Have made some few refactors to make sure node webcrypto is not affecting us also simplified proxy (by using main crypto as target, proxy handles calls with the right context)
The latest change broke some Nuxt deployments to Deno deploy for me. Deno's webcrypto is somewhat different, and
...globalThis.crypto
does not work in Deno. This replaces it with a custom getter that retrieves the correct value instead. This adds some overhead, but is required for Deno compatibility.