@neelegirl/baileys 1.5.2 → 1.5.4
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/README.md +26 -18
- package/WAProto/GenerateStatics.sh +3 -0
- package/WAProto/WAProto.proto +291 -665
- package/WAProto/fix-imports.js +29 -0
- package/WAProto/index.d.ts +2297 -48040
- package/WAProto/index.js +45500 -140101
- package/engine-requirements.js +10 -0
- package/lib/Defaults/index.d.ts +58 -64
- package/lib/Defaults/index.d.ts.map +1 -0
- package/lib/Defaults/index.js +74 -96
- package/lib/Defaults/index.js.map +1 -0
- package/lib/Signal/Group/ciphertext-message.d.ts +10 -0
- package/lib/Signal/Group/ciphertext-message.d.ts.map +1 -0
- package/lib/Signal/Group/ciphertext-message.js +12 -0
- package/lib/Signal/Group/ciphertext-message.js.map +1 -0
- package/lib/Signal/Group/group-session-builder.d.ts +15 -0
- package/lib/Signal/Group/group-session-builder.d.ts.map +1 -0
- package/lib/Signal/Group/group-session-builder.js +30 -0
- package/lib/Signal/Group/group-session-builder.js.map +1 -0
- package/lib/Signal/Group/group_cipher.d.ts +17 -0
- package/lib/Signal/Group/group_cipher.d.ts.map +1 -0
- package/lib/Signal/Group/group_cipher.js +82 -0
- package/lib/Signal/Group/group_cipher.js.map +1 -0
- package/lib/Signal/Group/index.d.ts +12 -0
- package/lib/Signal/Group/index.d.ts.map +1 -0
- package/lib/Signal/Group/index.js +12 -0
- package/lib/Signal/Group/index.js.map +1 -0
- package/lib/Signal/Group/keyhelper.d.ts +11 -0
- package/lib/Signal/Group/keyhelper.d.ts.map +1 -0
- package/lib/Signal/Group/keyhelper.js +18 -0
- package/lib/Signal/Group/keyhelper.js.map +1 -0
- package/lib/Signal/Group/sender-chain-key.d.ts +14 -0
- package/lib/Signal/Group/sender-chain-key.d.ts.map +1 -0
- package/lib/Signal/Group/sender-chain-key.js +26 -0
- package/lib/Signal/Group/sender-chain-key.js.map +1 -0
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +17 -0
- package/lib/Signal/Group/sender-key-distribution-message.d.ts.map +1 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +63 -0
- package/lib/Signal/Group/sender-key-distribution-message.js.map +1 -0
- package/lib/Signal/Group/sender-key-message.d.ts +19 -0
- package/lib/Signal/Group/sender-key-message.d.ts.map +1 -0
- package/lib/Signal/Group/sender-key-message.js +66 -0
- package/lib/Signal/Group/sender-key-message.js.map +1 -0
- package/lib/Signal/Group/sender-key-name.d.ts +18 -0
- package/lib/Signal/Group/sender-key-name.d.ts.map +1 -0
- package/lib/Signal/Group/sender-key-name.js +48 -0
- package/lib/Signal/Group/sender-key-name.js.map +1 -0
- package/lib/Signal/Group/sender-key-record.d.ts +31 -0
- package/lib/Signal/Group/sender-key-record.d.ts.map +1 -0
- package/lib/Signal/Group/sender-key-record.js +41 -0
- package/lib/Signal/Group/sender-key-record.js.map +1 -0
- package/lib/Signal/Group/sender-key-state.d.ts +39 -0
- package/lib/Signal/Group/sender-key-state.d.ts.map +1 -0
- package/lib/Signal/Group/sender-key-state.js +84 -0
- package/lib/Signal/Group/sender-key-state.js.map +1 -0
- package/lib/Signal/Group/sender-message-key.d.ts +12 -0
- package/lib/Signal/Group/sender-message-key.d.ts.map +1 -0
- package/lib/Signal/{WASignalGroup/sender_message_key.js → Group/sender-message-key.js} +3 -16
- package/lib/Signal/Group/sender-message-key.js.map +1 -0
- package/lib/Signal/libsignal.d.ts +5 -4
- package/lib/Signal/libsignal.d.ts.map +1 -0
- package/lib/Signal/libsignal.js +292 -112
- package/lib/Signal/libsignal.js.map +1 -0
- package/lib/Signal/lid-mapping.d.ts +23 -0
- package/lib/Signal/lid-mapping.d.ts.map +1 -0
- package/lib/Signal/lid-mapping.js +171 -0
- package/lib/Signal/lid-mapping.js.map +1 -0
- package/lib/Socket/Client/index.d.ts +3 -2
- package/lib/Socket/Client/index.d.ts.map +1 -0
- package/lib/Socket/Client/index.js +3 -22
- package/lib/Socket/Client/index.js.map +1 -0
- package/lib/Socket/Client/types.d.ts +15 -15
- package/lib/Socket/Client/types.d.ts.map +1 -0
- package/lib/Socket/Client/types.js +8 -15
- package/lib/Socket/Client/types.js.map +1 -0
- package/lib/Socket/Client/websocket.d.ts +12 -12
- package/lib/Socket/Client/websocket.d.ts.map +1 -0
- package/lib/Socket/Client/websocket.js +24 -36
- package/lib/Socket/Client/websocket.js.map +1 -0
- package/lib/Socket/business.d.ts +178 -177
- package/lib/Socket/business.d.ts.map +1 -0
- package/lib/Socket/business.js +179 -71
- package/lib/Socket/business.js.map +1 -0
- package/lib/Socket/chats.d.ts +93 -93
- package/lib/Socket/chats.d.ts.map +1 -0
- package/lib/Socket/chats.js +474 -625
- package/lib/Socket/chats.js.map +1 -0
- package/lib/Socket/communities.d.ts +83 -62
- package/lib/Socket/communities.d.ts.map +1 -0
- package/lib/Socket/communities.js +412 -414
- package/lib/Socket/communities.js.map +1 -0
- package/lib/Socket/groups.d.ts +118 -112
- package/lib/Socket/groups.d.ts.map +1 -0
- package/lib/Socket/groups.js +146 -171
- package/lib/Socket/groups.js.map +1 -0
- package/lib/Socket/index.d.ts +222 -182
- package/lib/Socket/index.d.ts.map +1 -0
- package/lib/Socket/index.js +12 -17
- package/lib/Socket/index.js.map +1 -0
- package/lib/Socket/messages-recv.d.ts +165 -169
- package/lib/Socket/messages-recv.d.ts.map +1 -0
- package/lib/Socket/messages-recv.js +1185 -1721
- package/lib/Socket/messages-recv.js.map +1 -0
- package/lib/Socket/messages-send.d.ts +161 -159
- package/lib/Socket/messages-send.d.ts.map +1 -0
- package/lib/Socket/messages-send.js +650 -991
- package/lib/Socket/messages-send.js.map +1 -0
- package/lib/Socket/mex.d.ts +1 -0
- package/lib/Socket/mex.d.ts.map +1 -0
- package/lib/Socket/mex.js +4 -9
- package/lib/Socket/mex.js.map +1 -0
- package/lib/Socket/newsletter.d.ts +139 -139
- package/lib/Socket/newsletter.d.ts.map +1 -0
- package/lib/Socket/newsletter.js +153 -258
- package/lib/Socket/newsletter.js.map +1 -0
- package/lib/Socket/socket.d.ts +42 -36
- package/lib/Socket/socket.d.ts.map +1 -0
- package/lib/Socket/socket.js +623 -507
- package/lib/Socket/socket.js.map +1 -0
- package/lib/Types/Auth.d.ts +87 -96
- package/lib/Types/Auth.d.ts.map +1 -0
- package/lib/Types/Auth.js +2 -3
- package/lib/Types/Auth.js.map +1 -0
- package/lib/Types/Bussines.d.ts +25 -0
- package/lib/Types/Bussines.d.ts.map +1 -0
- package/lib/Types/Bussines.js +2 -0
- package/lib/Types/Bussines.js.map +1 -0
- package/lib/Types/Call.d.ts +13 -13
- package/lib/Types/Call.d.ts.map +1 -0
- package/lib/Types/Call.js +2 -3
- package/lib/Types/Call.js.map +1 -0
- package/lib/Types/Chat.d.ts +79 -94
- package/lib/Types/Chat.d.ts.map +1 -0
- package/lib/Types/Chat.js +8 -9
- package/lib/Types/Chat.js.map +1 -0
- package/lib/Types/Contact.d.ts +13 -9
- package/lib/Types/Contact.d.ts.map +1 -0
- package/lib/Types/Contact.js +2 -3
- package/lib/Types/Contact.js.map +1 -0
- package/lib/Types/Events.d.ts +152 -179
- package/lib/Types/Events.d.ts.map +1 -0
- package/lib/Types/Events.js +2 -3
- package/lib/Types/Events.js.map +1 -0
- package/lib/Types/GroupMetadata.d.ts +49 -48
- package/lib/Types/GroupMetadata.d.ts.map +1 -0
- package/lib/Types/GroupMetadata.js +2 -3
- package/lib/Types/GroupMetadata.js.map +1 -0
- package/lib/Types/Label.d.ts +13 -14
- package/lib/Types/Label.d.ts.map +1 -0
- package/lib/Types/Label.js +24 -30
- package/lib/Types/Label.js.map +1 -0
- package/lib/Types/LabelAssociation.d.ts +15 -20
- package/lib/Types/LabelAssociation.d.ts.map +1 -0
- package/lib/Types/LabelAssociation.js +6 -12
- package/lib/Types/LabelAssociation.js.map +1 -0
- package/lib/Types/Message.d.ts +234 -404
- package/lib/Types/Message.d.ts.map +1 -0
- package/lib/Types/Message.js +11 -13
- package/lib/Types/Message.js.map +1 -0
- package/lib/Types/Newsletter.d.ts +130 -104
- package/lib/Types/Newsletter.d.ts.map +1 -0
- package/lib/Types/Newsletter.js +31 -40
- package/lib/Types/Newsletter.js.map +1 -0
- package/lib/Types/Product.d.ts +58 -71
- package/lib/Types/Product.d.ts.map +1 -0
- package/lib/Types/Product.js +2 -3
- package/lib/Types/Product.js.map +1 -0
- package/lib/Types/Signal.d.ts +63 -55
- package/lib/Types/Signal.d.ts.map +1 -0
- package/lib/Types/Signal.js +2 -3
- package/lib/Types/Signal.js.map +1 -0
- package/lib/Types/Socket.d.ts +78 -65
- package/lib/Types/Socket.d.ts.map +1 -0
- package/lib/Types/Socket.js +3 -3
- package/lib/Types/Socket.js.map +1 -0
- package/lib/Types/State.d.ts +17 -19
- package/lib/Types/State.d.ts.map +1 -0
- package/lib/Types/State.js +13 -14
- package/lib/Types/State.js.map +1 -0
- package/lib/Types/USync.d.ts +8 -8
- package/lib/Types/USync.d.ts.map +1 -0
- package/lib/Types/USync.js +2 -3
- package/lib/Types/USync.js.map +1 -0
- package/lib/Types/index.d.ts +47 -61
- package/lib/Types/index.d.ts.map +1 -0
- package/lib/Types/index.js +26 -48
- package/lib/Types/index.js.map +1 -0
- package/lib/Utils/auth-utils.d.ts +8 -10
- package/lib/Utils/auth-utils.d.ts.map +1 -0
- package/lib/Utils/auth-utils.js +206 -154
- package/lib/Utils/auth-utils.js.map +1 -0
- package/lib/Utils/baileys-event-stream.d.ts +6 -7
- package/lib/Utils/baileys-event-stream.d.ts.map +1 -0
- package/lib/Utils/baileys-event-stream.js +29 -43
- package/lib/Utils/baileys-event-stream.js.map +1 -0
- package/lib/Utils/browser-utils.d.ts +4 -0
- package/lib/Utils/browser-utils.d.ts.map +1 -0
- package/lib/Utils/browser-utils.js +28 -0
- package/lib/Utils/browser-utils.js.map +1 -0
- package/lib/Utils/business.d.ts +14 -20
- package/lib/Utils/business.d.ts.map +1 -0
- package/lib/Utils/business.js +110 -134
- package/lib/Utils/business.js.map +1 -0
- package/lib/Utils/chat-utils.d.ts +57 -69
- package/lib/Utils/chat-utils.d.ts.map +1 -0
- package/lib/Utils/chat-utils.js +362 -380
- package/lib/Utils/chat-utils.js.map +1 -0
- package/lib/Utils/crypto.d.ts +30 -45
- package/lib/Utils/crypto.d.ts.map +1 -0
- package/lib/Utils/crypto.js +141 -178
- package/lib/Utils/crypto.js.map +1 -0
- package/lib/Utils/decode-wa-message.d.ts +42 -35
- package/lib/Utils/decode-wa-message.d.ts.map +1 -0
- package/lib/Utils/decode-wa-message.js +176 -150
- package/lib/Utils/decode-wa-message.js.map +1 -0
- package/lib/Utils/event-buffer.d.ts +12 -17
- package/lib/Utils/event-buffer.d.ts.map +1 -0
- package/lib/Utils/event-buffer.js +269 -286
- package/lib/Utils/event-buffer.js.map +1 -0
- package/lib/Utils/generics.d.ts +60 -99
- package/lib/Utils/generics.d.ts.map +1 -0
- package/lib/Utils/generics.js +244 -487
- package/lib/Utils/generics.js.map +1 -0
- package/lib/Utils/history.d.ts +18 -22
- package/lib/Utils/history.d.ts.map +1 -0
- package/lib/Utils/history.js +54 -80
- package/lib/Utils/history.js.map +1 -0
- package/lib/Utils/index.d.ts +20 -19
- package/lib/Utils/index.d.ts.map +1 -0
- package/lib/Utils/index.js +19 -39
- package/lib/Utils/index.js.map +1 -0
- package/lib/Utils/link-preview.d.ts +12 -14
- package/lib/Utils/link-preview.d.ts.map +1 -0
- package/lib/Utils/link-preview.js +40 -75
- package/lib/Utils/link-preview.js.map +1 -0
- package/lib/Utils/logger.d.ts +10 -11
- package/lib/Utils/logger.d.ts.map +1 -0
- package/lib/Utils/logger.js +3 -7
- package/lib/Utils/logger.js.map +1 -0
- package/lib/Utils/lt-hash.d.ts +12 -13
- package/lib/Utils/lt-hash.d.ts.map +1 -0
- package/lib/Utils/lt-hash.js +27 -37
- package/lib/Utils/lt-hash.js.map +1 -0
- package/lib/Utils/make-mutex.d.ts +6 -7
- package/lib/Utils/make-mutex.d.ts.map +1 -0
- package/lib/Utils/make-mutex.js +20 -29
- package/lib/Utils/make-mutex.js.map +1 -0
- package/lib/Utils/message-retry-manager.d.ts +82 -0
- package/lib/Utils/message-retry-manager.d.ts.map +1 -0
- package/lib/Utils/message-retry-manager.js +149 -0
- package/lib/Utils/message-retry-manager.js.map +1 -0
- package/lib/Utils/messages-media.d.ts +87 -102
- package/lib/Utils/messages-media.d.ts.map +1 -0
- package/lib/Utils/messages-media.js +427 -570
- package/lib/Utils/messages-media.js.map +1 -0
- package/lib/Utils/messages.d.ts +37 -64
- package/lib/Utils/messages.d.ts.map +1 -0
- package/lib/Utils/messages.js +511 -1270
- package/lib/Utils/messages.js.map +1 -0
- package/lib/Utils/noise-handler.d.ts +18 -18
- package/lib/Utils/noise-handler.d.ts.map +1 -0
- package/lib/Utils/noise-handler.js +101 -109
- package/lib/Utils/noise-handler.js.map +1 -0
- package/lib/Utils/pre-key-manager.d.ts +28 -0
- package/lib/Utils/pre-key-manager.d.ts.map +1 -0
- package/lib/Utils/pre-key-manager.js +106 -0
- package/lib/Utils/pre-key-manager.js.map +1 -0
- package/lib/Utils/process-message.d.ts +25 -32
- package/lib/Utils/process-message.d.ts.map +1 -0
- package/lib/Utils/process-message.js +266 -281
- package/lib/Utils/process-message.js.map +1 -0
- package/lib/Utils/signal.d.ts +24 -32
- package/lib/Utils/signal.d.ts.map +1 -0
- package/lib/Utils/signal.js +98 -105
- package/lib/Utils/signal.js.map +1 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +5 -10
- package/lib/Utils/use-multi-file-auth-state.d.ts.map +1 -0
- package/lib/Utils/use-multi-file-auth-state.js +69 -186
- package/lib/Utils/use-multi-file-auth-state.js.map +1 -0
- package/lib/Utils/validate-connection.d.ts +11 -13
- package/lib/Utils/validate-connection.d.ts.map +1 -0
- package/lib/Utils/validate-connection.js +124 -116
- package/lib/Utils/validate-connection.js.map +1 -0
- package/lib/WABinary/constants.d.ts +25 -27
- package/lib/WABinary/constants.d.ts.map +1 -0
- package/lib/WABinary/constants.js +1277 -1292
- package/lib/WABinary/constants.js.map +1 -0
- package/lib/WABinary/decode.d.ts +7 -9
- package/lib/WABinary/decode.d.ts.map +1 -0
- package/lib/WABinary/decode.js +139 -189
- package/lib/WABinary/decode.js.map +1 -0
- package/lib/WABinary/encode.d.ts +3 -3
- package/lib/WABinary/encode.d.ts.map +1 -0
- package/lib/WABinary/encode.js +105 -154
- package/lib/WABinary/encode.js.map +1 -0
- package/lib/WABinary/generic-utils.d.ts +14 -27
- package/lib/WABinary/generic-utils.d.ts.map +1 -0
- package/lib/WABinary/generic-utils.js +62 -102
- package/lib/WABinary/generic-utils.js.map +1 -0
- package/lib/WABinary/index.d.ts +6 -5
- package/lib/WABinary/index.d.ts.map +1 -0
- package/lib/WABinary/index.js +6 -25
- package/lib/WABinary/index.js.map +1 -0
- package/lib/WABinary/jid-utils.d.ts +41 -46
- package/lib/WABinary/jid-utils.d.ts.map +1 -0
- package/lib/WABinary/jid-utils.js +84 -80
- package/lib/WABinary/jid-utils.js.map +1 -0
- package/lib/WABinary/types.d.ts +10 -13
- package/lib/WABinary/types.d.ts.map +1 -0
- package/lib/WABinary/types.js +2 -3
- package/lib/WABinary/types.js.map +1 -0
- package/lib/WAM/BinaryInfo.d.ts +8 -15
- package/lib/WAM/BinaryInfo.d.ts.map +1 -0
- package/lib/WAM/BinaryInfo.js +7 -14
- package/lib/WAM/BinaryInfo.js.map +1 -0
- package/lib/WAM/constants.d.ts +30 -37
- package/lib/WAM/constants.d.ts.map +1 -0
- package/lib/WAM/constants.js +19193 -11711
- package/lib/WAM/constants.js.map +1 -0
- package/lib/WAM/encode.d.ts +3 -3
- package/lib/WAM/encode.d.ts.map +1 -0
- package/lib/WAM/encode.js +95 -110
- package/lib/WAM/encode.js.map +1 -0
- package/lib/WAM/index.d.ts +4 -3
- package/lib/WAM/index.d.ts.map +1 -0
- package/lib/WAM/index.js +4 -23
- package/lib/WAM/index.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +9 -9
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +12 -19
- package/lib/WAUSync/Protocols/USyncContactProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +19 -22
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +18 -26
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +11 -12
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +12 -20
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +11 -12
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +16 -24
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +26 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +51 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +10 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +29 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/index.d.ts +5 -6
- package/lib/WAUSync/Protocols/index.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/index.js +5 -26
- package/lib/WAUSync/Protocols/index.js.map +1 -0
- package/lib/WAUSync/USyncQuery.d.ts +26 -28
- package/lib/WAUSync/USyncQuery.d.ts.map +1 -0
- package/lib/WAUSync/USyncQuery.js +64 -62
- package/lib/WAUSync/USyncQuery.js.map +1 -0
- package/lib/WAUSync/USyncUser.d.ts +11 -10
- package/lib/WAUSync/USyncUser.d.ts.map +1 -0
- package/lib/WAUSync/USyncUser.js +12 -19
- package/lib/WAUSync/USyncUser.js.map +1 -0
- package/lib/WAUSync/index.d.ts +4 -3
- package/lib/WAUSync/index.d.ts.map +1 -0
- package/lib/WAUSync/index.js +4 -23
- package/lib/WAUSync/index.js.map +1 -0
- package/lib/index.d.ts +10 -11
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +11 -33
- package/lib/index.js.map +1 -0
- package/package.json +48 -43
- package/lib/Defaults/baileys-version.json +0 -3
- package/lib/Defaults/phonenumber-mcc.json +0 -223
- package/lib/Signal/WASignalGroup/GroupProtocol.js +0 -1909
- package/lib/Signal/WASignalGroup/ciphertext_message.js +0 -16
- package/lib/Signal/WASignalGroup/generate-proto.sh +0 -1
- package/lib/Signal/WASignalGroup/group.proto +0 -42
- package/lib/Signal/WASignalGroup/group_cipher.js +0 -120
- package/lib/Signal/WASignalGroup/group_session_builder.js +0 -46
- package/lib/Signal/WASignalGroup/index.js +0 -6
- package/lib/Signal/WASignalGroup/keyhelper.js +0 -21
- package/lib/Signal/WASignalGroup/protobufs.js +0 -3
- package/lib/Signal/WASignalGroup/queue_job.js +0 -69
- package/lib/Signal/WASignalGroup/readme.md +0 -6
- package/lib/Signal/WASignalGroup/sender_chain_key.js +0 -50
- package/lib/Signal/WASignalGroup/sender_key_distribution_message.js +0 -78
- package/lib/Signal/WASignalGroup/sender_key_message.js +0 -92
- package/lib/Signal/WASignalGroup/sender_key_name.js +0 -70
- package/lib/Signal/WASignalGroup/sender_key_record.js +0 -56
- package/lib/Signal/WASignalGroup/sender_key_state.js +0 -129
- package/lib/Socket/Client/abstract-socket-client.d.ts +0 -15
- package/lib/Socket/Client/abstract-socket-client.js +0 -13
- package/lib/Socket/Client/mobile-socket-client.d.ts +0 -12
- package/lib/Socket/Client/mobile-socket-client.js +0 -65
- package/lib/Socket/registration.d.ts +0 -266
- package/lib/Socket/registration.js +0 -166
- package/lib/Socket/usync.d.ts +0 -37
- package/lib/Socket/usync.js +0 -83
- package/lib/Store/index.d.ts +0 -4
- package/lib/Store/index.js +0 -24
- package/lib/Store/make-cache-manager-store.d.ts +0 -14
- package/lib/Store/make-cache-manager-store.js +0 -90
- package/lib/Store/make-in-memory-store.d.ts +0 -123
- package/lib/Store/make-in-memory-store.js +0 -429
- package/lib/Store/make-ordered-dictionary.d.ts +0 -12
- package/lib/Store/make-ordered-dictionary.js +0 -86
- package/lib/Store/object-repository.d.ts +0 -10
- package/lib/Store/object-repository.js +0 -31
- package/lib/Types/MexUpdates.d.ts +0 -9
- package/lib/Types/MexUpdates.js +0 -18
- package/lib/Utils/use-mongo-file-auth-state.d.ts +0 -6
- package/lib/Utils/use-mongo-file-auth-state.js +0 -84
- package/lib/Utils/use-single-file-auth-state.d.ts +0 -13
- package/lib/Utils/use-single-file-auth-state.js +0 -80
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.d.ts +0 -28
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +0 -69
- package/lib/WAUSync/Protocols/USyncLIDProtocol.d.ts +0 -9
- package/lib/WAUSync/Protocols/USyncLIDProtocol.js +0 -30
package/lib/Utils/chat-utils.js
CHANGED
|
@@ -1,137 +1,116 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const crypto_1 = require("./crypto")
|
|
10
|
-
const generics_1 = require("./generics")
|
|
11
|
-
const lt_hash_1 = require("./lt-hash")
|
|
12
|
-
const messages_media_1 = require("./messages-media")
|
|
13
|
-
|
|
1
|
+
import { Boom } from '@hapi/boom';
|
|
2
|
+
import { proto } from '../../WAProto/index.js';
|
|
3
|
+
import { LabelAssociationType } from '../Types/LabelAssociation.js';
|
|
4
|
+
import { getBinaryNodeChild, getBinaryNodeChildren, isJidGroup, jidNormalizedUser } from '../WABinary/index.js';
|
|
5
|
+
import { aesDecrypt, aesEncrypt, hkdf, hmacSign } from './crypto.js';
|
|
6
|
+
import { toNumber } from './generics.js';
|
|
7
|
+
import { LT_HASH_ANTI_TAMPERING } from './lt-hash.js';
|
|
8
|
+
import { downloadContentFromMessage } from './messages-media.js';
|
|
14
9
|
const mutationKeys = async (keydata) => {
|
|
15
|
-
const expanded = await
|
|
10
|
+
const expanded = await hkdf(keydata, 160, { info: 'WhatsApp Mutation Keys' });
|
|
16
11
|
return {
|
|
17
12
|
indexKey: expanded.slice(0, 32),
|
|
18
13
|
valueEncryptionKey: expanded.slice(32, 64),
|
|
19
14
|
valueMacKey: expanded.slice(64, 96),
|
|
20
15
|
snapshotMacKey: expanded.slice(96, 128),
|
|
21
16
|
patchMacKey: expanded.slice(128, 160)
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
17
|
+
};
|
|
18
|
+
};
|
|
25
19
|
const generateMac = (operation, data, keyId, key) => {
|
|
26
20
|
const getKeyData = () => {
|
|
27
|
-
let r
|
|
21
|
+
let r;
|
|
28
22
|
switch (operation) {
|
|
29
|
-
case
|
|
30
|
-
r = 0x01
|
|
31
|
-
break
|
|
32
|
-
case
|
|
33
|
-
r = 0x02
|
|
34
|
-
break
|
|
35
|
-
}
|
|
36
|
-
const buff = Buffer.from([r])
|
|
37
|
-
return Buffer.concat([buff, Buffer.from(keyId, 'base64')])
|
|
38
|
-
}
|
|
39
|
-
const keyData = getKeyData()
|
|
40
|
-
const last = Buffer.alloc(8) // 8 bytes
|
|
41
|
-
last.set([keyData.length], last.length - 1)
|
|
42
|
-
const total = Buffer.concat([keyData, data, last])
|
|
43
|
-
const hmac =
|
|
44
|
-
return hmac.slice(0, 32)
|
|
45
|
-
}
|
|
46
|
-
|
|
23
|
+
case proto.SyncdMutation.SyncdOperation.SET:
|
|
24
|
+
r = 0x01;
|
|
25
|
+
break;
|
|
26
|
+
case proto.SyncdMutation.SyncdOperation.REMOVE:
|
|
27
|
+
r = 0x02;
|
|
28
|
+
break;
|
|
29
|
+
}
|
|
30
|
+
const buff = Buffer.from([r]);
|
|
31
|
+
return Buffer.concat([buff, Buffer.from(keyId, 'base64')]);
|
|
32
|
+
};
|
|
33
|
+
const keyData = getKeyData();
|
|
34
|
+
const last = Buffer.alloc(8); // 8 bytes
|
|
35
|
+
last.set([keyData.length], last.length - 1);
|
|
36
|
+
const total = Buffer.concat([keyData, data, last]);
|
|
37
|
+
const hmac = hmacSign(total, key, 'sha512');
|
|
38
|
+
return hmac.slice(0, 32);
|
|
39
|
+
};
|
|
47
40
|
const to64BitNetworkOrder = (e) => {
|
|
48
|
-
const buff = Buffer.alloc(8)
|
|
49
|
-
buff.writeUint32BE(e, 4)
|
|
50
|
-
return buff
|
|
51
|
-
}
|
|
52
|
-
|
|
41
|
+
const buff = Buffer.alloc(8);
|
|
42
|
+
buff.writeUint32BE(e, 4);
|
|
43
|
+
return buff;
|
|
44
|
+
};
|
|
53
45
|
const makeLtHashGenerator = ({ indexValueMap, hash }) => {
|
|
54
|
-
indexValueMap = { ...indexValueMap }
|
|
55
|
-
const addBuffs = []
|
|
56
|
-
const subBuffs = []
|
|
46
|
+
indexValueMap = { ...indexValueMap };
|
|
47
|
+
const addBuffs = [];
|
|
48
|
+
const subBuffs = [];
|
|
57
49
|
return {
|
|
58
50
|
mix: ({ indexMac, valueMac, operation }) => {
|
|
59
|
-
const indexMacBase64 = Buffer.from(indexMac).toString('base64')
|
|
60
|
-
const prevOp = indexValueMap[indexMacBase64]
|
|
61
|
-
if (operation ===
|
|
51
|
+
const indexMacBase64 = Buffer.from(indexMac).toString('base64');
|
|
52
|
+
const prevOp = indexValueMap[indexMacBase64];
|
|
53
|
+
if (operation === proto.SyncdMutation.SyncdOperation.REMOVE) {
|
|
62
54
|
if (!prevOp) {
|
|
63
|
-
throw new
|
|
55
|
+
throw new Boom('tried remove, but no previous op', { data: { indexMac, valueMac } });
|
|
64
56
|
}
|
|
65
57
|
// remove from index value mac, since this mutation is erased
|
|
66
|
-
delete indexValueMap[indexMacBase64]
|
|
58
|
+
delete indexValueMap[indexMacBase64];
|
|
67
59
|
}
|
|
68
60
|
else {
|
|
69
|
-
addBuffs.push(new Uint8Array(valueMac).buffer)
|
|
61
|
+
addBuffs.push(new Uint8Array(valueMac).buffer);
|
|
70
62
|
// add this index into the history map
|
|
71
|
-
indexValueMap[indexMacBase64] = { valueMac }
|
|
63
|
+
indexValueMap[indexMacBase64] = { valueMac };
|
|
72
64
|
}
|
|
73
65
|
if (prevOp) {
|
|
74
|
-
subBuffs.push(new Uint8Array(prevOp.valueMac).buffer)
|
|
66
|
+
subBuffs.push(new Uint8Array(prevOp.valueMac).buffer);
|
|
75
67
|
}
|
|
76
68
|
},
|
|
77
69
|
finish: async () => {
|
|
78
|
-
const hashArrayBuffer = new Uint8Array(hash).buffer
|
|
79
|
-
const result = await
|
|
80
|
-
const buffer = Buffer.from(result)
|
|
70
|
+
const hashArrayBuffer = new Uint8Array(hash).buffer;
|
|
71
|
+
const result = await LT_HASH_ANTI_TAMPERING.subtractThenAdd(hashArrayBuffer, addBuffs, subBuffs);
|
|
72
|
+
const buffer = Buffer.from(result);
|
|
81
73
|
return {
|
|
82
74
|
hash: buffer,
|
|
83
75
|
indexValueMap
|
|
84
|
-
}
|
|
76
|
+
};
|
|
85
77
|
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
78
|
+
};
|
|
79
|
+
};
|
|
89
80
|
const generateSnapshotMac = (lthash, version, name, key) => {
|
|
90
|
-
const total = Buffer.concat([
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
Buffer.from(name, 'utf-8')
|
|
94
|
-
])
|
|
95
|
-
return crypto_1.hmacSign(total, key, 'sha256')
|
|
96
|
-
}
|
|
97
|
-
|
|
81
|
+
const total = Buffer.concat([lthash, to64BitNetworkOrder(version), Buffer.from(name, 'utf-8')]);
|
|
82
|
+
return hmacSign(total, key, 'sha256');
|
|
83
|
+
};
|
|
98
84
|
const generatePatchMac = (snapshotMac, valueMacs, version, type, key) => {
|
|
99
|
-
const total = Buffer.concat([
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
return crypto_1.hmacSign(total, key)
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
const newLTHashState = () => ({ version: 0, hash: Buffer.alloc(128), indexValueMap: {} })
|
|
109
|
-
|
|
110
|
-
const encodeSyncdPatch = async ({ type, index, syncAction, apiVersion, operation }, myAppStateKeyId, state, getAppStateSyncKey) => {
|
|
111
|
-
const key = !!myAppStateKeyId ? await getAppStateSyncKey(myAppStateKeyId) : undefined
|
|
85
|
+
const total = Buffer.concat([snapshotMac, ...valueMacs, to64BitNetworkOrder(version), Buffer.from(type, 'utf-8')]);
|
|
86
|
+
return hmacSign(total, key);
|
|
87
|
+
};
|
|
88
|
+
export const newLTHashState = () => ({ version: 0, hash: Buffer.alloc(128), indexValueMap: {} });
|
|
89
|
+
export const encodeSyncdPatch = async ({ type, index, syncAction, apiVersion, operation }, myAppStateKeyId, state, getAppStateSyncKey) => {
|
|
90
|
+
const key = !!myAppStateKeyId ? await getAppStateSyncKey(myAppStateKeyId) : undefined;
|
|
112
91
|
if (!key) {
|
|
113
|
-
throw new
|
|
92
|
+
throw new Boom(`myAppStateKey ("${myAppStateKeyId}") not present`, { statusCode: 404 });
|
|
114
93
|
}
|
|
115
|
-
const encKeyId = Buffer.from(myAppStateKeyId, 'base64')
|
|
116
|
-
state = { ...state, indexValueMap: { ...state.indexValueMap } }
|
|
117
|
-
const indexBuffer = Buffer.from(JSON.stringify(index))
|
|
118
|
-
const dataProto =
|
|
94
|
+
const encKeyId = Buffer.from(myAppStateKeyId, 'base64');
|
|
95
|
+
state = { ...state, indexValueMap: { ...state.indexValueMap } };
|
|
96
|
+
const indexBuffer = Buffer.from(JSON.stringify(index));
|
|
97
|
+
const dataProto = proto.SyncActionData.fromObject({
|
|
119
98
|
index: indexBuffer,
|
|
120
99
|
value: syncAction,
|
|
121
100
|
padding: new Uint8Array(0),
|
|
122
101
|
version: apiVersion
|
|
123
|
-
})
|
|
124
|
-
const encoded =
|
|
125
|
-
const keyValue = await mutationKeys(key.keyData)
|
|
126
|
-
const encValue =
|
|
127
|
-
const valueMac = generateMac(operation, encValue, encKeyId, keyValue.valueMacKey)
|
|
128
|
-
const indexMac =
|
|
102
|
+
});
|
|
103
|
+
const encoded = proto.SyncActionData.encode(dataProto).finish();
|
|
104
|
+
const keyValue = await mutationKeys(key.keyData);
|
|
105
|
+
const encValue = aesEncrypt(encoded, keyValue.valueEncryptionKey);
|
|
106
|
+
const valueMac = generateMac(operation, encValue, encKeyId, keyValue.valueMacKey);
|
|
107
|
+
const indexMac = hmacSign(indexBuffer, keyValue.indexKey);
|
|
129
108
|
// update LT hash
|
|
130
|
-
const generator = makeLtHashGenerator(state)
|
|
131
|
-
generator.mix({ indexMac, valueMac, operation })
|
|
132
|
-
Object.assign(state, await generator.finish())
|
|
133
|
-
state.version += 1
|
|
134
|
-
const snapshotMac = generateSnapshotMac(state.hash, state.version, type, keyValue.snapshotMacKey)
|
|
109
|
+
const generator = makeLtHashGenerator(state);
|
|
110
|
+
generator.mix({ indexMac, valueMac, operation });
|
|
111
|
+
Object.assign(state, await generator.finish());
|
|
112
|
+
state.version += 1;
|
|
113
|
+
const snapshotMac = generateSnapshotMac(state.hash, state.version, type, keyValue.snapshotMacKey);
|
|
135
114
|
const patch = {
|
|
136
115
|
patchMac: generatePatchMac(snapshotMac, [valueMac], state.version, type, keyValue.patchMacKey),
|
|
137
116
|
snapshotMac: snapshotMac,
|
|
@@ -150,236 +129,231 @@ const encodeSyncdPatch = async ({ type, index, syncAction, apiVersion, operation
|
|
|
150
129
|
}
|
|
151
130
|
}
|
|
152
131
|
]
|
|
153
|
-
}
|
|
154
|
-
const base64Index = indexMac.toString('base64')
|
|
155
|
-
state.indexValueMap[base64Index] = { valueMac }
|
|
156
|
-
return { patch, state }
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
const
|
|
160
|
-
const ltGenerator = makeLtHashGenerator(initialState)
|
|
132
|
+
};
|
|
133
|
+
const base64Index = indexMac.toString('base64');
|
|
134
|
+
state.indexValueMap[base64Index] = { valueMac };
|
|
135
|
+
return { patch, state };
|
|
136
|
+
};
|
|
137
|
+
export const decodeSyncdMutations = async (msgMutations, initialState, getAppStateSyncKey, onMutation, validateMacs) => {
|
|
138
|
+
const ltGenerator = makeLtHashGenerator(initialState);
|
|
161
139
|
// indexKey used to HMAC sign record.index.blob
|
|
162
140
|
// valueEncryptionKey used to AES-256-CBC encrypt record.value.blob[0:-32]
|
|
163
141
|
// the remaining record.value.blob[0:-32] is the mac, it the HMAC sign of key.keyId + decoded proto data + length of bytes in keyId
|
|
164
142
|
for (const msgMutation of msgMutations) {
|
|
165
143
|
// if it's a syncdmutation, get the operation property
|
|
166
144
|
// otherwise, if it's only a record -- it'll be a SET mutation
|
|
167
|
-
const operation = 'operation' in msgMutation ? msgMutation.operation :
|
|
168
|
-
const record =
|
|
169
|
-
const key = await getKey(record.keyId.id)
|
|
170
|
-
const content = Buffer.from(record.value.blob)
|
|
171
|
-
const encContent = content.slice(0, -32)
|
|
172
|
-
const ogValueMac = content.slice(-32)
|
|
145
|
+
const operation = 'operation' in msgMutation ? msgMutation.operation : proto.SyncdMutation.SyncdOperation.SET;
|
|
146
|
+
const record = 'record' in msgMutation && !!msgMutation.record ? msgMutation.record : msgMutation;
|
|
147
|
+
const key = await getKey(record.keyId.id);
|
|
148
|
+
const content = Buffer.from(record.value.blob);
|
|
149
|
+
const encContent = content.slice(0, -32);
|
|
150
|
+
const ogValueMac = content.slice(-32);
|
|
173
151
|
if (validateMacs) {
|
|
174
|
-
const contentHmac = generateMac(operation, encContent, record.keyId.id, key.valueMacKey)
|
|
152
|
+
const contentHmac = generateMac(operation, encContent, record.keyId.id, key.valueMacKey);
|
|
175
153
|
if (Buffer.compare(contentHmac, ogValueMac) !== 0) {
|
|
176
|
-
throw new
|
|
154
|
+
throw new Boom('HMAC content verification failed');
|
|
177
155
|
}
|
|
178
156
|
}
|
|
179
|
-
const result =
|
|
180
|
-
const syncAction =
|
|
157
|
+
const result = aesDecrypt(encContent, key.valueEncryptionKey);
|
|
158
|
+
const syncAction = proto.SyncActionData.decode(result);
|
|
181
159
|
if (validateMacs) {
|
|
182
|
-
const hmac =
|
|
160
|
+
const hmac = hmacSign(syncAction.index, key.indexKey);
|
|
183
161
|
if (Buffer.compare(hmac, record.index.blob) !== 0) {
|
|
184
|
-
throw new
|
|
162
|
+
throw new Boom('HMAC index verification failed');
|
|
185
163
|
}
|
|
186
164
|
}
|
|
187
|
-
const indexStr = Buffer.from(syncAction.index).toString()
|
|
188
|
-
onMutation({ syncAction, index: JSON.parse(indexStr) })
|
|
165
|
+
const indexStr = Buffer.from(syncAction.index).toString();
|
|
166
|
+
onMutation({ syncAction, index: JSON.parse(indexStr) });
|
|
189
167
|
ltGenerator.mix({
|
|
190
168
|
indexMac: record.index.blob,
|
|
191
169
|
valueMac: ogValueMac,
|
|
192
170
|
operation: operation
|
|
193
|
-
})
|
|
171
|
+
});
|
|
194
172
|
}
|
|
195
|
-
return await ltGenerator.finish()
|
|
173
|
+
return await ltGenerator.finish();
|
|
196
174
|
async function getKey(keyId) {
|
|
197
|
-
const base64Key = Buffer.from(keyId).toString('base64')
|
|
198
|
-
const keyEnc = await getAppStateSyncKey(base64Key)
|
|
175
|
+
const base64Key = Buffer.from(keyId).toString('base64');
|
|
176
|
+
const keyEnc = await getAppStateSyncKey(base64Key);
|
|
199
177
|
if (!keyEnc) {
|
|
200
|
-
throw new
|
|
178
|
+
throw new Boom(`failed to find key "${base64Key}" to decode mutation`, {
|
|
179
|
+
statusCode: 404,
|
|
180
|
+
data: { msgMutations }
|
|
181
|
+
});
|
|
201
182
|
}
|
|
202
|
-
return mutationKeys(keyEnc.keyData)
|
|
183
|
+
return mutationKeys(keyEnc.keyData);
|
|
203
184
|
}
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
const decodeSyncdPatch = async (msg, name, initialState, getAppStateSyncKey, onMutation, validateMacs) => {
|
|
185
|
+
};
|
|
186
|
+
export const decodeSyncdPatch = async (msg, name, initialState, getAppStateSyncKey, onMutation, validateMacs) => {
|
|
207
187
|
if (validateMacs) {
|
|
208
|
-
const base64Key = Buffer.from(msg.keyId.id).toString('base64')
|
|
209
|
-
const mainKeyObj = await getAppStateSyncKey(base64Key)
|
|
188
|
+
const base64Key = Buffer.from(msg.keyId.id).toString('base64');
|
|
189
|
+
const mainKeyObj = await getAppStateSyncKey(base64Key);
|
|
210
190
|
if (!mainKeyObj) {
|
|
211
|
-
throw new
|
|
191
|
+
throw new Boom(`failed to find key "${base64Key}" to decode patch`, { statusCode: 404, data: { msg } });
|
|
212
192
|
}
|
|
213
|
-
const mainKey = await mutationKeys(mainKeyObj.keyData)
|
|
214
|
-
const mutationmacs = msg.mutations.map(mutation => mutation.record.value.blob.slice(-32))
|
|
215
|
-
const patchMac = generatePatchMac(msg.snapshotMac, mutationmacs,
|
|
193
|
+
const mainKey = await mutationKeys(mainKeyObj.keyData);
|
|
194
|
+
const mutationmacs = msg.mutations.map(mutation => mutation.record.value.blob.slice(-32));
|
|
195
|
+
const patchMac = generatePatchMac(msg.snapshotMac, mutationmacs, toNumber(msg.version.version), name, mainKey.patchMacKey);
|
|
216
196
|
if (Buffer.compare(patchMac, msg.patchMac) !== 0) {
|
|
217
|
-
throw new
|
|
197
|
+
throw new Boom('Invalid patch mac');
|
|
218
198
|
}
|
|
219
199
|
}
|
|
220
|
-
const result = await decodeSyncdMutations(msg.mutations, initialState, getAppStateSyncKey, onMutation, validateMacs)
|
|
221
|
-
return result
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
const
|
|
225
|
-
const
|
|
226
|
-
const
|
|
227
|
-
const final = {}
|
|
200
|
+
const result = await decodeSyncdMutations(msg.mutations, initialState, getAppStateSyncKey, onMutation, validateMacs);
|
|
201
|
+
return result;
|
|
202
|
+
};
|
|
203
|
+
export const extractSyncdPatches = async (result, options) => {
|
|
204
|
+
const syncNode = getBinaryNodeChild(result, 'sync');
|
|
205
|
+
const collectionNodes = getBinaryNodeChildren(syncNode, 'collection');
|
|
206
|
+
const final = {};
|
|
228
207
|
await Promise.all(collectionNodes.map(async (collectionNode) => {
|
|
229
|
-
const patchesNode =
|
|
230
|
-
const patches =
|
|
231
|
-
const snapshotNode =
|
|
232
|
-
const syncds = []
|
|
233
|
-
const name = collectionNode.attrs.name
|
|
234
|
-
const hasMorePatches = collectionNode.attrs.has_more_patches === 'true'
|
|
235
|
-
let snapshot = undefined
|
|
208
|
+
const patchesNode = getBinaryNodeChild(collectionNode, 'patches');
|
|
209
|
+
const patches = getBinaryNodeChildren(patchesNode || collectionNode, 'patch');
|
|
210
|
+
const snapshotNode = getBinaryNodeChild(collectionNode, 'snapshot');
|
|
211
|
+
const syncds = [];
|
|
212
|
+
const name = collectionNode.attrs.name;
|
|
213
|
+
const hasMorePatches = collectionNode.attrs.has_more_patches === 'true';
|
|
214
|
+
let snapshot = undefined;
|
|
236
215
|
if (snapshotNode && !!snapshotNode.content) {
|
|
237
216
|
if (!Buffer.isBuffer(snapshotNode)) {
|
|
238
|
-
snapshotNode.content = Buffer.from(Object.values(snapshotNode.content))
|
|
217
|
+
snapshotNode.content = Buffer.from(Object.values(snapshotNode.content));
|
|
239
218
|
}
|
|
240
|
-
const blobRef =
|
|
241
|
-
const data = await downloadExternalBlob(blobRef, options)
|
|
242
|
-
snapshot =
|
|
219
|
+
const blobRef = proto.ExternalBlobReference.decode(snapshotNode.content);
|
|
220
|
+
const data = await downloadExternalBlob(blobRef, options);
|
|
221
|
+
snapshot = proto.SyncdSnapshot.decode(data);
|
|
243
222
|
}
|
|
244
223
|
for (let { content } of patches) {
|
|
245
224
|
if (content) {
|
|
246
225
|
if (!Buffer.isBuffer(content)) {
|
|
247
|
-
content = Buffer.from(Object.values(content))
|
|
226
|
+
content = Buffer.from(Object.values(content));
|
|
248
227
|
}
|
|
249
|
-
const syncd =
|
|
228
|
+
const syncd = proto.SyncdPatch.decode(content);
|
|
250
229
|
if (!syncd.version) {
|
|
251
|
-
syncd.version = { version: +collectionNode.attrs.version + 1 }
|
|
230
|
+
syncd.version = { version: +collectionNode.attrs.version + 1 };
|
|
252
231
|
}
|
|
253
|
-
syncds.push(syncd)
|
|
232
|
+
syncds.push(syncd);
|
|
254
233
|
}
|
|
255
234
|
}
|
|
256
|
-
final[name] = { patches: syncds, hasMorePatches, snapshot }
|
|
257
|
-
}))
|
|
258
|
-
return final
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
const
|
|
262
|
-
const
|
|
263
|
-
const bufferArray = []
|
|
235
|
+
final[name] = { patches: syncds, hasMorePatches, snapshot };
|
|
236
|
+
}));
|
|
237
|
+
return final;
|
|
238
|
+
};
|
|
239
|
+
export const downloadExternalBlob = async (blob, options) => {
|
|
240
|
+
const stream = await downloadContentFromMessage(blob, 'md-app-state', { options });
|
|
241
|
+
const bufferArray = [];
|
|
264
242
|
for await (const chunk of stream) {
|
|
265
|
-
bufferArray.push(chunk)
|
|
266
|
-
}
|
|
267
|
-
return Buffer.concat(bufferArray)
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
const
|
|
271
|
-
const
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
const
|
|
278
|
-
newState.version
|
|
279
|
-
const mutationMap = {}
|
|
280
|
-
const areMutationsRequired = typeof minimumVersionNumber === 'undefined'
|
|
281
|
-
|| newState.version > minimumVersionNumber
|
|
243
|
+
bufferArray.push(chunk);
|
|
244
|
+
}
|
|
245
|
+
return Buffer.concat(bufferArray);
|
|
246
|
+
};
|
|
247
|
+
export const downloadExternalPatch = async (blob, options) => {
|
|
248
|
+
const buffer = await downloadExternalBlob(blob, options);
|
|
249
|
+
const syncData = proto.SyncdMutations.decode(buffer);
|
|
250
|
+
return syncData;
|
|
251
|
+
};
|
|
252
|
+
export const decodeSyncdSnapshot = async (name, snapshot, getAppStateSyncKey, minimumVersionNumber, validateMacs = true) => {
|
|
253
|
+
const newState = newLTHashState();
|
|
254
|
+
newState.version = toNumber(snapshot.version.version);
|
|
255
|
+
const mutationMap = {};
|
|
256
|
+
const areMutationsRequired = typeof minimumVersionNumber === 'undefined' || newState.version > minimumVersionNumber;
|
|
282
257
|
const { hash, indexValueMap } = await decodeSyncdMutations(snapshot.records, newState, getAppStateSyncKey, areMutationsRequired
|
|
283
|
-
?
|
|
284
|
-
const index = mutation.syncAction.index?.toString()
|
|
285
|
-
mutationMap[index] = mutation
|
|
258
|
+
? mutation => {
|
|
259
|
+
const index = mutation.syncAction.index?.toString();
|
|
260
|
+
mutationMap[index] = mutation;
|
|
286
261
|
}
|
|
287
|
-
: () => { }, validateMacs)
|
|
288
|
-
newState.hash = hash
|
|
289
|
-
newState.indexValueMap = indexValueMap
|
|
262
|
+
: () => { }, validateMacs);
|
|
263
|
+
newState.hash = hash;
|
|
264
|
+
newState.indexValueMap = indexValueMap;
|
|
290
265
|
if (validateMacs) {
|
|
291
|
-
const base64Key = Buffer.from(snapshot.keyId.id).toString('base64')
|
|
292
|
-
const keyEnc = await getAppStateSyncKey(base64Key)
|
|
266
|
+
const base64Key = Buffer.from(snapshot.keyId.id).toString('base64');
|
|
267
|
+
const keyEnc = await getAppStateSyncKey(base64Key);
|
|
293
268
|
if (!keyEnc) {
|
|
294
|
-
throw new
|
|
269
|
+
throw new Boom(`failed to find key "${base64Key}" to decode mutation`);
|
|
295
270
|
}
|
|
296
|
-
const result = await mutationKeys(keyEnc.keyData)
|
|
297
|
-
const computedSnapshotMac = generateSnapshotMac(newState.hash, newState.version, name, result.snapshotMacKey)
|
|
271
|
+
const result = await mutationKeys(keyEnc.keyData);
|
|
272
|
+
const computedSnapshotMac = generateSnapshotMac(newState.hash, newState.version, name, result.snapshotMacKey);
|
|
298
273
|
if (Buffer.compare(snapshot.mac, computedSnapshotMac) !== 0) {
|
|
299
|
-
throw new
|
|
274
|
+
throw new Boom(`failed to verify LTHash at ${newState.version} of ${name} from snapshot`);
|
|
300
275
|
}
|
|
301
276
|
}
|
|
302
277
|
return {
|
|
303
278
|
state: newState,
|
|
304
279
|
mutationMap
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
const decodePatches = async (name, syncds, initial, getAppStateSyncKey, options, minimumVersionNumber, logger, validateMacs = true) => {
|
|
280
|
+
};
|
|
281
|
+
};
|
|
282
|
+
export const decodePatches = async (name, syncds, initial, getAppStateSyncKey, options, minimumVersionNumber, logger, validateMacs = true) => {
|
|
309
283
|
const newState = {
|
|
310
284
|
...initial,
|
|
311
285
|
indexValueMap: { ...initial.indexValueMap }
|
|
312
|
-
}
|
|
313
|
-
const mutationMap = {}
|
|
286
|
+
};
|
|
287
|
+
const mutationMap = {};
|
|
314
288
|
for (const syncd of syncds) {
|
|
315
|
-
const { version, keyId, snapshotMac } = syncd
|
|
289
|
+
const { version, keyId, snapshotMac } = syncd;
|
|
316
290
|
if (syncd.externalMutations) {
|
|
317
|
-
logger?.trace({ name, version }, 'downloading external patch')
|
|
318
|
-
const ref = await downloadExternalPatch(syncd.externalMutations, options)
|
|
319
|
-
logger?.debug({ name, version, mutations: ref.mutations.length }, 'downloaded external patch')
|
|
320
|
-
syncd.mutations?.push(...ref.mutations)
|
|
321
|
-
}
|
|
322
|
-
const patchVersion =
|
|
323
|
-
newState.version = patchVersion
|
|
324
|
-
const shouldMutate = typeof minimumVersionNumber === 'undefined' || patchVersion > minimumVersionNumber
|
|
291
|
+
logger?.trace({ name, version }, 'downloading external patch');
|
|
292
|
+
const ref = await downloadExternalPatch(syncd.externalMutations, options);
|
|
293
|
+
logger?.debug({ name, version, mutations: ref.mutations.length }, 'downloaded external patch');
|
|
294
|
+
syncd.mutations?.push(...ref.mutations);
|
|
295
|
+
}
|
|
296
|
+
const patchVersion = toNumber(version.version);
|
|
297
|
+
newState.version = patchVersion;
|
|
298
|
+
const shouldMutate = typeof minimumVersionNumber === 'undefined' || patchVersion > minimumVersionNumber;
|
|
325
299
|
const decodeResult = await decodeSyncdPatch(syncd, name, newState, getAppStateSyncKey, shouldMutate
|
|
326
300
|
? mutation => {
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
mutationMap[index] = mutation
|
|
301
|
+
const index = mutation.syncAction.index?.toString();
|
|
302
|
+
mutationMap[index] = mutation;
|
|
330
303
|
}
|
|
331
|
-
: (
|
|
332
|
-
newState.hash = decodeResult.hash
|
|
333
|
-
newState.indexValueMap = decodeResult.indexValueMap
|
|
304
|
+
: () => { }, true);
|
|
305
|
+
newState.hash = decodeResult.hash;
|
|
306
|
+
newState.indexValueMap = decodeResult.indexValueMap;
|
|
334
307
|
if (validateMacs) {
|
|
335
|
-
const base64Key = Buffer.from(keyId.id).toString('base64')
|
|
336
|
-
const keyEnc = await getAppStateSyncKey(base64Key)
|
|
308
|
+
const base64Key = Buffer.from(keyId.id).toString('base64');
|
|
309
|
+
const keyEnc = await getAppStateSyncKey(base64Key);
|
|
337
310
|
if (!keyEnc) {
|
|
338
|
-
throw new
|
|
311
|
+
throw new Boom(`failed to find key "${base64Key}" to decode mutation`);
|
|
339
312
|
}
|
|
340
|
-
const result = await mutationKeys(keyEnc.keyData)
|
|
341
|
-
const computedSnapshotMac = generateSnapshotMac(newState.hash, newState.version, name, result.snapshotMacKey)
|
|
313
|
+
const result = await mutationKeys(keyEnc.keyData);
|
|
314
|
+
const computedSnapshotMac = generateSnapshotMac(newState.hash, newState.version, name, result.snapshotMacKey);
|
|
342
315
|
if (Buffer.compare(snapshotMac, computedSnapshotMac) !== 0) {
|
|
343
|
-
throw new
|
|
316
|
+
throw new Boom(`failed to verify LTHash at ${newState.version} of ${name}`);
|
|
344
317
|
}
|
|
345
318
|
}
|
|
346
319
|
// clear memory used up by the mutations
|
|
347
|
-
syncd.mutations = []
|
|
320
|
+
syncd.mutations = [];
|
|
348
321
|
}
|
|
349
|
-
return { state: newState, mutationMap }
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
const
|
|
353
|
-
const OP = WAProto_1.proto.SyncdMutation.SyncdOperation
|
|
322
|
+
return { state: newState, mutationMap };
|
|
323
|
+
};
|
|
324
|
+
export const chatModificationToAppPatch = (mod, jid) => {
|
|
325
|
+
const OP = proto.SyncdMutation.SyncdOperation;
|
|
354
326
|
const getMessageRange = (lastMessages) => {
|
|
355
|
-
let messageRange
|
|
327
|
+
let messageRange;
|
|
356
328
|
if (Array.isArray(lastMessages)) {
|
|
357
|
-
const lastMsg = lastMessages[lastMessages.length - 1]
|
|
329
|
+
const lastMsg = lastMessages[lastMessages.length - 1];
|
|
358
330
|
messageRange = {
|
|
359
331
|
lastMessageTimestamp: lastMsg?.messageTimestamp,
|
|
360
|
-
messages: lastMessages?.length
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
332
|
+
messages: lastMessages?.length
|
|
333
|
+
? lastMessages.map(m => {
|
|
334
|
+
if (!m.key?.id || !m.key?.remoteJid) {
|
|
335
|
+
throw new Boom('Incomplete key', { statusCode: 400, data: m });
|
|
336
|
+
}
|
|
337
|
+
if (isJidGroup(m.key.remoteJid) && !m.key.fromMe && !m.key.participant) {
|
|
338
|
+
throw new Boom('Expected not from me message to have participant', { statusCode: 400, data: m });
|
|
339
|
+
}
|
|
340
|
+
if (!m.messageTimestamp || !toNumber(m.messageTimestamp)) {
|
|
341
|
+
throw new Boom('Missing timestamp in last message list', { statusCode: 400, data: m });
|
|
342
|
+
}
|
|
343
|
+
if (m.key.participant) {
|
|
344
|
+
m.key.participant = jidNormalizedUser(m.key.participant);
|
|
345
|
+
}
|
|
346
|
+
return m;
|
|
347
|
+
})
|
|
348
|
+
: undefined
|
|
349
|
+
};
|
|
376
350
|
}
|
|
377
351
|
else {
|
|
378
|
-
messageRange = lastMessages
|
|
352
|
+
messageRange = lastMessages;
|
|
379
353
|
}
|
|
380
|
-
return messageRange
|
|
381
|
-
}
|
|
382
|
-
let patch
|
|
354
|
+
return messageRange;
|
|
355
|
+
};
|
|
356
|
+
let patch;
|
|
383
357
|
if ('mute' in mod) {
|
|
384
358
|
patch = {
|
|
385
359
|
syncAction: {
|
|
@@ -392,7 +366,7 @@ const chatModificationToAppPatch = (mod, jid) => {
|
|
|
392
366
|
type: 'regular_high',
|
|
393
367
|
apiVersion: 2,
|
|
394
368
|
operation: OP.SET
|
|
395
|
-
}
|
|
369
|
+
};
|
|
396
370
|
}
|
|
397
371
|
else if ('archive' in mod) {
|
|
398
372
|
patch = {
|
|
@@ -406,7 +380,7 @@ const chatModificationToAppPatch = (mod, jid) => {
|
|
|
406
380
|
type: 'regular_low',
|
|
407
381
|
apiVersion: 3,
|
|
408
382
|
operation: OP.SET
|
|
409
|
-
}
|
|
383
|
+
};
|
|
410
384
|
}
|
|
411
385
|
else if ('markRead' in mod) {
|
|
412
386
|
patch = {
|
|
@@ -420,10 +394,10 @@ const chatModificationToAppPatch = (mod, jid) => {
|
|
|
420
394
|
type: 'regular_low',
|
|
421
395
|
apiVersion: 3,
|
|
422
396
|
operation: OP.SET
|
|
423
|
-
}
|
|
397
|
+
};
|
|
424
398
|
}
|
|
425
399
|
else if ('deleteForMe' in mod) {
|
|
426
|
-
const { timestamp, key, deleteMedia } = mod.deleteForMe
|
|
400
|
+
const { timestamp, key, deleteMedia } = mod.deleteForMe;
|
|
427
401
|
patch = {
|
|
428
402
|
syncAction: {
|
|
429
403
|
deleteMessageForMeAction: {
|
|
@@ -435,20 +409,20 @@ const chatModificationToAppPatch = (mod, jid) => {
|
|
|
435
409
|
type: 'regular_high',
|
|
436
410
|
apiVersion: 3,
|
|
437
411
|
operation: OP.SET
|
|
438
|
-
}
|
|
412
|
+
};
|
|
439
413
|
}
|
|
440
414
|
else if ('clear' in mod) {
|
|
441
415
|
patch = {
|
|
442
416
|
syncAction: {
|
|
443
417
|
clearChatAction: {
|
|
444
|
-
messageRange: getMessageRange(mod.lastMessages)
|
|
418
|
+
messageRange: getMessageRange(mod.lastMessages)
|
|
445
419
|
}
|
|
446
420
|
},
|
|
447
421
|
index: ['clearChat', jid, '1' /*the option here is 0 when keep starred messages is enabled*/, '0'],
|
|
448
422
|
type: 'regular_high',
|
|
449
423
|
apiVersion: 6,
|
|
450
424
|
operation: OP.SET
|
|
451
|
-
}
|
|
425
|
+
};
|
|
452
426
|
}
|
|
453
427
|
else if ('pin' in mod) {
|
|
454
428
|
patch = {
|
|
@@ -461,21 +435,32 @@ const chatModificationToAppPatch = (mod, jid) => {
|
|
|
461
435
|
type: 'regular_low',
|
|
462
436
|
apiVersion: 5,
|
|
463
437
|
operation: OP.SET
|
|
464
|
-
}
|
|
438
|
+
};
|
|
465
439
|
}
|
|
466
440
|
else if ('contact' in mod) {
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
},
|
|
471
|
-
index: ['contact', jid],
|
|
472
|
-
type: 'critical_unblock_low',
|
|
441
|
+
patch = {
|
|
442
|
+
syncAction: {
|
|
443
|
+
contactAction: mod.contact || {}
|
|
444
|
+
},
|
|
445
|
+
index: ['contact', jid],
|
|
446
|
+
type: 'critical_unblock_low',
|
|
473
447
|
apiVersion: 2,
|
|
474
448
|
operation: mod.contact ? OP.SET : OP.REMOVE
|
|
475
|
-
}
|
|
449
|
+
};
|
|
450
|
+
}
|
|
451
|
+
else if ('disableLinkPreviews' in mod) {
|
|
452
|
+
patch = {
|
|
453
|
+
syncAction: {
|
|
454
|
+
privacySettingDisableLinkPreviewsAction: mod.disableLinkPreviews || {}
|
|
455
|
+
},
|
|
456
|
+
index: ['setting_disableLinkPreviews'],
|
|
457
|
+
type: 'regular',
|
|
458
|
+
apiVersion: 8,
|
|
459
|
+
operation: OP.SET
|
|
460
|
+
};
|
|
476
461
|
}
|
|
477
462
|
else if ('star' in mod) {
|
|
478
|
-
const key = mod.star.messages[0]
|
|
463
|
+
const key = mod.star.messages[0];
|
|
479
464
|
patch = {
|
|
480
465
|
syncAction: {
|
|
481
466
|
starAction: {
|
|
@@ -486,20 +471,20 @@ const chatModificationToAppPatch = (mod, jid) => {
|
|
|
486
471
|
type: 'regular_low',
|
|
487
472
|
apiVersion: 2,
|
|
488
473
|
operation: OP.SET
|
|
489
|
-
}
|
|
474
|
+
};
|
|
490
475
|
}
|
|
491
476
|
else if ('delete' in mod) {
|
|
492
477
|
patch = {
|
|
493
478
|
syncAction: {
|
|
494
479
|
deleteChatAction: {
|
|
495
|
-
messageRange: getMessageRange(mod.lastMessages)
|
|
480
|
+
messageRange: getMessageRange(mod.lastMessages)
|
|
496
481
|
}
|
|
497
482
|
},
|
|
498
483
|
index: ['deleteChat', jid, '1'],
|
|
499
484
|
type: 'regular_high',
|
|
500
485
|
apiVersion: 6,
|
|
501
486
|
operation: OP.SET
|
|
502
|
-
}
|
|
487
|
+
};
|
|
503
488
|
}
|
|
504
489
|
else if ('pushNameSetting' in mod) {
|
|
505
490
|
patch = {
|
|
@@ -511,8 +496,25 @@ const chatModificationToAppPatch = (mod, jid) => {
|
|
|
511
496
|
index: ['setting_pushName'],
|
|
512
497
|
type: 'critical_block',
|
|
513
498
|
apiVersion: 1,
|
|
514
|
-
operation: OP.SET
|
|
515
|
-
}
|
|
499
|
+
operation: OP.SET
|
|
500
|
+
};
|
|
501
|
+
}
|
|
502
|
+
else if ('quickReply' in mod) {
|
|
503
|
+
patch = {
|
|
504
|
+
syncAction: {
|
|
505
|
+
quickReplyAction: {
|
|
506
|
+
count: 0,
|
|
507
|
+
deleted: mod.quickReply.deleted || false,
|
|
508
|
+
keywords: [],
|
|
509
|
+
message: mod.quickReply.message || '',
|
|
510
|
+
shortcut: mod.quickReply.shortcut || ''
|
|
511
|
+
}
|
|
512
|
+
},
|
|
513
|
+
index: ['quick_reply', mod.quickReply.timestamp || String(Math.floor(Date.now() / 1000))],
|
|
514
|
+
type: 'regular',
|
|
515
|
+
apiVersion: 2,
|
|
516
|
+
operation: OP.SET
|
|
517
|
+
};
|
|
516
518
|
}
|
|
517
519
|
else if ('addLabel' in mod) {
|
|
518
520
|
patch = {
|
|
@@ -527,64 +529,57 @@ const chatModificationToAppPatch = (mod, jid) => {
|
|
|
527
529
|
index: ['label_edit', mod.addLabel.id],
|
|
528
530
|
type: 'regular',
|
|
529
531
|
apiVersion: 3,
|
|
530
|
-
operation: OP.SET
|
|
531
|
-
}
|
|
532
|
+
operation: OP.SET
|
|
533
|
+
};
|
|
532
534
|
}
|
|
533
535
|
else if ('addChatLabel' in mod) {
|
|
534
536
|
patch = {
|
|
535
537
|
syncAction: {
|
|
536
538
|
labelAssociationAction: {
|
|
537
|
-
labeled: true
|
|
539
|
+
labeled: true
|
|
538
540
|
}
|
|
539
541
|
},
|
|
540
|
-
index: [
|
|
542
|
+
index: [LabelAssociationType.Chat, mod.addChatLabel.labelId, jid],
|
|
541
543
|
type: 'regular',
|
|
542
544
|
apiVersion: 3,
|
|
543
|
-
operation: OP.SET
|
|
544
|
-
}
|
|
545
|
+
operation: OP.SET
|
|
546
|
+
};
|
|
545
547
|
}
|
|
546
548
|
else if ('removeChatLabel' in mod) {
|
|
547
549
|
patch = {
|
|
548
550
|
syncAction: {
|
|
549
551
|
labelAssociationAction: {
|
|
550
|
-
labeled: false
|
|
552
|
+
labeled: false
|
|
551
553
|
}
|
|
552
554
|
},
|
|
553
|
-
index: [
|
|
555
|
+
index: [LabelAssociationType.Chat, mod.removeChatLabel.labelId, jid],
|
|
554
556
|
type: 'regular',
|
|
555
557
|
apiVersion: 3,
|
|
556
|
-
operation: OP.SET
|
|
557
|
-
}
|
|
558
|
+
operation: OP.SET
|
|
559
|
+
};
|
|
558
560
|
}
|
|
559
561
|
else if ('addMessageLabel' in mod) {
|
|
560
562
|
patch = {
|
|
561
563
|
syncAction: {
|
|
562
564
|
labelAssociationAction: {
|
|
563
|
-
labeled: true
|
|
565
|
+
labeled: true
|
|
564
566
|
}
|
|
565
567
|
},
|
|
566
|
-
index: [
|
|
567
|
-
LabelAssociation_1.LabelAssociationType.Message,
|
|
568
|
-
mod.addMessageLabel.labelId,
|
|
569
|
-
jid,
|
|
570
|
-
mod.addMessageLabel.messageId,
|
|
571
|
-
'0',
|
|
572
|
-
'0'
|
|
573
|
-
],
|
|
568
|
+
index: [LabelAssociationType.Message, mod.addMessageLabel.labelId, jid, mod.addMessageLabel.messageId, '0', '0'],
|
|
574
569
|
type: 'regular',
|
|
575
570
|
apiVersion: 3,
|
|
576
|
-
operation: OP.SET
|
|
577
|
-
}
|
|
571
|
+
operation: OP.SET
|
|
572
|
+
};
|
|
578
573
|
}
|
|
579
574
|
else if ('removeMessageLabel' in mod) {
|
|
580
575
|
patch = {
|
|
581
576
|
syncAction: {
|
|
582
577
|
labelAssociationAction: {
|
|
583
|
-
labeled: false
|
|
578
|
+
labeled: false
|
|
584
579
|
}
|
|
585
580
|
},
|
|
586
581
|
index: [
|
|
587
|
-
|
|
582
|
+
LabelAssociationType.Message,
|
|
588
583
|
mod.removeMessageLabel.labelId,
|
|
589
584
|
jid,
|
|
590
585
|
mod.removeMessageLabel.messageId,
|
|
@@ -593,31 +588,28 @@ const chatModificationToAppPatch = (mod, jid) => {
|
|
|
593
588
|
],
|
|
594
589
|
type: 'regular',
|
|
595
590
|
apiVersion: 3,
|
|
596
|
-
operation: OP.SET
|
|
597
|
-
}
|
|
591
|
+
operation: OP.SET
|
|
592
|
+
};
|
|
598
593
|
}
|
|
599
594
|
else {
|
|
600
|
-
throw new
|
|
601
|
-
}
|
|
602
|
-
patch.syncAction.timestamp = Date.now()
|
|
603
|
-
return patch
|
|
604
|
-
}
|
|
605
|
-
|
|
606
|
-
const
|
|
607
|
-
const
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
const { syncAction: { value: action }, index: [type, id, msgId, fromMe] } = syncAction
|
|
595
|
+
throw new Boom('not supported');
|
|
596
|
+
}
|
|
597
|
+
patch.syncAction.timestamp = Date.now();
|
|
598
|
+
return patch;
|
|
599
|
+
};
|
|
600
|
+
export const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) => {
|
|
601
|
+
const isInitialSync = !!initialSyncOpts;
|
|
602
|
+
const accountSettings = initialSyncOpts?.accountSettings;
|
|
603
|
+
logger?.trace({ syncAction, initialSync: !!initialSyncOpts }, 'processing sync action');
|
|
604
|
+
const { syncAction: { value: action }, index: [type, id, msgId, fromMe] } = syncAction;
|
|
611
605
|
if (action?.muteAction) {
|
|
612
606
|
ev.emit('chats.update', [
|
|
613
607
|
{
|
|
614
608
|
id,
|
|
615
|
-
muteEndTime: action.muteAction?.muted
|
|
616
|
-
? generics_1.toNumber(action.muteAction.muteEndTimestamp)
|
|
617
|
-
: null,
|
|
609
|
+
muteEndTime: action.muteAction?.muted ? toNumber(action.muteAction.muteEndTimestamp) : null,
|
|
618
610
|
conditional: getChatUpdateConditional(id, undefined)
|
|
619
611
|
}
|
|
620
|
-
])
|
|
612
|
+
]);
|
|
621
613
|
}
|
|
622
614
|
else if (action?.archiveChatAction || type === 'archive' || type === 'unarchive') {
|
|
623
615
|
// okay so we've to do some annoying computation here
|
|
@@ -626,38 +618,40 @@ const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) => {
|
|
|
626
618
|
// 1. if the account unarchiveChats setting is true
|
|
627
619
|
// a. if the chat is archived, and no further messages have been received -- simple, keep archived
|
|
628
620
|
// b. if the chat was archived, and the user received messages from the other person afterwards
|
|
629
|
-
//
|
|
630
|
-
//
|
|
621
|
+
// then the chat should be marked unarchved --
|
|
622
|
+
// we compare the timestamp of latest message from the other person to determine this
|
|
631
623
|
// 2. if the account unarchiveChats setting is false -- then it doesn't matter,
|
|
632
|
-
//
|
|
633
|
-
const archiveAction = action?.archiveChatAction
|
|
634
|
-
const isArchived = archiveAction
|
|
635
|
-
? archiveAction.archived
|
|
636
|
-
: type === 'archive'
|
|
624
|
+
// it'll always take an app state action to mark in unarchived -- which we'll get anyway
|
|
625
|
+
const archiveAction = action?.archiveChatAction;
|
|
626
|
+
const isArchived = archiveAction ? archiveAction.archived : type === 'archive';
|
|
637
627
|
// // basically we don't need to fire an "archive" update if the chat is being marked unarchvied
|
|
638
628
|
// // this only applies for the initial sync
|
|
639
629
|
// if(isInitialSync && !isArchived) {
|
|
640
|
-
//
|
|
630
|
+
// isArchived = false
|
|
641
631
|
// }
|
|
642
|
-
const msgRange = !accountSettings?.unarchiveChats ? undefined : archiveAction?.messageRange
|
|
632
|
+
const msgRange = !accountSettings?.unarchiveChats ? undefined : archiveAction?.messageRange;
|
|
643
633
|
// logger?.debug({ chat: id, syncAction }, 'message range archive')
|
|
644
|
-
ev.emit('chats.update', [
|
|
634
|
+
ev.emit('chats.update', [
|
|
635
|
+
{
|
|
645
636
|
id,
|
|
646
637
|
archived: isArchived,
|
|
647
638
|
conditional: getChatUpdateConditional(id, msgRange)
|
|
648
|
-
}
|
|
639
|
+
}
|
|
640
|
+
]);
|
|
649
641
|
}
|
|
650
642
|
else if (action?.markChatAsReadAction) {
|
|
651
|
-
const markReadAction = action.markChatAsReadAction
|
|
643
|
+
const markReadAction = action.markChatAsReadAction;
|
|
652
644
|
// basically we don't need to fire an "read" update if the chat is being marked as read
|
|
653
645
|
// because the chat is read by default
|
|
654
646
|
// this only applies for the initial sync
|
|
655
|
-
const isNullUpdate = isInitialSync && markReadAction.read
|
|
656
|
-
ev.emit('chats.update', [
|
|
647
|
+
const isNullUpdate = isInitialSync && markReadAction.read;
|
|
648
|
+
ev.emit('chats.update', [
|
|
649
|
+
{
|
|
657
650
|
id,
|
|
658
651
|
unreadCount: isNullUpdate ? null : !!markReadAction?.read ? 0 : -1,
|
|
659
652
|
conditional: getChatUpdateConditional(id, markReadAction?.messageRange)
|
|
660
|
-
}
|
|
653
|
+
}
|
|
654
|
+
]);
|
|
661
655
|
}
|
|
662
656
|
else if (action?.deleteMessageForMeAction || type === 'deleteMessageForMe') {
|
|
663
657
|
ev.emit('messages.delete', {
|
|
@@ -668,114 +662,102 @@ const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) => {
|
|
|
668
662
|
fromMe: fromMe === '1'
|
|
669
663
|
}
|
|
670
664
|
]
|
|
671
|
-
})
|
|
665
|
+
});
|
|
672
666
|
}
|
|
673
667
|
else if (action?.contactAction) {
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
668
|
+
ev.emit('contacts.upsert', [
|
|
669
|
+
{
|
|
670
|
+
id: id,
|
|
671
|
+
name: action.contactAction.fullName,
|
|
672
|
+
lid: action.contactAction.lidJid || undefined,
|
|
673
|
+
phoneNumber: action.contactAction.pnJid || undefined
|
|
674
|
+
}
|
|
675
|
+
]);
|
|
680
676
|
}
|
|
681
677
|
else if (action?.pushNameSetting) {
|
|
682
|
-
const name = action?.pushNameSetting?.name
|
|
678
|
+
const name = action?.pushNameSetting?.name;
|
|
683
679
|
if (name && me?.name !== name) {
|
|
684
|
-
ev.emit('creds.update', { me: { ...me, name } })
|
|
680
|
+
ev.emit('creds.update', { me: { ...me, name } });
|
|
685
681
|
}
|
|
686
682
|
}
|
|
687
683
|
else if (action?.pinAction) {
|
|
688
|
-
ev.emit('chats.update', [
|
|
684
|
+
ev.emit('chats.update', [
|
|
685
|
+
{
|
|
689
686
|
id,
|
|
690
|
-
pinned: action.pinAction?.pinned ?
|
|
687
|
+
pinned: action.pinAction?.pinned ? toNumber(action.timestamp) : null,
|
|
691
688
|
conditional: getChatUpdateConditional(id, undefined)
|
|
692
|
-
}
|
|
689
|
+
}
|
|
690
|
+
]);
|
|
693
691
|
}
|
|
694
692
|
else if (action?.unarchiveChatsSetting) {
|
|
695
|
-
const unarchiveChats = !!action.unarchiveChatsSetting.unarchiveChats
|
|
696
|
-
ev.emit('creds.update', { accountSettings: { unarchiveChats } })
|
|
697
|
-
logger?.info(`archive setting updated => '${action.unarchiveChatsSetting.unarchiveChats}'`)
|
|
693
|
+
const unarchiveChats = !!action.unarchiveChatsSetting.unarchiveChats;
|
|
694
|
+
ev.emit('creds.update', { accountSettings: { unarchiveChats } });
|
|
695
|
+
logger?.info(`archive setting updated => '${action.unarchiveChatsSetting.unarchiveChats}'`);
|
|
698
696
|
if (accountSettings) {
|
|
699
|
-
accountSettings.unarchiveChats = unarchiveChats
|
|
697
|
+
accountSettings.unarchiveChats = unarchiveChats;
|
|
700
698
|
}
|
|
701
699
|
}
|
|
702
700
|
else if (action?.starAction || type === 'star') {
|
|
703
|
-
let starred = action?.starAction?.starred
|
|
701
|
+
let starred = action?.starAction?.starred;
|
|
704
702
|
if (typeof starred !== 'boolean') {
|
|
705
|
-
starred = syncAction.index[syncAction.index.length - 1] === '1'
|
|
703
|
+
starred = syncAction.index[syncAction.index.length - 1] === '1';
|
|
706
704
|
}
|
|
707
705
|
ev.emit('messages.update', [
|
|
708
706
|
{
|
|
709
707
|
key: { remoteJid: id, id: msgId, fromMe: fromMe === '1' },
|
|
710
708
|
update: { starred }
|
|
711
709
|
}
|
|
712
|
-
])
|
|
710
|
+
]);
|
|
713
711
|
}
|
|
714
712
|
else if (action?.deleteChatAction || type === 'deleteChat') {
|
|
715
713
|
if (!isInitialSync) {
|
|
716
|
-
ev.emit('chats.delete', [id])
|
|
714
|
+
ev.emit('chats.delete', [id]);
|
|
717
715
|
}
|
|
718
716
|
}
|
|
719
717
|
else if (action?.labelEditAction) {
|
|
720
|
-
const { name, color, deleted, predefinedId } = action.labelEditAction
|
|
718
|
+
const { name, color, deleted, predefinedId } = action.labelEditAction;
|
|
721
719
|
ev.emit('labels.edit', {
|
|
722
|
-
id,
|
|
720
|
+
id: id,
|
|
723
721
|
name: name,
|
|
724
722
|
color: color,
|
|
725
723
|
deleted: deleted,
|
|
726
724
|
predefinedId: predefinedId ? String(predefinedId) : undefined
|
|
727
|
-
})
|
|
725
|
+
});
|
|
728
726
|
}
|
|
729
727
|
else if (action?.labelAssociationAction) {
|
|
730
728
|
ev.emit('labels.association', {
|
|
731
|
-
type: action.labelAssociationAction.labeled
|
|
732
|
-
|
|
733
|
-
: 'remove',
|
|
734
|
-
association: type === LabelAssociation_1.LabelAssociationType.Chat
|
|
729
|
+
type: action.labelAssociationAction.labeled ? 'add' : 'remove',
|
|
730
|
+
association: type === LabelAssociationType.Chat
|
|
735
731
|
? {
|
|
736
|
-
type:
|
|
732
|
+
type: LabelAssociationType.Chat,
|
|
737
733
|
chatId: syncAction.index[2],
|
|
738
734
|
labelId: syncAction.index[1]
|
|
739
735
|
}
|
|
740
736
|
: {
|
|
741
|
-
type:
|
|
737
|
+
type: LabelAssociationType.Message,
|
|
742
738
|
chatId: syncAction.index[2],
|
|
743
739
|
messageId: syncAction.index[3],
|
|
744
740
|
labelId: syncAction.index[1]
|
|
745
741
|
}
|
|
746
|
-
})
|
|
742
|
+
});
|
|
747
743
|
}
|
|
748
744
|
else {
|
|
749
|
-
logger?.debug({ syncAction, id }, 'unprocessable update')
|
|
745
|
+
logger?.debug({ syncAction, id }, 'unprocessable update');
|
|
750
746
|
}
|
|
751
747
|
function getChatUpdateConditional(id, msgRange) {
|
|
752
748
|
return isInitialSync
|
|
753
|
-
?
|
|
754
|
-
const chat = data.historySets.chats[id] || data.chatUpserts[id]
|
|
749
|
+
? data => {
|
|
750
|
+
const chat = data.historySets.chats[id] || data.chatUpserts[id];
|
|
755
751
|
if (chat) {
|
|
756
|
-
return msgRange ? isValidPatchBasedOnMessageRange(chat, msgRange) : true
|
|
752
|
+
return msgRange ? isValidPatchBasedOnMessageRange(chat, msgRange) : true;
|
|
757
753
|
}
|
|
758
754
|
}
|
|
759
|
-
: undefined
|
|
755
|
+
: undefined;
|
|
760
756
|
}
|
|
761
757
|
function isValidPatchBasedOnMessageRange(chat, msgRange) {
|
|
762
|
-
const lastMsgTimestamp = Number(msgRange?.lastMessageTimestamp || msgRange?.lastSystemMessageTimestamp || 0)
|
|
763
|
-
const chatLastMsgTimestamp = Number(chat?.lastMessageRecvTimestamp || 0)
|
|
764
|
-
return lastMsgTimestamp >= chatLastMsgTimestamp
|
|
765
|
-
}
|
|
766
|
-
}
|
|
767
|
-
|
|
768
|
-
module.exports = {
|
|
769
|
-
mutationKeys,
|
|
770
|
-
newLTHashState,
|
|
771
|
-
encodeSyncdPatch,
|
|
772
|
-
decodeSyncdMutations,
|
|
773
|
-
decodeSyncdPatch,
|
|
774
|
-
extractSyncdPatches,
|
|
775
|
-
downloadExternalBlob,
|
|
776
|
-
downloadExternalPatch,
|
|
777
|
-
decodeSyncdSnapshot,
|
|
778
|
-
decodePatches,
|
|
779
|
-
chatModificationToAppPatch,
|
|
780
|
-
processSyncAction
|
|
781
|
-
}
|
|
758
|
+
const lastMsgTimestamp = Number(msgRange?.lastMessageTimestamp || msgRange?.lastSystemMessageTimestamp || 0);
|
|
759
|
+
const chatLastMsgTimestamp = Number(chat?.lastMessageRecvTimestamp || 0);
|
|
760
|
+
return lastMsgTimestamp >= chatLastMsgTimestamp;
|
|
761
|
+
}
|
|
762
|
+
};
|
|
763
|
+
//# sourceMappingURL=chat-utils.js.map
|