Documentation ¶
Index ¶
- Variables
- func ParseServerName(serverName string) (host string, port uint16, ok bool)
- func RequestSRV(ctx context.Context, cli *net.Resolver, hostname string) ([]*net.SRV, error)
- type Client
- func (c *Client) Backfill(ctx context.Context, req *ReqBackfill) (resp *RespBackfill, err error)
- func (c *Client) GetEvent(ctx context.Context, serverName string, eventID id.EventID) (resp *RespBackfill, err error)
- func (c *Client) GetEventAuthChain(ctx context.Context, serverName string, roomID id.RoomID, eventID id.EventID) (resp *RespGetEventAuthChain, err error)
- func (c *Client) GetMissingEvents(ctx context.Context, req *ReqGetMissingEvents) (resp *RespGetMissingEvents, err error)
- func (c *Client) GetOpenIDUserInfo(ctx context.Context, serverName, accessToken string) (resp *RespOpenIDUserInfo, err error)
- func (c *Client) GetState(ctx context.Context, serverName string, roomID id.RoomID, eventID id.EventID) (resp *RespGetState, err error)
- func (c *Client) GetStateIDs(ctx context.Context, serverName string, roomID id.RoomID, eventID id.EventID) (resp *RespGetStateIDs, err error)
- func (c *Client) MakeFullRequest(ctx context.Context, params RequestParams) ([]byte, *http.Response, error)
- func (c *Client) MakeRequest(ctx context.Context, serverName string, authenticate bool, method string, ...) error
- func (c *Client) Query(ctx context.Context, serverName, queryType string, queryParams url.Values, ...) (err error)
- func (c *Client) QueryDirectory(ctx context.Context, serverName string, roomAlias id.RoomAlias) (resp *mautrix.RespAliasResolve, err error)
- func (c *Client) QueryKeys(ctx context.Context, serverName string, req *ReqQueryKeys) (resp *ServerKeyResponse, err error)
- func (c *Client) QueryProfile(ctx context.Context, serverName string, userID id.UserID) (resp *mautrix.RespUserProfile, err error)
- func (c *Client) SendTransaction(ctx context.Context, req *ReqSendTransaction) (resp *RespSendTransaction, err error)
- func (c *Client) ServerKeys(ctx context.Context, serverName string) (resp *ServerKeyResponse, err error)
- func (c *Client) TimestampToEvent(ctx context.Context, serverName string, roomID id.RoomID, timestamp time.Time, ...) (resp *mautrix.RespTimestampToEvent, err error)
- func (c *Client) Version(ctx context.Context, serverName string) (resp *RespServerVersion, err error)
- type EDU
- type GetQueryKeysResponse
- type KeyServer
- func (ks *KeyServer) GetQueryKeys(w http.ResponseWriter, r *http.Request)
- func (ks *KeyServer) GetServerKey(w http.ResponseWriter, r *http.Request)
- func (ks *KeyServer) GetServerVersion(w http.ResponseWriter, r *http.Request)
- func (ks *KeyServer) GetWellKnown(w http.ResponseWriter, r *http.Request)
- func (ks *KeyServer) PostQueryKeys(w http.ResponseWriter, r *http.Request)
- func (ks *KeyServer) Register(r *mux.Router)
- type KeyURLPath
- type OldVerifyKey
- type PDU
- type PDUProcessingResult
- type PostQueryKeysResponse
- type QueryKeysCriteria
- type ReqBackfill
- type ReqGetMissingEvents
- type ReqQueryKeys
- type ReqSendTransaction
- type RequestParams
- type ResolveServerNameOpts
- type ResolvedServerName
- type RespBackfill
- type RespGetEventAuthChain
- type RespGetMissingEvents
- type RespGetState
- type RespGetStateIDs
- type RespOpenIDUserInfo
- type RespSendTransaction
- type RespServerVersion
- type RespWellKnown
- type ServerKeyProvider
- type ServerKeyResponse
- type ServerResolvingTransport
- type ServerVerifyKey
- type ServerVersion
- type SigningKey
- type StaticServerKey
- type URLPath
Constants ¶
This section is empty.
Variables ¶
var (
ErrInvalidServerName = errors.New("invalid server name")
)
Functions ¶
func ParseServerName ¶ added in v0.20.0
ParseServerName parses the port and hostname from a Matrix server name and validates that it matches the grammar specified in https://spec.matrix.org/v1.11/appendices/#server-name
Types ¶
type Client ¶ added in v0.20.0
type Client struct { HTTP *http.Client ServerName string UserAgent string Key *SigningKey }
func NewClient ¶ added in v0.20.0
func NewClient(serverName string, key *SigningKey) *Client
func (*Client) Backfill ¶ added in v0.20.0
func (c *Client) Backfill(ctx context.Context, req *ReqBackfill) (resp *RespBackfill, err error)
func (*Client) GetEventAuthChain ¶ added in v0.20.0
func (*Client) GetMissingEvents ¶ added in v0.20.0
func (c *Client) GetMissingEvents(ctx context.Context, req *ReqGetMissingEvents) (resp *RespGetMissingEvents, err error)
func (*Client) GetOpenIDUserInfo ¶ added in v0.20.0
func (*Client) GetStateIDs ¶ added in v0.20.0
func (*Client) MakeFullRequest ¶ added in v0.20.0
func (*Client) MakeRequest ¶ added in v0.20.0
func (*Client) QueryDirectory ¶ added in v0.20.0
func (*Client) QueryKeys ¶ added in v0.20.0
func (c *Client) QueryKeys(ctx context.Context, serverName string, req *ReqQueryKeys) (resp *ServerKeyResponse, err error)
func (*Client) QueryProfile ¶ added in v0.20.0
func (*Client) SendTransaction ¶ added in v0.20.0
func (c *Client) SendTransaction(ctx context.Context, req *ReqSendTransaction) (resp *RespSendTransaction, err error)
func (*Client) ServerKeys ¶ added in v0.20.0
func (*Client) TimestampToEvent ¶ added in v0.20.0
type EDU ¶ added in v0.20.0
type EDU = json.RawMessage
type GetQueryKeysResponse ¶
type GetQueryKeysResponse struct {
ServerKeys []*ServerKeyResponse `json:"server_keys"`
}
GetQueryKeysResponse is the response body for the `GET /_matrix/key/v2/query/{serverName}` endpoint
type KeyServer ¶
type KeyServer struct { KeyProvider ServerKeyProvider Version ServerVersion WellKnownTarget string }
KeyServer implements a basic Matrix key server that can serve its own keys, plus the federation version endpoint.
It does not implement querying keys of other servers, nor any other federation endpoints.
func (*KeyServer) GetQueryKeys ¶
func (ks *KeyServer) GetQueryKeys(w http.ResponseWriter, r *http.Request)
GetQueryKeys implements the `GET /_matrix/key/v2/query/{serverName}` endpoint
https://spec.matrix.org/v1.9/server-server-api/#get_matrixkeyv2queryservername
func (*KeyServer) GetServerKey ¶
func (ks *KeyServer) GetServerKey(w http.ResponseWriter, r *http.Request)
GetServerKey implements the `GET /_matrix/key/v2/server` endpoint.
https://spec.matrix.org/v1.9/server-server-api/#get_matrixkeyv2server
func (*KeyServer) GetServerVersion ¶
func (ks *KeyServer) GetServerVersion(w http.ResponseWriter, r *http.Request)
GetServerVersion implements the `GET /_matrix/federation/v1/version` endpoint
https://spec.matrix.org/v1.9/server-server-api/#get_matrixfederationv1version
func (*KeyServer) GetWellKnown ¶
func (ks *KeyServer) GetWellKnown(w http.ResponseWriter, r *http.Request)
GetWellKnown implements the `GET /.well-known/matrix/server` endpoint
https://spec.matrix.org/v1.9/server-server-api/#get_well-knownmatrixserver
func (*KeyServer) PostQueryKeys ¶
func (ks *KeyServer) PostQueryKeys(w http.ResponseWriter, r *http.Request)
PostQueryKeys implements the `POST /_matrix/key/v2/query` endpoint
https://spec.matrix.org/v1.9/server-server-api/#post_matrixkeyv2query
type KeyURLPath ¶ added in v0.20.0
type KeyURLPath []any
func (KeyURLPath) FullPath ¶ added in v0.20.0
func (fkup KeyURLPath) FullPath() []any
type OldVerifyKey ¶
type OldVerifyKey struct { Key id.SigningKey `json:"key"` ExpiredTS jsontime.UnixMilli `json:"expired_ts"` }
type PDU ¶ added in v0.20.0
type PDU = json.RawMessage
type PDUProcessingResult ¶ added in v0.20.0
type PDUProcessingResult struct {
Error string `json:"error,omitempty"`
}
type PostQueryKeysResponse ¶
type PostQueryKeysResponse struct {
ServerKeys map[string]*ServerKeyResponse `json:"server_keys"`
}
PostQueryKeysResponse is the response body for the `POST /_matrix/key/v2/query` endpoint
type QueryKeysCriteria ¶
type ReqBackfill ¶ added in v0.20.0
type ReqGetMissingEvents ¶ added in v0.20.0
type ReqQueryKeys ¶
type ReqQueryKeys struct {
ServerKeys map[string]map[id.KeyID]QueryKeysCriteria `json:"server_keys"`
}
ReqQueryKeys is the request body for the `POST /_matrix/key/v2/query` endpoint
type ReqSendTransaction ¶ added in v0.20.0
type RequestParams ¶ added in v0.20.0
type ResolveServerNameOpts ¶ added in v0.20.0
type ResolvedServerName ¶ added in v0.20.0
type ResolvedServerName struct { ServerName string `json:"server_name"` HostHeader string `json:"host_header"` IPPort []string `json:"ip_port"` Expires time.Time `json:"expires"` }
func ResolveServerName ¶ added in v0.20.0
func ResolveServerName(ctx context.Context, serverName string, opts ...*ResolveServerNameOpts) (*ResolvedServerName, error)
ResolveServerName implements the full server discovery algorithm as specified in https://spec.matrix.org/v1.11/server-server-api/#resolving-server-names
type RespBackfill ¶ added in v0.20.0
type RespGetEventAuthChain ¶ added in v0.20.0
type RespGetEventAuthChain struct {
AuthChain []PDU `json:"auth_chain"`
}
type RespGetMissingEvents ¶ added in v0.20.0
type RespGetMissingEvents struct {
Events []PDU `json:"events"`
}
type RespGetState ¶ added in v0.20.0
type RespGetStateIDs ¶ added in v0.20.0
type RespOpenIDUserInfo ¶ added in v0.20.0
type RespSendTransaction ¶ added in v0.20.0
type RespSendTransaction struct {
PDUs map[id.EventID]PDUProcessingResult `json:"pdus"`
}
type RespServerVersion ¶
type RespServerVersion struct {
Server ServerVersion `json:"server"`
}
RespServerVersion is the response body for the `GET /_matrix/federation/v1/version` endpoint
type RespWellKnown ¶
type RespWellKnown struct {
Server string `json:"m.server"`
}
RespWellKnown is the response body for the `GET /.well-known/matrix/server` endpoint.
type ServerKeyProvider ¶
type ServerKeyProvider interface {
Get(r *http.Request) (serverName string, key *SigningKey)
}
ServerKeyProvider is an interface that returns private server keys for server key requests.
type ServerKeyResponse ¶
type ServerKeyResponse struct { ServerName string `json:"server_name"` VerifyKeys map[id.KeyID]ServerVerifyKey `json:"verify_keys"` OldVerifyKeys map[id.KeyID]OldVerifyKey `json:"old_verify_keys,omitempty"` Signatures map[string]map[id.KeyID]string `json:"signatures,omitempty"` ValidUntilTS jsontime.UnixMilli `json:"valid_until_ts"` }
ServerKeyResponse is the response body for the `GET /_matrix/key/v2/server` endpoint. It's also used inside the query endpoint response structs.
type ServerResolvingTransport ¶ added in v0.20.0
type ServerResolvingTransport struct { ResolveOpts *ResolveServerNameOpts Transport *http.Transport Dialer *net.Dialer // contains filtered or unexported fields }
ServerResolvingTransport is an http.RoundTripper that resolves Matrix server names before sending requests. It only allows requests using the "matrix-federation" scheme.
func NewServerResolvingTransport ¶ added in v0.20.0
func NewServerResolvingTransport() *ServerResolvingTransport
func (*ServerResolvingTransport) DialContext ¶ added in v0.20.0
type ServerVerifyKey ¶
type ServerVerifyKey struct {
Key id.SigningKey `json:"key"`
}
type ServerVersion ¶
type SigningKey ¶
type SigningKey struct { ID id.KeyID Pub id.SigningKey Priv ed25519.PrivateKey }
SigningKey is a Matrix federation signing key pair.
func GenerateSigningKey ¶
func GenerateSigningKey() *SigningKey
GenerateSigningKey generates a new random signing key.
func ParseSynapseKey ¶
func ParseSynapseKey(key string) (*SigningKey, error)
ParseSynapseKey parses a Synapse-compatible private key string into a SigningKey.
func (*SigningKey) GenerateKeyResponse ¶
func (sk *SigningKey) GenerateKeyResponse(serverName string, oldVerifyKeys map[id.KeyID]OldVerifyKey) *ServerKeyResponse
GenerateKeyResponse generates a key response signed by this key with the given server name and optionally some old verify keys.
func (*SigningKey) SignRawJSON ¶
func (sk *SigningKey) SignRawJSON(data json.RawMessage) []byte
func (*SigningKey) SynapseString ¶
func (sk *SigningKey) SynapseString() string
SynapseString returns a string representation of the private key compatible with Synapse's .signing.key file format.
The output of this function can be parsed back into a SigningKey using the ParseSynapseKey function.
type StaticServerKey ¶
type StaticServerKey struct { ServerName string Key *SigningKey }
StaticServerKey is an implementation of ServerKeyProvider that always returns the same server name and key.
func (*StaticServerKey) Get ¶
func (ssk *StaticServerKey) Get(r *http.Request) (serverName string, key *SigningKey)