this repo has no description
0
fork

Configure Feed

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

identity: bit of progress

+115 -38
+63
atproto/identity/cmd/atp-id/main.go
··· 1 + package main 2 + 3 + import ( 4 + "fmt" 5 + "os" 6 + 7 + //"github.com/bluesky-social/indigo/atproto/identity" 8 + "github.com/bluesky-social/indigo/atproto/syntax" 9 + 10 + "github.com/urfave/cli/v2" 11 + ) 12 + 13 + func main() { 14 + app := cli.App{ 15 + Name: "atp-id", 16 + Usage: "informal debugging CLI tool for atproto identities", 17 + } 18 + app.Commands = []*cli.Command{ 19 + &cli.Command{ 20 + Name: "resolve-handle", 21 + Usage: "resolve a handle", 22 + Action: runResolveHandle, 23 + }, 24 + &cli.Command{ 25 + Name: "resolve-did", 26 + Usage: "resolve a DID", 27 + Action: runResolveDID, 28 + }, 29 + } 30 + app.RunAndExitOnError() 31 + } 32 + 33 + func runResolveHandle(cctx *cli.Context) error { 34 + s := cctx.Args().First() 35 + if s == "" { 36 + fmt.Println("need to provide handle as an argument") 37 + os.Exit(-1) 38 + } 39 + 40 + handle, err := syntax.ParseHandle(s) 41 + if err != nil { 42 + fmt.Println(err) 43 + os.Exit(-1) 44 + } 45 + fmt.Printf("valid handle syntax: %s\n", handle) 46 + return nil 47 + } 48 + 49 + func runResolveDID(cctx *cli.Context) error { 50 + s := cctx.Args().First() 51 + if s == "" { 52 + fmt.Println("need to provide DID as an argument") 53 + os.Exit(-1) 54 + } 55 + 56 + did, err := syntax.ParseDID(s) 57 + if err != nil { 58 + fmt.Println(err) 59 + os.Exit(-1) 60 + } 61 + fmt.Printf("valid DID syntax: %s\n", did) 62 + return nil 63 + }
+26 -18
atproto/identity/did.go
··· 1 1 package identity 2 2 3 + import ( 4 + "context" 5 + "errors" 6 + "fmt" 7 + 8 + "github.com/bluesky-social/indigo/atproto/syntax" 9 + ) 10 + 3 11 type DIDDocument struct { 4 - DID syntax.DID `json:"id"` 5 - AlsoKnownAs []string `json:"alsoKnownAs,omitempty"` 12 + DID syntax.DID `json:"id"` 13 + AlsoKnownAs []string `json:"alsoKnownAs,omitempty"` 6 14 VerificationMethod []DocVerificationMethod `json:"alsoKnownAs,omitempty"` 7 - Service []DocService `json:"alsoKnownAs,omitempty"` 15 + Service []DocService `json:"alsoKnownAs,omitempty"` 8 16 } 9 17 10 18 type DocVerificationMethod struct { 11 - ID `json:"id"` 12 - Type `json:"type"` 13 - Controller `json:"controller"` 14 - PublicKeyMultibase `json:"publicKeyMultibase"` 19 + ID string `json:"id"` 20 + Type string `json:"type"` 21 + Controller string `json:"controller"` 22 + PublicKeyMultibase string `json:"publicKeyMultibase"` 15 23 } 16 24 17 25 type DocService struct { 18 - ID `json:"id"` 19 - Type `json:"type"` 20 - ServiceEndpoint `json:"serviceEndpoint"` 26 + ID string `json:"id"` 27 + Type string `json:"type"` 28 + ServiceEndpoint string `json:"serviceEndpoint"` 21 29 } 22 30 23 - var ErrDIDNotFound = error.New("DID not found") 31 + var ErrDIDNotFound = errors.New("DID not found") 24 32 25 33 // WARNING: this does *not* bi-directionally verify account metadata; it only implements direct DID-to-DID-document lookup for the supported DID methods, and parses the resulting DID Doc into an Account struct 26 - func ResolveDID(ctx context.Context, did identifier.DID) (*DIDDocument, error) { 34 + func ResolveDID(ctx context.Context, did syntax.DID) (*DIDDocument, error) { 27 35 switch did.Method() { 28 36 case "web": 29 37 panic("NOT IMPLEMENTED") ··· 34 42 } 35 43 } 36 44 37 - func ResolveDIDWeb(ctx context.Context, did identifier.DID) (*DIDDocument, error) { 38 - // XXX 45 + func ResolveDIDWeb(ctx context.Context, did syntax.DID) (*DIDDocument, error) { 46 + return nil, fmt.Errorf("XXX UNIMPLEMENTED") 39 47 } 40 48 41 - func ResolvePLC(ctx context.Context, did identifier.DID) (*DIDDocument, error) { 42 - // XXX 49 + func ResolvePLC(ctx context.Context, did syntax.DID) (*DIDDocument, error) { 50 + return nil, fmt.Errorf("XXX UNIMPLEMENTED") 43 51 } 44 52 45 53 func (d *DIDDocument) Account() Account { 46 - // XXX 54 + panic("XXX UNIMPLEMENTED") 47 55 } 48 56 49 57 // "Renders" a DID Document 50 58 func (a *Account) DIDDocument() DIDDocument { 51 - // XXX 59 + panic("XXX UNIMPLEMENTED") 52 60 }
+3 -2
atproto/identity/doc.go
··· 1 - /* Package identity provides types and routines for resolving handles and DIDs from the network 1 + /* 2 + Package identity provides types and routines for resolving handles and DIDs from the network 2 3 3 - Much of the code in this SDK is based on existing code in indigo:api/extra.go 4 + Much of the implementation of this SDK is based on existing code in indigo:api/extra.go 4 5 */ 5 6 package identity
+12 -5
atproto/identity/handle.go
··· 1 1 package identity 2 2 3 3 import ( 4 + "context" 5 + "errors" 6 + "fmt" 7 + "io" 4 8 "net" 5 - "context" 9 + "net/http" 10 + "strings" 11 + 12 + "github.com/bluesky-social/indigo/atproto/syntax" 6 13 ) 7 14 8 - var ErrHandleNotFound = error.New("handle not found") 15 + var ErrHandleNotFound = errors.New("handle not found") 9 16 10 17 // Does not cross-verify, just does the handle resolution step. 11 - func ResolveHandleDNS(ctx context.Context, handle identifier.Handle) (identifier.DID, error) { 18 + func ResolveHandleDNS(ctx context.Context, handle syntax.Handle) (syntax.DID, error) { 12 19 13 - res, err := net.LookupTXT("_atproto." + handle) 20 + res, err := net.LookupTXT("_atproto." + handle.String()) 14 21 if err != nil { 15 22 return "", fmt.Errorf("handle DNS resolution failed: %w", err) 16 23 } ··· 28 35 return "", ErrHandleNotFound 29 36 } 30 37 31 - func ResolveHandleWellKnown(ctx context.Context, handle identifier.Handle) (identifier.DID, error) { 38 + func ResolveHandleWellKnown(ctx context.Context, handle syntax.Handle) (syntax.DID, error) { 32 39 // NOTE: could pull a client or transport from context 33 40 c := http.DefaultClient 34 41
+11 -13
atproto/identity/identity.go
··· 1 1 package identity 2 2 3 3 import ( 4 - "fmt" 5 - 6 4 "github.com/bluesky-social/indigo/atproto/syntax" 7 5 ) 8 6 ··· 28 26 29 27 // these fields are nullable 30 28 AlsoKnownAs []string 31 - Services map[string]Service 32 - Keys map[string]Key 29 + Services map[string]Service 30 + Keys map[string]Key 33 31 } 34 32 35 33 type Key struct { 36 - Type string 34 + Type string 37 35 PublicKeyMultibase string 38 36 } 39 37 40 38 type Service struct { 41 39 Type string 42 - URL string 40 + URL string 43 41 } 44 42 45 43 func (a *Account) SigningKey() *Key { 46 44 if a.Keys == nil { 47 45 return nil 48 46 } 49 - atp := a.Keys["atproto"] 50 - if atp == nil { 47 + atp, ok := a.Keys["atproto"] 48 + if !ok { 51 49 return nil 52 50 } 53 51 return &atp ··· 55 53 56 54 func (a *Account) PDS() string { 57 55 if a.Services == nil { 58 - return nil 56 + return "" 59 57 } 60 - atp := a.Services["atproto_pds"] 61 - if atp == nil { 62 - return nil 58 + atp, ok := a.Services["atproto_pds"] 59 + if !ok { 60 + return "" 63 61 } 64 - return &atp 62 + return atp.URL 65 63 }