* @param {number} [threshold=0xfffffff8] - Difficulty of proof-of-work calculation
*/
static async search (hash: string, options?: NanoPowOptions): Promise<string> {
+ if (NanoPowGl.#gl == null) throw new Error('WebGL 2 is required')
+ if (this.#gl == null) throw new Error('WebGL 2 is required')
+ if (!/^[A-Fa-f0-9]{64}$/.test(hash)) throw new Error(`Invalid hash ${hash}`)
if (this.#busy) {
return new Promise(resolve => {
setTimeout(async (): Promise<void> => {
})
}
this.#busy = true
- if (NanoPowGl.#gl == null) throw new Error('WebGL 2 is required')
- if (this.#gl == null) throw new Error('WebGL 2 is required')
- if (!/^[A-Fa-f0-9]{64}$/.test(hash)) throw new Error(`Invalid hash ${hash}`)
const threshold = (typeof options?.threshold !== 'number' || options.threshold < 0x0 || options.threshold > 0xffffffff)
? 0xfffffff8
: options.threshold
* @param {number} [threshold=0xfffffff8] - Difficulty of proof-of-work calculation
*/
static async validate (work: string, hash: string, options?: NanoPowOptions): Promise<boolean> {
+ if (NanoPowGl.#gl == null) throw new Error('WebGL 2 is required')
+ if (this.#gl == null) throw new Error('WebGL 2 is required')
+ 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 (this.#busy) {
return new Promise(resolve => {
setTimeout(async (): Promise<void> => {
})
}
this.#busy = true
- if (NanoPowGl.#gl == null) throw new Error('WebGL 2 is required')
- if (this.#gl == null) throw new Error('WebGL 2 is required')
- 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}`)
const threshold = (typeof options?.threshold !== 'number' || options.threshold < 0x0 || options.threshold > 0xffffffff)
? 0xfffffff8
: options.threshold
* @param {NanoPowOptions} options - Used to configure search execution
*/
static async search (hash: string, options?: NanoPowOptions): Promise<string> {
+ if (!/^[A-Fa-f0-9]{64}$/.test(hash)) throw new TypeError(`Invalid hash ${hash}`)
if (this.#busy) {
return new Promise(resolve => {
setTimeout(async (): Promise<void> => {
})
}
this.#busy = true
- if (!/^[A-Fa-f0-9]{64}$/.test(hash)) throw new TypeError(`Invalid hash ${hash}`)
const threshold = (typeof options?.threshold !== 'number' || options.threshold < 0x0 || options.threshold > 0xffffffff)
? 0xfffffff8
: options.threshold
setTimeout(resolve, 500)
})
}
- if (this.#device == null) throw new Error(`WebGPU device failed to load.`)
+ if (this.#device == null) {
+ this.#busy = false
+ throw new Error(`WebGPU device failed to load.`)
+ }
let times = []
let start = performance.now()
* @param {NanoPowOptions} options - Options used to configure search execution
*/
static async validate (work: string, hash: string, options?: NanoPowOptions): Promise<boolean> {
+ if (!/^[A-Fa-f0-9]{16}$/.test(work)) throw new TypeError(`Invalid work ${work}`)
+ if (!/^[A-Fa-f0-9]{64}$/.test(hash)) throw new TypeError(`Invalid hash ${hash}`)
if (this.#busy) {
return new Promise(resolve => {
setTimeout(async (): Promise<void> => {
})
}
this.#busy = true
- if (!/^[A-Fa-f0-9]{16}$/.test(work)) throw new TypeError(`Invalid work ${work}`)
- if (!/^[A-Fa-f0-9]{64}$/.test(hash)) throw new TypeError(`Invalid hash ${hash}`)
const debug = !!(options?.debug)
const threshold = (typeof options?.threshold !== 'number' || options.threshold < 0x0 || options.threshold > 0xffffffff)
? 0xfffffff8
setTimeout(resolve, 500)
})
}
- if (this.#device == null) throw new Error(`WebGPU device failed to load.`)
+ if (this.#device == null) {
+ this.#busy = false
+ throw new Error(`WebGPU device failed to load.`)
+ }
const seed = BigInt(`0x${work}`)
const data = await this.#dispatch(this.#validatePipeline, seed, hash, threshold, 1)