@queenanya/baileys 8.6.0-beta → 9.0.2
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/WAProto/GenerateStatics.sh +3 -0
- package/WAProto/WAProto.proto +4633 -0
- package/WAProto/fix-imports.js +29 -0
- package/WAProto/index.d.ts +2165 -45253
- package/WAProto/index.js +45236 -130529
- package/lib/Defaults/index.d.ts +14 -3
- package/lib/Defaults/index.d.ts.map +1 -0
- package/lib/Defaults/index.js +64 -55
- package/lib/Defaults/index.js.map +1 -0
- package/lib/Signal/Group/ciphertext-message.d.ts +1 -0
- package/lib/Signal/Group/ciphertext-message.d.ts.map +1 -0
- package/lib/Signal/Group/ciphertext-message.js +2 -5
- package/lib/Signal/Group/ciphertext-message.js.map +1 -0
- package/lib/Signal/Group/group-session-builder.d.ts +4 -3
- package/lib/Signal/Group/group-session-builder.d.ts.map +1 -0
- package/lib/Signal/Group/group-session-builder.js +7 -41
- package/lib/Signal/Group/group-session-builder.js.map +1 -0
- package/lib/Signal/Group/group_cipher.d.ts +4 -4
- package/lib/Signal/Group/group_cipher.d.ts.map +1 -0
- package/lib/Signal/Group/group_cipher.js +37 -51
- package/lib/Signal/Group/group_cipher.js.map +1 -0
- package/lib/Signal/Group/index.d.ts +12 -11
- package/lib/Signal/Group/index.d.ts.map +1 -0
- package/lib/Signal/Group/index.js +12 -57
- package/lib/Signal/Group/index.js.map +1 -0
- package/lib/Signal/Group/keyhelper.d.ts +2 -1
- package/lib/Signal/Group/keyhelper.d.ts.map +1 -0
- package/lib/Signal/Group/keyhelper.js +7 -44
- package/lib/Signal/Group/keyhelper.js.map +1 -0
- package/lib/Signal/Group/sender-chain-key.d.ts +3 -2
- package/lib/Signal/Group/sender-chain-key.d.ts.map +1 -0
- package/lib/Signal/Group/sender-chain-key.js +7 -15
- package/lib/Signal/Group/sender-chain-key.js.map +1 -0
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +2 -1
- package/lib/Signal/Group/sender-key-distribution-message.d.ts.map +1 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +8 -11
- package/lib/Signal/Group/sender-key-distribution-message.js.map +1 -0
- package/lib/Signal/Group/sender-key-message.d.ts +2 -1
- package/lib/Signal/Group/sender-key-message.d.ts.map +1 -0
- package/lib/Signal/Group/sender-key-message.js +9 -12
- package/lib/Signal/Group/sender-key-message.js.map +1 -0
- package/lib/Signal/Group/sender-key-name.d.ts +1 -0
- package/lib/Signal/Group/sender-key-name.d.ts.map +1 -0
- package/lib/Signal/Group/sender-key-name.js +2 -5
- package/lib/Signal/Group/sender-key-name.js.map +1 -0
- package/lib/Signal/Group/sender-key-record.d.ts +3 -2
- package/lib/Signal/Group/sender-key-record.d.ts.map +1 -0
- package/lib/Signal/Group/sender-key-record.js +9 -21
- package/lib/Signal/Group/sender-key-record.js.map +1 -0
- package/lib/Signal/Group/sender-key-state.d.ts +7 -6
- package/lib/Signal/Group/sender-key-state.d.ts.map +1 -0
- package/lib/Signal/Group/sender-key-state.js +27 -42
- package/lib/Signal/Group/sender-key-state.js.map +1 -0
- package/lib/Signal/Group/sender-message-key.d.ts +1 -0
- package/lib/Signal/Group/sender-message-key.d.ts.map +1 -0
- package/lib/Signal/Group/sender-message-key.js +4 -7
- package/lib/Signal/Group/sender-message-key.js.map +1 -0
- package/lib/Signal/libsignal.d.ts +5 -3
- package/lib/Signal/libsignal.d.ts.map +1 -0
- package/lib/Signal/libsignal.js +258 -90
- 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 -18
- package/lib/Socket/Client/index.js.map +1 -0
- package/lib/Socket/Client/types.d.ts +2 -2
- package/lib/Socket/Client/types.d.ts.map +1 -0
- package/lib/Socket/Client/types.js +4 -6
- package/lib/Socket/Client/types.js.map +1 -0
- package/lib/Socket/Client/websocket.d.ts +2 -2
- package/lib/Socket/Client/websocket.d.ts.map +1 -0
- package/lib/Socket/Client/websocket.js +15 -37
- package/lib/Socket/Client/websocket.js.map +1 -0
- package/lib/Socket/business.d.ts +106 -94
- package/lib/Socket/business.d.ts.map +1 -0
- package/lib/Socket/business.js +159 -43
- package/lib/Socket/business.js.map +1 -0
- package/lib/Socket/chats.d.ts +39 -27
- package/lib/Socket/chats.d.ts.map +1 -0
- package/lib/Socket/chats.js +271 -261
- package/lib/Socket/chats.js.map +1 -0
- package/lib/Socket/communities.d.ts +111 -86
- package/lib/Socket/communities.d.ts.map +1 -0
- package/lib/Socket/communities.js +138 -70
- package/lib/Socket/communities.js.map +1 -0
- package/lib/Socket/groups.d.ts +53 -43
- package/lib/Socket/groups.d.ts.map +1 -0
- package/lib/Socket/groups.js +94 -99
- package/lib/Socket/groups.js.map +1 -0
- package/lib/Socket/index.d.ts +133 -108
- package/lib/Socket/index.d.ts.map +1 -0
- package/lib/Socket/index.js +17 -9
- package/lib/Socket/index.js.map +1 -0
- package/lib/Socket/messages-recv.d.ts +90 -82
- package/lib/Socket/messages-recv.d.ts.map +1 -0
- package/lib/Socket/messages-recv.js +635 -480
- package/lib/Socket/messages-recv.js.map +1 -0
- package/lib/Socket/messages-send.d.ts +90 -76
- package/lib/Socket/messages-send.d.ts.map +1 -0
- package/lib/Socket/messages-send.js +476 -402
- package/lib/Socket/messages-send.js.map +1 -0
- package/lib/Socket/mex.d.ts +3 -0
- package/lib/Socket/mex.d.ts.map +1 -0
- package/lib/Socket/mex.js +42 -0
- package/lib/Socket/mex.js.map +1 -0
- package/lib/Socket/newsletter.d.ts +83 -73
- package/lib/Socket/newsletter.d.ts.map +1 -0
- package/lib/Socket/newsletter.js +181 -202
- package/lib/Socket/newsletter.js.map +1 -0
- package/lib/Socket/socket.d.ts +24 -16
- package/lib/Socket/socket.d.ts.map +1 -0
- package/lib/Socket/socket.js +402 -196
- package/lib/Socket/socket.js.map +1 -0
- package/lib/Types/Auth.d.ts +13 -5
- package/lib/Types/Auth.d.ts.map +1 -0
- package/lib/Types/Auth.js +2 -2
- 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 +1 -0
- package/lib/Types/Call.d.ts.map +1 -0
- package/lib/Types/Call.js +2 -2
- package/lib/Types/Call.js.map +1 -0
- package/lib/Types/Chat.d.ts +18 -9
- package/lib/Types/Chat.d.ts.map +1 -0
- package/lib/Types/Chat.js +8 -4
- package/lib/Types/Chat.js.map +1 -0
- package/lib/Types/Contact.d.ts +5 -4
- package/lib/Types/Contact.d.ts.map +1 -0
- package/lib/Types/Contact.js +2 -2
- package/lib/Types/Contact.js.map +1 -0
- package/lib/Types/Events.d.ts +36 -33
- package/lib/Types/Events.d.ts.map +1 -0
- package/lib/Types/Events.js +2 -2
- package/lib/Types/Events.js.map +1 -0
- package/lib/Types/GroupMetadata.d.ts +12 -11
- package/lib/Types/GroupMetadata.d.ts.map +1 -0
- package/lib/Types/GroupMetadata.js +2 -2
- package/lib/Types/GroupMetadata.js.map +1 -0
- package/lib/Types/Label.d.ts +12 -0
- package/lib/Types/Label.d.ts.map +1 -0
- package/lib/Types/Label.js +3 -5
- package/lib/Types/Label.js.map +1 -0
- package/lib/Types/LabelAssociation.d.ts +1 -0
- package/lib/Types/LabelAssociation.d.ts.map +1 -0
- package/lib/Types/LabelAssociation.js +3 -5
- package/lib/Types/LabelAssociation.js.map +1 -0
- package/lib/Types/Message.d.ts +51 -148
- package/lib/Types/Message.d.ts.map +1 -0
- package/lib/Types/Message.js +11 -7
- package/lib/Types/Message.js.map +1 -0
- package/lib/Types/Newsletter.d.ts +173 -71
- package/lib/Types/Newsletter.d.ts.map +1 -0
- package/lib/Types/Newsletter.js +54 -11
- package/lib/Types/Newsletter.js.map +1 -0
- package/lib/Types/Product.d.ts +2 -1
- package/lib/Types/Product.d.ts.map +1 -0
- package/lib/Types/Product.js +2 -2
- package/lib/Types/Product.js.map +1 -0
- package/lib/Types/Signal.d.ts +20 -1
- package/lib/Types/Signal.d.ts.map +1 -0
- package/lib/Types/Signal.js +2 -2
- package/lib/Types/Signal.js.map +1 -0
- package/lib/Types/Socket.d.ts +34 -20
- package/lib/Types/Socket.d.ts.map +1 -0
- package/lib/Types/Socket.js +3 -2
- package/lib/Types/Socket.js.map +1 -0
- package/lib/Types/State.d.ts +14 -2
- package/lib/Types/State.d.ts.map +1 -0
- package/lib/Types/State.js +13 -2
- package/lib/Types/State.js.map +1 -0
- package/lib/Types/USync.d.ts +3 -2
- package/lib/Types/USync.d.ts.map +1 -0
- package/lib/Types/USync.js +2 -2
- package/lib/Types/USync.js.map +1 -0
- package/lib/Types/index.d.ts +15 -14
- package/lib/Types/index.d.ts.map +1 -0
- package/lib/Types/index.js +15 -31
- package/lib/Types/index.js.map +1 -0
- package/lib/Utils/auth-utils.d.ts +5 -4
- package/lib/Utils/auth-utils.d.ts.map +1 -0
- package/lib/Utils/auth-utils.js +199 -141
- package/lib/Utils/auth-utils.js.map +1 -0
- package/lib/Utils/baileys-event-stream.d.ts +2 -1
- package/lib/Utils/baileys-event-stream.d.ts.map +1 -0
- package/lib/Utils/baileys-event-stream.js +15 -22
- 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 +3 -2
- package/lib/Utils/business.d.ts.map +1 -0
- package/lib/Utils/business.js +66 -69
- package/lib/Utils/business.js.map +1 -0
- package/lib/Utils/chat-utils.d.ts +11 -11
- package/lib/Utils/chat-utils.d.ts.map +1 -0
- package/lib/Utils/chat-utils.js +203 -194
- package/lib/Utils/chat-utils.js.map +1 -0
- package/lib/Utils/crypto.d.ts +8 -7
- package/lib/Utils/crypto.d.ts.map +1 -0
- package/lib/Utils/crypto.js +50 -101
- package/lib/Utils/crypto.js.map +1 -0
- package/lib/Utils/decode-wa-message.d.ts +18 -5
- package/lib/Utils/decode-wa-message.d.ts.map +1 -0
- package/lib/Utils/decode-wa-message.js +134 -62
- package/lib/Utils/decode-wa-message.js.map +1 -0
- package/lib/Utils/event-buffer.d.ts +6 -7
- package/lib/Utils/event-buffer.d.ts.map +1 -0
- package/lib/Utils/event-buffer.js +99 -69
- package/lib/Utils/event-buffer.js.map +1 -0
- package/lib/Utils/generics.d.ts +57 -68
- package/lib/Utils/generics.d.ts.map +1 -0
- package/lib/Utils/generics.js +179 -356
- package/lib/Utils/generics.js.map +1 -0
- package/lib/Utils/history.d.ts +10 -10
- package/lib/Utils/history.d.ts.map +1 -0
- package/lib/Utils/history.js +37 -50
- package/lib/Utils/history.js.map +1 -0
- package/lib/Utils/index.d.ts +21 -17
- package/lib/Utils/index.d.ts.map +1 -0
- package/lib/Utils/index.js +21 -33
- package/lib/Utils/index.js.map +1 -0
- package/lib/Utils/link-preview.d.ts +4 -4
- package/lib/Utils/link-preview.d.ts.map +1 -0
- package/lib/Utils/link-preview.js +15 -56
- package/lib/Utils/link-preview.js.map +1 -0
- package/lib/Utils/logger.d.ts +8 -6
- 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 +9 -8
- package/lib/Utils/lt-hash.d.ts.map +1 -0
- package/lib/Utils/lt-hash.js +23 -26
- package/lib/Utils/lt-hash.js.map +1 -0
- package/lib/Utils/make-mutex.d.ts +1 -0
- package/lib/Utils/make-mutex.d.ts.map +1 -0
- package/lib/Utils/make-mutex.js +7 -10
- 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 +32 -38
- package/lib/Utils/messages-media.d.ts.map +1 -0
- package/lib/Utils/messages-media.js +283 -496
- package/lib/Utils/messages-media.js.map +1 -0
- package/lib/Utils/messages.d.ts +11 -10
- package/lib/Utils/messages.d.ts.map +1 -0
- package/lib/Utils/messages.js +309 -519
- package/lib/Utils/messages.js.map +1 -0
- package/lib/Utils/noise-handler.d.ts +5 -4
- package/lib/Utils/noise-handler.d.ts.map +1 -0
- package/lib/Utils/noise-handler.js +23 -26
- 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 +12 -12
- package/lib/Utils/process-message.d.ts.map +1 -0
- package/lib/Utils/process-message.js +196 -155
- package/lib/Utils/process-message.js.map +1 -0
- package/lib/Utils/signal.d.ts +7 -6
- package/lib/Utils/signal.d.ts.map +1 -0
- package/lib/Utils/signal.js +70 -64
- package/lib/Utils/signal.js.map +1 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +2 -1
- package/lib/Utils/use-multi-file-auth-state.d.ts.map +1 -0
- package/lib/Utils/use-multi-file-auth-state.js +23 -27
- package/lib/Utils/use-multi-file-auth-state.js.map +1 -0
- package/lib/Utils/use-single-file-auth-state.d.ts +3 -2
- package/lib/Utils/use-single-file-auth-state.d.ts.map +1 -0
- package/lib/Utils/use-single-file-auth-state.js +63 -41
- package/lib/Utils/use-single-file-auth-state.js.map +1 -0
- package/lib/Utils/validate-connection.d.ts +4 -3
- package/lib/Utils/validate-connection.d.ts.map +1 -0
- package/lib/Utils/validate-connection.js +99 -77
- package/lib/Utils/validate-connection.js.map +1 -0
- package/lib/WABinary/constants.d.ts +1 -0
- package/lib/WABinary/constants.d.ts.map +1 -0
- package/lib/WABinary/constants.js +9 -11
- package/lib/WABinary/constants.js.map +1 -0
- package/lib/WABinary/decode.d.ts +2 -1
- package/lib/WABinary/decode.d.ts.map +1 -0
- package/lib/WABinary/decode.js +25 -52
- package/lib/WABinary/decode.js.map +1 -0
- package/lib/WABinary/encode.d.ts +2 -1
- package/lib/WABinary/encode.d.ts.map +1 -0
- package/lib/WABinary/encode.js +14 -48
- package/lib/WABinary/encode.js.map +1 -0
- package/lib/WABinary/generic-utils.d.ts +4 -3
- package/lib/WABinary/generic-utils.d.ts.map +1 -0
- package/lib/WABinary/generic-utils.js +31 -39
- 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 -21
- package/lib/WABinary/index.js.map +1 -0
- package/lib/WABinary/jid-utils.d.ts +21 -11
- package/lib/WABinary/jid-utils.d.ts.map +1 -0
- package/lib/WABinary/jid-utils.js +71 -60
- package/lib/WABinary/jid-utils.js.map +1 -0
- package/lib/WABinary/types.d.ts +2 -1
- package/lib/WABinary/types.d.ts.map +1 -0
- package/lib/WABinary/types.js +2 -2
- package/lib/WABinary/types.js.map +1 -0
- package/lib/WAM/BinaryInfo.d.ts +2 -1
- package/lib/WAM/BinaryInfo.d.ts.map +1 -0
- package/lib/WAM/BinaryInfo.js +2 -5
- package/lib/WAM/BinaryInfo.js.map +1 -0
- package/lib/WAM/constants.d.ts +5 -3
- package/lib/WAM/constants.d.ts.map +1 -0
- package/lib/WAM/constants.js +19071 -11568
- package/lib/WAM/constants.js.map +1 -0
- package/lib/WAM/encode.d.ts +2 -1
- package/lib/WAM/encode.d.ts.map +1 -0
- package/lib/WAM/encode.js +17 -22
- 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 -19
- package/lib/WAM/index.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +4 -3
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +8 -11
- package/lib/WAUSync/Protocols/USyncContactProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +3 -2
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +11 -14
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +3 -2
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +8 -11
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +3 -2
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +9 -13
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +4 -3
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +20 -22
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +5 -3
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +13 -8
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/index.d.ts +5 -4
- package/lib/WAUSync/Protocols/index.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/index.js +5 -20
- package/lib/WAUSync/Protocols/index.js.map +1 -0
- package/lib/WAUSync/USyncQuery.d.ts +5 -4
- package/lib/WAUSync/USyncQuery.d.ts.map +1 -0
- package/lib/WAUSync/USyncQuery.js +40 -35
- package/lib/WAUSync/USyncQuery.js.map +1 -0
- package/lib/WAUSync/USyncUser.d.ts +6 -5
- package/lib/WAUSync/USyncUser.d.ts.map +1 -0
- package/lib/WAUSync/USyncUser.js +2 -5
- 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 -19
- package/lib/WAUSync/index.js.map +1 -0
- package/lib/index.d.ts +10 -12
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +11 -34
- package/lib/index.js.map +1 -0
- package/package.json +55 -65
- package/CHANGELOG.md +0 -4
- package/README-anya.md +0 -459
- package/README-shizo.md +0 -445
- package/README-whiskey.md +0 -44
- package/lib/Defaults/baileys-version.json +0 -3
- package/lib/Signal/Group/queue-job.d.ts +0 -1
- package/lib/Signal/Group/queue-job.js +0 -57
- package/lib/Socket/usync.d.ts +0 -36
- package/lib/Socket/usync.js +0 -70
- package/lib/Store/index.d.ts +0 -2
- package/lib/Store/index.js +0 -8
- package/lib/Store/make-in-memory-store.d.ts +0 -118
- package/lib/Store/make-in-memory-store.js +0 -429
- package/lib/Store/make-ordered-dictionary.d.ts +0 -13
- package/lib/Store/make-ordered-dictionary.js +0 -81
- package/lib/Store/object-repository.d.ts +0 -10
- package/lib/Store/object-repository.js +0 -27
- package/lib/WAMedia/index.d.ts +0 -2
- package/lib/WAMedia/index.js +0 -18
- package/lib/WAMedia/media-messages.d.ts +0 -18
- package/lib/WAMedia/media-messages.js +0 -102
- package/lib/WAMedia/media-set.d.ts +0 -9
- package/lib/WAMedia/media-set.js +0 -312
package/lib/Utils/chat-utils.js
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const generics_1 = require("./generics");
|
|
10
|
-
const lt_hash_1 = require("./lt-hash");
|
|
11
|
-
const messages_media_1 = require("./messages-media");
|
|
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';
|
|
12
9
|
const mutationKeys = async (keydata) => {
|
|
13
|
-
const expanded = await
|
|
10
|
+
const expanded = await hkdf(keydata, 160, { info: 'WhatsApp Mutation Keys' });
|
|
14
11
|
return {
|
|
15
12
|
indexKey: expanded.slice(0, 32),
|
|
16
13
|
valueEncryptionKey: expanded.slice(32, 64),
|
|
@@ -23,10 +20,10 @@ const generateMac = (operation, data, keyId, key) => {
|
|
|
23
20
|
const getKeyData = () => {
|
|
24
21
|
let r;
|
|
25
22
|
switch (operation) {
|
|
26
|
-
case
|
|
23
|
+
case proto.SyncdMutation.SyncdOperation.SET:
|
|
27
24
|
r = 0x01;
|
|
28
25
|
break;
|
|
29
|
-
case
|
|
26
|
+
case proto.SyncdMutation.SyncdOperation.REMOVE:
|
|
30
27
|
r = 0x02;
|
|
31
28
|
break;
|
|
32
29
|
}
|
|
@@ -37,7 +34,7 @@ const generateMac = (operation, data, keyId, key) => {
|
|
|
37
34
|
const last = Buffer.alloc(8); // 8 bytes
|
|
38
35
|
last.set([keyData.length], last.length - 1);
|
|
39
36
|
const total = Buffer.concat([keyData, data, last]);
|
|
40
|
-
const hmac =
|
|
37
|
+
const hmac = hmacSign(total, key, 'sha512');
|
|
41
38
|
return hmac.slice(0, 32);
|
|
42
39
|
};
|
|
43
40
|
const to64BitNetworkOrder = (e) => {
|
|
@@ -53,9 +50,9 @@ const makeLtHashGenerator = ({ indexValueMap, hash }) => {
|
|
|
53
50
|
mix: ({ indexMac, valueMac, operation }) => {
|
|
54
51
|
const indexMacBase64 = Buffer.from(indexMac).toString('base64');
|
|
55
52
|
const prevOp = indexValueMap[indexMacBase64];
|
|
56
|
-
if (operation ===
|
|
53
|
+
if (operation === proto.SyncdMutation.SyncdOperation.REMOVE) {
|
|
57
54
|
if (!prevOp) {
|
|
58
|
-
throw new
|
|
55
|
+
throw new Boom('tried remove, but no previous op', { data: { indexMac, valueMac } });
|
|
59
56
|
}
|
|
60
57
|
// remove from index value mac, since this mutation is erased
|
|
61
58
|
delete indexValueMap[indexMacBase64];
|
|
@@ -71,7 +68,7 @@ const makeLtHashGenerator = ({ indexValueMap, hash }) => {
|
|
|
71
68
|
},
|
|
72
69
|
finish: async () => {
|
|
73
70
|
const hashArrayBuffer = new Uint8Array(hash).buffer;
|
|
74
|
-
const result = await
|
|
71
|
+
const result = await LT_HASH_ANTI_TAMPERING.subtractThenAdd(hashArrayBuffer, addBuffs, subBuffs);
|
|
75
72
|
const buffer = Buffer.from(result);
|
|
76
73
|
return {
|
|
77
74
|
hash: buffer,
|
|
@@ -81,43 +78,33 @@ const makeLtHashGenerator = ({ indexValueMap, hash }) => {
|
|
|
81
78
|
};
|
|
82
79
|
};
|
|
83
80
|
const generateSnapshotMac = (lthash, version, name, key) => {
|
|
84
|
-
const total = Buffer.concat([
|
|
85
|
-
|
|
86
|
-
to64BitNetworkOrder(version),
|
|
87
|
-
Buffer.from(name, 'utf-8')
|
|
88
|
-
]);
|
|
89
|
-
return (0, crypto_1.hmacSign)(total, key, 'sha256');
|
|
81
|
+
const total = Buffer.concat([lthash, to64BitNetworkOrder(version), Buffer.from(name, 'utf-8')]);
|
|
82
|
+
return hmacSign(total, key, 'sha256');
|
|
90
83
|
};
|
|
91
84
|
const generatePatchMac = (snapshotMac, valueMacs, version, type, key) => {
|
|
92
|
-
const total = Buffer.concat([
|
|
93
|
-
|
|
94
|
-
...valueMacs,
|
|
95
|
-
to64BitNetworkOrder(version),
|
|
96
|
-
Buffer.from(type, 'utf-8')
|
|
97
|
-
]);
|
|
98
|
-
return (0, crypto_1.hmacSign)(total, key);
|
|
85
|
+
const total = Buffer.concat([snapshotMac, ...valueMacs, to64BitNetworkOrder(version), Buffer.from(type, 'utf-8')]);
|
|
86
|
+
return hmacSign(total, key);
|
|
99
87
|
};
|
|
100
|
-
const newLTHashState = () => ({ version: 0, hash: Buffer.alloc(128), indexValueMap: {} });
|
|
101
|
-
|
|
102
|
-
const encodeSyncdPatch = async ({ type, index, syncAction, apiVersion, operation }, myAppStateKeyId, state, getAppStateSyncKey) => {
|
|
88
|
+
export const newLTHashState = () => ({ version: 0, hash: Buffer.alloc(128), indexValueMap: {} });
|
|
89
|
+
export const encodeSyncdPatch = async ({ type, index, syncAction, apiVersion, operation }, myAppStateKeyId, state, getAppStateSyncKey) => {
|
|
103
90
|
const key = !!myAppStateKeyId ? await getAppStateSyncKey(myAppStateKeyId) : undefined;
|
|
104
91
|
if (!key) {
|
|
105
|
-
throw new
|
|
92
|
+
throw new Boom(`myAppStateKey ("${myAppStateKeyId}") not present`, { statusCode: 404 });
|
|
106
93
|
}
|
|
107
94
|
const encKeyId = Buffer.from(myAppStateKeyId, 'base64');
|
|
108
95
|
state = { ...state, indexValueMap: { ...state.indexValueMap } };
|
|
109
96
|
const indexBuffer = Buffer.from(JSON.stringify(index));
|
|
110
|
-
const dataProto =
|
|
97
|
+
const dataProto = proto.SyncActionData.fromObject({
|
|
111
98
|
index: indexBuffer,
|
|
112
99
|
value: syncAction,
|
|
113
100
|
padding: new Uint8Array(0),
|
|
114
101
|
version: apiVersion
|
|
115
102
|
});
|
|
116
|
-
const encoded =
|
|
103
|
+
const encoded = proto.SyncActionData.encode(dataProto).finish();
|
|
117
104
|
const keyValue = await mutationKeys(key.keyData);
|
|
118
|
-
const encValue =
|
|
105
|
+
const encValue = aesEncrypt(encoded, keyValue.valueEncryptionKey);
|
|
119
106
|
const valueMac = generateMac(operation, encValue, encKeyId, keyValue.valueMacKey);
|
|
120
|
-
const indexMac =
|
|
107
|
+
const indexMac = hmacSign(indexBuffer, keyValue.indexKey);
|
|
121
108
|
// update LT hash
|
|
122
109
|
const generator = makeLtHashGenerator(state);
|
|
123
110
|
generator.mix({ indexMac, valueMac, operation });
|
|
@@ -147,8 +134,7 @@ const encodeSyncdPatch = async ({ type, index, syncAction, apiVersion, operation
|
|
|
147
134
|
state.indexValueMap[base64Index] = { valueMac };
|
|
148
135
|
return { patch, state };
|
|
149
136
|
};
|
|
150
|
-
|
|
151
|
-
const decodeSyncdMutations = async (msgMutations, initialState, getAppStateSyncKey, onMutation, validateMacs) => {
|
|
137
|
+
export const decodeSyncdMutations = async (msgMutations, initialState, getAppStateSyncKey, onMutation, validateMacs) => {
|
|
152
138
|
const ltGenerator = makeLtHashGenerator(initialState);
|
|
153
139
|
// indexKey used to HMAC sign record.index.blob
|
|
154
140
|
// valueEncryptionKey used to AES-256-CBC encrypt record.value.blob[0:-32]
|
|
@@ -156,8 +142,8 @@ const decodeSyncdMutations = async (msgMutations, initialState, getAppStateSyncK
|
|
|
156
142
|
for (const msgMutation of msgMutations) {
|
|
157
143
|
// if it's a syncdmutation, get the operation property
|
|
158
144
|
// otherwise, if it's only a record -- it'll be a SET mutation
|
|
159
|
-
const operation = 'operation' in msgMutation ? msgMutation.operation :
|
|
160
|
-
const record =
|
|
145
|
+
const operation = 'operation' in msgMutation ? msgMutation.operation : proto.SyncdMutation.SyncdOperation.SET;
|
|
146
|
+
const record = 'record' in msgMutation && !!msgMutation.record ? msgMutation.record : msgMutation;
|
|
161
147
|
const key = await getKey(record.keyId.id);
|
|
162
148
|
const content = Buffer.from(record.value.blob);
|
|
163
149
|
const encContent = content.slice(0, -32);
|
|
@@ -165,15 +151,15 @@ const decodeSyncdMutations = async (msgMutations, initialState, getAppStateSyncK
|
|
|
165
151
|
if (validateMacs) {
|
|
166
152
|
const contentHmac = generateMac(operation, encContent, record.keyId.id, key.valueMacKey);
|
|
167
153
|
if (Buffer.compare(contentHmac, ogValueMac) !== 0) {
|
|
168
|
-
throw new
|
|
154
|
+
throw new Boom('HMAC content verification failed');
|
|
169
155
|
}
|
|
170
156
|
}
|
|
171
|
-
const result =
|
|
172
|
-
const syncAction =
|
|
157
|
+
const result = aesDecrypt(encContent, key.valueEncryptionKey);
|
|
158
|
+
const syncAction = proto.SyncActionData.decode(result);
|
|
173
159
|
if (validateMacs) {
|
|
174
|
-
const hmac =
|
|
160
|
+
const hmac = hmacSign(syncAction.index, key.indexKey);
|
|
175
161
|
if (Buffer.compare(hmac, record.index.blob) !== 0) {
|
|
176
|
-
throw new
|
|
162
|
+
throw new Boom('HMAC index verification failed');
|
|
177
163
|
}
|
|
178
164
|
}
|
|
179
165
|
const indexStr = Buffer.from(syncAction.index).toString();
|
|
@@ -189,38 +175,39 @@ const decodeSyncdMutations = async (msgMutations, initialState, getAppStateSyncK
|
|
|
189
175
|
const base64Key = Buffer.from(keyId).toString('base64');
|
|
190
176
|
const keyEnc = await getAppStateSyncKey(base64Key);
|
|
191
177
|
if (!keyEnc) {
|
|
192
|
-
throw new
|
|
178
|
+
throw new Boom(`failed to find key "${base64Key}" to decode mutation`, {
|
|
179
|
+
statusCode: 404,
|
|
180
|
+
data: { msgMutations }
|
|
181
|
+
});
|
|
193
182
|
}
|
|
194
183
|
return mutationKeys(keyEnc.keyData);
|
|
195
184
|
}
|
|
196
185
|
};
|
|
197
|
-
|
|
198
|
-
const decodeSyncdPatch = async (msg, name, initialState, getAppStateSyncKey, onMutation, validateMacs) => {
|
|
186
|
+
export const decodeSyncdPatch = async (msg, name, initialState, getAppStateSyncKey, onMutation, validateMacs) => {
|
|
199
187
|
if (validateMacs) {
|
|
200
188
|
const base64Key = Buffer.from(msg.keyId.id).toString('base64');
|
|
201
189
|
const mainKeyObj = await getAppStateSyncKey(base64Key);
|
|
202
190
|
if (!mainKeyObj) {
|
|
203
|
-
throw new
|
|
191
|
+
throw new Boom(`failed to find key "${base64Key}" to decode patch`, { statusCode: 404, data: { msg } });
|
|
204
192
|
}
|
|
205
193
|
const mainKey = await mutationKeys(mainKeyObj.keyData);
|
|
206
194
|
const mutationmacs = msg.mutations.map(mutation => mutation.record.value.blob.slice(-32));
|
|
207
|
-
const patchMac = generatePatchMac(msg.snapshotMac, mutationmacs,
|
|
195
|
+
const patchMac = generatePatchMac(msg.snapshotMac, mutationmacs, toNumber(msg.version.version), name, mainKey.patchMacKey);
|
|
208
196
|
if (Buffer.compare(patchMac, msg.patchMac) !== 0) {
|
|
209
|
-
throw new
|
|
197
|
+
throw new Boom('Invalid patch mac');
|
|
210
198
|
}
|
|
211
199
|
}
|
|
212
|
-
const result = await
|
|
200
|
+
const result = await decodeSyncdMutations(msg.mutations, initialState, getAppStateSyncKey, onMutation, validateMacs);
|
|
213
201
|
return result;
|
|
214
202
|
};
|
|
215
|
-
|
|
216
|
-
const
|
|
217
|
-
const
|
|
218
|
-
const collectionNodes = (0, WABinary_1.getBinaryNodeChildren)(syncNode, 'collection');
|
|
203
|
+
export const extractSyncdPatches = async (result, options) => {
|
|
204
|
+
const syncNode = getBinaryNodeChild(result, 'sync');
|
|
205
|
+
const collectionNodes = getBinaryNodeChildren(syncNode, 'collection');
|
|
219
206
|
const final = {};
|
|
220
207
|
await Promise.all(collectionNodes.map(async (collectionNode) => {
|
|
221
|
-
const patchesNode =
|
|
222
|
-
const patches =
|
|
223
|
-
const snapshotNode =
|
|
208
|
+
const patchesNode = getBinaryNodeChild(collectionNode, 'patches');
|
|
209
|
+
const patches = getBinaryNodeChildren(patchesNode || collectionNode, 'patch');
|
|
210
|
+
const snapshotNode = getBinaryNodeChild(collectionNode, 'snapshot');
|
|
224
211
|
const syncds = [];
|
|
225
212
|
const name = collectionNode.attrs.name;
|
|
226
213
|
const hasMorePatches = collectionNode.attrs.has_more_patches === 'true';
|
|
@@ -229,16 +216,16 @@ const extractSyncdPatches = async (result, options) => {
|
|
|
229
216
|
if (!Buffer.isBuffer(snapshotNode)) {
|
|
230
217
|
snapshotNode.content = Buffer.from(Object.values(snapshotNode.content));
|
|
231
218
|
}
|
|
232
|
-
const blobRef =
|
|
233
|
-
const data = await
|
|
234
|
-
snapshot =
|
|
219
|
+
const blobRef = proto.ExternalBlobReference.decode(snapshotNode.content);
|
|
220
|
+
const data = await downloadExternalBlob(blobRef, options);
|
|
221
|
+
snapshot = proto.SyncdSnapshot.decode(data);
|
|
235
222
|
}
|
|
236
223
|
for (let { content } of patches) {
|
|
237
224
|
if (content) {
|
|
238
225
|
if (!Buffer.isBuffer(content)) {
|
|
239
226
|
content = Buffer.from(Object.values(content));
|
|
240
227
|
}
|
|
241
|
-
const syncd =
|
|
228
|
+
const syncd = proto.SyncdPatch.decode(content);
|
|
242
229
|
if (!syncd.version) {
|
|
243
230
|
syncd.version = { version: +collectionNode.attrs.version + 1 };
|
|
244
231
|
}
|
|
@@ -249,32 +236,27 @@ const extractSyncdPatches = async (result, options) => {
|
|
|
249
236
|
}));
|
|
250
237
|
return final;
|
|
251
238
|
};
|
|
252
|
-
|
|
253
|
-
const
|
|
254
|
-
const stream = await (0, messages_media_1.downloadContentFromMessage)(blob, 'md-app-state', { options });
|
|
239
|
+
export const downloadExternalBlob = async (blob, options) => {
|
|
240
|
+
const stream = await downloadContentFromMessage(blob, 'md-app-state', { options });
|
|
255
241
|
const bufferArray = [];
|
|
256
242
|
for await (const chunk of stream) {
|
|
257
243
|
bufferArray.push(chunk);
|
|
258
244
|
}
|
|
259
245
|
return Buffer.concat(bufferArray);
|
|
260
246
|
};
|
|
261
|
-
|
|
262
|
-
const
|
|
263
|
-
const
|
|
264
|
-
const syncData = WAProto_1.proto.SyncdMutations.decode(buffer);
|
|
247
|
+
export const downloadExternalPatch = async (blob, options) => {
|
|
248
|
+
const buffer = await downloadExternalBlob(blob, options);
|
|
249
|
+
const syncData = proto.SyncdMutations.decode(buffer);
|
|
265
250
|
return syncData;
|
|
266
251
|
};
|
|
267
|
-
|
|
268
|
-
const
|
|
269
|
-
|
|
270
|
-
newState.version = (0, generics_1.toNumber)(snapshot.version.version);
|
|
252
|
+
export const decodeSyncdSnapshot = async (name, snapshot, getAppStateSyncKey, minimumVersionNumber, validateMacs = true) => {
|
|
253
|
+
const newState = newLTHashState();
|
|
254
|
+
newState.version = toNumber(snapshot.version.version);
|
|
271
255
|
const mutationMap = {};
|
|
272
|
-
const areMutationsRequired = typeof minimumVersionNumber === 'undefined'
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
var _a;
|
|
277
|
-
const index = (_a = mutation.syncAction.index) === null || _a === void 0 ? void 0 : _a.toString();
|
|
256
|
+
const areMutationsRequired = typeof minimumVersionNumber === 'undefined' || newState.version > minimumVersionNumber;
|
|
257
|
+
const { hash, indexValueMap } = await decodeSyncdMutations(snapshot.records, newState, getAppStateSyncKey, areMutationsRequired
|
|
258
|
+
? mutation => {
|
|
259
|
+
const index = mutation.syncAction.index?.toString();
|
|
278
260
|
mutationMap[index] = mutation;
|
|
279
261
|
}
|
|
280
262
|
: () => { }, validateMacs);
|
|
@@ -284,12 +266,12 @@ const decodeSyncdSnapshot = async (name, snapshot, getAppStateSyncKey, minimumVe
|
|
|
284
266
|
const base64Key = Buffer.from(snapshot.keyId.id).toString('base64');
|
|
285
267
|
const keyEnc = await getAppStateSyncKey(base64Key);
|
|
286
268
|
if (!keyEnc) {
|
|
287
|
-
throw new
|
|
269
|
+
throw new Boom(`failed to find key "${base64Key}" to decode mutation`);
|
|
288
270
|
}
|
|
289
271
|
const result = await mutationKeys(keyEnc.keyData);
|
|
290
272
|
const computedSnapshotMac = generateSnapshotMac(newState.hash, newState.version, name, result.snapshotMacKey);
|
|
291
273
|
if (Buffer.compare(snapshot.mac, computedSnapshotMac) !== 0) {
|
|
292
|
-
throw new
|
|
274
|
+
throw new Boom(`failed to verify LTHash at ${newState.version} of ${name} from snapshot`);
|
|
293
275
|
}
|
|
294
276
|
}
|
|
295
277
|
return {
|
|
@@ -297,45 +279,41 @@ const decodeSyncdSnapshot = async (name, snapshot, getAppStateSyncKey, minimumVe
|
|
|
297
279
|
mutationMap
|
|
298
280
|
};
|
|
299
281
|
};
|
|
300
|
-
|
|
301
|
-
const decodePatches = async (name, syncds, initial, getAppStateSyncKey, options, minimumVersionNumber, logger, validateMacs = true) => {
|
|
302
|
-
var _a;
|
|
282
|
+
export const decodePatches = async (name, syncds, initial, getAppStateSyncKey, options, minimumVersionNumber, logger, validateMacs = true) => {
|
|
303
283
|
const newState = {
|
|
304
284
|
...initial,
|
|
305
285
|
indexValueMap: { ...initial.indexValueMap }
|
|
306
286
|
};
|
|
307
287
|
const mutationMap = {};
|
|
308
|
-
for (
|
|
309
|
-
const syncd = syncds[i];
|
|
288
|
+
for (const syncd of syncds) {
|
|
310
289
|
const { version, keyId, snapshotMac } = syncd;
|
|
311
290
|
if (syncd.externalMutations) {
|
|
312
|
-
logger
|
|
313
|
-
const ref = await
|
|
314
|
-
logger
|
|
315
|
-
|
|
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);
|
|
316
295
|
}
|
|
317
|
-
const patchVersion =
|
|
296
|
+
const patchVersion = toNumber(version.version);
|
|
318
297
|
newState.version = patchVersion;
|
|
319
298
|
const shouldMutate = typeof minimumVersionNumber === 'undefined' || patchVersion > minimumVersionNumber;
|
|
320
|
-
const decodeResult = await
|
|
299
|
+
const decodeResult = await decodeSyncdPatch(syncd, name, newState, getAppStateSyncKey, shouldMutate
|
|
321
300
|
? mutation => {
|
|
322
|
-
|
|
323
|
-
const index = (_a = mutation.syncAction.index) === null || _a === void 0 ? void 0 : _a.toString();
|
|
301
|
+
const index = mutation.syncAction.index?.toString();
|
|
324
302
|
mutationMap[index] = mutation;
|
|
325
303
|
}
|
|
326
|
-
: (
|
|
304
|
+
: () => { }, true);
|
|
327
305
|
newState.hash = decodeResult.hash;
|
|
328
306
|
newState.indexValueMap = decodeResult.indexValueMap;
|
|
329
307
|
if (validateMacs) {
|
|
330
308
|
const base64Key = Buffer.from(keyId.id).toString('base64');
|
|
331
309
|
const keyEnc = await getAppStateSyncKey(base64Key);
|
|
332
310
|
if (!keyEnc) {
|
|
333
|
-
throw new
|
|
311
|
+
throw new Boom(`failed to find key "${base64Key}" to decode mutation`);
|
|
334
312
|
}
|
|
335
313
|
const result = await mutationKeys(keyEnc.keyData);
|
|
336
314
|
const computedSnapshotMac = generateSnapshotMac(newState.hash, newState.version, name, result.snapshotMacKey);
|
|
337
315
|
if (Buffer.compare(snapshotMac, computedSnapshotMac) !== 0) {
|
|
338
|
-
throw new
|
|
316
|
+
throw new Boom(`failed to verify LTHash at ${newState.version} of ${name}`);
|
|
339
317
|
}
|
|
340
318
|
}
|
|
341
319
|
// clear memory used up by the mutations
|
|
@@ -343,31 +321,31 @@ const decodePatches = async (name, syncds, initial, getAppStateSyncKey, options,
|
|
|
343
321
|
}
|
|
344
322
|
return { state: newState, mutationMap };
|
|
345
323
|
};
|
|
346
|
-
|
|
347
|
-
const
|
|
348
|
-
const OP = WAProto_1.proto.SyncdMutation.SyncdOperation;
|
|
324
|
+
export const chatModificationToAppPatch = (mod, jid) => {
|
|
325
|
+
const OP = proto.SyncdMutation.SyncdOperation;
|
|
349
326
|
const getMessageRange = (lastMessages) => {
|
|
350
327
|
let messageRange;
|
|
351
328
|
if (Array.isArray(lastMessages)) {
|
|
352
329
|
const lastMsg = lastMessages[lastMessages.length - 1];
|
|
353
330
|
messageRange = {
|
|
354
|
-
lastMessageTimestamp: lastMsg
|
|
355
|
-
messages:
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
331
|
+
lastMessageTimestamp: lastMsg?.messageTimestamp,
|
|
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
|
|
371
349
|
};
|
|
372
350
|
}
|
|
373
351
|
else {
|
|
@@ -499,7 +477,7 @@ const chatModificationToAppPatch = (mod, jid) => {
|
|
|
499
477
|
patch = {
|
|
500
478
|
syncAction: {
|
|
501
479
|
deleteChatAction: {
|
|
502
|
-
messageRange: getMessageRange(mod.lastMessages)
|
|
480
|
+
messageRange: getMessageRange(mod.lastMessages)
|
|
503
481
|
}
|
|
504
482
|
},
|
|
505
483
|
index: ['deleteChat', jid, '1'],
|
|
@@ -518,64 +496,90 @@ const chatModificationToAppPatch = (mod, jid) => {
|
|
|
518
496
|
index: ['setting_pushName'],
|
|
519
497
|
type: 'critical_block',
|
|
520
498
|
apiVersion: 1,
|
|
521
|
-
operation: OP.SET
|
|
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
|
+
};
|
|
518
|
+
}
|
|
519
|
+
else if ('addLabel' in mod) {
|
|
520
|
+
patch = {
|
|
521
|
+
syncAction: {
|
|
522
|
+
labelEditAction: {
|
|
523
|
+
name: mod.addLabel.name,
|
|
524
|
+
color: mod.addLabel.color,
|
|
525
|
+
predefinedId: mod.addLabel.predefinedId,
|
|
526
|
+
deleted: mod.addLabel.deleted
|
|
527
|
+
}
|
|
528
|
+
},
|
|
529
|
+
index: ['label_edit', mod.addLabel.id],
|
|
530
|
+
type: 'regular',
|
|
531
|
+
apiVersion: 3,
|
|
532
|
+
operation: OP.SET
|
|
522
533
|
};
|
|
523
534
|
}
|
|
524
535
|
else if ('addChatLabel' in mod) {
|
|
525
536
|
patch = {
|
|
526
537
|
syncAction: {
|
|
527
538
|
labelAssociationAction: {
|
|
528
|
-
labeled: true
|
|
539
|
+
labeled: true
|
|
529
540
|
}
|
|
530
541
|
},
|
|
531
|
-
index: [
|
|
542
|
+
index: [LabelAssociationType.Chat, mod.addChatLabel.labelId, jid],
|
|
532
543
|
type: 'regular',
|
|
533
544
|
apiVersion: 3,
|
|
534
|
-
operation: OP.SET
|
|
545
|
+
operation: OP.SET
|
|
535
546
|
};
|
|
536
547
|
}
|
|
537
548
|
else if ('removeChatLabel' in mod) {
|
|
538
549
|
patch = {
|
|
539
550
|
syncAction: {
|
|
540
551
|
labelAssociationAction: {
|
|
541
|
-
labeled: false
|
|
552
|
+
labeled: false
|
|
542
553
|
}
|
|
543
554
|
},
|
|
544
|
-
index: [
|
|
555
|
+
index: [LabelAssociationType.Chat, mod.removeChatLabel.labelId, jid],
|
|
545
556
|
type: 'regular',
|
|
546
557
|
apiVersion: 3,
|
|
547
|
-
operation: OP.SET
|
|
558
|
+
operation: OP.SET
|
|
548
559
|
};
|
|
549
560
|
}
|
|
550
561
|
else if ('addMessageLabel' in mod) {
|
|
551
562
|
patch = {
|
|
552
563
|
syncAction: {
|
|
553
564
|
labelAssociationAction: {
|
|
554
|
-
labeled: true
|
|
565
|
+
labeled: true
|
|
555
566
|
}
|
|
556
567
|
},
|
|
557
|
-
index: [
|
|
558
|
-
LabelAssociation_1.LabelAssociationType.Message,
|
|
559
|
-
mod.addMessageLabel.labelId,
|
|
560
|
-
jid,
|
|
561
|
-
mod.addMessageLabel.messageId,
|
|
562
|
-
'0',
|
|
563
|
-
'0'
|
|
564
|
-
],
|
|
568
|
+
index: [LabelAssociationType.Message, mod.addMessageLabel.labelId, jid, mod.addMessageLabel.messageId, '0', '0'],
|
|
565
569
|
type: 'regular',
|
|
566
570
|
apiVersion: 3,
|
|
567
|
-
operation: OP.SET
|
|
571
|
+
operation: OP.SET
|
|
568
572
|
};
|
|
569
573
|
}
|
|
570
574
|
else if ('removeMessageLabel' in mod) {
|
|
571
575
|
patch = {
|
|
572
576
|
syncAction: {
|
|
573
577
|
labelAssociationAction: {
|
|
574
|
-
labeled: false
|
|
578
|
+
labeled: false
|
|
575
579
|
}
|
|
576
580
|
},
|
|
577
581
|
index: [
|
|
578
|
-
|
|
582
|
+
LabelAssociationType.Message,
|
|
579
583
|
mod.removeMessageLabel.labelId,
|
|
580
584
|
jid,
|
|
581
585
|
mod.removeMessageLabel.messageId,
|
|
@@ -584,34 +588,30 @@ const chatModificationToAppPatch = (mod, jid) => {
|
|
|
584
588
|
],
|
|
585
589
|
type: 'regular',
|
|
586
590
|
apiVersion: 3,
|
|
587
|
-
operation: OP.SET
|
|
591
|
+
operation: OP.SET
|
|
588
592
|
};
|
|
589
593
|
}
|
|
590
594
|
else {
|
|
591
|
-
throw new
|
|
595
|
+
throw new Boom('not supported');
|
|
592
596
|
}
|
|
593
597
|
patch.syncAction.timestamp = Date.now();
|
|
594
598
|
return patch;
|
|
595
599
|
};
|
|
596
|
-
|
|
597
|
-
const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) => {
|
|
598
|
-
var _a, _b, _c, _d;
|
|
600
|
+
export const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) => {
|
|
599
601
|
const isInitialSync = !!initialSyncOpts;
|
|
600
|
-
const accountSettings = initialSyncOpts
|
|
601
|
-
logger
|
|
602
|
+
const accountSettings = initialSyncOpts?.accountSettings;
|
|
603
|
+
logger?.trace({ syncAction, initialSync: !!initialSyncOpts }, 'processing sync action');
|
|
602
604
|
const { syncAction: { value: action }, index: [type, id, msgId, fromMe] } = syncAction;
|
|
603
|
-
if (action
|
|
605
|
+
if (action?.muteAction) {
|
|
604
606
|
ev.emit('chats.update', [
|
|
605
607
|
{
|
|
606
608
|
id,
|
|
607
|
-
muteEndTime:
|
|
608
|
-
? (0, generics_1.toNumber)(action.muteAction.muteEndTimestamp)
|
|
609
|
-
: null,
|
|
609
|
+
muteEndTime: action.muteAction?.muted ? toNumber(action.muteAction.muteEndTimestamp) : null,
|
|
610
610
|
conditional: getChatUpdateConditional(id, undefined)
|
|
611
611
|
}
|
|
612
612
|
]);
|
|
613
613
|
}
|
|
614
|
-
else if (
|
|
614
|
+
else if (action?.archiveChatAction || type === 'archive' || type === 'unarchive') {
|
|
615
615
|
// okay so we've to do some annoying computation here
|
|
616
616
|
// when we're initially syncing the app state
|
|
617
617
|
// there are a few cases we need to handle
|
|
@@ -622,36 +622,38 @@ const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) => {
|
|
|
622
622
|
// we compare the timestamp of latest message from the other person to determine this
|
|
623
623
|
// 2. if the account unarchiveChats setting is false -- then it doesn't matter,
|
|
624
624
|
// it'll always take an app state action to mark in unarchived -- which we'll get anyway
|
|
625
|
-
const archiveAction = action
|
|
626
|
-
const isArchived = archiveAction
|
|
627
|
-
? archiveAction.archived
|
|
628
|
-
: type === 'archive';
|
|
625
|
+
const archiveAction = action?.archiveChatAction;
|
|
626
|
+
const isArchived = archiveAction ? archiveAction.archived : type === 'archive';
|
|
629
627
|
// // basically we don't need to fire an "archive" update if the chat is being marked unarchvied
|
|
630
628
|
// // this only applies for the initial sync
|
|
631
629
|
// if(isInitialSync && !isArchived) {
|
|
632
630
|
// isArchived = false
|
|
633
631
|
// }
|
|
634
|
-
const msgRange = !
|
|
632
|
+
const msgRange = !accountSettings?.unarchiveChats ? undefined : archiveAction?.messageRange;
|
|
635
633
|
// logger?.debug({ chat: id, syncAction }, 'message range archive')
|
|
636
|
-
ev.emit('chats.update', [
|
|
634
|
+
ev.emit('chats.update', [
|
|
635
|
+
{
|
|
637
636
|
id,
|
|
638
637
|
archived: isArchived,
|
|
639
638
|
conditional: getChatUpdateConditional(id, msgRange)
|
|
640
|
-
}
|
|
639
|
+
}
|
|
640
|
+
]);
|
|
641
641
|
}
|
|
642
|
-
else if (action
|
|
642
|
+
else if (action?.markChatAsReadAction) {
|
|
643
643
|
const markReadAction = action.markChatAsReadAction;
|
|
644
644
|
// basically we don't need to fire an "read" update if the chat is being marked as read
|
|
645
645
|
// because the chat is read by default
|
|
646
646
|
// this only applies for the initial sync
|
|
647
647
|
const isNullUpdate = isInitialSync && markReadAction.read;
|
|
648
|
-
ev.emit('chats.update', [
|
|
648
|
+
ev.emit('chats.update', [
|
|
649
|
+
{
|
|
649
650
|
id,
|
|
650
|
-
unreadCount: isNullUpdate ? null : !!
|
|
651
|
-
conditional: getChatUpdateConditional(id, markReadAction
|
|
652
|
-
}
|
|
651
|
+
unreadCount: isNullUpdate ? null : !!markReadAction?.read ? 0 : -1,
|
|
652
|
+
conditional: getChatUpdateConditional(id, markReadAction?.messageRange)
|
|
653
|
+
}
|
|
654
|
+
]);
|
|
653
655
|
}
|
|
654
|
-
else if (
|
|
656
|
+
else if (action?.deleteMessageForMeAction || type === 'deleteMessageForMe') {
|
|
655
657
|
ev.emit('messages.delete', {
|
|
656
658
|
keys: [
|
|
657
659
|
{
|
|
@@ -662,32 +664,41 @@ const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) => {
|
|
|
662
664
|
]
|
|
663
665
|
});
|
|
664
666
|
}
|
|
665
|
-
else if (action
|
|
666
|
-
ev.emit('contacts.upsert', [
|
|
667
|
+
else if (action?.contactAction) {
|
|
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
|
+
]);
|
|
667
676
|
}
|
|
668
|
-
else if (action
|
|
669
|
-
const name =
|
|
670
|
-
if (name &&
|
|
677
|
+
else if (action?.pushNameSetting) {
|
|
678
|
+
const name = action?.pushNameSetting?.name;
|
|
679
|
+
if (name && me?.name !== name) {
|
|
671
680
|
ev.emit('creds.update', { me: { ...me, name } });
|
|
672
681
|
}
|
|
673
682
|
}
|
|
674
|
-
else if (action
|
|
675
|
-
ev.emit('chats.update', [
|
|
683
|
+
else if (action?.pinAction) {
|
|
684
|
+
ev.emit('chats.update', [
|
|
685
|
+
{
|
|
676
686
|
id,
|
|
677
|
-
pinned:
|
|
687
|
+
pinned: action.pinAction?.pinned ? toNumber(action.timestamp) : null,
|
|
678
688
|
conditional: getChatUpdateConditional(id, undefined)
|
|
679
|
-
}
|
|
689
|
+
}
|
|
690
|
+
]);
|
|
680
691
|
}
|
|
681
|
-
else if (action
|
|
692
|
+
else if (action?.unarchiveChatsSetting) {
|
|
682
693
|
const unarchiveChats = !!action.unarchiveChatsSetting.unarchiveChats;
|
|
683
694
|
ev.emit('creds.update', { accountSettings: { unarchiveChats } });
|
|
684
|
-
logger
|
|
695
|
+
logger?.info(`archive setting updated => '${action.unarchiveChatsSetting.unarchiveChats}'`);
|
|
685
696
|
if (accountSettings) {
|
|
686
697
|
accountSettings.unarchiveChats = unarchiveChats;
|
|
687
698
|
}
|
|
688
699
|
}
|
|
689
|
-
else if (
|
|
690
|
-
let starred =
|
|
700
|
+
else if (action?.starAction || type === 'star') {
|
|
701
|
+
let starred = action?.starAction?.starred;
|
|
691
702
|
if (typeof starred !== 'boolean') {
|
|
692
703
|
starred = syncAction.index[syncAction.index.length - 1] === '1';
|
|
693
704
|
}
|
|
@@ -698,34 +709,32 @@ const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) => {
|
|
|
698
709
|
}
|
|
699
710
|
]);
|
|
700
711
|
}
|
|
701
|
-
else if (
|
|
712
|
+
else if (action?.deleteChatAction || type === 'deleteChat') {
|
|
702
713
|
if (!isInitialSync) {
|
|
703
714
|
ev.emit('chats.delete', [id]);
|
|
704
715
|
}
|
|
705
716
|
}
|
|
706
|
-
else if (action
|
|
717
|
+
else if (action?.labelEditAction) {
|
|
707
718
|
const { name, color, deleted, predefinedId } = action.labelEditAction;
|
|
708
719
|
ev.emit('labels.edit', {
|
|
709
|
-
id,
|
|
720
|
+
id: id,
|
|
710
721
|
name: name,
|
|
711
722
|
color: color,
|
|
712
723
|
deleted: deleted,
|
|
713
724
|
predefinedId: predefinedId ? String(predefinedId) : undefined
|
|
714
725
|
});
|
|
715
726
|
}
|
|
716
|
-
else if (action
|
|
727
|
+
else if (action?.labelAssociationAction) {
|
|
717
728
|
ev.emit('labels.association', {
|
|
718
|
-
type: action.labelAssociationAction.labeled
|
|
719
|
-
|
|
720
|
-
: 'remove',
|
|
721
|
-
association: type === LabelAssociation_1.LabelAssociationType.Chat
|
|
729
|
+
type: action.labelAssociationAction.labeled ? 'add' : 'remove',
|
|
730
|
+
association: type === LabelAssociationType.Chat
|
|
722
731
|
? {
|
|
723
|
-
type:
|
|
732
|
+
type: LabelAssociationType.Chat,
|
|
724
733
|
chatId: syncAction.index[2],
|
|
725
734
|
labelId: syncAction.index[1]
|
|
726
735
|
}
|
|
727
736
|
: {
|
|
728
|
-
type:
|
|
737
|
+
type: LabelAssociationType.Message,
|
|
729
738
|
chatId: syncAction.index[2],
|
|
730
739
|
messageId: syncAction.index[3],
|
|
731
740
|
labelId: syncAction.index[1]
|
|
@@ -733,11 +742,11 @@ const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) => {
|
|
|
733
742
|
});
|
|
734
743
|
}
|
|
735
744
|
else {
|
|
736
|
-
logger
|
|
745
|
+
logger?.debug({ syncAction, id }, 'unprocessable update');
|
|
737
746
|
}
|
|
738
747
|
function getChatUpdateConditional(id, msgRange) {
|
|
739
748
|
return isInitialSync
|
|
740
|
-
?
|
|
749
|
+
? data => {
|
|
741
750
|
const chat = data.historySets.chats[id] || data.chatUpserts[id];
|
|
742
751
|
if (chat) {
|
|
743
752
|
return msgRange ? isValidPatchBasedOnMessageRange(chat, msgRange) : true;
|
|
@@ -746,9 +755,9 @@ const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) => {
|
|
|
746
755
|
: undefined;
|
|
747
756
|
}
|
|
748
757
|
function isValidPatchBasedOnMessageRange(chat, msgRange) {
|
|
749
|
-
const lastMsgTimestamp = Number(
|
|
750
|
-
const chatLastMsgTimestamp = Number(
|
|
758
|
+
const lastMsgTimestamp = Number(msgRange?.lastMessageTimestamp || msgRange?.lastSystemMessageTimestamp || 0);
|
|
759
|
+
const chatLastMsgTimestamp = Number(chat?.lastMessageRecvTimestamp || 0);
|
|
751
760
|
return lastMsgTimestamp >= chatLastMsgTimestamp;
|
|
752
761
|
}
|
|
753
762
|
};
|
|
754
|
-
|
|
763
|
+
//# sourceMappingURL=chat-utils.js.map
|