Commit Graph

331 Commits

Author SHA1 Message Date
Rajeh Taher f46e8b118c messages-recv: handle newsletter and unavailable message acks 2025-11-21 17:35:46 +02:00
Rajeh Taher 23f1268918 messages-recv: remove outdated case for privacy_token 2025-11-21 17:09:06 +02:00
Rajeh Taher 129df47fbb revert #2010 2025-11-19 16:57:22 +02:00
Rajeh Taher e3cc1acec0 messages-recv: ignore only view once messages 2025-11-19 16:54:57 +02:00
Rajeh Taher 247c717881 messages, auth: rename 'contacts-tc-token' to tctoken 2025-11-19 16:35:18 +02:00
Rajeh Taher 50d410d117 chore: lint 2025-11-19 16:25:56 +02:00
vini a70e4da1c4 feat(signal): better parity with whatsapp web (#1967) 2025-11-19 15:20:49 +02:00
Cassio Santos 5c456e514e fix: cannot send message on new Whatsapp Business limited accounts (#2080)
* fix: cannot send message on new Whatsapp Business limited accounts

* chore: add woraround to resend the message on 475 errors

* fix: lint

* fix: add handler

* fix: lint

* Update src/Socket/messages-send.ts

---------

Co-authored-by: Rajeh Taher <rajeh@reforward.dev>
2025-11-19 15:18:19 +02:00
vini b4863b624e refactor(retry): improve message encryption and retry logic (#2055) 2025-11-19 15:13:51 +02:00
João Lucas de Oliveira Lopes 9b012baa5c fix: suppress receipts for newsletter messages to prevent disconnection (#2071) 2025-11-19 15:13:03 +02:00
João Lucas de Oliveira Lopes e5f820d119 fix: gracefully handle unavailable view-once messages and improve log error (#2070) 2025-11-19 15:12:28 +02:00
Rajeh Taher 29318cf6c2 chore: lint and re-organize 2025-10-20 00:37:37 +03:00
Rajeh Taher cc3cd17392 cleanup: remove string lid / jid refs and improve hosted support 2025-10-20 00:05:54 +03:00
Rajeh Taher 928fa6ac66 messages-recv: simplify retry logic + re-do acks 2025-10-18 21:02:58 +03:00
Rajeh Taher 07536dedfc process-message: check fromMe properly in message addons 2025-10-18 20:28:58 +03:00
Rajeh Taher e41a66b3c4 libsignal,lid-mapping, etc.: Partially fix "No sessions" on hosted JIDs 2025-10-16 18:31:01 +03:00
vini 20c43d1d3c chore: remove unnecessary info logs (#1893) 2025-10-11 13:45:38 +03:00
Rajeh Taher f56293365f chore: avoid npm warnings (update conventional-changelog) 2025-10-08 19:46:39 +03:00
Rajeh Taher 54db127303 defaults,utils: Minimize vectors for automation detection 2025-10-07 20:29:47 +03:00
Rajeh Taher acc5111792 group events: fix serialization issue 2025-10-07 20:17:07 +03:00
Rajeh Taher c5b0001b61 *group: parse @lids properly when processing group notifications
*This commit is breaking, it changes the format of participants in group-participants.update.
2025-10-05 23:56:14 +03:00
Rajeh Taher 09263aa3d2 libsignal: Process @hosted conversions to @hosted.lid 2025-10-05 22:51:13 +03:00
Rajeh Taher dd93b641c9 Signal, messages-recv, jid-utils: Handle ADJIDs properly in Signal 2025-10-05 19:09:28 +03:00
Rajeh Taher 38e0f2c0e6 Signal, messages-recv: Fix previous commit, fix log 2025-10-04 15:30:04 +03:00
Rajeh Taher 334977f983 general: revert #1665 2025-10-03 18:14:30 +03:00
Rajeh Taher 37d729b33a messages-recv, decode-wa-message: handle storing new pairs better + lint 2025-10-03 01:17:37 +03:00
Rajeh Taher 50b36ece3b decode-wa-message, process-message: Fix @hosted lids processing 2025-10-03 00:22:57 +03:00
Rajeh Taher 39541cc162 messages: No longer send <ack>s on successful decrypt + fix lid acks 2025-10-02 23:30:28 +03:00
Gustavo Quadri ae456cb342 fix: send message speed, lid logic, remove messages-send useless functions (#1794)
* fix: remove redundant migration

* fix: remove deduplicatelidpnjids

* fix: assertsessions complexity

* fix: assertsessions call

* fix: remove getencryptionjid

* fix: add wirejid to injecte2esession, remove libsignal lid migration

* fix: logger lid-mapping

* fix: injecte2esession decoded approach

* fix: changes made by @AstroX11

* fix: lint

* fix: lint

* fix: lint

* Revert "fix: injecte2esession decoded approach"

This reverts commit 4e368296ed084398b8a173ec117dc2478e481748.

* fix: centralize getlidforpn calls in messages-send

* fix: add resolvechunklids to signal

* fix: remove useless arrays

* fix: assertsessions logic

* fix: lint

* Revert "fix: assertsessions logic"

This reverts commit 65b0730891c91573edcab1c96af010db54382fba.

* fix: remove onwhatsapp fallback to prevent rate limit, migrate sessions when lid-map is created, new migration logic and user devices key

* fix: migrate session devices, socket creation

* fix: add back decryptionjid validation

* fix: add resolveSignalAddress to get lid

* fix: type error migration

* fix: lint

* fix: device level cache, proposed changes
2025-09-26 06:53:15 +03:00
João Lucas de Oliveira Lopes 3b46d43beb fix: harden Protobuf Deserialization and Refactor Utilities (#1820)
* refactor: reorganize browser utility functions and improve buffer handling

* fix: harden protobuf deserialization and clean up code

* refactor: simplify data handling in GroupCipher and SenderKey classes

* fix: Ensure consistent Buffer hydration and remove redundant code

* refactor: update decodeAndHydrate calls to use proto types for improved type safety
2025-09-26 04:45:30 +03:00
Rajeh Taher 39d2ac004a messages-recv: remove old message retry system, new one handles fine 2025-09-25 23:47:29 +03:00
Gustavo Quadri 194b557b0f fix: optimize LID migration performance and introduce cache (#1782)
* chore: lid-map cache, bulk migration, fixes

* fix: type error

* fix: signalrepository with lid type, remove check from assertsessions, lid-mapping store level deduplication

* fix: migrations logs

* fix: remove migrationsops lenght check

* fix: skip deletesession if cached or existing migrations

* chore: remove check migrated session

* fix: remove return null loadsession

* fix: getLIDforPN call and jidsrequiringfetch

* fix: longer lid map cache TTL

* fix: lint

* fix: lid type

* fix: lid socket type
2025-09-14 21:58:59 +03:00
Martín Schere 8029446511 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>
2025-09-14 17:13:11 +03:00
Rajeh Taher e305d4848e sender-key: credit original fix and fix key handling 2025-09-13 11:41:52 +03:00
αѕтяσχ11 f0dcc30e0f fix: handle invalid signatureKeyPublic types in sender-key-state AND fix handling chain key objects for skmsg group message decryption (#1760)
* 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

* fix: lint

* 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

* hacky fix(sender-key-state): normalize signing pubkey as Buffer with 0x05 prefix

a little hacky fix that ensures getSigningKeyPublic always returns a proper Buffer to satisfy libsignal.
adds a fallback to prepend 0x05 when only a 32-byte key is present, avoiding
"Invalid public key" errors and TS type issues around Uint8Array vs Buffer.
2025-09-13 11:04:26 +03:00
Rajeh Taher 9aa356845d sender-key: Properly digest new uint8array format keys. THANKS @w3nder!! 2025-09-09 23:57:30 +03:00
Rajeh Taher 2ebaaf35a4 handlemessage: change console based log 2025-09-09 00:59:08 +03:00
Rajeh Taher acd7b757ce messages-recv,decode-wa-message: stability 2025-09-08 23:27:07 +03:00
Rajeh Taher a2e7e070fc general: remove console logs, linting 2025-09-08 23:11:32 +03:00
Rajeh Taher dc5bb11bb7 message-recv: fix logic 2025-09-08 23:01:02 +03:00
Rajeh Taher 20693a59d0 lid, wip: Support LIDs in Baileys (#1747)
* lid-mapping: get missing lid from usync

* lid-mapping, jid-utils: change to isPnUser and store multiple mappings

* process-message: parse protocolMsg mapping, and store from new msgs

* types: lid-mapping event, addressing enum, alt, contact, group types

* validate, decode: use lid for identity, better logic

* lid: final commit

* linting

* linting

* linting

* linting

* misc: fix testing and also remove version json

* lint: IDE fucking up lint

* lid-mapping: fix build error on NPM

* message-retry: fix proto import
2025-09-08 10:03:28 +03:00
Rajeh Taher 2a00d65e44 cleaning up after AI slop! 2025-09-07 20:34:19 +03:00
Paulo Victor Lund f83a1c2aff Add mutex-based transaction safety to Signal key store (re-reworked) (#1697)
* mutex reimplementation

* lint

* lint

* lint fix

* Add cleanup for expired sender key mutexes

Introduces a mechanism to periodically clean up unused sender key mutexes in addTransactionCapability, reducing memory usage by removing mutexes that have not been used for over an hour and are not locked. A timer is started when the first mutex is created, and cleanup runs every 30 minutes.

* Update auth-utils.ts

* Refactor Signal key transaction usage

Introduces a local variable for parsed Signal keys in libsignal.ts to avoid repeated type assertions and improve code clarity.

* Refactor transaction handling for key operations

Introduces per-entity mutexes and passes key identifiers to transaction calls for finer-grained concurrency control in Signal key storage and socket operations. Updates transaction signatures and usage across Signal, Socket, and Utils modules to improve atomicity and performance, especially for system and sync messages.

* Improve SignalKeyStore transaction handling

Refactored transaction logic in SignalKeyStore to add commit retries, cleanup of transaction state, and improved mutex management for sender keys. Enhanced validation and batching for pre-key deletions and updates, improving concurrency and reliability.

* Replace custom mutex cleanup with LRU cache

Switched from manual mutex cleanup logic to using the lru-cache package for managing mutexes in addTransactionCapability. This simplifies resource management and ensures expired mutexes are automatically purged. Added lru-cache as a dependency.

* Lint fix

* Update src/Signal/libsignal.ts

* Update libsignal.ts

---------

Co-authored-by: João Lucas <jlucaso@hotmail.com>
Co-authored-by: Rajeh Taher <rajeh@reforward.dev>
2025-09-07 20:22:47 +03:00
Paulo Victor Lund ae0cb89714 Session recreation and improved message retry (#1735)
* Add message retry manager for session recreation and caching

Introduces a MessageRetryManager to cache recent sent messages and manage automatic Signal session recreation for failed message retries. Adds new config options to enable these features, integrates retry manager into message send/receive logic, and provides periodic cache cleanup. Improves reliability of message delivery and retry handling.

* Add buffer timeout and cache limit to event-buffer

Introduces a buffer timeout to auto-flush events after 30 seconds and limits the history cache size to prevent memory bloat in event-buffer.ts.

* Add session validation to SignalRepository

Introduces a validateSession method to SignalRepository for checking session existence and state. Updates message retry logic to use the new validation, improving session recreation handling and retry management.

* Improve message retry management and tracking

Refactored message retry manager to use LRU caches for recent messages and session history, added retry counters and statistics tracking, and implemented phone request scheduling. Updated message receive and send logic to mark retry success and pass max retry count. Removed periodic cleanup logic in favor of cache TTLs for better resource management.

* lint fix

* Use validateSession for session checks in message send

Replaces direct session existence checks with the improved validateSession method, which also checks for session staleness. Adds debug logging for failed session validations to aid troubleshooting.

* Delete src/Utils/message-retry.ts

---------

Co-authored-by: Rajeh Taher <rajeh@reforward.dev>
2025-09-07 20:20:51 +03:00
Gustavo Quadri 0043f8be21 Add: LID support with lid-map and migrations of sessions (#1694)
* fix: add lid-map logic

* fix: lint and simplified version

* fix: single device migration

* fix: lid map discovery

* fix: lint

* fix: lid migration in socket connection

* fix: lint

* fix: decode-wa-message consistency

* fix: yarn lock

* fix: lint

* fix: retry logic

* fix: logger level
2025-09-07 14:12:24 +03:00
Gustavo Quadri 8f21a67e4a fix: sync pre-keys on socket start and add specific pre-key error approach (#1663)
* fix: sync prekeys when storage mismatch

* fix: verify if current pre-key exists instead of matching

* add: pre-keys error specific approach

* fix: lint

* fix: lint
2025-09-07 14:11:50 +03:00
Matheus Filype d2adbaf3fc fix: message retries loop (#1641)
* fix: improve message resend logic by adding checks for message IDs

* Revert "fix: improve message resend logic by adding checks for message IDs"

This reverts commit c03f9d8e6fc6cbfbb9d1f8f67c169700e704213d.

* fix: enhance message resend logic by adding checks for message IDs

* fix: adjust message resend logic to allow maximum retry count
2025-09-07 14:10:39 +03:00
João Lucas de Oliveira Lopes 4d4339dae6 feat(WAProto): Optimize protobuf generation for 80%+ bundle size reduction (#1665)
* chore: remove comments and veirfy from generated proto files (improve size)

* refactor: replace fromObject with create for proto message instantiation and flag no beautiful

* chore: lint issues
2025-09-07 14:08:11 +03:00
Renato Freitas 260311e6a2 Fix call offer from lid call (#1670)
* Fix call offer from lid call

* check prettier
2025-08-07 01:21:20 +03:00
Rajeh Taher 8dc852ee89 proto: fix proto generation, tsc: fix node imports of compiled code 2025-07-19 23:16:35 +03:00