Proper PoW, unified verification WS etc
This commit is contained in:
@@ -108,6 +108,7 @@ import QRCode from 'qrcode/lib/browser'
|
||||
import aWebSocket from '@/utils/awaitable-websocket'
|
||||
import { getSettings } from '@/utils/settings'
|
||||
import { formatDate } from '@/utils/helpers'
|
||||
import { solvePoW } from '@/utils/pow'
|
||||
|
||||
const props = defineProps({
|
||||
active: { type: Boolean, default: false },
|
||||
@@ -152,6 +153,18 @@ async function startRemoteAuth() {
|
||||
|
||||
ws = await aWebSocket(wsUrl)
|
||||
|
||||
// First message is PoW challenge
|
||||
const powChallenge = await ws.receive_json()
|
||||
if (powChallenge.pow) {
|
||||
const challenge = Uint8Array.from(atob(powChallenge.pow.challenge), c => c.charCodeAt(0))
|
||||
const powStart = performance.now()
|
||||
const nonce = await solvePoW(challenge, powChallenge.pow.bits)
|
||||
const powTime = performance.now() - powStart
|
||||
const nonceVal = nonce.reduce((acc, b, i) => acc + BigInt(b) * (1n << BigInt(i * 8)), 0n)
|
||||
console.log(`PoW solved: ${Number(nonceVal)} iterations in ${(powTime / 1000).toFixed(3)}s (${(powTime / Number(nonceVal)).toFixed(3)}ms/iter)`)
|
||||
ws.send_json({ pow: btoa(String.fromCharCode(...nonce)) })
|
||||
}
|
||||
|
||||
// Receive the remote auth token, pairing code, and URL
|
||||
const res = await ws.receive_json()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user