|
| 1 | +# mx.api |
| 2 | + |
| 3 | +A minimal-dependency client for the |
| 4 | +[Matrix Client-Server HTTP API](https://spec.matrix.org/), suitable for |
| 5 | +talking to a Synapse or Conduit homeserver from R. Two Imports: `curl` |
| 6 | +and `jsonlite`. No tidyverse. |
| 7 | + |
| 8 | +Pairs with [`mx.crypto`](https://github.com/cornball-ai/mx.crypto), |
| 9 | +which handles Olm + Megolm; mx.api itself does no cryptography. |
| 10 | + |
| 11 | +## Install |
| 12 | + |
| 13 | +```r |
| 14 | +# CRAN |
| 15 | +install.packages("mx.api") |
| 16 | + |
| 17 | +# GitHub (development version, 0.1.0.1) |
| 18 | +remotes::install_github("cornball-ai/mx.api") |
| 19 | +``` |
| 20 | + |
| 21 | +## Quick start: log in, send, sync |
| 22 | + |
| 23 | +```r |
| 24 | +library(mx.api) |
| 25 | + |
| 26 | +s <- mx_login( |
| 27 | + server = "https://matrix.example", |
| 28 | + user = "alice", |
| 29 | + password = "hunter2" |
| 30 | +) |
| 31 | + |
| 32 | +room <- mx_room_join(s, "#general:matrix.example") |
| 33 | +mx_send(s, room, "hello from R") |
| 34 | + |
| 35 | +batch <- mx_sync(s, timeout = 0) |
| 36 | +str(batch$rooms$join) |
| 37 | + |
| 38 | +mx_logout(s) |
| 39 | +``` |
| 40 | + |
| 41 | +## What's covered |
| 42 | + |
| 43 | +| Area | Functions | |
| 44 | +|---|---| |
| 45 | +| Session | `mx_register`, `mx_login`, `mx_logout`, `mx_whoami`, `mx_session` | |
| 46 | +| Rooms | `mx_rooms`, `mx_room_create`, `mx_room_join`, `mx_room_leave`, `mx_room_members`, `mx_room_name`, `mx_room_topic` | |
| 47 | +| Messages | `mx_send`, `mx_messages`, `mx_sync`, `mx_react`, `mx_read_receipt` | |
| 48 | +| Media | `mx_upload`, `mx_download` | |
| 49 | +| E2EE transport | `mx_keys_upload`, `mx_keys_query`, `mx_keys_claim`, `mx_send_to_device` | |
| 50 | +| E2EE signing helper | `mx_canonical_json` | |
| 51 | + |
| 52 | +End-to-end **cryptography** is out of scope; pair with `mx.crypto` |
| 53 | +(or another crypto library) to sign and verify the payloads these |
| 54 | +endpoints carry. Helpful framing: |
| 55 | + |
| 56 | +- mx.api speaks Matrix HTTP. It does no signing, no key management, |
| 57 | + no key validation. |
| 58 | +- mx.crypto speaks Olm + Megolm. It does no HTTP. |
| 59 | +- An integration script that wants encrypted rooms uses both. The |
| 60 | + current reference is `mx.crypto/inst/integration/e2e_demo.R`. |
| 61 | + |
| 62 | +## Canonical JSON |
| 63 | + |
| 64 | +`mx_canonical_json()` is the byte-stable encoder Matrix's signing rules |
| 65 | +require. It is hand-rolled (not a jsonlite wrapper) so the |
| 66 | +spec-sensitive choices — key ordering by UTF-8 byte sequence, integer |
| 67 | +range, NaN/Inf/NA rejection, duplicate-key rejection, control-char |
| 68 | +escaping — are visible and unit-tested rather than hidden in another |
| 69 | +package's defaults. |
| 70 | + |
| 71 | +```r |
| 72 | +mx_canonical_json(list(b = 2, a = 1)) |
| 73 | +#> [1] "{\"a\":1,\"b\":2}" |
| 74 | + |
| 75 | +mx_canonical_json(1.5) |
| 76 | +#> Error: mx_canonical_json: non-integer number 1.5 disallowed |
| 77 | +``` |
| 78 | + |
| 79 | +97 assertions exercise the encoder (see `inst/tinytest/test_canonical_json.R`). |
| 80 | + |
| 81 | +## Status |
| 82 | + |
| 83 | +**0.1.0.1** dev marker on `main` (2026-05-13). The 0.1.0 release is on |
| 84 | +CRAN. The 0.1.0.1 delta is additive: |
| 85 | + |
| 86 | +- New transport endpoints for E2EE coordination: |
| 87 | + `mx_keys_upload`, `mx_keys_query`, `mx_keys_claim`, |
| 88 | + `mx_send_to_device`. |
| 89 | +- New `mx_canonical_json` for signature payload encoding. |
| 90 | + |
| 91 | +See `NEWS.md` for the full changelog. |
| 92 | + |
| 93 | +## CI |
| 94 | + |
| 95 | +GitHub Actions via [r-ci](https://github.com/eddelbuettel/r-ci); macOS |
| 96 | +and Ubuntu runners cover every commit + PR. |
| 97 | + |
| 98 | +## License |
| 99 | + |
| 100 | +MIT. See `LICENSE`. |
0 commit comments