···
"github.com/bluesky-social/indigo/atproto/crypto"
17
-
"github.com/bluesky-social/indigo/atproto/data"
"github.com/bluesky-social/indigo/util"
rotationKey *crypto.PrivateKeyK256
···
h: util.RobustHTTPClient(),
51
-
recoveryKey: args.RecoveryKey,
pdsHostname: args.PdsHostname,
56
-
func (c *Client) CreateDID(ctx context.Context, sigkey *crypto.PrivateKeyK256, recovery string, handle string) (string, map[string]any, error) {
51
+
func (c *Client) CreateDID(ctx context.Context, sigkey *crypto.PrivateKeyK256, recovery string, handle string) (string, *PlcOperation, error) {
52
+
pubsigkey, err := sigkey.PublicKey()
pubrotkey, err := c.rotationKey.PublicKey()
···
rotationKeys := []string{pubrotkey.DIDKey()}
64
-
if c.recoveryKey != "" {
65
-
rotationKeys = []string{c.recoveryKey, rotationKeys[0]}
rotationKeys = func(recovery string) []string {
newRotationKeys := []string{recovery}
···
77
-
op, err := c.FormatAndSignAtprotoOp(sigkey, handle, rotationKeys, nil)
75
+
Type: "plc_operation",
76
+
VerificationMethods: map[string]string{
77
+
"atproto": pubsigkey.DIDKey(),
79
+
RotationKeys: rotationKeys,
80
+
AlsoKnownAs: []string{
83
+
Services: map[string]PlcOperationService{
85
+
Type: "AtprotoPersonalDataServer",
86
+
Endpoint: "https://" + c.pdsHostname,
92
+
signed, err := c.FormatAndSignAtprotoOp(sigkey, op)
82
-
did, err := didForCreateOp(op)
97
+
did, err := didFromOp(signed)
102
+
return did, &op, nil
90
-
func (c *Client) UpdateUserHandle(ctx context.Context, didstr string, nhandle string) error {
94
-
func (c *Client) FormatAndSignAtprotoOp(sigkey *crypto.PrivateKeyK256, handle string, rotationKeys []string, prev *string) (map[string]any, error) {
95
-
pubsigkey, err := sigkey.PublicKey()
105
+
func didFromOp(op *PlcOperation) (string, error) {
106
+
b, err := op.MarshalCBOR()
100
-
op := map[string]any{
101
-
"type": "plc_operation",
102
-
"verificationMethods": map[string]string{
103
-
"atproto": pubsigkey.DIDKey(),
105
-
"rotationKeys": rotationKeys,
106
-
"alsoKnownAs": []string{"at://" + handle},
107
-
"services": map[string]any{
108
-
"atproto_pds": map[string]string{
109
-
"type": "AtprotoPersonalDataServer",
110
-
"endpoint": "https://" + c.pdsHostname,
110
+
s := sha256.Sum256(b)
111
+
b32 := strings.ToLower(base32.StdEncoding.EncodeToString(s[:]))
112
+
return "did:plc:" + b32[0:24], nil
116
-
b, err := data.MarshalCBOR(op)
115
+
func (c *Client) FormatAndSignAtprotoOp(sigkey *crypto.PrivateKeyK256, op PlcOperation) (*PlcOperation, error) {
116
+
b, err := op.MarshalCBOR()
···
126
-
op["sig"] = base64.RawURLEncoding.EncodeToString(sig)
126
+
op.Sig = base64.RawURLEncoding.EncodeToString(sig)
131
-
func didForCreateOp(op map[string]any) (string, error) {
132
-
b, err := data.MarshalCBOR(op)
141
-
b32 := strings.ToLower(base32.StdEncoding.EncodeToString(bs))
143
-
return "did:plc:" + b32[0:24], nil
146
-
func (c *Client) SendOperation(ctx context.Context, did string, op any) error {
131
+
func (c *Client) SendOperation(ctx context.Context, did string, op *PlcOperation) error {
b, err := json.Marshal(op)
···
165
-
fmt.Println(resp.StatusCode)
b, err = io.ReadAll(resp.Body)
152
+
return fmt.Errorf("error sending operation. status code: %d, response: %s", resp.StatusCode, string(b))
172
-
fmt.Println(string(b))