A fork of the Cocoon PDS but being made more distributed.
11

Configure Feed

Select the types of activity you want to include in your feed.

simplify imports

Hailey (Mar 29, 2025, 4:33 PM -0700) b8a45307 536b10bd

+33 -34
+13 -14
identity/identity.go
··· 10 10 "strings" 11 11 12 12 "github.com/bluesky-social/indigo/atproto/syntax" 13 - "github.com/haileyok/cocoon/plc" 14 13 ) 15 14 16 15 func ResolveHandle(ctx context.Context, handle string) (string, error) { ··· 94 93 } 95 94 96 95 type DidData struct { 97 - Did string `json:"did"` 98 - VerificationMethods map[string]string `json:"verificationMethods"` 99 - RotationKeys []string `json:"rotationKeys"` 100 - AlsoKnownAs []string `json:"alsoKnownAs"` 101 - Services map[string]DidDataService `json:"services"` 96 + Did string `json:"did"` 97 + VerificationMethods map[string]string `json:"verificationMethods"` 98 + RotationKeys []string `json:"rotationKeys"` 99 + AlsoKnownAs []string `json:"alsoKnownAs"` 100 + Services map[string]OperationService `json:"services"` 102 101 } 103 102 104 - type DidDataService struct { 103 + type OperationService struct { 105 104 Type string `json:"type"` 106 105 Endpoint string `json:"endpoint"` 107 106 } ··· 109 108 type DidLog []DidLogEntry 110 109 111 110 type DidLogEntry struct { 112 - Sig string `json:"sig"` 113 - Prev *string `json:"prev"` 114 - Type string `json:"string"` 115 - Services map[string]plc.OperationService `json:"services"` 116 - AlsoKnownAs []string `json:"alsoKnownAs"` 117 - RotationKeys []string `json:"rotationKeys"` 118 - VerificationMethods map[string]string `json:"verificationMethods"` 111 + Sig string `json:"sig"` 112 + Prev *string `json:"prev"` 113 + Type string `json:"string"` 114 + Services map[string]OperationService `json:"services"` 115 + AlsoKnownAs []string `json:"alsoKnownAs"` 116 + RotationKeys []string `json:"rotationKeys"` 117 + VerificationMethods map[string]string `json:"verificationMethods"` 119 118 } 120 119 121 120 type DidAuditEntry struct {
+12 -12
plc/client.go
··· 48 48 }, nil 49 49 } 50 50 51 - func (c *Client) CreateDID(ctx context.Context, sigkey *crypto.PrivateKeyK256, recovery string, handle string) (string, *Operation, error) { 51 + func (c *Client) CreateDID(sigkey *crypto.PrivateKeyK256, recovery string, handle string) (string, *Operation, error) { 52 52 pubsigkey, err := sigkey.PublicKey() 53 53 if err != nil { 54 54 return "", nil, err ··· 93 93 return "", nil, err 94 94 } 95 95 96 - did, err := didFromOp(&op) 96 + did, err := DidFromOp(&op) 97 97 if err != nil { 98 98 return "", nil, err 99 99 } ··· 101 101 return did, &op, nil 102 102 } 103 103 104 - func didFromOp(op *Operation) (string, error) { 105 - b, err := op.MarshalCBOR() 106 - if err != nil { 107 - return "", err 108 - } 109 - s := sha256.Sum256(b) 110 - b32 := strings.ToLower(base32.StdEncoding.EncodeToString(s[:])) 111 - return "did:plc:" + b32[0:24], nil 112 - } 113 - 114 104 func (c *Client) SignOp(sigkey *crypto.PrivateKeyK256, op *Operation) error { 115 105 b, err := op.MarshalCBOR() 116 106 if err != nil { ··· 153 143 154 144 return nil 155 145 } 146 + 147 + func DidFromOp(op *Operation) (string, error) { 148 + b, err := op.MarshalCBOR() 149 + if err != nil { 150 + return "", err 151 + } 152 + s := sha256.Sum256(b) 153 + b32 := strings.ToLower(base32.StdEncoding.EncodeToString(s[:])) 154 + return "did:plc:" + b32[0:24], nil 155 + }
+8 -8
plc/types.go
··· 4 4 "encoding/json" 5 5 6 6 "github.com/bluesky-social/indigo/atproto/data" 7 + "github.com/haileyok/cocoon/identity" 7 8 cbg "github.com/whyrusleeping/cbor-gen" 8 9 ) 9 10 10 11 type Operation 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]OperationService `json:"services"` 16 - Prev *string `json:"prev"` 17 - Sig string `json:"sig,omitempty"` 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"` 18 19 } 19 20 20 21 type OperationService struct { ··· 22 23 Endpoint string `json:"endpoint"` 23 24 } 24 25 25 - // This is kinda gross. We could just use cborgen i suppose? 26 26 func (po *Operation) MarshalCBOR() ([]byte, error) { 27 27 if po == nil { 28 28 return cbg.CborNull, nil