@open-e2ee/signal-protocol-sdk 0.4.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (220) hide show
  1. package/CHANGELOG.md +63 -5
  2. package/README.md +10 -7
  3. package/SECURITY.md +2 -2
  4. package/THIRD_PARTY_NOTICES.md +1 -1
  5. package/device/README.md +7 -5
  6. package/dist/client/client.d.ts +3 -2
  7. package/dist/client/client.d.ts.map +1 -1
  8. package/dist/client/client.js +58 -25
  9. package/dist/client/client.js.map +1 -1
  10. package/dist/client/config.d.ts +46 -7
  11. package/dist/client/config.d.ts.map +1 -1
  12. package/dist/client/config.js +2 -2
  13. package/dist/client/config.js.map +1 -1
  14. package/dist/client/group-outbox.d.ts +38 -0
  15. package/dist/client/group-outbox.d.ts.map +1 -0
  16. package/dist/client/group-outbox.js +221 -0
  17. package/dist/client/group-outbox.js.map +1 -0
  18. package/dist/client/group-sealed-sender.d.ts +28 -0
  19. package/dist/client/group-sealed-sender.d.ts.map +1 -0
  20. package/dist/client/group-sealed-sender.js +74 -0
  21. package/dist/client/group-sealed-sender.js.map +1 -0
  22. package/dist/client/hosted-push.d.ts +77 -0
  23. package/dist/client/hosted-push.d.ts.map +1 -0
  24. package/dist/client/hosted-push.js +90 -0
  25. package/dist/client/hosted-push.js.map +1 -0
  26. package/dist/client/hosted.d.ts +207 -0
  27. package/dist/client/hosted.d.ts.map +1 -0
  28. package/dist/client/hosted.js +505 -0
  29. package/dist/client/hosted.js.map +1 -0
  30. package/dist/client/index.d.ts +4 -2
  31. package/dist/client/index.d.ts.map +1 -1
  32. package/dist/client/index.js +2 -0
  33. package/dist/client/index.js.map +1 -1
  34. package/dist/client/relay-subscription.d.ts.map +1 -1
  35. package/dist/client/relay-subscription.js +34 -7
  36. package/dist/client/relay-subscription.js.map +1 -1
  37. package/dist/client/{sealed-sender-ops.d.ts → sealed-sender.d.ts} +39 -22
  38. package/dist/client/sealed-sender.d.ts.map +1 -0
  39. package/dist/client/sealed-sender.js +296 -0
  40. package/dist/client/sealed-sender.js.map +1 -0
  41. package/dist/client/signal-service-cipher.d.ts +23 -26
  42. package/dist/client/signal-service-cipher.d.ts.map +1 -1
  43. package/dist/client/signal-service-cipher.js +465 -706
  44. package/dist/client/signal-service-cipher.js.map +1 -1
  45. package/dist/client/types.d.ts +18 -3
  46. package/dist/client/types.d.ts.map +1 -1
  47. package/dist/client/types.js +6 -0
  48. package/dist/client/types.js.map +1 -1
  49. package/dist/device/index.d.ts +2 -2
  50. package/dist/device/index.d.ts.map +1 -1
  51. package/dist/device/index.js +1 -1
  52. package/dist/device/index.js.map +1 -1
  53. package/dist/device/transfer.d.ts +7 -43
  54. package/dist/device/transfer.d.ts.map +1 -1
  55. package/dist/device/transfer.js +31 -150
  56. package/dist/device/transfer.js.map +1 -1
  57. package/dist/device/types.d.ts +6 -47
  58. package/dist/device/types.d.ts.map +1 -1
  59. package/dist/device/types.js +1 -1
  60. package/dist/device/types.js.map +1 -1
  61. package/dist/index.d.ts +5 -4
  62. package/dist/index.d.ts.map +1 -1
  63. package/dist/index.js +2 -1
  64. package/dist/index.js.map +1 -1
  65. package/dist/internal/encoding/proto/pq-ratchet-serialize.js +1 -1
  66. package/dist/internal/encoding/proto/pq-ratchet-serialize.js.map +1 -1
  67. package/dist/internal/encoding/proto/primitives.js +1 -1
  68. package/dist/internal/encoding/proto/primitives.js.map +1 -1
  69. package/dist/internal/groups/manager.d.ts +3 -3
  70. package/dist/internal/groups/manager.d.ts.map +1 -1
  71. package/dist/internal/groups/manager.js +5 -4
  72. package/dist/internal/groups/manager.js.map +1 -1
  73. package/dist/internal/protocol/sealed-sender/certificate.d.ts +10 -4
  74. package/dist/internal/protocol/sealed-sender/certificate.d.ts.map +1 -1
  75. package/dist/internal/protocol/sealed-sender/certificate.js +64 -7
  76. package/dist/internal/protocol/sealed-sender/certificate.js.map +1 -1
  77. package/dist/internal/protocol/sealed-sender/decryption.d.ts +34 -47
  78. package/dist/internal/protocol/sealed-sender/decryption.d.ts.map +1 -1
  79. package/dist/internal/protocol/sealed-sender/decryption.js +95 -182
  80. package/dist/internal/protocol/sealed-sender/decryption.js.map +1 -1
  81. package/dist/internal/protocol/sealed-sender/encryption.d.ts +49 -64
  82. package/dist/internal/protocol/sealed-sender/encryption.d.ts.map +1 -1
  83. package/dist/internal/protocol/sealed-sender/encryption.js +120 -123
  84. package/dist/internal/protocol/sealed-sender/encryption.js.map +1 -1
  85. package/dist/internal/protocol/sealed-sender/index.d.ts +5 -7
  86. package/dist/internal/protocol/sealed-sender/index.d.ts.map +1 -1
  87. package/dist/internal/protocol/sealed-sender/index.js +4 -12
  88. package/dist/internal/protocol/sealed-sender/index.js.map +1 -1
  89. package/dist/internal/protocol/sealed-sender/{v2-helpers.d.ts → multi-recipient-crypto.d.ts} +1 -1
  90. package/dist/internal/protocol/sealed-sender/multi-recipient-crypto.d.ts.map +1 -0
  91. package/dist/internal/protocol/sealed-sender/{v2-helpers.js → multi-recipient-crypto.js} +1 -1
  92. package/dist/internal/protocol/sealed-sender/multi-recipient-crypto.js.map +1 -0
  93. package/dist/internal/protocol/sealed-sender/{v2-binary.d.ts → multi-recipient-message.d.ts} +3 -2
  94. package/dist/internal/protocol/sealed-sender/multi-recipient-message.d.ts.map +1 -0
  95. package/dist/internal/protocol/sealed-sender/{v2-binary.js → multi-recipient-message.js} +16 -8
  96. package/dist/internal/protocol/sealed-sender/multi-recipient-message.js.map +1 -0
  97. package/dist/internal/protocol/sealed-sender/proto/index.d.ts +3 -0
  98. package/dist/internal/protocol/sealed-sender/proto/index.d.ts.map +1 -1
  99. package/dist/internal/protocol/sealed-sender/proto/index.js +25 -2
  100. package/dist/internal/protocol/sealed-sender/proto/index.js.map +1 -1
  101. package/dist/internal/protocol/sealed-sender/trust-root.d.ts +11 -1
  102. package/dist/internal/protocol/sealed-sender/trust-root.d.ts.map +1 -1
  103. package/dist/internal/protocol/sealed-sender/trust-root.js +13 -1
  104. package/dist/internal/protocol/sealed-sender/trust-root.js.map +1 -1
  105. package/dist/internal/protocol/sealed-sender/types.d.ts +20 -135
  106. package/dist/internal/protocol/sealed-sender/types.d.ts.map +1 -1
  107. package/dist/internal/protocol/sealed-sender/types.js +15 -6
  108. package/dist/internal/protocol/sealed-sender/types.js.map +1 -1
  109. package/dist/internal/protocol/sender-keys/manager.d.ts +22 -1
  110. package/dist/internal/protocol/sender-keys/manager.d.ts.map +1 -1
  111. package/dist/internal/protocol/sender-keys/manager.js +39 -4
  112. package/dist/internal/protocol/sender-keys/manager.js.map +1 -1
  113. package/dist/internal/protocol/spqr/braid-serialize.js +1 -1
  114. package/dist/internal/protocol/spqr/braid-serialize.js.map +1 -1
  115. package/dist/internal/protocol/spqr/ml-kem-braid/state-machine.js +4 -4
  116. package/dist/internal/protocol/spqr/ml-kem-braid/state-machine.js.map +1 -1
  117. package/dist/internal/protocol/zk/groups/index.d.ts +1 -1
  118. package/dist/internal/protocol/zk/groups/index.d.ts.map +1 -1
  119. package/dist/internal/protocol/zk/groups/index.js +1 -1
  120. package/dist/internal/protocol/zk/groups/index.js.map +1 -1
  121. package/dist/internal/protocol/zk/groups/profile-key-credential.d.ts +37 -12
  122. package/dist/internal/protocol/zk/groups/profile-key-credential.d.ts.map +1 -1
  123. package/dist/internal/protocol/zk/groups/profile-key-credential.js +104 -31
  124. package/dist/internal/protocol/zk/groups/profile-key-credential.js.map +1 -1
  125. package/dist/local/store/expo/adapter.d.ts +1 -0
  126. package/dist/local/store/expo/adapter.d.ts.map +1 -1
  127. package/dist/local/store/expo/adapter.js +3 -0
  128. package/dist/local/store/expo/adapter.js.map +1 -1
  129. package/dist/local/store/expo/key-storage.d.ts +1 -0
  130. package/dist/local/store/expo/key-storage.d.ts.map +1 -1
  131. package/dist/local/store/expo/key-storage.js +4 -0
  132. package/dist/local/store/expo/key-storage.js.map +1 -1
  133. package/dist/local/store/memory/adapter.d.ts +1 -0
  134. package/dist/local/store/memory/adapter.d.ts.map +1 -1
  135. package/dist/local/store/memory/adapter.js +4 -0
  136. package/dist/local/store/memory/adapter.js.map +1 -1
  137. package/dist/local/store/node/adapter.d.ts +1 -0
  138. package/dist/local/store/node/adapter.d.ts.map +1 -1
  139. package/dist/local/store/node/adapter.js +3 -0
  140. package/dist/local/store/node/adapter.js.map +1 -1
  141. package/dist/local/store/node/database.d.ts +1 -0
  142. package/dist/local/store/node/database.d.ts.map +1 -1
  143. package/dist/local/store/node/database.js +5 -0
  144. package/dist/local/store/node/database.js.map +1 -1
  145. package/dist/local/store/react-native/adapter.d.ts +1 -0
  146. package/dist/local/store/react-native/adapter.d.ts.map +1 -1
  147. package/dist/local/store/react-native/adapter.js +4 -0
  148. package/dist/local/store/react-native/adapter.js.map +1 -1
  149. package/dist/local/store/react-native/reference-backend.js +1 -1
  150. package/dist/local/store/react-native/reference-backend.js.map +1 -1
  151. package/dist/local/store/reliability.d.ts +63 -0
  152. package/dist/local/store/reliability.d.ts.map +1 -0
  153. package/dist/local/store/reliability.js +219 -0
  154. package/dist/local/store/reliability.js.map +1 -0
  155. package/dist/local/store/web/adapter.d.ts +1 -0
  156. package/dist/local/store/web/adapter.d.ts.map +1 -1
  157. package/dist/local/store/web/adapter.js +5 -0
  158. package/dist/local/store/web/adapter.js.map +1 -1
  159. package/dist/remote/relay/convex/backend.d.ts +4 -14
  160. package/dist/remote/relay/convex/backend.d.ts.map +1 -1
  161. package/dist/remote/relay/convex/backend.js +11 -20
  162. package/dist/remote/relay/convex/backend.js.map +1 -1
  163. package/dist/remote/relay/convex/component/_generated/component.d.ts +7 -14
  164. package/dist/remote/relay/convex/component/_generated/component.d.ts.map +1 -1
  165. package/dist/remote/relay/convex/component/certificates.d.ts.map +1 -1
  166. package/dist/remote/relay/convex/component/certificates.js +14 -5
  167. package/dist/remote/relay/convex/component/certificates.js.map +1 -1
  168. package/dist/remote/relay/convex/component/messages.d.ts +0 -13
  169. package/dist/remote/relay/convex/component/messages.d.ts.map +1 -1
  170. package/dist/remote/relay/convex/component/messages.js +13 -47
  171. package/dist/remote/relay/convex/component/messages.js.map +1 -1
  172. package/dist/remote/relay/convex/component/schema.d.ts +3 -1
  173. package/dist/remote/relay/convex/component/schema.js +1 -0
  174. package/dist/remote/relay/convex/component/schema.js.map +1 -1
  175. package/dist/remote/relay/convex/component/zkAuth.d.ts +7 -1
  176. package/dist/remote/relay/convex/component/zkAuth.d.ts.map +1 -1
  177. package/dist/remote/relay/convex/component/zkAuth.js +29 -14
  178. package/dist/remote/relay/convex/component/zkAuth.js.map +1 -1
  179. package/dist/remote/relay/convex/relay.d.ts +2 -5
  180. package/dist/remote/relay/convex/relay.d.ts.map +1 -1
  181. package/dist/remote/relay/convex/relay.js +17 -47
  182. package/dist/remote/relay/convex/relay.js.map +1 -1
  183. package/dist/remote/relay/memory/adapter.d.ts +4 -10
  184. package/dist/remote/relay/memory/adapter.d.ts.map +1 -1
  185. package/dist/remote/relay/memory/adapter.js +31 -34
  186. package/dist/remote/relay/memory/adapter.js.map +1 -1
  187. package/dist/remote/relay/types.d.ts +6 -19
  188. package/dist/remote/relay/types.d.ts.map +1 -1
  189. package/dist/types/api.d.ts +2 -0
  190. package/dist/types/api.d.ts.map +1 -1
  191. package/dist/types/errors.d.ts +3 -1
  192. package/dist/types/errors.d.ts.map +1 -1
  193. package/dist/types/errors.js +4 -2
  194. package/dist/types/errors.js.map +1 -1
  195. package/dist/types/protocol-config.d.ts +1 -1
  196. package/dist/username/link.d.ts.map +1 -1
  197. package/dist/username/link.js +1 -1
  198. package/dist/username/link.js.map +1 -1
  199. package/docs/ASSURANCE.md +5 -5
  200. package/docs/DEVIATIONS.md +32 -61
  201. package/docs/GETTING_STARTED.md +7 -0
  202. package/docs/SECURITY.md +6 -0
  203. package/package.json +1 -1
  204. package/remote/relay/convex/component/README.md +20 -14
  205. package/scripts/oe-groups.mjs +5 -1
  206. package/dist/client/sealed-sender-ops.d.ts.map +0 -1
  207. package/dist/client/sealed-sender-ops.js +0 -203
  208. package/dist/client/sealed-sender-ops.js.map +0 -1
  209. package/dist/internal/protocol/sealed-sender/decryption-v2.d.ts +0 -46
  210. package/dist/internal/protocol/sealed-sender/decryption-v2.d.ts.map +0 -1
  211. package/dist/internal/protocol/sealed-sender/decryption-v2.js +0 -198
  212. package/dist/internal/protocol/sealed-sender/decryption-v2.js.map +0 -1
  213. package/dist/internal/protocol/sealed-sender/encryption-v2.d.ts +0 -56
  214. package/dist/internal/protocol/sealed-sender/encryption-v2.d.ts.map +0 -1
  215. package/dist/internal/protocol/sealed-sender/encryption-v2.js +0 -163
  216. package/dist/internal/protocol/sealed-sender/encryption-v2.js.map +0 -1
  217. package/dist/internal/protocol/sealed-sender/v2-binary.d.ts.map +0 -1
  218. package/dist/internal/protocol/sealed-sender/v2-binary.js.map +0 -1
  219. package/dist/internal/protocol/sealed-sender/v2-helpers.d.ts.map +0 -1
  220. package/dist/internal/protocol/sealed-sender/v2-helpers.js.map +0 -1
@@ -0,0 +1,221 @@
1
+ import { EncryptionError, EncryptionErrorCode } from '../types/index.js';
2
+ import { SealedSenderAuthError } from '../types/errors.js';
3
+ import * as CryptoUtils from '../internal/crypto/index.js';
4
+ import { appendOutgoingGroupDeviceMessages, completeOutgoingMessageIntent, getOutgoingMessageIntent, storeOutgoingMessageIntent, withOutgoingMessageIntentLock, } from '../local/store/reliability.js';
5
+ async function sendStoredDeviceMessage(context, intent, message, forceIdentified = false) {
6
+ const relay = context.relay;
7
+ if (!relay)
8
+ throw new Error('Relay is required for a stored group transmission');
9
+ if (message.sealedSenderMessage && !relay.sendMultiRecipientUnidentified) {
10
+ if (message.sealedSenderDeliveryMode === 'required') {
11
+ throw new EncryptionError('Required group sealed-sender transport is unavailable', EncryptionErrorCode.SEALED_SENDER_REQUIRED, { recipientUserId: message.recipientUserId });
12
+ }
13
+ return sendStoredDeviceMessage(context, intent, message, true);
14
+ }
15
+ if (forceIdentified || !message.sealedSenderMessage) {
16
+ return relay.send({
17
+ targetUserId: message.recipientUserId,
18
+ targetDeviceId: message.recipientDeviceId,
19
+ senderUserId: context.senderUserId,
20
+ senderDeviceId: context.senderDeviceId,
21
+ ciphertext: message.ciphertext,
22
+ messageType: message.messageType,
23
+ timestamp: message.timestamp,
24
+ clientMessageId: intent.clientMessageId,
25
+ });
26
+ }
27
+ const auth = message.sealedSenderAuthorization === 'access_key' && message.sealedSenderAccessKey
28
+ ? {
29
+ type: 'accessKey',
30
+ unidentifiedAccessKey: message.sealedSenderAccessKey,
31
+ }
32
+ : message.sealedSenderAuthorization === 'group_send_token'
33
+ ? await context.resolveGroupAuthorization(intent.recipientId, [message.recipientUserId])
34
+ : null;
35
+ if (!auth) {
36
+ if (message.sealedSenderDeliveryMode === 'required') {
37
+ throw new Error('Required group sealed-sender authorization is unavailable');
38
+ }
39
+ return sendStoredDeviceMessage(context, intent, message, true);
40
+ }
41
+ return context.sendPreparedSealedDevice(intent, message, auth);
42
+ }
43
+ async function sendStoredGroupIntent(context, initialIntent) {
44
+ let intent = initialIntent;
45
+ if (intent.kind !== 'group')
46
+ throw new Error('Expected a group outbox intent');
47
+ if (!intent.groupCiphertext)
48
+ throw new Error('Corrupt group outbox intent');
49
+ const relay = context.relay;
50
+ if (!relay) {
51
+ const localResult = {
52
+ clientMessageId: intent.clientMessageId,
53
+ messageId: `local-${intent.clientTimestamp}`,
54
+ timestamp: intent.clientTimestamp,
55
+ recipientDeviceCount: intent.groupRecipientDeviceCount ?? 0,
56
+ groupId: intent.recipientId,
57
+ };
58
+ await completeOutgoingMessageIntent(context.storage, intent.clientMessageId, localResult);
59
+ return localResult;
60
+ }
61
+ let messageId = `group-${intent.recipientId}-${String(intent.clientTimestamp)}`;
62
+ let timestamp = intent.clientTimestamp;
63
+ let sharedSucceeded = false;
64
+ let skippedUsers = [];
65
+ for (const message of intent.preMessages ?? []) {
66
+ await relay.send({
67
+ targetUserId: message.recipientUserId,
68
+ targetDeviceId: message.recipientDeviceId,
69
+ senderUserId: context.senderUserId,
70
+ senderDeviceId: context.senderDeviceId,
71
+ ciphertext: message.ciphertext,
72
+ messageType: message.messageType,
73
+ timestamp: message.timestamp,
74
+ clientMessageId: message.clientMessageId,
75
+ recipientRegistrationId: message.recipientRegistrationId,
76
+ });
77
+ }
78
+ if (intent.groupSenderKeyDistributionId) {
79
+ await context.confirmSenderKeyDistributionSent(intent.recipientId, intent.groupSenderKeyDistributionId);
80
+ }
81
+ if (intent.groupSharedMessage?.deliveryMode === 'required' &&
82
+ !relay.sendMultiRecipientUnidentified) {
83
+ throw new EncryptionError('Required group sealed-sender transport is unavailable', EncryptionErrorCode.SEALED_SENDER_REQUIRED, { groupId: intent.recipientId });
84
+ }
85
+ if (intent.groupSharedMessage && relay.sendMultiRecipientUnidentified) {
86
+ const auth = await context.resolveGroupAuthorization(intent.groupSharedMessage.groupId, intent.groupSharedMessage.recipientUserIds);
87
+ if (!auth) {
88
+ if (intent.groupSharedMessage.deliveryMode === 'required') {
89
+ throw new Error('Required group sealed-sender authorization is unavailable');
90
+ }
91
+ }
92
+ else {
93
+ try {
94
+ const result = await relay.sendMultiRecipientUnidentified(intent.groupSharedMessage.sentMessageBase64, auth, intent.clientTimestamp, intent.groupSharedMessage.recipientUserIds, intent.clientMessageId);
95
+ messageId = result.messageId;
96
+ timestamp = result.serverTimestamp;
97
+ skippedUsers = result.uuids404;
98
+ sharedSucceeded = true;
99
+ }
100
+ catch (error) {
101
+ if (!(error instanceof SealedSenderAuthError))
102
+ throw error;
103
+ if (intent.groupSharedMessage.deliveryMode === 'required')
104
+ throw error;
105
+ await Promise.all(intent.groupSharedMessage.recipientUserIds.map((recipientUserId) => context.reportIdentifiedFallback(recipientUserId)));
106
+ }
107
+ }
108
+ }
109
+ const sharedUsers = new Set(intent.groupSharedMessage?.recipientUserIds ?? []);
110
+ const usersToRepair = new Set(skippedUsers);
111
+ const forceIdentified = Boolean(intent.groupSharedMessage && !sharedSucceeded);
112
+ for (const message of intent.deviceMessages) {
113
+ if (sharedSucceeded && sharedUsers.has(message.recipientUserId)) {
114
+ if (!usersToRepair.has(message.recipientUserId))
115
+ continue;
116
+ }
117
+ const result = await sendStoredDeviceMessage(context, intent, message, forceIdentified);
118
+ if (messageId.startsWith('group-')) {
119
+ messageId = result.messageId;
120
+ timestamp = result.serverTimestamp;
121
+ }
122
+ }
123
+ if (skippedUsers.length > 0) {
124
+ const refreshed = (await Promise.all(skippedUsers.map((userId) => relay.getActiveDevices(userId)))).flat();
125
+ const knownTargets = new Set(intent.deviceMessages.map((message) => `${message.recipientUserId}\u0000${String(message.recipientDeviceId)}`));
126
+ const additions = [];
127
+ for (const member of refreshed) {
128
+ const target = `${member.userId}\u0000${String(member.deviceId)}`;
129
+ if (knownTargets.has(target))
130
+ continue;
131
+ additions.push(await context.prepareDeviceMessage(member, intent.recipientId, intent.groupCiphertext, intent.clientTimestamp));
132
+ }
133
+ if (additions.length > 0) {
134
+ intent = await appendOutgoingGroupDeviceMessages(context.storage, intent.clientMessageId, additions);
135
+ for (const message of additions) {
136
+ await sendStoredDeviceMessage(context, intent, message);
137
+ }
138
+ }
139
+ }
140
+ for (const message of intent.syncMessages) {
141
+ await relay.send({
142
+ targetUserId: message.recipientUserId,
143
+ targetDeviceId: message.recipientDeviceId,
144
+ senderUserId: context.senderUserId,
145
+ senderDeviceId: context.senderDeviceId,
146
+ ciphertext: message.ciphertext,
147
+ messageType: message.messageType,
148
+ timestamp: message.timestamp,
149
+ clientMessageId: message.clientMessageId,
150
+ });
151
+ }
152
+ const result = {
153
+ clientMessageId: intent.clientMessageId,
154
+ messageId,
155
+ timestamp,
156
+ recipientDeviceCount: intent.groupRecipientDeviceCount ?? intent.deviceMessages.length,
157
+ groupId: intent.recipientId,
158
+ };
159
+ await completeOutgoingMessageIntent(context.storage, intent.clientMessageId, result);
160
+ return result;
161
+ }
162
+ export async function sendGroupWithExactOutbox(context, groupId, plaintextBytes, options) {
163
+ return withOutgoingMessageIntentLock(context.storage, options.clientMessageId, async () => {
164
+ const plaintextDigest = CryptoUtils.bytesToBase64(await CryptoUtils.sha256(plaintextBytes));
165
+ const groupMemberUserIds = [...new Set(options.groupMemberUserIds ?? [])].sort();
166
+ const existing = await getOutgoingMessageIntent(context.storage, options.clientMessageId);
167
+ if (existing) {
168
+ if (existing.kind !== 'group' ||
169
+ existing.recipientId !== groupId ||
170
+ existing.plaintextDigest !== plaintextDigest ||
171
+ (options.timestamp !== undefined && existing.clientTimestamp !== options.timestamp) ||
172
+ JSON.stringify(existing.groupMemberUserIds) !== JSON.stringify(groupMemberUserIds)) {
173
+ throw new Error('A clientMessageId cannot identify two different logical sends');
174
+ }
175
+ if (existing.result)
176
+ return existing.result;
177
+ return sendStoredGroupIntent(context, existing);
178
+ }
179
+ const clientTimestamp = options.timestamp ?? Date.now();
180
+ const preparedPayload = await context.preparePayload(groupId, plaintextBytes, {
181
+ ...options,
182
+ timestamp: clientTimestamp,
183
+ });
184
+ const encryptedMessageBase64 = preparedPayload.ciphertext;
185
+ const members = context.relay ? await context.resolveMemberDevices(groupId, options) : [];
186
+ const otherMembers = members.filter((member) => member.userId !== context.senderUserId);
187
+ const groupSharedMessage = await context.prepareSharedMessage(groupId, otherMembers, encryptedMessageBase64);
188
+ const deviceMessages = await Promise.all(otherMembers.map((member) => context.prepareDeviceMessage(member, groupId, encryptedMessageBase64, clientTimestamp)));
189
+ const syncMessages = context.relay
190
+ ? await context.prepareSyncMessages(groupId, plaintextBytes, clientTimestamp, options.clientMessageId)
191
+ : [];
192
+ const intent = {
193
+ kind: 'group',
194
+ clientMessageId: options.clientMessageId,
195
+ recipientId: groupId,
196
+ plaintextDigest,
197
+ clientTimestamp,
198
+ createdAt: Date.now(),
199
+ transportMode: groupSharedMessage
200
+ ? context.deliveryMode === 'required'
201
+ ? 'sealed_sender_required'
202
+ : 'sealed_sender_preferred'
203
+ : 'identified',
204
+ ...(preparedPayload.preMessages.length > 0 && {
205
+ preMessages: preparedPayload.preMessages,
206
+ }),
207
+ deviceMessages,
208
+ syncMessages,
209
+ groupMemberUserIds,
210
+ groupRecipientDeviceCount: otherMembers.length,
211
+ groupCiphertext: encryptedMessageBase64,
212
+ ...(preparedPayload.senderKeyDistributionId && {
213
+ groupSenderKeyDistributionId: preparedPayload.senderKeyDistributionId,
214
+ }),
215
+ ...(groupSharedMessage && { groupSharedMessage }),
216
+ };
217
+ await storeOutgoingMessageIntent(context.storage, intent);
218
+ return sendStoredGroupIntent(context, intent);
219
+ });
220
+ }
221
+ //# sourceMappingURL=group-outbox.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"group-outbox.js","sourceRoot":"","sources":["../../client/group-outbox.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAChE,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,KAAK,WAAW,MAAM,oBAAoB,CAAC;AAMlD,OAAO,EACL,iCAAiC,EACjC,6BAA6B,EAC7B,wBAAwB,EACxB,0BAA0B,EAC1B,6BAA6B,GAG9B,MAAM,4BAA4B,CAAC;AAoDpC,KAAK,UAAU,uBAAuB,CACpC,OAA2B,EAC3B,MAAmC,EACnC,OAAoC,EACpC,eAAe,GAAG,KAAK;IAEvB,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;IAC5B,IAAI,CAAC,KAAK;QAAE,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;IACjF,IAAI,OAAO,CAAC,mBAAmB,IAAI,CAAC,KAAK,CAAC,8BAA8B,EAAE,CAAC;QACzE,IAAI,OAAO,CAAC,wBAAwB,KAAK,UAAU,EAAE,CAAC;YACpD,MAAM,IAAI,eAAe,CACvB,uDAAuD,EACvD,mBAAmB,CAAC,sBAAsB,EAC1C,EAAE,eAAe,EAAE,OAAO,CAAC,eAAe,EAAE,CAC7C,CAAC;QACJ,CAAC;QACD,OAAO,uBAAuB,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;IACjE,CAAC;IACD,IAAI,eAA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js';
2
+ import type { ISignalProtocolLocalStore } from '../types/index.js';
3
+ export interface GroupSealedSenderKeys {
4
+ senderCertificateBase64: string;
5
+ senderIdentityPrivate: Uint8Array;
6
+ senderIdentityPublic: Uint8Array;
7
+ }
8
+ export interface PreparedGroupSharedMessage {
9
+ sentMessageBase64: string;
10
+ recipientUserIds: string[];
11
+ sharedMembers: GroupMemberDevice[];
12
+ fallbackMembers: GroupMemberDevice[];
13
+ }
14
+ /**
15
+ * Prepare one immutable multi-recipient sealed-sender body for a group send.
16
+ *
17
+ * Recipient identity and registration data are captured in the body. Callers
18
+ * can persist the returned bytes before transport and replay them verbatim.
19
+ * Members without a known identity remain outside the shared body and must be
20
+ * handled by a separately persisted per-device plan.
21
+ */
22
+ export declare function prepareGroupSharedMessage(input: {
23
+ storage: ISignalProtocolLocalStore;
24
+ senderKeys: GroupSealedSenderKeys;
25
+ members: GroupMemberDevice[];
26
+ encryptedMessageBase64: string;
27
+ }): Promise<PreparedGroupSharedMessage | null>;
28
+ //# sourceMappingURL=group-sealed-sender.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"group-sealed-sender.d.ts","sourceRoot":"","sources":["../../client/group-sealed-sender.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC/D,OAAO,KAAK,EAAE,yBAAyB,EAAU,MAAM,UAAU,CAAC;AAUlE,MAAM,WAAW,qBAAqB;IACpC,uBAAuB,EAAE,MAAM,CAAC;IAChC,qBAAqB,EAAE,UAAU,CAAC;IAClC,oBAAoB,EAAE,UAAU,CAAC;CAClC;AAED,MAAM,WAAW,0BAA0B;IACzC,iBAAiB,EAAE,MAAM,CAAC;IAC1B,gBAAgB,EAAE,MAAM,EAAE,CAAC;IAC3B,aAAa,EAAE,iBAAiB,EAAE,CAAC;IACnC,eAAe,EAAE,iBAAiB,EAAE,CAAC;CACtC;AAED;;;;;;;GAOG;AACH,wBAAsB,yBAAyB,CAAC,KAAK,EAAE;IACrD,OAAO,EAAE,yBAAyB,CAAC;IACnC,UAAU,EAAE,qBAAqB,CAAC;IAClC,OAAO,EAAE,iBAAiB,EAAE,CAAC;IAC7B,sBAAsB,EAAE,MAAM,CAAC;CAChC,GAAG,OAAO,CAAC,0BAA0B,GAAG,IAAI,CAAC,CAuF7C"}
@@ -0,0 +1,74 @@
1
+ import { ProtocolAddress } from '../types/address.js';
2
+ import { base64ToBytes, bytesToBase64 } from '../internal/crypto/index.js';
3
+ import { deserializeSenderCertificate, sealMultiRecipient, } from '../internal/protocol/sealed-sender/index.js';
4
+ import { serializeSentMessage } from '../internal/protocol/sealed-sender/multi-recipient-message.js';
5
+ import { SealedSenderContentType } from '../internal/protocol/sealed-sender/types.js';
6
+ /**
7
+ * Prepare one immutable multi-recipient sealed-sender body for a group send.
8
+ *
9
+ * Recipient identity and registration data are captured in the body. Callers
10
+ * can persist the returned bytes before transport and replay them verbatim.
11
+ * Members without a known identity remain outside the shared body and must be
12
+ * handled by a separately persisted per-device plan.
13
+ */
14
+ export async function prepareGroupSharedMessage(input) {
15
+ const identityByUser = new Map();
16
+ const uniqueUserIds = [...new Set(input.members.map((member) => member.userId))];
17
+ for (const userId of uniqueUserIds) {
18
+ const identityRecord = await input.storage.getContactIdentity(ProtocolAddress.create(userId, 1));
19
+ if (identityRecord) {
20
+ identityByUser.set(userId, base64ToBytes(identityRecord.identity.x25519PublicKey));
21
+ }
22
+ }
23
+ const sharedMembers = input.members.filter((member) => identityByUser.has(member.userId));
24
+ const fallbackMembers = input.members.filter((member) => !identityByUser.has(member.userId));
25
+ if (sharedMembers.length === 0)
26
+ return null;
27
+ const recipients = await Promise.all(sharedMembers.map(async (member) => {
28
+ const session = await input.storage.getSessionRecord(ProtocolAddress.create(member.userId, member.deviceId));
29
+ return {
30
+ serviceId: member.userId,
31
+ deviceId: member.deviceId,
32
+ registrationId: session?.currentSession?.remoteRegistrationId ?? 0,
33
+ identityPublic: identityByUser.get(member.userId),
34
+ };
35
+ }));
36
+ const sealed = await sealMultiRecipient({
37
+ senderCertificate: deserializeSenderCertificate(base64ToBytes(input.senderKeys.senderCertificateBase64)),
38
+ senderIdentityPrivate: input.senderKeys.senderIdentityPrivate,
39
+ senderIdentityPublic: input.senderKeys.senderIdentityPublic,
40
+ recipients,
41
+ signalProtocolMessage: base64ToBytes(input.encryptedMessageBase64),
42
+ contentType: SealedSenderContentType.SENDERKEY_MESSAGE,
43
+ });
44
+ const recipientsByUser = new Map();
45
+ for (const recipient of sealed.recipients) {
46
+ const existing = recipientsByUser.get(recipient.serviceId);
47
+ if (existing) {
48
+ existing.devices.push({
49
+ deviceId: recipient.deviceId,
50
+ registrationId: recipient.registrationId,
51
+ });
52
+ }
53
+ else {
54
+ recipientsByUser.set(recipient.serviceId, {
55
+ serviceId: recipient.serviceId,
56
+ devices: [
57
+ {
58
+ deviceId: recipient.deviceId,
59
+ registrationId: recipient.registrationId,
60
+ },
61
+ ],
62
+ encryptedMessageKey: base64ToBytes(recipient.encryptedMessageKey),
63
+ authenticationTag: base64ToBytes(recipient.authenticationTag),
64
+ });
65
+ }
66
+ }
67
+ return {
68
+ sentMessageBase64: bytesToBase64(serializeSentMessage([...recipientsByUser.values()], [], base64ToBytes(sealed.ephemeralPublic), base64ToBytes(sealed.messageCiphertext))),
69
+ recipientUserIds: [...recipientsByUser.keys()],
70
+ sharedMembers,
71
+ fallbackMembers,
72
+ };
73
+ }
74
+ //# sourceMappingURL=group-sealed-sender.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"group-sealed-sender.js","sourceRoot":"","sources":["../../client/group-sealed-sender.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAClE,OAAO,EACL,4BAA4B,EAC5B,kBAAkB,GACnB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,oBAAoB,EAAE,MAAM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,QAAQ,EAAE,SAAS,CAAC,QAAQ;wBAC5B,cAAc,EAAE,SAAS,CAAC,cAAc;qBACzC;iBACF;gBACD,mBAAmB,EAAE,aAAa,CAAC,SAAS,CAAC,mBAA6B,CAAC;gBAC3E,iBAAiB,EAAE,aAAa,CAAC,SAAS,CAAC,iBAA2B,CAAC;aACxE,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED,OAAO;QACL,iBAAiB,EAAE,aAAa,CAC9B,oBAAoB,CAClB,CAAC,GAAG,gBAAgB,CAAC,MAAM,EAAE,CAAC,EAC9B,EAAE,EACF,aAAa,CAAC,MAAM,CAAC,eAAyB,CAAC,EAC/C,aAAa,CAAC,MAAM,CAAC,iBAA2B,CAAC,CAClD,CACF;QACD,gBAAgB,EAAE,CAAC,GAAG,gBAAgB,CAAC,IAAI,EAAE,CAAC;QAC9C,aAAa;QACb,eAAe;KAChB,CAAC;AACJ,CAAC"}
@@ -0,0 +1,77 @@
1
+ import type { SignalProtocolClient } from './client.js';
2
+ import type { IncomingEnvelope, ProcessEnvelopeOptions } from './types.js';
3
+ /** Native or Expo provider token registered for this authenticated device. */
4
+ export type HostedRelayTokenPushRegistration = {
5
+ readonly provider: 'apns' | 'expo' | 'fcm';
6
+ readonly token: string;
7
+ };
8
+ /** Browser Push API subscription registered for this authenticated device. */
9
+ export interface HostedRelayWebPushRegistration {
10
+ readonly endpoint: string;
11
+ readonly keys: {
12
+ readonly auth: string;
13
+ readonly p256dh: string;
14
+ };
15
+ readonly provider: 'web-push';
16
+ }
17
+ /** Supported data-only wake registration shapes. */
18
+ export type HostedRelayPushRegistration = HostedRelayTokenPushRegistration | HostedRelayWebPushRegistration;
19
+ export interface HostedRelayPushRegistrationRequest {
20
+ readonly publishableKey: string;
21
+ readonly registration: HostedRelayPushRegistration;
22
+ }
23
+ export interface HostedRelayPushRemovalRequest {
24
+ readonly publishableKey: string;
25
+ }
26
+ export interface HostedRelayMailboxPullRequest {
27
+ readonly publishableKey: string;
28
+ }
29
+ export interface HostedRelayMailboxAcknowledgmentRequest {
30
+ readonly messageIds: readonly string[];
31
+ readonly publishableKey: string;
32
+ }
33
+ /**
34
+ * Authenticated hosted transport for wake registration and durable mailbox pull.
35
+ *
36
+ * The adapter owns the device credential. These request shapes do not accept an
37
+ * account, device, scope, or generation because the Relay derives those fields
38
+ * from that credential.
39
+ */
40
+ export interface HostedRelayPushAdapter {
41
+ acknowledgeMailbox(request: HostedRelayMailboxAcknowledgmentRequest): Promise<void>;
42
+ pullMailbox(request: HostedRelayMailboxPullRequest): Promise<readonly IncomingEnvelope[]>;
43
+ registerPush(request: HostedRelayPushRegistrationRequest): Promise<void>;
44
+ removePush(request: HostedRelayPushRemovalRequest): Promise<void>;
45
+ }
46
+ export interface HostedRelayWakeClient {
47
+ processIncomingEnvelopes(envelopes: IncomingEnvelope[], options?: ProcessEnvelopeOptions): ReturnType<SignalProtocolClient['processIncomingEnvelopes']>;
48
+ }
49
+ export interface HostedRelayWakeOptions {
50
+ readonly adapter: HostedRelayPushAdapter;
51
+ readonly client: HostedRelayWakeClient;
52
+ readonly processOptions?: ProcessEnvelopeOptions;
53
+ readonly publishableKey: string;
54
+ }
55
+ export interface HostedRelayWakeResult {
56
+ readonly acknowledgedMessageIds: readonly string[];
57
+ readonly failedMessageIds: readonly string[];
58
+ readonly pulled: number;
59
+ }
60
+ /** Register a data-only wake destination for the adapter's authenticated device. */
61
+ export declare function registerHostedRelayPush(options: {
62
+ readonly adapter: HostedRelayPushAdapter;
63
+ readonly publishableKey: string;
64
+ readonly registration: HostedRelayPushRegistration;
65
+ }): Promise<void>;
66
+ /** Remove the data-only wake destination for the adapter's authenticated device. */
67
+ export declare function removeHostedRelayPush(options: {
68
+ readonly adapter: HostedRelayPushAdapter;
69
+ readonly publishableKey: string;
70
+ }): Promise<void>;
71
+ /**
72
+ * Authenticate, pull the durable mailbox, process each envelope, and acknowledge
73
+ * only successful decryptions. This operation is safe to call after repeated
74
+ * wake hints and can also be called when push is unavailable.
75
+ */
76
+ export declare function pullHostedRelayAfterWake(options: HostedRelayWakeOptions): Promise<HostedRelayWakeResult>;
77
+ //# sourceMappingURL=hosted-push.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hosted-push.d.ts","sourceRoot":"","sources":["../../client/hosted-push.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AACrD,OAAO,KAAK,EAAE,gBAAgB,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAC;AAKxE,8EAA8E;AAC9E,MAAM,MAAM,gCAAgC,GAAG;IAC7C,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,KAAK,CAAC;IAC3C,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,8EAA8E;AAC9E,MAAM,WAAW,8BAA8B;IAC7C,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,IAAI,EAAE;QACb,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;QACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;KACzB,CAAC;IACF,QAAQ,CAAC,QAAQ,EAAE,UAAU,CAAC;CAC/B;AAED,oDAAoD;AACpD,MAAM,MAAM,2BAA2B,GACrC,gCAAgC,GAAG,8BAA8B,CAAC;AAEpE,MAAM,WAAW,kCAAkC;IACjD,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,YAAY,EAAE,2BAA2B,CAAC;CACpD;AAED,MAAM,WAAW,6BAA6B;IAC5C,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;CACjC;AAED,MAAM,WAAW,6BAA6B;IAC5C,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;CACjC;AAED,MAAM,WAAW,uCAAuC;IACtD,QAAQ,CAAC,UAAU,EAAE,SAAS,MAAM,EAAE,CAAC;IACvC,QAAQ,CAAC,cAAc,EAAE,MAA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AC,OAAO,EAAE;IACnD,QAAQ,CAAC,OAAO,EAAE,sBAAsB,CAAC;IACzC,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;CACjC,GAAG,OAAO,CAAC,IAAI,CAAC,CAIhB;AAED;;;;GAIG;AACH,wBAAsB,wBAAwB,CAC5C,OAAO,EAAE,sBAAsB,GAC9B,OAAO,CAAC,qBAAqB,CAAC,CAgChC"}
@@ -0,0 +1,90 @@
1
+ const PUSH_TOKEN_MAXIMUM_LENGTH = 4_096;
2
+ const PUSH_ENDPOINT_MAXIMUM_LENGTH = 2_048;
3
+ function assertPublishableKey(value) {
4
+ const publishableKey = value.trim();
5
+ if (!publishableKey || publishableKey.length > 512) {
6
+ throw new Error('Hosted Relay publishable key is invalid');
7
+ }
8
+ return publishableKey;
9
+ }
10
+ function assertToken(token) {
11
+ if (!token || token.length > PUSH_TOKEN_MAXIMUM_LENGTH) {
12
+ throw new Error('Hosted Relay push token is invalid');
13
+ }
14
+ return token;
15
+ }
16
+ function validatedRegistration(registration) {
17
+ if (registration.provider !== 'web-push') {
18
+ return {
19
+ provider: registration.provider,
20
+ token: assertToken(registration.token),
21
+ };
22
+ }
23
+ let endpoint;
24
+ try {
25
+ endpoint = new URL(registration.endpoint);
26
+ }
27
+ catch {
28
+ throw new Error('Hosted Relay Web Push endpoint is invalid');
29
+ }
30
+ if (endpoint.protocol !== 'https:' ||
31
+ registration.endpoint.length > PUSH_ENDPOINT_MAXIMUM_LENGTH) {
32
+ throw new Error('Hosted Relay Web Push endpoint is invalid');
33
+ }
34
+ return {
35
+ endpoint: registration.endpoint,
36
+ keys: {
37
+ auth: assertToken(registration.keys.auth),
38
+ p256dh: assertToken(registration.keys.p256dh),
39
+ },
40
+ provider: 'web-push',
41
+ };
42
+ }
43
+ /** Register a data-only wake destination for the adapter's authenticated device. */
44
+ export async function registerHostedRelayPush(options) {
45
+ await options.adapter.registerPush({
46
+ publishableKey: assertPublishableKey(options.publishableKey),
47
+ registration: validatedRegistration(options.registration),
48
+ });
49
+ }
50
+ /** Remove the data-only wake destination for the adapter's authenticated device. */
51
+ export async function removeHostedRelayPush(options) {
52
+ await options.adapter.removePush({
53
+ publishableKey: assertPublishableKey(options.publishableKey),
54
+ });
55
+ }
56
+ /**
57
+ * Authenticate, pull the durable mailbox, process each envelope, and acknowledge
58
+ * only successful decryptions. This operation is safe to call after repeated
59
+ * wake hints and can also be called when push is unavailable.
60
+ */
61
+ export async function pullHostedRelayAfterWake(options) {
62
+ const publishableKey = assertPublishableKey(options.publishableKey);
63
+ const envelopes = await options.adapter.pullMailbox({ publishableKey });
64
+ const results = await options.client.processIncomingEnvelopes([...envelopes], options.processOptions);
65
+ if (results.length !== envelopes.length) {
66
+ throw new Error('Hosted Relay mailbox processing returned an invalid result');
67
+ }
68
+ const acknowledgedMessageIds = [];
69
+ const failedMessageIds = [];
70
+ for (const result of results) {
71
+ if ('plaintext' in result) {
72
+ acknowledgedMessageIds.push(result.envelope.id);
73
+ }
74
+ else {
75
+ failedMessageIds.push(result.envelope.id);
76
+ }
77
+ }
78
+ if (acknowledgedMessageIds.length > 0) {
79
+ await options.adapter.acknowledgeMailbox({
80
+ messageIds: acknowledgedMessageIds,
81
+ publishableKey,
82
+ });
83
+ }
84
+ return {
85
+ acknowledgedMessageIds,
86
+ failedMessageIds,
87
+ pulled: envelopes.length,
88
+ };
89
+ }
90
+ //# sourceMappingURL=hosted-push.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hosted-push.js","sourceRoot":"","sources":["../../client/hosted-push.ts"],"names":[],"mappings":"AAGA,MAAM,yBAAyB,GAAG,KAAK,CAAC;AACxC,MAAM,4BAA4B,GAAG,KAAK,CAAC;AA8E3C,SAAS,oBAAoB,CAAC,KAAa;IACzC,MAAM,cAAc,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;IACpC,IAAI,CAAC,cAAc,IAAI,cAAc,CAAC,MAAM,GAAG,GAAG,EAAE,CAAC;QACnD,MAAM,IAAI,KAAK,CAAC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