···4242 hdl, err := id.DeclaredHandle()
4343 assert.NoError(err)
4444 assert.Equal("atproto.com", hdl.String())
4545+4646+ // NOTE: doesn't work if 'id' was in long form
4747+ if path != "testdata/did_plc_doc_legacy.json" {
4848+ assert.Equal(doc, id.DIDDocument())
4949+ }
4550 }
4651}
4752
+30
atproto/identity/identity.go
···8383 }
8484}
85858686+// Helper to generate a DID document based on an identity. Note that there is flexibility around parsing, and this won't necessarily "round-trip" for every valid DID document.
8787+func (ident *Identity) DIDDocument() DIDDocument {
8888+ doc := DIDDocument{
8989+ DID: ident.DID,
9090+ AlsoKnownAs: ident.AlsoKnownAs,
9191+ VerificationMethod: make([]DocVerificationMethod, len(ident.Keys)),
9292+ Service: make([]DocService, len(ident.Services)),
9393+ }
9494+ i := 0
9595+ for k, key := range ident.Keys {
9696+ doc.VerificationMethod[i] = DocVerificationMethod{
9797+ ID: fmt.Sprintf("%s#%s", ident.DID, k),
9898+ Type: key.Type,
9999+ Controller: ident.DID.String(),
100100+ PublicKeyMultibase: key.PublicKeyMultibase,
101101+ }
102102+ i += 1
103103+ }
104104+ i = 0
105105+ for k, svc := range ident.Services {
106106+ doc.Service[i] = DocService{
107107+ ID: fmt.Sprintf("#%s", k),
108108+ Type: svc.Type,
109109+ ServiceEndpoint: svc.URL,
110110+ }
111111+ i += 1
112112+ }
113113+ return doc
114114+}
115115+86116// Identifies and parses the atproto repo signing public key, specifically, out of any keys in this identity's DID document.
87117//
88118// Returns [ErrKeyNotFound] if there is no such key.