Skip to content

Commit

Permalink
rm CircuitBase
Browse files Browse the repository at this point in the history
  • Loading branch information
kroist committed Jan 10, 2025
1 parent 44f396b commit a1bd333
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 28 deletions.
14 changes: 8 additions & 6 deletions ts/shielder-sdk-crypto-wasm/src/circuits/deposit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<InstanceType<WasmDepositCircuit>>
extends WasmClientModuleBase
implements IDepositCircuit
{
private wasmCircuit: InstanceType<WasmDepositCircuit> | 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<Proof> {
Expand Down
14 changes: 8 additions & 6 deletions ts/shielder-sdk-crypto-wasm/src/circuits/newAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<InstanceType<WasmNewAccountCircuit>>
extends WasmClientModuleBase
implements INewAccountCircuit
{
private wasmCircuit: InstanceType<WasmNewAccountCircuit> | 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<Proof> {
Expand Down
14 changes: 8 additions & 6 deletions ts/shielder-sdk-crypto-wasm/src/circuits/withdraw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<InstanceType<WasmWithdrawCircuit>>
extends WasmClientModuleBase
implements IWithdrawCircuit
{
private wasmCircuit: InstanceType<WasmWithdrawCircuit> | 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<Proof> {
Expand Down
10 changes: 0 additions & 10 deletions ts/shielder-sdk-crypto-wasm/src/utils/wasmModuleLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,3 @@ export abstract class WasmClientModuleBase {
this.wasmModule = getWasmModule(caller);
}
}

export abstract class CircuitBase<T> extends WasmClientModuleBase {
protected wasmCircuit: T | undefined;

init(caller: Caller, createCircuit: (module: WasmModule) => T) {
super.init(caller);
const wasmModule = getWasmModule(caller);
this.wasmCircuit = createCircuit(wasmModule);
}
}

0 comments on commit a1bd333

Please sign in to comment.