@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
@@ -0,0 +1,36 @@
1
+ /**
2
+ * The dedicated module worker of the web SQLite driver.
3
+ *
4
+ * The worker loads the SQLite3 Multiple Ciphers Wasm engine and keeps each
5
+ * database file in its own `opfs-sahpool` pool, wrapped by the Multiple
6
+ * Ciphers VFS. It runs every statement for the driver in `./driver.ts`.
7
+ *
8
+ * A pool allows one connection, so the tabs of an origin share each file
9
+ * through one Web Lock, `open-e2ee:sqlite:<file>`:
10
+ *
11
+ * - The worker holds the pool attached, and the physical connection open,
12
+ * exactly while it holds the lock.
13
+ * - A worker that needs the file and does not hold the lock posts a request
14
+ * on the `BroadcastChannel` of the same name, then waits for the lock.
15
+ * - On a request, the holder finishes its current statement. At the next
16
+ * autocommit boundary it closes the connection, pauses the pool, and
17
+ * releases the lock. A transaction never moves to another tab.
18
+ * - The next holder attaches the pool and reopens the connection. It applies
19
+ * the key and the saved `foreign_keys` value again, and checks that
20
+ * `user_version` did not change while it was detached.
21
+ *
22
+ * Each request checks, in this order: the file name, the OPFS APIs, one
23
+ * access handle on a new probe file, and then the engine. So a context
24
+ * without OPFS reports `OPFS_UNAVAILABLE` and never downloads the Wasm, also
25
+ * when its CSP refuses the engine.
26
+ *
27
+ * A failure to attach the pool never changes the files. The vendored engine
28
+ * carries patches that keep the pool directory when its install fails and
29
+ * that release every access handle when an attach fails; see
30
+ * `./sqlite3mc/README.md`.
31
+ *
32
+ * The logical connection that the driver returns stays pinned to its file
33
+ * across these physical reopens.
34
+ */
35
+ export {};
36
+ //# sourceMappingURL=worker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"worker.d.ts","sourceRoot":"","sources":["../../../../../local/store/sqlite/web/worker.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG"}
@@ -0,0 +1,616 @@
1
+ /**
2
+ * The dedicated module worker of the web SQLite driver.
3
+ *
4
+ * The worker loads the SQLite3 Multiple Ciphers Wasm engine and keeps each
5
+ * database file in its own `opfs-sahpool` pool, wrapped by the Multiple
6
+ * Ciphers VFS. It runs every statement for the driver in `./driver.ts`.
7
+ *
8
+ * A pool allows one connection, so the tabs of an origin share each file
9
+ * through one Web Lock, `open-e2ee:sqlite:<file>`:
10
+ *
11
+ * - The worker holds the pool attached, and the physical connection open,
12
+ * exactly while it holds the lock.
13
+ * - A worker that needs the file and does not hold the lock posts a request
14
+ * on the `BroadcastChannel` of the same name, then waits for the lock.
15
+ * - On a request, the holder finishes its current statement. At the next
16
+ * autocommit boundary it closes the connection, pauses the pool, and
17
+ * releases the lock. A transaction never moves to another tab.
18
+ * - The next holder attaches the pool and reopens the connection. It applies
19
+ * the key and the saved `foreign_keys` value again, and checks that
20
+ * `user_version` did not change while it was detached.
21
+ *
22
+ * Each request checks, in this order: the file name, the OPFS APIs, one
23
+ * access handle on a new probe file, and then the engine. So a context
24
+ * without OPFS reports `OPFS_UNAVAILABLE` and never downloads the Wasm, also
25
+ * when its CSP refuses the engine.
26
+ *
27
+ * A failure to attach the pool never changes the files. The vendored engine
28
+ * carries patches that keep the pool directory when its install fails and
29
+ * that release every access handle when an attach fails; see
30
+ * `./sqlite3mc/README.md`.
31
+ *
32
+ * The logical connection that the driver returns stays pinned to its file
33
+ * across these physical reopens.
34
+ */
35
+ import sqlite3InitModule from './sqlite3mc/sqlite3.mjs';
36
+ import { generateRandomBytesSync } from '../../../../internal/crypto/random.js';
37
+ import { EncryptionError, EncryptionErrorCode } from '../../../../types/errors.js';
38
+ /** A file name is one path segment, so it cannot name another pool. */
39
+ const FILE_NAME = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/;
40
+ const KEY_LENGTH = 32;
41
+ /** Multiple Ciphers reads `raw:` and 32 bytes as a raw key, with no key derivation. */
42
+ const RAW_KEY_PREFIX = new Uint8Array([0x72, 0x61, 0x77, 0x3a]);
43
+ /** The pool keeps its slot files in this subdirectory of its directory. */
44
+ const POOL_SLOT_DIRECTORY = '.opaque';
45
+ /**
46
+ * After a tab dies, the browser can release its lock before its access
47
+ * handles. The next holder waits this long for the handles.
48
+ */
49
+ const HANDLE_WAIT_MS = 5_000;
50
+ const HANDLE_RETRY_MS = 50;
51
+ const scope = globalThis;
52
+ const engineConfiguration = globalThis;
53
+ const slots = new Map();
54
+ /** Multiple Ciphers VFSes that this worker created, by pool name. */
55
+ const encryptingVfses = new Set();
56
+ let wasmUrl = null;
57
+ let engine = null;
58
+ /** This context created an access handle on a new OPFS file. */
59
+ let opfsUsable = false;
60
+ function invalidState(message, operation) {
61
+ return new EncryptionError(message, EncryptionErrorCode.INVALID_STATE, { operation });
62
+ }
63
+ function detail(error) {
64
+ if (error instanceof Error)
65
+ return `${error.name}: ${error.message}`;
66
+ return String(error);
67
+ }
68
+ function engineUnavailable(error) {
69
+ return new EncryptionError('The SQLite Wasm engine did not load in its worker. The Content Security Policy ' +
70
+ "of the worker script must allow 'wasm-unsafe-eval' in script-src, and the " +
71
+ `server must send sqlite3.wasm as application/wasm. Cause: ${detail(error)}`, EncryptionErrorCode.SQLITE_ENGINE_UNAVAILABLE, { operation: 'loadEngine' });
72
+ }
73
+ function opfsUnavailable(cause) {
74
+ return new EncryptionError(`This browser context cannot keep a SQLite database in the origin private file system: ${cause}`, EncryptionErrorCode.OPFS_UNAVAILABLE, { operation: 'attachPool' });
75
+ }
76
+ function fileBusy(cause) {
77
+ return new EncryptionError(`The SQLite database file could not be opened in the origin private file system this time, ` +
78
+ `and it is unchanged. Retry later. Cause: ${cause}`, EncryptionErrorCode.OPFS_FILE_BUSY, { operation: 'attachPool' });
79
+ }
80
+ function delay(milliseconds) {
81
+ return new Promise((resolve) => setTimeout(resolve, milliseconds));
82
+ }
83
+ // ===== Engine =====
84
+ /**
85
+ * Compiles the Wasm before init. The engine's own loader resolves a promise
86
+ * that never rejects, so without this step a CSP refusal would leave init
87
+ * pending forever. A failed load is not kept: the next call tries again.
88
+ */
89
+ function loadEngine() {
90
+ engine ??= compileAndInitialize().catch((error) => {
91
+ engine = null;
92
+ throw error;
93
+ });
94
+ return engine;
95
+ }
96
+ async function compileAndInitialize() {
97
+ if (wasmUrl === null) {
98
+ throw engineUnavailable(new Error('The driver did not configure the Wasm URL'));
99
+ }
100
+ let module;
101
+ try {
102
+ module = await WebAssembly.compileStreaming(fetch(wasmUrl, { credentials: 'same-origin' }));
103
+ }
104
+ catch (error) {
105
+ throw engineUnavailable(error);
106
+ }
107
+ let instantiationFailed;
108
+ const failure = new Promise((_, reject) => {
109
+ instantiationFailed = reject;
110
+ });
111
+ // A cross-origin isolated context would also install the `opfs` VFS, which
112
+ // starts `sqlite3-opfs-async-proxy.js`. The package does not ship that
113
+ // script, and the driver uses only `opfs-sahpool`. The engine reads this
114
+ // configuration once, at init, and then deletes it.
115
+ engineConfiguration.sqlite3ApiConfig = { disable: { vfs: { opfs: true, 'opfs-vfs': true } } };
116
+ try {
117
+ return await Promise.race([
118
+ sqlite3InitModule({
119
+ instantiateWasm(imports, onSuccess) {
120
+ WebAssembly.instantiate(module, imports).then((instance) => onSuccess(instance, module), instantiationFailed);
121
+ return {};
122
+ },
123
+ }),
124
+ failure,
125
+ ]);
126
+ }
127
+ catch (error) {
128
+ throw engineUnavailable(error);
129
+ }
130
+ }
131
+ // ===== Pool and lock =====
132
+ function assertStorageApis() {
133
+ const missing = [];
134
+ if (typeof FileSystemFileHandle !== 'function' ||
135
+ !('createSyncAccessHandle' in FileSystemFileHandle.prototype) ||
136
+ typeof navigator.storage?.getDirectory !== 'function') {
137
+ missing.push('OPFS synchronous access handles');
138
+ }
139
+ if (typeof navigator.locks?.request !== 'function')
140
+ missing.push('Web Locks');
141
+ if (typeof BroadcastChannel !== 'function')
142
+ missing.push('BroadcastChannel');
143
+ if (missing.length > 0)
144
+ throw opfsUnavailable(`missing ${missing.join(', ')}`);
145
+ }
146
+ function slotFor(file, operation) {
147
+ if (!FILE_NAME.test(file)) {
148
+ throw invalidState('A SQLite file name must be 1 to 64 letters, digits, dots, dashes, or underscores, and start with a letter or digit', operation);
149
+ }
150
+ const existing = slots.get(file);
151
+ if (existing !== undefined)
152
+ return existing;
153
+ assertStorageApis();
154
+ const poolName = `open-e2ee-sqlite-${file}`;
155
+ const slot = {
156
+ path: `/${file}`,
157
+ lockName: `open-e2ee:sqlite:${file}`,
158
+ poolName,
159
+ poolDirectory: `.${poolName}`,
160
+ vfsName: `multipleciphers-${poolName}`,
161
+ channel: new BroadcastChannel(`open-e2ee:sqlite:${file}`),
162
+ pool: null,
163
+ release: null,
164
+ requested: false,
165
+ tail: Promise.resolve(),
166
+ connection: null,
167
+ database: null,
168
+ };
169
+ slot.channel.onmessage = () => {
170
+ slot.requested = true;
171
+ void enqueue(slot, async () => {
172
+ const sqlite3 = await loadEngine();
173
+ yieldIfRequested(slot, sqlite3);
174
+ }).catch(() => undefined);
175
+ };
176
+ slots.set(file, slot);
177
+ return slot;
178
+ }
179
+ /** Runs one task at a time for a slot, in call order. */
180
+ function enqueue(slot, task) {
181
+ const run = slot.tail.then(task);
182
+ slot.tail = run.then(() => undefined, () => undefined);
183
+ return run;
184
+ }
185
+ async function acquireLock(slot) {
186
+ slot.channel.postMessage('request');
187
+ await new Promise((granted, failed) => {
188
+ navigator.locks
189
+ .request(slot.lockName, () => new Promise((release) => {
190
+ slot.release = release;
191
+ granted();
192
+ }))
193
+ .catch(failed);
194
+ });
195
+ // A request posted before this grant reached a context that did not hold
196
+ // the lock. The lock manager still lists the waiter.
197
+ // It only adds a request: `onmessage` can set the flag while the query runs.
198
+ const state = await navigator.locks.query();
199
+ if ((state.pending ?? []).some((lock) => lock.name === slot.lockName))
200
+ slot.requested = true;
201
+ }
202
+ /**
203
+ * Proves once that this context can use OPFS access handles, on a new file
204
+ * that no other context holds. So a later failure is a property of the
205
+ * database file, not of the runtime, such as an ephemeral context that
206
+ * refuses OPFS.
207
+ */
208
+ async function assertOpfsUsable() {
209
+ if (opfsUsable)
210
+ return;
211
+ const name = `.open-e2ee-sqlite-probe-${Array.from(generateRandomBytesSync(8), (byte) => byte.toString(16).padStart(2, '0')).join('')}`;
212
+ try {
213
+ const root = await navigator.storage.getDirectory();
214
+ const file = (await root.getFileHandle(name, { create: true }));
215
+ try {
216
+ (await file.createSyncAccessHandle()).close();
217
+ }
218
+ finally {
219
+ await root.removeEntry(name).catch(() => undefined);
220
+ }
221
+ }
222
+ catch (error) {
223
+ throw opfsUnavailable(detail(error));
224
+ }
225
+ opfsUsable = true;
226
+ }
227
+ /**
228
+ * Waits until every slot file of the pool accepts a new access handle. After
229
+ * a tab dies, the browser can release its lock before its handles, and the
230
+ * pool cannot attach until the handles are free.
231
+ */
232
+ async function waitForFreeHandles(slot) {
233
+ let slotDirectory;
234
+ try {
235
+ const root = await navigator.storage.getDirectory();
236
+ const poolDirectory = await root.getDirectoryHandle(slot.poolDirectory);
237
+ slotDirectory = await poolDirectory.getDirectoryHandle(POOL_SLOT_DIRECTORY);
238
+ }
239
+ catch (error) {
240
+ if (error instanceof DOMException && error.name === 'NotFoundError')
241
+ return;
242
+ throw fileBusy(detail(error));
243
+ }
244
+ const deadline = Date.now() + HANDLE_WAIT_MS;
245
+ // `FileSystemDirectoryHandle` is async iterable; the DOM library of this
246
+ // build does not declare it.
247
+ const entries = slotDirectory;
248
+ for (;;) {
249
+ try {
250
+ for await (const [, handle] of entries) {
251
+ if (handle.kind !== 'file')
252
+ continue;
253
+ const file = handle;
254
+ (await file.createSyncAccessHandle()).close();
255
+ }
256
+ return;
257
+ }
258
+ catch (error) {
259
+ if (Date.now() >= deadline)
260
+ throw fileBusy(detail(error));
261
+ await delay(HANDLE_RETRY_MS);
262
+ }
263
+ }
264
+ }
265
+ /**
266
+ * Attaches the pool of the slot. A failed install or unpause leaves the pool
267
+ * directory as it was and holds no access handle, so the next call tries
268
+ * again.
269
+ */
270
+ async function attachPool(slot, sqlite3) {
271
+ if (slot.pool !== null && !slot.pool.isPaused())
272
+ return;
273
+ await waitForFreeHandles(slot);
274
+ if (slot.pool === null) {
275
+ try {
276
+ slot.pool = await sqlite3.installOpfsSAHPoolVfs({
277
+ name: slot.poolName,
278
+ directory: slot.poolDirectory,
279
+ verbosity: 1,
280
+ forceReinitIfPreviouslyFailed: true,
281
+ });
282
+ }
283
+ catch (error) {
284
+ throw fileBusy(detail(error));
285
+ }
286
+ }
287
+ else {
288
+ try {
289
+ await slot.pool.unpauseVfs();
290
+ }
291
+ catch (error) {
292
+ throw fileBusy(detail(error));
293
+ }
294
+ }
295
+ if (!encryptingVfses.has(slot.poolName)) {
296
+ const rc = sqlite3.capi.sqlite3mc_vfs_create(slot.poolName, 0);
297
+ if (rc !== 0)
298
+ throw new Error(`sqlite3mc_vfs_create: ${sqlite3.capi.sqlite3_js_rc_str(rc)}`);
299
+ encryptingVfses.add(slot.poolName);
300
+ }
301
+ }
302
+ // ===== Physical connection =====
303
+ function applyKey(sqlite3, database, key) {
304
+ database.exec("PRAGMA cipher = 'sqlcipher'");
305
+ database.exec('PRAGMA legacy = 4');
306
+ const length = RAW_KEY_PREFIX.length + key.length;
307
+ const pointer = sqlite3.wasm.alloc(length);
308
+ try {
309
+ const heap = sqlite3.wasm.heap8u();
310
+ heap.set(RAW_KEY_PREFIX, pointer);
311
+ heap.set(key, pointer + RAW_KEY_PREFIX.length);
312
+ const rc = sqlite3.capi.sqlite3_key_v2(database.pointer, 'main', pointer, length);
313
+ if (rc !== 0)
314
+ throw new Error(sqlite3.capi.sqlite3_errmsg(database.pointer));
315
+ }
316
+ finally {
317
+ // The heap view can change when memory grows, so read it again.
318
+ sqlite3.wasm.heap8u().fill(0, pointer, pointer + length);
319
+ sqlite3.wasm.dealloc(pointer);
320
+ }
321
+ }
322
+ function openPhysical(slot, sqlite3, flags, key) {
323
+ const database = new sqlite3.oo1.DB({ filename: slot.path, flags, vfs: slot.vfsName });
324
+ try {
325
+ if (key !== null)
326
+ applyKey(sqlite3, database, key);
327
+ // The cipher accepts any key and fails only at the first read. This read
328
+ // rejects a wrong key, a missing key, or a key on a plaintext file with
329
+ // `file is not a database`, before any other setting.
330
+ readValue(database, 'SELECT count(*) FROM sqlite_schema');
331
+ }
332
+ catch (error) {
333
+ database.close();
334
+ throw error;
335
+ }
336
+ return database;
337
+ }
338
+ /** The first column of the first row of `sql`, or `undefined` for no row. */
339
+ function readValue(database, sql) {
340
+ const statement = database.prepare(sql);
341
+ try {
342
+ return statement.step() ? Object.values(statement.get({}))[0] : undefined;
343
+ }
344
+ finally {
345
+ statement.finalize();
346
+ }
347
+ }
348
+ function readInteger(database, pragma) {
349
+ const value = readValue(database, `PRAGMA ${pragma}`);
350
+ if (typeof value !== 'number')
351
+ throw new Error(`PRAGMA ${pragma} returned ${typeof value}`);
352
+ return value;
353
+ }
354
+ function readIntegerOrNull(database, pragma) {
355
+ try {
356
+ return readInteger(database, pragma);
357
+ }
358
+ catch {
359
+ return null;
360
+ }
361
+ }
362
+ /** Opens the physical connection again after another context held the file. */
363
+ function reopen(slot, sqlite3, connection) {
364
+ if (!slot.pool.getFileNames().includes(slot.path)) {
365
+ throw invalidState('The database file was removed while another tab held it', 'reopen');
366
+ }
367
+ const database = openPhysical(slot, sqlite3, 'w', connection.key);
368
+ try {
369
+ if (connection.foreignKeys !== null) {
370
+ database.exec(`PRAGMA foreign_keys = ${connection.foreignKeys === 0 ? 'OFF' : 'ON'}`);
371
+ }
372
+ if (connection.userVersion !== null) {
373
+ const userVersion = readInteger(database, 'user_version');
374
+ if (userVersion !== connection.userVersion) {
375
+ throw invalidState(`Another tab changed the database schema version from ${connection.userVersion} to ${userVersion}. Close this store and open it again.`, 'reopen');
376
+ }
377
+ }
378
+ }
379
+ catch (error) {
380
+ database.close();
381
+ throw error;
382
+ }
383
+ slot.database = database;
384
+ }
385
+ /** Closes the physical connection, pauses the pool, and releases the lock. */
386
+ function detach(slot) {
387
+ const database = slot.database;
388
+ if (database !== null) {
389
+ const connection = slot.connection;
390
+ if (connection !== null) {
391
+ connection.foreignKeys = readIntegerOrNull(database, 'foreign_keys');
392
+ connection.userVersion = readIntegerOrNull(database, 'user_version');
393
+ }
394
+ slot.database = null;
395
+ database.close();
396
+ }
397
+ slot.pool?.pauseVfs();
398
+ const release = slot.release;
399
+ slot.release = null;
400
+ slot.requested = false;
401
+ release?.();
402
+ }
403
+ function atAutocommitBoundary(slot, sqlite3) {
404
+ return (slot.database === null || sqlite3.capi.sqlite3_get_autocommit(slot.database.pointer) !== 0);
405
+ }
406
+ function yieldIfRequested(slot, sqlite3) {
407
+ if (slot.release !== null && slot.requested && atAutocommitBoundary(slot, sqlite3)) {
408
+ detach(slot);
409
+ }
410
+ }
411
+ /**
412
+ * Runs `operation` while this worker holds the file. The OPFS probe runs
413
+ * before the engine loads; see the order at the top. The worker keeps the
414
+ * lock after the operation only while a connection is open and no other
415
+ * context asked for it, or while a transaction is open.
416
+ */
417
+ function withFile(slot, operation) {
418
+ return enqueue(slot, async () => {
419
+ await assertOpfsUsable();
420
+ const sqlite3 = await loadEngine();
421
+ if (slot.release === null)
422
+ await acquireLock(slot);
423
+ try {
424
+ await attachPool(slot, sqlite3);
425
+ if (slot.connection !== null && slot.database === null) {
426
+ reopen(slot, sqlite3, slot.connection);
427
+ }
428
+ return operation(sqlite3);
429
+ }
430
+ finally {
431
+ if (slot.connection === null || slot.database === null) {
432
+ detach(slot);
433
+ }
434
+ else {
435
+ yieldIfRequested(slot, sqlite3);
436
+ }
437
+ }
438
+ });
439
+ }
440
+ // ===== Operations =====
441
+ function connectionOf(slot, id, operation) {
442
+ const connection = slot.connection;
443
+ if (connection === null || connection.id !== id) {
444
+ throw invalidState('The SQLite connection is closed', operation);
445
+ }
446
+ return connection;
447
+ }
448
+ function toRow(row) {
449
+ for (const [column, value] of Object.entries(row)) {
450
+ if (typeof value === 'bigint') {
451
+ throw invalidState(`Column ${column} holds an integer outside the safe range`, 'execute');
452
+ }
453
+ if (value !== null && typeof value !== 'string' && typeof value !== 'number') {
454
+ throw invalidState(`Column ${column} holds a value that is not TEXT, INTEGER, REAL, or NULL`, 'execute');
455
+ }
456
+ }
457
+ return row;
458
+ }
459
+ /**
460
+ * Rejects SQL that holds more than one statement, as the Node driver does.
461
+ * `prepare` compiles the first statement and ignores the rest, so this
462
+ * compiles each statement of the text and finalizes it at once. Whitespace,
463
+ * comments, and semicolons after the statement are allowed.
464
+ */
465
+ function assertOneStatement(sqlite3, database, sql) {
466
+ // A second statement needs a semicolon, and most SQL has none.
467
+ if (!sql.includes(';'))
468
+ return;
469
+ const { capi, wasm } = sqlite3;
470
+ const [text, length] = wasm.allocCString(sql, true);
471
+ const out = wasm.alloc(2 * wasm.ptr.size);
472
+ const statementOut = out;
473
+ const tailOut = out + wasm.ptr.size;
474
+ const end = text + length;
475
+ try {
476
+ let next = text;
477
+ let statements = 0;
478
+ while (next < end) {
479
+ wasm.pokePtr(statementOut, 0);
480
+ wasm.pokePtr(tailOut, 0);
481
+ const rc = capi.sqlite3_prepare_v3(database.pointer, next, end - next, 0, statementOut, tailOut);
482
+ const statement = wasm.peekPtr(statementOut);
483
+ if (statement !== 0) {
484
+ capi.sqlite3_finalize(statement);
485
+ statements += 1;
486
+ }
487
+ if (rc !== 0 || statements > 1) {
488
+ throw new RangeError('The supplied SQL string contains more than one statement');
489
+ }
490
+ next = wasm.peekPtr(tailOut);
491
+ }
492
+ }
493
+ finally {
494
+ wasm.dealloc(out);
495
+ wasm.dealloc(text);
496
+ }
497
+ }
498
+ function execute(sqlite3, database, sql, params) {
499
+ const statement = database.prepare(sql);
500
+ try {
501
+ assertOneStatement(sqlite3, database, sql);
502
+ if (params.length > 0)
503
+ statement.bind(params);
504
+ const rows = [];
505
+ while (statement.step())
506
+ rows.push(toRow(statement.get({})));
507
+ return { rows, changes: database.changes() };
508
+ }
509
+ finally {
510
+ statement.finalize();
511
+ }
512
+ }
513
+ async function handle(request) {
514
+ const slot = slotFor(request.file, request.type);
515
+ switch (request.type) {
516
+ case 'exists':
517
+ return withFile(slot, () => slot.pool.getFileNames().includes(slot.path));
518
+ case 'remove':
519
+ if (slot.connection !== null) {
520
+ throw invalidState('Close the SQLite connection before removing its file', 'remove');
521
+ }
522
+ return withFile(slot, () => {
523
+ slot.pool.unlink(slot.path);
524
+ slot.pool.unlink(`${slot.path}-journal`);
525
+ return undefined;
526
+ });
527
+ case 'open': {
528
+ const key = request.key;
529
+ if (key !== null && key.length !== KEY_LENGTH) {
530
+ throw invalidState(`A SQLite key must be ${KEY_LENGTH} bytes`, 'open');
531
+ }
532
+ if (slot.connection !== null) {
533
+ throw invalidState('This store already has an open connection to the file', 'open');
534
+ }
535
+ return withFile(slot, (sqlite3) => {
536
+ slot.database = openPhysical(slot, sqlite3, 'c', key);
537
+ slot.connection = {
538
+ id: request.connection,
539
+ key,
540
+ foreignKeys: null,
541
+ userVersion: null,
542
+ };
543
+ return undefined;
544
+ });
545
+ }
546
+ case 'execute': {
547
+ connectionOf(slot, request.connection, 'execute');
548
+ return withFile(slot, (sqlite3) => {
549
+ connectionOf(slot, request.connection, 'execute');
550
+ return execute(sqlite3, slot.database, request.sql, request.params);
551
+ });
552
+ }
553
+ case 'probeCipher': {
554
+ connectionOf(slot, request.connection, 'probeCipher');
555
+ return withFile(slot, () => {
556
+ const database = slot.database;
557
+ // `PRAGMA cipher` also answers on an unkeyed plaintext database. Only
558
+ // a keyed database has a cipher salt.
559
+ if (readValue(database, "SELECT sqlite3mc_codec_data('cipher_salt')") == null)
560
+ return null;
561
+ const cipher = readValue(database, 'PRAGMA cipher');
562
+ return typeof cipher === 'string' ? cipher : null;
563
+ });
564
+ }
565
+ case 'close':
566
+ return enqueue(slot, async () => {
567
+ const connection = slot.connection;
568
+ if (connection === null || connection.id !== request.connection)
569
+ return undefined;
570
+ slot.connection = null;
571
+ connection.key?.fill(0);
572
+ if (slot.release !== null)
573
+ detach(slot);
574
+ return undefined;
575
+ });
576
+ }
577
+ }
578
+ function isConnectionKey(key) {
579
+ for (const slot of slots.values()) {
580
+ if (slot.connection?.key === key)
581
+ return true;
582
+ }
583
+ return false;
584
+ }
585
+ function toWireError(error) {
586
+ if (error instanceof EncryptionError) {
587
+ switch (error.code) {
588
+ case EncryptionErrorCode.INVALID_STATE:
589
+ case EncryptionErrorCode.SQLITE_ENGINE_UNAVAILABLE:
590
+ case EncryptionErrorCode.OPFS_UNAVAILABLE:
591
+ case EncryptionErrorCode.OPFS_FILE_BUSY:
592
+ return {
593
+ kind: 'sdk',
594
+ code: error.code,
595
+ message: error.message,
596
+ ...(error.operation === undefined ? {} : { context: { operation: error.operation } }),
597
+ };
598
+ }
599
+ }
600
+ return { kind: 'error', message: error instanceof Error ? error.message : String(error) };
601
+ }
602
+ scope.addEventListener('message', (event) => {
603
+ const message = event.data;
604
+ if (message.type === 'configure') {
605
+ wasmUrl = message.wasmUrl;
606
+ return;
607
+ }
608
+ handle(message).then((value) => scope.postMessage({ id: message.id, ok: true, value }), (error) => {
609
+ // A key that did not become a connection's key is zeroed at once.
610
+ if (message.type === 'open' && message.key !== null && !isConnectionKey(message.key)) {
611
+ message.key.fill(0);
612
+ }
613
+ scope.postMessage({ id: message.id, ok: false, error: toWireError(error) });
614
+ });
615
+ });
616
+ //# sourceMappingURL=worker.js.map