static async find (hash: string, threshold: string = this.SEND_THRESHOLD): Promise<string> {
return new Promise<string>(resolve => {
- this.calculate(hash, resolve, undefined, threshold)
+ this.calculate(hash, threshold, resolve)
})
}
// Both width and height must be multiple of 256, (one byte)
// but do not need to be the same,
// matching GPU capabilities is the aim
- static webglWidth = 256 * 1
- static webglHeight = 256 * 1
+ static webglWidth = 256 * 8
+ static webglHeight = 256 * 8
static hexify (arr: number[] | Uint8Array): string {
let out = ''
return out
}
- static calculate (hashHex: string, callback: (nonce: string | PromiseLike<string>) => any, progressCallback?: (frames: number) => any, threshold: number | string = '0xFFFFFFF8'): void {
+ static calculate (hashHex: string, threshold: number | string = '0xFFFFFFF8', callback: (nonce: string | PromiseLike<string>) => any): void {
if (typeof threshold === 'number') threshold = '0x' + threshold.toString(16)
const canvas = new OffscreenCanvas(this.webglWidth, this.webglHeight)
v[b + 1] = (xor0 >> 31) ^ (xor1 << 1);
}
- bool found = false;
- void find() {
+ void main() {
int i;
uint uv_x = uint(uv_pos.x * ${canvas.width - 1}.);
uint uv_y = uint(uv_pos.y * ${canvas.height - 1}.);
// only calculate digest of the second 4 bytes
if((BLAKE2B_IV32_1 ^ v[1] ^ v[17]) > ` + threshold + `u) {
// Success found, return pixel data so work value can be constructed
- found = true;
fragColor = vec4(
float(x_index + 1u)/255., // +1 to distinguish from 0 (unsuccessful) pixels
float(y_index + 1u)/255., // Same as previous
float(y_pos)/255. // Second custom byte
);
}
- }
-
- void main() {
- int count = 0;
- do {
- count++;
- find();
- } while (!found && count < 10);
}`
const vertexShader = gl.createShader(gl.VERTEX_SHADER)
// Draw output until success or progressCallback says to stop
const work0 = new Uint8Array(4)
const work1 = new Uint8Array(4)
- let n = 0
const draw = (): void => {
- n++
crypto.getRandomValues(work0)
crypto.getRandomValues(work1)
gl.uniform4uiv(work0Location, work0)
gl.uniform4uiv(work1Location, work1)
- // Check with progressCallback every 100 frames
- if (n % 100 === 0 && typeof progressCallback === 'function' && progressCallback(n))
- return
-
gl.clear(gl.COLOR_BUFFER_BIT)
gl.drawArrays(gl.TRIANGLES, 0, 6)
const pixels = new Uint8Array(gl.drawingBufferWidth * gl.drawingBufferHeight * 4)