mechanisms/evm/batch-settlement
import "github.com/x402-foundation/x402/go/v2/mechanisms/evm/batch-settlement"
Package batched holds shared batch-settlement error constants used across
client / facilitator / server. All reasons share the
invalid_batch_settlement_evm_* prefix and describe mechanism-level
failures only - no policy/business semantics.
A small subset is duplicated here (and authoritatively defined in
go/mechanisms/evm/batch-settlement/facilitator/errors.go) so non-facilitator
callers can reference them without importing facilitator (which would
cycle: facilitator already imports batched).
Constants
Source: mechanisms/evm/batch-settlement/constants.go:11
const (
// SchemeBatched is the scheme identifier for batch settlement.
SchemeBatched = "batch-settlement"
// BatchSettlementAddress is the deployed x402BatchSettlement contract address (CREATE2, all chains).
BatchSettlementAddress = "0x4020074e9dF2ce1deE5A9C1b5c3f541D02a10003"
// ERC3009DepositCollectorAddress is the deployed ERC3009DepositCollector contract address.
ERC3009DepositCollectorAddress = "0x4020806089470a89826cB9fB1f4059150b550004"
// Permit2DepositCollectorAddress is the deployed Permit2DepositCollector contract address.
Permit2DepositCollectorAddress = "0x4020425FAf3B746C082C2f942b4E5159887B0005"
// MinWithdrawDelay is the minimum withdraw delay in seconds (15 minutes).
MinWithdrawDelay = 900
// MaxWithdrawDelay is the maximum withdraw delay in seconds (30 days).
MaxWithdrawDelay = 2_592_000
)Source: mechanisms/evm/batch-settlement/errors.go:21
const (
// ErrCumulativeBelowClaimed is the canonical value of
// `facilitator.ErrMaxClaimableTooLow`. Surfaced both by the facilitator
// (as a verify rejection) AND by the resource server's corrective 402
// recovery handshake - clients accept it as a signal to refresh
// channel state and retry. Defined here so `client/scheme.go` can match
// it without importing the facilitator package.
ErrCumulativeBelowClaimed = "invalid_batch_settlement_evm_cumulative_below_claimed"
// ErrCumulativeAmountMismatch signals a recoverable 402 from the resource
// server when the client's signed cumulative disagrees with the server's
// tracked state. Clients refresh from the corrective ChannelState in
// requirements.extra and retry.
ErrCumulativeAmountMismatch = "invalid_batch_settlement_evm_cumulative_amount_mismatch"
// ErrChannelBusy signals that another request is currently holding the
// per-channel concurrency lock. Clients should back off briefly and
// retry. Emitted by AfterVerifyHook / BeforeSettleHook when a pending
// request is in flight.
ErrChannelBusy = "invalid_batch_settlement_evm_channel_busy"
// ErrInvalidChannelId signals a non-canonical channel id (not `0x` + 64 hex).
// Surfaced by binding checks and storage key normalization so untrusted
// ids never reach path builders or map keys.
ErrInvalidChannelId = "invalid_batch_settlement_evm_channel_id_invalid"
// ErrChannelIdMismatch signals that a claimed channel id does not match
// the EIP-712 hash of the payload's channelConfig for the payment network.
// Duplicated from facilitator/errors.go so utils can reference it without
// importing facilitator (which would cycle).
ErrChannelIdMismatch = "invalid_batch_settlement_evm_channel_id_mismatch"
// ErrVerificationStateUnavailable signals that the resource server could
// not establish local verification state (storage failure, missing
// reservation context). Fail-closed - clients should retry.
ErrVerificationStateUnavailable = "invalid_batch_settlement_evm_verification_state_unavailable"
// ErrMissingChannel signals that the server has no record of the
// channel referenced by the payload. Emitted by BeforeSettleHook for
// voucher and refund payloads when no session exists for the computed
// channelId.
ErrMissingChannel = "invalid_batch_settlement_evm_missing_channel"
// ErrChargeExceedsSignedCumulative signals that committing this voucher
// would push the server-tracked chargedCumulativeAmount above the
// voucher's signed maxClaimableAmount cap. Emitted by BeforeSettleHook's
// voucher-commit path; clients must re-sign with a larger cap.
ErrChargeExceedsSignedCumulative = "invalid_batch_settlement_evm_charge_exceeds_signed_cumulative"
// ErrRefundNoBalance signals that a cooperative refund request hit a
// channel with no remaining refundable balance (post-claim). Non-
// recoverable - the client must abandon the refund. Emitted by
// BeforeSettleHook's refund-rewrite path.
ErrRefundNoBalance = "invalid_batch_settlement_evm_refund_no_balance"
// ErrRefundAmountInvalid signals the client requested a malformed refund
// amount (non-numeric or non-positive). Non-recoverable - the client
// must fix the request before retrying.
ErrRefundAmountInvalid = "invalid_batch_settlement_evm_refund_amount_invalid"
// ErrRefundAmountExceedsBalance signals the client requested a refund
// larger than the channel's available balance. Non-recoverable; client
// should retry with a smaller amount or omit `amount` for a full refund.
ErrRefundAmountExceedsBalance = "invalid_batch_settlement_evm_refund_amount_exceeds_balance"
)ChannelConfigTypeString is the EIP-712 typed-data primary type string used for the onchain channel-id pre-image.
Source: mechanisms/evm/batch-settlement/constants.go:31
const ChannelConfigTypeString = "ChannelConfig(address payer,address payerAuthorizer,address receiver,address receiverAuthorizer,address token,uint40 withdrawDelay,bytes32 salt)"DepositWitnessTypeString is the canonical witness type-string fragment that
must be appended (without the leading ,) when computing the Permit2
witness type hash.
Source: mechanisms/evm/batch-settlement/constants.go:131
const DepositWitnessTypeString = "DepositWitness witness)DepositWitness(bytes32 channelId)TokenPermissions(address token,uint256 amount)"Permit2Address is the universal Permit2 deployment used across EVM chains.
Source: mechanisms/evm/batch-settlement/constants.go:101
const Permit2Address = "0x000000000022D473030F116dDEE9F6B43aC78BA3"Permit2DomainName is the EIP-712 domain name used by Permit2 typed data.
Source: mechanisms/evm/batch-settlement/constants.go:104
const Permit2DomainName = "Permit2"Source: mechanisms/evm/batch-settlement/types.go:47
const (
// AssetTransferMethodEip3009 is the default - uses USDC's
// `transferWithAuthorization` (EIP-3009) via the ERC3009DepositCollector.
AssetTransferMethodEip3009 AssetTransferMethod = "eip3009"
// AssetTransferMethodPermit2 funds the deposit via a channel-bound
// `PermitWitnessTransferFrom` against the universal Permit2 contract,
// brokered by the Permit2DepositCollector.
AssetTransferMethodPermit2 AssetTransferMethod = "permit2"
)Variables
BatchPermit2WitnessTypes defines the EIP-712 types for the channel-bound Permit2 PermitWitnessTransferFrom signed by the payer when the deposit uses the permit2 transfer method. The witness binds the transfer to a specific batch-settlement channel id so the Permit2DepositCollector can route funds on the receiver's behalf.
Source: mechanisms/evm/batch-settlement/constants.go:111
var BatchPermit2WitnessTypes = map[string][]evm.TypedDataField{
"PermitWitnessTransferFrom": {
{Name: "permitted", Type: "TokenPermissions"},
{Name: "spender", Type: "address"},
{Name: "nonce", Type: "uint256"},
{Name: "deadline", Type: "uint256"},
{Name: "witness", Type: "DepositWitness"},
},
"TokenPermissions": {
{Name: "token", Type: "address"},
{Name: "amount", Type: "uint256"},
},
"DepositWitness": {
{Name: "channelId", Type: "bytes32"},
},
}BatchSettlementChannelsABI for reading channels(channelId) -> (balance, totalClaimed).
Source: mechanisms/evm/batch-settlement/constants.go:277
var BatchSettlementChannelsABI = []byte(`[
{
"type": "function",
"name": "channels",
"inputs": [{"name": "channelId", "type": "bytes32"}],
"outputs": [
{"name": "balance", "type": "uint128"},
{"name": "totalClaimed", "type": "uint128"}
],
"stateMutability": "view"
}
]`)BatchSettlementClaimABI for calling claim(voucherClaims[]).
Source: mechanisms/evm/batch-settlement/constants.go:165
var BatchSettlementClaimABI = []byte(`[
{
"type": "function",
"name": "claim",
"inputs": [
{
"name": "voucherClaims",
"type": "tuple[]",
"components": [
{
"name": "voucher",
"type": "tuple",
"components": [
{"name": "channel", "type": "tuple", "components": ` + channelConfigComponentsJSON + `},
{"name": "maxClaimableAmount", "type": "uint128"}
]
},
{"name": "signature", "type": "bytes"},
{"name": "totalClaimed", "type": "uint128"}
]
}
],
"outputs": [],
"stateMutability": "nonpayable"
}
]`)BatchSettlementClaimWithSignatureABI for calling claimWithSignature(voucherClaims[], authorizerSignature).
Source: mechanisms/evm/batch-settlement/constants.go:193
var BatchSettlementClaimWithSignatureABI = []byte(`[
{
"type": "function",
"name": "claimWithSignature",
"inputs": [
{
"name": "voucherClaims",
"type": "tuple[]",
"components": [
{
"name": "voucher",
"type": "tuple",
"components": [
{"name": "channel", "type": "tuple", "components": ` + channelConfigComponentsJSON + `},
{"name": "maxClaimableAmount", "type": "uint128"}
]
},
{"name": "signature", "type": "bytes"},
{"name": "totalClaimed", "type": "uint128"}
]
},
{"name": "authorizerSignature", "type": "bytes"}
],
"outputs": [],
"stateMutability": "nonpayable"
}
]`)BatchSettlementDepositABI for calling deposit(config, amount, collector, collectorData).
Source: mechanisms/evm/batch-settlement/constants.go:149
var BatchSettlementDepositABI = []byte(`[
{
"type": "function",
"name": "deposit",
"inputs": [
{"name": "config", "type": "tuple", "components": ` + channelConfigComponentsJSON + `},
{"name": "amount", "type": "uint128"},
{"name": "collector", "type": "address"},
{"name": "collectorData", "type": "bytes"}
],
"outputs": [],
"stateMutability": "nonpayable"
}
]`)BatchSettlementDomain is the EIP-712 domain for the batch settlement contract. ChainId and VerifyingContract are set per-network at signing time.
Source: mechanisms/evm/batch-settlement/constants.go:38
var BatchSettlementDomain = evm.TypedDataDomain{
Name: "x402 Batch Settlement",
Version: "1",
}BatchSettlementFinalizeWithdrawABI for calling finalizeWithdraw(config).
Source: mechanisms/evm/batch-settlement/constants.go:358
var BatchSettlementFinalizeWithdrawABI = []byte(`[
{
"type": "function",
"name": "finalizeWithdraw",
"inputs": [{"name": "config", "type": "tuple", "components": ` + channelConfigComponentsJSON + `}],
"outputs": [],
"stateMutability": "nonpayable"
}
]`)BatchSettlementGetChannelIdABI for calling getChannelId(config).
Source: mechanisms/evm/batch-settlement/constants.go:316
var BatchSettlementGetChannelIdABI = []byte(`[
{
"type": "function",
"name": "getChannelId",
"inputs": [{"name": "config", "type": "tuple", "components": ` + channelConfigComponentsJSON + `}],
"outputs": [{"name": "", "type": "bytes32"}],
"stateMutability": "pure"
}
]`)BatchSettlementInitiateWithdrawABI for calling initiateWithdraw(config, amount).
Source: mechanisms/evm/batch-settlement/constants.go:344
var BatchSettlementInitiateWithdrawABI = []byte(`[
{
"type": "function",
"name": "initiateWithdraw",
"inputs": [
{"name": "config", "type": "tuple", "components": ` + channelConfigComponentsJSON + `},
{"name": "amount", "type": "uint128"}
],
"outputs": [],
"stateMutability": "nonpayable"
}
]`)BatchSettlementMulticallABI for calling multicall(data[]).
Source: mechanisms/evm/batch-settlement/constants.go:266
var BatchSettlementMulticallABI = []byte(`[
{
"type": "function",
"name": "multicall",
"inputs": [{"name": "data", "type": "bytes[]"}],
"outputs": [{"name": "results", "type": "bytes[]"}],
"stateMutability": "nonpayable"
}
]`)BatchSettlementPendingWithdrawalsABI for reading pendingWithdrawals(channelId).
Source: mechanisms/evm/batch-settlement/constants.go:291
var BatchSettlementPendingWithdrawalsABI = []byte(`[
{
"type": "function",
"name": "pendingWithdrawals",
"inputs": [{"name": "channelId", "type": "bytes32"}],
"outputs": [
{"name": "amount", "type": "uint128"},
{"name": "initiatedAt", "type": "uint40"}
],
"stateMutability": "view"
}
]`)BatchSettlementReceiversABI for reading receivers(receiver, token).
Source: mechanisms/evm/batch-settlement/constants.go:327
var BatchSettlementReceiversABI = []byte(`[
{
"type": "function",
"name": "receivers",
"inputs": [
{"name": "receiver", "type": "address"},
{"name": "token", "type": "address"}
],
"outputs": [
{"name": "totalClaimed", "type": "uint128"},
{"name": "totalSettled", "type": "uint128"}
],
"stateMutability": "view"
}
]`)BatchSettlementRefundABI for calling refund(config, amount).
Source: mechanisms/evm/batch-settlement/constants.go:236
var BatchSettlementRefundABI = []byte(`[
{
"type": "function",
"name": "refund",
"inputs": [
{"name": "config", "type": "tuple", "components": ` + channelConfigComponentsJSON + `},
{"name": "amount", "type": "uint128"}
],
"outputs": [],
"stateMutability": "nonpayable"
}
]`)BatchSettlementRefundNonceABI for reading refundNonce(channelId).
Source: mechanisms/evm/batch-settlement/constants.go:305
var BatchSettlementRefundNonceABI = []byte(`[
{
"type": "function",
"name": "refundNonce",
"inputs": [{"name": "channelId", "type": "bytes32"}],
"outputs": [{"name": "", "type": "uint256"}],
"stateMutability": "view"
}
]`)BatchSettlementRefundWithSignatureABI for calling refundWithSignature(config, amount, nonce, receiverAuthorizerSignature).
Source: mechanisms/evm/batch-settlement/constants.go:250
var BatchSettlementRefundWithSignatureABI = []byte(`[
{
"type": "function",
"name": "refundWithSignature",
"inputs": [
{"name": "config", "type": "tuple", "components": ` + channelConfigComponentsJSON + `},
{"name": "amount", "type": "uint128"},
{"name": "nonce", "type": "uint256"},
{"name": "receiverAuthorizerSignature", "type": "bytes"}
],
"outputs": [],
"stateMutability": "nonpayable"
}
]`)BatchSettlementSettleABI for calling settle(receiver, token).
Source: mechanisms/evm/batch-settlement/constants.go:222
var BatchSettlementSettleABI = []byte(`[
{
"type": "function",
"name": "settle",
"inputs": [
{"name": "receiver", "type": "address"},
{"name": "token", "type": "address"}
],
"outputs": [],
"stateMutability": "nonpayable"
}
]`)ChannelConfigTypeHash is keccak256(ChannelConfigTypeString).
Source: mechanisms/evm/batch-settlement/constants.go:34
var ChannelConfigTypeHash = crypto.Keccak256([]byte(ChannelConfigTypeString))ChannelConfigTypes defines the EIP-712 types for the channel-config struct, used to compute the chain-bound channel id via hashTypedData.
Source: mechanisms/evm/batch-settlement/constants.go:45
var ChannelConfigTypes = map[string][]evm.TypedDataField{
"ChannelConfig": {
{Name: "payer", Type: "address"},
{Name: "payerAuthorizer", Type: "address"},
{Name: "receiver", Type: "address"},
{Name: "receiverAuthorizer", Type: "address"},
{Name: "token", Type: "address"},
{Name: "withdrawDelay", Type: "uint40"},
{Name: "salt", Type: "bytes32"},
},
}ClaimBatchTypes defines the EIP-712 types for receiver-authorizer claim batches.
Source: mechanisms/evm/batch-settlement/constants.go:77
var ClaimBatchTypes = map[string][]evm.TypedDataField{
"ClaimBatch": {
{Name: "claims", Type: "ClaimEntry[]"},
},
"ClaimEntry": {
{Name: "channelId", Type: "bytes32"},
{Name: "maxClaimableAmount", Type: "uint128"},
{Name: "totalClaimed", Type: "uint128"},
},
}ReceiveAuthorizationTypes defines the EIP-712 types for ERC-3009 ReceiveWithAuthorization.
Source: mechanisms/evm/batch-settlement/constants.go:89
var ReceiveAuthorizationTypes = map[string][]evm.TypedDataField{
"ReceiveWithAuthorization": {
{Name: "from", Type: "address"},
{Name: "to", Type: "address"},
{Name: "value", Type: "uint256"},
{Name: "validAfter", Type: "uint256"},
{Name: "validBefore", Type: "uint256"},
{Name: "nonce", Type: "bytes32"},
},
}RefundTypes defines the EIP-712 types for cooperative refund. Refund(bytes32 channelId, uint256 nonce, uint128 amount)
Source: mechanisms/evm/batch-settlement/constants.go:68
var RefundTypes = map[string][]evm.TypedDataField{
"Refund": {
{Name: "channelId", Type: "bytes32"},
{Name: "nonce", Type: "uint256"},
{Name: "amount", Type: "uint128"},
},
}VoucherTypes defines the EIP-712 types for a cumulative voucher. Voucher(bytes32 channelId, uint128 maxClaimableAmount)
Source: mechanisms/evm/batch-settlement/constants.go:59
var VoucherTypes = map[string][]evm.TypedDataField{
"Voucher": {
{Name: "channelId", Type: "bytes32"},
{Name: "maxClaimableAmount", Type: "uint128"},
},
}Functions
func BuildEip2612PermitData(input Eip2612PermitInput) ([]byte, error)
Source: mechanisms/evm/batch-settlement/encoding.go:125
BuildEip2612PermitData ABI-encodes (value, deadline, v, r, s) for the optional EIP-2612 permit segment consumed by Permit2DepositCollector.
func BuildErc3009CollectorData(validAfter, validBefore, salt, signature string) ([]byte, error)
Source: mechanisms/evm/batch-settlement/encoding.go:87
BuildErc3009CollectorData ABI-encodes (validAfter, validBefore, salt, signature) for ERC3009DepositCollector.collect().
func BuildErc3009DepositNonce(channelId string, salt string) (string, error)
Source: mechanisms/evm/batch-settlement/encoding.go:68
BuildErc3009DepositNonce computes the ERC-3009 nonce used by the deposit collector: keccak256(abi.encode(channelId, salt)).
func BuildPermit2CollectorData(nonce, deadline, permit2Signature string, eip2612PermitData []byte) ([]byte, error)
Source: mechanisms/evm/batch-settlement/encoding.go:155
BuildPermit2CollectorData ABI-encodes (nonce, deadline, permit2Signature,
eip2612PermitData) as the collectorData passed to deposit(..., collector,
collectorData) when using the Permit2 transfer method. Pass an empty
eip2612PermitData ([]byte{} or 0x) when no EIP-2612 permit accompanies
the Permit2 authorization.
func ChannelConfigFromMap(data map[string]interface{}) (ChannelConfig, error)
Source: mechanisms/evm/batch-settlement/types.go:293
ChannelConfigFromMap parses a ChannelConfig from a raw map.
func ChannelConfigToMap(c ChannelConfig) map[string]interface{}
Source: mechanisms/evm/batch-settlement/types.go:557
ChannelConfigToMap converts a ChannelConfig to a map.
func ChannelIdBindingError(config ChannelConfig, claimedChannelId string, networkOrChainId interface{}) string
Source: mechanisms/evm/batch-settlement/utils.go:98
ChannelIdBindingError binds a claimed channel id to a channel config and network. Returns ErrInvalidChannelId or ErrChannelIdMismatch, or "" when the binding is valid.
func ChannelStateRequirementsFromMap(data map[string]interface{}) *BatchSettlementChannelStateExtra
Source: mechanisms/evm/batch-settlement/types.go:770
ChannelStateRequirementsFromMap parses a channelState entry on PaymentRequirements.extra. Returns nil when absent or missing channelId.
func ClaimPayloadFromMap(data map[string]interface{}) (*BatchSettlementClaimPayload, error)
Source: mechanisms/evm/batch-settlement/types.go:496
ClaimPayloadFromMap creates a BatchSettlementClaimPayload from a raw map.
func ComputeChannelId(config ChannelConfig, networkOrChainID interface{}) (string, error)
Source: mechanisms/evm/batch-settlement/utils.go:22
ComputeChannelId computes the chain-bound channel ID from a ChannelConfig via EIP-712 hashTypedData. The networkOrChainID argument may be either a CAIP-2 network identifier (e.g. "eip155:84532") or a numeric chain id as a *big.Int.
func DepositPayloadFromMap(data map[string]interface{}) (*BatchSettlementDepositPayload, error)
Source: mechanisms/evm/batch-settlement/types.go:373
DepositPayloadFromMap creates a BatchSettlementDepositPayload from a raw map.
func EnrichedRefundPayloadFromMap(data map[string]interface{}) (*BatchSettlementEnrichedRefundPayload, error)
Source: mechanisms/evm/batch-settlement/types.go:520
EnrichedRefundPayloadFromMap creates a BatchSettlementEnrichedRefundPayload from a raw map.
func GetBatchSettlementEip712Domain(chainID *big.Int) evm.TypedDataDomain
Source: mechanisms/evm/batch-settlement/utils.go:111
GetBatchSettlementEip712Domain returns the EIP-712 domain for the batch-settlement contract on the given chain.
func IsBatchedPayload(data map[string]interface{}) bool
Source: mechanisms/evm/batch-settlement/types.go:284
IsBatchedPayload checks if a raw payload map is any batched payload type.
func IsCanonicalChannelId(value string) bool
Source: mechanisms/evm/batch-settlement/utils.go:82
IsCanonicalChannelId reports whether value is a canonical bytes32 channel id
(0x + exactly 64 hex digits). Mixed-case hex is accepted.
func IsClaimPayload(data map[string]interface{}) bool
Source: mechanisms/evm/batch-settlement/types.go:257
IsClaimPayload checks if a raw payload map is a claim settle-action payload. The claimAuthorizerSignature field is optional (facilitator auto-signs when absent).
func IsDepositPayload(data map[string]interface{}) bool
Source: mechanisms/evm/batch-settlement/types.go:231
IsDepositPayload checks if a raw payload map is a batched deposit payload.
func IsEnrichedRefundPayload(data map[string]interface{}) bool
Source: mechanisms/evm/batch-settlement/types.go:273
IsEnrichedRefundPayload checks if a raw payload is an enriched refund settle-action. The amount + refundNonce + claims fields are added by the server's enrichment hook.
func IsNotExist(err error) bool
Source: mechanisms/evm/batch-settlement/storage_utils.go:16
IsNotExist returns true when err is a "file does not exist" error.
func IsRefundPayload(data map[string]interface{}) bool
Source: mechanisms/evm/batch-settlement/types.go:248
IsRefundPayload checks if a raw payload map is a client-side refund payload.
func IsSettlePayload(data map[string]interface{}) bool
Source: mechanisms/evm/batch-settlement/types.go:264
IsSettlePayload checks if a raw payload map is a settle action (transfer to receiver).
func IsVoucherPayload(data map[string]interface{}) bool
Source: mechanisms/evm/batch-settlement/types.go:240
IsVoucherPayload checks if a raw payload map is a batched voucher-only payload.
func NormalizeChannelId(channelId string) (string, error)
Source: mechanisms/evm/batch-settlement/utils.go:89
NormalizeChannelId validates canonical bytes32 form and returns lowercase. The error message is the stable ErrInvalidChannelId code only - untrusted input is never echoed.
func PaymentResponseExtraFromMap(data map[string]interface{}) (*BatchSettlementPaymentResponseExtra, error)
Source: mechanisms/evm/batch-settlement/types.go:736
PaymentResponseExtraFromMap parses the canonical nested
BatchSettlementPaymentResponseExtra shape from a map.
func ReadJSONFile(filePath string, out interface{}) (bool, error)
Source: mechanisms/evm/batch-settlement/storage_utils.go:41
ReadJSONFile reads filePath and unmarshals the JSON into out. Returns (false, nil) if the file does not exist; (true, nil) on success. Other errors (permissions, malformed JSON) are returned as-is.
func RefundPayloadFromMap(data map[string]interface{}) (*BatchSettlementRefundPayload, error)
Source: mechanisms/evm/batch-settlement/types.go:433
RefundPayloadFromMap creates a BatchSettlementRefundPayload from a raw map.
func ResolveWithinDir(baseDir, filename string) (string, error)
Source: mechanisms/evm/batch-settlement/storage_utils.go:22
ResolveWithinDir resolves filename under baseDir and asserts the result stays
within baseDir. Rejects path-escape attempts (e.g. via ..).
func SettlePayloadFromMap(data map[string]interface{}) (*BatchSettlementSettlePayload, error)
Source: mechanisms/evm/batch-settlement/types.go:512
SettlePayloadFromMap creates a BatchSettlementSettlePayload from a raw map.
func VoucherClaimFromMap(data map[string]interface{}) (*BatchSettlementVoucherClaim, error)
Source: mechanisms/evm/batch-settlement/types.go:456
VoucherClaimFromMap parses a single BatchSettlementVoucherClaim from a raw map.
func VoucherClaimToMap(c BatchSettlementVoucherClaim) map[string]interface{}
Source: mechanisms/evm/batch-settlement/types.go:680
VoucherClaimToMap converts a BatchSettlementVoucherClaim to a map.
func VoucherClaimsFromList(data []interface{}) ([]BatchSettlementVoucherClaim, error)
Source: mechanisms/evm/batch-settlement/types.go:479
VoucherClaimsFromList parses a list of BatchSettlementVoucherClaim from a raw slice.
func VoucherClaimsToList(claims []BatchSettlementVoucherClaim) []interface{}
Source: mechanisms/evm/batch-settlement/types.go:692
VoucherClaimsToList converts a slice of claims to a raw list.
func VoucherPayloadFromMap(data map[string]interface{}) (*BatchSettlementVoucherPayload, error)
Source: mechanisms/evm/batch-settlement/types.go:411
VoucherPayloadFromMap creates a BatchSettlementVoucherPayload from a raw map.
func VoucherStateRequirementsFromMap(data map[string]interface{}) *BatchSettlementVoucherStateExtra
Source: mechanisms/evm/batch-settlement/types.go:796
VoucherStateRequirementsFromMap parses a voucherState entry on PaymentRequirements.extra. Returns nil when absent or empty.
func WriteJSONAtomic(filePath string, value interface{}) error
Source: mechanisms/evm/batch-settlement/storage_utils.go:57
WriteJSONAtomic writes value as JSON to filePath atomically (write to temp file in the same directory, then rename). Creates parent directories as needed.
Types
type AssetTransferMethod
Source: mechanisms/evm/batch-settlement/types.go:42
AssetTransferMethod identifies how a deposit moves tokens into the channel:
either an ERC-3009 ReceiveWithAuthorization (default) or a Permit2
channel-bound PermitWitnessTransferFrom. Servers opt into a non-default
method by setting accepts.extra.assetTransferMethod on payment
requirements; clients dispatch on the same field.
type AssetTransferMethod stringtype AuthorizerSigner
Source: mechanisms/evm/batch-settlement/types.go:11
AuthorizerSigner is the interface for a dedicated key that provides EIP-712 signatures for claim / refund settle-action payloads.
type AuthorizerSigner interface {
Address() string
SignClaimBatch(ctx context.Context, claims []BatchSettlementVoucherClaim, network string) ([]byte, error)
SignRefund(ctx context.Context, channelId string, amount string, nonce string, network string) ([]byte, error)
}Methods
Address func() stringSignClaimBatch func(ctx context.Context, claims []BatchSettlementVoucherClaim, network string) ([]byte, error)SignRefund func(ctx context.Context, channelId string, amount string, nonce string, network string) ([]byte, error)
type BatchSettlementChannelStateExtra
Source: mechanisms/evm/batch-settlement/types.go:146
BatchSettlementChannelStateExtra is the public per-channel state snapshot embedded in settle/verify response extras.
type BatchSettlementChannelStateExtra struct {
ChannelId string `json:"channelId"`
Balance string `json:"balance"`
TotalClaimed string `json:"totalClaimed"`
WithdrawRequestedAt int `json:"withdrawRequestedAt"`
RefundNonce string `json:"refundNonce"`
ChargedCumulativeAmount string `json:"chargedCumulativeAmount,omitempty"`
}Fields
ChannelId string`json:"channelId"`Balance string`json:"balance"`TotalClaimed string`json:"totalClaimed"`WithdrawRequestedAt int`json:"withdrawRequestedAt"`RefundNonce string`json:"refundNonce"`ChargedCumulativeAmount string`json:"chargedCumulativeAmount,omitempty"`
func ToMap() map[string]interface{}
Source: mechanisms/evm/batch-settlement/types.go:811
ToMap converts a BatchSettlementChannelStateExtra to a map (used for emitting
extra.channelState on corrective-402 PaymentRequirements).
type BatchSettlementClaimPayload
Source: mechanisms/evm/batch-settlement/types.go:197
BatchSettlementClaimPayload batches claims with receiverAuthorizer signature. ClaimAuthorizerSignature is optional - when absent, the facilitator auto-signs using its AuthorizerSigner.
type BatchSettlementClaimPayload struct {
Type string `json:"type"` // "claim"
Claims []BatchSettlementVoucherClaim `json:"claims"`
ClaimAuthorizerSignature string `json:"claimAuthorizerSignature,omitempty"`
}Fields
Type string`json:"type"`"claim"
Claims []BatchSettlementVoucherClaim`json:"claims"`ClaimAuthorizerSignature string`json:"claimAuthorizerSignature,omitempty"`
func ToMap() map[string]interface{}
Source: mechanisms/evm/batch-settlement/types.go:640
ToMap converts a BatchSettlementClaimPayload to a map.
type BatchSettlementDepositAuthorization
Source: mechanisms/evm/batch-settlement/types.go:99
BatchSettlementDepositAuthorization wraps asset-transfer authorization data.
Exactly one of the fields is populated per deposit (erc3009Authorization
XOR permit2Authorization).
type BatchSettlementDepositAuthorization struct {
Erc3009Authorization *BatchSettlementErc3009Authorization `json:"erc3009Authorization,omitempty"`
Permit2Authorization *BatchSettlementPermit2Authorization `json:"permit2Authorization,omitempty"`
}Fields
Erc3009Authorization *BatchSettlementErc3009Authorization`json:"erc3009Authorization,omitempty"`Permit2Authorization *BatchSettlementPermit2Authorization`json:"permit2Authorization,omitempty"`
type BatchSettlementDepositData
Source: mechanisms/evm/batch-settlement/types.go:105
BatchSettlementDepositData is the deposit portion of a deposit payload.
type BatchSettlementDepositData struct {
Amount string `json:"amount"`
Authorization BatchSettlementDepositAuthorization `json:"authorization"`
}Fields
Amount string`json:"amount"`Authorization BatchSettlementDepositAuthorization`json:"authorization"`
type BatchSettlementDepositPayload
Source: mechanisms/evm/batch-settlement/types.go:111
BatchSettlementDepositPayload is sent on the first request to fund a channel.
type BatchSettlementDepositPayload struct {
Type string `json:"type"` // "deposit"
ChannelConfig ChannelConfig `json:"channelConfig"`
Voucher BatchSettlementVoucherFields `json:"voucher"`
Deposit BatchSettlementDepositData `json:"deposit"`
}Fields
Type string`json:"type"`"deposit"
ChannelConfig ChannelConfig`json:"channelConfig"`Voucher BatchSettlementVoucherFields`json:"voucher"`Deposit BatchSettlementDepositData`json:"deposit"`
func ToMap() map[string]interface{}
Source: mechanisms/evm/batch-settlement/types.go:578
ToMap converts a BatchSettlementDepositPayload to a map.
type BatchSettlementEnrichedRefundPayload
Source: mechanisms/evm/batch-settlement/types.go:215
BatchSettlementEnrichedRefundPayload is a refund payload enriched by the server with the resolved amount, refundNonce, and any claims that need to be included atomically with the refund. RefundAuthorizerSignature and ClaimAuthorizerSignature are optional - when absent, the facilitator auto-signs via its AuthorizerSigner.
type BatchSettlementEnrichedRefundPayload struct {
Type string `json:"type"` // "refund"
ChannelConfig ChannelConfig `json:"channelConfig"`
Voucher BatchSettlementVoucherFields `json:"voucher"`
Amount string `json:"amount"`
RefundNonce string `json:"refundNonce"`
Claims []BatchSettlementVoucherClaim `json:"claims"`
RefundAuthorizerSignature string `json:"refundAuthorizerSignature,omitempty"`
ClaimAuthorizerSignature string `json:"claimAuthorizerSignature,omitempty"`
}Fields
Type string`json:"type"`"refund"
ChannelConfig ChannelConfig`json:"channelConfig"`Voucher BatchSettlementVoucherFields`json:"voucher"`Amount string`json:"amount"`RefundNonce string`json:"refundNonce"`Claims []BatchSettlementVoucherClaim`json:"claims"`RefundAuthorizerSignature string`json:"refundAuthorizerSignature,omitempty"`ClaimAuthorizerSignature string`json:"claimAuthorizerSignature,omitempty"`
func ToMap() map[string]interface{}
Source: mechanisms/evm/batch-settlement/types.go:661
ToMap converts a BatchSettlementEnrichedRefundPayload to a map.
type BatchSettlementErc3009Authorization
Source: mechanisms/evm/batch-settlement/types.go:56
BatchSettlementErc3009Authorization represents the ERC-3009 ReceiveWithAuthorization params.
type BatchSettlementErc3009Authorization struct {
ValidAfter string `json:"validAfter"`
ValidBefore string `json:"validBefore"`
Salt string `json:"salt"`
Signature string `json:"signature"`
}Fields
ValidAfter string`json:"validAfter"`ValidBefore string`json:"validBefore"`Salt string`json:"salt"`Signature string`json:"signature"`
type BatchSettlementPaymentRequirementsExtra
Source: mechanisms/evm/batch-settlement/types.go:174
BatchSettlementPaymentRequirementsExtra is the typed shape of the extra
field on PaymentRequirements for the batch-settlement scheme. The
corrective-402 recovery payload is split across two camelCase keys:
channelState (channel snapshot) and voucherState (latest signed voucher
proof).
type BatchSettlementPaymentRequirementsExtra struct {
ReceiverAuthorizer string `json:"receiverAuthorizer"`
WithdrawDelay int `json:"withdrawDelay"`
Name string `json:"name"`
Version string `json:"version"`
AssetTransferMethod string `json:"assetTransferMethod,omitempty"` // "eip3009" or "permit2"
ChannelState *BatchSettlementChannelStateExtra `json:"channelState,omitempty"`
VoucherState *BatchSettlementVoucherStateExtra `json:"voucherState,omitempty"`
}Fields
ReceiverAuthorizer string`json:"receiverAuthorizer"`WithdrawDelay int`json:"withdrawDelay"`Name string`json:"name"`Version string`json:"version"`AssetTransferMethod string`json:"assetTransferMethod,omitempty"`"eip3009" or "permit2"
ChannelState *BatchSettlementChannelStateExtra`json:"channelState,omitempty"`VoucherState *BatchSettlementVoucherStateExtra`json:"voucherState,omitempty"`
type BatchSettlementPaymentResponseExtra
Source: mechanisms/evm/batch-settlement/types.go:163
BatchSettlementPaymentResponseExtra carries channel state in settle/verify responses.
type BatchSettlementPaymentResponseExtra struct {
ChargedAmount string `json:"chargedAmount,omitempty"`
ChannelState *BatchSettlementChannelStateExtra `json:"channelState,omitempty"`
VoucherState *BatchSettlementVoucherStateExtra `json:"voucherState,omitempty"`
}Fields
ChargedAmount string`json:"chargedAmount,omitempty"`ChannelState *BatchSettlementChannelStateExtra`json:"channelState,omitempty"`VoucherState *BatchSettlementVoucherStateExtra`json:"voucherState,omitempty"`
func ToMap() map[string]interface{}
Source: mechanisms/evm/batch-settlement/types.go:701
ToMap converts a BatchSettlementPaymentResponseExtra to its canonical nested wire shape.
type BatchSettlementPermit2Authorization
Source: mechanisms/evm/batch-settlement/types.go:79
BatchSettlementPermit2Authorization is the Permit2 PermitWitnessTransferFrom authorization signed by the payer when the deposit uses the permit2 transfer method.
type BatchSettlementPermit2Authorization struct {
From string `json:"from"`
Permitted BatchSettlementPermit2TokenPermissions `json:"permitted"`
Spender string `json:"spender"`
Nonce string `json:"nonce"`
Deadline string `json:"deadline"`
Witness BatchSettlementPermit2Witness `json:"witness"`
Signature string `json:"signature"`
}Fields
From string`json:"from"`Permitted BatchSettlementPermit2TokenPermissions`json:"permitted"`Spender string`json:"spender"`Nonce string`json:"nonce"`Deadline string`json:"deadline"`Witness BatchSettlementPermit2Witness`json:"witness"`Signature string`json:"signature"`
type BatchSettlementPermit2TokenPermissions
Source: mechanisms/evm/batch-settlement/types.go:65
BatchSettlementPermit2TokenPermissions is the {token, amount} pair signed inside a
Permit2 PermitWitnessTransferFrom authorization.
type BatchSettlementPermit2TokenPermissions struct {
Token string `json:"token"`
Amount string `json:"amount"`
}Fields
Token string`json:"token"`Amount string`json:"amount"`
type BatchSettlementPermit2Witness
Source: mechanisms/evm/batch-settlement/types.go:72
BatchSettlementPermit2Witness is the channel-bound witness binding a Permit2 transfer to a specific batch-settlement channel id.
type BatchSettlementPermit2Witness struct {
ChannelId string `json:"channelId"`
}Fields
ChannelId string`json:"channelId"`
type BatchSettlementRefundPayload
Source: mechanisms/evm/batch-settlement/types.go:127
BatchSettlementRefundPayload is the client-side cooperative-refund request.
Amount is optional - when absent, it defaults to the full remaining balance.
type BatchSettlementRefundPayload struct {
Type string `json:"type"` // "refund"
ChannelConfig ChannelConfig `json:"channelConfig"`
Voucher BatchSettlementVoucherFields `json:"voucher"`
Amount string `json:"amount,omitempty"`
}Fields
Type string`json:"type"`"refund"
ChannelConfig ChannelConfig`json:"channelConfig"`Voucher BatchSettlementVoucherFields`json:"voucher"`Amount string`json:"amount,omitempty"`
func ToMap() map[string]interface{}
Source: mechanisms/evm/batch-settlement/types.go:627
ToMap converts a BatchSettlementRefundPayload to a map.
type BatchSettlementSettlePayload
Source: mechanisms/evm/batch-settlement/types.go:204
BatchSettlementSettlePayload transfers claimed funds to receiver.
type BatchSettlementSettlePayload struct {
Type string `json:"type"` // "settle"
Receiver string `json:"receiver"`
Token string `json:"token"`
}Fields
Type string`json:"type"`"settle"
Receiver string`json:"receiver"`Token string`json:"token"`
func ToMap() map[string]interface{}
Source: mechanisms/evm/batch-settlement/types.go:652
ToMap converts a BatchSettlementSettlePayload to a map.
type BatchSettlementVoucherClaim
Source: mechanisms/evm/batch-settlement/types.go:135
BatchSettlementVoucherClaim is used in claim operations onchain.
type BatchSettlementVoucherClaim struct {
Voucher struct {
Channel ChannelConfig `json:"channel"`
MaxClaimableAmount string `json:"maxClaimableAmount"`
} `json:"voucher"`
Signature string `json:"signature"`
TotalClaimed string `json:"totalClaimed"`
}Fields
Voucher struct { Channel ChannelConfig `json:"channel"` MaxClaimableAmount string `json:"maxClaimableAmount"` }`json:"voucher"`Signature string`json:"signature"`TotalClaimed string`json:"totalClaimed"`
type BatchSettlementVoucherFields
Source: mechanisms/evm/batch-settlement/types.go:90
BatchSettlementVoucherFields holds the cumulative-ceiling voucher.
type BatchSettlementVoucherFields struct {
ChannelId string `json:"channelId"`
MaxClaimableAmount string `json:"maxClaimableAmount"`
Signature string `json:"signature"`
}Fields
ChannelId string`json:"channelId"`MaxClaimableAmount string`json:"maxClaimableAmount"`Signature string`json:"signature"`
type BatchSettlementVoucherPayload
Source: mechanisms/evm/batch-settlement/types.go:119
BatchSettlementVoucherPayload is sent on subsequent requests (no new deposit).
type BatchSettlementVoucherPayload struct {
Type string `json:"type"` // "voucher"
ChannelConfig ChannelConfig `json:"channelConfig"`
Voucher BatchSettlementVoucherFields `json:"voucher"`
}Fields
Type string`json:"type"`"voucher"
ChannelConfig ChannelConfig`json:"channelConfig"`Voucher BatchSettlementVoucherFields`json:"voucher"`
func ToMap() map[string]interface{}
Source: mechanisms/evm/batch-settlement/types.go:618
ToMap converts a BatchSettlementVoucherPayload to a map.
type BatchSettlementVoucherStateExtra
Source: mechanisms/evm/batch-settlement/types.go:157
BatchSettlementVoucherStateExtra is the public latest-voucher snapshot embedded in settle/verify response extras.
type BatchSettlementVoucherStateExtra struct {
SignedMaxClaimable string `json:"signedMaxClaimable,omitempty"`
Signature string `json:"signature,omitempty"`
}Fields
SignedMaxClaimable string`json:"signedMaxClaimable,omitempty"`Signature string`json:"signature,omitempty"`
func ToMap() map[string]interface{}
Source: mechanisms/evm/batch-settlement/types.go:830
ToMap converts a BatchSettlementVoucherStateExtra to a map (used for emitting
extra.voucherState on corrective-402 PaymentRequirements).
type ChannelConfig
Source: mechanisms/evm/batch-settlement/types.go:19
ChannelConfig is the immutable configuration for a payment channel. channelId = EIP-712 hashTypedData of ChannelConfig with the BatchSettlement domain.
type ChannelConfig struct {
Payer string `json:"payer"`
PayerAuthorizer string `json:"payerAuthorizer"`
Receiver string `json:"receiver"`
ReceiverAuthorizer string `json:"receiverAuthorizer"`
Token string `json:"token"`
WithdrawDelay int `json:"withdrawDelay"`
Salt string `json:"salt"`
}Fields
Payer string`json:"payer"`PayerAuthorizer string`json:"payerAuthorizer"`Receiver string`json:"receiver"`ReceiverAuthorizer string`json:"receiverAuthorizer"`Token string`json:"token"`WithdrawDelay int`json:"withdrawDelay"`Salt string`json:"salt"`
type ChannelState
Source: mechanisms/evm/batch-settlement/types.go:30
ChannelState represents onchain state read from the BatchSettlement contract.
type ChannelState struct {
Balance *big.Int
TotalClaimed *big.Int
WithdrawRequestedAt int
RefundNonce *big.Int
}Fields
Balance *big.IntTotalClaimed *big.IntWithdrawRequestedAt intRefundNonce *big.Int
type Eip2612PermitInput
Source: mechanisms/evm/batch-settlement/encoding.go:115
Eip2612PermitInput is the optional EIP-2612 permit segment consumed by Permit2DepositCollector when the deposit goes through the Permit2 path with a paired EIP-2612 approval.
type Eip2612PermitInput struct {
Value string
Deadline string
V uint8
R string // 32-byte hex (with or without 0x prefix)
S string
}Fields
Value stringDeadline stringV uint8R string32-byte hex (with or without 0x prefix)
S string
type FileChannelStorageOptions
Source: mechanisms/evm/batch-settlement/types.go:186
FileChannelStorageOptions configures file-backed channel storage. Channels are stored under {Directory}/{client|server}/{channelId}.json.
type FileChannelStorageOptions struct {
Directory string
}Fields
Directory string
