-
Notifications
You must be signed in to change notification settings - Fork 205
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
BUG: crypto.subtle.generateKey instanceof with undefined object #457
Comments
Just had the same issue working with Jose locally. Workaround is downgrade to node 18. Discussion in Jose: panva/jose#487 |
The issue is likely that miniflare depends on the webcrypto of node having CryptoKey attached to the webcrypto object. That was a workaround before webcrypto in node was stable and available on the global object in 19.x moving forward. miniflare should get an update to detect CryptoKey on the global object first, then try and get it from the webcrypto export. |
I think this patch ought to help with Node 19 or 18 with the --experimental-global-webcrypto flag. diff --git a/packages/core/src/plugins/core.ts b/packages/core/src/plugins/core.ts
index dc5ddaa..7437f11 100644
--- a/packages/core/src/plugins/core.ts
+++ b/packages/core/src/plugins/core.ts
@@ -543,7 +543,7 @@ export class CorePlugin extends Plugin<CoreOptions> implements CoreOptions {
Math,
crypto,
- CryptoKey: crypto.CryptoKey,
+ CryptoKey: globalThis.CryptoKey || crypto.CryptoKey,
TextDecoder,
TextEncoder,
diff --git a/packages/core/src/standards/crypto.ts b/packages/core/src/standards/crypto.ts
index 6883d6a..649484c 100644
--- a/packages/core/src/standards/crypto.ts
+++ b/packages/core/src/standards/crypto.ts
@@ -125,7 +125,7 @@ const generateKey: typeof webcrypto.subtle.generateKey = async function (
// @ts-expect-error TypeScript cannot infer the correct overload here
await webcrypto.subtle.generateKey(algorithm, extractable, keyUsages);
// noinspection SuspiciousTypeOfGuard
- if (key instanceof webcrypto.CryptoKey) {
+ if (key instanceof (globalThis.CryptoKey || webcrypto.CryptoKey)) {
return ensureValidWorkerKey(key);
} else {
key.publicKey = ensureValidWorkerKey(key.publicKey); |
I noticed that the last release was October 2022 and this issue is blocking me too. Is there some schedule for the next release? |
A simple repro:
Debugging the generated Javascript code, https://github.com/cloudflare/miniflare/blob/master/packages/core/src/standards/crypto.ts#L128 is the place where instanceof is called with an undefined object.
The text was updated successfully, but these errors were encountered: