apub

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2024 License: ISC Imports: 18 Imported by: 0

Documentation

Overview

apub is an implementation of the ActivityPub protocol.

https://www.w3.org/TR/activitypub/ https://www.w3.org/TR/activitystreams-core/ https://www.w3.org/TR/activitystreams-vocabulary/

Index

Constants

View Source
const ContentType string = "application/activity+json"

ContentType is the MIME media type for ActivityPub.

View Source
const NormContext string = "https://www.w3.org/ns/activitystreams"

NormContext is a URL referencing the normative Activity Streams 2.0 JSON-LD @context definition. All Activity variables should have their AtContext field set to this value. See Activity Streams 2.0 section 2.1.

View Source
const PublicCollection string = "https://www.w3.org/ns/activitystreams#Public"

PublicCollection is the ActivityPub ID for the special collection indicating public access. Any Activity addressed to this collection is meant to be available to all users, authenticated or not. See W3C Recommendation ActivityPub Section 5.6.

Variables

View Source
var DocFS embed.FS

DocFS contains the apas overview documentation to be served by http.FileServer.

View Source
var ErrNotExist = errors.New("no such activity")

Functions

func MarshalMail

func MarshalMail(activity *Activity) ([]byte, error)

func SendMail

func SendMail(addr string, auth smtp.Auth, from string, to []string, activity *Activity) error

func Sign

func Sign(req *http.Request, key *rsa.PrivateKey, pubkeyURL string) error

Sign signs the given HTTP request with the matching private key of the public key available at pubkeyURL.

Types

type Activity

type Activity struct {
	AtContext    string     `json:"@context"`
	ID           string     `json:"id"`
	Type         string     `json:"type"`
	Name         string     `json:"name,omitempty"`
	Actor        string     `json:"actor,omitempty"`
	Username     string     `json:"preferredUsername,omitempty"`
	Summary      string     `json:"summary,omitempty"`
	Inbox        string     `json:"inbox,omitempty"`
	Outbox       string     `json:"outbox,omitempty"`
	To           []string   `json:"to,omitempty"`
	CC           []string   `json:"cc,omitempty"`
	Followers    string     `json:"followers,omitempty"`
	InReplyTo    string     `json:"inReplyTo,omitempty"`
	Published    *time.Time `json:"published,omitempty"`
	AttributedTo string     `json:"attributedTo,omitempty"`
	Content      string     `json:"content,omitempty"`
	MediaType    string     `json:"mediaType,omitempty"`
	Source       struct {
		Content   string `json:"content,omitempty"`
		MediaType string `json:"mediaType,omitempty"`
	} `json:"source,omitempty"`
	PublicKey *PublicKey `json:"publicKey,omitempty"`
	Audience  string     `json:"audience,omitempty"`
	Href      string     `json:"href,omitempty"`
	Tag       []Activity `json:"tag,omitempty"`
	// Contains a JSON-encoded Activity, or a URL as a JSON string
	// pointing to an Activity. Use Activity.Unwrap() to access
	// the enclosed, decoded value.
	Object json.RawMessage `json:"object,omitempty"`
}

Activity represents the Activity Streams Object core type. See Activity Streams 2.0, section 4.1.

func Decode

func Decode(r io.Reader) (*Activity, error)

func Lookup

func Lookup(id string) (*Activity, error)

func UnmarshalMail

func UnmarshalMail(msg *mail.Message) (*Activity, error)

func (*Activity) UnmarshalJSON

func (act *Activity) UnmarshalJSON(b []byte) error

func (*Activity) Unwrap

func (act *Activity) Unwrap(client *Client) (*Activity, error)

Unwrap returns the JSON-encoded Activity, if any, enclosed in act. The Activity may be referenced by ID, in which case the activity is looked up by client or by apub.defaultClient if client is nil.

type Actor

type Actor struct {
	AtContext string     `json:"@context"`
	ID        string     `json:"id"`
	Type      string     `json:"type"`
	Name      string     `json:"name"`
	Username  string     `json:"preferredUsername"`
	Summary   string     `json:"summary,omitempty"`
	Inbox     string     `json:"inbox"`
	Outbox    string     `json:"outbox"`
	Followers string     `json:"followers"`
	Published *time.Time `json:"published,omitempty"`
	PublicKey PublicKey  `json:"publicKey"`
}

func DecodeActor

func DecodeActor(r io.Reader) (*Actor, error)

func Finger

func Finger(address string) (*Actor, error)

Finger is convenience function returning the corresponding Actor, if any, of an address resolvable by WebFinger. It is equivalent to doing webfinger.Lookup then LookupActor.

func LookupActor

func LookupActor(id string) (*Actor, error)

func (*Actor) Address

func (a *Actor) Address() *mail.Address

Address generates the most likely address of the Actor. The Actor's name (not the username) is used as the address' proper name, if present. Implementors should verify the address using WebFinger. For example, the followers address for Actor ID https://hachyderm.io/users/otl is:

"Oliver Lowe" <otl+followers@hachyderm.io>

func (*Actor) FollowersAddress

func (a *Actor) FollowersAddress() *mail.Address

FollowersAddress generates a non-standard address representing the Actor's followers using plus addressing. It is the Actor's address username part with a "+followers" suffix. The address cannot be resolved using WebFinger.

For example, the followers address for Actor ID https://hachyderm.io/users/otl is:

"Oliver Lowe (followers)" <otl+followers@hachyderm.io>

type Client

type Client struct {
	*http.Client
	// Key is a RSA private key which will be used to sign requests.
	Key *rsa.PrivateKey
	// PubKeyID is a URL where the corresponding public key of Key
	// may be accessed. This must be set if Key is also set.
	PubKeyID string // actor.PublicKey.ID
}

func (*Client) Lookup

func (c *Client) Lookup(id string) (*Activity, error)

func (*Client) LookupActor

func (c *Client) LookupActor(id string) (*Actor, error)

func (*Client) Send

func (c *Client) Send(inbox string, activity *Activity) (*Activity, error)

type PublicKey

type PublicKey struct {
	ID           string `json:"id"`
	Owner        string `json:"owner"`
	PublicKeyPEM string `json:"publicKeyPem"`
}

Directories

Path Synopsis
cmd
apsend
Command apsend reads a mail message from the standard input and disposes of it based on the provided recipient addresses.
Command apsend reads a mail message from the standard input and disposes of it based on the provided recipient addresses.
internal
sys

Jump to

Keyboard shortcuts

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