From f58ac1f58a7c548e64d3ec54fd23126343908206 Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Sat, 25 Jul 2026 00:18:34 -0700 Subject: [PATCH] Define single execution sequence in separate function. --- index.html | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/index.html b/index.html index 2973394..d88bfc6 100644 --- a/index.html +++ b/index.html @@ -45,7 +45,7 @@ SPDX-License-Identifier: GPL-3.0-or-later function random (length = 32) { const bytes = crypto.getRandomValues(new Uint8Array(length)) return [...bytes].map(b => b.toString(16).padStart(2, '0')).join('') - } + } function average(times, type, effort) { const averages = stats(times) @@ -59,6 +59,24 @@ SPDX-License-Identifier: GPL-3.0-or-later } } + async function sequenceGenerateValidate (hash, api, debug, difficulty, effort) { + logger.isEnabled = debug + let start = 0, end = 0, work = null, valid = false + + start = performance.now() + work = (await NanoPow.work_generate(hash, {api, debug, difficulty, effort})).work + valid = (await NanoPow.work_validate(work, hash, {api, debug, difficulty, effort})).valid + end = performance.now() + + if (!valid) { + throw new Error(`invalid result\nblock hash: ${hash}\nwork: ${work}`) + } + if (!start || !end || start > end) { + throw new Error(`invalid timing\nstart: ${start}\nend: ${end}`) + } + return end - start + } + async function run(size, difficulty, effort, api, isOutputShown, isDebug, isSelfCheck) { logger.isEnabled = isDebug // Generate once on load to compile shaders and initialize buffers -- 2.52.0