chat_xdk 0.7.10-arm64-darwin

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 4a5c980667f5d73dd5e16f49e9b395aec2f7e300e4f9f4db89f9437494315965
4
+ data.tar.gz: cacff1dae8b85230ba7aefe3fff7199fbe4da9792d076d28da7932c0d68d9371
5
+ SHA512:
6
+ metadata.gz: 32aeed47b591660c58dfc42fd3ed3c888142216c1ec70c18c3711caa8124bfbc9d51a011cf25a61334ac77e6cbbde24513c30ae3085bd056bbbc86cb31302784
7
+ data.tar.gz: 37fcfa208fd7f84c70b31adbd08a978ca8a7f24860ccb80e282288c02c3ba610889da742743bdca203b4abfd803668c83511077af6e8f2f7bb3651c065d8e27f
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 X Corp.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,150 @@
1
+ # chat-xdk Ruby bindings
2
+
3
+ Ruby bindings for the X Chat SDK — encryption for X Direct Messages.
4
+
5
+ ## Architecture
6
+
7
+ ```
8
+ Ruby (ChatXdk) → Ruby FFI → Rust cdylib (libchat_xdk_ffi) → chat-xdk-core
9
+ ```
10
+
11
+ The native library is `libchat_xdk_ffi`, the C ABI shared library built from `crates/ffi` and loaded via the [`ffi`](https://rubygems.org/gems/ffi) gem. Complex values cross the FFI boundary as JSON UTF-8 strings.
12
+
13
+ ## Prerequisites
14
+
15
+ - **Ruby 3.0+**
16
+ - **Rust** (stable) if building the native `chat_xdk_ffi` library from source
17
+
18
+ ## Installation
19
+
20
+ Add to your `Gemfile`:
21
+
22
+ ```ruby
23
+ gem "chat_xdk"
24
+ ```
25
+
26
+ Published platform gems bundle `libchat_xdk_ffi` for macOS (`arm64-darwin`, `x86_64-darwin`), Linux (`x86_64-linux`, `aarch64-linux`), and Windows (`x64-mingw-ucrt`).
27
+
28
+ ## Local development & tests
29
+
30
+ From the repo root, build the native library and run the Ruby test suite:
31
+
32
+ ```bash
33
+ make ruby-test
34
+ ```
35
+
36
+ Or run directly against a local build by setting `CHAT_XDK_LIB_PATH`:
37
+
38
+ ```bash
39
+ cargo build -p chat-xdk-ffi --release
40
+ cd crates/ruby
41
+ CHAT_XDK_LIB_PATH=../../target/release bundle exec rake test
42
+ ```
43
+
44
+ ## Quick Start
45
+
46
+ ```ruby
47
+ require "chat_xdk"
48
+
49
+ ChatXdk::Chat.open do |chat|
50
+ # Load a key blob + its registered version, then set the session once:
51
+ # identity, the opt-in conversation-key cache, and the signing-key store.
52
+ # Or pass the X API's Juicebox config to Chat.open(juicebox_config_json) and
53
+ # call chat.unlock(pin).
54
+ chat.import_keys(
55
+ ChatXdk::ImportKeysParams.new(keys: exported_bytes, signing_key_version: registered_key_version)
56
+ )
57
+ chat.set_identity(
58
+ ChatXdk::SetIdentityParams.new(user_id: my_user_id, signing_key_version: registered_key_version)
59
+ )
60
+ chat.set_cache_keys(true)
61
+ chat.set_signing_keys(signing_keys)
62
+ # set_signing_keys replaces the stored keys; add_signing_keys adds to them.
63
+ chat.add_signing_keys(new_member_signing_keys)
64
+
65
+ # Batch load — omitted signing_keys fall back to the store; verified
66
+ # conversation keys populate the cache.
67
+ batch = chat.decrypt_events(ChatXdk::DecryptEventsParams.new(events: raw_event_b64_list))
68
+
69
+ batch.unverified_key_changes.each do |index, change|
70
+ warn "#{index} #{change.reason} #{change.sender_id}"
71
+ end
72
+
73
+ # Individual events: omitted conversation_keys and signing_keys resolve from
74
+ # the session stores.
75
+ event = chat.decrypt_event(ChatXdk::DecryptEventParams.new(event_b64: event_b64))
76
+ conversation_id = event["conversation_id"]
77
+
78
+ # Sending resolves the identity and conversation key from the session too.
79
+ payload = chat.encrypt_message(
80
+ ChatXdk::EncryptMessageParams.new(conversation_id: conversation_id, text: "hi!")
81
+ )
82
+ reply = chat.encrypt_reply(
83
+ ChatXdk::EncryptReplyParams.new(conversation_id: conversation_id, text: "pong", reply_to_event: event_b64)
84
+ )
85
+ reaction = chat.encrypt_add_reaction(
86
+ ChatXdk::EncryptReactionParams.new(target_event: event_b64, emoji: "👍")
87
+ )
88
+ end
89
+ ```
90
+
91
+ Always call `chat.close` (or use `Chat.open { |chat| ... }`) to release native
92
+ resources and wipe private keys from memory. A `Chat` instance is thread-safe
93
+ and releases Ruby's GVL during blocking native calls.
94
+
95
+ ## Other users' public keys
96
+
97
+ Set a resolver block or callable with `set_resolve_public_keys` and the chat
98
+ fetches missing public keys from `GET /2/users/{id}/public_keys` automatically:
99
+
100
+ ```ruby
101
+ chat.set_resolve_public_keys do |user_ids|
102
+ user_ids.each_with_object({}) do |user_id, records|
103
+ # The "data" array of GET /2/users/{id}/public_keys from your X API client.
104
+ records[user_id] = fetch_public_keys(user_id)
105
+ end
106
+ end
107
+
108
+ # Fetches missing signing keys automatically, stores them, and decrypts again.
109
+ page = chat.decrypt_events(ChatXdk::DecryptEventsParams.new(events: raw_event_b64_list))
110
+
111
+ # Fetches missing member identity keys automatically before encrypting the key.
112
+ created = chat.prepare_group_create(
113
+ ChatXdk::GroupCreateParams.new(conversation_id: group_id, member_ids: member_ids, admin_ids: admin_ids)
114
+ )
115
+ ```
116
+
117
+ Setting a resolver turns the key cache on (`set_cache_keys(true)`). Without a
118
+ resolver, use `chat.missing_public_keys(page)` and `chat.add_public_keys(records)`.
119
+
120
+ ## API
121
+
122
+ See the **Ruby** column of the unified tables in [`docs/API.md`](../../docs/API.md) for the full method list, parameters, and return types. Files (media) are covered under [Files (Media)](../../docs/API.md#files-media).
123
+
124
+ Stateless helpers (base64/hex, MIME sniff, image dimensions, `encrypted_file_size`) live on the **`ChatXdk`** module.
125
+
126
+ ## Network access
127
+
128
+ Each chat makes one kind of request itself: an anonymous
129
+ `GET https://api.x.com/2/chat/features` in the background, which reads the X
130
+ API's feature switches that pick the format the SDK sends in. It runs when a
131
+ chat is created, again once `set_identity` gives it a sender bucket
132
+ (`?bucket=<last four digits of user_id>`), and every 5 minutes after each
133
+ answer, retrying failed reads with exponential backoff up to 5 minutes. The
134
+ request carries no credentials or cookies, follows no redirects, never delays
135
+ or fails an SDK call, and honors `HTTPS_PROXY` / `HTTP_PROXY` / `ALL_PROXY` /
136
+ `NO_PROXY` as well as `CHAT_XDK_API_BASE_URL`.
137
+
138
+ ## Security limitations
139
+
140
+ The underlying protocol provides **no forward secrecy and no post-compromise
141
+ security**: compromise of an identity private key exposes all conversation
142
+ keys ever encrypted to that public key — and therefore all past and future
143
+ messages in those conversations. Key rotation does not retroactively protect
144
+ messages encrypted under a previous key. See
145
+ [docs/CRYPTO.md — Known Limitations](../../docs/CRYPTO.md#known-limitations).
146
+
147
+ ## License
148
+
149
+ MIT — see the repo [`LICENSE`](../../LICENSE). Third-party notices:
150
+ [`THIRD_PARTY_NOTICES.md`](../../THIRD_PARTY_NOTICES.md).