Repository navigation
feat(dm): add encrypted XChat conversation support - #856
Conversation
|
@vachmara Is there any blocker on this? If there isn't, I can test it out and get this merged. |
|
Hey @Rishikant181, during my initial tests against the GraphQL endpoint, I ran into authentication issues (422 GRAPHQL_VALIDATION_FAILED). Also, there’s still a major gap I haven’t had time to fully investigate: it should works fine for non-encrypted messages, but I haven’t managed to crack the encrypted payload yet. |
|
Current PR scope:
Runtime check on a one-to-one mixed conversation:
Encryption InvestigationInspected both XChat chunks:
Observed primitives:
XChat stores local state in OPFS SQLite:
Relevant local tables found:
Conclusion: decrypting should be feasible, but it is a separate follow-up. The path is to load the same OPFS key material XChat uses, process Useful GraphQL operation IDs:
Investigation needed before decryption:
Todo
|
…o feat/encrypted-dms
…into feat/encrypted-dms
|
I successfully decrypted encrypted XChat DM messages when the conversation secret key was already available locally. Findings:
Key retrieval status:
I think we should keep the library key-source agnostic for now. Re-requesting or rebuilding conversation keys on every call may create abnormal client behavior and could be easier to detect or rate-limit. A safer follow-up may be an experimental local SQLite key store that mirrors the browser’s XChat storage model, with the library resolving keys through a provider hook and only running key-change/private-key flows when the local cache is missing data. What do you think @Rishikant181? Follow-up investigation:
|
|
i saw one platform that uses reverse api also dey ask for the 4 digit password for x chat while connecting account i wonder how they use it in decryption @vachmara |
I made solid progress and have now completed the reverse-engineering part. From what we’ve seen, the 4-digit password is used internally to derive or reconstruct the encryption keys. The next step is to integrate this into the lib and recreate the full key derivation/decryption flow cleanly. |
|
sry I didn't take the time to finish this, hopefully I'll find some time soon to at least ship a first version of it |
|
@vachmara That's fine lol |
|
This PR is finally ready for review! 🎉 @Rishikant181 @westcorperations Encrypted XChat conversations are now supported through manual conversation keys or PIN-backed key recovery, including verified event decryption, key rotation, group metadata, documentation, and safer TLV decoding. X Developer Platform team open-sourced their Chat XDK. It made the key recovery, signature verification, and encrypted-event integration significantly faster and safer to implement! |
|
@vachmara Thanks! Will check this out, and hopefully, get it merged. |
|
@Rishikant181 I only tested |
|
@vachmara Yeah I figured that out and deleted my earlier message lol. Conversations work great, though. Kudos for that! Let me know if fetching inbox is too much of a hassle. If yes, we can defer that to later, to another PR. |
|
After investigating, XChat inbox support requires separate GraphQL endpoints, response models, and pagination. That's beyond the scope of this PR, so I'll address it properly in a follow-up PR instead! |
|
@vachmara No issues. I'll continue with the review and get this merged. |
Rishikant181
left a comment
There was a problem hiding this comment.
Let me know if you can address the feedback or should I make the changes myself.
| * | ||
| * @internal | ||
| */ | ||
| export class DMEventDecoder { |
There was a problem hiding this comment.
No need for this to be a class. We can just make all the functions in here be standalone functions, with the private methods not having the export keyword, while the public methods will have the export keyword, making them be available for direct call.
| * | ||
| * @internal | ||
| */ | ||
| export class XChatCrypto { |
There was a problem hiding this comment.
No need for this to be a class. We can just make all the functions in here be standalone functions, with the private methods not having the export keyword, while the public methods will have the export keyword, making them be available for direct call.
| export class DirectMessage implements IDirectMessage { | ||
| /** The raw message details. */ | ||
| private readonly _raw: IRawMessage; | ||
| private readonly _raw: IRawMessage | Record<string, unknown>; |
There was a problem hiding this comment.
Instead of making this a generic Record, let's instead add the raw type to types/raw/dm, and use it here. That will gives us a type to compare against, if the data structure as received from X changes in the future.
| */ | ||
| public constructor(message: unknown) { | ||
| this._raw = message as IRawMessage; | ||
| this._raw = message as IRawMessage | Record<string, unknown>; |
|
|
||
| /** The raw message details. */ | ||
| public get raw(): IRawMessage { | ||
| public get raw(): IRawMessage | Record<string, unknown> { |
| public readonly maxRetries: number; | ||
| public readonly responseMiddleware?: (response: AxiosResponse) => void | Promise<void>; | ||
| public readonly timeout?: number; | ||
| public readonly xChatConversationKeyProvider?: IRettiwtConfig['xChatConversationKeyProvider']; |
There was a problem hiding this comment.
Instead of using the type from IRettiwtConfig['<field_name>'], let's type out the actual type here i.e, XChatConversationKeyProvider | undefined, etc. This is purely a style preference.
| @@ -0,0 +1,92 @@ | |||
| import { IXChatDecryptResult, IXChatSigningKey } from '../types/args/DirectMessageArgs'; | |||
|
|
|||
| interface IXChatClient { | |||
There was a problem hiding this comment.
Move this interface to types/XChatSession.ts
| } | ||
|
|
||
| /** Options used to create a PIN-backed XChat session. */ | ||
| export interface IXChatSessionOptions { |
There was a problem hiding this comment.
Move this interface to types/XChatSession.ts
There was a problem hiding this comment.
Can we split the contents of this file between FetchArgs.ts and PostArgs.ts, as necessary, instead of having it's own DirectMessageArgs.ts file? It seems a bit out of place.
|
On it! |
|
@vachmara Merged. Thanks! |
Related issue
Closes #836
Type of change
Summary
Security
Verification