x402pay

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

README

caddy-x402pay

A caddy module for x402 payment

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChainNetworkConfig

type ChainNetworkConfig struct {
	Name          string `json:"name,omitempty"`
	RPC           string `json:"rpc,omitempty"`
	ID            uint64 `json:"id,omitempty"`
	TokenAddress  string `json:"token_address,omitempty"`
	TokenName     string `json:"token_name,omitempty"`
	TokenVersion  string `json:"token_version,omitempty"`
	TokenDecimals int64  `json:"token_decimals,omitempty"`
	TokenType     string `json:"token_type,omitempty"`
}

ChainNetworkConfig represents a blockchain network configuration.

type X402BuyerMiddleware

type X402BuyerMiddleware struct {
	// Payment configuration
	PrivateKeyHex string `json:"private_key,omitempty"`
	MaxAmountPay  string `json:"max_amount_pay,omitempty"`
	MaxRetries    int    `json:"max_retries,omitempty"`

	ChainNetworks []ChainNetworkConfig
	// contains filtered or unexported fields
}

X402BuyerMiddleware is a Caddy HTTP middleware that intercepts 402 Payment Required responses from upstream handlers and automatically creates and submits payment.

func (X402BuyerMiddleware) CaddyModule

func (X402BuyerMiddleware) CaddyModule() caddy.ModuleInfo

CaddyModule returns the Caddy module information.

func (*X402BuyerMiddleware) Provision

func (m *X402BuyerMiddleware) Provision(ctx caddy.Context) error

Provision sets up the middleware.

func (*X402BuyerMiddleware) ServeHTTP

ServeHTTP implements the caddyhttp.MiddlewareHandler interface.

func (*X402BuyerMiddleware) UnmarshalCaddyfile

func (m *X402BuyerMiddleware) UnmarshalCaddyfile(d *caddyfile.Dispenser) error

UnmarshalCaddyfile implements caddyfile.Unmarshaler for X402BuyerMiddleware. Syntax:

x402buyer {
    private_key {$X402_BUYER_PRIVATE_KEY}
    max_amount_pay 2000000
    max_retries 1
}

func (*X402BuyerMiddleware) Validate

func (m *X402BuyerMiddleware) Validate() error

Validate validates the middleware configuration.

type X402FacilitatorApp

type X402FacilitatorApp struct {
	// Facilitator configuration
	PrivateKey       string               `json:"private_key,omitempty"`
	SupportedSchemes []string             `json:"supported_schemes,omitempty"`
	GasLimit         uint64               `json:"gas_limit,omitempty"`
	GasPrice         uint64               `json:"gas_price,omitempty"`
	ChainNetworks    []ChainNetworkConfig `json:"chain_networks,omitempty"`
	// contains filtered or unexported fields
}

X402FacilitatorApp is an app-level module that provides facilitator services. It runs an HTTP server with verify and settle endpoints.

func (X402FacilitatorApp) CaddyModule

func (X402FacilitatorApp) CaddyModule() caddy.ModuleInfo

CaddyModule returns the Caddy module information.

func (*X402FacilitatorApp) GetFacilitator

GetFacilitator returns the facilitator instance. This allows middleware to access the facilitator for payment verification.

func (X402FacilitatorApp) Name

func (X402FacilitatorApp) Name() string

Name returns the name of the app.

func (*X402FacilitatorApp) Provision

func (m *X402FacilitatorApp) Provision(ctx caddy.Context) error

Provision sets up the module.

func (*X402FacilitatorApp) Start

func (m *X402FacilitatorApp) Start() error

Start starts the application.

func (*X402FacilitatorApp) Stop

func (m *X402FacilitatorApp) Stop() error

Stop stops the application.

func (*X402FacilitatorApp) UnmarshalCaddyfile

func (m *X402FacilitatorApp) UnmarshalCaddyfile(d *caddyfile.Dispenser) error

UnmarshalCaddyfile implements caddyfile.Unmarshaler for X402FacilitatorApp. Syntax:

x402.facilitator {
    private_key 0x...
    supported_schemes exact
    gas_limit 21000
    gas_price 10
}

func (*X402FacilitatorApp) Validate

func (m *X402FacilitatorApp) Validate() error

Validate validates the module configuration.

type X402SellerMiddleware

type X402SellerMiddleware struct {
	// Payment requirements configuration
	Scheme            string `json:"scheme,omitempty"`
	Network           string `json:"network,omitempty"`
	Resource          string `json:"resource,omitempty"`
	Description       string `json:"description,omitempty"`
	MaxAmountRequired string `json:"max_amount_required,omitempty"`
	PayTo             string `json:"pay_to,omitempty"`
	// contains filtered or unexported fields
}

X402SellerMiddleware is a Caddy HTTP middleware that intercepts requests and requires X402 payment verification before allowing access to resources.

func (X402SellerMiddleware) CaddyModule

func (X402SellerMiddleware) CaddyModule() caddy.ModuleInfo

CaddyModule returns the Caddy module information.

func (*X402SellerMiddleware) Provision

func (m *X402SellerMiddleware) Provision(ctx caddy.Context) error

Provision sets up the middleware.

func (*X402SellerMiddleware) ServeHTTP

ServeHTTP implements the caddyhttp.MiddlewareHandler interface.

func (*X402SellerMiddleware) UnmarshalCaddyfile

func (m *X402SellerMiddleware) UnmarshalCaddyfile(d *caddyfile.Dispenser) error

UnmarshalCaddyfile implements caddyfile.Unmarshaler for X402SellerMiddleware. Syntax:

x402seller [<pattern>] {
    scheme exact
    network localhost
    resource premium-data-api
    description "Access to premium market data"
    max_amount_required 1000000
    pay_to 0x93866dBB587db8b9f2C36570Ae083E3F9814e508
}

func (*X402SellerMiddleware) Validate

func (m *X402SellerMiddleware) Validate() error

Validate validates the middleware configuration.

Directories

Path Synopsis
cmd
caddy command

Jump to

Keyboard shortcuts

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