CryptoEngineInit.ts (701B)
1 import * as common from "../common"; 2 import { CryptoEngine } from "./CryptoEngine"; 3 4 export function initCryptoEngine() { 5 if (typeof globalThis !== "undefined" && "crypto" in globalThis) { 6 let engineName = "webcrypto"; 7 8 // Apple Safari support 9 if ("webkitSubtle" in globalThis.crypto) { 10 engineName = "safari"; 11 } 12 13 common.setEngine(engineName, new CryptoEngine({ name: engineName, crypto: globalThis.crypto })); 14 } else if (typeof crypto !== "undefined" && "webcrypto" in crypto) { 15 // NodeJS ^15 16 const name = "NodeJS ^15"; 17 const nodeCrypto = (crypto as any).webcrypto as Crypto; 18 common.setEngine(name, new CryptoEngine({ name, crypto: nodeCrypto })); 19 } 20 21 }