})
}
- /**
- * nano-webgl-pow
- * Nano Currency Proof of Work Value generation using WebGL2
- * Author: numtel <ben@latenightsketches.com>
- * License: MIT
- */
// Vertex Shader
static #vsSource = `#version 300 es
#pragma vscode_glsllint_stage: vert
}
static #calculate (hashHex: string, callback: (nonce: string | PromiseLike<string>) => any, threshold: number): void {
+ if (Pow.#gl == null) throw new Error('WebGL 2 is required')
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')
view.setUint8(i / 2, parseInt(byte, 16))
}
const hashBytes = new Uint32Array(view.buffer)
+ Pow.#gl.uniform1uiv(Pow.#blockHashLocation, hashBytes)
+ Pow.#gl.uniform1ui(Pow.#thresholdLocation, threshold)
+ Pow.#gl.uniform1f(Pow.#workloadLocation, Pow.#WORKLOAD - 1)
const work0 = new Uint8Array(4)
const work1 = new Uint8Array(4)
Pow.#gl.uniform4uiv(Pow.#work0Location, work0)
Pow.#gl.uniform4uiv(Pow.#work1Location, work1)
- Pow.#gl.uniform1uiv(Pow.#blockHashLocation, hashBytes)
- Pow.#gl.uniform1ui(Pow.#thresholdLocation, threshold)
- Pow.#gl.uniform1f(Pow.#workloadLocation, Pow.#WORKLOAD - 1)
Pow.#gl.beginQuery(Pow.#gl.ANY_SAMPLES_PASSED_CONSERVATIVE, Pow.#query)
Pow.#gl.drawArrays(Pow.#gl.TRIANGLES, 0, 6)