summaryrefslogtreecommitdiffstats
path: root/third_party/js/PKI.js/src/CryptoEngine/CryptoEngineInit.ts
blob: 93422f8adddc267135a4082154e48118c2e78348 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import * as common from "../common";
import { CryptoEngine } from "./CryptoEngine";

export function initCryptoEngine() {
  if (typeof self !== "undefined") {
    if ("crypto" in self) {
      let engineName = "webcrypto";

      // Apple Safari support
      if ("webkitSubtle" in self.crypto) {
        engineName = "safari";
      }

      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 }));
  }

}