Skip to content

fix(xchat): wrap the newest identity version in the conversation-key handshake - #220

Merged
teknium1 merged 1 commit into
NousResearch:mainfrom
dacheah:fix/xchat-newest-identity-key
Nov 6, 2026
Merged

teknium1 merged 1 commit into
NousResearch:mainfrom
dacheah:fix/xchat-newest-identity-key

Conversation

@dacheah

@dacheah dacheah commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

Summary

_initiate_conversation selected a participant's identity with records[0], the first record returned by GET /2/users/{id}/public_keys — the oldest identity the account ever registered. X refuses a conversation key built on anything but the account's latest version, so any recipient that had registered a second identity could never be messaged:

400 Invalid identity key: one or more participant keys do not use the latest public key version.

This selects the numerically greatest public_key_version instead. They are millisecond timestamps whose string length can vary, so the comparison is done as integers — the caution the X Chat troubleshooting guide gives for exactly this comparison.

Reproduction

Against a recipient whose account had three registered identities (oldest first):

GET /2/users/<id>/public_keys
  1787584059885   original device
  1793107625688   registered by an earlier client
  1793191919524   device re-initialised encrypted DMs

hermes send -t xchat:<id> "…" failed every time with the 400 above, while hermes xchat status reported every credential green. Because the conversation key never seeds, the recipient's client falls back to an unencrypted thread — which this adapter does not read — so the user-visible symptom is silence rather than an error.

Single-identity accounts are unaffected, which is why the defect hides until an account rotates or re-initialises its keys.

Tests

xchat/tests/ on this branch: 56 passed.

The new test, test_handshake_wraps_the_newest_identity_version, fails on the unpatched base — the control that shows the old rule was the broken one:

E   AssertionError: assert '1787584059885' == '1793191919524'

Related

Closes #219.

…handshake

GET /2/users/{id}/public_keys returns every identity an account has ever
registered, oldest first. `_initiate_conversation` used records[0], so once a
participant had registered a second identity - the X app re-initialising
encrypted DMs, or an identity registered by another client - the handshake
kept wrapping a superseded key and X refused it:

  HTTP 400 Invalid identity key: one or more participant keys do not use the
  latest public key version.

Conversation keys then never seed, and a client that cannot establish
encryption falls back to unencrypted DMs, which this adapter does not read.

Select the numerically greatest public_key_version instead. Versions are
millisecond timestamps whose string length can vary, so compare them as
integers, per the X Chat troubleshooting guide.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

xchat: conversation-key handshake wraps a superseded identity version

2 participants