add better styling and rename pow_client => nojscap

This commit is contained in:
libroot 2025-08-06 18:33:53 +00:00
parent 0a9434be1b
commit 40ee2ea272
3 changed files with 39 additions and 27 deletions

View file

@ -32,7 +32,7 @@ function checkDifficulty(hash: Buffer, bits: number): boolean {
return true;
}
app.get('/', (_req: Request, res: Response) => {
app.get('/NOJSCAP-demo', (_req: Request, res: Response) => {
const challenge = generateChallenge();
challengeStore.set(challenge, Date.now());
res.send(`
@ -49,6 +49,10 @@ app.get('/', (_req: Request, res: Response) => {
background: #cacaca;
color: black;
}
::selection {
background: #a60000;
color: white;
}
code {
white-space: break-spaces;
background: black;
@ -94,36 +98,36 @@ $ cd NOJSCAP/client/</code>
<strong>Python:</strong>
</p>
<p>
<input type="text" value="python3 pow_client.py ${challenge} ${DIFFICULTY}">
<input type="text" value="python3 nojscap.py ${challenge} ${DIFFICULTY}">
</p>
<p>
<strong>Go:</strong>
</p>
<p>
<input type="text" value="go run pow_client.go ${challenge} ${DIFFICULTY}">
<input type="text" value="go run nojscap.go ${challenge} ${DIFFICULTY}">
</p>
<p>
<strong>Node.js:</strong>
</p>
<p>
<input type="text" value="node pow_client.js ${challenge} ${DIFFICULTY}">
<input type="text" value="node nojscap.js ${challenge} ${DIFFICULTY}">
</p>
<p>
<strong>Rust:</strong>
</p>
<p>
<details><summary>Show compilation commands</summary><code>$ rustc pow_client.rs -o pow_client_rs</code>
<details><summary>Show compilation commands</summary><code>$ rustc nojscap.rs -o nojscap_rs</code>
<small>Requires Rust and sha2 crate if using the Cargo version.</small><br></details>
<input type="text" value="pow_client_rs ${challenge} ${DIFFICULTY}">
<input type="text" value="nojscap_rs ${challenge} ${DIFFICULTY}">
</p>
<p>
<strong>C:</strong>
</p>
<p>
<details><summary>Show compilation commands</summary><code>$ gcc -O2 -o pow_client pow_client.c -lssl -lcrypto</code>
<details><summary>Show compilation commands</summary><code>$ gcc -O2 -o nojscap nojscap.c -lssl -lcrypto</code>
<small>Required: GCC or any C compiler. OpenSSL development libraries (libssl-dev on Debian-based systems)</small><br></details>
<input type="text" value="./pow_client ${challenge} ${DIFFICULTY}">
<input type="text" value="./nojscap ${challenge} ${DIFFICULTY}">
</p>
<form method="POST">
@ -136,7 +140,7 @@ $ cd NOJSCAP/client/</code>
`);
});
app.post('/', (req: Request, res: Response) => {
app.post('/NOJSCAP-demo', (req: Request, res: Response) => {
const { challenge, nonce } = req.body as { challenge?: string; nonce?: string };
if (!challenge || !nonce || !challengeStore.has(challenge)) {
return res.send('Invalid input.');
@ -145,10 +149,10 @@ app.post('/', (req: Request, res: Response) => {
challengeStore.delete(challenge);
const hash = hashSha256(challenge + nonce);
if (checkDifficulty(hash, DIFFICULTY)) {
res.send('<p>Success! Valid nonce.</p><a href="/">Try again</a>');
res.send('<div style="text-align:center;"><h1>Success! Valid nonce.</h1><a href="?">Try again</a></div>');
} else {
res.send('<p>Invalid nonce.</p><a href="/">Try again</a>');
res.send('<div style="text-align:center;"><h1>Invalid nonce.</h1><a href="?">Try again</a></div>');
}
});
app.listen(3000, () => console.log('Server running at http://localhost:3000'));
app.listen(3000, () => console.log('/NOJSCAP-demo server running at http://localhost:3000'));