server

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2026 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewServer

func NewServer(opts ...Option) (ucantoServer.ServerView[ucantoServer.Service], error)

NewServer creates a new UCAN log server with optional validation.

Parameters:

  • opts: Configuration options (WithSigner, WithLogService, WithStoreManager, WithValidator)

Returns a UCanto server ready to handle HTTP requests.

func ProvideWithoutAuth

ProvideWithoutAuth is like ucantoServer.Provide but skips UCAN authorization. Authorization is expected to be handled in the handler via delegation in caveats. This allows anyone to invoke the capability - access control is done by validating the Storacha delegation passed in the caveats.

Types

type Config

type Config struct {
	Signer       interface{} // go-ucanto signer.Signer
	LogService   interface{} // log.LogService
	StoreManager interface{} // sqlite.StoreManager
	Validator    RequestValidator
}

Config holds server configuration.

type HTTPHandler

type HTTPHandler struct {
	// contains filtered or unexported fields
}

HTTPHandler handles HTTP endpoints for log queries.

func NewHTTPHandler

func NewHTTPHandler(storeManager *sqlite.StoreManager) *HTTPHandler

NewHTTPHandler creates a new HTTP handler.

func (*HTTPHandler) HandleGetHead

func (h *HTTPHandler) HandleGetHead(w http.ResponseWriter, r *http.Request)

HandleGetHead handles GET /logs/{logID}/head. Returns the current head CID, tree size, and optional checkpoint CID.

func (*HTTPHandler) HandleListLogs

func (h *HTTPHandler) HandleListLogs(w http.ResponseWriter, r *http.Request)

HandleListLogs handles GET /logs. Returns a JSON array of all known logs ordered by updatedAt descending.

type HeadResponse

type HeadResponse struct {
	IndexCID string `json:"index_cid"`
	TreeSize uint64 `json:"tree_size"`
}

HeadResponse is the response for GET /logs/{logID}/head.

type LogService

type LogService interface {
}

LogService defines the interface for log operations. This allows the pkg/server to depend on an interface rather than concrete type.

type LogSummary

type LogSummary struct {
	LogID      string    `json:"logID"`
	UpdatedAt  time.Time `json:"updatedAt"`
	TreeSize   uint64    `json:"treeSize"`
	HeadCID    string    `json:"headCID"`
	RevHeadCID string    `json:"revHeadCID,omitempty"`
}

LogSummary is an entry in the response for GET /logs.

type Option

type Option func(*Config)

Option configures the server.

func WithLogService

func WithLogService(ls interface{}) Option

WithLogService sets the log service.

func WithSigner

func WithSigner(s interface{}) Option

WithSigner sets the UCAN signer.

func WithStoreManager

func WithStoreManager(sm interface{}) Option

WithStoreManager sets the SQLite store manager.

func WithValidator

func WithValidator(v RequestValidator) Option

WithValidator sets a request validator for account/rate-limit checks. If nil (default), no validation is performed.

type RequestValidator

type RequestValidator interface {
	// ValidateRequest is called before each capability invocation.
	// Return nil to allow the request, or an error to reject it.
	// The error message will be returned to the client.
	ValidateRequest(ctx context.Context, inv invocation.Invocation) error
}

RequestValidator validates incoming UCAN invocations before processing. Implementations can check account status, rate limits, permissions, etc.

type TlogIPFSHandler

type TlogIPFSHandler struct {
	// contains filtered or unexported fields
}

TlogIPFSHandler provides public HTTP GET endpoints for the tlog-tiles API by proxying requests to IPFS gateway using the latest index CAR root CID.

func NewTlogIPFSHandler

func NewTlogIPFSHandler(cidStore tlog.CIDStore, gatewayURL string, httpClient *http.Client) *TlogIPFSHandler

NewTlogIPFSHandler creates a new IPFS-backed handler for tlog-tiles API endpoints.

func (*TlogIPFSHandler) HandleCheckpoint

func (h *TlogIPFSHandler) HandleCheckpoint(w http.ResponseWriter, r *http.Request)

HandleCheckpoint serves GET /logs/<logID>/checkpoint by proxying to IPFS gateway.

func (*TlogIPFSHandler) HandleEntries

func (h *TlogIPFSHandler) HandleEntries(w http.ResponseWriter, r *http.Request)

HandleEntries serves GET /logs/<logID>/tile/entries/<entryPath> by proxying to IPFS gateway.

func (*TlogIPFSHandler) HandleTile

func (h *TlogIPFSHandler) HandleTile(w http.ResponseWriter, r *http.Request)

HandleTile serves GET /logs/<logID>/tile/<L>/<tilePath> by proxying to IPFS gateway.

type TlogTilesHandler

type TlogTilesHandler struct {
	// contains filtered or unexported fields
}

TlogTilesHandler provides public HTTP GET endpoints for the tlog-tiles API as specified in https://github.com/C2SP/C2SP/blob/main/tlog-tiles.md

func NewTlogTilesHandler

func NewTlogTilesHandler(logService *log.LogService) *TlogTilesHandler

NewTlogTilesHandler creates a new handler for tlog-tiles API endpoints

func (*TlogTilesHandler) HandleCheckpoint

func (h *TlogTilesHandler) HandleCheckpoint(w http.ResponseWriter, r *http.Request)

HandleCheckpoint serves GET /logs/<logID>/checkpoint

func (*TlogTilesHandler) HandleEntries

func (h *TlogTilesHandler) HandleEntries(w http.ResponseWriter, r *http.Request)

HandleEntries serves GET /logs/<logID>/tile/entries/<N>[.p/<W>]

func (*TlogTilesHandler) HandleTile

func (h *TlogTilesHandler) HandleTile(w http.ResponseWriter, r *http.Request)

HandleTile serves GET /logs/<logID>/tile/<L>/<N>[.p/<W>]

type ValidationError

type ValidationError struct {
	Code    string // Machine-readable error code (e.g., "ACCOUNT_SUSPENDED")
	Message string // Human-readable message
}

ValidationError represents a validation failure with structured info.

func NewValidationError

func NewValidationError(code, message string) *ValidationError

NewValidationError creates a new validation error.

func (*ValidationError) Error

func (e *ValidationError) Error() string

Jump to

Keyboard shortcuts

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