From 20420f865e6d20b956f103d437f8626aae85f6ed Mon Sep 17 00:00:00 2001 From: Sander Declerck Date: Fri, 28 Nov 2025 15:32:52 +0100 Subject: [PATCH] Try set pure javascript for node-forge --- build.js | 12 ++++++++++++ packages/safe-chain/src/registryProxy/certBundle.js | 8 ++++---- packages/safe-chain/src/registryProxy/certUtils.js | 3 --- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/build.js b/build.js index e576c5a..667e2ed 100644 --- a/build.js +++ b/build.js @@ -26,6 +26,15 @@ async function clearOutputFolder() { } async function bundleSafeChain() { + // Read the forge.js file and modify it to use pure JavaScript + const forgeContent = await readFile("./node_modules/node-forge/lib/forge.js", "utf-8"); + const modifiedForge = forgeContent.replace( + "usePureJavaScript: false", + "usePureJavaScript: true" + ); + await mkdir("./build/temp", { recursive: true }); + await writeFile("./build/temp/forge.js", modifiedForge); + await build({ entryPoints: ["./packages/safe-chain/bin/safe-chain.js"], bundle: true, @@ -33,6 +42,9 @@ async function bundleSafeChain() { target: "node24", outfile: "./build/bin/safe-chain.cjs", external: ["certifi"], + alias: { + "node-forge/lib/forge": "./build/temp/forge.js", + }, }); } diff --git a/packages/safe-chain/src/registryProxy/certBundle.js b/packages/safe-chain/src/registryProxy/certBundle.js index 9b36c80..956279d 100644 --- a/packages/safe-chain/src/registryProxy/certBundle.js +++ b/packages/safe-chain/src/registryProxy/certBundle.js @@ -5,7 +5,7 @@ import path from "node:path"; import certifi from "certifi"; import tls from "node:tls"; import { X509Certificate } from "node:crypto"; -// import { getCaCertPath } from "./certUtils.js"; +import { getCaCertPath } from "./certUtils.js"; /** * Check if a PEM string contains only parsable cert blocks. @@ -58,10 +58,10 @@ export function getCombinedCaBundlePath() { const parts = []; // 1) Safe Chain CA (for MITM'd registries) - // const safeChainPath = getCaCertPath(); + const safeChainPath = getCaCertPath(); try { - // const safeChainPem = fs.readFileSync(safeChainPath, "utf8"); - // if (isParsable(safeChainPem)) parts.push(safeChainPem.trim()); + const safeChainPem = fs.readFileSync(safeChainPath, "utf8"); + if (isParsable(safeChainPem)) parts.push(safeChainPem.trim()); } catch { // Ignore if Safe Chain CA is not available } diff --git a/packages/safe-chain/src/registryProxy/certUtils.js b/packages/safe-chain/src/registryProxy/certUtils.js index cb69473..02a0f53 100644 --- a/packages/safe-chain/src/registryProxy/certUtils.js +++ b/packages/safe-chain/src/registryProxy/certUtils.js @@ -4,9 +4,6 @@ import fs from "fs"; import os from "os"; import { ui } from "../environment/userInteraction.js"; -// @ts-ignore -forge.options.usePureJavaScript = true; - const certFolder = path.join(os.homedir(), ".safe-chain", "certs"); const ca = loadCa();