httpserver

package
v0.19.0-rc.14 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 28, 2025 License: Apache-2.0 Imports: 13 Imported by: 7

README

httpserver

HTTPServer uses crypto/ed25519 by default for signing verification. You can inject your own implementation by setting the Verify in this package.

Example

For a simple command crypto/ed25519 takes around 0.54ms on my machine and github.com/oasisprotocol/curve25519-voi takes about 0.13ms.

package main

import (
	"github.com/oasisprotocol/curve25519-voi/primitives/ed25519"
	"github.com/disgoorg/disgo/httpserver"
)
func main() {
	httpserver.Verify = func(publicKey httpserver.PublicKey, message, sig []byte) bool {
		return ed25519.Verify(publicKey, message, sig)
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HandleInteraction added in v0.13.10

func HandleInteraction(verifier Verifier, publicKey PublicKey, logger *slog.Logger, handleFunc EventHandlerFunc) http.HandlerFunc

HandleInteraction handles an interaction from Discord's Outgoing Webhooks. It verifies and parses the interaction and then calls the passed EventHandlerFunc.

func VerifyRequest

func VerifyRequest(verifier Verifier, r *http.Request, key PublicKey) bool

VerifyRequest implements the verification side of the discord interactions api signing algorithm, as documented here: https://discord.com/developers/docs/interactions/slash-commands#security-and-authorization Credit: https://github.com/bsdlp/discord-interactions-go/blob/main/interactions/verify.go

Types

type ConfigOpt

type ConfigOpt func(config *config)

ConfigOpt is a type alias for a function that takes a config and is used to configure your Server.

func WithAddress

func WithAddress(address string) ConfigOpt

WithAddress sets the Address of the config.

func WithHTTPServer

func WithHTTPServer(httpServer *http.Server) ConfigOpt

WithHTTPServer sets the http.Server of the config.

func WithLogger

func WithLogger(logger *slog.Logger) ConfigOpt

WithLogger sets the Logger of the config.

func WithServeMux

func WithServeMux(serveMux *http.ServeMux) ConfigOpt

WithServeMux sets the http.ServeMux of the config.

func WithTLS

func WithTLS(certFile string, keyFile string) ConfigOpt

WithTLS sets the CertFile of the config.

func WithURL

func WithURL(url string) ConfigOpt

WithURL sets the URL of the config.

func WithVerifier added in v0.19.0

func WithVerifier(verifier Verifier) ConfigOpt

WithVerifier sets the Verifier of the config.

type DefaultVerifier added in v0.19.0

type DefaultVerifier struct{}

DefaultVerifier is the default implementation of the Verifier interface.

func (DefaultVerifier) SignatureSize added in v0.19.0

func (DefaultVerifier) SignatureSize() int

func (DefaultVerifier) Verify added in v0.19.0

func (DefaultVerifier) Verify(publicKey PublicKey, message []byte, sig []byte) bool

type EventHandlerFunc

type EventHandlerFunc func(responseFunc RespondFunc, event EventInteractionCreate)

EventHandlerFunc is used to handle events from Discord's Outgoing Webhooks

type EventInteractionCreate added in v0.13.10

type EventInteractionCreate struct {
	discord.Interaction
}

EventInteractionCreate is the event payload when an interaction is created via Discord's Outgoing Webhooks

func (EventInteractionCreate) MarshalJSON added in v0.15.1

func (e EventInteractionCreate) MarshalJSON() ([]byte, error)

func (*EventInteractionCreate) UnmarshalJSON added in v0.13.10

func (e *EventInteractionCreate) UnmarshalJSON(data []byte) error

type PublicKey

type PublicKey = []byte

PublicKey is the type of Ed25519 public keys.

type RespondFunc added in v0.8.9

type RespondFunc func(response discord.InteractionResponse) error

RespondFunc is used to respond to Discord's Outgoing Webhooks

type Server

type Server interface {
	// Start starts the Server
	Start()

	// Close closes the Server
	Close(ctx context.Context)
}

Server is used for receiving Discord's interactions via Outgoing Webhooks

func New

func New(publicKey string, eventHandlerFunc EventHandlerFunc, opts ...ConfigOpt) (Server, error)

New creates a new Server with the given publicKey eventHandlerFunc and ConfigOpt(s)

type Verifier added in v0.19.0

type Verifier interface {
	// Verify verifies the signature of the message using the public key.
	// It returns true if the signature is valid, false otherwise.
	Verify(publicKey PublicKey, message []byte, sig []byte) bool

	// SignatureSize is the size, in bytes, of signatures generated and verified by this package.
	SignatureSize() int
}

Verifier is used to verify Ed25519 signatures.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL