Federated via graft
2.3 kB
62 lines
1package activitypub
2
3// Actor is the ActivityPub actor object for one series. Field set kept
4// intentionally minimal: what Mastodon needs to resolve, display, and
5// verify signed requests from this actor.
6type Actor struct {
7 Context []string `json:"@context"`
8 ID string `json:"id"`
9 Type string `json:"type"`
10 PreferredUsername string `json:"preferredUsername"`
11 Name string `json:"name"`
12 Summary string `json:"summary,omitempty"`
13 URL string `json:"url,omitempty"`
14 Inbox string `json:"inbox"`
15 Outbox string `json:"outbox"`
16 Followers string `json:"followers"`
17 PublicKey PublicKey `json:"publicKey"`
18 Attachment []Attachment `json:"attachment,omitempty"`
19}
20
21type PublicKey struct {
22 ID string `json:"id"`
23 Owner string `json:"owner"`
24 PublicKeyPem string `json:"publicKeyPem"`
25}
26
27// Attachment is one profile field, rendered by Mastodon as a labeled value
28// on the actor's profile page — used to surface a series' Radicle DID.
29type Attachment struct {
30 Type string `json:"type"`
31 Name string `json:"name"`
32 Value string `json:"value"`
33}
34
35// ActorURI returns the canonical actor URI for a series on host.
36func ActorURI(host, series string) string {
37 return "https://" + host + "/actors/" + series
38}
39
40// BuildActor constructs the actor object for a series. repoURL links to
41// the underlying repo (its Forgejo or Radicle explorer page); publicKeyPEM
42// is that series' stored public key.
43func BuildActor(host, series, repoURL, publicKeyPEM string) Actor {
44 base := ActorURI(host, series)
45 return Actor{
46 Context: []string{"https://www.w3.org/ns/activitystreams", "https://w3id.org/security/v1"},
47 ID: base,
48 Type: "Service",
49 PreferredUsername: series,
50 Name: series,
51 Summary: "Mirrored by graft — commits, issues, and patches for " + series + ".",
52 URL: repoURL,
53 Inbox: base + "/inbox",
54 Outbox: base + "/outbox",
55 Followers: base + "/followers",
56 PublicKey: PublicKey{
57 ID: base + "#main-key",
58 Owner: base,
59 PublicKeyPem: publicKeyPEM,
60 },
61 }
62}