Types

types

github.com/x402-foundation/x402/go/v2/types

import "github.com/x402-foundation/x402/go/v2/types"

Functions

func DetectVersion(data []byte) (int, error)

Source: types/raw.go:9

DetectVersion extracts x402Version from JSON bytes

func ExtractRequirementsInfo(data []byte) (*RequirementsInfo, error)

Source: types/raw.go:24

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)

Source: types/helpers.go:11

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)

Source: types/helpers.go:45

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)

Source: types/raw.go:52

ToPayloadBase unmarshals just version and payload field

func ToPaymentPayload(data []byte) (*PaymentPayload, error)

Source: types/v2.go:84

ToPaymentPayload unmarshals bytes to v2 payment payload

func ToPaymentPayloadV1(data []byte) (*PaymentPayloadV1, error)

Source: types/v1.go:73

ToPaymentPayloadV1 unmarshals bytes to v1 payment payload

func ToPaymentRequired(data []byte) (*PaymentRequired, error)

Source: types/v2.go:102

ToPaymentRequired unmarshals bytes to v2 payment required response

func ToPaymentRequiredPartial(data []byte) (*PaymentRequiredPartial, error)

Source: types/raw.go:71

ToPaymentRequiredPartial unmarshals PaymentRequired keeping accepts as raw bytes

func ToPaymentRequiredV1(data []byte) (*PaymentRequiredV1, error)

Source: types/v1.go:91

ToPaymentRequiredV1 unmarshals bytes to v1 payment required response

func ToPaymentRequirements(data []byte) (*PaymentRequirements, error)

Source: types/v2.go:93

ToPaymentRequirements unmarshals bytes to v2 payment requirements

func ToPaymentRequirementsV1(data []byte) (*PaymentRequirementsV1, error)

Source: types/v1.go:82

ToPaymentRequirementsV1 unmarshals bytes to v1 payment requirements

func ToSupportedKind(data []byte) (*SupportedKind, error)

Source: types/v2.go:111

ToSupportedKind unmarshals bytes to v2 supported kind

func ToSupportedKindV1(data []byte) (*SupportedKindV1, error)

Source: types/v1.go:105

ToSupportedKindV1 unmarshals bytes to v1 supported kind

Types

type PayloadBase

Source: types/raw.go:46

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

Source: types/v2.go:9

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

Source: types/v2.go:20

func GetPayload() map[string]interface{}

Source: types/v2.go:21

func GetScheme() string

Source: types/v2.go:19

func GetVersion() int

Source: types/v2.go:18

PaymentPayloadView interface implementation for V2

type PaymentPayloadV1

Source: types/v1.go:9

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

Source: types/v1.go:19

func GetPayload() map[string]interface{}

Source: types/v1.go:20

func GetScheme() string

Source: types/v1.go:18

func GetVersion() int

Source: types/v1.go:17

PaymentPayloadView interface implementation for V1

type PaymentRequired

Source: types/v2.go:44

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

Source: types/raw.go:62

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

Source: types/v1.go:56

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

Source: types/v2.go:24

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

Source: types/v2.go:38

func GetAsset() string

Source: types/v2.go:37

func GetExtra() map[string]interface{}

Source: types/v2.go:41

func GetMaxTimeoutSeconds() int

Source: types/v2.go:40

func GetNetwork() string

Source: types/v2.go:36

func GetPayTo() string

Source: types/v2.go:39

func GetScheme() string

Source: types/v2.go:35

PaymentRequirementsView interface implementation for V2

type PaymentRequirementsV1

Source: types/v1.go:23

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

Source: types/v1.go:41

func GetAsset() string

Source: types/v1.go:40

func GetExtra() map[string]interface{}

Source: types/v1.go:44

func GetMaxTimeoutSeconds() int

Source: types/v1.go:43

func GetNetwork() string

Source: types/v1.go:39

func GetPayTo() string

Source: types/v1.go:42

func GetScheme() string

Source: types/v1.go:38

PaymentRequirementsView interface implementation for V1

type RequirementsInfo

Source: types/raw.go:39

RequirementsInfo is minimal info extracted from requirements for routing

type RequirementsInfo struct {
	Scheme  string
	Network string
}
Fields
  • Scheme string
  • Network string

type ResourceInfo

Source: types/v2.go:57

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() string
  • EnrichDeclaration func(declaration interface{}, transportContext interface{}) interface{}

type SupportedKind

Source: types/v2.go:67

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

Source: types/v1.go:63

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

Source: types/v2.go:75

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

Source: types/v1.go:100

SupportedResponseV1 is the old supported response format (V1 only, no extensions)

type SupportedResponseV1 struct {
	Kinds []SupportedKindV1 `json:"kinds"`
}
Fields
  • Kinds []SupportedKindV1 `json:"kinds"`