refactor: cleanup solver module structure
This commit is contained in:
@@ -1,3 +1,3 @@
|
|||||||
export * as server from "./server";
|
export * as server from "./server";
|
||||||
export * as solver from "./solver";
|
export * as solver from "./solver/solver";
|
||||||
export * as wire from "./wire";
|
export * as wire from "./wire";
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import * as wire from "./wire";
|
import * as wire from "./wire";
|
||||||
import * as solver from "./solver";
|
import * as solver from "./solver/solver";
|
||||||
import { createArray } from "./utils";
|
import { createArray } from "./utils";
|
||||||
|
|
||||||
export type CreateChallengesOptions = {
|
export type CreateChallengesOptions = {
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ import {
|
|||||||
WORKER_READY,
|
WORKER_READY,
|
||||||
type WorkerRequest,
|
type WorkerRequest,
|
||||||
type WorkerResponse,
|
type WorkerResponse,
|
||||||
} from "./solver-shared";
|
} from "./shared";
|
||||||
import { arrayStartsWith, chunkArray } from "./utils";
|
import { arrayStartsWith, chunkArray } from "../utils";
|
||||||
|
|
||||||
export async function solveJs(
|
export async function solveJs(
|
||||||
nonce: Uint8Array,
|
nonce: Uint8Array,
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
import * as solver from "./solver";
|
import { solveJs } from "./solver";
|
||||||
import * as wasm from "@pow-captcha/solver-wasm";
|
import { solve as solveWasm } from "@pow-captcha/solver-wasm";
|
||||||
import {
|
import {
|
||||||
WORKER_READY,
|
WORKER_READY,
|
||||||
type WorkerRequest,
|
type WorkerRequest,
|
||||||
type WorkerResponse,
|
type WorkerResponse,
|
||||||
} from "./solver-shared";
|
} from "./shared";
|
||||||
|
|
||||||
async function solve(
|
async function solve(
|
||||||
nonce: Uint8Array,
|
nonce: Uint8Array,
|
||||||
@@ -14,20 +14,20 @@ async function solve(
|
|||||||
): Promise<Uint8Array> {
|
): Promise<Uint8Array> {
|
||||||
switch (engine) {
|
switch (engine) {
|
||||||
case "js":
|
case "js":
|
||||||
return await solver.solveJs(nonce, target, difficultyBits);
|
return await solveJs(nonce, target, difficultyBits);
|
||||||
|
|
||||||
case "wasm":
|
case "wasm":
|
||||||
return wasm.solve(nonce, target, difficultyBits);
|
return solveWasm(nonce, target, difficultyBits);
|
||||||
|
|
||||||
case undefined:
|
case undefined:
|
||||||
try {
|
try {
|
||||||
return wasm.solve(nonce, target, difficultyBits);
|
return solveWasm(nonce, target, difficultyBits);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.warn(
|
console.warn(
|
||||||
"pow-captcha: Falling back to js solver. Error: ",
|
"pow-captcha: Falling back to js solver. Error: ",
|
||||||
err,
|
err,
|
||||||
);
|
);
|
||||||
return await solver.solveJs(nonce, target, difficultyBits);
|
return await solveJs(nonce, target, difficultyBits);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user