@d0v3riz/baileys 6.7.19 → 6.7.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1263 -4
- package/WAProto/GenerateStatics.sh +2 -0
- package/WAProto/WAProto.proto +4633 -0
- package/WAProto/index.d.ts +3212 -122
- package/WAProto/index.js +9635 -299
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.d.ts +1 -1
- package/lib/Defaults/index.js +16 -16
- package/lib/Signal/Group/ciphertext-message.d.ts +9 -0
- package/lib/Signal/Group/ciphertext-message.js +15 -0
- package/lib/Signal/Group/group-session-builder.d.ts +14 -0
- package/lib/Signal/Group/group-session-builder.js +64 -0
- package/lib/Signal/Group/group_cipher.d.ts +17 -0
- package/lib/Signal/Group/group_cipher.js +96 -0
- package/lib/Signal/Group/index.d.ts +11 -0
- package/lib/Signal/Group/index.js +57 -0
- package/lib/Signal/Group/keyhelper.d.ts +10 -0
- package/lib/Signal/Group/keyhelper.js +55 -0
- package/lib/Signal/Group/queue-job.d.ts +1 -0
- package/lib/Signal/Group/queue-job.js +57 -0
- package/lib/Signal/Group/sender-chain-key.d.ts +13 -0
- package/lib/Signal/Group/sender-chain-key.js +34 -0
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +66 -0
- package/lib/Signal/Group/sender-key-message.d.ts +18 -0
- package/lib/Signal/Group/sender-key-message.js +69 -0
- package/lib/Signal/Group/sender-key-name.d.ts +17 -0
- package/lib/Signal/Group/sender-key-name.js +51 -0
- package/lib/Signal/Group/sender-key-record.d.ts +30 -0
- package/lib/Signal/Group/sender-key-record.js +53 -0
- package/lib/Signal/Group/sender-key-state.d.ts +38 -0
- package/lib/Signal/Group/sender-key-state.js +99 -0
- package/lib/Signal/Group/sender-message-key.d.ts +11 -0
- package/{WASignalGroup/sender_message_key.js → lib/Signal/Group/sender-message-key.js} +29 -39
- package/lib/Signal/libsignal.js +33 -20
- package/lib/Socket/Client/websocket.js +1 -1
- package/lib/Socket/business.d.ts +5 -5
- package/lib/Socket/business.js +5 -5
- package/lib/Socket/chats.d.ts +4 -4
- package/lib/Socket/chats.js +70 -70
- package/lib/Socket/groups.d.ts +6 -6
- package/lib/Socket/groups.js +39 -24
- package/lib/Socket/index.d.ts +5 -5
- package/lib/Socket/index.js +2 -2
- package/lib/Socket/messages-recv.d.ts +5 -5
- package/lib/Socket/messages-recv.js +73 -56
- package/lib/Socket/messages-send.d.ts +5 -5
- package/lib/Socket/messages-send.js +53 -46
- package/lib/Socket/socket.d.ts +3 -3
- package/lib/Socket/socket.js +22 -29
- package/lib/Socket/usync.d.ts +3 -3
- package/lib/Socket/usync.js +10 -15
- package/lib/Types/Auth.d.ts +1 -1
- package/lib/Types/Chat.d.ts +1 -1
- package/lib/Types/Chat.js +7 -1
- package/lib/Types/Contact.d.ts +4 -0
- package/lib/Types/Events.d.ts +1 -1
- package/lib/Types/GroupMetadata.d.ts +7 -3
- package/lib/Types/Message.d.ts +6 -1
- package/lib/Types/Socket.d.ts +3 -3
- package/lib/Utils/auth-utils.js +8 -9
- package/lib/Utils/baileys-event-stream.js +1 -1
- package/lib/Utils/business.js +9 -11
- package/lib/Utils/chat-utils.d.ts +4 -4
- package/lib/Utils/chat-utils.js +64 -69
- package/lib/Utils/crypto.js +4 -10
- package/lib/Utils/decode-wa-message.js +6 -2
- package/lib/Utils/event-buffer.d.ts +2 -2
- package/lib/Utils/event-buffer.js +9 -13
- package/lib/Utils/generics.d.ts +1 -1
- package/lib/Utils/generics.js +28 -30
- package/lib/Utils/history.js +10 -5
- package/lib/Utils/link-preview.js +5 -9
- package/lib/Utils/lt-hash.js +2 -2
- package/lib/Utils/make-mutex.js +1 -1
- package/lib/Utils/messages-media.js +40 -55
- package/lib/Utils/messages.d.ts +1 -1
- package/lib/Utils/messages.js +71 -61
- package/lib/Utils/process-message.d.ts +1 -1
- package/lib/Utils/process-message.js +25 -30
- package/lib/Utils/signal.js +9 -7
- package/lib/Utils/use-multi-file-auth-state.js +2 -3
- package/lib/Utils/validate-connection.js +17 -22
- package/lib/WABinary/constants.d.ts +4 -4
- package/lib/WABinary/constants.js +1271 -8
- package/lib/WABinary/decode.js +2 -1
- package/lib/WABinary/encode.js +2 -2
- package/lib/WABinary/generic-utils.js +1 -1
- package/lib/WABinary/jid-utils.js +8 -11
- package/lib/WAM/constants.js +2252 -2359
- package/lib/WAM/encode.js +5 -7
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +2 -2
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +2 -2
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +2 -2
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +5 -5
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +1 -1
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +1 -1
- package/lib/WAUSync/USyncQuery.js +17 -13
- package/package.json +11 -6
- 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/auth-utils.js
CHANGED
|
@@ -17,11 +17,12 @@ const generics_1 = require("./generics");
|
|
|
17
17
|
* @param _cache cache store to use
|
|
18
18
|
*/
|
|
19
19
|
function makeCacheableSignalKeyStore(store, logger, _cache) {
|
|
20
|
-
const cache = _cache ||
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
const cache = _cache ||
|
|
21
|
+
new node_cache_1.default({
|
|
22
|
+
stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.SIGNAL_STORE, // 5 minutes
|
|
23
|
+
useClones: false,
|
|
24
|
+
deleteOnExpire: true
|
|
25
|
+
});
|
|
25
26
|
function getUniqueId(type, id) {
|
|
26
27
|
return `${type}.${id}`;
|
|
27
28
|
}
|
|
@@ -87,9 +88,7 @@ const addTransactionCapability = (state, logger, { maxCommitRetries, delayBetwee
|
|
|
87
88
|
get: async (type, ids) => {
|
|
88
89
|
if (isInTransaction()) {
|
|
89
90
|
const dict = transactionCache[type];
|
|
90
|
-
const idsRequiringFetch = dict
|
|
91
|
-
? ids.filter(item => typeof dict[item] === 'undefined')
|
|
92
|
-
: ids;
|
|
91
|
+
const idsRequiringFetch = dict ? ids.filter(item => typeof dict[item] === 'undefined') : ids;
|
|
93
92
|
// only fetch if there are any items to fetch
|
|
94
93
|
if (idsRequiringFetch.length) {
|
|
95
94
|
dbQueriesInTransaction += 1;
|
|
@@ -194,7 +193,7 @@ const initAuthCreds = () => {
|
|
|
194
193
|
registered: false,
|
|
195
194
|
pairingCode: undefined,
|
|
196
195
|
lastPropHash: undefined,
|
|
197
|
-
routingInfo: undefined
|
|
196
|
+
routingInfo: undefined
|
|
198
197
|
};
|
|
199
198
|
};
|
|
200
199
|
exports.initAuthCreds = initAuthCreds;
|
|
@@ -50,7 +50,7 @@ const readAndEmitEventStream = (filename, delayIntervalMs = 0) => {
|
|
|
50
50
|
if (line) {
|
|
51
51
|
const { event, data } = JSON.parse(line);
|
|
52
52
|
ev.emit(event, data);
|
|
53
|
-
delayIntervalMs && await (0, generics_1.delay)(delayIntervalMs);
|
|
53
|
+
delayIntervalMs && (await (0, generics_1.delay)(delayIntervalMs));
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
fileStream.close();
|
package/lib/Utils/business.js
CHANGED
|
@@ -16,9 +16,7 @@ const parseCatalogNode = (node) => {
|
|
|
16
16
|
const paging = (0, WABinary_1.getBinaryNodeChild)(catalogNode, 'paging');
|
|
17
17
|
return {
|
|
18
18
|
products,
|
|
19
|
-
nextPageCursor: paging
|
|
20
|
-
? (0, WABinary_1.getBinaryNodeChildString)(paging, 'after')
|
|
21
|
-
: undefined
|
|
19
|
+
nextPageCursor: paging ? (0, WABinary_1.getBinaryNodeChildString)(paging, 'after') : undefined
|
|
22
20
|
};
|
|
23
21
|
};
|
|
24
22
|
exports.parseCatalogNode = parseCatalogNode;
|
|
@@ -57,7 +55,7 @@ const parseOrderDetailsNode = (node) => {
|
|
|
57
55
|
const orderDetails = {
|
|
58
56
|
price: {
|
|
59
57
|
total: +(0, WABinary_1.getBinaryNodeChildString)(priceNode, 'total'),
|
|
60
|
-
currency: (0, WABinary_1.getBinaryNodeChildString)(priceNode, 'currency')
|
|
58
|
+
currency: (0, WABinary_1.getBinaryNodeChildString)(priceNode, 'currency')
|
|
61
59
|
},
|
|
62
60
|
products
|
|
63
61
|
};
|
|
@@ -169,7 +167,7 @@ const parseProductNode = (productNode) => {
|
|
|
169
167
|
id,
|
|
170
168
|
imageUrls: parseImageUrls(mediaNode),
|
|
171
169
|
reviewStatus: {
|
|
172
|
-
whatsapp: (0, WABinary_1.getBinaryNodeChildString)(statusInfoNode, 'status')
|
|
170
|
+
whatsapp: (0, WABinary_1.getBinaryNodeChildString)(statusInfoNode, 'status')
|
|
173
171
|
},
|
|
174
172
|
availability: 'in stock',
|
|
175
173
|
name: (0, WABinary_1.getBinaryNodeChildString)(productNode, 'name'),
|
|
@@ -178,7 +176,7 @@ const parseProductNode = (productNode) => {
|
|
|
178
176
|
description: (0, WABinary_1.getBinaryNodeChildString)(productNode, 'description'),
|
|
179
177
|
price: +(0, WABinary_1.getBinaryNodeChildString)(productNode, 'price'),
|
|
180
178
|
currency: (0, WABinary_1.getBinaryNodeChildString)(productNode, 'currency'),
|
|
181
|
-
isHidden
|
|
179
|
+
isHidden
|
|
182
180
|
};
|
|
183
181
|
return product;
|
|
184
182
|
};
|
|
@@ -189,7 +187,9 @@ exports.parseProductNode = parseProductNode;
|
|
|
189
187
|
async function uploadingNecessaryImagesOfProduct(product, waUploadToServer, timeoutMs = 30000) {
|
|
190
188
|
product = {
|
|
191
189
|
...product,
|
|
192
|
-
images: product.images
|
|
190
|
+
images: product.images
|
|
191
|
+
? await (0, exports.uploadingNecessaryImages)(product.images, waUploadToServer, timeoutMs)
|
|
192
|
+
: product.images
|
|
193
193
|
};
|
|
194
194
|
return product;
|
|
195
195
|
}
|
|
@@ -218,9 +218,7 @@ const uploadingNecessaryImages = async (images, waUploadToServer, timeoutMs = 30
|
|
|
218
218
|
fileEncSha256B64: sha,
|
|
219
219
|
timeoutMs
|
|
220
220
|
});
|
|
221
|
-
await fs_1.promises
|
|
222
|
-
.unlink(filePath)
|
|
223
|
-
.catch(err => console.log('Error deleting temp file ', err));
|
|
221
|
+
await fs_1.promises.unlink(filePath).catch(err => console.log('Error deleting temp file ', err));
|
|
224
222
|
return { url: (0, messages_media_1.getUrlFromDirectPath)(directPath) };
|
|
225
223
|
}));
|
|
226
224
|
return results;
|
|
@@ -237,6 +235,6 @@ const parseStatusInfo = (mediaNode) => {
|
|
|
237
235
|
const node = (0, WABinary_1.getBinaryNodeChild)(mediaNode, 'status_info');
|
|
238
236
|
return {
|
|
239
237
|
status: (0, WABinary_1.getBinaryNodeChildString)(node, 'status'),
|
|
240
|
-
canAppeal: (0, WABinary_1.getBinaryNodeChildString)(node, 'can_appeal') === 'true'
|
|
238
|
+
canAppeal: (0, WABinary_1.getBinaryNodeChildString)(node, 'can_appeal') === 'true'
|
|
241
239
|
};
|
|
242
240
|
};
|
|
@@ -29,22 +29,22 @@ export declare const decodeSyncdPatch: (msg: proto.ISyncdPatch, name: WAPatchNam
|
|
|
29
29
|
};
|
|
30
30
|
}>;
|
|
31
31
|
export declare const extractSyncdPatches: (result: BinaryNode, options: AxiosRequestConfig<{}>) => Promise<{
|
|
32
|
-
|
|
32
|
+
critical_unblock_low: {
|
|
33
33
|
patches: proto.ISyncdPatch[];
|
|
34
34
|
hasMorePatches: boolean;
|
|
35
35
|
snapshot?: proto.ISyncdSnapshot;
|
|
36
36
|
};
|
|
37
|
-
|
|
37
|
+
regular_high: {
|
|
38
38
|
patches: proto.ISyncdPatch[];
|
|
39
39
|
hasMorePatches: boolean;
|
|
40
40
|
snapshot?: proto.ISyncdSnapshot;
|
|
41
41
|
};
|
|
42
|
-
|
|
42
|
+
regular_low: {
|
|
43
43
|
patches: proto.ISyncdPatch[];
|
|
44
44
|
hasMorePatches: boolean;
|
|
45
45
|
snapshot?: proto.ISyncdSnapshot;
|
|
46
46
|
};
|
|
47
|
-
|
|
47
|
+
critical_block: {
|
|
48
48
|
patches: proto.ISyncdPatch[];
|
|
49
49
|
hasMorePatches: boolean;
|
|
50
50
|
snapshot?: proto.ISyncdSnapshot;
|
package/lib/Utils/chat-utils.js
CHANGED
|
@@ -81,20 +81,11 @@ const makeLtHashGenerator = ({ indexValueMap, hash }) => {
|
|
|
81
81
|
};
|
|
82
82
|
};
|
|
83
83
|
const generateSnapshotMac = (lthash, version, name, key) => {
|
|
84
|
-
const total = Buffer.concat([
|
|
85
|
-
lthash,
|
|
86
|
-
to64BitNetworkOrder(version),
|
|
87
|
-
Buffer.from(name, 'utf-8')
|
|
88
|
-
]);
|
|
84
|
+
const total = Buffer.concat([lthash, to64BitNetworkOrder(version), Buffer.from(name, 'utf-8')]);
|
|
89
85
|
return (0, crypto_1.hmacSign)(total, key, 'sha256');
|
|
90
86
|
};
|
|
91
87
|
const generatePatchMac = (snapshotMac, valueMacs, version, type, key) => {
|
|
92
|
-
const total = Buffer.concat([
|
|
93
|
-
snapshotMac,
|
|
94
|
-
...valueMacs,
|
|
95
|
-
to64BitNetworkOrder(version),
|
|
96
|
-
Buffer.from(type, 'utf-8')
|
|
97
|
-
]);
|
|
88
|
+
const total = Buffer.concat([snapshotMac, ...valueMacs, to64BitNetworkOrder(version), Buffer.from(type, 'utf-8')]);
|
|
98
89
|
return (0, crypto_1.hmacSign)(total, key);
|
|
99
90
|
};
|
|
100
91
|
const newLTHashState = () => ({ version: 0, hash: Buffer.alloc(128), indexValueMap: {} });
|
|
@@ -157,7 +148,7 @@ const decodeSyncdMutations = async (msgMutations, initialState, getAppStateSyncK
|
|
|
157
148
|
// if it's a syncdmutation, get the operation property
|
|
158
149
|
// otherwise, if it's only a record -- it'll be a SET mutation
|
|
159
150
|
const operation = 'operation' in msgMutation ? msgMutation.operation : WAProto_1.proto.SyncdMutation.SyncdOperation.SET;
|
|
160
|
-
const record =
|
|
151
|
+
const record = 'record' in msgMutation && !!msgMutation.record ? msgMutation.record : msgMutation;
|
|
161
152
|
const key = await getKey(record.keyId.id);
|
|
162
153
|
const content = Buffer.from(record.value.blob);
|
|
163
154
|
const encContent = content.slice(0, -32);
|
|
@@ -189,7 +180,10 @@ const decodeSyncdMutations = async (msgMutations, initialState, getAppStateSyncK
|
|
|
189
180
|
const base64Key = Buffer.from(keyId).toString('base64');
|
|
190
181
|
const keyEnc = await getAppStateSyncKey(base64Key);
|
|
191
182
|
if (!keyEnc) {
|
|
192
|
-
throw new boom_1.Boom(`failed to find key "${base64Key}" to decode mutation`, {
|
|
183
|
+
throw new boom_1.Boom(`failed to find key "${base64Key}" to decode mutation`, {
|
|
184
|
+
statusCode: 404,
|
|
185
|
+
data: { msgMutations }
|
|
186
|
+
});
|
|
193
187
|
}
|
|
194
188
|
return mutationKeys(keyEnc.keyData);
|
|
195
189
|
}
|
|
@@ -269,10 +263,9 @@ const decodeSyncdSnapshot = async (name, snapshot, getAppStateSyncKey, minimumVe
|
|
|
269
263
|
const newState = (0, exports.newLTHashState)();
|
|
270
264
|
newState.version = (0, generics_1.toNumber)(snapshot.version.version);
|
|
271
265
|
const mutationMap = {};
|
|
272
|
-
const areMutationsRequired = typeof minimumVersionNumber === 'undefined'
|
|
273
|
-
|| newState.version > minimumVersionNumber;
|
|
266
|
+
const areMutationsRequired = typeof minimumVersionNumber === 'undefined' || newState.version > minimumVersionNumber;
|
|
274
267
|
const { hash, indexValueMap } = await (0, exports.decodeSyncdMutations)(snapshot.records, newState, getAppStateSyncKey, areMutationsRequired
|
|
275
|
-
?
|
|
268
|
+
? mutation => {
|
|
276
269
|
var _a;
|
|
277
270
|
const index = (_a = mutation.syncAction.index) === null || _a === void 0 ? void 0 : _a.toString();
|
|
278
271
|
mutationMap[index] = mutation;
|
|
@@ -322,7 +315,7 @@ const decodePatches = async (name, syncds, initial, getAppStateSyncKey, options,
|
|
|
322
315
|
const index = (_a = mutation.syncAction.index) === null || _a === void 0 ? void 0 : _a.toString();
|
|
323
316
|
mutationMap[index] = mutation;
|
|
324
317
|
}
|
|
325
|
-
: (
|
|
318
|
+
: () => { }, true);
|
|
326
319
|
newState.hash = decodeResult.hash;
|
|
327
320
|
newState.indexValueMap = decodeResult.indexValueMap;
|
|
328
321
|
if (validateMacs) {
|
|
@@ -351,22 +344,24 @@ const chatModificationToAppPatch = (mod, jid) => {
|
|
|
351
344
|
const lastMsg = lastMessages[lastMessages.length - 1];
|
|
352
345
|
messageRange = {
|
|
353
346
|
lastMessageTimestamp: lastMsg === null || lastMsg === void 0 ? void 0 : lastMsg.messageTimestamp,
|
|
354
|
-
messages: (lastMessages === null || lastMessages === void 0 ? void 0 : lastMessages.length)
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
347
|
+
messages: (lastMessages === null || lastMessages === void 0 ? void 0 : lastMessages.length)
|
|
348
|
+
? lastMessages.map(m => {
|
|
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 });
|
|
352
|
+
}
|
|
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 });
|
|
355
|
+
}
|
|
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 });
|
|
358
|
+
}
|
|
359
|
+
if (m.key.participant) {
|
|
360
|
+
m.key.participant = (0, WABinary_1.jidNormalizedUser)(m.key.participant);
|
|
361
|
+
}
|
|
362
|
+
return m;
|
|
363
|
+
})
|
|
364
|
+
: undefined
|
|
370
365
|
};
|
|
371
366
|
}
|
|
372
367
|
else {
|
|
@@ -474,7 +469,7 @@ const chatModificationToAppPatch = (mod, jid) => {
|
|
|
474
469
|
patch = {
|
|
475
470
|
syncAction: {
|
|
476
471
|
deleteChatAction: {
|
|
477
|
-
messageRange: getMessageRange(mod.lastMessages)
|
|
472
|
+
messageRange: getMessageRange(mod.lastMessages)
|
|
478
473
|
}
|
|
479
474
|
},
|
|
480
475
|
index: ['deleteChat', jid, '1'],
|
|
@@ -493,7 +488,7 @@ const chatModificationToAppPatch = (mod, jid) => {
|
|
|
493
488
|
index: ['setting_pushName'],
|
|
494
489
|
type: 'critical_block',
|
|
495
490
|
apiVersion: 1,
|
|
496
|
-
operation: OP.SET
|
|
491
|
+
operation: OP.SET
|
|
497
492
|
};
|
|
498
493
|
}
|
|
499
494
|
else if ('addLabel' in mod) {
|
|
@@ -509,60 +504,53 @@ const chatModificationToAppPatch = (mod, jid) => {
|
|
|
509
504
|
index: ['label_edit', mod.addLabel.id],
|
|
510
505
|
type: 'regular',
|
|
511
506
|
apiVersion: 3,
|
|
512
|
-
operation: OP.SET
|
|
507
|
+
operation: OP.SET
|
|
513
508
|
};
|
|
514
509
|
}
|
|
515
510
|
else if ('addChatLabel' in mod) {
|
|
516
511
|
patch = {
|
|
517
512
|
syncAction: {
|
|
518
513
|
labelAssociationAction: {
|
|
519
|
-
labeled: true
|
|
514
|
+
labeled: true
|
|
520
515
|
}
|
|
521
516
|
},
|
|
522
517
|
index: [LabelAssociation_1.LabelAssociationType.Chat, mod.addChatLabel.labelId, jid],
|
|
523
518
|
type: 'regular',
|
|
524
519
|
apiVersion: 3,
|
|
525
|
-
operation: OP.SET
|
|
520
|
+
operation: OP.SET
|
|
526
521
|
};
|
|
527
522
|
}
|
|
528
523
|
else if ('removeChatLabel' in mod) {
|
|
529
524
|
patch = {
|
|
530
525
|
syncAction: {
|
|
531
526
|
labelAssociationAction: {
|
|
532
|
-
labeled: false
|
|
527
|
+
labeled: false
|
|
533
528
|
}
|
|
534
529
|
},
|
|
535
530
|
index: [LabelAssociation_1.LabelAssociationType.Chat, mod.removeChatLabel.labelId, jid],
|
|
536
531
|
type: 'regular',
|
|
537
532
|
apiVersion: 3,
|
|
538
|
-
operation: OP.SET
|
|
533
|
+
operation: OP.SET
|
|
539
534
|
};
|
|
540
535
|
}
|
|
541
536
|
else if ('addMessageLabel' in mod) {
|
|
542
537
|
patch = {
|
|
543
538
|
syncAction: {
|
|
544
539
|
labelAssociationAction: {
|
|
545
|
-
labeled: true
|
|
540
|
+
labeled: true
|
|
546
541
|
}
|
|
547
542
|
},
|
|
548
|
-
index: [
|
|
549
|
-
LabelAssociation_1.LabelAssociationType.Message,
|
|
550
|
-
mod.addMessageLabel.labelId,
|
|
551
|
-
jid,
|
|
552
|
-
mod.addMessageLabel.messageId,
|
|
553
|
-
'0',
|
|
554
|
-
'0'
|
|
555
|
-
],
|
|
543
|
+
index: [LabelAssociation_1.LabelAssociationType.Message, mod.addMessageLabel.labelId, jid, mod.addMessageLabel.messageId, '0', '0'],
|
|
556
544
|
type: 'regular',
|
|
557
545
|
apiVersion: 3,
|
|
558
|
-
operation: OP.SET
|
|
546
|
+
operation: OP.SET
|
|
559
547
|
};
|
|
560
548
|
}
|
|
561
549
|
else if ('removeMessageLabel' in mod) {
|
|
562
550
|
patch = {
|
|
563
551
|
syncAction: {
|
|
564
552
|
labelAssociationAction: {
|
|
565
|
-
labeled: false
|
|
553
|
+
labeled: false
|
|
566
554
|
}
|
|
567
555
|
},
|
|
568
556
|
index: [
|
|
@@ -575,7 +563,7 @@ const chatModificationToAppPatch = (mod, jid) => {
|
|
|
575
563
|
],
|
|
576
564
|
type: 'regular',
|
|
577
565
|
apiVersion: 3,
|
|
578
|
-
operation: OP.SET
|
|
566
|
+
operation: OP.SET
|
|
579
567
|
};
|
|
580
568
|
}
|
|
581
569
|
else {
|
|
@@ -595,9 +583,7 @@ const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) => {
|
|
|
595
583
|
ev.emit('chats.update', [
|
|
596
584
|
{
|
|
597
585
|
id,
|
|
598
|
-
muteEndTime: ((_a = action.muteAction) === null || _a === void 0 ? void 0 : _a.muted)
|
|
599
|
-
? (0, generics_1.toNumber)(action.muteAction.muteEndTimestamp)
|
|
600
|
-
: null,
|
|
586
|
+
muteEndTime: ((_a = action.muteAction) === null || _a === void 0 ? void 0 : _a.muted) ? (0, generics_1.toNumber)(action.muteAction.muteEndTimestamp) : null,
|
|
601
587
|
conditional: getChatUpdateConditional(id, undefined)
|
|
602
588
|
}
|
|
603
589
|
]);
|
|
@@ -614,9 +600,7 @@ const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) => {
|
|
|
614
600
|
// 2. if the account unarchiveChats setting is false -- then it doesn't matter,
|
|
615
601
|
// it'll always take an app state action to mark in unarchived -- which we'll get anyway
|
|
616
602
|
const archiveAction = action === null || action === void 0 ? void 0 : action.archiveChatAction;
|
|
617
|
-
const isArchived = archiveAction
|
|
618
|
-
? archiveAction.archived
|
|
619
|
-
: type === 'archive';
|
|
603
|
+
const isArchived = archiveAction ? archiveAction.archived : type === 'archive';
|
|
620
604
|
// // basically we don't need to fire an "archive" update if the chat is being marked unarchvied
|
|
621
605
|
// // this only applies for the initial sync
|
|
622
606
|
// if(isInitialSync && !isArchived) {
|
|
@@ -624,11 +608,13 @@ const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) => {
|
|
|
624
608
|
// }
|
|
625
609
|
const msgRange = !(accountSettings === null || accountSettings === void 0 ? void 0 : accountSettings.unarchiveChats) ? undefined : archiveAction === null || archiveAction === void 0 ? void 0 : archiveAction.messageRange;
|
|
626
610
|
// logger?.debug({ chat: id, syncAction }, 'message range archive')
|
|
627
|
-
ev.emit('chats.update', [
|
|
611
|
+
ev.emit('chats.update', [
|
|
612
|
+
{
|
|
628
613
|
id,
|
|
629
614
|
archived: isArchived,
|
|
630
615
|
conditional: getChatUpdateConditional(id, msgRange)
|
|
631
|
-
}
|
|
616
|
+
}
|
|
617
|
+
]);
|
|
632
618
|
}
|
|
633
619
|
else if (action === null || action === void 0 ? void 0 : action.markChatAsReadAction) {
|
|
634
620
|
const markReadAction = action.markChatAsReadAction;
|
|
@@ -636,11 +622,13 @@ const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) => {
|
|
|
636
622
|
// because the chat is read by default
|
|
637
623
|
// this only applies for the initial sync
|
|
638
624
|
const isNullUpdate = isInitialSync && markReadAction.read;
|
|
639
|
-
ev.emit('chats.update', [
|
|
625
|
+
ev.emit('chats.update', [
|
|
626
|
+
{
|
|
640
627
|
id,
|
|
641
628
|
unreadCount: isNullUpdate ? null : !!(markReadAction === null || markReadAction === void 0 ? void 0 : markReadAction.read) ? 0 : -1,
|
|
642
629
|
conditional: getChatUpdateConditional(id, markReadAction === null || markReadAction === void 0 ? void 0 : markReadAction.messageRange)
|
|
643
|
-
}
|
|
630
|
+
}
|
|
631
|
+
]);
|
|
644
632
|
}
|
|
645
633
|
else if ((action === null || action === void 0 ? void 0 : action.deleteMessageForMeAction) || type === 'deleteMessageForMe') {
|
|
646
634
|
ev.emit('messages.delete', {
|
|
@@ -654,7 +642,14 @@ const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) => {
|
|
|
654
642
|
});
|
|
655
643
|
}
|
|
656
644
|
else if (action === null || action === void 0 ? void 0 : action.contactAction) {
|
|
657
|
-
ev.emit('contacts.upsert', [
|
|
645
|
+
ev.emit('contacts.upsert', [
|
|
646
|
+
{
|
|
647
|
+
id: id,
|
|
648
|
+
name: action.contactAction.fullName,
|
|
649
|
+
lid: action.contactAction.lidJid || undefined,
|
|
650
|
+
jid: (0, WABinary_1.isJidUser)(id) ? id : undefined
|
|
651
|
+
}
|
|
652
|
+
]);
|
|
658
653
|
}
|
|
659
654
|
else if (action === null || action === void 0 ? void 0 : action.pushNameSetting) {
|
|
660
655
|
const name = (_b = action === null || action === void 0 ? void 0 : action.pushNameSetting) === null || _b === void 0 ? void 0 : _b.name;
|
|
@@ -663,11 +658,13 @@ const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) => {
|
|
|
663
658
|
}
|
|
664
659
|
}
|
|
665
660
|
else if (action === null || action === void 0 ? void 0 : action.pinAction) {
|
|
666
|
-
ev.emit('chats.update', [
|
|
661
|
+
ev.emit('chats.update', [
|
|
662
|
+
{
|
|
667
663
|
id,
|
|
668
664
|
pinned: ((_c = action.pinAction) === null || _c === void 0 ? void 0 : _c.pinned) ? (0, generics_1.toNumber)(action.timestamp) : null,
|
|
669
665
|
conditional: getChatUpdateConditional(id, undefined)
|
|
670
|
-
}
|
|
666
|
+
}
|
|
667
|
+
]);
|
|
671
668
|
}
|
|
672
669
|
else if (action === null || action === void 0 ? void 0 : action.unarchiveChatsSetting) {
|
|
673
670
|
const unarchiveChats = !!action.unarchiveChatsSetting.unarchiveChats;
|
|
@@ -706,9 +703,7 @@ const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) => {
|
|
|
706
703
|
}
|
|
707
704
|
else if (action === null || action === void 0 ? void 0 : action.labelAssociationAction) {
|
|
708
705
|
ev.emit('labels.association', {
|
|
709
|
-
type: action.labelAssociationAction.labeled
|
|
710
|
-
? 'add'
|
|
711
|
-
: 'remove',
|
|
706
|
+
type: action.labelAssociationAction.labeled ? 'add' : 'remove',
|
|
712
707
|
association: type === LabelAssociation_1.LabelAssociationType.Chat
|
|
713
708
|
? {
|
|
714
709
|
type: LabelAssociation_1.LabelAssociationType.Chat,
|
|
@@ -728,7 +723,7 @@ const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) => {
|
|
|
728
723
|
}
|
|
729
724
|
function getChatUpdateConditional(id, msgRange) {
|
|
730
725
|
return isInitialSync
|
|
731
|
-
?
|
|
726
|
+
? data => {
|
|
732
727
|
const chat = data.historySets.chats[id] || data.chatUpserts[id];
|
|
733
728
|
if (chat) {
|
|
734
729
|
return msgRange ? isValidPatchBasedOnMessageRange(chat, msgRange) : true;
|
package/lib/Utils/crypto.js
CHANGED
|
@@ -53,9 +53,7 @@ const Defaults_1 = require("../Defaults");
|
|
|
53
53
|
// insure browser & node compatibility
|
|
54
54
|
const { subtle } = globalThis.crypto;
|
|
55
55
|
/** prefix version byte to the pub keys, required for some curve crypto functions */
|
|
56
|
-
const generateSignalPubKey = (pubKey) =>
|
|
57
|
-
? pubKey
|
|
58
|
-
: Buffer.concat([Defaults_1.KEY_BUNDLE_TYPE, pubKey]));
|
|
56
|
+
const generateSignalPubKey = (pubKey) => pubKey.length === 33 ? pubKey : Buffer.concat([Defaults_1.KEY_BUNDLE_TYPE, pubKey]);
|
|
59
57
|
exports.generateSignalPubKey = generateSignalPubKey;
|
|
60
58
|
exports.Curve = {
|
|
61
59
|
generateKeyPair: () => {
|
|
@@ -70,7 +68,7 @@ exports.Curve = {
|
|
|
70
68
|
const shared = libsignal.curve.calculateAgreement((0, exports.generateSignalPubKey)(publicKey), privateKey);
|
|
71
69
|
return Buffer.from(shared);
|
|
72
70
|
},
|
|
73
|
-
sign: (privateKey, buf) =>
|
|
71
|
+
sign: (privateKey, buf) => libsignal.curve.calculateSignature(privateKey, buf),
|
|
74
72
|
verify: (pubKey, message, signature) => {
|
|
75
73
|
try {
|
|
76
74
|
libsignal.curve.verifySignature((0, exports.generateSignalPubKey)(pubKey), message, signature);
|
|
@@ -153,14 +151,10 @@ function md5(buffer) {
|
|
|
153
151
|
// HKDF key expansion
|
|
154
152
|
async function hkdf(buffer, expandedLength, info) {
|
|
155
153
|
// Ensure we have a Uint8Array for the key material
|
|
156
|
-
const inputKeyMaterial = buffer instanceof Uint8Array
|
|
157
|
-
? buffer
|
|
158
|
-
: new Uint8Array(buffer);
|
|
154
|
+
const inputKeyMaterial = buffer instanceof Uint8Array ? buffer : new Uint8Array(buffer);
|
|
159
155
|
// Set default values if not provided
|
|
160
156
|
const salt = info.salt ? new Uint8Array(info.salt) : new Uint8Array(0);
|
|
161
|
-
const infoBytes = info.info
|
|
162
|
-
? new TextEncoder().encode(info.info)
|
|
163
|
-
: new Uint8Array(0);
|
|
157
|
+
const infoBytes = info.info ? new TextEncoder().encode(info.info) : new Uint8Array(0);
|
|
164
158
|
// Import the input key material
|
|
165
159
|
const importedKey = await subtle.importKey('raw', inputKeyMaterial, { name: 'HKDF' }, false, ['deriveBits']);
|
|
166
160
|
// Derive bits using HKDF
|
|
@@ -28,7 +28,7 @@ exports.NACK_REASONS = {
|
|
|
28
28
|
* @note this will only parse the message, not decrypt it
|
|
29
29
|
*/
|
|
30
30
|
function decodeMessageNode(stanza, meId, meLid) {
|
|
31
|
-
var _a;
|
|
31
|
+
var _a, _b, _c, _d, _e;
|
|
32
32
|
let msgType;
|
|
33
33
|
let chatId;
|
|
34
34
|
let author;
|
|
@@ -87,7 +87,11 @@ function decodeMessageNode(stanza, meId, meLid) {
|
|
|
87
87
|
remoteJid: chatId,
|
|
88
88
|
fromMe,
|
|
89
89
|
id: msgId,
|
|
90
|
-
|
|
90
|
+
senderLid: (_b = stanza === null || stanza === void 0 ? void 0 : stanza.attrs) === null || _b === void 0 ? void 0 : _b.sender_lid,
|
|
91
|
+
senderPn: (_c = stanza === null || stanza === void 0 ? void 0 : stanza.attrs) === null || _c === void 0 ? void 0 : _c.sender_pn,
|
|
92
|
+
participant,
|
|
93
|
+
participantPn: (_d = stanza === null || stanza === void 0 ? void 0 : stanza.attrs) === null || _d === void 0 ? void 0 : _d.participant_pn,
|
|
94
|
+
participantLid: (_e = stanza === null || stanza === void 0 ? void 0 : stanza.attrs) === null || _e === void 0 ? void 0 : _e.participant_lid
|
|
91
95
|
};
|
|
92
96
|
const fullMessage = {
|
|
93
97
|
key,
|
|
@@ -10,13 +10,13 @@ import { ILogger } from './logger';
|
|
|
10
10
|
type BaileysEventData = Partial<BaileysEventMap>;
|
|
11
11
|
type BaileysBufferableEventEmitter = BaileysEventEmitter & {
|
|
12
12
|
/** Use to process events in a batch */
|
|
13
|
-
process(handler: (events: BaileysEventData) => void | Promise<void>): (
|
|
13
|
+
process(handler: (events: BaileysEventData) => void | Promise<void>): () => void;
|
|
14
14
|
/**
|
|
15
15
|
* starts buffering events, call flush() to release them
|
|
16
16
|
* */
|
|
17
17
|
buffer(): void;
|
|
18
18
|
/** buffers all events till the promise completes */
|
|
19
|
-
createBufferedFunction<A extends any[], T>(work: (...args: A) => Promise<T>): (
|
|
19
|
+
createBufferedFunction<A extends any[], T>(work: (...args: A) => Promise<T>): (...args: A) => Promise<T>;
|
|
20
20
|
/**
|
|
21
21
|
* flushes all buffered events
|
|
22
22
|
* @param force if true, will flush all data regardless of any pending buffers
|
|
@@ -21,7 +21,7 @@ const BUFFERABLE_EVENT = [
|
|
|
21
21
|
'messages.delete',
|
|
22
22
|
'messages.reaction',
|
|
23
23
|
'message-receipt.update',
|
|
24
|
-
'groups.update'
|
|
24
|
+
'groups.update'
|
|
25
25
|
];
|
|
26
26
|
const BUFFERABLE_EVENT_SET = new Set(BUFFERABLE_EVENT);
|
|
27
27
|
/**
|
|
@@ -112,7 +112,7 @@ const makeEventBuffer = (logger) => {
|
|
|
112
112
|
},
|
|
113
113
|
on: (...args) => ev.on(...args),
|
|
114
114
|
off: (...args) => ev.off(...args),
|
|
115
|
-
removeAllListeners: (...args) => ev.removeAllListeners(...args)
|
|
115
|
+
removeAllListeners: (...args) => ev.removeAllListeners(...args)
|
|
116
116
|
};
|
|
117
117
|
};
|
|
118
118
|
exports.makeEventBuffer = makeEventBuffer;
|
|
@@ -314,9 +314,7 @@ eventData, logger) {
|
|
|
314
314
|
else {
|
|
315
315
|
data.messageUpserts[key] = {
|
|
316
316
|
message,
|
|
317
|
-
type: type === 'notify' || ((_b = data.messageUpserts[key]) === null || _b === void 0 ? void 0 : _b.type) === 'notify'
|
|
318
|
-
? 'notify'
|
|
319
|
-
: type
|
|
317
|
+
type: type === 'notify' || ((_b = data.messageUpserts[key]) === null || _b === void 0 ? void 0 : _b.type) === 'notify' ? 'notify' : type
|
|
320
318
|
};
|
|
321
319
|
}
|
|
322
320
|
}
|
|
@@ -372,8 +370,7 @@ eventData, logger) {
|
|
|
372
370
|
(0, messages_1.updateMessageWithReaction)(existing.message, reaction);
|
|
373
371
|
}
|
|
374
372
|
else {
|
|
375
|
-
data.messageReactions[keyStr] = data.messageReactions[keyStr]
|
|
376
|
-
|| { key, reactions: [] };
|
|
373
|
+
data.messageReactions[keyStr] = data.messageReactions[keyStr] || { key, reactions: [] };
|
|
377
374
|
(0, messages_1.updateMessageWithReaction)(data.messageReactions[keyStr], reaction);
|
|
378
375
|
}
|
|
379
376
|
}
|
|
@@ -387,8 +384,7 @@ eventData, logger) {
|
|
|
387
384
|
(0, messages_1.updateMessageWithReceipt)(existing.message, receipt);
|
|
388
385
|
}
|
|
389
386
|
else {
|
|
390
|
-
data.messageReceipts[keyStr] = data.messageReceipts[keyStr]
|
|
391
|
-
|| { key, userReceipt: [] };
|
|
387
|
+
data.messageReceipts[keyStr] = data.messageReceipts[keyStr] || { key, userReceipt: [] };
|
|
392
388
|
(0, messages_1.updateMessageWithReceipt)(data.messageReceipts[keyStr], receipt);
|
|
393
389
|
}
|
|
394
390
|
}
|
|
@@ -428,10 +424,10 @@ eventData, logger) {
|
|
|
428
424
|
// if the message has already been marked read by us
|
|
429
425
|
const chatId = message.key.remoteJid;
|
|
430
426
|
const chat = data.chatUpdates[chatId] || data.chatUpserts[chatId];
|
|
431
|
-
if ((0, process_message_1.isRealMessage)(message, '')
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
427
|
+
if ((0, process_message_1.isRealMessage)(message, '') &&
|
|
428
|
+
(0, process_message_1.shouldIncrementChatUnread)(message) &&
|
|
429
|
+
typeof (chat === null || chat === void 0 ? void 0 : chat.unreadCount) === 'number' &&
|
|
430
|
+
chat.unreadCount > 0) {
|
|
435
431
|
logger.debug({ chatId: chat.id }, 'decrementing chat counter');
|
|
436
432
|
chat.unreadCount -= 1;
|
|
437
433
|
if (chat.unreadCount === 0) {
|
package/lib/Utils/generics.d.ts
CHANGED
|
@@ -81,7 +81,7 @@ export declare const getCodeFromWSError: (error: Error) => number;
|
|
|
81
81
|
* Is the given platform WA business
|
|
82
82
|
* @param platform AuthenticationCreds.platform
|
|
83
83
|
*/
|
|
84
|
-
export declare const isWABusinessPlatform: (platform: string) => platform is "
|
|
84
|
+
export declare const isWABusinessPlatform: (platform: string) => platform is "smba" | "smbi";
|
|
85
85
|
export declare function trimUndefined(obj: {
|
|
86
86
|
[_: string]: any;
|
|
87
87
|
}): {
|