Help us shape the future of Go! Take the 2026 Go Developer Survey

chargeclient

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: MIT, Apache-2.0, MIT Imports: 16 Imported by: 0

Documentation

Overview

Package chargeclient contains the Tempo charge client method for creating Payment Credentials that satisfy Tempo HTTP 402 Challenges. It is usually imported as charge alongside the generic client package.

Package chargeclient creates Tempo charge Credentials for MPP HTTP clients.

Index

Constants

This section is empty.

Variables

View Source
var ErrSponsoredChallengeExpiresTooSoon = errors.New("tempo client: sponsored challenge expires too soon")

ErrSponsoredChallengeExpiresTooSoon reports a sponsored (fee-payer) charge challenge that expires less than tempo.FeePayerMinRemainingValidity from now. The client refuses it before signing or broadcasting anything, since a server would reject the sponsored transaction for too little validity.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Signer signs Tempo transactions and proof payloads.
	Signer *temposigner.Signer
	// PrivateKey constructs Signer when Signer is nil.
	PrivateKey string
	// RPC overrides the Tempo JSON-RPC client used for signing flows.
	RPC tempo.RPCClient
	// RPCURL is used to build an RPC client when RPC is nil.
	RPCURL string
	// ChainID constrains the challenge to a specific Tempo chain when set.
	ChainID int64
	// ClientID is folded into automatically generated attribution memos.
	ClientID string
	// CredentialType selects transaction, hash, or proof credentials.
	CredentialType tempo.CredentialType
	// PaymentPolicy must authorize every nonzero payment before signing or broadcasting.
	// Nil rejects paid challenges. Check the normalized amount (including splits),
	// currency, recipient, and verified RPC chain; enforce cumulative budgets atomically if needed.
	// The callback may run concurrently and must not mutate the request.
	PaymentPolicy func(context.Context, tempo.ChargeRequest) error
}

Config configures a Tempo charge client method.

type Method

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

Method implements Tempo charge credential creation for the generic MPP client.

func New

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

New constructs a Tempo charge client method.

func (*Method) CanHandleChallenge added in v0.4.0

func (m *Method) CanHandleChallenge(challenge *mpp.Challenge) bool

CanHandleChallenge skips a sponsored charge challenge that expires too soon to sign, so a transport offered other challenges can pay with one of those instead of failing on this one.

func (*Method) CreateCredential

func (m *Method) CreateCredential(ctx context.Context, challenge *mpp.Challenge) (*mpp.Credential, error)

CreateCredential turns a Tempo charge Challenge into a Tempo Credential.

Concurrent calls for the same challenge share one in-flight signing, so they cannot produce two independently settleable transactions. Once that signing finishes, successfully or not, a later call signs afresh. Calls share a signing only when every challenge field matches, and each caller gets its own copy of the credential.

func (*Method) Intent added in v0.4.0

func (m *Method) Intent() string

Intent returns the charge intent handled by this method.

func (*Method) Name

func (m *Method) Name() string

Name returns the method token used in Challenges and Credentials.

Jump to

Keyboard shortcuts

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