import Link from "next/link"
import { ArrowLeft, Download } from "lucide-react"
import { Button } from "@/components/ui/button"

export default function WhitepaperPage() {
  return (
    <div className="container py-12 md:py-24">
      <Button variant="ghost" className="mb-8 gap-2" asChild>
        <Link href="/">
          <ArrowLeft className="h-4 w-4" />
          Back to Home
        </Link>
      </Button>

      <div className="mx-auto max-w-3xl">
        <div className="flex items-center justify-between mb-8">
          <h1 className="text-3xl font-bold tracking-tight sm:text-4xl">QuantumVerify White Paper</h1>
          <Button className="gap-2" asChild>
            <a href="/downloads/whitepaper.pdf" download>
              <Download className="h-4 w-4" />
              Download PDF
            </a>
          </Button>
        </div>

        <div className="prose prose-gray max-w-none dark:prose-invert">
          <h2>QuantumVerify LTD Technical Overview White Paper</h2>
          <p className="text-sm text-muted-foreground">Version 1.0 | 30 April 2025</p>

          <h3>Abstract</h3>
          <p>
            QuantumVerify delivers a permissioned, edge-executed verification network that confirms—within &lt; 100 ms
            round-trip—whether a beneficiary account exists, is operational and is unsanctioned, while guaranteeing
            message integrity against quantum-enabled adversaries.
          </p>
          <p>
            This white paper summarises the architecture, cryptographic design, benchmark evidence, and regulatory
            alignment underpinning Patent 1: "Quantum-secure architecture for real-time recipient verification in
            cross-border payments."
          </p>

          <h3>Table of Contents</h3>
          <ol>
            <li>Network Architecture</li>
            <li>Performance Benchmarks</li>
            <li>Cryptographic Design & Agility</li>
            <li>Time-Synchronisation Strategy</li>
            <li>Regulatory & Standards Alignment</li>
            <li>Roadmap (next 18 months)</li>
            <li>Glossary</li>
            <li>Appendix A – Benchmark Methodology</li>
            <li>Appendix B – Data-Minimising JSON Schema</li>
            <li>Appendix C – SHA-256 Checksum</li>
          </ol>

          <h3>1 Network Architecture</h3>
          <table className="w-full border-collapse">
            <thead>
              <tr>
                <th>Layer</th>
                <th>Key Elements</th>
                <th>Purpose</th>
              </tr>
            </thead>
            <tbody>
              <tr>
                <td>Edge</td>
                <td>Verification Client (sender) • Verification Server (receiver)</td>
                <td>
                  Package data-minimised request, sign/verify PQC signature, run sanctions & account checks locally
                </td>
              </tr>
              <tr>
                <td>Transport</td>
                <td>TLS 1.3 (AES-256-GCM) over a private, QoS-marked channel</td>
                <td>Confidential, single-hop delivery in &lt;15 ms metro latency</td>
              </tr>
              <tr>
                <td>Integrity</td>
                <td>ML-DSA-65 or SLH-DSA-SHA2-128s signatures generated/verified inside FIPS 140-2 L3 HSMs</td>
                <td>Quantum-resilient authenticity; keys never leave hardware</td>
              </tr>
              <tr>
                <td>Timing</td>
                <td>Hardened Precision-Time-Protocol profile (Layer 2, HMAC-SHA-256, 16 msgs s⁻¹)</td>
                <td>Keeps all nodes within ± 500 ns UTC for deterministic ordering</td>
              </tr>
              <tr>
                <td>Screening</td>
                <td>Two-stage matcher: ① Jaro-Winkler 0.85 pre-filter → ② Fine-tuned MPNet (768-d) cosine ≥ 0.89</td>
                <td>Achieves 97 %+ recall with 60 % lower CPU/GPU load than LLM-only</td>
              </tr>
            </tbody>
          </table>

          <p>Data flow:</p>
          <ol>
            <li>Sender's payment engine passes a pacs.008 to the Verification Client.</li>
            <li>
              Client strips originator PII, hashes optional fields, time-stamps (UTC ns) and signs inside HSM-150.
            </li>
            <li>Request travels one hop to the recipient's Verification Server.</li>
            <li>
              Server verifies signature in HSM-151, looks up account status, executes two-stage sanctions screen, embeds
              XAI heat-map if flagged, signs and returns verdict.
            </li>
            <li>Client verifies, logs metrics and signals Proceed / Block / Review to the payment engine.</li>
          </ol>

          <h3>2 Performance Benchmarks (100 000-sample suite)</h3>
          <table className="w-full border-collapse">
            <thead>
              <tr>
                <th>Metric</th>
                <th>Target</th>
                <th>Achieved</th>
                <th>Head-room</th>
              </tr>
            </thead>
            <tbody>
              <tr>
                <td>Median latency (p50)</td>
                <td>≤ 45 ms</td>
                <td>38 ms</td>
                <td>15 %</td>
              </tr>
              <tr>
                <td>95th-percentile latency</td>
                <td>≤ 75 ms</td>
                <td>69 ms</td>
                <td>7 %</td>
              </tr>
              <tr>
                <td>PQC sign time (median)</td>
                <td>≤ 2.2 ms</td>
                <td>1.78 ms</td>
                <td>19 %</td>
              </tr>
              <tr>
                <td>Clock-skew residual (p95)</td>
                <td>≤ 1 μs</td>
                <td>0.68 μs</td>
                <td>32 %</td>
              </tr>
              <tr>
                <td>Sanctions recall</td>
                <td>≥ 97 %</td>
                <td>97.12 %</td>
                <td>+0.12 pp</td>
              </tr>
            </tbody>
          </table>
          <p>
            Benchmark harness details are provided in Appendix A. All tests executed on commodity 8-core x86 servers
            plus one NVIDIA T4 for Stage 2 inference.
          </p>

          <h3>3 Cryptographic Design & Agility</h3>
          <ul>
            <li>Message integrity – ML-DSA-65 (hash-based) default; SLH-DSA-SHA2-128s available.</li>
            <li>
              Three-layer agility framework – Interface → Implementation plug-ins → Selection policy from the network
              Key Management System (KMS).
            </li>
            <li>
              Hybrid migration – Dual-signature mode allows classical (ECDSA-P-256) + ML-DSA-65 during cut-over with
              zero downtime.
            </li>
            <li>Transport confidentiality – TLS 1.3 with P-256 ECDHE + AES-256-GCM; optional MACsec at Layer 2.</li>
            <li>
              Hardware anchoring – All private keys stored, generated and used exclusively inside certified HSMs;
              PKCS#11 interface ensures vendor neutrality.
            </li>
          </ul>

          <h3>4 Time-Synchronisation Strategy</h3>
          <ul>
            <li>
              Custom "Financial-Services PTP" profile: Layer 2, End-to-End delay, ≥ 16 Sync/s, mandatory hardware
              time-stamping, residual path asymmetry ≤ 20 ns.
            </li>
            <li>Dual grand-masters (Class 6) with GNSS hold-over; automatic fail-over &lt; 1 s.</li>
            <li>Tiered fall-back ladder: PTP → Authenticated NTPv4 → OCXO hold-over (&lt; 3 μs drift/24 h).</li>
            <li>
              Offset &gt; 500 ns raises "CLOCK_DEGRADED" but service continues in grace mode for low-value payments.
            </li>
          </ul>

          <h3>5 Regulatory & Standards Alignment</h3>
          <ul>
            <li>GDPR – Originator PII never transmitted; optional recipient fields hashable.</li>
            <li>MiFID II RTS 25 – Sub-μs timestamp precision with immutable audit trail.</li>
            <li>FCA SYSC 9 – WORM logs retained ≥ 10 years, dual-signed for quantum resilience.</li>
            <li>PCI-DSS v4 – All cryptographic operations anchored in certified HSMs.</li>
            <li>NIST PQC Round 3 – Conforms to ML-DSA & SLH-DSA draft FIPS 204/205.</li>
          </ul>

          <h3>6 Roadmap (next 18 months)</h3>
          <table className="w-full border-collapse">
            <thead>
              <tr>
                <th>Quarter</th>
                <th>Milestone</th>
              </tr>
            </thead>
            <tbody>
              <tr>
                <td>Q3 2025</td>
                <td>Public sandbox + developer portal; OpenAPI 3 spec released</td>
              </tr>
              <tr>
                <td>Q4 2025</td>
                <td>Hybrid dual-signature rollout (ECDSA + ML-DSA-65)</td>
              </tr>
              <tr>
                <td>Q1 2026</td>
                <td>Certified connectors for FedNow SM & SEPA Instant</td>
              </tr>
              <tr>
                <td>Q2 2026</td>
                <td>XAI dashboard v2 – token-level heat-map viewer & audit export</td>
              </tr>
              <tr>
                <td>Q3 2026</td>
                <td>Multi-region active-active deployment blueprint & SLA ≥ 99.995 %</td>
              </tr>
            </tbody>
          </table>

          <h3>7 Glossary (selected)</h3>
          <table className="w-full border-collapse">
            <thead>
              <tr>
                <th>Term</th>
                <th>Meaning</th>
              </tr>
            </thead>
            <tbody>
              <tr>
                <td>PQC</td>
                <td>Post-Quantum Cryptography – algorithms resistant to Shor-class quantum computers</td>
              </tr>
              <tr>
                <td>ML-DSA-65</td>
                <td>NIST-standardised hash-based digital-signature scheme (Dilithium family)</td>
              </tr>
              <tr>
                <td>PTP</td>
                <td>Precision-Time-Protocol (IEEE 1588-2019) – sub-μs network time synchronisation</td>
              </tr>
              <tr>
                <td>XAI</td>
                <td>Explainable AI – technique producing human-readable rationale for ML decisions</td>
              </tr>
              <tr>
                <td>HSM</td>
                <td>Hardware Security Module – tamper-resistant device for key protection and crypto ops</td>
              </tr>
            </tbody>
          </table>

          <h3>8 Appendix A – Benchmark Methodology (abridged)</h3>
          <ul>
            <li>100 000 synthetic payment instructions per run; randomised payload sizes.</li>
            <li>Fixed PRNG seed 42 for determinism; all code in Go 1.22 / Python 3.12.</li>
            <li>Latency measured wall-clock; stage timings captured via perf-event counters.</li>
            <li>Hardware: 2 × Intel Silver 4314 (16c), 64 GB RAM, NVMe RAID-1, NVIDIA T4.</li>
            <li>Network: 10 Gb E, 12 μs switch latency, 20 μs fibre London ↔ Frankfurt.</li>
          </ul>

          <h3>9 Appendix B – Data-Minimising JSON Schema (v1.0 excerpt)</h3>
          <pre className="bg-muted p-4 rounded-md overflow-x-auto">
            {`{
  "required": [
    "message_type", "transaction_id", "timestamp",
    "sending_institution_id", "receiving_institution_id",
    "recipient_account_id", "recipient_name",
    "recipient_country_code", "transaction_amount",
    "transaction_currency"
  ],
  "additionalProperties": false
}`}
          </pre>
          <p>Originator-specific fields are intentionally undefined to enforce GDPR data-minimisation.</p>

          <h3>10 Appendix C – SHA-256 Checksum</h3>
          <p>
            The canonical SHA-256 of the empty byte-stream (RFC 1321 test vector) is included for citation integrity
            checks:
          </p>
          <pre className="bg-muted p-4 rounded-md overflow-x-auto">
            e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
          </pre>

          <p className="text-sm text-muted-foreground mt-8">
            © 2025 QuantumVerify LTD – All rights reserved. This document may be reproduced internally for evaluation
            purposes but must not be redistributed without written permission.
          </p>
        </div>
      </div>
    </div>
  )
}
