···
"github.com/bluesky-social/indigo/atproto/crypto"
-
"github.com/bluesky-social/indigo/atproto/data"
"github.com/bluesky-social/indigo/util"
rotationKey *crypto.PrivateKeyK256
···
h: util.RobustHTTPClient(),
-
recoveryKey: args.RecoveryKey,
pdsHostname: args.PdsHostname,
-
func (c *Client) CreateDID(ctx context.Context, sigkey *crypto.PrivateKeyK256, recovery string, handle string) (string, map[string]any, error) {
pubrotkey, err := c.rotationKey.PublicKey()
···
rotationKeys := []string{pubrotkey.DIDKey()}
-
if c.recoveryKey != "" {
-
rotationKeys = []string{c.recoveryKey, rotationKeys[0]}
rotationKeys = func(recovery string) []string {
newRotationKeys := []string{recovery}
···
-
op, err := c.FormatAndSignAtprotoOp(sigkey, handle, rotationKeys, nil)
-
did, err := didForCreateOp(op)
-
func (c *Client) UpdateUserHandle(ctx context.Context, didstr string, nhandle string) error {
-
func (c *Client) FormatAndSignAtprotoOp(sigkey *crypto.PrivateKeyK256, handle string, rotationKeys []string, prev *string) (map[string]any, error) {
-
pubsigkey, err := sigkey.PublicKey()
-
"type": "plc_operation",
-
"verificationMethods": map[string]string{
-
"atproto": pubsigkey.DIDKey(),
-
"rotationKeys": rotationKeys,
-
"alsoKnownAs": []string{"at://" + handle},
-
"services": map[string]any{
-
"atproto_pds": map[string]string{
-
"type": "AtprotoPersonalDataServer",
-
"endpoint": "https://" + c.pdsHostname,
-
b, err := data.MarshalCBOR(op)
···
-
op["sig"] = base64.RawURLEncoding.EncodeToString(sig)
-
func didForCreateOp(op map[string]any) (string, error) {
-
b, err := data.MarshalCBOR(op)
-
b32 := strings.ToLower(base32.StdEncoding.EncodeToString(bs))
-
return "did:plc:" + b32[0:24], nil
-
func (c *Client) SendOperation(ctx context.Context, did string, op any) error {
b, err := json.Marshal(op)
···
-
fmt.Println(resp.StatusCode)
b, err = io.ReadAll(resp.Body)
···
"github.com/bluesky-social/indigo/atproto/crypto"
"github.com/bluesky-social/indigo/util"
rotationKey *crypto.PrivateKeyK256
···
h: util.RobustHTTPClient(),
pdsHostname: args.PdsHostname,
+
func (c *Client) CreateDID(ctx context.Context, sigkey *crypto.PrivateKeyK256, recovery string, handle string) (string, *PlcOperation, error) {
+
pubsigkey, err := sigkey.PublicKey()
pubrotkey, err := c.rotationKey.PublicKey()
···
rotationKeys := []string{pubrotkey.DIDKey()}
rotationKeys = func(recovery string) []string {
newRotationKeys := []string{recovery}
···
+
VerificationMethods: map[string]string{
+
"atproto": pubsigkey.DIDKey(),
+
RotationKeys: rotationKeys,
+
Services: map[string]PlcOperationService{
+
Type: "AtprotoPersonalDataServer",
+
Endpoint: "https://" + c.pdsHostname,
+
signed, err := c.FormatAndSignAtprotoOp(sigkey, op)
+
did, err := didFromOp(signed)
+
func didFromOp(op *PlcOperation) (string, error) {
+
b, err := op.MarshalCBOR()
+
b32 := strings.ToLower(base32.StdEncoding.EncodeToString(s[:]))
+
return "did:plc:" + b32[0:24], nil
+
func (c *Client) FormatAndSignAtprotoOp(sigkey *crypto.PrivateKeyK256, op PlcOperation) (*PlcOperation, error) {
+
b, err := op.MarshalCBOR()
···
+
op.Sig = base64.RawURLEncoding.EncodeToString(sig)
+
func (c *Client) SendOperation(ctx context.Context, did string, op *PlcOperation) error {
b, err := json.Marshal(op)
···
b, err = io.ReadAll(resp.Body)
+
return fmt.Errorf("error sending operation. status code: %d, response: %s", resp.StatusCode, string(b))