]> git.codecow.com Git - nano-pow.git/commitdiff
Fix WASM handling of small bigints.
authorChris Duncan <chris@codecow.com>
Fri, 10 Jul 2026 15:03:55 +0000 (08:03 -0700)
committerChris Duncan <chris@codecow.com>
Fri, 10 Jul 2026 15:03:55 +0000 (08:03 -0700)
src/lib/generate/wasm/index.ts

index 6817bb5009af25fce8653c36c49ab014970d1b29..a08f7173aea0a13e5bcceadc5fcf099c6b273722 100644 (file)
@@ -38,8 +38,8 @@ function reset (): void {
 }
 
 async function init (hash: bigint, difficulty: bigint, effort: number): Promise<void> {
-       data.hash = bigHex(hash)
-       data.difficulty = bigHex(difficulty)
+       data.hash = bigHex(hash, 64)
+       data.difficulty = bigHex(difficulty, 16)
 
        for (let i = workers.length; i < effort; i++) {
                workers.push(new Worker(url, { type: 'module' }))
@@ -79,14 +79,14 @@ async function dispatch (): Promise<bigint> {
                const seed = crypto.getRandomValues(new BigUint64Array(workers.length))
                const attempts = []
                for (let i = 0; i < workers.length; i++) {
-                       data.seed = bigHex(seed[i])
+                       data.seed = bigHex(seed[i], 16)
                        attempts.push(new Promise((found, err) => {
                                const w = workers[i]
                                w.onerror = err
                                w.onmessage = (msg) => {
                                        const { data } = msg
                                        if (data.url === url) {
-                                               LOG: logger.log(`received result ${data.result} from worker ${i}`)
+                                               LOG: logger.log(`received result ${typeof data.result} "${data.result}" from worker ${i}`)
                                                found(data.result)
                                        }
                                }