})
}
- // Between 8-256 threads per workgroup based on hardware
- static workload: number = Math.min(256, Math.max(64, 2 ** (navigator.hardwareConcurrency / 2)))
-
// WebGPU Compute Shader
static shader = `
struct UBO {
* 8-byte work is split into two 4-byte u32. Low 4 bytes are random u32 from
* UBO. High 4 bytes are the random value XOR'd with index of each thread.
*/
- @compute @workgroup_size(${this.workload})
+ @compute @workgroup_size(256)
fn main(
@builtin(workgroup_id) workgroup_id: vec3<u32>,
@builtin(local_invocation_id) local_id: vec3<u32>
* @param {number} [threshold=0xfffffff8] - Difficulty of proof-of-work calculation
*/
static async search (hashHex: string, callback: (nonce: string | PromiseLike<string>) => any, threshold: number = 0xfffffff8): Promise<void> {
- if (!/^[A-Fa-f0-9]{64}$/.test(hashHex)) throw new Error(`Invalid hash ${hashHex}`)
+ if (!/^[A-Fa-f0-9]{64}$/.test(hashHex)) throw new TypeError(`Invalid hash ${hashHex}`)
if (typeof threshold !== 'number') throw new TypeError(`Invalid threshold ${threshold}`)
// Ensure WebGPU is initialized before calculating, up to a max time frame