Commit Graph

283 Commits

Author SHA1 Message Date
Christomatt c47b0141f5 feat: Remove chat key management and debug endpoints, simplify chat message handling, and enhance migration page with DM and bot export capabilities. 2026-01-29 00:04:22 +01:00
Christopher 9cd23081ed fixed modal 2026-01-28 13:18:26 -08:00
Christomatt aebc3a81fc package.json. 2026-01-28 22:14:40 +01:00
Christomatt 605f6d8422 feat: Introduce a dedicated development environment setup with .env.dev and a dev:dev script. 2026-01-28 22:06:41 +01:00
Christopher ceae76d58f Refactor chat system to remove E2EE and simplify messaging
Removed all E2EE chat endpoints, crypto logic, and related API routes, transitioning chat to plain text storage and transport. Updated chat send/receive endpoints to use signed actions and enforce DM privacy settings. Cleaned up Swarm chat inbox, key management, and related debug endpoints. Updated user profile to support DM privacy, improved search for handle queries, and refactored conversation/message logic to support the new model. Migrated bot settings and privacy settings to new locations.
2026-01-28 13:05:34 -08:00
Christopher b52b3f9804 Remove lastSeenAt from handle update in chat API
The lastSeenAt field is no longer set when updating the handle in the chat receive API route. This may be due to a change in how user activity is tracked or to simplify the update payload.
2026-01-28 07:55:38 -08:00
Christopher ced2b958ed Upsert sender into HandleRegistry on message receive
Adds logic to upsert the sender's handle, DID, and node domain into the HandleRegistry when a chat message is received. This ensures the sender's information is available for future replies or key retrieval.
2026-01-28 07:53:23 -08:00
Christopher 558c1aecdf Ensure chat key fetches bypass cache
Added `{ cache: 'no-store' }` to fetch requests for chat keys in both the chat page and useSodiumChat hook to prevent stale key data. Also updated the chat key query to order by `lastSeenAt` descending, ensuring the most recent bundle is retrieved.
2026-01-28 07:48:10 -08:00
Christopher 28f561f689 Sync chat public key to users table and fix handle formatting
The chat public key is now also updated in the users table during key publishing for profile discovery. Additionally, sender handles in chat receive are now fully qualified with domain when necessary to ensure consistency in conversation and message storage.
2026-01-28 07:43:05 -08:00
Christopher 93a587f185 Refactor chat page useEffect organization and improve compose intent handling
Reorganizes useEffect hooks in chat/page.tsx to follow a helper-functions-first structure, improving readability and maintainability. Adds error handling and user feedback for compose intent, preventing UI flash while processing. In send/route.ts, ensures remote user handles are fully qualified and adds debug logging. Temporarily disables key caching in keys/route.ts to address development key mismatches.
2026-01-28 07:37:27 -08:00
Christopher a21af87144 Implement federated chat message sending and receiving
Adds /api/chat/receive endpoint to accept federated chat messages from remote nodes and store them for local users. Updates /api/chat/send to support sending messages to remote nodes by resolving recipient domains, posting to their /api/chat/receive endpoint, and storing a local copy of the sent message. Enables basic cross-node chat federation.
2026-01-28 07:27:44 -08:00
Christopher 70b86244a7 Refactor Base64 variant handling in tryDecodeBase64
Simplifies and clarifies the logic for selecting Base64 variants by using a Set to ensure uniqueness and order. This change improves maintainability and robustness when decoding Base64 strings with different variants.
2026-01-28 07:22:11 -08:00
Christopher f678f1f87e Refactor handle registry updates and improve key decoding
Removed 'healing' logic and authoritative update propagation from handle registry and gossip code, simplifying handle upserts to only update on strictly newer timestamps. Enhanced sodium-chat key handling with robust base64 decoding and key repair logic. Added scripts for key inspection and crypto testing. Deleted unused healing module.
2026-01-28 07:16:15 -08:00
Christopher 36f653d500 Improve handle registry healing and gossip propagation
Added healing utilities to update the handle registry when a user profile is found at a new node domain. Enhanced upsertHandleEntries to accept a sourceDomain parameter, allowing authoritative updates from the owning node. Updated gossip logic to pass sender/target domains for proper trust handling during handle propagation. Integrated healing logic into chat key lookup to keep the registry accurate.
2026-01-28 06:55:13 -08:00
Christopher 213dcc8095 Enhance chat key lookup with remote and cache fallback
The GET /api/chat/keys endpoint now checks a remote identity cache and, if necessary, fetches keys from remote nodes or Swarm user profiles when a local key is not found. Results from remote lookups are cached for 24 hours to improve performance and reliability.
2026-01-28 06:45:28 -08:00
Christopher 4ab464bcaa Fix crypto_generichash usage in useUserIdentity
Adds the missing third argument (null) to sodium.crypto_generichash to ensure correct hashing behavior when generating the salt for storage key derivation.
2026-01-28 06:16:35 -08:00
Christopher 015d4ecbd8 Add check for user DID before key verification
Throws an error if the user DID is not available before attempting to verify the key on the server, preventing potential runtime errors.
2026-01-28 06:12:51 -08:00
Christopher a87977241c Refactor chat encryption to use sodium, update API
Replaces legacy chat encryption modules with new sodium-based implementation. Adds and updates API routes for chat key management and debugging, introduces new hooks and scripts for sodium chat, and updates related database schema and configuration. Removes old crypto modules and updates dependencies accordingly.
2026-01-28 06:07:03 -08:00
Christopher 222f1c6d8a Add sender DID resolution and self-decryption for chat messages
The messages API now resolves and includes sender DIDs for received messages, enabling proper decryption in the chat UI. The chat page adds logic to decrypt self-encrypted messages for sent items and improves V2 envelope handling, while useChatEncryption now serializes ratchet state before storage.
2026-01-27 22:06:47 -08:00
Christopher c8e4dedd61 Add sender_did to chat messages and new chat tables
Introduces a migration to add a sender_did column to the chat_messages table and creates new tables for chat_device_bundles, chat_inbox, and chat_one_time_keys. Updates related API routes and adds a script for sender DID migration. These changes support device-based messaging and improved chat security.
2026-01-27 21:57:33 -08:00
Christopher 3c7937312d Add self-encryption for sent chat messages
Introduces helper functions to encrypt and decrypt a copy of sent messages for the sender using AES-GCM with a key derived from the identity public key. Updates message sending to include a self-encrypted payload, and modifies message reading logic to allow the sender to decrypt their own messages on any device.
2026-01-27 21:46:48 -08:00
Christopher d460139ede Store chat messages locally for sender and recipient
Messages sent to remote users are now stored locally for the sender, and incoming remote messages are stored for the recipient, ensuring both parties see their message history in the UI. The implementation creates or updates conversations as needed and marks messages as delivered when appropriate.
2026-01-27 21:33:11 -08:00
Christopher dd87d51fa6 Add V2 chat protocol support and improve error handling
Introduces support for V2 encrypted chat envelopes in the swarm inbox route, allowing storage and processing of new message formats. Enhances error handling and logging in both chat send and encryption hooks, including detection of remote nodes that do not support the V2 protocol and providing clearer error messages for users and developers.
2026-01-27 21:25:51 -08:00
Christopher e92c747a5b Improve chat encryption, delivery, and session handling
Adds robust session serialization/deserialization for ratchet state, session cleanup for corrupted data, and improved error handling in chat encryption hooks. Enhances chat delivery to support both local and remote recipients, ensures conversation creation, and adds timeouts to key fetches. Also introduces utilities for deleting and clearing encrypted session data from storage.
2026-01-27 20:36:03 -08:00
Christopher 8c3dffaa4c Add placeholder signature to bundle payload
Introduced a 'signature' field with a placeholder value ('signed-by-did-envelope') in the bundle payload to satisfy expected structure and prevent potential issues with undefined values. Added detailed comments explaining the reasoning and context for this change, particularly regarding the signing of the signedPreKey and the use of the DID key.
2026-01-27 20:11:23 -08:00
Christopher 96053ebd65 Improve chat key fetch and self-repair logic
Refactors the chat key fetch API to support fallback lookups using user handle and did:web aliasing, improving reliability when primary lookups fail. Updates useChatEncryption to detect and repair 'Zombie State' where local keys exist but are missing on the server, ensuring keys are republished as needed. Modifies sendMessage to pass recipient handle and bind sessions to the correct DID, supporting aliasing scenarios.
2026-01-27 19:45:36 -08:00
Christopher 7eae96bc44 Add remote key fetch proxy and improve chat reliability
Introduces an API route to proxy remote key bundle fetches, improving CORS handling for secure chat. Updates chat UI to handle error states and retries, enhances key/identity synchronization, and refactors message sending to support remote node domains. Also adds CORS preflight support to the .well-known chat route and improves in-memory key store management.
2026-01-27 19:34:37 -08:00
Christopher 33295b744e Add DID support and improve login state handling
Introduces a 'did' field to SwarmUserProfile and related API routes to support decentralized identifiers. Refactors login flow to use soft navigation and synchronize AuthContext state, including new 'login' and enhanced 'unlockIdentity' methods for better user state management.
2026-01-27 19:10:07 -08:00
Christopher 4627917921 feat: Improve node identification logic to handle domain mismatches and update the node's domain during admin updates. 2026-01-27 18:48:06 -08:00
Christopher f59625c83f Revamp chat UI and add V2 encrypted messaging support
Major update to chat page with new conversation list, message thread view, and support for V2 end-to-end encrypted messaging using DIDs. Adds chat lock state, message sending, conversation deletion, and improved polling. Updates user API and types to include DID and chatPublicKey. Fixes race conditions in feed loading, adds message button to user profile, and improves crypto and identity hooks for better locked/unlocked state detection.
2026-01-27 18:33:56 -08:00
Christopher 9ee0cbbb9a feat: Implement end-to-end encrypted chat with new API routes, crypto utilities, and UI components. 2026-01-27 17:59:08 -08:00
Christopher 5903022f8a Add encrypted key support for chat and nodes
Introduces encrypted private key storage for nodes and users, updates chat message schema to support sender-side encryption, and adds supporting libraries and tests for cryptographic signing and identity unlock flows. Includes new database migrations, API route updates, and React components for identity unlock prompts.
2026-01-27 17:13:28 -08:00
Christopher 25f71e320b Implement federated chat conversation deletion
Adds logic to notify remote nodes when a chat conversation is deleted, and introduces a new API endpoint to receive and process deletion requests from other swarm nodes. Ensures that only authorized participants can trigger deletions and handles both local and remote user scenarios.
2026-01-27 14:09:25 -08:00
Christopher cb141a91a1 Fix DELETE handler to support async params
The DELETE API route now expects params as a Promise and awaits it to extract the conversation id. All references to params.id have been updated to use the resolved id variable.
2026-01-27 14:03:53 -08:00
Christopher 374f707dbf Add conversation deletion to chat UI and API
Introduces an API route for deleting chat conversations, supporting deletion for self or both parties. Updates the chat page UI to allow users to delete conversations with confirmation modal and handles state updates after deletion.
2026-01-27 14:00:48 -08:00
Christopher 2a65f78610 Update feed labels and improve chat UX
Renamed 'Latest' feed to 'Following' across the home and profile pages for clarity, and updated related UI text. Improved chat experience by adding a scroll-to-bottom button, tracking scroll position, and only auto-scrolling when the user is at the bottom. Updated default node description to 'A swarm social network node.' in multiple locations.
2026-01-27 13:29:15 -08:00
Christopher a68aee8758 Migrate user/profile URLs to /u/[handle] and remove legacy scripts
All user and post profile URLs have been updated from /[handle] to /u/[handle] for consistency. Added a redirect page for /posts/[id] to the canonical /u/[handle]/posts/[id] route. Deprecated and removed legacy scripts and documentation related to chat and federation endpoints. Push-based federation endpoints are now disabled in favor of real-time pull-based federation.
2026-01-27 01:26:41 -08:00
Christopher 44610157a1 Add chat page, improve chat API, and remove ChatWidget
Introduces a new chat page with end-to-end encryption, conversation list, and message thread UI. Adds new API endpoints for unread message count and debugging chat keys/messages. Improves chat key validation and reciprocal conversation/message creation for local recipients. Removes the old ChatWidget component. Updates login and chat API logic for better Turnstile and key handling.
2026-01-27 01:05:40 -08:00
Christopher 9739539733 Improve registration logging and error handling
Adds detailed logging for registration attempts (excluding passwords) and Turnstile verification failures. Enhances error handling by distinguishing between validation, business logic, and server errors, returning appropriate HTTP status codes.
2026-01-26 23:08:12 -08:00
Christomatt 75a2d87d9a feat: Implement a new chat widget with enhanced encryption handling and supporting utility scripts, replacing the old chat page. 2026-01-27 08:07:32 +01:00
Christomatt f758421748 feat(chat): Add remote user public key fetching for cross-node messaging
- Implement remote user detection based on @domain format in recipient handle
- Add HTTP/HTTPS protocol selection logic for localhost vs production domains
- Fetch remote user public keys from their node's /api/users endpoint
- Maintain local user key lookup for non-remote recipients
- Add error handling and debug logging for remote key fetch failures
- Enable end-to-end encryption support for federated chat across nodes
2026-01-27 06:28:42 +01:00
Christomatt 7d1e22e457 feat(chat): Enhance message decryption with improved key management and debug logging
- Add recipient public key fetching in messages API endpoint for sent message decryption
- Include `isE2E` flag in message response to indicate end-to-end encryption status
- Simplify encrypted content handling by always returning `encryptedContent` field
- Add comprehensive debug logging throughout message loading pipeline for troubleshooting
- Improve key resolution logic to fetch recipient keys when not available in conversation data
- Add detailed logging for each message processing step including key availability and decryption status
- Enhance error handling with more descriptive error messages in key fetching operations
- Better distinguish between sent and received message decryption requirements with clear comments
2026-01-27 06:18:20 +01:00
Christomatt 863cbc8dce feat(chat): Improve message decryption with better key management and error handling
- Add fallback logic to fetch recipient's public key if not already cached
- Distinguish between E2E encrypted messages (with senderPublicKey) and legacy RSA messages
- Return appropriate error messages for legacy encrypted messages and missing decryption keys
- Improve ECDH key derivation logic with clearer comments explaining sent vs received message handling
- Add comprehensive error logging for decryption failures and missing keys
- Refactor loadMessages function for better readability with expanded formatting
- Ensure recipient key is available before attempting message decryption to prevent silent failures
2026-01-27 04:27:06 +01:00
Christomatt c007741b65 feat: Include chat public key in conversation data and enhance chat page layout for full width and dynamic height. 2026-01-27 04:16:05 +01:00
Christomatt 5262cb1dbd Fix for chat 2026-01-27 04:10:03 +01:00
Christomatt 1726ef0c7b feat: include chatPublicKey in user profiles and the swarm user interface. 2026-01-27 04:00:27 +01:00
Christomatt 0d03933292 fix(chat): Correct template literal syntax in chat page
- Fix template literal syntax from escaped backticks to proper ${} notation
- Remove unnecessary comments from empty catch blocks for cleaner code
- Add emoji to initial chat greeting message for better UX
- Ensure consistent string interpolation across all API calls and JSX attributes
2026-01-27 03:39:06 +01:00
Christomatt f0253581d2 feat(chat): Implement client-side end-to-end encryption with key management
- Add chat keys API endpoint for storing and retrieving encrypted RSA public/private key pairs
- Create client-side crypto utilities for E2E encryption/decryption with hybrid encryption support
- Implement useChatEncryption hook for managing encryption state and key generation in chat UI
- Add chatPublicKey and chatPrivateKeyEncrypted fields to user schema for key storage
- Update chat messages API to return encrypted content with sender's public key for decryption
- Modify send message endpoint to accept pre-encrypted content from client while maintaining legacy server-side encryption
- Update chat page UI to integrate client-side encryption workflow
- Ensure private keys are encrypted client-side with user password before transmission to server
- Server cannot decrypt message content in E2E mode, providing true end-to-end encryption
2026-01-27 03:38:54 +01:00
Christomatt fb2c80b0e3 feat(chat): Validate and cache remote user public keys for encryption
- Add validation to check if cached users have valid public keys (PEM format)
- Fetch remote public keys when local cache has placeholder/invalid keys
- Update existing cached users with real public keys instead of creating duplicates
- Include public key in user profile API response for E2E encrypted chat support
- Improve error handling to reject recipients without valid encryption keys
- Ensure remote user data is properly extracted from API responses
This prevents sending encrypted messages to users with placeholder keys and ensures the chat system always has access to valid public keys for encryption operations.
2026-01-27 02:12:43 +01:00
Christomatt 998a1bcf4a feat(chat): Improve recipient handle parsing for swarm messaging
- Strip leading @ symbol from recipient handle before normalization
- Replace simple split() with substring-based parsing for more robust handle@domain extraction
- Add clarifying comments explaining handle format expectations (handle@domain)
- Prevent potential issues with malformed recipient handles containing multiple @ symbols
- Ensure consistent handle normalization across local and remote recipients
2026-01-27 01:54:59 +01:00