From 0bcb7149dc7119e2e812c6e0aee89dc4213fc2c9 Mon Sep 17 00:00:00 2001 From: Kiko Beats Date: Tue, 9 Nov 2021 18:39:29 +0100 Subject: [PATCH] fix(middleware): expose `CryptoKey` and `globalThis.CryptoKey` (#31193) closes https://github.com/vercel/next.js/issues/30475 --- packages/next/server/web/sandbox/polyfills.ts | 6 +++++- packages/next/server/web/sandbox/sandbox.ts | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/next/server/web/sandbox/polyfills.ts b/packages/next/server/web/sandbox/polyfills.ts index 65aadf0488d210f..2a02824f99f7811 100644 --- a/packages/next/server/web/sandbox/polyfills.ts +++ b/packages/next/server/web/sandbox/polyfills.ts @@ -1,4 +1,7 @@ -import { Crypto as WebCrypto } from 'next/dist/compiled/@peculiar/webcrypto' +import { + Crypto as WebCrypto, + CryptoKey, +} from 'next/dist/compiled/@peculiar/webcrypto' import { TransformStream } from 'next/dist/compiled/web-streams-polyfill' import { v4 as uuid } from 'next/dist/compiled/uuid' import crypto from 'crypto' @@ -53,6 +56,7 @@ class TextDecoderRuntime { export { TextDecoderRuntime as TextDecoder } export { TextEncoderRuntime as TextEncoder } +export { CryptoKey } export class Crypto extends WebCrypto { // @ts-ignore Remove once types are updated and we deprecate node 12 diff --git a/packages/next/server/web/sandbox/sandbox.ts b/packages/next/server/web/sandbox/sandbox.ts index 94afaf0b501fd41..8645aa78c700843 100644 --- a/packages/next/server/web/sandbox/sandbox.ts +++ b/packages/next/server/web/sandbox/sandbox.ts @@ -59,6 +59,7 @@ export async function run(params: { timeLog: console.timeLog.bind(console), warn: console.warn.bind(console), }, + CryptoKey: polyfills.CryptoKey, Crypto: polyfills.Crypto, crypto: new polyfills.Crypto(), fetch: (input: RequestInfo, init: RequestInit = {}) => {