Skip to content

Commit

Permalink
add cmd/didweb
Browse files Browse the repository at this point in the history
Signed-off-by: Xe Iaso <[email protected]>
  • Loading branch information
Xe committed Jan 12, 2025
1 parent 70e85fd commit bc996c9
Show file tree
Hide file tree
Showing 9 changed files with 647 additions and 4 deletions.
3 changes: 3 additions & 0 deletions cmd/didweb/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.keys
did.json
atproto-did
3 changes: 3 additions & 0 deletions cmd/didweb/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# didweb

This is a heavily forked and modified version of [didweb](https://github.com/afternooncurry/bsky-did-web), but made to be much more understandable.
52 changes: 52 additions & 0 deletions cmd/didweb/atproto-recommended-credentials.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package main

import (
"context"
"encoding/json"
"net/http"

"github.com/bluesky-social/indigo/xrpc"
"github.com/whyrusleeping/go-did"
"within.website/x/web"
)

type RecommendedCredentials struct {
AlsoKnownAs []string `json:"alsoKnownAs"`
VerificationMethods struct {
Atproto did.DID `json:"atproto"`
} `json:"verificationMethods"`
RotationKeys []string `json:"rotationKeys"`
Services struct {
AtprotoPds struct {
Type string `json:"type"`
Endpoint string `json:"endpoint"`
} `json:"atproto_pds"`
} `json:"services"`
}

func IdentityGetRecommendedDidCredentials(ctx context.Context, cli *xrpc.Client) (*RecommendedCredentials, error) {
req, err := http.NewRequestWithContext(ctx, http.MethodGet, cli.Host+"/xrpc/com.atproto.identity.getRecommendedDidCredentials", nil)
if err != nil {
return nil, err
}

req.Header.Add("Authorization", "Bearer "+cli.Auth.AccessJwt)
req.Header.Add("Accept", "application/json")

resp, err := http.DefaultClient.Do(req)
if err != nil {
return nil, err
}
defer resp.Body.Close()

if resp.StatusCode != http.StatusOK {
return nil, web.NewError(http.StatusOK, resp)
}

var result RecommendedCredentials
if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
return nil, err
}

return &result, nil
}
24 changes: 24 additions & 0 deletions cmd/didweb/did.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package main

import "github.com/whyrusleeping/go-did"

type Document struct {
Context []string `json:"@context"`
Id did.DID `json:"id"`
AlsoKnownAs []string `json:"alsoKnownAs"`
VerificationMethod []*VerificationMethod `json:"verificationMethod"`
Service []*Service `json:"service"`
}

type VerificationMethod struct {
ID string `json:"id"`
Type string `json:"type"`
Controller string `json:"controller"`
PublicKeyMultibase string `json:"publicKeyMultibase"`
}

type Service struct {
ID did.DID `json:"id"`
Type string `json:"type"`
ServiceEndpoint string `json:"serviceEndpoint"`
}
Loading

0 comments on commit bc996c9

Please sign in to comment.