@open-e2ee/signal-protocol-sdk 7.1.0 → 8.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 (698) hide show
  1. package/ADAPTERS.md +55 -6
  2. package/ARCHITECTURE.md +1 -0
  3. package/CHANGELOG.md +565 -0
  4. package/README.md +19 -5
  5. package/SECURITY.md +2 -2
  6. package/THIRD_PARTY_NOTICES.md +429 -0
  7. package/TROUBLESHOOTING.md +10 -0
  8. package/client/README.md +1 -2
  9. package/device/README.md +50 -19
  10. package/dist/client/client.d.ts +31 -5
  11. package/dist/client/client.d.ts.map +1 -1
  12. package/dist/client/client.js +149 -90
  13. package/dist/client/client.js.map +1 -1
  14. package/dist/client/event-hooks.d.ts.map +1 -1
  15. package/dist/client/event-hooks.js +2 -0
  16. package/dist/client/event-hooks.js.map +1 -1
  17. package/dist/client/files.d.ts.map +1 -1
  18. package/dist/client/files.js +19 -2
  19. package/dist/client/files.js.map +1 -1
  20. package/dist/client/headless.d.ts +1 -1
  21. package/dist/client/headless.js +1 -1
  22. package/dist/client/hosted-anonymous-delivery.d.ts.map +1 -1
  23. package/dist/client/hosted-anonymous-delivery.js +2 -1
  24. package/dist/client/hosted-anonymous-delivery.js.map +1 -1
  25. package/dist/client/hosted-connection.d.ts +1 -1
  26. package/dist/client/hosted-connection.d.ts.map +1 -1
  27. package/dist/client/hosted-connection.js +8 -12
  28. package/dist/client/hosted-connection.js.map +1 -1
  29. package/dist/client/hosted-group-authority.d.ts.map +1 -1
  30. package/dist/client/hosted-group-authority.js +2 -1
  31. package/dist/client/hosted-group-authority.js.map +1 -1
  32. package/dist/client/hosted-groups.d.ts.map +1 -1
  33. package/dist/client/hosted-groups.js +2 -1
  34. package/dist/client/hosted-groups.js.map +1 -1
  35. package/dist/client/hosted-push.d.ts.map +1 -1
  36. package/dist/client/hosted-push.js +2 -1
  37. package/dist/client/hosted-push.js.map +1 -1
  38. package/dist/client/hosted-transport.d.ts.map +1 -1
  39. package/dist/client/hosted-transport.js +10 -11
  40. package/dist/client/hosted-transport.js.map +1 -1
  41. package/dist/client/hosted-trust.d.ts +11 -11
  42. package/dist/client/hosted-trust.d.ts.map +1 -1
  43. package/dist/client/hosted-trust.js +12 -12
  44. package/dist/client/hosted-trust.js.map +1 -1
  45. package/dist/client/messages.d.ts.map +1 -1
  46. package/dist/client/messages.js +6 -1
  47. package/dist/client/messages.js.map +1 -1
  48. package/dist/client/multi-device.d.ts.map +1 -1
  49. package/dist/client/multi-device.js +2 -1
  50. package/dist/client/multi-device.js.map +1 -1
  51. package/dist/client/relay-lifecycle.d.ts +6 -2
  52. package/dist/client/relay-lifecycle.d.ts.map +1 -1
  53. package/dist/client/relay-lifecycle.js.map +1 -1
  54. package/dist/client/relay-work.d.ts +30 -0
  55. package/dist/client/relay-work.d.ts.map +1 -0
  56. package/dist/client/relay-work.js +189 -0
  57. package/dist/client/relay-work.js.map +1 -0
  58. package/dist/client/retry.d.ts.map +1 -1
  59. package/dist/client/retry.js +2 -0
  60. package/dist/client/retry.js.map +1 -1
  61. package/dist/client/sessions.d.ts.map +1 -1
  62. package/dist/client/sessions.js +3 -0
  63. package/dist/client/sessions.js.map +1 -1
  64. package/dist/client/signal-service-cipher.d.ts +39 -16
  65. package/dist/client/signal-service-cipher.d.ts.map +1 -1
  66. package/dist/client/signal-service-cipher.js +100 -60
  67. package/dist/client/signal-service-cipher.js.map +1 -1
  68. package/dist/client/state.d.ts +8 -0
  69. package/dist/client/state.d.ts.map +1 -1
  70. package/dist/client/state.js +11 -0
  71. package/dist/client/state.js.map +1 -1
  72. package/dist/client/types.d.ts +5 -1
  73. package/dist/client/types.d.ts.map +1 -1
  74. package/dist/client/types.js.map +1 -1
  75. package/dist/device/connection.d.ts +1 -1
  76. package/dist/device/connection.d.ts.map +1 -1
  77. package/dist/device/connection.js +4 -11
  78. package/dist/device/connection.js.map +1 -1
  79. package/dist/device/device-id.d.ts +10 -4
  80. package/dist/device/device-id.d.ts.map +1 -1
  81. package/dist/device/device-id.js +15 -9
  82. package/dist/device/device-id.js.map +1 -1
  83. package/dist/device/device-name-crypto.d.ts.map +1 -1
  84. package/dist/device/device-name-crypto.js +2 -2
  85. package/dist/device/device-name-crypto.js.map +1 -1
  86. package/dist/device/expo/index.d.ts +25 -8
  87. package/dist/device/expo/index.d.ts.map +1 -1
  88. package/dist/device/expo/index.js +58 -8
  89. package/dist/device/expo/index.js.map +1 -1
  90. package/dist/device/index.d.ts +2 -2
  91. package/dist/device/index.d.ts.map +1 -1
  92. package/dist/device/index.js +3 -2
  93. package/dist/device/index.js.map +1 -1
  94. package/dist/device/lifecycle/index.d.ts +4 -2
  95. package/dist/device/lifecycle/index.d.ts.map +1 -1
  96. package/dist/device/lifecycle/index.js.map +1 -1
  97. package/dist/device/lifecycle/manager.d.ts +12 -14
  98. package/dist/device/lifecycle/manager.d.ts.map +1 -1
  99. package/dist/device/lifecycle/manager.js +52 -97
  100. package/dist/device/lifecycle/manager.js.map +1 -1
  101. package/dist/device/lifecycle/types.d.ts +26 -16
  102. package/dist/device/lifecycle/types.d.ts.map +1 -1
  103. package/dist/device/lifecycle/utils.d.ts +8 -4
  104. package/dist/device/lifecycle/utils.d.ts.map +1 -1
  105. package/dist/device/lifecycle/utils.js +12 -16
  106. package/dist/device/lifecycle/utils.js.map +1 -1
  107. package/dist/device/provisioning.d.ts.map +1 -1
  108. package/dist/device/provisioning.js +6 -8
  109. package/dist/device/provisioning.js.map +1 -1
  110. package/dist/device/react-native/index.d.ts +40 -0
  111. package/dist/device/react-native/index.d.ts.map +1 -0
  112. package/dist/device/react-native/index.js +74 -0
  113. package/dist/device/react-native/index.js.map +1 -0
  114. package/dist/device/transfer.d.ts +15 -7
  115. package/dist/device/transfer.d.ts.map +1 -1
  116. package/dist/device/transfer.js +30 -22
  117. package/dist/device/transfer.js.map +1 -1
  118. package/dist/device/types.d.ts +15 -7
  119. package/dist/device/types.d.ts.map +1 -1
  120. package/dist/device/types.js.map +1 -1
  121. package/dist/device/vault-text.d.ts +13 -0
  122. package/dist/device/vault-text.d.ts.map +1 -0
  123. package/dist/device/vault-text.js +17 -0
  124. package/dist/device/vault-text.js.map +1 -0
  125. package/dist/hooks/use-key-rotation.d.ts.map +1 -1
  126. package/dist/hooks/use-key-rotation.js +2 -1
  127. package/dist/hooks/use-key-rotation.js.map +1 -1
  128. package/dist/index.d.ts +9 -5
  129. package/dist/index.d.ts.map +1 -1
  130. package/dist/index.js +9 -5
  131. package/dist/index.js.map +1 -1
  132. package/dist/internal/crypto/index.d.ts +3 -3
  133. package/dist/internal/crypto/index.d.ts.map +1 -1
  134. package/dist/internal/crypto/index.js +3 -3
  135. package/dist/internal/crypto/index.js.map +1 -1
  136. package/dist/internal/crypto/random-host.d.ts +1 -1
  137. package/dist/internal/crypto/random-host.d.ts.map +1 -1
  138. package/dist/internal/crypto/random-host.js +3 -2
  139. package/dist/internal/crypto/random-host.js.map +1 -1
  140. package/dist/internal/crypto/random-host.native.d.ts +6 -1
  141. package/dist/internal/crypto/random-host.native.d.ts.map +1 -1
  142. package/dist/internal/crypto/random-host.native.js +14 -10
  143. package/dist/internal/crypto/random-host.native.js.map +1 -1
  144. package/dist/internal/crypto/random-host.node.d.ts +1 -1
  145. package/dist/internal/crypto/random-host.node.d.ts.map +1 -1
  146. package/dist/internal/crypto/random-host.node.js +1 -1
  147. package/dist/internal/crypto/random-host.node.js.map +1 -1
  148. package/dist/internal/crypto/random.d.ts +12 -3
  149. package/dist/internal/crypto/random.d.ts.map +1 -1
  150. package/dist/internal/crypto/random.js +14 -3
  151. package/dist/internal/crypto/random.js.map +1 -1
  152. package/dist/internal/crypto/utils.d.ts.map +1 -1
  153. package/dist/internal/crypto/utils.js +10 -6
  154. package/dist/internal/crypto/utils.js.map +1 -1
  155. package/dist/internal/encoding/proto/primitives.d.ts +2 -0
  156. package/dist/internal/encoding/proto/primitives.d.ts.map +1 -1
  157. package/dist/internal/encoding/proto/primitives.js +2 -1
  158. package/dist/internal/encoding/proto/primitives.js.map +1 -1
  159. package/dist/internal/encoding/proto/signal-message.d.ts +1 -0
  160. package/dist/internal/encoding/proto/signal-message.d.ts.map +1 -1
  161. package/dist/internal/encoding/proto/signal-message.js +2 -1
  162. package/dist/internal/encoding/proto/signal-message.js.map +1 -1
  163. package/dist/internal/groups/authority-certificate.d.ts.map +1 -1
  164. package/dist/internal/groups/authority-certificate.js +2 -1
  165. package/dist/internal/groups/authority-certificate.js.map +1 -1
  166. package/dist/internal/groups/encrypted-state.d.ts.map +1 -1
  167. package/dist/internal/groups/encrypted-state.js +9 -7
  168. package/dist/internal/groups/encrypted-state.js.map +1 -1
  169. package/dist/internal/groups/invite-link.d.ts.map +1 -1
  170. package/dist/internal/groups/invite-link.js +2 -1
  171. package/dist/internal/groups/invite-link.js.map +1 -1
  172. package/dist/internal/groups/manager.d.ts.map +1 -1
  173. package/dist/internal/groups/manager.js +5 -5
  174. package/dist/internal/groups/manager.js.map +1 -1
  175. package/dist/internal/groups/sdk-store.d.ts.map +1 -1
  176. package/dist/internal/groups/sdk-store.js +4 -3
  177. package/dist/internal/groups/sdk-store.js.map +1 -1
  178. package/dist/internal/groups/server-engine.d.ts +6 -1
  179. package/dist/internal/groups/server-engine.d.ts.map +1 -1
  180. package/dist/internal/groups/server-engine.js +11 -15
  181. package/dist/internal/groups/server-engine.js.map +1 -1
  182. package/dist/internal/groups/wire.d.ts.map +1 -1
  183. package/dist/internal/groups/wire.js +2 -1
  184. package/dist/internal/groups/wire.js.map +1 -1
  185. package/dist/internal/platform/blob.d.ts +10 -0
  186. package/dist/internal/platform/blob.d.ts.map +1 -0
  187. package/dist/internal/platform/blob.js +30 -0
  188. package/dist/internal/platform/blob.js.map +1 -0
  189. package/dist/internal/platform/env.d.ts +13 -0
  190. package/dist/internal/platform/env.d.ts.map +1 -0
  191. package/dist/internal/platform/env.js +17 -0
  192. package/dist/internal/platform/env.js.map +1 -0
  193. package/dist/internal/platform/index.d.ts +5 -0
  194. package/dist/internal/platform/index.d.ts.map +1 -0
  195. package/dist/internal/platform/index.js +5 -0
  196. package/dist/internal/platform/index.js.map +1 -0
  197. package/dist/internal/platform/url.d.ts +72 -0
  198. package/dist/internal/platform/url.d.ts.map +1 -0
  199. package/dist/internal/platform/url.js +275 -0
  200. package/dist/internal/platform/url.js.map +1 -0
  201. package/dist/internal/platform/utf8.d.ts +28 -0
  202. package/dist/internal/platform/utf8.d.ts.map +1 -0
  203. package/dist/internal/platform/utf8.js +167 -0
  204. package/dist/internal/platform/utf8.js.map +1 -0
  205. package/dist/internal/protocol/sealed-sender/delivery-token.d.ts +1 -1
  206. package/dist/internal/protocol/sealed-sender/delivery-token.d.ts.map +1 -1
  207. package/dist/internal/protocol/sealed-sender/delivery-token.js +5 -10
  208. package/dist/internal/protocol/sealed-sender/delivery-token.js.map +1 -1
  209. package/dist/internal/protocol/sealed-sender/proto/index.d.ts.map +1 -1
  210. package/dist/internal/protocol/sealed-sender/proto/index.js +2 -4
  211. package/dist/internal/protocol/sealed-sender/proto/index.js.map +1 -1
  212. package/dist/internal/protocol/sender-keys/manager.d.ts.map +1 -1
  213. package/dist/internal/protocol/sender-keys/manager.js +4 -3
  214. package/dist/internal/protocol/sender-keys/manager.js.map +1 -1
  215. package/dist/internal/protocol/spqr/ml-kem-braid/noble-pq/index.d.ts +4 -4
  216. package/dist/internal/protocol/spqr/ml-kem-braid/noble-pq/index.d.ts.map +1 -1
  217. package/dist/internal/protocol/spqr/ml-kem-braid/noble-pq/index.js +8 -10
  218. package/dist/internal/protocol/spqr/ml-kem-braid/noble-pq/index.js.map +1 -1
  219. package/dist/internal/protocol/username/hash.d.ts.map +1 -1
  220. package/dist/internal/protocol/username/hash.js +18 -3
  221. package/dist/internal/protocol/username/hash.js.map +1 -1
  222. package/dist/internal/protocol/username/link.d.ts.map +1 -1
  223. package/dist/internal/protocol/username/link.js +2 -1
  224. package/dist/internal/protocol/username/link.js.map +1 -1
  225. package/dist/internal/protocol/username/proof.d.ts.map +1 -1
  226. package/dist/internal/protocol/username/proof.js +2 -1
  227. package/dist/internal/protocol/username/proof.js.map +1 -1
  228. package/dist/internal/sesame/device-registry.d.ts +22 -6
  229. package/dist/internal/sesame/device-registry.d.ts.map +1 -1
  230. package/dist/internal/sesame/device-registry.js +18 -12
  231. package/dist/internal/sesame/device-registry.js.map +1 -1
  232. package/dist/internal/sesame/index.d.ts +1 -1
  233. package/dist/internal/sesame/index.d.ts.map +1 -1
  234. package/dist/internal/sesame/manager.d.ts.map +1 -1
  235. package/dist/internal/sesame/manager.js +3 -2
  236. package/dist/internal/sesame/manager.js.map +1 -1
  237. package/dist/internal/session/index.d.ts +1 -2
  238. package/dist/internal/session/index.d.ts.map +1 -1
  239. package/dist/internal/session/index.js +1 -1
  240. package/dist/internal/session/index.js.map +1 -1
  241. package/dist/internal/session/validation.d.ts +0 -80
  242. package/dist/internal/session/validation.d.ts.map +1 -1
  243. package/dist/internal/session/validation.js +0 -134
  244. package/dist/internal/session/validation.js.map +1 -1
  245. package/dist/local/store/device-record.d.ts +18 -0
  246. package/dist/local/store/device-record.d.ts.map +1 -0
  247. package/dist/local/store/device-record.js +34 -0
  248. package/dist/local/store/device-record.js.map +1 -0
  249. package/dist/local/store/expo/adapter.d.ts +59 -238
  250. package/dist/local/store/expo/adapter.d.ts.map +1 -1
  251. package/dist/local/store/expo/adapter.js +83 -640
  252. package/dist/local/store/expo/adapter.js.map +1 -1
  253. package/dist/local/store/expo/driver.d.ts +16 -0
  254. package/dist/local/store/expo/driver.d.ts.map +1 -0
  255. package/dist/local/store/expo/driver.js +141 -0
  256. package/dist/local/store/expo/driver.js.map +1 -0
  257. package/dist/local/store/expo/index.d.ts +3 -12
  258. package/dist/local/store/expo/index.d.ts.map +1 -1
  259. package/dist/local/store/expo/index.js +1 -8
  260. package/dist/local/store/expo/index.js.map +1 -1
  261. package/dist/local/store/expo/maintenance.d.ts +3 -2
  262. package/dist/local/store/expo/maintenance.d.ts.map +1 -1
  263. package/dist/local/store/expo/maintenance.js +5 -34
  264. package/dist/local/store/expo/maintenance.js.map +1 -1
  265. package/dist/local/store/index.d.ts +10 -5
  266. package/dist/local/store/index.d.ts.map +1 -1
  267. package/dist/local/store/index.js +10 -5
  268. package/dist/local/store/index.js.map +1 -1
  269. package/dist/local/store/key-value/adapter.d.ts +326 -0
  270. package/dist/local/store/key-value/adapter.d.ts.map +1 -0
  271. package/dist/local/store/key-value/adapter.js +1472 -0
  272. package/dist/local/store/key-value/adapter.js.map +1 -0
  273. package/dist/local/store/{react-native → key-value}/backend-conformance.d.ts +7 -8
  274. package/dist/local/store/key-value/backend-conformance.d.ts.map +1 -0
  275. package/dist/local/store/{react-native → key-value}/backend-conformance.js +4 -5
  276. package/dist/local/store/key-value/backend-conformance.js.map +1 -0
  277. package/dist/local/store/key-value/batch.d.ts +41 -0
  278. package/dist/local/store/key-value/batch.d.ts.map +1 -0
  279. package/dist/local/store/key-value/batch.js +77 -0
  280. package/dist/local/store/key-value/batch.js.map +1 -0
  281. package/dist/local/store/key-value/device-record.d.ts +23 -0
  282. package/dist/local/store/key-value/device-record.d.ts.map +1 -0
  283. package/dist/local/store/key-value/device-record.js +33 -0
  284. package/dist/local/store/key-value/device-record.js.map +1 -0
  285. package/dist/local/store/key-value/index.d.ts +24 -0
  286. package/dist/local/store/key-value/index.d.ts.map +1 -0
  287. package/dist/local/store/key-value/index.js +8 -0
  288. package/dist/local/store/key-value/index.js.map +1 -0
  289. package/dist/local/store/key-value/realm/index.d.ts +83 -0
  290. package/dist/local/store/key-value/realm/index.d.ts.map +1 -0
  291. package/dist/local/store/key-value/realm/index.js +102 -0
  292. package/dist/local/store/key-value/realm/index.js.map +1 -0
  293. package/dist/local/store/{react-native → key-value}/storage.d.ts +6 -6
  294. package/dist/local/store/key-value/storage.d.ts.map +1 -0
  295. package/dist/local/store/key-value/storage.js.map +1 -0
  296. package/dist/local/store/key-value/transactional-backend.d.ts +50 -0
  297. package/dist/local/store/key-value/transactional-backend.d.ts.map +1 -0
  298. package/dist/local/store/key-value/transactional-backend.js +90 -0
  299. package/dist/local/store/key-value/transactional-backend.js.map +1 -0
  300. package/dist/local/store/key-value/value-key.d.ts +34 -0
  301. package/dist/local/store/key-value/value-key.d.ts.map +1 -0
  302. package/dist/local/store/key-value/value-key.js +83 -0
  303. package/dist/local/store/key-value/value-key.js.map +1 -0
  304. package/dist/local/store/memory/adapter.d.ts +8 -0
  305. package/dist/local/store/memory/adapter.d.ts.map +1 -1
  306. package/dist/local/store/memory/adapter.js +60 -75
  307. package/dist/local/store/memory/adapter.js.map +1 -1
  308. package/dist/local/store/node/adapter.d.ts +74 -130
  309. package/dist/local/store/node/adapter.d.ts.map +1 -1
  310. package/dist/local/store/node/adapter.js +83 -727
  311. package/dist/local/store/node/adapter.js.map +1 -1
  312. package/dist/local/store/node/index.d.ts +8 -6
  313. package/dist/local/store/node/index.d.ts.map +1 -1
  314. package/dist/local/store/node/index.js +3 -7
  315. package/dist/local/store/node/index.js.map +1 -1
  316. package/dist/local/store/node/maintenance.d.ts +5 -0
  317. package/dist/local/store/node/maintenance.d.ts.map +1 -0
  318. package/dist/local/store/node/maintenance.js +7 -0
  319. package/dist/local/store/node/maintenance.js.map +1 -0
  320. package/dist/local/store/node/owner-lock.d.ts +26 -0
  321. package/dist/local/store/node/owner-lock.d.ts.map +1 -0
  322. package/dist/local/store/node/owner-lock.js +88 -0
  323. package/dist/local/store/node/owner-lock.js.map +1 -0
  324. package/dist/local/store/react-native/adapter.d.ts +63 -273
  325. package/dist/local/store/react-native/adapter.d.ts.map +1 -1
  326. package/dist/local/store/react-native/adapter.js +80 -1405
  327. package/dist/local/store/react-native/adapter.js.map +1 -1
  328. package/dist/local/store/react-native/index.d.ts +7 -19
  329. package/dist/local/store/react-native/index.d.ts.map +1 -1
  330. package/dist/local/store/react-native/index.js +2 -7
  331. package/dist/local/store/react-native/index.js.map +1 -1
  332. package/dist/local/store/react-native/maintenance.d.ts +5 -0
  333. package/dist/local/store/react-native/maintenance.d.ts.map +1 -0
  334. package/dist/local/store/react-native/maintenance.js +7 -0
  335. package/dist/local/store/react-native/maintenance.js.map +1 -0
  336. package/dist/local/store/sqlite/better-sqlite3-multiple-ciphers-driver.d.ts +38 -0
  337. package/dist/local/store/sqlite/better-sqlite3-multiple-ciphers-driver.d.ts.map +1 -0
  338. package/dist/local/store/sqlite/better-sqlite3-multiple-ciphers-driver.js +196 -0
  339. package/dist/local/store/sqlite/better-sqlite3-multiple-ciphers-driver.js.map +1 -0
  340. package/dist/local/store/sqlite/database.d.ts +20 -0
  341. package/dist/local/store/sqlite/database.d.ts.map +1 -0
  342. package/dist/local/store/sqlite/database.js +41 -0
  343. package/dist/local/store/sqlite/database.js.map +1 -0
  344. package/dist/local/store/sqlite/driver.d.ts +138 -0
  345. package/dist/local/store/sqlite/driver.d.ts.map +1 -0
  346. package/dist/local/store/sqlite/driver.js +10 -0
  347. package/dist/local/store/sqlite/driver.js.map +1 -0
  348. package/dist/local/store/sqlite/encryption.d.ts +61 -0
  349. package/dist/local/store/sqlite/encryption.d.ts.map +1 -0
  350. package/dist/local/store/sqlite/encryption.js +98 -0
  351. package/dist/local/store/sqlite/encryption.js.map +1 -0
  352. package/dist/local/store/sqlite/errors.d.ts +70 -0
  353. package/dist/local/store/sqlite/errors.d.ts.map +1 -0
  354. package/dist/local/store/sqlite/errors.js +101 -0
  355. package/dist/local/store/sqlite/errors.js.map +1 -0
  356. package/dist/local/store/sqlite/executor.d.ts +22 -0
  357. package/dist/local/store/sqlite/executor.d.ts.map +1 -0
  358. package/dist/local/store/sqlite/executor.js +129 -0
  359. package/dist/local/store/sqlite/executor.js.map +1 -0
  360. package/dist/local/store/sqlite/index.d.ts +20 -0
  361. package/dist/local/store/sqlite/index.d.ts.map +1 -0
  362. package/dist/local/store/sqlite/index.js +18 -0
  363. package/dist/local/store/sqlite/index.js.map +1 -0
  364. package/dist/local/store/sqlite/key-storage/account.d.ts +45 -0
  365. package/dist/local/store/sqlite/key-storage/account.d.ts.map +1 -0
  366. package/dist/local/store/sqlite/key-storage/account.js +125 -0
  367. package/dist/local/store/sqlite/key-storage/account.js.map +1 -0
  368. package/dist/local/store/sqlite/key-storage/contact-identities.d.ts +19 -0
  369. package/dist/local/store/sqlite/key-storage/contact-identities.d.ts.map +1 -0
  370. package/dist/local/store/sqlite/key-storage/contact-identities.js +85 -0
  371. package/dist/local/store/sqlite/key-storage/contact-identities.js.map +1 -0
  372. package/dist/local/store/sqlite/key-storage/context.d.ts +19 -0
  373. package/dist/local/store/sqlite/key-storage/context.d.ts.map +1 -0
  374. package/dist/local/store/sqlite/key-storage/context.js +18 -0
  375. package/dist/local/store/sqlite/key-storage/context.js.map +1 -0
  376. package/dist/local/store/sqlite/key-storage/identity-keys.d.ts +18 -0
  377. package/dist/local/store/sqlite/key-storage/identity-keys.d.ts.map +1 -0
  378. package/dist/local/store/sqlite/key-storage/identity-keys.js +88 -0
  379. package/dist/local/store/sqlite/key-storage/identity-keys.js.map +1 -0
  380. package/dist/local/store/sqlite/key-storage/index.d.ts +108 -0
  381. package/dist/local/store/sqlite/key-storage/index.d.ts.map +1 -0
  382. package/dist/local/store/sqlite/key-storage/index.js +241 -0
  383. package/dist/local/store/sqlite/key-storage/index.js.map +1 -0
  384. package/dist/local/store/sqlite/key-storage/message-records.d.ts +41 -0
  385. package/dist/local/store/sqlite/key-storage/message-records.d.ts.map +1 -0
  386. package/dist/local/store/sqlite/key-storage/message-records.js +133 -0
  387. package/dist/local/store/sqlite/key-storage/message-records.js.map +1 -0
  388. package/dist/local/store/sqlite/key-storage/metadata.d.ts +16 -0
  389. package/dist/local/store/sqlite/key-storage/metadata.d.ts.map +1 -0
  390. package/dist/local/store/sqlite/key-storage/metadata.js +53 -0
  391. package/dist/local/store/sqlite/key-storage/metadata.js.map +1 -0
  392. package/dist/local/store/sqlite/key-storage/one-time-prekeys.d.ts +36 -0
  393. package/dist/local/store/sqlite/key-storage/one-time-prekeys.d.ts.map +1 -0
  394. package/dist/local/store/sqlite/key-storage/one-time-prekeys.js +129 -0
  395. package/dist/local/store/sqlite/key-storage/one-time-prekeys.js.map +1 -0
  396. package/dist/local/store/sqlite/key-storage/session-trust.d.ts +10 -0
  397. package/dist/local/store/sqlite/key-storage/session-trust.d.ts.map +1 -0
  398. package/dist/local/store/sqlite/key-storage/session-trust.js +88 -0
  399. package/dist/local/store/sqlite/key-storage/session-trust.js.map +1 -0
  400. package/dist/local/store/sqlite/key-storage/sessions.d.ts +50 -0
  401. package/dist/local/store/sqlite/key-storage/sessions.d.ts.map +1 -0
  402. package/dist/local/store/sqlite/key-storage/sessions.js +209 -0
  403. package/dist/local/store/sqlite/key-storage/sessions.js.map +1 -0
  404. package/dist/local/store/sqlite/key-storage/signed-prekeys.d.ts +69 -0
  405. package/dist/local/store/sqlite/key-storage/signed-prekeys.d.ts.map +1 -0
  406. package/dist/local/store/sqlite/key-storage/signed-prekeys.js +219 -0
  407. package/dist/local/store/sqlite/key-storage/signed-prekeys.js.map +1 -0
  408. package/dist/local/store/sqlite/maintenance.d.ts +7 -0
  409. package/dist/local/store/sqlite/maintenance.d.ts.map +1 -0
  410. package/dist/local/store/sqlite/maintenance.js +32 -0
  411. package/dist/local/store/sqlite/maintenance.js.map +1 -0
  412. package/dist/local/store/sqlite/migrations.d.ts +31 -0
  413. package/dist/local/store/sqlite/migrations.d.ts.map +1 -0
  414. package/dist/local/store/sqlite/migrations.js +232 -0
  415. package/dist/local/store/sqlite/migrations.js.map +1 -0
  416. package/dist/local/store/{expo → sqlite}/models/ec-one-time-prekey.d.ts +17 -22
  417. package/dist/local/store/sqlite/models/ec-one-time-prekey.d.ts.map +1 -0
  418. package/dist/local/store/{expo → sqlite}/models/ec-one-time-prekey.js +61 -99
  419. package/dist/local/store/sqlite/models/ec-one-time-prekey.js.map +1 -0
  420. package/dist/local/store/{expo → sqlite}/models/ec-signed-prekey.d.ts +22 -25
  421. package/dist/local/store/sqlite/models/ec-signed-prekey.d.ts.map +1 -0
  422. package/dist/local/store/{expo → sqlite}/models/ec-signed-prekey.js +82 -128
  423. package/dist/local/store/sqlite/models/ec-signed-prekey.js.map +1 -0
  424. package/dist/local/store/sqlite/models/identity-key-id.d.ts.map +1 -0
  425. package/dist/local/store/sqlite/models/identity-key-id.js.map +1 -0
  426. package/dist/local/store/{expo → sqlite}/models/index.d.ts +5 -5
  427. package/dist/local/store/sqlite/models/index.d.ts.map +1 -0
  428. package/dist/local/store/{expo → sqlite}/models/index.js +12 -5
  429. package/dist/local/store/sqlite/models/index.js.map +1 -0
  430. package/dist/local/store/{expo → sqlite}/models/kyber-one-time-prekey.d.ts +17 -20
  431. package/dist/local/store/sqlite/models/kyber-one-time-prekey.d.ts.map +1 -0
  432. package/dist/local/store/{expo → sqlite}/models/kyber-one-time-prekey.js +65 -105
  433. package/dist/local/store/sqlite/models/kyber-one-time-prekey.js.map +1 -0
  434. package/dist/local/store/{expo → sqlite}/models/kyber-prekey-used.d.ts +3 -3
  435. package/dist/local/store/sqlite/models/kyber-prekey-used.d.ts.map +1 -0
  436. package/dist/local/store/{expo → sqlite}/models/kyber-prekey-used.js +13 -25
  437. package/dist/local/store/sqlite/models/kyber-prekey-used.js.map +1 -0
  438. package/dist/local/store/{expo → sqlite}/models/kyber-prekey.d.ts +16 -19
  439. package/dist/local/store/sqlite/models/kyber-prekey.d.ts.map +1 -0
  440. package/dist/local/store/{expo → sqlite}/models/kyber-prekey.js +67 -111
  441. package/dist/local/store/sqlite/models/kyber-prekey.js.map +1 -0
  442. package/dist/local/store/sqlite/models/local-identity.d.ts +51 -0
  443. package/dist/local/store/sqlite/models/local-identity.d.ts.map +1 -0
  444. package/dist/local/store/sqlite/models/local-identity.js +150 -0
  445. package/dist/local/store/sqlite/models/local-identity.js.map +1 -0
  446. package/dist/local/store/{expo → sqlite}/models/message-record.d.ts +15 -44
  447. package/dist/local/store/sqlite/models/message-record.d.ts.map +1 -0
  448. package/dist/local/store/{expo → sqlite}/models/message-record.js +43 -109
  449. package/dist/local/store/sqlite/models/message-record.js.map +1 -0
  450. package/dist/local/store/sqlite/models/recipient-identity.d.ts +21 -0
  451. package/dist/local/store/sqlite/models/recipient-identity.d.ts.map +1 -0
  452. package/dist/local/store/sqlite/models/recipient-identity.js +59 -0
  453. package/dist/local/store/sqlite/models/recipient-identity.js.map +1 -0
  454. package/dist/local/store/sqlite/models/replaced-prekeys.d.ts +23 -0
  455. package/dist/local/store/sqlite/models/replaced-prekeys.d.ts.map +1 -0
  456. package/dist/local/store/sqlite/models/replaced-prekeys.js +42 -0
  457. package/dist/local/store/sqlite/models/replaced-prekeys.js.map +1 -0
  458. package/dist/local/store/{expo → sqlite}/models/sender-key.d.ts +22 -23
  459. package/dist/local/store/sqlite/models/sender-key.d.ts.map +1 -0
  460. package/dist/local/store/{expo → sqlite}/models/sender-key.js +66 -94
  461. package/dist/local/store/sqlite/models/sender-key.js.map +1 -0
  462. package/dist/local/store/sqlite/models/sesame-user-record.d.ts +32 -0
  463. package/dist/local/store/sqlite/models/sesame-user-record.d.ts.map +1 -0
  464. package/dist/local/store/sqlite/models/sesame-user-record.js +78 -0
  465. package/dist/local/store/sqlite/models/sesame-user-record.js.map +1 -0
  466. package/dist/local/store/{expo → sqlite}/models/session.d.ts +24 -20
  467. package/dist/local/store/sqlite/models/session.d.ts.map +1 -0
  468. package/dist/local/store/{expo → sqlite}/models/session.js +54 -72
  469. package/dist/local/store/sqlite/models/session.js.map +1 -0
  470. package/dist/local/store/sqlite/models/skipped-sender-key.d.ts +24 -0
  471. package/dist/local/store/sqlite/models/skipped-sender-key.d.ts.map +1 -0
  472. package/dist/local/store/sqlite/models/skipped-sender-key.js +62 -0
  473. package/dist/local/store/sqlite/models/skipped-sender-key.js.map +1 -0
  474. package/dist/local/store/sqlite/op-sqlite-driver.d.ts +14 -0
  475. package/dist/local/store/sqlite/op-sqlite-driver.d.ts.map +1 -0
  476. package/dist/local/store/sqlite/op-sqlite-driver.js +180 -0
  477. package/dist/local/store/sqlite/op-sqlite-driver.js.map +1 -0
  478. package/dist/local/store/sqlite/open-store.d.ts +83 -0
  479. package/dist/local/store/sqlite/open-store.d.ts.map +1 -0
  480. package/dist/local/store/sqlite/open-store.js +177 -0
  481. package/dist/local/store/sqlite/open-store.js.map +1 -0
  482. package/dist/local/store/sqlite/schema.d.ts +102 -0
  483. package/dist/local/store/sqlite/schema.d.ts.map +1 -0
  484. package/dist/local/store/sqlite/schema.js +61 -0
  485. package/dist/local/store/sqlite/schema.js.map +1 -0
  486. package/dist/local/store/sqlite/store.d.ts +199 -0
  487. package/dist/local/store/sqlite/store.d.ts.map +1 -0
  488. package/dist/local/store/sqlite/store.js +494 -0
  489. package/dist/local/store/sqlite/store.js.map +1 -0
  490. package/dist/local/store/sqlite/web/driver.d.ts +50 -0
  491. package/dist/local/store/sqlite/web/driver.d.ts.map +1 -0
  492. package/dist/local/store/sqlite/web/driver.js +169 -0
  493. package/dist/local/store/sqlite/web/driver.js.map +1 -0
  494. package/dist/local/store/sqlite/web/protocol.d.ts +80 -0
  495. package/dist/local/store/sqlite/web/protocol.d.ts.map +1 -0
  496. package/dist/local/store/sqlite/web/protocol.js +13 -0
  497. package/dist/local/store/sqlite/web/protocol.js.map +1 -0
  498. package/dist/local/store/sqlite/web/sqlite3mc/sqlite3.mjs +14526 -0
  499. package/dist/local/store/sqlite/web/sqlite3mc/sqlite3.wasm +0 -0
  500. package/dist/local/store/sqlite/web/worker.d.ts +36 -0
  501. package/dist/local/store/sqlite/web/worker.d.ts.map +1 -0
  502. package/dist/local/store/sqlite/web/worker.js +616 -0
  503. package/dist/local/store/sqlite/web/worker.js.map +1 -0
  504. package/dist/local/store/web/adapter.d.ts +5 -14
  505. package/dist/local/store/web/adapter.d.ts.map +1 -1
  506. package/dist/local/store/web/adapter.js +119 -106
  507. package/dist/local/store/web/adapter.js.map +1 -1
  508. package/dist/local/store/web/device-record.d.ts +23 -0
  509. package/dist/local/store/web/device-record.d.ts.map +1 -0
  510. package/dist/local/store/web/device-record.js +31 -0
  511. package/dist/local/store/web/device-record.js.map +1 -0
  512. package/dist/local/store/web-sqlite/adapter.d.ts +98 -0
  513. package/dist/local/store/web-sqlite/adapter.d.ts.map +1 -0
  514. package/dist/local/store/web-sqlite/adapter.js +151 -0
  515. package/dist/local/store/web-sqlite/adapter.js.map +1 -0
  516. package/dist/local/store/web-sqlite/index.d.ts +14 -0
  517. package/dist/local/store/web-sqlite/index.d.ts.map +1 -0
  518. package/dist/local/store/web-sqlite/index.js +3 -0
  519. package/dist/local/store/web-sqlite/index.js.map +1 -0
  520. package/dist/local/store/web-sqlite/maintenance.d.ts +5 -0
  521. package/dist/local/store/web-sqlite/maintenance.d.ts.map +1 -0
  522. package/dist/local/store/web-sqlite/maintenance.js +7 -0
  523. package/dist/local/store/web-sqlite/maintenance.js.map +1 -0
  524. package/dist/local/store/web-sqlite/store-locks.d.ts +33 -0
  525. package/dist/local/store/web-sqlite/store-locks.d.ts.map +1 -0
  526. package/dist/local/store/web-sqlite/store-locks.js +60 -0
  527. package/dist/local/store/web-sqlite/store-locks.js.map +1 -0
  528. package/dist/local/vault/electron-safe-storage.d.ts +45 -0
  529. package/dist/local/vault/electron-safe-storage.d.ts.map +1 -0
  530. package/dist/local/vault/electron-safe-storage.js +212 -0
  531. package/dist/local/vault/electron-safe-storage.js.map +1 -0
  532. package/dist/local/vault/index.d.ts +4 -2
  533. package/dist/local/vault/index.d.ts.map +1 -1
  534. package/dist/local/vault/indexed-db.d.ts +37 -0
  535. package/dist/local/vault/indexed-db.d.ts.map +1 -0
  536. package/dist/local/vault/indexed-db.js +102 -0
  537. package/dist/local/vault/indexed-db.js.map +1 -0
  538. package/dist/local/vault/react-native-keychain.d.ts +12 -0
  539. package/dist/local/vault/react-native-keychain.d.ts.map +1 -0
  540. package/dist/local/vault/react-native-keychain.js +71 -0
  541. package/dist/local/vault/react-native-keychain.js.map +1 -0
  542. package/dist/local/vault/require.d.ts +10 -0
  543. package/dist/local/vault/require.d.ts.map +1 -0
  544. package/dist/local/vault/require.js +16 -0
  545. package/dist/local/vault/require.js.map +1 -0
  546. package/dist/logger.d.ts.map +1 -1
  547. package/dist/logger.js +2 -1
  548. package/dist/logger.js.map +1 -1
  549. package/dist/media/index.d.ts.map +1 -1
  550. package/dist/media/index.js +2 -1
  551. package/dist/media/index.js.map +1 -1
  552. package/dist/profile/contact-state.d.ts.map +1 -1
  553. package/dist/profile/contact-state.js +2 -4
  554. package/dist/profile/contact-state.js.map +1 -1
  555. package/dist/profile/index.d.ts +0 -1
  556. package/dist/profile/index.d.ts.map +1 -1
  557. package/dist/profile/index.js +0 -2
  558. package/dist/profile/index.js.map +1 -1
  559. package/dist/profile/profile-key.d.ts +16 -11
  560. package/dist/profile/profile-key.d.ts.map +1 -1
  561. package/dist/profile/profile-key.js +29 -29
  562. package/dist/profile/profile-key.js.map +1 -1
  563. package/dist/profile/update-service.d.ts +6 -0
  564. package/dist/profile/update-service.d.ts.map +1 -1
  565. package/dist/profile/update-service.js +3 -1
  566. package/dist/profile/update-service.js.map +1 -1
  567. package/dist/remote/object-store/validation.d.ts.map +1 -1
  568. package/dist/remote/object-store/validation.js +2 -1
  569. package/dist/remote/object-store/validation.js.map +1 -1
  570. package/dist/remote/relay/memory/adapter.d.ts +2 -3
  571. package/dist/remote/relay/memory/adapter.d.ts.map +1 -1
  572. package/dist/remote/relay/memory/adapter.js +22 -30
  573. package/dist/remote/relay/memory/adapter.js.map +1 -1
  574. package/dist/remote/relay/memory/failures.d.ts.map +1 -1
  575. package/dist/remote/relay/memory/failures.js +2 -1
  576. package/dist/remote/relay/memory/failures.js.map +1 -1
  577. package/dist/remote/relay/memory/group-server.d.ts +5 -1
  578. package/dist/remote/relay/memory/group-server.d.ts.map +1 -1
  579. package/dist/remote/relay/memory/group-server.js +11 -1
  580. package/dist/remote/relay/memory/group-server.js.map +1 -1
  581. package/dist/safety/url.d.ts.map +1 -1
  582. package/dist/safety/url.js +21 -26
  583. package/dist/safety/url.js.map +1 -1
  584. package/dist/types/api.d.ts +15 -2
  585. package/dist/types/api.d.ts.map +1 -1
  586. package/dist/types/errors.d.ts +97 -1
  587. package/dist/types/errors.d.ts.map +1 -1
  588. package/dist/types/errors.js +105 -1
  589. package/dist/types/errors.js.map +1 -1
  590. package/dist/types/session.d.ts.map +1 -1
  591. package/dist/types/session.js +2 -1
  592. package/dist/types/session.js.map +1 -1
  593. package/dist/utils/retry.d.ts +2 -0
  594. package/dist/utils/retry.d.ts.map +1 -1
  595. package/dist/utils/retry.js +4 -2
  596. package/dist/utils/retry.js.map +1 -1
  597. package/docs/ASSURANCE.md +81 -8
  598. package/docs/CLIENT_COMPOSITION.md +1 -2
  599. package/docs/DEVIATIONS.md +27 -3
  600. package/docs/ERROR_HANDLING.md +6 -0
  601. package/docs/GETTING_STARTED.md +1 -2
  602. package/docs/PACKAGE_SURFACE.md +29 -11
  603. package/docs/RECIPES.md +1 -2
  604. package/examples/browser/index.html +1 -1
  605. package/local/store/README.md +117 -34
  606. package/local/store/expo/README.md +67 -47
  607. package/local/store/key-value/README.md +278 -0
  608. package/local/store/node/README.md +206 -45
  609. package/local/store/react-native/README.md +121 -52
  610. package/local/store/web/README.md +9 -0
  611. package/local/store/web-sqlite/README.md +202 -0
  612. package/local/vault/README.md +115 -2
  613. package/package.json +61 -42
  614. package/profile/README.md +9 -11
  615. package/remote/README.md +1 -2
  616. package/dist/local/store/expo/database-key.d.ts +0 -142
  617. package/dist/local/store/expo/database-key.d.ts.map +0 -1
  618. package/dist/local/store/expo/database-key.js +0 -312
  619. package/dist/local/store/expo/database-key.js.map +0 -1
  620. package/dist/local/store/expo/db.d.ts +0 -95
  621. package/dist/local/store/expo/db.d.ts.map +0 -1
  622. package/dist/local/store/expo/db.js +0 -147
  623. package/dist/local/store/expo/db.js.map +0 -1
  624. package/dist/local/store/expo/key-storage.d.ts +0 -429
  625. package/dist/local/store/expo/key-storage.d.ts.map +0 -1
  626. package/dist/local/store/expo/key-storage.js +0 -1361
  627. package/dist/local/store/expo/key-storage.js.map +0 -1
  628. package/dist/local/store/expo/models/ec-one-time-prekey.d.ts.map +0 -1
  629. package/dist/local/store/expo/models/ec-one-time-prekey.js.map +0 -1
  630. package/dist/local/store/expo/models/ec-signed-prekey.d.ts.map +0 -1
  631. package/dist/local/store/expo/models/ec-signed-prekey.js.map +0 -1
  632. package/dist/local/store/expo/models/identity-key-id.d.ts.map +0 -1
  633. package/dist/local/store/expo/models/identity-key-id.js.map +0 -1
  634. package/dist/local/store/expo/models/index.d.ts.map +0 -1
  635. package/dist/local/store/expo/models/index.js.map +0 -1
  636. package/dist/local/store/expo/models/kyber-one-time-prekey.d.ts.map +0 -1
  637. package/dist/local/store/expo/models/kyber-one-time-prekey.js.map +0 -1
  638. package/dist/local/store/expo/models/kyber-prekey-used.d.ts.map +0 -1
  639. package/dist/local/store/expo/models/kyber-prekey-used.js.map +0 -1
  640. package/dist/local/store/expo/models/kyber-prekey.d.ts.map +0 -1
  641. package/dist/local/store/expo/models/kyber-prekey.js.map +0 -1
  642. package/dist/local/store/expo/models/local-identity.d.ts +0 -52
  643. package/dist/local/store/expo/models/local-identity.d.ts.map +0 -1
  644. package/dist/local/store/expo/models/local-identity.js +0 -166
  645. package/dist/local/store/expo/models/local-identity.js.map +0 -1
  646. package/dist/local/store/expo/models/message-record.d.ts.map +0 -1
  647. package/dist/local/store/expo/models/message-record.js.map +0 -1
  648. package/dist/local/store/expo/models/recipient-identity.d.ts +0 -21
  649. package/dist/local/store/expo/models/recipient-identity.d.ts.map +0 -1
  650. package/dist/local/store/expo/models/recipient-identity.js +0 -66
  651. package/dist/local/store/expo/models/recipient-identity.js.map +0 -1
  652. package/dist/local/store/expo/models/replaced-prekey-utils.d.ts +0 -33
  653. package/dist/local/store/expo/models/replaced-prekey-utils.d.ts.map +0 -1
  654. package/dist/local/store/expo/models/replaced-prekey-utils.js +0 -54
  655. package/dist/local/store/expo/models/replaced-prekey-utils.js.map +0 -1
  656. package/dist/local/store/expo/models/sender-key.d.ts.map +0 -1
  657. package/dist/local/store/expo/models/sender-key.js.map +0 -1
  658. package/dist/local/store/expo/models/session.d.ts.map +0 -1
  659. package/dist/local/store/expo/models/session.js.map +0 -1
  660. package/dist/local/store/expo/schema.d.ts +0 -1917
  661. package/dist/local/store/expo/schema.d.ts.map +0 -1
  662. package/dist/local/store/expo/schema.js +0 -197
  663. package/dist/local/store/expo/schema.js.map +0 -1
  664. package/dist/local/store/node/database-encryption.d.ts +0 -109
  665. package/dist/local/store/node/database-encryption.d.ts.map +0 -1
  666. package/dist/local/store/node/database-encryption.js +0 -202
  667. package/dist/local/store/node/database-encryption.js.map +0 -1
  668. package/dist/local/store/node/database-file-commit.d.ts +0 -8
  669. package/dist/local/store/node/database-file-commit.d.ts.map +0 -1
  670. package/dist/local/store/node/database-file-commit.js +0 -62
  671. package/dist/local/store/node/database-file-commit.js.map +0 -1
  672. package/dist/local/store/node/database-key.d.ts +0 -129
  673. package/dist/local/store/node/database-key.d.ts.map +0 -1
  674. package/dist/local/store/node/database-key.js +0 -293
  675. package/dist/local/store/node/database-key.js.map +0 -1
  676. package/dist/local/store/node/database-lock.d.ts +0 -8
  677. package/dist/local/store/node/database-lock.d.ts.map +0 -1
  678. package/dist/local/store/node/database-lock.js +0 -44
  679. package/dist/local/store/node/database-lock.js.map +0 -1
  680. package/dist/local/store/node/database.d.ts +0 -226
  681. package/dist/local/store/node/database.d.ts.map +0 -1
  682. package/dist/local/store/node/database.js +0 -813
  683. package/dist/local/store/node/database.js.map +0 -1
  684. package/dist/local/store/react-native/backend-conformance.d.ts.map +0 -1
  685. package/dist/local/store/react-native/backend-conformance.js.map +0 -1
  686. package/dist/local/store/react-native/reference-backend.d.ts +0 -43
  687. package/dist/local/store/react-native/reference-backend.d.ts.map +0 -1
  688. package/dist/local/store/react-native/reference-backend.js +0 -178
  689. package/dist/local/store/react-native/reference-backend.js.map +0 -1
  690. package/dist/local/store/react-native/storage.d.ts.map +0 -1
  691. package/dist/local/store/react-native/storage.js.map +0 -1
  692. package/dist/profile/storage.d.ts +0 -61
  693. package/dist/profile/storage.d.ts.map +0 -1
  694. package/dist/profile/storage.js +0 -145
  695. package/dist/profile/storage.js.map +0 -1
  696. /package/dist/local/store/{react-native → key-value}/storage.js +0 -0
  697. /package/dist/local/store/{expo → sqlite}/models/identity-key-id.d.ts +0 -0
  698. /package/dist/local/store/{expo → sqlite}/models/identity-key-id.js +0 -0
@@ -1,743 +1,99 @@
1
1
  /**
2
- * Node.js Storage Adapter
2
+ * Node and Electron Signal Protocol Store
3
3
  *
4
- * Storage adapter for Node.js applications (CLI tools, servers, etc.)
5
- * Uses:
6
- * - Encrypted filesystem for key storage
7
- * - node:crypto for encryption
8
- * - Secure file permissions (0600)
9
- *
10
- * @example Usage
11
- * ```typescript
12
- * const storage = new NodeSignalProtocolStore({
13
- * dataDir: '~/.signal-protocol/signal'
14
- * });
15
- * await storage.initialize();
16
- *
17
- * // Store identity key
18
- * await storage.storeIdentityKey(keyPair);
19
- * ```
4
+ * The SDK owns the database file. One call opens it in a directory that the
5
+ * app chooses, gets or creates its key through the app's secret vault, applies
6
+ * the SDK migrations, and returns the store.
20
7
  */
21
- import { acceptContactIdentityRotation as acceptRotation, createUnverifiedContactIdentityRecord, evaluateContactIdentityCandidate, validateContactIdentityRecord, verifyContactIdentityRecord, } from '../../../keys/identity.js';
22
- import { assertCurrentSessionRecord } from '../../../types/session.js';
23
- import { ProtocolAddress } from '../../../types/address.js';
24
- import { IdentityKeyChange } from '../../../types/trust.js';
25
- import { EncryptionError, EncryptionErrorCode } from '../../../types/index.js';
26
- import { getNodeEncryptedDatabase } from './database.js';
27
- import { encodeCompositeIdentityV1, UNPINNED_DEVICE_IDENTITY_KEY } from '../../../keys/identity.js';
28
- import { deserializeSessionRecord, serializeSessionRecord } from '../session-codec.js';
29
- import { parseReceivedContent } from '../received-content.js';
30
- function serializeDeviceRecord(record) {
31
- return {
32
- ...record,
33
- identityKey: Array.from(record.identityKey),
34
- session: record.session ? serializeSessionRecord(record.session) : null,
35
- };
36
- }
37
- function deserializeDeviceRecord(data) {
38
- return {
39
- ...data,
40
- identityKey: Uint8Array.from(data.identityKey),
41
- session: data.session ? deserializeSessionRecord(data.session) : null,
42
- };
8
+ import { createBetterSqlite3MultipleCiphersDriver } from '../sqlite/better-sqlite3-multiple-ciphers-driver.js';
9
+ import { openSqliteStore, resetSqliteStore, } from '../sqlite/open-store.js';
10
+ import { SqliteSignalProtocolStore } from '../sqlite/store.js';
11
+ import { withOwnerLock } from './owner-lock.js';
12
+ /** The database file name when the options name none. */
13
+ const DEFAULT_DATABASE_NAME = 'open-e2ee-signal-protocol.db';
14
+ /** The database of each open store, for the helpers of this entry. */
15
+ const databases = new WeakMap();
16
+ /** The executor of an open store. Not exported from the entry. */
17
+ export function nodeStoreDatabase(store) {
18
+ const database = databases.get(store);
19
+ if (!database)
20
+ throw new TypeError('Open the store with nodeStore().');
21
+ return database;
43
22
  }
44
- function serializeUserRecord(record) {
45
- return {
46
- ...record,
47
- devices: Array.from(record.devices.entries(), ([deviceId, device]) => [
48
- deviceId,
49
- serializeDeviceRecord(device),
50
- ]),
51
- };
52
- }
53
- function deserializeUserRecord(data) {
54
- return {
55
- ...data,
56
- devices: new Map(data.devices.map(([deviceId, device]) => [deviceId, deserializeDeviceRecord(device)])),
57
- };
23
+ /** Run `run` on the core options of the store, with the owner lock. */
24
+ async function withStoreOptions(options, operation, run) {
25
+ const driver = createBetterSqlite3MultipleCiphersDriver({ directory: options.directory });
26
+ const storeOptions = { ...options, driver, name: options.name ?? DEFAULT_DATABASE_NAME };
27
+ return withOwnerLock(driver, storeOptions.name, operation, () => run(storeOptions));
58
28
  }
59
29
  /**
60
- * Decode a persisted device session, treating an unreadable one as absent.
30
+ * Local Signal Protocol state for Node and the Electron main process, in an
31
+ * SDK-owned SQLCipher database.
32
+ *
33
+ * Open it with {@link nodeStore}. The store holds the database file until
34
+ * {@link NodeSignalProtocolStore.close}. A second open of the same file in
35
+ * the process fails with `INVALID_STATE`, and an open in another process
36
+ * fails with `SqliteStoreInUseError`.
37
+ *
38
+ * Every table holds material that must not leave the device, including the
39
+ * group sender keys. SQLCipher encrypts the whole file, so the database key
40
+ * in the vault is the only thing that protects it.
61
41
  *
62
- * `getSessionRecord` already drops a session it cannot decode instead of
63
- * failing the caller. A maintenance sweep that threw on the same record would
64
- * abort the whole pass, leaving a store that can never expire anything again.
42
+ * @category Key Storage
43
+ * @see {@link SignalProtocolLocalStore} for interface documentation
65
44
  */
66
- function readStoredSession(serialized) {
67
- if (!serialized)
68
- return null;
69
- try {
70
- return deserializeSessionRecord(serialized);
45
+ export class NodeSignalProtocolStore extends SqliteSignalProtocolStore {
46
+ constructor(database, logger) {
47
+ super(database, { logger });
48
+ databases.set(this, database);
49
+ }
50
+ /** @internal Use {@link nodeStore}. */
51
+ static async open(options) {
52
+ const database = await withStoreOptions(options, 'open', openSqliteStore);
53
+ return new NodeSignalProtocolStore(database, options.logger);
54
+ }
55
+ /** @internal Use {@link resetNodeStore}. */
56
+ static async reset(options) {
57
+ const database = await withStoreOptions(options, 'reset', resetSqliteStore);
58
+ return new NodeSignalProtocolStore(database, options.logger);
59
+ }
60
+ /**
61
+ * Wait for the queued work, then close the database and release the file.
62
+ * Every later call rejects with `SqliteStoreClosedError`.
63
+ */
64
+ close() {
65
+ return nodeStoreDatabase(this).close();
71
66
  }
72
- catch {
73
- return null;
74
- }
75
- }
76
- /** Read a nested dictionary level, creating it on demand for writes. */
77
- function branch(parent, key, create) {
78
- const existing = parent[key];
79
- if (existing !== undefined)
80
- return existing;
81
- const created = create();
82
- parent[key] = created;
83
- return created;
84
- }
85
- /** Same, for a level whose value is itself a dictionary. */
86
- function subtree(parent, key) {
87
- return branch(parent, key, () => Object.create(null));
88
67
  }
89
- /** Remove one device from a group/user/device tree, pruning levels left empty. */
90
- function pruneSenderKeyDevice(tree, groupId, userId, deviceId) {
91
- const users = tree[groupId];
92
- const devices = users?.[userId];
93
- if (!users || !devices)
94
- return;
95
- delete devices[String(deviceId)];
96
- if (Object.keys(devices).length === 0)
97
- delete users[userId];
98
- if (Object.keys(users).length === 0)
99
- delete tree[groupId];
68
+ /**
69
+ * Open the store. On first use it creates the database key in the vault, then
70
+ * the database file. With `encryptionAtRest: false` it does not use the vault.
71
+ *
72
+ * @throws SqliteStoreInUseError when a store in another process holds the
73
+ * file. The open reads no vault entry and does not touch the file.
74
+ * @throws EncryptionError with `LOCAL_STORE_KEY_LOST` when the database file
75
+ * exists and the vault holds no key for it, also after the directory moved.
76
+ * Move the vault entry, restore it, or call {@link resetNodeStore}.
77
+ * @throws EncryptionError with `KEY_STORAGE_ERROR` when the vault fails or
78
+ * holds a key of the wrong size, when the key does not open the file, or
79
+ * when the file was created with the other `encryptionAtRest` setting.
80
+ * @throws EncryptionError with `INVALID_STATE` when the name is not valid,
81
+ * when a store of this process holds the file, or when a newer SDK wrote
82
+ * the file.
83
+ */
84
+ export function nodeStore(options) {
85
+ return NodeSignalProtocolStore.open(options);
100
86
  }
101
87
  /**
102
- * Node.js Storage Adapter
88
+ * Delete the database file, then create a new key, and return the open, empty
89
+ * store. This is the only way to open a store whose key is lost.
103
90
  *
104
- * Provides encrypted filesystem storage for Signal Protocol keys.
91
+ * @throws SqliteStoreInUseError when a store in another process holds the
92
+ * file. The reset changes nothing.
93
+ * @throws EncryptionError with `INVALID_STATE` when the name is not valid, or
94
+ * when a store of this process holds the file. Close that store first.
105
95
  */
106
- export class NodeSignalProtocolStore {
107
- db;
108
- constructor(config) {
109
- this.db = getNodeEncryptedDatabase(config?.dataDir);
110
- }
111
- // ============================================================================
112
- // Initialization
113
- // ============================================================================
114
- async initialize() {
115
- await this.db.initialize();
116
- }
117
- // ============================================================================
118
- // Identity Key Management (Own Keys)
119
- // ============================================================================
120
- async storeIdentityKey(keyPair, identityType) {
121
- const it = identityType ?? 'aci';
122
- await this.db.storeIdentityKey(keyPair, it);
123
- }
124
- async getIdentityKey(identityType) {
125
- const it = identityType ?? 'aci';
126
- return await this.db.getIdentityKey(it);
127
- }
128
- async hasIdentityKey(identityType) {
129
- const key = await this.getIdentityKey(identityType);
130
- return key !== null;
131
- }
132
- async getLocalRegistrationId(identityType) {
133
- return await this.db.getRegistrationId(identityType ?? 'aci');
134
- }
135
- async setLocalRegistrationId(id, identityType) {
136
- // A registration ID identifies this install for the lifetime of the
137
- // install. Holding it in memory would hand every restart a fresh one and
138
- // make every peer read the process as a reinstall.
139
- await this.db.setRegistrationId(identityType ?? 'aci', id);
140
- }
141
- // ============================================================================
142
- // Identity Verification (Contact Identity Keys)
143
- // ============================================================================
144
- async saveContactIdentity(address, identity, identityType, suppliedCommitment) {
145
- const key = this.getContactIdentityKey(address, identityType);
146
- const existing = await this.db.getContactIdentity(key);
147
- const status = evaluateContactIdentityCandidate(existing, identity, suppliedCommitment);
148
- if (status === 'NEW') {
149
- await this.db.storeContactIdentity(key, createUnverifiedContactIdentityRecord(identity, Date.now()));
150
- return IdentityKeyChange.NEW_IDENTITY;
151
- }
152
- if (status === 'MATCH')
153
- return IdentityKeyChange.UNCHANGED;
154
- if (status === 'ROLLBACK')
155
- return IdentityKeyChange.ROLLBACK;
156
- return IdentityKeyChange.CHANGED;
157
- }
158
- async getContactIdentity(address, identityType) {
159
- const record = await this.db.getContactIdentity(this.getContactIdentityKey(address, identityType));
160
- if (record)
161
- validateContactIdentityRecord(record);
162
- return record;
163
- }
164
- async acceptContactIdentityRotation(address, identity, identityType, suppliedCommitment) {
165
- return await this.acceptContactIdentityRotationAndDeleteSessions(address, identity, identityType, suppliedCommitment);
166
- }
167
- async acceptContactIdentityRotationAndDeleteSessions(address, identity, identityType, suppliedCommitment) {
168
- const key = this.getContactIdentityKey(address, identityType);
169
- return await this.db.mutateContactIdentityAndDeleteSessions(key, address.userId, (existing) => {
170
- if (!existing)
171
- throw new Error('Cannot rotate an unseen identity');
172
- return acceptRotation(existing, identity, Date.now(), suppliedCommitment);
173
- });
174
- }
175
- async verifyContactIdentity(address, identity, identityType, suppliedCommitment) {
176
- const key = this.getContactIdentityKey(address, identityType);
177
- return await this.db.mutateContactIdentity(key, (existing) => {
178
- if (!existing)
179
- throw new Error('Cannot verify an unseen identity');
180
- return verifyContactIdentityRecord(existing, identity, Date.now(), suppliedCommitment);
181
- });
182
- }
183
- async isTrustedIdentity(address, identity, _direction, identityType) {
184
- const saved = await this.getContactIdentity(address, identityType);
185
- const status = evaluateContactIdentityCandidate(saved, identity);
186
- return status === 'NEW' || status === 'MATCH';
187
- }
188
- // ============================================================================
189
- // PreKey Management
190
- // ============================================================================
191
- async storeEcSignedPreKey(signedPreKey, identityType) {
192
- const it = identityType ?? 'aci';
193
- await this.db.storeEcSignedPreKey(signedPreKey, it);
194
- }
195
- async getEcSignedPreKey(keyId, identityType) {
196
- const it = identityType ?? 'aci';
197
- return await this.db.getEcSignedPreKey(keyId, it);
198
- }
199
- async getAllEcSignedPreKeys(identityType) {
200
- const it = identityType ?? 'aci';
201
- return await this.db.getAllEcSignedPreKeys(it);
202
- }
203
- async removeEcSignedPreKey(keyId, identityType) {
204
- const it = identityType ?? 'aci';
205
- return await this.db.removeEcSignedPreKey(keyId, it);
206
- }
207
- async storeEcOneTimePreKeys(prekeys, identityType) {
208
- const it = identityType ?? 'aci';
209
- await this.db.storeEcOneTimePreKeys(prekeys, it);
210
- }
211
- async getEcOneTimePreKeys(identityType) {
212
- const it = identityType ?? 'aci';
213
- return await this.db.getEcOneTimePreKeys(it);
214
- }
215
- async removeEcOneTimePreKey(preKeyId, identityType) {
216
- const it = identityType ?? 'aci';
217
- await this.db.removeEcOneTimePreKey((key) => key.keyId === preKeyId, it);
218
- }
219
- async storeKemOneTimePreKeys(prekeys, identityType) {
220
- await this.db.storeKemOneTimePreKeys(prekeys, identityType ?? 'aci');
221
- }
222
- async getKemOneTimePreKeys(identityType) {
223
- return await this.db.getKemOneTimePreKeys(identityType ?? 'aci');
224
- }
225
- async getKemOneTimePreKey(keyId, identityType) {
226
- return ((await this.getKemOneTimePreKeys(identityType)).find((key) => key.keyId === keyId) ?? null);
227
- }
228
- async removeKemOneTimePreKey(keyId, identityType) {
229
- await this.db.removeKemOneTimePreKey(keyId, identityType ?? 'aci');
230
- }
231
- async getKemOneTimePreKeyCount(identityType) {
232
- return (await this.getKemOneTimePreKeys(identityType)).length;
233
- }
234
- async storeKyberPreKey(kyberPreKey, identityType) {
235
- const it = identityType ?? 'aci';
236
- await this.db.storeKyberPreKey(kyberPreKey, it);
237
- }
238
- async getKyberPreKey(identityType) {
239
- const it = identityType ?? 'aci';
240
- return await this.db.getCurrentKyberPreKey(it);
241
- }
242
- async getKyberPreKeyById(keyId, identityType) {
243
- return await this.db.getKyberPreKeyById(keyId, identityType ?? 'aci');
244
- }
245
- async markKyberPreKeyUsed(kyberPreKeyId, signedPreKeyId, baseKeyBytes, identityType) {
246
- const it = identityType ?? 'aci';
247
- await this.db.markKyberPreKeyUsed(it, { kyberPreKeyId, signedPreKeyId, baseKeyBytes });
248
- }
249
- // ============================================================================
250
- // Session Management
251
- // ============================================================================
252
- async storeSessionRecord(address, record) {
253
- assertCurrentSessionRecord(record);
254
- const key = this.getAddressKey(address);
255
- await this.db.storeSession(key, address.userId, address.deviceId, serializeSessionRecord(record));
256
- }
257
- async getSessionRecord(address) {
258
- const key = this.getAddressKey(address);
259
- const serialized = await this.db.getSession(key);
260
- if (serialized) {
261
- try {
262
- const record = deserializeSessionRecord(serialized);
263
- assertCurrentSessionRecord(record);
264
- return record;
265
- }
266
- catch {
267
- await this.db.deleteSession(key);
268
- return null;
269
- }
270
- }
271
- return null;
272
- }
273
- async deleteSessionRecord(address) {
274
- const key = this.getAddressKey(address);
275
- await this.db.deleteSession(key);
276
- }
277
- async archiveCurrentSession(address, newSession) {
278
- const key = this.getAddressKey(address);
279
- const serialized = await this.db.getSession(key);
280
- const record = serialized ? deserializeSessionRecord(serialized) : null;
281
- if (!record) {
282
- return;
283
- }
284
- // Archive current session by its baseKey
285
- if (record.currentSession) {
286
- if (!record.archivedSessions) {
287
- record.archivedSessions = {};
288
- }
289
- record.archivedSessions[record.currentSession.baseKey] = record.currentSession;
290
- }
291
- // Set new session as current
292
- record.currentSession = newSession || null;
293
- await this.db.storeSession(key, address.userId, address.deviceId, serializeSessionRecord(record));
294
- }
295
- async getSessionsForUser(userId) {
296
- const serialized = await this.db.getSessionsForUser(userId);
297
- return serialized.map(deserializeSessionRecord);
298
- }
299
- async commitSessionTrust(commit) {
300
- assertCurrentSessionRecord(commit.record);
301
- const contactKey = this.getContactIdentityKey(commit.address, commit.contactIdentityType);
302
- await this.db.commitSessionTrust(this.getAddressKey(commit.address), commit.address.userId, commit.address.deviceId, serializeSessionRecord(commit.record), commit.localIdentityType, contactKey, (existing) => {
303
- const status = evaluateContactIdentityCandidate(existing, commit.contactIdentity);
304
- if (status === 'NEW') {
305
- return createUnverifiedContactIdentityRecord(commit.contactIdentity, Date.now());
306
- }
307
- if (status === 'MATCH' && existing)
308
- return existing;
309
- throw new Error(`Atomic session/trust commit rejected contact identity status ${status}`);
310
- }, commit.oneTimePreKeyId, commit.kemOneTimePreKeyId, commit.receivedContent, commit.kyberPreKeyUse);
311
- }
312
- async hasSession(address) {
313
- const record = await this.getSessionRecord(address);
314
- return record !== null;
315
- }
316
- async getSessionCount() {
317
- const stats = await this.db.getStats();
318
- return stats.sessions;
319
- }
320
- // ============================================================================
321
- // Database Encryption
322
- // ============================================================================
323
- async getDatabaseKey() {
324
- const key = await this.db['dbKey'];
325
- if (!key) {
326
- throw new EncryptionError('Database key not initialized', EncryptionErrorCode.INITIALIZATION_FAILED);
327
- }
328
- return key;
329
- }
330
- // ============================================================================
331
- // SESAME Multi-Device Session Management
332
- //
333
- // A device's session is the same session the protocol store holds for that
334
- // address. Writes go to both so `getSessionRecord` and `getDeviceSession`
335
- // never disagree about which ratchet is current.
336
- // ============================================================================
337
- async getUserRecord(userId) {
338
- const { users } = await this.db.readSesameState();
339
- const stored = users[userId];
340
- return stored ? deserializeUserRecord(stored) : null;
341
- }
342
- async setUserRecord(userId, record) {
343
- const serialized = serializeUserRecord(record);
344
- await this.db.mutateSesameState(({ users, sessions }) => {
345
- users[userId] = serialized;
346
- for (const [deviceId, device] of serialized.devices) {
347
- if (!device.session)
348
- continue;
349
- sessions[this.getAddressKey({ userId, deviceId })] = {
350
- userId,
351
- deviceId,
352
- serializedRecord: device.session,
353
- };
354
- }
355
- });
356
- }
357
- async getDeviceRecord(userId, deviceId) {
358
- // The live session is read through `getSessionRecord` rather than out of
359
- // the device record. A session this store would refuse to hand the protocol
360
- // layer is therefore not handed to the SESAME layer either.
361
- const session = await this.getSessionRecord(ProtocolAddress.create(userId, deviceId));
362
- const { users } = await this.db.readSesameState();
363
- const stored = users[userId]?.devices.find(([id]) => id === deviceId)?.[1] ?? null;
364
- if (!session)
365
- return stored ? deserializeDeviceRecord(stored) : null;
366
- const now = Date.now();
367
- return {
368
- ...(stored ? deserializeDeviceRecord(stored) : {}),
369
- userId,
370
- deviceId,
371
- // The identity pin is a trust decision, so it comes from what was
372
- // persisted rather than from whichever session happens to be current.
373
- // Re-deriving it would unpin a device the moment its session is archived.
374
- identityKey: stored?.identityKey.length
375
- ? Uint8Array.from(stored.identityKey)
376
- : session.currentSession?.remoteIdentity
377
- ? encodeCompositeIdentityV1(session.currentSession.remoteIdentity)
378
- : UNPINNED_DEVICE_IDENTITY_KEY,
379
- session,
380
- createdAt: session.metadata?.createdAt ?? stored?.createdAt ?? now,
381
- updatedAt: now,
382
- };
383
- }
384
- async setDeviceRecord(userId, deviceId, record) {
385
- const serialized = serializeDeviceRecord(record);
386
- await this.db.mutateSesameState(({ users, sessions }) => {
387
- const now = Date.now();
388
- const user = branch(users, userId, () => ({
389
- userId,
390
- devices: [],
391
- createdAt: now,
392
- updatedAt: now,
393
- }));
394
- const index = user.devices.findIndex(([id]) => id === deviceId);
395
- if (index >= 0)
396
- user.devices[index] = [deviceId, serialized];
397
- else
398
- user.devices.push([deviceId, serialized]);
399
- user.updatedAt = now;
400
- if (serialized.session) {
401
- sessions[this.getAddressKey({ userId, deviceId })] = {
402
- userId,
403
- deviceId,
404
- serializedRecord: serialized.session,
405
- };
406
- }
407
- });
408
- }
409
- async deleteDeviceRecord(userId, deviceId) {
410
- await this.db.mutateSesameState(({ users, sessions }) => {
411
- delete sessions[this.getAddressKey({ userId, deviceId })];
412
- const user = users[userId];
413
- if (!user)
414
- return;
415
- user.devices = user.devices.filter(([id]) => id !== deviceId);
416
- user.updatedAt = Date.now();
417
- if (user.devices.length === 0)
418
- delete users[userId];
419
- });
420
- }
421
- async getDeviceSession(userId, deviceId) {
422
- return (await this.getDeviceRecord(userId, deviceId))?.session ?? null;
423
- }
424
- async setDeviceSession(userId, deviceId, session) {
425
- const record = await this.getDeviceRecord(userId, deviceId);
426
- if (!record)
427
- throw new Error(`Device record not found: ${userId}:${deviceId}`);
428
- record.session = session;
429
- record.updatedAt = Date.now();
430
- await this.setDeviceRecord(userId, deviceId, record);
431
- }
432
- async deleteStaleRecords(maxLatency) {
433
- return await this.db.mutateSesameState(({ users }) => {
434
- const now = Date.now();
435
- let deleted = 0;
436
- for (const userId of Object.keys(users)) {
437
- const user = users[userId];
438
- const kept = user.devices.filter(([, device]) => {
439
- const record = readStoredSession(device.session);
440
- const hasNoSessions = !record ||
441
- (!record.currentSession && Object.keys(record.archivedSessions).length === 0);
442
- return !(hasNoSessions && now - device.createdAt > maxLatency);
443
- });
444
- deleted += user.devices.length - kept.length;
445
- user.devices = kept;
446
- user.updatedAt = now;
447
- if (user.devices.length === 0)
448
- delete users[userId];
449
- }
450
- return deleted;
451
- });
452
- }
453
- async cleanupExpiredSessions(maxRecv) {
454
- return await this.db.mutateSesameState(({ users, sessions }) => {
455
- const now = Date.now();
456
- let deleted = 0;
457
- for (const user of Object.values(users)) {
458
- for (const [deviceId, device] of user.devices) {
459
- if (!device.session)
460
- continue;
461
- const record = readStoredSession(device.session);
462
- if (!record) {
463
- device.session = null;
464
- delete sessions[this.getAddressKey({ userId: user.userId, deviceId })];
465
- continue;
466
- }
467
- const createdAt = record.metadata?.createdAt ?? 0;
468
- if (now - createdAt > maxRecv) {
469
- if (record.currentSession)
470
- deleted++;
471
- deleted += Object.keys(record.archivedSessions).length;
472
- device.session = null;
473
- delete sessions[this.getAddressKey({ userId: user.userId, deviceId })];
474
- }
475
- else {
476
- for (const [baseKey, state] of Object.entries(record.archivedSessions)) {
477
- if (now - (state?.lastUsedAt ?? createdAt) <= maxRecv)
478
- continue;
479
- delete record.archivedSessions[baseKey];
480
- deleted++;
481
- }
482
- device.session = serializeSessionRecord(record);
483
- sessions[this.getAddressKey({ userId: user.userId, deviceId })] = {
484
- userId: user.userId,
485
- deviceId,
486
- serializedRecord: device.session,
487
- };
488
- }
489
- device.updatedAt = now;
490
- }
491
- user.updatedAt = now;
492
- }
493
- return deleted;
494
- });
495
- }
496
- async getAllUserIds() {
497
- const { users } = await this.db.readSesameState();
498
- return Object.keys(users);
499
- }
500
- async getSesameDeviceIds(userId) {
501
- const { users } = await this.db.readSesameState();
502
- return users[userId]?.devices.map(([deviceId]) => deviceId) ?? [];
503
- }
504
- // ============================================================================
505
- // Sender Keys (Group Messaging)
506
- // ============================================================================
507
- async storeSenderKey(groupId, userId, deviceId, state) {
508
- await this.db.mutateSenderKeyState(({ current }) => {
509
- const users = subtree(current, groupId);
510
- subtree(users, userId)[String(deviceId)] = state;
511
- });
512
- }
513
- async getSenderKey(groupId, userId, deviceId) {
514
- const { current } = await this.db.readSenderKeyState();
515
- return current[groupId]?.[userId]?.[String(deviceId)] ?? null;
516
- }
517
- async deleteSenderKey(groupId, userId, deviceId) {
518
- await this.db.mutateSenderKeyState(({ current, records }) => {
519
- pruneSenderKeyDevice(current, groupId, userId, deviceId);
520
- pruneSenderKeyDevice(records, groupId, userId, deviceId);
521
- });
522
- }
523
- async resolveGroupForSenderKeyId(senderKeyId, userId, deviceId) {
524
- if (!senderKeyId)
525
- return null;
526
- const { current, records } = await this.db.readSenderKeyState();
527
- const device = String(deviceId);
528
- for (const groupId of new Set([...Object.keys(current), ...Object.keys(records)])) {
529
- if (current[groupId]?.[userId]?.[device]?.senderKeyId === senderKeyId)
530
- return groupId;
531
- // A message encrypted just before a rotation still names the superseded
532
- // key, so the retained previous states have to be searched too.
533
- const retained = records[groupId]?.[userId]?.[device];
534
- if (retained?.some((state) => state.senderKeyId === senderKeyId))
535
- return groupId;
536
- }
537
- return null;
538
- }
539
- async getAllSenderKeysForGroup(groupId) {
540
- const { current } = await this.db.readSenderKeyState();
541
- const users = current[groupId];
542
- if (!users)
543
- return [];
544
- return Object.values(users).flatMap((devices) => Object.values(devices));
545
- }
546
- async deleteAllSenderKeysForGroup(groupId) {
547
- return await this.db.mutateSenderKeyState(({ current, records, skipped }) => {
548
- const users = current[groupId];
549
- const count = users
550
- ? Object.values(users).reduce((total, devices) => total + Object.keys(devices).length, 0)
551
- : 0;
552
- // Each identifier is its own key, so deleting one group cannot reach a
553
- // group whose name merely shares a prefix with it.
554
- delete current[groupId];
555
- delete records[groupId];
556
- delete skipped[groupId];
557
- return count;
558
- });
559
- }
560
- async storeSenderKeyRecord(groupId, userId, deviceId, states, receive) {
561
- if (states.length === 0)
562
- return;
563
- await this.db.mutateSenderKeyState(({ current, records, skipped }) => {
564
- const device = String(deviceId);
565
- subtree(subtree(current, groupId), userId)[device] = states[0];
566
- subtree(subtree(records, groupId), userId)[device] = states;
567
- if (receive?.consumedChainIndex !== undefined) {
568
- const keys = skipped[groupId]?.[userId]?.[device];
569
- if (keys)
570
- delete keys[String(receive.consumedChainIndex)];
571
- }
572
- }, receive?.content);
573
- }
574
- async getSenderKeyRecord(groupId, userId, deviceId) {
575
- const { current, records } = await this.db.readSenderKeyState();
576
- const device = String(deviceId);
577
- const record = records[groupId]?.[userId]?.[device];
578
- if (record)
579
- return record;
580
- const state = current[groupId]?.[userId]?.[device];
581
- return state ? [state] : null;
582
- }
583
- // ============================================================================
584
- // Skipped Sender Keys (Out-of-Order Group Messages)
585
- // ============================================================================
586
- async storeSkippedSenderKey(groupId, senderId, senderDeviceId, chainIndex, messageKey) {
587
- await this.db.mutateSenderKeyState(({ skipped }) => {
588
- const senders = subtree(skipped, groupId);
589
- const devices = subtree(senders, senderId);
590
- subtree(devices, String(senderDeviceId))[String(chainIndex)] = messageKey;
591
- });
592
- }
593
- async getSkippedSenderKey(groupId, senderId, senderDeviceId, chainIndex) {
594
- const { skipped } = await this.db.readSenderKeyState();
595
- const stored = skipped[groupId]?.[senderId]?.[String(senderDeviceId)]?.[String(chainIndex)];
596
- return stored ?? null;
597
- }
598
- async deleteSkippedSenderKey(groupId, senderId, senderDeviceId, chainIndex) {
599
- await this.db.mutateSenderKeyState(({ skipped }) => {
600
- const keys = skipped[groupId]?.[senderId]?.[String(senderDeviceId)];
601
- if (keys)
602
- delete keys[String(chainIndex)];
603
- });
604
- }
605
- async countSkippedSenderKeys(groupId, senderId, senderDeviceId) {
606
- const { skipped } = await this.db.readSenderKeyState();
607
- const keys = skipped[groupId]?.[senderId]?.[String(senderDeviceId)];
608
- return keys ? Object.keys(keys).length : 0;
609
- }
610
- async deleteOldestSkippedSenderKeys(groupId, senderId, senderDeviceId, count) {
611
- return await this.db.mutateSenderKeyState(({ skipped }) => {
612
- const keys = skipped[groupId]?.[senderId]?.[String(senderDeviceId)];
613
- if (!keys)
614
- return 0;
615
- // Chain index is the message order, so the lowest indices are the oldest.
616
- const oldest = Object.keys(keys)
617
- .sort((a, b) => Number(a) - Number(b))
618
- .slice(0, count);
619
- for (const chainIndex of oldest)
620
- delete keys[chainIndex];
621
- return oldest.length;
622
- });
623
- }
624
- // ============================================================================
625
- // Message Records (SESAME Retry Support)
626
- // ============================================================================
627
- async storeMessageRecord(record) {
628
- await this.db.mutateMessageRecords((records) => {
629
- subtree(records, record.sessionId)[String(record.timestamp)] = record;
630
- });
631
- }
632
- async getMessageRecord(sessionId, timestamp) {
633
- const records = await this.db.readMessageRecords();
634
- return records[sessionId]?.[String(timestamp)] ?? null;
635
- }
636
- async deleteMessageRecord(sessionId, timestamp) {
637
- await this.db.mutateMessageRecords((records) => {
638
- const session = records[sessionId];
639
- if (!session)
640
- return;
641
- delete session[String(timestamp)];
642
- if (Object.keys(session).length === 0)
643
- delete records[sessionId];
644
- });
645
- }
646
- async deleteExpiredMessageRecords(maxAgeMs) {
647
- const cutoff = Date.now() - maxAgeMs;
648
- return await this.db.mutateMessageRecords((records) => {
649
- let deleted = 0;
650
- for (const sessionId of Object.keys(records)) {
651
- const session = records[sessionId];
652
- for (const key of Object.keys(session)) {
653
- if (session[key].createdAt >= cutoff)
654
- continue;
655
- delete session[key];
656
- deleted++;
657
- }
658
- if (Object.keys(session).length === 0)
659
- delete records[sessionId];
660
- }
661
- return deleted;
662
- });
663
- }
664
- async clearAllMessageRecords() {
665
- return await this.db.mutateMessageRecords((records) => {
666
- let deleted = 0;
667
- for (const sessionId of Object.keys(records)) {
668
- deleted += Object.keys(records[sessionId]).length;
669
- delete records[sessionId];
670
- }
671
- return deleted;
672
- });
673
- }
674
- async deleteMessageRecordsForSession(sessionId) {
675
- return await this.db.mutateMessageRecords((records) => {
676
- const deleted = Object.keys(records[sessionId] ?? {}).length;
677
- delete records[sessionId];
678
- return deleted;
679
- });
680
- }
681
- // ============================================================================
682
- // Metadata
683
- // ============================================================================
684
- async getMetadata(key) {
685
- return await this.db.getMetadataValue(key);
686
- }
687
- async getReceivedContent(id) {
688
- const value = await this.db.getMetadataValue(`received-content:${id}`);
689
- return value ? parseReceivedContent(value, id) : null;
690
- }
691
- async deleteReceivedContent(id) {
692
- await this.db.deleteMetadataValue(`received-content:${id}`);
693
- }
694
- async deleteExpiredReceivedContent(before) {
695
- return this.db.deleteExpiredReceivedContent(before);
696
- }
697
- async setMetadata(key, value) {
698
- await this.db.setMetadataValue(key, value);
699
- }
700
- async deleteMetadata(key) {
701
- await this.db.deleteMetadataValue(key);
702
- }
703
- async compareAndSetMetadata(key, expected, value) {
704
- return this.db.compareAndSetMetadataValue(key, expected, value);
705
- }
706
- // ============================================================================
707
- // Key Recovery (PQXDH §4.13 identifier-collision recovery)
708
- // ============================================================================
709
- async getEcSignedPreKeyMaxId(identityType) {
710
- return await this.db.getEcSignedPreKeyMaxId(identityType ?? 'aci');
711
- }
712
- async getKyberPreKeyMaxId(identityType) {
713
- return await this.db.getKyberPreKeyMaxId(identityType ?? 'aci');
714
- }
715
- async deleteAllPreKeys(identityType) {
716
- return await this.db.deleteAllPreKeys(identityType ?? 'aci');
717
- }
718
- async clearAllSessions() {
719
- // A device record whose session is gone is not a device this store can
720
- // reach. The SESAME records therefore go with the sessions in the same
721
- // commit.
722
- await this.db.clearSesameState();
723
- }
724
- async getDetailedStats() {
725
- return await this.db.getDetailedStats();
726
- }
727
- // ============================================================================
728
- // Utility
729
- // ============================================================================
730
- async clearAllKeys() {
731
- await this.db.deleteDatabase();
732
- }
733
- // ============================================================================
734
- // Helper Methods
735
- // ============================================================================
736
- getAddressKey(address) {
737
- return ProtocolAddress.toString(address);
738
- }
739
- getContactIdentityKey(address, identityType) {
740
- return `${address.userId}:${identityType ?? 'aci'}`;
741
- }
96
+ export function resetNodeStore(options) {
97
+ return NodeSignalProtocolStore.reset(options);
742
98
  }
743
99
  //# sourceMappingURL=adapter.js.map