paygate

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package paygate implements a payment gate that checks tool pricing and verifies EIP-3009 payment authorizations between the firewall and tool executor in the P2P protocol.

Index

Constants

View Source
const DefaultQuoteExpiry = 5 * time.Minute

DefaultQuoteExpiry is the validity window for a price quote.

Variables

This section is empty.

Functions

func ParseUSDC

func ParseUSDC(amount string) (*big.Int, error)

ParseUSDC converts a decimal USDC string (e.g. "0.50") into the smallest unit (*big.Int with 6 decimals, e.g. 500000).

Types

type Config

type Config struct {
	PricingFn PricingFunc
	LocalAddr string
	ChainID   int64
	USDCAddr  common.Address
	RPCClient *ethclient.Client
	Logger    *zap.SugaredLogger
}

Config holds construction parameters for a Gate.

type Gate

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

Gate sits between the firewall and the tool executor, enforcing payment requirements for paid tools.

func New

func New(cfg Config) *Gate

New creates a payment gate from the given configuration.

func (*Gate) BuildQuote

func (g *Gate) BuildQuote(toolName, price string) *PriceQuote

BuildQuote creates a PriceQuote for the given tool and price.

func (*Gate) Check

func (g *Gate) Check(peerDID, toolName string, payload map[string]interface{}) (*Result, error)

Check evaluates whether a tool invocation should proceed. It looks up the tool price, and if payment is required, validates the EIP-3009 authorization embedded in the payload.

func (*Gate) SubmitOnChain

func (g *Gate) SubmitOnChain(ctx context.Context, auth *eip3009.Authorization) (string, error)

SubmitOnChain encodes the authorization as calldata and submits the transferWithAuthorization transaction to the USDC contract. For MVP this logs the intent and returns a placeholder hash, since actual submission requires a signed transaction from the seller's wallet.

type PriceQuote

type PriceQuote struct {
	ToolName     string `json:"toolName"`
	Price        string `json:"price"`
	Currency     string `json:"currency"`
	USDCContract string `json:"usdcContract"`
	ChainID      int64  `json:"chainId"`
	SellerAddr   string `json:"sellerAddr"`
	QuoteExpiry  int64  `json:"quoteExpiry"`
}

PriceQuote tells a buyer what to pay for a tool invocation.

type PricingFunc

type PricingFunc func(toolName string) (price string, isFree bool)

PricingFunc returns the price (decimal USDC string like "0.50") and whether the tool is free.

type Result

type Result struct {
	Status     ResultStatus           `json:"status"`
	Auth       *eip3009.Authorization `json:"auth,omitempty"`
	PriceQuote *PriceQuote            `json:"priceQuote,omitempty"`
	Reason     string                 `json:"reason,omitempty"`
}

Result describes the outcome of a payment gate check.

type ResultStatus

type ResultStatus string

ResultStatus describes the outcome of a payment gate check.

const (
	// StatusFree means the tool is free; no payment required.
	StatusFree ResultStatus = "free"

	// StatusVerified means a valid payment authorization was provided.
	StatusVerified ResultStatus = "verified"

	// StatusPaymentRequired means the tool is paid but no authorization was
	// provided; the PriceQuote tells the caller what to pay.
	StatusPaymentRequired ResultStatus = "payment_required"

	// StatusInvalid means the provided payment authorization is invalid.
	StatusInvalid ResultStatus = "invalid"
)

Jump to

Keyboard shortcuts

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