An atproto PDS written in Go

simplify imports

Changed files
+33 -34
identity
plc
+13 -14
identity/identity.go
···
"strings"
"github.com/bluesky-social/indigo/atproto/syntax"
-
"github.com/haileyok/cocoon/plc"
)
func ResolveHandle(ctx context.Context, handle string) (string, error) {
···
}
type DidData struct {
-
Did string `json:"did"`
-
VerificationMethods map[string]string `json:"verificationMethods"`
-
RotationKeys []string `json:"rotationKeys"`
-
AlsoKnownAs []string `json:"alsoKnownAs"`
-
Services map[string]DidDataService `json:"services"`
+
Did string `json:"did"`
+
VerificationMethods map[string]string `json:"verificationMethods"`
+
RotationKeys []string `json:"rotationKeys"`
+
AlsoKnownAs []string `json:"alsoKnownAs"`
+
Services map[string]OperationService `json:"services"`
}
-
type DidDataService struct {
+
type OperationService struct {
Type string `json:"type"`
Endpoint string `json:"endpoint"`
}
···
type DidLog []DidLogEntry
type DidLogEntry struct {
-
Sig string `json:"sig"`
-
Prev *string `json:"prev"`
-
Type string `json:"string"`
-
Services map[string]plc.OperationService `json:"services"`
-
AlsoKnownAs []string `json:"alsoKnownAs"`
-
RotationKeys []string `json:"rotationKeys"`
-
VerificationMethods map[string]string `json:"verificationMethods"`
+
Sig string `json:"sig"`
+
Prev *string `json:"prev"`
+
Type string `json:"string"`
+
Services map[string]OperationService `json:"services"`
+
AlsoKnownAs []string `json:"alsoKnownAs"`
+
RotationKeys []string `json:"rotationKeys"`
+
VerificationMethods map[string]string `json:"verificationMethods"`
}
type DidAuditEntry struct {
+12 -12
plc/client.go
···
}, nil
}
-
func (c *Client) CreateDID(ctx context.Context, sigkey *crypto.PrivateKeyK256, recovery string, handle string) (string, *Operation, error) {
+
func (c *Client) CreateDID(sigkey *crypto.PrivateKeyK256, recovery string, handle string) (string, *Operation, error) {
pubsigkey, err := sigkey.PublicKey()
if err != nil {
return "", nil, err
···
return "", nil, err
}
-
did, err := didFromOp(&op)
+
did, err := DidFromOp(&op)
if err != nil {
return "", nil, err
}
···
return did, &op, nil
}
-
func didFromOp(op *Operation) (string, error) {
-
b, err := op.MarshalCBOR()
-
if err != nil {
-
return "", err
-
}
-
s := sha256.Sum256(b)
-
b32 := strings.ToLower(base32.StdEncoding.EncodeToString(s[:]))
-
return "did:plc:" + b32[0:24], nil
-
}
-
func (c *Client) SignOp(sigkey *crypto.PrivateKeyK256, op *Operation) error {
b, err := op.MarshalCBOR()
if err != nil {
···
return nil
}
+
+
func DidFromOp(op *Operation) (string, error) {
+
b, err := op.MarshalCBOR()
+
if err != nil {
+
return "", err
+
}
+
s := sha256.Sum256(b)
+
b32 := strings.ToLower(base32.StdEncoding.EncodeToString(s[:]))
+
return "did:plc:" + b32[0:24], nil
+
}
+8 -8
plc/types.go
···
"encoding/json"
"github.com/bluesky-social/indigo/atproto/data"
+
"github.com/haileyok/cocoon/identity"
cbg "github.com/whyrusleeping/cbor-gen"
)
type Operation struct {
-
Type string `json:"type"`
-
VerificationMethods map[string]string `json:"verificationMethods"`
-
RotationKeys []string `json:"rotationKeys"`
-
AlsoKnownAs []string `json:"alsoKnownAs"`
-
Services map[string]OperationService `json:"services"`
-
Prev *string `json:"prev"`
-
Sig string `json:"sig,omitempty"`
+
Type string `json:"type"`
+
VerificationMethods map[string]string `json:"verificationMethods"`
+
RotationKeys []string `json:"rotationKeys"`
+
AlsoKnownAs []string `json:"alsoKnownAs"`
+
Services map[string]identity.OperationService `json:"services"`
+
Prev *string `json:"prev"`
+
Sig string `json:"sig,omitempty"`
}
type OperationService struct {
···
Endpoint string `json:"endpoint"`
}
-
// This is kinda gross. We could just use cborgen i suppose?
func (po *Operation) MarshalCBOR() ([]byte, error) {
if po == nil {
return cbg.CborNull, nil