···167167 if i.Keys == nil {
168168 return nil, fmt.Errorf("identity has no atproto public key attached")
169169 }
170170- k, ok := i.Keys["atproto"]
170170+ return i.PublicKeyFor("atproto")
171171+}
172172+173173+// Identifies and parses a specified service signing public key, specifically, out of any keys associated with this identity.
174174+//
175175+// Returns [ErrKeyNotFound] if there is no such key.
176176+//
177177+// Note that [crypto.PublicKey] is an interface, not a concrete type.
178178+func (i *Identity) PublicKeyFor(forKey string) (crypto.PublicKey, error) {
179179+ if i.ParsedPublicKey != nil {
180180+ return i.ParsedPublicKey, nil
181181+ }
182182+ if i.Keys == nil {
183183+ return nil, fmt.Errorf("identity has no atproto public key attached")
184184+ }
185185+ k, ok := i.Keys[forKey]
171186 if !ok {
172187 return nil, ErrKeyNotDeclared
173188 }