+5
atproto/identity/diddoc_test.go
+5
atproto/identity/diddoc_test.go
+30
atproto/identity/identity.go
+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.