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 ¶
const DefaultQuoteExpiry = 5 * time.Minute
DefaultQuoteExpiry is the validity window for a price quote.
Variables ¶
This section is empty.
Functions ¶
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 (*Gate) BuildQuote ¶
func (g *Gate) BuildQuote(toolName, price string) *PriceQuote
BuildQuote creates a PriceQuote for the given tool and price.
func (*Gate) Check ¶
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 ¶
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 ¶
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" )