Wallet-authenticated chat with Discord-like rooms and real-time messaging, using plain SQL and no ORM.
This is the messaging service for OpenForge, a milestone-escrow prototype on the Sepolia test network. Rooms can be attached to an escrow, which is how a funder and a developer talk about a dispute.
Prototype, not audited. It holds no funds and signs no transactions, but it does hold private conversation in plain text. See SECURITY.md.
- Wallet Authentication: EIP-191
personal_signbased authentication - Room Types: Public, Private, and P2P (one-to-one) rooms
- Room Permissions: Admin controls with join request system for public rooms
- Real-time Messaging: Socket.IO powered real-time chat
- Message Reactions: Like/unlike messages with real-time updates
- Typing Indicators: Real-time typing status
- Invitation System: Wallet-based invitations for private rooms
- Runtime: Node.js + Express
- Database: PostgreSQL (Neon compatible), plain SQL via
pg - Real-time: Socket.IO
- Authentication: JWT + EIP-191 signatures
users ├── wallet_address (unique) ├── nonce (for signing) └── timestamps
chat_rooms ├── name, description ├── room_type (public/private/p2p) ├── admin_id (references users) └── timestamps
room_members ├── room_id, user_id (composite unique) ├── status (pending/approved/rejected/left) ├── is_admin └── timestamps
messages ├── room_id, sender_id ├── content ├── parent_message_id (for replies) └── timestamps
message_likes ├── message_id, user_id, reaction_type └── timestamps
room_invitations ├── room_id, inviter_id, invitee_wallet_address ├── status (pending/accepted/rejected) └── expiration
text
POST /api/auth/nonce- Get nonce for walletPOST /api/auth/verify- Verify signature and get JWTPOST /api/auth/refresh- Refresh JWT tokenGET /api/auth/me- Get user profile
POST /api/rooms- Create roomGET /api/rooms/public- Get public roomsGET /api/rooms/my- Get user's roomsGET /api/rooms/:roomId- Get room detailsPOST /api/rooms/:roomId/join- Request to join public roomPOST /api/rooms/:roomId/invite- Invite to private room (admin only)GET /api/rooms/:roomId/requests- Get pending requests (admin only)POST /api/rooms/:roomId/leave- Leave roomDELETE /api/rooms/:roomId- Delete room (admin only)POST /api/rooms/p2p/:walletAddress- Create/get P2P room
GET /api/rooms/:roomId/messages- Get room messagesPOST /api/rooms/:roomId/messages- Send messagePUT /api/messages/:messageId- Edit messageDELETE /api/messages/:messageId- Delete messagePOST /api/messages/:messageId/like- Like messageDELETE /api/messages/:messageId/like- Unlike messageGET /api/messages/:messageId/likes- Get message likes
GET /api/invitations- Get user invitationsPOST /api/invitations/:invitationId/accept- Accept invitationPOST /api/invitations/:invitationId/reject- Reject invitation
join_room- Join a roomleave_room- Leave a roomsend_message- Send message to roomtyping- Typing indicator starttyping_stop- Typing indicator stoplike_message- Like a messageunlike_message- Unlike a message
rooms_joined- List of joined rooms on connectroom_joined- Room join confirmationroom_left- Room leave confirmationuser_joined- Another user joined roomuser_left- Another user left roomnew_message- New message in roomuser_typing- User typing in roomuser_typing_stop- User stopped typingmessage_liked- Message likedmessage_unliked- Message unliked
GET /health— checks the database and reportshealthyorunhealthy.GET /ping— returnsok, touches nothing.
Point an uptime monitor at /ping, not /health. On a free instance that
sleeps after 15 minutes idle, a 5-minute poll is what stops the first real
request paying a cold start — but polling /health runs SELECT 1 288 times a
day and holds the database's compute awake around the clock, which exhausts a
free tier faster than sleeping did. /ping also sits outside /api, so it
never consumes the rate-limit budget real callers share.
npm install
cp .env.example .env # see below
npm run migrate # applies migrations in filename order
npm run dev # nodemon, PORT defaults to 5164| Command | Does |
|---|---|
npm run dev |
Development server with reload |
npm start |
Production server |
npm run migrate |
Apply pending migrations |
| Variable | Notes |
|---|---|
DATABASE_URL |
Postgres connection string. TLS is required. |
JWT_SECRET |
Generate a real one. Rotating it invalidates every issued token. |
CORS_ORIGIN |
Comma-separated origins. Each needs its scheme. |
PORT |
Defaults to 5164. |
RATE_LIMIT_WINDOW / RATE_LIMIT_MAX |
Defaults: 15 minutes, 100 requests. |
node -e "console.log(require('crypto').randomBytes(32).toString('hex'))"
CORS_ORIGINneeds the scheme on every entry. AnOriginheader is always scheme, host and port, solocalhost:3000matches nothing whilehttp://localhost:3000matches. This fails in the most misleading way available: the server returns a normal200without anAccess-Control-Allow-Originheader, curl sees success, and only the browser discards the response — so it presents as the backend being down. The server now warns at startup about scheme-less entries and logs every refused origin.
Vercel preview deployments get a new hostname per commit, so each preview origin needs adding.
Applied in filename order and tracked by filename, not by content hash. Editing an applied migration does not re-run it — deliberate, so comments can be corrected — which means a schema change needs a new file. Write them to be safe to run twice.
| CONTRIBUTING.md | Setup, conventions, what to check before a PR |
| SECURITY.md | The auth model, known weaknesses, reporting |
| CODE_OF_CONDUCT.md | Contributor Covenant 2.1 |
MIT.