diff --git a/changelog.mdx b/changelog.mdx
index b8e7de46c..5358870da 100644
--- a/changelog.mdx
+++ b/changelog.mdx
@@ -7,6 +7,17 @@ keywords: ["changelog", "API updates", "release notes", "what's new", "API chang
To subscribe to updates, please [**“Turn on notifications”**](https://help.x.com/en/managing-your-account/notifications-on-mobile-devices#:~:text=In%20the%20top%20menu,%20you,you%20would%20like%20to%20receive) for [**@API**](https://x.com/api). You can also follow this changelog in your feed reader via the [**RSS feed**](https://docs.x.com/changelog/rss.xml).
+
+ ### Ruby bindings for Chat XDK (`chat_xdk`)
+
+ Official **Ruby** bindings for the X Chat encryption SDK are now available as the [`chat_xdk`](https://rubygems.org/gems/chat_xdk) gem (Ruby 3.0+):
+
+ - **Prebuilt native libraries:** Platform gems bundle `libchat_xdk_ffi` for macOS (`arm64-darwin`, `x86_64-darwin`), Linux (`x86_64-linux`, `aarch64-linux`), and Windows (`x64-mingw-ucrt`) with no Rust toolchain required.
+ - **Full API parity:** Key generation, Juicebox PIN-backed storage (`setup` / `unlock`), raw key export/import (`export_keys` / `import_keys`), batch and single-event decryption (`decrypt_events` / `decrypt_event`), automatic public-key resolution (`set_resolve_public_keys`), message and file encryption, and signed group/conversation actions.
+
+ Install with `gem install chat_xdk` and see [Chat XDK](/xchat/xchat-xdk) and [`chat-xdk/examples/ruby`](https://github.com/xdevplatform/chat-xdk/tree/main/examples/ruby).
+
+
### Java 8+ support for Chat XDK (`com.x:chatxdk`) and Java XDK (`com.x:xdk`)
diff --git a/xchat/getting-started.mdx b/xchat/getting-started.mdx
index 736ca3b57..069c03f0f 100644
--- a/xchat/getting-started.mdx
+++ b/xchat/getting-started.mdx
@@ -1,8 +1,8 @@
---
title: "Get started: send your first encrypted message"
sidebarTitle: Getting Started
-description: "A hands-on tutorial that takes you from zero to your first encrypted X Chat message, in Python, TypeScript, Go, Rust, C#, or Java."
-keywords: ["X Chat tutorial", "X Chat quickstart", "Chat XDK", "encrypted DM", "Python", "TypeScript", "Go", "Rust", "C#", "Java"]
+description: "A hands-on tutorial that takes you from zero to your first encrypted X Chat message, in Python, TypeScript, Go, Rust, C#, Java, or Ruby."
+keywords: ["X Chat tutorial", "X Chat quickstart", "Chat XDK", "encrypted DM", "Python", "TypeScript", "Go", "Rust", "C#", "Java", "Ruby"]
---
Send and receive encrypted direct messages on X: set up keys, initialize a conversation, send a message, and decrypt inbound traffic.
@@ -82,6 +82,13 @@ X Chat apps use two pieces together:
Available on Maven Central. The jar bundles the native library for macOS (arm64, x64), Linux (x64, arm64), and Windows (x64); no `jna.library.path` setup is needed. Import from `com.x.chatxdk`. Requires JDK 8+.
+
+ ```bash
+ gem install chat_xdk
+ ```
+
+ Available on RubyGems. Published platform gems bundle the native library for macOS (`arm64-darwin`, `x86_64-darwin`), Linux (`x86_64-linux`, `aarch64-linux`), and Windows (`x64-mingw-ucrt`). Import with `require "chat_xdk"`. Requires Ruby 3.0+.
+
Create an API client with your **user** OAuth 2.0 access token:
@@ -269,7 +276,7 @@ Skip this step if you loaded existing keys in [step 2](#2-initialize-the-chat-xd
Finish by calling `set_identity` with the registration's key version, so this session signs as the new identity.
-Ready-to-run one-time registration scripts for every binding live under [`chat-xdk/examples`](https://github.com/xdevplatform/chat-xdk/tree/main/examples) (Python, TypeScript, Go, Rust, C#, and Java). Use them instead of hand-rolling the flow below when you just need to onboard a new identity.
+Ready-to-run one-time registration scripts for every binding live under [`chat-xdk/examples`](https://github.com/xdevplatform/chat-xdk/tree/main/examples) (Python, TypeScript, Go, Rust, C#, Java, and Ruby). Use them instead of hand-rolling the flow below when you just need to onboard a new identity.
diff --git a/xchat/introduction.mdx b/xchat/introduction.mdx
index 0b3801a90..9a4c378bc 100644
--- a/xchat/introduction.mdx
+++ b/xchat/introduction.mdx
@@ -13,7 +13,7 @@ The **X Chat API** lets you send and receive **encrypted** direct messages on X.
| Piece | Responsibility |
|:------|:---------------|
-| **[Chat XDK](/xchat/xchat-xdk)** | Generate keys, encrypt/decrypt, sign/verify, optional passcode-protected secure key backup (Python, JS, Rust, Go, C#, Java) |
+| **[Chat XDK](/xchat/xchat-xdk)** | Generate keys, encrypt/decrypt, sign/verify, optional passcode-protected secure key backup (Python, JS, Rust, Go, C#, Java, Ruby) |
| **X API access** | Public keys, conversation keys, messages, events, media: via **[XDK](/xdks/overview)** ([Python](/xdks/python/overview), [TypeScript](/xdks/typescript/overview), [Java](/xdks/java/overview), [C#](/xdks/csharp/overview)) or HTTPS |
| **Delivery** | [Webhooks or activity stream](/xchat/real-time-events) for live events; events API for history |
diff --git a/xchat/media.mdx b/xchat/media.mdx
index 35235c330..918d44f4e 100644
--- a/xchat/media.mdx
+++ b/xchat/media.mdx
@@ -156,6 +156,27 @@ Read the MIME type and dimensions from the plaintext for the attachment descript
byte[] encryptedBlob = chat.encryptFile(fileParams);
```
+
+ ```ruby
+ require "chat_xdk"
+
+ plaintext = File.binread("photo.jpg")
+ mime = ChatXdk.detect_mime_type(plaintext)
+ dims = ChatXdk.detect_image_dimensions(plaintext)
+ width = dims&.width || 0
+ height = dims&.height || 0
+ # payload: from encrypt_message with media_hash_key in its attachments
+ encrypted_blob = chat.encrypt_file(
+ ChatXdk::EncryptFileParams.new(
+ file: plaintext,
+ event_b64: payload.event_b64,
+ media_hash_key: media_hash_key,
+ conversation_key: raw_conv_key,
+ conversation_key_version: conversation_key_version
+ )
+ )
+ ```
+
`encrypt_file` / `decrypt_file` process the whole file in memory. For large files, `file_encryptor` / `file_decryptor` take the same parameters without the file bytes and return incremental objects: feed chunks with `push`, then call `finish` once; `finish` errors if the file was truncated.
@@ -314,6 +335,30 @@ Encrypt with a media attachment, then POST the send-message body (same field map
// and payload.encodedEventSignature to /2/chat/conversations/{id}/messages
```
+
+ ```ruby
+ # chat has keys loaded and set_identity called (see Getting Started)
+ payload = chat.encrypt_message(
+ ChatXdk::EncryptMessageParams.new(
+ conversation_id: conversation_id,
+ text: caption || "",
+ conversation_key: raw_conv_key,
+ conversation_key_version: conversation_key_version,
+ attachments: [
+ ChatXdk::AttachmentDescriptor.media(
+ media_hash_key: media_hash_key,
+ width: width,
+ height: height,
+ filesize_bytes: ChatXdk.encrypted_file_size(plaintext.bytesize),
+ filename: "photo.jpg"
+ )
+ ]
+ )
+ )
+ # POST payload.message_id (generated by the SDK), payload.encoded_message_create_event,
+ # and payload.encoded_message_event_signature to /2/chat/conversations/{id}/messages
+ ```
+
The conversation key pair can be omitted entirely: with `set_cache_keys(true)` enabled, `encrypt_message` resolves the key and version from the conversation's latest verified key change (see [Getting Started](/xchat/getting-started)).
@@ -424,6 +469,30 @@ Path: [`GET /2/chat/media/{conversation_id}/{media_hash_key}`](/x-api/chat/downl
String mime = ChatXdkUtilities.detectMimeType(plaintext);
```
+
+ ```ruby
+ require "net/http"
+ require "uri"
+ require "chat_xdk"
+
+ api_id = conversation_id.tr(":", "-")
+ uri = URI.parse("https://api.x.com/2/chat/media/#{api_id}/#{media_hash_key}")
+ req = Net::HTTP::Get.new(uri)
+ req["Authorization"] = "Bearer #{access_token}"
+ res = Net::HTTP.start(uri.host, uri.port, use_ssl: true) { |http| http.request(req) }
+
+ # event_b64: the message's event; keys: result.conversation_keys.keys
+ plaintext = chat.decrypt_file(
+ ChatXdk::DecryptFileParams.new(
+ encrypted: res.body.b,
+ event_b64: event_b64,
+ conversation_keys: keys,
+ media_hash_key: media_hash_key
+ )
+ )
+ mime = ChatXdk.detect_mime_type(plaintext) || "application/octet-stream"
+ ```
+
---
diff --git a/xchat/migrate-from-legacy-dms.mdx b/xchat/migrate-from-legacy-dms.mdx
index 73487dd7c..d9466131a 100644
--- a/xchat/migrate-from-legacy-dms.mdx
+++ b/xchat/migrate-from-legacy-dms.mdx
@@ -65,7 +65,8 @@ Existing conversations are upgraded on X's side — you do **not** need to migra
| **Python** (`chatxdk`, `import chat_xdk`) | `pip install chatxdk` | Python 3.10+. Supports Juicebox unlock and `export_keys` / `import_keys`. |
| **JS / TS (browser)** (`@xdevplatform/chat-xdk`) | `npm install @xdevplatform/chat-xdk juicebox-sdk` | WASM for browsers and Node 18+. Keys stay in Juicebox secure key backup (**no key export**). |
| **Node.js (server)** (`@xdevplatform/chat-xdk-server`) | `npm install @xdevplatform/chat-xdk-server` | Server-side `exportKeys` / `importKeys`. Never bundle into a browser app. |
- | **Go, Rust, .NET 8+, JVM (JDK 8+)** | See [Chat XDK](/xchat/xchat-xdk) | Native bindings supporting `export_keys` / `import_keys`. Go ships prebuilt libraries for macOS and Linux `amd64` only (on Linux `ARM64`, use Python or `@xdevplatform/chat-xdk-server`). |
+ | **Go, Rust, .NET 8+, JVM (JDK 8+)** | See [Chat XDK](/xchat/xchat-xdk) | Native bindings supporting `export_keys` / `import_keys`. Go ships prebuilt libraries for macOS and Linux `amd64` only (on Linux `ARM64`, use Python, Ruby, or `@xdevplatform/chat-xdk-server`). |
+ | **Ruby** (`chat_xdk`, `require "chat_xdk"`) | `gem install chat_xdk` | Ruby 3.0+. Bundles prebuilt native libraries for macOS (`arm64`, `x64`), Linux (`x64`, `arm64`), and Windows (`x64`). Supports Juicebox unlock and `export_keys` / `import_keys`. |
There are no Ruby or PHP bindings — run encryption in a small service in a supported language and call it from your app. For REST transport, use the official XDK (`pip install xdk` / `npm install @xdevplatform/xdk`) or any HTTP client.
@@ -237,7 +238,7 @@ OAuth access and encryption keys are **separate control planes**: an OAuth token
- Construct a server/native Chat XDK instance (`@xdevplatform/chat-xdk-server`, Python, Go, .NET, JVM, or Rust — browser WASM cannot export keys) with `juicebox_config`, call `unlock(pin)` **once**, call `export_keys()`, store only the opaque blob in a KMS / HSM / Secrets Manager (one secret per account keyed by `user_id` + `public_key_version`, least-privilege IAM, audited reads), and **discard the PIN immediately**. Workers load the blob with `import_keys(blob, version)` and `set_identity(user_id, version)` — no PIN needed.
+ Construct a server/native Chat XDK instance (`@xdevplatform/chat-xdk-server`, Python, Ruby, Go, .NET, JVM, or Rust — browser WASM cannot export keys) with `juicebox_config`, call `unlock(pin)` **once**, call `export_keys()`, store only the opaque blob in a KMS / HSM / Secrets Manager (one secret per account keyed by `user_id` + `public_key_version`, least-privilege IAM, audited reads), and **discard the PIN immediately**. Workers load the blob with `import_keys(blob, version)` and `set_identity(user_id, version)` — no PIN needed.
**Never auto-retry a wrong PIN:** Juicebox enforces a small, hardware-enforced, **non-renewable** wrong-guess budget (`juicebox_config.max_guess_count`). Exhausting it deletes the backup and makes older encrypted messages unreadable. Fail closed after one wrong attempt. Unlocks also carry an independent edge rate limit (~30 unlocks/min per egress IP) — unlock once and reuse the result.
diff --git a/xchat/xchat-xdk.mdx b/xchat/xchat-xdk.mdx
index e1465681d..56f4c30c8 100644
--- a/xchat/xchat-xdk.mdx
+++ b/xchat/xchat-xdk.mdx
@@ -68,6 +68,19 @@ App walkthrough: [Getting Started](/xchat/getting-started). Sample bots: [chat-x
Available on Maven Central. The jar bundles the native library for macOS (arm64, x64), Linux (x64, arm64), and Windows (x64); no `jna.library.path` setup is needed. Import from `com.x.chatxdk`. Requires JDK 8+.
+
+ ```bash
+ gem install chat_xdk
+ ```
+
+ Or in your `Gemfile`:
+
+ ```ruby
+ gem "chat_xdk"
+ ```
+
+ Available on RubyGems. Published platform gems bundle the native library for macOS (`arm64-darwin`, `x86_64-darwin`), Linux (`x86_64-linux`, `aarch64-linux`), and Windows (`x64-mingw-ucrt`); no Rust toolchain is needed. Import with `require "chat_xdk"` (`ChatXdk`). Requires Ruby 3.0+.
+
---
@@ -257,13 +270,46 @@ The snippets use the two **optional** session stores for the shortest call forms
}
```
+
+ ```ruby
+ require "chat_xdk"
+
+ ChatXdk::Chat.open do |chat|
+ chat.import_keys(ChatXdk::ImportKeysParams.new(keys: private_key_bytes, signing_key_version: signing_key_version))
+ # Or ChatXdk::Chat.open(juicebox_config_json) { |chat| chat.unlock("YOUR_PASSCODE") ... }
+
+ # Session defaults: identity for signing, stored signing keys for
+ # verification, opt-in cache for conversation keys
+ chat.set_identity(ChatXdk::SetIdentityParams.new(user_id: my_user_id, signing_key_version: signing_key_version))
+ chat.set_signing_keys(signing_keys) # all participants
+ chat.set_cache_keys(true)
+
+ # Batch-decrypt the backlog; senders verify against the stored keys
+ result = chat.decrypt_events(ChatXdk::DecryptEventsParams.new(events: raw_events))
+ result.events.each do |dm|
+ if dm.event["type"] == "Message"
+ puts "#{dm.event['sender_id']}: #{dm.event.dig('content', 'text')}"
+ end
+ end
+
+ # Decrypt one live event with the cached conversation key
+ event = chat.decrypt_event(ChatXdk::DecryptEventParams.new(event_b64: one_event_b64))
+
+ # Encrypt and sign as the session identity, under the cached key
+ payload = chat.encrypt_message(
+ ChatXdk::EncryptMessageParams.new(conversation_id: event["conversation_id"], text: "Hi!")
+ )
+ message_id = payload.message_id # SDK-generated; send as message_id
+ end
+ ```
+
---
## Lifecycle and keys
-Construct the SDK, store private keys (passcode-protected secure key backup or a local key blob), register **public** keys with the X Chat API, and call **`set_identity(user_id, signing_key_version)`** after unlock or import. It sets the sender and signing-key version every signed action defaults to, so the encrypt and prepare methods work without per-call identity arguments. Call `generate_keypairs` once per device/app identity; post the registration payload to the public-keys endpoint. Use `setup` / `unlock` (and related passcode helpers) for secure key backup on every binding. `export_keys` / `import_keys` (raw key-blob persistence for bots and servers) are available on the **native bindings only**: Python, Go, .NET, JVM, and Rust. The JS/WASM binding does not expose raw key export or import: in a browser any script that reaches the instance could exfiltrate the identity, so JS keeps keys inside secure key backup. A JS server that wants to avoid a backup-realm round-trip per request should reuse one unlocked `Chat` instance across requests, or run a native binding where key blobs are supported.
+Construct the SDK, store private keys (passcode-protected secure key backup or a local key blob), register **public** keys with the X Chat API, and call **`set_identity(user_id, signing_key_version)`** after unlock or import. It sets the sender and signing-key version every signed action defaults to, so the encrypt and prepare methods work without per-call identity arguments. Call `generate_keypairs` once per device/app identity; post the registration payload to the public-keys endpoint. Use `setup` / `unlock` (and related passcode helpers) for secure key backup on every binding. `export_keys` / `import_keys` (raw key-blob persistence for bots and servers) are available on the **native bindings only**: Python, Ruby, Go, .NET, JVM, and Rust. The JS/WASM binding does not expose raw key export or import: in a browser any script that reaches the instance could exfiltrate the identity, so JS keeps keys inside secure key backup. A JS server that wants to avoid a backup-realm round-trip per request should reuse one unlocked `Chat` instance across requests, or run a native binding where key blobs are supported.
The SDK also needs the version the X API reports for your registered public key, so key-change entries targeting other versions are skipped. `set_identity` records it together with the user id; `import_keys` accepts it directly as an optional argument (Rust and Go use `import_keys_with_version` / `ImportKeysWithVersion`).
@@ -352,6 +398,25 @@ The SDK also needs the version the X API reports for your registered public key,
}
```
+
+ ```ruby
+ require "chat_xdk"
+
+ # Secure key backup (Juicebox)
+ ChatXdk::Chat.open(juicebox_config_json) do |chat|
+ chat.setup("YOUR_PASSCODE") # or chat.unlock("YOUR_PASSCODE")
+ chat.set_identity(ChatXdk::SetIdentityParams.new(user_id: user_id, signing_key_version: version))
+ publics = chat.get_public_keys
+ end
+
+ # Key blob (server / bot)
+ ChatXdk::Chat.open do |chat|
+ chat.import_keys(ChatXdk::ImportKeysParams.new(keys: secret_blob, signing_key_version: version))
+ chat.set_identity(ChatXdk::SetIdentityParams.new(user_id: user_id, signing_key_version: version))
+ blob = chat.export_keys # treat as a password
+ end
+ ```
+
The secure key backup config accepts three shapes: the X API `juicebox_config` object (recommended; passed verbatim), a full `sdk_config` wrapper, or a bare `token_map`.
@@ -359,7 +424,7 @@ The secure key backup config accepts three shapes: the X API `juicebox_config` o
Optional: signature verification is **on by default** (`reject_unverified = true`); call `set_reject_unverified(false)` to disable it (not recommended); `update_config` if backup realm config changes; `is_unlocked` / `has_identity_key` for UI state. Full field lists live in the [chat-xdk repo](https://github.com/xdevplatform/chat-xdk) stubs.
-**Outbound feature-switch check:** Python, JS, Go, .NET, and JVM bindings make an anonymous `GET https://api.x.com/2/chat/features` request to select the current v1 message and media encryption format. Allowlist this URL in firewalled environments — if blocked, the SDK silently falls back to v0.
+**Outbound feature-switch check:** Python, JS, Go, .NET, JVM, and Ruby bindings make an anonymous `GET https://api.x.com/2/chat/features` request to select the current v1 message and media encryption format. Allowlist this URL in firewalled environments — if blocked, the SDK silently falls back to v0.
---
@@ -458,6 +523,16 @@ Use `extract_conversation_keys` on key-change event payloads to rebuild `{ keys,
byte[] one = chat.decryptConversationKey(encryptedBlob);
```
+
+ ```ruby
+ prepared = chat.prepare_conversation_key_change(
+ ChatXdk::ConversationKeyChangeParams.new(public_keys: participants)
+ )
+ extracted = chat.extract_conversation_keys(key_change_blobs)
+ raw = extracted.keys[extracted.latest_version]
+ one = chat.decrypt_conversation_key(encrypted_blob)
+ ```
+
For group create and member adds, pass the params each method needs (member/admin id lists for `prepare_group_create`; new plus current roster for `prepare_group_members_change`); see [Groups](/xchat/groups#create-the-group-and-establish-keys) for samples. Both return **two** action signatures; the POST must include both.
@@ -557,6 +632,25 @@ Verification is mandatory by default: omitting signing keys never skips it. With
JsonNode live = chat.decryptEvent(oneEventB64, cached, signingKeys);
```
+
+ ```ruby
+ signing_keys = api_public_keys.map do |row|
+ ChatXdk::SigningKeyEntry.new(
+ user_id: uid,
+ public_key_version: row["public_key_version"].to_s,
+ public_key: row["signing_public_key"],
+ identity_public_key: row["public_key"],
+ identity_public_key_signature: row["identity_public_key_signature"]
+ )
+ end
+
+ result = chat.decrypt_events(ChatXdk::DecryptEventsParams.new(events: raw_events, signing_keys: signing_keys))
+ cached = result.conversation_keys.keys
+ live = chat.decrypt_event(
+ ChatXdk::DecryptEventParams.new(event_b64: one_event_b64, conversation_keys: cached, signing_keys: signing_keys)
+ )
+ ```
+
---
@@ -565,7 +659,7 @@ Verification is mandatory by default: omitting signing keys never skips it. With
**`encrypt_message(conversation_id, text)`** builds the signed ciphertext for a text message; optional `entities`, `attachments` (via `media_hash_key`), `quick_reply`, `should_notify`, and `ttl_msec`. Encrypted message payloads are capped at **20 KB** (~11,000 UTF-8 plaintext bytes). The sender identity resolves from the session (`set_identity`) and the conversation key from the opt-in key cache (`set_cache_keys`), or pass `sender_id` / `signing_key_version` and `conversation_key` + `conversation_key_version` explicitly. The SDK generates the **`message_id`** (a UUID embedded in the signed event) and returns it on the payload. Never mint your own; reuse the same payload on retries so an id is never minted twice. Map the payload into the send-message body: `message_id` → **`message_id`**, `encrypted_content` → **`encoded_message_create_event`**, `encoded_event_signature` → **`encoded_message_event_signature`**.
-**Quick replies and clickable URLs.** Pass `quick_reply` on `encrypt_message` or `encrypt_reply` (supported across all bindings since v0.5.1) with either a `request` (`options: { id, options: [{ id, label, metadata, description }] }`) to present selectable choices, or a `response` (`options: { request_id, metadata, selected_option_id }`) when answering one; user selections arrive in decrypted `content.quick_reply` (`quickReply` in JS). The SDK does **not** auto-extract URLs or mentions from `text`: to make links clickable in X Chat clients, pass explicit `entities` (`"url"`, `"mention"`, etc.) with **UTF-8 byte offsets** (`start` inclusive, `end` exclusive — `EntityDescriptor` in Rust/.NET/JVM, `[start, end, type]` tuples in Python/JS/Go).
+**Quick replies and clickable URLs.** Pass `quick_reply` on `encrypt_message` or `encrypt_reply` (supported across all bindings since v0.5.1) with either a `request` (`options: { id, options: [{ id, label, metadata, description }] }`) to present selectable choices, or a `response` (`options: { request_id, metadata, selected_option_id }`) when answering one; user selections arrive in decrypted `content.quick_reply` (`quickReply` in JS). The SDK does **not** auto-extract URLs or mentions from `text`: to make links clickable in X Chat clients, pass explicit `entities` (`"url"`, `"mention"`, etc.) with **UTF-8 byte offsets** (`start` inclusive, `end` exclusive — `EntityDescriptor` in Rust/.NET/JVM/Ruby, `[start, end, type]` tuples in Python/JS/Go).
**Replies are event-based.** `encrypt_reply(conversation_id, text, reply_to_event)` takes the base64 raw event being replied to. The SDK derives the quoted preview (sequence id, sender, text, entities, attachments) from it and embeds the signed original in the outgoing message so recipients can validate the quote. Pass `reply_to_ckces` (the raw key-change events) when the original was encrypted under an older key version than the reply. When the original was **edited**, pass the raw edit event as `reply_to_edit_event`: the preview then quotes what the message says now (its text and entities come from the edit), and the edit travels alongside the original for the receiver to check. The explicit `reply_to_*` fields remain as overrides for callers that no longer hold the raw event.
@@ -730,6 +824,30 @@ The conversation id passed to `encrypt_message` / `encrypt_reply` can be any for
String title = chat.decrypt(nameCt, rawKey);
```
+
+ ```ruby
+ payload = chat.encrypt_message(
+ ChatXdk::EncryptMessageParams.new(conversation_id: conversation_id, text: "Hello")
+ )
+ # Send body: payload.message_id -> message_id,
+ # payload.encoded_message_create_event -> encoded_message_create_event,
+ # payload.encoded_message_event_signature -> encoded_message_event_signature
+
+ reply = chat.encrypt_reply(
+ ChatXdk::EncryptReplyParams.new(
+ conversation_id: conversation_id,
+ text: "Sounds good",
+ reply_to_event: original_event_b64
+ )
+ )
+
+ reaction = ChatXdk::EncryptReactionParams.new(emoji: "👍", target_event: original_event_b64)
+ add = chat.encrypt_add_reaction(reaction)
+ remove = chat.encrypt_remove_reaction(reaction)
+
+ title = chat.decrypt(encrypted_group_name_b64, raw_key)
+ ```
+
---
@@ -782,6 +900,21 @@ For message attachments in the current (v1) format, initialize the upload first
byte[] plain = chat.decryptStream(ciphertext, rawKey);
```
+
+ ```ruby
+ # File attached to a message:
+ ciphertext = chat.encrypt_file(
+ ChatXdk::EncryptFileParams.new(file: file_bytes, event_b64: payload.event_b64, media_hash_key: media_hash_key)
+ )
+ plain = chat.decrypt_file(
+ ChatXdk::DecryptFileParams.new(encrypted: ciphertext, event_b64: event_b64, conversation_keys: keys, media_hash_key: media_hash_key)
+ )
+
+ # Standalone file under a key you already hold (such as a group avatar):
+ enc_avatar = chat.encrypt_file_with_key(ChatXdk::EncryptFileWithKeyParams.new(file: avatar_bytes, key: raw_key))
+ dec_avatar = chat.decrypt_file_with_key(ChatXdk::DecryptFileWithKeyParams.new(encrypted: enc_avatar, key: raw_key))
+ ```
+
### Incremental streaming for large media
@@ -826,7 +959,7 @@ For large files, avoid holding the whole payload in memory: `stream_encryptor()`
## Utilities
-Base64/hex helpers, MIME sniffing, and image dimensions are available as module-level functions (Python/JS/Rust/Go) or `ChatXdkUtilities` (C#/Java): useful when building attachment metadata without pulling in extra libraries.
+Base64/hex helpers, MIME sniffing, and image dimensions are available as module-level functions (Python/JS/Rust/Go/Ruby) or `ChatXdkUtilities` (C#/Java): useful when building attachment metadata without pulling in extra libraries.
@@ -911,6 +1044,18 @@ Base64/hex helpers, MIME sniffing, and image dimensions are available as module-
long width = wh.width, height = wh.height;
```
+
+ ```ruby
+ b64 = ChatXdk.bytes_to_base64(raw)
+ raw2 = ChatXdk.base64_to_bytes(b64)
+ hexed = ChatXdk.bytes_to_hex(raw)
+ raw3 = ChatXdk.hex_to_bytes(hexed)
+ mime = ChatXdk.detect_mime_type(file_bytes)
+ dims = ChatXdk.detect_image_dimensions(file_bytes)
+ width = dims&.width || 0
+ height = dims&.height || 0
+ ```
+
---
@@ -931,7 +1076,7 @@ For complete field lists, use language stubs in the [chat-xdk repo](https://gith
## Errors
-Python typically raises **`ValueError`** with a descriptive message (for example an invalid passcode). TypeScript/JavaScript throws **`Error`**. Go returns `(value, error)`. Prefer **`decrypt_events`** for history so one bad event does not abort the batch; inspect the errors collection for partial failures.
+Python typically raises **`ValueError`** (subclasses of `ChatXdkError`) with a descriptive message (for example an invalid passcode). Ruby raises **`ChatXdk::Error`** subclasses (`InvalidInputError`, `InvalidStateError`, `ParseError`, `DecryptionError`, `VerificationError`, `InvalidPinError`, `JuiceboxError`) with `#kind` and `#guesses_remaining`. TypeScript/JavaScript throws **`Error`**. Go returns `(value, error)`. Prefer **`decrypt_events`** for history so one bad event does not abort the batch; inspect the errors collection for partial failures.
Some verification errors are **permanent**. Signatures are immutable and verified by rebuilding the signed payload from the event itself, so an old event that fails with `signature missing or no matching signing key` or an ECDSA mismatch will fail on every future load. No retry, key refresh, or API call can heal it. Treat these as tombstones, not transient errors. Rotating the conversation key starts a clean, verifiable history from that point forward.