nano-rspow-web 0.13.1 → 0.17.0
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 +11 -4
- package/index.d.ts +3 -0
- package/index.js +3 -0
- package/nano_rspow_web.d.ts +9 -5
- package/nano_rspow_web.js +11 -7
- package/nano_rspow_web_bg.wasm +0 -0
- package/package.json +11 -3
- package/pow-engine.d.ts +4 -0
- package/pow-engine.js +18 -0
package/README.md
CHANGED
|
@@ -32,6 +32,13 @@ console.log("Is GPU:", result.is_gpu); // true/false
|
|
|
32
32
|
const isValid = validate_work(hash, result.nonce, threshold); // true
|
|
33
33
|
```
|
|
34
34
|
|
|
35
|
+
The threshold argument is always caller supplied. For current Nano mainnet,
|
|
36
|
+
use `fffffff800000000` for send/change blocks or `fffffe0000000000` for
|
|
37
|
+
receive/open/epoch blocks. Pass the stricter value required by the publishing
|
|
38
|
+
node when it differs. See Nano's
|
|
39
|
+
[Work Generation guide](https://docs.nano.org/integration-guides/work-generation/)
|
|
40
|
+
for current network requirements.
|
|
41
|
+
|
|
35
42
|
## Benchmarking Dashboard
|
|
36
43
|
|
|
37
44
|
<table>
|
|
@@ -66,20 +73,20 @@ Initializes the asynchronous WASM loader. Await this default export before calli
|
|
|
66
73
|
Initializes the module synchronously from bytes or a precompiled `WebAssembly.Module`. Use this only when the module bytes are already available.
|
|
67
74
|
|
|
68
75
|
### `generate_work(hash_hex: string, threshold_hex: string): Promise<GenerateResult>`
|
|
69
|
-
Asynchronously generates Proof of Work for a 32-byte block hash. Tries WebGPU first, falling back to CPU WebAssembly.
|
|
76
|
+
Asynchronously generates Proof of Work for a 32-byte block hash at any hexadecimal threshold. Tries WebGPU first, falling back to CPU WebAssembly.
|
|
70
77
|
|
|
71
78
|
### `generate_work_gpu(hash_hex: string, threshold_hex: string, cancel_token: WasmCancelToken): Promise<GenerateResult>`
|
|
72
|
-
Forces WebGPU PoW generation. Rejects if WebGPU is unavailable or if the cancellation token is triggered.
|
|
79
|
+
Forces WebGPU PoW generation at any hexadecimal threshold. Rejects if WebGPU is unavailable or if the cancellation token is triggered.
|
|
73
80
|
|
|
74
81
|
### `generate_work_cpu(hash_hex: string, threshold_hex: string): GenerateResult`
|
|
75
|
-
Synchronously generates PoW forcing single-threaded CPU WebAssembly.
|
|
82
|
+
Synchronously generates PoW at any hexadecimal threshold, forcing single-threaded CPU WebAssembly.
|
|
76
83
|
|
|
77
84
|
### `generate_work_cpu_batch(hash_hex: string, threshold_hex: string, max_nonces: number): string | null`
|
|
78
85
|
|
|
79
86
|
Tests at most `max_nonces` nonces synchronously on the CPU. Returns a lowercase 16-character nonce when found, otherwise `null`. The CPU random-number-generator state persists between calls. Pass an unsigned 32-bit integer.
|
|
80
87
|
|
|
81
88
|
### `validate_work(hash_hex: string, nonce_hex: string, threshold_hex: string): boolean`
|
|
82
|
-
Synchronously validates whether a nonce meets
|
|
89
|
+
Synchronously validates whether a nonce meets an arbitrary hexadecimal threshold for the given block hash.
|
|
83
90
|
|
|
84
91
|
### `WasmCancelToken`
|
|
85
92
|
A class utilized to signal cancellation to the asynchronous GPU solver loop.
|
package/index.d.ts
ADDED
package/index.js
ADDED
package/nano_rspow_web.d.ts
CHANGED
|
@@ -21,26 +21,30 @@ export class WasmCancelToken {
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
|
-
* Asynchronously generate Proof of Work for a 32-byte block hash
|
|
24
|
+
* Asynchronously generate Proof of Work for a 32-byte block hash and an
|
|
25
|
+
* arbitrary hexadecimal threshold.
|
|
25
26
|
*
|
|
26
27
|
* Tries WebGPU first, then falls back to single-threaded CPU WASM.
|
|
27
28
|
*/
|
|
28
29
|
export function generate_work(hash_hex: string, threshold_hex: string): Promise<GenerateResult>;
|
|
29
30
|
|
|
30
31
|
/**
|
|
31
|
-
* Synchronously generate Proof of Work
|
|
32
|
+
* Synchronously generate Proof of Work at an arbitrary threshold, forcing
|
|
33
|
+
* single-threaded WASM CPU execution.
|
|
32
34
|
*/
|
|
33
35
|
export function generate_work_cpu(hash_hex: string, threshold_hex: string): GenerateResult;
|
|
34
36
|
|
|
35
37
|
/**
|
|
36
|
-
* Try up to max_nonces nonces
|
|
38
|
+
* Try up to `max_nonces` nonces at an arbitrary hexadecimal threshold in a
|
|
39
|
+
* single synchronous batch.
|
|
37
40
|
* Returns the nonce as a hex string if found, or `null` if the batch
|
|
38
41
|
* was exhausted. RNG state persists across calls.
|
|
39
42
|
*/
|
|
40
43
|
export function generate_work_cpu_batch(hash_hex: string, threshold_hex: string, max_nonces: number): any;
|
|
41
44
|
|
|
42
45
|
/**
|
|
43
|
-
* Asynchronously generate Proof of Work
|
|
46
|
+
* Asynchronously generate Proof of Work at an arbitrary threshold, forcing
|
|
47
|
+
* WebGPU execution.
|
|
44
48
|
*
|
|
45
49
|
* Pass a `WasmCancelToken` created via `new WasmCancelToken()` and call
|
|
46
50
|
* `.cancel()` on it from JavaScript to abort the GPU batch loop (e.g. on timeout).
|
|
@@ -48,7 +52,7 @@ export function generate_work_cpu_batch(hash_hex: string, threshold_hex: string,
|
|
|
48
52
|
export function generate_work_gpu(hash_hex: string, threshold_hex: string, cancel_token: WasmCancelToken): Promise<GenerateResult>;
|
|
49
53
|
|
|
50
54
|
/**
|
|
51
|
-
* Synchronously validate
|
|
55
|
+
* Synchronously validate a nonce against an arbitrary threshold for a block hash.
|
|
52
56
|
*/
|
|
53
57
|
export function validate_work(hash_hex: string, nonce_hex: string, threshold_hex: string): boolean;
|
|
54
58
|
|
package/nano_rspow_web.js
CHANGED
|
@@ -70,7 +70,8 @@ export class WasmCancelToken {
|
|
|
70
70
|
if (Symbol.dispose) WasmCancelToken.prototype[Symbol.dispose] = WasmCancelToken.prototype.free;
|
|
71
71
|
|
|
72
72
|
/**
|
|
73
|
-
* Asynchronously generate Proof of Work for a 32-byte block hash
|
|
73
|
+
* Asynchronously generate Proof of Work for a 32-byte block hash and an
|
|
74
|
+
* arbitrary hexadecimal threshold.
|
|
74
75
|
*
|
|
75
76
|
* Tries WebGPU first, then falls back to single-threaded CPU WASM.
|
|
76
77
|
* @param {string} hash_hex
|
|
@@ -87,7 +88,8 @@ export function generate_work(hash_hex, threshold_hex) {
|
|
|
87
88
|
}
|
|
88
89
|
|
|
89
90
|
/**
|
|
90
|
-
* Synchronously generate Proof of Work
|
|
91
|
+
* Synchronously generate Proof of Work at an arbitrary threshold, forcing
|
|
92
|
+
* single-threaded WASM CPU execution.
|
|
91
93
|
* @param {string} hash_hex
|
|
92
94
|
* @param {string} threshold_hex
|
|
93
95
|
* @returns {GenerateResult}
|
|
@@ -105,7 +107,8 @@ export function generate_work_cpu(hash_hex, threshold_hex) {
|
|
|
105
107
|
}
|
|
106
108
|
|
|
107
109
|
/**
|
|
108
|
-
* Try up to max_nonces nonces
|
|
110
|
+
* Try up to `max_nonces` nonces at an arbitrary hexadecimal threshold in a
|
|
111
|
+
* single synchronous batch.
|
|
109
112
|
* Returns the nonce as a hex string if found, or `null` if the batch
|
|
110
113
|
* was exhausted. RNG state persists across calls.
|
|
111
114
|
* @param {string} hash_hex
|
|
@@ -126,7 +129,8 @@ export function generate_work_cpu_batch(hash_hex, threshold_hex, max_nonces) {
|
|
|
126
129
|
}
|
|
127
130
|
|
|
128
131
|
/**
|
|
129
|
-
* Asynchronously generate Proof of Work
|
|
132
|
+
* Asynchronously generate Proof of Work at an arbitrary threshold, forcing
|
|
133
|
+
* WebGPU execution.
|
|
130
134
|
*
|
|
131
135
|
* Pass a `WasmCancelToken` created via `new WasmCancelToken()` and call
|
|
132
136
|
* `.cancel()` on it from JavaScript to abort the GPU batch loop (e.g. on timeout).
|
|
@@ -146,7 +150,7 @@ export function generate_work_gpu(hash_hex, threshold_hex, cancel_token) {
|
|
|
146
150
|
}
|
|
147
151
|
|
|
148
152
|
/**
|
|
149
|
-
* Synchronously validate
|
|
153
|
+
* Synchronously validate a nonce against an arbitrary threshold for a block hash.
|
|
150
154
|
* @param {string} hash_hex
|
|
151
155
|
* @param {string} nonce_hex
|
|
152
156
|
* @param {string} threshold_hex
|
|
@@ -607,12 +611,12 @@ function __wbg_get_imports() {
|
|
|
607
611
|
arg0.writeBuffer(arg1, arg2, getArrayU8FromWasm0(arg3, arg4), arg5, arg6);
|
|
608
612
|
}, arguments); },
|
|
609
613
|
__wbindgen_cast_0000000000000001: function(arg0, arg1) {
|
|
610
|
-
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx:
|
|
614
|
+
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 64, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
|
|
611
615
|
const ret = makeMutClosure(arg0, arg1, wasm_bindgen_8b74beb86e9b2264___convert__closures_____invoke___wasm_bindgen_8b74beb86e9b2264___JsValue______true_);
|
|
612
616
|
return ret;
|
|
613
617
|
},
|
|
614
618
|
__wbindgen_cast_0000000000000002: function(arg0, arg1) {
|
|
615
|
-
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx:
|
|
619
|
+
// 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`.
|
|
616
620
|
const ret = makeMutClosure(arg0, arg1, wasm_bindgen_8b74beb86e9b2264___convert__closures_____invoke___wasm_bindgen_8b74beb86e9b2264___JsValue__core_f0fd674eaa06beef___result__Result_____wasm_bindgen_8b74beb86e9b2264___JsError___true_);
|
|
617
621
|
return ret;
|
|
618
622
|
},
|
package/nano_rspow_web_bg.wasm
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nano-rspow-web",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.0",
|
|
4
|
+
"type": "module",
|
|
4
5
|
"description": "WebGPU-accelerated Nano (XNO) Proof of Work generation in the browser using WebAssembly",
|
|
5
6
|
"keywords": [
|
|
6
7
|
"nano",
|
|
@@ -18,15 +19,22 @@
|
|
|
18
19
|
"directory": "nano-rspow-web"
|
|
19
20
|
},
|
|
20
21
|
"author": "Casual Security Inc. & Conny Brunnkvist <cbrunnkvist@gmail.com>",
|
|
21
|
-
"main": "
|
|
22
|
-
"types": "
|
|
22
|
+
"main": "index.js",
|
|
23
|
+
"types": "index.d.ts",
|
|
23
24
|
"files": [
|
|
24
25
|
"nano_rspow_web.js",
|
|
25
26
|
"nano_rspow_web_bg.wasm",
|
|
26
27
|
"nano_rspow_web.d.ts",
|
|
28
|
+
"index.js",
|
|
29
|
+
"index.d.ts",
|
|
30
|
+
"pow-engine.js",
|
|
31
|
+
"pow-engine.d.ts",
|
|
27
32
|
"README.md"
|
|
28
33
|
],
|
|
29
34
|
"scripts": {
|
|
30
35
|
"build": "cargo build -p nano-rspow-web --target wasm32-unknown-unknown --release && wasm-bindgen --target web --out-dir . ../target/wasm32-unknown-unknown/release/nano_rspow_web.wasm"
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@openrai/nano-pow-contract": "^0.1.0"
|
|
31
39
|
}
|
|
32
40
|
}
|
package/pow-engine.d.ts
ADDED
package/pow-engine.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import init, { generate_work, validate_work } from './nano_rspow_web.js'
|
|
2
|
+
|
|
3
|
+
let initialization
|
|
4
|
+
|
|
5
|
+
function ready () {
|
|
6
|
+
initialization ??= init()
|
|
7
|
+
return initialization
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/** Create the nano-pow-contract adapter for the WebAssembly/WebGPU engine. */
|
|
11
|
+
export function createPowEngine () {
|
|
12
|
+
return {
|
|
13
|
+
name: 'nano-rspow-web',
|
|
14
|
+
ready,
|
|
15
|
+
generate: async (root, threshold) => (await generate_work(root, threshold)).nonce,
|
|
16
|
+
validate: (root, work, threshold) => validate_work(root, work, threshold)
|
|
17
|
+
}
|
|
18
|
+
}
|