@ethora/chat-component-rn 26.8.6 → 26.8.8

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 (537) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/README.md +64 -2
  3. package/lib/commonjs/assets/icons.js +4 -2
  4. package/lib/commonjs/assets/icons.js.map +1 -1
  5. package/lib/commonjs/components/MainComponents/ChatHeader.js +28 -6
  6. package/lib/commonjs/components/MainComponents/ChatHeader.js.map +1 -1
  7. package/lib/commonjs/components/MainComponents/ChatRoom.js +9 -1
  8. package/lib/commonjs/components/MainComponents/ChatRoom.js.map +1 -1
  9. package/lib/commonjs/components/MainComponents/ChatWrapper.js +5 -3
  10. package/lib/commonjs/components/MainComponents/ChatWrapper.js.map +1 -1
  11. package/lib/commonjs/components/MainComponents/EncryptedSendNotice.js +47 -0
  12. package/lib/commonjs/components/MainComponents/EncryptedSendNotice.js.map +1 -0
  13. package/lib/commonjs/components/MainComponents/EncryptionCard.js +286 -0
  14. package/lib/commonjs/components/MainComponents/EncryptionCard.js.map +1 -0
  15. package/lib/commonjs/components/MainComponents/MediaMessage.js +7 -0
  16. package/lib/commonjs/components/MainComponents/MediaMessage.js.map +1 -1
  17. package/lib/commonjs/components/MainComponents/ReduxWrapper.js +13 -0
  18. package/lib/commonjs/components/MainComponents/ReduxWrapper.js.map +1 -1
  19. package/lib/commonjs/components/MainComponents/SealedAttachment.js +231 -0
  20. package/lib/commonjs/components/MainComponents/SealedAttachment.js.map +1 -0
  21. package/lib/commonjs/components/Menu/HeaderRoomListMenu.js +26 -13
  22. package/lib/commonjs/components/Menu/HeaderRoomListMenu.js.map +1 -1
  23. package/lib/commonjs/components/MenuRoom/MenuRoom.js +5 -3
  24. package/lib/commonjs/components/MenuRoom/MenuRoom.js.map +1 -1
  25. package/lib/commonjs/components/MessageBubble/BottomReplyContainer.js +2 -1
  26. package/lib/commonjs/components/MessageBubble/BottomReplyContainer.js.map +1 -1
  27. package/lib/commonjs/components/MessageBubble/Message.js +69 -9
  28. package/lib/commonjs/components/MessageBubble/Message.js.map +1 -1
  29. package/lib/commonjs/components/MessageBubble/MessageInteractions.js +7 -4
  30. package/lib/commonjs/components/MessageBubble/MessageInteractions.js.map +1 -1
  31. package/lib/commonjs/components/Modals/ChatProfileModal/ChatProfileModal.js +8 -5
  32. package/lib/commonjs/components/Modals/ChatProfileModal/ChatProfileModal.js.map +1 -1
  33. package/lib/commonjs/components/Modals/ChatProfileModal/ReportChatModal.js +2 -2
  34. package/lib/commonjs/components/Modals/ChatProfileModal/ReportChatModal.js.map +1 -1
  35. package/lib/commonjs/components/Modals/FilePreviewModal/FilePreviewModal.js +166 -21
  36. package/lib/commonjs/components/Modals/FilePreviewModal/FilePreviewModal.js.map +1 -1
  37. package/lib/commonjs/components/Modals/FilePreviewModal/PdfView.js +4 -0
  38. package/lib/commonjs/components/Modals/FilePreviewModal/PdfView.js.map +1 -1
  39. package/lib/commonjs/components/Modals/Modal/Modal.js +33 -11
  40. package/lib/commonjs/components/Modals/Modal/Modal.js.map +1 -1
  41. package/lib/commonjs/components/Modals/NewChatModal/NewChatModal.js +8 -8
  42. package/lib/commonjs/components/Modals/NewChatModal/NewChatModal.js.map +1 -1
  43. package/lib/commonjs/components/Modals/SettingsModals/ChangePassword/ChangePasswordModal.js +279 -0
  44. package/lib/commonjs/components/Modals/SettingsModals/ChangePassword/ChangePasswordModal.js.map +1 -0
  45. package/lib/commonjs/components/Modals/SettingsModals/ManageDataModal/ManageDataModal.js +10 -8
  46. package/lib/commonjs/components/Modals/SettingsModals/ManageDataModal/ManageDataModal.js.map +1 -1
  47. package/lib/commonjs/components/Modals/SettingsModals/Visibility/VisibilityModal.js +13 -11
  48. package/lib/commonjs/components/Modals/SettingsModals/Visibility/VisibilityModal.js.map +1 -1
  49. package/lib/commonjs/components/Modals/UserProfileModal/UserProfileModal.js +50 -15
  50. package/lib/commonjs/components/Modals/UserProfileModal/UserProfileModal.js.map +1 -1
  51. package/lib/commonjs/components/Modals/UserSettingsModal/LanguageCard.js +121 -0
  52. package/lib/commonjs/components/Modals/UserSettingsModal/LanguageCard.js.map +1 -0
  53. package/lib/commonjs/components/Modals/UserSettingsModal/UserSettingsModal.js +10 -1
  54. package/lib/commonjs/components/Modals/UserSettingsModal/UserSettingsModal.js.map +1 -1
  55. package/lib/commonjs/components/RoomComponents/ChatRoomItem.js +32 -9
  56. package/lib/commonjs/components/RoomComponents/ChatRoomItem.js.map +1 -1
  57. package/lib/commonjs/components/RoomComponents/LastMessageItem.js +6 -0
  58. package/lib/commonjs/components/RoomComponents/LastMessageItem.js.map +1 -1
  59. package/lib/commonjs/components/RoomComponents/styled/LastAudioMessage.js +2 -2
  60. package/lib/commonjs/components/RoomComponents/styled/LastAudioMessage.js.map +1 -1
  61. package/lib/commonjs/components/RoomComponents/styled/LastMessageFile.js +4 -6
  62. package/lib/commonjs/components/RoomComponents/styled/LastMessageFile.js.map +1 -1
  63. package/lib/commonjs/components/RoomComponents/styled/LastMessagePhoto.js +2 -2
  64. package/lib/commonjs/components/RoomComponents/styled/LastMessagePhoto.js.map +1 -1
  65. package/lib/commonjs/components/RoomComponents/styled/LastMessageSealed.js +41 -0
  66. package/lib/commonjs/components/RoomComponents/styled/LastMessageSealed.js.map +1 -0
  67. package/lib/commonjs/components/RoomComponents/styled/LastMessageVideo.js +2 -2
  68. package/lib/commonjs/components/RoomComponents/styled/LastMessageVideo.js.map +1 -1
  69. package/lib/commonjs/components/Thread/ThreadWrapper.js +56 -46
  70. package/lib/commonjs/components/Thread/ThreadWrapper.js.map +1 -1
  71. package/lib/commonjs/components/UsersList/UsersList.js +2 -1
  72. package/lib/commonjs/components/UsersList/UsersList.js.map +1 -1
  73. package/lib/commonjs/components/styled/SendInput.js +4 -2
  74. package/lib/commonjs/components/styled/SendInput.js.map +1 -1
  75. package/lib/commonjs/e2ee/crypto.js +207 -0
  76. package/lib/commonjs/e2ee/crypto.js.map +1 -0
  77. package/lib/commonjs/e2ee/deviceStore.js +84 -0
  78. package/lib/commonjs/e2ee/deviceStore.js.map +1 -0
  79. package/lib/commonjs/e2ee/fileCipher.js +95 -0
  80. package/lib/commonjs/e2ee/fileCipher.js.map +1 -0
  81. package/lib/commonjs/e2ee/fileEnvelope.js +79 -0
  82. package/lib/commonjs/e2ee/fileEnvelope.js.map +1 -0
  83. package/lib/commonjs/e2ee/index.js +210 -0
  84. package/lib/commonjs/e2ee/index.js.map +1 -0
  85. package/lib/commonjs/e2ee/limits.js +9 -0
  86. package/lib/commonjs/e2ee/limits.js.map +1 -0
  87. package/lib/commonjs/e2ee/ns.js +8 -0
  88. package/lib/commonjs/e2ee/ns.js.map +1 -0
  89. package/lib/commonjs/e2ee/omemo.js +622 -0
  90. package/lib/commonjs/e2ee/omemo.js.map +1 -0
  91. package/lib/commonjs/e2ee/protobuf.js +149 -0
  92. package/lib/commonjs/e2ee/protobuf.js.map +1 -0
  93. package/lib/commonjs/e2ee/ratchet.js +238 -0
  94. package/lib/commonjs/e2ee/ratchet.js.map +1 -0
  95. package/lib/commonjs/e2ee/sealedBody.js +23 -0
  96. package/lib/commonjs/e2ee/sealedBody.js.map +1 -0
  97. package/lib/commonjs/e2ee/sealedFiles.js +174 -0
  98. package/lib/commonjs/e2ee/sealedFiles.js.map +1 -0
  99. package/lib/commonjs/e2ee/send.js +54 -0
  100. package/lib/commonjs/e2ee/send.js.map +1 -0
  101. package/lib/commonjs/e2ee/stanza.js +114 -0
  102. package/lib/commonjs/e2ee/stanza.js.map +1 -0
  103. package/lib/commonjs/e2ee/store.js +43 -0
  104. package/lib/commonjs/e2ee/store.js.map +1 -0
  105. package/lib/commonjs/helpers/accountName.js +23 -0
  106. package/lib/commonjs/helpers/accountName.js.map +1 -0
  107. package/lib/commonjs/helpers/constants/MODAL_COMPONENTS.js +2 -0
  108. package/lib/commonjs/helpers/constants/MODAL_COMPONENTS.js.map +1 -1
  109. package/lib/commonjs/helpers/constants/MODAL_TYPES.js +1 -0
  110. package/lib/commonjs/helpers/constants/MODAL_TYPES.js.map +1 -1
  111. package/lib/commonjs/helpers/createMessageFromXml.js +19 -4
  112. package/lib/commonjs/helpers/createMessageFromXml.js.map +1 -1
  113. package/lib/commonjs/helpers/createUserNameFromSetUser.js +2 -1
  114. package/lib/commonjs/helpers/createUserNameFromSetUser.js.map +1 -1
  115. package/lib/commonjs/helpers/displayName.js +16 -0
  116. package/lib/commonjs/helpers/displayName.js.map +1 -0
  117. package/lib/commonjs/helpers/persistCrypto.js +5 -0
  118. package/lib/commonjs/helpers/persistCrypto.js.map +1 -1
  119. package/lib/commonjs/helpers/preferencesStorage.js.map +1 -1
  120. package/lib/commonjs/helpers/secureKeyValue.js +20 -0
  121. package/lib/commonjs/helpers/secureKeyValue.js.map +1 -1
  122. package/lib/commonjs/helpers/videoCache.js +136 -0
  123. package/lib/commonjs/helpers/videoCache.js.map +1 -0
  124. package/lib/commonjs/hooks/useChatSettingState.js +2 -0
  125. package/lib/commonjs/hooks/useChatSettingState.js.map +1 -1
  126. package/lib/commonjs/hooks/useChatWrapperInit.js +4 -0
  127. package/lib/commonjs/hooks/useChatWrapperInit.js.map +1 -1
  128. package/lib/commonjs/hooks/useLogout.js +8 -0
  129. package/lib/commonjs/hooks/useLogout.js.map +1 -1
  130. package/lib/commonjs/hooks/useSendMessage.js +71 -7
  131. package/lib/commonjs/hooks/useSendMessage.js.map +1 -1
  132. package/lib/commonjs/i18n/strings.js +367 -1
  133. package/lib/commonjs/i18n/strings.js.map +1 -1
  134. package/lib/commonjs/i18n/useT.js +8 -4
  135. package/lib/commonjs/i18n/useT.js.map +1 -1
  136. package/lib/commonjs/main.js +13 -0
  137. package/lib/commonjs/main.js.map +1 -1
  138. package/lib/commonjs/networking/api-requests/auth.api.js +4 -1
  139. package/lib/commonjs/networking/api-requests/auth.api.js.map +1 -1
  140. package/lib/commonjs/networking/api-requests/rooms.api.js +111 -17
  141. package/lib/commonjs/networking/api-requests/rooms.api.js.map +1 -1
  142. package/lib/commonjs/networking/api-requests/user.api.js +13 -0
  143. package/lib/commonjs/networking/api-requests/user.api.js.map +1 -1
  144. package/lib/commonjs/networking/stanzaHandlers.js +1 -1
  145. package/lib/commonjs/networking/stanzaHandlers.js.map +1 -1
  146. package/lib/commonjs/networking/xmpp/handleStanzas.xmpp.js +40 -0
  147. package/lib/commonjs/networking/xmpp/handleStanzas.xmpp.js.map +1 -1
  148. package/lib/commonjs/networking/xmpp/sendMediaMessage.xmpp.js +16 -3
  149. package/lib/commonjs/networking/xmpp/sendMediaMessage.xmpp.js.map +1 -1
  150. package/lib/commonjs/networking/xmpp/sendTextMessage.xmpp.js +13 -6
  151. package/lib/commonjs/networking/xmpp/sendTextMessage.xmpp.js.map +1 -1
  152. package/lib/commonjs/networking/xmpp/sendTextMessageWithTranslateTag.xmpp.js +14 -6
  153. package/lib/commonjs/networking/xmpp/sendTextMessageWithTranslateTag.xmpp.js.map +1 -1
  154. package/lib/commonjs/networking/xmppClient.js +6 -0
  155. package/lib/commonjs/networking/xmppClient.js.map +1 -1
  156. package/lib/commonjs/roomStore/chatSettingsSlice.js +7 -2
  157. package/lib/commonjs/roomStore/chatSettingsSlice.js.map +1 -1
  158. package/lib/commonjs/roomStore/persistBackend.js +9 -12
  159. package/lib/commonjs/roomStore/persistBackend.js.map +1 -1
  160. package/lib/commonjs/roomStore/persistence.js +8 -1
  161. package/lib/commonjs/roomStore/persistence.js.map +1 -1
  162. package/lib/commonjs/services/languageSettings.js +177 -0
  163. package/lib/commonjs/services/languageSettings.js.map +1 -0
  164. package/lib/commonjs/version.js +1 -1
  165. package/lib/module/assets/icons.js +3 -1
  166. package/lib/module/assets/icons.js.map +1 -1
  167. package/lib/module/components/MainComponents/ChatHeader.js +29 -7
  168. package/lib/module/components/MainComponents/ChatHeader.js.map +1 -1
  169. package/lib/module/components/MainComponents/ChatRoom.js +9 -1
  170. package/lib/module/components/MainComponents/ChatRoom.js.map +1 -1
  171. package/lib/module/components/MainComponents/ChatWrapper.js +5 -3
  172. package/lib/module/components/MainComponents/ChatWrapper.js.map +1 -1
  173. package/lib/module/components/MainComponents/EncryptedSendNotice.js +42 -0
  174. package/lib/module/components/MainComponents/EncryptedSendNotice.js.map +1 -0
  175. package/lib/module/components/MainComponents/EncryptionCard.js +281 -0
  176. package/lib/module/components/MainComponents/EncryptionCard.js.map +1 -0
  177. package/lib/module/components/MainComponents/MediaMessage.js +7 -0
  178. package/lib/module/components/MainComponents/MediaMessage.js.map +1 -1
  179. package/lib/module/components/MainComponents/ReduxWrapper.js +14 -1
  180. package/lib/module/components/MainComponents/ReduxWrapper.js.map +1 -1
  181. package/lib/module/components/MainComponents/SealedAttachment.js +224 -0
  182. package/lib/module/components/MainComponents/SealedAttachment.js.map +1 -0
  183. package/lib/module/components/Menu/HeaderRoomListMenu.js +26 -13
  184. package/lib/module/components/Menu/HeaderRoomListMenu.js.map +1 -1
  185. package/lib/module/components/MenuRoom/MenuRoom.js +5 -3
  186. package/lib/module/components/MenuRoom/MenuRoom.js.map +1 -1
  187. package/lib/module/components/MessageBubble/BottomReplyContainer.js +2 -1
  188. package/lib/module/components/MessageBubble/BottomReplyContainer.js.map +1 -1
  189. package/lib/module/components/MessageBubble/Message.js +72 -12
  190. package/lib/module/components/MessageBubble/Message.js.map +1 -1
  191. package/lib/module/components/MessageBubble/MessageInteractions.js +7 -4
  192. package/lib/module/components/MessageBubble/MessageInteractions.js.map +1 -1
  193. package/lib/module/components/Modals/ChatProfileModal/ChatProfileModal.js +8 -5
  194. package/lib/module/components/Modals/ChatProfileModal/ChatProfileModal.js.map +1 -1
  195. package/lib/module/components/Modals/ChatProfileModal/ReportChatModal.js +2 -2
  196. package/lib/module/components/Modals/ChatProfileModal/ReportChatModal.js.map +1 -1
  197. package/lib/module/components/Modals/FilePreviewModal/FilePreviewModal.js +168 -23
  198. package/lib/module/components/Modals/FilePreviewModal/FilePreviewModal.js.map +1 -1
  199. package/lib/module/components/Modals/FilePreviewModal/PdfView.js +4 -0
  200. package/lib/module/components/Modals/FilePreviewModal/PdfView.js.map +1 -1
  201. package/lib/module/components/Modals/Modal/Modal.js +33 -11
  202. package/lib/module/components/Modals/Modal/Modal.js.map +1 -1
  203. package/lib/module/components/Modals/NewChatModal/NewChatModal.js +8 -8
  204. package/lib/module/components/Modals/NewChatModal/NewChatModal.js.map +1 -1
  205. package/lib/module/components/Modals/SettingsModals/ChangePassword/ChangePasswordModal.js +274 -0
  206. package/lib/module/components/Modals/SettingsModals/ChangePassword/ChangePasswordModal.js.map +1 -0
  207. package/lib/module/components/Modals/SettingsModals/ManageDataModal/ManageDataModal.js +10 -8
  208. package/lib/module/components/Modals/SettingsModals/ManageDataModal/ManageDataModal.js.map +1 -1
  209. package/lib/module/components/Modals/SettingsModals/Visibility/VisibilityModal.js +13 -11
  210. package/lib/module/components/Modals/SettingsModals/Visibility/VisibilityModal.js.map +1 -1
  211. package/lib/module/components/Modals/UserProfileModal/UserProfileModal.js +54 -18
  212. package/lib/module/components/Modals/UserProfileModal/UserProfileModal.js.map +1 -1
  213. package/lib/module/components/Modals/UserSettingsModal/LanguageCard.js +116 -0
  214. package/lib/module/components/Modals/UserSettingsModal/LanguageCard.js.map +1 -0
  215. package/lib/module/components/Modals/UserSettingsModal/UserSettingsModal.js +10 -1
  216. package/lib/module/components/Modals/UserSettingsModal/UserSettingsModal.js.map +1 -1
  217. package/lib/module/components/RoomComponents/ChatRoomItem.js +32 -9
  218. package/lib/module/components/RoomComponents/ChatRoomItem.js.map +1 -1
  219. package/lib/module/components/RoomComponents/LastMessageItem.js +6 -0
  220. package/lib/module/components/RoomComponents/LastMessageItem.js.map +1 -1
  221. package/lib/module/components/RoomComponents/styled/LastAudioMessage.js +2 -2
  222. package/lib/module/components/RoomComponents/styled/LastAudioMessage.js.map +1 -1
  223. package/lib/module/components/RoomComponents/styled/LastMessageFile.js +4 -6
  224. package/lib/module/components/RoomComponents/styled/LastMessageFile.js.map +1 -1
  225. package/lib/module/components/RoomComponents/styled/LastMessagePhoto.js +2 -2
  226. package/lib/module/components/RoomComponents/styled/LastMessagePhoto.js.map +1 -1
  227. package/lib/module/components/RoomComponents/styled/LastMessageSealed.js +36 -0
  228. package/lib/module/components/RoomComponents/styled/LastMessageSealed.js.map +1 -0
  229. package/lib/module/components/RoomComponents/styled/LastMessageVideo.js +2 -2
  230. package/lib/module/components/RoomComponents/styled/LastMessageVideo.js.map +1 -1
  231. package/lib/module/components/Thread/ThreadWrapper.js +57 -47
  232. package/lib/module/components/Thread/ThreadWrapper.js.map +1 -1
  233. package/lib/module/components/UsersList/UsersList.js +2 -1
  234. package/lib/module/components/UsersList/UsersList.js.map +1 -1
  235. package/lib/module/components/styled/SendInput.js +4 -2
  236. package/lib/module/components/styled/SendInput.js.map +1 -1
  237. package/lib/module/e2ee/crypto.js +170 -0
  238. package/lib/module/e2ee/crypto.js.map +1 -0
  239. package/lib/module/e2ee/deviceStore.js +77 -0
  240. package/lib/module/e2ee/deviceStore.js.map +1 -0
  241. package/lib/module/e2ee/fileCipher.js +90 -0
  242. package/lib/module/e2ee/fileCipher.js.map +1 -0
  243. package/lib/module/e2ee/fileEnvelope.js +66 -0
  244. package/lib/module/e2ee/fileEnvelope.js.map +1 -0
  245. package/lib/module/e2ee/index.js +185 -0
  246. package/lib/module/e2ee/index.js.map +1 -0
  247. package/lib/module/e2ee/limits.js +5 -0
  248. package/lib/module/e2ee/limits.js.map +1 -0
  249. package/lib/module/e2ee/ns.js +4 -0
  250. package/lib/module/e2ee/ns.js.map +1 -0
  251. package/lib/module/e2ee/omemo.js +610 -0
  252. package/lib/module/e2ee/omemo.js.map +1 -0
  253. package/lib/module/e2ee/protobuf.js +140 -0
  254. package/lib/module/e2ee/protobuf.js.map +1 -0
  255. package/lib/module/e2ee/ratchet.js +228 -0
  256. package/lib/module/e2ee/ratchet.js.map +1 -0
  257. package/lib/module/e2ee/sealedBody.js +19 -0
  258. package/lib/module/e2ee/sealedBody.js.map +1 -0
  259. package/lib/module/e2ee/sealedFiles.js +154 -0
  260. package/lib/module/e2ee/sealedFiles.js.map +1 -0
  261. package/lib/module/e2ee/send.js +48 -0
  262. package/lib/module/e2ee/send.js.map +1 -0
  263. package/lib/module/e2ee/stanza.js +107 -0
  264. package/lib/module/e2ee/stanza.js.map +1 -0
  265. package/lib/module/e2ee/store.js +35 -0
  266. package/lib/module/e2ee/store.js.map +1 -0
  267. package/lib/module/helpers/accountName.js +18 -0
  268. package/lib/module/helpers/accountName.js.map +1 -0
  269. package/lib/module/helpers/constants/MODAL_COMPONENTS.js +2 -0
  270. package/lib/module/helpers/constants/MODAL_COMPONENTS.js.map +1 -1
  271. package/lib/module/helpers/constants/MODAL_TYPES.js +1 -0
  272. package/lib/module/helpers/constants/MODAL_TYPES.js.map +1 -1
  273. package/lib/module/helpers/createMessageFromXml.js +19 -4
  274. package/lib/module/helpers/createMessageFromXml.js.map +1 -1
  275. package/lib/module/helpers/createUserNameFromSetUser.js +3 -1
  276. package/lib/module/helpers/createUserNameFromSetUser.js.map +1 -1
  277. package/lib/module/helpers/displayName.js +11 -0
  278. package/lib/module/helpers/displayName.js.map +1 -0
  279. package/lib/module/helpers/persistCrypto.js +4 -0
  280. package/lib/module/helpers/persistCrypto.js.map +1 -1
  281. package/lib/module/helpers/preferencesStorage.js.map +1 -1
  282. package/lib/module/helpers/secureKeyValue.js +19 -0
  283. package/lib/module/helpers/secureKeyValue.js.map +1 -1
  284. package/lib/module/helpers/videoCache.js +125 -0
  285. package/lib/module/helpers/videoCache.js.map +1 -0
  286. package/lib/module/hooks/useChatSettingState.js +2 -0
  287. package/lib/module/hooks/useChatSettingState.js.map +1 -1
  288. package/lib/module/hooks/useChatWrapperInit.js +4 -0
  289. package/lib/module/hooks/useChatWrapperInit.js.map +1 -1
  290. package/lib/module/hooks/useLogout.js +8 -0
  291. package/lib/module/hooks/useLogout.js.map +1 -1
  292. package/lib/module/hooks/useSendMessage.js +71 -7
  293. package/lib/module/hooks/useSendMessage.js.map +1 -1
  294. package/lib/module/i18n/strings.js +367 -1
  295. package/lib/module/i18n/strings.js.map +1 -1
  296. package/lib/module/i18n/useT.js +8 -4
  297. package/lib/module/i18n/useT.js.map +1 -1
  298. package/lib/module/main.js +1 -0
  299. package/lib/module/main.js.map +1 -1
  300. package/lib/module/networking/api-requests/auth.api.js +4 -1
  301. package/lib/module/networking/api-requests/auth.api.js.map +1 -1
  302. package/lib/module/networking/api-requests/rooms.api.js +109 -18
  303. package/lib/module/networking/api-requests/rooms.api.js.map +1 -1
  304. package/lib/module/networking/api-requests/user.api.js +12 -0
  305. package/lib/module/networking/api-requests/user.api.js.map +1 -1
  306. package/lib/module/networking/stanzaHandlers.js +1 -1
  307. package/lib/module/networking/stanzaHandlers.js.map +1 -1
  308. package/lib/module/networking/xmpp/handleStanzas.xmpp.js +38 -0
  309. package/lib/module/networking/xmpp/handleStanzas.xmpp.js.map +1 -1
  310. package/lib/module/networking/xmpp/sendMediaMessage.xmpp.js +16 -3
  311. package/lib/module/networking/xmpp/sendMediaMessage.xmpp.js.map +1 -1
  312. package/lib/module/networking/xmpp/sendTextMessage.xmpp.js +13 -6
  313. package/lib/module/networking/xmpp/sendTextMessage.xmpp.js.map +1 -1
  314. package/lib/module/networking/xmpp/sendTextMessageWithTranslateTag.xmpp.js +14 -6
  315. package/lib/module/networking/xmpp/sendTextMessageWithTranslateTag.xmpp.js.map +1 -1
  316. package/lib/module/networking/xmppClient.js +6 -0
  317. package/lib/module/networking/xmppClient.js.map +1 -1
  318. package/lib/module/roomStore/chatSettingsSlice.js +5 -1
  319. package/lib/module/roomStore/chatSettingsSlice.js.map +1 -1
  320. package/lib/module/roomStore/persistBackend.js +10 -13
  321. package/lib/module/roomStore/persistBackend.js.map +1 -1
  322. package/lib/module/roomStore/persistence.js +8 -1
  323. package/lib/module/roomStore/persistence.js.map +1 -1
  324. package/lib/module/services/languageSettings.js +164 -0
  325. package/lib/module/services/languageSettings.js.map +1 -0
  326. package/lib/module/version.js +1 -1
  327. package/lib/typescript/assets/icons.d.ts +8 -0
  328. package/lib/typescript/assets/icons.d.ts.map +1 -1
  329. package/lib/typescript/components/MainComponents/ChatHeader.d.ts.map +1 -1
  330. package/lib/typescript/components/MainComponents/ChatRoom.d.ts.map +1 -1
  331. package/lib/typescript/components/MainComponents/ChatWrapper.d.ts.map +1 -1
  332. package/lib/typescript/components/MainComponents/EncryptedSendNotice.d.ts +4 -0
  333. package/lib/typescript/components/MainComponents/EncryptedSendNotice.d.ts.map +1 -0
  334. package/lib/typescript/components/MainComponents/EncryptionCard.d.ts +10 -0
  335. package/lib/typescript/components/MainComponents/EncryptionCard.d.ts.map +1 -0
  336. package/lib/typescript/components/MainComponents/MediaMessage.d.ts.map +1 -1
  337. package/lib/typescript/components/MainComponents/ReduxWrapper.d.ts.map +1 -1
  338. package/lib/typescript/components/MainComponents/SealedAttachment.d.ts +13 -0
  339. package/lib/typescript/components/MainComponents/SealedAttachment.d.ts.map +1 -0
  340. package/lib/typescript/components/Menu/HeaderRoomListMenu.d.ts +7 -1
  341. package/lib/typescript/components/Menu/HeaderRoomListMenu.d.ts.map +1 -1
  342. package/lib/typescript/components/MenuRoom/MenuRoom.d.ts.map +1 -1
  343. package/lib/typescript/components/MessageBubble/BottomReplyContainer.d.ts.map +1 -1
  344. package/lib/typescript/components/MessageBubble/Message.d.ts.map +1 -1
  345. package/lib/typescript/components/MessageBubble/MessageInteractions.d.ts.map +1 -1
  346. package/lib/typescript/components/Modals/ChatProfileModal/ChatProfileModal.d.ts.map +1 -1
  347. package/lib/typescript/components/Modals/FilePreviewModal/FilePreviewModal.d.ts.map +1 -1
  348. package/lib/typescript/components/Modals/FilePreviewModal/PdfView.d.ts.map +1 -1
  349. package/lib/typescript/components/Modals/Modal/Modal.d.ts.map +1 -1
  350. package/lib/typescript/components/Modals/SettingsModals/ChangePassword/ChangePasswordModal.d.ts +15 -0
  351. package/lib/typescript/components/Modals/SettingsModals/ChangePassword/ChangePasswordModal.d.ts.map +1 -0
  352. package/lib/typescript/components/Modals/SettingsModals/ManageDataModal/ManageDataModal.d.ts.map +1 -1
  353. package/lib/typescript/components/Modals/SettingsModals/Visibility/VisibilityModal.d.ts.map +1 -1
  354. package/lib/typescript/components/Modals/UserProfileModal/UserProfileModal.d.ts.map +1 -1
  355. package/lib/typescript/components/Modals/UserSettingsModal/LanguageCard.d.ts +14 -0
  356. package/lib/typescript/components/Modals/UserSettingsModal/LanguageCard.d.ts.map +1 -0
  357. package/lib/typescript/components/Modals/UserSettingsModal/UserSettingsModal.d.ts.map +1 -1
  358. package/lib/typescript/components/RoomComponents/ChatRoomItem.d.ts.map +1 -1
  359. package/lib/typescript/components/RoomComponents/LastMessageItem.d.ts.map +1 -1
  360. package/lib/typescript/components/RoomComponents/styled/LastAudioMessage.d.ts.map +1 -1
  361. package/lib/typescript/components/RoomComponents/styled/LastMessageSealed.d.ts +7 -0
  362. package/lib/typescript/components/RoomComponents/styled/LastMessageSealed.d.ts.map +1 -0
  363. package/lib/typescript/components/Thread/ThreadWrapper.d.ts.map +1 -1
  364. package/lib/typescript/components/UsersList/UsersList.d.ts.map +1 -1
  365. package/lib/typescript/components/styled/SendInput.d.ts +1 -0
  366. package/lib/typescript/components/styled/SendInput.d.ts.map +1 -1
  367. package/lib/typescript/e2ee/crypto.d.ts +28 -0
  368. package/lib/typescript/e2ee/crypto.d.ts.map +1 -0
  369. package/lib/typescript/e2ee/deviceStore.d.ts +4 -0
  370. package/lib/typescript/e2ee/deviceStore.d.ts.map +1 -0
  371. package/lib/typescript/e2ee/fileCipher.d.ts +7 -0
  372. package/lib/typescript/e2ee/fileCipher.d.ts.map +1 -0
  373. package/lib/typescript/e2ee/fileEnvelope.d.ts +27 -0
  374. package/lib/typescript/e2ee/fileEnvelope.d.ts.map +1 -0
  375. package/lib/typescript/e2ee/index.d.ts +23 -0
  376. package/lib/typescript/e2ee/index.d.ts.map +1 -0
  377. package/lib/typescript/e2ee/limits.d.ts +3 -0
  378. package/lib/typescript/e2ee/limits.d.ts.map +1 -0
  379. package/lib/typescript/e2ee/ns.d.ts +2 -0
  380. package/lib/typescript/e2ee/ns.d.ts.map +1 -0
  381. package/lib/typescript/e2ee/omemo.d.ts +64 -0
  382. package/lib/typescript/e2ee/omemo.d.ts.map +1 -0
  383. package/lib/typescript/e2ee/protobuf.d.ts +25 -0
  384. package/lib/typescript/e2ee/protobuf.d.ts.map +1 -0
  385. package/lib/typescript/e2ee/ratchet.d.ts +39 -0
  386. package/lib/typescript/e2ee/ratchet.d.ts.map +1 -0
  387. package/lib/typescript/e2ee/sealedBody.d.ts +2 -0
  388. package/lib/typescript/e2ee/sealedBody.d.ts.map +1 -0
  389. package/lib/typescript/e2ee/sealedFiles.d.ts +31 -0
  390. package/lib/typescript/e2ee/sealedFiles.d.ts.map +1 -0
  391. package/lib/typescript/e2ee/send.d.ts +6 -0
  392. package/lib/typescript/e2ee/send.d.ts.map +1 -0
  393. package/lib/typescript/e2ee/stanza.d.ts +8 -0
  394. package/lib/typescript/e2ee/stanza.d.ts.map +1 -0
  395. package/lib/typescript/e2ee/store.d.ts +16 -0
  396. package/lib/typescript/e2ee/store.d.ts.map +1 -0
  397. package/lib/typescript/helpers/accountName.d.ts +7 -0
  398. package/lib/typescript/helpers/accountName.d.ts.map +1 -0
  399. package/lib/typescript/helpers/constants/MODAL_COMPONENTS.d.ts.map +1 -1
  400. package/lib/typescript/helpers/constants/MODAL_TYPES.d.ts +1 -0
  401. package/lib/typescript/helpers/constants/MODAL_TYPES.d.ts.map +1 -1
  402. package/lib/typescript/helpers/createMessageFromXml.d.ts.map +1 -1
  403. package/lib/typescript/helpers/createUserNameFromSetUser.d.ts.map +1 -1
  404. package/lib/typescript/helpers/displayName.d.ts +2 -0
  405. package/lib/typescript/helpers/displayName.d.ts.map +1 -0
  406. package/lib/typescript/helpers/persistCrypto.d.ts +1 -0
  407. package/lib/typescript/helpers/persistCrypto.d.ts.map +1 -1
  408. package/lib/typescript/helpers/preferencesStorage.d.ts +4 -0
  409. package/lib/typescript/helpers/preferencesStorage.d.ts.map +1 -1
  410. package/lib/typescript/helpers/secureKeyValue.d.ts +4 -0
  411. package/lib/typescript/helpers/secureKeyValue.d.ts.map +1 -1
  412. package/lib/typescript/helpers/videoCache.d.ts +19 -0
  413. package/lib/typescript/helpers/videoCache.d.ts.map +1 -0
  414. package/lib/typescript/hooks/useChatSettingState.d.ts +1 -0
  415. package/lib/typescript/hooks/useChatSettingState.d.ts.map +1 -1
  416. package/lib/typescript/hooks/useChatWrapperInit.d.ts.map +1 -1
  417. package/lib/typescript/hooks/useLogout.d.ts.map +1 -1
  418. package/lib/typescript/hooks/useSendMessage.d.ts.map +1 -1
  419. package/lib/typescript/i18n/strings.d.ts.map +1 -1
  420. package/lib/typescript/i18n/useT.d.ts.map +1 -1
  421. package/lib/typescript/main.d.ts +2 -0
  422. package/lib/typescript/main.d.ts.map +1 -1
  423. package/lib/typescript/networking/api-requests/auth.api.d.ts +4 -1
  424. package/lib/typescript/networking/api-requests/auth.api.d.ts.map +1 -1
  425. package/lib/typescript/networking/api-requests/rooms.api.d.ts +22 -1
  426. package/lib/typescript/networking/api-requests/rooms.api.d.ts.map +1 -1
  427. package/lib/typescript/networking/api-requests/user.api.d.ts +6 -0
  428. package/lib/typescript/networking/api-requests/user.api.d.ts.map +1 -1
  429. package/lib/typescript/networking/stanzaHandlers.d.ts.map +1 -1
  430. package/lib/typescript/networking/xmpp/handleStanzas.xmpp.d.ts +1 -0
  431. package/lib/typescript/networking/xmpp/handleStanzas.xmpp.d.ts.map +1 -1
  432. package/lib/typescript/networking/xmpp/sendMediaMessage.xmpp.d.ts.map +1 -1
  433. package/lib/typescript/networking/xmpp/sendTextMessage.xmpp.d.ts.map +1 -1
  434. package/lib/typescript/networking/xmpp/sendTextMessageWithTranslateTag.xmpp.d.ts.map +1 -1
  435. package/lib/typescript/networking/xmppClient.d.ts.map +1 -1
  436. package/lib/typescript/roomStore/chatSettingsSlice.d.ts +8 -1
  437. package/lib/typescript/roomStore/chatSettingsSlice.d.ts.map +1 -1
  438. package/lib/typescript/roomStore/persistBackend.d.ts.map +1 -1
  439. package/lib/typescript/roomStore/persistence.d.ts.map +1 -1
  440. package/lib/typescript/services/languageSettings.d.ts +29 -0
  441. package/lib/typescript/services/languageSettings.d.ts.map +1 -0
  442. package/lib/typescript/types/models/message.model.d.ts +5 -0
  443. package/lib/typescript/types/models/message.model.d.ts.map +1 -1
  444. package/lib/typescript/types/models/room.model.d.ts +5 -0
  445. package/lib/typescript/types/models/room.model.d.ts.map +1 -1
  446. package/lib/typescript/types/models/user.model.d.ts +4 -0
  447. package/lib/typescript/types/models/user.model.d.ts.map +1 -1
  448. package/lib/typescript/types/types.d.ts +25 -0
  449. package/lib/typescript/types/types.d.ts.map +1 -1
  450. package/lib/typescript/version.d.ts +1 -1
  451. package/package.json +8 -4
  452. package/src/assets/icons.tsx +27 -0
  453. package/src/components/MainComponents/ChatHeader.tsx +30 -9
  454. package/src/components/MainComponents/ChatRoom.tsx +11 -1
  455. package/src/components/MainComponents/ChatWrapper.tsx +5 -3
  456. package/src/components/MainComponents/EncryptedSendNotice.tsx +35 -0
  457. package/src/components/MainComponents/EncryptionCard.tsx +287 -0
  458. package/src/components/MainComponents/MediaMessage.tsx +5 -0
  459. package/src/components/MainComponents/ReduxWrapper.tsx +11 -0
  460. package/src/components/MainComponents/SealedAttachment.tsx +251 -0
  461. package/src/components/Menu/HeaderRoomListMenu.tsx +40 -13
  462. package/src/components/MenuRoom/MenuRoom.tsx +5 -3
  463. package/src/components/MessageBubble/BottomReplyContainer.tsx +2 -1
  464. package/src/components/MessageBubble/Message.tsx +99 -9
  465. package/src/components/MessageBubble/MessageInteractions.tsx +7 -6
  466. package/src/components/Modals/ChatProfileModal/ChatProfileModal.tsx +8 -5
  467. package/src/components/Modals/ChatProfileModal/ReportChatModal.tsx +2 -2
  468. package/src/components/Modals/FilePreviewModal/FilePreviewModal.tsx +188 -40
  469. package/src/components/Modals/FilePreviewModal/PdfView.tsx +4 -0
  470. package/src/components/Modals/Modal/Modal.tsx +44 -16
  471. package/src/components/Modals/NewChatModal/NewChatModal.tsx +8 -8
  472. package/src/components/Modals/SettingsModals/ChangePassword/ChangePasswordModal.tsx +316 -0
  473. package/src/components/Modals/SettingsModals/ManageDataModal/ManageDataModal.tsx +10 -15
  474. package/src/components/Modals/SettingsModals/Visibility/VisibilityModal.tsx +13 -14
  475. package/src/components/Modals/UserProfileModal/UserProfileModal.tsx +72 -20
  476. package/src/components/Modals/UserSettingsModal/LanguageCard.tsx +144 -0
  477. package/src/components/Modals/UserSettingsModal/UserSettingsModal.tsx +13 -1
  478. package/src/components/RoomComponents/ChatRoomItem.tsx +23 -11
  479. package/src/components/RoomComponents/LastMessageItem.tsx +5 -0
  480. package/src/components/RoomComponents/styled/LastAudioMessage.tsx +3 -1
  481. package/src/components/RoomComponents/styled/LastMessageFile.tsx +2 -2
  482. package/src/components/RoomComponents/styled/LastMessagePhoto.tsx +1 -1
  483. package/src/components/RoomComponents/styled/LastMessageSealed.tsx +31 -0
  484. package/src/components/RoomComponents/styled/LastMessageVideo.tsx +1 -1
  485. package/src/components/Thread/ThreadWrapper.tsx +17 -2
  486. package/src/components/UsersList/UsersList.tsx +2 -1
  487. package/src/components/styled/SendInput.tsx +5 -2
  488. package/src/e2ee/crypto.ts +194 -0
  489. package/src/e2ee/deviceStore.ts +80 -0
  490. package/src/e2ee/fileCipher.ts +86 -0
  491. package/src/e2ee/fileEnvelope.ts +115 -0
  492. package/src/e2ee/index.ts +192 -0
  493. package/src/e2ee/limits.ts +2 -0
  494. package/src/e2ee/ns.ts +1 -0
  495. package/src/e2ee/omemo.ts +802 -0
  496. package/src/e2ee/protobuf.ts +188 -0
  497. package/src/e2ee/ratchet.ts +271 -0
  498. package/src/e2ee/sealedBody.ts +17 -0
  499. package/src/e2ee/sealedFiles.ts +181 -0
  500. package/src/e2ee/send.ts +70 -0
  501. package/src/e2ee/stanza.ts +133 -0
  502. package/src/e2ee/store.ts +54 -0
  503. package/src/helpers/accountName.ts +15 -0
  504. package/src/helpers/constants/MODAL_COMPONENTS.tsx +2 -0
  505. package/src/helpers/constants/MODAL_TYPES.ts +1 -0
  506. package/src/helpers/createMessageFromXml.ts +31 -6
  507. package/src/helpers/createUserNameFromSetUser.ts +2 -1
  508. package/src/helpers/displayName.ts +9 -0
  509. package/src/helpers/persistCrypto.ts +5 -0
  510. package/src/helpers/preferencesStorage.ts +4 -0
  511. package/src/helpers/secureKeyValue.ts +15 -0
  512. package/src/helpers/videoCache.ts +138 -0
  513. package/src/hooks/useChatSettingState.tsx +4 -0
  514. package/src/hooks/useChatWrapperInit.ts +4 -0
  515. package/src/hooks/useLogout.tsx +9 -0
  516. package/src/hooks/useSendMessage.tsx +71 -5
  517. package/src/i18n/strings.ts +367 -1
  518. package/src/i18n/useT.ts +6 -4
  519. package/src/main.ts +2 -0
  520. package/src/networking/api-requests/auth.api.ts +9 -1
  521. package/src/networking/api-requests/rooms.api.ts +121 -18
  522. package/src/networking/api-requests/user.api.ts +9 -0
  523. package/src/networking/stanzaHandlers.ts +1 -0
  524. package/src/networking/xmpp/handleStanzas.xmpp.ts +49 -0
  525. package/src/networking/xmpp/sendMediaMessage.xmpp.ts +19 -1
  526. package/src/networking/xmpp/sendTextMessage.xmpp.ts +17 -10
  527. package/src/networking/xmpp/sendTextMessageWithTranslateTag.xmpp.ts +23 -10
  528. package/src/networking/xmppClient.ts +6 -0
  529. package/src/roomStore/chatSettingsSlice.ts +13 -0
  530. package/src/roomStore/persistBackend.ts +8 -11
  531. package/src/roomStore/persistence.ts +15 -0
  532. package/src/services/languageSettings.ts +143 -0
  533. package/src/types/models/message.model.ts +5 -0
  534. package/src/types/models/room.model.ts +5 -0
  535. package/src/types/models/user.model.ts +4 -0
  536. package/src/types/types.ts +25 -0
  537. package/src/version.ts +1 -1
@@ -0,0 +1,140 @@
1
+ "use strict";
2
+
3
+ import { concatBytes } from './crypto';
4
+ const VARINT = 0;
5
+ const FIXED64 = 1;
6
+ const BYTES = 2;
7
+ const FIXED32 = 5;
8
+ function varint(value) {
9
+ if (!Number.isInteger(value) || value < 0 || value > 0xffffffff) {
10
+ throw new Error(`Invalid uint32: ${value}`);
11
+ }
12
+ const out = [];
13
+ while (value > 0x7f) {
14
+ out.push(value % 0x80 | 0x80);
15
+ value = Math.floor(value / 0x80);
16
+ }
17
+ out.push(value);
18
+ return out;
19
+ }
20
+ class Writer {
21
+ parts = [];
22
+ uint(field, value) {
23
+ this.parts.push(Uint8Array.from([...varint(field << 3 | VARINT), ...varint(value)]));
24
+ return this;
25
+ }
26
+ bytes(field, value) {
27
+ if (value === undefined) {
28
+ return this;
29
+ }
30
+ this.parts.push(Uint8Array.from([...varint(field << 3 | BYTES), ...varint(value.length)]), value);
31
+ return this;
32
+ }
33
+ finish() {
34
+ return concatBytes(...this.parts);
35
+ }
36
+ }
37
+ function read(buf) {
38
+ const fields = new Map();
39
+ let pos = 0;
40
+ const readVarint = () => {
41
+ let result = 0;
42
+ let scale = 1;
43
+ for (let i = 0; i < 10; i++) {
44
+ if (pos >= buf.length) {
45
+ throw new Error('Truncated varint');
46
+ }
47
+ const b = buf[pos++];
48
+ result += (b & 0x7f) * scale;
49
+ if (!(b & 0x80)) {
50
+ return result;
51
+ }
52
+ scale *= 0x80;
53
+ }
54
+ throw new Error('Varint too long');
55
+ };
56
+ const skip = length => {
57
+ if (pos + length > buf.length) {
58
+ throw new Error('Truncated field');
59
+ }
60
+ pos += length;
61
+ };
62
+ while (pos < buf.length) {
63
+ const tag = readVarint();
64
+ const field = Math.floor(tag / 8);
65
+ switch (tag % 8) {
66
+ case VARINT:
67
+ fields.set(field, readVarint());
68
+ break;
69
+ case BYTES:
70
+ {
71
+ const length = readVarint();
72
+ const start = pos;
73
+ skip(length);
74
+ fields.set(field, buf.subarray(start, pos));
75
+ break;
76
+ }
77
+ case FIXED64:
78
+ skip(8);
79
+ break;
80
+ case FIXED32:
81
+ skip(4);
82
+ break;
83
+ default:
84
+ throw new Error('Unsupported wire type');
85
+ }
86
+ }
87
+ return fields;
88
+ }
89
+ function requireUint(fields, field) {
90
+ const value = fields.get(field);
91
+ if (typeof value !== 'number' || value > 0xffffffff) {
92
+ throw new Error(`Missing field ${field}`);
93
+ }
94
+ return value;
95
+ }
96
+ function requireBytes(fields, field) {
97
+ const value = fields.get(field);
98
+ if (!(value instanceof Uint8Array)) {
99
+ throw new Error(`Missing field ${field}`);
100
+ }
101
+ // Copy, so stored values don't keep the whole input buffer alive
102
+ return value.slice();
103
+ }
104
+ export function encodeMessage(m) {
105
+ return new Writer().uint(1, m.n).uint(2, m.pn).bytes(3, m.dhPub).bytes(4, m.ciphertext).finish();
106
+ }
107
+ export function decodeMessage(buf) {
108
+ const f = read(buf);
109
+ const ciphertext = f.get(4);
110
+ return {
111
+ n: requireUint(f, 1),
112
+ pn: requireUint(f, 2),
113
+ dhPub: requireBytes(f, 3),
114
+ ciphertext: ciphertext instanceof Uint8Array ? ciphertext.slice() : undefined
115
+ };
116
+ }
117
+ export function encodeAuthenticated(m) {
118
+ return new Writer().bytes(1, m.mac).bytes(2, m.message).finish();
119
+ }
120
+ export function decodeAuthenticated(buf) {
121
+ const f = read(buf);
122
+ return {
123
+ mac: requireBytes(f, 1),
124
+ message: requireBytes(f, 2)
125
+ };
126
+ }
127
+ export function encodeKeyExchange(m) {
128
+ return new Writer().uint(1, m.pkId).uint(2, m.spkId).bytes(3, m.ik).bytes(4, m.ek).bytes(5, m.message).finish();
129
+ }
130
+ export function decodeKeyExchange(buf) {
131
+ const f = read(buf);
132
+ return {
133
+ pkId: requireUint(f, 1),
134
+ spkId: requireUint(f, 2),
135
+ ik: requireBytes(f, 3),
136
+ ek: requireBytes(f, 4),
137
+ message: requireBytes(f, 5)
138
+ };
139
+ }
140
+ //# sourceMappingURL=protobuf.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["concatBytes","VARINT","FIXED64","BYTES","FIXED32","varint","value","Number","isInteger","Error","out","push","Math","floor","Writer","parts","uint","field","Uint8Array","from","bytes","undefined","length","finish","read","buf","fields","Map","pos","readVarint","result","scale","i","b","skip","tag","set","start","subarray","requireUint","get","requireBytes","slice","encodeMessage","m","n","pn","dhPub","ciphertext","decodeMessage","f","encodeAuthenticated","mac","message","decodeAuthenticated","encodeKeyExchange","pkId","spkId","ik","ek","decodeKeyExchange"],"sourceRoot":"../../../src","sources":["e2ee/protobuf.ts"],"mappings":";;AAAA,SAASA,WAAW,QAAQ,UAAU;AAEtC,MAAMC,MAAM,GAAG,CAAC;AAChB,MAAMC,OAAO,GAAG,CAAC;AACjB,MAAMC,KAAK,GAAG,CAAC;AACf,MAAMC,OAAO,GAAG,CAAC;AAEjB,SAASC,MAAMA,CAACC,KAAa,EAAY;EACvC,IAAI,CAACC,MAAM,CAACC,SAAS,CAACF,KAAK,CAAC,IAAIA,KAAK,GAAG,CAAC,IAAIA,KAAK,GAAG,UAAU,EAAE;IAC/D,MAAM,IAAIG,KAAK,CAAC,mBAAmBH,KAAK,EAAE,CAAC;EAC7C;EACA,MAAMI,GAAa,GAAG,EAAE;EACxB,OAAOJ,KAAK,GAAG,IAAI,EAAE;IACnBI,GAAG,CAACC,IAAI,CAACL,KAAK,GAAG,IAAI,GAAG,IAAI,CAAC;IAC7BA,KAAK,GAAGM,IAAI,CAACC,KAAK,CAACP,KAAK,GAAG,IAAI,CAAC;EAClC;EACAI,GAAG,CAACC,IAAI,CAACL,KAAK,CAAC;EACf,OAAOI,GAAG;AACZ;AAEA,MAAMI,MAAM,CAAC;EACHC,KAAK,GAAiB,EAAE;EAEhCC,IAAIA,CAACC,KAAa,EAAEX,KAAa,EAAQ;IACvC,IAAI,CAACS,KAAK,CAACJ,IAAI,CACbO,UAAU,CAACC,IAAI,CAAC,CAAC,GAAGd,MAAM,CAAEY,KAAK,IAAI,CAAC,GAAIhB,MAAM,CAAC,EAAE,GAAGI,MAAM,CAACC,KAAK,CAAC,CAAC,CACtE,CAAC;IACD,OAAO,IAAI;EACb;EAEAc,KAAKA,CAACH,KAAa,EAAEX,KAA6B,EAAQ;IACxD,IAAIA,KAAK,K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C,GAAG,CAAC;EACnB,OAAO;IAAE2B,GAAG,EAAEX,YAAY,CAACS,CAAC,EAAE,CAAC,CAAC;IAAEG,OAAO,EAAEZ,YAAY,CAACS,CAAC,EAAE,CAAC;EAAE,CAAC;AACjE;AAWA,OAAO,SAASK,iBAAiBA,CAACX,CAAc,EAAc;EAC5D,OAAO,IAAI9B,MAAM,CAAC,CAAC,CAChBE,IAAI,CAAC,CAAC,EAAE4B,CAAC,CAACY,IAAI,CAAC,CACfxC,IAAI,CAAC,CAAC,EAAE4B,CAAC,CAACa,KAAK,CAAC,CAChBrC,KAAK,CAAC,CAAC,EAAEwB,CAAC,CAACc,EAAE,CAAC,CACdtC,KAAK,CAAC,CAAC,EAAEwB,CAAC,CAACe,EAAE,CAAC,CACdvC,KAAK,CAAC,CAAC,EAAEwB,CAAC,CAACS,OAAO,CAAC,CACnB9B,MAAM,CAAC,CAAC;AACb;AAEA,OAAO,SAASqC,iBAAiBA,CAACnC,GAAe,EAAe;EAC9D,MAAMyB,CAAC,GAAG1B,IAAI,CAACC,GAAG,CAAC;EACnB,OAAO;IACL+B,IAAI,EAAEjB,WAAW,CAACW,CAAC,EAAE,CAAC,CAAC;IACvBO,KAAK,EAAElB,WAAW,CAACW,CAAC,EAAE,CAAC,CAAC;IACxBQ,EAAE,EAAEjB,YAAY,CAACS,CAAC,EAAE,CAAC,CAAC;IACtBS,EAAE,EAAElB,YAAY,CAACS,CAAC,EAAE,CAAC,CAAC;IACtBG,OAAO,EAAEZ,YAAY,CAACS,CAAC,EAAE,CAAC;EAC5B,CAAC;AACH","ignoreList":[]}
@@ -0,0 +1,228 @@
1
+ "use strict";
2
+
3
+ import { aesDecrypt, aesEncrypt, bytesEqual, concatBytes, dh, generateKeyPair, hkdfSha256, hmacSha256, identityDhPrivate, identityDhPublic, randomBytes, toBase64, verify } from './crypto';
4
+ import { decodeAuthenticated, decodeMessage, encodeAuthenticated, encodeMessage } from './protobuf';
5
+ const MAX_SKIP = 1000;
6
+ const X3DH_PREFIX = new Uint8Array(32).fill(0xff);
7
+ export function cloneSession(session) {
8
+ const skipped = {};
9
+ for (const id of Object.keys(session.skipped)) {
10
+ skipped[id] = session.skipped[id].slice();
11
+ }
12
+ return {
13
+ rk: session.rk.slice(),
14
+ dhs: {
15
+ priv: session.dhs.priv.slice(),
16
+ pub: session.dhs.pub.slice()
17
+ },
18
+ ...(session.dhr ? {
19
+ dhr: session.dhr.slice()
20
+ } : {}),
21
+ ...(session.cks ? {
22
+ cks: session.cks.slice()
23
+ } : {}),
24
+ ...(session.ckr ? {
25
+ ckr: session.ckr.slice()
26
+ } : {}),
27
+ ns: session.ns,
28
+ nr: session.nr,
29
+ pn: session.pn,
30
+ skipped,
31
+ ad: session.ad.slice(),
32
+ peerIk: session.peerIk.slice(),
33
+ ...(session.pendingKex ? {
34
+ pendingKex: {
35
+ pkId: session.pendingKex.pkId,
36
+ spkId: session.pendingKex.spkId,
37
+ ek: session.pendingKex.ek.slice()
38
+ }
39
+ } : {}),
40
+ ...(session.kexEk ? {
41
+ kexEk: session.kexEk.slice()
42
+ } : {})
43
+ };
44
+ }
45
+ function kdfRk(rk, dhOut) {
46
+ const out = hkdfSha256(dhOut, rk, 'OMEMO Root Chain', 64);
47
+ return [out.slice(0, 32), out.slice(32)];
48
+ }
49
+ function kdfCk(ck) {
50
+ return [hmacSha256(ck, Uint8Array.of(0x02)), hmacSha256(ck, Uint8Array.of(0x01))];
51
+ }
52
+ function messageKeys(mk) {
53
+ const km = hkdfSha256(mk, undefined, 'OMEMO Message Key Material', 80);
54
+ return {
55
+ enc: km.slice(0, 32),
56
+ auth: km.slice(32, 64),
57
+ iv: km.slice(64)
58
+ };
59
+ }
60
+ function x3dhSecret(...dhs) {
61
+ return hkdfSha256(concatBytes(X3DH_PREFIX, ...dhs), undefined, 'OMEMO X3DH', 32);
62
+ }
63
+ export function initiateSession(own, bundle) {
64
+ if (!verify(bundle.spkSignature, bundle.spk, bundle.ik)) {
65
+ throw new Error('Invalid signed prekey signature');
66
+ }
67
+ const ek = generateKeyPair();
68
+ const sk = x3dhSecret(dh(identityDhPrivate(own), bundle.spk), dh(ek.priv, identityDhPublic(bundle.ik)), dh(ek.priv, bundle.spk), dh(ek.priv, bundle.pk));
69
+ const dhs = generateKeyPair();
70
+ const [rk, cks] = kdfRk(sk, dh(dhs.priv, bundle.spk));
71
+ return {
72
+ rk,
73
+ dhs,
74
+ dhr: bundle.spk,
75
+ cks,
76
+ ns: 0,
77
+ nr: 0,
78
+ pn: 0,
79
+ skipped: {},
80
+ ad: concatBytes(own.pub, bundle.ik),
81
+ peerIk: bundle.ik,
82
+ pendingKex: {
83
+ pkId: bundle.pkId,
84
+ spkId: bundle.spkId,
85
+ ek: ek.pub
86
+ }
87
+ };
88
+ }
89
+ export function acceptSession(own, spk, pk, peerIk, ek) {
90
+ const sk = x3dhSecret(dh(spk.priv, identityDhPublic(peerIk)), dh(identityDhPrivate(own), ek), dh(spk.priv, ek), dh(pk.priv, ek));
91
+ return {
92
+ rk: sk,
93
+ dhs: spk,
94
+ ns: 0,
95
+ nr: 0,
96
+ pn: 0,
97
+ skipped: {},
98
+ ad: concatBytes(peerIk, own.pub),
99
+ peerIk,
100
+ kexEk: ek
101
+ };
102
+ }
103
+ export function ratchetEncrypt(session, plaintext) {
104
+ if (!session.cks) {
105
+ throw new Error('Session cannot send yet');
106
+ }
107
+ const s = cloneSession(session);
108
+ const [cks, mk] = kdfCk(s.cks);
109
+ s.cks = cks;
110
+ const {
111
+ enc,
112
+ auth,
113
+ iv
114
+ } = messageKeys(mk);
115
+ const message = encodeMessage({
116
+ n: s.ns,
117
+ pn: s.pn,
118
+ dhPub: s.dhs.pub,
119
+ ciphertext: aesEncrypt(enc, iv, plaintext)
120
+ });
121
+ s.ns++;
122
+ const mac = hmacSha256(auth, concatBytes(s.ad, message)).slice(0, 16);
123
+ return [s, encodeAuthenticated({
124
+ mac,
125
+ message
126
+ })];
127
+ }
128
+ export function ratchetDecrypt(session, data) {
129
+ const {
130
+ mac,
131
+ message
132
+ } = decodeAuthenticated(data);
133
+ const header = decodeMessage(message);
134
+ if (!header.ciphertext) {
135
+ throw new Error('Message without ciphertext');
136
+ }
137
+ const s = cloneSession(session);
138
+ const decrypt = mk => {
139
+ const {
140
+ enc,
141
+ auth,
142
+ iv
143
+ } = messageKeys(mk);
144
+ const expected = hmacSha256(auth, concatBytes(s.ad, message)).slice(0, 16);
145
+ if (!bytesEqual(expected, mac)) {
146
+ throw new Error('Message authentication failed');
147
+ }
148
+ return aesDecrypt(enc, iv, header.ciphertext);
149
+ };
150
+ const skippedId = `${toBase64(header.dhPub)}:${header.n}`;
151
+ const skippedKey = s.skipped[skippedId];
152
+ if (skippedKey) {
153
+ delete s.skipped[skippedId];
154
+ return [s, decrypt(skippedKey)];
155
+ }
156
+ if (!s.dhr || !bytesEqual(header.dhPub, s.dhr)) {
157
+ skipMessageKeys(s, header.pn);
158
+ s.pn = s.ns;
159
+ s.ns = 0;
160
+ s.nr = 0;
161
+ s.dhr = header.dhPub;
162
+ [s.rk, s.ckr] = kdfRk(s.rk, dh(s.dhs.priv, s.dhr));
163
+ s.dhs = generateKeyPair();
164
+ [s.rk, s.cks] = kdfRk(s.rk, dh(s.dhs.priv, s.dhr));
165
+ }
166
+ skipMessageKeys(s, header.n);
167
+ const [ckr, mk] = kdfCk(s.ckr);
168
+ s.ckr = ckr;
169
+ s.nr++;
170
+ return [s, decrypt(mk)];
171
+ }
172
+ function skipMessageKeys(s, until) {
173
+ if (!s.ckr || !s.dhr) {
174
+ return;
175
+ }
176
+ if (until - s.nr > MAX_SKIP) {
177
+ throw new Error('Too many skipped messages');
178
+ }
179
+ const dhr = toBase64(s.dhr);
180
+ while (s.nr < until) {
181
+ const [ckr, mk] = kdfCk(s.ckr);
182
+ s.ckr = ckr;
183
+ s.skipped[`${dhr}:${s.nr}`] = mk;
184
+ s.nr++;
185
+ }
186
+ const ids = Object.keys(s.skipped);
187
+ for (const id of ids.slice(0, Math.max(0, ids.length - MAX_SKIP))) {
188
+ delete s.skipped[id];
189
+ }
190
+ }
191
+ function payloadKeys(key) {
192
+ const km = hkdfSha256(key, undefined, 'OMEMO Payload', 80);
193
+ return {
194
+ enc: km.slice(0, 32),
195
+ auth: km.slice(32, 64),
196
+ iv: km.slice(64)
197
+ };
198
+ }
199
+ export function encryptPayload(plaintext) {
200
+ const key = randomBytes(32);
201
+ const {
202
+ enc,
203
+ auth,
204
+ iv
205
+ } = payloadKeys(key);
206
+ const payload = aesEncrypt(enc, iv, plaintext);
207
+ const mac = hmacSha256(auth, payload).slice(0, 16);
208
+ return {
209
+ keyMaterial: concatBytes(key, mac),
210
+ payload
211
+ };
212
+ }
213
+ export function decryptPayload(keyMaterial, payload) {
214
+ if (keyMaterial.length !== 48) {
215
+ throw new Error('Invalid key material');
216
+ }
217
+ const {
218
+ enc,
219
+ auth,
220
+ iv
221
+ } = payloadKeys(keyMaterial.slice(0, 32));
222
+ const expected = hmacSha256(auth, payload).slice(0, 16);
223
+ if (!bytesEqual(expected, keyMaterial.slice(32))) {
224
+ throw new Error('Payload authentication failed');
225
+ }
226
+ return aesDecrypt(enc, iv, payload);
227
+ }
228
+ //# sourceMappingURL=ratchet.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["aesDecrypt","aesEncrypt","bytesEqual","concatBytes","dh","generateKeyPair","hkdfSha256","hmacSha256","identityDhPrivate","identityDhPublic","randomBytes","toBase64","verify","decodeAuthenticated","decodeMessage","encodeAuthenticated","encodeMessage","MAX_SKIP","X3DH_PREFIX","Uint8Array","fill","cloneSession","session","skipped","id","Object","keys","slice","rk","dhs","priv","pub","dhr","cks","ckr","ns","nr","pn","ad","peerIk","pendingKex","pkId","spkId","ek","kexEk","kdfRk","dhOut","out","kdfCk","ck","of","messageKeys","mk","km","undefined","enc","auth","iv","x3dhSecret","initiateSession","own","bundle","spkSignature","spk","ik","Error","sk","pk","acceptSession","ratchetEncrypt","plaintext","s","message","n","dhPub","ciphertext","mac","ratchetDecrypt","data","header","decrypt","expected","skippedId","skippedKey","skipMessageKeys","until","ids","Math","max","length","payloadKeys","key","encryptPayload","payload","keyMaterial","decryptPayload"],"sourceRoot":"../../../src","sources":["e2ee/ratchet.ts"],"mappings":";;AAAA,SACEA,UAAU,EACVC,UAAU,EACVC,UAAU,EACVC,WAAW,EACXC,EAAE,EACFC,eAAe,EACfC,UAAU,EACVC,UAAU,EACVC,iBAAiB,EACjBC,gBAAgB,EAChBC,WAAW,EACXC,QAAQ,EACRC,MAAM,QAGD,UAAU;AACjB,SACEC,mBAAmB,EACnBC,aAAa,EACbC,mBAAmB,EACnBC,aAAa,QACR,YAAY;AAEnB,MAAMC,QAAQ,GAAG,IAAI;AACrB,MAAMC,WAAW,GAAG,IAAIC,UAAU,CAAC,EAAE,CAAC,CAACC,IAAI,CAAC,IAAI,CAAC;AA2BjD,OAAO,SAASC,YAAYA,CAACC,OAAgB,EAAW;EACtD,MAAMC,OAAmC,GAAG,CAAC,CAAC;EAC9C,KAAK,MAAMC,EAAE,IAAIC,MAAM,CAACC,IAAI,CAACJ,OAAO,CAACC,OAAO,CAAC,EAAE;IAC7CA,OAAO,CAACC,EAAE,CAAC,GAAGF,OAAO,CAACC,OAAO,CAACC,EAAE,CAAC,CAAEG,KAAK,CAAC,CAAC;EAC5C;EACA,OAAO;IACLC,EAAE,EAAEN,OAAO,CAACM,EAAE,CAACD,KAAK,CAAC,CAAC;IACtBE,GAAG,EAAE;MAAEC,IAAI,EAAER,OAAO,CAACO,GAAG,CAACC,IAAI,CAACH,KAAK,CAAC,CAAC;MAAEI,GAAG,EAAET,OAAO,CAACO,GAAG,CAACE,GAAG,CAACJ,KAAK,CAAC;IAAE,CAAC;IACrE,IAAIL,OAAO,CAACU,GAAG,GAAG;MAAEA,GAAG,EAAEV,OAAO,CAACU,GAAG,CAACL,KAAK,CAAC;IAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IACpD,IAAIL,OAAO,CAACW,GAAG,GAAG;MAAEA,GAAG,EAAEX,OAAO,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AAC;EAC3B,MAAM;IAAE6C,GAAG;IAAEC,IAAI;IAAEC;EAAG,CAAC,GAAGiC,WAAW,CAACC,GAAG,CAAC;EAC1C,MAAME,OAAO,GAAG5F,UAAU,CAACsD,GAAG,EAAEE,EAAE,EAAEa,SAAS,CAAC;EAC9C,MAAMM,GAAG,GAAGrE,UAAU,CAACiD,IAAI,EAAEqC,OAAO,CAAC,CAAClE,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC;EAClD,OAAO;IAAEmE,WAAW,EAAE3F,WAAW,CAACwF,GAAG,EAAEf,GAAG,CAAC;IAAEiB;EAAQ,CAAC;AACxD;AAEA,OAAO,SAASE,cAAcA,CAC5BD,WAAuB,EACvBD,OAAmB,EACP;EACZ,IAAIC,WAAW,CAACL,MAAM,KAAK,EAAE,EAAE;IAAC,MAAM,IAAIxB,KAAK,CAAC,sBAAsB,CAAC;EAAC;EACxE,MAAM;IAAEV,GAAG;IAAEC,IAAI;IAAEC;EAAG,CAAC,GAAGiC,WAAW,CAACI,WAAW,CAACnE,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;EAC/D,MAAMsD,QAAQ,GAAG1E,UAAU,CAACiD,IAAI,EAAEqC,OAAO,CAAC,CAAClE,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC;EACvD,IAAI,CAACzB,UAAU,CAAC+E,QAAQ,EAAEa,WAAW,CAACnE,KAAK,CAAC,EAAE,CAAC,CAAC,EAAE;IAChD,MAAM,IAAIsC,KAAK,CAAC,+BAA+B,CAAC;EAClD;EACA,OAAOjE,UAAU,CAACuD,GAAG,EAAEE,EAAE,EAAEoC,OAAO,CAAC;AACrC","ignoreList":[]}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ export function parseSealedMediaBody(body) {
4
+ const text = String(body || '').trim();
5
+ if (!text.startsWith('{')) {
6
+ return undefined;
7
+ }
8
+ try {
9
+ const parsed = JSON.parse(text);
10
+ if (parsed?.v !== 1 || !Array.isArray(parsed.keys)) {
11
+ return undefined;
12
+ }
13
+ const keys = parsed.keys.filter(k => typeof k === 'string' && k.length > 0);
14
+ return keys.length === parsed.keys.length && keys.length > 0 ? keys : undefined;
15
+ } catch {
16
+ return undefined;
17
+ }
18
+ }
19
+ //# sourceMappingURL=sealedBody.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["parseSealedMediaBody","body","text","String","trim","startsWith","undefined","parsed","JSON","parse","v","Array","isArray","keys","filter","k","length"],"sourceRoot":"../../../src","sources":["e2ee/sealedBody.ts"],"mappings":";;AAAA,OAAO,SAASA,oBAAoBA,CAACC,IAAa,EAAwB;EACxE,MAAMC,IAAI,GAAGC,MAAM,CAACF,IAAI,IAAI,EAAE,CAAC,CAACG,IAAI,CAAC,CAAC;EACtC,IAAI,CAACF,IAAI,CAACG,UAAU,CAAC,GAAG,CAAC,EAAE;IAAC,OAAOC,SAAS;EAAC;EAE7C,IAAI;IACF,MAAMC,MAAM,GAAGC,IAAI,CAACC,KAAK,CAACP,IAAI,CAAoC;IAClE,IAAIK,MAAM,EAAEG,CAAC,KAAK,CAAC,IAAI,CAACC,KAAK,CAACC,OAAO,CAACL,MAAM,CAACM,IAAI,CAAC,EAAE;MAAC,OAAOP,SAAS;IAAC;IACtE,MAAMO,IAAI,GAAGN,MAAM,CAACM,IAAI,CAACC,MAAM,CAC5BC,CAAC,IAAkB,OAAOA,CAAC,KAAK,QAAQ,IAAIA,CAAC,CAACC,MAAM,GAAG,CAC1D,CAAC;IACD,OAAOH,IAAI,CAACG,MAAM,KAAKT,MAAM,CAACM,IAAI,CAACG,MAAM,IAAIH,IAAI,CAACG,MAAM,GAAG,CAAC,GACxDH,IAAI,GACJP,SAAS;EACf,CAAC,CAAC,MAAM;IACN,OAAOA,SAAS;EAClB;AACF","ignoreList":[]}
@@ -0,0 +1,154 @@
1
+ "use strict";
2
+
3
+ import { Directory, File as FsFile, Paths } from 'expo-file-system';
4
+ import * as LegacyFileSystem from 'expo-file-system/legacy';
5
+ import { ensureFilenameHasExtension } from '../helpers/mimeToExtension';
6
+ import { sanitizeFileNameForPath } from '../helpers/getDisplayFileName';
7
+ import { openSealedFile, sealFileForUpload } from './fileEnvelope';
8
+ import { MAX_OPEN_BYTES, MAX_SEAL_BYTES } from './limits';
9
+ export { MAX_OPEN_BYTES, MAX_SEAL_BYTES };
10
+ const OPENED_DIR = 'ethora-sealed';
11
+ const hashString = value => {
12
+ let hash = 5381;
13
+ for (let i = 0; i < value.length; i++) {
14
+ hash = hash * 33 ^ value.charCodeAt(i);
15
+ }
16
+ return (hash >>> 0).toString(36);
17
+ };
18
+ export async function sealPickedFile(picked, onProgress) {
19
+ if (typeof picked.size === 'number' && picked.size > MAX_SEAL_BYTES) {
20
+ throw new Error('sealed_attachment_too_large');
21
+ }
22
+ const bytes = await new FsFile(picked.uri).bytes();
23
+ if (bytes.length > MAX_SEAL_BYTES) {
24
+ throw new Error('sealed_attachment_too_large');
25
+ }
26
+ const sealed = await sealFileForUpload({
27
+ bytes,
28
+ name: picked.name,
29
+ type: picked.type
30
+ }, onProgress);
31
+ const parked = new FsFile(Paths.cache, `ethora-seal-${sealed.filename}`);
32
+ parked.write(sealed.ciphertext);
33
+ return {
34
+ uri: parked.uri,
35
+ name: sealed.filename,
36
+ keyMaterial: sealed.keyMaterial,
37
+ dispose: () => {
38
+ try {
39
+ if (parked.exists) {
40
+ parked.delete();
41
+ }
42
+ } catch {}
43
+ }
44
+ };
45
+ }
46
+ const folderFor = location => new Directory(Paths.cache, OPENED_DIR, hashString(location.split('#')[0].split('?')[0]));
47
+ const noteIn = folder => new FsFile(folder, 'meta.json');
48
+ export async function findOpened(location) {
49
+ if (!location) {
50
+ return null;
51
+ }
52
+ try {
53
+ const folder = folderFor(location);
54
+ const note = noteIn(folder);
55
+ if (!note.exists) {
56
+ return null;
57
+ }
58
+ const opened = JSON.parse(await note.text());
59
+ return new FsFile(opened.uri).exists ? opened : null;
60
+ } catch {
61
+ return null;
62
+ }
63
+ }
64
+ function keep(location, meta, write) {
65
+ return (async () => {
66
+ const folder = folderFor(location);
67
+ folder.create({
68
+ intermediates: true,
69
+ idempotent: true
70
+ });
71
+ const name = sanitizeFileNameForPath(ensureFilenameHasExtension(meta.name, meta.mimetype)).replace(/^\.+/, '') || 'file';
72
+ const target = new FsFile(folder, name);
73
+ if (target.exists) {
74
+ target.delete();
75
+ }
76
+ await write(target);
77
+ const opened = {
78
+ uri: target.uri,
79
+ name: meta.name,
80
+ mimetype: meta.mimetype,
81
+ size: meta.size
82
+ };
83
+ const note = noteIn(folder);
84
+ if (note.exists) {
85
+ note.delete();
86
+ }
87
+ note.write(JSON.stringify(opened));
88
+ return opened;
89
+ })();
90
+ }
91
+ const opening = new Map();
92
+ export function openSealedAttachment(location, url, keyMaterial, onProgress) {
93
+ const running = opening.get(location);
94
+ if (running) {
95
+ return running;
96
+ }
97
+ const task = (async () => {
98
+ const kept = await findOpened(location);
99
+ if (kept) {
100
+ return kept;
101
+ }
102
+ const parked = new FsFile(Paths.cache, `ethora-open-${hashString(location)}`);
103
+ try {
104
+ if (parked.exists) {
105
+ parked.delete();
106
+ }
107
+ const download = await LegacyFileSystem.downloadAsync(url, parked.uri);
108
+ if (download.status < 200 || download.status >= 300) {
109
+ throw new Error(`sealed_attachment_http_${download.status}`);
110
+ }
111
+ if ((parked.size ?? 0) > MAX_OPEN_BYTES) {
112
+ throw new Error('sealed_attachment_too_large');
113
+ }
114
+ const ciphertext = await parked.bytes();
115
+ const {
116
+ meta,
117
+ bytes
118
+ } = await openSealedFile(ciphertext, keyMaterial, onProgress);
119
+ return await keep(location, {
120
+ name: meta.originalname,
121
+ mimetype: meta.mimetype,
122
+ size: bytes.length
123
+ }, target => target.write(bytes));
124
+ } finally {
125
+ try {
126
+ if (parked.exists) {
127
+ parked.delete();
128
+ }
129
+ } catch {}
130
+ }
131
+ })().finally(() => opening.delete(location));
132
+ opening.set(location, task);
133
+ return task;
134
+ }
135
+ export async function rememberOpened(location, source) {
136
+ if (!location || !source?.uri) {
137
+ return;
138
+ }
139
+ const original = new FsFile(source.uri);
140
+ await keep(location, {
141
+ name: source.name || 'blob',
142
+ mimetype: source.type || 'application/octet-stream',
143
+ size: source.size ?? original.size ?? 0
144
+ }, target => original.copy(target));
145
+ }
146
+ export function clearOpenedFiles() {
147
+ try {
148
+ const root = new Directory(Paths.cache, OPENED_DIR);
149
+ if (root.exists) {
150
+ root.delete();
151
+ }
152
+ } catch {}
153
+ }
154
+ //# sourceMappingURL=sealedFiles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["Directory","File","FsFile","Paths","LegacyFileSystem","ensureFilenameHasExtension","sanitizeFileNameForPath","openSealedFile","sealFileForUpload","MAX_OPEN_BYTES","MAX_SEAL_BYTES","OPENED_DIR","hashString","value","hash","i","length","charCodeAt","toString","sealPickedFile","picked","onProgress","size","Error","bytes","uri","sealed","name","type","parked","cache","filename","write","ciphertext","keyMaterial","dispose","exists","delete","folderFor","location","split","noteIn","folder","findOpened","note","opened","JSON","parse","text","keep","meta","create","intermediates","idempotent","mimetype","replace","target","stringify","opening","Map","openSealedAttachment","url","running","get","task","kept","download","downloadAsync","status","originalname","finally","set","rememberOpened","source","original","copy","clearOpenedFiles","root"],"sourceRoot":"../../../src","sources":["e2ee/sealedFiles.ts"],"mappings":";;AAAA,SAASA,SAAS,EAAEC,IAAI,IAAIC,MAAM,EAAEC,KAAK,QAAQ,kBAAkB;AACnE,OAAO,KAAKC,gBAAgB,MAAM,yBAAyB;AAC3D,SAASC,0BAA0B,QAAQ,4BAA4B;AACvE,SAASC,uBAAuB,QAAQ,+BAA+B;AACvE,SAASC,cAAc,EAAEC,iBAAiB,QAAQ,gBAAgB;AAElE,SAASC,cAAc,EAAEC,cAAc,QAAQ,UAAU;AAEzD,SAASD,cAAc,EAAEC,cAAc;AAEvC,MAAMC,UAAU,GAAG,eAAe;AAgBlC,MAAMC,UAAU,GAAIC,KAAa,IAAK;EACpC,IAAIC,IAAI,GAAG,IAAI;EACf,KAAK,IAAIC,CAAC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;EAC3B,OAAOA,IAAI;AACb;AAEA,OAAO,eAAeQ,cAAcA,CAClCjC,QAAgB,EAChBkC,MAAoE,EACrD;EACf,IAAI,CAAClC,QAAQ,IAAI,CAACkC,MAAM,EAAEhD,GAAG,EAAE;IAAC;EAAO;EACvC,MAAMiD,QAAQ,GAAG,IAAIxE,MAAM,CAACuE,MAAM,CAAChD,GAAG,CAAC;EACvC,MAAMwB,IAAI,CACRV,QAAQ,EACR;IACEZ,IAAI,EAAE8C,MAAM,CAAC9C,IAAI,IAAI,MAAM;IAC3B2B,QAAQ,EAAEmB,MAAM,CAAC7C,IAAI,IAAI,0BAA0B;IACnDN,IAAI,EAAEmD,MAAM,CAACnD,IAAI,IAAIoD,QAAQ,CAACpD,IAAI,IAAI;EACxC,CAAC,EACAkC,MAAM,IAAKkB,QAAQ,CAACC,IAAI,CAACnB,MAAM,CAClC,CAAC;AACH;AAEA,OAAO,SAASoB,gBAAgBA,CAAA,EAAS;EACvC,IAAI;IACF,MAAMC,IAAI,GAAG,IAAI7E,SAAS,CAACG,KAAK,CAAC2B,KAAK,EAAEnB,UAAU,CAAC;IACnD,IAAIkE,IAAI,CAACzC,MAAM,EAAE;MAACyC,IAAI,CAACxC,MAAM,CAAC,CAAC;IAAC;EAClC,CAAC,CAAC,MAAM,CACR;AACF","ignoreList":[]}
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+
3
+ import { accountDomain, isE2eeEnabled, isE2eeRoom, omemoReady, resolveRecipients } from './index';
4
+ export function shouldEncrypt(roomJID) {
5
+ return isE2eeEnabled() && isE2eeRoom(roomJID);
6
+ }
7
+ let queue = Promise.resolve();
8
+ export function sendEncrypted(client, roomJID, id, data, body, plain) {
9
+ queue = queue.then(async () => {
10
+ let stanza = plain;
11
+ try {
12
+ const crypto = await omemoReady();
13
+ if (!crypto) {
14
+ throw new Error('omemo_not_ready');
15
+ }
16
+ const recipients = await resolveRecipients(roomJID, accountDomain(client));
17
+ stanza = await crypto.encryptGroupMessage(roomJID, recipients, [body], id, [data]);
18
+ } catch (error) {
19
+ const reason = String(error?.message || error);
20
+ if (reason.startsWith('omemo_members_unknown')) {
21
+ console.warn(`OMEMO: not sending to ${roomJID} - ${reason}`);
22
+ return;
23
+ }
24
+ console.warn(`OMEMO: sending to ${roomJID} in clear - ${reason}`);
25
+ }
26
+ try {
27
+ await client.send(stanza);
28
+ } catch (error) {
29
+ console.error('An error occurred while sending message:', error);
30
+ }
31
+ });
32
+ }
33
+ export function sendSealedMedia(client, roomJID, id, body, cleartext) {
34
+ queue = queue.then(async () => {
35
+ try {
36
+ const crypto = await omemoReady();
37
+ if (!crypto) {
38
+ throw new Error('omemo_not_ready');
39
+ }
40
+ const recipients = await resolveRecipients(roomJID, accountDomain(client));
41
+ const stanza = await crypto.encryptGroupMessage(roomJID, recipients, [body], id, cleartext);
42
+ await client.send(stanza);
43
+ } catch (error) {
44
+ console.error(`OMEMO: refusing to send sealed attachment to ${roomJID} - ${String(error?.message || error)}`);
45
+ }
46
+ });
47
+ }
48
+ //# sourceMappingURL=send.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["accountDomain","isE2eeEnabled","isE2eeRoom","omemoReady","resolveRecipients","shouldEncrypt","roomJID","queue","Promise","resolve","sendEncrypted","client","id","data","body","plain","then","stanza","crypto","Error","recipients","encryptGroupMessage","error","reason","String","message","startsWith","console","warn","send","sendSealedMedia","cleartext"],"sourceRoot":"../../../src","sources":["e2ee/send.ts"],"mappings":";;AAEA,SACEA,aAAa,EACbC,aAAa,EACbC,UAAU,EACVC,UAAU,EACVC,iBAAiB,QACZ,SAAS;AAEhB,OAAO,SAASC,aAAaA,CAACC,OAAe,EAAW;EACtD,OAAOL,aAAa,CAAC,CAAC,IAAIC,UAAU,CAACI,OAAO,CAAC;AAC/C;AAEA,IAAIC,KAAoB,GAAGC,OAAO,CAACC,OAAO,CAAC,CAAC;AAE5C,OAAO,SAASC,aAAaA,CAC3BC,MAAc,EACdL,OAAe,EACfM,EAAU,EACVC,IAA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