Overview of ATrium Common
mainatproto protocol. It serves as a foundational layer for other ATrium packages.repository·main·Indexed 19 days ago
https://github.com/atrium-rs/atriumA modular ecosystem of Rust libraries for interacting with the AT Protocol and Bluesky. It includes atrium-api for XRPC communication and session management via AtpAgent, atrium-crypto for p256 and k256 cryptographic operations, atrium-identity for DID and handle resolution, atrium-oauth for authentication flows, atrium-repo for user repository and Merkle Search Tree (MST) access, and atrium-xrpc-client providing HTTP backends such as reqwest and isahc with WASM support.
atproto protocol. It serves as a foundational layer for other ATrium packages.ATrium is a collection of Rust libraries designed to work with the AT Protocol. It is organized into modular sub-projects to handle different layers of the protocol, from low-level XRPC definitions to high-level Bluesky SDKs.
Key components include:
XrpcClient trait defined in atrium-xrpc.The bsky-cli is a command-line application for interacting with Bluesky using the ATrium API. It allows you to manage authentication, retrieve social data (profiles, feeds, timelines, notifications), and perform actions like creating or deleting posts and sending chat messages.
To use the CLI, you must first authenticate using the login command to create an authentication session.
Usage: bsky-cli [OPTIONS] <COMMAND>atproto ecosystem. It provides mechanisms to resolve identities using both Decentralized Identifiers (DIDs) and atproto handles.ATrium Crypto provides cryptographic helpers specifically designed for the AT Protocol. It implements two elliptic curve systems:
p256 (NIST P-256 / secp256r1 / prime256v1)k256 (NIST K-256 / secp256k1)The library handles AT Protocol specific requirements such as string encodings, 'low-S' signature validity, byte representation compression, and hashing as defined in the atproto specification.
wasm32, the library automatically enables reqwest features and uses the WASM-compatible reqwest client implementation.XrpcClient trait provides the logic for handling ATProto XRPC requests, but it relies on an underlying HttpClient to perform the actual network operations. To create a custom XRPC client, you must implement the HttpClient trait. This allows you to control how asynchronous HTTP requests are sent (e.g., using different HTTP libraries or adding custom middleware) while still leveraging the high-level XRPC request/response definitions and error handling provided by atrium-xrpc.Use BskyAgent to authenticate with a Bluesky server. Most API methods require an active session. You can perform a standard login using credentials, or persist the session to a file using FileStore to avoid re-authenticating in future runs.
use bsky_sdk::BskyAgent;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let agent = BskyAgent::builder().build().await?;
let session = agent.login("alice@mail.com", "hunter2").await?;
Ok(())
}If you are using tokio as your asynchronous runtime, you can use the reqwest backend. By default, it uses reqwest's default-tls feature.
To use a custom reqwest::Client (for example, to configure timeouts or use rustls instead of native-tls), use the ReqwestClientBuilder to inject your own client instance.
use atrium_xrpc_client::reqwest::ReqwestClientBuilder;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = ReqwestClientBuilder::new("https://bsky.social")
.client(
reqwest::ClientBuilder::new()
.timeout(std::time::Duration::from_millis(1000))
.use_rustls_tls()
.build()?,
)
.build();
Ok(())
}The SDK provides moderation tools similar to the official @atproto/api. To moderate content (like posts in a timeline), first retrieve the user's moderation preferences and label definitions using agent.get_preferences(true). Then, create a moderator instance using agent.moderator(&preferences). You can then use moderator.moderate_post(&post) to evaluate content against the user's settings, using DecisionContext to determine how to filter the output.
use bsky_sdk::moderation::decision::DecisionContext;
use bsky_sdk::BskyAgent;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let agent = BskyAgent::builder().build().await?;
// log in...
let preferences = agent.get_preferences(true).await?;
let moderator = agent.moderator(&preferences).await?;
let output = agent
.api
.app
.bsky
.feed
.get_timeline(
atrium_api::app::bsky::feed::get_timeline::ParametersData {
algorithm: None,
cursor: None,
limit: None,
}
.into(),
)
.await?;
for feed_view_post in &output.feed {
let post_mod = moderator.moderate_post(&feed_view_post.post);
println!(
"{:?} (filter: {})",
feed_view_post.post.cid.as_ref(),
post_mod.ui(DecisionContext::ContentList).filter()
);
}
Ok(())
}If you are not using the tokio runtime, you can use the isahc backend as an alternative to reqwest.
You can initialize a basic client with IsahcClient::new(base_url) or use IsahcClientBuilder to provide a custom isahc::HttpClient with specific configurations like timeouts.
use atrium_xrpc_client::isahc::IsahcClientBuilder;
use isahc::config::Configurable;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = IsahcClientBuilder::new("https://bsky.social")
.client(
isahc::HttpClientBuilder::new()
.timeout(std::time::Duration::from_millis(1000))
.build()?,
)
.build();
Ok(())
}