Various improvements to remote link login. PoW algorithm tuned. Added base64url and helper modules.
This commit is contained in:
@@ -106,6 +106,7 @@
|
||||
import { ref, computed, watch, nextTick, onMounted, onUnmounted } from 'vue'
|
||||
import QRCode from 'qrcode/lib/browser'
|
||||
import aWebSocket from '@/utils/awaitable-websocket'
|
||||
import { dec as b64dec, enc as b64enc } from '@/utils/base64url'
|
||||
import { getSettings } from '@/utils/settings'
|
||||
import { formatDate } from '@/utils/helpers'
|
||||
import { solvePoW } from '@/utils/pow'
|
||||
@@ -156,13 +157,12 @@ async function startRemoteAuth() {
|
||||
// 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 challenge = b64dec(powChallenge.pow.challenge)
|
||||
const powStart = performance.now()
|
||||
const nonce = await solvePoW(challenge, powChallenge.pow.bits)
|
||||
const nonces = await solvePoW(challenge, powChallenge.pow.work)
|
||||
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)) })
|
||||
console.log(`PoW solved: ${powChallenge.pow.work} work units in ${(powTime / 1000).toFixed(3)}s`)
|
||||
ws.send_json({ pow: b64enc(nonces) })
|
||||
}
|
||||
|
||||
// Receive the remote auth token, pairing code, and URL
|
||||
|
||||
Reference in New Issue
Block a user