Skip to content

Pairing: handle companion_reg_refresh (Baileys patch, pending a live check) - #3

Closed
AlmogCohen wants to merge 3 commits into
fork/2.3.7from
fork/wip-companion-reg-refresh
Closed

AlmogCohen wants to merge 3 commits into
fork/2.3.7from
fork/wip-companion-reg-refresh

Conversation

@AlmogCohen

Copy link
Copy Markdown
Owner

Ports evolution-foundation#2727 (a compile of WhiskeySockets/Baileys#2765 plus the evolution-foundation#2602 guard) and the one-token ack fix from WhiskeySockets/Baileys#2749, as a patch-package patch on Baileys 7.0.0-rc14, test first. Since late July WhatsApp sends companion_reg_refresh during pairing (WhiskeySockets/Baileys#2737); rc14 acks and drops it, so a QR link never completes.

Tests run the real connect and the real Baileys socket against a local fake WhatsApp: on unpatched rc14 the QR test gets no re-rendered QR and the code test hits "Invalid buffer"; a guard fails if the patch is missing. The Docker build copies patches/ before npm ci and patch-package runs with --error-on-fail.

Not merged until a live check on a real phone: QR linking works today for accounts WhatsApp has not moved to the new step, and this changes the pairing path.

🤖 Generated with Claude Code

AlmogCohen and others added 3 commits September 29, 2026 13:52
…ed secret

Since about 2026-07-28 WhatsApp sends <notification
type='companion_reg_refresh'> to a companion being linked (Baileys evolution-foundation#2737).
WA Web answers it by minting a new adv secret and re-rendering the QR on
screen; a QR still carrying the retired secret fails on the phone
("Couldn't link device"). Baileys 7.0.0-rc14 has no handler: its ack
throws a TypeError on an unlinked companion (creds.me is undefined,
Baileys evolution-foundation#2738), and the QR keeps the retired secret until the refs run out.

The tests run Evolution's real connect and the real Baileys socket
against a local WhatsApp (test/helpers/fake-whatsapp.ts), with the phone
played by the primitives Baileys verifies with:

- QR: after the refresh the QR on screen must show the same ref with a
  new 32-byte adv secret, the stored creds must carry it, the refresh
  must be acked, and a scan of that QR must link the device. On rc14 no
  second QR ever comes.
- Pairing code: both sides derive the adv secret from the code
  exchange, so refreshes before and after the companion_finish must
  leave it alone, and the link must complete. On rc14 it does; what
  fails is the link_code_companion_reg notification with no pairing
  data (Baileys evolution-foundation#2600), logged as 'Invalid buffer'.
- A harness guard: the pinned Baileys carries patches/baileys+<pin>.patch,
  npm applies it on postinstall, and the Docker builder copies patches/
  before npm ci. There is no patch yet.

Run against unpatched rc14: all five fail, for the reasons above.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…7.0.0-rc14

No published Baileys release handles the notification, so the fork
carries a patch, applied by patch-package on npm's postinstall (upstream
develop has the same mechanism). --error-on-fail makes a patch that does
not apply fail the install, CI and the Docker build alike; without it
patch-package only fails on CI. The Docker builder copies patches/ before
npm ci, which runs with dev dependencies and without --ignore-scripts, so
patch-package is there when postinstall runs, and the final stage copies
the patched node_modules.

patches/baileys+7.0.0-rc14.patch is the patch vendored in
evolution-foundation#2727 by Clovis Coli Jr (cloviscoli),
which compiles two upstream Baileys fixes for rc14:

- WhiskeySockets/Baileys#2765 by doryani-ai: on companion_reg_refresh
  (with a companion_reg_refresh or pair-device-rotate-qr child), mint a
  new 32-byte adv secret, emit it on creds.update, and re-render the ref
  on screen with it, reading the secret per render and spending no ref.
  A session with creds.me set keeps its secret: after pair-success it is
  the session's, and after requestPairingCode the code exchange derives
  its own, which a pending pair-success is verified against.
- WhiskeySockets/Baileys#2602 by joivo: a link_code_companion_reg notification
  with no primary_identity_pub is not a primary_hello, and is skipped
  instead of failing with 'Invalid buffer' (Baileys evolution-foundation#2600).

and adds one line of a third:

- WhiskeySockets/Baileys#2749 by IamYGT: sendMessageAck reads
  creds.me?.id, so a notification before login is acked (the ack stanza
  carries no from for a notification) instead of throwing a TypeError
  (Baileys evolution-foundation#2738). Without it the refresh was never acked.

Analysis of the protocol change: Baileys evolution-foundation#2737 by bankon1t.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s patch

Credits the upstream work it carries: evolution-foundation/evolution-api
evolution-foundation#2727 (the vendored patch), Baileys #2765, evolution-foundation#2602 and #2749 (the fixes it
compiles), and Baileys evolution-foundation#2737 (the analysis).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@AlmogCohen

Copy link
Copy Markdown
Owner Author

Closing: waiting for a Baileys release that handles companion_reg_refresh (WhiskeySockets/Baileys#2737) instead of vendoring a patch. QR and code linking work on the accounts this fork runs today.

@AlmogCohen AlmogCohen closed this Sep 29, 2026
@AlmogCohen
AlmogCohen deleted the fork/wip-companion-reg-refresh branch September 29, 2026 11:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant