types
import "github.com/x402-foundation/x402/go/v2/types"
Functions
func DetectVersion(data []byte) (int, error)
DetectVersion extracts x402Version from JSON bytes
func ExtractRequirementsInfo(data []byte) (*RequirementsInfo, error)
ExtractRequirementsInfo gets scheme and network from requirements bytes Works for both v1 and v2 (both have scheme/network at top level)
func GetSchemeAndNetwork(version int, payloadBytes []byte) (scheme string, network string, err error)
GetSchemeAndNetwork extracts scheme and network from payment payload bytes This is one of TWO version-aware functions in core (co-located for maintainability) Used by facilitator for routing
func MatchPayloadToRequirements( version int, payloadBytes []byte, requirementsBytes []byte, ) (bool, error)
MatchPayloadToRequirements checks if payment payload matches requirements This is one of TWO version-aware functions in core (co-located for maintainability) Used by server.FindMatchingRequirements
func ToPayloadBase(data []byte) (*PayloadBase, error)
ToPayloadBase unmarshals just version and payload field
func ToPaymentPayload(data []byte) (*PaymentPayload, error)
ToPaymentPayload unmarshals bytes to v2 payment payload
func ToPaymentPayloadV1(data []byte) (*PaymentPayloadV1, error)
ToPaymentPayloadV1 unmarshals bytes to v1 payment payload
func ToPaymentRequired(data []byte) (*PaymentRequired, error)
ToPaymentRequired unmarshals bytes to v2 payment required response
func ToPaymentRequiredPartial(data []byte) (*PaymentRequiredPartial, error)
ToPaymentRequiredPartial unmarshals PaymentRequired keeping accepts as raw bytes
func ToPaymentRequiredV1(data []byte) (*PaymentRequiredV1, error)
ToPaymentRequiredV1 unmarshals bytes to v1 payment required response
func ToPaymentRequirements(data []byte) (*PaymentRequirements, error)
ToPaymentRequirements unmarshals bytes to v2 payment requirements
func ToPaymentRequirementsV1(data []byte) (*PaymentRequirementsV1, error)
ToPaymentRequirementsV1 unmarshals bytes to v1 payment requirements
func ToSupportedKind(data []byte) (*SupportedKind, error)
ToSupportedKind unmarshals bytes to v2 supported kind
func ToSupportedKindV1(data []byte) (*SupportedKindV1, error)
ToSupportedKindV1 unmarshals bytes to v1 supported kind
Types
type PayloadBase
PayloadBase is minimal payload structure (version + payload field only) Used by v2 client to return partial payload before core wraps it
type PayloadBase struct {
X402Version int `json:"x402Version"`
Payload map[string]interface{} `json:"payload"`
}Fields
X402Version int`json:"x402Version"`Payload map[string]interface{}`json:"payload"`
type PaymentPayload
PaymentPayload represents a v2 payment payload structure V2 has accepted field with nested scheme/network/requirements
type PaymentPayload struct {
X402Version int `json:"x402Version"`
Payload map[string]interface{} `json:"payload"`
Accepted PaymentRequirements `json:"accepted"`
Resource *ResourceInfo `json:"resource,omitempty"`
Extensions map[string]interface{} `json:"extensions,omitempty"`
}Fields
X402Version int`json:"x402Version"`Payload map[string]interface{}`json:"payload"`Accepted PaymentRequirements`json:"accepted"`Resource *ResourceInfo`json:"resource,omitempty"`Extensions map[string]interface{}`json:"extensions,omitempty"`
func GetNetwork() string
func GetPayload() map[string]interface{}
func GetScheme() string
func GetVersion() int
PaymentPayloadView interface implementation for V2
type PaymentPayloadV1
PaymentPayloadV1 represents a v1 payment payload structure V1 has scheme and network at top level (not in accepted field)
type PaymentPayloadV1 struct {
X402Version int `json:"x402Version"`
Scheme string `json:"scheme"`
Network string `json:"network"`
Payload map[string]interface{} `json:"payload"`
}Fields
X402Version int`json:"x402Version"`Scheme string`json:"scheme"`Network string`json:"network"`Payload map[string]interface{}`json:"payload"`
func GetNetwork() string
func GetPayload() map[string]interface{}
func GetScheme() string
func GetVersion() int
PaymentPayloadView interface implementation for V1
type PaymentRequired
PaymentRequired represents a v2 402 response structure
type PaymentRequired struct {
X402Version int `json:"x402Version"`
Error string `json:"error,omitempty"`
Resource *ResourceInfo `json:"resource,omitempty"`
Accepts []PaymentRequirements `json:"accepts"`
Extensions map[string]interface{} `json:"extensions,omitempty"`
}Fields
X402Version int`json:"x402Version"`Error string`json:"error,omitempty"`Resource *ResourceInfo`json:"resource,omitempty"`Accepts []PaymentRequirements`json:"accepts"`Extensions map[string]interface{}`json:"extensions,omitempty"`
type PaymentRequiredPartial
PaymentRequiredPartial for extracting accepts array as raw bytes Keeps accepts as raw bytes to avoid version-specific unmarshaling
type PaymentRequiredPartial struct {
X402Version int `json:"x402Version"`
Error string `json:"error,omitempty"`
Accepts []json.RawMessage `json:"accepts"` // Keep as raw bytes
Resource json.RawMessage `json:"resource,omitempty"`
Extensions json.RawMessage `json:"extensions,omitempty"`
}Fields
X402Version int`json:"x402Version"`Error string`json:"error,omitempty"`Accepts []json.RawMessage`json:"accepts"`Keep as raw bytes
Resource json.RawMessage`json:"resource,omitempty"`Extensions json.RawMessage`json:"extensions,omitempty"`
type PaymentRequiredV1
PaymentRequiredV1 represents a v1 402 response structure
type PaymentRequiredV1 struct {
X402Version int `json:"x402Version"`
Error string `json:"error,omitempty"`
Accepts []PaymentRequirementsV1 `json:"accepts"`
}Fields
X402Version int`json:"x402Version"`Error string`json:"error,omitempty"`Accepts []PaymentRequirementsV1`json:"accepts"`
type PaymentRequirements
PaymentRequirements represents v2 payment requirements structure
type PaymentRequirements struct {
Scheme string `json:"scheme"`
Network string `json:"network"`
Asset string `json:"asset"`
Amount string `json:"amount"`
PayTo string `json:"payTo"`
MaxTimeoutSeconds int `json:"maxTimeoutSeconds"`
Extra map[string]interface{} `json:"extra,omitempty"`
}Fields
Scheme string`json:"scheme"`Network string`json:"network"`Asset string`json:"asset"`Amount string`json:"amount"`PayTo string`json:"payTo"`MaxTimeoutSeconds int`json:"maxTimeoutSeconds"`Extra map[string]interface{}`json:"extra,omitempty"`
func GetAmount() string
func GetAsset() string
func GetExtra() map[string]interface{}
func GetMaxTimeoutSeconds() int
func GetNetwork() string
func GetPayTo() string
func GetScheme() string
PaymentRequirementsView interface implementation for V2
type PaymentRequirementsV1
PaymentRequirementsV1 represents v1 payment requirements structure
type PaymentRequirementsV1 struct {
Scheme string `json:"scheme"`
Network string `json:"network"`
MaxAmountRequired string `json:"maxAmountRequired"`
Resource string `json:"resource"`
Description string `json:"description,omitempty"`
MimeType string `json:"mimeType,omitempty"`
PayTo string `json:"payTo"`
MaxTimeoutSeconds int `json:"maxTimeoutSeconds"`
Asset string `json:"asset"`
OutputSchema *json.RawMessage `json:"outputSchema,omitempty"`
Extra *json.RawMessage `json:"extra,omitempty"`
}Fields
Scheme string`json:"scheme"`Network string`json:"network"`MaxAmountRequired string`json:"maxAmountRequired"`Resource string`json:"resource"`Description string`json:"description,omitempty"`MimeType string`json:"mimeType,omitempty"`PayTo string`json:"payTo"`MaxTimeoutSeconds int`json:"maxTimeoutSeconds"`Asset string`json:"asset"`OutputSchema *json.RawMessage`json:"outputSchema,omitempty"`Extra *json.RawMessage`json:"extra,omitempty"`
func GetAmount() string
func GetAsset() string
func GetExtra() map[string]interface{}
func GetMaxTimeoutSeconds() int
func GetNetwork() string
func GetPayTo() string
func GetScheme() string
PaymentRequirementsView interface implementation for V1
type RequirementsInfo
RequirementsInfo is minimal info extracted from requirements for routing
type RequirementsInfo struct {
Scheme string
Network string
}Fields
Scheme stringNetwork string
type ResourceInfo
ResourceInfo describes the resource being accessed.
ServiceName, Tags, and IconUrl are bazaar service metadata fields. See
specs/extensions/bazaar.md "Service Metadata on resource" for the
soft-drop validation rules facilitators apply during extraction.
type ResourceInfo struct {
URL string `json:"url"`
Description string `json:"description,omitempty"`
MimeType string `json:"mimeType,omitempty"`
ServiceName string `json:"serviceName,omitempty"`
Tags []string `json:"tags,omitempty"`
IconUrl string `json:"iconUrl,omitempty"`
}Fields
URL string`json:"url"`Description string`json:"description,omitempty"`MimeType string`json:"mimeType,omitempty"`ServiceName string`json:"serviceName,omitempty"`Tags []string`json:"tags,omitempty"`IconUrl string`json:"iconUrl,omitempty"`
type ResourceServerExtension
Source: types/extensions.go:12
ResourceServerExtension is a resource-side extension. Implementations
surface a stable Key() plus an enrichment callback used to expand the
extension declaration on the route.
Optional capabilities are exposed via the per-capability interfaces in
go/server_hooks.go (e.g. ResourceServerExtensionHookProvider,
ResourceServerExtensionEnrichPaymentRequiredProvider,
ResourceServerExtensionEnrichSettleResponseProvider). The resource
server type-asserts to those interfaces at registration time.
type ResourceServerExtension interface {
Key() string
EnrichDeclaration(declaration interface{}, transportContext interface{}) interface{}
}Methods
Key func() stringEnrichDeclaration func(declaration interface{}, transportContext interface{}) interface{}
type SupportedKind
SupportedKind represents a supported payment configuration
type SupportedKind struct {
X402Version int `json:"x402Version"`
Scheme string `json:"scheme"`
Network string `json:"network"`
Extra map[string]interface{} `json:"extra,omitempty"`
}Fields
X402Version int`json:"x402Version"`Scheme string`json:"scheme"`Network string`json:"network"`Extra map[string]interface{}`json:"extra,omitempty"`
type SupportedKindV1
SupportedKindV1 represents a V1 supported payment configuration
type SupportedKindV1 struct {
X402Version int `json:"x402Version"`
Scheme string `json:"scheme"`
Network string `json:"network"`
Extra *json.RawMessage `json:"extra,omitempty"`
}Fields
X402Version int`json:"x402Version"`Scheme string`json:"scheme"`Network string`json:"network"`Extra *json.RawMessage`json:"extra,omitempty"`
type SupportedResponse
SupportedResponse describes what payment kinds a facilitator supports
type SupportedResponse struct {
Kinds []SupportedKind `json:"kinds"` // Array of kinds with version in each element
Extensions []string `json:"extensions"` // Protocol extensions supported
Signers map[string][]string `json:"signers"` // CAIP family → Signer addresses
}Fields
Kinds []SupportedKind`json:"kinds"`Array of kinds with version in each element
Extensions []string`json:"extensions"`Protocol extensions supported
Signers map[string][]string`json:"signers"`CAIP family → Signer addresses
type SupportedResponseV1
SupportedResponseV1 is the old supported response format (V1 only, no extensions)
type SupportedResponseV1 struct {
Kinds []SupportedKindV1 `json:"kinds"`
}Fields
Kinds []SupportedKindV1`json:"kinds"`
