ソースを参照

seems working now

master
SeraphJACK 3年前
コミット
4a529a1ed0
署名者: SeraphJACK <seraphjack@outlook.com> GPGキーID: 14162B46567AB06F
6個のファイルの変更25行の追加21行の削除
  1. +1
    -1
      http/challenge.go
  2. +0
    -2
      static/index.html
  3. +0
    -11
      static/js/challenge.js
  4. +5
    -3
      static/js/vote.js
  5. +18
    -1
      static/js/worker.js
  6. +1
    -3
      static/pending.html

+ 1
- 1
http/challenge.go ファイルの表示

@@ -28,7 +28,7 @@ func checkChallenge(ip net.IP, magic string) bool {
challenge := getChallenge(ip)
bytes := []byte(challenge + magic)
hash := sha256.Sum256(bytes[:])
for i := 0; i < 2; i++ {
for i := 0; i < 4; i++ {
if hash[i] != 0 {
return false
}


+ 0
- 2
static/index.html ファイルの表示

@@ -16,6 +16,4 @@
</div>
</body>
<script src="js/vote.js"></script>
<script src="js/sha256.min.js"></script>
<script src="js/challenge.js"></script>
</html>

+ 0
- 11
static/js/challenge.js ファイルの表示

@@ -1,11 +0,0 @@
async function findMagic(challengeString) {
if (challengeString !== null) {
for (let i=0n; true; i++) {
let result = sha256.array(challengeString + i.toString())
if (result[0] === 0 && result[1] === 0 && result[2] === 0 && result[3] === 0) {
return i.toString()
}
}
}
return null
}

+ 5
- 3
static/js/vote.js ファイルの表示

@@ -8,14 +8,16 @@ function voteIsNotDL() {
location.href = "pending.html"
}

async function doVote() {
function doVote() {
fetch("/challenge").then(response => {
response.text().then(body => {
if (!response.ok) {
alert(body)
location.href = "fail.html"
} else {
findMagic(body).then((magicString) => {
let worker = new Worker("js/worker.js")
worker.postMessage(body)
worker.onmessage = (magicString) => {
fetch("/submit", {
method: "POST",
headers: {
@@ -30,7 +32,7 @@ async function doVote() {
location.href = "finish.html"
}
})
})
}
}
})
})


static/js/worker.js
ファイル差分が大きすぎるため省略します
ファイルの表示


+ 1
- 3
static/pending.html ファイルの表示

@@ -18,9 +18,7 @@
</div>
</body>
<script src="js/vote.js"></script>
<script src="js/sha256.min.js"></script>
<script src="js/challenge.js"></script>
<script>
<script async>
doVote()
</script>
</html>

読み込み中…
キャンセル
保存