Backend behavior: main.zig: load config, initialize allocato...
Prompt
Backend behavior: main.zig: load config, initialize allocator, open SQLite, run migrations, start purge job, start HTTP server, serve API and static frontend build. config.zig: read environment variables: APP_BIND APP_PUBLIC_ORIGIN APP_DATABASE_PATH APP_STATIC_DIR APP_COOKIE_SECURE APP_SESSION_DAYS APP_MESSAGE_MAX_BYTES APP_UNOPENED_TTL_SECONDS APP_CLAIMED_PURGE_SECONDS APP_RATE_LIMIT_PER_MINUTE migrations/001_initial.sql: create tables: users devices one_time_prekeys sessions contacts contact_requests conversations conversation_members messages message_recipients message_envelopes receipts event_queue Enable SQLite PRAGMA foreign_keys=ON. Enable SQLite PRAGMA secure_delete=ON. Use WAL mode, but truncate checkpoints after message purges. Do not create backups of message payload tables. Store no plaintext message content anywhere. Database semantics: messages stores encrypted payload bytes, nonce, AAD, sender metadata, visual policy, creation time, unopened expiry, and revoked time. message_recipients stores one row per recipient user per message and controls one-view state. message_envelopes stores one encrypted content-key envelope per recipient device. If a recipient user has multiple devices, the first device to claim the message consumes the recipient’s single view and invalidates that recipient’s other device envelopes. When all recipients are purged, delete the encrypted payload row. A purge job must delete expired unopened messages, claimed-but-unacknowledged messages after the configured grace period, revoked messages, and all related envelopes. Backend API: POST /api/v1/auth/register Creates user, first device, device public keys, signed prekey, one-time prekeys. POST /api/v1/auth/login Validates password, creates session, sets HttpOnly cookie, returns CSRF token. POST /api/v1/auth/logout Deletes current session. GET /api/v1/me Returns current user, device, and security status. GET /api/v1/users/search?handle=... Search by exact or prefix handle with rate limiting. POST /api/v1/contacts/request Send contact request. POST /api/v1/contacts/accept Accept contact request. POST /api/v1/contacts/reject Reject contact request. GET /api/v1/contacts List contacts and request states. GET /api/v1/devices List current user’s devices. POST /api/v1/devices/current/prekeys Upload more one-time prekeys. POST /api/v1/prekeys/claim For selected recipient users, atomically returns public key bundles for each active recipient device and marks one-time prekeys reserved/claimed. POST /api/v1/conversations Create one-to-one or small group conversation. GET /api/v1/conversations List conversations without plaintext. POST /api/v1/messages Accept encrypted payload and recipient envelopes. Validate sender membership, recipient membership, size limits, expiry limits, and visual policy. Never decrypt. Queue events for recipients. GET /api/v1/messages/pending List sealed message summaries only; never return encrypted payload here. POST /api/v1/messages/{message_id}/claim Atomic one-view operation. If unclaimed, mark recipient claimed, invalidate that recipient’s other device envelopes, return encrypted payload and the claiming device’s envelope once. If already claimed, expired, revoked, or purged, return a non-retryable consumed response. POST /api/v1/messages/{message_id}/viewed Mark viewed, purge recipient envelope, delete payload if no recipients remain. POST /api/v1/messages/{message_id}/revoke Sender revokes unopened message. GET /api/v1/events SSE stream with heartbeat and events: message_available message_claimed message_viewed message_revoked contact_request conversation_updated prekey_low Security headers: Content-Security-Policy must restrict scripts to self, disallow objects, disallow framing, restrict connections to self, and prevent mixed content. Referrer-Policy: no-referrer X-Content-Type-Options: nosniff Cross-Origin-Opener-Policy: same-origin Cross-Origin-Embedder-Policy: require-corp Permissions-Policy must deny unused sensors and allow camera only for the optional local camera-resistance calibration/detection feature. API responses with sensitive metadata must be Cache-Control: no-store. Client cryptographic protocol: On device setup: Generate ECDSA P-256 signing key pair. Generate ECDH P-256 identity key pair. Generate signed ECDH prekey. Generate at least 100 one-time ECDH prekeys. Sign prekey public keys with the device signing key. Store private keys in IndexedDB as non-extractable CryptoKeys when possible. Upload only public keys and signatures. Maintain a prekey threshold; upload more when fewer than 30 remain. Pin contact signing keys on first use and expose a safety-number comparison screen. Message send: Encode plaintext as UTF-8 bytes. Generate random 256-bit content key and 96-bit AES-GCM nonce. Build canonical AAD containing protocol version, conversation id, sender id, sender device id, visual policy, creation time, and recipient ids. Encrypt plaintext using AES-GCM. For every recipient device, claim/fetch a prekey bundle. Verify recipient prekey signatures. Generate sender ephemeral ECDH key. Derive shared secret with recipient prekey. Derive wrapping key using HKDF-SHA-256. AES-GCM-wrap the content key. Sign the canonical message header. Send encrypted payload and envelopes to the Zig backend. Clear composer plaintext and zeroize byte arrays best-effort. Message receive: Show only sealed pending message metadata. User must tap “Open once”. Call claim endpoint. Verify sender signature and pinned keys. Derive wrapping key using recipient private prekey. Unwrap content key. Decrypt payload. Immediately enter protected viewer. Delete used one-time private prekey. On close, timeout, visibility loss, print, blur, or route change, zeroize best-effort and send viewed acknowledgement. Frontend protected display: Protected messages must never be inserted as DOM text, aria-label, title, data-*, logs, URL parameters, localStorage, sessionStorage, or unencrypted IndexedDB values. Protected text must be rendered only through ProtectedMessageViewusing VisualTintCanvas. The normal direct human viewer should perceive readable text. A second phone/camera aimed at the screen should see the message bubble as unreadable blurry/liquid distortion in the live camera preview and in saved photos. Implement two visual modes: standard: full message appears readable to the naked eye while dynamic visual tint disrupts camera capture. maximum: combines visual tint with scan/attention reveal so the full clean plaintext is never present as stable pixels in one frame. Protected view must request fullscreen after user activation where available. Protected view must blank on: visibilitychange blur pagehide freeze beforeprint route navigation Escape/close configured timeout Add CSS print rules that render a blank protected page. Block context menu, selection, copy, cut, drag, save, and print shortcuts inside protected mode where browsers allow it. Do not claim these browser controls are absolute. Visual tint renderer: glyphRasterizer.ts: Convert Unicode text into wrapped glyph masks on an offscreen canvas. Use grapheme-aware wrapping. Do not expose text to DOM. visualTintRenderer.ts: Use WebGL2 with preserveDrawingBuffer: false. Continuously animate while protected view is active. Clear GPU buffers immediately when inactive. shaders.ts: Implement vertex and fragment shader source. Fragment shader must combine: glyph alpha mask dynamic liquid displacement field multiscale procedural noise temporal phase shifts chroma/is luminance perturbation high-frequency subpixel stripe fields rolling-shutter hostile moving bands decoy glyph-like strokes inside message bubbles randomized per-frame masks Standard mode should preserve direct readability. Maximum mode should time-slice strokes and optionally reveal only a narrow moving focus band. cameraResistance.ts: Provide a simulated camera pipeline: downsample, Bayer-like sampling approximation, rolling shutter row offsets, exposure integration, compression blur, and OCR-hostile contrast estimation. visualCalibration.ts: Provide user calibration sliders for readability versus capture resistance. Save only non-sensitive visual settings. If WebGL2 is unavailable: Use Canvas2D fallback with dynamic liquid masks. Warn that protection is weaker. Allow maximum scan-reveal mode as the safer fallback. PWA behavior: manifest.webmanifest: standalone display, privacy-focused name using neutral terms, icons, theme color. Service worker: Cache app shell files only. Never cache /api/ responses. Clear protected resources on activation. SPA routes: login register device setup contacts contact requests conversations protected message view visual calibration security settings safety number comparison Acceptance criteria: The repository builds from a clean checkout. Zig backend runs locally and serves the API. Frontend PWA builds and can be served by the Zig backend. Two users can exchange one-view encrypted messages. A message can be viewed once and cannot be claimed again. Protected messages are never rendered as DOM text. Protected view uses animated visual tint by default. Camera-facing visual tint should make message bubbles appear liquid/blurred/unreadable in ordinary external camera previews and saved photos while remaining readable to the direct viewer in standard mode. Maximum mode must avoid displaying the complete clean plaintext as stable pixels in a single frame. All sensitive server endpoints use authentication, CSRF protection, validation, rate limiting, and no-store caching. The implementation must not falsely promise absolute screenshot prevention on the web, but it must implement every practical layer described above. Technology stack: Backend: Zig. Backend storage: SQLite. Backend realtime: Server-Sent Events over HTTP plus normal JSON POST/GET endpoints. Frontend: TypeScript PWA SPA. Frontend rendering: WebGL2 protected viewer with Canvas2D fallback. Frontend crypto: Web Crypto API using P-256 ECDH, ECDSA P-256 signatures, HKDF-SHA-256, and AES-GCM. Authentication: password login with server-side Argon2id hashing, opaque session tokens, HttpOnly secure cookies, CSRF protection. No analytics. No third-party runtime scripts loaded from remote origins. API responses containing message data must use Cache-Control: no-store. Service worker must cache only the app shell, never message payloads or API responses. must be defense-in-depth: End-to-end encrypt every message on the client. Never store plaintext on the server. Deliver encrypted payloads only once using an atomic claim operation. Render protected messages without DOM text. Render protected messages only inside a GPU/canvas protected viewer. Use a “visual tint” renderer that makes direct human viewing readable but makes external camera previews and saved photos see unreadable liquid-like blurred message bubbles. In maximum-security mode, ensure the whole plaintext is never present as clean stable pixels in a single frame by using temporal encoding, dynamic adversarial masks, and an attention/scan reveal option. Blank and destroy the protected view immediately on visibility loss, blur, print, route change, page freeze, page hide, timeout, or close. Build a complete web-first private one-view messaging system from scratch. Use neutral descriptive naming only. Do not create or use brand-like identifiers. Backend language must be Zig. The initial deliverable is a PWA SPA that works on the web; structure the code so native Swift and Kotlin clients can later reuse the same protocol and API, but do not build native apps now. Core requirement: users can send chat messages that are viewable once, then permanently removed from the server-side delivery state and from the client’s protected view. The system must aggressively resist screenshots, screen recordings, browser printing, copy/paste, app-switcher previews, and photographing the screen with another phone or camera. ne Ărj semmi mást csak a teljes fájlokat es kommentek nem lehetnek benne! soha semmi egyszerusitett mock placeholder dummy szimulalt fake szart nem engedelyezek es teljes fájl roviditetlen production ready kĂłd nem lehet trancutted nem lehet olyan hogy …és hasonlĂłan 50 xy nem lehet dummy to do sorry hiányosság minden fájl teljes kĂłdját egyesĂ©vel fájkba Ărod semmi mást nem Ărsz ezen kĂvűl
Response not available
Response not available
Response not available