Async + Multi Cache (#1741)

* fix: handle invalid signatureKeyPublic types in sender-key-state

- added extra check to ensure signatureKeyPublic is either a base64 string or a Buffer
- fallback to empty buffer when unexpected object type is received
- prevents ERR_INVALID_ARG_TYPE error in Buffer.from

* adjusted based on  @jlucaso1 recommmendation

* fix: handle chain key objects for skmsg group message decryption

previously, some sender chain keys were stored or retrieved as plain objects
(e.g. { '0': 85, '1': 100, ... }) instead of Buffers. this caused
"ERR_INVALID_ARG_TYPE" during initial decryption of skmsg group messages.

this fixes any chain key object is converted to a proper Buffer
before being passed to SenderChainKey.

* fix: add more robust checks and fallbacks

* feat: async cache

feat: async caching

* fix: linting issues

* fix: mget logic

---------

Co-authored-by: αѕтяσχ11 <devastro0010@gmail.com>
This commit is contained in:
Martín Schere
2025-09-14 16:13:11 +02:00
committed by GitHub
parent f0cc173aa3
commit 8029446511
7 changed files with 70 additions and 50 deletions
+11 -5
View File
@@ -13,13 +13,19 @@ export type WABrowserDescription = [string, string, string]
export type CacheStore = {
/** get a cached key and change the stats */
get<T>(key: string): T | undefined
get<T>(key: string): Promise<T> | T | undefined
/** set a key in the cache */
set<T>(key: string, value: T): void
set<T>(key: string, value: T): Promise<void> | void | number | boolean
/** delete a key from the cache */
del(key: string): void
del(key: string): void | Promise<void> | number | boolean
/** flush all data */
flushAll(): void
flushAll(): void | Promise<void>
}
export type PossiblyExtendedCacheStore = CacheStore & {
mget?: <T>(keys: string[]) => Promise<Record<string, T | undefined>>
mset?: <T>(entries: { key: string; value: T }[]) => Promise<void> | void | number | boolean
mdel?: (keys: string[]) => void | Promise<void> | number | boolean
}
export type PatchedMessageWithRecipientJID = proto.IMessage & { recipientJid?: string }
@@ -78,7 +84,7 @@ export type SocketConfig = {
* used to determine whether to retry a message or not */
msgRetryCounterCache?: CacheStore
/** provide a cache to store a user's device list */
userDevicesCache?: CacheStore
userDevicesCache?: PossiblyExtendedCacheStore
/** cache to store call offers */
callOfferCache?: CacheStore
/** cache to track placeholder resends */