x402scan

package
v0.13.0-rc4 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package x402scan registers this stack's public origin in the x402scan.com discovery index (https://x402scan.com/discovery/spec). Registration is a SIWX-authenticated POST: the registry answers an unauthenticated request with a 402 carrying a Sign-In-With-X (EIP-4361 / SIWE) challenge, the client signs it EIP-191 with the agent wallet, and retries with the signed payload base64-encoded in the SIGN-IN-WITH-X header. x402scan then crawls the origin's /openapi.json, probes each advertised endpoint for a real x402 402 challenge, and indexes the ones that pass.

Index

Constants

View Source
const DefaultBaseURL = "https://x402scan.com"

DefaultBaseURL is the public x402scan registry.

Variables

View Source
var (
	// ErrNoDiscovery: the registry could not find a discovery document
	// (openapi.json / .well-known/x402) at the origin. HTTP 404.
	ErrNoDiscovery = errors.New("x402scan found no discovery document at the origin")
	// ErrNoValidResources: a discovery document was found but no advertised
	// endpoint passed the live x402 402 probe. HTTP 422.
	ErrNoValidResources = errors.New("x402scan found no valid paid resources at the origin")
)

Sentinel errors for the registry's two well-known rejection modes so the CLI can print targeted fix-it guidance.

Functions

func FormatSIWEMessage

func FormatSIWEMessage(info SIWXInfo, addr common.Address) string

FormatSIWEMessage renders the EIP-4361 message for a challenge and signer address. Layout follows the spec ABNF exactly — the server re-renders the same message from the payload fields, so any deviation (a missing blank line, a lowercase address) makes signature verification fail.

Types

type Client

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

Client talks to an x402scan-compatible registry.

func NewClient

func NewClient(baseURL string) *Client

NewClient returns a registry client. An empty baseURL selects the public x402scan.com instance.

func (*Client) RegisterOrigin

func (c *Client) RegisterOrigin(ctx context.Context, origin string, addr common.Address, signer MessageSigner) (*RegisterResult, error)

RegisterOrigin registers origin in the discovery index, authenticating as addr via signer. It performs the full SIWX handshake: unauthenticated POST -> 402 challenge -> EIP-191 sign -> authenticated retry.

type FailedResource

type FailedResource struct {
	URL    string `json:"url"`
	Error  string `json:"error"`
	Status int    `json:"status,omitempty"`
}

FailedResource describes one advertised endpoint that failed the registry's live probe.

type MessageSigner

type MessageSigner interface {
	SignMessage(ctx context.Context, addr common.Address, message string) (string, error)
}

MessageSigner signs a plain-text message EIP-191 style with the key held for addr. *erc8004.RemoteSigner satisfies this.

type RegisterResult

type RegisterResult struct {
	Success      bool             `json:"success"`
	Registered   int              `json:"registered"`
	SIWX         int              `json:"siwx"`
	Failed       int              `json:"failed"`
	Skipped      int              `json:"skipped"`
	Deprecated   int              `json:"deprecated"`
	Total        int              `json:"total"`
	Source       string           `json:"source"`
	FailedList   []FailedResource `json:"failedDetails,omitempty"`
	SIWXList     []SIWXResource   `json:"siwxDetails,omitempty"`
	ContactEmail string           `json:"contactEmail,omitempty"`
	Warning      string           `json:"warning,omitempty"`
}

RegisterResult is the registry's summary of a registration run.

type SIWXInfo

type SIWXInfo struct {
	Domain         string   `json:"domain"`
	URI            string   `json:"uri"`
	Version        string   `json:"version"`
	ChainID        string   `json:"chainId"` // CAIP-2, e.g. "eip155:8453"
	Type           string   `json:"type"`    // signature scheme, "eip191"
	Nonce          string   `json:"nonce"`
	IssuedAt       string   `json:"issuedAt"`
	ExpirationTime string   `json:"expirationTime,omitempty"`
	NotBefore      string   `json:"notBefore,omitempty"`
	RequestID      string   `json:"requestId,omitempty"`
	Statement      string   `json:"statement,omitempty"`
	Resources      []string `json:"resources,omitempty"`
}

SIWXInfo is the challenge issued by the registry under extensions["sign-in-with-x"].info in the 402 body. The signed payload echoes these fields verbatim (plus address and signature) — the server re-renders the SIWE message from them to verify the signature, so they must round-trip unmodified.

type SIWXResource

type SIWXResource struct {
	URL string `json:"url"`
}

SIWXResource is an identity-only (wallet-gated, unpaid) endpoint.

Jump to

Keyboard shortcuts

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