@open-e2ee/signal-protocol-sdk 10.1.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 (595) hide show
  1. package/ADAPTERS.md +4 -4
  2. package/ARCHITECTURE.md +6 -8
  3. package/CHANGELOG.md +1413 -0
  4. package/README.md +1 -1
  5. package/SECURITY.md +2 -2
  6. package/TROUBLESHOOTING.md +1 -1
  7. package/client/README.md +84 -37
  8. package/device/README.md +39 -85
  9. package/dist/client/client.d.ts +342 -62
  10. package/dist/client/client.d.ts.map +1 -1
  11. package/dist/client/client.js +1195 -179
  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 +308 -6
  42. package/dist/client/event-hooks.d.ts.map +1 -1
  43. package/dist/client/event-hooks.js +9 -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-device-standing.d.ts +52 -0
  82. package/dist/client/hosted-device-standing.d.ts.map +1 -0
  83. package/dist/client/hosted-device-standing.js +74 -0
  84. package/dist/client/hosted-device-standing.js.map +1 -0
  85. package/dist/client/hosted-mailbox-subscription.d.ts +48 -3
  86. package/dist/client/hosted-mailbox-subscription.d.ts.map +1 -1
  87. package/dist/client/hosted-mailbox-subscription.js +288 -74
  88. package/dist/client/hosted-mailbox-subscription.js.map +1 -1
  89. package/dist/client/hosted-push.d.ts +22 -4
  90. package/dist/client/hosted-push.d.ts.map +1 -1
  91. package/dist/client/hosted-push.js +75 -22
  92. package/dist/client/hosted-push.js.map +1 -1
  93. package/dist/client/hosted-transport.d.ts +22 -28
  94. package/dist/client/hosted-transport.d.ts.map +1 -1
  95. package/dist/client/hosted-transport.js +167 -69
  96. package/dist/client/hosted-transport.js.map +1 -1
  97. package/dist/client/hosted.d.ts +22 -5
  98. package/dist/client/hosted.d.ts.map +1 -1
  99. package/dist/client/hosted.js +122 -45
  100. package/dist/client/hosted.js.map +1 -1
  101. package/dist/client/index.d.ts +6 -4
  102. package/dist/client/index.d.ts.map +1 -1
  103. package/dist/client/index.js +3 -1
  104. package/dist/client/index.js.map +1 -1
  105. package/dist/client/messages.d.ts +25 -3
  106. package/dist/client/messages.d.ts.map +1 -1
  107. package/dist/client/messages.js +118 -17
  108. package/dist/client/messages.js.map +1 -1
  109. package/dist/client/one-time-prekey-refill.d.ts +7 -0
  110. package/dist/client/one-time-prekey-refill.d.ts.map +1 -1
  111. package/dist/client/one-time-prekey-refill.js +5 -1
  112. package/dist/client/one-time-prekey-refill.js.map +1 -1
  113. package/dist/client/receive-admission.d.ts +58 -0
  114. package/dist/client/receive-admission.d.ts.map +1 -0
  115. package/dist/client/receive-admission.js +78 -0
  116. package/dist/client/receive-admission.js.map +1 -0
  117. package/dist/client/receive-expiry.d.ts +31 -0
  118. package/dist/client/receive-expiry.d.ts.map +1 -0
  119. package/dist/client/receive-expiry.js +35 -0
  120. package/dist/client/receive-expiry.js.map +1 -0
  121. package/dist/client/receive-hook-bound.d.ts +50 -0
  122. package/dist/client/receive-hook-bound.d.ts.map +1 -0
  123. package/dist/client/receive-hook-bound.js +115 -0
  124. package/dist/client/receive-hook-bound.js.map +1 -0
  125. package/dist/client/receive-queue.d.ts +299 -0
  126. package/dist/client/receive-queue.d.ts.map +1 -0
  127. package/dist/client/receive-queue.js +1420 -0
  128. package/dist/client/receive-queue.js.map +1 -0
  129. package/dist/client/receive-work-seed.d.ts +54 -0
  130. package/dist/client/receive-work-seed.d.ts.map +1 -0
  131. package/dist/client/receive-work-seed.js +116 -0
  132. package/dist/client/receive-work-seed.js.map +1 -0
  133. package/dist/client/recovery-driver.d.ts +25 -0
  134. package/dist/client/recovery-driver.d.ts.map +1 -0
  135. package/dist/client/recovery-driver.js +121 -0
  136. package/dist/client/recovery-driver.js.map +1 -0
  137. package/dist/client/relay-acceptance.d.ts +30 -0
  138. package/dist/client/relay-acceptance.d.ts.map +1 -1
  139. package/dist/client/relay-acceptance.js +55 -0
  140. package/dist/client/relay-acceptance.js.map +1 -1
  141. package/dist/client/relay-device-refusal.d.ts +18 -0
  142. package/dist/client/relay-device-refusal.d.ts.map +1 -1
  143. package/dist/client/relay-device-refusal.js +31 -0
  144. package/dist/client/relay-device-refusal.js.map +1 -1
  145. package/dist/client/relay-sealed-route.d.ts +36 -0
  146. package/dist/client/relay-sealed-route.d.ts.map +1 -0
  147. package/dist/client/relay-sealed-route.js +45 -0
  148. package/dist/client/relay-sealed-route.js.map +1 -0
  149. package/dist/client/relay-subscription.d.ts +56 -13
  150. package/dist/client/relay-subscription.d.ts.map +1 -1
  151. package/dist/client/relay-subscription.js +220 -150
  152. package/dist/client/relay-subscription.js.map +1 -1
  153. package/dist/client/resendable-content.d.ts +98 -0
  154. package/dist/client/resendable-content.d.ts.map +1 -0
  155. package/dist/client/resendable-content.js +136 -0
  156. package/dist/client/resendable-content.js.map +1 -0
  157. package/dist/client/retry-family.d.ts +68 -19
  158. package/dist/client/retry-family.d.ts.map +1 -1
  159. package/dist/client/retry-family.js +59 -17
  160. package/dist/client/retry-family.js.map +1 -1
  161. package/dist/client/retry-request-envelope.d.ts +145 -18
  162. package/dist/client/retry-request-envelope.d.ts.map +1 -1
  163. package/dist/client/retry-request-envelope.js +301 -64
  164. package/dist/client/retry-request-envelope.js.map +1 -1
  165. package/dist/client/retry-request-lifecycle.d.ts +157 -0
  166. package/dist/client/retry-request-lifecycle.d.ts.map +1 -0
  167. package/dist/client/retry-request-lifecycle.js +437 -0
  168. package/dist/client/retry-request-lifecycle.js.map +1 -0
  169. package/dist/client/retry-terminal-recovery.d.ts +100 -0
  170. package/dist/client/retry-terminal-recovery.d.ts.map +1 -0
  171. package/dist/client/retry-terminal-recovery.js +164 -0
  172. package/dist/client/retry-terminal-recovery.js.map +1 -0
  173. package/dist/client/retry-utils.d.ts +27 -0
  174. package/dist/client/retry-utils.d.ts.map +1 -1
  175. package/dist/client/retry-utils.js +46 -0
  176. package/dist/client/retry-utils.js.map +1 -1
  177. package/dist/client/retry.d.ts +106 -18
  178. package/dist/client/retry.d.ts.map +1 -1
  179. package/dist/client/retry.js +687 -139
  180. package/dist/client/retry.js.map +1 -1
  181. package/dist/client/sealed-sender.d.ts +23 -6
  182. package/dist/client/sealed-sender.d.ts.map +1 -1
  183. package/dist/client/sealed-sender.js +30 -6
  184. package/dist/client/sealed-sender.js.map +1 -1
  185. package/dist/client/sessions.d.ts +2 -2
  186. package/dist/client/sessions.js +2 -2
  187. package/dist/client/signal-service-cipher.d.ts +726 -19
  188. package/dist/client/signal-service-cipher.d.ts.map +1 -1
  189. package/dist/client/signal-service-cipher.js +2265 -343
  190. package/dist/client/signal-service-cipher.js.map +1 -1
  191. package/dist/client/state.d.ts +5 -0
  192. package/dist/client/state.d.ts.map +1 -1
  193. package/dist/client/state.js +11 -1
  194. package/dist/client/state.js.map +1 -1
  195. package/dist/client/storage-protection.d.ts +64 -0
  196. package/dist/client/storage-protection.d.ts.map +1 -0
  197. package/dist/client/storage-protection.js +150 -0
  198. package/dist/client/storage-protection.js.map +1 -0
  199. package/dist/client/types.d.ts +149 -15
  200. package/dist/client/types.d.ts.map +1 -1
  201. package/dist/client/types.js +1 -1
  202. package/dist/client/types.js.map +1 -1
  203. package/dist/device/constants.d.ts +0 -5
  204. package/dist/device/constants.d.ts.map +1 -1
  205. package/dist/device/constants.js +0 -5
  206. package/dist/device/constants.js.map +1 -1
  207. package/dist/device/expo/index.d.ts +4 -17
  208. package/dist/device/expo/index.d.ts.map +1 -1
  209. package/dist/device/expo/index.js +4 -23
  210. package/dist/device/expo/index.js.map +1 -1
  211. package/dist/device/index.d.ts +0 -2
  212. package/dist/device/index.d.ts.map +1 -1
  213. package/dist/device/index.js +0 -7
  214. package/dist/device/index.js.map +1 -1
  215. package/dist/device/lifecycle/manager.d.ts +5 -4
  216. package/dist/device/lifecycle/manager.d.ts.map +1 -1
  217. package/dist/device/lifecycle/manager.js +16 -16
  218. package/dist/device/lifecycle/manager.js.map +1 -1
  219. package/dist/device/lifecycle/types.d.ts +2 -2
  220. package/dist/device/lifecycle/types.d.ts.map +1 -1
  221. package/dist/device/react-native/index.d.ts +4 -15
  222. package/dist/device/react-native/index.d.ts.map +1 -1
  223. package/dist/device/react-native/index.js +4 -21
  224. package/dist/device/react-native/index.js.map +1 -1
  225. package/dist/device/types.d.ts +1 -1
  226. package/dist/groups/index.d.ts +1 -1
  227. package/dist/groups/index.d.ts.map +1 -1
  228. package/dist/index.d.ts +8 -6
  229. package/dist/index.d.ts.map +1 -1
  230. package/dist/index.js +2 -1
  231. package/dist/index.js.map +1 -1
  232. package/dist/internal/crypto/ec/x25519-validation.d.ts +0 -1
  233. package/dist/internal/crypto/ec/x25519-validation.d.ts.map +1 -1
  234. package/dist/internal/crypto/ec/x25519-validation.js +0 -1
  235. package/dist/internal/crypto/ec/x25519-validation.js.map +1 -1
  236. package/dist/internal/crypto/validation.d.ts +2 -2
  237. package/dist/internal/groups/index.d.ts +1 -0
  238. package/dist/internal/groups/index.d.ts.map +1 -1
  239. package/dist/internal/groups/index.js +1 -0
  240. package/dist/internal/groups/index.js.map +1 -1
  241. package/dist/internal/groups/manager.d.ts +37 -16
  242. package/dist/internal/groups/manager.d.ts.map +1 -1
  243. package/dist/internal/groups/manager.js +46 -1
  244. package/dist/internal/groups/manager.js.map +1 -1
  245. package/dist/internal/groups/receive-record.d.ts +78 -0
  246. package/dist/internal/groups/receive-record.d.ts.map +1 -0
  247. package/dist/internal/groups/receive-record.js +43 -0
  248. package/dist/internal/groups/receive-record.js.map +1 -0
  249. package/dist/internal/groups/sdk-store.d.ts +27 -3
  250. package/dist/internal/groups/sdk-store.d.ts.map +1 -1
  251. package/dist/internal/groups/sdk-store.js +151 -19
  252. package/dist/internal/groups/sdk-store.js.map +1 -1
  253. package/dist/internal/groups/wire.d.ts +12 -1
  254. package/dist/internal/groups/wire.d.ts.map +1 -1
  255. package/dist/internal/groups/wire.js +36 -0
  256. package/dist/internal/groups/wire.js.map +1 -1
  257. package/dist/internal/manager/index.d.ts +1 -1
  258. package/dist/internal/manager/manager.d.ts +20 -19
  259. package/dist/internal/manager/manager.d.ts.map +1 -1
  260. package/dist/internal/manager/manager.js +56 -39
  261. package/dist/internal/manager/manager.js.map +1 -1
  262. package/dist/internal/protocol/double-ratchet/chains.d.ts +4 -18
  263. package/dist/internal/protocol/double-ratchet/chains.d.ts.map +1 -1
  264. package/dist/internal/protocol/double-ratchet/chains.js +23 -74
  265. package/dist/internal/protocol/double-ratchet/chains.js.map +1 -1
  266. package/dist/internal/protocol/double-ratchet/index.d.ts +1 -1
  267. package/dist/internal/protocol/double-ratchet/index.d.ts.map +1 -1
  268. package/dist/internal/protocol/double-ratchet/index.js +1 -1
  269. package/dist/internal/protocol/double-ratchet/index.js.map +1 -1
  270. package/dist/internal/protocol/double-ratchet/ratchet.d.ts +5 -7
  271. package/dist/internal/protocol/double-ratchet/ratchet.d.ts.map +1 -1
  272. package/dist/internal/protocol/double-ratchet/ratchet.js +4 -6
  273. package/dist/internal/protocol/double-ratchet/ratchet.js.map +1 -1
  274. package/dist/internal/protocol/pqxdh/pqxdh.d.ts.map +1 -1
  275. package/dist/internal/protocol/pqxdh/pqxdh.js +2 -1
  276. package/dist/internal/protocol/pqxdh/pqxdh.js.map +1 -1
  277. package/dist/internal/protocol/sealed-sender/types.d.ts +6 -8
  278. package/dist/internal/protocol/sealed-sender/types.d.ts.map +1 -1
  279. package/dist/internal/protocol/sealed-sender/types.js +8 -9
  280. package/dist/internal/protocol/sealed-sender/types.js.map +1 -1
  281. package/dist/internal/protocol/sender-keys/handoff-ledger.d.ts +110 -0
  282. package/dist/internal/protocol/sender-keys/handoff-ledger.d.ts.map +1 -0
  283. package/dist/internal/protocol/sender-keys/handoff-ledger.js +124 -0
  284. package/dist/internal/protocol/sender-keys/handoff-ledger.js.map +1 -0
  285. package/dist/internal/protocol/sender-keys/manager.d.ts +71 -62
  286. package/dist/internal/protocol/sender-keys/manager.d.ts.map +1 -1
  287. package/dist/internal/protocol/sender-keys/manager.js +228 -175
  288. package/dist/internal/protocol/sender-keys/manager.js.map +1 -1
  289. package/dist/internal/protocol/spqr/index.d.ts +2 -2
  290. package/dist/internal/protocol/spqr/index.d.ts.map +1 -1
  291. package/dist/internal/protocol/spqr/index.js +2 -2
  292. package/dist/internal/protocol/spqr/index.js.map +1 -1
  293. package/dist/internal/protocol/spqr/serialize.d.ts +9 -1
  294. package/dist/internal/protocol/spqr/serialize.d.ts.map +1 -1
  295. package/dist/internal/protocol/spqr/serialize.js +56 -16
  296. package/dist/internal/protocol/spqr/serialize.js.map +1 -1
  297. package/dist/internal/protocol/spqr/spqr.d.ts +1 -14
  298. package/dist/internal/protocol/spqr/spqr.d.ts.map +1 -1
  299. package/dist/internal/protocol/spqr/spqr.js +54 -42
  300. package/dist/internal/protocol/spqr/spqr.js.map +1 -1
  301. package/dist/internal/protocol/spqr/validate.d.ts +26 -6
  302. package/dist/internal/protocol/spqr/validate.d.ts.map +1 -1
  303. package/dist/internal/protocol/spqr/validate.js +49 -21
  304. package/dist/internal/protocol/spqr/validate.js.map +1 -1
  305. package/dist/internal/sesame/index.d.ts +1 -1
  306. package/dist/internal/sesame/index.d.ts.map +1 -1
  307. package/dist/internal/sesame/index.js.map +1 -1
  308. package/dist/internal/sesame/manager.d.ts +66 -13
  309. package/dist/internal/sesame/manager.d.ts.map +1 -1
  310. package/dist/internal/sesame/manager.js +221 -87
  311. package/dist/internal/sesame/manager.js.map +1 -1
  312. package/dist/internal/sesame/types.d.ts +95 -17
  313. package/dist/internal/sesame/types.d.ts.map +1 -1
  314. package/dist/internal/sesame/types.js +17 -0
  315. package/dist/internal/sesame/types.js.map +1 -1
  316. package/dist/internal/session/builder.d.ts +5 -5
  317. package/dist/internal/session/builder.d.ts.map +1 -1
  318. package/dist/internal/session/builder.js +12 -17
  319. package/dist/internal/session/builder.js.map +1 -1
  320. package/dist/internal/session/cipher.d.ts +13 -11
  321. package/dist/internal/session/cipher.d.ts.map +1 -1
  322. package/dist/internal/session/cipher.js +40 -22
  323. package/dist/internal/session/cipher.js.map +1 -1
  324. package/dist/internal/session/factory.d.ts +5 -5
  325. package/dist/internal/session/factory.d.ts.map +1 -1
  326. package/dist/internal/session/factory.js +4 -4
  327. package/dist/internal/session/factory.js.map +1 -1
  328. package/dist/internal/session/handshake.d.ts +14 -16
  329. package/dist/internal/session/handshake.d.ts.map +1 -1
  330. package/dist/internal/session/handshake.js +18 -75
  331. package/dist/internal/session/handshake.js.map +1 -1
  332. package/dist/internal/session/index.d.ts +1 -1
  333. package/dist/internal/session/index.js +1 -1
  334. package/dist/internal/session/record-locks.d.ts +17 -6
  335. package/dist/internal/session/record-locks.d.ts.map +1 -1
  336. package/dist/internal/session/record-locks.js +43 -7
  337. package/dist/internal/session/record-locks.js.map +1 -1
  338. package/dist/internal/session/session-resolver.d.ts +1 -1
  339. package/dist/internal/session/session-resolver.js +1 -1
  340. package/dist/internal/session/state.d.ts +2 -2
  341. package/dist/internal/session/state.js +1 -1
  342. package/dist/internal/session/types.d.ts +4 -12
  343. package/dist/internal/session/types.d.ts.map +1 -1
  344. package/dist/internal/session/types.js +1 -1
  345. package/dist/keys/generation.d.ts +2 -2
  346. package/dist/keys/generation.js +2 -2
  347. package/dist/keys/types.d.ts +5 -5
  348. package/dist/keys/types.d.ts.map +1 -1
  349. package/dist/keys/types.js +1 -1
  350. package/dist/layers.d.ts +1 -1
  351. package/dist/layers.js +2 -2
  352. package/dist/layers.js.map +1 -1
  353. package/dist/local/store/expo/adapter.d.ts.map +1 -1
  354. package/dist/local/store/expo/adapter.js +12 -8
  355. package/dist/local/store/expo/adapter.js.map +1 -1
  356. package/dist/local/store/key-value/adapter.d.ts +76 -10
  357. package/dist/local/store/key-value/adapter.d.ts.map +1 -1
  358. package/dist/local/store/key-value/adapter.js +367 -61
  359. package/dist/local/store/key-value/adapter.js.map +1 -1
  360. package/dist/local/store/key-value/backend-conformance.d.ts.map +1 -1
  361. package/dist/local/store/key-value/backend-conformance.js +74 -0
  362. package/dist/local/store/key-value/backend-conformance.js.map +1 -1
  363. package/dist/local/store/key-value/batch.d.ts +2 -0
  364. package/dist/local/store/key-value/batch.d.ts.map +1 -1
  365. package/dist/local/store/key-value/batch.js +26 -0
  366. package/dist/local/store/key-value/batch.js.map +1 -1
  367. package/dist/local/store/key-value/receive-work.d.ts +55 -0
  368. package/dist/local/store/key-value/receive-work.d.ts.map +1 -0
  369. package/dist/local/store/key-value/receive-work.js +162 -0
  370. package/dist/local/store/key-value/receive-work.js.map +1 -0
  371. package/dist/local/store/key-value/send-log.d.ts +61 -0
  372. package/dist/local/store/key-value/send-log.d.ts.map +1 -0
  373. package/dist/local/store/key-value/send-log.js +430 -0
  374. package/dist/local/store/key-value/send-log.js.map +1 -0
  375. package/dist/local/store/key-value/sender-key-handoff.d.ts +68 -0
  376. package/dist/local/store/key-value/sender-key-handoff.d.ts.map +1 -0
  377. package/dist/local/store/key-value/sender-key-handoff.js +189 -0
  378. package/dist/local/store/key-value/sender-key-handoff.js.map +1 -0
  379. package/dist/local/store/key-value/storage.d.ts +15 -0
  380. package/dist/local/store/key-value/storage.d.ts.map +1 -1
  381. package/dist/local/store/keyed-index.d.ts +23 -0
  382. package/dist/local/store/keyed-index.d.ts.map +1 -0
  383. package/dist/local/store/keyed-index.js +41 -0
  384. package/dist/local/store/keyed-index.js.map +1 -0
  385. package/dist/local/store/memory/adapter.d.ts +44 -12
  386. package/dist/local/store/memory/adapter.d.ts.map +1 -1
  387. package/dist/local/store/memory/adapter.js +197 -46
  388. package/dist/local/store/memory/adapter.js.map +1 -1
  389. package/dist/local/store/memory/send-log.d.ts +42 -0
  390. package/dist/local/store/memory/send-log.d.ts.map +1 -0
  391. package/dist/local/store/memory/send-log.js +190 -0
  392. package/dist/local/store/memory/send-log.js.map +1 -0
  393. package/dist/local/store/node/adapter.d.ts.map +1 -1
  394. package/dist/local/store/node/adapter.js +8 -6
  395. package/dist/local/store/node/adapter.js.map +1 -1
  396. package/dist/local/store/react-native/adapter.d.ts.map +1 -1
  397. package/dist/local/store/react-native/adapter.js +12 -8
  398. package/dist/local/store/react-native/adapter.js.map +1 -1
  399. package/dist/local/store/receive-work.d.ts +87 -0
  400. package/dist/local/store/receive-work.d.ts.map +1 -0
  401. package/dist/local/store/receive-work.js +204 -0
  402. package/dist/local/store/receive-work.js.map +1 -0
  403. package/dist/local/store/received-content.d.ts +3 -3
  404. package/dist/local/store/received-content.d.ts.map +1 -1
  405. package/dist/local/store/received-content.js +2 -11
  406. package/dist/local/store/received-content.js.map +1 -1
  407. package/dist/local/store/reliability.d.ts +411 -14
  408. package/dist/local/store/reliability.d.ts.map +1 -1
  409. package/dist/local/store/reliability.js +532 -58
  410. package/dist/local/store/reliability.js.map +1 -1
  411. package/dist/local/store/send-log-order.d.ts +15 -0
  412. package/dist/local/store/send-log-order.d.ts.map +1 -0
  413. package/dist/local/store/send-log-order.js +24 -0
  414. package/dist/local/store/send-log-order.js.map +1 -0
  415. package/dist/local/store/sender-key-handoff-index.d.ts +38 -0
  416. package/dist/local/store/sender-key-handoff-index.d.ts.map +1 -0
  417. package/dist/local/store/sender-key-handoff-index.js +101 -0
  418. package/dist/local/store/sender-key-handoff-index.js.map +1 -0
  419. package/dist/local/store/sender-key-handoff-table.d.ts +29 -0
  420. package/dist/local/store/sender-key-handoff-table.d.ts.map +1 -0
  421. package/dist/local/store/sender-key-handoff-table.js +97 -0
  422. package/dist/local/store/sender-key-handoff-table.js.map +1 -0
  423. package/dist/local/store/sqlite/encryption.d.ts +8 -1
  424. package/dist/local/store/sqlite/encryption.d.ts.map +1 -1
  425. package/dist/local/store/sqlite/encryption.js +9 -0
  426. package/dist/local/store/sqlite/encryption.js.map +1 -1
  427. package/dist/local/store/sqlite/key-storage/index.d.ts +25 -4
  428. package/dist/local/store/sqlite/key-storage/index.d.ts.map +1 -1
  429. package/dist/local/store/sqlite/key-storage/index.js +68 -7
  430. package/dist/local/store/sqlite/key-storage/index.js.map +1 -1
  431. package/dist/local/store/sqlite/key-storage/message-records.d.ts +16 -4
  432. package/dist/local/store/sqlite/key-storage/message-records.d.ts.map +1 -1
  433. package/dist/local/store/sqlite/key-storage/message-records.js +49 -6
  434. package/dist/local/store/sqlite/key-storage/message-records.js.map +1 -1
  435. package/dist/local/store/sqlite/key-storage/metadata.d.ts +8 -7
  436. package/dist/local/store/sqlite/key-storage/metadata.d.ts.map +1 -1
  437. package/dist/local/store/sqlite/key-storage/metadata.js +17 -15
  438. package/dist/local/store/sqlite/key-storage/metadata.js.map +1 -1
  439. package/dist/local/store/sqlite/key-storage/receive-work.d.ts +27 -0
  440. package/dist/local/store/sqlite/key-storage/receive-work.d.ts.map +1 -0
  441. package/dist/local/store/sqlite/key-storage/receive-work.js +98 -0
  442. package/dist/local/store/sqlite/key-storage/receive-work.js.map +1 -0
  443. package/dist/local/store/sqlite/key-storage/send-log.d.ts +27 -0
  444. package/dist/local/store/sqlite/key-storage/send-log.d.ts.map +1 -0
  445. package/dist/local/store/sqlite/key-storage/send-log.js +178 -0
  446. package/dist/local/store/sqlite/key-storage/send-log.js.map +1 -0
  447. package/dist/local/store/sqlite/key-storage/sender-key-handoff.d.ts +27 -0
  448. package/dist/local/store/sqlite/key-storage/sender-key-handoff.d.ts.map +1 -0
  449. package/dist/local/store/sqlite/key-storage/sender-key-handoff.js +75 -0
  450. package/dist/local/store/sqlite/key-storage/sender-key-handoff.js.map +1 -0
  451. package/dist/local/store/sqlite/key-storage/session-trust.d.ts +2 -2
  452. package/dist/local/store/sqlite/key-storage/session-trust.js +5 -5
  453. package/dist/local/store/sqlite/key-storage/session-trust.js.map +1 -1
  454. package/dist/local/store/sqlite/migrations.d.ts.map +1 -1
  455. package/dist/local/store/sqlite/migrations.js +101 -0
  456. package/dist/local/store/sqlite/migrations.js.map +1 -1
  457. package/dist/local/store/sqlite/models/index.d.ts +2 -1
  458. package/dist/local/store/sqlite/models/index.d.ts.map +1 -1
  459. package/dist/local/store/sqlite/models/index.js +5 -1
  460. package/dist/local/store/sqlite/models/index.js.map +1 -1
  461. package/dist/local/store/sqlite/models/message-record.d.ts +15 -0
  462. package/dist/local/store/sqlite/models/message-record.d.ts.map +1 -1
  463. package/dist/local/store/sqlite/models/message-record.js +24 -0
  464. package/dist/local/store/sqlite/models/message-record.js.map +1 -1
  465. package/dist/local/store/sqlite/models/send-log.d.ts +51 -0
  466. package/dist/local/store/sqlite/models/send-log.d.ts.map +1 -0
  467. package/dist/local/store/sqlite/models/send-log.js +206 -0
  468. package/dist/local/store/sqlite/models/send-log.js.map +1 -0
  469. package/dist/local/store/sqlite/open-store.d.ts +9 -1
  470. package/dist/local/store/sqlite/open-store.d.ts.map +1 -1
  471. package/dist/local/store/sqlite/open-store.js +20 -1
  472. package/dist/local/store/sqlite/open-store.js.map +1 -1
  473. package/dist/local/store/sqlite/schema.d.ts +34 -1
  474. package/dist/local/store/sqlite/schema.d.ts.map +1 -1
  475. package/dist/local/store/sqlite/schema.js +14 -0
  476. package/dist/local/store/sqlite/schema.js.map +1 -1
  477. package/dist/local/store/sqlite/store.d.ts +61 -11
  478. package/dist/local/store/sqlite/store.d.ts.map +1 -1
  479. package/dist/local/store/sqlite/store.js +191 -27
  480. package/dist/local/store/sqlite/store.js.map +1 -1
  481. package/dist/local/store/web/adapter.d.ts +76 -8
  482. package/dist/local/store/web/adapter.d.ts.map +1 -1
  483. package/dist/local/store/web/adapter.js +579 -127
  484. package/dist/local/store/web/adapter.js.map +1 -1
  485. package/dist/local/store/web/receive-work.d.ts +57 -0
  486. package/dist/local/store/web/receive-work.d.ts.map +1 -0
  487. package/dist/local/store/web/receive-work.js +99 -0
  488. package/dist/local/store/web/receive-work.js.map +1 -0
  489. package/dist/local/store/web/send-log.d.ts +92 -0
  490. package/dist/local/store/web/send-log.d.ts.map +1 -0
  491. package/dist/local/store/web/send-log.js +267 -0
  492. package/dist/local/store/web/send-log.js.map +1 -0
  493. package/dist/local/store/web/sender-key-handoff.d.ts +81 -0
  494. package/dist/local/store/web/sender-key-handoff.d.ts.map +1 -0
  495. package/dist/local/store/web/sender-key-handoff.js +156 -0
  496. package/dist/local/store/web/sender-key-handoff.js.map +1 -0
  497. package/dist/local/store/web-sqlite/adapter.d.ts +2 -0
  498. package/dist/local/store/web-sqlite/adapter.d.ts.map +1 -1
  499. package/dist/local/store/web-sqlite/adapter.js +12 -6
  500. package/dist/local/store/web-sqlite/adapter.js.map +1 -1
  501. package/dist/local/vault/custody.d.ts +8 -0
  502. package/dist/local/vault/custody.d.ts.map +1 -0
  503. package/dist/local/vault/custody.js +9 -0
  504. package/dist/local/vault/custody.js.map +1 -0
  505. package/dist/local/vault/electron-safe-storage.d.ts +3 -1
  506. package/dist/local/vault/electron-safe-storage.d.ts.map +1 -1
  507. package/dist/local/vault/electron-safe-storage.js +2 -0
  508. package/dist/local/vault/electron-safe-storage.js.map +1 -1
  509. package/dist/local/vault/expo-secure-store.d.ts +3 -1
  510. package/dist/local/vault/expo-secure-store.d.ts.map +1 -1
  511. package/dist/local/vault/expo-secure-store.js +2 -0
  512. package/dist/local/vault/expo-secure-store.js.map +1 -1
  513. package/dist/local/vault/indexed-db.d.ts +3 -1
  514. package/dist/local/vault/indexed-db.d.ts.map +1 -1
  515. package/dist/local/vault/indexed-db.js +2 -0
  516. package/dist/local/vault/indexed-db.js.map +1 -1
  517. package/dist/local/vault/react-native-keychain.d.ts +3 -1
  518. package/dist/local/vault/react-native-keychain.d.ts.map +1 -1
  519. package/dist/local/vault/react-native-keychain.js +2 -0
  520. package/dist/local/vault/react-native-keychain.js.map +1 -1
  521. package/dist/remote/relay/device-set.d.ts +94 -0
  522. package/dist/remote/relay/device-set.d.ts.map +1 -0
  523. package/dist/remote/relay/device-set.js +156 -0
  524. package/dist/remote/relay/device-set.js.map +1 -0
  525. package/dist/remote/relay/types.d.ts +104 -110
  526. package/dist/remote/relay/types.d.ts.map +1 -1
  527. package/dist/safety/core.d.ts +15 -6
  528. package/dist/safety/core.d.ts.map +1 -1
  529. package/dist/safety/core.js +41 -27
  530. package/dist/safety/core.js.map +1 -1
  531. package/dist/safety/index.d.ts +2 -1
  532. package/dist/safety/index.d.ts.map +1 -1
  533. package/dist/safety/index.js +12 -18
  534. package/dist/safety/index.js.map +1 -1
  535. package/dist/types/api.d.ts +707 -62
  536. package/dist/types/api.d.ts.map +1 -1
  537. package/dist/types/errors.d.ts +14 -33
  538. package/dist/types/errors.d.ts.map +1 -1
  539. package/dist/types/errors.js +14 -24
  540. package/dist/types/errors.js.map +1 -1
  541. package/dist/types/messages.d.ts +2 -2
  542. package/dist/types/messages.js +1 -1
  543. package/dist/types/protocol-config.d.ts +175 -42
  544. package/dist/types/protocol-config.d.ts.map +1 -1
  545. package/dist/types/protocol-config.js +19 -38
  546. package/dist/types/protocol-config.js.map +1 -1
  547. package/dist/types/protocol-constants.d.ts +6 -6
  548. package/dist/types/protocol-constants.js +6 -6
  549. package/dist/types/session.d.ts +7 -7
  550. package/dist/types/session.d.ts.map +1 -1
  551. package/dist/types/session.js +39 -21
  552. package/dist/types/session.js.map +1 -1
  553. package/dist/username/link.d.ts +2 -2
  554. package/dist/username/link.js +2 -2
  555. package/dist/utils/origin-lock.d.ts +45 -0
  556. package/dist/utils/origin-lock.d.ts.map +1 -0
  557. package/dist/utils/origin-lock.js +80 -0
  558. package/dist/utils/origin-lock.js.map +1 -0
  559. package/dist/utils/retry.d.ts +2 -0
  560. package/dist/utils/retry.d.ts.map +1 -1
  561. package/dist/utils/retry.js +7 -0
  562. package/dist/utils/retry.js.map +1 -1
  563. package/docs/ASSURANCE.md +6 -6
  564. package/docs/CLIENT_COMPOSITION.md +2 -2
  565. package/docs/DEVIATIONS.md +677 -182
  566. package/docs/E2EE.md +1 -1
  567. package/docs/ERROR_HANDLING.md +235 -2
  568. package/docs/GETTING_STARTED.md +7 -4
  569. package/docs/INTERFACES.md +1 -1
  570. package/docs/PACKAGE_SURFACE.md +6 -5
  571. package/docs/PROTOCOL_POLICY.md +102 -22
  572. package/docs/RECIPES.md +3 -15
  573. package/docs/SECURITY.md +90 -5
  574. package/keys/README.md +3 -3
  575. package/local/store/README.md +78 -14
  576. package/local/store/key-value/README.md +14 -3
  577. package/local/store/node/README.md +8 -3
  578. package/local/store/web/README.md +9 -0
  579. package/local/store/web-sqlite/README.md +14 -2
  580. package/local/vault/README.md +21 -0
  581. package/package.json +1 -6
  582. package/remote/README.md +0 -1
  583. package/remote/relay/README.md +2 -2
  584. package/dist/device/provisioning.d.ts +0 -242
  585. package/dist/device/provisioning.d.ts.map +0 -1
  586. package/dist/device/provisioning.js +0 -421
  587. package/dist/device/provisioning.js.map +0 -1
  588. package/dist/internal/protocol/x3dh/index.d.ts +0 -15
  589. package/dist/internal/protocol/x3dh/index.d.ts.map +0 -1
  590. package/dist/internal/protocol/x3dh/index.js +0 -13
  591. package/dist/internal/protocol/x3dh/index.js.map +0 -1
  592. package/dist/internal/protocol/x3dh/x3dh.d.ts +0 -131
  593. package/dist/internal/protocol/x3dh/x3dh.d.ts.map +0 -1
  594. package/dist/internal/protocol/x3dh/x3dh.js +0 -261
  595. package/dist/internal/protocol/x3dh/x3dh.js.map +0 -1
@@ -0,0 +1,150 @@
1
+ /**
2
+ * The delivery error of a failed incoming envelope on the requester device.
3
+ *
4
+ * A failed decrypt that asks the sender for a resend stores a request
5
+ * record and acknowledges the failed envelope. The record decides when the
6
+ * application learns that the content did not come: `onDeliveryError` runs
7
+ * for the record, and `onDeliveryRecovered` runs when the content comes
8
+ * back after the error. Each hook runs at least once. The record is marked
9
+ * only after the hook returns, as `reportDeliveryError` and
10
+ * `reportDeliveryRecovered` tell. The content hint of the failed envelope
11
+ * sets the time of the error:
12
+ *
13
+ * - `Default`, or no hint: at the first failure.
14
+ * - `Resendable`: `RETRY_PLACEHOLDER_DEADLINE_MS` after the first failure.
15
+ * - `Implicit`: never. The receive paths store no record for it.
16
+ *
17
+ * A rate limit that refused the request, and the end of the request, make
18
+ * the error due at once. The error deletes nothing, and the attempts of the
19
+ * request continue after it. Each function runs under the processed lock
20
+ * of the failed envelope, as each write of its record does.
21
+ *
22
+ * A failure that no resend can repair stores no request record. The
23
+ * application hears about it through `onDecryptionError`, and the receive
24
+ * path acknowledges the envelope. `receiveRefusal` decides this for both
25
+ * receive paths.
26
+ */
27
+ import { getRetryRequest, type StoredRetryRequest } from '../local/store/reliability.js';
28
+ import { type DeliveryErrorCause, type SignalProtocolClientHooks } from './event-hooks.js';
29
+ type DeliveryErrorStore = Parameters<typeof getRetryRequest>[0];
30
+ /**
31
+ * When the delivery error of a request record is due, and why. Null when
32
+ * the record reports no error: the error ran, the failed envelope has the
33
+ * Implicit hint, or the record has no receive time or sender.
34
+ *
35
+ * @param record - The stored request record.
36
+ * @returns The time when the error is due, 0 for at once, and its cause.
37
+ */
38
+ export declare function deliveryErrorDue(record: StoredRetryRequest): {
39
+ readonly at: number;
40
+ readonly cause: DeliveryErrorCause;
41
+ } | null;
42
+ /**
43
+ * Run `onDeliveryError` for one failed envelope when its error is due, and
44
+ * then store the record as shown. A failed envelope whose content the
45
+ * application has gets no error.
46
+ *
47
+ * The hook is called directly, not through `callHook`, so a hook that
48
+ * throws, and the RelayWorkStopped of a stop, propagate and leave the record
49
+ * not shown. The rule is: mark only after the hook returns, and keep the
50
+ * caller alive. The scheduler logs the error, keeps the next attempt time
51
+ * of the record, and goes on with the next record. The receive path does
52
+ * not acknowledge the failed envelope. The next scheduler pass, at the next
53
+ * start or the next armed time, or the redelivery runs the hook again.
54
+ *
55
+ * @param storage - The local store that keeps the request records.
56
+ * @param hooks - The client hooks.
57
+ * @param failedEnvelopeId - The failed envelope of the record.
58
+ * @param now - The current time.
59
+ * @returns The time when the error of the record is due later, or
60
+ * Infinity when the record needs no later check.
61
+ */
62
+ export declare function reportDeliveryError(storage: DeliveryErrorStore, hooks: SignalProtocolClientHooks | undefined, failedEnvelopeId: string, now?: number): Promise<number>;
63
+ /**
64
+ * Run `onDeliveryRecovered` for a failed envelope whose content came back,
65
+ * when `onDeliveryError` ran for it, and then store the record as
66
+ * recovered. It does nothing until the application finished the content:
67
+ * the receive record of the resend completed and marked the failed envelope
68
+ * `completed`. A fulfilled envelope only stops the retry scheduler. It
69
+ * does nothing when the record is stored as recovered. The receive queue
70
+ * runs it after each completion of a resend. Each receive in the family,
71
+ * and each scheduler pass, runs it again for a record that the hook did not
72
+ * mark.
73
+ *
74
+ * The hook is called directly, not through `callHook`, so a hook that
75
+ * throws, and the RelayWorkStopped of a stop, propagate and leave the record
76
+ * not recovered. The rule is: mark only after the hook returns. The record
77
+ * stays until its retention ends, so the hook runs at least once.
78
+ *
79
+ * @param storage - The local store that keeps the request records.
80
+ * @param hooks - The client hooks.
81
+ * @param failedEnvelopeId - The failed envelope of the record.
82
+ * @param now - The current time.
83
+ */
84
+ export declare function reportDeliveryRecovered(storage: DeliveryErrorStore, hooks: SignalProtocolClientHooks | undefined, failedEnvelopeId: string, now?: number): Promise<void>;
85
+ /**
86
+ * A receive failure that no resend can repair. The sender would send the
87
+ * same content again, and it would fail again.
88
+ *
89
+ * - `authorization`: the verified group state refuses the sender.
90
+ * - `untrusted-identity`: the local device does not trust the identity
91
+ * of the sender.
92
+ * - `malformed`: the envelope does not decode, or its message does not
93
+ * parse.
94
+ */
95
+ export type ReceiveRefusal = 'authorization' | 'untrusted-identity' | 'malformed';
96
+ /**
97
+ * The refusal of a failed decrypt, or null when a resend can repair the
98
+ * failure. The relay subscription route and `processIncomingEnvelope`
99
+ * both decide with this function.
100
+ *
101
+ * @param error - The error of the failed decrypt.
102
+ */
103
+ export declare function receiveRefusal(error: unknown): ReceiveRefusal | null;
104
+ /**
105
+ * The bytes of the ciphertext of a delivered envelope.
106
+ *
107
+ * @param ciphertext - The ciphertext as the envelope holds it.
108
+ * @throws EncryptionError INVALID_CIPHERTEXT when the ciphertext is not
109
+ * base64, which makes the envelope malformed.
110
+ */
111
+ export declare function envelopeCiphertextBytes(ciphertext: string | Uint8Array): Uint8Array;
112
+ /**
113
+ * Report a refused envelope to the application, and store the envelope
114
+ * as processed. A redelivery on either receive path is then dropped with
115
+ * no decrypt, so the application hears about the refusal once. The
116
+ * caller acknowledges the envelope after this. The hook runs before the
117
+ * write, so a stop between the two runs the hook again at the
118
+ * redelivery. Content of a group that the user blocked is dropped with
119
+ * no report, as Signal drops it.
120
+ *
121
+ * @param storage - The local store that keeps the processed records.
122
+ * @param hooks - The client hooks.
123
+ * @param envelope - The refused envelope. For a sealed envelope, its
124
+ * sender is the unsealed sender.
125
+ * @param error - The error of the failed decrypt.
126
+ * @param fingerprint - The fingerprint of the delivered envelope.
127
+ * @param reported - True when the decrypt already ran
128
+ * `onDecryptionError` for the error.
129
+ */
130
+ export declare function reportReceiveRefusal(storage: DeliveryErrorStore, hooks: SignalProtocolClientHooks | undefined, envelope: {
131
+ readonly id?: string;
132
+ readonly senderUserId: string;
133
+ readonly senderDeviceId: number;
134
+ }, error: Error, fingerprint: string | undefined, reported?: boolean): Promise<void>;
135
+ /**
136
+ * Report a refusal to the application with `onDecryptionError`, and write
137
+ * nothing. The receive queue writes the denied record of committed
138
+ * content after this, in the completion of the receive record. Content of
139
+ * a group that the user blocked has no report.
140
+ *
141
+ * @param hooks - The client hooks.
142
+ * @param sender - The sender of the refused content.
143
+ * @param error - The refusal.
144
+ */
145
+ export declare function reportReceiveDenial(hooks: SignalProtocolClientHooks | undefined, sender: {
146
+ readonly senderUserId: string;
147
+ readonly senderDeviceId: number;
148
+ }, error: Error): Promise<void>;
149
+ export {};
150
+ //# sourceMappingURL=delivery-error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"delivery-error.d.ts","sourceRoot":"","sources":["../../client/delivery-error.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAGH,OAAO,EAEL,eAAe,EAGf,KAAK,kBAAkB,EACxB,MAAM,4BAA4B,CAAC;AAKpC,OAAO,EAEL,KAAK,kBAAkB,EAEvB,KAAK,yBAAyB,EAC/B,MAAM,eAAe,CAAC;AAGvB,KAAK,kBAAkB,GAAG,UAAU,CAAC,OAAO,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC;AAEhE;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,kBAAkB,GACzB;IAAE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,kBAAkB,CAAA;CAAE,GAAG,IAAI,CAoBpE;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAsB,mBAAmB,CACvC,OAAO,EAAE,kBAAkB,EAC3B,KAAK,EAAE,yBAAyB,GAAG,SAAS,EAC5C,gBAAgB,EAAE,MAAM,EACxB,GAAG,SAAa,GACf,OAAO,CAAC,MAAM,CAAC,CAYjB;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAsB,uBAAuB,CAC3C,OAAO,EAAE,kBAAkB,EAC3B,KAAK,EAAE,yBAAyB,GAAG,SAAS,EAC5C,gBAAgB,EAAE,MAAM,EACxB,GAAG,SAAa,GACf,OAAO,CAAC,IAAI,CAAC,CAWf;AAmBD;;;;;;;;;GASG;AACH,MAAM,MAAM,cAAc,GAAG,eAAe,GAAG,oBAAoB,GAAG,WAAW,CAAC;AAElF;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,cAAc,GAAG,IAAI,CAMpE;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CAAC,UAAU,EAAE,MAAM,GAAG,UAAU,GAAG,UAAU,CAWnF;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAsB,oBAAoB,CACxC,OAAO,EAAE,kBAAkB,EAC3B,KAAK,EAAE,yBAAyB,GAAG,SAAS,EAC5C,QAAQ,EAAE;IACR,QAAQ,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;CACjC,EACD,KAAK,EAAE,KAAK,EACZ,WAAW,EAAE,MAAM,GAAG,SAAS,EAC/B,QAAQ,UAAQ,GACf,OAAO,CAAC,IAAI,CAAC,CAGf;AAED;;;;;;;;;GASG;AACH,wBAAsB,mBAAmB,CACvC,KAAK,EAAE,yBAAyB,GAAG,SAAS,EAC5C,MAAM,EAAE;IAAE,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAA;CAAE,EAC1E,KAAK,EAAE,KAAK,GACX,OAAO,CAAC,IAAI,CAAC,CAIf"}
@@ -0,0 +1,226 @@
1
+ /**
2
+ * The delivery error of a failed incoming envelope on the requester device.
3
+ *
4
+ * A failed decrypt that asks the sender for a resend stores a request
5
+ * record and acknowledges the failed envelope. The record decides when the
6
+ * application learns that the content did not come: `onDeliveryError` runs
7
+ * for the record, and `onDeliveryRecovered` runs when the content comes
8
+ * back after the error. Each hook runs at least once. The record is marked
9
+ * only after the hook returns, as `reportDeliveryError` and
10
+ * `reportDeliveryRecovered` tell. The content hint of the failed envelope
11
+ * sets the time of the error:
12
+ *
13
+ * - `Default`, or no hint: at the first failure.
14
+ * - `Resendable`: `RETRY_PLACEHOLDER_DEADLINE_MS` after the first failure.
15
+ * - `Implicit`: never. The receive paths store no record for it.
16
+ *
17
+ * A rate limit that refused the request, and the end of the request, make
18
+ * the error due at once. The error deletes nothing, and the attempts of the
19
+ * request continue after it. Each function runs under the processed lock
20
+ * of the failed envelope, as each write of its record does.
21
+ *
22
+ * A failure that no resend can repair stores no request record. The
23
+ * application hears about it through `onDecryptionError`, and the receive
24
+ * path acknowledges the envelope. `receiveRefusal` decides this for both
25
+ * receive paths.
26
+ */
27
+ import { base64ToBytes } from '../internal/crypto/index.js';
28
+ import { getProcessedEnvelope, getRetryRequest, storeProcessedEnvelope, updateRetryRequest, } from '../local/store/reliability.js';
29
+ import { EncryptionError, EncryptionErrorCode } from '../types/errors.js';
30
+ import { ContentHint } from '../types/messages.js';
31
+ import { RETRY_PLACEHOLDER_DEADLINE_MS } from './constants.js';
32
+ import { callHook, } from './event-hooks.js';
33
+ import { GroupReceiveRefusedError } from './group-receive-authorization.js';
34
+ /**
35
+ * When the delivery error of a request record is due, and why. Null when
36
+ * the record reports no error: the error ran, the failed envelope has the
37
+ * Implicit hint, or the record has no receive time or sender.
38
+ *
39
+ * @param record - The stored request record.
40
+ * @returns The time when the error is due, 0 for at once, and its cause.
41
+ */
42
+ export function deliveryErrorDue(record) {
43
+ if (record.errorShown ||
44
+ record.receivedAt === undefined ||
45
+ record.failedSender === undefined ||
46
+ record.contentHint === ContentHint.Implicit) {
47
+ return null;
48
+ }
49
+ if (record.terminal?.class === 'abuse-allowance-exhausted' ||
50
+ record.lastFailureClass === 'rate-refusal') {
51
+ return { at: 0, cause: 'rate-limit' };
52
+ }
53
+ if (record.terminal)
54
+ return { at: 0, cause: 'request-ended' };
55
+ if (record.contentHint === ContentHint.Resendable) {
56
+ return { at: record.receivedAt + RETRY_PLACEHOLDER_DEADLINE_MS, cause: 'deadline' };
57
+ }
58
+ return { at: 0, cause: 'content-hint' };
59
+ }
60
+ /**
61
+ * Run `onDeliveryError` for one failed envelope when its error is due, and
62
+ * then store the record as shown. A failed envelope whose content the
63
+ * application has gets no error.
64
+ *
65
+ * The hook is called directly, not through `callHook`, so a hook that
66
+ * throws, and the RelayWorkStopped of a stop, propagate and leave the record
67
+ * not shown. The rule is: mark only after the hook returns, and keep the
68
+ * caller alive. The scheduler logs the error, keeps the next attempt time
69
+ * of the record, and goes on with the next record. The receive path does
70
+ * not acknowledge the failed envelope. The next scheduler pass, at the next
71
+ * start or the next armed time, or the redelivery runs the hook again.
72
+ *
73
+ * @param storage - The local store that keeps the request records.
74
+ * @param hooks - The client hooks.
75
+ * @param failedEnvelopeId - The failed envelope of the record.
76
+ * @param now - The current time.
77
+ * @returns The time when the error of the record is due later, or
78
+ * Infinity when the record needs no later check.
79
+ */
80
+ export async function reportDeliveryError(storage, hooks, failedEnvelopeId, now = Date.now()) {
81
+ const record = await getRetryRequest(storage, failedEnvelopeId, now);
82
+ const due = record ? deliveryErrorDue(record) : null;
83
+ if (!record || !due)
84
+ return Infinity;
85
+ if ((await getProcessedEnvelope(storage, failedEnvelopeId, now))?.fulfilled)
86
+ return Infinity;
87
+ if (due.at > now)
88
+ return due.at;
89
+ const hook = hooks?.onDeliveryError;
90
+ if (hook)
91
+ await hook({ ...deliveryEvent(record), cause: due.cause });
92
+ await updateRetryRequest(storage, failedEnvelopeId, record.retryId, record.attempt, {
93
+ errorShown: true,
94
+ });
95
+ return Infinity;
96
+ }
97
+ /**
98
+ * Run `onDeliveryRecovered` for a failed envelope whose content came back,
99
+ * when `onDeliveryError` ran for it, and then store the record as
100
+ * recovered. It does nothing until the application finished the content:
101
+ * the receive record of the resend completed and marked the failed envelope
102
+ * `completed`. A fulfilled envelope only stops the retry scheduler. It
103
+ * does nothing when the record is stored as recovered. The receive queue
104
+ * runs it after each completion of a resend. Each receive in the family,
105
+ * and each scheduler pass, runs it again for a record that the hook did not
106
+ * mark.
107
+ *
108
+ * The hook is called directly, not through `callHook`, so a hook that
109
+ * throws, and the RelayWorkStopped of a stop, propagate and leave the record
110
+ * not recovered. The rule is: mark only after the hook returns. The record
111
+ * stays until its retention ends, so the hook runs at least once.
112
+ *
113
+ * @param storage - The local store that keeps the request records.
114
+ * @param hooks - The client hooks.
115
+ * @param failedEnvelopeId - The failed envelope of the record.
116
+ * @param now - The current time.
117
+ */
118
+ export async function reportDeliveryRecovered(storage, hooks, failedEnvelopeId, now = Date.now()) {
119
+ const record = await getRetryRequest(storage, failedEnvelopeId, now);
120
+ if (!record?.errorShown || record.recoveredEmitted)
121
+ return;
122
+ const event = deliveryEvent(record);
123
+ if (!event)
124
+ return;
125
+ if (!(await getProcessedEnvelope(storage, failedEnvelopeId, now))?.completed)
126
+ return;
127
+ const hook = hooks?.onDeliveryRecovered;
128
+ if (hook)
129
+ await hook(event);
130
+ await updateRetryRequest(storage, failedEnvelopeId, record.retryId, record.attempt, {
131
+ recoveredEmitted: true,
132
+ });
133
+ }
134
+ /** The event fields of a record, or undefined when it has no receive time or sender. */
135
+ function deliveryEvent(record) {
136
+ const { receivedAt, failedSender } = record;
137
+ if (receivedAt === undefined || failedSender === undefined)
138
+ return undefined;
139
+ return {
140
+ failedEnvelopeId: record.failedEnvelopeId,
141
+ ...(record.failedClientMessageId !== undefined && {
142
+ clientMessageId: record.failedClientMessageId,
143
+ }),
144
+ ...(record.groupId !== undefined && { groupId: record.groupId }),
145
+ senderUserId: failedSender.userId,
146
+ senderDeviceId: failedSender.deviceId,
147
+ groupMessage: record.groupMessage === true,
148
+ receivedAt,
149
+ };
150
+ }
151
+ /**
152
+ * The refusal of a failed decrypt, or null when a resend can repair the
153
+ * failure. The relay subscription route and `processIncomingEnvelope`
154
+ * both decide with this function.
155
+ *
156
+ * @param error - The error of the failed decrypt.
157
+ */
158
+ export function receiveRefusal(error) {
159
+ if (error instanceof GroupReceiveRefusedError)
160
+ return 'authorization';
161
+ if (!(error instanceof EncryptionError))
162
+ return null;
163
+ if (error.code === EncryptionErrorCode.UNTRUSTED_IDENTITY)
164
+ return 'untrusted-identity';
165
+ if (error.code === EncryptionErrorCode.INVALID_CIPHERTEXT)
166
+ return 'malformed';
167
+ return null;
168
+ }
169
+ /**
170
+ * The bytes of the ciphertext of a delivered envelope.
171
+ *
172
+ * @param ciphertext - The ciphertext as the envelope holds it.
173
+ * @throws EncryptionError INVALID_CIPHERTEXT when the ciphertext is not
174
+ * base64, which makes the envelope malformed.
175
+ */
176
+ export function envelopeCiphertextBytes(ciphertext) {
177
+ if (typeof ciphertext !== 'string')
178
+ return ciphertext;
179
+ try {
180
+ return base64ToBytes(ciphertext);
181
+ }
182
+ catch (error) {
183
+ throw new EncryptionError('The envelope ciphertext is not base64', EncryptionErrorCode.INVALID_CIPHERTEXT, { originalError: error });
184
+ }
185
+ }
186
+ /**
187
+ * Report a refused envelope to the application, and store the envelope
188
+ * as processed. A redelivery on either receive path is then dropped with
189
+ * no decrypt, so the application hears about the refusal once. The
190
+ * caller acknowledges the envelope after this. The hook runs before the
191
+ * write, so a stop between the two runs the hook again at the
192
+ * redelivery. Content of a group that the user blocked is dropped with
193
+ * no report, as Signal drops it.
194
+ *
195
+ * @param storage - The local store that keeps the processed records.
196
+ * @param hooks - The client hooks.
197
+ * @param envelope - The refused envelope. For a sealed envelope, its
198
+ * sender is the unsealed sender.
199
+ * @param error - The error of the failed decrypt.
200
+ * @param fingerprint - The fingerprint of the delivered envelope.
201
+ * @param reported - True when the decrypt already ran
202
+ * `onDecryptionError` for the error.
203
+ */
204
+ export async function reportReceiveRefusal(storage, hooks, envelope, error, fingerprint, reported = false) {
205
+ if (!reported)
206
+ await reportReceiveDenial(hooks, envelope, error);
207
+ if (envelope.id)
208
+ await storeProcessedEnvelope(storage, envelope.id, Date.now(), fingerprint);
209
+ }
210
+ /**
211
+ * Report a refusal to the application with `onDecryptionError`, and write
212
+ * nothing. The receive queue writes the denied record of committed
213
+ * content after this, in the completion of the receive record. Content of
214
+ * a group that the user blocked has no report.
215
+ *
216
+ * @param hooks - The client hooks.
217
+ * @param sender - The sender of the refused content.
218
+ * @param error - The refusal.
219
+ */
220
+ export async function reportReceiveDenial(hooks, sender, error) {
221
+ if (error instanceof GroupReceiveRefusedError && error.reason === 'blocked')
222
+ return;
223
+ const sessionId = `${sender.senderUserId}:${sender.senderDeviceId}`;
224
+ await callHook(hooks, 'onDecryptionError', sessionId, error);
225
+ }
226
+ //# sourceMappingURL=delivery-error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"delivery-error.js","sourceRoot":"","sources":["../../client/delivery-error.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EACL,oBAAoB,EACpB,eAAe,EACf,sBAAsB,EACtB,kBAAkB,GAEnB,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACvE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,6BAA6B,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,EACL,QAAQ,GAIT,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAIzE;;;;;;;GAOG;AACH,MAAM,UAAU,gBAAgB,CAC9B,MAA0B;IAE1B,IACE,MAAM,CAAC,UAAU;QACjB,MAAM,CAAC,UAAU,KAAK,SAAS;QAC/B,MAAM,CAAC,YAAY,KAAK,SAAS;QACjC,MAAM,CAAC,WAAW,KAAK,WAAW,CAAC,QAAQ,EAC3C,CAAC;QACD,OAA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AC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,OAA2B,EAC3B,KAA4C,EAC5C,QAIC,EACD,KAAY,EACZ,WAA+B,EAC/B,QAAQ,GAAG,KAAK;IAEhB,IAAI,CAAC,QAAQ;QAAE,MAAM,mBAAmB,CAAC,KAAK,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC;IACjE,IAAI,QAAQ,CAAC,EAAE;QAAE,MAAM,sBAAsB,CAAC,OAAO,EAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC,GAAG,EAAE,EAAE,WAAW,CAAC,CAAC;AAC/F,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACvC,KAA4C,EAC5C,MAA0E,EAC1E,KAAY;IAEZ,IAAI,KAAK,YAAY,wBAAwB,IAAI,KAAK,CAAC,MAAM,KAAK,SAAS;QAAE,OAAO;IACpF,MAAM,SAAS,GAAG,GAAG,MAAM,CAAC,YAAY,IAAI,MAAM,CAAC,cAAc,EAAE,CAAC;IACpE,MAAM,QAAQ,CAAC,KAAK,EAAE,mBAAmB,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC;AAC/D,CAAC"}
@@ -9,19 +9,24 @@
9
9
  * tells that the device decrypted it. A second report of the same source
10
10
  * changes nothing.
11
11
  *
12
- * The status is durable. Each change is written before the client announces
13
- * it, and the write marks it announced, so a replayed receipt announces
14
- * nothing again. A receipt for a send that has not resolved is kept and
15
- * announced when the send resolves.
12
+ * The status is durable. A receipt writes its source before the client
13
+ * announces it. The client marks a source announced only after the
14
+ * `onDelivered` hook returns for it. A hook that throws, a stop during the
15
+ * hook, or a crash leaves the source unannounced, and the next receipt for
16
+ * the message announces it again: a replay of the same receipt, or a receipt
17
+ * of another source or device. So the announcement is at least once, and a
18
+ * replayed receipt announces nothing again only after the hook returned. A
19
+ * receipt for a send that has not resolved is kept and announced when the
20
+ * send resolves.
16
21
  *
17
22
  * A receipt names no message that has no outbox intent, such as a sync copy
18
23
  * or a retry resend. Such a receipt changes nothing.
19
24
  *
20
25
  * @internal
21
26
  */
22
- import type { DeliveredEvent } from './event-hooks.js';
27
+ import type { DeliveredEvent, SignalProtocolClientHooks } from './event-hooks.js';
23
28
  import type { RelayDeliveryReceipt } from './relay-receipt-intake.js';
24
- type DeliveryStatusStore = Pick<SignalProtocolLocalStore, 'getMetadata' | 'setMetadata' | 'deleteMetadata'>;
29
+ type DeliveryStatusStore = Pick<SignalProtocolLocalStore, 'getMetadata' | 'setMetadata' | 'deleteMetadata' | 'deleteSendLogRecipientsByTimestamp'>;
25
30
  export declare class DeliveryStatusTracker {
26
31
  private readonly store;
27
32
  /** The client message IDs that a send of this client is posting, with a count of the sends. */
@@ -37,6 +42,11 @@ export declare class DeliveryStatusTracker {
37
42
  * Apply one E2EE delivery receipt from a recipient device. The receipt
38
43
  * names each message by its client timestamp. Resolves to the events to
39
44
  * announce.
45
+ *
46
+ * The device decrypted each message, so the receipt first deletes the send
47
+ * log row of that device at each timestamp. A Relay receipt deletes no
48
+ * row: a device also acknowledges a copy that it could not decrypt, and
49
+ * the row authorizes the resend of the content to it.
40
50
  */
41
51
  applyE2eeReceipt(recipientId: string, recipientDeviceId: number, timestamps: readonly number[], deliveredAt: number): Promise<DeliveredEvent[]>;
42
52
  /**
@@ -44,6 +54,22 @@ export declare class DeliveryStatusTracker {
44
54
  * ID. Resolves to the events to announce.
45
55
  */
46
56
  release(clientMessageId: string): Promise<DeliveredEvent[]>;
57
+ /**
58
+ * Run the `onDelivered` hook for each event in order, and mark each event
59
+ * announced after its hook returns. The hook is called directly, not
60
+ * through `callHook`, so an error from the hook, or the RelayWorkStopped of
61
+ * a stop, rejects the call. That event and each later event then stay
62
+ * unannounced, and the next receipt for the message announces them again.
63
+ * The caller lets the rejection fail the hand-off of the receipt, so the
64
+ * relay replays it.
65
+ */
66
+ announce(hooks: SignalProtocolClientHooks | undefined, events: readonly DeliveredEvent[]): Promise<void>;
67
+ /**
68
+ * Mark the sources of this event announced. The announced count of a
69
+ * device only moves forward, so a late or repeated mark never announces a
70
+ * source again.
71
+ */
72
+ private markAnnounced;
47
73
  private apply;
48
74
  }
49
75
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"delivery-status.d.ts","sourceRoot":"","sources":["../../client/delivery-status.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AASH,OAAO,KAAK,EAAE,cAAc,EAAkB,MAAM,eAAe,CAAC;AACpE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAEnE,KAAK,mBAAmB,GAAG,IAAI,CAAC,wBAAwB,EAAE,aAAa,GAAG,aAAa,GAAG,gBAAgB,CAAC,CAAC;AAoC5G,qBAAa,qBAAqB;IAIpB,OAAO,CAAC,QAAQ,CAAC,KAAK;IAHlC,+FAA+F;IAC/F,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA6B;IAErD,YAA6B,KAAK,EAAE,mBAAmB,EAAI;IAE3D,kFAAkF;IAC3E,SAAS,CAAC,eAAe,EAAE,MAAM,GAAG,IAAI,CAE9C;IAED,2DAA2D;IACpD,OAAO,CAAC,eAAe,EAAE,MAAM,GAAG,IAAI,CAI5C;IAED,4EAA4E;IAC/D,iBAAiB,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC,CAcvF;IAED;;;;OAIG;IACU,gBAAgB,CAC3B,WAAW,EAAE,MAAM,EACnB,iBAAiB,EAAE,MAAM,EACzB,UAAU,EAAE,SAAS,MAAM,EAAE,EAC7B,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,cAAc,EAAE,CAAC,CAU3B;IAED;;;OAGG;IACU,OAAO,CAAC,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC,CAOvE;YAEa,KAAK;CAuBpB"}
1
+ {"version":3,"file":"delivery-status.d.ts","sourceRoot":"","sources":["../../client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
10
10
  * changes nothing.
11
11
  *
12
- * The status is durable. Each change is written before the client announces
13
- * it, and the write marks it announced, so a replayed receipt announces
14
- * nothing again. A receipt for a send that has not resolved is kept and
15
- * announced when the send resolves.
12
+ * The status is durable. A receipt writes its source before the client
13
+ * announces it. The client marks a source announced only after the
14
+ * `onDelivered` hook returns for it. A hook that throws, a stop during the
15
+ * hook, or a crash leaves the source unannounced, and the next receipt for
16
+ * the message announces it again: a replay of the same receipt, or a receipt
17
+ * of another source or device. So the announcement is at least once, and a
18
+ * replayed receipt announces nothing again only after the hook returned. A
19
+ * receipt for a send that has not resolved is kept and announced when the
20
+ * send resolves.
16
21
  *
17
22
  * A receipt names no message that has no outbox intent, such as a sync copy
18
23
  * or a retry resend. Such a receipt changes nothing.
@@ -25,8 +30,12 @@ function addresses(intent, recipientId) {
25
30
  ? (intent.groupMemberUserIds ?? []).includes(recipientId)
26
31
  : intent.recipientId === recipientId;
27
32
  }
28
- /** Mark each unannounced source of each device announced, and return one event for each. */
29
- function announce(status, intent) {
33
+ /**
34
+ * One event for each source of each device that the client has not
35
+ * announced, in the order of arrival. It changes nothing: `announce` marks
36
+ * an event announced after its hook returns.
37
+ */
38
+ function unannounced(status, intent) {
30
39
  const events = [];
31
40
  for (const [recipientId, devices] of Object.entries(status.devices)) {
32
41
  for (const [deviceId, delivery] of Object.entries(devices)) {
@@ -44,7 +53,6 @@ function announce(status, intent) {
44
53
  ...(intent.kind === 'group' && { groupId: intent.recipientId }),
45
54
  });
46
55
  }
47
- delivery.announced = delivery.sources.length;
48
56
  }
49
57
  }
50
58
  return events;
@@ -80,10 +88,17 @@ export class DeliveryStatusTracker {
80
88
  * Apply one E2EE delivery receipt from a recipient device. The receipt
81
89
  * names each message by its client timestamp. Resolves to the events to
82
90
  * announce.
91
+ *
92
+ * The device decrypted each message, so the receipt first deletes the send
93
+ * log row of that device at each timestamp. A Relay receipt deletes no
94
+ * row: a device also acknowledges a copy that it could not decrypt, and
95
+ * the row authorizes the resend of the content to it.
83
96
  */
84
97
  async applyE2eeReceipt(recipientId, recipientDeviceId, timestamps, deliveredAt) {
98
+ const unique = [...new Set(timestamps)];
99
+ await this.store.deleteSendLogRecipientsByTimestamp({ userId: recipientId, deviceId: recipientDeviceId }, unique);
85
100
  const events = [];
86
- for (const timestamp of new Set(timestamps)) {
101
+ for (const timestamp of unique) {
87
102
  for (const clientMessageId of await getSentClientMessageIds(this.store, timestamp)) {
88
103
  events.push(...(await this.apply(clientMessageId, 'e2ee', recipientId, recipientDeviceId, deliveredAt)));
89
104
  }
@@ -97,7 +112,39 @@ export class DeliveryStatusTracker {
97
112
  async release(clientMessageId) {
98
113
  if (this.sending.has(clientMessageId))
99
114
  return [];
100
- return ((await updateDeliveryStatus(this.store, clientMessageId, (status, intent) => intent.result && !this.sending.has(clientMessageId) ? announce(status, intent) : [])) ?? []);
115
+ return ((await updateDeliveryStatus(this.store, clientMessageId, (status, intent) => intent.result && !this.sending.has(clientMessageId) ? unannounced(status, intent) : [])) ?? []);
116
+ }
117
+ /**
118
+ * Run the `onDelivered` hook for each event in order, and mark each event
119
+ * announced after its hook returns. The hook is called directly, not
120
+ * through `callHook`, so an error from the hook, or the RelayWorkStopped of
121
+ * a stop, rejects the call. That event and each later event then stay
122
+ * unannounced, and the next receipt for the message announces them again.
123
+ * The caller lets the rejection fail the hand-off of the receipt, so the
124
+ * relay replays it.
125
+ */
126
+ async announce(hooks, events) {
127
+ const deliver = hooks?.onDelivered;
128
+ for (const event of events) {
129
+ if (deliver)
130
+ await deliver(event);
131
+ await this.markAnnounced(event);
132
+ }
133
+ }
134
+ /**
135
+ * Mark the sources of this event announced. The announced count of a
136
+ * device only moves forward, so a late or repeated mark never announces a
137
+ * source again.
138
+ */
139
+ async markAnnounced(event) {
140
+ await updateDeliveryStatus(this.store, event.clientMessageId, (status) => {
141
+ const delivery = status.devices[event.recipientId]?.[String(event.recipientDeviceId)];
142
+ if (!delivery)
143
+ return;
144
+ const announced = Math.min(event.sources.length, delivery.sources.length);
145
+ if (announced > delivery.announced)
146
+ delivery.announced = announced;
147
+ });
101
148
  }
102
149
  async apply(clientMessageId, source, recipientId, recipientDeviceId, deliveredAt) {
103
150
  return ((await updateDeliveryStatus(this.store, clientMessageId, (status, intent) => {
@@ -109,12 +156,13 @@ export class DeliveryStatusTracker {
109
156
  deliveredAt,
110
157
  announced: 0,
111
158
  });
112
- if (delivery.sources.includes(source))
113
- return [];
114
- delivery.sources.push(source);
159
+ // A replay of a source adds nothing. It still announces each source
160
+ // whose hook did not return.
161
+ if (!delivery.sources.includes(source))
162
+ delivery.sources.push(source);
115
163
  if (!intent.result || this.sending.has(clientMessageId))
116
164
  return [];
117
- return announce(status, intent);
165
+ return unannounced(status, intent);
118
166
  })) ?? []);
119
167
  }
120
168
  }
@@ -1 +1 @@
1
- {"version":3,"file":"delivery-status.js","sourceRoot":"","sources":["../../client/delivery-status.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAGH,OAAO,EACL,uBAAuB,EACvB,oBAAoB,GAGrB,MAAM,4BAA4B,CAAC;AAMpC,SAAS,SAAS,CAAC,MAAmC,EAAE,WAAmB;IACzE,OAAO,MAAM,CAAC,IAAI,KAAK,OAAO;QAC5B,CAAC,CAAC,CAAC,MAAM,CAAC,kBAAkB,IAAI,EAAE,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC;QACzD,CAAC,CAAC,MAAM,CAAC,WAAW,KAAK,WAAW,CAAC;AACzC,CAAC;AAED,4FAA4F;AAC5F,SAAS,QAAQ,CACf,MAA4B,EAC5B,MAAmC;IAEnC,MAAM,MAAM,GAAqB,EAAE,CAAC;IACpC,KAAK,MAAM,CAAC,WAAW,EAAE,OAAO,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC;QACpE,KAAK,MAAM,CAAC,QAAQ,EAAE,QAAQ,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CA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