ap

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2024 License: BSD-3-Clause Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const ACCEPT_ACTIVITY string = "Accept"
View Source
const ACTIVITYSTREAMS_ACCEPT_HEADER string = `application/ld+json; profile="https://www.w3.org/ns/activitystreams"`

Deprecated, please use ACTIVITYSTREAMS_ACCEPT_HEADER

View Source
const ACTIVITYSTREAMS_CONTEXT string = "https://www.w3.org/ns/activitystreams"
View Source
const ACTIVITYSTREAMS_CONTEXT_PUBLIC string = "https://www.w3.org/ns/activitystreams#Public"
View Source
const ACTIVITY_CONTENT_TYPE string = "application/activity+json"
View Source
const ACTIVITY_LD_CONTENT_TYPE string = `application/ld+json; profile="https://www.w3.org/ns/activitystreams"`
View Source
const CREATE_ACTIVITY string = "Create"
View Source
const FOLLOW_ACTIVITY string = "Follow"

Variables

This section is empty.

Functions

func NewId

func NewId(uris_table *uris.URIs, prefix string) string

NewId return a new identifier in the form of a unique URI.

func ParseAddress added in v0.0.2

func ParseAddress(addr string) (string, string, error)

func ParseAddressFromRequest added in v0.0.2

func ParseAddressFromRequest(req *http.Request) (string, string, error)

func ParseAddressesFromString added in v0.0.2

func ParseAddressesFromString(body string) ([]string, error)

Types

type Activity

type Activity struct {
	// Context needs to be a "whatever" (interface{}) because ActivityPub (JSON-LD)
	// mixes and matches string URIs, arbritrary data structures and arrays of string
	// URIs and arbritrary data structures in @context...
	Context interface{} `json:"@context,omitempty"`
	// Id is the unique identifier for the activity.
	Id string `json:"id"`
	// Type is the name of the activity being performed.
	Type string `json:"type"`
	// Actor is the URI of the person (actor) performing the activity. Note: This is a fully-qualified "profile" URI and not a "@user@host" address.
	Actor string `json:"actor"`
	// To is the list of URIs the activity should be delivered to. Note: The fact that this can be something like [ "https://www.w3.org/ns/activitystreams#Public" ] makes me wonder what the point of this property is (since the relevant issue is the inbox that the encoded activity is delivered to).
	To []string `json:"to,omitempty"`
	// CC is the list of URIs the activity should be copied to. Note: It's not clear what the point of this unless the purpose of this property (and the "To" property) is for an activity to double as a complete record, inclusive of every address it should be delivered to, that can be scheduled for asynchronous delivery.
	Cc []string `json:"cc,omitempty"`
	// Audience limits visibility to just the specified users.
	Audience string `json:"audience,omitempty"`
	// Object is body of the activity itself.
	Object interface{} `json:"object,omitempty"`
	// The RFC3339 date that the activity was published.
	Published string `json:"published,omitempty"`
}

Activity is a struct encapsulating an ActivityPub activity.

func NewAcceptActivity

func NewAcceptActivity(ctx context.Context, uris_table *uris.URIs, from string, object interface{}) (*Activity, error)

NewAcceptActvity returns a new `Activity` instance of type "Accept". The Accept activity "indicates that the actor accepts the object. The target property can be used in certain circumstances to indicate the context into which the object has been accepted."

func NewAnnounceActivity

func NewAnnounceActivity(ctx context.Context, uris_table *uris.URIs, from string, author_addr string, object interface{}) (*Activity, error)

NewAnnounceActivity will return an ActivityPub "Announce" activity from 'from' about 'object' (created by 'author_addr').

func NewBoostActivity

func NewBoostActivity(ctx context.Context, uris_table *uris.URIs, from string, author_addr string, object interface{}) (*Activity, error)

NewBoostActivity will return an ActivityPub "Announce" activity from 'from' about 'object' (created by 'author_addr').

func NewBoostActivityForNote added in v0.0.2

func NewBoostActivityForNote(ctx context.Context, uris_table *uris.URIs, from string, note_uri string) (*Activity, error)

func NewCreateActivity

func NewCreateActivity(ctx context.Context, uris_table *uris.URIs, from string, to []string, object interface{}) (*Activity, error)

NewCreateActivity returns a new `Activity` instance of type "Create".

func NewFollowActivity

func NewFollowActivity(ctx context.Context, uris_table *uris.URIs, from string, to string) (*Activity, error)

NewCreateActivity returns a new `Activity` instance of type "Follow".

func NewUndoFollowActivity

func NewUndoFollowActivity(ctx context.Context, uris_table *uris.URIs, from string, to string) (*Activity, error)

func (*Activity) PostToInbox added in v0.0.2

func (activity *Activity) PostToInbox(ctx context.Context, key_id string, private_key *rsa.PrivateKey, inbox_uri string) error

PostToInbox delivers an Activity message to a specific inbox.

type Actor

type Actor struct {
	// It has to be an interface because JSON-LD... thanks, JSON-LD...
	Context           []interface{} `json:"@context"`
	Id                string        `json:"id"`
	Type              string        `json:"type"`
	PreferredUsername string        `json:"preferredUsername"`
	Inbox             string        `json:"inbox"`
	Outbox            string        `json:"outbox"`
	PublicKey         PublicKey     `json:"publicKey"`

	Following string `json:"following,omitempty"`
	Followers string `json:"followers,omitempty"`
	Name      string `json:"name,omitempty"`
	Summary   string `json:"summary,omitempty"`
	URL       string `json:"url,omitempty"`
	// Don't omitempty because if you do then false values are omitted
	// ManuallyApprovesFollowers bool   `json:"manuallyApprovesFollowers"`
	Discoverable bool          `json:"discoverable,omitempty"`
	Published    string        `json:"published,omitempty"`
	Icon         Icon          `json:"icon,omitempty"`
	Attachments  []*Attachment `json:"attachment,omitempty"` // Is this just a Mastodon-ism?
}

func RetrieveActor added in v0.0.2

func RetrieveActor(ctx context.Context, id string, insecure bool) (*Actor, error)

func RetrieveActorWithProfileURL added in v0.0.2

func RetrieveActorWithProfileURL(ctx context.Context, profile_url string) (*Actor, error)

func (*Actor) Address added in v0.0.2

func (a *Actor) Address() (string, error)

func (*Actor) PublicKeyRSA

func (a *Actor) PublicKeyRSA(ctx context.Context) (*rsa.PublicKey, error)

Returns the `rsa.PublicKey` instance for 'a'.

type Attachment

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

type Followers

type Followers struct {
	Context    string `json:"@context"`
	Id         string `json:"id"`
	Type       string `json:"type"`
	TotalItems uint32 `json:"totalItems"`
	First      string `json:"first"`
}

type Following

type Following struct {
	Context    string `json:"@context"`
	Id         string `json:"id"`
	Type       string `json:"type"`
	TotalItems uint32 `json:"totalItems"`
	First      string `json:"first"`
}

type Icon

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

type Note

type Note struct {
	// Type is the type of the note (aka "Note").
	Type string `json:"type"`
	// Id is the unique identifier for the note.
	Id string `json:"id"`
	// The URI of the actor that the note is attributed to.
	AttributedTo string `json:"attributedTo"`
	// ...
	InReplyTo string `json:"inReplyTo,omitempty"`
	// Zero or more tags associated with the note.
	Tags []*Tag `json:"tag,omitempty"`
	// To is the list of URIs the activity should be delivered to.
	To []string `json:"to"`
	// CC is the list of URIs the activity should be copied to.
	Cc []string `json:"cc,omitempty"`
	// The body of the note.
	Content string `json:"content"`
	// The permanent URL of the post.
	URL string `json:"url"`
	// The RFC3339 date that the activity was published.
	Published string `json:"published"`
	// Zero or more attachments to include with the note.
	Attachments []*Attachment `json:"attachment,omitempty"`
}

func RetrieveNote added in v0.0.2

func RetrieveNote(ctx context.Context, uri string) (*Note, error)

Retrieve note fetches and unmarshals the "application/activity+json" representation of 'uri'.

type OrderedCollection

type OrderedCollection struct {
	// It has to be an interface because JSON-LD... thanks, JSON-LD...
	Context     []interface{}  `json:"@context"`
	Id          string         `json:"id"`
	Summary     string         `json:"summary,omitempty"`
	Type        string         `json:"type"`
	TotalItems  int            `json:"totalItems"`
	OrderedItem []*interface{} `json:"orderedItems,omitempty"`
}

type PostToInboxOptions added in v0.0.2

type PostToInboxOptions struct {
	// KeyId is a pointer (URI) to the actor/profile page where the public key of the actor posting the activity can be retrieved.
	KeyId string
	// The private key of the actor posting the activity used to sign the message.
	PrivateKey *rsa.PrivateKey
	// The URL of the inbox where the Activity should be posted.
	Inbox string
	// Log POST requests before they are sent using the default [log/slog] Logger. Note that this will
	// include the HTTP signature sent with the request so you should apply all the necessary care that
	// these values are logged somewhere you don't want unauthorized eyes to see the.
	LogRequest bool
	// Log the body of the POST response if it contains a status code that is not 200-202 or 204 using
	// the default [log/slog] Logger
	LogResponseOnError bool
}

type PublicKey

type PublicKey struct {
	Id    string `json:"id"`
	Owner string `json:"owner"`
	PEM   string `json:"publicKeyPem"`
}

type Tag

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

Tag is a struct encapsulating details about a tag.

Jump to

Keyboard shortcuts

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