Documentation ¶
Index ¶
- Variables
- func LoadOrGenerateKeys(path string) (ed25519.PublicKey, ed25519.PrivateKey, error)
- func LoadPrivateKey(path string) (ed25519.PrivateKey, error)
- func LoadPrivateKeys(paths ...string) []ed25519.PrivateKey
- type Client
- func (c Client) Lookup(resource string) (*Descriptor, error)
- func (c Client) LookupAll(resource string) (map[string]*Descriptor, error)
- func (c Client) LookupAllWebFinger(wfdesc *webfinger.Descriptor) (map[string]*Descriptor, error)
- func (c Client) LookupID(resource, id string) (*Descriptor, error)
- func (c Client) LookupWebFinger(wfdesc *webfinger.Descriptor) (*Descriptor, error)
- func (c Client) LookupWebFingerID(wfdesc *webfinger.Descriptor, id string) (*Descriptor, error)
- type Descriptor
- type Extra
- type Handler
- type Role
- type ServerInfoHandler
Constants ¶
This section is empty.
Variables ¶
var ( // ErrPubkeyNotFound signifies that the server public key is not found. ErrPubkeyNotFound = errors.New("server pubkey not found") // ErrNoSignature signifies that the response contains no signature. ErrNoSignature = errors.New("response contains no signature") // ErrSignatureMismatch signifies that the message does not match the server signature. ErrSignatureMismatch = errors.New("message does not match server signature") )
var ErrDescriptorNotFound = errors.New("descriptor not found")
ErrDescriptorNotFound should be returned
Functions ¶
func LoadOrGenerateKeys ¶
LoadOrGenerateKeys checks whether the file at path exists. If it does, the private and public keys at that path are loaded and returned. If not, new keys are generated and saved to the given path.
func LoadPrivateKey ¶
func LoadPrivateKey(path string) (ed25519.PrivateKey, error)
LoadPrivateKey loads a private Ed25519 key from the given path.
func LoadPrivateKeys ¶
func LoadPrivateKeys(paths ...string) []ed25519.PrivateKey
LoadPrivateKeys loads the private keys at all the provided paths.
Any invalid keys are skipped.
Types ¶
type Client ¶
type Client struct { // SavePubkey saves the public key for a given server. SavePubkey func(serverName string, previousNames []string, pubkey ed25519.PublicKey) error // GetPubkey retrieves the public key for a given server. // If the key isn't found, GetPubkey should return [ErrPubkeyNotFound] GetPubkey func(serverName string) (ed25519.PublicKey, error) }
Client represents a ProfileFed client
func DefaultClient ¶
func DefaultClient() Client
DefaultClient returns a default client for ProfileFed.
It uses an in-memory synchronized map to store public keys. For production, it's highly recommended to implement a custom client that persists the keys to a database or similar, so that restarting your app doesn't provide opportunities for malicious servers.
func (Client) Lookup ¶
func (c Client) Lookup(resource string) (*Descriptor, error)
Lookup looks up the profile descriptor for the given resource.
func (Client) LookupAll ¶
func (c Client) LookupAll(resource string) (map[string]*Descriptor, error)
Lookup looks up all the available profile descriptors for the given resource.
func (Client) LookupAllWebFinger ¶
func (c Client) LookupAllWebFinger(wfdesc *webfinger.Descriptor) (map[string]*Descriptor, error)
LookupAllWebFinger is the same as Client.LookupAll, but it accepts an existing WebFinger descriptor rather than looking one up.
func (Client) LookupID ¶
func (c Client) LookupID(resource, id string) (*Descriptor, error)
LookupID looks up the profile descriptor that matches the given ID for the given resource.
func (Client) LookupWebFinger ¶
func (c Client) LookupWebFinger(wfdesc *webfinger.Descriptor) (*Descriptor, error)
LookupWebFinger is the same as Client.Lookup, but it accepts an existing WebFinger descriptor rather than looking one up.
func (Client) LookupWebFingerID ¶
func (c Client) LookupWebFingerID(wfdesc *webfinger.Descriptor, id string) (*Descriptor, error)
LookupWebFingerID is the same as Client.LookupID, but it accepts an existing WebFinger descriptor rather than looking one up.
type Descriptor ¶
type Descriptor struct { // ID is an arbitrary ID string for the profile. ID string `json:"id"` // Namespaces is a list of namespaces used in the profile. Namespaces []string `json:"namespaces"` // DisplayName is the user's preferred display name. DisplayName string `json:"display_name"` // Username is the user's username. Username string `json:"username"` // Bio is the user's bio text. Bio string `json:"bio"` // Role is the user's role on the server. If not set, // [RoleUser] is assumed. Role Role `json:"role"` // Extra is additional user data defined by namespaces Extra []Extra `json:"extra"` }
Descriptor represents a ProfileFed descriptor
type Extra ¶
type Extra struct { // Namespace is the namespace URL used in this object Namespace string `json:"namespace"` // Type is an arbitrary string that represents the type of // data in the Data field. Type string `json:"type"` // Data is the arbitrary additional user data Data json.RawMessage `json:"data"` }
Extra represents additional user data defined by namespaces
type Handler ¶
type Handler struct { // PrivateKey contains the server's Ed25519 private key for signing responses PrivateKey ed25519.PrivateKey // AllDescriptorsFunc should return all the profile descriptors known to the server. // If no matching descriptors can be found, AllDescriptorsFunc should reutnr // [ErrDescriptorNotFound]. AllDescriptorsFunc func(req *http.Request) (map[string]*Descriptor, error) // DescriptorFunc should return a single descriptor. Make sure to check the `id` // query parameter if your user has several descriptors available. If a matching // descriptor cannot be found, DescriptorFunc should return [ErrDescriptorNotFound]. DescriptorFunc func(req *http.Request) (*Descriptor, error) // ErrorHandler is called whenever an error is encountered. ErrorHandler func(err error, res http.ResponseWriter) }
func (Handler) ServeHTTP ¶
func (h Handler) ServeHTTP(res http.ResponseWriter, req *http.Request)
ServeHTTP implements the http.Handler interface
type ServerInfoHandler ¶
type ServerInfoHandler struct { // ServerName is the current name of the server. This // should be the same as the domain used to access it. ServerName string // PreviousNames should contain any previous names this server used. PreviousNames []string // PublicKey should contain the server's public Ed25519 key. PublicKey ed25519.PublicKey // PrivateKey should contain the server's private Ed25519 key. PrivateKey ed25519.PrivateKey // PreviousKeys should contain any previously-used private keys. // If this is not provided when the key changes, servers will not // trust the new key and all responses will be rejected. PreviousKeys []ed25519.PrivateKey // ErrorHandler is called whenever an error is encountered. ErrorHandler func(err error, res http.ResponseWriter) }
ServerInfoHandler handles the server info endpoint defined by ProfileFed.
func (ServerInfoHandler) ServeHTTP ¶
func (sih ServerInfoHandler) ServeHTTP(res http.ResponseWriter, req *http.Request)
ServeHTTP implements the http.Handler interface