nano-pow 4.0.4 → 4.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/bin/cli.js CHANGED
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  //! SPDX-FileCopyrightText: 2025 Chris Duncan <chris@zoso.dev>
3
3
  //! SPDX-License-Identifier: GPL-3.0-or-later
4
+ import * as crypto from "node:crypto";
4
5
  import * as fs from "node:fs/promises";
5
6
  import * as readline from "node:readline/promises";
6
7
  import * as puppeteer from "puppeteer";
@@ -93,8 +94,9 @@ if (hashes.length === 0) {
93
94
  ]
94
95
  });
95
96
  const page = await browser.newPage();
96
- const cliPage = `${import.meta.dirname}/cli.html`;
97
- await fs.writeFile(cliPage, "");
97
+ const path = new URL(import.meta.url).pathname;
98
+ const dir = path.slice(0, path.lastIndexOf("/"));
99
+ await fs.writeFile(`${dir}/cli.html`, "");
98
100
  await page.goto(import.meta.resolve("./cli.html"));
99
101
  await page.waitForFunction(async () => {
100
102
  return await navigator.gpu.requestAdapter();
@@ -154,6 +156,6 @@ if (hashes.length === 0) {
154
156
  </head>
155
157
  </html>
156
158
  `);
157
- await fs.unlink(cliPage);
159
+ await fs.unlink(`${dir}/cli.html`);
158
160
  if (options["debug"]) console.log("Puppeteer initialized");
159
161
  })();
package/dist/main.min.js CHANGED
@@ -43,6 +43,7 @@ layout(location=0)in vec4 position;void main(){gl_Position=position;}`;
43
43
  var NanoPowGl = class _NanoPowGl {
44
44
  static #SEND = 0xfffffff800000000n;
45
45
  static #RECEIVE = 0xfffffe0000000000n;
46
+ static #isInitialized = false;
46
47
  static #busy = false;
47
48
  static #debug = false;
48
49
  static #raf = 0;
@@ -187,12 +188,13 @@ var NanoPowGl = class _NanoPowGl {
187
188
  this.#gl.bindBuffer(this.#gl.UNIFORM_BUFFER, null);
188
189
  this.#query = this.#gl.createQuery();
189
190
  this.#pixels = new Uint32Array(this.size * 4);
190
- console.log(`NanoPow WebGL initialized at ${this.#gl.drawingBufferWidth}x${this.#gl.drawingBufferHeight}. Maximum nonces checked per frame: ${this.size}`);
191
191
  } catch (err) {
192
192
  throw new Error("WebGL initialization failed.", { cause: err });
193
193
  } finally {
194
194
  this.#busy = false;
195
195
  }
196
+ this.#isInitialized = true;
197
+ console.log(`NanoPow WebGL initialized at ${this.#gl.drawingBufferWidth}x${this.#gl.drawingBufferHeight}. Maximum nonces checked per frame: ${this.size}`);
196
198
  }
197
199
  /**
198
200
  * On WebGL context loss, attempts to clear all program variables and then
@@ -358,6 +360,7 @@ var NanoPowGl = class _NanoPowGl {
358
360
  }, 100);
359
361
  });
360
362
  }
363
+ if (this.#isInitialized === false) this.init();
361
364
  this.#busy = true;
362
365
  if (typeof options?.threshold === "string") {
363
366
  try {
@@ -442,6 +445,7 @@ var NanoPowGl = class _NanoPowGl {
442
445
  }, 100);
443
446
  });
444
447
  }
448
+ if (this.#isInitialized === false) this.init();
445
449
  this.#busy = true;
446
450
  if (typeof options?.threshold === "string") {
447
451
  try {
@@ -514,6 +518,7 @@ var NanoPowGpu = class _NanoPowGpu {
514
518
  static #SEND = 0xfffffff800000000n;
515
519
  static #RECEIVE = 0xfffffe0000000000n;
516
520
  // Initialize WebGPU
521
+ static #isInitialized = false;
517
522
  static #busy = false;
518
523
  static #debug = false;
519
524
  static #device = null;
@@ -543,6 +548,7 @@ var NanoPowGpu = class _NanoPowGpu {
543
548
  } finally {
544
549
  this.#busy = false;
545
550
  }
551
+ this.#isInitialized = true;
546
552
  }
547
553
  static setup() {
548
554
  if (this.#device == null) throw new Error(`WebGPU device failed to load.`);
@@ -704,6 +710,7 @@ var NanoPowGpu = class _NanoPowGpu {
704
710
  }, 100);
705
711
  });
706
712
  }
713
+ if (this.#isInitialized === false) this.init();
707
714
  this.#busy = true;
708
715
  if (typeof options?.threshold === "string") {
709
716
  try {
@@ -773,6 +780,7 @@ var NanoPowGpu = class _NanoPowGpu {
773
780
  }, 100);
774
781
  });
775
782
  }
783
+ if (this.#isInitialized === false) this.init();
776
784
  this.#busy = true;
777
785
  if (typeof options?.threshold === "string") {
778
786
  try {
@@ -824,15 +832,15 @@ var NanoPowGpu = class _NanoPowGpu {
824
832
  var isGlSupported;
825
833
  var isGpuSupported = false;
826
834
  try {
827
- await NanoPowGpu.init();
828
- isGpuSupported = true;
835
+ const adapter = await navigator?.gpu?.requestAdapter?.();
836
+ isGpuSupported = adapter instanceof GPUAdapter;
829
837
  } catch (err) {
830
838
  console.warn("WebGPU is not supported in this environment.\n", err);
831
839
  isGpuSupported = false;
832
840
  }
833
841
  try {
834
- await NanoPowGl.init();
835
- isGlSupported = true;
842
+ const gl = new OffscreenCanvas(0, 0)?.getContext?.("webgl2");
843
+ isGlSupported = gl instanceof WebGL2RenderingContext;
836
844
  } catch (err) {
837
845
  console.warn("WebGL is not supported in this environment.\n", err);
838
846
  isGlSupported = false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nano-pow",
3
- "version": "4.0.4",
3
+ "version": "4.0.6",
4
4
  "description": "Proof-of-work generation and validation with WebGPU/WebGL for Nano cryptocurrency.",
5
5
  "keywords": [
6
6
  "nemo",
@@ -46,8 +46,9 @@
46
46
  },
47
47
  "scripts": {
48
48
  "build": "rm -rf {dist,types} && tsc && node esbuild.mjs && cp -p src/bin/nano-pow.sh dist/bin",
49
+ "prepare": "npm run build",
49
50
  "start": "./dist/bin/nano-pow.sh --server",
50
- "test": "./test/script.sh"
51
+ "test": "npm run build && ./test/script.sh"
51
52
  },
52
53
  "devDependencies": {
53
54
  "@types/node": "^22.13.11",