Crate jdt_activity_pub

Crate jdt_activity_pub 

Source
Expand description

ActivityPub Library for Rust

This crate provides comprehensive support for the ActivityPub protocol, enabling decentralized social networking and content federation. It includes structures and utilities for creating, parsing, and manipulating ActivityPub objects, activities, and actors.

§Features

  • Complete ActivityPub Support: All standard ActivityPub object types including Notes, Actors, Activities, Collections, and more
  • Cryptographic Extensions: Support for end-to-end encryption using Olm/Megolm and MLS (Messaging Layer Security) protocols
  • Media Handling: Image and video processing with metadata extraction
  • Signature Verification: JSON-LD signature support for message integrity
  • WebAssembly Compatible: Core functionality works in WASM environments

§Quick Start

use jdt_activity_pub::{ApNote, ApActor, ApAddress, ApContext, ApActorType};
use jdt_maybe_multiple::MaybeMultiple;

// Create an actor
let actor = ApActor {
    kind: ApActorType::Person,
    preferred_username: "alice".to_string(),
    name: Some("Alice Smith".to_string()),
    inbox: "https://example.com/users/alice/inbox".to_string(),
    outbox: "https://example.com/users/alice/outbox".to_string(),
    ..Default::default()
};

// Create a note
let note = ApNote {
    context: Some(ApContext::default()),
    attributed_to: ApAddress::Address("https://example.com/users/alice".to_string()),
    content: Some("Hello, ActivityPub world!".to_string()),
    to: MaybeMultiple::Single(ApAddress::get_public()),
    ..Default::default()
};

§Environment Variables

This library requires several environment variables to be set:

  • SERVER_NAME: The domain name of your server
  • MEDIA_DIR: Directory path for storing media files

These can be set in a .env file or as system environment variables.

§Modules

  • actor: Actor objects representing users, services, and other entities
  • activity: Activities that describe actions performed by actors
  • object: Core objects like notes, images, and collections
  • collection: Collections for organizing and paginating objects
  • session: Cryptographic sessions and instruments for secure communication
  • signature: Digital signatures for message integrity and authenticity

§Examples

§Creating and Serializing a Note

use jdt_activity_pub::{ApNote, ApAddress, ApContext};
use jdt_maybe_multiple::MaybeMultiple;

let note = ApNote {
    context: Some(ApContext::default()),
    attributed_to: ApAddress::Address("https://example.com/users/alice".to_string()),
    content: Some("This is a test note".to_string()),
    to: MaybeMultiple::Single(ApAddress::get_public()),
    ..Default::default()
};

let json = serde_json::to_string_pretty(&note).unwrap();
println!("{}", json);

§Working with Collections

use jdt_activity_pub::{ApCollection, ApCollectionType, ActivityPub, ApObject};

let mut collection = ApCollection::default();
collection.kind = ApCollectionType::OrderedCollection;
collection.total_items = Some(42);
collection.id = Some("https://example.com/collections/test".to_string());

Re-exports§

pub use accept::ApAccept;
pub use accept::ApAcceptType;
pub use activity::ApActivity;
pub use actor::ApActor;
pub use actor::ApActorTerse;
pub use actor::ApActorType;
pub use actor::ApAddress;
pub use actor::ApCapabilities;
pub use actor::ApPublicKey;
pub use actor::PUBLIC_COLLECTION;
pub use add::ApAdd;
pub use add::ApAddType;
pub use announce::ApAnnounce;
pub use announce::ApAnnounceType;
pub use ap_move::ApMove;
pub use ap_move::ApMoveType;
pub use article::ApArticle;
pub use article::ApArticleType;
pub use article::ApSource;
pub use attachment::ApAttachment;
pub use attachment::ApDocument;
pub use attachment::ApDocumentType;
pub use attachment::ApProof;
pub use attachment::ApUrl;
pub use attachment::ApVerifiableIdentityStatement;
pub use block::ApBlock;
pub use block::ApBlockType;
pub use collection::ActorsPage;
pub use collection::ApCollection;
pub use collection::ApCollectionParams;
pub use collection::ApCollectionType;
pub use collection::Collectible;
pub use collection::CollectionFetcher;
pub use collection::FollowersPage;
pub use collection::LeadersPage;
pub use create::ApCreate;
pub use create::ApCreateType;
pub use delete::ApDelete;
pub use delete::ApDeleteType;
pub use delete::ApTombstone;
pub use delete::ApTombstoneType;
pub use follow::ApFollow;
pub use follow::ApFollowType;
pub use image::ApImage;
pub use image::ApImageType;
pub use like::ApLike;
pub use like::ApLikeType;
pub use note::ApNote;
pub use note::ApNoteType;
pub use note::Metadata;
pub use note::MinimalNote;
pub use object::ApContext;
pub use object::ApEmoji;
pub use object::ApEmojiType;
pub use object::ApEndpoint;
pub use object::ApHashtag;
pub use object::ApHashtagType;
pub use object::ApMention;
pub use object::ApMentionType;
pub use object::ApObject;
pub use object::ApTag;
pub use object::ApTimelineObject;
pub use question::ApQuestion;
pub use question::ApQuestionType;
pub use question::QuestionCollection;
pub use question::QuestionNote;
pub use remove::ApRemove;
pub use remove::ApRemoveType;
pub use session::ApInstrument;
pub use session::ApInstrumentType;
pub use session::ApSession;
pub use session::ApSessionType;
pub use session::CredentialKeyPair;
pub use signature::ApSignature;
pub use signature::ApSignatureType;
pub use video::ApVideo;
pub use video::ApVideoType;
pub use signature::verify_jsonld_signature;
pub use undo::ApUndo;
pub use undo::ApUndoType;
pub use update::ApUpdate;
pub use update::ApUpdateType;

Modules§

accept
ActivityPub Accept Activity
activity
actor
ActivityPub Actor Types
add
ActivityPub Add Activity
announce
ActivityPub Announce Activity
ap_move
ActivityPub Move Activity
article
ActivityPub Article Object
attachment
ActivityPub Attachment Types
block
ActivityPub Block Activity
collection
ActivityPub Collections
create
ActivityPub Create Activity
delete
ActivityPub Delete Activity and Tombstone Types
follow
ActivityPub Follow Activity
image
ActivityPub Image Types
like
ActivityPub Like Activity
note
ActivityPub Note Object
object
ActivityPub Object Types and Context
question
ActivityPub Question Object
remove
ActivityPub Remove Activity
session
ActivityPub Session and Cryptographic Instruments
signature
ActivityPub Cryptographic Signatures
undo
ActivityPub Undo Activity
update
ActivityPub Update Activity
video
ActivityPub Video Types

Structs§

ApDateTime
ActivityPub-compatible datetime wrapper.
Ephemeral
Client-side ephemeral data not part of the ActivityPub specification.
IMAGE_MEDIA_RE
Identifier
MEDIA_DIR
OrdValue
Ordered wrapper for JSON values.
SERVER_NAME

Enums§

ActivityPub
Universal container for any ActivityPub entity.
MaybeMultiple
MaybeReference

Traits§

Referenceable
Temporal
Trait for objects that have temporal properties.

Functions§

deserialize_filter_json_nulls
Custom deserializer for filtering JSON null values and “null” string references from MaybeMultiple fields.
get_followers_ap_id_from_username
Generates an ActivityPub ID for a user’s followers collection.
get_following_ap_id_from_username
Generates an ActivityPub ID for a user’s following collection.
get_session_as_id_from_uuid
Generates an ActivityPub ID for a session from its UUID.
serialize_convert_null_strings
Custom serializer that converts “null” strings to actual JSON null