1package plc
2
3import (
4 "encoding/json"
5
6 "github.com/bluesky-social/indigo/atproto/data"
7 cbg "github.com/whyrusleeping/cbor-gen"
8)
9
10type PlcOperation struct {
11 Type string `json:"type"`
12 VerificationMethods map[string]string `json:"verificationMethods"`
13 RotationKeys []string `json:"rotationKeys"`
14 AlsoKnownAs []string `json:"alsoKnownAs"`
15 Services map[string]PlcOperationService `json:"services"`
16 Prev *string `json:"prev"`
17 Sig string `json:"sig,omitempty"`
18}
19
20type PlcOperationService struct {
21 Type string `json:"type"`
22 Endpoint string `json:"endpoint"`
23}
24
25// This is kinda gross. We could just use cborgen i suppose?
26func (po *PlcOperation) 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}