11import 'dart:convert' ;
2- import 'dart:typed_data' ;
32
43class Session {
54 final String id;
65 final String chatId;
76 final String senderDeviceId;
87 final String receiverDeviceId;
9- final Uint8List rootKey;
10- final Uint8List ? sendChainKey;
11- final Uint8List ? recvChainKey;
12- final int sendCounter;
13- final int recvCounter;
14- final Uint8List ratchetPub;
15- final Uint8List ? ratchetPriv;
16- final Uint8List ? lastRemotePub;
178 final DateTime createdAt;
189 final DateTime updatedAt;
1910
2011 Session ({
21- this .id = '' ,
22- this .chatId = '' ,
12+ this .id = '' ,
13+ this .chatId = '' ,
2314 required this .senderDeviceId,
2415 required this .receiverDeviceId,
25- required this .rootKey,
26- this .sendChainKey,
27- this .recvChainKey,
28- this .sendCounter = 0 ,
29- this .recvCounter = 0 ,
30- required this .ratchetPub,
31- this .ratchetPriv,
32- this .lastRemotePub,
3316 required this .createdAt,
3417 required this .updatedAt,
3518 });
36-
3719
3820 factory Session .fromJson (Map <String , dynamic > json) {
3921 return Session (
40- id: json['id' ],
41- chatId: json['chat_id' ],
22+ id: json['id' ] ?? '' ,
23+ chatId: json['chat_id' ] ?? '' ,
4224 senderDeviceId: json['sender_device_id' ],
4325 receiverDeviceId: json['receiver_device_id' ],
44- rootKey: base64Decode (json['root_key' ]),
45- sendChainKey: json['send_chain_key' ] != null
46- ? base64Decode (json['send_chain_key' ])
47- : null ,
48- recvChainKey: json['recv_chain_key' ] != null
49- ? base64Decode (json['recv_chain_key' ])
50- : null ,
51- sendCounter: json['send_counter' ] ?? 0 ,
52- recvCounter: json['recv_counter' ] ?? 0 ,
53- ratchetPub: base64Decode (json['ratchet_pub' ]),
54- ratchetPriv: json['ratchet_priv' ] != null
55- ? base64Decode (json['ratchet_priv' ])
56- : null ,
57- lastRemotePub: json['last_remote_pub' ] != null
58- ? base64Decode (json['last_remote_pub' ])
59- : null ,
6026 createdAt: DateTime .parse (json['created_at' ]),
6127 updatedAt: DateTime .parse (json['updated_at' ]),
6228 );
@@ -68,30 +34,17 @@ class Session {
6834 'chat_id' : chatId,
6935 'sender_device_id' : senderDeviceId,
7036 'receiver_device_id' : receiverDeviceId,
71- 'root_key' : base64Encode (rootKey),
72- if (sendChainKey != null )
73- 'send_chain_key' : base64Encode (sendChainKey! ),
74- if (recvChainKey != null )
75- 'recv_chain_key' : base64Encode (recvChainKey! ),
76- 'send_counter' : sendCounter,
77- 'recv_counter' : recvCounter,
78- 'ratchet_pub' : base64Encode (ratchetPub),
79- if (ratchetPriv != null )
80- 'ratchet_priv' : base64Encode (ratchetPriv! ),
81- if (lastRemotePub != null )
82- 'last_remote_pub' : base64Encode (lastRemotePub! ),
8337 'created_at' : createdAt.toIso8601String (),
8438 'updated_at' : updatedAt.toIso8601String (),
8539 };
8640 }
41+
42+ /// This JSON is used when confirming a pending session with the node.
43+ /// Only non-sensitive metadata is uploaded — the actual ratchet keys remain client-side.
8744 Map <String , dynamic > toConfirmJson () {
88- return {
89- "sender_device_id" : senderDeviceId,
90- "receiver_device_id" : receiverDeviceId,
91- "root_key" : base64Encode (rootKey),
92- "ratchet_pub" : base64Encode (ratchetPub),
93- if (lastRemotePub != null )
94- "last_remote_pub" : base64Encode (lastRemotePub! ),
95- };
96- }
45+ return {
46+ 'sender_device_id' : senderDeviceId,
47+ 'receiver_device_id' : receiverDeviceId,
48+ };
49+ }
9750}
0 commit comments