chargeserver

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2026 License: MIT, Apache-2.0, MIT Imports: 17 Imported by: 0

Documentation

Overview

Package chargeserver contains the Tempo charge server method and verifier. It is usually imported as charge alongside the generic HTTP 402 flow in package server.

Package chargeserver verifies Tempo charge Credentials and builds Tempo charge Challenges for MPP HTTP servers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Intent verifies Tempo charge credentials for this method.
	Intent *Intent
	// Currency is the default token contract address for issued challenges.
	Currency string
	// Recipient is the default payee address for issued challenges.
	Recipient string
	// Decimals controls how human-readable amounts are normalized.
	Decimals int
	// ChainID binds issued challenges to a specific Tempo chain when set.
	ChainID int64
	// FeePayer enables sponsored transaction flows by default.
	FeePayer bool
	// FeePayerURL points at a remote co-signer when the server does not sign locally.
	FeePayerURL string
	// Memo overrides the default attribution memo generation.
	Memo string
	// SupportedModes limits the credential submission modes advertised to clients.
	SupportedModes []tempo.ChargeMode
	// RPC overrides the Tempo JSON-RPC client used for verification.
	RPC tempo.RPCClient
	// RPCURL is used to build an RPC client when RPC is nil.
	RPCURL string
	// FeePayerSigner co-signs sponsored transactions locally when provided.
	FeePayerSigner *temposigner.Signer
	// FeePayerPrivateKey constructs FeePayerSigner when FeePayerSigner is nil.
	FeePayerPrivateKey string
	// FeePayerPrivateKeyEnv loads the fee-payer key from an environment variable when FeePayerPrivateKey is empty.
	FeePayerPrivateKeyEnv string
	// FeePayerPolicies allowlists the fee tokens this verifier will sponsor.
	FeePayerPolicies map[string]FeePayerPolicy
	// Store persists replay-protection keys for hash and proof credentials.
	Store tempo.Store
}

Config combines the method defaults and intent verification settings used by the high-level Tempo server constructor.

type FeePayerPolicy

type FeePayerPolicy struct {
	MaxFeePerGas         *big.Int
	MaxPriorityFeePerGas *big.Int
	MaxTotalFee          *big.Int
}

FeePayerPolicy configures sponsored transaction limits for one TIP-20 fee token.

type Intent

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

Intent verifies Tempo charge Credentials and returns Receipts.

func NewIntent

func NewIntent(config IntentConfig) (*Intent, error)

NewIntent constructs a Tempo charge verifier.

func (*Intent) Name

func (i *Intent) Name() string

Name returns the intent token handled by this verifier.

func (*Intent) Verify

func (i *Intent) Verify(
	ctx context.Context,
	credential *mpp.Credential,
	requestMap map[string]any,
) (*mpp.Receipt, error)

Verify validates a Tempo charge Credential against the supplied request.

type IntentConfig

type IntentConfig struct {
	// RPC overrides the Tempo JSON-RPC client used for verification.
	RPC tempo.RPCClient
	// RPCURL is used to build an RPC client when RPC is nil.
	RPCURL string
	// FeePayerSigner co-signs sponsored transactions locally when provided.
	FeePayerSigner *temposigner.Signer
	// FeePayerPrivateKey constructs FeePayerSigner when FeePayerSigner is nil.
	FeePayerPrivateKey string
	// FeePayerPrivateKeyEnv loads the fee-payer key from an environment variable when FeePayerPrivateKey is empty.
	FeePayerPrivateKeyEnv string
	// FeePayerPolicies allowlists the fee tokens this verifier will sponsor.
	FeePayerPolicies map[string]FeePayerPolicy
	// Store persists replay-protection keys for hash and proof credentials.
	Store tempo.Store
}

IntentConfig configures Tempo charge verification.

type Method

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

Method adapts Tempo charge configuration to the generic server interfaces.

func MethodFromConfig

func MethodFromConfig(config Config) (*Method, error)

MethodFromConfig constructs a Tempo charge method from one config struct.

func NewMethod

func NewMethod(config MethodConfig) *Method

NewMethod builds a Tempo server method with request defaults.

func (*Method) BuildChargeRequest

func (m *Method) BuildChargeRequest(params mppserver.ChargeParams) (map[string]any, error)

BuildChargeRequest normalizes server charge parameters into Tempo request data.

func (*Method) Intents

func (m *Method) Intents() map[string]mppserver.Intent

Intents exposes the Tempo intents handled by this method.

func (*Method) Name

func (m *Method) Name() string

Name returns the method token used in Challenges and Credentials.

type MethodConfig

type MethodConfig struct {
	// Intent verifies Tempo charge credentials for this method.
	Intent *Intent
	// Currency is the default token contract address for issued challenges.
	Currency string
	// Recipient is the default payee address for issued challenges.
	Recipient string
	// Decimals controls how human-readable amounts are normalized.
	Decimals int
	// ChainID binds issued challenges to a specific Tempo chain when set.
	ChainID int64
	// FeePayer enables sponsored transaction flows by default.
	FeePayer bool
	// FeePayerURL points at a remote co-signer when the server does not sign locally.
	FeePayerURL string
	// Memo overrides the default attribution memo generation.
	Memo string
	// SupportedModes limits the credential submission modes advertised to clients.
	SupportedModes []tempo.ChargeMode
}

MethodConfig configures a Tempo payment method for server-side charging.

Jump to

Keyboard shortcuts

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