nano-pow 3.2.0 → 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/bin/cli.js +47 -40
- package/package.json +2 -2
package/dist/bin/cli.js
CHANGED
|
@@ -46,7 +46,7 @@ while (/^[0-9A-Fa-f]{64}$/.test(args[args.length - 1] ?? "")) {
|
|
|
46
46
|
inArgs.unshift(args.pop());
|
|
47
47
|
}
|
|
48
48
|
hashes.push(...inArgs);
|
|
49
|
-
let fn = "
|
|
49
|
+
let fn = "work_generate";
|
|
50
50
|
let work = "";
|
|
51
51
|
let isJson = false;
|
|
52
52
|
const options = {};
|
|
@@ -56,7 +56,7 @@ for (let i = 0; i < args.length; i++) {
|
|
|
56
56
|
case "-v": {
|
|
57
57
|
if (args[i + 1] == null) throw new Error("Missing argument for work validation");
|
|
58
58
|
if (!/^[0-9A-Fa-f]{16}$/.test(args[i + 1])) throw new Error("Invalid work to validate");
|
|
59
|
-
fn = "
|
|
59
|
+
fn = "work_validate";
|
|
60
60
|
work = `'${args[i + 1]}', `;
|
|
61
61
|
break;
|
|
62
62
|
}
|
|
@@ -110,60 +110,67 @@ if (hashes.length === 0) {
|
|
|
110
110
|
]
|
|
111
111
|
});
|
|
112
112
|
const page = await browser.newPage();
|
|
113
|
-
|
|
114
|
-
await
|
|
113
|
+
const cliPage = `${import.meta.dirname}/cli.html`;
|
|
114
|
+
await fs.writeFile(cliPage, "");
|
|
115
|
+
await page.goto(import.meta.resolve("./cli.html"));
|
|
116
|
+
await page.waitForFunction(async () => {
|
|
117
|
+
return await navigator.gpu.requestAdapter();
|
|
118
|
+
});
|
|
119
|
+
const inject = `
|
|
120
|
+
${NanoPow}
|
|
121
|
+
window.results = []
|
|
122
|
+
const hashes = ["${hashes.join('","')}"]
|
|
123
|
+
for (const hash of hashes) {
|
|
124
|
+
try {
|
|
125
|
+
const result = await NanoPow.${fn}(${work}hash, ${JSON.stringify(options)})
|
|
126
|
+
window.results.push(result)
|
|
127
|
+
console.log(\`cli \${JSON.stringify(result, null, 4)}\`)
|
|
128
|
+
} catch (err) {
|
|
129
|
+
console.error(\`cli \${err}\`)
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
console.log('cli exit')
|
|
133
|
+
`;
|
|
134
|
+
const hash = await crypto.subtle.digest("SHA-256", Buffer.from(inject, "utf-8"));
|
|
135
|
+
const src = `sha256-${Buffer.from(hash).toString("base64")}`;
|
|
115
136
|
let start = performance.now();
|
|
116
137
|
page.on("console", async (msg) => {
|
|
117
|
-
const output = msg.text().split(
|
|
118
|
-
if (output[0] === "
|
|
138
|
+
const output = msg.text().split(/^cli /);
|
|
139
|
+
if (output[0] === "") {
|
|
119
140
|
if (output[1] === "exit") {
|
|
120
141
|
if (isJson) {
|
|
121
142
|
const results = await page.evaluate(() => {
|
|
122
143
|
return window.results;
|
|
123
144
|
});
|
|
124
|
-
for (let i = 0; i < results.length; i++) {
|
|
125
|
-
results[i] = {
|
|
126
|
-
blockhash: hashes[i],
|
|
127
|
-
work: results[i]
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
145
|
console.log(JSON.stringify(results, null, 4));
|
|
131
146
|
}
|
|
132
147
|
const end = performance.now();
|
|
133
148
|
if (options["debug"]) console.log(end - start, "ms total |", (end - start) / hashes.length, "ms avg");
|
|
134
149
|
await browser.close();
|
|
135
150
|
} else if (!isJson) {
|
|
136
|
-
|
|
151
|
+
try {
|
|
152
|
+
console.log(JSON.parse(output[1]));
|
|
153
|
+
} catch (err) {
|
|
154
|
+
console.log(output[1]);
|
|
155
|
+
}
|
|
137
156
|
}
|
|
138
157
|
} else if (options["debug"]) {
|
|
139
|
-
|
|
158
|
+
try {
|
|
159
|
+
console.log(JSON.parse(msg.text()));
|
|
160
|
+
} catch (err) {
|
|
161
|
+
console.log(msg.text());
|
|
162
|
+
}
|
|
140
163
|
}
|
|
141
164
|
});
|
|
142
|
-
await page.waitForFunction(async () => {
|
|
143
|
-
return await navigator.gpu.requestAdapter();
|
|
144
|
-
});
|
|
145
165
|
start = performance.now();
|
|
146
|
-
await page.
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
const hashes = ["${hashes.join('","')}"]
|
|
157
|
-
for (const hash of hashes) {
|
|
158
|
-
try {
|
|
159
|
-
const work = await NanoPow.${fn}(${work}hash, ${JSON.stringify(options)})
|
|
160
|
-
window.results.push(work)
|
|
161
|
-
console.log(\`cli \${work}\`)
|
|
162
|
-
} catch (err) {
|
|
163
|
-
console.error(\`cli \${err}\`)
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
console.log('cli exit')
|
|
167
|
-
`
|
|
168
|
-
});
|
|
166
|
+
await page.setContent(`
|
|
167
|
+
<!DOCTYPE html>
|
|
168
|
+
<head>
|
|
169
|
+
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; base-uri 'none'; form-action 'none'; script-src '${src}';">
|
|
170
|
+
<script type="module">${inject}</script>
|
|
171
|
+
</head>
|
|
172
|
+
</html>
|
|
173
|
+
`);
|
|
174
|
+
await fs.unlink(cliPage);
|
|
175
|
+
if (options["debug"]) console.log("Puppeteer initialized");
|
|
169
176
|
})();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nano-pow",
|
|
3
|
-
"version": "3.2.
|
|
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",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"build": "rm -rf {dist,types} && tsc && node esbuild.mjs"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
|
-
"@types/node": "^22.13.
|
|
51
|
+
"@types/node": "^22.13.11",
|
|
52
52
|
"@webgpu/types": "^0.1.57",
|
|
53
53
|
"esbuild": "^0.25.1",
|
|
54
54
|
"esbuild-plugin-glsl": "^1.4.0",
|