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. */
}, 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
}, 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