diff --git a/activitystreams/data.go b/activitystreams/data.go index af5bedd..42f3bfc 100644 --- a/activitystreams/data.go +++ b/activitystreams/data.go @@ -1,70 +1,71 @@ package activitystreams import "fmt" type ( BaseObject struct { Context []string `json:"@context"` Type string `json:"type"` ID string `json:"id"` } PublicKey struct { ID string `json:"id"` Owner string `json:"owner"` PublicKeyPEM string `json:"publicKeyPem"` + privateKey []byte } Image struct { Type string `json:"type"` MediaType string `json:"mediaType"` URL string `json:"url"` } ) type OrderedCollection struct { BaseObject TotalItems int `json:"totalItems"` First string `json:"first"` Last string `json:"last,omitempty"` } func NewOrderedCollection(accountRoot string, items int) *OrderedCollection { oc := OrderedCollection{ BaseObject: BaseObject{ Context: []string{ "https://www.w3.org/ns/activitystreams", }, ID: accountRoot + "/outbox", Type: "OrderedCollection", }, First: accountRoot + "/outbox?page=1", TotalItems: items, } return &oc } type OrderedCollectionPage struct { BaseObject TotalItems int `json:"totalItems"` PartOf string `json:"partOf"` Next string `json:"next,omitempty"` Prev string `json:"prev,omitempty"` OrderedItems []Activity `json:"orderedItems"` } func NewOrderedCollectionPage(accountRoot string, items, page int) *OrderedCollectionPage { ocp := OrderedCollectionPage{ BaseObject: BaseObject{ Context: []string{ "https://www.w3.org/ns/activitystreams", }, ID: fmt.Sprintf("%s/outbox?page=%d", accountRoot, page), Type: "OrderedCollectionPage", }, TotalItems: items, PartOf: accountRoot + "/outbox", Next: fmt.Sprintf("%s/outbox?page=%d", accountRoot, page+1), } return &ocp } diff --git a/activitystreams/person.go b/activitystreams/person.go index 73f95d0..3fc4e41 100644 --- a/activitystreams/person.go +++ b/activitystreams/person.go @@ -1,43 +1,51 @@ package activitystreams type Person struct { BaseObject Inbox string `json:"inbox"` Outbox string `json:"outbox"` PreferredUsername string `json:"preferredUsername"` URL string `json:"url"` Name string `json:"name"` Icon Image `json:"icon"` Following string `json:"following"` Followers string `json:"followers"` Summary string `json:"summary"` PublicKey PublicKey `json:"publicKey"` } func NewPerson(accountRoot string) *Person { p := Person{ BaseObject: BaseObject{ Type: "Person", Context: []string{ "https://www.w3.org/ns/activitystreams", }, ID: accountRoot, }, URL: accountRoot, Following: accountRoot + "/following", Followers: accountRoot + "/followers", Inbox: accountRoot + "/inbox", Outbox: accountRoot + "/outbox", } return &p } func (p *Person) AddPubKey(k []byte) { p.Context = append(p.Context, "https://w3id.org/security/v1") p.PublicKey = PublicKey{ ID: p.ID + "#main-key", Owner: p.ID, PublicKeyPEM: string(k), } } + +func (p *Person) SetPrivKey(k []byte) { + p.PublicKey.privateKey = k +} + +func (p *Person) GetPrivKey() []byte { + return p.PublicKey.privateKey +}