+26
-61
identity/identity.go
+26
-61
identity/identity.go
···
10
"strings"
11
12
"github.com/bluesky-social/indigo/atproto/syntax"
13
)
14
15
-
func ResolveHandle(ctx context.Context, handle string) (string, error) {
16
var did string
17
18
_, err := syntax.ParseHandle(handle)
···
71
return did, nil
72
}
73
74
-
type DidDoc struct {
75
-
Context []string `json:"@context"`
76
-
Id string `json:"id"`
77
-
AlsoKnownAs []string `json:"alsoKnownAs"`
78
-
VerificationMethods []DidDocVerificationMethod `json:"verificationMethods"`
79
-
Service []DidDocService `json:"service"`
80
-
}
81
-
82
-
type DidDocVerificationMethod struct {
83
-
Id string `json:"id"`
84
-
Type string `json:"type"`
85
-
Controller string `json:"controller"`
86
-
PublicKeyMultibase string `json:"publicKeyMultibase"`
87
-
}
88
-
89
-
type DidDocService struct {
90
-
Id string `json:"id"`
91
-
Type string `json:"type"`
92
-
ServiceEndpoint string `json:"serviceEndpoint"`
93
-
}
94
-
95
-
type DidData struct {
96
-
Did string `json:"did"`
97
-
VerificationMethods map[string]string `json:"verificationMethods"`
98
-
RotationKeys []string `json:"rotationKeys"`
99
-
AlsoKnownAs []string `json:"alsoKnownAs"`
100
-
Services map[string]OperationService `json:"services"`
101
-
}
102
-
103
-
type OperationService struct {
104
-
Type string `json:"type"`
105
-
Endpoint string `json:"endpoint"`
106
-
}
107
108
-
type DidLog []DidLogEntry
109
-
110
-
type DidLogEntry struct {
111
-
Sig string `json:"sig"`
112
-
Prev *string `json:"prev"`
113
-
Type string `json:"string"`
114
-
Services map[string]OperationService `json:"services"`
115
-
AlsoKnownAs []string `json:"alsoKnownAs"`
116
-
RotationKeys []string `json:"rotationKeys"`
117
-
VerificationMethods map[string]string `json:"verificationMethods"`
118
-
}
119
-
120
-
type DidAuditEntry struct {
121
-
Did string `json:"did"`
122
-
Operation DidLogEntry `json:"operation"`
123
-
Cid string `json:"cid"`
124
-
Nullified bool `json:"nullified"`
125
-
CreatedAt string `json:"createdAt"`
126
-
}
127
-
128
-
type DidAuditLog []DidAuditEntry
129
-
130
-
func FetchDidDoc(ctx context.Context, did string) (*DidDoc, error) {
131
var ustr string
132
if strings.HasPrefix(did, "did:plc:") {
133
ustr = fmt.Sprintf("https://plc.directory/%s", did)
···
161
return &diddoc, nil
162
}
163
164
-
func FetchDidData(ctx context.Context, did string) (*DidData, error) {
165
var ustr string
166
ustr = fmt.Sprintf("https://plc.directory/%s/data", did)
167
···
189
return &diddata, nil
190
}
191
192
-
func FetchDidAuditLog(ctx context.Context, did string) (DidAuditLog, error) {
193
var ustr string
194
ustr = fmt.Sprintf("https://plc.directory/%s/log/audit", did)
195
···
217
return didlog, nil
218
}
219
220
-
func ResolveService(ctx context.Context, did string) (string, error) {
221
-
diddoc, err := FetchDidDoc(ctx, did)
222
if err != nil {
223
return "", err
224
}
···
10
"strings"
11
12
"github.com/bluesky-social/indigo/atproto/syntax"
13
+
"github.com/bluesky-social/indigo/util"
14
)
15
16
+
func ResolveHandle(ctx context.Context, cli *http.Client, handle string) (string, error) {
17
+
if cli == nil {
18
+
cli = util.RobustHTTPClient()
19
+
}
20
+
21
var did string
22
23
_, err := syntax.ParseHandle(handle)
···
76
return did, nil
77
}
78
79
+
func FetchDidDoc(ctx context.Context, cli *http.Client, did string) (*DidDoc, error) {
80
+
if cli == nil {
81
+
cli = util.RobustHTTPClient()
82
+
}
83
84
var ustr string
85
if strings.HasPrefix(did, "did:plc:") {
86
ustr = fmt.Sprintf("https://plc.directory/%s", did)
···
114
return &diddoc, nil
115
}
116
117
+
func FetchDidData(ctx context.Context, cli *http.Client, did string) (*DidData, error) {
118
+
if cli == nil {
119
+
cli = util.RobustHTTPClient()
120
+
}
121
+
122
var ustr string
123
ustr = fmt.Sprintf("https://plc.directory/%s/data", did)
124
···
146
return &diddata, nil
147
}
148
149
+
func FetchDidAuditLog(ctx context.Context, cli *http.Client, did string) (DidAuditLog, error) {
150
+
if cli == nil {
151
+
cli = util.RobustHTTPClient()
152
+
}
153
+
154
var ustr string
155
ustr = fmt.Sprintf("https://plc.directory/%s/log/audit", did)
156
···
178
return didlog, nil
179
}
180
181
+
func ResolveService(ctx context.Context, cli *http.Client, did string) (string, error) {
182
+
if cli == nil {
183
+
cli = util.RobustHTTPClient()
184
+
}
185
+
186
+
diddoc, err := FetchDidDoc(ctx, cli, did)
187
if err != nil {
188
return "", err
189
}
+10
-3
identity/passport.go
+10
-3
identity/passport.go
···
2
3
import (
4
"context"
5
"sync"
6
)
7
···
16
}
17
18
type Passport struct {
19
bc BackingCache
20
lk sync.Mutex
21
}
22
23
-
func NewPassport(bc BackingCache) *Passport {
24
return &Passport{
25
bc: bc,
26
lk: sync.Mutex{},
27
}
···
40
p.lk.Lock() // this is pretty pathetic, and i should rethink this. but for now, fuck it
41
defer p.lk.Unlock()
42
43
-
doc, err := FetchDidDoc(ctx, did)
44
if err != nil {
45
return nil, err
46
}
···
60
}
61
}
62
63
-
did, err := ResolveHandle(ctx, handle)
64
if err != nil {
65
return "", err
66
}
···
2
3
import (
4
"context"
5
+
"net/http"
6
"sync"
7
)
8
···
17
}
18
19
type Passport struct {
20
+
h *http.Client
21
bc BackingCache
22
lk sync.Mutex
23
}
24
25
+
func NewPassport(h *http.Client, bc BackingCache) *Passport {
26
+
if h == nil {
27
+
h = http.DefaultClient
28
+
}
29
+
30
return &Passport{
31
+
h: h,
32
bc: bc,
33
lk: sync.Mutex{},
34
}
···
47
p.lk.Lock() // this is pretty pathetic, and i should rethink this. but for now, fuck it
48
defer p.lk.Unlock()
49
50
+
doc, err := FetchDidDoc(ctx, p.h, did)
51
if err != nil {
52
return nil, err
53
}
···
67
}
68
}
69
70
+
did, err := ResolveHandle(ctx, p.h, handle)
71
if err != nil {
72
return "", err
73
}
+57
identity/types.go
+57
identity/types.go
···
···
1
+
package identity
2
+
3
+
type DidDoc struct {
4
+
Context []string `json:"@context"`
5
+
Id string `json:"id"`
6
+
AlsoKnownAs []string `json:"alsoKnownAs"`
7
+
VerificationMethods []DidDocVerificationMethod `json:"verificationMethods"`
8
+
Service []DidDocService `json:"service"`
9
+
}
10
+
11
+
type DidDocVerificationMethod struct {
12
+
Id string `json:"id"`
13
+
Type string `json:"type"`
14
+
Controller string `json:"controller"`
15
+
PublicKeyMultibase string `json:"publicKeyMultibase"`
16
+
}
17
+
18
+
type DidDocService struct {
19
+
Id string `json:"id"`
20
+
Type string `json:"type"`
21
+
ServiceEndpoint string `json:"serviceEndpoint"`
22
+
}
23
+
24
+
type DidData struct {
25
+
Did string `json:"did"`
26
+
VerificationMethods map[string]string `json:"verificationMethods"`
27
+
RotationKeys []string `json:"rotationKeys"`
28
+
AlsoKnownAs []string `json:"alsoKnownAs"`
29
+
Services map[string]OperationService `json:"services"`
30
+
}
31
+
32
+
type OperationService struct {
33
+
Type string `json:"type"`
34
+
Endpoint string `json:"endpoint"`
35
+
}
36
+
37
+
type DidLog []DidLogEntry
38
+
39
+
type DidLogEntry struct {
40
+
Sig string `json:"sig"`
41
+
Prev *string `json:"prev"`
42
+
Type string `json:"string"`
43
+
Services map[string]OperationService `json:"services"`
44
+
AlsoKnownAs []string `json:"alsoKnownAs"`
45
+
RotationKeys []string `json:"rotationKeys"`
46
+
VerificationMethods map[string]string `json:"verificationMethods"`
47
+
}
48
+
49
+
type DidAuditEntry struct {
50
+
Did string `json:"did"`
51
+
Operation DidLogEntry `json:"operation"`
52
+
Cid string `json:"cid"`
53
+
Nullified bool `json:"nullified"`
54
+
CreatedAt string `json:"createdAt"`
55
+
}
56
+
57
+
type DidAuditLog []DidAuditEntry
+8
-2
plc/client.go
+8
-2
plc/client.go
···
15
16
"github.com/bluesky-social/indigo/atproto/crypto"
17
"github.com/bluesky-social/indigo/util"
18
)
19
20
type Client struct {
···
25
}
26
27
type ClientArgs struct {
28
Service string
29
RotationKey []byte
30
PdsHostname string
···
35
args.Service = "https://plc.directory"
36
}
37
38
rk, err := crypto.ParsePrivateBytesK256([]byte(args.RotationKey))
39
if err != nil {
40
return nil, err
41
}
42
43
return &Client{
44
-
h: util.RobustHTTPClient(),
45
service: args.Service,
46
rotationKey: rk,
47
pdsHostname: args.PdsHostname,
···
80
AlsoKnownAs: []string{
81
"at://" + handle,
82
},
83
-
Services: map[string]OperationService{
84
"atproto_pds": {
85
Type: "AtprotoPersonalDataServer",
86
Endpoint: "https://" + c.pdsHostname,
···
15
16
"github.com/bluesky-social/indigo/atproto/crypto"
17
"github.com/bluesky-social/indigo/util"
18
+
"github.com/haileyok/cocoon/identity"
19
)
20
21
type Client struct {
···
26
}
27
28
type ClientArgs struct {
29
+
H *http.Client
30
Service string
31
RotationKey []byte
32
PdsHostname string
···
37
args.Service = "https://plc.directory"
38
}
39
40
+
if args.H == nil {
41
+
args.H = util.RobustHTTPClient()
42
+
}
43
+
44
rk, err := crypto.ParsePrivateBytesK256([]byte(args.RotationKey))
45
if err != nil {
46
return nil, err
47
}
48
49
return &Client{
50
+
h: args.H,
51
service: args.Service,
52
rotationKey: rk,
53
pdsHostname: args.PdsHostname,
···
86
AlsoKnownAs: []string{
87
"at://" + handle,
88
},
89
+
Services: map[string]identity.OperationService{
90
"atproto_pds": {
91
Type: "AtprotoPersonalDataServer",
92
Endpoint: "https://" + c.pdsHostname,
+1
-1
server/handle_identity_update_handle.go
+1
-1
server/handle_identity_update_handle.go
···
39
ctx := context.WithValue(e.Request().Context(), "skip-cache", true)
40
41
if strings.HasPrefix(repo.Repo.Did, "did:plc:") {
42
-
log, err := identity.FetchDidAuditLog(ctx, repo.Repo.Did)
43
if err != nil {
44
s.logger.Error("error fetching doc", "error", err)
45
return helpers.ServerError(e, nil)
···
39
ctx := context.WithValue(e.Request().Context(), "skip-cache", true)
40
41
if strings.HasPrefix(repo.Repo.Did, "did:plc:") {
42
+
log, err := identity.FetchDidAuditLog(ctx, nil, repo.Repo.Did)
43
if err != nil {
44
s.logger.Error("error fetching doc", "error", err)
45
return helpers.ServerError(e, nil)
+1
-1
server/handle_server_create_account.go
+1
-1
server/handle_server_create_account.go
···
116
return helpers.ServerError(e, nil)
117
}
118
119
-
did, op, err := s.plcClient.CreateDID(e.Request().Context(), k, "", request.Handle)
120
if err != nil {
121
s.logger.Error("error creating operation", "endpoint", "com.atproto.server.createAccount", "error", err)
122
return helpers.ServerError(e, nil)
+7
-1
server/server.go
+7
-1
server/server.go
···
15
"github.com/bluesky-social/indigo/api/atproto"
16
"github.com/bluesky-social/indigo/atproto/syntax"
17
"github.com/bluesky-social/indigo/events"
18
"github.com/bluesky-social/indigo/xrpc"
19
"github.com/go-playground/validator"
20
"github.com/golang-jwt/jwt/v4"
···
31
)
32
33
type Server struct {
34
httpd *http.Server
35
echo *echo.Echo
36
db *gorm.DB
···
268
return nil, err
269
}
270
271
plcClient, err := plc.NewClient(&plc.ClientArgs{
272
Service: "https://plc.directory",
273
PdsHostname: args.Hostname,
274
RotationKey: rkbytes,
···
293
}
294
295
s := &Server{
296
httpd: httpd,
297
echo: e,
298
logger: args.Logger,
···
308
Relays: args.Relays,
309
},
310
evtman: events.NewEventManager(events.NewMemPersister()),
311
-
passport: identity.NewPassport(identity.NewMemCache(10_000)),
312
}
313
314
s.repoman = NewRepoMan(s) // TODO: this is way too lazy, stop it
···
15
"github.com/bluesky-social/indigo/api/atproto"
16
"github.com/bluesky-social/indigo/atproto/syntax"
17
"github.com/bluesky-social/indigo/events"
18
+
"github.com/bluesky-social/indigo/util"
19
"github.com/bluesky-social/indigo/xrpc"
20
"github.com/go-playground/validator"
21
"github.com/golang-jwt/jwt/v4"
···
32
)
33
34
type Server struct {
35
+
http *http.Client
36
httpd *http.Server
37
echo *echo.Echo
38
db *gorm.DB
···
270
return nil, err
271
}
272
273
+
h := util.RobustHTTPClient()
274
+
275
plcClient, err := plc.NewClient(&plc.ClientArgs{
276
+
H: h,
277
Service: "https://plc.directory",
278
PdsHostname: args.Hostname,
279
RotationKey: rkbytes,
···
298
}
299
300
s := &Server{
301
+
http: h,
302
httpd: httpd,
303
echo: e,
304
logger: args.Logger,
···
314
Relays: args.Relays,
315
},
316
evtman: events.NewEventManager(events.NewMemPersister()),
317
+
passport: identity.NewPassport(h, identity.NewMemCache(10_000)),
318
}
319
320
s.repoman = NewRepoMan(s) // TODO: this is way too lazy, stop it