diff --git a/packages/lib/src/core/membership_prover.ts b/packages/lib/src/core/membership_prover.ts index de7d9629e..82f2c771c 100644 --- a/packages/lib/src/core/membership_prover.ts +++ b/packages/lib/src/core/membership_prover.ts @@ -90,7 +90,8 @@ export class MembershipProver extends Profiler implements IProver { this.timeEnd("Generate witness"); this.time("Load circuit"); - const circuitBin = await loadCircuit(this.circuit); + const useRemoteCircuit = typeof window !== "undefined"; + const circuitBin = await loadCircuit(this.circuit, useRemoteCircuit); this.timeEnd("Load circuit"); // Get the public input in bytes diff --git a/packages/lib/src/core/membership_verifier.ts b/packages/lib/src/core/membership_verifier.ts index 2ce14ba74..c9be29045 100644 --- a/packages/lib/src/core/membership_verifier.ts +++ b/packages/lib/src/core/membership_verifier.ts @@ -13,6 +13,7 @@ import { PublicInput, verifyEffEcdsaPubInput } from "../helpers/public_input"; */ export class MembershipVerifier extends Profiler implements IVerifier { circuit: string; + useRemoteCircuit: boolean; constructor(options: VerifyConfig) { super({ enabled: options?.enableProfiler }); @@ -30,6 +31,8 @@ export class MembershipVerifier extends Profiler implements IVerifier { } this.circuit = options.circuit; + this.useRemoteCircuit = + options.useRemoteCircuit ?? typeof window !== "undefined"; } async initWasm() { @@ -41,7 +44,7 @@ export class MembershipVerifier extends Profiler implements IVerifier { publicInputSer: Uint8Array ): Promise { this.time("Load circuit"); - const circuitBin = await loadCircuit(this.circuit); + const circuitBin = await loadCircuit(this.circuit, this.useRemoteCircuit); this.timeEnd("Load circuit"); this.time("Verify public input"); diff --git a/packages/lib/src/helpers/utils.ts b/packages/lib/src/helpers/utils.ts index 978801cb8..542396482 100644 --- a/packages/lib/src/helpers/utils.ts +++ b/packages/lib/src/helpers/utils.ts @@ -18,9 +18,8 @@ export const snarkJsWitnessGen = async (input: any, wasmFile: string) => { /** * Load a circuit from a file or URL */ -export const loadCircuit = async (pathOrUrl: string): Promise => { - const isWeb = typeof window !== "undefined"; - if (isWeb) { +export const loadCircuit = async (pathOrUrl: string, useRemoteCircuit: boolean): Promise => { + if (useRemoteCircuit) { return await fetchCircuit(pathOrUrl); } else { return await readCircuitFromFs(pathOrUrl); diff --git a/packages/lib/src/types.ts b/packages/lib/src/types.ts index e6f63eb9b..d7f0997a0 100644 --- a/packages/lib/src/types.ts +++ b/packages/lib/src/types.ts @@ -29,6 +29,7 @@ export interface ProverConfig { export interface VerifyConfig { circuit: string; // Path to circuit file compiled by Nova-Scotia enableProfiler?: boolean; + useRemoteCircuit?: boolean; } export interface IProver {