From c09da9a23f272b3646352931f0b0c17954083dbf Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Mon, 22 Apr 2024 13:44:01 -0600 Subject: [PATCH] Modernize window.crypto access constants (#4169) * Force service worker-safe crypto when operating under a service worker * Fix tests/unsafe execution * Further fix tests? * Docs would probably be good * Define a type guard function https://www.typescriptlang.org/docs/handbook/advanced-types.html#user-defined-type-guards * Use `@types` repo * Maybe don't modify tsconfig, I guess * Revert "Use `@types` repo" This reverts commit db46bcf1db4b94fbc7e0c97a20d5d800fcb2768b. * Use a different type for Window * Simplify the crypto accessors --- src/crypto/crypto.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/crypto/crypto.ts b/src/crypto/crypto.ts index c78970708..170dabb09 100644 --- a/src/crypto/crypto.ts +++ b/src/crypto/crypto.ts @@ -16,9 +16,9 @@ limitations under the License. import { logger } from "../logger"; -export let crypto = globalThis.window?.crypto; -export let subtleCrypto = globalThis.window?.crypto?.subtle ?? global.window?.crypto?.webkitSubtle; -export let TextEncoder = globalThis.window?.TextEncoder; +export let crypto = globalThis.crypto; +export let subtleCrypto = crypto?.subtle ?? crypto?.webkitSubtle; // TODO: Stop using webkitSubtle fallback +export let TextEncoder = globalThis.TextEncoder; /* eslint-disable @typescript-eslint/no-var-requires */ if (!crypto) {