sequenceDiagram autonumber participant User participant Frontend as Frontend Application participant Server as WebSocket Server User ->> Frontend: Opens chat page (https://chat.yuchu.space/) Frontend ->> Frontend: Display randomly generated channel name or select a preset channel User ->> Frontend: Selects channel Frontend ->> Frontend: Generates RSA key pair Frontend ->> Frontend: Calculates HMAC of channel name Frontend ->> Server: Connects to WebSocket server Server ->> Frontend: Confirms connection Frontend ->> Server: Sends join channel request (public key, channel ID HMAC, public key signature) Server ->> Server: Validates public key signature Server ->> Server: Generates public key hash and stores it Server ->> Server: Updates channel user list Server ->> Frontend: Returns other users' public keys and signatures in the channel Frontend ->> Frontend: Validates other users' public key signatures Frontend ->> Frontend: Stores other users' public keys Frontend ->> Frontend: Generates AES key Frontend ->> Server: Encrypts AES key and sends it to other users Server ->> Frontend: Forwards encrypted AES key to other users Frontend ->> Frontend: Decrypts received AES key and stores it User ->> Frontend: Enters message and sends Frontend ->> Frontend: Encrypts message using AES key Frontend ->> Server: Sends encrypted message Server ->> Server: Forwards encrypted message Server ->> Frontend: Broadcasts encrypted message to other users Frontend ->> Frontend: Decrypts and displays message Server ->> Frontend: Sends heartbeat Frontend ->> Server: Returns heartbeat User ->> Frontend: Disconnects or closes page Frontend ->> Server: Sends disconnect notification Server ->> Server: Handles user leaving Server ->> Frontend: Notifies other users that the user has left Frontend ->> Frontend: Updates user list Frontend ->> Frontend: Randomly prompts a user in the channel to generate a new AES key Frontend ->> Server: Encrypts new AES key and sends it to other users Server ->> Frontend: Forwards encrypted new AES key to other users Frontend ->> Frontend: Decrypts received new AES key and stores it