Documentation
¶
Overview ¶
Package ap implements types that represent the ActivityPub vocabulary.
These types implement database/sql.Scanner and database/sql/driver.Valuer, allowing them to be stored in a SQL database as a JSON column.
Index ¶
- Constants
- Variables
- func Canonical(id string) string
- func Gateway(gw, id string) string
- func IsPortable(id string) bool
- func Origin(id string) (string, error)
- func Origins(id string) (string, string, error)
- func ValidateOrigin(domain string, activity *Activity, origin string) error
- type Activity
- type ActivityType
- type Actor
- type ActorType
- type Array
- type AssertionMethod
- type Attachment
- type AttachmentType
- type Audience
- type Capability
- type Collection
- type CollectionPage
- type CollectionPageType
- type CollectionType
- type Generator
- type Implement
- type Inbox
- type InteractionPolicy
- type Object
- type ObjectType
- type PollOption
- type Proof
- type PublicKey
- type QuotePolicy
- type Resolver
- type ResolverFlag
- type Tag
- type TagType
- type Time
Constants ¶
const ( OrderedCollection CollectionType = "OrderedCollection" OrderedCollectionPage CollectionPageType = "OrderedCollectionPage" )
const ( // Offline disables fetching of remote actors and forces use of local or cached actors. Offline ResolverFlag = 1 // InstanceActor enables discovery of the "instance actor" instead of the regular actor discovery flow. InstanceActor = 2 // GroupActor makes [Resolver] prefer the first [Group] actor in the WebFinger response. GroupActor = 4 )
const Public = "https://www.w3.org/ns/activitystreams#Public"
Public is the special ActivityPub collection used for public addressing.
Variables ¶
var ( ErrInvalidActivity = errors.New("invalid activity") ErrUnsupportedActivity = errors.New("unsupported activity") )
var ( // KeyRegex matches a Multibase-encoded Ed25519 public key. KeyRegex = regexp.MustCompile(`\b(z6Mk[a-km-zA-HJ-NP-Z1-9]+|u7Q[A-Za-z0-9_-]+)\b`) // GatewayURLRegex matches an https:// gateway URL. GatewayURLRegex = regexp.MustCompile(`^https:\/\/[a-z0-9-]+(?:\.[a-z0-9-]+)+\/\.well-known\/apgateway\/did:key:(z6Mk[a-km-zA-HJ-NP-Z1-9]+)((?:[\/#?].*){0,1})`) )
Functions ¶
func Canonical ¶ added in v0.19.0
Canonical returns an ID in canonical form: if portable, it's converted to an ap:// URL.
func Gateway ¶ added in v0.19.0
Gateway returns a https:// gateway URL for a portable ActivityPub ID.
func IsPortable ¶ added in v0.19.0
IsPortable determines whether or not an ActivityPub ID is portable.
func ValidateOrigin ¶ added in v0.21.0
ValidateOrigin validates the origin of an Activity.
In other words, it can be used to enforce a same-owner policy and prevent actors from creating, editing or deleting entities owned by other actors. See https://fediverse.codeberg.page/fep/fep/fe34/ for more details.
Types ¶
type Activity ¶
type Activity struct {
Context any `json:"@context,omitempty"`
ID string `json:"id"`
Type ActivityType `json:"type"`
Actor string `json:"actor"`
Object any `json:"object"`
Target string `json:"target,omitempty"`
To Audience `json:"to"`
CC Audience `json:"cc"`
Published Time `json:"published,omitzero"`
Proof Proof `json:"proof,omitzero"`
}
Activity represents an ActivityPub activity. Object can point to another Activity, an Object or a string.
func (*Activity) UnmarshalJSON ¶
type ActivityType ¶
type ActivityType string
const ( MaxActivityDepth = 3 Create ActivityType = "Create" Follow ActivityType = "Follow" Accept ActivityType = "Accept" Reject ActivityType = "Reject" Undo ActivityType = "Undo" Delete ActivityType = "Delete" Announce ActivityType = "Announce" Update ActivityType = "Update" Move ActivityType = "Move" Like ActivityType = "Like" Dislike ActivityType = "Dislike" EmojiReact ActivityType = "EmojiReact" Add ActivityType = "Add" Remove ActivityType = "Remove" )
type Actor ¶
type Actor struct {
Context any `json:"@context"`
ID string `json:"id"`
Type ActorType `json:"type"`
Inbox string `json:"inbox"`
Outbox string `json:"outbox"`
Endpoints map[string]string `json:"endpoints,omitempty"`
PreferredUsername string `json:"preferredUsername"`
Name string `json:"name,omitempty"`
Summary string `json:"summary,omitempty"`
Followers string `json:"followers,omitempty"`
PublicKey PublicKey `json:"publicKey"`
Icon Array[Attachment] `json:"icon,omitempty"`
Image *Attachment `json:"image,omitempty"`
ManuallyApprovesFollowers bool `json:"manuallyApprovesFollowers"`
AlsoKnownAs Audience `json:"alsoKnownAs,omitzero"`
Published Time `json:"published,omitzero"`
Updated Time `json:"updated,omitzero"`
MovedTo string `json:"movedTo,omitempty"`
Suspended bool `json:"suspended,omitempty"`
Attachment []Attachment `json:"attachment,omitempty"`
AssertionMethod []AssertionMethod `json:"assertionMethod,omitempty"`
Implements Array[Implement] `json:"implements,omitzero"`
Generator Generator `json:"generator,omitzero"`
Gateways []string `json:"gateways,omitempty"`
Proof Proof `json:"proof,omitzero"`
}
Actor represents an ActivityPub actor.
type Array ¶
type Array[T any] []T
Array is an array or a single item.
func (Array[T]) MarshalJSON ¶
func (*Array[T]) UnmarshalJSON ¶
type AssertionMethod ¶ added in v0.19.0
type AssertionMethod struct {
ID string `json:"id"`
Type string `json:"type"`
Controller string `json:"controller"`
PublicKeyMultibase string `json:"publicKeyMultibase"`
}
AssertionMethod contains a public key used to verify requests sent on behalf of an Actor.
type Attachment ¶
type Attachment struct {
Type AttachmentType `json:"type,omitempty"`
MediaType string `json:"mediaType,omitempty"`
URL string `json:"url,omitempty"`
Href string `json:"href,omitempty"`
Name string `json:"name,omitempty"`
Val string `json:"value,omitempty"`
}
func (*Attachment) Scan ¶ added in v0.19.0
func (a *Attachment) Scan(src any) error
type AttachmentType ¶
type AttachmentType string
const ( Image AttachmentType = "Image" PropertyValue AttachmentType = "PropertyValue" )
type Audience ¶
type Audience struct {
data.OrderedMap[string, struct{}]
}
Audience is an ordered, unique list of actor IDs.
func (Audience) MarshalJSON ¶
func (*Audience) UnmarshalJSON ¶
type Capability ¶ added in v0.19.0
type Capability uint
Capability is a capability that may be supported by an ActivityPub server.
const ( // CavageDraftSignatures is support for draft-cavage-http-signatures, with rsa-sha256. CavageDraftSignatures Capability = 1 << iota // RFC9421RSASignatures is support for RFC9421 HTTP signatures, with rsa-v1_5-sha256. RFC9421RSASignatures // RFC9421Ed25519Signatures is support for RFC9421 HTTP signatures, with Ed25119 keys. RFC9421Ed25519Signatures )
type Collection ¶ added in v0.21.0
type Collection struct {
Context any `json:"@context"`
ID string `json:"id"`
Type CollectionType `json:"type"`
First string `json:"first,omitempty"`
Last string `json:"last,omitempty"`
TotalItems *int64 `json:"totalItems,omitempty"`
OrderedItems any `json:"orderedItems,omitzero"`
}
Collection represents an ActivityPub collection.
type CollectionPage ¶ added in v0.21.0
type CollectionPage struct {
Context any `json:"@context"`
ID string `json:"id"`
Type CollectionPageType `json:"type"`
Next string `json:"next,omitempty"`
Prev string `json:"prev,omitempty"`
PartOf string `json:"partOf,omitempty"`
OrderedItems any `json:"orderedItems,omitzero"`
}
CollectionPage represents a Collection page.
type CollectionPageType ¶ added in v0.21.0
type CollectionPageType string
type CollectionType ¶ added in v0.21.0
type CollectionType string
type Generator ¶ added in v0.19.0
type Generator struct {
Type ActorType `json:"type"`
Implements Array[Implement] `json:"implements,omitzero"`
}
Generator generates Object objects.
type Inbox ¶ added in v0.19.0
type Inbox interface {
NewID(actorID, prefix string) (string, error)
Accept(ctx context.Context, followed *Actor, key httpsig.Key, follower, followID string, tx *sql.Tx) error
Announce(ctx context.Context, tx *sql.Tx, actor *Actor, key httpsig.Key, note *Object) error
Create(ctx context.Context, cfg *cfg.Config, post *Object, author *Actor, key httpsig.Key) error
Delete(ctx context.Context, actor *Actor, key httpsig.Key, note *Object) error
Follow(ctx context.Context, follower *Actor, key httpsig.Key, followed string) error
Move(ctx context.Context, from *Actor, key httpsig.Key, to string) error
Reject(ctx context.Context, followed *Actor, key httpsig.Key, follower, followID string, tx *sql.Tx) error
Undo(ctx context.Context, actor *Actor, key httpsig.Key, activity *Activity) error
UpdateActorTx(ctx context.Context, tx *sql.Tx, actor *Actor, key httpsig.Key) error
UpdateActor(ctx context.Context, actor *Actor, key httpsig.Key) error
UpdateNote(ctx context.Context, actor *Actor, key httpsig.Key, note *Object) error
Unfollow(ctx context.Context, follower *Actor, key httpsig.Key, followed, followID string) error
ProcessActivity(ctx context.Context, tx *sql.Tx, path sql.NullString, sender *Actor, activity *Activity, rawActivity string, depth int, shared bool) error
}
Inbox creates and processes activities.
type InteractionPolicy ¶ added in v0.19.0
type InteractionPolicy struct {
CanQuote QuotePolicy `json:"canQuote,omitzero"`
}
InteractionPolicy describes interaction policies for an Object.
type Object ¶
type Object struct {
Context any `json:"@context,omitempty"`
ID string `json:"id"`
Type ObjectType `json:"type"`
AttributedTo string `json:"attributedTo,omitempty"`
InReplyTo string `json:"inReplyTo,omitempty"`
Content string `json:"content,omitempty"`
Summary string `json:"summary,omitempty"`
Sensitive bool `json:"sensitive,omitempty"`
Name string `json:"name,omitempty"`
Published Time `json:"published,omitzero"`
Updated Time `json:"updated,omitzero"`
To Audience `json:"to,omitzero"`
CC Audience `json:"cc,omitzero"`
Audience string `json:"audience,omitempty"`
Tag Array[Tag] `json:"tag,omitzero"`
Attachment []Attachment `json:"attachment,omitempty"`
URL string `json:"url,omitempty"`
Quote string `json:"quote,omitempty"`
InteractionPolicy InteractionPolicy `json:"interactionPolicy,omitzero"`
Proof Proof `json:"proof,omitzero"`
// polls
VotersCount int64 `json:"votersCount,omitempty"`
OneOf []PollOption `json:"oneOf,omitempty"`
AnyOf []PollOption `json:"anyOf,omitempty"`
EndTime Time `json:"endTime,omitzero"`
Closed Time `json:"closed,omitzero"`
}
Object represents most ActivityPub objects. Actors are represented by Actor.
type ObjectType ¶
type ObjectType string
const ( Note ObjectType = "Note" Page ObjectType = "Page" Article ObjectType = "Article" Question ObjectType = "Question" Tombstone ObjectType = "Tombstone" )
type PollOption ¶
type QuotePolicy ¶ added in v0.19.0
type QuotePolicy struct {
AutomaticApproval Audience `json:"automaticApproval,omitzero"`
ManualApproval Audience `json:"manualApproval,omitzero"`
}
QuotePolicy describes quote policies for an Object.
type Resolver ¶
type Resolver interface {
ResolveID(ctx context.Context, keys [2]httpsig.Key, id string, flags ResolverFlag) (*Actor, error)
Resolve(ctx context.Context, keys [2]httpsig.Key, host, name string, flags ResolverFlag) (*Actor, error)
Get(ctx context.Context, keys [2]httpsig.Key, url string) (*http.Response, error)
}
type ResolverFlag ¶
type ResolverFlag uint
type Tag ¶
type Tag struct {
Type TagType `json:"type,omitempty"`
Name string `json:"name,omitempty"`
Href string `json:"href,omitempty"`
Icon *Attachment `json:"icon,omitempty"`
}