@ethora/chat-component-rn 26.8.6 → 26.8.7
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.
- package/CHANGELOG.md +26 -0
- package/README.md +40 -0
- package/lib/commonjs/assets/icons.js +4 -2
- package/lib/commonjs/assets/icons.js.map +1 -1
- package/lib/commonjs/components/MainComponents/ChatHeader.js +28 -6
- package/lib/commonjs/components/MainComponents/ChatHeader.js.map +1 -1
- package/lib/commonjs/components/MainComponents/ChatRoom.js +9 -1
- package/lib/commonjs/components/MainComponents/ChatRoom.js.map +1 -1
- package/lib/commonjs/components/MainComponents/EncryptedSendNotice.js +47 -0
- package/lib/commonjs/components/MainComponents/EncryptedSendNotice.js.map +1 -0
- package/lib/commonjs/components/MainComponents/EncryptionCard.js +286 -0
- package/lib/commonjs/components/MainComponents/EncryptionCard.js.map +1 -0
- package/lib/commonjs/components/MainComponents/MediaMessage.js +7 -0
- package/lib/commonjs/components/MainComponents/MediaMessage.js.map +1 -1
- package/lib/commonjs/components/MainComponents/ReduxWrapper.js +5 -0
- package/lib/commonjs/components/MainComponents/ReduxWrapper.js.map +1 -1
- package/lib/commonjs/components/MainComponents/SealedAttachment.js +231 -0
- package/lib/commonjs/components/MainComponents/SealedAttachment.js.map +1 -0
- package/lib/commonjs/components/MessageBubble/BottomReplyContainer.js +2 -1
- package/lib/commonjs/components/MessageBubble/BottomReplyContainer.js.map +1 -1
- package/lib/commonjs/components/MessageBubble/Message.js +66 -6
- package/lib/commonjs/components/MessageBubble/Message.js.map +1 -1
- package/lib/commonjs/components/MessageBubble/MessageInteractions.js +2 -1
- package/lib/commonjs/components/MessageBubble/MessageInteractions.js.map +1 -1
- package/lib/commonjs/components/Modals/ChatProfileModal/ChatProfileModal.js +7 -4
- package/lib/commonjs/components/Modals/ChatProfileModal/ChatProfileModal.js.map +1 -1
- package/lib/commonjs/components/Modals/FilePreviewModal/FilePreviewModal.js +159 -16
- package/lib/commonjs/components/Modals/FilePreviewModal/FilePreviewModal.js.map +1 -1
- package/lib/commonjs/components/Modals/FilePreviewModal/PdfView.js +4 -0
- package/lib/commonjs/components/Modals/FilePreviewModal/PdfView.js.map +1 -1
- package/lib/commonjs/components/Modals/UserProfileModal/UserProfileModal.js +29 -6
- package/lib/commonjs/components/Modals/UserProfileModal/UserProfileModal.js.map +1 -1
- package/lib/commonjs/components/Modals/UserSettingsModal/UserSettingsModal.js +5 -1
- package/lib/commonjs/components/Modals/UserSettingsModal/UserSettingsModal.js.map +1 -1
- package/lib/commonjs/components/RoomComponents/ChatRoomItem.js +32 -9
- package/lib/commonjs/components/RoomComponents/ChatRoomItem.js.map +1 -1
- package/lib/commonjs/components/RoomComponents/LastMessageItem.js +6 -0
- package/lib/commonjs/components/RoomComponents/LastMessageItem.js.map +1 -1
- package/lib/commonjs/components/RoomComponents/styled/LastAudioMessage.js +2 -2
- package/lib/commonjs/components/RoomComponents/styled/LastAudioMessage.js.map +1 -1
- package/lib/commonjs/components/RoomComponents/styled/LastMessageFile.js +4 -6
- package/lib/commonjs/components/RoomComponents/styled/LastMessageFile.js.map +1 -1
- package/lib/commonjs/components/RoomComponents/styled/LastMessagePhoto.js +2 -2
- package/lib/commonjs/components/RoomComponents/styled/LastMessagePhoto.js.map +1 -1
- package/lib/commonjs/components/RoomComponents/styled/LastMessageSealed.js +41 -0
- package/lib/commonjs/components/RoomComponents/styled/LastMessageSealed.js.map +1 -0
- package/lib/commonjs/components/RoomComponents/styled/LastMessageVideo.js +2 -2
- package/lib/commonjs/components/RoomComponents/styled/LastMessageVideo.js.map +1 -1
- package/lib/commonjs/components/Thread/ThreadWrapper.js +53 -45
- package/lib/commonjs/components/Thread/ThreadWrapper.js.map +1 -1
- package/lib/commonjs/components/UsersList/UsersList.js +2 -1
- package/lib/commonjs/components/UsersList/UsersList.js.map +1 -1
- package/lib/commonjs/components/styled/SendInput.js +4 -2
- package/lib/commonjs/components/styled/SendInput.js.map +1 -1
- package/lib/commonjs/e2ee/crypto.js +207 -0
- package/lib/commonjs/e2ee/crypto.js.map +1 -0
- package/lib/commonjs/e2ee/deviceStore.js +84 -0
- package/lib/commonjs/e2ee/deviceStore.js.map +1 -0
- package/lib/commonjs/e2ee/fileCipher.js +95 -0
- package/lib/commonjs/e2ee/fileCipher.js.map +1 -0
- package/lib/commonjs/e2ee/fileEnvelope.js +79 -0
- package/lib/commonjs/e2ee/fileEnvelope.js.map +1 -0
- package/lib/commonjs/e2ee/index.js +210 -0
- package/lib/commonjs/e2ee/index.js.map +1 -0
- package/lib/commonjs/e2ee/limits.js +9 -0
- package/lib/commonjs/e2ee/limits.js.map +1 -0
- package/lib/commonjs/e2ee/ns.js +8 -0
- package/lib/commonjs/e2ee/ns.js.map +1 -0
- package/lib/commonjs/e2ee/omemo.js +622 -0
- package/lib/commonjs/e2ee/omemo.js.map +1 -0
- package/lib/commonjs/e2ee/protobuf.js +149 -0
- package/lib/commonjs/e2ee/protobuf.js.map +1 -0
- package/lib/commonjs/e2ee/ratchet.js +238 -0
- package/lib/commonjs/e2ee/ratchet.js.map +1 -0
- package/lib/commonjs/e2ee/sealedBody.js +23 -0
- package/lib/commonjs/e2ee/sealedBody.js.map +1 -0
- package/lib/commonjs/e2ee/sealedFiles.js +174 -0
- package/lib/commonjs/e2ee/sealedFiles.js.map +1 -0
- package/lib/commonjs/e2ee/send.js +54 -0
- package/lib/commonjs/e2ee/send.js.map +1 -0
- package/lib/commonjs/e2ee/stanza.js +114 -0
- package/lib/commonjs/e2ee/stanza.js.map +1 -0
- package/lib/commonjs/e2ee/store.js +43 -0
- package/lib/commonjs/e2ee/store.js.map +1 -0
- package/lib/commonjs/helpers/accountName.js +23 -0
- package/lib/commonjs/helpers/accountName.js.map +1 -0
- package/lib/commonjs/helpers/createMessageFromXml.js +19 -4
- package/lib/commonjs/helpers/createMessageFromXml.js.map +1 -1
- package/lib/commonjs/helpers/createUserNameFromSetUser.js +2 -1
- package/lib/commonjs/helpers/createUserNameFromSetUser.js.map +1 -1
- package/lib/commonjs/helpers/displayName.js +16 -0
- package/lib/commonjs/helpers/displayName.js.map +1 -0
- package/lib/commonjs/helpers/persistCrypto.js +5 -0
- package/lib/commonjs/helpers/persistCrypto.js.map +1 -1
- package/lib/commonjs/helpers/secureKeyValue.js +20 -0
- package/lib/commonjs/helpers/secureKeyValue.js.map +1 -1
- package/lib/commonjs/helpers/videoCache.js +136 -0
- package/lib/commonjs/helpers/videoCache.js.map +1 -0
- package/lib/commonjs/hooks/useLogout.js +8 -0
- package/lib/commonjs/hooks/useLogout.js.map +1 -1
- package/lib/commonjs/hooks/useSendMessage.js +71 -7
- package/lib/commonjs/hooks/useSendMessage.js.map +1 -1
- package/lib/commonjs/i18n/strings.js +180 -0
- package/lib/commonjs/i18n/strings.js.map +1 -1
- package/lib/commonjs/main.js +13 -0
- package/lib/commonjs/main.js.map +1 -1
- package/lib/commonjs/networking/api-requests/auth.api.js +4 -1
- package/lib/commonjs/networking/api-requests/auth.api.js.map +1 -1
- package/lib/commonjs/networking/api-requests/rooms.api.js +111 -17
- package/lib/commonjs/networking/api-requests/rooms.api.js.map +1 -1
- package/lib/commonjs/networking/xmpp/handleStanzas.xmpp.js +40 -0
- package/lib/commonjs/networking/xmpp/handleStanzas.xmpp.js.map +1 -1
- package/lib/commonjs/networking/xmpp/sendMediaMessage.xmpp.js +16 -3
- package/lib/commonjs/networking/xmpp/sendMediaMessage.xmpp.js.map +1 -1
- package/lib/commonjs/networking/xmpp/sendTextMessage.xmpp.js +13 -6
- package/lib/commonjs/networking/xmpp/sendTextMessage.xmpp.js.map +1 -1
- package/lib/commonjs/networking/xmpp/sendTextMessageWithTranslateTag.xmpp.js +14 -6
- package/lib/commonjs/networking/xmpp/sendTextMessageWithTranslateTag.xmpp.js.map +1 -1
- package/lib/commonjs/networking/xmppClient.js +6 -0
- package/lib/commonjs/networking/xmppClient.js.map +1 -1
- package/lib/commonjs/roomStore/persistBackend.js +9 -12
- package/lib/commonjs/roomStore/persistBackend.js.map +1 -1
- package/lib/commonjs/roomStore/persistence.js +8 -1
- package/lib/commonjs/roomStore/persistence.js.map +1 -1
- package/lib/commonjs/version.js +1 -1
- package/lib/module/assets/icons.js +3 -1
- package/lib/module/assets/icons.js.map +1 -1
- package/lib/module/components/MainComponents/ChatHeader.js +29 -7
- package/lib/module/components/MainComponents/ChatHeader.js.map +1 -1
- package/lib/module/components/MainComponents/ChatRoom.js +9 -1
- package/lib/module/components/MainComponents/ChatRoom.js.map +1 -1
- package/lib/module/components/MainComponents/EncryptedSendNotice.js +42 -0
- package/lib/module/components/MainComponents/EncryptedSendNotice.js.map +1 -0
- package/lib/module/components/MainComponents/EncryptionCard.js +281 -0
- package/lib/module/components/MainComponents/EncryptionCard.js.map +1 -0
- package/lib/module/components/MainComponents/MediaMessage.js +7 -0
- package/lib/module/components/MainComponents/MediaMessage.js.map +1 -1
- package/lib/module/components/MainComponents/ReduxWrapper.js +5 -0
- package/lib/module/components/MainComponents/ReduxWrapper.js.map +1 -1
- package/lib/module/components/MainComponents/SealedAttachment.js +224 -0
- package/lib/module/components/MainComponents/SealedAttachment.js.map +1 -0
- package/lib/module/components/MessageBubble/BottomReplyContainer.js +2 -1
- package/lib/module/components/MessageBubble/BottomReplyContainer.js.map +1 -1
- package/lib/module/components/MessageBubble/Message.js +69 -9
- package/lib/module/components/MessageBubble/Message.js.map +1 -1
- package/lib/module/components/MessageBubble/MessageInteractions.js +2 -1
- package/lib/module/components/MessageBubble/MessageInteractions.js.map +1 -1
- package/lib/module/components/Modals/ChatProfileModal/ChatProfileModal.js +7 -4
- package/lib/module/components/Modals/ChatProfileModal/ChatProfileModal.js.map +1 -1
- package/lib/module/components/Modals/FilePreviewModal/FilePreviewModal.js +161 -18
- package/lib/module/components/Modals/FilePreviewModal/FilePreviewModal.js.map +1 -1
- package/lib/module/components/Modals/FilePreviewModal/PdfView.js +4 -0
- package/lib/module/components/Modals/FilePreviewModal/PdfView.js.map +1 -1
- package/lib/module/components/Modals/UserProfileModal/UserProfileModal.js +32 -8
- package/lib/module/components/Modals/UserProfileModal/UserProfileModal.js.map +1 -1
- package/lib/module/components/Modals/UserSettingsModal/UserSettingsModal.js +4 -0
- package/lib/module/components/Modals/UserSettingsModal/UserSettingsModal.js.map +1 -1
- package/lib/module/components/RoomComponents/ChatRoomItem.js +32 -9
- package/lib/module/components/RoomComponents/ChatRoomItem.js.map +1 -1
- package/lib/module/components/RoomComponents/LastMessageItem.js +6 -0
- package/lib/module/components/RoomComponents/LastMessageItem.js.map +1 -1
- package/lib/module/components/RoomComponents/styled/LastAudioMessage.js +2 -2
- package/lib/module/components/RoomComponents/styled/LastAudioMessage.js.map +1 -1
- package/lib/module/components/RoomComponents/styled/LastMessageFile.js +4 -6
- package/lib/module/components/RoomComponents/styled/LastMessageFile.js.map +1 -1
- package/lib/module/components/RoomComponents/styled/LastMessagePhoto.js +2 -2
- package/lib/module/components/RoomComponents/styled/LastMessagePhoto.js.map +1 -1
- package/lib/module/components/RoomComponents/styled/LastMessageSealed.js +36 -0
- package/lib/module/components/RoomComponents/styled/LastMessageSealed.js.map +1 -0
- package/lib/module/components/RoomComponents/styled/LastMessageVideo.js +2 -2
- package/lib/module/components/RoomComponents/styled/LastMessageVideo.js.map +1 -1
- package/lib/module/components/Thread/ThreadWrapper.js +54 -46
- package/lib/module/components/Thread/ThreadWrapper.js.map +1 -1
- package/lib/module/components/UsersList/UsersList.js +2 -1
- package/lib/module/components/UsersList/UsersList.js.map +1 -1
- package/lib/module/components/styled/SendInput.js +4 -2
- package/lib/module/components/styled/SendInput.js.map +1 -1
- package/lib/module/e2ee/crypto.js +170 -0
- package/lib/module/e2ee/crypto.js.map +1 -0
- package/lib/module/e2ee/deviceStore.js +77 -0
- package/lib/module/e2ee/deviceStore.js.map +1 -0
- package/lib/module/e2ee/fileCipher.js +90 -0
- package/lib/module/e2ee/fileCipher.js.map +1 -0
- package/lib/module/e2ee/fileEnvelope.js +66 -0
- package/lib/module/e2ee/fileEnvelope.js.map +1 -0
- package/lib/module/e2ee/index.js +185 -0
- package/lib/module/e2ee/index.js.map +1 -0
- package/lib/module/e2ee/limits.js +5 -0
- package/lib/module/e2ee/limits.js.map +1 -0
- package/lib/module/e2ee/ns.js +4 -0
- package/lib/module/e2ee/ns.js.map +1 -0
- package/lib/module/e2ee/omemo.js +610 -0
- package/lib/module/e2ee/omemo.js.map +1 -0
- package/lib/module/e2ee/protobuf.js +140 -0
- package/lib/module/e2ee/protobuf.js.map +1 -0
- package/lib/module/e2ee/ratchet.js +228 -0
- package/lib/module/e2ee/ratchet.js.map +1 -0
- package/lib/module/e2ee/sealedBody.js +19 -0
- package/lib/module/e2ee/sealedBody.js.map +1 -0
- package/lib/module/e2ee/sealedFiles.js +154 -0
- package/lib/module/e2ee/sealedFiles.js.map +1 -0
- package/lib/module/e2ee/send.js +48 -0
- package/lib/module/e2ee/send.js.map +1 -0
- package/lib/module/e2ee/stanza.js +107 -0
- package/lib/module/e2ee/stanza.js.map +1 -0
- package/lib/module/e2ee/store.js +35 -0
- package/lib/module/e2ee/store.js.map +1 -0
- package/lib/module/helpers/accountName.js +18 -0
- package/lib/module/helpers/accountName.js.map +1 -0
- package/lib/module/helpers/createMessageFromXml.js +19 -4
- package/lib/module/helpers/createMessageFromXml.js.map +1 -1
- package/lib/module/helpers/createUserNameFromSetUser.js +3 -1
- package/lib/module/helpers/createUserNameFromSetUser.js.map +1 -1
- package/lib/module/helpers/displayName.js +11 -0
- package/lib/module/helpers/displayName.js.map +1 -0
- package/lib/module/helpers/persistCrypto.js +4 -0
- package/lib/module/helpers/persistCrypto.js.map +1 -1
- package/lib/module/helpers/secureKeyValue.js +19 -0
- package/lib/module/helpers/secureKeyValue.js.map +1 -1
- package/lib/module/helpers/videoCache.js +125 -0
- package/lib/module/helpers/videoCache.js.map +1 -0
- package/lib/module/hooks/useLogout.js +8 -0
- package/lib/module/hooks/useLogout.js.map +1 -1
- package/lib/module/hooks/useSendMessage.js +71 -7
- package/lib/module/hooks/useSendMessage.js.map +1 -1
- package/lib/module/i18n/strings.js +180 -0
- package/lib/module/i18n/strings.js.map +1 -1
- package/lib/module/main.js +1 -0
- package/lib/module/main.js.map +1 -1
- package/lib/module/networking/api-requests/auth.api.js +4 -1
- package/lib/module/networking/api-requests/auth.api.js.map +1 -1
- package/lib/module/networking/api-requests/rooms.api.js +109 -18
- package/lib/module/networking/api-requests/rooms.api.js.map +1 -1
- package/lib/module/networking/xmpp/handleStanzas.xmpp.js +38 -0
- package/lib/module/networking/xmpp/handleStanzas.xmpp.js.map +1 -1
- package/lib/module/networking/xmpp/sendMediaMessage.xmpp.js +16 -3
- package/lib/module/networking/xmpp/sendMediaMessage.xmpp.js.map +1 -1
- package/lib/module/networking/xmpp/sendTextMessage.xmpp.js +13 -6
- package/lib/module/networking/xmpp/sendTextMessage.xmpp.js.map +1 -1
- package/lib/module/networking/xmpp/sendTextMessageWithTranslateTag.xmpp.js +14 -6
- package/lib/module/networking/xmpp/sendTextMessageWithTranslateTag.xmpp.js.map +1 -1
- package/lib/module/networking/xmppClient.js +6 -0
- package/lib/module/networking/xmppClient.js.map +1 -1
- package/lib/module/roomStore/persistBackend.js +10 -13
- package/lib/module/roomStore/persistBackend.js.map +1 -1
- package/lib/module/roomStore/persistence.js +8 -1
- package/lib/module/roomStore/persistence.js.map +1 -1
- package/lib/module/version.js +1 -1
- package/lib/typescript/assets/icons.d.ts +8 -0
- package/lib/typescript/assets/icons.d.ts.map +1 -1
- package/lib/typescript/components/MainComponents/ChatHeader.d.ts.map +1 -1
- package/lib/typescript/components/MainComponents/ChatRoom.d.ts.map +1 -1
- package/lib/typescript/components/MainComponents/EncryptedSendNotice.d.ts +4 -0
- package/lib/typescript/components/MainComponents/EncryptedSendNotice.d.ts.map +1 -0
- package/lib/typescript/components/MainComponents/EncryptionCard.d.ts +10 -0
- package/lib/typescript/components/MainComponents/EncryptionCard.d.ts.map +1 -0
- package/lib/typescript/components/MainComponents/MediaMessage.d.ts.map +1 -1
- package/lib/typescript/components/MainComponents/ReduxWrapper.d.ts.map +1 -1
- package/lib/typescript/components/MainComponents/SealedAttachment.d.ts +13 -0
- package/lib/typescript/components/MainComponents/SealedAttachment.d.ts.map +1 -0
- package/lib/typescript/components/MessageBubble/BottomReplyContainer.d.ts.map +1 -1
- package/lib/typescript/components/MessageBubble/Message.d.ts.map +1 -1
- package/lib/typescript/components/MessageBubble/MessageInteractions.d.ts.map +1 -1
- package/lib/typescript/components/Modals/ChatProfileModal/ChatProfileModal.d.ts.map +1 -1
- package/lib/typescript/components/Modals/FilePreviewModal/FilePreviewModal.d.ts.map +1 -1
- package/lib/typescript/components/Modals/FilePreviewModal/PdfView.d.ts.map +1 -1
- package/lib/typescript/components/Modals/UserProfileModal/UserProfileModal.d.ts.map +1 -1
- package/lib/typescript/components/Modals/UserSettingsModal/UserSettingsModal.d.ts.map +1 -1
- package/lib/typescript/components/RoomComponents/ChatRoomItem.d.ts.map +1 -1
- package/lib/typescript/components/RoomComponents/LastMessageItem.d.ts.map +1 -1
- package/lib/typescript/components/RoomComponents/styled/LastAudioMessage.d.ts.map +1 -1
- package/lib/typescript/components/RoomComponents/styled/LastMessageSealed.d.ts +7 -0
- package/lib/typescript/components/RoomComponents/styled/LastMessageSealed.d.ts.map +1 -0
- package/lib/typescript/components/Thread/ThreadWrapper.d.ts.map +1 -1
- package/lib/typescript/components/UsersList/UsersList.d.ts.map +1 -1
- package/lib/typescript/components/styled/SendInput.d.ts +1 -0
- package/lib/typescript/components/styled/SendInput.d.ts.map +1 -1
- package/lib/typescript/e2ee/crypto.d.ts +28 -0
- package/lib/typescript/e2ee/crypto.d.ts.map +1 -0
- package/lib/typescript/e2ee/deviceStore.d.ts +4 -0
- package/lib/typescript/e2ee/deviceStore.d.ts.map +1 -0
- package/lib/typescript/e2ee/fileCipher.d.ts +7 -0
- package/lib/typescript/e2ee/fileCipher.d.ts.map +1 -0
- package/lib/typescript/e2ee/fileEnvelope.d.ts +27 -0
- package/lib/typescript/e2ee/fileEnvelope.d.ts.map +1 -0
- package/lib/typescript/e2ee/index.d.ts +23 -0
- package/lib/typescript/e2ee/index.d.ts.map +1 -0
- package/lib/typescript/e2ee/limits.d.ts +3 -0
- package/lib/typescript/e2ee/limits.d.ts.map +1 -0
- package/lib/typescript/e2ee/ns.d.ts +2 -0
- package/lib/typescript/e2ee/ns.d.ts.map +1 -0
- package/lib/typescript/e2ee/omemo.d.ts +64 -0
- package/lib/typescript/e2ee/omemo.d.ts.map +1 -0
- package/lib/typescript/e2ee/protobuf.d.ts +25 -0
- package/lib/typescript/e2ee/protobuf.d.ts.map +1 -0
- package/lib/typescript/e2ee/ratchet.d.ts +39 -0
- package/lib/typescript/e2ee/ratchet.d.ts.map +1 -0
- package/lib/typescript/e2ee/sealedBody.d.ts +2 -0
- package/lib/typescript/e2ee/sealedBody.d.ts.map +1 -0
- package/lib/typescript/e2ee/sealedFiles.d.ts +31 -0
- package/lib/typescript/e2ee/sealedFiles.d.ts.map +1 -0
- package/lib/typescript/e2ee/send.d.ts +6 -0
- package/lib/typescript/e2ee/send.d.ts.map +1 -0
- package/lib/typescript/e2ee/stanza.d.ts +8 -0
- package/lib/typescript/e2ee/stanza.d.ts.map +1 -0
- package/lib/typescript/e2ee/store.d.ts +16 -0
- package/lib/typescript/e2ee/store.d.ts.map +1 -0
- package/lib/typescript/helpers/accountName.d.ts +7 -0
- package/lib/typescript/helpers/accountName.d.ts.map +1 -0
- package/lib/typescript/helpers/createMessageFromXml.d.ts.map +1 -1
- package/lib/typescript/helpers/createUserNameFromSetUser.d.ts.map +1 -1
- package/lib/typescript/helpers/displayName.d.ts +2 -0
- package/lib/typescript/helpers/displayName.d.ts.map +1 -0
- package/lib/typescript/helpers/persistCrypto.d.ts +1 -0
- package/lib/typescript/helpers/persistCrypto.d.ts.map +1 -1
- package/lib/typescript/helpers/secureKeyValue.d.ts +4 -0
- package/lib/typescript/helpers/secureKeyValue.d.ts.map +1 -1
- package/lib/typescript/helpers/videoCache.d.ts +19 -0
- package/lib/typescript/helpers/videoCache.d.ts.map +1 -0
- package/lib/typescript/hooks/useLogout.d.ts.map +1 -1
- package/lib/typescript/hooks/useSendMessage.d.ts.map +1 -1
- package/lib/typescript/i18n/strings.d.ts.map +1 -1
- package/lib/typescript/main.d.ts +2 -0
- package/lib/typescript/main.d.ts.map +1 -1
- package/lib/typescript/networking/api-requests/auth.api.d.ts +4 -1
- package/lib/typescript/networking/api-requests/auth.api.d.ts.map +1 -1
- package/lib/typescript/networking/api-requests/rooms.api.d.ts +22 -1
- package/lib/typescript/networking/api-requests/rooms.api.d.ts.map +1 -1
- package/lib/typescript/networking/xmpp/handleStanzas.xmpp.d.ts +1 -0
- package/lib/typescript/networking/xmpp/handleStanzas.xmpp.d.ts.map +1 -1
- package/lib/typescript/networking/xmpp/sendMediaMessage.xmpp.d.ts.map +1 -1
- package/lib/typescript/networking/xmpp/sendTextMessage.xmpp.d.ts.map +1 -1
- package/lib/typescript/networking/xmpp/sendTextMessageWithTranslateTag.xmpp.d.ts.map +1 -1
- package/lib/typescript/networking/xmppClient.d.ts.map +1 -1
- package/lib/typescript/roomStore/persistBackend.d.ts.map +1 -1
- package/lib/typescript/roomStore/persistence.d.ts.map +1 -1
- package/lib/typescript/types/models/message.model.d.ts +5 -0
- package/lib/typescript/types/models/message.model.d.ts.map +1 -1
- package/lib/typescript/types/models/room.model.d.ts +5 -0
- package/lib/typescript/types/models/room.model.d.ts.map +1 -1
- package/lib/typescript/types/types.d.ts +4 -0
- package/lib/typescript/types/types.d.ts.map +1 -1
- package/lib/typescript/version.d.ts +1 -1
- package/package.json +8 -4
- package/src/assets/icons.tsx +27 -0
- package/src/components/MainComponents/ChatHeader.tsx +30 -9
- package/src/components/MainComponents/ChatRoom.tsx +11 -1
- package/src/components/MainComponents/EncryptedSendNotice.tsx +35 -0
- package/src/components/MainComponents/EncryptionCard.tsx +287 -0
- package/src/components/MainComponents/MediaMessage.tsx +5 -0
- package/src/components/MainComponents/ReduxWrapper.tsx +5 -0
- package/src/components/MainComponents/SealedAttachment.tsx +251 -0
- package/src/components/MessageBubble/BottomReplyContainer.tsx +2 -1
- package/src/components/MessageBubble/Message.tsx +96 -6
- package/src/components/MessageBubble/MessageInteractions.tsx +2 -3
- package/src/components/Modals/ChatProfileModal/ChatProfileModal.tsx +7 -4
- package/src/components/Modals/FilePreviewModal/FilePreviewModal.tsx +181 -35
- package/src/components/Modals/FilePreviewModal/PdfView.tsx +4 -0
- package/src/components/Modals/UserProfileModal/UserProfileModal.tsx +53 -8
- package/src/components/Modals/UserSettingsModal/UserSettingsModal.tsx +5 -0
- package/src/components/RoomComponents/ChatRoomItem.tsx +23 -11
- package/src/components/RoomComponents/LastMessageItem.tsx +5 -0
- package/src/components/RoomComponents/styled/LastAudioMessage.tsx +3 -1
- package/src/components/RoomComponents/styled/LastMessageFile.tsx +2 -2
- package/src/components/RoomComponents/styled/LastMessagePhoto.tsx +1 -1
- package/src/components/RoomComponents/styled/LastMessageSealed.tsx +31 -0
- package/src/components/RoomComponents/styled/LastMessageVideo.tsx +1 -1
- package/src/components/Thread/ThreadWrapper.tsx +13 -0
- package/src/components/UsersList/UsersList.tsx +2 -1
- package/src/components/styled/SendInput.tsx +5 -2
- package/src/e2ee/crypto.ts +194 -0
- package/src/e2ee/deviceStore.ts +80 -0
- package/src/e2ee/fileCipher.ts +86 -0
- package/src/e2ee/fileEnvelope.ts +115 -0
- package/src/e2ee/index.ts +192 -0
- package/src/e2ee/limits.ts +2 -0
- package/src/e2ee/ns.ts +1 -0
- package/src/e2ee/omemo.ts +802 -0
- package/src/e2ee/protobuf.ts +188 -0
- package/src/e2ee/ratchet.ts +271 -0
- package/src/e2ee/sealedBody.ts +17 -0
- package/src/e2ee/sealedFiles.ts +181 -0
- package/src/e2ee/send.ts +70 -0
- package/src/e2ee/stanza.ts +133 -0
- package/src/e2ee/store.ts +54 -0
- package/src/helpers/accountName.ts +15 -0
- package/src/helpers/createMessageFromXml.ts +31 -6
- package/src/helpers/createUserNameFromSetUser.ts +2 -1
- package/src/helpers/displayName.ts +9 -0
- package/src/helpers/persistCrypto.ts +5 -0
- package/src/helpers/secureKeyValue.ts +15 -0
- package/src/helpers/videoCache.ts +138 -0
- package/src/hooks/useLogout.tsx +9 -0
- package/src/hooks/useSendMessage.tsx +71 -5
- package/src/i18n/strings.ts +180 -0
- package/src/main.ts +2 -0
- package/src/networking/api-requests/auth.api.ts +9 -1
- package/src/networking/api-requests/rooms.api.ts +121 -18
- package/src/networking/xmpp/handleStanzas.xmpp.ts +49 -0
- package/src/networking/xmpp/sendMediaMessage.xmpp.ts +19 -1
- package/src/networking/xmpp/sendTextMessage.xmpp.ts +17 -10
- package/src/networking/xmpp/sendTextMessageWithTranslateTag.xmpp.ts +23 -10
- package/src/networking/xmppClient.ts +6 -0
- package/src/roomStore/persistBackend.ts +8 -11
- package/src/roomStore/persistence.ts +15 -0
- package/src/types/models/message.model.ts +5 -0
- package/src/types/models/room.model.ts +5 -0
- package/src/types/types.ts +4 -0
- package/src/version.ts +1 -1
|
@@ -5,6 +5,7 @@ import React, {
|
|
|
5
5
|
useMemo,
|
|
6
6
|
useEffect,
|
|
7
7
|
} from 'react';
|
|
8
|
+
import { composeName } from '../../helpers/displayName';
|
|
8
9
|
import { ModalTitle, LabelData } from '../Modals/styledModalComponents';
|
|
9
10
|
import {
|
|
10
11
|
ScrollableContainer,
|
|
@@ -101,7 +102,7 @@ const UsersList: React.FC<UsersListProps> = ({
|
|
|
101
102
|
disabled={selectedUsers.length === 20}
|
|
102
103
|
/>
|
|
103
104
|
<View>
|
|
104
|
-
<Label>{
|
|
105
|
+
<Label>{composeName(user.firstName, user.lastName)}</Label>
|
|
105
106
|
{/* <LabelData>{user.xmppUsername}</LabelData> */}
|
|
106
107
|
</View>
|
|
107
108
|
</UserItem>
|
|
@@ -87,12 +87,14 @@ interface SendInputProps {
|
|
|
87
87
|
inputHeight?: number;
|
|
88
88
|
showPreview?: boolean;
|
|
89
89
|
previewParser?: (text: string) => (string | JSX.Element)[];
|
|
90
|
+
maxMediaBytes?: number;
|
|
90
91
|
}
|
|
91
92
|
|
|
92
93
|
const SendInput: React.FC<SendInputProps> = ({
|
|
93
94
|
sendMessage,
|
|
94
95
|
sendMedia,
|
|
95
96
|
config,
|
|
97
|
+
maxMediaBytes,
|
|
96
98
|
onFocus,
|
|
97
99
|
onBlur,
|
|
98
100
|
editMessage,
|
|
@@ -151,14 +153,15 @@ const SendInput: React.FC<SendInputProps> = ({
|
|
|
151
153
|
// Enforce the upload size cap before anything reaches the network.
|
|
152
154
|
// The backend rejects oversized bodies with HTTP 413; catching it
|
|
153
155
|
// here gives a clear message instead of a silent failed bubble.
|
|
156
|
+
const limit = maxMediaBytes ?? MAX_MEDIA_BYTES;
|
|
154
157
|
const oversize = files.find(
|
|
155
|
-
(f) => typeof f.size === 'number' && f.size >
|
|
158
|
+
(f) => typeof f.size === 'number' && f.size > limit
|
|
156
159
|
);
|
|
157
160
|
if (oversize) {
|
|
158
161
|
Alert.alert(
|
|
159
162
|
'File too large',
|
|
160
163
|
`"${oversize.name}" is ${formatBytes(oversize.size!)}. The maximum allowed size is ${Math.round(
|
|
161
|
-
|
|
164
|
+
limit / (1024 * 1024)
|
|
162
165
|
)} MB.`
|
|
163
166
|
);
|
|
164
167
|
return;
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { cbc } from '@noble/ciphers/aes.js';
|
|
2
|
+
import { ed25519, x25519 } from '@noble/curves/ed25519.js';
|
|
3
|
+
import { hkdf } from '@noble/hashes/hkdf.js';
|
|
4
|
+
import { hmac } from '@noble/hashes/hmac.js';
|
|
5
|
+
import { sha256 } from '@noble/hashes/sha2.js';
|
|
6
|
+
import { concatBytes, randomBytes, utf8ToBytes } from '@noble/hashes/utils.js';
|
|
7
|
+
|
|
8
|
+
export { concatBytes, randomBytes, utf8ToBytes };
|
|
9
|
+
|
|
10
|
+
export interface KeyPair {
|
|
11
|
+
priv: Uint8Array;
|
|
12
|
+
pub: Uint8Array;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface IdentityKey {
|
|
16
|
+
seed: Uint8Array;
|
|
17
|
+
pub: Uint8Array;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const ZERO_SALT = new Uint8Array(32);
|
|
21
|
+
|
|
22
|
+
export function hkdfSha256(
|
|
23
|
+
ikm: Uint8Array,
|
|
24
|
+
salt: Uint8Array | undefined,
|
|
25
|
+
info: string,
|
|
26
|
+
length: number
|
|
27
|
+
): Uint8Array {
|
|
28
|
+
return hkdf(sha256, ikm, salt ?? ZERO_SALT, utf8ToBytes(info), length);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function hmacSha256(key: Uint8Array, data: Uint8Array): Uint8Array {
|
|
32
|
+
return hmac(sha256, key, data);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function aesEncrypt(
|
|
36
|
+
key: Uint8Array,
|
|
37
|
+
iv: Uint8Array,
|
|
38
|
+
data: Uint8Array
|
|
39
|
+
): Uint8Array {
|
|
40
|
+
return cbc(key, iv).encrypt(data);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function aesDecrypt(
|
|
44
|
+
key: Uint8Array,
|
|
45
|
+
iv: Uint8Array,
|
|
46
|
+
data: Uint8Array
|
|
47
|
+
): Uint8Array {
|
|
48
|
+
return cbc(key, iv).decrypt(data);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function generateKeyPair(): KeyPair {
|
|
52
|
+
const { secretKey, publicKey } = x25519.keygen();
|
|
53
|
+
return { priv: secretKey, pub: publicKey };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function generateIdentity(): IdentityKey {
|
|
57
|
+
const { secretKey, publicKey } = ed25519.keygen();
|
|
58
|
+
return { seed: secretKey, pub: publicKey };
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function dh(priv: Uint8Array, pub: Uint8Array): Uint8Array {
|
|
62
|
+
return x25519.getSharedSecret(priv, pub);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function identityDhPrivate(identity: IdentityKey): Uint8Array {
|
|
66
|
+
return ed25519.utils.toMontgomerySecret(identity.seed);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function identityDhPublic(identityPub: Uint8Array): Uint8Array {
|
|
70
|
+
return ed25519.utils.toMontgomery(identityPub);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function sign(identity: IdentityKey, message: Uint8Array): Uint8Array {
|
|
74
|
+
return ed25519.sign(message, identity.seed);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function verify(
|
|
78
|
+
signature: Uint8Array,
|
|
79
|
+
message: Uint8Array,
|
|
80
|
+
identityPub: Uint8Array
|
|
81
|
+
): boolean {
|
|
82
|
+
try {
|
|
83
|
+
return ed25519.verify(signature, message, identityPub);
|
|
84
|
+
} catch {
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export function bytesEqual(a: Uint8Array, b: Uint8Array): boolean {
|
|
90
|
+
if (a.length !== b.length) {return false;}
|
|
91
|
+
let diff = 0;
|
|
92
|
+
for (let i = 0; i < a.length; i++) {diff |= a[i]! ^ b[i]!;}
|
|
93
|
+
return diff === 0;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const B64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
|
97
|
+
const B64_VALUE = new Int16Array(128).fill(-1);
|
|
98
|
+
for (let i = 0; i < B64.length; i++) {B64_VALUE[B64.charCodeAt(i)] = i;}
|
|
99
|
+
|
|
100
|
+
export function toBase64(bytes: Uint8Array): string {
|
|
101
|
+
let out = '';
|
|
102
|
+
let i = 0;
|
|
103
|
+
for (; i + 2 < bytes.length; i += 3) {
|
|
104
|
+
const n = (bytes[i]! << 16) | (bytes[i + 1]! << 8) | bytes[i + 2]!;
|
|
105
|
+
out += B64[n >> 18]! + B64[(n >> 12) & 63]! + B64[(n >> 6) & 63]! + B64[n & 63]!;
|
|
106
|
+
}
|
|
107
|
+
if (i + 1 === bytes.length) {
|
|
108
|
+
const n = bytes[i]! << 16;
|
|
109
|
+
out += B64[n >> 18]! + B64[(n >> 12) & 63]! + '==';
|
|
110
|
+
} else if (i + 2 === bytes.length) {
|
|
111
|
+
const n = (bytes[i]! << 16) | (bytes[i + 1]! << 8);
|
|
112
|
+
out += B64[n >> 18]! + B64[(n >> 12) & 63]! + B64[(n >> 6) & 63]! + '=';
|
|
113
|
+
}
|
|
114
|
+
return out;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export function fromBase64(text: string): Uint8Array {
|
|
118
|
+
const clean = text.replace(/\s+/g, '').replace(/=+$/, '');
|
|
119
|
+
if (clean.length % 4 === 1) {throw new Error('Invalid base64');}
|
|
120
|
+
const out = new Uint8Array(Math.floor((clean.length * 3) / 4));
|
|
121
|
+
let acc = 0;
|
|
122
|
+
let bits = 0;
|
|
123
|
+
let pos = 0;
|
|
124
|
+
for (let i = 0; i < clean.length; i++) {
|
|
125
|
+
const code = clean.charCodeAt(i);
|
|
126
|
+
const value = code < 128 ? B64_VALUE[code]! : -1;
|
|
127
|
+
if (value < 0) {throw new Error('Invalid base64');}
|
|
128
|
+
acc = (acc << 6) | value;
|
|
129
|
+
bits += 6;
|
|
130
|
+
if (bits >= 8) {
|
|
131
|
+
bits -= 8;
|
|
132
|
+
out[pos++] = (acc >> bits) & 0xff;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return out;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export function toHex(bytes: Uint8Array): string {
|
|
139
|
+
return Array.from(bytes, (b) => b.toString(16).padStart(2, '0')).join('');
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export function randomInt(min: number, max: number): number {
|
|
143
|
+
const bytes = randomBytes(4);
|
|
144
|
+
const n = new DataView(bytes.buffer, bytes.byteOffset, 4).getUint32(0);
|
|
145
|
+
return min + (n % (max - min + 1));
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export function bytesToUtf8(bytes: Uint8Array): string {
|
|
149
|
+
const chunks: string[] = [];
|
|
150
|
+
let units: number[] = [];
|
|
151
|
+
const push = (unit: number) => {
|
|
152
|
+
units.push(unit);
|
|
153
|
+
if (units.length >= 8192) {
|
|
154
|
+
chunks.push(String.fromCharCode.apply(null, units));
|
|
155
|
+
units = [];
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
let i = 0;
|
|
160
|
+
while (i < bytes.length) {
|
|
161
|
+
const b = bytes[i++]!;
|
|
162
|
+
if (b < 0x80) {
|
|
163
|
+
push(b);
|
|
164
|
+
continue;
|
|
165
|
+
}
|
|
166
|
+
const extra = b >= 0xf0 && b < 0xf8 ? 3 : b >= 0xe0 ? 2 : b >= 0xc2 ? 1 : -1;
|
|
167
|
+
let code = extra === 3 ? b & 0x07 : extra === 2 ? b & 0x0f : b & 0x1f;
|
|
168
|
+
let valid = extra > 0 && b < 0xf8 && i + extra <= bytes.length;
|
|
169
|
+
for (let k = 0; valid && k < extra; k++) {
|
|
170
|
+
const next = bytes[i + k]!;
|
|
171
|
+
if ((next & 0xc0) !== 0x80) {valid = false;}
|
|
172
|
+
code = (code << 6) | (next & 0x3f);
|
|
173
|
+
}
|
|
174
|
+
if (
|
|
175
|
+
!valid ||
|
|
176
|
+
(extra === 2 && code < 0x800) ||
|
|
177
|
+
(extra === 3 && (code < 0x10000 || code > 0x10ffff)) ||
|
|
178
|
+
(code >= 0xd800 && code <= 0xdfff)
|
|
179
|
+
) {
|
|
180
|
+
push(0xfffd);
|
|
181
|
+
continue;
|
|
182
|
+
}
|
|
183
|
+
i += extra;
|
|
184
|
+
if (code > 0xffff) {
|
|
185
|
+
code -= 0x10000;
|
|
186
|
+
push(0xd800 | (code >> 10));
|
|
187
|
+
push(0xdc00 | (code & 0x3ff));
|
|
188
|
+
} else {
|
|
189
|
+
push(code);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
if (units.length) {chunks.push(String.fromCharCode.apply(null, units));}
|
|
193
|
+
return chunks.join('');
|
|
194
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
2
|
+
import { secureGetOrCreate } from '../helpers/secureKeyValue';
|
|
3
|
+
import {
|
|
4
|
+
decryptFromPersist,
|
|
5
|
+
encryptForPersist,
|
|
6
|
+
isPersistKeyKept,
|
|
7
|
+
} from '../helpers/persistCrypto';
|
|
8
|
+
import { randomBytes, toHex } from './crypto';
|
|
9
|
+
import { createStore, type OmemoStore, type StringBackend } from './store';
|
|
10
|
+
|
|
11
|
+
const MMKV_INSTANCE_ID = 'ethora-omemo';
|
|
12
|
+
const MMKV_KEY_STORE_KEY = 'ethora_omemo_store_key';
|
|
13
|
+
const ASYNC_STORAGE_PREFIX = '@ethora/omemo:';
|
|
14
|
+
|
|
15
|
+
const createMmkvBackend = async (): Promise<StringBackend | null> => {
|
|
16
|
+
let MMKV: any;
|
|
17
|
+
try {
|
|
18
|
+
MMKV = require('react-native-mmkv').MMKV;
|
|
19
|
+
} catch {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
if (typeof MMKV !== 'function') {return null;}
|
|
23
|
+
const key = await secureGetOrCreate(MMKV_KEY_STORE_KEY, () =>
|
|
24
|
+
toHex(randomBytes(8))
|
|
25
|
+
);
|
|
26
|
+
if (!key) {throw new Error('e2ee: the device store key was not kept');}
|
|
27
|
+
try {
|
|
28
|
+
const storage = new MMKV({ id: MMKV_INSTANCE_ID, encryptionKey: key.value });
|
|
29
|
+
if (key.created) {storage.clearAll();}
|
|
30
|
+
return {
|
|
31
|
+
getItem: async (key) => storage.getString(key) ?? null,
|
|
32
|
+
setItem: async (key, value) => void storage.set(key, value),
|
|
33
|
+
removeItem: async (key) => void storage.delete(key),
|
|
34
|
+
};
|
|
35
|
+
} catch (e) {
|
|
36
|
+
console.warn('[e2ee] react-native-mmkv present but unusable, falling back', e);
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const asyncStorageBackend: StringBackend = {
|
|
42
|
+
getItem: async (key) => {
|
|
43
|
+
const raw = await AsyncStorage.getItem(ASYNC_STORAGE_PREFIX + key);
|
|
44
|
+
return raw ? decryptFromPersist(raw) : null;
|
|
45
|
+
},
|
|
46
|
+
setItem: async (key, value) =>
|
|
47
|
+
AsyncStorage.setItem(ASYNC_STORAGE_PREFIX + key, await encryptForPersist(value)),
|
|
48
|
+
removeItem: (key) => AsyncStorage.removeItem(ASYNC_STORAGE_PREFIX + key),
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const createAsyncStorageBackend = async (): Promise<StringBackend> => {
|
|
52
|
+
if (!(await isPersistKeyKept())) {
|
|
53
|
+
throw new Error('e2ee: the storage cipher key was not kept');
|
|
54
|
+
}
|
|
55
|
+
return asyncStorageBackend;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
let backendPromise: Promise<StringBackend> | null = null;
|
|
59
|
+
|
|
60
|
+
const getBackend = (): Promise<StringBackend> => {
|
|
61
|
+
if (!backendPromise) {
|
|
62
|
+
const opening = createMmkvBackend().then(
|
|
63
|
+
(mmkv) => mmkv ?? createAsyncStorageBackend()
|
|
64
|
+
);
|
|
65
|
+
backendPromise = opening;
|
|
66
|
+
// A refusal is not cached: the next start may find the store usable.
|
|
67
|
+
opening.catch(() => {
|
|
68
|
+
if (backendPromise === opening) {backendPromise = null;}
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
return backendPromise;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
export async function openDeviceStore(jid: string): Promise<OmemoStore> {
|
|
75
|
+
return createStore(await getBackend(), jid);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export const __resetDeviceStoreForTests = (): void => {
|
|
79
|
+
backendPromise = null;
|
|
80
|
+
};
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { cbc } from '@noble/ciphers/aes.js';
|
|
2
|
+
import { hmac } from '@noble/hashes/hmac.js';
|
|
3
|
+
import { sha256 } from '@noble/hashes/sha2.js';
|
|
4
|
+
import { bytesEqual, concatBytes, hkdfSha256, randomBytes } from './crypto';
|
|
5
|
+
|
|
6
|
+
const SLICE = 32 * 1024;
|
|
7
|
+
const BLOCK = 16;
|
|
8
|
+
|
|
9
|
+
export type Progress = (fraction: number) => void;
|
|
10
|
+
|
|
11
|
+
const yieldToUi = () => new Promise<void>((resolve) => setTimeout(resolve, 0));
|
|
12
|
+
|
|
13
|
+
function payloadKeys(key: Uint8Array) {
|
|
14
|
+
const km = hkdfSha256(key, undefined, 'OMEMO Payload', 80);
|
|
15
|
+
return { enc: km.slice(0, 32), auth: km.slice(32, 64), iv: km.slice(64) };
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export async function encryptLargePayload(
|
|
19
|
+
plaintext: Uint8Array,
|
|
20
|
+
onProgress?: Progress
|
|
21
|
+
): Promise<{ keyMaterial: Uint8Array; payload: Uint8Array }> {
|
|
22
|
+
const key = randomBytes(32);
|
|
23
|
+
const { enc, auth, iv } = payloadKeys(key);
|
|
24
|
+
const payload = new Uint8Array((Math.floor(plaintext.length / BLOCK) + 1) * BLOCK);
|
|
25
|
+
const mac = hmac.create(sha256, auth);
|
|
26
|
+
|
|
27
|
+
let offset = 0;
|
|
28
|
+
let chain = iv;
|
|
29
|
+
while (plaintext.length - offset > SLICE) {
|
|
30
|
+
const out = payload.subarray(offset, offset + SLICE);
|
|
31
|
+
out.set(
|
|
32
|
+
cbc(enc, chain, { disablePadding: true }).encrypt(
|
|
33
|
+
plaintext.subarray(offset, offset + SLICE)
|
|
34
|
+
)
|
|
35
|
+
);
|
|
36
|
+
mac.update(out);
|
|
37
|
+
chain = out.slice(SLICE - BLOCK);
|
|
38
|
+
offset += SLICE;
|
|
39
|
+
onProgress?.(offset / plaintext.length);
|
|
40
|
+
await yieldToUi();
|
|
41
|
+
}
|
|
42
|
+
const last = cbc(enc, chain).encrypt(plaintext.subarray(offset));
|
|
43
|
+
payload.set(last, offset);
|
|
44
|
+
mac.update(last);
|
|
45
|
+
onProgress?.(1);
|
|
46
|
+
|
|
47
|
+
return { keyMaterial: concatBytes(key, mac.digest().slice(0, 16)), payload };
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export async function decryptLargePayload(
|
|
51
|
+
keyMaterial: Uint8Array,
|
|
52
|
+
payload: Uint8Array,
|
|
53
|
+
onProgress?: Progress
|
|
54
|
+
): Promise<Uint8Array> {
|
|
55
|
+
if (keyMaterial.length !== 48) {throw new Error('Invalid key material');}
|
|
56
|
+
if (payload.length === 0 || payload.length % BLOCK !== 0) {
|
|
57
|
+
throw new Error('Payload authentication failed');
|
|
58
|
+
}
|
|
59
|
+
const { enc, auth, iv } = payloadKeys(keyMaterial.slice(0, 32));
|
|
60
|
+
|
|
61
|
+
const mac = hmac.create(sha256, auth);
|
|
62
|
+
for (let offset = 0; offset < payload.length; offset += SLICE) {
|
|
63
|
+
mac.update(payload.subarray(offset, offset + SLICE));
|
|
64
|
+
onProgress?.((Math.min(offset + SLICE, payload.length) / payload.length) * 0.65);
|
|
65
|
+
if (offset + SLICE < payload.length) {await yieldToUi();}
|
|
66
|
+
}
|
|
67
|
+
if (!bytesEqual(mac.digest().slice(0, 16), keyMaterial.slice(32))) {
|
|
68
|
+
throw new Error('Payload authentication failed');
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const plaintext = new Uint8Array(payload.length);
|
|
72
|
+
let offset = 0;
|
|
73
|
+
let chain = iv;
|
|
74
|
+
while (payload.length - offset > SLICE) {
|
|
75
|
+
const part = payload.subarray(offset, offset + SLICE);
|
|
76
|
+
plaintext.set(cbc(enc, chain, { disablePadding: true }).decrypt(part), offset);
|
|
77
|
+
chain = part.slice(SLICE - BLOCK);
|
|
78
|
+
offset += SLICE;
|
|
79
|
+
onProgress?.(0.65 + (offset / payload.length) * 0.35);
|
|
80
|
+
await yieldToUi();
|
|
81
|
+
}
|
|
82
|
+
const last = cbc(enc, chain).decrypt(payload.subarray(offset));
|
|
83
|
+
plaintext.set(last, offset);
|
|
84
|
+
onProgress?.(1);
|
|
85
|
+
return plaintext.subarray(0, offset + last.length);
|
|
86
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import {
|
|
2
|
+
bytesToUtf8,
|
|
3
|
+
fromBase64,
|
|
4
|
+
randomBytes,
|
|
5
|
+
toBase64,
|
|
6
|
+
toHex,
|
|
7
|
+
utf8ToBytes,
|
|
8
|
+
} from './crypto';
|
|
9
|
+
import {
|
|
10
|
+
decryptLargePayload,
|
|
11
|
+
encryptLargePayload,
|
|
12
|
+
type Progress,
|
|
13
|
+
} from './fileCipher';
|
|
14
|
+
|
|
15
|
+
export { parseSealedMediaBody } from './sealedBody';
|
|
16
|
+
|
|
17
|
+
const MAGIC = Uint8Array.from([0x45, 0x54, 0x48, 0x4f, 0x46, 0x49, 0x4c, 0x45]);
|
|
18
|
+
const VERSION = 1;
|
|
19
|
+
const HEADER_OFFSET = MAGIC.length + 1 + 4;
|
|
20
|
+
|
|
21
|
+
export interface FileEnvelopeMeta {
|
|
22
|
+
mimetype: string;
|
|
23
|
+
originalname: string;
|
|
24
|
+
size: number;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface SealedFile {
|
|
28
|
+
ciphertext: Uint8Array;
|
|
29
|
+
keyMaterial: string;
|
|
30
|
+
filename: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function encodeFileEnvelope(
|
|
34
|
+
meta: FileEnvelopeMeta,
|
|
35
|
+
bytes: Uint8Array
|
|
36
|
+
): Uint8Array {
|
|
37
|
+
const header = utf8ToBytes(
|
|
38
|
+
JSON.stringify({
|
|
39
|
+
mimetype: meta.mimetype,
|
|
40
|
+
originalname: meta.originalname,
|
|
41
|
+
size: meta.size,
|
|
42
|
+
})
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
const out = new Uint8Array(HEADER_OFFSET + header.length + bytes.length);
|
|
46
|
+
out.set(MAGIC, 0);
|
|
47
|
+
out[MAGIC.length] = VERSION;
|
|
48
|
+
new DataView(out.buffer).setUint32(MAGIC.length + 1, header.length, false);
|
|
49
|
+
out.set(header, HEADER_OFFSET);
|
|
50
|
+
out.set(bytes, HEADER_OFFSET + header.length);
|
|
51
|
+
return out;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function decodeFileEnvelope(envelope: Uint8Array): {
|
|
55
|
+
meta: FileEnvelopeMeta;
|
|
56
|
+
bytes: Uint8Array;
|
|
57
|
+
} {
|
|
58
|
+
if (envelope.length < HEADER_OFFSET) {
|
|
59
|
+
throw new Error('file_envelope_truncated');
|
|
60
|
+
}
|
|
61
|
+
for (let i = 0; i < MAGIC.length; i++) {
|
|
62
|
+
if (envelope[i] !== MAGIC[i]) {throw new Error('file_envelope_bad_magic');}
|
|
63
|
+
}
|
|
64
|
+
const version = envelope[MAGIC.length];
|
|
65
|
+
if (version !== VERSION) {
|
|
66
|
+
throw new Error(`file_envelope_unsupported_version_${version}`);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const headerLen = new DataView(
|
|
70
|
+
envelope.buffer,
|
|
71
|
+
envelope.byteOffset,
|
|
72
|
+
envelope.byteLength
|
|
73
|
+
).getUint32(MAGIC.length + 1, false);
|
|
74
|
+
|
|
75
|
+
const bodyStart = HEADER_OFFSET + headerLen;
|
|
76
|
+
if (bodyStart > envelope.length) {throw new Error('file_envelope_truncated');}
|
|
77
|
+
|
|
78
|
+
const meta = JSON.parse(
|
|
79
|
+
bytesToUtf8(envelope.subarray(HEADER_OFFSET, bodyStart))
|
|
80
|
+
) as FileEnvelopeMeta;
|
|
81
|
+
|
|
82
|
+
return { meta, bytes: envelope.subarray(bodyStart) };
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export async function sealFileForUpload(
|
|
86
|
+
file: { bytes: Uint8Array; name?: string; type?: string },
|
|
87
|
+
onProgress?: Progress
|
|
88
|
+
): Promise<SealedFile> {
|
|
89
|
+
const envelope = encodeFileEnvelope(
|
|
90
|
+
{
|
|
91
|
+
mimetype: file.type || 'application/octet-stream',
|
|
92
|
+
originalname: file.name || 'blob',
|
|
93
|
+
size: file.bytes.length,
|
|
94
|
+
},
|
|
95
|
+
file.bytes
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
const { keyMaterial, payload } = await encryptLargePayload(envelope, onProgress);
|
|
99
|
+
|
|
100
|
+
return {
|
|
101
|
+
ciphertext: payload,
|
|
102
|
+
keyMaterial: toBase64(keyMaterial),
|
|
103
|
+
filename: toHex(randomBytes(16)),
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export async function openSealedFile(
|
|
108
|
+
ciphertext: Uint8Array,
|
|
109
|
+
keyMaterial: string,
|
|
110
|
+
onProgress?: Progress
|
|
111
|
+
): Promise<{ meta: FileEnvelopeMeta; bytes: Uint8Array }> {
|
|
112
|
+
return decodeFileEnvelope(
|
|
113
|
+
await decryptLargePayload(fromBase64(keyMaterial), ciphertext, onProgress)
|
|
114
|
+
);
|
|
115
|
+
}
|