nano-pow 5.1.5 → 5.1.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
@@ -132,10 +132,70 @@ Object.defineProperty(webgpu, "isSupported", {
132
132
  // src/utils/bigint.ts
133
133
  //! SPDX-FileCopyrightText: 2025 Chris Duncan <chris@zoso.dev>
134
134
  //! SPDX-License-Identifier: GPL-3.0-or-later
135
+ function bigintFrom(value, type) {
136
+ if (typeof value === "bigint") {
137
+ return value;
138
+ } else if (typeof value === "boolean" || typeof value === "number") {
139
+ return BigInt(value);
140
+ } else if (typeof value === "string") {
141
+ const v = value.trim().replace(/n$/, "");
142
+ if (/^0[Bb][01]+$/.test(v) || /^0[Oo][0-7]+$/.test(v) || /^0[Xx][A-Fa-f\d]+$/.test(v) || /^\d+$/.test(v)) {
143
+ return BigInt(v);
144
+ }
145
+ if (type === "bin" && /^[01]+$/.test(v)) {
146
+ return BigInt(`0b${v}`);
147
+ }
148
+ if (type === "oct" && /^[0-7]+$/.test(v)) {
149
+ return BigInt(`0o${v}`);
150
+ }
151
+ if (type === "hex" || /^\d*[A-Fa-f]+\d*$/.test(v)) {
152
+ return BigInt(`0x${v}`);
153
+ }
154
+ }
155
+ throw new TypeError(`can't convert string to BigInt`);
156
+ }
135
157
 
136
158
  // src/utils/cache.ts
137
159
  //! SPDX-FileCopyrightText: 2025 Chris Duncan <chris@zoso.dev>
138
160
  //! SPDX-License-Identifier: GPL-3.0-or-later
161
+ var Cache = class {
162
+ static clear() {
163
+ this.#removeItem("NanoPowCache");
164
+ }
165
+ static search(hash, difficulty) {
166
+ const bigintHash = bigintFrom(hash, "hex");
167
+ const item = this.#getItem("NanoPowCache");
168
+ if (item) {
169
+ const cache = JSON.parse(item);
170
+ for (const c of cache) {
171
+ if (bigintFrom(c.hash, "hex") === bigintHash && bigintFrom(c.difficulty, "hex") >= difficulty) {
172
+ return c;
173
+ }
174
+ }
175
+ }
176
+ return null;
177
+ }
178
+ static store(result) {
179
+ const item = this.#getItem("NanoPowCache");
180
+ const cache = JSON.parse(item ?? "[]");
181
+ if (cache.push(result) > 1e3) cache.shift();
182
+ this.#setItem("NanoPowCache", JSON.stringify(cache));
183
+ return result;
184
+ }
185
+ static #storage = {};
186
+ static #getItem(key) {
187
+ if (globalThis?.localStorage) return globalThis.localStorage.getItem(key);
188
+ return this.#storage[key];
189
+ }
190
+ static #removeItem(key) {
191
+ if (globalThis?.localStorage) return globalThis.localStorage.removeItem(key);
192
+ this.#storage = {};
193
+ }
194
+ static #setItem(key, item) {
195
+ if (globalThis?.localStorage) return globalThis.localStorage.setItem(key, item);
196
+ this.#storage[key] = item;
197
+ }
198
+ };
139
199
 
140
200
  // src/utils/logger.ts
141
201
  //! SPDX-FileCopyrightText: 2025 Chris Duncan <chris@zoso.dev>
@@ -184,6 +244,7 @@ var Logger = class {
184
244
  // src/utils/index.ts
185
245
  //! SPDX-FileCopyrightText: 2025 Chris Duncan <chris@zoso.dev>
186
246
  //! SPDX-License-Identifier: GPL-3.0-or-later
247
+ var clearCache = Cache.clear;
187
248
  function isHexN(value, byteLength) {
188
249
  if (typeof value !== "string") return false;
189
250
  const v = value.replace(/^0[Xx]/, "");
@@ -135,10 +135,70 @@ Object.defineProperty(webgpu, "isSupported", {
135
135
  // src/utils/bigint.ts
136
136
  //! SPDX-FileCopyrightText: 2025 Chris Duncan <chris@zoso.dev>
137
137
  //! SPDX-License-Identifier: GPL-3.0-or-later
138
+ function bigintFrom(value, type) {
139
+ if (typeof value === "bigint") {
140
+ return value;
141
+ } else if (typeof value === "boolean" || typeof value === "number") {
142
+ return BigInt(value);
143
+ } else if (typeof value === "string") {
144
+ const v = value.trim().replace(/n$/, "");
145
+ if (/^0[Bb][01]+$/.test(v) || /^0[Oo][0-7]+$/.test(v) || /^0[Xx][A-Fa-f\d]+$/.test(v) || /^\d+$/.test(v)) {
146
+ return BigInt(v);
147
+ }
148
+ if (type === "bin" && /^[01]+$/.test(v)) {
149
+ return BigInt(`0b${v}`);
150
+ }
151
+ if (type === "oct" && /^[0-7]+$/.test(v)) {
152
+ return BigInt(`0o${v}`);
153
+ }
154
+ if (type === "hex" || /^\d*[A-Fa-f]+\d*$/.test(v)) {
155
+ return BigInt(`0x${v}`);
156
+ }
157
+ }
158
+ throw new TypeError(`can't convert string to BigInt`);
159
+ }
138
160
 
139
161
  // src/utils/cache.ts
140
162
  //! SPDX-FileCopyrightText: 2025 Chris Duncan <chris@zoso.dev>
141
163
  //! SPDX-License-Identifier: GPL-3.0-or-later
164
+ var Cache = class {
165
+ static clear() {
166
+ this.#removeItem("NanoPowCache");
167
+ }
168
+ static search(hash2, difficulty) {
169
+ const bigintHash = bigintFrom(hash2, "hex");
170
+ const item = this.#getItem("NanoPowCache");
171
+ if (item) {
172
+ const cache = JSON.parse(item);
173
+ for (const c of cache) {
174
+ if (bigintFrom(c.hash, "hex") === bigintHash && bigintFrom(c.difficulty, "hex") >= difficulty) {
175
+ return c;
176
+ }
177
+ }
178
+ }
179
+ return null;
180
+ }
181
+ static store(result) {
182
+ const item = this.#getItem("NanoPowCache");
183
+ const cache = JSON.parse(item ?? "[]");
184
+ if (cache.push(result) > 1e3) cache.shift();
185
+ this.#setItem("NanoPowCache", JSON.stringify(cache));
186
+ return result;
187
+ }
188
+ static #storage = {};
189
+ static #getItem(key) {
190
+ if (globalThis?.localStorage) return globalThis.localStorage.getItem(key);
191
+ return this.#storage[key];
192
+ }
193
+ static #removeItem(key) {
194
+ if (globalThis?.localStorage) return globalThis.localStorage.removeItem(key);
195
+ this.#storage = {};
196
+ }
197
+ static #setItem(key, item) {
198
+ if (globalThis?.localStorage) return globalThis.localStorage.setItem(key, item);
199
+ this.#storage[key] = item;
200
+ }
201
+ };
142
202
 
143
203
  // src/utils/logger.ts
144
204
  //! SPDX-FileCopyrightText: 2025 Chris Duncan <chris@zoso.dev>
@@ -187,6 +247,7 @@ var Logger = class {
187
247
  // src/utils/index.ts
188
248
  //! SPDX-FileCopyrightText: 2025 Chris Duncan <chris@zoso.dev>
189
249
  //! SPDX-License-Identifier: GPL-3.0-or-later
250
+ var clearCache = Cache.clear;
190
251
  function isHexN(value, byteLength) {
191
252
  if (typeof value !== "string") return false;
192
253
  const v = value.replace(/^0[Xx]/, "");
package/dist/main.min.js CHANGED
@@ -228,14 +228,8 @@ function bigintToHex(int, length = 0) {
228
228
  //! SPDX-FileCopyrightText: 2025 Chris Duncan <chris@zoso.dev>
229
229
  //! SPDX-License-Identifier: GPL-3.0-or-later
230
230
  var Cache = class {
231
- static #storage = {};
232
- static #getItem(key) {
233
- if (globalThis?.localStorage) return globalThis.localStorage.getItem(key);
234
- return this.#storage[key];
235
- }
236
- static #setItem(key, item) {
237
- if (globalThis?.localStorage) return globalThis.localStorage.setItem(key, item);
238
- this.#storage[key] = item;
231
+ static clear() {
232
+ this.#removeItem("NanoPowCache");
239
233
  }
240
234
  static search(hash, difficulty) {
241
235
  const bigintHash = bigintFrom(hash, "hex");
@@ -257,6 +251,19 @@ var Cache = class {
257
251
  this.#setItem("NanoPowCache", JSON.stringify(cache));
258
252
  return result2;
259
253
  }
254
+ static #storage = {};
255
+ static #getItem(key) {
256
+ if (globalThis?.localStorage) return globalThis.localStorage.getItem(key);
257
+ return this.#storage[key];
258
+ }
259
+ static #removeItem(key) {
260
+ if (globalThis?.localStorage) return globalThis.localStorage.removeItem(key);
261
+ this.#storage = {};
262
+ }
263
+ static #setItem(key, item) {
264
+ if (globalThis?.localStorage) return globalThis.localStorage.setItem(key, item);
265
+ this.#storage[key] = item;
266
+ }
260
267
  };
261
268
 
262
269
  // src/utils/logger.ts
@@ -334,6 +341,7 @@ var Queue = class {
334
341
  // src/utils/index.ts
335
342
  //! SPDX-FileCopyrightText: 2025 Chris Duncan <chris@zoso.dev>
336
343
  //! SPDX-License-Identifier: GPL-3.0-or-later
344
+ var clearCache = Cache.clear;
337
345
  var SEND = 0xfffffff800000000n;
338
346
  var RECEIVE = 0xfffffe0000000000n;
339
347
  function stats(times) {
@@ -1573,6 +1581,7 @@ var NanoPow = class {
1573
1581
  };
1574
1582
  export {
1575
1583
  NanoPow,
1584
+ clearCache,
1576
1585
  NanoPow as default,
1577
1586
  stats
1578
1587
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nano-pow",
3
- "version": "5.1.5",
3
+ "version": "5.1.6",
4
4
  "description": "Proof-of-work generation and validation with WebGPU/WebGL/WASM for Nano cryptocurrency.",
5
5
  "keywords": [
6
6
  "nemo",
@@ -60,7 +60,7 @@
60
60
  "typescript": "^5.9.2"
61
61
  },
62
62
  "optionalDependencies": {
63
- "puppeteer": "^24.16.2"
63
+ "puppeteer": "^24.17.0"
64
64
  },
65
65
  "type": "module",
66
66
  "exports": {