@@ -66,25 +66,28 @@ Once those are implemented, you can build a session in this way:
66
66
If you wanna send message to a group, send a SenderKeyDistributionMessage to all members of the group.
67
67
68
68
``` dart
69
- final senderAddress = SignalProtocolAddress('+00000000001', 1);
70
- final groupSender =
71
- SenderKeyName('Private group', senderAddress);
72
- final aliceStore = InMemorySenderKeyStore();
73
- final bobStore = InMemorySenderKeyStore();
74
-
75
- final aliceSessionBuilder = GroupSessionBuilder(aliceStore);
76
- final bobSessionBuilder = GroupSessionBuilder(bobStore);
77
-
78
- final aliceGroupCipher = GroupCipher(aliceStore, groupSender);
79
- final bobGroupCipher = GroupCipher(bobStore, groupSender);
80
-
81
- final sentAliceDistributionMessage = aliceSessionBuilder.create(groupSender);
82
- final receivedAliceDistributionMessage =
83
- SenderKeyDistributionMessageWrapper.fromSerialized(
84
- sentAliceDistributionMessage.serialize());
85
- bobSessionBuilder.process(groupSender, receivedAliceDistributionMessage);
86
-
87
- final ciphertextFromAlice = aliceGroupCipher
88
- .encrypt(Uint8List.fromList(utf8.encode('Hello Mixin')));
89
- final plaintextFromAlice = bobGroupCipher.decrypt(ciphertextFromAlice);
69
+ const alice = SignalProtocolAddress('+00000000001', 1);
70
+ const groupSender = SenderKeyName('Private group', alice);
71
+ final aliceStore = InMemorySenderKeyStore();
72
+ final bobStore = InMemorySenderKeyStore();
73
+
74
+ final aliceSessionBuilder = GroupSessionBuilder(aliceStore);
75
+ final bobSessionBuilder = GroupSessionBuilder(bobStore);
76
+
77
+ final aliceGroupCipher = GroupCipher(aliceStore, groupSender);
78
+ final bobGroupCipher = GroupCipher(bobStore, groupSender);
79
+
80
+ final sentAliceDistributionMessage =
81
+ await aliceSessionBuilder.create(groupSender);
82
+ final receivedAliceDistributionMessage =
83
+ SenderKeyDistributionMessageWrapper.fromSerialized(
84
+ sentAliceDistributionMessage.serialize());
85
+ await bobSessionBuilder.process(
86
+ groupSender, receivedAliceDistributionMessage);
87
+
88
+ final ciphertextFromAlice = await aliceGroupCipher
89
+ .encrypt(Uint8List.fromList(utf8.encode('Hello Mixin')));
90
+ final plaintextFromAlice = await bobGroupCipher.decrypt(ciphertextFromAlice);
91
+ // ignore: avoid_print
92
+ print(utf8.decode(plaintextFromAlice));
90
93
```
0 commit comments