browser based webworker block generator demo completed

This commit is contained in:
Kevin Froman 2020-09-27 18:07:18 +00:00
commit 1d53c5054f
8 changed files with 141 additions and 0 deletions

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "onionr-jspow"]
path = onionr-jspow
url = ../onionr-jspow

7
css/bulma-dark.min.css vendored Normal file

File diff suppressed because one or more lines are too long

34
generator.html Normal file
View File

@ -0,0 +1,34 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Onionr Block Generator</title>
<meta name="description" content="Generate Onionr block">
<meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
<link rel="stylesheet" href="css/bulma-dark.min.css">
<script src="sha3.js" defer></script>
<script src="onionr-jspow/index.js" defer></script>
<script src="main.js" defer></script>
</head>
<body>
Block Type: <input type="text" id="type">
<br>
Contents:
<br>
<textarea id="message"></textarea>
<br>
<button id="generate">Generate Block</button>
<br>
<br>
<h2>Output</h2>
<br>
<textarea id="output" cols=75 rows=50></textarea>
</body>
</html>

25
main.js Normal file
View File

@ -0,0 +1,25 @@
var worker = new Worker("./powworker.js")
document.getElementById('generate').onclick = function(){
document.getElementById('output').value = "computing..."
var metadata = {
"meta": {
"type": document.getElementById("type")
},
"time": 0
}
// todo web workers
var data = document.getElementById('message').value
var postData = {
"data": data,
"metadata": metadata,
}
worker.postMessage(JSON.stringify(postData))
}
worker.addEventListener('message', function(e) {
document.getElementById('output').value = doHashHex(e.data) + "\n"
document.getElementById('output').value += new TextDecoder("utf-8").decode(e.data)
})

1
onionr-jspow Submodule

@ -0,0 +1 @@
Subproject commit abd1872a9174c983a75f2ffe102dab72da706b14

38
package-lock.json generated Normal file
View File

@ -0,0 +1,38 @@
{
"requires": true,
"lockfileVersion": 1,
"dependencies": {
"base64-js": {
"version": "1.3.1",
"resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.3.1.tgz",
"integrity": "sha512-mLQ4i2QO1ytvGWFWmcngKO//JXAQueZvwEKtjgQFM4jIK0kU+ytMfplL8j+n5mspOfjHwoAg+9yhb7BwAHm36g=="
},
"buffer": {
"version": "5.6.0",
"resolved": "https://registry.npmjs.org/buffer/-/buffer-5.6.0.tgz",
"integrity": "sha512-/gDYp/UtU0eA1ys8bOs9J6a+E/KWIY+DZ+Q2WESNUA0jFRsJOc0SNUO6xJ5SGA1xueg3NL65W6s+NY5l9cunuw==",
"requires": {
"base64-js": "^1.0.2",
"ieee754": "^1.1.4"
}
},
"ieee754": {
"version": "1.1.13",
"resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.1.13.tgz",
"integrity": "sha512-4vf7I2LYV/HaWerSo3XmlMkp5eZ83i+/CDluXi/IGTs/O1sejBNhTtnxzmRZfvOUqj7lZjqHkeTvpgSFDlWZTg=="
},
"sha3": {
"version": "2.1.3",
"resolved": "https://registry.npmjs.org/sha3/-/sha3-2.1.3.tgz",
"integrity": "sha512-Io53D4o9qOmf3Ow9p/DoGLQiQHhtuR0ulbyambvRSG+OX5yXExk2yYfvjHtb7AtOyk6K6+sPeK/qaowWc/E/GA==",
"requires": {
"buffer": "5.6.0"
}
},
"webworkify": {
"version": "1.5.0",
"resolved": "https://registry.npmjs.org/webworkify/-/webworkify-1.5.0.tgz",
"integrity": "sha512-AMcUeyXAhbACL8S2hqqdqOLqvJ8ylmIbNwUIqQujRSouf4+eUFaXbG6F1Rbu+srlJMmxQWsiU7mOJi0nMBfM1g=="
}
}
}

12
powworker.js Normal file
View File

@ -0,0 +1,12 @@
importScripts("onionr-jspow/index.js")
importScripts("sha3.js")
self.addEventListener('message', function(e) {
var data = JSON.parse(e.data)
self.postMessage(
doPow(
data.metadata,
data.data,
2
));
}, false);

21
sha3.js Normal file

File diff suppressed because one or more lines are too long