summaryrefslogtreecommitdiff
path: root/srv/src/http/static/solvePow.js
diff options
context:
space:
mode:
authorBrian Picciano <mediocregopher@gmail.com>2022-09-13 12:56:08 +0200
committerBrian Picciano <mediocregopher@gmail.com>2022-09-13 12:56:08 +0200
commit4f01edb9230f58ff84b0dd892c931ec8ac9aad55 (patch)
tree9c1598a3f98203913ac2548883c02a81deb33dc7 /srv/src/http/static/solvePow.js
parent5485984e05aebde22819adebfbd5ad51475a6c21 (diff)
move src out of srv, clean up default.nix and Makefile
Diffstat (limited to 'srv/src/http/static/solvePow.js')
-rw-r--r--srv/src/http/static/solvePow.js28
1 files changed, 0 insertions, 28 deletions
diff --git a/srv/src/http/static/solvePow.js b/srv/src/http/static/solvePow.js
deleted file mode 100644
index 900400c..0000000
--- a/srv/src/http/static/solvePow.js
+++ /dev/null
@@ -1,28 +0,0 @@
-const fromHexString = hexString =>
- new Uint8Array(hexString.match(/.{1,2}/g).map(byte => parseInt(byte, 16)));
-
-const toHexString = bytes =>
- bytes.reduce((str, byte) => str + byte.toString(16).padStart(2, '0'), '');
-
-onmessage = async (e) => {
- const seed = fromHexString(e.data.seedHex);
- const target = e.data.target;
-
- const fullBuf = new ArrayBuffer(seed.byteLength*2);
-
- const fullBufSeed = new Uint8Array(fullBuf, 0, seed.byteLength);
- seed.forEach((v, i) => fullBufSeed[i] = v);
-
- const randBuf = new Uint8Array(fullBuf, seed.byteLength);
-
- while (true) {
- crypto.getRandomValues(randBuf);
- const digest = await crypto.subtle.digest('SHA-512', fullBuf);
- const digestView = new DataView(digest);
- if (digestView.getUint32(0) < target) {
- postMessage(toHexString(randBuf));
- return;
- }
- }
-
-};