@d0v3riz/baileys 6.7.19 → 6.7.21
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 +1263 -4
- package/WAProto/GenerateStatics.sh +3 -0
- package/WAProto/WAProto.proto +4633 -0
- package/WAProto/fix-imports.js +29 -0
- package/WAProto/index.d.ts +3212 -122
- package/WAProto/index.js +13516 -4182
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.d.ts +4 -3
- package/lib/Defaults/index.d.ts.map +1 -0
- package/lib/Defaults/index.js +50 -54
- 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 +18 -0
- package/lib/Signal/Group/group_cipher.d.ts.map +1 -0
- package/lib/Signal/Group/group_cipher.js +94 -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 +19 -0
- package/lib/Signal/Group/keyhelper.js.map +1 -0
- package/lib/Signal/Group/queue-job.d.ts +3 -0
- package/lib/Signal/Group/queue-job.d.ts.map +1 -0
- package/lib/Signal/Group/queue-job.js +57 -0
- package/lib/Signal/Group/queue-job.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 +32 -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 +67 -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 +50 -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 +96 -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/{WASignalGroup/sender_message_key.js → lib/Signal/Group/sender-message-key.js} +27 -39
- package/lib/Signal/Group/sender-message-key.js.map +1 -0
- package/lib/Signal/libsignal.d.ts +3 -2
- package/lib/Signal/libsignal.d.ts.map +1 -0
- package/lib/Signal/libsignal.js +41 -61
- package/lib/Signal/libsignal.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 -1
- 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 -1
- package/lib/Socket/Client/websocket.d.ts.map +1 -0
- package/lib/Socket/Client/websocket.js +15 -27
- package/lib/Socket/Client/websocket.js.map +1 -0
- package/lib/Socket/business.d.ts +92 -62
- package/lib/Socket/business.d.ts.map +1 -0
- package/lib/Socket/business.js +37 -42
- package/lib/Socket/business.js.map +1 -0
- package/lib/Socket/chats.d.ts +31 -24
- package/lib/Socket/chats.d.ts.map +1 -0
- package/lib/Socket/chats.js +251 -198
- package/lib/Socket/chats.js.map +1 -0
- package/lib/Socket/communities.d.ts +219 -0
- package/lib/Socket/communities.d.ts.map +1 -0
- package/lib/Socket/communities.js +351 -0
- package/lib/Socket/communities.js.map +1 -0
- package/lib/Socket/groups.d.ts +47 -39
- package/lib/Socket/groups.d.ts.map +1 -0
- package/lib/Socket/groups.js +91 -82
- package/lib/Socket/groups.js.map +1 -0
- package/lib/Socket/index.d.ts +128 -68
- package/lib/Socket/index.d.ts.map +1 -0
- package/lib/Socket/index.js +16 -9
- package/lib/Socket/index.js.map +1 -0
- package/lib/Socket/messages-recv.d.ts +79 -49
- package/lib/Socket/messages-recv.d.ts.map +1 -0
- package/lib/Socket/messages-recv.js +364 -200
- package/lib/Socket/messages-recv.js.map +1 -0
- package/lib/Socket/messages-send.d.ts +76 -46
- package/lib/Socket/messages-send.d.ts.map +1 -0
- package/lib/Socket/messages-send.js +144 -120
- 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 +143 -0
- package/lib/Socket/newsletter.d.ts.map +1 -0
- package/lib/Socket/newsletter.js +179 -0
- package/lib/Socket/newsletter.js.map +1 -0
- package/lib/Socket/socket.d.ts +15 -14
- package/lib/Socket/socket.d.ts.map +1 -0
- package/lib/Socket/socket.js +153 -141
- package/lib/Socket/socket.js.map +1 -0
- package/lib/Socket/usync.d.ts +17 -16
- package/lib/Socket/usync.d.ts.map +1 -0
- package/lib/Socket/usync.js +19 -26
- package/lib/Socket/usync.js.map +1 -0
- package/lib/Types/Auth.d.ts +5 -4
- 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/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 +14 -8
- 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 -0
- 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 +38 -11
- 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 +10 -4
- 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 +1 -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 +21 -9
- package/lib/Types/Message.d.ts.map +1 -0
- package/lib/Types/Message.js +7 -7
- package/lib/Types/Message.js.map +1 -0
- package/lib/Types/Newsletter.d.ts +135 -0
- package/lib/Types/Newsletter.d.ts.map +1 -0
- package/lib/Types/Newsletter.js +31 -0
- 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 +2 -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 +11 -10
- 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 -13
- package/lib/Types/index.d.ts.map +1 -0
- package/lib/Types/index.js +15 -30
- package/lib/Types/index.js.map +1 -0
- package/lib/Utils/auth-utils.d.ts +3 -2
- package/lib/Utils/auth-utils.d.ts.map +1 -0
- package/lib/Utils/auth-utils.js +30 -40
- 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/business.d.ts +3 -2
- package/lib/Utils/business.d.ts.map +1 -0
- package/lib/Utils/business.js +64 -75
- package/lib/Utils/business.js.map +1 -0
- package/lib/Utils/chat-utils.d.ts +12 -11
- package/lib/Utils/chat-utils.d.ts.map +1 -0
- package/lib/Utils/chat-utils.js +195 -194
- package/lib/Utils/chat-utils.js.map +1 -0
- package/lib/Utils/crypto.d.ts +2 -1
- package/lib/Utils/crypto.d.ts.map +1 -0
- package/lib/Utils/crypto.js +40 -95
- package/lib/Utils/crypto.js.map +1 -0
- package/lib/Utils/decode-wa-message.d.ts +7 -7
- package/lib/Utils/decode-wa-message.d.ts.map +1 -0
- package/lib/Utils/decode-wa-message.js +43 -41
- package/lib/Utils/decode-wa-message.js.map +1 -0
- package/lib/Utils/event-buffer.d.ts +6 -6
- package/lib/Utils/event-buffer.d.ts.map +1 -0
- package/lib/Utils/event-buffer.js +42 -59
- package/lib/Utils/event-buffer.js.map +1 -0
- package/lib/Utils/generics.d.ts +11 -9
- package/lib/Utils/generics.d.ts.map +1 -0
- package/lib/Utils/generics.js +105 -130
- package/lib/Utils/generics.js.map +1 -0
- package/lib/Utils/history.d.ts +4 -3
- package/lib/Utils/history.d.ts.map +1 -0
- package/lib/Utils/history.js +37 -46
- package/lib/Utils/history.js.map +1 -0
- package/lib/Utils/index.d.ts +18 -17
- package/lib/Utils/index.d.ts.map +1 -0
- package/lib/Utils/index.js +18 -33
- package/lib/Utils/index.js.map +1 -0
- package/lib/Utils/link-preview.d.ts +4 -3
- package/lib/Utils/link-preview.d.ts.map +1 -0
- package/lib/Utils/link-preview.js +14 -55
- 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 +6 -10
- package/lib/Utils/make-mutex.js.map +1 -0
- package/lib/Utils/messages-media.d.ts +20 -11
- package/lib/Utils/messages-media.d.ts.map +1 -0
- package/lib/Utils/messages-media.js +215 -253
- package/lib/Utils/messages-media.js.map +1 -0
- package/lib/Utils/messages.d.ts +9 -8
- package/lib/Utils/messages.d.ts.map +1 -0
- package/lib/Utils/messages.js +259 -228
- 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 +22 -26
- package/lib/Utils/noise-handler.js.map +1 -0
- package/lib/Utils/process-message.d.ts +6 -5
- package/lib/Utils/process-message.d.ts.map +1 -0
- package/lib/Utils/process-message.js +109 -123
- package/lib/Utils/process-message.js.map +1 -0
- package/lib/Utils/signal.d.ts +5 -4
- package/lib/Utils/signal.d.ts.map +1 -0
- package/lib/Utils/signal.js +52 -55
- 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/validate-connection.d.ts +4 -3
- package/lib/Utils/validate-connection.d.ts.map +1 -0
- package/lib/Utils/validate-connection.js +64 -75
- package/lib/Utils/validate-connection.js.map +1 -0
- package/lib/WABinary/constants.d.ts +5 -4
- package/lib/WABinary/constants.d.ts.map +1 -0
- package/lib/WABinary/constants.js +1280 -19
- 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 +15 -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 +7 -43
- 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 +1 -0
- package/lib/WABinary/jid-utils.d.ts.map +1 -0
- package/lib/WABinary/jid-utils.js +21 -38
- 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 +1 -0
- package/lib/WAM/constants.d.ts.map +1 -0
- package/lib/WAM/constants.js +2257 -2366
- 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 +15 -19
- 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 +9 -12
- 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 +3 -2
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +3 -6
- 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 +4 -3
- package/lib/WAUSync/USyncQuery.d.ts.map +1 -0
- package/lib/WAUSync/USyncQuery.js +34 -32
- 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 +9 -8
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +11 -30
- package/lib/index.js.map +1 -0
- package/package.json +36 -31
- package/WASignalGroup/GroupProtocol.js +0 -1697
- package/WASignalGroup/ciphertext_message.js +0 -16
- package/WASignalGroup/group_cipher.js +0 -120
- package/WASignalGroup/group_session_builder.js +0 -46
- package/WASignalGroup/index.js +0 -5
- package/WASignalGroup/keyhelper.js +0 -21
- package/WASignalGroup/protobufs.js +0 -3
- package/WASignalGroup/queue_job.js +0 -69
- package/WASignalGroup/sender_chain_key.js +0 -50
- package/WASignalGroup/sender_key_distribution_message.js +0 -78
- package/WASignalGroup/sender_key_message.js +0 -92
- package/WASignalGroup/sender_key_name.js +0 -70
- package/WASignalGroup/sender_key_record.js +0 -56
- package/WASignalGroup/sender_key_state.js +0 -129
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, isJidUser, 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,9 +279,7 @@ 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 }
|
|
@@ -308,33 +288,32 @@ const decodePatches = async (name, syncds, initial, getAppStateSyncKey, options,
|
|
|
308
288
|
for (const syncd of syncds) {
|
|
309
289
|
const { version, keyId, snapshotMac } = syncd;
|
|
310
290
|
if (syncd.externalMutations) {
|
|
311
|
-
logger
|
|
312
|
-
const ref = await
|
|
313
|
-
logger
|
|
314
|
-
|
|
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);
|
|
315
295
|
}
|
|
316
|
-
const patchVersion =
|
|
296
|
+
const patchVersion = toNumber(version.version);
|
|
317
297
|
newState.version = patchVersion;
|
|
318
298
|
const shouldMutate = typeof minimumVersionNumber === 'undefined' || patchVersion > minimumVersionNumber;
|
|
319
|
-
const decodeResult = await
|
|
299
|
+
const decodeResult = await decodeSyncdPatch(syncd, name, newState, getAppStateSyncKey, shouldMutate
|
|
320
300
|
? mutation => {
|
|
321
|
-
|
|
322
|
-
const index = (_a = mutation.syncAction.index) === null || _a === void 0 ? void 0 : _a.toString();
|
|
301
|
+
const index = mutation.syncAction.index?.toString();
|
|
323
302
|
mutationMap[index] = mutation;
|
|
324
303
|
}
|
|
325
|
-
: (
|
|
304
|
+
: () => { }, true);
|
|
326
305
|
newState.hash = decodeResult.hash;
|
|
327
306
|
newState.indexValueMap = decodeResult.indexValueMap;
|
|
328
307
|
if (validateMacs) {
|
|
329
308
|
const base64Key = Buffer.from(keyId.id).toString('base64');
|
|
330
309
|
const keyEnc = await getAppStateSyncKey(base64Key);
|
|
331
310
|
if (!keyEnc) {
|
|
332
|
-
throw new
|
|
311
|
+
throw new Boom(`failed to find key "${base64Key}" to decode mutation`);
|
|
333
312
|
}
|
|
334
313
|
const result = await mutationKeys(keyEnc.keyData);
|
|
335
314
|
const computedSnapshotMac = generateSnapshotMac(newState.hash, newState.version, name, result.snapshotMacKey);
|
|
336
315
|
if (Buffer.compare(snapshotMac, computedSnapshotMac) !== 0) {
|
|
337
|
-
throw new
|
|
316
|
+
throw new Boom(`failed to verify LTHash at ${newState.version} of ${name}`);
|
|
338
317
|
}
|
|
339
318
|
}
|
|
340
319
|
// clear memory used up by the mutations
|
|
@@ -342,31 +321,31 @@ const decodePatches = async (name, syncds, initial, getAppStateSyncKey, options,
|
|
|
342
321
|
}
|
|
343
322
|
return { state: newState, mutationMap };
|
|
344
323
|
};
|
|
345
|
-
|
|
346
|
-
const
|
|
347
|
-
const OP = WAProto_1.proto.SyncdMutation.SyncdOperation;
|
|
324
|
+
export const chatModificationToAppPatch = (mod, jid) => {
|
|
325
|
+
const OP = proto.SyncdMutation.SyncdOperation;
|
|
348
326
|
const getMessageRange = (lastMessages) => {
|
|
349
327
|
let messageRange;
|
|
350
328
|
if (Array.isArray(lastMessages)) {
|
|
351
329
|
const lastMsg = lastMessages[lastMessages.length - 1];
|
|
352
330
|
messageRange = {
|
|
353
|
-
lastMessageTimestamp: lastMsg
|
|
354
|
-
messages:
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
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
|
|
370
349
|
};
|
|
371
350
|
}
|
|
372
351
|
else {
|
|
@@ -435,7 +414,9 @@ const chatModificationToAppPatch = (mod, jid) => {
|
|
|
435
414
|
else if ('clear' in mod) {
|
|
436
415
|
patch = {
|
|
437
416
|
syncAction: {
|
|
438
|
-
clearChatAction: {
|
|
417
|
+
clearChatAction: {
|
|
418
|
+
messageRange: getMessageRange(mod.lastMessages)
|
|
419
|
+
}
|
|
439
420
|
},
|
|
440
421
|
index: ['clearChat', jid, '1' /*the option here is 0 when keep starred messages is enabled*/, '0'],
|
|
441
422
|
type: 'regular_high',
|
|
@@ -456,6 +437,28 @@ const chatModificationToAppPatch = (mod, jid) => {
|
|
|
456
437
|
operation: OP.SET
|
|
457
438
|
};
|
|
458
439
|
}
|
|
440
|
+
else if ('contact' in mod) {
|
|
441
|
+
patch = {
|
|
442
|
+
syncAction: {
|
|
443
|
+
contactAction: mod.contact || {}
|
|
444
|
+
},
|
|
445
|
+
index: ['contact', jid],
|
|
446
|
+
type: 'critical_unblock_low',
|
|
447
|
+
apiVersion: 2,
|
|
448
|
+
operation: mod.contact ? OP.SET : OP.REMOVE
|
|
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
|
+
};
|
|
461
|
+
}
|
|
459
462
|
else if ('star' in mod) {
|
|
460
463
|
const key = mod.star.messages[0];
|
|
461
464
|
patch = {
|
|
@@ -474,7 +477,7 @@ const chatModificationToAppPatch = (mod, jid) => {
|
|
|
474
477
|
patch = {
|
|
475
478
|
syncAction: {
|
|
476
479
|
deleteChatAction: {
|
|
477
|
-
messageRange: getMessageRange(mod.lastMessages)
|
|
480
|
+
messageRange: getMessageRange(mod.lastMessages)
|
|
478
481
|
}
|
|
479
482
|
},
|
|
480
483
|
index: ['deleteChat', jid, '1'],
|
|
@@ -493,7 +496,7 @@ const chatModificationToAppPatch = (mod, jid) => {
|
|
|
493
496
|
index: ['setting_pushName'],
|
|
494
497
|
type: 'critical_block',
|
|
495
498
|
apiVersion: 1,
|
|
496
|
-
operation: OP.SET
|
|
499
|
+
operation: OP.SET
|
|
497
500
|
};
|
|
498
501
|
}
|
|
499
502
|
else if ('addLabel' in mod) {
|
|
@@ -509,64 +512,57 @@ const chatModificationToAppPatch = (mod, jid) => {
|
|
|
509
512
|
index: ['label_edit', mod.addLabel.id],
|
|
510
513
|
type: 'regular',
|
|
511
514
|
apiVersion: 3,
|
|
512
|
-
operation: OP.SET
|
|
515
|
+
operation: OP.SET
|
|
513
516
|
};
|
|
514
517
|
}
|
|
515
518
|
else if ('addChatLabel' in mod) {
|
|
516
519
|
patch = {
|
|
517
520
|
syncAction: {
|
|
518
521
|
labelAssociationAction: {
|
|
519
|
-
labeled: true
|
|
522
|
+
labeled: true
|
|
520
523
|
}
|
|
521
524
|
},
|
|
522
|
-
index: [
|
|
525
|
+
index: [LabelAssociationType.Chat, mod.addChatLabel.labelId, jid],
|
|
523
526
|
type: 'regular',
|
|
524
527
|
apiVersion: 3,
|
|
525
|
-
operation: OP.SET
|
|
528
|
+
operation: OP.SET
|
|
526
529
|
};
|
|
527
530
|
}
|
|
528
531
|
else if ('removeChatLabel' in mod) {
|
|
529
532
|
patch = {
|
|
530
533
|
syncAction: {
|
|
531
534
|
labelAssociationAction: {
|
|
532
|
-
labeled: false
|
|
535
|
+
labeled: false
|
|
533
536
|
}
|
|
534
537
|
},
|
|
535
|
-
index: [
|
|
538
|
+
index: [LabelAssociationType.Chat, mod.removeChatLabel.labelId, jid],
|
|
536
539
|
type: 'regular',
|
|
537
540
|
apiVersion: 3,
|
|
538
|
-
operation: OP.SET
|
|
541
|
+
operation: OP.SET
|
|
539
542
|
};
|
|
540
543
|
}
|
|
541
544
|
else if ('addMessageLabel' in mod) {
|
|
542
545
|
patch = {
|
|
543
546
|
syncAction: {
|
|
544
547
|
labelAssociationAction: {
|
|
545
|
-
labeled: true
|
|
548
|
+
labeled: true
|
|
546
549
|
}
|
|
547
550
|
},
|
|
548
|
-
index: [
|
|
549
|
-
LabelAssociation_1.LabelAssociationType.Message,
|
|
550
|
-
mod.addMessageLabel.labelId,
|
|
551
|
-
jid,
|
|
552
|
-
mod.addMessageLabel.messageId,
|
|
553
|
-
'0',
|
|
554
|
-
'0'
|
|
555
|
-
],
|
|
551
|
+
index: [LabelAssociationType.Message, mod.addMessageLabel.labelId, jid, mod.addMessageLabel.messageId, '0', '0'],
|
|
556
552
|
type: 'regular',
|
|
557
553
|
apiVersion: 3,
|
|
558
|
-
operation: OP.SET
|
|
554
|
+
operation: OP.SET
|
|
559
555
|
};
|
|
560
556
|
}
|
|
561
557
|
else if ('removeMessageLabel' in mod) {
|
|
562
558
|
patch = {
|
|
563
559
|
syncAction: {
|
|
564
560
|
labelAssociationAction: {
|
|
565
|
-
labeled: false
|
|
561
|
+
labeled: false
|
|
566
562
|
}
|
|
567
563
|
},
|
|
568
564
|
index: [
|
|
569
|
-
|
|
565
|
+
LabelAssociationType.Message,
|
|
570
566
|
mod.removeMessageLabel.labelId,
|
|
571
567
|
jid,
|
|
572
568
|
mod.removeMessageLabel.messageId,
|
|
@@ -575,34 +571,30 @@ const chatModificationToAppPatch = (mod, jid) => {
|
|
|
575
571
|
],
|
|
576
572
|
type: 'regular',
|
|
577
573
|
apiVersion: 3,
|
|
578
|
-
operation: OP.SET
|
|
574
|
+
operation: OP.SET
|
|
579
575
|
};
|
|
580
576
|
}
|
|
581
577
|
else {
|
|
582
|
-
throw new
|
|
578
|
+
throw new Boom('not supported');
|
|
583
579
|
}
|
|
584
580
|
patch.syncAction.timestamp = Date.now();
|
|
585
581
|
return patch;
|
|
586
582
|
};
|
|
587
|
-
|
|
588
|
-
const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) => {
|
|
589
|
-
var _a, _b, _c, _d;
|
|
583
|
+
export const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) => {
|
|
590
584
|
const isInitialSync = !!initialSyncOpts;
|
|
591
|
-
const accountSettings = initialSyncOpts
|
|
592
|
-
logger
|
|
585
|
+
const accountSettings = initialSyncOpts?.accountSettings;
|
|
586
|
+
logger?.trace({ syncAction, initialSync: !!initialSyncOpts }, 'processing sync action');
|
|
593
587
|
const { syncAction: { value: action }, index: [type, id, msgId, fromMe] } = syncAction;
|
|
594
|
-
if (action
|
|
588
|
+
if (action?.muteAction) {
|
|
595
589
|
ev.emit('chats.update', [
|
|
596
590
|
{
|
|
597
591
|
id,
|
|
598
|
-
muteEndTime:
|
|
599
|
-
? (0, generics_1.toNumber)(action.muteAction.muteEndTimestamp)
|
|
600
|
-
: null,
|
|
592
|
+
muteEndTime: action.muteAction?.muted ? toNumber(action.muteAction.muteEndTimestamp) : null,
|
|
601
593
|
conditional: getChatUpdateConditional(id, undefined)
|
|
602
594
|
}
|
|
603
595
|
]);
|
|
604
596
|
}
|
|
605
|
-
else if (
|
|
597
|
+
else if (action?.archiveChatAction || type === 'archive' || type === 'unarchive') {
|
|
606
598
|
// okay so we've to do some annoying computation here
|
|
607
599
|
// when we're initially syncing the app state
|
|
608
600
|
// there are a few cases we need to handle
|
|
@@ -613,36 +605,38 @@ const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) => {
|
|
|
613
605
|
// we compare the timestamp of latest message from the other person to determine this
|
|
614
606
|
// 2. if the account unarchiveChats setting is false -- then it doesn't matter,
|
|
615
607
|
// it'll always take an app state action to mark in unarchived -- which we'll get anyway
|
|
616
|
-
const archiveAction = action
|
|
617
|
-
const isArchived = archiveAction
|
|
618
|
-
? archiveAction.archived
|
|
619
|
-
: type === 'archive';
|
|
608
|
+
const archiveAction = action?.archiveChatAction;
|
|
609
|
+
const isArchived = archiveAction ? archiveAction.archived : type === 'archive';
|
|
620
610
|
// // basically we don't need to fire an "archive" update if the chat is being marked unarchvied
|
|
621
611
|
// // this only applies for the initial sync
|
|
622
612
|
// if(isInitialSync && !isArchived) {
|
|
623
613
|
// isArchived = false
|
|
624
614
|
// }
|
|
625
|
-
const msgRange = !
|
|
615
|
+
const msgRange = !accountSettings?.unarchiveChats ? undefined : archiveAction?.messageRange;
|
|
626
616
|
// logger?.debug({ chat: id, syncAction }, 'message range archive')
|
|
627
|
-
ev.emit('chats.update', [
|
|
617
|
+
ev.emit('chats.update', [
|
|
618
|
+
{
|
|
628
619
|
id,
|
|
629
620
|
archived: isArchived,
|
|
630
621
|
conditional: getChatUpdateConditional(id, msgRange)
|
|
631
|
-
}
|
|
622
|
+
}
|
|
623
|
+
]);
|
|
632
624
|
}
|
|
633
|
-
else if (action
|
|
625
|
+
else if (action?.markChatAsReadAction) {
|
|
634
626
|
const markReadAction = action.markChatAsReadAction;
|
|
635
627
|
// basically we don't need to fire an "read" update if the chat is being marked as read
|
|
636
628
|
// because the chat is read by default
|
|
637
629
|
// this only applies for the initial sync
|
|
638
630
|
const isNullUpdate = isInitialSync && markReadAction.read;
|
|
639
|
-
ev.emit('chats.update', [
|
|
631
|
+
ev.emit('chats.update', [
|
|
632
|
+
{
|
|
640
633
|
id,
|
|
641
|
-
unreadCount: isNullUpdate ? null : !!
|
|
642
|
-
conditional: getChatUpdateConditional(id, markReadAction
|
|
643
|
-
}
|
|
634
|
+
unreadCount: isNullUpdate ? null : !!markReadAction?.read ? 0 : -1,
|
|
635
|
+
conditional: getChatUpdateConditional(id, markReadAction?.messageRange)
|
|
636
|
+
}
|
|
637
|
+
]);
|
|
644
638
|
}
|
|
645
|
-
else if (
|
|
639
|
+
else if (action?.deleteMessageForMeAction || type === 'deleteMessageForMe') {
|
|
646
640
|
ev.emit('messages.delete', {
|
|
647
641
|
keys: [
|
|
648
642
|
{
|
|
@@ -653,32 +647,41 @@ const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) => {
|
|
|
653
647
|
]
|
|
654
648
|
});
|
|
655
649
|
}
|
|
656
|
-
else if (action
|
|
657
|
-
ev.emit('contacts.upsert', [
|
|
650
|
+
else if (action?.contactAction) {
|
|
651
|
+
ev.emit('contacts.upsert', [
|
|
652
|
+
{
|
|
653
|
+
id: id,
|
|
654
|
+
name: action.contactAction.fullName,
|
|
655
|
+
lid: action.contactAction.lidJid || undefined,
|
|
656
|
+
jid: isJidUser(id) ? id : undefined
|
|
657
|
+
}
|
|
658
|
+
]);
|
|
658
659
|
}
|
|
659
|
-
else if (action
|
|
660
|
-
const name =
|
|
661
|
-
if (name &&
|
|
660
|
+
else if (action?.pushNameSetting) {
|
|
661
|
+
const name = action?.pushNameSetting?.name;
|
|
662
|
+
if (name && me?.name !== name) {
|
|
662
663
|
ev.emit('creds.update', { me: { ...me, name } });
|
|
663
664
|
}
|
|
664
665
|
}
|
|
665
|
-
else if (action
|
|
666
|
-
ev.emit('chats.update', [
|
|
666
|
+
else if (action?.pinAction) {
|
|
667
|
+
ev.emit('chats.update', [
|
|
668
|
+
{
|
|
667
669
|
id,
|
|
668
|
-
pinned:
|
|
670
|
+
pinned: action.pinAction?.pinned ? toNumber(action.timestamp) : null,
|
|
669
671
|
conditional: getChatUpdateConditional(id, undefined)
|
|
670
|
-
}
|
|
672
|
+
}
|
|
673
|
+
]);
|
|
671
674
|
}
|
|
672
|
-
else if (action
|
|
675
|
+
else if (action?.unarchiveChatsSetting) {
|
|
673
676
|
const unarchiveChats = !!action.unarchiveChatsSetting.unarchiveChats;
|
|
674
677
|
ev.emit('creds.update', { accountSettings: { unarchiveChats } });
|
|
675
|
-
logger
|
|
678
|
+
logger?.info(`archive setting updated => '${action.unarchiveChatsSetting.unarchiveChats}'`);
|
|
676
679
|
if (accountSettings) {
|
|
677
680
|
accountSettings.unarchiveChats = unarchiveChats;
|
|
678
681
|
}
|
|
679
682
|
}
|
|
680
|
-
else if (
|
|
681
|
-
let starred =
|
|
683
|
+
else if (action?.starAction || type === 'star') {
|
|
684
|
+
let starred = action?.starAction?.starred;
|
|
682
685
|
if (typeof starred !== 'boolean') {
|
|
683
686
|
starred = syncAction.index[syncAction.index.length - 1] === '1';
|
|
684
687
|
}
|
|
@@ -689,34 +692,32 @@ const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) => {
|
|
|
689
692
|
}
|
|
690
693
|
]);
|
|
691
694
|
}
|
|
692
|
-
else if (
|
|
695
|
+
else if (action?.deleteChatAction || type === 'deleteChat') {
|
|
693
696
|
if (!isInitialSync) {
|
|
694
697
|
ev.emit('chats.delete', [id]);
|
|
695
698
|
}
|
|
696
699
|
}
|
|
697
|
-
else if (action
|
|
700
|
+
else if (action?.labelEditAction) {
|
|
698
701
|
const { name, color, deleted, predefinedId } = action.labelEditAction;
|
|
699
702
|
ev.emit('labels.edit', {
|
|
700
|
-
id,
|
|
703
|
+
id: id,
|
|
701
704
|
name: name,
|
|
702
705
|
color: color,
|
|
703
706
|
deleted: deleted,
|
|
704
707
|
predefinedId: predefinedId ? String(predefinedId) : undefined
|
|
705
708
|
});
|
|
706
709
|
}
|
|
707
|
-
else if (action
|
|
710
|
+
else if (action?.labelAssociationAction) {
|
|
708
711
|
ev.emit('labels.association', {
|
|
709
|
-
type: action.labelAssociationAction.labeled
|
|
710
|
-
|
|
711
|
-
: 'remove',
|
|
712
|
-
association: type === LabelAssociation_1.LabelAssociationType.Chat
|
|
712
|
+
type: action.labelAssociationAction.labeled ? 'add' : 'remove',
|
|
713
|
+
association: type === LabelAssociationType.Chat
|
|
713
714
|
? {
|
|
714
|
-
type:
|
|
715
|
+
type: LabelAssociationType.Chat,
|
|
715
716
|
chatId: syncAction.index[2],
|
|
716
717
|
labelId: syncAction.index[1]
|
|
717
718
|
}
|
|
718
719
|
: {
|
|
719
|
-
type:
|
|
720
|
+
type: LabelAssociationType.Message,
|
|
720
721
|
chatId: syncAction.index[2],
|
|
721
722
|
messageId: syncAction.index[3],
|
|
722
723
|
labelId: syncAction.index[1]
|
|
@@ -724,11 +725,11 @@ const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) => {
|
|
|
724
725
|
});
|
|
725
726
|
}
|
|
726
727
|
else {
|
|
727
|
-
logger
|
|
728
|
+
logger?.debug({ syncAction, id }, 'unprocessable update');
|
|
728
729
|
}
|
|
729
730
|
function getChatUpdateConditional(id, msgRange) {
|
|
730
731
|
return isInitialSync
|
|
731
|
-
?
|
|
732
|
+
? data => {
|
|
732
733
|
const chat = data.historySets.chats[id] || data.chatUpserts[id];
|
|
733
734
|
if (chat) {
|
|
734
735
|
return msgRange ? isValidPatchBasedOnMessageRange(chat, msgRange) : true;
|
|
@@ -737,9 +738,9 @@ const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) => {
|
|
|
737
738
|
: undefined;
|
|
738
739
|
}
|
|
739
740
|
function isValidPatchBasedOnMessageRange(chat, msgRange) {
|
|
740
|
-
const lastMsgTimestamp = Number(
|
|
741
|
-
const chatLastMsgTimestamp = Number(
|
|
741
|
+
const lastMsgTimestamp = Number(msgRange?.lastMessageTimestamp || msgRange?.lastSystemMessageTimestamp || 0);
|
|
742
|
+
const chatLastMsgTimestamp = Number(chat?.lastMessageRecvTimestamp || 0);
|
|
742
743
|
return lastMsgTimestamp >= chatLastMsgTimestamp;
|
|
743
744
|
}
|
|
744
745
|
};
|
|
745
|
-
|
|
746
|
+
//# sourceMappingURL=chat-utils.js.map
|