]> zoso.dev Git - nano-pow.git/commitdiff
Merge branch 'main' into next/recover-execution
authorChris Duncan <chris@zoso.dev>
Fri, 28 Mar 2025 03:31:09 +0000 (20:31 -0700)
committerChris Duncan <chris@zoso.dev>
Fri, 28 Mar 2025 03:31:09 +0000 (20:31 -0700)
1  2 
package.json
src/lib/gl/index.ts
src/types.d.ts

diff --cc package.json
Simple merge
index ed39a9ed86be0ac2a26b138be45ca5e0c10e60bb,0c90c2d5b5ec3833cefe6659eb800ce8a16186bc..fca8265e511d94487366784eac93dbc0fcecbc1a
@@@ -14,8 -14,8 +14,9 @@@ export class NanoPowGl 
        static #SEND: bigint = 0xfffffff800000000n
        static #RECEIVE: bigint = 0xfffffe0000000000n
  
+       static #isInitialized: boolean = false
        static #busy: boolean = false
 +      static #call: NanoPowExecution | null = null
        static #debug: boolean = false
        static #raf: number = 0
        /** Used to set canvas size. */
                                }, 100)
                        })
                }
+               if (this.#isInitialized === false) this.init()
                this.#busy = true
-               this.#call ??= {
++              this.#call = {
 +                      method: 'work_generate',
 +                      hash,
 +                      options
 +              }
  
-               /** Process user input */
-               if (!/^[A-Fa-f0-9]{64}$/.test(hash)) throw new Error(`Invalid hash ${hash}`)
+               if (typeof options?.threshold === 'string') {
+                       try {
+                               options.threshold = BigInt(`0x${options.threshold}`)
+                       } catch (err) {
+                               throw new TypeError(`Invalid threshold ${options.threshold}`)
+                       }
+               }
                const threshold = (typeof options?.threshold !== 'bigint' || options.threshold < 1n || options.threshold > 0xffffffffffffffffn)
                        ? 0xfffffff800000000n
                        : options.threshold
                                }, 100)
                        })
                }
+               if (this.#isInitialized === false) this.init()
                this.#busy = true
++              this.#call = {
++                      method: 'work_validate',
++                      hash,
++                      options
++              }
  
-               /** Process user input */
-               if (!/^[A-Fa-f0-9]{16}$/.test(work)) throw new Error(`Invalid work ${work}`)
-               if (!/^[A-Fa-f0-9]{64}$/.test(hash)) throw new Error(`Invalid hash ${hash}`)
+               if (typeof options?.threshold === 'string') {
+                       try {
+                               options.threshold = BigInt(`0x${options.threshold}`)
+                       } catch (err) {
+                               throw new TypeError(`Invalid threshold ${options.threshold}`)
+                       }
+               }
                const threshold = (typeof options?.threshold !== 'bigint' || options.threshold < 1n || options.threshold > 0xffffffffffffffffn)
                        ? 0xfffffff800000000n
                        : options.threshold
diff --cc src/types.d.ts
Simple merge