Update to Anubis v1.28.2 (#1)
This upgrades the Masyunis fork from Anubis v1.25.0 to the latest stable release, **v1.28.2** (“Wuk Lamat Echo 2”), while keeping the fork’s custom styling and removals. ## Approach The Gitea repo is a tree snapshot of v1.25.0, not a git-level fork of [TecharoHQ/anubis](https://github.com/TecharoHQ/anubis). The histories share no commits, so a merge or rebase onto the upstream tag is not usable. The first commit on this branch replaces the tree with a snapshot of the **v1.28.2** tag (`git rm -r` plus `git checkout v1.28.2 -- .`; the import tree is identical to the tag). A short patch series on top restores the Masyunis customizations. ## Customizations kept - Masyunya mascots (`web/static/img/{happy,pensive,reject}.webp`), hashes match current `master`. - `web/static/img/ATTRIBUTIONS.txt` stays deleted. - Challenge footer: drop the `made_with` (Canada / maple-leaf) line and the CELPHASE mascot credit; keep “Protected by Anubis from Techaro”. The generated `web/index_templ.go` matches `go generate ./web`. - Short README (the old `anubisc` typo is fixed). - Version stamped `v1.28.2/masyunis` via Makefile ldflags. `anubis.go` `init()` does not overwrite a link-time version; `go run` / `go test` still report `devel` on purpose. - Upstream `.github`, `.devcontainer`, `.husky`, and `.vscode` stay deleted. - `"uk"` is removed from `lib/localization/locales/manifest.json` **on purpose**, because of Alpine locale problems. `uk.json` and its test entry stay; the served manifest lists 27 languages. - `package.json` `prepare` no longer runs `husky` (the hooks directory is gone). The rest of the script is unchanged. `husky` remains in devDependencies, as upstream left it. ## Deploy notes - **Cookie rename (v1.27):** with the default `DYNAMIC_COOKIE_SUFFIX=true`, cookie names become e.g. `techaro.lol-anubis-auth-<hash>`. Existing clients get a **one-time re-challenge**. That is expected, not a loop. - **Docker / ko / yeet builds** skip the Makefile ldflags, so the displayed version is `<git-version>/masyunis`. It is `v1.28.2/masyunis` only when built from a `v1.28.2` tag (or via `make build` / `make prebaked-build`). - Go 1.27.3 is required (upstream bump in v1.28.2). Thoth (`THOTH_URL` / `THOTH_TOKEN`) was removed upstream; those settings now warn and do nothing. New WASM challenge methods stay disabled unless opted in. ## Verification - `make build` succeeds. `./var/anubis --version` prints `Anubis v1.28.2/masyunis`. - `SKIP_INTEGRATION=1 go test ./...` passes (unit tests; integration package is skipped). - Local challenge/reject pages (en and ru) show Masyunya, version `v1.28.2/masyunis`, and no Canada / CELPHASE / mascot-credit text. Screenshots:   - Upstream Playwright tests (`make test` without `SKIP_INTEGRATION`) fail on this box because the browser download fails. A clean v1.28.2 tree fails the same three Playwright tests here, so this is not a fork regression. - `npm audit` reports **4** findings in upstream’s lockfile (2 moderate, 2 high: `brace-expansion`, `fast-uri`, `lodash.trim`, `source-map-js`). Left alone. Please review and merge when ready. I will not merge this myself. Reviewed-on: #1 Co-authored-by: Lead <3+lead_bot@noreply.git.unvr.site>
This commit was merged in pull request #1.
This commit is contained in:
1 parent
eb3e46d8d0
commit
caf4d72880
529 files changed
+33015
-6659
No files matched your search
@@ -0,0 +1,320 @@
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import clsx from "clsx";
|
||||
import styles from "./styles.module.css";
|
||||
|
||||
// The diagram shows a 64 bit hash rather than a full SHA-256 digest. Real
|
||||
// hashes are 256 bits, but 64 of them fit on a phone screen and the point
|
||||
// about bits versus nibbles is the same either way.
|
||||
const HASH_BYTES = 8;
|
||||
const HEX_CHARS = HASH_BYTES * 2;
|
||||
const HASH_BITS = HASH_BYTES * 8;
|
||||
|
||||
// Each row of the diagram covers four hex characters, so 16 bits.
|
||||
const HEX_PER_CHUNK = 4;
|
||||
const BITS_PER_CHUNK = HEX_PER_CHUNK * 4;
|
||||
const CHUNKS = HEX_CHARS / HEX_PER_CHUNK;
|
||||
|
||||
// A fixed starting hash so the server-rendered markup matches the first
|
||||
// client render. Mining replaces it with random hashes.
|
||||
const INITIAL_HEX = "f3a2b1c4d5e6f7a8";
|
||||
const INITIAL_BIN = hexToBin(INITIAL_HEX);
|
||||
|
||||
// Number of hashes to try per animation frame. High enough to feel like
|
||||
// mining, low enough to keep the page responsive.
|
||||
const HASHES_PER_FRAME = 200;
|
||||
|
||||
// How often the hash display is allowed to change when the reader has asked
|
||||
// for reduced motion. Mining still runs every frame; only the repaint slows
|
||||
// down, which turns a 60fps strobe into a readable ticker.
|
||||
const REDUCED_MOTION_PAINT_MS = 400;
|
||||
|
||||
// Converts a hex string into its binary expansion, four bits per character.
|
||||
function hexToBin(hex) {
|
||||
return hex
|
||||
.split("")
|
||||
.map((c) => parseInt(c, 16).toString(2).padStart(4, "0"))
|
||||
.join("");
|
||||
}
|
||||
|
||||
// Generates a random hash value in both hex and binary form.
|
||||
function generateRandomHash() {
|
||||
const buffer = new Uint8Array(HASH_BYTES);
|
||||
crypto.getRandomValues(buffer);
|
||||
const hex = Array.from(buffer)
|
||||
.map((byte) => byte.toString(16).padStart(2, "0"))
|
||||
.join("");
|
||||
return { hex, bin: hexToBin(hex) };
|
||||
}
|
||||
|
||||
// Reports whether a hash clears the target: `difficulty` leading zero bits in
|
||||
// bit mode, or `difficulty` leading zero hex characters in nibble mode.
|
||||
function meetsTarget(mode, difficulty, hex, bin) {
|
||||
const prefix = "0".repeat(difficulty);
|
||||
return mode === "bit" ? bin.startsWith(prefix) : hex.startsWith(prefix);
|
||||
}
|
||||
|
||||
// Tracks the reader's reduced motion preference. Starts false so the server
|
||||
// and the first client render agree, then corrects itself on mount.
|
||||
function usePrefersReducedMotion() {
|
||||
const [prefersReducedMotion, setPrefersReducedMotion] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
const query = window.matchMedia("(prefers-reduced-motion: reduce)");
|
||||
setPrefersReducedMotion(query.matches);
|
||||
|
||||
const handleChange = (event) => setPrefersReducedMotion(event.matches);
|
||||
query.addEventListener("change", handleChange);
|
||||
return () => query.removeEventListener("change", handleChange);
|
||||
}, []);
|
||||
|
||||
return prefersReducedMotion;
|
||||
}
|
||||
|
||||
export default function DifficultyVisualizer() {
|
||||
const [mode, setMode] = useState("nibble");
|
||||
const [difficulty, setDifficulty] = useState(1);
|
||||
const [nonce, setNonce] = useState(0);
|
||||
const [hashHex, setHashHex] = useState(INITIAL_HEX);
|
||||
const [hashBin, setHashBin] = useState(INITIAL_BIN);
|
||||
const [isMining, setIsMining] = useState(false);
|
||||
const frameRef = useRef(null);
|
||||
const untalliedRef = useRef(0);
|
||||
const lastPaintRef = useRef(0);
|
||||
const prefersReducedMotion = usePrefersReducedMotion();
|
||||
|
||||
const maxDifficulty = mode === "bit" ? HASH_BITS : HEX_CHARS;
|
||||
const isSolved = nonce > 0 && meetsTarget(mode, difficulty, hashHex, hashBin);
|
||||
const isSlow =
|
||||
(mode === "bit" && difficulty > 20) ||
|
||||
(mode === "nibble" && difficulty > 5);
|
||||
|
||||
// Drives the mining loop. Reruns whenever the target changes so the loop
|
||||
// always tests against the current mode and difficulty.
|
||||
useEffect(() => {
|
||||
if (!isMining) return;
|
||||
|
||||
const mineStep = () => {
|
||||
let found = false;
|
||||
let latest = null;
|
||||
|
||||
for (let i = 0; i < HASHES_PER_FRAME; i++) {
|
||||
untalliedRef.current++;
|
||||
latest = generateRandomHash();
|
||||
if (meetsTarget(mode, difficulty, latest.hex, latest.bin)) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Under reduced motion, keep hashing at full speed but let the display
|
||||
// settle between updates. The winning hash always paints immediately.
|
||||
const now = performance.now();
|
||||
const shouldPaint =
|
||||
found ||
|
||||
!prefersReducedMotion ||
|
||||
now - lastPaintRef.current >= REDUCED_MOTION_PAINT_MS;
|
||||
|
||||
if (shouldPaint) {
|
||||
const tried = untalliedRef.current;
|
||||
untalliedRef.current = 0;
|
||||
lastPaintRef.current = now;
|
||||
setNonce((prev) => prev + tried);
|
||||
setHashHex(latest.hex);
|
||||
setHashBin(latest.bin);
|
||||
}
|
||||
|
||||
if (found) {
|
||||
setIsMining(false);
|
||||
} else {
|
||||
frameRef.current = requestAnimationFrame(mineStep);
|
||||
}
|
||||
};
|
||||
|
||||
frameRef.current = requestAnimationFrame(mineStep);
|
||||
|
||||
return () => {
|
||||
if (frameRef.current !== null) {
|
||||
cancelAnimationFrame(frameRef.current);
|
||||
frameRef.current = null;
|
||||
}
|
||||
|
||||
// Stopping between throttled repaints would otherwise drop the hashes
|
||||
// tried since the last one, leaving the nonce reading low.
|
||||
if (untalliedRef.current > 0) {
|
||||
const tried = untalliedRef.current;
|
||||
untalliedRef.current = 0;
|
||||
setNonce((prev) => prev + tried);
|
||||
}
|
||||
};
|
||||
}, [isMining, mode, difficulty, prefersReducedMotion]);
|
||||
|
||||
const handleModeChange = (nextMode) => {
|
||||
setMode(nextMode);
|
||||
setDifficulty(1);
|
||||
setIsMining(false);
|
||||
};
|
||||
|
||||
const handleDifficultyChange = (event) => {
|
||||
setDifficulty(Number(event.target.value));
|
||||
setIsMining(false);
|
||||
};
|
||||
|
||||
const handleMineClick = () => {
|
||||
setNonce(0);
|
||||
untalliedRef.current = 0;
|
||||
lastPaintRef.current = 0;
|
||||
setIsMining(true);
|
||||
};
|
||||
|
||||
const handleStopClick = () => {
|
||||
setIsMining(false);
|
||||
};
|
||||
|
||||
// Renders one slice of the hash: a few hex characters with the bits they
|
||||
// encode lined up directly underneath them.
|
||||
const renderChunk = (chunkIndex) => {
|
||||
const hexOffset = chunkIndex * HEX_PER_CHUNK;
|
||||
const binOffset = chunkIndex * BITS_PER_CHUNK;
|
||||
const hexChunk = hashHex.slice(hexOffset, hexOffset + HEX_PER_CHUNK);
|
||||
const binChunk = hashBin.slice(binOffset, binOffset + BITS_PER_CHUNK);
|
||||
|
||||
return (
|
||||
<div key={chunkIndex} className={styles.chunk}>
|
||||
{chunkIndex === 0 && (
|
||||
<div className={styles.sectionLabel}>Hexadecimal</div>
|
||||
)}
|
||||
<div className={styles.hexRow}>
|
||||
{hexChunk.split("").map((char, localIndex) => {
|
||||
const index = hexOffset + localIndex;
|
||||
const isTarget = mode === "nibble" && index < difficulty;
|
||||
return (
|
||||
<div
|
||||
key={`hex-${index}`}
|
||||
className={clsx(
|
||||
styles.hexCell,
|
||||
isTarget && (char === "0" ? styles.cellHit : styles.cellBad),
|
||||
)}
|
||||
>
|
||||
{char}
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
|
||||
{chunkIndex === 0 && (
|
||||
<div className={styles.sectionLabel}>Binary ({HASH_BITS} bits)</div>
|
||||
)}
|
||||
<div className={styles.binRow}>
|
||||
{binChunk.split("").map((bit, localIndex) => {
|
||||
const index = binOffset + localIndex;
|
||||
const isBitTarget = mode === "bit" && index < difficulty;
|
||||
const isNibbleTarget =
|
||||
mode === "nibble" && Math.floor(index / 4) < difficulty;
|
||||
const isZero = bit === "0";
|
||||
|
||||
let state = null;
|
||||
if (isBitTarget) {
|
||||
state = isZero ? styles.cellOk : styles.cellBad;
|
||||
} else if (isNibbleTarget) {
|
||||
state = isZero ? styles.cellHit : styles.cellBad;
|
||||
}
|
||||
|
||||
return (
|
||||
<div key={`bin-${index}`} className={clsx(styles.binCell, state)}>
|
||||
{bit}
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className={styles.container}>
|
||||
{/* Controls */}
|
||||
<div className={styles.controls}>
|
||||
<div className={styles.controlGroup}>
|
||||
<span className={styles.label}>Measurement mode</span>
|
||||
<div className={styles.modeButtons}>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => handleModeChange("nibble")}
|
||||
className={clsx(
|
||||
styles.modeButton,
|
||||
mode === "nibble" && styles.modeButtonActiveHit,
|
||||
)}
|
||||
>
|
||||
Nibbles (hex)
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => handleModeChange("bit")}
|
||||
className={clsx(
|
||||
styles.modeButton,
|
||||
mode === "bit" && styles.modeButtonActiveOk,
|
||||
)}
|
||||
>
|
||||
Bits (binary)
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className={styles.controlGroup}>
|
||||
<label
|
||||
htmlFor="dv-difficulty"
|
||||
className={clsx(styles.label, styles.labelRow)}
|
||||
>
|
||||
<span>Target difficulty</span>
|
||||
<span className={styles.difficultyValue}>
|
||||
{difficulty} {mode}
|
||||
{difficulty === 1 ? "" : "s"}
|
||||
</span>
|
||||
</label>
|
||||
<input
|
||||
id="dv-difficulty"
|
||||
type="range"
|
||||
min="1"
|
||||
max={maxDifficulty}
|
||||
value={difficulty}
|
||||
onChange={handleDifficultyChange}
|
||||
className={styles.slider}
|
||||
/>
|
||||
<div className={styles.hintRow}>
|
||||
<p className={styles.hint}>
|
||||
{mode === "nibble" ? difficulty * 4 : difficulty} / {HASH_BITS}{" "}
|
||||
leading zero bits
|
||||
</p>
|
||||
{isSlow && <p className={styles.warning}>Slow</p>}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Mining dashboard */}
|
||||
<div className={styles.dashboard}>
|
||||
{!isMining && isSolved && <div className={styles.successGlow} />}
|
||||
|
||||
<div className={styles.statusRow}>
|
||||
<div className={styles.nonce}>
|
||||
Nonce:
|
||||
<span className={styles.nonceValue}>{nonce.toLocaleString()}</span>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
onClick={isMining ? handleStopClick : handleMineClick}
|
||||
className={clsx(
|
||||
styles.mineButton,
|
||||
isMining && styles.mineButtonMining,
|
||||
)}
|
||||
>
|
||||
{isMining ? "Stop mining" : "Start mining"}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className={styles.hashGrid}>
|
||||
{Array.from({ length: CHUNKS }, (_, i) => renderChunk(i))}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user