nano-rspow-web 0.5.0 → 0.5.7

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/README.md CHANGED
@@ -49,7 +49,11 @@ Synchronously validates whether a nonce meets the difficulty threshold for the g
49
49
 
50
50
  ---
51
51
 
52
- ## See Also
52
+ ## Browser Compatibility
53
+
54
+ WebGPU works correctly in all major browsers including Chrome, Brave, Edge, and Safari.
55
+
56
+
53
57
 
54
58
  - **[nano-rspow-node](https://www.npmjs.com/package/nano-rspow-node)**: High-performance pre-compiled Node.js bindings for backend servers.
55
59
  - **[nano-rspow Workspace](https://github.com/CasualSecurityInc/nano-rspow)**: The monorepo source code containing both packages.
@@ -9,6 +9,17 @@ export class GenerateResult {
9
9
  readonly nonce: string;
10
10
  }
11
11
 
12
+ /**
13
+ * A cancellation handle that can be passed to `generate_work_gpu` and
14
+ * called from JavaScript to stop the GPU batch loop.
15
+ */
16
+ export class WasmCancelToken {
17
+ free(): void;
18
+ [Symbol.dispose](): void;
19
+ cancel(): void;
20
+ constructor();
21
+ }
22
+
12
23
  /**
13
24
  * Asynchronously generate Proof of Work for a 32-byte block hash (hex).
14
25
  *
@@ -23,8 +34,11 @@ export function generate_work_cpu(hash_hex: string, threshold_hex: string): Gene
23
34
 
24
35
  /**
25
36
  * Asynchronously generate Proof of Work forcing WebGPU execution.
37
+ *
38
+ * Pass a `WasmCancelToken` created via `new WasmCancelToken()` and call
39
+ * `.cancel()` on it from JavaScript to abort the GPU batch loop (e.g. on timeout).
26
40
  */
27
- export function generate_work_gpu(hash_hex: string, threshold_hex: string): Promise<GenerateResult>;
41
+ export function generate_work_gpu(hash_hex: string, threshold_hex: string, cancel_token: WasmCancelToken): Promise<GenerateResult>;
28
42
 
29
43
  /**
30
44
  * Synchronously validate if a nonce meets the difficulty threshold for a given block hash.
@@ -36,15 +50,18 @@ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembl
36
50
  export interface InitOutput {
37
51
  readonly memory: WebAssembly.Memory;
38
52
  readonly __wbg_generateresult_free: (a: number, b: number) => void;
53
+ readonly __wbg_wasmcanceltoken_free: (a: number, b: number) => void;
39
54
  readonly generate_work: (a: number, b: number, c: number, d: number) => any;
40
55
  readonly generate_work_cpu: (a: number, b: number, c: number, d: number) => [number, number, number];
41
- readonly generate_work_gpu: (a: number, b: number, c: number, d: number) => any;
56
+ readonly generate_work_gpu: (a: number, b: number, c: number, d: number, e: number) => any;
42
57
  readonly generateresult_is_gpu: (a: number) => number;
43
58
  readonly generateresult_nonce: (a: number) => [number, number];
44
59
  readonly validate_work: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number];
45
- readonly wasm_bindgen__convert__closures_____invoke__h494390435fc5ceaa: (a: number, b: number, c: any) => [number, number];
46
- readonly wasm_bindgen__convert__closures_____invoke__h08e8530b2c1a3586: (a: number, b: number, c: any, d: any) => void;
47
- readonly wasm_bindgen__convert__closures_____invoke__h01517a4dd6c2751e: (a: number, b: number, c: any) => void;
60
+ readonly wasmcanceltoken_cancel: (a: number) => void;
61
+ readonly wasmcanceltoken_new: () => number;
62
+ readonly wasm_bindgen__convert__closures_____invoke__h58e4f4265216b47b: (a: number, b: number, c: any) => [number, number];
63
+ readonly wasm_bindgen__convert__closures_____invoke__h01bd443bd6c87491: (a: number, b: number, c: any, d: any) => void;
64
+ readonly wasm_bindgen__convert__closures_____invoke__h15c04ebc453d8f26: (a: number, b: number, c: any) => void;
48
65
  readonly __wbindgen_malloc: (a: number, b: number) => number;
49
66
  readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
50
67
  readonly __wbindgen_exn_store: (a: number) => void;
package/nano_rspow_web.js CHANGED
@@ -42,6 +42,33 @@ export class GenerateResult {
42
42
  }
43
43
  if (Symbol.dispose) GenerateResult.prototype[Symbol.dispose] = GenerateResult.prototype.free;
44
44
 
45
+ /**
46
+ * A cancellation handle that can be passed to `generate_work_gpu` and
47
+ * called from JavaScript to stop the GPU batch loop.
48
+ */
49
+ export class WasmCancelToken {
50
+ __destroy_into_raw() {
51
+ const ptr = this.__wbg_ptr;
52
+ this.__wbg_ptr = 0;
53
+ WasmCancelTokenFinalization.unregister(this);
54
+ return ptr;
55
+ }
56
+ free() {
57
+ const ptr = this.__destroy_into_raw();
58
+ wasm.__wbg_wasmcanceltoken_free(ptr, 0);
59
+ }
60
+ cancel() {
61
+ wasm.wasmcanceltoken_cancel(this.__wbg_ptr);
62
+ }
63
+ constructor() {
64
+ const ret = wasm.wasmcanceltoken_new();
65
+ this.__wbg_ptr = ret;
66
+ WasmCancelTokenFinalization.register(this, this.__wbg_ptr, this);
67
+ return this;
68
+ }
69
+ }
70
+ if (Symbol.dispose) WasmCancelToken.prototype[Symbol.dispose] = WasmCancelToken.prototype.free;
71
+
45
72
  /**
46
73
  * Asynchronously generate Proof of Work for a 32-byte block hash (hex).
47
74
  *
@@ -79,16 +106,21 @@ export function generate_work_cpu(hash_hex, threshold_hex) {
79
106
 
80
107
  /**
81
108
  * Asynchronously generate Proof of Work forcing WebGPU execution.
109
+ *
110
+ * Pass a `WasmCancelToken` created via `new WasmCancelToken()` and call
111
+ * `.cancel()` on it from JavaScript to abort the GPU batch loop (e.g. on timeout).
82
112
  * @param {string} hash_hex
83
113
  * @param {string} threshold_hex
114
+ * @param {WasmCancelToken} cancel_token
84
115
  * @returns {Promise<GenerateResult>}
85
116
  */
86
- export function generate_work_gpu(hash_hex, threshold_hex) {
117
+ export function generate_work_gpu(hash_hex, threshold_hex, cancel_token) {
87
118
  const ptr0 = passStringToWasm0(hash_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
88
119
  const len0 = WASM_VECTOR_LEN;
89
120
  const ptr1 = passStringToWasm0(threshold_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
90
121
  const len1 = WASM_VECTOR_LEN;
91
- const ret = wasm.generate_work_gpu(ptr0, len0, ptr1, len1);
122
+ _assertClass(cancel_token, WasmCancelToken);
123
+ const ret = wasm.generate_work_gpu(ptr0, len0, ptr1, len1, cancel_token.__wbg_ptr);
92
124
  return ret;
93
125
  }
94
126
 
@@ -152,10 +184,20 @@ function __wbg_get_imports() {
152
184
  const ret = arg0.beginComputePass(arg1);
153
185
  return ret;
154
186
  },
187
+ __wbg_call_13665d9f14390edc: function() { return handleError(function (arg0, arg1) {
188
+ const ret = arg0.call(arg1);
189
+ return ret;
190
+ }, arguments); },
155
191
  __wbg_call_dfde26266607c996: function() { return handleError(function (arg0, arg1, arg2) {
156
192
  const ret = arg0.call(arg1, arg2);
157
193
  return ret;
158
194
  }, arguments); },
195
+ __wbg_clearBuffer_1a66bf0852937316: function(arg0, arg1, arg2) {
196
+ arg0.clearBuffer(arg1, arg2);
197
+ },
198
+ __wbg_clearBuffer_8b28969d396ae40b: function(arg0, arg1, arg2, arg3) {
199
+ arg0.clearBuffer(arg1, arg2, arg3);
200
+ },
159
201
  __wbg_copyBufferToBuffer_3b119149df2dc5eb: function() { return handleError(function (arg0, arg1, arg2, arg3, arg4) {
160
202
  arg0.copyBufferToBuffer(arg1, arg2, arg3, arg4);
161
203
  }, arguments); },
@@ -270,7 +312,7 @@ function __wbg_get_imports() {
270
312
  const a = state0.a;
271
313
  state0.a = 0;
272
314
  try {
273
- return wasm_bindgen__convert__closures_____invoke__h08e8530b2c1a3586(a, state0.b, arg0, arg1);
315
+ return wasm_bindgen__convert__closures_____invoke__h01bd443bd6c87491(a, state0.b, arg0, arg1);
274
316
  } finally {
275
317
  state0.a = a;
276
318
  }
@@ -288,7 +330,7 @@ function __wbg_get_imports() {
288
330
  const a = state0.a;
289
331
  state0.a = 0;
290
332
  try {
291
- return wasm_bindgen__convert__closures_____invoke__h08e8530b2c1a3586(a, state0.b, arg0, arg1);
333
+ return wasm_bindgen__convert__closures_____invoke__h01bd443bd6c87491(a, state0.b, arg0, arg1);
292
334
  } finally {
293
335
  state0.a = a;
294
336
  }
@@ -346,10 +388,6 @@ function __wbg_get_imports() {
346
388
  __wbg_setPipeline_c6aca1c13ec27120: function(arg0, arg1) {
347
389
  arg0.setPipeline(arg1);
348
390
  },
349
- __wbg_setTimeout_1bc1140eb7b08d02: function(arg0, arg1) {
350
- const ret = setTimeout(arg0, arg1);
351
- return ret;
352
- },
353
391
  __wbg_set_37221b90dcdc9a98: function(arg0, arg1, arg2) {
354
392
  arg0.set(arg1, arg2 >>> 0);
355
393
  },
@@ -548,13 +586,13 @@ function __wbg_get_imports() {
548
586
  arg0.writeBuffer(arg1, arg2, getArrayU8FromWasm0(arg3, arg4), arg5, arg6);
549
587
  }, arguments); },
550
588
  __wbindgen_cast_0000000000000001: function(arg0, arg1) {
551
- // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 100, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
552
- const ret = makeMutClosure(arg0, arg1, wasm_bindgen__convert__closures_____invoke__h494390435fc5ceaa);
589
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 63, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
590
+ const ret = makeMutClosure(arg0, arg1, wasm_bindgen__convert__closures_____invoke__h15c04ebc453d8f26);
553
591
  return ret;
554
592
  },
555
593
  __wbindgen_cast_0000000000000002: function(arg0, arg1) {
556
- // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 66, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
557
- const ret = makeMutClosure(arg0, arg1, wasm_bindgen__convert__closures_____invoke__h01517a4dd6c2751e);
594
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 98, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
595
+ const ret = makeMutClosure(arg0, arg1, wasm_bindgen__convert__closures_____invoke__h58e4f4265216b47b);
558
596
  return ret;
559
597
  },
560
598
  __wbindgen_cast_0000000000000003: function(arg0) {
@@ -588,19 +626,19 @@ function __wbg_get_imports() {
588
626
  };
589
627
  }
590
628
 
591
- function wasm_bindgen__convert__closures_____invoke__h01517a4dd6c2751e(arg0, arg1, arg2) {
592
- wasm.wasm_bindgen__convert__closures_____invoke__h01517a4dd6c2751e(arg0, arg1, arg2);
629
+ function wasm_bindgen__convert__closures_____invoke__h15c04ebc453d8f26(arg0, arg1, arg2) {
630
+ wasm.wasm_bindgen__convert__closures_____invoke__h15c04ebc453d8f26(arg0, arg1, arg2);
593
631
  }
594
632
 
595
- function wasm_bindgen__convert__closures_____invoke__h494390435fc5ceaa(arg0, arg1, arg2) {
596
- const ret = wasm.wasm_bindgen__convert__closures_____invoke__h494390435fc5ceaa(arg0, arg1, arg2);
633
+ function wasm_bindgen__convert__closures_____invoke__h58e4f4265216b47b(arg0, arg1, arg2) {
634
+ const ret = wasm.wasm_bindgen__convert__closures_____invoke__h58e4f4265216b47b(arg0, arg1, arg2);
597
635
  if (ret[1]) {
598
636
  throw takeFromExternrefTable0(ret[0]);
599
637
  }
600
638
  }
601
639
 
602
- function wasm_bindgen__convert__closures_____invoke__h08e8530b2c1a3586(arg0, arg1, arg2, arg3) {
603
- wasm.wasm_bindgen__convert__closures_____invoke__h08e8530b2c1a3586(arg0, arg1, arg2, arg3);
640
+ function wasm_bindgen__convert__closures_____invoke__h01bd443bd6c87491(arg0, arg1, arg2, arg3) {
641
+ wasm.wasm_bindgen__convert__closures_____invoke__h01bd443bd6c87491(arg0, arg1, arg2, arg3);
604
642
  }
605
643
 
606
644
 
@@ -626,6 +664,9 @@ const __wbindgen_enum_GpuTextureViewDimension = ["1d", "2d", "2d-array", "cube",
626
664
  const GenerateResultFinalization = (typeof FinalizationRegistry === 'undefined')
627
665
  ? { register: () => {}, unregister: () => {} }
628
666
  : new FinalizationRegistry(ptr => wasm.__wbg_generateresult_free(ptr, 1));
667
+ const WasmCancelTokenFinalization = (typeof FinalizationRegistry === 'undefined')
668
+ ? { register: () => {}, unregister: () => {} }
669
+ : new FinalizationRegistry(ptr => wasm.__wbg_wasmcanceltoken_free(ptr, 1));
629
670
 
630
671
  function addToExternrefTable0(obj) {
631
672
  const idx = wasm.__externref_table_alloc();
@@ -633,6 +674,12 @@ function addToExternrefTable0(obj) {
633
674
  return idx;
634
675
  }
635
676
 
677
+ function _assertClass(instance, klass) {
678
+ if (!(instance instanceof klass)) {
679
+ throw new Error(`expected instance of ${klass.name}`);
680
+ }
681
+ }
682
+
636
683
  const CLOSURE_DTORS = (typeof FinalizationRegistry === 'undefined')
637
684
  ? { register: () => {}, unregister: () => {} }
638
685
  : new FinalizationRegistry(state => wasm.__wbindgen_destroy_closure(state.a, state.b));
Binary file
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "nano-rspow-web",
3
- "version": "0.5.0",
3
+ "version": "0.5.7",
4
4
  "description": "WebGPU-accelerated Nano (XNO) Proof of Work generation in the browser using WebAssembly",
5
5
  "repository": {
6
6
  "type": "git",
7
- "url": "https://github.com/CasualSecurityInc/nano-rspow"
7
+ "url": "git+https://github.com/CasualSecurityInc/nano-rspow.git"
8
8
  },
9
9
  "author": "Casual Security Inc. & Conny Brunnkvist <cbrunnkvist@gmail.com>",
10
10
  "main": "nano_rspow_web.js",