@periskope/baileys 6.7.18-alpha.2 → 6.7.18-alpha.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 +1 -1
- package/WAProto/GenerateStatics.sh +3 -0
- package/WAProto/WAProto.proto +4633 -0
- package/WAProto/fix-imports.js +29 -0
- package/WAProto/index.js +4136 -4138
- package/lib/Defaults/index.d.ts +4 -3
- package/lib/Defaults/index.d.ts.map +1 -0
- package/lib/Defaults/index.js +36 -40
- 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 +2 -0
- package/lib/Signal/Group/queue-job.d.ts.map +1 -0
- package/lib/Signal/Group/queue-job.js +54 -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 +37 -57
- 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 +14 -26
- package/lib/Socket/Client/websocket.js.map +1 -0
- package/lib/Socket/business.d.ts +88 -59
- package/lib/Socket/business.d.ts.map +1 -0
- package/lib/Socket/business.js +32 -37
- package/lib/Socket/business.js.map +1 -0
- package/lib/Socket/chats.d.ts +27 -21
- package/lib/Socket/chats.d.ts.map +1 -0
- package/lib/Socket/chats.js +132 -119
- package/lib/Socket/chats.js.map +1 -0
- package/lib/Socket/communities.d.ts +218 -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 +42 -35
- package/lib/Socket/groups.d.ts.map +1 -0
- package/lib/Socket/groups.js +57 -63
- package/lib/Socket/groups.js.map +1 -0
- package/lib/Socket/index.d.ts +124 -65
- package/lib/Socket/index.d.ts.map +1 -0
- package/lib/Socket/index.js +6 -7
- package/lib/Socket/index.js.map +1 -0
- package/lib/Socket/messages-recv.d.ts +74 -45
- package/lib/Socket/messages-recv.d.ts.map +1 -0
- package/lib/Socket/messages-recv.js +294 -164
- package/lib/Socket/messages-recv.js.map +1 -0
- package/lib/Socket/messages-send.d.ts +71 -42
- package/lib/Socket/messages-send.d.ts.map +1 -0
- package/lib/Socket/messages-send.js +100 -83
- 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 +142 -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 +12 -11
- package/lib/Socket/socket.d.ts.map +1 -0
- package/lib/Socket/socket.js +100 -106
- package/lib/Socket/socket.js.map +1 -0
- package/lib/Socket/usync.d.ts +14 -13
- package/lib/Socket/usync.d.ts.map +1 -0
- package/lib/Socket/usync.js +9 -11
- package/lib/Socket/usync.js.map +1 -0
- package/lib/Types/Auth.d.ts +4 -3
- 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 +11 -7
- package/lib/Types/Chat.d.ts.map +1 -0
- package/lib/Types/Chat.js +2 -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 +44 -10
- 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 +3 -1
- 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 +17 -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 +8 -7
- 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 +4 -2
- package/lib/Types/State.d.ts.map +1 -0
- package/lib/Types/State.js +2 -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 +24 -33
- 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 +61 -70
- 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 +141 -139
- 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 +37 -86
- 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 -43
- package/lib/Utils/decode-wa-message.js.map +1 -0
- package/lib/Utils/event-buffer.d.ts +3 -2
- package/lib/Utils/event-buffer.d.ts.map +1 -0
- package/lib/Utils/event-buffer.js +24 -30
- 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 +88 -111
- 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 +11 -48
- package/lib/Utils/link-preview.js.map +1 -0
- package/lib/Utils/logger.d.ts +6 -5
- 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 +21 -24
- 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 +5 -9
- 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 +200 -234
- 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 +217 -199
- 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 +5 -4
- package/lib/Utils/process-message.d.ts.map +1 -0
- package/lib/Utils/process-message.js +125 -130
- 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 +47 -52
- 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 -26
- 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 +55 -61
- 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 +1174 -1176
- 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 +13 -51
- 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 +5 -41
- 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 +30 -38
- 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 -35
- 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 +4 -6
- 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 +12 -14
- 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 +6 -9
- 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 +9 -12
- 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 +7 -10
- 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 +7 -11
- 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 +19 -21
- 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 +2 -5
- 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 +18 -20
- 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 +26 -28
- 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,
|
|
@@ -82,33 +79,32 @@ const makeLtHashGenerator = ({ indexValueMap, hash }) => {
|
|
|
82
79
|
};
|
|
83
80
|
const generateSnapshotMac = (lthash, version, name, key) => {
|
|
84
81
|
const total = Buffer.concat([lthash, to64BitNetworkOrder(version), Buffer.from(name, 'utf-8')]);
|
|
85
|
-
return
|
|
82
|
+
return hmacSign(total, key, 'sha256');
|
|
86
83
|
};
|
|
87
84
|
const generatePatchMac = (snapshotMac, valueMacs, version, type, key) => {
|
|
88
85
|
const total = Buffer.concat([snapshotMac, ...valueMacs, to64BitNetworkOrder(version), Buffer.from(type, 'utf-8')]);
|
|
89
|
-
return
|
|
86
|
+
return hmacSign(total, key);
|
|
90
87
|
};
|
|
91
|
-
const newLTHashState = () => ({ version: 0, hash: Buffer.alloc(128), indexValueMap: {} });
|
|
92
|
-
|
|
93
|
-
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) => {
|
|
94
90
|
const key = !!myAppStateKeyId ? await getAppStateSyncKey(myAppStateKeyId) : undefined;
|
|
95
91
|
if (!key) {
|
|
96
|
-
throw new
|
|
92
|
+
throw new Boom(`myAppStateKey ("${myAppStateKeyId}") not present`, { statusCode: 404 });
|
|
97
93
|
}
|
|
98
94
|
const encKeyId = Buffer.from(myAppStateKeyId, 'base64');
|
|
99
95
|
state = { ...state, indexValueMap: { ...state.indexValueMap } };
|
|
100
96
|
const indexBuffer = Buffer.from(JSON.stringify(index));
|
|
101
|
-
const dataProto =
|
|
97
|
+
const dataProto = proto.SyncActionData.fromObject({
|
|
102
98
|
index: indexBuffer,
|
|
103
99
|
value: syncAction,
|
|
104
100
|
padding: new Uint8Array(0),
|
|
105
101
|
version: apiVersion
|
|
106
102
|
});
|
|
107
|
-
const encoded =
|
|
103
|
+
const encoded = proto.SyncActionData.encode(dataProto).finish();
|
|
108
104
|
const keyValue = await mutationKeys(key.keyData);
|
|
109
|
-
const encValue =
|
|
105
|
+
const encValue = aesEncrypt(encoded, keyValue.valueEncryptionKey);
|
|
110
106
|
const valueMac = generateMac(operation, encValue, encKeyId, keyValue.valueMacKey);
|
|
111
|
-
const indexMac =
|
|
107
|
+
const indexMac = hmacSign(indexBuffer, keyValue.indexKey);
|
|
112
108
|
// update LT hash
|
|
113
109
|
const generator = makeLtHashGenerator(state);
|
|
114
110
|
generator.mix({ indexMac, valueMac, operation });
|
|
@@ -138,8 +134,7 @@ const encodeSyncdPatch = async ({ type, index, syncAction, apiVersion, operation
|
|
|
138
134
|
state.indexValueMap[base64Index] = { valueMac };
|
|
139
135
|
return { patch, state };
|
|
140
136
|
};
|
|
141
|
-
|
|
142
|
-
const decodeSyncdMutations = async (msgMutations, initialState, getAppStateSyncKey, onMutation, validateMacs) => {
|
|
137
|
+
export const decodeSyncdMutations = async (msgMutations, initialState, getAppStateSyncKey, onMutation, validateMacs) => {
|
|
143
138
|
const ltGenerator = makeLtHashGenerator(initialState);
|
|
144
139
|
// indexKey used to HMAC sign record.index.blob
|
|
145
140
|
// valueEncryptionKey used to AES-256-CBC encrypt record.value.blob[0:-32]
|
|
@@ -147,7 +142,7 @@ const decodeSyncdMutations = async (msgMutations, initialState, getAppStateSyncK
|
|
|
147
142
|
for (const msgMutation of msgMutations) {
|
|
148
143
|
// if it's a syncdmutation, get the operation property
|
|
149
144
|
// otherwise, if it's only a record -- it'll be a SET mutation
|
|
150
|
-
const operation = 'operation' in msgMutation ? msgMutation.operation :
|
|
145
|
+
const operation = 'operation' in msgMutation ? msgMutation.operation : proto.SyncdMutation.SyncdOperation.SET;
|
|
151
146
|
const record = 'record' in msgMutation && !!msgMutation.record ? msgMutation.record : msgMutation;
|
|
152
147
|
const key = await getKey(record.keyId.id);
|
|
153
148
|
const content = Buffer.from(record.value.blob);
|
|
@@ -156,15 +151,15 @@ const decodeSyncdMutations = async (msgMutations, initialState, getAppStateSyncK
|
|
|
156
151
|
if (validateMacs) {
|
|
157
152
|
const contentHmac = generateMac(operation, encContent, record.keyId.id, key.valueMacKey);
|
|
158
153
|
if (Buffer.compare(contentHmac, ogValueMac) !== 0) {
|
|
159
|
-
throw new
|
|
154
|
+
throw new Boom('HMAC content verification failed');
|
|
160
155
|
}
|
|
161
156
|
}
|
|
162
|
-
const result =
|
|
163
|
-
const syncAction =
|
|
157
|
+
const result = aesDecrypt(encContent, key.valueEncryptionKey);
|
|
158
|
+
const syncAction = proto.SyncActionData.decode(result);
|
|
164
159
|
if (validateMacs) {
|
|
165
|
-
const hmac =
|
|
160
|
+
const hmac = hmacSign(syncAction.index, key.indexKey);
|
|
166
161
|
if (Buffer.compare(hmac, record.index.blob) !== 0) {
|
|
167
|
-
throw new
|
|
162
|
+
throw new Boom('HMAC index verification failed');
|
|
168
163
|
}
|
|
169
164
|
}
|
|
170
165
|
const indexStr = Buffer.from(syncAction.index).toString();
|
|
@@ -180,7 +175,7 @@ const decodeSyncdMutations = async (msgMutations, initialState, getAppStateSyncK
|
|
|
180
175
|
const base64Key = Buffer.from(keyId).toString('base64');
|
|
181
176
|
const keyEnc = await getAppStateSyncKey(base64Key);
|
|
182
177
|
if (!keyEnc) {
|
|
183
|
-
throw new
|
|
178
|
+
throw new Boom(`failed to find key "${base64Key}" to decode mutation`, {
|
|
184
179
|
statusCode: 404,
|
|
185
180
|
data: { msgMutations }
|
|
186
181
|
});
|
|
@@ -188,33 +183,31 @@ const decodeSyncdMutations = async (msgMutations, initialState, getAppStateSyncK
|
|
|
188
183
|
return mutationKeys(keyEnc.keyData);
|
|
189
184
|
}
|
|
190
185
|
};
|
|
191
|
-
|
|
192
|
-
const decodeSyncdPatch = async (msg, name, initialState, getAppStateSyncKey, onMutation, validateMacs) => {
|
|
186
|
+
export const decodeSyncdPatch = async (msg, name, initialState, getAppStateSyncKey, onMutation, validateMacs) => {
|
|
193
187
|
if (validateMacs) {
|
|
194
188
|
const base64Key = Buffer.from(msg.keyId.id).toString('base64');
|
|
195
189
|
const mainKeyObj = await getAppStateSyncKey(base64Key);
|
|
196
190
|
if (!mainKeyObj) {
|
|
197
|
-
throw new
|
|
191
|
+
throw new Boom(`failed to find key "${base64Key}" to decode patch`, { statusCode: 404, data: { msg } });
|
|
198
192
|
}
|
|
199
193
|
const mainKey = await mutationKeys(mainKeyObj.keyData);
|
|
200
194
|
const mutationmacs = msg.mutations.map(mutation => mutation.record.value.blob.slice(-32));
|
|
201
|
-
const patchMac = generatePatchMac(msg.snapshotMac, mutationmacs,
|
|
195
|
+
const patchMac = generatePatchMac(msg.snapshotMac, mutationmacs, toNumber(msg.version.version), name, mainKey.patchMacKey);
|
|
202
196
|
if (Buffer.compare(patchMac, msg.patchMac) !== 0) {
|
|
203
|
-
throw new
|
|
197
|
+
throw new Boom('Invalid patch mac');
|
|
204
198
|
}
|
|
205
199
|
}
|
|
206
|
-
const result = await
|
|
200
|
+
const result = await decodeSyncdMutations(msg.mutations, initialState, getAppStateSyncKey, onMutation, validateMacs);
|
|
207
201
|
return result;
|
|
208
202
|
};
|
|
209
|
-
|
|
210
|
-
const
|
|
211
|
-
const
|
|
212
|
-
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');
|
|
213
206
|
const final = {};
|
|
214
207
|
await Promise.all(collectionNodes.map(async (collectionNode) => {
|
|
215
|
-
const patchesNode =
|
|
216
|
-
const patches =
|
|
217
|
-
const snapshotNode =
|
|
208
|
+
const patchesNode = getBinaryNodeChild(collectionNode, 'patches');
|
|
209
|
+
const patches = getBinaryNodeChildren(patchesNode || collectionNode, 'patch');
|
|
210
|
+
const snapshotNode = getBinaryNodeChild(collectionNode, 'snapshot');
|
|
218
211
|
const syncds = [];
|
|
219
212
|
const name = collectionNode.attrs.name;
|
|
220
213
|
const hasMorePatches = collectionNode.attrs.has_more_patches === 'true';
|
|
@@ -223,16 +216,16 @@ const extractSyncdPatches = async (result, options) => {
|
|
|
223
216
|
if (!Buffer.isBuffer(snapshotNode)) {
|
|
224
217
|
snapshotNode.content = Buffer.from(Object.values(snapshotNode.content));
|
|
225
218
|
}
|
|
226
|
-
const blobRef =
|
|
227
|
-
const data = await
|
|
228
|
-
snapshot =
|
|
219
|
+
const blobRef = proto.ExternalBlobReference.decode(snapshotNode.content);
|
|
220
|
+
const data = await downloadExternalBlob(blobRef, options);
|
|
221
|
+
snapshot = proto.SyncdSnapshot.decode(data);
|
|
229
222
|
}
|
|
230
223
|
for (let { content } of patches) {
|
|
231
224
|
if (content) {
|
|
232
225
|
if (!Buffer.isBuffer(content)) {
|
|
233
226
|
content = Buffer.from(Object.values(content));
|
|
234
227
|
}
|
|
235
|
-
const syncd =
|
|
228
|
+
const syncd = proto.SyncdPatch.decode(content);
|
|
236
229
|
if (!syncd.version) {
|
|
237
230
|
syncd.version = { version: +collectionNode.attrs.version + 1 };
|
|
238
231
|
}
|
|
@@ -243,31 +236,27 @@ const extractSyncdPatches = async (result, options) => {
|
|
|
243
236
|
}));
|
|
244
237
|
return final;
|
|
245
238
|
};
|
|
246
|
-
|
|
247
|
-
const
|
|
248
|
-
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 });
|
|
249
241
|
const bufferArray = [];
|
|
250
242
|
for await (const chunk of stream) {
|
|
251
243
|
bufferArray.push(chunk);
|
|
252
244
|
}
|
|
253
245
|
return Buffer.concat(bufferArray);
|
|
254
246
|
};
|
|
255
|
-
|
|
256
|
-
const
|
|
257
|
-
const
|
|
258
|
-
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);
|
|
259
250
|
return syncData;
|
|
260
251
|
};
|
|
261
|
-
|
|
262
|
-
const
|
|
263
|
-
|
|
264
|
-
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);
|
|
265
255
|
const mutationMap = {};
|
|
266
256
|
const areMutationsRequired = typeof minimumVersionNumber === 'undefined' || newState.version > minimumVersionNumber;
|
|
267
|
-
const { hash, indexValueMap } = await
|
|
257
|
+
const { hash, indexValueMap } = await decodeSyncdMutations(snapshot.records, newState, getAppStateSyncKey, areMutationsRequired
|
|
268
258
|
? mutation => {
|
|
269
|
-
|
|
270
|
-
const index = (_a = mutation.syncAction.index) === null || _a === void 0 ? void 0 : _a.toString();
|
|
259
|
+
const index = mutation.syncAction.index?.toString();
|
|
271
260
|
mutationMap[index] = mutation;
|
|
272
261
|
}
|
|
273
262
|
: () => { }, validateMacs);
|
|
@@ -277,12 +266,12 @@ const decodeSyncdSnapshot = async (name, snapshot, getAppStateSyncKey, minimumVe
|
|
|
277
266
|
const base64Key = Buffer.from(snapshot.keyId.id).toString('base64');
|
|
278
267
|
const keyEnc = await getAppStateSyncKey(base64Key);
|
|
279
268
|
if (!keyEnc) {
|
|
280
|
-
throw new
|
|
269
|
+
throw new Boom(`failed to find key "${base64Key}" to decode mutation`);
|
|
281
270
|
}
|
|
282
271
|
const result = await mutationKeys(keyEnc.keyData);
|
|
283
272
|
const computedSnapshotMac = generateSnapshotMac(newState.hash, newState.version, name, result.snapshotMacKey);
|
|
284
273
|
if (Buffer.compare(snapshot.mac, computedSnapshotMac) !== 0) {
|
|
285
|
-
throw new
|
|
274
|
+
throw new Boom(`failed to verify LTHash at ${newState.version} of ${name} from snapshot`);
|
|
286
275
|
}
|
|
287
276
|
}
|
|
288
277
|
return {
|
|
@@ -290,9 +279,7 @@ const decodeSyncdSnapshot = async (name, snapshot, getAppStateSyncKey, minimumVe
|
|
|
290
279
|
mutationMap
|
|
291
280
|
};
|
|
292
281
|
};
|
|
293
|
-
|
|
294
|
-
const decodePatches = async (name, syncds, initial, getAppStateSyncKey, options, minimumVersionNumber, logger, validateMacs = true) => {
|
|
295
|
-
var _a;
|
|
282
|
+
export const decodePatches = async (name, syncds, initial, getAppStateSyncKey, options, minimumVersionNumber, logger, validateMacs = true) => {
|
|
296
283
|
const newState = {
|
|
297
284
|
...initial,
|
|
298
285
|
indexValueMap: { ...initial.indexValueMap }
|
|
@@ -301,18 +288,17 @@ const decodePatches = async (name, syncds, initial, getAppStateSyncKey, options,
|
|
|
301
288
|
for (const syncd of syncds) {
|
|
302
289
|
const { version, keyId, snapshotMac } = syncd;
|
|
303
290
|
if (syncd.externalMutations) {
|
|
304
|
-
logger
|
|
305
|
-
const ref = await
|
|
306
|
-
logger
|
|
307
|
-
|
|
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);
|
|
308
295
|
}
|
|
309
|
-
const patchVersion =
|
|
296
|
+
const patchVersion = toNumber(version.version);
|
|
310
297
|
newState.version = patchVersion;
|
|
311
298
|
const shouldMutate = typeof minimumVersionNumber === 'undefined' || patchVersion > minimumVersionNumber;
|
|
312
|
-
const decodeResult = await
|
|
299
|
+
const decodeResult = await decodeSyncdPatch(syncd, name, newState, getAppStateSyncKey, shouldMutate
|
|
313
300
|
? mutation => {
|
|
314
|
-
|
|
315
|
-
const index = (_a = mutation.syncAction.index) === null || _a === void 0 ? void 0 : _a.toString();
|
|
301
|
+
const index = mutation.syncAction.index?.toString();
|
|
316
302
|
mutationMap[index] = mutation;
|
|
317
303
|
}
|
|
318
304
|
: () => { }, true);
|
|
@@ -322,12 +308,12 @@ const decodePatches = async (name, syncds, initial, getAppStateSyncKey, options,
|
|
|
322
308
|
const base64Key = Buffer.from(keyId.id).toString('base64');
|
|
323
309
|
const keyEnc = await getAppStateSyncKey(base64Key);
|
|
324
310
|
if (!keyEnc) {
|
|
325
|
-
throw new
|
|
311
|
+
throw new Boom(`failed to find key "${base64Key}" to decode mutation`);
|
|
326
312
|
}
|
|
327
313
|
const result = await mutationKeys(keyEnc.keyData);
|
|
328
314
|
const computedSnapshotMac = generateSnapshotMac(newState.hash, newState.version, name, result.snapshotMacKey);
|
|
329
315
|
if (Buffer.compare(snapshotMac, computedSnapshotMac) !== 0) {
|
|
330
|
-
throw new
|
|
316
|
+
throw new Boom(`failed to verify LTHash at ${newState.version} of ${name}`);
|
|
331
317
|
}
|
|
332
318
|
}
|
|
333
319
|
// clear memory used up by the mutations
|
|
@@ -335,29 +321,27 @@ const decodePatches = async (name, syncds, initial, getAppStateSyncKey, options,
|
|
|
335
321
|
}
|
|
336
322
|
return { state: newState, mutationMap };
|
|
337
323
|
};
|
|
338
|
-
|
|
339
|
-
const
|
|
340
|
-
const OP = WAProto_1.proto.SyncdMutation.SyncdOperation;
|
|
324
|
+
export const chatModificationToAppPatch = (mod, jid) => {
|
|
325
|
+
const OP = proto.SyncdMutation.SyncdOperation;
|
|
341
326
|
const getMessageRange = (lastMessages) => {
|
|
342
327
|
let messageRange;
|
|
343
328
|
if (Array.isArray(lastMessages)) {
|
|
344
329
|
const lastMsg = lastMessages[lastMessages.length - 1];
|
|
345
330
|
messageRange = {
|
|
346
|
-
lastMessageTimestamp: lastMsg
|
|
347
|
-
messages:
|
|
331
|
+
lastMessageTimestamp: lastMsg?.messageTimestamp,
|
|
332
|
+
messages: lastMessages?.length
|
|
348
333
|
? lastMessages.map(m => {
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
throw new boom_1.Boom('Incomplete key', { statusCode: 400, data: m });
|
|
334
|
+
if (!m.key?.id || !m.key?.remoteJid) {
|
|
335
|
+
throw new Boom('Incomplete key', { statusCode: 400, data: m });
|
|
352
336
|
}
|
|
353
|
-
if (
|
|
354
|
-
throw new
|
|
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 });
|
|
355
339
|
}
|
|
356
|
-
if (!m.messageTimestamp || !
|
|
357
|
-
throw new
|
|
340
|
+
if (!m.messageTimestamp || !toNumber(m.messageTimestamp)) {
|
|
341
|
+
throw new Boom('Missing timestamp in last message list', { statusCode: 400, data: m });
|
|
358
342
|
}
|
|
359
343
|
if (m.key.participant) {
|
|
360
|
-
m.key.participant =
|
|
344
|
+
m.key.participant = jidNormalizedUser(m.key.participant);
|
|
361
345
|
}
|
|
362
346
|
return m;
|
|
363
347
|
})
|
|
@@ -430,7 +414,9 @@ const chatModificationToAppPatch = (mod, jid) => {
|
|
|
430
414
|
else if ('clear' in mod) {
|
|
431
415
|
patch = {
|
|
432
416
|
syncAction: {
|
|
433
|
-
clearChatAction: {
|
|
417
|
+
clearChatAction: {
|
|
418
|
+
messageRange: getMessageRange(mod.lastMessages)
|
|
419
|
+
}
|
|
434
420
|
},
|
|
435
421
|
index: ['clearChat', jid, '1' /*the option here is 0 when keep starred messages is enabled*/, '0'],
|
|
436
422
|
type: 'regular_high',
|
|
@@ -451,6 +437,17 @@ const chatModificationToAppPatch = (mod, jid) => {
|
|
|
451
437
|
operation: OP.SET
|
|
452
438
|
};
|
|
453
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
|
+
}
|
|
454
451
|
else if ('star' in mod) {
|
|
455
452
|
const key = mod.star.messages[0];
|
|
456
453
|
patch = {
|
|
@@ -514,7 +511,7 @@ const chatModificationToAppPatch = (mod, jid) => {
|
|
|
514
511
|
labeled: true
|
|
515
512
|
}
|
|
516
513
|
},
|
|
517
|
-
index: [
|
|
514
|
+
index: [LabelAssociationType.Chat, mod.addChatLabel.labelId, jid],
|
|
518
515
|
type: 'regular',
|
|
519
516
|
apiVersion: 3,
|
|
520
517
|
operation: OP.SET
|
|
@@ -527,7 +524,7 @@ const chatModificationToAppPatch = (mod, jid) => {
|
|
|
527
524
|
labeled: false
|
|
528
525
|
}
|
|
529
526
|
},
|
|
530
|
-
index: [
|
|
527
|
+
index: [LabelAssociationType.Chat, mod.removeChatLabel.labelId, jid],
|
|
531
528
|
type: 'regular',
|
|
532
529
|
apiVersion: 3,
|
|
533
530
|
operation: OP.SET
|
|
@@ -540,7 +537,7 @@ const chatModificationToAppPatch = (mod, jid) => {
|
|
|
540
537
|
labeled: true
|
|
541
538
|
}
|
|
542
539
|
},
|
|
543
|
-
index: [
|
|
540
|
+
index: [LabelAssociationType.Message, mod.addMessageLabel.labelId, jid, mod.addMessageLabel.messageId, '0', '0'],
|
|
544
541
|
type: 'regular',
|
|
545
542
|
apiVersion: 3,
|
|
546
543
|
operation: OP.SET
|
|
@@ -554,7 +551,7 @@ const chatModificationToAppPatch = (mod, jid) => {
|
|
|
554
551
|
}
|
|
555
552
|
},
|
|
556
553
|
index: [
|
|
557
|
-
|
|
554
|
+
LabelAssociationType.Message,
|
|
558
555
|
mod.removeMessageLabel.labelId,
|
|
559
556
|
jid,
|
|
560
557
|
mod.removeMessageLabel.messageId,
|
|
@@ -567,28 +564,26 @@ const chatModificationToAppPatch = (mod, jid) => {
|
|
|
567
564
|
};
|
|
568
565
|
}
|
|
569
566
|
else {
|
|
570
|
-
throw new
|
|
567
|
+
throw new Boom('not supported');
|
|
571
568
|
}
|
|
572
569
|
patch.syncAction.timestamp = Date.now();
|
|
573
570
|
return patch;
|
|
574
571
|
};
|
|
575
|
-
|
|
576
|
-
const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) => {
|
|
577
|
-
var _a, _b, _c, _d;
|
|
572
|
+
export const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) => {
|
|
578
573
|
const isInitialSync = !!initialSyncOpts;
|
|
579
|
-
const accountSettings = initialSyncOpts
|
|
580
|
-
logger
|
|
574
|
+
const accountSettings = initialSyncOpts?.accountSettings;
|
|
575
|
+
logger?.trace({ syncAction, initialSync: !!initialSyncOpts }, 'processing sync action');
|
|
581
576
|
const { syncAction: { value: action }, index: [type, id, msgId, fromMe] } = syncAction;
|
|
582
|
-
if (action
|
|
577
|
+
if (action?.muteAction) {
|
|
583
578
|
ev.emit('chats.update', [
|
|
584
579
|
{
|
|
585
580
|
id,
|
|
586
|
-
muteEndTime:
|
|
581
|
+
muteEndTime: action.muteAction?.muted ? toNumber(action.muteAction.muteEndTimestamp) : null,
|
|
587
582
|
conditional: getChatUpdateConditional(id, undefined)
|
|
588
583
|
}
|
|
589
584
|
]);
|
|
590
585
|
}
|
|
591
|
-
else if (
|
|
586
|
+
else if (action?.archiveChatAction || type === 'archive' || type === 'unarchive') {
|
|
592
587
|
// okay so we've to do some annoying computation here
|
|
593
588
|
// when we're initially syncing the app state
|
|
594
589
|
// there are a few cases we need to handle
|
|
@@ -599,14 +594,14 @@ const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) => {
|
|
|
599
594
|
// we compare the timestamp of latest message from the other person to determine this
|
|
600
595
|
// 2. if the account unarchiveChats setting is false -- then it doesn't matter,
|
|
601
596
|
// it'll always take an app state action to mark in unarchived -- which we'll get anyway
|
|
602
|
-
const archiveAction = action
|
|
597
|
+
const archiveAction = action?.archiveChatAction;
|
|
603
598
|
const isArchived = archiveAction ? archiveAction.archived : type === 'archive';
|
|
604
599
|
// // basically we don't need to fire an "archive" update if the chat is being marked unarchvied
|
|
605
600
|
// // this only applies for the initial sync
|
|
606
601
|
// if(isInitialSync && !isArchived) {
|
|
607
602
|
// isArchived = false
|
|
608
603
|
// }
|
|
609
|
-
const msgRange = !
|
|
604
|
+
const msgRange = !accountSettings?.unarchiveChats ? undefined : archiveAction?.messageRange;
|
|
610
605
|
// logger?.debug({ chat: id, syncAction }, 'message range archive')
|
|
611
606
|
ev.emit('chats.update', [
|
|
612
607
|
{
|
|
@@ -616,7 +611,7 @@ const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) => {
|
|
|
616
611
|
}
|
|
617
612
|
]);
|
|
618
613
|
}
|
|
619
|
-
else if (action
|
|
614
|
+
else if (action?.markChatAsReadAction) {
|
|
620
615
|
const markReadAction = action.markChatAsReadAction;
|
|
621
616
|
// basically we don't need to fire an "read" update if the chat is being marked as read
|
|
622
617
|
// because the chat is read by default
|
|
@@ -625,12 +620,12 @@ const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) => {
|
|
|
625
620
|
ev.emit('chats.update', [
|
|
626
621
|
{
|
|
627
622
|
id,
|
|
628
|
-
unreadCount: isNullUpdate ? null : !!
|
|
629
|
-
conditional: getChatUpdateConditional(id, markReadAction
|
|
623
|
+
unreadCount: isNullUpdate ? null : !!markReadAction?.read ? 0 : -1,
|
|
624
|
+
conditional: getChatUpdateConditional(id, markReadAction?.messageRange)
|
|
630
625
|
}
|
|
631
626
|
]);
|
|
632
627
|
}
|
|
633
|
-
else if (
|
|
628
|
+
else if (action?.deleteMessageForMeAction || type === 'deleteMessageForMe') {
|
|
634
629
|
ev.emit('messages.delete', {
|
|
635
630
|
keys: [
|
|
636
631
|
{
|
|
@@ -641,34 +636,41 @@ const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) => {
|
|
|
641
636
|
]
|
|
642
637
|
});
|
|
643
638
|
}
|
|
644
|
-
else if (action
|
|
645
|
-
ev.emit('contacts.upsert', [
|
|
639
|
+
else if (action?.contactAction) {
|
|
640
|
+
ev.emit('contacts.upsert', [
|
|
641
|
+
{
|
|
642
|
+
id: id,
|
|
643
|
+
name: action.contactAction.fullName,
|
|
644
|
+
lid: action.contactAction.lidJid || undefined,
|
|
645
|
+
jid: isJidUser(id) ? id : undefined
|
|
646
|
+
}
|
|
647
|
+
]);
|
|
646
648
|
}
|
|
647
|
-
else if (action
|
|
648
|
-
const name =
|
|
649
|
-
if (name &&
|
|
649
|
+
else if (action?.pushNameSetting) {
|
|
650
|
+
const name = action?.pushNameSetting?.name;
|
|
651
|
+
if (name && me?.name !== name) {
|
|
650
652
|
ev.emit('creds.update', { me: { ...me, name } });
|
|
651
653
|
}
|
|
652
654
|
}
|
|
653
|
-
else if (action
|
|
655
|
+
else if (action?.pinAction) {
|
|
654
656
|
ev.emit('chats.update', [
|
|
655
657
|
{
|
|
656
658
|
id,
|
|
657
|
-
pinned:
|
|
659
|
+
pinned: action.pinAction?.pinned ? toNumber(action.timestamp) : null,
|
|
658
660
|
conditional: getChatUpdateConditional(id, undefined)
|
|
659
661
|
}
|
|
660
662
|
]);
|
|
661
663
|
}
|
|
662
|
-
else if (action
|
|
664
|
+
else if (action?.unarchiveChatsSetting) {
|
|
663
665
|
const unarchiveChats = !!action.unarchiveChatsSetting.unarchiveChats;
|
|
664
666
|
ev.emit('creds.update', { accountSettings: { unarchiveChats } });
|
|
665
|
-
logger
|
|
667
|
+
logger?.info(`archive setting updated => '${action.unarchiveChatsSetting.unarchiveChats}'`);
|
|
666
668
|
if (accountSettings) {
|
|
667
669
|
accountSettings.unarchiveChats = unarchiveChats;
|
|
668
670
|
}
|
|
669
671
|
}
|
|
670
|
-
else if (
|
|
671
|
-
let starred =
|
|
672
|
+
else if (action?.starAction || type === 'star') {
|
|
673
|
+
let starred = action?.starAction?.starred;
|
|
672
674
|
if (typeof starred !== 'boolean') {
|
|
673
675
|
starred = syncAction.index[syncAction.index.length - 1] === '1';
|
|
674
676
|
}
|
|
@@ -679,43 +681,43 @@ const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) => {
|
|
|
679
681
|
}
|
|
680
682
|
]);
|
|
681
683
|
}
|
|
682
|
-
else if (
|
|
684
|
+
else if (action?.deleteChatAction || type === 'deleteChat') {
|
|
683
685
|
if (!isInitialSync) {
|
|
684
686
|
ev.emit('chats.delete', [id]);
|
|
685
687
|
}
|
|
686
688
|
}
|
|
687
|
-
else if (action
|
|
689
|
+
else if (action?.labelEditAction) {
|
|
688
690
|
const { name, color, deleted, predefinedId } = action.labelEditAction;
|
|
689
691
|
ev.emit('labels.edit', {
|
|
690
|
-
id,
|
|
692
|
+
id: id,
|
|
691
693
|
name: name,
|
|
692
694
|
color: color,
|
|
693
695
|
deleted: deleted,
|
|
694
696
|
predefinedId: predefinedId ? String(predefinedId) : undefined
|
|
695
697
|
});
|
|
696
698
|
}
|
|
697
|
-
else if (action
|
|
699
|
+
else if (action?.labelAssociationAction) {
|
|
698
700
|
ev.emit('labels.association', {
|
|
699
701
|
type: action.labelAssociationAction.labeled ? 'add' : 'remove',
|
|
700
|
-
association: type ===
|
|
702
|
+
association: type === LabelAssociationType.Chat
|
|
701
703
|
? {
|
|
702
|
-
type:
|
|
704
|
+
type: LabelAssociationType.Chat,
|
|
703
705
|
chatId: syncAction.index[2],
|
|
704
706
|
labelId: syncAction.index[1]
|
|
705
707
|
}
|
|
706
708
|
: {
|
|
707
|
-
type:
|
|
709
|
+
type: LabelAssociationType.Message,
|
|
708
710
|
chatId: syncAction.index[2],
|
|
709
711
|
messageId: syncAction.index[3],
|
|
710
712
|
labelId: syncAction.index[1]
|
|
711
713
|
}
|
|
712
714
|
});
|
|
713
715
|
}
|
|
714
|
-
else if (action
|
|
716
|
+
else if (action?.callLogAction) {
|
|
715
717
|
ev.emit('call.outgoing', action.callLogAction);
|
|
716
718
|
}
|
|
717
719
|
else {
|
|
718
|
-
logger
|
|
720
|
+
logger?.debug({ syncAction, id }, 'unprocessable update');
|
|
719
721
|
}
|
|
720
722
|
function getChatUpdateConditional(id, msgRange) {
|
|
721
723
|
return isInitialSync
|
|
@@ -728,9 +730,9 @@ const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) => {
|
|
|
728
730
|
: undefined;
|
|
729
731
|
}
|
|
730
732
|
function isValidPatchBasedOnMessageRange(chat, msgRange) {
|
|
731
|
-
const lastMsgTimestamp = Number(
|
|
732
|
-
const chatLastMsgTimestamp = Number(
|
|
733
|
+
const lastMsgTimestamp = Number(msgRange?.lastMessageTimestamp || msgRange?.lastSystemMessageTimestamp || 0);
|
|
734
|
+
const chatLastMsgTimestamp = Number(chat?.lastMessageRecvTimestamp || 0);
|
|
733
735
|
return lastMsgTimestamp >= chatLastMsgTimestamp;
|
|
734
736
|
}
|
|
735
737
|
};
|
|
736
|
-
|
|
738
|
+
//# sourceMappingURL=chat-utils.js.map
|