refactor: cleanup solver module structure

This commit is contained in:
2025-07-13 22:15:32 +02:00
parent 085492214a
commit 2ebab1eaa6
6 changed files with 11 additions and 11 deletions

View File

@@ -1,3 +1,3 @@
export * as server from "./server";
export * as solver from "./solver";
export * as solver from "./solver/solver";
export * as wire from "./wire";

View File

@@ -1,5 +1,5 @@
import * as wire from "./wire";
import * as solver from "./solver";
import * as solver from "./solver/solver";
import { createArray } from "./utils";
export type CreateChallengesOptions = {

View File

@@ -2,8 +2,8 @@ import {
WORKER_READY,
type WorkerRequest,
type WorkerResponse,
} from "./solver-shared";
import { arrayStartsWith, chunkArray } from "./utils";
} from "./shared";
import { arrayStartsWith, chunkArray } from "../utils";
export async function solveJs(
nonce: Uint8Array,

View File

@@ -1,10 +1,10 @@
import * as solver from "./solver";
import * as wasm from "@pow-captcha/solver-wasm";
import { solveJs } from "./solver";
import { solve as solveWasm } from "@pow-captcha/solver-wasm";
import {
WORKER_READY,
type WorkerRequest,
type WorkerResponse,
} from "./solver-shared";
} from "./shared";
async function solve(
nonce: Uint8Array,
@@ -14,20 +14,20 @@ async function solve(
): Promise<Uint8Array> {
switch (engine) {
case "js":
return await solver.solveJs(nonce, target, difficultyBits);
return await solveJs(nonce, target, difficultyBits);
case "wasm":
return wasm.solve(nonce, target, difficultyBits);
return solveWasm(nonce, target, difficultyBits);
case undefined:
try {
return wasm.solve(nonce, target, difficultyBits);
return solveWasm(nonce, target, difficultyBits);
} catch (err) {
console.warn(
"pow-captcha: Falling back to js solver. Error: ",
err,
);
return await solver.solveJs(nonce, target, difficultyBits);
return await solveJs(nonce, target, difficultyBits);
}
}
}