@neelegirly/baileys 2.2.22 → 2.2.23
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/lib/Socket/chats.js +1 -1
- package/lib/Socket/messages-recv.js +12 -2
- package/lib/Utils/chat-utils.d.ts +1 -1
- package/lib/Utils/chat-utils.js +40 -13
- package/package.json +1 -1
package/lib/Socket/chats.js
CHANGED
|
@@ -544,7 +544,7 @@ const makeChatsSocket = (config) => {
|
|
|
544
544
|
const { patches, hasMorePatches, snapshot } = decoded[name]
|
|
545
545
|
try {
|
|
546
546
|
if (snapshot) {
|
|
547
|
-
const { state: newState, mutationMap } = await Utils_1.decodeSyncdSnapshot(name, snapshot, getAppStateSyncKey, initialVersionMap[name], appStateMacVerification.snapshot)
|
|
547
|
+
const { state: newState, mutationMap } = await Utils_1.decodeSyncdSnapshot(name, snapshot, getAppStateSyncKey, initialVersionMap[name], appStateMacVerification.snapshot, logger)
|
|
548
548
|
states[name] = newState
|
|
549
549
|
Object.assign(globalMutationMap, mutationMap)
|
|
550
550
|
logger.info(`restored state of ${name} from snapshot to v${newState.version} with mutations`)
|
|
@@ -896,9 +896,19 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
896
896
|
node.attrs.participant_username
|
|
897
897
|
);
|
|
898
898
|
break;
|
|
899
|
-
case "newsletter":
|
|
900
|
-
|
|
899
|
+
case "newsletter": {
|
|
900
|
+
const newsletterChildren = WABinary_1.getAllBinaryNodeChildren(node);
|
|
901
|
+
const nodesToHandle = newsletterChildren.length
|
|
902
|
+
? newsletterChildren
|
|
903
|
+
: child
|
|
904
|
+
? [child]
|
|
905
|
+
: [];
|
|
906
|
+
|
|
907
|
+
for (const newsletterChild of nodesToHandle) {
|
|
908
|
+
handleNewsletterNotification(node.attrs.from, newsletterChild);
|
|
909
|
+
}
|
|
901
910
|
break;
|
|
911
|
+
}
|
|
902
912
|
case "mex":
|
|
903
913
|
await handleMexNotification(node.attrs.from, child);
|
|
904
914
|
break;
|
|
@@ -85,7 +85,7 @@ export declare const extractSyncdPatches: (result: BinaryNode, options: AxiosReq
|
|
|
85
85
|
|
|
86
86
|
export declare const downloadExternalBlob: (blob: proto.IExternalBlobReference, options: AxiosRequestConfig<{}>) => Promise<Buffer>
|
|
87
87
|
export declare const downloadExternalPatch: (blob: proto.IExternalBlobReference, options: AxiosRequestConfig<{}>) => Promise<proto.SyncdMutations>
|
|
88
|
-
export declare const decodeSyncdSnapshot: (name: WAPatchName, snapshot: proto.ISyncdSnapshot, getAppStateSyncKey: FetchAppStateSyncKey, minimumVersionNumber: number | undefined, validateMacs?: boolean) => Promise<{
|
|
88
|
+
export declare const decodeSyncdSnapshot: (name: WAPatchName, snapshot: proto.ISyncdSnapshot, getAppStateSyncKey: FetchAppStateSyncKey, minimumVersionNumber: number | undefined, validateMacs?: boolean, logger?: ILogger) => Promise<{
|
|
89
89
|
state: LTHashState
|
|
90
90
|
mutationMap: ChatMutationMap
|
|
91
91
|
}>
|
package/lib/Utils/chat-utils.js
CHANGED
|
@@ -179,18 +179,33 @@ const decodeSyncdMutations = async (msgMutations, initialState, getAppStateSyncK
|
|
|
179
179
|
// otherwise, if it's only a record -- it'll be a SET mutation
|
|
180
180
|
const operation = 'operation' in msgMutation ? msgMutation.operation : WAProto_1.proto.SyncdMutation.SyncdOperation.SET
|
|
181
181
|
const record = ('record' in msgMutation && !!msgMutation.record) ? msgMutation.record : msgMutation
|
|
182
|
-
|
|
182
|
+
let key
|
|
183
|
+
try {
|
|
184
|
+
key = await getKey(record.keyId.id)
|
|
185
|
+
}
|
|
186
|
+
catch (error) {
|
|
187
|
+
if (isMissingKeyError(error)) {
|
|
188
|
+
throw error
|
|
189
|
+
}
|
|
190
|
+
continue
|
|
191
|
+
}
|
|
183
192
|
const content = Buffer.from(record.value.blob)
|
|
184
193
|
const encContent = content.slice(0, -32)
|
|
185
194
|
const ogValueMac = content.slice(-32)
|
|
186
195
|
if (validateMacs) {
|
|
187
196
|
const contentHmac = generateMac(operation, encContent, record.keyId.id, key.valueMacKey)
|
|
188
197
|
if (Buffer.compare(contentHmac, ogValueMac) !== 0) {
|
|
189
|
-
|
|
198
|
+
continue
|
|
190
199
|
}
|
|
191
200
|
}
|
|
192
|
-
|
|
193
|
-
|
|
201
|
+
let syncAction
|
|
202
|
+
try {
|
|
203
|
+
const result = crypto_1.aesDecrypt(encContent, key.valueEncryptionKey)
|
|
204
|
+
syncAction = WAProto_1.proto.SyncActionData.decode(result)
|
|
205
|
+
}
|
|
206
|
+
catch (error) {
|
|
207
|
+
continue
|
|
208
|
+
}
|
|
194
209
|
if (validateMacs) {
|
|
195
210
|
const hmac = crypto_1.hmacSign(syncAction.index, key.indexKey)
|
|
196
211
|
if (Buffer.compare(hmac, record.index.blob) !== 0) {
|
|
@@ -286,7 +301,7 @@ const downloadExternalPatch = async (blob, options) => {
|
|
|
286
301
|
return syncData
|
|
287
302
|
}
|
|
288
303
|
|
|
289
|
-
const decodeSyncdSnapshot = async (name, snapshot, getAppStateSyncKey, minimumVersionNumber, validateMacs = true) => {
|
|
304
|
+
const decodeSyncdSnapshot = async (name, snapshot, getAppStateSyncKey, minimumVersionNumber, validateMacs = true, logger) => {
|
|
290
305
|
const newState = newLTHashState()
|
|
291
306
|
newState.version = generics_1.toNumber(snapshot.version.version)
|
|
292
307
|
const mutationMap = {}
|
|
@@ -309,7 +324,7 @@ const decodeSyncdSnapshot = async (name, snapshot, getAppStateSyncKey, minimumVe
|
|
|
309
324
|
const result = await mutationKeys(keyEnc.keyData)
|
|
310
325
|
const computedSnapshotMac = generateSnapshotMac(newState.hash, newState.version, name, result.snapshotMacKey)
|
|
311
326
|
if (Buffer.compare(snapshot.mac, computedSnapshotMac) !== 0) {
|
|
312
|
-
|
|
327
|
+
logger?.warn({ name, version: newState.version }, 'LTHash verification failed on snapshot, continuing with partial state')
|
|
313
328
|
}
|
|
314
329
|
}
|
|
315
330
|
return {
|
|
@@ -335,13 +350,24 @@ const decodePatches = async (name, syncds, initial, getAppStateSyncKey, options,
|
|
|
335
350
|
const patchVersion = generics_1.toNumber(version.version)
|
|
336
351
|
newState.version = patchVersion
|
|
337
352
|
const shouldMutate = typeof minimumVersionNumber === 'undefined' || patchVersion > minimumVersionNumber
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
353
|
+
let decodeResult
|
|
354
|
+
try {
|
|
355
|
+
decodeResult = await decodeSyncdPatch(syncd, name, newState, getAppStateSyncKey, shouldMutate
|
|
356
|
+
? mutation => {
|
|
357
|
+
var _a
|
|
358
|
+
const index = mutation.syncAction.index?.toString()
|
|
359
|
+
mutationMap[index] = mutation
|
|
360
|
+
}
|
|
361
|
+
: (() => { }), validateMacs)
|
|
362
|
+
}
|
|
363
|
+
catch (error) {
|
|
364
|
+
if (isMissingKeyError(error)) {
|
|
365
|
+
throw error
|
|
343
366
|
}
|
|
344
|
-
:
|
|
367
|
+
logger?.warn({ name, version: patchVersion, error: error?.stack || error }, 'failed to decode patch, skipping')
|
|
368
|
+
syncd.mutations = []
|
|
369
|
+
continue
|
|
370
|
+
}
|
|
345
371
|
newState.hash = decodeResult.hash
|
|
346
372
|
newState.indexValueMap = decodeResult.indexValueMap
|
|
347
373
|
if (validateMacs) {
|
|
@@ -353,7 +379,8 @@ const decodePatches = async (name, syncds, initial, getAppStateSyncKey, options,
|
|
|
353
379
|
const result = await mutationKeys(keyEnc.keyData)
|
|
354
380
|
const computedSnapshotMac = generateSnapshotMac(newState.hash, newState.version, name, result.snapshotMacKey)
|
|
355
381
|
if (Buffer.compare(snapshotMac, computedSnapshotMac) !== 0) {
|
|
356
|
-
|
|
382
|
+
logger?.warn({ name, version: newState.version }, 'LTHash verification failed, skipping remaining patches')
|
|
383
|
+
break
|
|
357
384
|
}
|
|
358
385
|
}
|
|
359
386
|
// clear memory used up by the mutations
|