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