diff --git a/build.js b/build.js index ecc49e7..9cb8ca5 100644 --- a/build.js +++ b/build.js @@ -35,14 +35,25 @@ async function bundleSafeChain() { external: ["certifi"], }); - // Post-process: Replace all usePureJavaScript: false with true - // This ensures node-forge uses pure JavaScript crypto instead of native bindings - // which prevents segmentation faults in pkg binaries on Linux + // Post-process: Force node-forge to use pure JavaScript + // This prevents segmentation faults in pkg binaries on Linux let bundledContent = await readFile("./build/bin/safe-chain.cjs", "utf-8"); + + // 1. Set the option to true bundledContent = bundledContent.replace( /usePureJavaScript:\s*false/g, "usePureJavaScript: true" ); + + // 2. Replace all checks that would enable native crypto + // Change: if (!forge2.options.usePureJavaScript && ...) + // To: if (false && ...) + // This makes the native crypto branches unreachable + bundledContent = bundledContent.replace( + /!forge2\.options\.usePureJavaScript/g, + "false" + ); + await writeFile("./build/bin/safe-chain.cjs", bundledContent); }