@open-e2ee/signal-protocol-sdk 11.0.0 → 12.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 (583) hide show
  1. package/ADAPTERS.md +4 -4
  2. package/ARCHITECTURE.md +6 -8
  3. package/CHANGELOG.md +1315 -0
  4. package/README.md +1 -1
  5. package/SECURITY.md +2 -2
  6. package/TROUBLESHOOTING.md +1 -1
  7. package/client/README.md +70 -37
  8. package/device/README.md +39 -85
  9. package/dist/client/client.d.ts +334 -63
  10. package/dist/client/client.d.ts.map +1 -1
  11. package/dist/client/client.js +1168 -184
  12. package/dist/client/client.js.map +1 -1
  13. package/dist/client/config.d.ts +40 -32
  14. package/dist/client/config.d.ts.map +1 -1
  15. package/dist/client/config.js +1 -1
  16. package/dist/client/config.js.map +1 -1
  17. package/dist/client/constants.d.ts +42 -8
  18. package/dist/client/constants.d.ts.map +1 -1
  19. package/dist/client/constants.js +48 -3
  20. package/dist/client/constants.js.map +1 -1
  21. package/dist/client/content-adapter.d.ts +80 -0
  22. package/dist/client/content-adapter.d.ts.map +1 -1
  23. package/dist/client/content-adapter.js +225 -12
  24. package/dist/client/content-adapter.js.map +1 -1
  25. package/dist/client/delivery-error.d.ts +150 -0
  26. package/dist/client/delivery-error.d.ts.map +1 -0
  27. package/dist/client/delivery-error.js +226 -0
  28. package/dist/client/delivery-error.js.map +1 -0
  29. package/dist/client/delivery-status.d.ts +32 -6
  30. package/dist/client/delivery-status.d.ts.map +1 -1
  31. package/dist/client/delivery-status.js +61 -13
  32. package/dist/client/delivery-status.js.map +1 -1
  33. package/dist/client/device-set-reconciliation.d.ts +196 -0
  34. package/dist/client/device-set-reconciliation.d.ts.map +1 -0
  35. package/dist/client/device-set-reconciliation.js +282 -0
  36. package/dist/client/device-set-reconciliation.js.map +1 -0
  37. package/dist/client/distribution-records.d.ts +29 -0
  38. package/dist/client/distribution-records.d.ts.map +1 -0
  39. package/dist/client/distribution-records.js +33 -0
  40. package/dist/client/distribution-records.js.map +1 -0
  41. package/dist/client/event-hooks.d.ts +280 -14
  42. package/dist/client/event-hooks.d.ts.map +1 -1
  43. package/dist/client/event-hooks.js +8 -0
  44. package/dist/client/event-hooks.js.map +1 -1
  45. package/dist/client/group-device-set.d.ts +47 -0
  46. package/dist/client/group-device-set.d.ts.map +1 -0
  47. package/dist/client/group-device-set.js +65 -0
  48. package/dist/client/group-device-set.js.map +1 -0
  49. package/dist/client/group-fetcher.d.ts +116 -0
  50. package/dist/client/group-fetcher.d.ts.map +1 -0
  51. package/dist/client/group-fetcher.js +598 -0
  52. package/dist/client/group-fetcher.js.map +1 -0
  53. package/dist/client/group-outbox.d.ts +172 -10
  54. package/dist/client/group-outbox.d.ts.map +1 -1
  55. package/dist/client/group-outbox.js +915 -74
  56. package/dist/client/group-outbox.js.map +1 -1
  57. package/dist/client/group-receive-authorization.d.ts +127 -4
  58. package/dist/client/group-receive-authorization.d.ts.map +1 -1
  59. package/dist/client/group-receive-authorization.js +270 -20
  60. package/dist/client/group-receive-authorization.js.map +1 -1
  61. package/dist/client/group-sealed-sender.d.ts +3 -0
  62. package/dist/client/group-sealed-sender.d.ts.map +1 -1
  63. package/dist/client/group-sealed-sender.js +1 -0
  64. package/dist/client/group-sealed-sender.js.map +1 -1
  65. package/dist/client/group-sender-key-operations.d.ts +14 -3
  66. package/dist/client/group-sender-key-operations.d.ts.map +1 -1
  67. package/dist/client/group-sender-key-operations.js +26 -5
  68. package/dist/client/group-sender-key-operations.js.map +1 -1
  69. package/dist/client/groups.d.ts +5 -5
  70. package/dist/client/groups.d.ts.map +1 -1
  71. package/dist/client/groups.js +5 -4
  72. package/dist/client/groups.js.map +1 -1
  73. package/dist/client/hosted-anonymous-delivery.d.ts +61 -9
  74. package/dist/client/hosted-anonymous-delivery.d.ts.map +1 -1
  75. package/dist/client/hosted-anonymous-delivery.js +242 -48
  76. package/dist/client/hosted-anonymous-delivery.js.map +1 -1
  77. package/dist/client/hosted-assertion-id.d.ts +7 -0
  78. package/dist/client/hosted-assertion-id.d.ts.map +1 -0
  79. package/dist/client/hosted-assertion-id.js +51 -0
  80. package/dist/client/hosted-assertion-id.js.map +1 -0
  81. package/dist/client/hosted-mailbox-subscription.d.ts +34 -2
  82. package/dist/client/hosted-mailbox-subscription.d.ts.map +1 -1
  83. package/dist/client/hosted-mailbox-subscription.js +87 -17
  84. package/dist/client/hosted-mailbox-subscription.js.map +1 -1
  85. package/dist/client/hosted-push.d.ts +22 -4
  86. package/dist/client/hosted-push.d.ts.map +1 -1
  87. package/dist/client/hosted-push.js +75 -22
  88. package/dist/client/hosted-push.js.map +1 -1
  89. package/dist/client/hosted-transport.d.ts +22 -28
  90. package/dist/client/hosted-transport.d.ts.map +1 -1
  91. package/dist/client/hosted-transport.js +115 -55
  92. package/dist/client/hosted-transport.js.map +1 -1
  93. package/dist/client/hosted.d.ts +10 -4
  94. package/dist/client/hosted.d.ts.map +1 -1
  95. package/dist/client/hosted.js +10 -4
  96. package/dist/client/hosted.js.map +1 -1
  97. package/dist/client/index.d.ts +5 -3
  98. package/dist/client/index.d.ts.map +1 -1
  99. package/dist/client/index.js +2 -0
  100. package/dist/client/index.js.map +1 -1
  101. package/dist/client/messages.d.ts +25 -3
  102. package/dist/client/messages.d.ts.map +1 -1
  103. package/dist/client/messages.js +111 -20
  104. package/dist/client/messages.js.map +1 -1
  105. package/dist/client/receive-admission.d.ts +58 -0
  106. package/dist/client/receive-admission.d.ts.map +1 -0
  107. package/dist/client/receive-admission.js +78 -0
  108. package/dist/client/receive-admission.js.map +1 -0
  109. package/dist/client/receive-expiry.d.ts +31 -0
  110. package/dist/client/receive-expiry.d.ts.map +1 -0
  111. package/dist/client/receive-expiry.js +35 -0
  112. package/dist/client/receive-expiry.js.map +1 -0
  113. package/dist/client/receive-hook-bound.d.ts +50 -0
  114. package/dist/client/receive-hook-bound.d.ts.map +1 -0
  115. package/dist/client/receive-hook-bound.js +115 -0
  116. package/dist/client/receive-hook-bound.js.map +1 -0
  117. package/dist/client/receive-queue.d.ts +299 -0
  118. package/dist/client/receive-queue.d.ts.map +1 -0
  119. package/dist/client/receive-queue.js +1420 -0
  120. package/dist/client/receive-queue.js.map +1 -0
  121. package/dist/client/receive-work-seed.d.ts +54 -0
  122. package/dist/client/receive-work-seed.d.ts.map +1 -0
  123. package/dist/client/receive-work-seed.js +116 -0
  124. package/dist/client/receive-work-seed.js.map +1 -0
  125. package/dist/client/recovery-driver.d.ts +25 -0
  126. package/dist/client/recovery-driver.d.ts.map +1 -0
  127. package/dist/client/recovery-driver.js +121 -0
  128. package/dist/client/recovery-driver.js.map +1 -0
  129. package/dist/client/relay-acceptance.d.ts +20 -7
  130. package/dist/client/relay-acceptance.d.ts.map +1 -1
  131. package/dist/client/relay-acceptance.js +30 -12
  132. package/dist/client/relay-acceptance.js.map +1 -1
  133. package/dist/client/relay-device-refusal.d.ts +18 -0
  134. package/dist/client/relay-device-refusal.d.ts.map +1 -1
  135. package/dist/client/relay-device-refusal.js +31 -0
  136. package/dist/client/relay-device-refusal.js.map +1 -1
  137. package/dist/client/relay-sealed-route.d.ts +36 -0
  138. package/dist/client/relay-sealed-route.d.ts.map +1 -0
  139. package/dist/client/relay-sealed-route.js +45 -0
  140. package/dist/client/relay-sealed-route.js.map +1 -0
  141. package/dist/client/relay-subscription.d.ts +56 -13
  142. package/dist/client/relay-subscription.d.ts.map +1 -1
  143. package/dist/client/relay-subscription.js +193 -123
  144. package/dist/client/relay-subscription.js.map +1 -1
  145. package/dist/client/resendable-content.d.ts +98 -0
  146. package/dist/client/resendable-content.d.ts.map +1 -0
  147. package/dist/client/resendable-content.js +136 -0
  148. package/dist/client/resendable-content.js.map +1 -0
  149. package/dist/client/retry-family.d.ts +57 -10
  150. package/dist/client/retry-family.d.ts.map +1 -1
  151. package/dist/client/retry-family.js +54 -12
  152. package/dist/client/retry-family.js.map +1 -1
  153. package/dist/client/retry-request-envelope.d.ts +107 -8
  154. package/dist/client/retry-request-envelope.d.ts.map +1 -1
  155. package/dist/client/retry-request-envelope.js +172 -23
  156. package/dist/client/retry-request-envelope.js.map +1 -1
  157. package/dist/client/retry-request-lifecycle.d.ts +70 -14
  158. package/dist/client/retry-request-lifecycle.d.ts.map +1 -1
  159. package/dist/client/retry-request-lifecycle.js +162 -32
  160. package/dist/client/retry-request-lifecycle.js.map +1 -1
  161. package/dist/client/retry-terminal-recovery.d.ts +100 -0
  162. package/dist/client/retry-terminal-recovery.d.ts.map +1 -0
  163. package/dist/client/retry-terminal-recovery.js +164 -0
  164. package/dist/client/retry-terminal-recovery.js.map +1 -0
  165. package/dist/client/retry-utils.d.ts +27 -0
  166. package/dist/client/retry-utils.d.ts.map +1 -1
  167. package/dist/client/retry-utils.js +46 -0
  168. package/dist/client/retry-utils.js.map +1 -1
  169. package/dist/client/retry.d.ts +100 -12
  170. package/dist/client/retry.d.ts.map +1 -1
  171. package/dist/client/retry.js +619 -116
  172. package/dist/client/retry.js.map +1 -1
  173. package/dist/client/sealed-sender.d.ts +23 -6
  174. package/dist/client/sealed-sender.d.ts.map +1 -1
  175. package/dist/client/sealed-sender.js +30 -6
  176. package/dist/client/sealed-sender.js.map +1 -1
  177. package/dist/client/sessions.d.ts +2 -2
  178. package/dist/client/sessions.js +2 -2
  179. package/dist/client/signal-service-cipher.d.ts +726 -19
  180. package/dist/client/signal-service-cipher.d.ts.map +1 -1
  181. package/dist/client/signal-service-cipher.js +2260 -342
  182. package/dist/client/signal-service-cipher.js.map +1 -1
  183. package/dist/client/state.d.ts +5 -0
  184. package/dist/client/state.d.ts.map +1 -1
  185. package/dist/client/state.js +11 -1
  186. package/dist/client/state.js.map +1 -1
  187. package/dist/client/storage-protection.d.ts +64 -0
  188. package/dist/client/storage-protection.d.ts.map +1 -0
  189. package/dist/client/storage-protection.js +150 -0
  190. package/dist/client/storage-protection.js.map +1 -0
  191. package/dist/client/types.d.ts +149 -15
  192. package/dist/client/types.d.ts.map +1 -1
  193. package/dist/client/types.js +1 -1
  194. package/dist/client/types.js.map +1 -1
  195. package/dist/device/constants.d.ts +0 -5
  196. package/dist/device/constants.d.ts.map +1 -1
  197. package/dist/device/constants.js +0 -5
  198. package/dist/device/constants.js.map +1 -1
  199. package/dist/device/expo/index.d.ts +4 -17
  200. package/dist/device/expo/index.d.ts.map +1 -1
  201. package/dist/device/expo/index.js +4 -23
  202. package/dist/device/expo/index.js.map +1 -1
  203. package/dist/device/index.d.ts +0 -2
  204. package/dist/device/index.d.ts.map +1 -1
  205. package/dist/device/index.js +0 -7
  206. package/dist/device/index.js.map +1 -1
  207. package/dist/device/lifecycle/manager.d.ts +5 -4
  208. package/dist/device/lifecycle/manager.d.ts.map +1 -1
  209. package/dist/device/lifecycle/manager.js +16 -16
  210. package/dist/device/lifecycle/manager.js.map +1 -1
  211. package/dist/device/lifecycle/types.d.ts +2 -2
  212. package/dist/device/lifecycle/types.d.ts.map +1 -1
  213. package/dist/device/react-native/index.d.ts +4 -15
  214. package/dist/device/react-native/index.d.ts.map +1 -1
  215. package/dist/device/react-native/index.js +4 -21
  216. package/dist/device/react-native/index.js.map +1 -1
  217. package/dist/device/types.d.ts +1 -1
  218. package/dist/groups/index.d.ts +1 -1
  219. package/dist/groups/index.d.ts.map +1 -1
  220. package/dist/index.d.ts +8 -6
  221. package/dist/index.d.ts.map +1 -1
  222. package/dist/index.js +2 -1
  223. package/dist/index.js.map +1 -1
  224. package/dist/internal/crypto/ec/x25519-validation.d.ts +0 -1
  225. package/dist/internal/crypto/ec/x25519-validation.d.ts.map +1 -1
  226. package/dist/internal/crypto/ec/x25519-validation.js +0 -1
  227. package/dist/internal/crypto/ec/x25519-validation.js.map +1 -1
  228. package/dist/internal/crypto/validation.d.ts +2 -2
  229. package/dist/internal/groups/index.d.ts +1 -0
  230. package/dist/internal/groups/index.d.ts.map +1 -1
  231. package/dist/internal/groups/index.js +1 -0
  232. package/dist/internal/groups/index.js.map +1 -1
  233. package/dist/internal/groups/manager.d.ts +37 -16
  234. package/dist/internal/groups/manager.d.ts.map +1 -1
  235. package/dist/internal/groups/manager.js +46 -1
  236. package/dist/internal/groups/manager.js.map +1 -1
  237. package/dist/internal/groups/receive-record.d.ts +78 -0
  238. package/dist/internal/groups/receive-record.d.ts.map +1 -0
  239. package/dist/internal/groups/receive-record.js +43 -0
  240. package/dist/internal/groups/receive-record.js.map +1 -0
  241. package/dist/internal/groups/sdk-store.d.ts +27 -3
  242. package/dist/internal/groups/sdk-store.d.ts.map +1 -1
  243. package/dist/internal/groups/sdk-store.js +151 -19
  244. package/dist/internal/groups/sdk-store.js.map +1 -1
  245. package/dist/internal/groups/wire.d.ts +12 -1
  246. package/dist/internal/groups/wire.d.ts.map +1 -1
  247. package/dist/internal/groups/wire.js +36 -0
  248. package/dist/internal/groups/wire.js.map +1 -1
  249. package/dist/internal/manager/index.d.ts +1 -1
  250. package/dist/internal/manager/manager.d.ts +20 -19
  251. package/dist/internal/manager/manager.d.ts.map +1 -1
  252. package/dist/internal/manager/manager.js +56 -39
  253. package/dist/internal/manager/manager.js.map +1 -1
  254. package/dist/internal/protocol/double-ratchet/chains.d.ts +4 -18
  255. package/dist/internal/protocol/double-ratchet/chains.d.ts.map +1 -1
  256. package/dist/internal/protocol/double-ratchet/chains.js +23 -74
  257. package/dist/internal/protocol/double-ratchet/chains.js.map +1 -1
  258. package/dist/internal/protocol/double-ratchet/index.d.ts +1 -1
  259. package/dist/internal/protocol/double-ratchet/index.d.ts.map +1 -1
  260. package/dist/internal/protocol/double-ratchet/index.js +1 -1
  261. package/dist/internal/protocol/double-ratchet/index.js.map +1 -1
  262. package/dist/internal/protocol/double-ratchet/ratchet.d.ts +5 -7
  263. package/dist/internal/protocol/double-ratchet/ratchet.d.ts.map +1 -1
  264. package/dist/internal/protocol/double-ratchet/ratchet.js +4 -6
  265. package/dist/internal/protocol/double-ratchet/ratchet.js.map +1 -1
  266. package/dist/internal/protocol/pqxdh/pqxdh.d.ts.map +1 -1
  267. package/dist/internal/protocol/pqxdh/pqxdh.js +2 -1
  268. package/dist/internal/protocol/pqxdh/pqxdh.js.map +1 -1
  269. package/dist/internal/protocol/sealed-sender/types.d.ts +6 -8
  270. package/dist/internal/protocol/sealed-sender/types.d.ts.map +1 -1
  271. package/dist/internal/protocol/sealed-sender/types.js +8 -9
  272. package/dist/internal/protocol/sealed-sender/types.js.map +1 -1
  273. package/dist/internal/protocol/sender-keys/handoff-ledger.d.ts +110 -0
  274. package/dist/internal/protocol/sender-keys/handoff-ledger.d.ts.map +1 -0
  275. package/dist/internal/protocol/sender-keys/handoff-ledger.js +124 -0
  276. package/dist/internal/protocol/sender-keys/handoff-ledger.js.map +1 -0
  277. package/dist/internal/protocol/sender-keys/manager.d.ts +71 -62
  278. package/dist/internal/protocol/sender-keys/manager.d.ts.map +1 -1
  279. package/dist/internal/protocol/sender-keys/manager.js +228 -175
  280. package/dist/internal/protocol/sender-keys/manager.js.map +1 -1
  281. package/dist/internal/protocol/spqr/index.d.ts +2 -2
  282. package/dist/internal/protocol/spqr/index.d.ts.map +1 -1
  283. package/dist/internal/protocol/spqr/index.js +2 -2
  284. package/dist/internal/protocol/spqr/index.js.map +1 -1
  285. package/dist/internal/protocol/spqr/serialize.d.ts +9 -1
  286. package/dist/internal/protocol/spqr/serialize.d.ts.map +1 -1
  287. package/dist/internal/protocol/spqr/serialize.js +56 -16
  288. package/dist/internal/protocol/spqr/serialize.js.map +1 -1
  289. package/dist/internal/protocol/spqr/spqr.d.ts +1 -14
  290. package/dist/internal/protocol/spqr/spqr.d.ts.map +1 -1
  291. package/dist/internal/protocol/spqr/spqr.js +54 -42
  292. package/dist/internal/protocol/spqr/spqr.js.map +1 -1
  293. package/dist/internal/protocol/spqr/validate.d.ts +26 -6
  294. package/dist/internal/protocol/spqr/validate.d.ts.map +1 -1
  295. package/dist/internal/protocol/spqr/validate.js +49 -21
  296. package/dist/internal/protocol/spqr/validate.js.map +1 -1
  297. package/dist/internal/sesame/index.d.ts +1 -1
  298. package/dist/internal/sesame/index.d.ts.map +1 -1
  299. package/dist/internal/sesame/index.js.map +1 -1
  300. package/dist/internal/sesame/manager.d.ts +66 -13
  301. package/dist/internal/sesame/manager.d.ts.map +1 -1
  302. package/dist/internal/sesame/manager.js +221 -87
  303. package/dist/internal/sesame/manager.js.map +1 -1
  304. package/dist/internal/sesame/types.d.ts +95 -17
  305. package/dist/internal/sesame/types.d.ts.map +1 -1
  306. package/dist/internal/sesame/types.js +17 -0
  307. package/dist/internal/sesame/types.js.map +1 -1
  308. package/dist/internal/session/builder.d.ts +5 -5
  309. package/dist/internal/session/builder.d.ts.map +1 -1
  310. package/dist/internal/session/builder.js +12 -17
  311. package/dist/internal/session/builder.js.map +1 -1
  312. package/dist/internal/session/cipher.d.ts +13 -11
  313. package/dist/internal/session/cipher.d.ts.map +1 -1
  314. package/dist/internal/session/cipher.js +40 -22
  315. package/dist/internal/session/cipher.js.map +1 -1
  316. package/dist/internal/session/factory.d.ts +5 -5
  317. package/dist/internal/session/factory.d.ts.map +1 -1
  318. package/dist/internal/session/factory.js +4 -4
  319. package/dist/internal/session/factory.js.map +1 -1
  320. package/dist/internal/session/handshake.d.ts +14 -16
  321. package/dist/internal/session/handshake.d.ts.map +1 -1
  322. package/dist/internal/session/handshake.js +18 -75
  323. package/dist/internal/session/handshake.js.map +1 -1
  324. package/dist/internal/session/index.d.ts +1 -1
  325. package/dist/internal/session/index.js +1 -1
  326. package/dist/internal/session/record-locks.d.ts +17 -6
  327. package/dist/internal/session/record-locks.d.ts.map +1 -1
  328. package/dist/internal/session/record-locks.js +43 -7
  329. package/dist/internal/session/record-locks.js.map +1 -1
  330. package/dist/internal/session/session-resolver.d.ts +1 -1
  331. package/dist/internal/session/session-resolver.js +1 -1
  332. package/dist/internal/session/state.d.ts +2 -2
  333. package/dist/internal/session/state.js +1 -1
  334. package/dist/internal/session/types.d.ts +4 -12
  335. package/dist/internal/session/types.d.ts.map +1 -1
  336. package/dist/internal/session/types.js +1 -1
  337. package/dist/keys/generation.d.ts +2 -2
  338. package/dist/keys/generation.js +2 -2
  339. package/dist/keys/types.d.ts +5 -5
  340. package/dist/keys/types.d.ts.map +1 -1
  341. package/dist/keys/types.js +1 -1
  342. package/dist/layers.d.ts +1 -1
  343. package/dist/layers.js +2 -2
  344. package/dist/layers.js.map +1 -1
  345. package/dist/local/store/expo/adapter.d.ts.map +1 -1
  346. package/dist/local/store/expo/adapter.js +12 -8
  347. package/dist/local/store/expo/adapter.js.map +1 -1
  348. package/dist/local/store/key-value/adapter.d.ts +76 -10
  349. package/dist/local/store/key-value/adapter.d.ts.map +1 -1
  350. package/dist/local/store/key-value/adapter.js +367 -61
  351. package/dist/local/store/key-value/adapter.js.map +1 -1
  352. package/dist/local/store/key-value/backend-conformance.d.ts.map +1 -1
  353. package/dist/local/store/key-value/backend-conformance.js +74 -0
  354. package/dist/local/store/key-value/backend-conformance.js.map +1 -1
  355. package/dist/local/store/key-value/batch.d.ts +2 -0
  356. package/dist/local/store/key-value/batch.d.ts.map +1 -1
  357. package/dist/local/store/key-value/batch.js +26 -0
  358. package/dist/local/store/key-value/batch.js.map +1 -1
  359. package/dist/local/store/key-value/receive-work.d.ts +55 -0
  360. package/dist/local/store/key-value/receive-work.d.ts.map +1 -0
  361. package/dist/local/store/key-value/receive-work.js +162 -0
  362. package/dist/local/store/key-value/receive-work.js.map +1 -0
  363. package/dist/local/store/key-value/send-log.d.ts +61 -0
  364. package/dist/local/store/key-value/send-log.d.ts.map +1 -0
  365. package/dist/local/store/key-value/send-log.js +430 -0
  366. package/dist/local/store/key-value/send-log.js.map +1 -0
  367. package/dist/local/store/key-value/sender-key-handoff.d.ts +68 -0
  368. package/dist/local/store/key-value/sender-key-handoff.d.ts.map +1 -0
  369. package/dist/local/store/key-value/sender-key-handoff.js +189 -0
  370. package/dist/local/store/key-value/sender-key-handoff.js.map +1 -0
  371. package/dist/local/store/key-value/storage.d.ts +15 -0
  372. package/dist/local/store/key-value/storage.d.ts.map +1 -1
  373. package/dist/local/store/keyed-index.d.ts +23 -0
  374. package/dist/local/store/keyed-index.d.ts.map +1 -0
  375. package/dist/local/store/keyed-index.js +41 -0
  376. package/dist/local/store/keyed-index.js.map +1 -0
  377. package/dist/local/store/memory/adapter.d.ts +44 -12
  378. package/dist/local/store/memory/adapter.d.ts.map +1 -1
  379. package/dist/local/store/memory/adapter.js +197 -46
  380. package/dist/local/store/memory/adapter.js.map +1 -1
  381. package/dist/local/store/memory/send-log.d.ts +42 -0
  382. package/dist/local/store/memory/send-log.d.ts.map +1 -0
  383. package/dist/local/store/memory/send-log.js +190 -0
  384. package/dist/local/store/memory/send-log.js.map +1 -0
  385. package/dist/local/store/node/adapter.d.ts.map +1 -1
  386. package/dist/local/store/node/adapter.js +8 -6
  387. package/dist/local/store/node/adapter.js.map +1 -1
  388. package/dist/local/store/react-native/adapter.d.ts.map +1 -1
  389. package/dist/local/store/react-native/adapter.js +12 -8
  390. package/dist/local/store/react-native/adapter.js.map +1 -1
  391. package/dist/local/store/receive-work.d.ts +87 -0
  392. package/dist/local/store/receive-work.d.ts.map +1 -0
  393. package/dist/local/store/receive-work.js +204 -0
  394. package/dist/local/store/receive-work.js.map +1 -0
  395. package/dist/local/store/received-content.d.ts +3 -3
  396. package/dist/local/store/received-content.d.ts.map +1 -1
  397. package/dist/local/store/received-content.js +2 -11
  398. package/dist/local/store/received-content.js.map +1 -1
  399. package/dist/local/store/reliability.d.ts +317 -18
  400. package/dist/local/store/reliability.d.ts.map +1 -1
  401. package/dist/local/store/reliability.js +371 -46
  402. package/dist/local/store/reliability.js.map +1 -1
  403. package/dist/local/store/send-log-order.d.ts +15 -0
  404. package/dist/local/store/send-log-order.d.ts.map +1 -0
  405. package/dist/local/store/send-log-order.js +24 -0
  406. package/dist/local/store/send-log-order.js.map +1 -0
  407. package/dist/local/store/sender-key-handoff-index.d.ts +38 -0
  408. package/dist/local/store/sender-key-handoff-index.d.ts.map +1 -0
  409. package/dist/local/store/sender-key-handoff-index.js +101 -0
  410. package/dist/local/store/sender-key-handoff-index.js.map +1 -0
  411. package/dist/local/store/sender-key-handoff-table.d.ts +29 -0
  412. package/dist/local/store/sender-key-handoff-table.d.ts.map +1 -0
  413. package/dist/local/store/sender-key-handoff-table.js +97 -0
  414. package/dist/local/store/sender-key-handoff-table.js.map +1 -0
  415. package/dist/local/store/sqlite/encryption.d.ts +8 -1
  416. package/dist/local/store/sqlite/encryption.d.ts.map +1 -1
  417. package/dist/local/store/sqlite/encryption.js +9 -0
  418. package/dist/local/store/sqlite/encryption.js.map +1 -1
  419. package/dist/local/store/sqlite/key-storage/index.d.ts +25 -4
  420. package/dist/local/store/sqlite/key-storage/index.d.ts.map +1 -1
  421. package/dist/local/store/sqlite/key-storage/index.js +68 -7
  422. package/dist/local/store/sqlite/key-storage/index.js.map +1 -1
  423. package/dist/local/store/sqlite/key-storage/message-records.d.ts +16 -4
  424. package/dist/local/store/sqlite/key-storage/message-records.d.ts.map +1 -1
  425. package/dist/local/store/sqlite/key-storage/message-records.js +49 -6
  426. package/dist/local/store/sqlite/key-storage/message-records.js.map +1 -1
  427. package/dist/local/store/sqlite/key-storage/metadata.d.ts +8 -7
  428. package/dist/local/store/sqlite/key-storage/metadata.d.ts.map +1 -1
  429. package/dist/local/store/sqlite/key-storage/metadata.js +17 -15
  430. package/dist/local/store/sqlite/key-storage/metadata.js.map +1 -1
  431. package/dist/local/store/sqlite/key-storage/receive-work.d.ts +27 -0
  432. package/dist/local/store/sqlite/key-storage/receive-work.d.ts.map +1 -0
  433. package/dist/local/store/sqlite/key-storage/receive-work.js +98 -0
  434. package/dist/local/store/sqlite/key-storage/receive-work.js.map +1 -0
  435. package/dist/local/store/sqlite/key-storage/send-log.d.ts +27 -0
  436. package/dist/local/store/sqlite/key-storage/send-log.d.ts.map +1 -0
  437. package/dist/local/store/sqlite/key-storage/send-log.js +178 -0
  438. package/dist/local/store/sqlite/key-storage/send-log.js.map +1 -0
  439. package/dist/local/store/sqlite/key-storage/sender-key-handoff.d.ts +27 -0
  440. package/dist/local/store/sqlite/key-storage/sender-key-handoff.d.ts.map +1 -0
  441. package/dist/local/store/sqlite/key-storage/sender-key-handoff.js +75 -0
  442. package/dist/local/store/sqlite/key-storage/sender-key-handoff.js.map +1 -0
  443. package/dist/local/store/sqlite/key-storage/session-trust.d.ts +2 -2
  444. package/dist/local/store/sqlite/key-storage/session-trust.js +5 -5
  445. package/dist/local/store/sqlite/key-storage/session-trust.js.map +1 -1
  446. package/dist/local/store/sqlite/migrations.d.ts.map +1 -1
  447. package/dist/local/store/sqlite/migrations.js +101 -0
  448. package/dist/local/store/sqlite/migrations.js.map +1 -1
  449. package/dist/local/store/sqlite/models/index.d.ts +2 -1
  450. package/dist/local/store/sqlite/models/index.d.ts.map +1 -1
  451. package/dist/local/store/sqlite/models/index.js +5 -1
  452. package/dist/local/store/sqlite/models/index.js.map +1 -1
  453. package/dist/local/store/sqlite/models/message-record.d.ts +15 -0
  454. package/dist/local/store/sqlite/models/message-record.d.ts.map +1 -1
  455. package/dist/local/store/sqlite/models/message-record.js +24 -0
  456. package/dist/local/store/sqlite/models/message-record.js.map +1 -1
  457. package/dist/local/store/sqlite/models/send-log.d.ts +51 -0
  458. package/dist/local/store/sqlite/models/send-log.d.ts.map +1 -0
  459. package/dist/local/store/sqlite/models/send-log.js +206 -0
  460. package/dist/local/store/sqlite/models/send-log.js.map +1 -0
  461. package/dist/local/store/sqlite/open-store.d.ts +9 -1
  462. package/dist/local/store/sqlite/open-store.d.ts.map +1 -1
  463. package/dist/local/store/sqlite/open-store.js +20 -1
  464. package/dist/local/store/sqlite/open-store.js.map +1 -1
  465. package/dist/local/store/sqlite/schema.d.ts +34 -1
  466. package/dist/local/store/sqlite/schema.d.ts.map +1 -1
  467. package/dist/local/store/sqlite/schema.js +14 -0
  468. package/dist/local/store/sqlite/schema.js.map +1 -1
  469. package/dist/local/store/sqlite/store.d.ts +61 -11
  470. package/dist/local/store/sqlite/store.d.ts.map +1 -1
  471. package/dist/local/store/sqlite/store.js +191 -27
  472. package/dist/local/store/sqlite/store.js.map +1 -1
  473. package/dist/local/store/web/adapter.d.ts +76 -8
  474. package/dist/local/store/web/adapter.d.ts.map +1 -1
  475. package/dist/local/store/web/adapter.js +579 -127
  476. package/dist/local/store/web/adapter.js.map +1 -1
  477. package/dist/local/store/web/receive-work.d.ts +57 -0
  478. package/dist/local/store/web/receive-work.d.ts.map +1 -0
  479. package/dist/local/store/web/receive-work.js +99 -0
  480. package/dist/local/store/web/receive-work.js.map +1 -0
  481. package/dist/local/store/web/send-log.d.ts +92 -0
  482. package/dist/local/store/web/send-log.d.ts.map +1 -0
  483. package/dist/local/store/web/send-log.js +267 -0
  484. package/dist/local/store/web/send-log.js.map +1 -0
  485. package/dist/local/store/web/sender-key-handoff.d.ts +81 -0
  486. package/dist/local/store/web/sender-key-handoff.d.ts.map +1 -0
  487. package/dist/local/store/web/sender-key-handoff.js +156 -0
  488. package/dist/local/store/web/sender-key-handoff.js.map +1 -0
  489. package/dist/local/store/web-sqlite/adapter.d.ts +2 -0
  490. package/dist/local/store/web-sqlite/adapter.d.ts.map +1 -1
  491. package/dist/local/store/web-sqlite/adapter.js +12 -6
  492. package/dist/local/store/web-sqlite/adapter.js.map +1 -1
  493. package/dist/local/vault/custody.d.ts +8 -0
  494. package/dist/local/vault/custody.d.ts.map +1 -0
  495. package/dist/local/vault/custody.js +9 -0
  496. package/dist/local/vault/custody.js.map +1 -0
  497. package/dist/local/vault/electron-safe-storage.d.ts +3 -1
  498. package/dist/local/vault/electron-safe-storage.d.ts.map +1 -1
  499. package/dist/local/vault/electron-safe-storage.js +2 -0
  500. package/dist/local/vault/electron-safe-storage.js.map +1 -1
  501. package/dist/local/vault/expo-secure-store.d.ts +3 -1
  502. package/dist/local/vault/expo-secure-store.d.ts.map +1 -1
  503. package/dist/local/vault/expo-secure-store.js +2 -0
  504. package/dist/local/vault/expo-secure-store.js.map +1 -1
  505. package/dist/local/vault/indexed-db.d.ts +3 -1
  506. package/dist/local/vault/indexed-db.d.ts.map +1 -1
  507. package/dist/local/vault/indexed-db.js +2 -0
  508. package/dist/local/vault/indexed-db.js.map +1 -1
  509. package/dist/local/vault/react-native-keychain.d.ts +3 -1
  510. package/dist/local/vault/react-native-keychain.d.ts.map +1 -1
  511. package/dist/local/vault/react-native-keychain.js +2 -0
  512. package/dist/local/vault/react-native-keychain.js.map +1 -1
  513. package/dist/remote/relay/device-set.d.ts +94 -0
  514. package/dist/remote/relay/device-set.d.ts.map +1 -0
  515. package/dist/remote/relay/device-set.js +156 -0
  516. package/dist/remote/relay/device-set.js.map +1 -0
  517. package/dist/remote/relay/types.d.ts +92 -107
  518. package/dist/remote/relay/types.d.ts.map +1 -1
  519. package/dist/safety/core.d.ts +15 -6
  520. package/dist/safety/core.d.ts.map +1 -1
  521. package/dist/safety/core.js +41 -27
  522. package/dist/safety/core.js.map +1 -1
  523. package/dist/safety/index.d.ts +2 -1
  524. package/dist/safety/index.d.ts.map +1 -1
  525. package/dist/safety/index.js +12 -18
  526. package/dist/safety/index.js.map +1 -1
  527. package/dist/types/api.d.ts +707 -62
  528. package/dist/types/api.d.ts.map +1 -1
  529. package/dist/types/errors.d.ts +14 -33
  530. package/dist/types/errors.d.ts.map +1 -1
  531. package/dist/types/errors.js +14 -24
  532. package/dist/types/errors.js.map +1 -1
  533. package/dist/types/messages.d.ts +2 -2
  534. package/dist/types/messages.js +1 -1
  535. package/dist/types/protocol-config.d.ts +175 -42
  536. package/dist/types/protocol-config.d.ts.map +1 -1
  537. package/dist/types/protocol-config.js +19 -38
  538. package/dist/types/protocol-config.js.map +1 -1
  539. package/dist/types/protocol-constants.d.ts +6 -6
  540. package/dist/types/protocol-constants.js +6 -6
  541. package/dist/types/session.d.ts +7 -7
  542. package/dist/types/session.d.ts.map +1 -1
  543. package/dist/types/session.js +39 -21
  544. package/dist/types/session.js.map +1 -1
  545. package/dist/username/link.d.ts +2 -2
  546. package/dist/username/link.js +2 -2
  547. package/dist/utils/origin-lock.d.ts +45 -0
  548. package/dist/utils/origin-lock.d.ts.map +1 -0
  549. package/dist/utils/origin-lock.js +80 -0
  550. package/dist/utils/origin-lock.js.map +1 -0
  551. package/docs/ASSURANCE.md +6 -6
  552. package/docs/CLIENT_COMPOSITION.md +2 -2
  553. package/docs/DEVIATIONS.md +677 -182
  554. package/docs/E2EE.md +1 -1
  555. package/docs/ERROR_HANDLING.md +165 -2
  556. package/docs/GETTING_STARTED.md +7 -4
  557. package/docs/INTERFACES.md +1 -1
  558. package/docs/PACKAGE_SURFACE.md +6 -5
  559. package/docs/PROTOCOL_POLICY.md +102 -22
  560. package/docs/RECIPES.md +3 -15
  561. package/docs/SECURITY.md +90 -5
  562. package/keys/README.md +3 -3
  563. package/local/store/README.md +78 -14
  564. package/local/store/key-value/README.md +14 -3
  565. package/local/store/node/README.md +8 -3
  566. package/local/store/web/README.md +9 -0
  567. package/local/store/web-sqlite/README.md +14 -2
  568. package/local/vault/README.md +21 -0
  569. package/package.json +1 -6
  570. package/remote/README.md +0 -1
  571. package/remote/relay/README.md +2 -2
  572. package/dist/device/provisioning.d.ts +0 -242
  573. package/dist/device/provisioning.d.ts.map +0 -1
  574. package/dist/device/provisioning.js +0 -421
  575. package/dist/device/provisioning.js.map +0 -1
  576. package/dist/internal/protocol/x3dh/index.d.ts +0 -15
  577. package/dist/internal/protocol/x3dh/index.d.ts.map +0 -1
  578. package/dist/internal/protocol/x3dh/index.js +0 -13
  579. package/dist/internal/protocol/x3dh/index.js.map +0 -1
  580. package/dist/internal/protocol/x3dh/x3dh.d.ts +0 -131
  581. package/dist/internal/protocol/x3dh/x3dh.d.ts.map +0 -1
  582. package/dist/internal/protocol/x3dh/x3dh.js +0 -261
  583. package/dist/internal/protocol/x3dh/x3dh.js.map +0 -1
@@ -0,0 +1,136 @@
1
+ /**
2
+ * Resendable content and its retention.
3
+ *
4
+ * A sender keeps the plaintext of a resendable message to answer a retry
5
+ * request: each group send in the send log, and each pairwise message in a
6
+ * MessageRecord. The retention runs from the store clock when the store
7
+ * first wrote the content, and a retry never extends it. This module
8
+ * enforces the retention at each send log lookup and at each sweep. A sweep
9
+ * runs at client creation, at stop, and before the first resendable group
10
+ * send of each day.
11
+ *
12
+ * When content recovery is off, the client keeps no resendable content, and
13
+ * the start of each client clears the content that an earlier policy kept.
14
+ * A metadata marker records the clear, so a start with nothing kept since
15
+ * the last clear reads one value and scans nothing.
16
+ *
17
+ * An E2EE delivery receipt from a device deletes its row (see
18
+ * `DeliveryStatusTracker`). A Relay delivery receipt deletes nothing, because
19
+ * a device also acknowledges a copy that it could not decrypt.
20
+ *
21
+ * Deletion in an encrypted store is logical. The retention bounds the time
22
+ * that the client keeps the content. It does not promise erasure from the
23
+ * storage medium.
24
+ *
25
+ * @internal
26
+ */
27
+ const DAY_MS = 24 * 60 * 60 * 1_000;
28
+ /**
29
+ * The metadata key that records a clear of all resendable content. Its
30
+ * presence means the store kept no resendable content since that clear.
31
+ */
32
+ export const RESENDABLE_CONTENT_CLEARED_MARKER = 'resendable-content:cleared';
33
+ export class ResendableContent {
34
+ store;
35
+ retentionMs;
36
+ now;
37
+ /** The day of the last sweep, in whole days since the epoch. */
38
+ sweptDay;
39
+ constructor(store,
40
+ /** The retention of the content, from `protocol.contentRecovery`. */
41
+ retentionMs, now = Date.now) {
42
+ this.store = store;
43
+ this.retentionMs = retentionMs;
44
+ this.now = now;
45
+ }
46
+ /** True when content that the store wrote at `createdAt` is past the retention. */
47
+ isExpired(createdAt) {
48
+ return this.now() - createdAt > this.retentionMs;
49
+ }
50
+ /** Delete each send log entry and each message record past the retention. */
51
+ async sweep() {
52
+ this.sweptDay = Math.floor(this.now() / DAY_MS);
53
+ const sendLogEntries = await this.store.deleteExpiredSendLog(this.retentionMs);
54
+ const messageRecords = await this.store.deleteExpiredMessageRecords(this.retentionMs);
55
+ return { sendLogEntries, messageRecords };
56
+ }
57
+ /**
58
+ * Sweep when no sweep ran today. A long-running client that never stops
59
+ * still deletes expired content each day that it sends.
60
+ */
61
+ async sweepDaily() {
62
+ return this.sweptDay === Math.floor(this.now() / DAY_MS) ? null : this.sweep();
63
+ }
64
+ /**
65
+ * The logged entries that a retry request from one device names, after
66
+ * expired entries are deleted. The first message ID with a row for the
67
+ * device wins. With none, every entry of the device at the client
68
+ * timestamp answers, ordered by `clientMessageId`. Only the row of this
69
+ * exact device authorizes a resend.
70
+ */
71
+ async lookup(device, clientMessageIds, clientTimestamp) {
72
+ await this.store.deleteExpiredSendLog(this.retentionMs);
73
+ for (const clientMessageId of clientMessageIds) {
74
+ if (clientMessageId === undefined)
75
+ continue;
76
+ const entry = await this.store.getSendLogEntry(clientMessageId, device);
77
+ if (entry)
78
+ return [entry];
79
+ }
80
+ return this.store.findSendLogEntries(device, clientTimestamp);
81
+ }
82
+ /**
83
+ * The logged entry of one send and the row of one device, after expired
84
+ * entries are deleted, or null when the device has no row.
85
+ */
86
+ async entry(clientMessageId, device) {
87
+ await this.store.deleteExpiredSendLog(this.retentionMs);
88
+ return this.store.getSendLogEntry(clientMessageId, device);
89
+ }
90
+ /**
91
+ * Count one resend of a logged send to one device. The count survives a
92
+ * restart. Returns the new count, or null when the device has no row.
93
+ */
94
+ async countResend(clientMessageId, device) {
95
+ return this.store.incrementSendLogResendCount(clientMessageId, device);
96
+ }
97
+ /**
98
+ * The devices that have not confirmed a logged send with an E2EE delivery
99
+ * receipt, after expired entries are deleted.
100
+ */
101
+ async pendingRecipients(clientMessageId) {
102
+ await this.store.deleteExpiredSendLog(this.retentionMs);
103
+ return (await this.store.getSendLogRecipients(clientMessageId)).map(({ userId, deviceId }) => ({
104
+ userId,
105
+ deviceId,
106
+ }));
107
+ }
108
+ /**
109
+ * Delete all resendable content, for a client with content recovery off.
110
+ * The clear is skipped when the store kept no content since the last
111
+ * clear. The marker is written only after the clear succeeds, and a
112
+ * failure propagates.
113
+ *
114
+ * @returns The deleted entries and records, or null for a skipped clear
115
+ */
116
+ async clear() {
117
+ if ((await this.store.getMetadata(RESENDABLE_CONTENT_CLEARED_MARKER)) !== null)
118
+ return null;
119
+ const messageRecords = await this.store.clearAllMessageRecords();
120
+ const sendLogEntries = await this.store.clearSendLog();
121
+ await this.store.setMetadata(RESENDABLE_CONTENT_CLEARED_MARKER, String(this.now()));
122
+ return { sendLogEntries, messageRecords };
123
+ }
124
+ /**
125
+ * Record that the client can keep resendable content, so the next clear
126
+ * runs. Call it before the client writes any content.
127
+ */
128
+ async keepContent() {
129
+ await this.store.deleteMetadata(RESENDABLE_CONTENT_CLEARED_MARKER);
130
+ }
131
+ /** Delete the logged content of one send and its rows. */
132
+ async forget(clientMessageId) {
133
+ return this.store.deleteSendLogEntry(clientMessageId);
134
+ }
135
+ }
136
+ //# sourceMappingURL=resendable-content.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resendable-content.js","sourceRoot":"","sources":["../../client/resendable-content.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAQH,MAAM,MAAM,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,KAAK,CAAC;AAEpC;;;GAGG;AACH,MAAM,CAAC,MAAM,iCAAiC,GAAG,4BAA4B,CAAC;AAwB9E,MAAM,OAAO,iBAAiB;IAKT,KAAK;IAEN,WAAW;IACV,GAAG;IAPtB,gEAAgE;IACxD,QAAQ,CAAqB;IAErC,YACmB,KAA6B;IAC9C,qEAAqE;IACrD,WAAmB,EAClB,GAAG,GAAiB,IAAI,CAAC,GAAG;qBAH5B,KAAK;2BAEN,WAAW;mBACV,GAAG;IACnB,CAAC;IAEJ,mFAAmF;IAC5E,SAAS,CAAC,SAAiB;QAChC,OAAO,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS,GAAG,IAAI,CAAC,WAAW,CAAC;IACnD,CAAC;IAED,6EAA6E;IACtE,KAAK,CAAC,KAAK;QAChB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,MAAM,CAAC,CAAC;QAChD,MAAM,cAAc,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,oBAAo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13
13
  import { withProcessedEnvelopeLock, type ResolvedRetryFamilyMember } from '../local/store/reliability.js';
14
14
  import type { RetryRequestFailure } from './retry-request-envelope.js';
15
+ import type { SignalProtocolClientHooks } from './event-hooks.js';
15
16
  import type { RetryRequestOutcome } from './retry-request-lifecycle.js';
16
17
  type RetryFamilyStore = Parameters<typeof withProcessedEnvelopeLock>[0];
17
18
  /**
@@ -38,16 +39,56 @@ export interface RetryFamilyReceive {
38
39
  */
39
40
  admit(): Promise<boolean>;
40
41
  /**
41
- * Record a decrypt that succeeded. For a member, and for a failed
42
- * envelope with a request record, one write marks the failed envelope
43
- * processed and fulfilled. A redelivery of the failed envelope on either
44
- * path is then dropped, and so is each later member. When the write
45
- * fails, it writes one warning with the behavior
46
- * RETRY_FULFILL_WRITE_FAILED and returns, so the caller continues as for
47
- * any decrypted envelope. A redelivery of the failed envelope or of
48
- * another member can then give the content again.
42
+ * Tell which failed envelope a decrypt with this content fulfills: the
43
+ * failed envelope of a member, or of a failed envelope with a request
44
+ * record. Undefined when `fulfill` writes nothing for it. The receive
45
+ * record of the content names the result as its `failedEnvelopeId`.
46
+ * Call it after `admit`.
47
+ */
48
+ fulfills(decrypted?: {
49
+ readonly senderKeyDistribution: boolean;
50
+ readonly content: boolean;
51
+ }): string | undefined;
52
+ /**
53
+ * Record a decrypt that succeeded: outcome 1. The receive path calls it
54
+ * right after the commit of the receive record, before the
55
+ * acknowledgment or the return. For a member, and for a failed envelope
56
+ * with a request record, one write marks the failed envelope processed
57
+ * and fulfilled. That write stops the retry scheduler for the failed
58
+ * envelope. A redelivery of the failed envelope on either path is then
59
+ * dropped, and so is each later member. When the write fails, the error
60
+ * propagates: the caller does not acknowledge the envelope, and its
61
+ * redelivery finds the committed receive record and writes again.
62
+ *
63
+ * The fulfilled write does not run `onDeliveryRecovered`. That hook waits
64
+ * for the completion of the receive record (outcome 2), as
65
+ * `reportDeliveryRecovered` tells.
66
+ *
67
+ * A failed group message whose sender key was missing has a request
68
+ * record with no group. When the decrypt that gives its content resolves
69
+ * the group, the record gets it before the fulfilled write, so
70
+ * `onDeliveryRecovered` names it. A record that names a group keeps it.
71
+ *
72
+ * A member that brings only a sender-key distribution, for a failed
73
+ * envelope that is a sender-key group message, writes nothing and does
74
+ * not fulfill the failed envelope. The member installs the sender key and
75
+ * gives no content. A redelivery of the failed envelope then decrypts
76
+ * with that key and gives its content, and a later member is admitted.
77
+ * One debug line records the behavior RETRY_SENDER_KEY_RESEND. A member
78
+ * that brings content beside the distribution fulfills the failed
79
+ * envelope, as any other member does.
80
+ *
81
+ * @param decrypted - The decrypted content. `senderKeyDistribution` is
82
+ * true when the content carries a sender-key distribution. `content` is
83
+ * true when it carries content other than a distribution. `groupId` is
84
+ * the group that the decrypt resolved for group content, in the form
85
+ * of `DecryptedEnvelope.conversationId`.
49
86
  */
50
- fulfill(): Promise<void>;
87
+ fulfill(decrypted?: {
88
+ readonly senderKeyDistribution: boolean;
89
+ readonly content: boolean;
90
+ readonly groupId?: string;
91
+ }): Promise<void>;
51
92
  /**
52
93
  * Record a decrypted null message, in place of `fulfill`. A null
53
94
  * message carries no content, so the caller never gives it to the
@@ -107,13 +148,19 @@ export interface RetryFamilyReceive {
107
148
  * The processed record and the acknowledgment use the delivered envelope
108
149
  * ID.
109
150
  *
151
+ * Under the lock and before the receive, it runs `onDeliveryRecovered` for
152
+ * a failed envelope whose recovery the hook did not mark. An error from
153
+ * that hook propagates, so the receive path does not acknowledge the
154
+ * envelope, and its redelivery runs the hook again.
155
+ *
110
156
  * @param storage - The local store that keeps the retry records.
111
157
  * @param logger - The client logger.
158
+ * @param hooks - The client hooks, for `onDeliveryRecovered`.
112
159
  * @param envelope - The IDs of the received envelope: the delivered
113
160
  * envelope ID, and the client message ID when the relay delivers one.
114
161
  * @param receive - The receive path. It runs under the lock.
115
162
  */
116
- export declare function receiveInRetryFamily<T>(storage: RetryFamilyStore, logger: Required<Logger>, envelope: {
163
+ export declare function receiveInRetryFamily<T>(storage: RetryFamilyStore, logger: Required<Logger>, hooks: SignalProtocolClientHooks | undefined, envelope: {
117
164
  readonly id?: string;
118
165
  readonly clientMessageId?: string;
119
166
  }, receive: (family: RetryFamilyReceive) => Promise<T>): Promise<T>;
@@ -1 +1 @@
1
- {"version":3,"file":"retry-family.d.ts","sourceRoot":"","sources":["../../client/retry-family.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EAOL,yBAAyB,EACzB,KAAK,yBAAyB,EAE/B,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AACpE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAErE,KAAK,gBAAgB,GAAG,UAAU,CAAC,OAAO,yBAAyB,CAAC,CAAC,CAAC,CAAC,CAAC;AAExE;;;;GAIG;AACH,MAAM,WAAW,kBAAkB;IACjC;;;;OAIG;IACH,QAAQ,CAAC,MAAM,EAAE,yBAAyB,GAAG,SAAS,CAAC;IACvD;;;;;;;;;OASG;IACH,KAAK,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;IAC1B;;;;;;;;;OASG;IACH,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACzB;;;;;;;;;;;;;OAaG;IACH,WAAW,CAAC,WAAW,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5D;;;;;;OAMG;IACH,mBAAmB,CAAC,CAAC,SAAS;QAAE,YAAY,EAAE,MAAM,CAAC;QAAC,cAAc,EAAE,MAAM,CAAA;KAAE,EAC5E,QAAQ,EAAE,CAAC,GACV,CAAC,CAAC;IACL;;;;;;;;;;;;;;;;OAgBG;IACH,YAAY,CACV,WAAW,EAAE,MAAM,GAAG,SAAS,EAC/B,IAAI,EAAE,CAAC,MAAM,EAAE,mBAAmB,KAAK,OAAO,CAAC,mBA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
  * gets the content of one failed envelope at most once, from the envelope
10
10
  * itself or from one family member.
11
11
  */
12
- import { getProcessedEnvelope, getRetryRequest, markRetryRequestAnswered, resolveRetryFamilyMember, RetryRequestedEnvelopeChangedError, storeProcessedEnvelope, withProcessedEnvelopeLock, } from '../local/store/reliability.js';
12
+ import { getProcessedEnvelope, getRetryRequest, markRetryRequestAnswered, resolveRetryFamilyMember, RetryRequestedEnvelopeChangedError, storeProcessedEnvelope, updateRetryRequest, withProcessedEnvelopeLock, } from '../local/store/reliability.js';
13
+ import { reportDeliveryRecovered } from './delivery-error.js';
13
14
  /**
14
15
  * Receive one envelope in the retry family of its failed envelope.
15
16
  *
@@ -24,23 +25,35 @@ import { getProcessedEnvelope, getRetryRequest, markRetryRequestAnswered, resolv
24
25
  * The processed record and the acknowledgment use the delivered envelope
25
26
  * ID.
26
27
  *
28
+ * Under the lock and before the receive, it runs `onDeliveryRecovered` for
29
+ * a failed envelope whose recovery the hook did not mark. An error from
30
+ * that hook propagates, so the receive path does not acknowledge the
31
+ * envelope, and its redelivery runs the hook again.
32
+ *
27
33
  * @param storage - The local store that keeps the retry records.
28
34
  * @param logger - The client logger.
35
+ * @param hooks - The client hooks, for `onDeliveryRecovered`.
29
36
  * @param envelope - The IDs of the received envelope: the delivered
30
37
  * envelope ID, and the client message ID when the relay delivers one.
31
38
  * @param receive - The receive path. It runs under the lock.
32
39
  */
33
- export async function receiveInRetryFamily(storage, logger, envelope, receive) {
40
+ export async function receiveInRetryFamily(storage, logger, hooks, envelope, receive) {
34
41
  const envelopeId = envelope.id;
35
- if (!envelopeId)
42
+ if (!envelopeId) {
36
43
  return receive(retryFamilyReceive(storage, logger, undefined, undefined));
44
+ }
37
45
  const member = await resolveRetryFamilyMember(storage, envelope.clientMessageId ?? envelopeId);
38
- return withProcessedEnvelopeLock(storage, member?.failedEnvelopeId ?? envelopeId, () => receive(retryFamilyReceive(storage, logger, envelopeId, member)));
46
+ const failedEnvelopeId = member?.failedEnvelopeId ?? envelopeId;
47
+ return withProcessedEnvelopeLock(storage, failedEnvelopeId, async () => {
48
+ // A recovery whose hook did not return runs again. An error from the
49
+ // hook fails the receive, so the envelope is delivered again.
50
+ await reportDeliveryRecovered(storage, hooks, failedEnvelopeId);
51
+ return receive(retryFamilyReceive(storage, logger, envelopeId, member));
52
+ });
39
53
  }
40
54
  function retryFamilyReceive(storage, logger, envelopeId, member) {
41
55
  const failedEnvelopeId = member?.failedEnvelopeId ?? envelopeId;
42
- // The read comes before the decrypt, so only writes follow the
43
- // application hook.
56
+ // The read comes before the decrypt, so only writes follow the commit.
44
57
  let request = null;
45
58
  return {
46
59
  member,
@@ -75,18 +88,46 @@ function retryFamilyReceive(storage, logger, envelopeId, member) {
75
88
  request = await getRetryRequest(storage, failedEnvelopeId);
76
89
  return true;
77
90
  },
78
- async fulfill() {
91
+ fulfills(decrypted) {
92
+ if (member &&
93
+ request?.groupMessage &&
94
+ decrypted?.senderKeyDistribution &&
95
+ !decrypted.content) {
96
+ return undefined;
97
+ }
98
+ if (failedEnvelopeId === undefined || !(member || request))
99
+ return undefined;
100
+ return failedEnvelopeId;
101
+ },
102
+ async fulfill(decrypted) {
103
+ if (member &&
104
+ request?.groupMessage &&
105
+ decrypted?.senderKeyDistribution &&
106
+ !decrypted.content) {
107
+ logger.debug('A resend gave the sender key of a failed group message', {
108
+ category: 'E2EE',
109
+ data: { envelopeId, behavior: 'RETRY_SENDER_KEY_RESEND' },
110
+ });
111
+ return;
112
+ }
113
+ if (failedEnvelopeId === undefined || !(member || request))
114
+ return;
79
115
  try {
116
+ const groupId = decrypted?.groupId;
117
+ if (request && request.groupId === undefined && groupId !== undefined) {
118
+ request =
119
+ (await updateRetryRequest(storage, failedEnvelopeId, request.retryId, request.attempt, {
120
+ groupId,
121
+ })) ?? request;
122
+ }
80
123
  // One write marks the failed envelope processed and fulfilled. A
81
124
  // redelivery of it is then acknowledged with no decrypt, and each
82
125
  // later member of its request is dropped.
83
- if (failedEnvelopeId !== undefined && (member || request)) {
84
- await storeProcessedEnvelope(storage, failedEnvelopeId, Date.now(), undefined, true);
85
- }
126
+ await storeProcessedEnvelope(storage, failedEnvelopeId, Date.now(), undefined, true);
86
127
  }
87
128
  catch (error) {
88
- // The application gets the plaintext. Only a redelivery can
89
- // decrypt the content again.
129
+ // The receive record holds the content. The caller does not
130
+ // acknowledge, so the redelivery writes outcome 1 again.
90
131
  logger.warn('The retry family record of a decrypted envelope failed to store', {
91
132
  category: 'E2EE',
92
133
  data: {
@@ -95,6 +136,7 @@ function retryFamilyReceive(storage, logger, envelopeId, member) {
95
136
  error: error.message,
96
137
  },
97
138
  });
139
+ throw error;
98
140
  }
99
141
  },
100
142
  async consumeNull(fingerprint) {
@@ -1 +1 @@
1
- {"version":3,"file":"retry-family.js","sourceRoot":"","sources":["../../client/retry-family.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,EACL,oBAAoB,EACpB,eAAe,EACf,wBAAwB,EACxB,wBAAwB,EACxB,kCAAkC,EAClC,sBAAsB,EACtB,yBAAyB,GAG1B,MAAM,4BAA4B,CAAC;AAwFpC;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,OAAyB,EACzB,MAAwB,EACxB,QAAqE,EACrE,OAAmD;IAEnD,MAAM,UAAU,GAAG,QAAQ,CAAC,EAAE,CAAC;IAC/B,IAAI,CAAC,UAAU;QAAE,OAAO,OAAO,CAAC,kBAAkB,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC,CAAC;IAC3F,MAAM,MAAM,GAAG,MAAM,wBAAwB,CAC3C,OAAO,EACP,QAAQ,CAAC,eAAe,IAAI,UAAU,CACvC,CAAC;IACF,OAAO,yBAAyB,CAAC,OAAO,EAAE,MAAM,EAAE,gBAAgB,IAAI,UAAU,EAAE,GAAG,EAAE,CACrF,OAAO,CAAC,kBAAkB,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU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AC,CAAC;oBACH,OAAO,SAAS,CAAC;gBACnB,CAAC;gBACD,OAAO,IAAI,CAAC;oBACV,EAAE,EAAE,gBAAgB;oBACpB,GAAG,CAAC,WAAW,KAAK,SAAS,IAAI,EAAE,WAAW,EAAE,CAAC;oBACjD,MAAM;iBACP,CAAC,CAAC;YACL,CAAC;YACD,8DAA8D;YAC9D,sCAAsC;YACtC,MAAM,MAAM,GAAG,MAAM,eAAe,CAAC,OAAO,EAAE,gBAAgB,CAAC,CAAC;YAChE,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC;gBACzB,EAAE,EAAE,gBAAgB;gBACpB,GAAG,CAAC,MAAM,EAAE,WAAW,KAAK,SAAS,IAAI,EAAE,WAAW,EAAE,MAAM,CAAC,WAAW,EAAE,CAAC;gBAC7E,MAAM;gBACN,GAAG,CAAC,UAAU,KAAK,SAAS,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC;aACxD,CAAC,CAAC;YACH,IAAI,CAAC,OAAO,KAAK,QAAQ,IAAI,OAAO,KAAK,UAAU,CAAC,IAAI,UAAU,EAAE,CAAC;gBACnE,MAAM,sBAAsB,CAAC,OAAO,EAAE,UAAU,EAAE,IAAI,CAAC,GAAG,EAAE,EAAE,WAAW,CAAC,CAAC;YAC7E,CAAC;YACD,OAAO,OAAO,CAAC;QACjB,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -1,11 +1,18 @@
1
1
  /**
2
2
  * Wire form of a retry request.
3
3
  *
4
- * A retry request travels as an identified mailbox envelope with
5
- * `messageType: 'retry_request'`. The envelope sender is the requester: the
6
- * relay stamps it, so the payload never carries it. The `ciphertext` field
7
- * holds canonical base64 of a small UTF-8 JSON payload. The payload is not
8
- * encrypted. It holds only what the requester knows about the failed message.
4
+ * A retry request is a mailbox envelope with `messageType: 'retry_request'`.
5
+ * The envelope sender is the requester, so the payload never carries it.
6
+ * The `ciphertext` field holds canonical base64 of a small UTF-8 JSON
7
+ * payload. The payload is not ratchet-encrypted. It holds only what the
8
+ * requester knows about the failed message.
9
+ *
10
+ * The request record stores the identified form of the envelope.
11
+ * `retryRequestPost` seals it at each post when an access key of the target
12
+ * permits it: the seal holds the same payload as `PLAINTEXT_CONTENT`, and
13
+ * the sender certificate in the seal names the requester. Otherwise the
14
+ * post is identified, and the relay stamps the requester, only when the
15
+ * sealed sender delivery mode permits it.
9
16
  *
10
17
  * The requester keeps one request record for each failed envelope. The record
11
18
  * holds a random retry ID, and every wire ID of the request family derives from
@@ -16,9 +23,15 @@
16
23
  * The requester stores each request envelope before the post. After a post
17
24
  * that fails with a retryable class, the retry request scheduler posts the
18
25
  * stored envelope again, until the deadline of the record.
26
+ *
27
+ * A relay can assign its own envelope ID. The payload then also carries the
28
+ * client message ID of the failed envelope, the ID that the sender chose. A
29
+ * request without a ratchet key names a failed sender-key message.
19
30
  */
20
- import type { Envelope } from '../remote/relay/types.js';
31
+ import type { Envelope, SignalProtocolRelayServer } from '../remote/relay/types.js';
32
+ import type { SealedReceipt } from './types.js';
21
33
  import { type RetryRequest } from '../internal/sesame/types.js';
34
+ import type { ContentHint } from '../types/messages.js';
22
35
  import { storeRetryRequest, type RetryRequestIds, type StoredRetryRequest } from '../local/store/reliability.js';
23
36
  /** The decoder refuses a longer `ciphertext` value before it decodes it. */
24
37
  export declare const MAX_RETRY_REQUEST_CIPHERTEXT_LENGTH = 2048;
@@ -49,6 +62,37 @@ export interface RetryRequestFailure {
49
62
  fingerprint?: string;
50
63
  /** The stored attempt of the request for this envelope, from `getRetryRequest`. */
51
64
  stored: StoredRetryRequest | null;
65
+ /**
66
+ * True when the failed envelope is a sender-key group message. A new
67
+ * record stores it. A new attempt keeps the value of the stored record.
68
+ */
69
+ groupMessage?: boolean;
70
+ /**
71
+ * The client message ID of the failed envelope. Set it only when the
72
+ * failed envelope itself failed, because a member has its own ID. A new
73
+ * record stores it. A new attempt keeps the value of the stored record.
74
+ */
75
+ clientMessageId?: string;
76
+ /**
77
+ * The raw group ID of the failed envelope, when the local device knows
78
+ * it. Set it only when the failed envelope itself failed. A new record
79
+ * stores it. A new attempt keeps the value of the stored record.
80
+ */
81
+ groupId?: string;
82
+ /**
83
+ * The content hint of the failed envelope. Set it only when the failed
84
+ * envelope itself failed. A new record stores it. A new attempt keeps the
85
+ * value of the stored record.
86
+ */
87
+ contentHint?: ContentHint;
88
+ /**
89
+ * The device that sent the failed envelope. A new record stores it. A
90
+ * new attempt keeps the value of the stored record.
91
+ */
92
+ sender?: {
93
+ userId: string;
94
+ deviceId: number;
95
+ };
52
96
  /**
53
97
  * The envelope ID of the resend or the null message that failed to
54
98
  * decrypt. Undefined when the failed envelope itself failed.
@@ -67,6 +111,47 @@ export interface RetryRequestFailure {
67
111
  export declare function retryRequestEnvelope(request: RetryRequest, sender: RetryRequestDevice, failed?: RetryRequestIds & {
68
112
  attempt: number;
69
113
  }): Promise<Envelope>;
114
+ /**
115
+ * Seals the payload of one retry request for its target device, or resolves
116
+ * to undefined when the request goes identified. It throws when sealed
117
+ * sender is required and the request cannot be sealed.
118
+ */
119
+ export type SealRetryRequest = (recipientUserId: string, recipientDeviceId: number, payloadBase64: string) => Promise<SealedReceipt | undefined>;
120
+ /**
121
+ * Make the function that posts one retry request envelope, by the sealed
122
+ * sender delivery mode, as a receipt goes.
123
+ *
124
+ * With an access key of the target, the post is sealed: the Relay sees the
125
+ * target, the timing and the size, and not the requester. The sealed post
126
+ * keeps the client message ID and the timestamp of the envelope, so the
127
+ * Relay deduplicates the attempt by the same operation as an identified
128
+ * post. When the Relay refuses the access key, the post goes identified
129
+ * only when the delivery mode permits it. When `seal` resolves to
130
+ * undefined, the post goes identified. In `'required'` mode `seal` throws
131
+ * instead, and nothing goes identified. The caller classifies each error
132
+ * of the post.
133
+ *
134
+ * When the Relay refuses the post as `STALE_DEVICE`, the target device has
135
+ * a new registration. The post then refreshes the session with the device
136
+ * once from a fresh bundle, and posts the same envelope again, sealed and
137
+ * named with the new session, as a receipt goes. The request is plaintext,
138
+ * so nothing is encrypted again. A refresh that finds no bundle,
139
+ * or a second refusal, throws the refusal. A refresh that fails for another
140
+ * reason throws StaleSessionRefreshError, which classifies as a transport
141
+ * outage, so the next post refreshes again.
142
+ *
143
+ * @param seal - Seals the payload. Without it, each post is identified.
144
+ * @param relay - Posts the sealed envelope.
145
+ * @param sendIdentified - Posts the identified envelope.
146
+ * @param registrationOf - The registration ID of the current session with
147
+ * the target device. The identified envelope names it, as the sealed body
148
+ * does, so the Relay refuses the post to a reinstalled device. With no
149
+ * session, or without this function, the envelope names none.
150
+ * @param refreshStaleSession - Refreshes the session with a refused device.
151
+ * Resolves to true when the new session is ready. Without it, a stale
152
+ * refusal throws.
153
+ */
154
+ export declare function retryRequestPost(seal: SealRetryRequest | undefined, relay: Pick<SignalProtocolRelayServer, 'sendMultiRecipientUnidentified'> | undefined, sendIdentified: (envelope: Envelope) => Promise<unknown>, registrationOf?: (userId: string, deviceId: number) => Promise<number | undefined>, refreshStaleSession?: (userId: string, deviceId: number) => Promise<boolean>): (envelope: Envelope) => Promise<unknown>;
70
155
  /** What a retry request post did. */
71
156
  export type RetryPostOutcome =
72
157
  /** The Relay holds the request attempt. */
@@ -75,6 +160,13 @@ export type RetryPostOutcome =
75
160
  | 'pending'
76
161
  /** The request ended. The record holds the terminal state. */
77
162
  | 'terminal';
163
+ /**
164
+ * Tell whether a stored request attempt is answered and is the last
165
+ * attempt of its request. A sender answers at most
166
+ * `MAX_RETRY_RESPONSES_PER_MESSAGE` requests for one message, so when the
167
+ * resend that answered this attempt also fails, the request ends.
168
+ */
169
+ export declare function answeredLastRetryAttempt(stored: StoredRetryRequest): boolean;
78
170
  /**
79
171
  * Post the retry request for one failed envelope.
80
172
  *
@@ -85,8 +177,15 @@ export type RetryPostOutcome =
85
177
  * record that ended posts nothing. At the deadline of the record, the
86
178
  * request ends as `expired-content` and posts nothing. When a member
87
179
  * failed and the stored attempt is answered, it creates the next attempt
88
- * under the same retry ID, with the same deadline, and posts it. Otherwise
89
- * it posts the stored attempt, as `postStoredRetryRequest` does.
180
+ * under the same retry ID, with the same deadline, and posts it. When that
181
+ * answered attempt is the last one, as `answeredLastRetryAttempt` tells,
182
+ * the request ends as `attempts-exhausted` and posts nothing. Otherwise it
183
+ * posts the stored attempt, as `postStoredRetryRequest` does.
184
+ *
185
+ * Each new attempt carries the failed client message ID, the content hint,
186
+ * the sender, the receive time and the delivery error state of the stored
187
+ * record. Attempt 1 takes them from `failed`, with the time of now as the
188
+ * receive time.
90
189
  *
91
190
  * @param store - The local store that keeps the request records.
92
191
  * @param failed - The failed envelope and its stored request.
@@ -1 +1 @@
1
- {"version":3,"file":"retry-request-envelope.d.ts","sourceRoot":"","sources":["../../client/retry-request-envelope.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAe,KAAK,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAI1E,OAAO,EAML,iBAAiB,EAEjB,KAAK,eAAe,EACpB,KAAK,kBAAkB,EACxB,MAAM,4BAA4B,CAAC;AAWpC,4EAA4E;AAC5E,eAAO,MAAM,mCAAmC,OAAQ,CAAC;AAUzD,qCAAqC;AACrC,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;CAClB;AAcD;;;;;GAKG;AACH,MAAM,MAAM,wBAAwB,GAChC;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,OAAO,EAAE,YAAY,CAAC;IAAC,KAAK,CAAC,EAAE,eAAe,CAAA;CAAE,GAC5D;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAEjC,8EAA8E;AAC9E,MAAM,WAAW,mBAAmB;IAClC,kFAAkF;IAClF,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,8CAA8C;IAC9C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,m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