Documentation ¶
Overview ¶
Package activitypub implements ActivityPub types, handling and c2s (client-to-server) functionality
Index ¶
- Constants
- Variables
- func DiscoverActor(uri string) (string, error)
- func EncodePublicKey(key *rsa.PrivateKey) (string, error)
- func FastHash(data []byte) string
- func FastHashString(s string) string
- func GenerateKeys(bits int) (*rsa.PrivateKey, error)
- func GetOrCreateKey(fn string) (key *rsa.PrivateKey, err error)
- func IsWebFingerURI(uri string) bool
- func ParseObject(data []byte) (v any, err error)
- func ReadKey(fn string) (*rsa.PrivateKey, error)
- func SignedRequest(actor *Actor, method, uri string, body io.Reader) (*http.Response, error)
- func WriteKey(fn string, key *rsa.PrivateKey) error
- type Accept
- type ActivityPub
- func (ap *ActivityPub) AddFollower(actor string, follower *Follower)
- func (ap *ActivityPub) Broadcast(actor *Actor, obj any)
- func (ap *ActivityPub) DebugHandler(w http.ResponseWriter, r *http.Request)
- func (ap *ActivityPub) DelFollower(id string, idx int)
- func (ap *ActivityPub) GetAllFollowers() Followers
- func (ap *ActivityPub) GetFollowerFor(id, actor string) (*Follower, int)
- func (ap *ActivityPub) GetFollowers(id string) Followers
- func (ap *ActivityPub) GetNote(uri string) (*Note, error)
- func (ap *ActivityPub) InboxHandler(w http.ResponseWriter, r *http.Request)
- func (ap *ActivityPub) IsActor(uri string) bool
- func (ap *ActivityPub) IsFollowing(id, actor string) bool
- func (ap *ActivityPub) Load() error
- func (ap *ActivityPub) Lookup(uri string) (*Actor, error)
- func (ap *ActivityPub) Save() error
- func (ap *ActivityPub) Send(actor *Actor, to string, obj any)
- func (ap *ActivityPub) Stats() (stats Stats)
- type Actor
- type Create
- type Delete
- type Follow
- type Follower
- type Followers
- type Icon
- type Note
- type OrderedCollection
- type PublicKey
- type Reject
- type Stats
- type Tag
- type Tags
- type Undo
Constants ¶
const ( // ActivityContentType is the content type for all ActivityPub activities ActivityContentType = "application/activity+json" // LinkedDataContentType is the JSON Linked Data type LinkedDataContentType = "application/ld+json" // ActivityBaseURI the URI for the ActivityStreams namespace ActivityBaseURI = "https://www.w3.org/ns/activitystreams" // SecurityContextURI the URI for the security namespace (for an Actor's PublicKey) SecurityContextURI = "https://w3id.org/security/v1" // PublicNS is the reference to the Public entity in the ActivityStreams namespace. PublicNS = ActivityBaseURI + "#Public" )
Variables ¶
var DefaultContext = []string{ ActivityBaseURI, SecurityContextURI, }
DefaultContext is a slice of URIs that form the default context for all objects
var ( // ErrUnsupportedObject is the error returned when parsing objects that are not supported ErrUnsupportedObject = errors.New("error: unsupported object") )
Functions ¶
func DiscoverActor ¶
DiscoverActor performs a webfinger lookup for `uri` and returns the actor's id
func EncodePublicKey ¶
func EncodePublicKey(key *rsa.PrivateKey) (string, error)
EncodePublicKey encodes the public key of a private rsa key
func FastHashString ¶
func GenerateKeys ¶
func GenerateKeys(bits int) (*rsa.PrivateKey, error)
GenerateKeys generates a private rsa key
func GetOrCreateKey ¶
func GetOrCreateKey(fn string) (key *rsa.PrivateKey, err error)
GetOrCreateKey reads the private rsa key from a file or creates a new one if it doesn't exist
func IsWebFingerURI ¶
IsWebFingerURI returns true if the `uri` looks like a webfinger URI
func ParseObject ¶
ParseObject parses the JSON object into an ActivityPub activity object by first inspecting its type before un-marshalling into the correct type.
func ReadKey ¶
func ReadKey(fn string) (*rsa.PrivateKey, error)
ReadKey reads the private rsa key from a file
func SignedRequest ¶
SignedRequest performs a signed request using the Actor's private key
Types ¶
type Accept ¶
type Accept struct { Context any `json:"@context"` ID string `json:"id"` Type string `json:"type"` Actor string `json:"actor"` Object any `json:"object"` }
Accept is an Accept activity
func AcceptFollow ¶
AcceptFollow creates a new ActivityPub Accept Activity with an embedded Follow object
type ActivityPub ¶
type ActivityPub struct { sync.RWMutex // HandleFollow is a function that handles an incoming Follow from an Activity Pub actor // Consumers should override this field with a custom handler that suits the application. HandleFollow func(actor *Actor, follow *Follow) error // HandleNote is a function that handles an incoming Note from an Activity Pub actor // Consumers should override this field with a custom handler that suits the application. HandleNote func(actor *Actor, note *Note) error // LoadActor is a function that takes an actor `id` (URI) as input and returns an `*Actor` object // Consumers should override this field with a custom actor loader that suits the application. LoadActor func(id string) (*Actor, error) // NewID is a function that returns a new unique identifier for a new activity. // In the case of arguments supplied, a hash should be generated from the arguments supplied // to create a content addressable identifier. // Consumers should override this field with a custom function that suits the application. NewID func(args ...string) string // contains filtered or unexported fields }
func New ¶
func New(fn string, actor *Actor) *ActivityPub
New returns a new ActivityPub endpoint and processor
func (*ActivityPub) AddFollower ¶
func (ap *ActivityPub) AddFollower(actor string, follower *Follower)
func (*ActivityPub) Broadcast ¶
func (ap *ActivityPub) Broadcast(actor *Actor, obj any)
func (*ActivityPub) DebugHandler ¶
func (ap *ActivityPub) DebugHandler(w http.ResponseWriter, r *http.Request)
func (*ActivityPub) DelFollower ¶
func (ap *ActivityPub) DelFollower(id string, idx int)
func (*ActivityPub) GetAllFollowers ¶
func (ap *ActivityPub) GetAllFollowers() Followers
func (*ActivityPub) GetFollowerFor ¶
func (ap *ActivityPub) GetFollowerFor(id, actor string) (*Follower, int)
func (*ActivityPub) GetFollowers ¶
func (ap *ActivityPub) GetFollowers(id string) Followers
func (*ActivityPub) InboxHandler ¶
func (ap *ActivityPub) InboxHandler(w http.ResponseWriter, r *http.Request)
func (*ActivityPub) IsActor ¶
func (ap *ActivityPub) IsActor(uri string) bool
func (*ActivityPub) IsFollowing ¶
func (ap *ActivityPub) IsFollowing(id, actor string) bool
func (*ActivityPub) Load ¶
func (ap *ActivityPub) Load() error
func (*ActivityPub) Save ¶
func (ap *ActivityPub) Save() error
func (*ActivityPub) Stats ¶
func (ap *ActivityPub) Stats() (stats Stats)
type Actor ¶
type Actor struct { Context any `json:"@context"` ID string `json:"id"` Type string `json:"type"` Icon Icon `json:"icon"` Summary string `json:"summary"` PreferredUsername string `json:"preferredUsername"` Inbox string `json:"inbox"` Outbox string `json:"outbox"` Following string `json:"following"` Followers string `json:"followers"` PublicKey PublicKey `json:"publicKey"` // contains filtered or unexported fields }
Actor is a basic ActivityPub Actor
func LookupActor ¶
LookupActor looks up an actor by its URI and returns an Actor object
func NewService ¶
NewService creates a new ActivityPub Actor of Type Service
type Create ¶
type Create struct { Context any `json:"@context"` ID string `json:"id"` Type string `json:"type"` Actor string `json:"actor"` Object any `json:"object"` // XXX: Can be "foo" or ["foo", "bar"] // TODO: Do a better job of handling this? To any `json:"to"` }
Create is a Create activity
type Delete ¶
type Delete struct { Context any `json:"@context"` ID string `json:"id"` Type string `json:"type"` Actor string `json:"actor"` Object any `json:"object"` }
Delete is a Delete activity
type Follow ¶
type Follow struct { Context any `json:"@context"` ID string `json:"id"` Type string `json:"type"` Actor string `json:"actor"` Object string `json:"object"` To string `json:"to"` }
Follow is a Follow activity
type Follower ¶
type Follower struct { Actor string `json:"actor"` Inbox string `json:"inbox"` CreatedAt time.Time `json:"created_at"` }
func NewFollower ¶
type Icon ¶
type Icon struct { Type string `json:"type"` MediaType string `json:"mediaType"` URL string `json:"url"` }
Icon is an Icon
type Note ¶
type Note struct { ID string `json:"id"` Type string `json:"type"` To any `json:"to"` Tag Tags `json:"tag"` Content string `json:"content"` Published time.Time `json:"published"` AttributeTo string `json:"attributedTo"` InReplyTo string `json:"inReplyTo"` }
Note is a Note object type embedded in an Create Activity
type OrderedCollection ¶
type OrderedCollection struct { Context any `json:"@context"` ID string `json:"id"` Type string `json:"type"` First string `json:"first"` }
OrderedCollection is an Ordered Collection for Outboxes
func NewOrderedCollection ¶
func NewOrderedCollection(id string) *OrderedCollection
NewOrderedCollection creates a new ActivityPub OrderedCollection
type PublicKey ¶
type PublicKey struct { ID string `json:"id"` Owner string `json:"owner"` PublicKey string `json:"publicKeyPem"` }
PublicKey is a a Person's Public RSA Key
type Reject ¶
type Reject struct { Context any `json:"@context"` ID string `json:"id"` Type string `json:"type"` Actor string `json:"actor"` Object any `json:"object"` }
Reject is an Reject activity