mirror of
https://github.com/TecharoHQ/anubis.git
synced 2026-04-17 05:44:57 +00:00
fix(js): add typed ChallengeResult interface for PoW worker results
The process() function in fast.ts declared Promise<string> but actually
resolved with the full worker message object { hash, data, difficulty,
nonce }. main.tsx papered over this with `any`. Introduce a shared
ChallengeResult type so the contract between workers, algorithms, and
the main component is enforced by the type checker.
Assisted-by: Claude Opus 4.6 via Claude Code
Signed-off-by: Xe Iaso <me@xeiaso.net>
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
import { ChallengeResult } from "./types";
|
||||||
|
|
||||||
type ProgressCallback = (nonce: number) => void;
|
type ProgressCallback = (nonce: number) => void;
|
||||||
|
|
||||||
interface ProcessOptions {
|
interface ProcessOptions {
|
||||||
@@ -17,7 +19,7 @@ export default function process(
|
|||||||
signal: AbortSignal | null = null,
|
signal: AbortSignal | null = null,
|
||||||
progressCallback?: ProgressCallback,
|
progressCallback?: ProgressCallback,
|
||||||
threads: number = Math.trunc(Math.max(getHardwareConcurrency() / 2, 1)),
|
threads: number = Math.trunc(Math.max(getHardwareConcurrency() / 2, 1)),
|
||||||
): Promise<string> {
|
): Promise<ChallengeResult> {
|
||||||
console.debug("fast algo");
|
console.debug("fast algo");
|
||||||
|
|
||||||
// Choose worker based on secure context.
|
// Choose worker based on secure context.
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import fast from "./fast";
|
import fast from "./fast";
|
||||||
|
|
||||||
|
export type { ChallengeResult } from "./types";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
fast: fast,
|
fast: fast,
|
||||||
slow: fast, // XXX(Xe): slow is deprecated, but keep this around in case anything goes bad
|
slow: fast, // XXX(Xe): slow is deprecated, but keep this around in case anything goes bad
|
||||||
|
|||||||
6
web/js/algorithms/types.ts
Normal file
6
web/js/algorithms/types.ts
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
export interface ChallengeResult {
|
||||||
|
hash: string;
|
||||||
|
data: string;
|
||||||
|
difficulty: number;
|
||||||
|
nonce: number;
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import { render } from "preact";
|
import { render } from "preact";
|
||||||
import { useState, useEffect, useRef } from "preact/hooks";
|
import { useState, useEffect, useRef } from "preact/hooks";
|
||||||
import algorithms from "./algorithms";
|
import algorithms, { ChallengeResult } from "./algorithms";
|
||||||
|
|
||||||
// from Xeact
|
// from Xeact
|
||||||
const u = (url: string = "", params: Record<string, any> = {}) => {
|
const u = (url: string = "", params: Record<string, any> = {}) => {
|
||||||
@@ -211,7 +211,7 @@ function App({ anubisVersion, basePrefix }: AppProps) {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.then((result: any) => {
|
.then((result: ChallengeResult) => {
|
||||||
const t1 = Date.now();
|
const t1 = Date.now();
|
||||||
const { hash, nonce } = result;
|
const { hash, nonce } = result;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user