@open-e2ee/signal-protocol-sdk 14.0.0 → 14.2.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 (406) hide show
  1. package/ADAPTERS.md +5 -5
  2. package/ARCHITECTURE.md +1 -1
  3. package/CHANGELOG.md +461 -0
  4. package/README.md +21 -15
  5. package/SECURITY.md +2 -2
  6. package/TROUBLESHOOTING.md +1 -1
  7. package/client/README.md +35 -22
  8. package/device/README.md +5 -5
  9. package/dist/client/client.d.ts +44 -34
  10. package/dist/client/client.d.ts.map +1 -1
  11. package/dist/client/client.js +221 -146
  12. package/dist/client/client.js.map +1 -1
  13. package/dist/client/compose.d.ts +7 -5
  14. package/dist/client/compose.d.ts.map +1 -1
  15. package/dist/client/compose.js +7 -2
  16. package/dist/client/compose.js.map +1 -1
  17. package/dist/client/config.d.ts +23 -14
  18. package/dist/client/config.d.ts.map +1 -1
  19. package/dist/client/config.js.map +1 -1
  20. package/dist/client/content-adapter.d.ts +9 -0
  21. package/dist/client/content-adapter.d.ts.map +1 -1
  22. package/dist/client/content-adapter.js +6 -0
  23. package/dist/client/content-adapter.js.map +1 -1
  24. package/dist/client/delivery-status.d.ts +2 -2
  25. package/dist/client/delivery-status.d.ts.map +1 -1
  26. package/dist/client/delivery-status.js +10 -4
  27. package/dist/client/delivery-status.js.map +1 -1
  28. package/dist/client/device-set-reconciliation.d.ts +24 -16
  29. package/dist/client/device-set-reconciliation.d.ts.map +1 -1
  30. package/dist/client/device-set-reconciliation.js +17 -14
  31. package/dist/client/device-set-reconciliation.js.map +1 -1
  32. package/dist/client/event-hooks.d.ts +22 -7
  33. package/dist/client/event-hooks.d.ts.map +1 -1
  34. package/dist/client/event-hooks.js +35 -5
  35. package/dist/client/event-hooks.js.map +1 -1
  36. package/dist/client/group-device-set.d.ts +1 -1
  37. package/dist/client/group-device-set.d.ts.map +1 -1
  38. package/dist/client/group-key-sync.js +1 -1
  39. package/dist/client/group-key-sync.js.map +1 -1
  40. package/dist/client/group-outbox.d.ts +7 -7
  41. package/dist/client/group-outbox.d.ts.map +1 -1
  42. package/dist/client/group-outbox.js +24 -24
  43. package/dist/client/group-outbox.js.map +1 -1
  44. package/dist/client/group-sealed-sender.d.ts +1 -1
  45. package/dist/client/group-sealed-sender.d.ts.map +1 -1
  46. package/dist/client/group-sender-key-operations.js +1 -1
  47. package/dist/client/group-sender-key-operations.js.map +1 -1
  48. package/dist/client/headless.d.ts +6 -6
  49. package/dist/client/headless.d.ts.map +1 -1
  50. package/dist/client/headless.js +7 -7
  51. package/dist/client/headless.js.map +1 -1
  52. package/dist/client/hosted-anonymous-delivery.d.ts +18 -6
  53. package/dist/client/hosted-anonymous-delivery.d.ts.map +1 -1
  54. package/dist/client/hosted-anonymous-delivery.js +63 -20
  55. package/dist/client/hosted-anonymous-delivery.js.map +1 -1
  56. package/dist/client/hosted-assertion-id.d.ts +1 -1
  57. package/dist/client/hosted-assertion-id.d.ts.map +1 -1
  58. package/dist/client/hosted-assertion-id.js +1 -1
  59. package/dist/client/hosted-assertion-id.js.map +1 -1
  60. package/dist/client/hosted-connection.d.ts +5 -5
  61. package/dist/client/hosted-connection.d.ts.map +1 -1
  62. package/dist/client/hosted-connection.js +32 -32
  63. package/dist/client/hosted-connection.js.map +1 -1
  64. package/dist/client/hosted-device-link-transport.d.ts +2 -2
  65. package/dist/client/hosted-device-link-transport.d.ts.map +1 -1
  66. package/dist/client/hosted-device-link-transport.js +1 -1
  67. package/dist/client/hosted-device-link-transport.js.map +1 -1
  68. package/dist/client/hosted-device-link.d.ts +5 -1
  69. package/dist/client/hosted-device-link.d.ts.map +1 -1
  70. package/dist/client/hosted-device-link.js +7 -4
  71. package/dist/client/hosted-device-link.js.map +1 -1
  72. package/dist/client/hosted-device-standing.d.ts +13 -5
  73. package/dist/client/hosted-device-standing.d.ts.map +1 -1
  74. package/dist/client/hosted-device-standing.js +11 -6
  75. package/dist/client/hosted-device-standing.js.map +1 -1
  76. package/dist/client/hosted-group-authority.d.ts +2 -2
  77. package/dist/client/hosted-group-authority.d.ts.map +1 -1
  78. package/dist/client/hosted-group-authority.js +8 -8
  79. package/dist/client/hosted-group-authority.js.map +1 -1
  80. package/dist/client/hosted-groups.d.ts +4 -4
  81. package/dist/client/hosted-groups.d.ts.map +1 -1
  82. package/dist/client/hosted-groups.js +8 -8
  83. package/dist/client/hosted-groups.js.map +1 -1
  84. package/dist/client/hosted-http-error.d.ts +8 -4
  85. package/dist/client/hosted-http-error.d.ts.map +1 -1
  86. package/dist/client/hosted-http-error.js +7 -4
  87. package/dist/client/hosted-http-error.js.map +1 -1
  88. package/dist/client/hosted-mailbox-subscription.d.ts +16 -15
  89. package/dist/client/hosted-mailbox-subscription.d.ts.map +1 -1
  90. package/dist/client/hosted-mailbox-subscription.js +21 -25
  91. package/dist/client/hosted-mailbox-subscription.js.map +1 -1
  92. package/dist/client/hosted-prekey-publication.d.ts +9 -9
  93. package/dist/client/hosted-prekey-publication.d.ts.map +1 -1
  94. package/dist/client/hosted-prekey-publication.js.map +1 -1
  95. package/dist/client/hosted-presence-frames.d.ts +62 -38
  96. package/dist/client/hosted-presence-frames.d.ts.map +1 -1
  97. package/dist/client/hosted-presence-frames.js +4 -2
  98. package/dist/client/hosted-presence-frames.js.map +1 -1
  99. package/dist/client/hosted-presence.d.ts +22 -14
  100. package/dist/client/hosted-presence.d.ts.map +1 -1
  101. package/dist/client/hosted-presence.js +26 -17
  102. package/dist/client/hosted-presence.js.map +1 -1
  103. package/dist/client/hosted-profile-keys.d.ts +3 -1
  104. package/dist/client/hosted-profile-keys.d.ts.map +1 -1
  105. package/dist/client/hosted-profile-keys.js +19 -15
  106. package/dist/client/hosted-profile-keys.js.map +1 -1
  107. package/dist/client/hosted-push.d.ts +38 -16
  108. package/dist/client/hosted-push.d.ts.map +1 -1
  109. package/dist/client/hosted-push.js +11 -5
  110. package/dist/client/hosted-push.js.map +1 -1
  111. package/dist/client/hosted-resume-error.d.ts +21 -9
  112. package/dist/client/hosted-resume-error.d.ts.map +1 -1
  113. package/dist/client/hosted-resume-error.js +4 -1
  114. package/dist/client/hosted-resume-error.js.map +1 -1
  115. package/dist/client/hosted-resume.d.ts +3 -3
  116. package/dist/client/hosted-resume.d.ts.map +1 -1
  117. package/dist/client/hosted-resume.js +12 -12
  118. package/dist/client/hosted-resume.js.map +1 -1
  119. package/dist/client/hosted-sandbox-identity.d.ts +82 -5
  120. package/dist/client/hosted-sandbox-identity.d.ts.map +1 -1
  121. package/dist/client/hosted-sandbox-identity.js +160 -50
  122. package/dist/client/hosted-sandbox-identity.js.map +1 -1
  123. package/dist/client/hosted-store-records.d.ts +46 -0
  124. package/dist/client/hosted-store-records.d.ts.map +1 -0
  125. package/dist/client/hosted-store-records.js +32 -0
  126. package/dist/client/hosted-store-records.js.map +1 -0
  127. package/dist/client/hosted-transport.d.ts +53 -33
  128. package/dist/client/hosted-transport.d.ts.map +1 -1
  129. package/dist/client/hosted-transport.js +225 -138
  130. package/dist/client/hosted-transport.js.map +1 -1
  131. package/dist/client/hosted-trust.d.ts +1 -1
  132. package/dist/client/hosted-trust.d.ts.map +1 -1
  133. package/dist/client/hosted-trust.js +1 -1
  134. package/dist/client/hosted-trust.js.map +1 -1
  135. package/dist/client/hosted.d.ts +144 -75
  136. package/dist/client/hosted.d.ts.map +1 -1
  137. package/dist/client/hosted.js +106 -61
  138. package/dist/client/hosted.js.map +1 -1
  139. package/dist/client/index.d.ts +4 -4
  140. package/dist/client/index.d.ts.map +1 -1
  141. package/dist/client/index.js +4 -4
  142. package/dist/client/index.js.map +1 -1
  143. package/dist/client/key-rotation-core.d.ts +4 -4
  144. package/dist/client/key-rotation-core.d.ts.map +1 -1
  145. package/dist/client/key-rotation-core.js +8 -8
  146. package/dist/client/key-rotation-core.js.map +1 -1
  147. package/dist/client/key-rotation.js +2 -2
  148. package/dist/client/key-rotation.js.map +1 -1
  149. package/dist/client/messages.d.ts +3 -3
  150. package/dist/client/messages.d.ts.map +1 -1
  151. package/dist/client/messages.js +18 -18
  152. package/dist/client/messages.js.map +1 -1
  153. package/dist/client/one-time-prekey-refill.d.ts +1 -1
  154. package/dist/client/one-time-prekey-refill.d.ts.map +1 -1
  155. package/dist/client/prekeys.js +17 -17
  156. package/dist/client/prekeys.js.map +1 -1
  157. package/dist/client/receive-queue.d.ts +4 -4
  158. package/dist/client/receive-queue.d.ts.map +1 -1
  159. package/dist/client/receive-queue.js +29 -29
  160. package/dist/client/receive-queue.js.map +1 -1
  161. package/dist/client/receive-work-seed.d.ts +6 -2
  162. package/dist/client/receive-work-seed.d.ts.map +1 -1
  163. package/dist/client/receive-work-seed.js.map +1 -1
  164. package/dist/client/recovery-driver.js +7 -7
  165. package/dist/client/recovery-driver.js.map +1 -1
  166. package/dist/client/retry-request-envelope.d.ts +3 -3
  167. package/dist/client/retry-request-envelope.d.ts.map +1 -1
  168. package/dist/client/retry-request-envelope.js +10 -10
  169. package/dist/client/retry-request-envelope.js.map +1 -1
  170. package/dist/client/retry-request-lifecycle.d.ts +1 -1
  171. package/dist/client/retry-request-lifecycle.d.ts.map +1 -1
  172. package/dist/client/retry-request-lifecycle.js +8 -8
  173. package/dist/client/retry-request-lifecycle.js.map +1 -1
  174. package/dist/client/retry-terminal-recovery.js +2 -2
  175. package/dist/client/retry-terminal-recovery.js.map +1 -1
  176. package/dist/client/retry.js +13 -13
  177. package/dist/client/retry.js.map +1 -1
  178. package/dist/client/sealed-sender.d.ts +13 -4
  179. package/dist/client/sealed-sender.d.ts.map +1 -1
  180. package/dist/client/sealed-sender.js +27 -15
  181. package/dist/client/sealed-sender.js.map +1 -1
  182. package/dist/client/send-deadline.d.ts +8 -7
  183. package/dist/client/send-deadline.d.ts.map +1 -1
  184. package/dist/client/send-deadline.js +41 -23
  185. package/dist/client/send-deadline.js.map +1 -1
  186. package/dist/client/send-intent-driver.js +9 -9
  187. package/dist/client/send-intent-driver.js.map +1 -1
  188. package/dist/client/sessions.js +11 -11
  189. package/dist/client/sessions.js.map +1 -1
  190. package/dist/client/{relay-acceptance.d.ts → signal-relay-acceptance.d.ts} +9 -9
  191. package/dist/client/signal-relay-acceptance.d.ts.map +1 -0
  192. package/dist/client/{relay-acceptance.js → signal-relay-acceptance.js} +7 -7
  193. package/dist/client/signal-relay-acceptance.js.map +1 -0
  194. package/dist/client/{relay-device-refusal.d.ts → signal-relay-device-refusal.d.ts} +7 -7
  195. package/dist/client/signal-relay-device-refusal.d.ts.map +1 -0
  196. package/dist/client/{relay-device-refusal.js → signal-relay-device-refusal.js} +9 -9
  197. package/dist/client/signal-relay-device-refusal.js.map +1 -0
  198. package/dist/client/{relay-lifecycle.d.ts → signal-relay-lifecycle.d.ts} +21 -11
  199. package/dist/client/signal-relay-lifecycle.d.ts.map +1 -0
  200. package/dist/client/{relay-lifecycle.js → signal-relay-lifecycle.js} +19 -9
  201. package/dist/client/signal-relay-lifecycle.js.map +1 -0
  202. package/dist/client/signal-relay-period-close.d.ts +35 -0
  203. package/dist/client/signal-relay-period-close.d.ts.map +1 -0
  204. package/dist/client/signal-relay-period-close.js +63 -0
  205. package/dist/client/signal-relay-period-close.js.map +1 -0
  206. package/dist/client/{relay-protocol.d.ts → signal-relay-protocol.d.ts} +12 -8
  207. package/dist/client/signal-relay-protocol.d.ts.map +1 -0
  208. package/dist/client/{relay-protocol.js → signal-relay-protocol.js} +13 -10
  209. package/dist/client/signal-relay-protocol.js.map +1 -0
  210. package/dist/client/{relay-receipt-intake.d.ts → signal-relay-receipt-intake.d.ts} +12 -12
  211. package/dist/client/signal-relay-receipt-intake.d.ts.map +1 -0
  212. package/dist/client/{relay-receipt-intake.js → signal-relay-receipt-intake.js} +9 -9
  213. package/dist/client/signal-relay-receipt-intake.js.map +1 -0
  214. package/dist/client/{relay-receipt-join.d.ts → signal-relay-receipt-join.d.ts} +8 -8
  215. package/dist/client/signal-relay-receipt-join.d.ts.map +1 -0
  216. package/dist/client/{relay-receipt-join.js → signal-relay-receipt-join.js} +11 -11
  217. package/dist/client/signal-relay-receipt-join.js.map +1 -0
  218. package/dist/client/{relay-request-deadline.d.ts → signal-relay-request-deadline.d.ts} +3 -3
  219. package/dist/client/signal-relay-request-deadline.d.ts.map +1 -0
  220. package/dist/client/{relay-request-deadline.js → signal-relay-request-deadline.js} +4 -4
  221. package/dist/client/signal-relay-request-deadline.js.map +1 -0
  222. package/dist/client/{relay-sealed-route.d.ts → signal-relay-sealed-route.d.ts} +1 -1
  223. package/dist/client/signal-relay-sealed-route.d.ts.map +1 -0
  224. package/dist/client/{relay-sealed-route.js → signal-relay-sealed-route.js} +1 -1
  225. package/dist/client/signal-relay-sealed-route.js.map +1 -0
  226. package/dist/client/{relay-subscription.d.ts → signal-relay-subscription.d.ts} +12 -12
  227. package/dist/client/signal-relay-subscription.d.ts.map +1 -0
  228. package/dist/client/{relay-subscription.js → signal-relay-subscription.js} +23 -23
  229. package/dist/client/signal-relay-subscription.js.map +1 -0
  230. package/dist/client/{relay-work.d.ts → signal-relay-work.d.ts} +7 -7
  231. package/dist/client/signal-relay-work.d.ts.map +1 -0
  232. package/dist/client/{relay-work.js → signal-relay-work.js} +13 -13
  233. package/dist/client/signal-relay-work.js.map +1 -0
  234. package/dist/client/signal-service-cipher.d.ts +11 -9
  235. package/dist/client/signal-service-cipher.d.ts.map +1 -1
  236. package/dist/client/signal-service-cipher.js +103 -98
  237. package/dist/client/signal-service-cipher.js.map +1 -1
  238. package/dist/client/state.d.ts +4 -4
  239. package/dist/client/state.d.ts.map +1 -1
  240. package/dist/client/state.js +3 -3
  241. package/dist/client/state.js.map +1 -1
  242. package/dist/client/types.d.ts +13 -4
  243. package/dist/client/types.d.ts.map +1 -1
  244. package/dist/client/types.js.map +1 -1
  245. package/dist/device/connection.d.ts +10 -4
  246. package/dist/device/connection.d.ts.map +1 -1
  247. package/dist/device/connection.js +8 -3
  248. package/dist/device/connection.js.map +1 -1
  249. package/dist/device/index.d.ts +2 -2
  250. package/dist/device/index.d.ts.map +1 -1
  251. package/dist/device/index.js +1 -1
  252. package/dist/device/index.js.map +1 -1
  253. package/dist/device/types.d.ts +3 -1
  254. package/dist/device/types.d.ts.map +1 -1
  255. package/dist/hooks/index.d.ts +2 -2
  256. package/dist/hooks/index.d.ts.map +1 -1
  257. package/dist/hooks/index.js +2 -2
  258. package/dist/hooks/index.js.map +1 -1
  259. package/dist/hooks/use-signal-relay-connection-state.d.ts +40 -0
  260. package/dist/hooks/use-signal-relay-connection-state.d.ts.map +1 -0
  261. package/dist/hooks/use-signal-relay-connection-state.js +45 -0
  262. package/dist/hooks/use-signal-relay-connection-state.js.map +1 -0
  263. package/dist/hooks/use-signal-relay-lifecycle.d.ts +43 -0
  264. package/dist/hooks/use-signal-relay-lifecycle.d.ts.map +1 -0
  265. package/dist/hooks/use-signal-relay-lifecycle.js +38 -0
  266. package/dist/hooks/use-signal-relay-lifecycle.js.map +1 -0
  267. package/dist/index.d.ts +18 -12
  268. package/dist/index.d.ts.map +1 -1
  269. package/dist/index.js +5 -5
  270. package/dist/index.js.map +1 -1
  271. package/dist/internal/groups/authority-certificate.d.ts +7 -1
  272. package/dist/internal/groups/authority-certificate.d.ts.map +1 -1
  273. package/dist/internal/groups/authority-certificate.js +29 -6
  274. package/dist/internal/groups/authority-certificate.js.map +1 -1
  275. package/dist/internal/protocol/sealed-sender/certificate.js +2 -2
  276. package/dist/internal/protocol/sealed-sender/certificate.js.map +1 -1
  277. package/dist/internal/protocol/sealed-sender/proto/index.d.ts +1 -1
  278. package/dist/internal/protocol/sealed-sender/proto/index.d.ts.map +1 -1
  279. package/dist/internal/protocol/sealed-sender/proto/index.js +5 -5
  280. package/dist/internal/protocol/sealed-sender/proto/index.js.map +1 -1
  281. package/dist/internal/sesame/device-registry.d.ts +13 -13
  282. package/dist/internal/sesame/device-registry.d.ts.map +1 -1
  283. package/dist/internal/sesame/device-registry.js +20 -20
  284. package/dist/internal/sesame/device-registry.js.map +1 -1
  285. package/dist/local/store/receive-work.d.ts +29 -0
  286. package/dist/local/store/receive-work.d.ts.map +1 -1
  287. package/dist/local/store/receive-work.js +58 -1
  288. package/dist/local/store/receive-work.js.map +1 -1
  289. package/dist/local/store/received-content.d.ts +1 -1
  290. package/dist/local/store/received-content.d.ts.map +1 -1
  291. package/dist/local/store/reliability.d.ts +11 -3
  292. package/dist/local/store/reliability.d.ts.map +1 -1
  293. package/dist/local/store/reliability.js +4 -0
  294. package/dist/local/store/reliability.js.map +1 -1
  295. package/dist/local/store/sqlite/key-storage/index.d.ts +3 -9
  296. package/dist/local/store/sqlite/key-storage/index.d.ts.map +1 -1
  297. package/dist/local/store/sqlite/key-storage/index.js.map +1 -1
  298. package/dist/local/store/sqlite/key-storage/signed-prekeys.d.ts +1 -7
  299. package/dist/local/store/sqlite/key-storage/signed-prekeys.d.ts.map +1 -1
  300. package/dist/local/store/sqlite/key-storage/signed-prekeys.js.map +1 -1
  301. package/dist/local/store/sqlite/models/kyber-prekey.d.ts +4 -9
  302. package/dist/local/store/sqlite/models/kyber-prekey.d.ts.map +1 -1
  303. package/dist/local/store/sqlite/models/kyber-prekey.js +4 -1
  304. package/dist/local/store/sqlite/models/kyber-prekey.js.map +1 -1
  305. package/dist/local/store/sqlite/store.d.ts.map +1 -1
  306. package/dist/local/store/sqlite/store.js +1 -2
  307. package/dist/local/store/sqlite/store.js.map +1 -1
  308. package/dist/remote/signal-relay/connection-state.d.ts +16 -0
  309. package/dist/remote/signal-relay/connection-state.d.ts.map +1 -0
  310. package/dist/remote/{relay → signal-relay}/connection-state.js +1 -1
  311. package/dist/remote/signal-relay/connection-state.js.map +1 -0
  312. package/dist/remote/{relay → signal-relay}/device-set.d.ts +3 -3
  313. package/dist/remote/signal-relay/device-set.d.ts.map +1 -0
  314. package/dist/remote/{relay → signal-relay}/device-set.js +7 -7
  315. package/dist/remote/signal-relay/device-set.js.map +1 -0
  316. package/dist/remote/{relay → signal-relay}/index.d.ts +3 -3
  317. package/dist/remote/signal-relay/index.d.ts.map +1 -0
  318. package/dist/remote/{relay → signal-relay}/index.js +2 -2
  319. package/dist/remote/signal-relay/index.js.map +1 -0
  320. package/dist/remote/{relay → signal-relay}/request-admission.d.ts +7 -5
  321. package/dist/remote/signal-relay/request-admission.d.ts.map +1 -0
  322. package/dist/remote/{relay → signal-relay}/request-admission.js +7 -6
  323. package/dist/remote/signal-relay/request-admission.js.map +1 -0
  324. package/dist/remote/{relay → signal-relay}/types.d.ts +30 -12
  325. package/dist/remote/signal-relay/types.d.ts.map +1 -0
  326. package/dist/remote/{relay → signal-relay}/types.js +1 -1
  327. package/dist/remote/signal-relay/types.js.map +1 -0
  328. package/dist/safety/core.d.ts +1 -1
  329. package/dist/safety/core.js +1 -1
  330. package/dist/types/api.d.ts +43 -20
  331. package/dist/types/api.d.ts.map +1 -1
  332. package/dist/types/errors.d.ts +55 -7
  333. package/dist/types/errors.d.ts.map +1 -1
  334. package/dist/types/errors.js +61 -8
  335. package/dist/types/errors.js.map +1 -1
  336. package/dist/types/renamed-member.d.ts +41 -0
  337. package/dist/types/renamed-member.d.ts.map +1 -0
  338. package/dist/types/renamed-member.js +73 -0
  339. package/dist/types/renamed-member.js.map +1 -0
  340. package/dist/utils/bounded-fan-out.d.ts +2 -2
  341. package/dist/utils/bounded-fan-out.d.ts.map +1 -1
  342. package/dist/utils/bounded-fan-out.js +2 -2
  343. package/dist/utils/bounded-fan-out.js.map +1 -1
  344. package/dist/utils/retry.d.ts +3 -3
  345. package/dist/utils/retry.d.ts.map +1 -1
  346. package/dist/utils/retry.js +4 -3
  347. package/dist/utils/retry.js.map +1 -1
  348. package/docs/ASSURANCE.md +8 -8
  349. package/docs/CLIENT_COMPOSITION.md +11 -7
  350. package/docs/DEVIATIONS.md +58 -8
  351. package/docs/ERROR_HANDLING.md +24 -24
  352. package/docs/GETTING_STARTED.md +25 -16
  353. package/docs/INTERFACES.md +5 -5
  354. package/docs/PACKAGE_SURFACE.md +14 -4
  355. package/docs/PROTOCOL_POLICY.md +4 -4
  356. package/docs/RECIPES.md +274 -15
  357. package/hooks/README.md +11 -11
  358. package/local/store/expo/README.md +1 -1
  359. package/local/store/key-value/README.md +2 -2
  360. package/local/store/node/README.md +1 -1
  361. package/local/store/react-native/README.md +1 -1
  362. package/local/store/web/README.md +1 -1
  363. package/local/store/web-sqlite/README.md +2 -2
  364. package/package.json +22 -7
  365. package/remote/README.md +4 -4
  366. package/remote/object-store/convex-r2/README.md +1 -1
  367. package/remote/{relay → signal-relay}/README.md +16 -6
  368. package/dist/client/relay-acceptance.d.ts.map +0 -1
  369. package/dist/client/relay-acceptance.js.map +0 -1
  370. package/dist/client/relay-device-refusal.d.ts.map +0 -1
  371. package/dist/client/relay-device-refusal.js.map +0 -1
  372. package/dist/client/relay-lifecycle.d.ts.map +0 -1
  373. package/dist/client/relay-lifecycle.js.map +0 -1
  374. package/dist/client/relay-protocol.d.ts.map +0 -1
  375. package/dist/client/relay-protocol.js.map +0 -1
  376. package/dist/client/relay-receipt-intake.d.ts.map +0 -1
  377. package/dist/client/relay-receipt-intake.js.map +0 -1
  378. package/dist/client/relay-receipt-join.d.ts.map +0 -1
  379. package/dist/client/relay-receipt-join.js.map +0 -1
  380. package/dist/client/relay-request-deadline.d.ts.map +0 -1
  381. package/dist/client/relay-request-deadline.js.map +0 -1
  382. package/dist/client/relay-sealed-route.d.ts.map +0 -1
  383. package/dist/client/relay-sealed-route.js.map +0 -1
  384. package/dist/client/relay-subscription.d.ts.map +0 -1
  385. package/dist/client/relay-subscription.js.map +0 -1
  386. package/dist/client/relay-work.d.ts.map +0 -1
  387. package/dist/client/relay-work.js.map +0 -1
  388. package/dist/hooks/use-relay-connection-state.d.ts +0 -32
  389. package/dist/hooks/use-relay-connection-state.d.ts.map +0 -1
  390. package/dist/hooks/use-relay-connection-state.js +0 -31
  391. package/dist/hooks/use-relay-connection-state.js.map +0 -1
  392. package/dist/hooks/use-relay-lifecycle.d.ts +0 -36
  393. package/dist/hooks/use-relay-lifecycle.d.ts.map +0 -1
  394. package/dist/hooks/use-relay-lifecycle.js +0 -35
  395. package/dist/hooks/use-relay-lifecycle.js.map +0 -1
  396. package/dist/remote/relay/connection-state.d.ts +0 -16
  397. package/dist/remote/relay/connection-state.d.ts.map +0 -1
  398. package/dist/remote/relay/connection-state.js.map +0 -1
  399. package/dist/remote/relay/device-set.d.ts.map +0 -1
  400. package/dist/remote/relay/device-set.js.map +0 -1
  401. package/dist/remote/relay/index.d.ts.map +0 -1
  402. package/dist/remote/relay/index.js.map +0 -1
  403. package/dist/remote/relay/request-admission.d.ts.map +0 -1
  404. package/dist/remote/relay/request-admission.js.map +0 -1
  405. package/dist/remote/relay/types.d.ts.map +0 -1
  406. package/dist/remote/relay/types.js.map +0 -1
@@ -1,28 +1,33 @@
1
- import { HostedRelayResumeError } from './hosted-resume-error.js';
1
+ import { HostedSignalProtocolRelayResumeError } from './hosted-resume-error.js';
2
2
  import { hostedAssertionIdentifier } from "./hosted-assertion-id.js";
3
- import { HostedRelayHttpError } from "./hosted-http-error.js";
4
- import { submitHostedRelayDeviceLink } from "./hosted-device-link-transport.js";
3
+ import { HostedSignalProtocolRelayHttpError } from "./hosted-http-error.js";
4
+ import { submitHostedSignalProtocolRelayDeviceLink } from "./hosted-device-link-transport.js";
5
5
  import { utf8Decode, websocketUrl } from "../internal/platform/index.js";
6
6
  import AsyncLock from "async-lock";
7
7
  import { createCompositeIdentityV1, decodeCompositeIdentityV1, encodeCompositeIdentityV1, } from "../keys/identity.js";
8
8
  import { base64ToBytes, bytesToBase64, bytesToUrlSafeBase64, concatBytes, generateRandomBytes, generateUuidV4, sha256, stringToBytes, urlSafeToBase64, } from "../internal/crypto/index.js";
9
9
  import { RemoteObjectUploadError } from "../remote/object-store/index.js";
10
- import { RelayConnectionStateOwner } from "../remote/relay/connection-state.js";
10
+ import { SignalProtocolRelayConnectionStateOwner } from "../remote/signal-relay/connection-state.js";
11
11
  import { presenceHttpBody, } from "./hosted-presence-frames.js";
12
12
  import { subscribeHostedMailbox, } from "./hosted-mailbox-subscription.js";
13
13
  import { HostedGroupServer } from "./hosted-groups.js";
14
- import { RELAY_PROTOCOL_VERSION, markRelayAnswerVersion, relayProtocolHeadersFor, throwIfUpgradeRequired, } from "./relay-protocol.js";
15
- import { HostedRelayDeviceUnknownError, throwIfDeviceRevoked, } from "./hosted-device-standing.js";
14
+ import { RELAY_PROTOCOL_VERSION, markSignalProtocolRelayAnswerVersion, signalRelayProtocolHeadersFor, throwIfUpgradeRequired, } from "./signal-relay-protocol.js";
15
+ import { HostedSignalProtocolRelayDeviceUnknownError, throwIfDeviceRevoked, } from "./hosted-device-standing.js";
16
16
  import { HostedAnonymousDelivery, HostedAnonymousDeliveryError, decodeHostedAnonymousEnvelope, } from "./hosted-anonymous-delivery.js";
17
- import { createAdapterRelayFanOut } from "./relay-work.js";
18
- import { withRelayRequestDeadline } from "./relay-request-deadline.js";
17
+ import { createAdapterSignalProtocolRelayFanOut, rethrowSignalProtocolRelayWorkStopped } from "./signal-relay-work.js";
18
+ import { withSignalProtocolRelayRequestDeadline } from "./signal-relay-request-deadline.js";
19
19
  import { applyPreKeyUploads, parseHostedPreKeyStatus, parseStoredPendingPublication, parseStoredPublication, publicationMatchesStatus, registrationPreKey, statusPreKeys, storedPreKey, storedPublication, } from "./hosted-prekey-publication.js";
20
- import { declareRefusesRemovedDevices, markRelayDeviceRefusal, } from "./relay-device-refusal.js";
21
- import { declareComparesDeviceSets, deviceSetRefusal, markDeviceSetRefusal, parseDeviceSetRefusal, } from "../remote/relay/device-set.js";
22
- import { admitRepeatRequest, markAfterRepeatedRequest, } from "../remote/relay/request-admission.js";
23
- import { RelayReceiptInbox, declareRelayReceiptIntake, decodeRelayDeliveryReceipts, } from "./relay-receipt-intake.js";
24
- import { RelayReceiptJoin, declareRelayReceiptJoin, } from "./relay-receipt-join.js";
25
- const SESSION_METADATA_PREFIX = "hostedRelay.session.v1:";
20
+ import { declareRefusesRemovedDevices, markSignalProtocolRelayDeviceRefusal, } from "./signal-relay-device-refusal.js";
21
+ import { onePeriodClosedRetry } from "./signal-relay-period-close.js";
22
+ import { declareComparesDeviceSets, deviceSetRefusal, markDeviceSetRefusal, parseDeviceSetRefusal, } from "../remote/signal-relay/device-set.js";
23
+ import { admitRepeatRequest, markAfterRepeatedRequest, } from "../remote/signal-relay/request-admission.js";
24
+ import { SignalProtocolRelayReceiptInbox, declareSignalProtocolRelayReceiptIntake, decodeSignalProtocolRelayDeliveryReceipts, } from "./signal-relay-receipt-intake.js";
25
+ import { SignalProtocolRelayReceiptJoin, declareSignalProtocolRelayReceiptJoin, } from "./signal-relay-receipt-join.js";
26
+ import { hostedStoreRecordKey, readHostedStoreRecord, writeHostedStoreRecord, } from "./hosted-store-records.js";
27
+ const SESSION_METADATA_PREFIX = {
28
+ current: "signalRelay.session.v2:",
29
+ earlier: "hostedRelay.session.v1:",
30
+ };
26
31
  const DEVICE_TOKEN_REFRESH_SECONDS = 60;
27
32
  const MAXIMUM_RESPONSE_BYTES = 1024 * 1024;
28
33
  const PREKEY_EXPIRY_MILLISECONDS = 30 * 24 * 60 * 60 * 1000;
@@ -69,7 +74,7 @@ const CONCLUSIVE_REFUSAL_CODES = new Set([
69
74
  * outage, is not conclusive.
70
75
  */
71
76
  function isConclusiveRefusal(error) {
72
- return (error instanceof HostedRelayHttpError &&
77
+ return (error instanceof HostedSignalProtocolRelayHttpError &&
73
78
  !error.retryable &&
74
79
  CONCLUSIVE_REFUSAL_CODES.has(error.code));
75
80
  }
@@ -87,7 +92,7 @@ async function withOneUncertainRetry(deliveryClass, post, beforeRepeat) {
87
92
  }
88
93
  catch (error) {
89
94
  if (deliveryClass === "ephemeral" ||
90
- !(error instanceof HostedRelayHttpError) ||
95
+ !(error instanceof HostedSignalProtocolRelayHttpError) ||
91
96
  error.code !== "DELIVERY_UNCERTAIN") {
92
97
  throw error;
93
98
  }
@@ -151,7 +156,7 @@ function decodeBase64Url(value, label) {
151
156
  throw new Error(`${label} is invalid`);
152
157
  }
153
158
  }
154
- function relayScopeId(connection) {
159
+ function signalProtocolRelayScopeId(connection) {
155
160
  return bytesToUrlSafeBase64(connection.relayScopeId);
156
161
  }
157
162
  function identifiedEndpoint(connection) {
@@ -159,10 +164,10 @@ function identifiedEndpoint(connection) {
159
164
  }
160
165
  /**
161
166
  * Read the body of a Relay answer. An error answer throws, and the error
162
- * records `relayProtocolVersion`, the protocol version of the request that
167
+ * records `signalRelayProtocolVersion`, the protocol version of the request that
163
168
  * it answers.
164
169
  */
165
- async function parseResponse(response, relayProtocolVersion) {
170
+ async function parseResponse(response, signalRelayProtocolVersion) {
166
171
  const body = await response.text();
167
172
  if (body.length > MAXIMUM_RESPONSE_BYTES) {
168
173
  throw new Error("Signal Protocol Relay response is too large");
@@ -183,11 +188,11 @@ async function parseResponse(response, relayProtocolVersion) {
183
188
  if (!response.ok) {
184
189
  // `UPGRADE_REQUIRED` and `DEVICE_REVOKED` are terminal at any error
185
190
  // status, so `authenticatedPost` and every other retry, which matches only
186
- // a `HostedRelayHttpError`, never repeat them. `PROTOCOL_UNSUPPORTED`
187
- // stays a `HostedRelayHttpError` whose `retryable` is true: the Relay
191
+ // a `HostedSignalProtocolRelayHttpError`, never repeat them. `PROTOCOL_UNSUPPORTED`
192
+ // stays a `HostedSignalProtocolRelayHttpError` whose `retryable` is true: the Relay
188
193
  // sends it for a version above the newest one that it serves, which
189
194
  // happens only after a Relay rollback.
190
- throwIfUpgradeRequired(response.status, parsed, relayProtocolVersion);
195
+ throwIfUpgradeRequired(response.status, parsed, signalRelayProtocolVersion);
191
196
  throwIfDeviceRevoked(response.status, parsed);
192
197
  const error = record(parsed) && record(parsed.error) ? parsed.error : {};
193
198
  const code = typeof error.code === "string" ? error.code : "UNKNOWN";
@@ -196,10 +201,10 @@ async function parseResponse(response, relayProtocolVersion) {
196
201
  : "Signal Protocol Relay request failed";
197
202
  // A refused declared post names the devices of each account in
198
203
  // `details`. The error keeps them for the device-set reconciliation.
199
- throw markRelayAnswerVersion(new HostedRelayHttpError(response.status, code, message, {
204
+ throw markSignalProtocolRelayAnswerVersion(new HostedSignalProtocolRelayHttpError(response.status, code, message, {
200
205
  ...(record(error.details) ? { data: { details: error.details } } : {}),
201
206
  retryable: error.retryable === true,
202
- }), relayProtocolVersion);
207
+ }), signalRelayProtocolVersion);
203
208
  }
204
209
  return parsed;
205
210
  }
@@ -208,17 +213,17 @@ async function parseResponse(response, relayProtocolVersion) {
208
213
  * generation names it. The Relay refuses such a device as NOT_FOUND.
209
214
  */
210
215
  function missingDestination(userId, deviceId) {
211
- return markRelayDeviceRefusal(new Error("Signal Protocol Relay destination device does not exist"), { code: "NOT_FOUND", userId, deviceId });
216
+ return markSignalProtocolRelayDeviceRefusal(new Error("Signal Protocol Relay destination device does not exist"), { code: "NOT_FOUND", userId, deviceId });
212
217
  }
213
- async function postJson(connection, relayProtocolVersion, path, body, token) {
218
+ async function postJson(connection, signalRelayProtocolVersion, path, body, token) {
214
219
  const headers = new Headers({
215
220
  accept: "application/json",
216
221
  "content-type": "application/json",
217
- ...relayProtocolHeadersFor(relayProtocolVersion),
222
+ ...signalRelayProtocolHeadersFor(signalRelayProtocolVersion),
218
223
  });
219
224
  if (token !== undefined)
220
225
  headers.set("authorization", `Bearer ${token}`);
221
- return withRelayRequestDeadline(async (signal) => {
226
+ return withSignalProtocolRelayRequestDeadline(async (signal) => {
222
227
  let response;
223
228
  try {
224
229
  response = await fetch(`${identifiedEndpoint(connection)}${path}`, {
@@ -233,7 +238,7 @@ async function postJson(connection, relayProtocolVersion, path, body, token) {
233
238
  catch (cause) {
234
239
  throw new Error("Signal Protocol Relay request could not be completed", { cause });
235
240
  }
236
- return parseResponse(response, relayProtocolVersion);
241
+ return parseResponse(response, signalRelayProtocolVersion);
237
242
  });
238
243
  }
239
244
  function serializedPreKey(prekey) {
@@ -276,10 +281,10 @@ async function registrationMaterialFingerprint(identity, registrationId, prekeys
276
281
  async function registrationChallenge(request) {
277
282
  return sha256(concatBytes(request.assertionPurpose === "recover"
278
283
  ? RECOVERY_CHALLENGE_LABEL
279
- : REGISTRATION_CHALLENGE_LABEL, text(relayScopeId(request.connection)), text(await hostedAssertionIdentifier(request.assertion, request.assertionPurpose, request.operationId)), text(request.operationId), text(await registrationMaterialFingerprint(request.signalIdentity, request.registrationId, request.registrationPreKeys))));
284
+ : REGISTRATION_CHALLENGE_LABEL, text(signalProtocolRelayScopeId(request.connection)), text(await hostedAssertionIdentifier(request.assertion, request.assertionPurpose, request.operationId)), text(request.operationId), text(await registrationMaterialFingerprint(request.signalIdentity, request.registrationId, request.registrationPreKeys))));
280
285
  }
281
286
  async function sessionMetadataKey(connection) {
282
- return `${SESSION_METADATA_PREFIX}${bytesToUrlSafeBase64(await sha256(concatBytes(stringToBytes(connection.publishableKey), new Uint8Array([0]), connection.relayScopeId)))}`;
287
+ return hostedStoreRecordKey(SESSION_METADATA_PREFIX, bytesToUrlSafeBase64(await sha256(concatBytes(stringToBytes(connection.publishableKey), new Uint8Array([0]), connection.relayScopeId))));
283
288
  }
284
289
  function parseSession(value, connection) {
285
290
  let parsed;
@@ -302,7 +307,7 @@ function parseSession(value, connection) {
302
307
  parsed.generation < 0 ||
303
308
  !Number.isSafeInteger(parsed.mailboxGeneration) ||
304
309
  parsed.mailboxGeneration < 0 ||
305
- parsed.relayScopeId !== relayScopeId(connection)) {
310
+ parsed.relayScopeId !== signalProtocolRelayScopeId(connection)) {
306
311
  throw new Error("Stored Signal Protocol Relay session is invalid");
307
312
  }
308
313
  return {
@@ -316,6 +321,19 @@ function parseSession(value, connection) {
316
321
  relayScopeId: parsed.relayScopeId,
317
322
  };
318
323
  }
324
+ /**
325
+ * The scope claim of a device token. Protocol version 3 names the claim
326
+ * `signal_relay_scope_id`, and protocol versions 1 and 2 name it
327
+ * `relay_scope_id`. A token that carries both claims with different values
328
+ * has no scope.
329
+ */
330
+ function deviceTokenScopeId(claims) {
331
+ const scope = claims.signal_relay_scope_id;
332
+ const earlierScope = claims.relay_scope_id;
333
+ if (scope === undefined)
334
+ return earlierScope;
335
+ return earlierScope === undefined || earlierScope === scope ? scope : undefined;
336
+ }
319
337
  function tokenExpiration(token, session) {
320
338
  const parts = token.split(".");
321
339
  if (parts.length !== 3)
@@ -327,7 +345,7 @@ function tokenExpiration(token, session) {
327
345
  claims.device_id !== session.deviceId ||
328
346
  claims.generation !== session.generation ||
329
347
  claims.mailbox_generation !== session.mailboxGeneration ||
330
- claims.relay_scope_id !== session.relayScopeId ||
348
+ deviceTokenScopeId(claims) !== session.relayScopeId ||
331
349
  !Number.isSafeInteger(claims.exp)) {
332
350
  return 0;
333
351
  }
@@ -337,6 +355,18 @@ function tokenExpiration(token, session) {
337
355
  return 0;
338
356
  }
339
357
  }
358
+ /**
359
+ * The issuer and audience pairs of a device token. Protocol versions 1 and 2
360
+ * issue the first pair, and protocol version 3 issues the second. The SDK
361
+ * accepts each pair until the Relay retires versions 1 and 2.
362
+ */
363
+ const SIGNAL_RELAY_DEVICE_TOKEN_ISSUERS = [
364
+ { issuer: 'open-e2ee-relay', audience: 'open-e2ee-relay-device' },
365
+ { issuer: 'signal-relay', audience: 'signal-relay-device' },
366
+ ];
367
+ function isSignalRelayDeviceTokenIssuer(issuer, audience) {
368
+ return SIGNAL_RELAY_DEVICE_TOKEN_ISSUERS.some((pair) => pair.issuer === issuer && pair.audience === audience);
369
+ }
340
370
  function assertLinkToken(session) {
341
371
  const parts = session.deviceToken.split('.');
342
372
  if (parts.length !== 3)
@@ -347,7 +377,7 @@ function assertLinkToken(session) {
347
377
  header.alg !== 'EdDSA' || header.typ !== 'JWT' || typeof header.kid !== 'string' || !header.kid ||
348
378
  decodeBase64Url(parts[2], 'Device token signature').length !== 64 ||
349
379
  !record(claims) || typeof claims.jti !== 'string' || !claims.jti ||
350
- claims.iss !== 'open-e2ee-relay' || claims.aud !== 'open-e2ee-relay-device' || claims.token_use !== 'device' ||
380
+ !isSignalRelayDeviceTokenIssuer(claims.iss, claims.aud) || claims.token_use !== 'device' ||
351
381
  typeof claims.account_state_id !== 'string' || !claims.account_state_id ||
352
382
  !Number.isSafeInteger(claims.iat) || claims.iat < 0 ||
353
383
  tokenExpiration(session.deviceToken, session) <= claims.iat)
@@ -417,13 +447,13 @@ function decodeDeliveryWire(value) {
417
447
  version: DELIVERY_WIRE_VERSION,
418
448
  };
419
449
  }
420
- export class HostedRelayHttpTransport {
450
+ export class HostedSignalProtocolRelayHttpTransport {
421
451
  connection;
422
452
  storage;
423
453
  deviceAuthentication;
424
454
  session;
425
455
  persistRefreshedToken;
426
- relayProtocolVersion;
456
+ signalRelayProtocolVersion;
427
457
  groups;
428
458
  groupServer;
429
459
  anonymousDelivery;
@@ -435,22 +465,22 @@ export class HostedRelayHttpTransport {
435
465
  ephemeralAcknowledgments = new Set();
436
466
  subscription;
437
467
  subscriptionGeneration = 0;
438
- connectionState = new RelayConnectionStateOwner();
468
+ connectionState = new SignalProtocolRelayConnectionStateOwner();
439
469
  presenceListeners = new Set();
440
- receiptInbox = new RelayReceiptInbox();
441
- receiptJoin = new RelayReceiptJoin();
470
+ receiptInbox = new SignalProtocolRelayReceiptInbox();
471
+ receiptJoin = new SignalProtocolRelayReceiptJoin();
442
472
  constructor(connection, storage, deviceAuthentication, session, persistRefreshedToken = true,
443
473
  /**
444
474
  * @internal The Relay protocol version of the client that owns this
445
475
  * transport. Every carrier of the client sends it.
446
476
  */
447
- relayProtocolVersion = RELAY_PROTOCOL_VERSION) {
477
+ signalRelayProtocolVersion = RELAY_PROTOCOL_VERSION) {
448
478
  this.connection = connection;
449
479
  this.storage = storage;
450
480
  this.deviceAuthentication = deviceAuthentication;
451
481
  this.session = session;
452
482
  this.persistRefreshedToken = persistRefreshedToken;
453
- this.relayProtocolVersion = relayProtocolVersion;
483
+ this.signalRelayProtocolVersion = signalRelayProtocolVersion;
454
484
  // The Relay refuses a removed device's mailbox on every send path before
455
485
  // its device list shows the removal, so a direct send may post first.
456
486
  declareRefusesRemovedDevices(this);
@@ -460,16 +490,16 @@ export class HostedRelayHttpTransport {
460
490
  declareComparesDeviceSets(this);
461
491
  // The Relay sends Relay delivery receipts to the sender, and replies to
462
492
  // each acknowledgment with the messages whose receipt it owns.
463
- declareRelayReceiptIntake(this, this.receiptInbox);
464
- declareRelayReceiptJoin(this, this.receiptJoin);
465
- this.groups = new HostedGroupServer(connection, relayProtocolVersion);
493
+ declareSignalProtocolRelayReceiptIntake(this, this.receiptInbox);
494
+ declareSignalProtocolRelayReceiptJoin(this, this.receiptJoin);
495
+ this.groups = new HostedGroupServer(connection, signalRelayProtocolVersion);
466
496
  this.groupServer = {
467
497
  server: this.groups,
468
498
  issueAuthCredential: (userId, authorityKeyId) => this.issueAuthCredential(userId, authorityKeyId),
469
499
  issueProfileKeyCredential: (userId, request, authorityKeyId) => this.issueProfileKeyCredential(userId, request, authorityKeyId),
470
500
  setUnidentifiedAccessKey: (userId, accessKey) => this.setUnidentifiedAccessKey(userId, accessKey),
471
501
  };
472
- this.fanOut = createAdapterRelayFanOut(this);
502
+ this.fanOut = createAdapterSignalProtocolRelayFanOut(this);
473
503
  this.anonymousDelivery = new HostedAnonymousDelivery(connection, this.fanOut, async (accountAddress, deviceId, declaredDeviceIds) => {
474
504
  const key = `${accountAddress}\0${deviceId}`;
475
505
  if (!this.destinationGenerations.has(key))
@@ -482,7 +512,7 @@ export class HostedRelayHttpTransport {
482
512
  if (generation === undefined)
483
513
  throw missingDestination(accountAddress, deviceId);
484
514
  return { accountAddress, deviceId, generation };
485
- }, (clientMessageId, request) => admitRepeatRequest(this, clientMessageId, request), relayProtocolVersion);
515
+ }, (clientMessageId, request) => admitRepeatRequest(this, clientMessageId, request), signalRelayProtocolVersion, ({ accountAddress, deviceId, generation }) => this.destinationRecovered(accountAddress, deviceId, generation, true));
486
516
  }
487
517
  get accountId() {
488
518
  return this.session.canonicalAccountId;
@@ -524,7 +554,7 @@ export class HostedRelayHttpTransport {
524
554
  return await this.commitObjectUpload(objectId);
525
555
  }
526
556
  catch (error) {
527
- if (error instanceof HostedRelayHttpError &&
557
+ if (error instanceof HostedSignalProtocolRelayHttpError &&
528
558
  error.code === "UPLOAD_INCOMPLETE")
529
559
  return null;
530
560
  throw this.uploadError(error, "settlement");
@@ -538,7 +568,7 @@ export class HostedRelayHttpTransport {
538
568
  },
539
569
  };
540
570
  uploadError(error, phase) {
541
- if (!(error instanceof HostedRelayHttpError))
571
+ if (!(error instanceof HostedSignalProtocolRelayHttpError))
542
572
  return error;
543
573
  switch (error.code) {
544
574
  case "UPLOAD_EXPIRED":
@@ -563,7 +593,7 @@ export class HostedRelayHttpTransport {
563
593
  }
564
594
  }
565
595
  async persistSession() {
566
- await this.storage.setMetadata(await sessionMetadataKey(this.connection), JSON.stringify(this.session));
596
+ await writeHostedStoreRecord(this.storage, await sessionMetadataKey(this.connection), JSON.stringify(this.session));
567
597
  }
568
598
  async commitObjectUpload(objectId) {
569
599
  const value = await this.authenticatedPost("/objects/commit-upload", {
@@ -591,7 +621,7 @@ export class HostedRelayHttpTransport {
591
621
  const proof = await this.deviceAuthentication.signChallenge(challenge);
592
622
  let value;
593
623
  try {
594
- value = await postJson(this.connection, this.relayProtocolVersion, "/identity/token", {
624
+ value = await postJson(this.connection, this.signalRelayProtocolVersion, "/identity/token", {
595
625
  accountAddress: this.session.canonicalAccountId,
596
626
  // The Relay checks this key against the keys that a recovery revoked.
597
627
  deviceAuthenticationPublicKey: bytesToBase64(this.deviceAuthentication.publicKey),
@@ -604,10 +634,10 @@ export class HostedRelayHttpTransport {
604
634
  }
605
635
  catch (error) {
606
636
  // A token refusal names this device, so it is not a
607
- // `HostedRelayHttpError`. A catch that reads `NOT_FOUND` as a missing
637
+ // `HostedSignalProtocolRelayHttpError`. A catch that reads `NOT_FOUND` as a missing
608
638
  // destination cannot take it.
609
- if (error instanceof HostedRelayHttpError && error.code === "NOT_FOUND")
610
- throw new HostedRelayDeviceUnknownError(error.status, error.message);
639
+ if (error instanceof HostedSignalProtocolRelayHttpError && error.code === "NOT_FOUND")
640
+ throw new HostedSignalProtocolRelayDeviceUnknownError(error.status, error.message);
611
641
  throw error;
612
642
  }
613
643
  if (!record(value) || typeof value.deviceToken !== "string") {
@@ -647,20 +677,20 @@ export class HostedRelayHttpTransport {
647
677
  throw new Error('Signal Protocol Relay returned an invalid device token');
648
678
  return body(claims.jti);
649
679
  };
650
- const value = await submitHostedRelayDeviceLink(request, {
680
+ const value = await submitHostedSignalProtocolRelayDeviceLink(request, {
651
681
  relayScopeId: this.session.relayScopeId,
652
682
  materialFingerprint,
653
683
  signalRegistration: signalRegistration(request.signalIdentity, request.registrationId, request.registrationPreKeys),
654
684
  post: async (body) => {
655
685
  let token = await this.token();
656
686
  try {
657
- return await postJson(this.connection, this.relayProtocolVersion, '/identity/devices/link', await bodyFor(body, token), token);
687
+ return await postJson(this.connection, this.signalRelayProtocolVersion, '/identity/devices/link', await bodyFor(body, token), token);
658
688
  }
659
689
  catch (error) {
660
- if (!(error instanceof HostedRelayHttpError) || error.code !== 'TOKEN_INVALID')
690
+ if (!(error instanceof HostedSignalProtocolRelayHttpError) || error.code !== 'TOKEN_INVALID')
661
691
  throw error;
662
692
  token = await this.token(true);
663
- return postJson(this.connection, this.relayProtocolVersion, '/identity/devices/link', await bodyFor(body, token), token);
693
+ return postJson(this.connection, this.signalRelayProtocolVersion, '/identity/devices/link', await bodyFor(body, token), token);
664
694
  }
665
695
  },
666
696
  });
@@ -684,7 +714,7 @@ export class HostedRelayHttpTransport {
684
714
  throw new Error('Signal Protocol Relay returned an invalid managed device link');
685
715
  assertLinkToken(session);
686
716
  const key = await sessionMetadataKey(this.connection);
687
- const stored = await storage.getMetadata(key);
717
+ const stored = await readHostedStoreRecord(storage, key);
688
718
  if (stored !== null) {
689
719
  const existing = parseSession(stored, this.connection);
690
720
  assertLinkToken(existing);
@@ -698,22 +728,24 @@ export class HostedRelayHttpTransport {
698
728
  throw new Error('Stored Signal Protocol Relay link session conflicts with the retained attempt');
699
729
  session = existing;
700
730
  }
701
- const transport = new HostedRelayHttpTransport(this.connection, storage, request.newDeviceAuthentication, session, true, this.relayProtocolVersion);
731
+ const transport = new HostedSignalProtocolRelayHttpTransport(this.connection, storage, request.newDeviceAuthentication, session, true, this.signalRelayProtocolVersion);
702
732
  // Persist the complete shape before synchronization or token renewal can fail.
703
733
  try {
704
- await storage.setMetadata(key, JSON.stringify(session));
734
+ await writeHostedStoreRecord(storage, key, JSON.stringify(session));
705
735
  await transport.ensureAuthenticated();
706
736
  }
707
737
  catch (error) {
708
738
  // A renewal refusal cannot prove that the accepted link had no effect.
709
- if (error instanceof HostedRelayHttpError && !error.retryable &&
739
+ if (error instanceof HostedSignalProtocolRelayHttpError && !error.retryable &&
710
740
  (error.code === 'KEY_PROOF_INVALID' || error.code === 'CONFLICT'))
711
741
  throw new Error('Signal Protocol Relay accepted the link but session adoption failed', { cause: error });
712
742
  throw error;
713
743
  }
744
+ const scopeId = this.connection.relayScopeId.slice();
714
745
  return {
715
746
  canonicalAccountId: session.canonicalAccountId, deviceId: session.deviceId,
716
- relayScopeId: this.connection.relayScopeId.slice(), relay: transport,
747
+ signalProtocolRelayScopeId: scopeId, relayScopeId: scopeId,
748
+ signalProtocolRelay: transport, relay: transport,
717
749
  remoteObjectStore: transport.objectStore, transport,
718
750
  accountPreserved: true, protocolStateCopied: false,
719
751
  };
@@ -726,10 +758,10 @@ export class HostedRelayHttpTransport {
726
758
  async authenticatedPost(path, body, beforeRepeat) {
727
759
  let token = await this.token();
728
760
  try {
729
- return await postJson(this.connection, this.relayProtocolVersion, path, body, token);
761
+ return await postJson(this.connection, this.signalRelayProtocolVersion, path, body, token);
730
762
  }
731
763
  catch (error) {
732
- if (!(error instanceof HostedRelayHttpError) ||
764
+ if (!(error instanceof HostedSignalProtocolRelayHttpError) ||
733
765
  error.code !== "TOKEN_INVALID") {
734
766
  throw error;
735
767
  }
@@ -740,7 +772,7 @@ export class HostedRelayHttpTransport {
740
772
  catch {
741
773
  throw error;
742
774
  }
743
- return postJson(this.connection, this.relayProtocolVersion, path, body, token);
775
+ return postJson(this.connection, this.signalRelayProtocolVersion, path, body, token);
744
776
  }
745
777
  }
746
778
  assertCurrentIdentity(userId, deviceId, identityType = "aci") {
@@ -764,6 +796,30 @@ export class HostedRelayHttpTransport {
764
796
  }
765
797
  return lookup;
766
798
  }
799
+ /**
800
+ * The Relay refused a post to this mailbox generation as NOT_FOUND. True
801
+ * when a new read of the device directory lists the device at another
802
+ * mailbox generation: a recovery replaced the device, so the refusal is
803
+ * the stale-device refusal of the posted generation. False when the read
804
+ * fails, or the directory does not list the device, or lists it at the
805
+ * posted generation. The read refills the destination cache, so a repost
806
+ * goes to the listed generation. An identified post runs in a slot of the
807
+ * relay request bound, so it reads without a slot. A sealed post holds no
808
+ * slot, so it reads under the bound.
809
+ */
810
+ async destinationRecovered(userId, deviceId, postedGeneration, underBound) {
811
+ try {
812
+ await (underBound
813
+ ? this.fanOut.request(() => this.directory(userId))
814
+ : this.directory(userId));
815
+ }
816
+ catch (error) {
817
+ rethrowSignalProtocolRelayWorkStopped(error);
818
+ return false;
819
+ }
820
+ const listed = this.destinationGenerations.get(`${userId}\0${String(deviceId)}`);
821
+ return listed !== undefined && listed !== postedGeneration;
822
+ }
767
823
  async directory(userId) {
768
824
  const value = await this.authenticatedPost("/identity/devices", {
769
825
  accountAddress: userId,
@@ -822,7 +878,7 @@ export class HostedRelayHttpTransport {
822
878
  ? this.session.mailboxGeneration
823
879
  : this.destinationGenerations.get(key);
824
880
  if (generation === undefined) {
825
- throw new HostedRelayHttpError(404, "NOT_FOUND", "Signal Protocol Relay destination device does not exist");
881
+ throw new HostedSignalProtocolRelayHttpError(404, "NOT_FOUND", "Signal Protocol Relay destination device does not exist");
826
882
  }
827
883
  return this.authenticatedPost(path, {
828
884
  accountAddress: userId,
@@ -837,7 +893,7 @@ export class HostedRelayHttpTransport {
837
893
  }
838
894
  catch (error) {
839
895
  if (!cached ||
840
- !(error instanceof HostedRelayHttpError) ||
896
+ !(error instanceof HostedSignalProtocolRelayHttpError) ||
841
897
  error.code !== "NOT_FOUND") {
842
898
  throw error;
843
899
  }
@@ -871,7 +927,7 @@ export class HostedRelayHttpTransport {
871
927
  * publication returns after that one read.
872
928
  */
873
929
  async publishCurrentPrekeys(plan) {
874
- await hostedPreKeyPublicationLock.acquire(await sessionMetadataKey(this.connection), async () => {
930
+ await hostedPreKeyPublicationLock.acquire((await sessionMetadataKey(this.connection)).current, async () => {
875
931
  const current = await this.currentIdentity();
876
932
  let status = await this.prekeyStatus(this.session.canonicalAccountId, this.session.deviceId);
877
933
  if (status.authorityGeneration !== this.session.generation ||
@@ -988,7 +1044,7 @@ export class HostedRelayHttpTransport {
988
1044
  messages: value.messages.map((candidate) => this.incomingEnvelope(candidate)),
989
1045
  receipts: value.receipts === undefined
990
1046
  ? []
991
- : decodeRelayDeliveryReceipts(value.receipts),
1047
+ : decodeSignalProtocolRelayDeliveryReceipts(value.receipts),
992
1048
  ...(value.nextCursor === undefined
993
1049
  ? {}
994
1050
  : { nextCursor: value.nextCursor }),
@@ -1056,7 +1112,7 @@ export class HostedRelayHttpTransport {
1056
1112
  if (proof.byteLength !== 64)
1057
1113
  throw new Error("Signal Protocol Relay certificate proof is invalid");
1058
1114
  try {
1059
- const result = await postJson(this.connection, this.relayProtocolVersion, "/certificates/issue", {
1115
+ const result = await postJson(this.connection, this.signalRelayProtocolVersion, "/certificates/issue", {
1060
1116
  publishableKey: this.connection.publishableKey,
1061
1117
  nonce,
1062
1118
  deviceProof: bytesToBase64(proof),
@@ -1070,7 +1126,7 @@ export class HostedRelayHttpTransport {
1070
1126
  }
1071
1127
  catch (error) {
1072
1128
  if (attempt > 0 ||
1073
- !(error instanceof HostedRelayHttpError) ||
1129
+ !(error instanceof HostedSignalProtocolRelayHttpError) ||
1074
1130
  error.code !== "TOKEN_INVALID")
1075
1131
  throw error;
1076
1132
  }
@@ -1233,7 +1289,7 @@ export class HostedRelayHttpTransport {
1233
1289
  for (let start = MAXIMUM_ACKNOWLEDGMENT_IDS; start < receiptIds.length; start += MAXIMUM_ACKNOWLEDGMENT_IDS)
1234
1290
  await this.acknowledge([], receiptIds.slice(start, start + MAXIMUM_ACKNOWLEDGMENT_IDS));
1235
1291
  }
1236
- receiveRelayReceipt(receipt) {
1292
+ receiveSignalProtocolRelayReceipt(receipt) {
1237
1293
  return this.receiptInbox.handOff(receipt);
1238
1294
  }
1239
1295
  async createObjectUpload(input) {
@@ -1273,7 +1329,7 @@ export class HostedRelayHttpTransport {
1273
1329
  expiresAt: tokenExpiration(token, this.session) * 1_000,
1274
1330
  headers: {
1275
1331
  authorization: `Bearer ${token}`,
1276
- ...relayProtocolHeadersFor(this.relayProtocolVersion),
1332
+ ...signalRelayProtocolHeadersFor(this.signalRelayProtocolVersion),
1277
1333
  "x-open-e2ee-publishable-key": this.connection.publishableKey,
1278
1334
  "x-open-e2ee-object-id": input.objectId,
1279
1335
  "x-open-e2ee-attachment-capability": input.readCapability,
@@ -1294,7 +1350,7 @@ export class HostedRelayHttpTransport {
1294
1350
  generation = this.destinationGenerations.get(key);
1295
1351
  }
1296
1352
  if (generation === undefined && envelope.declaredDeviceIds !== undefined) {
1297
- throw markDeviceSetRefusal(new HostedRelayHttpError(409, "DEVICE_SET_MISMATCH", "The declared device set differs from the device directory"), this.directoryDeviceSetRefusal(envelope.targetUserId, envelope.declaredDeviceIds));
1353
+ throw markDeviceSetRefusal(new HostedSignalProtocolRelayHttpError(409, "DEVICE_SET_MISMATCH", "The declared device set differs from the device directory"), this.directoryDeviceSetRefusal(envelope.targetUserId, envelope.declaredDeviceIds));
1298
1354
  }
1299
1355
  if (generation === undefined)
1300
1356
  throw missingDestination(envelope.targetUserId, envelope.targetDeviceId);
@@ -1307,7 +1363,7 @@ export class HostedRelayHttpTransport {
1307
1363
  },
1308
1364
  ];
1309
1365
  let value;
1310
- let attempts = 0;
1366
+ let uncertainRepeat = false;
1311
1367
  // Each repeat request meets the checks that the owner of the post
1312
1368
  // registered under its message ID, and names its device and the answer
1313
1369
  // that it follows.
@@ -1316,59 +1372,83 @@ export class HostedRelayHttpTransport {
1316
1372
  deviceId: envelope.targetDeviceId,
1317
1373
  after,
1318
1374
  });
1375
+ const repeatAfterUncertain = async () => {
1376
+ await beforeRepeat("uncertain")();
1377
+ uncertainRepeat = true;
1378
+ };
1379
+ // A PERIOD_CLOSED answer proves that the Relay stored nothing, so the
1380
+ // same request goes once more, in the next period.
1381
+ const periodClosedRetry = onePeriodClosedRetry();
1319
1382
  try {
1320
- value = await withOneUncertainRetry(envelope.deliveryClass, () => {
1321
- attempts++;
1322
- return this.authenticatedPost("/delivery/send", {
1323
- contentKind: envelope.contentKind ?? "message",
1324
- deliveryClass: envelope.deliveryClass,
1325
- destination: {
1326
- accountAddress: envelope.targetUserId,
1327
- deviceId: envelope.targetDeviceId,
1328
- generation,
1329
- },
1330
- envelope: bytesToBase64(encodeDeliveryWire(envelope)),
1331
- messageId,
1332
- operationEpochMilliseconds: envelope.operationEpochMilliseconds ?? envelope.timestamp,
1333
- publishableKey: this.connection.publishableKey,
1334
- ...(envelope.recipientRegistrationId === undefined
1335
- ? {}
1336
- : { recipientRegistrationId: envelope.recipientRegistrationId }),
1337
- ...(deviceSets === undefined ? {} : { deviceSets }),
1338
- }, beforeRepeat("token"));
1339
- }, beforeRepeat("uncertain"));
1383
+ value = await withOneUncertainRetry(envelope.deliveryClass, () => periodClosedRetry(() => this.authenticatedPost("/delivery/send", {
1384
+ contentKind: envelope.contentKind ?? "message",
1385
+ deliveryClass: envelope.deliveryClass,
1386
+ destination: {
1387
+ accountAddress: envelope.targetUserId,
1388
+ deviceId: envelope.targetDeviceId,
1389
+ generation,
1390
+ },
1391
+ envelope: bytesToBase64(encodeDeliveryWire(envelope)),
1392
+ messageId,
1393
+ operationEpochMilliseconds: envelope.operationEpochMilliseconds ?? envelope.timestamp,
1394
+ publishableKey: this.connection.publishableKey,
1395
+ ...(envelope.recipientRegistrationId === undefined
1396
+ ? {}
1397
+ : { recipientRegistrationId: envelope.recipientRegistrationId }),
1398
+ ...(deviceSets === undefined ? {} : { deviceSets }),
1399
+ }, beforeRepeat("token")), beforeRepeat("period-closed")), repeatAfterUncertain);
1340
1400
  }
1341
1401
  catch (error) {
1342
1402
  // After an uncertain answer, the first request can have stored the
1343
1403
  // copy, so the answer to the repeat tells nothing about the post.
1344
- const answer = (failure) => attempts > 1 ? markAfterRepeatedRequest(failure) : failure;
1404
+ const answer = (failure) => uncertainRepeat ? markAfterRepeatedRequest(failure) : failure;
1345
1405
  const device = {
1346
1406
  userId: envelope.targetUserId,
1347
1407
  deviceId: envelope.targetDeviceId,
1348
1408
  };
1349
- if (deviceSets !== undefined && error instanceof HostedRelayHttpError) {
1409
+ if (deviceSets !== undefined && error instanceof HostedSignalProtocolRelayHttpError) {
1350
1410
  const refusal = parseDeviceSetRefusal(error.code, error.data?.details);
1351
1411
  if (refusal !== undefined) {
1352
1412
  this.forgetDestinationGenerations(refusal.accounts);
1353
1413
  throw answer(markDeviceSetRefusal(error, refusal));
1354
1414
  }
1355
1415
  }
1356
- if (error instanceof HostedRelayHttpError &&
1416
+ const staleDevice = (stale) => answer(markSignalProtocolRelayDeviceRefusal(new HostedSignalProtocolRelayHttpError(stale.status, "STALE_DEVICE", stale.message, {
1417
+ data: {
1418
+ code: "STALE_DEVICE",
1419
+ message: stale.message,
1420
+ reason: "device_reinstalled",
1421
+ staleDevices: [envelope.targetDeviceId],
1422
+ },
1423
+ retryable: stale.retryable,
1424
+ }), { code: "STALE_DEVICE", ...device }));
1425
+ if (error instanceof HostedSignalProtocolRelayHttpError &&
1357
1426
  error.code === "STALE_DEVICE") {
1358
- throw answer(markRelayDeviceRefusal(new HostedRelayHttpError(error.status, error.code, error.message, {
1359
- data: {
1360
- code: "STALE_DEVICE",
1361
- message: error.message,
1362
- reason: "device_reinstalled",
1363
- staleDevices: [envelope.targetDeviceId],
1364
- },
1365
- retryable: error.retryable,
1366
- }), { code: "STALE_DEVICE", ...device }));
1427
+ throw staleDevice(error);
1367
1428
  }
1368
1429
  // Only the Relay's own error body names NOT_FOUND. A 404 without it
1369
1430
  // fails to parse or carries no code, so it is not a device refusal.
1370
- if (error instanceof HostedRelayHttpError && error.code === "NOT_FOUND")
1371
- throw answer(markRelayDeviceRefusal(error, { code: "NOT_FOUND", ...device }));
1431
+ if (error instanceof HostedSignalProtocolRelayHttpError && error.code === "NOT_FOUND") {
1432
+ // A recovery retired the posted generation. As for a stale device,
1433
+ // the send archives the session and posts to the recovered device.
1434
+ // A declared post gets the declared STALE_DEVICE that the Relay
1435
+ // gives for a changed registration.
1436
+ if (await this.destinationRecovered(envelope.targetUserId, envelope.targetDeviceId, generation, false)) {
1437
+ const stale = staleDevice(error);
1438
+ throw deviceSets === undefined
1439
+ ? stale
1440
+ : markDeviceSetRefusal(stale, {
1441
+ kind: "stale",
1442
+ accounts: [
1443
+ {
1444
+ userId: envelope.targetUserId,
1445
+ staleDeviceIds: [envelope.targetDeviceId],
1446
+ },
1447
+ ],
1448
+ });
1449
+ }
1450
+ throw answer(markSignalProtocolRelayDeviceRefusal(error, { code: "NOT_FOUND", ...device }));
1451
+ }
1372
1452
  throw answer(error);
1373
1453
  }
1374
1454
  if (!record(value) ||
@@ -1390,7 +1470,7 @@ export class HostedRelayHttpTransport {
1390
1470
  serverTimestamp: typeof value.enqueuedAt === "number"
1391
1471
  ? value.enqueuedAt
1392
1472
  : envelope.timestamp,
1393
- ...(typeof value.duplicate === "boolean" && attempts === 1
1473
+ ...(typeof value.duplicate === "boolean" && !uncertainRepeat
1394
1474
  ? { duplicate: value.duplicate }
1395
1475
  : {}),
1396
1476
  ...(typeof value.expiresAt === "number"
@@ -1408,7 +1488,7 @@ export class HostedRelayHttpTransport {
1408
1488
  const generation = ++this.subscriptionGeneration;
1409
1489
  const subscription = subscribeHostedMailbox({
1410
1490
  ...options,
1411
- relayProtocolVersion: this.relayProtocolVersion,
1491
+ signalRelayProtocolVersion: this.signalRelayProtocolVersion,
1412
1492
  onConnectionState: (state, reason) => {
1413
1493
  if (generation === this.subscriptionGeneration)
1414
1494
  this.connectionState.move(state, reason);
@@ -1432,14 +1512,7 @@ export class HostedRelayHttpTransport {
1432
1512
  const previous = this.session.deviceToken;
1433
1513
  const token = await this.token();
1434
1514
  const url = websocketUrl(`${identifiedEndpoint(this.connection)}/mailbox/connect`, [["publishableKey", this.connection.publishableKey]]);
1435
- return {
1436
- url,
1437
- token,
1438
- renewAt: (tokenExpiration(token, this.session) -
1439
- DEVICE_TOKEN_REFRESH_SECONDS) *
1440
- 1_000,
1441
- refreshed: token !== previous,
1442
- };
1515
+ return { url, token, refreshed: token !== previous };
1443
1516
  },
1444
1517
  isConclusiveRefusal,
1445
1518
  decodeDurable: (message) => this.incomingEnvelope(message),
@@ -1489,12 +1562,20 @@ export class HostedRelayHttpTransport {
1489
1562
  subscription.unsubscribe();
1490
1563
  };
1491
1564
  }
1492
- get relayConnectionState() {
1565
+ get signalProtocolRelayConnectionState() {
1493
1566
  return this.connectionState.current;
1494
1567
  }
1495
- subscribeRelayConnectionState(listener) {
1568
+ subscribeSignalProtocolRelayConnectionState(listener) {
1496
1569
  return this.connectionState.subscribe(listener);
1497
1570
  }
1571
+ /** @deprecated Use `signalProtocolRelayConnectionState`. SDK 15.0.0 removes this name. */
1572
+ get relayConnectionState() {
1573
+ return this.signalProtocolRelayConnectionState;
1574
+ }
1575
+ /** @deprecated Use `subscribeSignalProtocolRelayConnectionState`. SDK 15.0.0 removes this name. */
1576
+ subscribeRelayConnectionState(listener) {
1577
+ return this.subscribeSignalProtocolRelayConnectionState(listener);
1578
+ }
1498
1579
  /**
1499
1580
  * Acknowledges over the live mailbox socket when one exists, in one frame per
1500
1581
  * drained burst, and over HTTP otherwise.
@@ -1539,7 +1620,7 @@ export class HostedRelayHttpTransport {
1539
1620
  .identityPublicMaterial);
1540
1621
  }
1541
1622
  catch (error) {
1542
- if (error instanceof HostedRelayHttpError && error.code === "NOT_FOUND")
1623
+ if (error instanceof HostedSignalProtocolRelayHttpError && error.code === "NOT_FOUND")
1543
1624
  return null;
1544
1625
  throw error;
1545
1626
  }
@@ -1556,7 +1637,7 @@ export class HostedRelayHttpTransport {
1556
1637
  value = await this.prekeyPost("/prekeys/consume", userId, deviceId, identityType);
1557
1638
  }
1558
1639
  catch (error) {
1559
- if (error instanceof HostedRelayHttpError && error.code === "NOT_FOUND")
1640
+ if (error instanceof HostedSignalProtocolRelayHttpError && error.code === "NOT_FOUND")
1560
1641
  return null;
1561
1642
  throw error;
1562
1643
  }
@@ -1708,7 +1789,7 @@ export class HostedRelayHttpTransport {
1708
1789
  }
1709
1790
  }
1710
1791
  }
1711
- export async function bootstrapHostedRelayTransport(request) {
1792
+ export async function bootstrapHostedSignalProtocolRelayTransport(request) {
1712
1793
  const proof = await request.deviceAuthentication.signChallenge(await registrationChallenge(request));
1713
1794
  // A new client starts at the default version, which the transport built
1714
1795
  // below also takes.
@@ -1739,7 +1820,7 @@ export async function bootstrapHostedRelayTransport(request) {
1739
1820
  preKeyPublication: storedPublication(generation, materialFingerprint, request.operationId, 0, request.registrationPreKeys),
1740
1821
  relayScopeId: requiredString(value, "relayScopeId"),
1741
1822
  };
1742
- if (session.relayScopeId !== relayScopeId(request.connection) ||
1823
+ if (session.relayScopeId !== signalProtocolRelayScopeId(request.connection) ||
1743
1824
  session.deviceId < 1 ||
1744
1825
  session.generation < 0 ||
1745
1826
  session.mailboxGeneration < 0 ||
@@ -1747,31 +1828,34 @@ export async function bootstrapHostedRelayTransport(request) {
1747
1828
  Math.floor(Date.now() / 1_000)) {
1748
1829
  throw new Error("Signal Protocol Relay returned an invalid registration");
1749
1830
  }
1750
- await request.storage.setMetadata(await sessionMetadataKey(request.connection), JSON.stringify(session));
1751
- const transport = new HostedRelayHttpTransport(request.connection, request.storage, request.deviceAuthentication, session);
1831
+ await writeHostedStoreRecord(request.storage, await sessionMetadataKey(request.connection), JSON.stringify(session));
1832
+ const transport = new HostedSignalProtocolRelayHttpTransport(request.connection, request.storage, request.deviceAuthentication, session);
1833
+ const scopeId = request.connection.relayScopeId.slice();
1752
1834
  return {
1753
1835
  canonicalAccountId: session.canonicalAccountId,
1754
1836
  deviceId: session.deviceId,
1837
+ signalProtocolRelay: transport,
1755
1838
  relay: transport,
1756
- relayScopeId: request.connection.relayScopeId.slice(),
1839
+ signalProtocolRelayScopeId: scopeId,
1840
+ relayScopeId: scopeId,
1757
1841
  remoteObjectStore: transport.objectStore,
1758
1842
  transport,
1759
1843
  };
1760
1844
  }
1761
- export async function resumeHostedRelayTransport(options) {
1845
+ export async function resumeHostedSignalProtocolRelayTransport(options) {
1762
1846
  let stored;
1763
1847
  try {
1764
- stored = await options.storage.getMetadata(await sessionMetadataKey(options.connection));
1848
+ stored = await readHostedStoreRecord(options.storage, await sessionMetadataKey(options.connection));
1765
1849
  }
1766
1850
  catch (cause) {
1767
1851
  if (options.requireExisting) {
1768
- throw new HostedRelayResumeError('RETAINED_STATE_UNREADABLE', 'reading-local-state', { cause });
1852
+ throw new HostedSignalProtocolRelayResumeError('RETAINED_STATE_UNREADABLE', 'reading-local-state', { cause });
1769
1853
  }
1770
1854
  throw cause;
1771
1855
  }
1772
1856
  if (!stored) {
1773
1857
  if (options.requireExisting) {
1774
- throw new HostedRelayResumeError('RETAINED_SESSION_UNAVAILABLE', 'reading-local-state');
1858
+ throw new HostedSignalProtocolRelayResumeError('RETAINED_SESSION_UNAVAILABLE', 'reading-local-state');
1775
1859
  }
1776
1860
  return undefined;
1777
1861
  }
@@ -1781,28 +1865,31 @@ export async function resumeHostedRelayTransport(options) {
1781
1865
  }
1782
1866
  catch (cause) {
1783
1867
  if (options.requireExisting) {
1784
- throw new HostedRelayResumeError('RETAINED_SESSION_UNAVAILABLE', 'reading-local-state', { cause });
1868
+ throw new HostedSignalProtocolRelayResumeError('RETAINED_SESSION_UNAVAILABLE', 'reading-local-state', { cause });
1785
1869
  }
1786
1870
  throw cause;
1787
1871
  }
1788
- const transport = new HostedRelayHttpTransport(options.connection, options.storage, options.deviceAuthentication, session);
1872
+ const transport = new HostedSignalProtocolRelayHttpTransport(options.connection, options.storage, options.deviceAuthentication, session);
1789
1873
  options.onAuthenticating?.();
1790
1874
  await transport.ensureAuthenticated(true);
1875
+ const scopeId = options.connection.relayScopeId.slice();
1791
1876
  return {
1792
1877
  canonicalAccountId: session.canonicalAccountId,
1793
1878
  deviceId: session.deviceId,
1879
+ signalProtocolRelay: transport,
1794
1880
  relay: transport,
1795
- relayScopeId: options.connection.relayScopeId.slice(),
1881
+ signalProtocolRelayScopeId: scopeId,
1882
+ relayScopeId: scopeId,
1796
1883
  remoteObjectStore: transport.objectStore,
1797
1884
  transport,
1798
1885
  };
1799
1886
  }
1800
1887
  /** Compose a link using a detached active session without publication writes. */
1801
- export async function linkHostedRelayTransport(options) {
1802
- const stored = await options.activeStorage.getMetadata(await sessionMetadataKey(options.connection));
1888
+ export async function linkHostedSignalProtocolRelayTransport(options) {
1889
+ const stored = await readHostedStoreRecord(options.activeStorage, await sessionMetadataKey(options.connection));
1803
1890
  if (!stored)
1804
1891
  throw new Error('Signal Protocol Relay device link requires an active hosted session');
1805
- const active = new HostedRelayHttpTransport(options.connection, options.activeStorage, options.request.activeDeviceAuthentication, parseSession(stored, options.connection), false);
1892
+ const active = new HostedSignalProtocolRelayHttpTransport(options.connection, options.activeStorage, options.request.activeDeviceAuthentication, parseSession(stored, options.connection), false);
1806
1893
  return active.linkDevice(options.request, options.storage);
1807
1894
  }
1808
1895
  //# sourceMappingURL=hosted-transport.js.map