static #WORKLOAD: number = 256 * Math.max(1, Math.floor(navigator.hardwareConcurrency / 2))
static #work0 = new Uint8Array(4)
static #work1 = new Uint8Array(4)
- static #SIGMA82: number[] = [
- 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 28, 20, 8, 16, 18, 30, 26, 12, 2, 24,
- 0, 4, 22, 14, 10, 6, 22, 16, 24, 0, 10, 4, 30, 26, 20, 28, 6, 12, 14, 2, 18, 8, 14, 18, 6, 2, 26,
- 24, 22, 28, 4, 12, 10, 20, 8, 0, 30, 16, 18, 0, 10, 14, 4, 8, 20, 30, 28, 2, 22, 24, 12, 16, 6,
- 26, 4, 24, 12, 20, 0, 22, 16, 6, 8, 26, 14, 10, 30, 28, 2, 18, 24, 10, 2, 30, 28, 26, 8, 20, 0,
- 14, 12, 6, 18, 4, 16, 22, 26, 22, 14, 28, 24, 2, 6, 18, 10, 0, 30, 8, 16, 12, 4, 20, 12, 30, 28,
- 18, 22, 6, 0, 16, 24, 4, 26, 14, 2, 8, 20, 10, 20, 4, 16, 8, 14, 12, 2, 10, 30, 22, 18, 28, 6, 24,
- 26, 0, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 28, 20, 8, 16, 18, 30, 26, 12,
- 2, 24, 0, 4, 22, 14, 10, 6
- ]
- static #B2B_G_params: number[] = []
- static {
- for (let i = 0; i < 12; i++) {
- this.#B2B_G_params.push(this.#SIGMA82[i * 16 + 0])
- this.#B2B_G_params.push(this.#SIGMA82[i * 16 + 1])
- this.#B2B_G_params.push(this.#SIGMA82[i * 16 + 2])
- this.#B2B_G_params.push(this.#SIGMA82[i * 16 + 3])
- this.#B2B_G_params.push(this.#SIGMA82[i * 16 + 4])
- this.#B2B_G_params.push(this.#SIGMA82[i * 16 + 5])
- this.#B2B_G_params.push(this.#SIGMA82[i * 16 + 6])
- this.#B2B_G_params.push(this.#SIGMA82[i * 16 + 7])
- this.#B2B_G_params.push(this.#SIGMA82[i * 16 + 8])
- this.#B2B_G_params.push(this.#SIGMA82[i * 16 + 9])
- this.#B2B_G_params.push(this.#SIGMA82[i * 16 + 10])
- this.#B2B_G_params.push(this.#SIGMA82[i * 16 + 11])
- this.#B2B_G_params.push(this.#SIGMA82[i * 16 + 12])
- this.#B2B_G_params.push(this.#SIGMA82[i * 16 + 13])
- this.#B2B_G_params.push(this.#SIGMA82[i * 16 + 14])
- this.#B2B_G_params.push(this.#SIGMA82[i * 16 + 15])
- }
- }
static #hexify (arr: number[] | Uint8Array): string {
let out = ''
return out
}
- static #processHash (hashHex: string): Uint32Array {
- if (!/^[A-F-a-f0-9]{64}$/.test(hashHex)) {
- throw new Error(`invalid_hash ${hashHex}`)
- }
- const view = new DataView(new ArrayBuffer(32))
- for (let i = 0; i < 64; i += 2) {
- const byte = hashHex.slice(i, i + 2)
- view.setUint8(i / 2, parseInt(byte, 16))
- }
- return new Uint32Array(view.buffer)
- }
-
/*
for (i = 0; i<12; i++) {
B2B_G(0, 8, 16, 24, SIGMA82[i * 16 + 0], SIGMA82[i * 16 + 1]);
}
static #calculate (hashHex: string, callback: (nonce: string | PromiseLike<string>) => any, threshold: number): void {
+ if (!/^[A-F-a-f0-9]{64}$/.test(hashHex)) throw new Error(`invalid_hash ${hashHex}`)
if (typeof threshold !== 'number') throw new TypeError(`Invalid threshold ${threshold}`)
if (this.#gl == null) throw new Error('WebGL 2 is required')
this.#gl.clearColor(0, 0, 0, 1)
- const hashBytes: Uint32Array = this.#processHash(hashHex)
+
+ // Convert big-endian hash hex to buffer for use by shader
+ const view = new DataView(new ArrayBuffer(32))
+ for (let i = 0; i < 64; i += 2) {
+ const byte = hashHex.slice(i, i + 2)
+ view.setUint8(i / 2, parseInt(byte, 16))
+ }
+ const hashBytes = new Uint32Array(view.buffer)
// Draw output until success or progressCallback says to stop
let n = 0