porting all github actions from bluesky-social/indigo to tangled CI

identity helper for rendering as DID doc

Changed files
+35
atproto
+5
atproto/identity/diddoc_test.go
··· 42 42 hdl, err := id.DeclaredHandle() 43 43 assert.NoError(err) 44 44 assert.Equal("atproto.com", hdl.String()) 45 + 46 + // NOTE: doesn't work if 'id' was in long form 47 + if path != "testdata/did_plc_doc_legacy.json" { 48 + assert.Equal(doc, id.DIDDocument()) 49 + } 45 50 } 46 51 } 47 52
+30
atproto/identity/identity.go
··· 83 83 } 84 84 } 85 85 86 + // 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. 87 + func (ident *Identity) DIDDocument() DIDDocument { 88 + doc := DIDDocument{ 89 + DID: ident.DID, 90 + AlsoKnownAs: ident.AlsoKnownAs, 91 + VerificationMethod: make([]DocVerificationMethod, len(ident.Keys)), 92 + Service: make([]DocService, len(ident.Services)), 93 + } 94 + i := 0 95 + for k, key := range ident.Keys { 96 + doc.VerificationMethod[i] = DocVerificationMethod{ 97 + ID: fmt.Sprintf("%s#%s", ident.DID, k), 98 + Type: key.Type, 99 + Controller: ident.DID.String(), 100 + PublicKeyMultibase: key.PublicKeyMultibase, 101 + } 102 + i += 1 103 + } 104 + i = 0 105 + for k, svc := range ident.Services { 106 + doc.Service[i] = DocService{ 107 + ID: fmt.Sprintf("#%s", k), 108 + Type: svc.Type, 109 + ServiceEndpoint: svc.URL, 110 + } 111 + i += 1 112 + } 113 + return doc 114 + } 115 + 86 116 // Identifies and parses the atproto repo signing public key, specifically, out of any keys in this identity's DID document. 87 117 // 88 118 // Returns [ErrKeyNotFound] if there is no such key.