nano-pow 1.2.3 → 2.0.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.
@@ -0,0 +1 @@
1
+ export declare const NanoPowGlFragmentShader = "#version 300 es\n#pragma vscode_glsllint_stage: frag\nprecision highp float;\nprecision highp int;\n\nin vec2 uv_pos;\nout vec4 fragColor;\n\n// blockhash - array of precalculated block hash components\n// threshold - 0xfffffff8 for send/change blocks, 0xfffffe00 for all else\n// workload - Defines canvas size\nlayout(std140) uniform UBO {\n\tuint blockhash[8];\n\tuint threshold;\n\tfloat workload;\n};\n\n// Random work values\n// First 2 bytes will be overwritten by texture pixel position\n// Second 2 bytes will be modified if the canvas size is greater than 256x256\n// Last 4 bytes remain as generated externally\nlayout(std140) uniform WORK {\n\tuvec4 work[2];\n};\n\n// Defined separately from uint v[32] below as the original value is required\n// to calculate the second uint32 of the digest for threshold comparison\nconst uint BLAKE2B_IV32_1 = 0x6A09E667u;\n\n// Both buffers represent 16 uint64s as 32 uint32s\n// because that's what GLSL offers, just like Javascript\n\n// Compression buffer, intialized to 2 instances of the initialization vector\n// The following values have been modified from the BLAKE2B_IV:\n// OUTLEN is constant 8 bytes\n// v[0] ^= 0x01010000u ^ uint(OUTLEN);\n// INLEN is constant 40 bytes: work value (8) + block hash (32)\n// v[24] ^= uint(INLEN);\n// It's always the \"last\" compression at this INLEN\n// v[28] = ~v[28];\n// v[29] = ~v[29];\nuint v[32] = uint[32](\n\t0xF2BDC900u, 0x6A09E667u, 0x84CAA73Bu, 0xBB67AE85u,\n\t0xFE94F82Bu, 0x3C6EF372u, 0x5F1D36F1u, 0xA54FF53Au,\n\t0xADE682D1u, 0x510E527Fu, 0x2B3E6C1Fu, 0x9B05688Cu,\n\t0xFB41BD6Bu, 0x1F83D9ABu, 0x137E2179u, 0x5BE0CD19u,\n\t0xF3BCC908u, 0x6A09E667u, 0x84CAA73Bu, 0xBB67AE85u,\n\t0xFE94F82Bu, 0x3C6EF372u, 0x5F1D36F1u, 0xA54FF53Au,\n\t0xADE682F9u, 0x510E527Fu, 0x2B3E6C1Fu, 0x9B05688Cu,\n\t0x04BE4294u, 0xE07C2654u, 0x137E2179u, 0x5BE0CD19u\n);\n// Input data buffer\nuint m[32];\n\n// These are offsets into the input data buffer for each mixing step.\n// They are multiplied by 2 from the original SIGMA values in\n// the C reference implementation, which refered to uint64s.\nconst uint SIGMA82[192] = uint[192](\n\t0u,2u,4u,6u,8u,10u,12u,14u,16u,18u,20u,22u,24u,26u,28u,30u,\n\t28u,20u,8u,16u,18u,30u,26u,12u,2u,24u,0u,4u,22u,14u,10u,6u,\n\t22u,16u,24u,0u,10u,4u,30u,26u,20u,28u,6u,12u,14u,2u,18u,8u,\n\t14u,18u,6u,2u,26u,24u,22u,28u,4u,12u,10u,20u,8u,0u,30u,16u,\n\t18u,0u,10u,14u,4u,8u,20u,30u,28u,2u,22u,24u,12u,16u,6u,26u,\n\t4u,24u,12u,20u,0u,22u,16u,6u,8u,26u,14u,10u,30u,28u,2u,18u,\n\t24u,10u,2u,30u,28u,26u,8u,20u,0u,14u,12u,6u,18u,4u,16u,22u,\n\t26u,22u,14u,28u,24u,2u,6u,18u,10u,0u,30u,8u,16u,12u,4u,20u,\n\t12u,30u,28u,18u,22u,6u,0u,16u,24u,4u,26u,14u,2u,8u,20u,10u,\n\t20u,4u,16u,8u,14u,12u,2u,10u,30u,22u,18u,28u,6u,24u,26u,0u,\n\t0u,2u,4u,6u,8u,10u,12u,14u,16u,18u,20u,22u,24u,26u,28u,30u,\n\t28u,20u,8u,16u,18u,30u,26u,12u,2u,24u,0u,4u,22u,14u,10u,6u\n);\n\n// G mixing function\nvoid G (uint ix, uint iy, uint a, uint b, uint c, uint d) {\n\tbool carry;\n\tuint o0;\n\tuint o1;\n\tuint xor0;\n\tuint xor1;\n\n\t// a = a + b;\n\to0 = v[a] + v[b];\n\to1 = v[a+1u] + v[b+1u];\n\tcarry = o0 < v[a];\n\to1 = o1 + uint(mix(0.0, 1.0, float(carry)));\n\tv[a] = o0;\n\tv[a+1u] = o1;\n\n\t// a = a + m[sigma[r][2*i+0]];\n\to0 = v[a] + m[ix];\n\to1 = v[a+1u] + m[ix+1u];\n\tcarry = o0 < v[a];\n\to1 = o1 + uint(mix(0.0, 1.0, float(carry)));\n\tv[a] = o0;\n\tv[a+1u] = o1;\n\n\t// d = rotr64(d ^ a, 32);\n\txor0 = v[d] ^ v[a];\n\txor1 = v[d+1u] ^ v[a+1u];\n\tv[d] = xor1;\n\tv[d+1u] = xor0;\n\n\t// c = c + d;\n\to0 = v[c] + v[d];\n\to1 = v[c+1u] + v[d+1u];\n\tcarry = o0 < v[c];\n\to1 = o1 + uint(mix(0.0, 1.0, float(carry)));\n\tv[c] = o0;\n\tv[c+1u] = o1;\n\n\t// b = rotr64(b ^ c, 24);\n\txor0 = v[b] ^ v[c];\n\txor1 = v[b+1u] ^ v[c+1u];\n\tv[b] = (xor0 >> 24u) ^ (xor1 << 8u);\n\tv[b+1u] = (xor1 >> 24u) ^ (xor0 << 8u);\n\n\t// a = a + b;\n\to0 = v[a] + v[b];\n\to1 = v[a+1u] + v[b+1u];\n\tcarry = o0 < v[a];\n\to1 = o1 + uint(mix(0.0, 1.0, float(carry)));\n\tv[a] = o0;\n\tv[a+1u] = o1;\n\n\t// a = a + m[sigma[r][2*i+1]];\n\to0 = v[a] + m[iy];\n\to1 = v[a+1u] + m[iy+1u];\n\tcarry = o0 < v[a];\n\to1 = o1 + uint(mix(0.0, 1.0, float(carry)));\n\tv[a] = o0;\n\tv[a+1u] = o1;\n\n\t// d = rotr64(d ^ a, 16)\n\txor0 = v[d] ^ v[a];\n\txor1 = v[d+1u] ^ v[a+1u];\n\tv[d] = (xor0 >> 16u) ^ (xor1 << 16u);\n\tv[d+1u] = (xor1 >> 16u) ^ (xor0 << 16u);\n\n\t// c = c + d;\n\to0 = v[c] + v[d];\n\to1 = v[c+1u] + v[d+1u];\n\tcarry = o0 < v[c];\n\to1 = o1 + uint(mix(0.0, 1.0, float(carry)));\n\tv[c] = o0;\n\tv[c+1u] = o1;\n\n\t// b = rotr64(b ^ c, 63)\n\txor0 = v[b] ^ v[c];\n\txor1 = v[b+1u] ^ v[c+1u];\n\tv[b] = (xor1 >> 31u) ^ (xor0 << 1u);\n\tv[b+1u] = (xor0 >> 31u) ^ (xor1 << 1u);\n}\n\nvoid main() {\n\tint i;\n\tuvec4 u_work0 = work[0u];\n\tuvec4 u_work1 = work[1u];\n\tuint uv_x = uint(uv_pos.x * workload);\n\tuint uv_y = uint(uv_pos.y * workload);\n\tuint x_pos = uv_x % 256u;\n\tuint y_pos = uv_y % 256u;\n\tuint x_index = (uv_x - x_pos) / 256u;\n\tuint y_index = (uv_y - y_pos) / 256u;\n\n\t// First 2 work bytes are the x,y pos within the 256x256 area, the next\n\t// two bytes are modified from the random generated value, XOR'd with\n\t// the x,y area index of where this pixel is located\n\tm[0u] = (x_pos ^ (y_pos << 8u) ^ ((u_work0.b ^ x_index) << 16u) ^ ((u_work0.a ^ y_index) << 24u));\n\n\t// Remaining bytes are un-modified from the random generated value\n\tm[1u] = (u_work1.r ^ (u_work1.g << 8u) ^ (u_work1.b << 16u) ^ (u_work1.a << 24u));\n\n\t// Block hash\n\tfor (uint i = 0u; i < 8u; i = i + 1u) {\n\t\tm[i+2u] = blockhash[i];\n\t}\n\n\t// twelve rounds of mixing\n\tfor(uint i = 0u; i < 12u; i = i + 1u) {\n\t\tG(SIGMA82[i * 16u + 0u], SIGMA82[i * 16u + 1u], 0u, 8u, 16u, 24u);\n\t\tG(SIGMA82[i * 16u + 2u], SIGMA82[i * 16u + 3u], 2u, 10u, 18u, 26u);\n\t\tG(SIGMA82[i * 16u + 4u], SIGMA82[i * 16u + 5u], 4u, 12u, 20u, 28u);\n\t\tG(SIGMA82[i * 16u + 6u], SIGMA82[i * 16u + 7u], 6u, 14u, 22u, 30u);\n\t\tG(SIGMA82[i * 16u + 8u], SIGMA82[i * 16u + 9u], 0u, 10u, 20u, 30u);\n\t\tG(SIGMA82[i * 16u + 10u], SIGMA82[i * 16u + 11u], 2u, 12u, 22u, 24u);\n\t\tG(SIGMA82[i * 16u + 12u], SIGMA82[i * 16u + 13u], 4u, 14u, 16u, 26u);\n\t\tG(SIGMA82[i * 16u + 14u], SIGMA82[i * 16u + 15u], 6u, 8u, 18u, 28u);\n\t}\n\n\t// Pixel data is multipled by threshold test result (0 or 1)\n\t// First 4 bytes insignificant, only calculate digest of second 4 bytes\n\tif ((BLAKE2B_IV32_1 ^ v[1u] ^ v[17u]) > threshold) {\n\t\tfragColor = vec4(\n\t\t\tfloat(x_index + 1u)/255.0, // +1 to distinguish from 0 (unsuccessful) pixels\n\t\t\tfloat(y_index + 1u)/255.0, // Same as previous\n\t\t\tfloat(x_pos)/255.0, // Return the 2 custom bytes used in work value\n\t\t\tfloat(y_pos)/255.0 // Second custom byte\n\t\t);\n\t} else {\n \t\tdiscard;\n\t}\n}\n";
@@ -0,0 +1,206 @@
1
+ // SPDX-FileCopyrightText: 2025 Chris Duncan <chris@zoso.dev>
2
+ // SPDX-FileContributor: Ben Green <ben@latenightsketches.com>
3
+ // SPDX-License-Identifier: GPL-3.0-or-later AND MIT
4
+ export const NanoPowGlFragmentShader = `#version 300 es
5
+ #pragma vscode_glsllint_stage: frag
6
+ precision highp float;
7
+ precision highp int;
8
+
9
+ in vec2 uv_pos;
10
+ out vec4 fragColor;
11
+
12
+ // blockhash - array of precalculated block hash components
13
+ // threshold - 0xfffffff8 for send/change blocks, 0xfffffe00 for all else
14
+ // workload - Defines canvas size
15
+ layout(std140) uniform UBO {
16
+ uint blockhash[8];
17
+ uint threshold;
18
+ float workload;
19
+ };
20
+
21
+ // Random work values
22
+ // First 2 bytes will be overwritten by texture pixel position
23
+ // Second 2 bytes will be modified if the canvas size is greater than 256x256
24
+ // Last 4 bytes remain as generated externally
25
+ layout(std140) uniform WORK {
26
+ uvec4 work[2];
27
+ };
28
+
29
+ // Defined separately from uint v[32] below as the original value is required
30
+ // to calculate the second uint32 of the digest for threshold comparison
31
+ const uint BLAKE2B_IV32_1 = 0x6A09E667u;
32
+
33
+ // Both buffers represent 16 uint64s as 32 uint32s
34
+ // because that's what GLSL offers, just like Javascript
35
+
36
+ // Compression buffer, intialized to 2 instances of the initialization vector
37
+ // The following values have been modified from the BLAKE2B_IV:
38
+ // OUTLEN is constant 8 bytes
39
+ // v[0] ^= 0x01010000u ^ uint(OUTLEN);
40
+ // INLEN is constant 40 bytes: work value (8) + block hash (32)
41
+ // v[24] ^= uint(INLEN);
42
+ // It's always the "last" compression at this INLEN
43
+ // v[28] = ~v[28];
44
+ // v[29] = ~v[29];
45
+ uint v[32] = uint[32](
46
+ 0xF2BDC900u, 0x6A09E667u, 0x84CAA73Bu, 0xBB67AE85u,
47
+ 0xFE94F82Bu, 0x3C6EF372u, 0x5F1D36F1u, 0xA54FF53Au,
48
+ 0xADE682D1u, 0x510E527Fu, 0x2B3E6C1Fu, 0x9B05688Cu,
49
+ 0xFB41BD6Bu, 0x1F83D9ABu, 0x137E2179u, 0x5BE0CD19u,
50
+ 0xF3BCC908u, 0x6A09E667u, 0x84CAA73Bu, 0xBB67AE85u,
51
+ 0xFE94F82Bu, 0x3C6EF372u, 0x5F1D36F1u, 0xA54FF53Au,
52
+ 0xADE682F9u, 0x510E527Fu, 0x2B3E6C1Fu, 0x9B05688Cu,
53
+ 0x04BE4294u, 0xE07C2654u, 0x137E2179u, 0x5BE0CD19u
54
+ );
55
+ // Input data buffer
56
+ uint m[32];
57
+
58
+ // These are offsets into the input data buffer for each mixing step.
59
+ // They are multiplied by 2 from the original SIGMA values in
60
+ // the C reference implementation, which refered to uint64s.
61
+ const uint SIGMA82[192] = uint[192](
62
+ 0u,2u,4u,6u,8u,10u,12u,14u,16u,18u,20u,22u,24u,26u,28u,30u,
63
+ 28u,20u,8u,16u,18u,30u,26u,12u,2u,24u,0u,4u,22u,14u,10u,6u,
64
+ 22u,16u,24u,0u,10u,4u,30u,26u,20u,28u,6u,12u,14u,2u,18u,8u,
65
+ 14u,18u,6u,2u,26u,24u,22u,28u,4u,12u,10u,20u,8u,0u,30u,16u,
66
+ 18u,0u,10u,14u,4u,8u,20u,30u,28u,2u,22u,24u,12u,16u,6u,26u,
67
+ 4u,24u,12u,20u,0u,22u,16u,6u,8u,26u,14u,10u,30u,28u,2u,18u,
68
+ 24u,10u,2u,30u,28u,26u,8u,20u,0u,14u,12u,6u,18u,4u,16u,22u,
69
+ 26u,22u,14u,28u,24u,2u,6u,18u,10u,0u,30u,8u,16u,12u,4u,20u,
70
+ 12u,30u,28u,18u,22u,6u,0u,16u,24u,4u,26u,14u,2u,8u,20u,10u,
71
+ 20u,4u,16u,8u,14u,12u,2u,10u,30u,22u,18u,28u,6u,24u,26u,0u,
72
+ 0u,2u,4u,6u,8u,10u,12u,14u,16u,18u,20u,22u,24u,26u,28u,30u,
73
+ 28u,20u,8u,16u,18u,30u,26u,12u,2u,24u,0u,4u,22u,14u,10u,6u
74
+ );
75
+
76
+ // G mixing function
77
+ void G (uint ix, uint iy, uint a, uint b, uint c, uint d) {
78
+ bool carry;
79
+ uint o0;
80
+ uint o1;
81
+ uint xor0;
82
+ uint xor1;
83
+
84
+ // a = a + b;
85
+ o0 = v[a] + v[b];
86
+ o1 = v[a+1u] + v[b+1u];
87
+ carry = o0 < v[a];
88
+ o1 = o1 + uint(mix(0.0, 1.0, float(carry)));
89
+ v[a] = o0;
90
+ v[a+1u] = o1;
91
+
92
+ // a = a + m[sigma[r][2*i+0]];
93
+ o0 = v[a] + m[ix];
94
+ o1 = v[a+1u] + m[ix+1u];
95
+ carry = o0 < v[a];
96
+ o1 = o1 + uint(mix(0.0, 1.0, float(carry)));
97
+ v[a] = o0;
98
+ v[a+1u] = o1;
99
+
100
+ // d = rotr64(d ^ a, 32);
101
+ xor0 = v[d] ^ v[a];
102
+ xor1 = v[d+1u] ^ v[a+1u];
103
+ v[d] = xor1;
104
+ v[d+1u] = xor0;
105
+
106
+ // c = c + d;
107
+ o0 = v[c] + v[d];
108
+ o1 = v[c+1u] + v[d+1u];
109
+ carry = o0 < v[c];
110
+ o1 = o1 + uint(mix(0.0, 1.0, float(carry)));
111
+ v[c] = o0;
112
+ v[c+1u] = o1;
113
+
114
+ // b = rotr64(b ^ c, 24);
115
+ xor0 = v[b] ^ v[c];
116
+ xor1 = v[b+1u] ^ v[c+1u];
117
+ v[b] = (xor0 >> 24u) ^ (xor1 << 8u);
118
+ v[b+1u] = (xor1 >> 24u) ^ (xor0 << 8u);
119
+
120
+ // a = a + b;
121
+ o0 = v[a] + v[b];
122
+ o1 = v[a+1u] + v[b+1u];
123
+ carry = o0 < v[a];
124
+ o1 = o1 + uint(mix(0.0, 1.0, float(carry)));
125
+ v[a] = o0;
126
+ v[a+1u] = o1;
127
+
128
+ // a = a + m[sigma[r][2*i+1]];
129
+ o0 = v[a] + m[iy];
130
+ o1 = v[a+1u] + m[iy+1u];
131
+ carry = o0 < v[a];
132
+ o1 = o1 + uint(mix(0.0, 1.0, float(carry)));
133
+ v[a] = o0;
134
+ v[a+1u] = o1;
135
+
136
+ // d = rotr64(d ^ a, 16)
137
+ xor0 = v[d] ^ v[a];
138
+ xor1 = v[d+1u] ^ v[a+1u];
139
+ v[d] = (xor0 >> 16u) ^ (xor1 << 16u);
140
+ v[d+1u] = (xor1 >> 16u) ^ (xor0 << 16u);
141
+
142
+ // c = c + d;
143
+ o0 = v[c] + v[d];
144
+ o1 = v[c+1u] + v[d+1u];
145
+ carry = o0 < v[c];
146
+ o1 = o1 + uint(mix(0.0, 1.0, float(carry)));
147
+ v[c] = o0;
148
+ v[c+1u] = o1;
149
+
150
+ // b = rotr64(b ^ c, 63)
151
+ xor0 = v[b] ^ v[c];
152
+ xor1 = v[b+1u] ^ v[c+1u];
153
+ v[b] = (xor1 >> 31u) ^ (xor0 << 1u);
154
+ v[b+1u] = (xor0 >> 31u) ^ (xor1 << 1u);
155
+ }
156
+
157
+ void main() {
158
+ int i;
159
+ uvec4 u_work0 = work[0u];
160
+ uvec4 u_work1 = work[1u];
161
+ uint uv_x = uint(uv_pos.x * workload);
162
+ uint uv_y = uint(uv_pos.y * workload);
163
+ uint x_pos = uv_x % 256u;
164
+ uint y_pos = uv_y % 256u;
165
+ uint x_index = (uv_x - x_pos) / 256u;
166
+ uint y_index = (uv_y - y_pos) / 256u;
167
+
168
+ // First 2 work bytes are the x,y pos within the 256x256 area, the next
169
+ // two bytes are modified from the random generated value, XOR'd with
170
+ // the x,y area index of where this pixel is located
171
+ m[0u] = (x_pos ^ (y_pos << 8u) ^ ((u_work0.b ^ x_index) << 16u) ^ ((u_work0.a ^ y_index) << 24u));
172
+
173
+ // Remaining bytes are un-modified from the random generated value
174
+ m[1u] = (u_work1.r ^ (u_work1.g << 8u) ^ (u_work1.b << 16u) ^ (u_work1.a << 24u));
175
+
176
+ // Block hash
177
+ for (uint i = 0u; i < 8u; i = i + 1u) {
178
+ m[i+2u] = blockhash[i];
179
+ }
180
+
181
+ // twelve rounds of mixing
182
+ for(uint i = 0u; i < 12u; i = i + 1u) {
183
+ G(SIGMA82[i * 16u + 0u], SIGMA82[i * 16u + 1u], 0u, 8u, 16u, 24u);
184
+ G(SIGMA82[i * 16u + 2u], SIGMA82[i * 16u + 3u], 2u, 10u, 18u, 26u);
185
+ G(SIGMA82[i * 16u + 4u], SIGMA82[i * 16u + 5u], 4u, 12u, 20u, 28u);
186
+ G(SIGMA82[i * 16u + 6u], SIGMA82[i * 16u + 7u], 6u, 14u, 22u, 30u);
187
+ G(SIGMA82[i * 16u + 8u], SIGMA82[i * 16u + 9u], 0u, 10u, 20u, 30u);
188
+ G(SIGMA82[i * 16u + 10u], SIGMA82[i * 16u + 11u], 2u, 12u, 22u, 24u);
189
+ G(SIGMA82[i * 16u + 12u], SIGMA82[i * 16u + 13u], 4u, 14u, 16u, 26u);
190
+ G(SIGMA82[i * 16u + 14u], SIGMA82[i * 16u + 15u], 6u, 8u, 18u, 28u);
191
+ }
192
+
193
+ // Pixel data is multipled by threshold test result (0 or 1)
194
+ // First 4 bytes insignificant, only calculate digest of second 4 bytes
195
+ if ((BLAKE2B_IV32_1 ^ v[1u] ^ v[17u]) > threshold) {
196
+ fragColor = vec4(
197
+ float(x_index + 1u)/255.0, // +1 to distinguish from 0 (unsuccessful) pixels
198
+ float(y_index + 1u)/255.0, // Same as previous
199
+ float(x_pos)/255.0, // Return the 2 custom bytes used in work value
200
+ float(y_pos)/255.0 // Second custom byte
201
+ );
202
+ } else {
203
+ discard;
204
+ }
205
+ }
206
+ `;
@@ -0,0 +1 @@
1
+ export declare const NanoPowGlVertexShader = "#version 300 es\n#pragma vscode_glsllint_stage: vert\nprecision highp float;\nlayout (location=0) in vec4 position;\nlayout (location=1) in vec2 uv;\n\nout vec2 uv_pos;\n\nvoid main() {\n\tuv_pos = uv;\n\tgl_Position = position;\n}\n";
@@ -0,0 +1,16 @@
1
+ // SPDX-FileCopyrightText: 2025 Chris Duncan <chris@zoso.dev>
2
+ // SPDX-FileContributor: Ben Green <ben@latenightsketches.com>
3
+ // SPDX-License-Identifier: GPL-3.0-or-later AND MIT
4
+ export const NanoPowGlVertexShader = `#version 300 es
5
+ #pragma vscode_glsllint_stage: vert
6
+ precision highp float;
7
+ layout (location=0) in vec4 position;
8
+ layout (location=1) in vec2 uv;
9
+
10
+ out vec2 uv_pos;
11
+
12
+ void main() {
13
+ uv_pos = uv;
14
+ gl_Position = position;
15
+ }
16
+ `;
@@ -0,0 +1,4 @@
1
+ import { default as NanoPowGpuComputeShader } from "./compute.wgsl";
2
+ import { NanoPowGlFragmentShader } from "./gl-fragment.js";
3
+ import { NanoPowGlVertexShader } from "./gl-vertex.js";
4
+ export { NanoPowGpuComputeShader, NanoPowGlFragmentShader, NanoPowGlVertexShader };
@@ -0,0 +1,6 @@
1
+ // SPDX-FileCopyrightText: 2025 Chris Duncan <chris@zoso.dev>
2
+ // SPDX-License-Identifier: GPL-3.0-or-later
3
+ import { default as NanoPowGpuComputeShader } from "./compute.wgsl";
4
+ import { NanoPowGlFragmentShader } from "./gl-fragment.js";
5
+ import { NanoPowGlVertexShader } from "./gl-vertex.js";
6
+ export { NanoPowGpuComputeShader, NanoPowGlFragmentShader, NanoPowGlVertexShader };
package/dist/types.d.ts CHANGED
@@ -1,18 +1,42 @@
1
+ // SPDX-FileCopyrightText: 2025 Chris Duncan <chris@zoso.dev>
2
+ // SPDX-License-Identifier: GPL-3.0-or-later
3
+
1
4
  import "@webgpu/types"
2
5
 
6
+ export declare const NanoPowGlFragmentShader: string
7
+ export declare const NanoPowGlVertexShader: string
8
+ export declare const NanoPowGpuComputeShader: any
9
+
3
10
  declare const NanoPow: typeof NanoPowGl | typeof NanoPowGpu | null
4
11
 
12
+ /**
13
+ * Used to configure NanoPow.
14
+ *
15
+ * @param {boolean} [debug=false] - Enables additional debug logging to the console. Default: false
16
+ * @param {number} [effort=0x8] - Multiplier for dispatching work search. Larger values are not necessarily better since they can quickly overwhelm the GPU. Ignored when validating. Default: 0x8
17
+ * @param {number} [threshold=0xfffffff8] - Minimum value result of `BLAKE2b(nonce||blockhash) << 0x32`. Default: 0xFFFFFFF8
18
+ */
19
+ export type NanoPowOptions = {
20
+ debug?: boolean
21
+ effort?: number
22
+ threshold?: number
23
+ }
24
+
25
+ /**
26
+ * Nano proof-of-work using WebGL 2.0.
27
+ */
5
28
  export declare class NanoPowGl {
6
29
  #private
7
30
  /** Compile */
8
31
  static init (): Promise<void>
32
+ static reset (): void
9
33
  /**
10
34
  * Finds a nonce that satisfies the Nano proof-of-work requirements.
11
35
  *
12
36
  * @param {string} hash - Hexadecimal hash of previous block, or public key for new accounts
13
37
  * @param {number} [threshold=0xfffffff8] - Difficulty of proof-of-work calculation
14
38
  */
15
- static search (hash: string, threshold?: number): Promise<string>
39
+ static search (hash: string, options?: NanoPowOptions): Promise<string>
16
40
  /**
17
41
  * Validates that a nonce satisfies Nano proof-of-work requirements.
18
42
  *
@@ -20,7 +44,7 @@ export declare class NanoPowGl {
20
44
  * @param {string} hash - Hexadecimal hash of previous block, or public key for new accounts
21
45
  * @param {number} [threshold=0xfffffff8] - Difficulty of proof-of-work calculation
22
46
  */
23
- static validate (work: string, hash: string, threshold?: number): Promise<boolean>
47
+ static validate (work: string, hash: string, options?: NanoPowOptions): Promise<boolean>
24
48
  }
25
49
 
26
50
  /**
@@ -35,19 +59,15 @@ export declare class NanoPowGpu {
35
59
  * Finds a nonce that satisfies the Nano proof-of-work requirements.
36
60
  *
37
61
  * @param {string} hash - Hexadecimal hash of previous block, or public key for new accounts
38
- * @param {number} [threshold=0xfffffff8] - Difficulty of proof-of-work calculation
62
+ * @param {NanoPowOptions} options - Used to configure search execution
39
63
  */
40
- static search (hash: string, threshold?: number): Promise<string>
64
+ static search (hash: string, options?: NanoPowOptions): Promise<string>
41
65
  /**
42
66
  * Validates that a nonce satisfies Nano proof-of-work requirements.
43
67
  *
44
68
  * @param {string} work - Hexadecimal proof-of-work value to validate
45
69
  * @param {string} hash - Hexadecimal hash of previous block, or public key for new accounts
46
- * @param {number} [threshold=0xfffffff8] - Difficulty of proof-of-work calculation
70
+ * @param {NanoPowOptions} options - Options used to configure search execution
47
71
  */
48
- static validate (work: string, hash: string, threshold?: number): Promise<boolean>
72
+ static validate (work: string, hash: string, options?: NanoPowOptions): Promise<boolean>
49
73
  }
50
-
51
- export declare const NanoPowGlFragmentShader: string
52
- export declare const NanoPowGlVertexShader: string
53
- export declare const NanoPowGpuComputeShader: any
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nano-pow",
3
- "version": "1.2.3",
3
+ "version": "2.0.0",
4
4
  "description": "Proof-of-work generation and validation with WebGPU/WebGL for Nano cryptocurrency.",
5
5
  "keywords": [
6
6
  "nemo",
@@ -47,7 +47,6 @@
47
47
  "@webgpu/types": "^0.1.52",
48
48
  "esbuild": "^0.24.2",
49
49
  "esbuild-plugin-glsl": "^1.2.2",
50
- "nano-webgl-pow": "^1.1.1",
51
50
  "typescript": "^5.7.3"
52
51
  },
53
52
  "type": "module",