From 09e07326b8f30c77a78b0d6381ae93bcd1ca360d Mon Sep 17 00:00:00 2001 From: Justin Tay <49700559+justin-tay@users.noreply.github.com> Date: Sat, 29 Mar 2025 12:27:10 +0800 Subject: [PATCH] feat: support detection of crypto for node 19 and above --- src/CryptoEngine/CryptoEngineInit.ts | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/CryptoEngine/CryptoEngineInit.ts b/src/CryptoEngine/CryptoEngineInit.ts index 93422f8ad..7a1366f09 100644 --- a/src/CryptoEngine/CryptoEngineInit.ts +++ b/src/CryptoEngine/CryptoEngineInit.ts @@ -13,11 +13,17 @@ export function initCryptoEngine() { common.setEngine(engineName, new CryptoEngine({ name: engineName, crypto: crypto })); } - } else if (typeof crypto !== "undefined" && "webcrypto" in crypto) { - // NodeJS ^15 - const name = "NodeJS ^15"; - const nodeCrypto = (crypto as any).webcrypto as Crypto; - common.setEngine(name, new CryptoEngine({ name, crypto: nodeCrypto })); + } else if (typeof crypto !== "undefined") { + if ("webcrypto" in crypto) { + // NodeJS ^15 + const name = "NodeJS ^15"; + const nodeCrypto = (crypto as any).webcrypto as Crypto; + common.setEngine(name, new CryptoEngine({ name, crypto: nodeCrypto })); + } else if ("subtle" in crypto) { + // NodeJS ^19 + const name = "NodeJS ^19"; + common.setEngine(name, new CryptoEngine({ name, crypto })); + } } }