nano-pow 3.1.4 → 3.2.1

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/types.d.ts CHANGED
@@ -1,7 +1,67 @@
1
1
  // SPDX-FileCopyrightText: 2025 Chris Duncan <chris@zoso.dev>
2
2
  // SPDX-License-Identifier: GPL-3.0-or-later
3
3
 
4
- import "@webgpu/types"
4
+ import '@webgpu/types'
5
+
6
+ /**
7
+ * Used by work server for inbound requests to `work_generate`.
8
+ *
9
+ * @param {string} action - Method to call
10
+ * @param {string} hash - Block hash used to generate work
11
+ * @param {string} [difficulty=FFFFFFF800000000] - Minimum threshold for a nonce to be valid
12
+ */
13
+ type WorkGenerateRequest = {
14
+ action: 'work_generate'
15
+ hash: string
16
+ difficulty?: string
17
+ }
18
+
19
+ /**
20
+ * Used by work server for outbound responses to `work_generate`.
21
+ *
22
+ * @param {string} hash - Block hash used to generate or validate work
23
+ * @param {string} work - Valid proof-of-work nonce generated for input hash
24
+ * @param {string} difficulty - BLAKE2b hash result which was compared to specified minimum threshold
25
+ */
26
+ type WorkGenerateResponse = {
27
+ hash: string
28
+ work: string
29
+ difficulty: string
30
+ }
31
+
32
+ /**
33
+ * Used by work server for inbound requests to `work_validate`.
34
+ *
35
+ * @param {string} action - Method to call
36
+ * @param {string} hash - Block hash used to validate work
37
+ * @param {string} work - Existing nonce to check against hash
38
+ * @param {string} [difficulty=FFFFFFF800000000] - Minimum threshold for a nonce to be valid
39
+ */
40
+ type WorkValidateRequest = {
41
+ action: 'work_validate'
42
+ hash: string
43
+ work: string
44
+ difficulty?: string
45
+ }
46
+
47
+ /**
48
+ * Used by work server for outbound responses to `work_validate`.
49
+ *
50
+ * @param {string} hash - Hash from validate request
51
+ * @param {string} work - Nonce from validate request
52
+ * @param {string} difficulty - BLAKE2b hash result which is compared to specified minimum threshold
53
+ * @param {string} [valid] - Excluded if optional difficulty was not included in the request. 1 for true if nonce is valid for requested difficulty, else 0 for false
54
+ * @param {string} valid_all - 1 for true if nonce is valid for send blocks, else 0 for false
55
+ * @param {string} valid_receive - 1 for true if nonce is valid for receive blocks, else 0 for false
56
+ */
57
+ type WorkValidateResponse = {
58
+ hash: string
59
+ work: string
60
+ difficulty: string
61
+ valid?: '0' | '1'
62
+ valid_all: '0' | '1'
63
+ valid_receive: '0' | '1'
64
+ }
5
65
 
6
66
  export declare const NanoPowGlDownsampleShader: string
7
67
  export declare const NanoPowGlDrawShader: string
@@ -36,24 +96,41 @@ export type FBO = {
36
96
  export type NanoPowOptions = {
37
97
  debug?: boolean
38
98
  effort?: number
39
- threshold?: number
99
+ threshold?: bigint | number
40
100
  }
41
101
 
42
102
  /**
43
103
  * Nano proof-of-work using WebGL 2.0.
44
104
  */
45
105
  export declare class NanoPowGl {
46
- /** Compile */
106
+ #private
107
+ /** Drawing buffer width in pixels. */
108
+ static get size (): number | undefined
109
+ /**
110
+ * Constructs canvas, gets WebGL context, initializes buffers, and compiles
111
+ * shaders.
112
+ */
47
113
  static init (): Promise<void>
114
+ /**
115
+ * On WebGL context loss, attempts to clear all program variables and then
116
+ * reinitialize them by calling `init()`.
117
+ */
48
118
  static reset (): void
49
119
  /**
50
120
  * Finds a nonce that satisfies the Nano proof-of-work requirements.
51
121
  *
52
122
  * @param {string} hash - Hexadecimal hash of previous block, or public key for new accounts
53
- * @param {NanoPowOptions} options - Options used to configure search execution
123
+ * @param {NanoPowOptions} options - Used to configure search execution
54
124
  */
55
125
  static search (hash: string, options?: NanoPowOptions): Promise<string>
56
126
  /**
127
+ * Finds a nonce that satisfies the Nano proof-of-work requirements.
128
+ *
129
+ * @param {string} hash - Hexadecimal hash of previous block, or public key for new accounts
130
+ * @param {NanoPowOptions} options - Options used to configure search execution
131
+ */
132
+ static work_generate (hash: string, options?: NanoPowOptions): Promise<WorkGenerateResponse>
133
+ /**
57
134
  * Validates that a nonce satisfies Nano proof-of-work requirements.
58
135
  *
59
136
  * @param {string} work - Hexadecimal proof-of-work value to validate
@@ -61,12 +138,21 @@ export declare class NanoPowGl {
61
138
  * @param {NanoPowOptions} options - Options used to configure search execution
62
139
  */
63
140
  static validate (work: string, hash: string, options?: NanoPowOptions): Promise<boolean>
141
+ /**
142
+ * Validates that a nonce satisfies Nano proof-of-work requirements.
143
+ *
144
+ * @param {string} work - Hexadecimal proof-of-work value to validate
145
+ * @param {string} hash - Hexadecimal hash of previous block, or public key for new accounts
146
+ * @param {NanoPowOptions} options - Options used to configure search execution
147
+ */
148
+ static work_validate (work: string, hash: string, options?: NanoPowOptions): Promise<WorkValidateResponse>
64
149
  }
65
150
 
66
151
  /**
67
152
  * Nano proof-of-work using WebGPU.
68
153
  */
69
154
  export declare class NanoPowGpu {
155
+ #private
70
156
  static init (): Promise<void>
71
157
  static setup (): void
72
158
  static reset (): void
@@ -78,6 +164,13 @@ export declare class NanoPowGpu {
78
164
  */
79
165
  static search (hash: string, options?: NanoPowOptions): Promise<string>
80
166
  /**
167
+ * Finds a nonce that satisfies the Nano proof-of-work requirements.
168
+ *
169
+ * @param {string} hash - Hexadecimal hash of previous block, or public key for new accounts
170
+ * @param {NanoPowOptions} options - Used to configure search execution
171
+ */
172
+ static work_generate (hash: string, options?: NanoPowOptions): Promise<WorkGenerateResponse>
173
+ /**
81
174
  * Validates that a nonce satisfies Nano proof-of-work requirements.
82
175
  *
83
176
  * @param {string} work - Hexadecimal proof-of-work value to validate
@@ -85,4 +178,12 @@ export declare class NanoPowGpu {
85
178
  * @param {NanoPowOptions} options - Options used to configure search execution
86
179
  */
87
180
  static validate (work: string, hash: string, options?: NanoPowOptions): Promise<boolean>
181
+ /**
182
+ * Validates that a nonce satisfies Nano proof-of-work requirements.
183
+ *
184
+ * @param {string} work - Hexadecimal proof-of-work value to validate
185
+ * @param {string} hash - Hexadecimal hash of previous block, or public key for new accounts
186
+ * @param {NanoPowOptions} options - Options used to configure search execution
187
+ */
188
+ static work_validate (work: string, hash: string, options?: NanoPowOptions): Promise<WorkValidateResponse>
88
189
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nano-pow",
3
- "version": "3.1.4",
3
+ "version": "3.2.1",
4
4
  "description": "Proof-of-work generation and validation with WebGPU/WebGL for Nano cryptocurrency.",
5
5
  "keywords": [
6
6
  "nemo",
@@ -45,14 +45,13 @@
45
45
  "url": "git+https://zoso.dev/nano-pow.git"
46
46
  },
47
47
  "scripts": {
48
- "build": "rm -rf {dist,types} && tsc && node esbuild.mjs && npm run fix-copyright && cp -r src/bin src/types.d.ts dist",
49
- "fix-copyright": "sed -i '/\\/\\/ src\\/shaders\\/compute\\.wgsl/a //! SPDX-FileCopyrightText: 2025 Chris Duncan <chris@zoso.dev>\\n//! SPDX-License-Identifier: GPL-3.0-or-later' dist/main.min.js"
48
+ "build": "rm -rf {dist,types} && tsc && node esbuild.mjs"
50
49
  },
51
50
  "devDependencies": {
52
- "@types/node": "^22.13.10",
53
- "@webgpu/types": "^0.1.55",
51
+ "@types/node": "^22.13.11",
52
+ "@webgpu/types": "^0.1.57",
54
53
  "esbuild": "^0.25.1",
55
- "esbuild-plugin-glsl": "^1.2.3",
54
+ "esbuild-plugin-glsl": "^1.4.0",
56
55
  "typescript": "^5.8.2"
57
56
  },
58
57
  "type": "module",