import 'package:networks_sdk/networks_sdk.dart'; /// 对齐老项目 /app/api/cipher/v2/* API 端点 /// /// /app/api/cipher/v2/key/set 是预发布接口,仅测试阶段使用。 // ── GET /app/api/cipher/v2/key/my — 获取自己的公钥 ──────────────────────── class CipherMyKeyResponse { final String publicKey; final String? encPrivate; final int? uid; const CipherMyKeyResponse({ required this.publicKey, this.encPrivate, this.uid, }); factory CipherMyKeyResponse.fromJson(Map json) => CipherMyKeyResponse( publicKey: (json['public_key'] ?? '') as String, encPrivate: json['enc_pk'] as String?, uid: json['uid'] as int?, ); } class CipherGetMyKeyRequest extends ApiRequestable { @override String get path => '/app/api/cipher/v2/key/my'; @override HttpMethod get method => HttpMethod.get; @override Map get parameters => {}; @override CipherMyKeyResponse? decodeResponse(dynamic response) { final data = (response as dynamic).data; if (data is! Map) return null; return CipherMyKeyResponse.fromJson(data); } } // ── POST /app/api/cipher/v2/key/set — 上传公钥 ───────────────────────────── class CipherSetKeyRequest extends ApiRequestable { final String publicKey; final String encPk; CipherSetKeyRequest({required this.publicKey, required this.encPk}); @override String get path => '/app/api/cipher/v2/key/set'; @override HttpMethod get method => HttpMethod.post; @override Map get parameters => { 'public_key': publicKey, 'enc_pk': encPk, }; @override void decodeResponse(dynamic response) {} } // ── GET /app/api/cipher/v2/chat/my — 获取所有聊天的加密密钥 ───────────────── class CipherChatKeyItem { final int? chatId; final String? session; final int? round; const CipherChatKeyItem({this.chatId, this.session, this.round}); factory CipherChatKeyItem.fromJson(Map json) => CipherChatKeyItem( chatId: json['chat_id'] as int?, session: json['session'] as String?, round: json['round'] as int?, ); } class CipherGetMyChatKeysRequest extends ApiRequestable?> { @override String get path => '/app/api/cipher/v2/chat/my'; @override HttpMethod get method => HttpMethod.get; @override Map get parameters => {}; @override List? decodeResponse(dynamic response) { final data = (response as dynamic).data; if (data is! List) return null; return data .cast>() .map(CipherChatKeyItem.fromJson) .toList(); } } // ── GET /app/api/cipher/v2/key/gets — 获取其他用户的公钥 ───────────────────── class CipherUserKeyResponse { final int? uid; final String? publicKey; const CipherUserKeyResponse({this.uid, this.publicKey}); factory CipherUserKeyResponse.fromJson(Map json) => CipherUserKeyResponse( uid: json['uid'] as int?, publicKey: json['public_key'] as String?, ); } class CipherGetUsersKeysRequest extends ApiRequestable?> { final List userIds; CipherGetUsersKeysRequest({required this.userIds}); @override String get path => '/app/api/cipher/v2/key/gets'; @override HttpMethod get method => HttpMethod.get; @override Map get parameters => { 'uids': userIds.join(','), }; @override List? decodeResponse(dynamic response) { final data = (response as dynamic).data; if (data is! List) return null; return data .cast>() .map(CipherUserKeyResponse.fromJson) .toList(); } } // ── POST /app/api/cipher/v2/chat/update — 更新聊天加密密钥 ────────────────── class CipherUpdateChatKeysRequest extends ApiRequestable { final List> sessions; CipherUpdateChatKeysRequest({required this.sessions}); @override String get path => '/app/api/cipher/v2/chat/update'; @override HttpMethod get method => HttpMethod.post; @override Map get parameters => {'sessions': sessions}; @override void decodeResponse(dynamic response) {} }