From 4cfbd3931f4a7447db3a6eeb570767d3ef1ed6b7 Mon Sep 17 00:00:00 2001 From: Cedoor Date: Mon, 22 Dec 2025 12:23:14 +0100 Subject: [PATCH 1/4] fix: update getOptimalThreadCount to work in browsers --- .../CRISP/packages/crisp-sdk/src/utils.ts | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/examples/CRISP/packages/crisp-sdk/src/utils.ts b/examples/CRISP/packages/crisp-sdk/src/utils.ts index c49980f724..9cdbbc094c 100644 --- a/examples/CRISP/packages/crisp-sdk/src/utils.ts +++ b/examples/CRISP/packages/crisp-sdk/src/utils.ts @@ -124,27 +124,34 @@ export const getAddressFromSignature = async (signature: `0x${string}`, messageH } /** - * Get optimal number of threads for proof generation - * Leaves at least 1 core free for other operations - * Works in both Node.js and browser environments + * Get optimal number of threads for proof generation. + * Leaves at least 1 core free for other operations. + * Works in both Node.js and browser environments. */ export async function getOptimalThreadCount(): Promise { + // Browser environment - check first to avoid Node.js imports in browser builds + if (typeof navigator !== 'undefined' && navigator.hardwareConcurrency) { + return Math.max(1, navigator.hardwareConcurrency - 1) + } + // Node.js environment - use os module if available - if (typeof process !== 'undefined' && process.versions?.node) { + // Check for Node.js without directly accessing process to avoid polyfill detection + const isNode = typeof window === 'undefined' && typeof globalThis !== 'undefined' && typeof globalThis.process !== 'undefined' + + if (isNode) { try { - const os = await import('os') + // Build module specifier from character codes to avoid string literal detection. + // This prevents bundlers and polyfill plugins from detecting 'os'. + const moduleName = [111, 115].map((c) => String.fromCharCode(c)).join('') + const dynamicImport = new Function('specifier', 'return import(specifier)') + const os = await dynamicImport(moduleName) const cpuCount = typeof os.availableParallelism === 'function' ? os.availableParallelism() : os.cpus().length return Math.max(1, cpuCount - 1) } catch { - // Fall through to browser check or fallback + // Fall through to fallback } } - // Browser environment - if (typeof navigator !== 'undefined' && navigator.hardwareConcurrency) { - return Math.max(1, navigator.hardwareConcurrency - 1) - } - // Fallback return 5 } From 7d816ce250d9755b4ce381e0faa7f89623b2b48e Mon Sep 17 00:00:00 2001 From: Cedoor Date: Mon, 22 Dec 2025 12:30:57 +0100 Subject: [PATCH 2/4] refactor: import os module dynamically without obfuscation --- examples/CRISP/packages/crisp-sdk/src/utils.ts | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/examples/CRISP/packages/crisp-sdk/src/utils.ts b/examples/CRISP/packages/crisp-sdk/src/utils.ts index 9cdbbc094c..7317a128b9 100644 --- a/examples/CRISP/packages/crisp-sdk/src/utils.ts +++ b/examples/CRISP/packages/crisp-sdk/src/utils.ts @@ -136,16 +136,12 @@ export async function getOptimalThreadCount(): Promise { // Node.js environment - use os module if available // Check for Node.js without directly accessing process to avoid polyfill detection - const isNode = typeof window === 'undefined' && typeof globalThis !== 'undefined' && typeof globalThis.process !== 'undefined' - - if (isNode) { + if (typeof window === 'undefined' && typeof globalThis !== 'undefined' && typeof globalThis.process !== 'undefined') { try { - // Build module specifier from character codes to avoid string literal detection. - // This prevents bundlers and polyfill plugins from detecting 'os'. - const moduleName = [111, 115].map((c) => String.fromCharCode(c)).join('') - const dynamicImport = new Function('specifier', 'return import(specifier)') - const os = await dynamicImport(moduleName) + const os = await import('os') + const cpuCount = typeof os.availableParallelism === 'function' ? os.availableParallelism() : os.cpus().length + return Math.max(1, cpuCount - 1) } catch { // Fall through to fallback From 55cfe21c2faa0bab7132fab237b0d4cdf5f4dc8e Mon Sep 17 00:00:00 2001 From: Cedoor Date: Mon, 22 Dec 2025 12:58:22 +0100 Subject: [PATCH 3/4] chore(crisp): publish version 0.5.6 - Updated @crisp-e3/sdk to 0.5.6 - Updated @crisp-e3/contracts to 0.5.6 - Updated @crisp-e3/zk-inputs to 0.5.6 - Published to npm --- examples/CRISP/client/package.json | 2 +- examples/CRISP/packages/crisp-contracts/package.json | 2 +- examples/CRISP/packages/crisp-sdk/package.json | 2 +- examples/CRISP/packages/crisp-zk-inputs/package.json | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/CRISP/client/package.json b/examples/CRISP/client/package.json index 2f6ab8b2c2..3e0b9e015b 100644 --- a/examples/CRISP/client/package.json +++ b/examples/CRISP/client/package.json @@ -18,7 +18,7 @@ "deploy": "gh-pages -d dist" }, "dependencies": { - "@crisp-e3/sdk": "0.5.4", + "@crisp-e3/sdk": "0.5.6", "@emotion/babel-plugin": "^11.11.0", "@emotion/react": "^11.11.4", "@phosphor-icons/react": "^2.1.4", diff --git a/examples/CRISP/packages/crisp-contracts/package.json b/examples/CRISP/packages/crisp-contracts/package.json index e880974454..49af32d353 100644 --- a/examples/CRISP/packages/crisp-contracts/package.json +++ b/examples/CRISP/packages/crisp-contracts/package.json @@ -1,6 +1,6 @@ { "name": "@crisp-e3/contracts", - "version": "0.5.4", + "version": "0.5.6", "type": "module", "files": [ "contracts", diff --git a/examples/CRISP/packages/crisp-sdk/package.json b/examples/CRISP/packages/crisp-sdk/package.json index 2a2dc0d678..6f0b44bbeb 100644 --- a/examples/CRISP/packages/crisp-sdk/package.json +++ b/examples/CRISP/packages/crisp-sdk/package.json @@ -1,6 +1,6 @@ { "name": "@crisp-e3/sdk", - "version": "0.5.4", + "version": "0.5.6", "type": "module", "author": { "name": "gnosisguild", diff --git a/examples/CRISP/packages/crisp-zk-inputs/package.json b/examples/CRISP/packages/crisp-zk-inputs/package.json index c9120422e6..70d4b078c1 100644 --- a/examples/CRISP/packages/crisp-zk-inputs/package.json +++ b/examples/CRISP/packages/crisp-zk-inputs/package.json @@ -2,7 +2,7 @@ "name": "@crisp-e3/zk-inputs", "type": "module", "description": "Core logic to pre-compute CRISP ZK inputs (WASM/JavaScript bindings).", - "version": "0.5.4", + "version": "0.5.6", "license": "LGPL-3.0-only", "repository": { "type": "git", From c6513e436c7d6e39663bd3abbc629282503f5f7b Mon Sep 17 00:00:00 2001 From: Cedoor Date: Mon, 22 Dec 2025 12:58:26 +0100 Subject: [PATCH 4/4] chore: update lockfile --- pnpm-lock.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 39779de543..c117a0cb98 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -143,7 +143,7 @@ importers: examples/CRISP/client: dependencies: '@crisp-e3/sdk': - specifier: 0.5.4 + specifier: 0.5.6 version: link:../packages/crisp-sdk '@emotion/babel-plugin': specifier: ^11.11.0