}
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 < view.byteLength; i += 2) {
+ const byte = hashHex.slice(i, i + 2)
+ view.setUint8(i / 2, parseInt(byte, 16))
+ }
+ let hashBytesLE: number[] = []
+ for (let i = 0; i < view.byteLength; i += 4) {
+ hashBytesLE.push(view.getUint32(i, true))
+ }
+ return new Uint32Array(hashBytesLE)
+ }
+
/*
for (i = 0; i<12; i++) {
B2B_G(0, 8, 16, 24, SIGMA82[i * 16 + 0], SIGMA82[i * 16 + 1]);
static calculate (hashHex: string, threshold: number = this.SEND_THRESHOLD, callback: (nonce: string | PromiseLike<string>) => any): void {
if (typeof threshold !== 'number') throw new TypeError(`invalid_threshold ${threshold}`)
if (!/^[A-F-a-f0-9]{64}$/.test(hashHex)) throw new Error(`invalid_hash ${hashHex}`)
- let reverseHex = ''
- for (let i = hashHex.length; i > 0; i -= 2) reverseHex += hashHex.slice(i - 2, i)
if (this.gl == null) throw new Error('webgl2_required')
this.gl.clearColor(0, 0, 0, 1)
+ const blockHashComponents: Uint32Array = this.processHash(hashHex)
// Vertext Shader
const vsSource = `#version 300 es
uniform uvec4 u_work0;
// Last 4 bytes remain as generated externally
uniform uvec4 u_work1;
+ // Precalculated block hash components
+ uniform uint blockHash[8];
// Defined separately from uint v[32] below as the original value is required
// to calculate the second uint32 of the digest for threshold comparison
const work0Location = this.gl.getUniformLocation(program, 'u_work0')
const work1Location = this.gl.getUniformLocation(program, 'u_work1')
+ const blockHashLocation = this.gl.getUniformLocation(program, "blockHash")
// Draw output until success or progressCallback says to stop
let n = 0
this.gl.uniform4uiv(work0Location, this.work0)
this.gl.uniform4uiv(work1Location, this.work1)
+ this.gl.uniform1uiv(blockHashLocation, blockHashComponents)
this.gl.clear(this.gl.COLOR_BUFFER_BIT)
this.gl.drawArrays(this.gl.TRIANGLES, 0, 6)