From: Chris Duncan Date: Fri, 28 Mar 2025 03:31:09 +0000 (-0700) Subject: Merge branch 'main' into next/recover-execution X-Git-Url: https://zoso.dev/?a=commitdiff_plain;h=6e8ed6882c7be77afd9a224cd0473f8da5236a38;p=nano-pow.git Merge branch 'main' into next/recover-execution --- 6e8ed6882c7be77afd9a224cd0473f8da5236a38 diff --cc src/lib/gl/index.ts index ed39a9e,0c90c2d..fca8265 --- a/src/lib/gl/index.ts +++ b/src/lib/gl/index.ts @@@ -14,8 -14,8 +14,9 @@@ export class NanoPowGl static #SEND: bigint = 0xfffffff800000000n static #RECEIVE: bigint = 0xfffffe0000000000n + static #isInitialized: boolean = false static #busy: boolean = false + static #call: NanoPowExecution | null = null static #debug: boolean = false static #raf: number = 0 /** Used to set canvas size. */ @@@ -391,15 -366,16 +392,21 @@@ }, 100) }) } + if (this.#isInitialized === false) this.init() this.#busy = true - this.#call ??= { ++ this.#call = { + method: 'work_generate', + hash, + options + } - /** Process user input */ - if (!/^[A-Fa-f0-9]{64}$/.test(hash)) throw new Error(`Invalid hash ${hash}`) + if (typeof options?.threshold === 'string') { + try { + options.threshold = BigInt(`0x${options.threshold}`) + } catch (err) { + throw new TypeError(`Invalid threshold ${options.threshold}`) + } + } const threshold = (typeof options?.threshold !== 'bigint' || options.threshold < 1n || options.threshold > 0xffffffffffffffffn) ? 0xfffffff800000000n : options.threshold @@@ -515,11 -466,16 +524,21 @@@ }, 100) }) } + if (this.#isInitialized === false) this.init() this.#busy = true ++ this.#call = { ++ method: 'work_validate', ++ hash, ++ options ++ } - /** Process user input */ - if (!/^[A-Fa-f0-9]{16}$/.test(work)) throw new Error(`Invalid work ${work}`) - if (!/^[A-Fa-f0-9]{64}$/.test(hash)) throw new Error(`Invalid hash ${hash}`) + if (typeof options?.threshold === 'string') { + try { + options.threshold = BigInt(`0x${options.threshold}`) + } catch (err) { + throw new TypeError(`Invalid threshold ${options.threshold}`) + } + } const threshold = (typeof options?.threshold !== 'bigint' || options.threshold < 1n || options.threshold > 0xffffffffffffffffn) ? 0xfffffff800000000n : options.threshold