RustStake - Cases

node v18.11.0
version: 2.0.3
endpointsharetweet
var express = require("@runkit/runkit/express-endpoint/1.0.0"); var app = express(exports); const crypto = require('crypto') let clientSeed = '' let serverSeed = '' let serverHash = '' let caseQuantity = 1 let dailyCase = false async function getResults() { let winningTickets = [] const serverHashBuffer = Buffer.from(serverHash, 'hex'); const serverSeedHash = crypto.createHash('sha256').update(serverSeed).digest(); if (!serverSeedHash.equals(serverHashBuffer)) { return { matches: false, winningTickets }; } for (let case_num = 1; case_num <= caseQuantity; case_num++) { let hmac = crypto.createHmac('SHA512', serverSeed) hmac.write(clientSeed) if (!dailyCase) { hmac.write(case_num.toString()) } let buf = hmac.digest() let winningTicket = Math.floor((buf.readUInt32BE() / Math.pow(2, 32)) * 10000) winningTickets.push(winningTicket) } return {matches: true, winningTickets} } getResults() .then(({ matches, winningTickets }) => { if (matches) { console.log(`Winning tickets:`); winningTickets.forEach((ticket, i) => { console.log(`Case #${i + 1}: ${ticket}`); }); } else { console.log("Server hash doesn't match server seed."); } }) .catch((error) => { console.error("An error occurred:", error); }); // ENDPOINT CODE - IRRELEVANT FOR IN-CODE VERIFICATION app.get("/", async (req, res) => { clientSeed = req.query.clientSeed serverSeed = req.query.serverSeed serverHash = req.query.serverHash dailyCase = req.query.dailyCase === 'true' if (!dailyCase) caseQuantity = parseInt(req.query.caseQuantity) const {matches, winningTickets} = await getResults() let html = `<body style="margin: 0"><div style="display: flex; align-items: center; justify-content: center; flex-direction: column; width: 100%; height: 100%; background: #1E242B;">` html += matches ? `<img src="https://img.icons8.com/color/344/checked.png" style="height: 75px;width: 75px;">` : `<img src="https://img.icons8.com/color/344/cancel.png" style="height: 75px;width: 75px;">` let ticketString = '' winningTickets.forEach((ticket, i) => { ticketString += `<h3 style="margin: 0; color: white">Case #${i + 1}: ${ticket}</h2>` }) html += matches ? `<h3 style="margin: 0; color: white">Tickets:</h3> ${ticketString}` : `<h3 style="margin: 0; color: white">Private seed hash doesn't match private seed</h3>` res.send(html) })
Loading…

no comments

    sign in to comment