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