Here's a thinking process that leads to the suggested HTML/CSS/JS solution:
-
Analyze the User's Request:
- Topic: Cryptographic audit trail for legal document collaboration.
- Key Features: Event hashing, append-only storage, notarization workflows, dispute resolution.
- Role/Aesthetic: Advanced front-end engineer & visual designer specializing in Neo-Brutalism & Y2K. The aesthetic should be raw, rough, high-contrast, clashing colors, unpolished, use hard borders, big typography, glitch effects, etc.
- Constraints: Single HTML file, no external frameworks (though GSAP was mentioned in the prompt's "Technical Stack" as a preference for the persona, the system prompt says "Do not use front-end frameworks... unless the user explicitly requests them." The user asked for a "cryptographic audit trail." I should implement the logic of these features using vanilla JS (or lightweight libraries if strictly needed, but pure JS is safer/cleaner). I will emulate "GSAP-like" animation with CSS or raw JS to keep it self-contained and robust, respecting the "raw" nature of the aesthetic. However, the persona wants to use Tailwind/GSAP. The system prompt says "Do not use front-end frameworks... unless the user explicitly requests them." The user didn't explicitly request Tailwind or GSAP, they requested a concept. My persona instruction says to use Tailwind/GSAP. There's a conflict. System prompt overrides persona instruction when they conflict. Correction: The system prompt says "Do not use front-end frameworks... unless the user explicitly requests them." The user did not request Tailwind/GSAP. Therefore, I must use Vanilla HTML/CSS/JS. However, I can mimic the style of Tailwind classes in custom CSS for a single file, but I cannot import the massive Tailwind library via CDN reliably if we want a truly self-contained file without external dependencies (though CDN is often okay, strict "self-contained" implies few external requests). I will stick to Vanilla CSS for maximum control and "raw" feel, and Vanilla JS for the cryptographic simulation.
- Language: English (user input is English).
-
Deconstruct the "Neo-Brutalism/Y2K" Aesthetic for this Specific Application:
- Theme: Legal/Technical but chaotic.
- Colors: Stark black/white background, with neon green (terminal/success), probation orange (warning), bright red (dispute/error), electric blue (info).
- Typography: Monospace (Courier, VT323) for data/code, giant Bold Sans Serif (Impact, Arial Black) for headers. Some text should be "glitched".
- Layout: Grid-like, overlapping elements, hard borders (2px black), box-shadows that aren't blurry but offset "brutalist" shadows (e.g.,
box-shadow: 4px 4px 0px 0px #000).
- UI Elements: Buttons that look like Windows 95/98 (bevels/borders) but with neon colors. Marquees everywhere. ASCII art borders.
-
Define the Functional Requirements (Simulation):
Since this is a front-end demo, we can't build a real blockchain or cryptographic backend in one file. We must simulate the experience.
- Event Hashing: Display a hash of a document or event. Simulate SHA-256 generation (maybe just random hex strings that look consistent).
- Append-Only Storage: A log viewer that shows "blocks" being added. It should read-only, immutable visual scrolling.
- Notarization Workflows: A section where a user "signs" a document. It should show a certificate or a timestamped seal.
- Dispute Resolution: An interface to "flag" an event or view a verification status (valid/invalid).
-
Drafting the Architecture (Single HTML):
-
HTML Structure:
<header>: Giant title, marquee text.
<main>: Three columns (Visually sectioned).
- Column 1: The Workspace / Document Upload.
- Column 2: The Audit Trail (The "Chain").
- Column 3: Verification / Disputes.
<footer>: Scrolling credits.
-
CSS (Style):
- CSS Variables for colors (Black, White, NeonGreen, HotPink, etc.).
- Global resets.
.brutal-box: 4px solid black, thick offset shadows, solid bg colors.
.marquee: CSS animation.
.glitch: Keyframes with clip-path and transform.
- Fonts: Import a Google Font like
VT323 (retro terminal) and Bungee or Impact (heavy headings).
-
JavaScript (Logic):
- State: Simple array of "blocks". Each block contains: index, timestamp, previousHash, data (event), currentHash, signature.
- Functions:
calculateHash(index, prevHash, data) -> Simulated crypto.
addBlock(eventType, description) -> Adds to the chain, updates UI.
renderChain() -> Draws the vertical list.
notarizeDocument(docID) -> Simulates a notary event, adds a block.
initiateDispute(blockIndex) -> Highlights block, changes status to "Under Review".
-
Step-by-Step Implementation Plan:
- Step 1: Skeleton & Styling Setup. Define the raw look.
- Step 2: Visual Components. Create the "Terminal" window for the hash display. Create the "Chain" container.
- Step 3: JS Logic - The Blockchain Sim. Create the class/object to manage blocks. Implement simple hash generation (dummy but deterministic based on string concatenation).
- Step 4: Interactivity. Buttons to trigger events: "Upload Doc", "Sign/Notarize", "Create Dispute". These should visually add items to the chain.
- Step 5: Polish. Add glitch effects on hover, sound effects (optional, maybe too complex for restrictions, sticking to visual), marquee movement.
-
Refining the Design (Self-Correction during thought process):
- Critique: Is it too messy?
- Fix: Keep the "core" chain in a centered column to maintain readability, even if the surroundings are chaotic. The borders should be crisp.
- Feature: "Event Hashing". I need to show the hash string. I'll make a distinct box that looks like a cryptographic fingerprint (long string of hex).
- Feature: "Notarization". I need an image or icon of a seal. Since I can't use external images arbitrarily, I'll use CSS or SVG to draw a "Notary Seal" (a circle with a star).
- Feature: "Dispute Resolution". A button that toggles a "red flag" state on a block.
-
Writing the Code (Mental Draft & Translation to Output):
- HTML Head: Include Google Fonts (Bungee, VT323). CSS styles.
- CSS:
.brutalist: border: 3px solid #000; box-shadow: 5px 5px 0px 0px #000; background: #fff;
.marquee: flex overflow, animation translate X.
.glitch: position: relative; pseudo-elements for color channels.
- JS:
class AuditTrail { constructor() { this.chain = [this.createGenesis()]; } ... }
- Every time a user action occurs, generate a block and prepend/append.
- Use
requestAnimationFrame or setInterval to simulate "mining" or calculating hash with a loading bar (crucial for the "tech" feel).
-
Detailed UX Flow:
- Page loads. Big bold title: "CRYPTO LEGAL // AUDIT PROTOCOL".
- Left panel: "Document Entry". Input field + "Upload/Notarize" button. (Actions: Create doc, Notarize).
- Center panel: "Immutable Log". Shows blocks vertically. Each block has: Index, Hash (Prev & Curr), Event Type, Timestamp, Status Verified/Disputed.
- Right panel: "Verification Console". Outputs the current chain status. Buttons to "Dispute" selected block.
- Marquee at top and bottom: "SECURE • DECENTRALIZED • IRREVERSIBLE".
-
Adding the "Neo-Brutalism/Y2K" Glitter:
- Use
cursor: crosshair.
- Use
background: repeating-linear-gradient(...) for some borders or backgrounds to give a scanline effect.
- Button active state:
transform: translate(2px, 2px); box-shadow: 0px 0px 0px 0px #000; (classic brutalist press).
- Diagonal stripes pattern for "hash validated".
-
Final Code Assembly & Check:
- Does it use
alert()? No, use a custom "System Log" div for messages.
- Is it one file? Yes.
- Is the interaction clear? Yes.
- Are the features (hashing, append-only, notarization, dispute) represented? Yes.
(Self-Correction on Complexity): The user asked for "Advanced front-end engineer". I should ensure the code is structured cleanly using ES6 classes and modular functions, even within a single file, to show "professional knowledge" but keep the visuals raw/ugly (in a good way). The contrast between sophisticated logic and ugly UI is part of the charm.
-
Final Polish of the Output:
- Ensure all comments explain the "why" behind the raw design.
- Make sure the hash simulation looks "cryptographic" (e.g., double SHA-256 mock).
- Add a "Verifier" tool to check if a block is tampered (by modifying data and recalculating hash).
-
Producing the HTML. (Proceed to generate the code based on these thoughts).
(Detailed check on specific prompt requirement: "Event hashing, append-only storage, notarization workflows, and dispute resolution.")
- Event Hashing: Visualized as the block's ID and the fingerprint strings.
- Append-Only: The UI is a feed, no delete buttons, blocks are displayed as a chain.
- Notarization: A specific event type "DOCUMENT_NOTARIZED" that triggers a visual seal animation/graphic.
- Dispute Resolution: A button to flag a block as disputed, changing its visual state (red border) and logging the dispute.
Let's write the code.
Here is a complete, single-file HTML solution. It implements a functional simulation of a cryptographic audit trail for legal documents. The visuals strictly follow the Neo-Brutalism/Y2K aesthetic: raw, high-contrast, unpolished, and aggressive.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CRYPT AUDIT // LEGAL PROTOCOL</title>
<!-- Importing retro/display fonts to match the Y2K aesthetic -->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Bungee+Shade&family=Courier+Prime:wght@400;700&family=VT323&display=swap" rel="stylesheet">
<style>
/* =========================================
CORE VARIABLES & RESET
========================================= */
:root {
--c-black: #000000;
--c-white: #ffffff;
--c-acid: #ccff00; /* Acid green */
--c-neon: #ff00ff; /* Magenta */
--c-cyan: #00ffff; /* Electric blue */
--c-warn: #ff6600; /* Safety orange */
--c-alert: #ff0000; /* Red */
--c-dim: #e0e0e0;
--border-width: 3px;
--shadow-offset: 6px;
}
* {
box-sizing: border-box;
cursor: crosshair; /* Raw feel */
}
body {
margin: 0;
padding: 0;
background-color: var(--c-white);
color: var(--c-black);
font-family: 'Courier Prime', monospace; /* Default to raw text */
overflow-x: hidden;
background-image: radial-gradient(#000 1px, transparent 1px);
background-size: 40px 40px; /* Grid pattern */
}
/* =========================================
TYPOGRAPHY
========================================= */
h1, h2, h3 {
font-family: 'Bungee Shade', cursive;
margin: 0;
line-height: 1.1;
text-transform: uppercase;
}
.mono { font-family: 'Courier Prime', monospace; }
.retro { font-family: 'VT323', monospace; }
/* Glitch Text Effect */
.glitch {
position: relative;
color: var(--c-black);
}
.glitch::before, .glitch::after {
content: attr(data-text);
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: var(--c-white);
}
.glitch::before {
left: 2px;
text-shadow: -1px 0 var(--c-neon);
clip-path: inset(44% 0 61% 0);
animation: glitch-anim 2s infinite linear alternate-reverse;
}
.glitch::after {
left: -2px;
text-shadow: -1px 0 var(--c-cyan);
clip-path: inset(12% 0 56% 0);
animation: glitch-anim-2 3s infinite linear alternate-reverse;
}
@keyframes glitch-anim {
0% { clip-path: inset(20% 0 30% 0); }
20% { clip-path: inset(60% 0 10% 0); }
40% { clip-path: inset(40% 0 80% 0); }
60% { clip-path: inset(80% 0 5% 0); }
80% { clip-path: inset(10% 0 60% 0); }
100% { clip-path: inset(30% 0 20% 0); }
}
@keyframes glitch-anim-2 {
0% { clip-path: inset(10% 0 60% 0); }
20% { clip-path: inset(30% 0 20% 0); }
40% { clip-path: inset(80% 0 5% 0); }
60% { clip-path: inset(40% 0 80% 0); }
80% { clip-path: inset(60% 0 10% 0); }
100% { clip-path: inset(20% 0 30% 0); }
}
/* =========================================
LAYOUT UTILITIES (Brutalist Grid)
========================================= */
.container {
max-width: 1400px;
margin: 0 auto;
padding: 20px;
display: grid;
grid-template-columns: 1fr 1.5fr 1fr;
gap: 30px;
}
section {
display: flex;
flex-direction: column;
gap: 20px;
}
/* Responsive */
@media (max-width: 1000px) {
.container { grid-template-columns: 1fr; }
}
/* =========================================
COMPONENTS: BRUTALIST CONTAINERS
========================================= */
.box {
background: var(--c-white);
border: var(--border-width) solid var(--c-black);
box-shadow: var(--shadow-offset) var(--shadow-offset) 0 0 var(--c-black);
padding: 20px;
position: relative;
transition: transform 0.1s, box-shadow 0.1s;
}
.box:hover {
transform: translate(-2px, -2px);
box-shadow: calc(var(--shadow-offset) + 2px) calc(var(--shadow-offset) + 2px) 0 0 var(--c-black);
}
.box.crimson { background: #ffcccc; border-color: var(--c-alert); }
.box.acid { background: #e0ff6b; border-color: var(--c-acid); }
.box.cyan { background: #ccffff; border-color: var(--c-cyan); }
.box.warn { background: #ffe0b2; border-color: var(--c-warn); }
.btn {
font-family: 'Bungee Shade', cursive;
font-size: 1.2rem;
padding: 15px 25px;
border: var(--border-width) solid var(--c-black);
background: var(--c-acid);
color: var(--c-black);
cursor: pointer;
text-transform: uppercase;
box-shadow: 4px 4px 0 0 var(--c-black);
transition: all 0.1s;
width: 100%;
margin-top: 10px;
text-align: center;
}
.btn:hover {
transform: translate(-2px, -2px);
box-shadow: 6px 6px 0 0 var(--c-black);
background: #fff;
}
.btn:active {
transform: translate(2px, 2px);
box-shadow: 0 0 0 0 var(--c-black);
}
.btn-dispute { background: var(--c-alert); color: white; }
.btn-verify { background: var(--c-cyan); }
/* =========================================
MARQUEE
========================================= */
.marquee-container {
width: 100%;
border-bottom: var(--border-width) solid var(--c-black);
background: var(--c-black);
color: var(--c-acid);
overflow: hidden;
white-space: nowrap;
padding: 10px 0;
font-family: 'VT323', monospace;
font-size: 1.5rem;
position: sticky;
top: 0;
z-index: 100;
}
.marquee-content {
display: inline-block;
animation: marquee 20s linear infinite;
}
@keyframes marquee {
0% { transform: translateX(100vw); }
100% { transform: translateX(-100%); }
}
/* =========================================
AUDIT CHAIN VISUALIZATION
========================================= */
.chain-list {
display: flex;
flex-direction: column;
gap: 20px;
padding-left: 20px;
position: relative;
}
/* Vertical connecting line */
.chain-list::before {
content: '';
position: absolute;
left: 30px; /* Align with blocks */
top: 20px;
bottom: 20px;
width: 4px;
background: var(--c-black);
z-index: 0;
}
.block-item {
display: flex;
align-items: center;
gap: 20px;
position: relative;
z-index: 1;
opacity: 0;
animation: popIn 0.3s forwards cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
@keyframes popIn {
from { opacity: 0; transform: scale(0.9) translateX(-20px); }
to { opacity: 1; transform: scale(1) translateX(0); }
}
.block-icon {
width: 60px;
height: 60px;
background: var(--c-cyan);
border: var(--border-width) solid var(--c-black);
display: flex;
align-items: center;
justify-content: center;
font-weight: bold;
font-size: 1.5rem;
box-shadow: 4px 4px 0 0 var(--c-black);
flex-shrink: 0;
}
.block-content {
flex-grow: 1;
}
.block-header {
display: flex;
justify-content: space-between;
border-bottom: 2px dotted var(--c-black);
margin-bottom: 8px;
padding-bottom: 4px;
}
.hash-string {
font-size: 0.75rem;
word-break: break-all;
background: #eee;
padding: 4px;
border: 1px solid var(--c-black);
font-family: 'Courier Prime', monospace;
margin-top: 5px;
}
.tag {
font-size: 0.8rem;
padding: 2px 8px;
text-transform: uppercase;
font-weight: bold;
border: 2px solid var(--c-black);
}
.tag.notary { background: var(--c-acid); border-color: var(--c-black); }
.tag.upload { background: var(--c-cyan); }
.tag.dispute { background: var(--c-alert); color: var(--c-white); border-color: white; }
/* Notary Seal Animation */
.notary-seal {
width: 50px;
height: 50px;
border: 3px dashed var(--c-warn);
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
position: absolute;
bottom: 0;
right: -10px;
transform: rotate(-15deg);
opacity: 0.8;
background: rgba(255, 255, 255, 0.5);
font-size: 1.2rem;
color: var(--c-warn);
pointer-events: none;
}
.block-item.disputed .block-content {
background: repeating-linear-gradient(
45deg,
#ffcccc,
#ffcccc 5px,
#ffaaaa 5px,
#ffaaaa 10px
);
}
.block-item.disputed {
border: 2px solid var(--c-alert);
animation: shake 0.5s;
}
@keyframes shake {
0% { transform: translateX(0); }
25% { transform: translateX(-5px); }
50% { transform: translateX(5px); }
75% { transform: translateX(-5px); }
100% { transform: translateX(0); }
}
/* =========================================
TERMINAL / LOG OUTPUT
========================================= */
.terminal {
background: #000;
color: var(--c-acid);
font-family: 'VT323', monospace;
padding: 15px;
height: 300px;
overflow-y: auto;
border: var(--border-width) solid var(--c-black);
font-size: 1.2rem;
margin-top: auto;
}
.terminal-header {
background: var(--c-black);
color: white;
padding: 5px 10px;
font-family: 'Courier Prime', monospace;
font-weight: bold;
border-bottom: 2px solid var(--c-acid);
}
.log-entry { margin-bottom: 5px; }
.log-success { color: var(--c-acid); }
.log-error { color: var(--c-alert); }
.log-info { color: var(--c-cyan); }
/* =========================================
LOADING / PROCESSING
========================================= */
.processing-overlay {
position: absolute;
inset: 0;
background: rgba(255,255,255,0.8);
display: flex;
align-items: center;
justify-content: center;
font-size: 2rem;
font-weight: bold;
z-index: 10;
display: none;
}
.processing-overlay.active { display: flex; }
.scanline {
width: 100%;
height: 2px;
background: var(--c-cyan);
position: absolute;
top: 0;
animation: scan 1s infinite linear;
box-shadow: 0 0 10px var(--c-cyan);
}
@keyframes scan {
0% { top: 0%; opacity: 1; }
50% { opacity: 0.5; }
100% { top: 100%; opacity: 1; }
}
/* Windows 95 Style Scrollbar (Just for fun) */
::-webkit-scrollbar { width: 12px; }
::-webkit-scrollbar-track { background: #f0f0f0; border: 2px solid var(--c-black); }
::-webkit-scrollbar-thumb { background: var(--c-acid); border: 2px solid var(--c-black); }
</style>
</head>
<body>
<!-- Top Marquee -->
<div class="marquee-container">
<div class="marquee-content">
🚨 CRYPTOGRAPHIC AUDIT PROTOCOL INITIALIZED --- IMMUTABLE LEDGER ACTIVE --- NOTARIZATION WORKFLOW ENGAGED --- DISPUTE RESOLUTION STANDBY 🚨
</div>
</div>
<div class="container">
<!-- SIDEBAR 1: CONTROLS -->
<section>
<div class="box acid">
<h2 class="glitch" data-text="DOCUMENT UPLOAD">DOCUMENT UPLOAD</h2>
<div class="mono" style="margin-top: 10px;">
<label>DOCUMENT HASH (SHA-256):</label><br>
<input type="text" id="docHashInput" placeholder="Paste file hash here..."
style="width: 100%; padding: 10px; border: 2px solid black; font-family: 'Courier Prime'; margin-bottom: 10px;">
<div id="docPreview" style="border: 2px dashed black; padding: 10px; min-height: 80px; margin-bottom: 10px; opacity: 0.5;">
/// WAITING FOR HASH INPUT ///
</div>
<button class="btn" id="btnUpload">UPLOAD TO LEDGER</button>
<button class="btn" style="background: var(--c-cyan)" id="btnNotarize">SIGN & NOTARIZE</button>
</div>
</div>
<div class="box warn">
<h2 class="glitch" data-text="SYSTEM METRICS">SYSTEM METRICS</h2>
<div class="mono">
<p>CHAIN HEIGHT: <span id="chainHeight" class="retro">0</span></p>
<p>DIFFICULTY: <span class="retro">000000</span> (TESTNET)</p>
<p>NODE PEERS: <span class="retro">4</span></p>
<p>LATENCY: <span class="retro">12ms</span></p>
</div>
</div>
</section>
<!-- CENTER: THE CHAIN -->
<section>
<div class="box" style="background: #f9f9f9;">
<div style="display: flex; justify-content: space-between; align-items: center;">
<h2>IMMUTABLE LOG</h2>
<div class="mono" style="font-size: 0.8rem; background: black; color: lime; padding: 4px;">
MODE: VERIFIED
</div>
</div>
<!-- Chain Visualization -->
<div class="chain-list" id="chainList">
<!-- Blocks will be injected here JS -->
<div class="box mono" style="border-style: dashed; text-align: center; opacity: 0.6;">
NO BLOCKCHAIN DATA YET.<br>WAITING FOR TRANSACTIONS...
</div>
</div>
</div>
</section>
<!-- SIDEBAR 2: VERIFICATION & DISPUTE -->
<section>
<div class="box crimson">
<h2 class="glitch" data-text="VERIFY / DISPUTE">VERIFY / DISPUTE</h2>
<div class="mono" style="margin-bottom: 15px;">
SELECT A BLOCK INDEX TO INSPECT:
<div style="display: flex; gap: 5px; margin-top: 5px;">
<input type="number" id="inspectIndex" min="0" style="width: 80px; border: 2px solid black; padding: 5px;">
<button class="btn" style="padding: 5px 10px; font-size: 0.8rem; width: auto; margin: 0;" id="btnInspect">CHECK</button>
</div>
</div>
<!-- Inspection Result -->
<div id="inspectResult" class="mono" style="min-height: 150px; border: 2px solid black; background: #fff; padding: 10px;">
/// SELECT A BLOCK AND PRESS CHECK ///
</div>
<hr style="border: 0; border-top: 2px solid black; margin: 10px 0;">
<div class="mono">
<p>TRIGGER DISPUTE RESOLUTION:</p>
<p style="font-size: 0.8rem; color: #555;">Flag the selected block as contested. Requires manual override to override chain consensus.</p>
<button class="btn btn-dispute" id="btnDispute">🚨 FILE DISPUTE 🚨</button>
</div>
</div>
<!-- System Log -->
<div style="flex-grow: 1; display: flex; flex-direction: column;">
<div class="terminal-header">SYSTEM LOG STREAM</div>
<div class="terminal" id="sysLog">
<div class="log-entry log-info">> SYSTEM INITIALIZED...</div>
<div class="log-entry log-info">> WAITING FOR DOCUMENT HASH...</div>
</div>
</div>
</section>
</div>
<!-- Bottom Marquee -->
<div class="marquee-container" style="bottom: 0; position: fixed; z-index: 100;">
<div class="marquee-content" style="animation-direction: reverse;">
© 1999-2023 CRYPTO LEGAL INC. /// ALL RIGHTS RESERVED /// NO UNAUTHORIZED DELETION PERMITTED ///
</div>
</div>
<script>
/**
* CRYPTO AUDIT TRAIL ENGINE (Simulated)
* Handles block generation, hashing, and chain management.
*/
// --- Utilities ---
// Simulate a cryptographic hash (SHA-256 mock)
// In a real app, use SubtleCrypto or a library like SHA.js.
// Here we generate a deterministic-ish hex string from inputs.
function simpleHash(str) {
let hash = 0;
for (let i = 0; i < str.length; i++) {
const char = str.charCodeAt(i);
hash = ((hash << 5) - hash) + char;
hash = hash & hash; // Convert to 32bit integer
}
// Convert to hex and pad to look like a digest
return Math.abs(hash).toString(16).padStart(8, '0') +
Math.random().toString(16).substr(2, 8).toUpperCase();
}
// Generate a full fake 64-char hex string
function generateFakeHash() {
const chars = '0123456789ABCDEF';
let result = '';
for (let i = 0; i < 64; i++) {
result += chars[Math.floor(Math.random() * chars.length)];
}
return result;
}
// Format timestamp
function getTimestamp() {
const now = new Date();
return now.toISOString().replace('T', ' ').substr(0, 19);
}
// --- The Blockchain Class ---
class AuditChain {
constructor() {
this.chain = [];
this.pendingBlocks = [];
this.createGenesis();
}
createGenesis() {
const genBlock = {
index: 0,
previousHash: '00000000000000000000000000000000',
timestamp: '1999-01-01 00:00:00',
event: 'GENESIS_BLOCK_CREATED',
data: 'SYSTEM INITIALIZATION',
hash: generateFakeHash(),
status: 'VERIFIED'
};
this.chain.push(genBlock);
return genBlock;
}
// Calculate hash of a block (deterministic for verification)
calculateBlockHash(block) {
const str = block.index + block.previousHash + block.timestamp + block.event + block.data;
// For demo, we mix a pseudo-crypto with a random seeding based on string
return simpleHash(str) + simpleHash(str.substring(0, 10)); // 32+ chars
}
async addBlock(eventType, data, isNotary = false) {
// Simulate network delay / mining
await new Promise(r => setTimeout(r, 800));
const lastBlock = this.chain[this.chain.length - 1];
const newBlock = {
index: lastBlock.index + 1,
previousHash: lastBlock.hash,
timestamp: getTimestamp(),
event: eventType,
data: data,
hash: '', // Will fill after calculating
status: 'VERIFIED',
notarySeal: isNotary
};
// Lock timestamp and hash generation
newBlock.hash = this.calculateBlockHash(newBlock);
this.chain.push(newBlock);
ui.renderChain();
ui.log(`[BLOCK #${newBlock.index}] MINED & ADDED. HASH: ${newBlock.hash.substr(0,16)}...`, 'success');
}
// Check integrity of the chain
validateChain() {
for (let i = 1; i < this.chain.length; i++) {
const current = this.chain[i];
const prev = this.chain[i-1];
const recalcHash = this.calculateBlockHash(current);
// Note: In real strict blockchain, we compare stored hash.
// For this demo, we regenerate to prove "mathematical structure" holds.
// But if we want to check tampering, we just ensure prevHash matches stored prev's hash.
if (current.previousHash !== prev.hash) {
return false;
}
}
return true;
}
getBlock(index) {
return this.chain[index];
}
}
// --- UI Manager ---
class UIManager {
constructor(chainInstance) {
this.chain = chainInstance;
this.chainListEl = document.getElementById('chainList');
this.logEl = document.getElementById('sysLog');
this.heightEl = document.getElementById('chainHeight');
this.previewEl = document.getElementById('docPreview');
this.inspectResultEl = document.getElementById('inspectResult');
// Event Listeners
this.bindEvents();
this.updateHeight();
}
bindEvents() {
// Upload Button
document.getElementById('btnUpload').addEventListener('click', () => {
const hashInput = document.getElementById('docHashInput').value.trim();
if (!hashInput) {
this.log("ERROR: EMPTY DOCUMENT HASH INPUT", 'error');
this.shakeElement(document.getElementById('docHashInput'));
return;
}
this.chain.addBlock('DOC_UPLOADED', `DocHash: ${hashInput}`);
});
// Notarize Button
document.getElementById('btnNotarize').addEventListener('click', () => {
const hashInput = document.getElementById('docHashInput').value.trim();
if (!hashInput) {
this.log("ERROR: CANNOT NOTARIZE EMPTY DOCUMENT", 'error');
this.shakeElement(document.getElementById('docHashInput'));
return;
}
this.chain.addBlock('DOC_NOTARIZED', `DocHash: ${hashInput} | NotaryID: 0xFF22`, true);
});
// Inspect Button
document.getElementById('btnInspect').addEventListener('click', () => {
const idx = parseInt(document.getElementById('inspectIndex').value);
this.renderInspection(idx);
});
// Dispute Button
document.getElementById('btnDispute').addEventListener('click', () => {
const idx = parseInt(document.getElementById('inspectIndex').value);
const block = this.chain.getBlock(idx);
if (block) {
if (block.status === 'DISPUTED') {
this.log(`BLOCK ${idx} ALREADY IN DISPUTE.`, 'error');
} else {
block.status = 'DISPUTED';
this.log(`[CRITICAL] DISPUTE FILED FOR BLOCK #${idx}. FLAGGING...`, 'error');
this.renderChain(); // Re-render to show visual change
this.renderInspection(idx);
this.triggerGlitchEffect();
}
} else {
this.log(`INVALID INDEX: ${idx}`, 'error');
}
});
// Input listener for preview
document.getElementById('docHashInput').addEventListener('input', (e) => {
if(e.target.value.length > 0) {
this.previewEl.innerHTML = `<span style="color:var(--c-cyan)">/// HASH DETECTED ///</span><br><code>${e.target.value}</code><br><span class="retro">READY FOR NOTARIZATION</span>`;
this.previewEl.style.opacity = "1";
} else {
this.previewEl.innerHTML = '/// WAITING FOR HASH INPUT ///';
this.previewEl.style.opacity = "0.5";
}
});
}
renderChain() {
this.chainListEl.innerHTML = '';
this.updateHeight();
// Reverse order to show latest at top? Usually newest at bottom/right.
// Let's do vertical stack with newest at top for visibility.
const sortedChain = [...this.chain].reverse();
sortedChain.forEach(block => {
const el = document.createElement('div');
el.className = `block-item ${block.status === 'DISPUTED' ? 'disputed' : ''}`;
// Determine Icon Color/Text based on Event
let iconColor = '#fff';
let iconText = 'U';
if (block.event.includes('NOTARIZE')) { iconColor = 'var(--c-acid)'; iconText = 'N'; }
if (block.event.includes('DISPUTE') || block.status === 'DISPUTED') { iconColor = 'var(--c-alert)'; iconText = '!'; }
// Determine Tag HTML
let tagHtml = '';
if(block.event.includes('NOTARIZE')) tagHtml = '<span class="tag notary">SIGNED & SEALED</span>';
else if(block.event.includes('UPLOAD')) tagHtml = '<span class="tag upload">DOCUMENT HASHED</span>';
else tagHtml = `<span class="tag">${block.event}</span>`;
// Notary Seal Overlay
let sealHtml = '';
if (block.notarySeal) {
sealHtml = `<div class="notary-seal">NOTARY</div>`;
}
el.innerHTML = `
<div class="block-icon" style="background:${iconColor}">${iconText}</div>
<div class="block-content box" style="padding:10px; box-shadow: 3px 3px 0 0 var(--c-black);">
${sealHtml}
<div class="block-header">
<strong class="retro">#${block.index}</strong>
${tagHtml}
<span class="retro" style="font-size:0.8rem">${block.timestamp}</span>
</div>
<div style="margin-bottom: 5px; font-weight:bold;">${block.data}</div>
<div class="mono" style="font-size:0.7rem; color:#555;">
PREV: ${block.previousHash.substr(0,16)}...
</div>
<div class="mono hash-string" style="background:${block.status === 'DISPUTED' ? '#ffcccc' : '#eee'}">
HASH: ${block.hash}
</div>
${block.status === 'DISPUTED' ? '<div style="position:absolute; top:0; left:0; width:100%; height:100%; background:rgba(255,0,0,0.1); pointer-events:none;"></div>' : ''}
</div>
`;
this.chainListEl.appendChild(el);
});
}
renderInspection(index) {
const block = this.chain.getBlock(index);
if (!block) {
this.inspectResultEl.innerHTML = `<span class="log-error">ERROR: BLOCK INDEX ${index} NOT FOUND.</span>`;
return;
}
const isTampered = block.previousHash !== this.chain.getBlock(index-1)?.hash && index > 0;
let html = `
<div style="border-bottom: 2px solid black; padding-bottom: 10px; margin-bottom: 10px;">
<strong class="retro">BLOCK ANALYSIS REPORT</strong><br>
INDEX: ${block.index}
</div>
<div style="margin-bottom: 8px;">
EVENT TYPE:<br>
<span style="background:var(--c-acid); padding:2px 5px; border:1px solid black;">${block.event}</span>
</div>
<div style="margin-bottom: 8px;">
TIMESTAMP:<br>
${block.timestamp}
</div>
<div style="margin-bottom: 8px;">
CURRENT HASH:<br>
<code style="font-size:0.8rem; display:block; word-break:break-all; background:#000; color:lime;">${block.hash}</code>
</div>
<div style="margin-bottom: 8px;">
PREV HASH:<br>
<code style="font-size:0.8rem; display:block; word-break:break-all;">${block.previousHash}</code>
</div>
<div style="margin-bottom: 10px;">
VERIFICATION STATUS: <strong style="color:${block.status === 'VERIFIED' ? 'green' : 'red'}">${block.status}</strong>
</div>
`;
if (block.status === 'DISPUTED') {
html += `<div class="log-error" style="border:2px solid red; padding:5px;">⚠️ THIS BLOCK IS UNDER LEGAL REVIEW. HASH VALIDITY UNCONFIRMED BY CONSENSUS.</div>`;
} else if (isTampered) {
html += `<div class="log-error" style="border:2px solid red; padding:5px;">⚠️ CHAIN INTEGRITY COMPROMISED! PREV_HASH MISMATCH.</div>`;
} else {
html += `<div class="log-success" style="border:2px solid green; padding:5px;">✅ CRYPTOGRAPHIC PROOF OF INTEGRITY VALID.</div>`;
}
this.inspectResultEl.innerHTML = html;
}
log(msg, type = 'info') {
const entry = document.createElement('div');
entry.className = `log-entry log-${type}`;
entry.textContent = `> ${msg}`;
this.logEl.prepend(entry); // Newest top
// Limit log size
if (this.logEl.children.length > 50) {
this.logEl.lastElementChild.remove();
}
}
updateHeight() {
this.heightEl.textContent = this.chain.length;
}
shakeElement(el) {
el.animate([
{ transform: 'translateX(0)' },
{ transform: 'translateX(-10px)' },
{ transform: 'translateX(10px)' },
{ transform: 'translateX(0)' }
], {
duration: 300,
iterations: 1
});
}
triggerGlitchEffect() {
document.body.animate([
{ filter: 'grayscale(0)' },
{ filter: 'grayscale(100%) invert(100%)' },
{ filter: 'grayscale(0)' }
], {
duration: 200,
iterations: 3
});
}
}
// --- Boot ---
const auditChain = new AuditChain();
const ui = new UIManager(auditChain);
ui.renderChain();
ui.log("AUDIT ENGINE READY.", 'success');
</script>
</body>
</html>