@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
@@ -1,11 +1,18 @@
1
1
  /**
2
2
  * Wire form of a retry request.
3
3
  *
4
- * A retry request travels as an identified mailbox envelope with
5
- * `messageType: 'retry_request'`. The envelope sender is the requester: the
6
- * relay stamps it, so the payload never carries it. The `ciphertext` field
7
- * holds canonical base64 of a small UTF-8 JSON payload. The payload is not
8
- * encrypted. It holds only what the requester knows about the failed message.
4
+ * A retry request is a mailbox envelope with `messageType: 'retry_request'`.
5
+ * The envelope sender is the requester, so the payload never carries it.
6
+ * The `ciphertext` field holds canonical base64 of a small UTF-8 JSON
7
+ * payload. The payload is not ratchet-encrypted. It holds only what the
8
+ * requester knows about the failed message.
9
+ *
10
+ * The request record stores the identified form of the envelope.
11
+ * `retryRequestPost` seals it at each post when an access key of the target
12
+ * permits it: the seal holds the same payload as `PLAINTEXT_CONTENT`, and
13
+ * the sender certificate in the seal names the requester. Otherwise the
14
+ * post is identified, and the relay stamps the requester, only when the
15
+ * sealed sender delivery mode permits it.
9
16
  *
10
17
  * The requester keeps one request record for each failed envelope. The record
11
18
  * holds a random retry ID, and every wire ID of the request family derives from
@@ -13,20 +20,32 @@
13
20
  * `:<n>` from attempt 2. The resend and the null message carry the attempt
14
21
  * number of the request that they answer. The failed envelope ID travels
15
22
  * only in the payload.
16
- * The requester stores each request envelope before the post, and posts the
17
- * stored envelope again on a later decrypt failure of the same envelope.
23
+ * The requester stores each request envelope before the post. After a post
24
+ * that fails with a retryable class, the retry request scheduler posts the
25
+ * stored envelope again, until the deadline of the record.
26
+ *
27
+ * A relay can assign its own envelope ID. The payload then also carries the
28
+ * client message ID of the failed envelope, the ID that the sender chose. A
29
+ * request without a ratchet key names a failed sender-key message.
18
30
  */
31
+ import { SealedSenderAuthError } from '../types/errors.js';
19
32
  import { RetryReason } from '../internal/sesame/types.js';
20
33
  import { base64ToBytes, bytesToBase64, generateUuidV4, stringToBytes } from '../internal/crypto/index.js';
21
34
  import { utf8Decode } from '../internal/platform/index.js';
22
- import { isRetryId, retryAttemptClientMessageId, retryRequestClientMessageId, storeRetryRequest, } from '../local/store/reliability.js';
23
- import { relayOperationRefusal } from './relay-acceptance.js';
35
+ import { isRetryId, RETRY_REQUEST_DEADLINE_MS, retryAttemptClientMessageId, retryRequestClientMessageId, storeRetryRequest, updateRetryRequest, } from '../local/store/reliability.js';
36
+ import { classifyRetryRequestPostFailure, relayOperationRefusal, } from './relay-acceptance.js';
37
+ import { rethrowRelayWorkStopped } from './relay-work.js';
38
+ import { isStaleDeviceRefusal } from './relay-device-refusal.js';
39
+ import { MAX_RETRY_RESPONSES_PER_MESSAGE } from './constants.js';
24
40
  /** The payload version that this client writes and reads. */
25
41
  const RETRY_REQUEST_PAYLOAD_VERSION = 1;
26
42
  /** The decoder refuses a longer `ciphertext` value before it decodes it. */
27
43
  export const MAX_RETRY_REQUEST_CIPHERTEXT_LENGTH = 2_048;
28
- /** The Relay refuses a longer message ID, so a failed envelope ID is 1 to this many characters. */
29
- const MAX_FAILED_ENVELOPE_ID_LENGTH = 128;
44
+ /**
45
+ * The Relay refuses a longer message ID, so a failed envelope ID and a
46
+ * failed client message ID are 1 to this many characters.
47
+ */
48
+ const MAX_MESSAGE_ID_LENGTH = 128;
30
49
  /** The decoded ratchet key is 1 to this many bytes. */
31
50
  const MAX_RATCHET_KEY_BYTES = 64;
32
51
  const RETRY_REASONS = new Set(Object.values(RetryReason));
@@ -48,6 +67,10 @@ export async function retryRequestEnvelope(request, sender, failed) {
48
67
  timestamp: request.timestamp,
49
68
  ...(request.ratchetKey === undefined ? {} : { ratchetKey: request.ratchetKey }),
50
69
  ...(failed && { failedEnvelopeId: failed.failedEnvelopeId, retryId: failed.retryId }),
70
+ // The sender chose this ID. A value that the decoder refuses is left out.
71
+ ...(isMessageId(request.failedClientMessageId) && {
72
+ failedClientMessageId: request.failedClientMessageId,
73
+ }),
51
74
  };
52
75
  return {
53
76
  targetUserId: request.originalSenderUserId,
@@ -63,19 +86,108 @@ export async function retryRequestEnvelope(request, sender, failed) {
63
86
  : await generateUuidV4(),
64
87
  };
65
88
  }
89
+ /**
90
+ * Make the function that posts one retry request envelope, by the sealed
91
+ * sender delivery mode, as a receipt goes.
92
+ *
93
+ * With an access key of the target, the post is sealed: the Relay sees the
94
+ * target, the timing and the size, and not the requester. The sealed post
95
+ * keeps the client message ID and the timestamp of the envelope, so the
96
+ * Relay deduplicates the attempt by the same operation as an identified
97
+ * post. When the Relay refuses the access key, the post goes identified
98
+ * only when the delivery mode permits it. When `seal` resolves to
99
+ * undefined, the post goes identified. In `'required'` mode `seal` throws
100
+ * instead, and nothing goes identified. The caller classifies each error
101
+ * of the post.
102
+ *
103
+ * When the Relay refuses the post as `STALE_DEVICE`, the target device has
104
+ * a new registration. The post then refreshes the session with the device
105
+ * once from a fresh bundle, and posts the same envelope again, sealed and
106
+ * named with the new session, as a receipt goes. The request is plaintext,
107
+ * so nothing is encrypted again. A refresh that finds no bundle,
108
+ * or a second refusal, throws the refusal. A refresh that fails for another
109
+ * reason throws StaleSessionRefreshError, which classifies as a transport
110
+ * outage, so the next post refreshes again.
111
+ *
112
+ * @param seal - Seals the payload. Without it, each post is identified.
113
+ * @param relay - Posts the sealed envelope.
114
+ * @param sendIdentified - Posts the identified envelope.
115
+ * @param registrationOf - The registration ID of the current session with
116
+ * the target device. The identified envelope names it, as the sealed body
117
+ * does, so the Relay refuses the post to a reinstalled device. With no
118
+ * session, or without this function, the envelope names none.
119
+ * @param refreshStaleSession - Refreshes the session with a refused device.
120
+ * Resolves to true when the new session is ready. Without it, a stale
121
+ * refusal throws.
122
+ */
123
+ export function retryRequestPost(seal, relay, sendIdentified, registrationOf, refreshStaleSession) {
124
+ const post = async (envelope) => {
125
+ const payloadBase64 = typeof envelope.ciphertext === 'string'
126
+ ? envelope.ciphertext
127
+ : bytesToBase64(envelope.ciphertext);
128
+ const sealed = await seal?.(envelope.targetUserId, envelope.targetDeviceId, payloadBase64);
129
+ if (sealed) {
130
+ // The seal resolves only when the relay has anonymous delivery.
131
+ if (!relay?.sendMultiRecipientUnidentified) {
132
+ throw new Error('Relay has no anonymous delivery for a sealed retry request');
133
+ }
134
+ try {
135
+ return await relay.sendMultiRecipientUnidentified(sealed.sentMessageBase64, sealed.auth, envelope.timestamp, envelope.deliveryClass, [envelope.targetUserId], envelope.clientMessageId);
136
+ }
137
+ catch (error) {
138
+ if (!(error instanceof SealedSenderAuthError) || !sealed.identifiedFallback)
139
+ throw error;
140
+ }
141
+ }
142
+ const recipientRegistrationId = await registrationOf?.(envelope.targetUserId, envelope.targetDeviceId);
143
+ return sendIdentified(recipientRegistrationId === undefined ? envelope : { ...envelope, recipientRegistrationId });
144
+ };
145
+ return async (envelope) => {
146
+ try {
147
+ return await post(envelope);
148
+ }
149
+ catch (error) {
150
+ if (!refreshStaleSession || !isStaleDeviceRefusal(error))
151
+ throw error;
152
+ const refreshed = await refreshStaleSession(envelope.targetUserId, envelope.targetDeviceId);
153
+ if (!refreshed)
154
+ throw error;
155
+ return post(envelope);
156
+ }
157
+ };
158
+ }
159
+ /**
160
+ * Tell whether a stored request attempt is answered and is the last
161
+ * attempt of its request. A sender answers at most
162
+ * `MAX_RETRY_RESPONSES_PER_MESSAGE` requests for one message, so when the
163
+ * resend that answered this attempt also fails, the request ends.
164
+ */
165
+ export function answeredLastRetryAttempt(stored) {
166
+ return stored.answered && stored.attempt >= MAX_RETRY_RESPONSES_PER_MESSAGE;
167
+ }
168
+ /** The shortest wait before the next post of a stored attempt. */
169
+ const MIN_RETRY_REQUEST_BACKOFF_MS = 60_000;
170
+ /** The longest wait before the next post of a stored attempt. */
171
+ const MAX_RETRY_REQUEST_BACKOFF_MS = 60 * 60_000;
66
172
  /**
67
173
  * Post the retry request for one failed envelope.
68
174
  *
69
175
  * Without a failed envelope ID, it creates a request and posts it under a
70
- * new UUID, and stores nothing. With a stored attempt, it posts the stored
71
- * envelope again. Otherwise it creates attempt 1 with a new retry ID and
72
- * stores it before the post. Each later attempt keeps the retry ID. When
73
- * the Relay refuses a stored attempt with OPERATION_EXPIRED, or when a
74
- * member failed and the stored attempt is answered, it creates the next
75
- * attempt, replaces the record in one write, and posts it. Each new
76
- * attempt is not answered. A RETRY_CONFLICT answer to any post completes
77
- * the attempt, because the Relay holds an earlier encryption of this
78
- * attempt.
176
+ * new UUID, stores nothing, and throws when the post fails. Otherwise the
177
+ * request record owns the request. With no record, it creates attempt 1
178
+ * with a new retry ID and stores it before the post, due at once. A
179
+ * record that ended posts nothing. At the deadline of the record, the
180
+ * request ends as `expired-content` and posts nothing. When a member
181
+ * failed and the stored attempt is answered, it creates the next attempt
182
+ * under the same retry ID, with the same deadline, and posts it. When that
183
+ * answered attempt is the last one, as `answeredLastRetryAttempt` tells,
184
+ * the request ends as `attempts-exhausted` and posts nothing. Otherwise it
185
+ * posts the stored attempt, as `postStoredRetryRequest` does.
186
+ *
187
+ * Each new attempt carries the failed client message ID, the content hint,
188
+ * the sender, the receive time and the delivery error state of the stored
189
+ * record. Attempt 1 takes them from `failed`, with the time of now as the
190
+ * receive time.
79
191
  *
80
192
  * @param store - The local store that keeps the request records.
81
193
  * @param failed - The failed envelope and its stored request.
@@ -87,55 +199,168 @@ export async function retryRequestEnvelope(request, sender, failed) {
87
199
  export async function postRetryRequest(store, failed, createRequest, sender, send) {
88
200
  const failedEnvelopeId = failed.id;
89
201
  if (failedEnvelopeId === undefined) {
90
- await send(await retryRequestEnvelope(await createRequest(), sender));
91
- return;
202
+ const request = withFailedClientMessageId(await createRequest(), failed.clientMessageId);
203
+ await send(await retryRequestEnvelope(request, sender));
204
+ return 'posted';
92
205
  }
93
- const post = async (envelope) => {
94
- try {
95
- await send(envelope);
96
- }
97
- catch (error) {
98
- if (relayOperationRefusal(error) !== 'RETRY_CONFLICT')
99
- throw error;
100
- }
101
- };
102
- const create = async (attempt, retryId) => {
103
- const envelope = await retryRequestEnvelope(await createRequest(), sender, {
206
+ const attempts = retryRequestAttempts(store, createRequest, sender, send);
207
+ const { stored } = failed;
208
+ if (!stored) {
209
+ return attempts.postNew(await attempts.create({
104
210
  failedEnvelopeId,
105
- retryId,
106
- attempt,
107
- });
108
- await storeRetryRequest(store, {
109
- failedEnvelopeId,
110
- retryId,
111
- attempt,
112
- requestedAt: envelope.timestamp,
211
+ retryId: await generateUuidV4(),
212
+ attempt: 1,
113
213
  ...(failed.fingerprint !== undefined && { fingerprint: failed.fingerprint }),
214
+ ...(failed.groupMessage && { groupMessage: true }),
215
+ ...(failed.clientMessageId !== undefined && {
216
+ failedClientMessageId: failed.clientMessageId,
217
+ }),
218
+ ...(failed.groupId !== undefined && { groupId: failed.groupId }),
219
+ receivedAt: Date.now(),
220
+ ...(failed.contentHint !== undefined && { contentHint: failed.contentHint }),
221
+ ...(failed.sender !== undefined && { failedSender: failed.sender }),
222
+ }));
223
+ }
224
+ if (stored.terminal !== undefined || stored.envelope === undefined)
225
+ return 'terminal';
226
+ if (Date.now() >= stored.deadlineAt)
227
+ return attempts.end(stored, 'expired-content');
228
+ if (failed.member !== undefined && stored.answered) {
229
+ if (answeredLastRetryAttempt(stored))
230
+ return attempts.end(stored, 'attempts-exhausted');
231
+ return attempts.postNew(await attempts.next(stored));
232
+ }
233
+ return attempts.postStored(stored);
234
+ }
235
+ /**
236
+ * Post the stored attempt of a retry request again, with its stored bytes
237
+ * and ID. When the Relay refuses it with OPERATION_EXPIRED, it creates the
238
+ * next attempt under the same retry ID, with the same deadline, replaces
239
+ * the record in one write, and posts it.
240
+ *
241
+ * Each post classifies its failure. A RETRY_CONFLICT answer completes the
242
+ * attempt, because the Relay holds an earlier encryption of it. A
243
+ * conclusive class stores the terminal state, with `emitted` false, and
244
+ * gives 'terminal'. A retryable class stores the class and the next
245
+ * attempt time, the age of the attempt from 1 minute to 1 hour from now,
246
+ * and gives 'pending'. A post that the Relay accepts clears both.
247
+ *
248
+ * @param store - The local store that keeps the request records.
249
+ * @param stored - The stored attempt. It has an envelope.
250
+ * @param createRequest - Creates the request of a new attempt.
251
+ * @param sender - The local identity, which sends the envelope.
252
+ * @param send - Posts one request envelope.
253
+ */
254
+ export async function postStoredRetryRequest(store, stored, createRequest, sender, send) {
255
+ return retryRequestAttempts(store, createRequest, sender, send).postStored(stored);
256
+ }
257
+ /** The attempt steps of one retry request. */
258
+ function retryRequestAttempts(store, createRequest, sender, send) {
259
+ const update = (record, changes) => updateRetryRequest(store, record.failedEnvelopeId, record.retryId, record.attempt, changes);
260
+ /**
261
+ * Create and store a new attempt. Attempt 1 sets the deadline from its
262
+ * own time, the first failure. The attempt is due at its own time until
263
+ * its post settles, so the scheduler posts it again when a stop or a
264
+ * crash ends the post.
265
+ */
266
+ const create = async (attempt) => {
267
+ const request = withFailedClientMessageId(await createRequest(), attempt.failedClientMessageId);
268
+ const envelope = await retryRequestEnvelope(request, sender, attempt);
269
+ const record = {
270
+ failedEnvelopeId: attempt.failedEnvelopeId,
271
+ retryId: attempt.retryId,
272
+ attempt: attempt.attempt,
273
+ requestedAt: envelope.timestamp,
274
+ ...(attempt.fingerprint !== undefined && { fingerprint: attempt.fingerprint }),
275
+ ...(attempt.groupId !== undefined && { groupId: attempt.groupId }),
114
276
  answered: false,
277
+ ...(attempt.groupMessage && { groupMessage: true }),
278
+ ...(attempt.failedClientMessageId !== undefined && {
279
+ failedClientMessageId: attempt.failedClientMessageId,
280
+ }),
281
+ ...(attempt.groupId !== undefined && { groupId: attempt.groupId }),
282
+ ...(attempt.receivedAt !== undefined && { receivedAt: attempt.receivedAt }),
283
+ ...(attempt.contentHint !== undefined && { contentHint: attempt.contentHint }),
284
+ ...(attempt.failedSender !== undefined && { failedSender: attempt.failedSender }),
285
+ ...(attempt.errorShown && { errorShown: true }),
286
+ ...(attempt.recoveredEmitted && { recoveredEmitted: true }),
287
+ deadlineAt: attempt.deadlineAt ?? envelope.timestamp + RETRY_REQUEST_DEADLINE_MS,
288
+ nextAttemptAt: envelope.timestamp,
115
289
  envelope,
290
+ };
291
+ await storeRetryRequest(store, record);
292
+ return record;
293
+ };
294
+ /** Create the attempt after the stored one, with the same retry ID and deadline. */
295
+ const next = (stored) => create({
296
+ failedEnvelopeId: stored.failedEnvelopeId,
297
+ retryId: stored.retryId,
298
+ attempt: stored.attempt + 1,
299
+ fingerprint: stored.fingerprint,
300
+ groupMessage: stored.groupMessage,
301
+ failedClientMessageId: stored.failedClientMessageId,
302
+ groupId: stored.groupId,
303
+ receivedAt: stored.receivedAt,
304
+ contentHint: stored.contentHint,
305
+ failedSender: stored.failedSender,
306
+ errorShown: stored.errorShown,
307
+ recoveredEmitted: stored.recoveredEmitted,
308
+ deadlineAt: stored.deadlineAt,
309
+ });
310
+ const end = async (stored, terminal) => {
311
+ await update(stored, {
312
+ terminal: { class: terminal, at: Date.now(), emitted: false },
313
+ nextAttemptAt: undefined,
116
314
  });
117
- return envelope;
315
+ return 'terminal';
316
+ };
317
+ /**
318
+ * Post one attempt. `fresh` is true for an attempt that this call
319
+ * created: OPERATION_EXPIRED then means a clock outside the admission
320
+ * window, and counts as a transport outage.
321
+ */
322
+ const post = async (record, fresh) => {
323
+ try {
324
+ await send(record.envelope);
325
+ }
326
+ catch (error) {
327
+ rethrowRelayWorkStopped(error);
328
+ const refusal = relayOperationRefusal(error);
329
+ if (refusal === 'OPERATION_EXPIRED' && !fresh) {
330
+ // The Relay no longer admits or replays the stored operation. The
331
+ // new attempt replaces the record before its post.
332
+ return post(await next(record), true);
333
+ }
334
+ if (refusal !== 'RETRY_CONFLICT') {
335
+ const failure = refusal === 'OPERATION_EXPIRED'
336
+ ? { retry: 'transport-outage' }
337
+ : classifyRetryRequestPostFailure(error);
338
+ if ('terminal' in failure) {
339
+ await update(record, {
340
+ terminal: { class: failure.terminal, at: Date.now(), emitted: false },
341
+ nextAttemptAt: undefined,
342
+ lastFailureClass: undefined,
343
+ });
344
+ return 'terminal';
345
+ }
346
+ const now = Date.now();
347
+ const wait = Math.min(MAX_RETRY_REQUEST_BACKOFF_MS, Math.max(MIN_RETRY_REQUEST_BACKOFF_MS, now - record.requestedAt));
348
+ await update(record, { lastFailureClass: failure.retry, nextAttemptAt: now + wait });
349
+ return 'pending';
350
+ }
351
+ }
352
+ if (record.nextAttemptAt !== undefined || record.lastFailureClass !== undefined) {
353
+ await update(record, { nextAttemptAt: undefined, lastFailureClass: undefined });
354
+ }
355
+ return 'posted';
356
+ };
357
+ return {
358
+ create,
359
+ next,
360
+ end,
361
+ postNew: (record) => post(record, true),
362
+ postStored: (stored) => post(stored, false),
118
363
  };
119
- if (!failed.stored) {
120
- await post(await create(1, await generateUuidV4()));
121
- return;
122
- }
123
- const { attempt, retryId } = failed.stored;
124
- if (failed.member !== undefined && failed.stored.answered) {
125
- await post(await create(attempt + 1, retryId));
126
- return;
127
- }
128
- try {
129
- await post(failed.stored.envelope);
130
- return;
131
- }
132
- catch (error) {
133
- if (relayOperationRefusal(error) !== 'OPERATION_EXPIRED')
134
- throw error;
135
- }
136
- // The Relay no longer admits or replays the stored operation. The new
137
- // attempt replaces the record before its post.
138
- await post(await create(attempt + 1, retryId));
139
364
  }
140
365
  /**
141
366
  * Read a `retry_request` envelope that the local device received.
@@ -177,7 +402,7 @@ export function readRetryRequestEnvelope(envelope, local) {
177
402
  if (payload.v !== RETRY_REQUEST_PAYLOAD_VERSION) {
178
403
  return { ok: false, cause: 'payload version is not supported' };
179
404
  }
180
- const { failedTimestamp, deviceId, reason, timestamp, ratchetKey, failedEnvelopeId, retryId } = payload;
405
+ const { failedTimestamp, deviceId, reason, timestamp, ratchetKey, failedEnvelopeId, retryId, failedClientMessageId, } = payload;
181
406
  if (!Number.isSafeInteger(failedTimestamp) || failedTimestamp <= 0) {
182
407
  return { ok: false, cause: 'failedTimestamp is not valid' };
183
408
  }
@@ -201,12 +426,15 @@ export function readRetryRequestEnvelope(envelope, local) {
201
426
  if (failedEnvelopeId !== undefined &&
202
427
  (typeof failedEnvelopeId !== 'string' ||
203
428
  failedEnvelopeId.length < 1 ||
204
- failedEnvelopeId.length > MAX_FAILED_ENVELOPE_ID_LENGTH)) {
429
+ failedEnvelopeId.length > MAX_MESSAGE_ID_LENGTH)) {
205
430
  return { ok: false, cause: 'failedEnvelopeId is not valid' };
206
431
  }
207
432
  if (retryId !== undefined && !isRetryId(retryId)) {
208
433
  return { ok: false, cause: 'retryId is not valid' };
209
434
  }
435
+ if (failedClientMessageId !== undefined && !isMessageId(failedClientMessageId)) {
436
+ return { ok: false, cause: 'failedClientMessageId is not valid' };
437
+ }
210
438
  // The sender derives the resend IDs from the retry ID and keys its record by
211
439
  // the failed envelope ID, so a payload carries both or neither.
212
440
  if ((failedEnvelopeId === undefined) !== (retryId === undefined)) {
@@ -226,12 +454,21 @@ export function readRetryRequestEnvelope(envelope, local) {
226
454
  timestamp: timestamp,
227
455
  reason: reason,
228
456
  ...(ratchetKey === undefined ? {} : { ratchetKey: ratchetKey }),
457
+ ...(failedClientMessageId === undefined ? {} : { failedClientMessageId }),
229
458
  },
230
459
  ...(retryId === undefined
231
460
  ? {}
232
461
  : { retry: { failedEnvelopeId: failedEnvelopeId, retryId: retryId } }),
233
462
  };
234
463
  }
464
+ /** The request with the failed client message ID, when there is one. */
465
+ function withFailedClientMessageId(request, failedClientMessageId) {
466
+ return failedClientMessageId === undefined ? request : { ...request, failedClientMessageId };
467
+ }
468
+ /** True for a string of 1 to `MAX_MESSAGE_ID_LENGTH` characters. */
469
+ function isMessageId(value) {
470
+ return typeof value === 'string' && value.length >= 1 && value.length <= MAX_MESSAGE_ID_LENGTH;
471
+ }
235
472
  /** Decode canonical base64, or return undefined. */
236
473
  function canonicalBase64Bytes(value) {
237
474
  try {
@@ -1 +1 @@
1
- {"version":3,"file":"retry-request-envelope.js","sourceRoot":"","sources":["../../client/retry-request-envelope.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;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EAAE,GAAG,OAAO,EAAE,qBAAqB,EAAE,CAAC;AAC/F,CAAC;AAED,oEAAoE;AACpE,SAAS,WAAW,CAAC,KAAc;IACjC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,MAAM,IAAI,CAAC,IAAI,KAAK,CAAC,MAAM,IAAI,qBAAqB,CAAC;AACjG,CAAC;AAED,oDAAoD;AACpD,SAAS,oBAAoB,CAAC,KAAa;IACzC,IAAI,CAAC;QACH,MAAM,KAAK,GAAG,aAAa,CAAC,KAAe,CAAC,CAAC;QAC7C,OAAO,aAAa,CAAC,KAAK,CAAC,KAAK,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;IAC5D,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC"}
@@ -0,0 +1,157 @@
1
+ /**
2
+ * The lifecycle of a retry request on the requester device.
3
+ *
4
+ * The request record of a failed envelope owns its retry request from the
5
+ * first post to the answer or to a terminal state. A redelivery of the
6
+ * failed envelope posts nothing while the record exists. A post that fails
7
+ * with a retryable class is posted again by the scheduler at its next
8
+ * attempt time. A post that fails with a conclusive class, the deadline of
9
+ * the record, a failed resend of the last answered attempt, and an
10
+ * exhausted abuse allowance end the request. Each end calls the
11
+ * `onRetryTerminal` hook at least once: the record is marked emitted only
12
+ * after the hook returns. Each request and each scheduler pass also checks
13
+ * the delivery error of the record, as `reportDeliveryError` tells. Each
14
+ * scheduler pass also runs a recovery that the hook did not mark, as
15
+ * `reportDeliveryRecovered` tells.
16
+ */
17
+ import type { Logger } from '../logger.js';
18
+ import type { Envelope } from '../remote/relay/types.js';
19
+ import type { RetryRequest } from '../internal/sesame/types.js';
20
+ import type { ContentHint } from '../types/messages.js';
21
+ import { storeRetryRequest } from '../local/store/reliability.js';
22
+ import type { SignalProtocolClientHooks } from './event-hooks.js';
23
+ import type { RetryFamilyReceive } from './retry-family.js';
24
+ import { type RetryPostOutcome, type RetryRequestDevice } from './retry-request-envelope.js';
25
+ import { type RetryTerminalResetContext, type RetryTerminalResetSteps } from './retry-terminal-recovery.js';
26
+ type RetryRequestStore = Parameters<typeof storeRetryRequest>[0];
27
+ /**
28
+ * What the retry request of one failed decrypt did.
29
+ *
30
+ * - `posted`, `pending`, `terminal`: as `postRetryRequest` gives them. A
31
+ * terminal request also called the hook.
32
+ * - `owned`: the record of the failed envelope owns the request, so a
33
+ * redelivery of the failed envelope posted nothing.
34
+ * - `deferred`: the rate limit refused a member, and the next attempt waits
35
+ * for the end of the limit window.
36
+ * - `skipped`: nothing was posted or stored.
37
+ */
38
+ export type RetryRequestOutcome = RetryPostOutcome | 'owned' | 'deferred' | 'skipped';
39
+ /**
40
+ * Tell whether the receive path acknowledges a failed envelope after its
41
+ * retry request. A failed envelope is acknowledged once a record owns its
42
+ * request. A member is acknowledged only when its request attempt is posted
43
+ * or ended, so a member that waits is delivered again.
44
+ */
45
+ export declare function acknowledgesRetryRequest(outcome: RetryRequestOutcome, member: boolean): boolean;
46
+ /** What the requester uses to ask for a resend after one failed decrypt. */
47
+ export interface RetryRequestSource {
48
+ readonly storage: RetryRequestStore;
49
+ readonly logger: Required<Logger>;
50
+ readonly hooks: SignalProtocolClientHooks | undefined;
51
+ /** The local identity, which sends the request envelope. */
52
+ readonly local: RetryRequestDevice;
53
+ /** The user ID of the failed sender. A new record stores it. */
54
+ readonly senderUserId: string;
55
+ /** The device ID of the failed sender. A new record stores it. */
56
+ readonly senderDeviceId: number;
57
+ /** Spends one request of the rate limit of the sender. False when refused. */
58
+ allow(): boolean;
59
+ /** The rate limit window, for the log line and the cooldown of a member. */
60
+ readonly windowMs: number;
61
+ /** Posts one request envelope. Without it, nothing is posted. */
62
+ readonly send: ((envelope: Envelope) => Promise<unknown>) | undefined;
63
+ /**
64
+ * What the failed envelope itself names. A member is a resend or a null
65
+ * message of a stored request, so the stored record names its failed
66
+ * envelope, and the request ignores these.
67
+ */
68
+ readonly failedEnvelope?: {
69
+ /** The client message ID that the relay delivered with the envelope. */
70
+ readonly clientMessageId?: string;
71
+ /** True when the envelope is a sender-key message. */
72
+ readonly senderKey: boolean;
73
+ /** True when the request record stores the envelope as a group message. */
74
+ readonly groupMessage?: boolean;
75
+ /** The group of the envelope, when the local device knows it. */
76
+ readonly groupId?: string;
77
+ /** The content hint of the envelope, which sets the time of its delivery error. */
78
+ readonly contentHint?: ContentHint;
79
+ };
80
+ /**
81
+ * Creates the request of a new attempt. `senderKey` is true when the
82
+ * failed envelope is a sender-key message, so the request has no ratchet
83
+ * key.
84
+ */
85
+ createRequest(senderKey: boolean): Promise<RetryRequest>;
86
+ /** Arms the scheduler for the next attempt time or the deadline of a record. */
87
+ readonly schedule: ((at: number) => void) | undefined;
88
+ /**
89
+ * The raw group ID of the failed envelope, when it is a group message
90
+ * whose group the receive resolved. A new record stores it, before the
91
+ * group of `failedEnvelope`.
92
+ */
93
+ readonly groupId?: string;
94
+ /** The session reset of an `expired-content` end. Without it, nothing resets. */
95
+ readonly reset: RetryTerminalResetSteps | undefined;
96
+ }
97
+ /**
98
+ * Call the `onRetryTerminal` hook for the terminal state of a request
99
+ * record, once. It reads the record, and when the terminal state is not
100
+ * emitted, it first resets the session of an `expired-content` end with
101
+ * `resetRetryTerminalSession`. It then calls the hook and stores the state
102
+ * as emitted. The other classes reset nothing.
103
+ *
104
+ * The hook is called directly, not through `callHook`, so a hook that
105
+ * throws, and the RelayWorkStopped of a stop or of the reset, propagate and
106
+ * leave the state not emitted. The rule is: mark only after the hook
107
+ * returns, and keep the caller alive. The scheduler logs the error and goes
108
+ * on with the next record, and the receive path does not acknowledge the
109
+ * failed envelope. The next scheduler pass, at the next start or the next
110
+ * armed time, or the redelivery continues the reset from its stored steps
111
+ * and calls the hook again. The record holds no emit count, so a hook that
112
+ * keeps throwing runs once each pass until the record expires.
113
+ */
114
+ export declare function emitRetryTerminal(context: RetryTerminalResetContext, failedEnvelopeId: string): Promise<void>;
115
+ /**
116
+ * Ask for a resend after a failed decrypt, through the retry family of the
117
+ * envelope.
118
+ *
119
+ * - A failed envelope with a record posts nothing and gives `owned`. It
120
+ * only calls the hook for a terminal state that is not emitted. The rate
121
+ * limit does not count it.
122
+ * - A failed envelope with no record spends one request of the rate limit.
123
+ * A refusal stores a record that ends as `abuse-allowance-exhausted`.
124
+ * - A member of a request that ended posts nothing and gives `terminal`.
125
+ * - A member whose stored attempt is answered and is the last attempt, as
126
+ * `answeredLastRetryAttempt` tells, ends the request as
127
+ * `attempts-exhausted` and gives `terminal`. The rate limit does not
128
+ * count it.
129
+ * - A member whose stored attempt is answered, or that has no record,
130
+ * spends one request of the rate limit, unless an earlier refusal set a
131
+ * next attempt time that has not come. A refusal sets that time to the
132
+ * end of the limit window and gives `deferred`.
133
+ * - A member whose stored attempt is not answered posts it again, with no
134
+ * rate limit.
135
+ *
136
+ * After a post, a terminal outcome calls the hook, and any other outcome
137
+ * arms the scheduler for the record. Then, for each failed envelope with
138
+ * an ID, it runs `onDeliveryError` when the error of the record is due,
139
+ * and arms the scheduler for an error that is due later.
140
+ */
141
+ export declare function requestRetryInFamily(family: RetryFamilyReceive, fingerprint: string | undefined, source: RetryRequestSource): Promise<RetryRequestOutcome>;
142
+ /**
143
+ * The context of one scheduler pass: the hooks run through the relay work
144
+ * of the pass. Without `send`, the pass only calls the hooks for terminal
145
+ * states and delivery errors.
146
+ */
147
+ export interface RetryRequestPass {
148
+ readonly storage: RetryRequestStore;
149
+ readonly logger: Required<Logger>;
150
+ readonly hooks: SignalProtocolClientHooks | undefined;
151
+ readonly local: RetryRequestDevice;
152
+ readonly send: ((envelope: Envelope) => Promise<unknown>) | undefined;
153
+ /** The session reset of an `expired-content` end. Without it, nothing resets. */
154
+ readonly reset: RetryTerminalResetSteps | undefined;
155
+ }
156
+ export {};
157
+ //# sourceMappingURL=retry-request-lifecycle.d.ts.map