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 ¶
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 (*Method) CanHandleChallenge ¶ added in v0.4.0
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.