forked from
hailey.at/cocoon
An atproto PDS written in Go
1package plc
2
3import (
4 "encoding/json"
5
6 "github.com/bluesky-social/indigo/atproto/atdata"
7 "github.com/haileyok/cocoon/identity"
8 cbg "github.com/whyrusleeping/cbor-gen"
9)
10
11type DidCredentials struct {
12 VerificationMethods map[string]string `json:"verificationMethods"`
13 RotationKeys []string `json:"rotationKeys"`
14 AlsoKnownAs []string `json:"alsoKnownAs"`
15 Services map[string]identity.OperationService `json:"services"`
16}
17
18type Operation struct {
19 Type string `json:"type"`
20 VerificationMethods map[string]string `json:"verificationMethods"`
21 RotationKeys []string `json:"rotationKeys"`
22 AlsoKnownAs []string `json:"alsoKnownAs"`
23 Services map[string]identity.OperationService `json:"services"`
24 Prev *string `json:"prev"`
25 Sig string `json:"sig,omitempty"`
26}
27
28type OperationService struct {
29 Type string `json:"type"`
30 Endpoint string `json:"endpoint"`
31}
32
33func (po *Operation) MarshalCBOR() ([]byte, error) {
34 if po == nil {
35 return cbg.CborNull, nil
36 }
37
38 b, err := json.Marshal(po)
39 if err != nil {
40 return nil, err
41 }
42
43 var m map[string]any
44 if err := json.Unmarshal(b, &m); err != nil {
45 return nil, err
46 }
47
48 b, err = atdata.MarshalCBOR(m)
49 if err != nil {
50 return nil, err
51 }
52
53 return b, nil
54}