diff --git a/ts/shielder-sdk-crypto-wasm/src/circuits/deposit.ts b/ts/shielder-sdk-crypto-wasm/src/circuits/deposit.ts index 4307ac77..74221fc3 100644 --- a/ts/shielder-sdk-crypto-wasm/src/circuits/deposit.ts +++ b/ts/shielder-sdk-crypto-wasm/src/circuits/deposit.ts @@ -5,21 +5,23 @@ import { DepositCircuit as IDepositCircuit } from "shielder-sdk-crypto"; import { Caller } from "../wasmClient"; -import { CircuitBase, WasmModule } from "../utils/wasmModuleLoader"; +import { WasmClientModuleBase } from "../utils/wasmModuleLoader"; type WasmDepositCircuit = | typeof import("shielder-wasm/web-singlethreaded").DepositCircuit | typeof import("shielder-wasm/web-multithreaded").DepositCircuit; export class DepositCircuit - extends CircuitBase> + extends WasmClientModuleBase implements IDepositCircuit { + private wasmCircuit: InstanceType | undefined; init(caller: Caller) { - super.init( - caller, - (wasmModule: WasmModule) => new wasmModule.DepositCircuit() - ); + super.init(caller); + if (!this.wasmModule) { + throw new Error("Wasm module not loaded"); + } + this.wasmCircuit = new this.wasmModule.DepositCircuit(); } prove(values: DepositAdvice): Promise { diff --git a/ts/shielder-sdk-crypto-wasm/src/circuits/newAccount.ts b/ts/shielder-sdk-crypto-wasm/src/circuits/newAccount.ts index 91430ca7..7c0f0507 100644 --- a/ts/shielder-sdk-crypto-wasm/src/circuits/newAccount.ts +++ b/ts/shielder-sdk-crypto-wasm/src/circuits/newAccount.ts @@ -5,21 +5,23 @@ import { NewAccountCircuit as INewAccountCircuit } from "shielder-sdk-crypto"; import { Caller } from "../wasmClient"; -import { CircuitBase, WasmModule } from "../utils/wasmModuleLoader"; +import { WasmClientModuleBase } from "../utils/wasmModuleLoader"; type WasmNewAccountCircuit = | typeof import("shielder-wasm/web-singlethreaded").NewAccountCircuit | typeof import("shielder-wasm/web-multithreaded").NewAccountCircuit; export class NewAccountCircuit - extends CircuitBase> + extends WasmClientModuleBase implements INewAccountCircuit { + private wasmCircuit: InstanceType | undefined; init(caller: Caller) { - super.init( - caller, - (wasmModule: WasmModule) => new wasmModule.NewAccountCircuit() - ); + super.init(caller); + if (!this.wasmModule) { + throw new Error("Wasm module not loaded"); + } + this.wasmCircuit = new this.wasmModule.NewAccountCircuit(); } prove(values: NewAccountAdvice): Promise { diff --git a/ts/shielder-sdk-crypto-wasm/src/circuits/withdraw.ts b/ts/shielder-sdk-crypto-wasm/src/circuits/withdraw.ts index 310b8da4..a20d97a1 100644 --- a/ts/shielder-sdk-crypto-wasm/src/circuits/withdraw.ts +++ b/ts/shielder-sdk-crypto-wasm/src/circuits/withdraw.ts @@ -5,21 +5,23 @@ import { WithdrawCircuit as IWithdrawCircuit } from "shielder-sdk-crypto"; import { Caller } from "../wasmClient"; -import { CircuitBase, WasmModule } from "../utils/wasmModuleLoader"; +import { WasmClientModuleBase } from "../utils/wasmModuleLoader"; type WasmWithdrawCircuit = | typeof import("shielder-wasm/web-singlethreaded").WithdrawCircuit | typeof import("shielder-wasm/web-multithreaded").WithdrawCircuit; export class WithdrawCircuit - extends CircuitBase> + extends WasmClientModuleBase implements IWithdrawCircuit { + private wasmCircuit: InstanceType | undefined; init(caller: Caller) { - super.init( - caller, - (wasmModule: WasmModule) => new wasmModule.WithdrawCircuit() - ); + super.init(caller); + if (!this.wasmModule) { + throw new Error("Wasm module not loaded"); + } + this.wasmCircuit = new this.wasmModule.WithdrawCircuit(); } prove(values: WithdrawAdvice): Promise { diff --git a/ts/shielder-sdk-crypto-wasm/src/utils/wasmModuleLoader.ts b/ts/shielder-sdk-crypto-wasm/src/utils/wasmModuleLoader.ts index 79f95883..169ff302 100644 --- a/ts/shielder-sdk-crypto-wasm/src/utils/wasmModuleLoader.ts +++ b/ts/shielder-sdk-crypto-wasm/src/utils/wasmModuleLoader.ts @@ -26,13 +26,3 @@ export abstract class WasmClientModuleBase { this.wasmModule = getWasmModule(caller); } } - -export abstract class CircuitBase extends WasmClientModuleBase { - protected wasmCircuit: T | undefined; - - init(caller: Caller, createCircuit: (module: WasmModule) => T) { - super.init(caller); - const wasmModule = getWasmModule(caller); - this.wasmCircuit = createCircuit(wasmModule); - } -}