feat: Initial MVP with home server identity model
- User model with Ed25519 keypair identity - Register/login on home server (creates keypair) - Join guest servers with signature verification - Public endpoints for cross-server identity - Channel and message CRUD - JWT authentication middleware Architecture: Home server model, no federation, client-driven sync
This commit is contained in:
commit
6a8977c4c3
14 files changed
+1494
No files matched your search
@@ -0,0 +1,85 @@
|
||||
import 'package:chat_server/models.dart';
|
||||
import 'package:chat_server/objectbox.g.dart';
|
||||
import 'package:relic/relic.dart';
|
||||
|
||||
import '../utils/extensions.dart';
|
||||
|
||||
/// Public endpoint for cross-server identity verification
|
||||
/// Called by other servers to verify a user's public key
|
||||
///
|
||||
/// GET /.well-known/users/{username}
|
||||
/// Returns: { userId, publicKey, username, displayName, avatarUrl }
|
||||
Future<Response> publicUserHandler(Request req, String username) async {
|
||||
final query = userBox.query(
|
||||
User_.username.equals(username) & User_.isLocal.equals(true),
|
||||
).build();
|
||||
|
||||
final user = query.findFirst();
|
||||
query.close();
|
||||
|
||||
if (user == null) {
|
||||
return Response.notFound(
|
||||
body: Body.fromString('User not found'),
|
||||
);
|
||||
}
|
||||
|
||||
return Response.ok(
|
||||
body: {
|
||||
'userId': user.userId,
|
||||
'username': user.username,
|
||||
'displayName': user.displayName,
|
||||
'avatarUrl': user.avatarUrl,
|
||||
'bio': user.bio,
|
||||
'publicKey': user.publicKey,
|
||||
'homeServer': Config.serverHost,
|
||||
'createdAt': user.createdAt.toIso8601String(),
|
||||
}.toBody,
|
||||
);
|
||||
}
|
||||
|
||||
/// Public endpoint to verify a user exists
|
||||
/// Lightweight check without full profile
|
||||
///
|
||||
/// GET /.well-known/verify/{userId}
|
||||
/// Returns: { exists, userId, publicKey }
|
||||
Future<Response> publicVerifyHandler(Request req, String userId) async {
|
||||
final query = userBox.query(
|
||||
User_.userId.equals(userId) & User_.isLocal.equals(true),
|
||||
).build();
|
||||
|
||||
final user = query.findFirst();
|
||||
query.close();
|
||||
|
||||
if (user == null) {
|
||||
return Response.ok(
|
||||
body: {
|
||||
'exists': false,
|
||||
'userId': userId,
|
||||
}.toBody,
|
||||
);
|
||||
}
|
||||
|
||||
return Response.ok(
|
||||
body: {
|
||||
'exists': true,
|
||||
'userId': user.userId,
|
||||
'publicKey': user.publicKey,
|
||||
'username': user.username,
|
||||
}.toBody,
|
||||
);
|
||||
}
|
||||
|
||||
/// Public server info
|
||||
///
|
||||
/// GET /.well-known/server
|
||||
/// Returns: { serverHost, serverName, version }
|
||||
Future<Response> publicServerInfoHandler(Request req) async {
|
||||
return Response.ok(
|
||||
body: {
|
||||
'serverHost': Config.serverHost,
|
||||
'serverName': Config.serverName,
|
||||
'version': '0.1.0',
|
||||
'features': ['identity', 'chat', 'sticker-packs'],
|
||||
}.toBody,
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user