@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
@@ -36,6 +36,7 @@
36
36
  * ```
37
37
  */
38
38
  import type { RetryTerminalClass } from '../local/store/reliability.js';
39
+ import type { RelayProtocolError } from './device-set-reconciliation.js';
39
40
  export type { RetryTerminalClass };
40
41
  /**
41
42
  * Decrypted envelope passed to onMessageDecrypted hook
@@ -86,6 +87,118 @@ export interface RetryTerminalEvent {
86
87
  class: RetryTerminalClass;
87
88
  /** The Relay message ID of the envelope that the requester failed to decrypt. */
88
89
  failedEnvelopeId: string;
90
+ /**
91
+ * The session reset of the requester. Only an `expired-content` end of a
92
+ * client with a Relay has it.
93
+ */
94
+ recovery?: RetryTerminalRecoveryEvent;
95
+ }
96
+ /**
97
+ * The session reset of the requester after a retry request ends as
98
+ * `expired-content`.
99
+ *
100
+ * The requester archived its session with the device that sent the failed
101
+ * envelope, after each decrypt from that device in progress ended. The next
102
+ * message to or from the device starts a new session.
103
+ */
104
+ export interface RetryTerminalRecoveryEvent {
105
+ /** The user ID of the device whose session the requester archived. */
106
+ userId: string;
107
+ /** The device ID of the device whose session the requester archived. */
108
+ deviceId: number;
109
+ /**
110
+ * `applied`: the failed message is a group message, and the requester has
111
+ * a sender key for that group. The reset does not rotate the key. A key
112
+ * older than `maxSenderKeyAge` rotates at the next send, as at any send,
113
+ * and the new key goes to each member.
114
+ * `skipped`: a pairwise message, a group message whose group the receive
115
+ * did not resolve, or a group with no local sender key.
116
+ *
117
+ * With each outcome, the reset deletes the handoff rows of each device of
118
+ * that account in every group. The next send to each of those groups
119
+ * gives the current key to each of those devices.
120
+ */
121
+ senderKey: 'applied' | 'skipped';
122
+ /**
123
+ * `sent`: one null message went to the device and started the new session.
124
+ * `limited`: a null message went to the device in the last hour, so none
125
+ * was sent. `failed`: the send failed. With `limited` and `failed`, the
126
+ * next ordinary message starts the new session.
127
+ */
128
+ nullMessage: 'sent' | 'limited' | 'failed';
129
+ }
130
+ /**
131
+ * Why the client reports a delivery error for a failed envelope.
132
+ *
133
+ * - `content-hint`: the failed envelope has the `Default` content hint, or
134
+ * no hint, so the error comes at the first failure.
135
+ * - `deadline`: the failed envelope has the `Resendable` content hint, and
136
+ * its content did not come back within `RETRY_PLACEHOLDER_DEADLINE_MS`.
137
+ * - `rate-limit`: a rate limit refused the retry request of the envelope.
138
+ * - `request-ended`: the retry request ended with no resend, as
139
+ * `onRetryTerminal` reports.
140
+ */
141
+ export type DeliveryErrorCause = 'content-hint' | 'deadline' | 'rate-limit' | 'request-ended';
142
+ /** The recovery of one failed incoming envelope that had a delivery error. */
143
+ export interface DeliveryRecoveredEvent {
144
+ /** The Relay message ID of the envelope that the local device failed to decrypt. */
145
+ failedEnvelopeId: string;
146
+ /** The client message ID of the failed envelope, when its relay delivered one. */
147
+ clientMessageId?: string;
148
+ /** The user that sent the failed envelope. */
149
+ senderUserId: string;
150
+ /** The device that sent the failed envelope. */
151
+ senderDeviceId: number;
152
+ /** True when the failed envelope is a sender-key group message. */
153
+ groupMessage: boolean;
154
+ /**
155
+ * The group of a failed group message, in the form of
156
+ * `DecryptedEnvelope.conversationId`. A group envelope names no group, so
157
+ * the client knows it only when it holds the sender key that the message
158
+ * names. The error of a message that failed for a missing sender key has
159
+ * none. Its recovery has one when the decrypt that gave the content
160
+ * installed or used the sender key of the group. `processIncomingEnvelope`
161
+ * gives a resend's distribution to the caller and installs no key, so
162
+ * its recovery can have none.
163
+ */
164
+ groupId?: string;
165
+ /** The time of the first failure of the envelope, in epoch milliseconds. */
166
+ receivedAt: number;
167
+ }
168
+ /** The delivery error of one failed incoming envelope. */
169
+ export interface DeliveryErrorEvent extends DeliveryRecoveredEvent {
170
+ /** Why the client reports the error now. */
171
+ cause: DeliveryErrorCause;
172
+ }
173
+ /**
174
+ * Received content that waited on this device for 30 days. The client
175
+ * drops it after the hook.
176
+ */
177
+ export interface ReceiveExpiredEvent {
178
+ /** The receive record ID: the delivered fingerprint of the envelope. */
179
+ workId: string;
180
+ /** Why the content expired. */
181
+ reason: 'max-age';
182
+ /** When the device first admitted the content, in epoch milliseconds. */
183
+ receivedAt: number;
184
+ /**
185
+ * Where the content waited: `decrypted` for content that the client did
186
+ * not deliver yet, `awaiting-completion` for a helper receive that the
187
+ * application did not complete.
188
+ */
189
+ stage: 'decrypted' | 'awaiting-completion';
190
+ /** `relay` for a Relay message, `caller` for a helper receive. */
191
+ origin: 'relay' | 'caller';
192
+ /** The message ID. Absent for content stored before the receive queue. */
193
+ messageId?: string;
194
+ /** The sender. Absent for content stored before the receive queue. */
195
+ senderId?: string;
196
+ /** The sender device. Absent for content stored before the receive queue. */
197
+ senderDeviceId?: number;
198
+ /** The raw group of the content, when known. */
199
+ groupId?: string;
200
+ /** The failed envelope that the content resends, for a resend. */
201
+ failedEnvelopeId?: string;
89
202
  }
90
203
  export interface DecryptedEnvelope {
91
204
  /** Unique message ID (from server or generated) */
@@ -100,11 +213,17 @@ export interface DecryptedEnvelope {
100
213
  conversationId: string;
101
214
  /** Decrypted plaintext content (typically JSON) */
102
215
  content: string;
103
- /** Message timestamp (from sender) */
216
+ /**
217
+ * The sender's timestamp from the content, which a receipt for the
218
+ * message names. Content with no timestamp gives `receivedAt`.
219
+ */
104
220
  timestamp: number;
105
221
  /** Relay server timestamp when available */
106
222
  serverTimestamp?: number;
107
- /** When the device received the message locally */
223
+ /**
224
+ * When the device first admitted the message locally, in epoch
225
+ * milliseconds. A retry and a restart give the same time.
226
+ */
108
227
  receivedAt: number;
109
228
  /** Whether this is a group message */
110
229
  isGroup: boolean;
@@ -159,7 +278,11 @@ export interface SignalProtocolClientHooks {
159
278
  * Runs after the client archives a session (moved to inactive list)
160
279
  *
161
280
  * Stale-device recovery archives the session so delayed messages can still
162
- * attempt decryption.
281
+ * attempt decryption. When the recovery refreshes the session of a receipt
282
+ * or a retry request, the new session archives the stale one in the same
283
+ * write, and the hook runs after that session start succeeds. A failure
284
+ * in the SESAME registration after that write keeps the new session and
285
+ * runs no hook.
163
286
  * Per SESAME §3.2: "previously active session is moved to the head of the inactive sessions list"
164
287
  *
165
288
  * @param sessionId - The identifier of the archived session
@@ -212,6 +335,15 @@ export interface SignalProtocolClientHooks {
212
335
  * The hook receives the full decrypted envelope with all metadata
213
336
  * needed to store the message in the encrypted content database.
214
337
  *
338
+ * Delivery is at least once. The client stores the content before it
339
+ * acknowledges the Relay message and runs the hook after that. A stop or
340
+ * a crash before the client records the delivery runs the hook again
341
+ * with the same `messageId`. Deduplicate on `messageId`.
342
+ *
343
+ * The hook must settle. The receive queue runs one hook call at a time,
344
+ * so a hook that never settles stops the queue and `processPendingReceives`
345
+ * until the process restarts.
346
+ *
215
347
  * @param envelope - The decrypted message envelope
216
348
  *
217
349
  * @example
@@ -297,11 +429,20 @@ export interface SignalProtocolClientHooks {
297
429
  * Runs when a recipient device gets one of this client's messages
298
430
  *
299
431
  * A message to one device goes from accepted (the send resolved) to
300
- * delivered. The hook runs once for each source that reports the delivery:
432
+ * delivered. The hook runs for each source that reports the delivery:
301
433
  * `'relay'` when the Relay hands the message to the device, and `'e2ee'`
302
434
  * when the device decrypts it and sends an encrypted delivery receipt. A
303
- * second report from the same source does not run the hook. A receipt that
304
- * arrives before the send resolves runs the hook after the send resolves.
435
+ * receipt that arrives before the send resolves runs the hook after the
436
+ * send resolves.
437
+ *
438
+ * The hook runs at least once for each source. The client marks a source
439
+ * announced only after the hook returns. An error from the hook fails the
440
+ * receipt, so the relay delivers it again. A hook that throws, a client
441
+ * stop during the hook, or a crash leaves the source unannounced, and the
442
+ * hook runs again for it with the next receipt for the message. A second
443
+ * report from the same source after the hook returned does not run the
444
+ * hook. Make the hook idempotent for one `clientMessageId`,
445
+ * `recipientDeviceId`, and `source`.
305
446
  *
306
447
  * @param event - The delivery and its sources so far
307
448
  *
@@ -320,14 +461,25 @@ export interface SignalProtocolClientHooks {
320
461
  * Runs when a retry request ends with no resend
321
462
  *
322
463
  * A failed decrypt asks the sender device for a resend. The request ends
323
- * when the Relay gives a conclusive answer to its post, when it gets no
324
- * answer within 24 hours, when the sender used up its retry allowance, or
325
- * when the sender device has no prekey bundle of the requester. The
326
- * content of the failed envelope is then lost. The hook runs once for
327
- * each request. A client stop during the hook can make it run again after
328
- * the next start.
329
- *
330
- * @param event - The class of the end and the failed envelope
464
+ * when the Relay gives a conclusive answer to its post, when it does not
465
+ * get its content before its deadline, 14 days after the first failure,
466
+ * when the resend of the fifth attempt also fails, when the sender used up
467
+ * its retry allowance, when the sender device has no prekey bundle of the
468
+ * requester, or when the sender device refuses group content to a
469
+ * requester that is not a current member of the group. The content of the
470
+ * failed envelope is then lost. The hook runs at least once for each
471
+ * request. The SDK marks the end emitted only after the hook returns. A
472
+ * hook that throws, a client stop during the hook, or a crash leaves the
473
+ * end not emitted, and the hook runs again at the next retry request pass,
474
+ * start, or redelivery. Make the hook idempotent for one
475
+ * `failedEnvelopeId`.
476
+ *
477
+ * Before the hook, an `expired-content` end resets the session with the
478
+ * device that sent the failed envelope, and `event.recovery` tells what
479
+ * the reset did. The other classes, and a post that fails and can be
480
+ * posted again, reset nothing. `onSessionArchived` runs for the archive.
481
+ *
482
+ * @param event - The class of the end, the failed envelope, and the reset
331
483
  *
332
484
  * @example
333
485
  * ```typescript
@@ -337,6 +489,120 @@ export interface SignalProtocolClientHooks {
337
489
  * ```
338
490
  */
339
491
  onRetryTerminal?: (event: RetryTerminalEvent) => void | Promise<void>;
492
+ /**
493
+ * Runs when an incoming message failed to decrypt and its content did not
494
+ * come back
495
+ *
496
+ * A failed decrypt asks the sender device for a resend and acknowledges
497
+ * the failed envelope. The content hint of the envelope sets when the
498
+ * hook runs. With the `Default` hint, or no hint, it runs at the first
499
+ * failure. With the `Resendable` hint, it runs when the content did not
500
+ * come back within `RETRY_PLACEHOLDER_DEADLINE_MS`, one hour, of the
501
+ * first failure. With the `Implicit` hint, it never runs. A rate limit
502
+ * that refuses the retry request, and the end of the request, make it run
503
+ * at once. The client checks the time at each redelivery of the envelope
504
+ * and at each retry family write. With a relay, it also checks at
505
+ * create() and, while the client runs, at the time when the error is due.
506
+ *
507
+ * The hook runs at least once for each failed envelope, also across a
508
+ * restart. The client marks the error shown only after the hook returns.
509
+ * A hook that throws, a client stop during the hook, or a crash leaves the
510
+ * error not shown, and the hook runs again at the next retry request
511
+ * pass, start, or redelivery. The receive path does not acknowledge a
512
+ * failed envelope whose hook threw. Make the hook idempotent for one
513
+ * `failedEnvelopeId`. The error deletes nothing: the retry request
514
+ * continues, and when the content comes back, `onDeliveryRecovered` runs.
515
+ *
516
+ * @param event - The failed envelope, its sender and the cause
517
+ *
518
+ * @example
519
+ * ```typescript
520
+ * onDeliveryError: async (event) => {
521
+ * await messageStore.showUndelivered(event.failedEnvelopeId, event.senderUserId);
522
+ * }
523
+ * ```
524
+ */
525
+ onDeliveryError?: (event: DeliveryErrorEvent) => void | Promise<void>;
526
+ /**
527
+ * Runs when the content of a failed incoming message comes back after
528
+ * `onDeliveryError` ran for it
529
+ *
530
+ * The content comes back in a resend from the sender device, or in a
531
+ * redelivery of the failed envelope that now decrypts. The application
532
+ * gets the content as for any message, and then this hook runs. Its
533
+ * event carries the time of the first failure, so the application can put
534
+ * the message back in its first place.
535
+ *
536
+ * The hook runs at least once for each failed envelope, also across a
537
+ * restart. The client marks the recovery only after the hook returns. A
538
+ * hook that throws, a client stop during the hook, or a crash leaves the
539
+ * recovery not marked, and the hook runs again at the next retry request
540
+ * pass, start, or receive of an envelope of the same retry family. An
541
+ * error from the hook after the content does not fail that receive. Make
542
+ * the hook idempotent for one `failedEnvelopeId`.
543
+ *
544
+ * @param event - The failed envelope and its sender
545
+ *
546
+ * @example
547
+ * ```typescript
548
+ * onDeliveryRecovered: async (event) => {
549
+ * await messageStore.clearUndelivered(event.failedEnvelopeId);
550
+ * }
551
+ * ```
552
+ */
553
+ onDeliveryRecovered?: (event: DeliveryRecoveredEvent) => void | Promise<void>;
554
+ /**
555
+ * Runs when received content waited on this device for 30 days, before
556
+ * the client drops it.
557
+ *
558
+ * Content waits when its group state is not current, or when a helper
559
+ * receive is not completed. The hook runs at least once: a stop or a
560
+ * crash before the client records the expiry runs it again for the same
561
+ * `workId`. The client sends no delivery receipt and no retry request for
562
+ * expired content.
563
+ *
564
+ * @param event - The expired content, without its plaintext
565
+ *
566
+ * @example
567
+ * ```typescript
568
+ * onReceiveExpired: async (event) => {
569
+ * await messageStore.markLost(event.messageId ?? event.workId);
570
+ * }
571
+ * ```
572
+ */
573
+ onReceiveExpired?: (event: ReceiveExpiredEvent) => void | Promise<void>;
574
+ /**
575
+ * Runs once for a completed send whose Relay accepted a declared post
576
+ * without the `deviceSetChecked` mark. A declared post is a post to a
577
+ * recipient device or a sync copy to another device of the own account.
578
+ *
579
+ * The client declares the device set of each recipient account only to a
580
+ * Relay that compares device sets. Such a Relay marks each post that it
581
+ * compared. An accepted post without the mark is a Relay defect: the Relay
582
+ * did not check the declared devices. The send is delivered, so its result
583
+ * does not change and the client does not post it again. The error carries
584
+ * the code `DEVICE_SET_UNCHECKED`, the `clientMessageId` of the send, and
585
+ * the route of the post. The route is `identified-direct`,
586
+ * `anonymous-direct`, or `anonymous-group`. A sync copy is an
587
+ * `identified-direct` post. The client also logs one warning with the code
588
+ * and the route.
589
+ *
590
+ * The hook also runs once for a sync payload of a method such as
591
+ * `syncReadToLinkedDevices`. That error has no `clientMessageId`.
592
+ *
593
+ * The hook runs after the send completes. An error from the hook does not
594
+ * change the send result. The client logs the error.
595
+ *
596
+ * @param error - The protocol error of the send
597
+ *
598
+ * @example
599
+ * ```typescript
600
+ * onRelayProtocolError: (error) => {
601
+ * monitoring.report('relay-protocol', { code: error.code, route: error.route });
602
+ * }
603
+ * ```
604
+ */
605
+ onRelayProtocolError?: (error: RelayProtocolError) => void | Promise<void>;
340
606
  /**
341
607
  * Runs when the client receives a read receipt
342
608
  *
@@ -1 +1 @@
1
- {"version":3,"file":"event-hooks.d.ts","sourceRoot":"","sources":["../../client/event-hooks.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AACrE,YAAY,EAAE,kBAAkB,EAAE,CAAC;AAGnC;;;;;GAKG;AACH,OAAO,EAAE,CAAC;AAEV;;;;;;;GAOG;AACH,MAAM,MAAM,cAAc,GAAG,OAAO,GAAG,MAAM,CAAC;AAE9C,oEAAoE;AACpE,MAAM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,KAAK,EAAE,kBAAkB,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE3E;;;;;;;;;;;;;;;;;OAiBG;IACH,qBAAqB,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEzF;;;;;;;;;;;;;;;;;OAiBG;IACH,uBAAuB,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE3F;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,yBAAyB,CAAC,EAAE,CAC1B,QAAQ,EAAE,MAAM,EAChB,cAAc,EAAE,MAAM,EACtB,MAAM,EAAE,OAAO,SAAS,EAAE,YAAY,KACnC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3B;AAED;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG,MAAM,yBAAyB,CAAC"}
@@ -35,6 +35,7 @@
35
35
  * });
36
36
  * ```
37
37
  */
38
+ import { ReceiveHookTimeout } from './receive-hook-bound.js';
38
39
  import { rethrowRelayWorkStopped } from './relay-work.js';
39
40
  const HOOK_NAMES = {
40
41
  onSessionEstablished: true,
@@ -48,6 +49,10 @@ const HOOK_NAMES = {
48
49
  onKeysCleanedUp: true,
49
50
  onDelivered: true,
50
51
  onRetryTerminal: true,
52
+ onDeliveryError: true,
53
+ onDeliveryRecovered: true,
54
+ onReceiveExpired: true,
55
+ onRelayProtocolError: true,
51
56
  onReadReceiptReceived: true,
52
57
  onViewedReceiptReceived: true,
53
58
  onTypingIndicatorReceived: true,
@@ -81,6 +86,9 @@ export async function callHook(hooks, hookName, ...args) {
81
86
  }
82
87
  catch (error) {
83
88
  rethrowRelayWorkStopped(error);
89
+ // The receive hook bound logged its timeout.
90
+ if (error instanceof ReceiveHookTimeout)
91
+ return;
84
92
  // Log hook error but do not let it break core functionality
85
93
  console.error(`Hook ${hookName} failed:`, error);
86
94
  }
@@ -1 +1 @@
1
- {"version":3,"file":"event-hooks.js","sourceRoot":"","sources":["../../client/event-hooks.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AAIH,OAAO,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AAuYvD,MAAM,UAAU,GAAG;IACjB,oBAAoB,EAAE,IAAI;IAC1B,gBAAgB,EAAE,IAAI;IACtB,iBAAiB,EAAE,IAAI;IACvB,YAAY,EAAE,IAAI;IAClB,kBAAkB,EAAE,IAAI;IACxB,kBAAkB,EAAE,IAAI;IACxB,iBAAiB,EAAE,IAAI;IACvB,iBAAiB,EAAE,IAAI;IACvB,eAAe,EAAE,IAAI;IACrB,WAAW,EAAE,IAAI;IACjB,eAAe,EAAE,IAAI;IACrB,qBAAqB,EAAE,IAAI;IAC3B,uBAAuB,EAAE,IAAI;IAC7B,yBAAyB,EAAE,IAAI;CACU,CAAC;AAE5C;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,IAAY;IACzC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,EAAE,CAAC;QAC5D,MAAM,IAAI,KAAK,CAAC,wCAAwC,IAAI,EAAE,CAAC,CAAC;IAClE,CAAC;AACH,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,QAAQ,CAC5B,KAA4C,EAC5C,QAAW,EACX,GAAG,IAA2D;IAE9D,IAAI,CAAC,KAAK,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC/B,OAAO;IACT,CAAC;IAED,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,KAAK,CAAC,QAAQ,CAA8C,CAAC;QAC1E,MAAM,OAAO,CAAC,OAAO,CACnB,OAAO,CAAC,KAA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C;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,uBAAuB,CAAC,KAAK,CAAC,CAAC;QAC/B,6CAA6C;QAC7C,IAAI,KAAK,YAAY,kBAAkB;YAAE,OAAO;QAChD,4DAA4D;QAC5D,OAAO,CAAC,KAAK,CAAC,QAAQ,QAAQ,UAAU,EAAE,KAAK,CAAC,CAAC;IACnD,CAAC;AACH,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,UAAU,CAAC,KAA4C;IAIrE,MAAM,MAAM,GAAiC,EAAE,CAAC;IAChD,MAAM,QAAQ,GAAiD,EAAE,CAAC;IAClE,KAAK,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,IAAI,EAAE,CAAC,EAAE,CAAC;QACvD,IAAI,OAAO,IAAI,KAAK,UAAU;YAAE,SAAS;QACzC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI,EAAE,EAAE;YAC3B,MAAM,CAAC,IAAI,CAAC,CAAC,IAAgB,EAAE,IAAI,CAAC,CAAC,CAAC;QACxC,CAAC,CAAC;IACJ,CAAC;IACD,MAAM,IAAI,GAAG,QAIK,CAAC;IACnB,OAAO;QACL,KAAK,EAAE,QAAqC;QAC5C,KAAK,CAAC,KAAK;YACT,KAAK,IAAI,IAAI,GAAG,MAAM,CAAC,KAAK,EAAE,EAAE,IAAI,EAAE,IAAI,GAAG,MAAM,CAAC,KAAK,EAAE,EAAE,CAAC;gBAC5D,MAAM,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;YACzC,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,47 @@
1
+ /**
2
+ * The listed device set of one send. A replay reads the device lists of the
3
+ * members and of the sender's own account again, and this module finds how
4
+ * the read changes the stored set: the stored targets that the read no longer
5
+ * lists, and the listed devices that the send does not reach yet. It does not
6
+ * post or encrypt.
7
+ */
8
+ import type { OutgoingGroupDevice, StoredGroupSharedMessage, StoredOutgoingDeviceMessage, StoredOutgoingMessageIntent } from '../local/store/reliability.js';
9
+ import type { GroupMemberDevice } from '../remote/relay/types.js';
10
+ /** The change that a new read of the member device lists makes to a stored group send. */
11
+ export interface ListedGroupDeviceChange {
12
+ /**
13
+ * The devices of other members that a stored pre-message or device message
14
+ * targets, and that the read no longer lists.
15
+ */
16
+ unlisted: OutgoingGroupDevice[];
17
+ /** The listed devices of other members that no stored device message targets. */
18
+ added: GroupMemberDevice[];
19
+ }
20
+ /** The change that a new read of the sender's own device list makes to the sync copies of a send. */
21
+ export interface ListedOwnDeviceChange {
22
+ /** The own devices that a stored sync copy targets, and that the read no longer lists. */
23
+ unlisted: number[];
24
+ /** The listed own devices that no stored sync copy targets, in list order. */
25
+ added: number[];
26
+ }
27
+ /** One key for each device of an account. */
28
+ export declare function groupDeviceKey({ userId, deviceId }: OutgoingGroupDevice): string;
29
+ /**
30
+ * The change that `listed` makes to the stored targets of `intent`. `listed`
31
+ * holds the complete device list of each member of the send. The devices of
32
+ * the sender's own account are not member targets.
33
+ */
34
+ export declare function listedGroupDeviceChange(intent: StoredOutgoingMessageIntent, listed: readonly GroupMemberDevice[], senderUserId: string): ListedGroupDeviceChange;
35
+ /**
36
+ * The change that `listedDeviceIds` makes to the stored sync copies of a
37
+ * send. `listedDeviceIds` holds the sender's own listed devices other than
38
+ * the sending device.
39
+ */
40
+ export declare function listedOwnDeviceChange(syncMessages: readonly StoredOutgoingDeviceMessage[], listedDeviceIds: readonly number[]): ListedOwnDeviceChange;
41
+ /**
42
+ * The devices that a stored shared body names, as keys, each with the
43
+ * registration that the body names for it. The body names the devices of
44
+ * each account in the order of `recipientUserIds`.
45
+ */
46
+ export declare function sharedBodyDevices(shared: StoredGroupSharedMessage): Map<string, number>;
47
+ //# sourceMappingURL=group-device-set.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"group-device-set.d.ts","sourceRoot":"","sources":["../../client/group-device-set.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,OAAO,KAAK,EACV,mBAAmB,EACnB,wBAAwB,EACxB,2BAA2B,EAC3B,2BAA2B,EAC5B,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAG/D,0FAA0F;AAC1F,MAAM,WAAW,uBAAuB;IACtC;;;OAGG;IACH,QAAQ,EAAE,mBAAmB,EAAE,CAAC;IAChC,iFAAiF;IACjF,KAAK,EAAE,iBAAiB,EAAE,CAAC;CAC5B;AAED,qGAAqG;AACrG,MAAM,WAAW,qBAAqB;IACpC,0FAA0F;IAC1F,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,8EAA8E;IAC9E,KAAK,EAAE,MAAM,EAAE,CAAC;CACjB;AAED,6CAA6C;AAC7C,wBAAgB,cAAc,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,mBAAmB,GAAG,MAAM,CAEhF;AAOD;;;;GAIG;AACH,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,2BAA2B,EACnC,MAAM,EAAE,SAAS,iBAAiB,EAAE,EACpC,YAAY,EAAE,MAAM,GACnB,uBAAuB,CAezB;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CACnC,YAAY,EAAE,SAAS,2BAA2B,EAAE,EACpD,eAAe,EAAE,SAAS,MAAM,EAAE,GACjC,qBAAqB,CAOvB;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,wBAAwB,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAYvF"}
@@ -0,0 +1,65 @@
1
+ /**
2
+ * The listed device set of one send. A replay reads the device lists of the
3
+ * members and of the sender's own account again, and this module finds how
4
+ * the read changes the stored set: the stored targets that the read no longer
5
+ * lists, and the listed devices that the send does not reach yet. It does not
6
+ * post or encrypt.
7
+ */
8
+ import { base64ToBytes } from '../internal/crypto/index.js';
9
+ import { deserializeSentMessage } from '../internal/protocol/sealed-sender/multi-recipient-message.js';
10
+ import { asBase64 } from '../types/utils.js';
11
+ /** One key for each device of an account. */
12
+ export function groupDeviceKey({ userId, deviceId }) {
13
+ return `${userId}\u0000${String(deviceId)}`;
14
+ }
15
+ /** The key of the device that a stored message targets. */
16
+ function targetKey(message) {
17
+ return groupDeviceKey({ userId: message.recipientUserId, deviceId: message.recipientDeviceId });
18
+ }
19
+ /**
20
+ * The change that `listed` makes to the stored targets of `intent`. `listed`
21
+ * holds the complete device list of each member of the send. The devices of
22
+ * the sender's own account are not member targets.
23
+ */
24
+ export function listedGroupDeviceChange(intent, listed, senderUserId) {
25
+ const others = listed.filter((member) => member.userId !== senderUserId);
26
+ const listedKeys = new Set(others.map(groupDeviceKey));
27
+ const unlisted = new Map();
28
+ for (const message of [...(intent.preMessages ?? []), ...intent.deviceMessages]) {
29
+ const key = targetKey(message);
30
+ if (!listedKeys.has(key)) {
31
+ unlisted.set(key, { userId: message.recipientUserId, deviceId: message.recipientDeviceId });
32
+ }
33
+ }
34
+ const targeted = new Set(intent.deviceMessages.map(targetKey));
35
+ return {
36
+ unlisted: [...unlisted.values()],
37
+ added: others.filter((member) => !targeted.has(groupDeviceKey(member))),
38
+ };
39
+ }
40
+ /**
41
+ * The change that `listedDeviceIds` makes to the stored sync copies of a
42
+ * send. `listedDeviceIds` holds the sender's own listed devices other than
43
+ * the sending device.
44
+ */
45
+ export function listedOwnDeviceChange(syncMessages, listedDeviceIds) {
46
+ const listed = new Set(listedDeviceIds);
47
+ const stored = new Set(syncMessages.map((message) => message.recipientDeviceId));
48
+ return {
49
+ unlisted: [...stored].filter((deviceId) => !listed.has(deviceId)),
50
+ added: [...listed].filter((deviceId) => !stored.has(deviceId)),
51
+ };
52
+ }
53
+ /**
54
+ * The devices that a stored shared body names, as keys, each with the
55
+ * registration that the body names for it. The body names the devices of
56
+ * each account in the order of `recipientUserIds`.
57
+ */
58
+ export function sharedBodyDevices(shared) {
59
+ const { recipients } = deserializeSentMessage(base64ToBytes(asBase64(shared.sentMessageBase64)));
60
+ return new Map(recipients.flatMap(({ devices }, index) => devices.map(({ deviceId, registrationId }) => [
61
+ groupDeviceKey({ userId: shared.recipientUserIds[index], deviceId }),
62
+ registrationId,
63
+ ])));
64
+ }
65
+ //# sourceMappingURL=group-device-set.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"group-device-set.js","sourceRoot":"","sources":["../../client/group-device-set.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,sBAAsB,EAAE,MAAM,4DAA4D,CAAC;AAQpG,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAqB1C,6CAA6C;AAC7C,MAAM,UAAU,cAAc,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAuB;IACtE,OAAO,GAAG,MAAM,SAAS,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC;AAC9C,CAAC;AAED,2DAA2D;AAC3D,SAAS,SAAS,CAAC,OAAoC;IACrD,OAAO,cAAc,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,eAAe,EAAE,QAAQ,EAAE,OAAO,CAAC,iBAAiB,EAAE,CAAC,CAAC;AAClG,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,uBAAuB,CACrC,MAAmC,EACnC,MAAoC,EACpC,YAAoB;IAEpB,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,KAAK,YAAY,CAAC,CAAC;IACzE,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC,CAAC;IACvD,MAAM,QAAQ,GAAG,IAAI,GAAG,EAA+B,CAAC;IACxD,KAAK,MAAM,OAAO,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC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QAAQ,CAAC,CAAC;KAC/D,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAAC,MAAgC;IAChE,MAAM,EAAE,UAAU,EAAE,GAAG,sBAAsB,CAC3C,aAAa,CAAC,QAAQ,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC,CAClD,CAAC;IACF,OAAO,IAAI,GAAG,CACZ,UAAU,CAAC,OAAO,CAAC,CAAC,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,EAAE,CACxC,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,QAAQ,EAAE,cAAc,EAAE,EAAoB,EAAE,CAAC;QAC9D,cAAc,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,gBAAgB,CAAC,KAAK,CAAE,EAAE,QAAQ,EAAE,CAAC;QACrE,cAAc;KACf,CAAC,CACH,CACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,116 @@
1
+ /**
2
+ * The group fetcher of a client.
3
+ *
4
+ * The fetcher is the one path that brings a group's local state up to the
5
+ * revision that authenticated group contexts claim. Receive and resend share
6
+ * it, so they share one fetch budget for each group:
7
+ *
8
+ * - One fetch runs for a group at a time. A caller that needs the group while
9
+ * a fetch runs joins that fetch.
10
+ * - A caller waits for a fetch up to a deadline. The fetch continues after the
11
+ * deadline, and its result still updates the group's receive record.
12
+ * - A fetch that reaches the server head opens a 30 s window, also when the
13
+ * head is below the claim. Only a fetch that reaches no head, or a denial,
14
+ * doubles the window up to 1 h. Inside a window, the fetcher runs at most
15
+ * one fetch for each distinct claimed revision, up to
16
+ * `GROUP_FETCH_CLAIMS_PER_WINDOW`. A lying sender therefore delays an
17
+ * honest claim by one base window at most.
18
+ * - Each message is decided on its own claim, not on the highest claim of
19
+ * the group. A sender that claims a revision the server never reaches
20
+ * therefore uses up only the fetch of that claim, and an honest claim
21
+ * above the head still gets its own fetch.
22
+ * - A claim whose fetch ends below it is evaluated at the server head, as
23
+ * Signal evaluates a message against the state it could fetch, and the
24
+ * required revision becomes that head. A claim raised while the fetch ran
25
+ * stays the required revision when it is above that head. A claim above
26
+ * the head that no fetch in the window asked for is not evaluated at that
27
+ * head: it waits for a fetch.
28
+ * - A verified refusal from the group server is a denial. It answers every
29
+ * claim known when its fetch started, and holds until a context claims a
30
+ * higher revision. A claim raised while the fetch ran is above it, so the
31
+ * next message with that claim fetches again.
32
+ * - A fetch for a context that carries a signed group change first tries to
33
+ * apply that one change. It asks the group server only when the change
34
+ * does not apply or does not reach the claim. When the window has fetched
35
+ * its limit of claims, the change still applies, with no server call.
36
+ * - start() resumes the groups that wait for a fetch, and one timer runs each
37
+ * group again when its window ends. The timer never fetches a group that
38
+ * the application blocks, as Signal never updates a blocked group.
39
+ *
40
+ * The fetch calls `syncGroup`, which takes the group's sender-key lock. The
41
+ * fetcher must therefore never run inside that lock.
42
+ */
43
+ import type { Logger } from '../logger.js';
44
+ import { type GroupStateStore } from '../internal/groups/manager.js';
45
+ import { type GroupFetchDenial } from '../internal/groups/receive-record.js';
46
+ import type { DecryptedGroup } from '../internal/groups/types.js';
47
+ /** What the local state of a group supports now. */
48
+ export type GroupFreshness = {
49
+ kind: 'fresh';
50
+ revision: number;
51
+ } | {
52
+ kind: 'denied';
53
+ reason: GroupFetchDenial;
54
+ } | {
55
+ kind: 'unavailable';
56
+ reason: 'update-pending' | 'update-failed';
57
+ retryAfterMs: number;
58
+ };
59
+ /** How long a caller waits for a fetch before it answers `update-pending`. */
60
+ export declare const GROUP_FETCH_DEADLINE_MS = 10000;
61
+ /** The distinct claimed revisions that one window may fetch for a group. */
62
+ export declare const GROUP_FETCH_CLAIMS_PER_WINDOW = 16;
63
+ /**
64
+ * The groups that one sender device's contexts may create and leave
65
+ * unverified. It is a provisional resource bound.
66
+ */
67
+ export declare const GROUP_UNVERIFIED_PER_SENDER_DEVICE = 100;
68
+ /** The sender device whose authenticated content carried a group context. */
69
+ export interface GroupContextSender {
70
+ readonly senderId: string;
71
+ readonly senderDeviceId: number;
72
+ }
73
+ /** The revision that one authenticated group context claims. */
74
+ export interface GroupRevisionClaim {
75
+ /** The revision that the context claims. */
76
+ readonly revision: number;
77
+ /** The bytes of the signed change that the context carries, if any. */
78
+ readonly change?: Uint8Array;
79
+ }
80
+ /** What the fetcher needs from its client. */
81
+ export interface GroupFetcherOptions {
82
+ readonly store: GroupStateStore;
83
+ /** Bring the group to the server head. It takes the sender-key lock. */
84
+ readonly sync: (groupId: string) => Promise<DecryptedGroup>;
85
+ /**
86
+ * Apply a carried signed change. Null when the change does not apply, so
87
+ * the fetch asks the group server.
88
+ */
89
+ readonly applyChange?: (groupId: string, revision: number, change: Uint8Array) => Promise<DecryptedGroup | null>;
90
+ /**
91
+ * True for a group that the application blocks. The timer does not fetch
92
+ * it. A hook that throws counts as blocked.
93
+ */
94
+ readonly isBlocked?: (groupId: string) => boolean | Promise<boolean>;
95
+ /**
96
+ * True while received content waits on the group. The receive queue owns
97
+ * that content. A group with waiting content is never evicted, and the
98
+ * timer fetches a stale group only while content waits. A hook that throws
99
+ * counts as true.
100
+ */
101
+ readonly hasBlockedContent?: (groupId: string) => Promise<boolean>;
102
+ /**
103
+ * Called after a fetch records a synced or denied outcome, so that the
104
+ * content that waits on the group is decided again. A failed fetch does
105
+ * not call it, because the content still waits.
106
+ */
107
+ readonly onFetched?: (groupId: string) => void;
108
+ /** Run one timer pass as tracked client work. */
109
+ readonly runInBackground: (pass: () => Promise<void>) => Promise<void>;
110
+ readonly logger: Required<Logger>;
111
+ readonly now?: () => number;
112
+ readonly deadlineMs?: number;
113
+ }
114
+ /** The denial that a group server refusal states, if it states one. */
115
+ export declare function groupFetchDenial(error: unknown): GroupFetchDenial | null;
116
+ //# sourceMappingURL=group-fetcher.d.ts.map