}
})
- async function find (hash: string, threshold: string = SEND_THRESHOLD): Promise<void> {
- return new Promise(resolve => {
+ async function find (hash: string, threshold: string = SEND_THRESHOLD): Promise<string> {
+ return new Promise<string>(resolve => {
calculate(hash, resolve, undefined, threshold)
})
}
return out
}
- function calculate (hashHex: string, callback: (nonce: string) => any, progressCallback: (frames: number) => any, threshold: number | string = '0xFFFFFFF8'): void {
+ function calculate (hashHex: string, callback: (nonce: string | PromiseLike<string>) => any, progressCallback?: (frames: number) => any, threshold: number | string = '0xFFFFFFF8'): void {
if (typeof threshold === 'number') threshold = '0x' + threshold.toString(16)
const canvas = new OffscreenCanvas(webglWidth, webglHeight)
}`
const vertexShader = gl.createShader(gl.VERTEX_SHADER)
+ if (vertexShader == null)
+ throw 'error creating vertex shader'
gl.shaderSource(vertexShader, vsSource)
gl.compileShader(vertexShader)
throw gl.getShaderInfoLog(vertexShader)
const fragmentShader = gl.createShader(gl.FRAGMENT_SHADER)
+ if (fragmentShader == null)
+ throw 'error creating fragment shader'
gl.shaderSource(fragmentShader, fsSource)
gl.compileShader(fragmentShader)
throw gl.getShaderInfoLog(fragmentShader)
const program = gl.createProgram()
+ if (program == null)
+ throw 'error creating program'
gl.attachShader(program, vertexShader)
gl.attachShader(program, fragmentShader)
gl.linkProgram(program)
const work1 = new Uint8Array(4)
let n = 0
- function draw () {
+ const draw = (): void => {
n++
crypto.getRandomValues(work0)
crypto.getRandomValues(work1)
if (pixels[i] !== 0) {
// Return the work value with the custom bits
typeof callback === 'function' &&
- callback(
- hexify(work1) +
- hexify([
- pixels[i + 2],
- pixels[i + 3],
- work0[2] ^ (pixels[i] - 1),
- work0[3] ^ (pixels[i + 1] - 1)
- ]), n)
+ callback(hexify(work1) + hexify([
+ pixels[i + 2],
+ pixels[i + 3],
+ work0[2] ^ (pixels[i] - 1),
+ work0[3] ^ (pixels[i + 1] - 1)
+ ]))
return
}
}