activitypub

package
v0.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 18, 2026 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Overview

Package activitypub implements ActivityPub federation protocol for Omnom.

This package enables Omnom to act as an ActivityPub server, allowing users to:

  • Follow ActivityPub actors (Mastodon, Pleroma, etc.)
  • Receive posts from followed actors in their feed
  • Be discovered and followed by other ActivityPub servers
  • Serve user profiles via WebFinger

The implementation follows the ActivityPub specification (W3C Recommendation) and supports core activities:

  • Follow/Unfollow: Subscribe to actor updates
  • Accept: Confirm follow requests
  • Create: Receive new posts
  • Announce: Receive boosts/reblogs

HTTP signatures are used to authenticate requests between servers. The package handles signing outgoing requests and verifying incoming requests using RSA keys configured in the application.

Key types:

  • Actor: Represents a user or service on the federation
  • InboxRequest: Incoming activity from another server
  • OutboxItem: Outgoing activity to send to followers

Example usage:

// Follow an actor
actor, err := activitypub.FetchActor(actorURL, userKey, privateKey)
err = activitypub.SendFollowRequest(actor.Inbox, actorURL, userURL, privateKey)

// Process inbox delivery
err = activitypub.ProcessInboxRequest(request, config, user)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SendFollowRequest

func SendFollowRequest(inURL, actorURL, userURL string, key *rsa.PrivateKey) error

SendFollowRequest sends a Follow activity to an actor's inbox. This is used to subscribe to an actor's posts.

func SendSignedPostRequest

func SendSignedPostRequest(us, keyID string, data []byte, key *rsa.PrivateKey) error

SendSignedPostRequest sends an HTTP POST request with HTTP signature authentication. The request is signed using the provided RSA private key.

func SendUnfollowRequest

func SendUnfollowRequest(us, userURL string, key *rsa.PrivateKey) error

SendUnfollowRequest sends an Undo Follow activity to unsubscribe from an actor.

Types

type Attachment

type Attachment struct {
	Type      string `json:"type"`
	MediaType string `json:"mediaType"`
	URL       string `json:"url"`
	Name      string `json:"name"`
}

Attachment represents a media attachment in an ActivityPub post.

type Context

type Context struct {
	ID    string
	Parts []any
}

Context represents the JSON-LD context for ActivityPub messages.

func (*Context) MarshalJSON

func (c *Context) MarshalJSON() ([]byte, error)

MarshalJSON implements custom JSON marshaling for Context. Returns either a string or array depending on the context content.

func (*Context) UnmarshalJSON

func (c *Context) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom JSON unmarshaling for Context. Handles both string and array representations of JSON-LD contexts.

type FollowResponseItem

type FollowResponseItem struct {
	Context string               `json:"@context"`
	ID      string               `json:"id"`
	Type    string               `json:"type"`
	Actor   string               `json:"actor"`
	Object  FollowResponseObject `json:"object"`
}

FollowResponseItem represents a response to a follow request (Accept activity).

type FollowResponseObject

type FollowResponseObject struct {
	ID     string `json:"id"`
	Type   string `json:"type"`
	Actor  string `json:"actor"`
	Object string `json:"object"`
}

FollowResponseObject represents the object in a follow response.

type Identity

type Identity struct {
	Context           *Context `json:"@context"`
	ID                string   `json:"id"`
	Type              string   `json:"type"`
	Following         *string  `json:"following,omitempty"`
	Followers         *string  `json:"followers,omitempty"`
	Inbox             string   `json:"inbox"`
	Outbox            string   `json:"outbox"`
	PreferredUsername string   `json:"preferredUsername"`
	Name              string   `json:"name"`
	Summary           string   `json:"summary"`
	URL               string   `json:"url"`
	Discoverable      bool     `json:"discoverable"`
	Memorial          bool     `json:"memorial"`
	Icon              *Image   `json:"icon"`
	Image             *Image   `json:"image"`
	PubKey            PubKey   `json:"publicKey"`
}

Identity represents an ActivityPub actor (user or service).

func FetchActor

func FetchActor(us string, keyID string, key *rsa.PrivateKey) (*Identity, error)

FetchActor fetches an actor's profile information with HTTP signature authentication.

func (*Identity) GetName

func (i *Identity) GetName() string

GetName returns the best available display name for the actor. Priority: PreferredUsername > Name > ID.

func (*Identity) SaveFavicon

func (i *Identity) SaveFavicon() (string, error)

SaveFavicon downloads and saves user favicon as a storage resource.

type Image

type Image struct {
	Type      string `json:"type"`
	MediaType string `json:"mediaType"`
	URL       string `json:"url"`
}

Image represents an image attachment in ActivityPub.

func (*Image) UnmarshalJSON

func (i *Image) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom JSON unmarshaling for Image. Handles both string URLs and object representations.

type InboxRequest

type InboxRequest struct {
	Context      *Context            `json:"@context,omitempty"`
	ID           string              `json:"id,omitempty"`
	Type         string              `json:"type,omitempty"`
	Actor        string              `json:"actor,omitempty"`
	AttributedTo string              `json:"attributedTo,omitempty"`
	Object       *InboxRequestObject `json:"object,omitempty"`
	To           []string            `json:"to,omitempty"`
	Cc           []string            `json:"cc,omitempty"`
	Published    string              `json:"published,omitempty"`
	Tag          []Tag               `json:"tag,omitempty"`
	Replies      map[string]string   `json:"replies,omitempty"`
}

InboxRequest represents an incoming ActivityPub activity delivered to the inbox.

type InboxRequestObject

type InboxRequestObject struct {
	ID           string        `json:"id,omitempty"`
	Type         string        `json:"type,omitempty"`
	Actor        string        `json:"actor,omitempty"`
	URL          string        `json:"url,omitempty"`
	Object       string        `json:"object,omitempty"`
	Content      string        `json:"content,omitempty"`
	InReplyTo    string        `json:"inReplyTo,omitempty"`
	Context      string        `json:"context,omitempty"`
	AttributedTo string        `json:"attributedTo,omitempty"`
	Attachments  []*Attachment `json:"attachment,omitempty"`
	// contains filtered or unexported fields
}

InboxRequestObject represents the object within an inbox activity.

func FetchObject

func FetchObject(u string) (*InboxRequestObject, error)

FetchObject fetches an ActivityPub object from a URL.

func (*InboxRequestObject) MarshalJSON

func (i *InboxRequestObject) MarshalJSON() ([]byte, error)

MarshalJSON implements custom JSON marshaling for InboxRequestObject. Returns just the ID string when inlineID is true, otherwise returns the full object.

func (*InboxRequestObject) UnmarshalJSON

func (i *InboxRequestObject) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom JSON unmarshaling for InboxRequestObject. Handles both string IDs and full object representations.

type Link struct {
	Rel  string `json:"rel"`
	Href string `json:"href"`
	Type string `json:"type"`
}

Link represents a link in a WebFinger response.

type Outbox

type Outbox struct {
	Context      string        `json:"@context"`
	ID           string        `json:"id"`
	Type         string        `json:"type"`
	Summary      string        `json:"summary"`
	TotalItems   int64         `json:"totalItems"`
	OrderedItems []*OutboxItem `json:"orderedItems"`
}

Outbox represents an ActivityPub outbox containing published activities.

type OutboxItem

type OutboxItem struct {
	Context   string       `json:"@context"`
	ID        string       `json:"id"`
	Type      string       `json:"type"`
	Actor     string       `json:"actor"`
	To        []string     `json:"to"`
	Cc        []string     `json:"cc"`
	Published string       `json:"published"`
	Object    OutboxObject `json:"object"`
}

OutboxItem represents a single activity in an outbox.

type OutboxObject

type OutboxObject struct {
	ID           string            `json:"id"`
	Type         string            `json:"type"`
	Content      string            `json:"content"`
	URL          string            `json:"url"`
	URI          string            `json:"uri"`
	Summary      string            `json:"summary"`
	AttributedTo string            `json:"attributedTo"`
	To           []string          `json:"to"`
	Cc           []string          `json:"cc"`
	Published    string            `json:"published"`
	Tag          []Tag             `json:"tag"`
	Replies      map[string]string `json:"replies"`
}

OutboxObject represents the object being published in an activity.

type PubKey

type PubKey struct {
	ID           string `json:"id"`
	Owner        string `json:"owner"`
	PublicKeyPem string `json:"publicKeyPem"`
}

PubKey represents a public key for HTTP signature verification.

type Tag

type Tag struct {
	Type string `json:"type"`
	Href string `json:"href"`
	Name string `json:"name"`
}

Tag represents a tag or mention in ActivityPub content.

type Webfinger

type Webfinger struct {
	Subject string   `json:"subject"`
	Aliases []string `json:"aliases"`
	Links   []Link   `json:"links"`
}

Webfinger represents a WebFinger response for actor discovery.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL