Documentation
¶
Overview ¶
Package castar is a client for Castar wallet verification + attestation. Use ModeAPIKey for the business path (an API key, no crypto payment) or ModeX402 to pay per request with the x402 protocol. The x402 handshake, EIP-3009 payment signature, and wallet challenge are handled for you.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrConfig = &Error{Code: "config_error"} ErrMaxSpendExceeded = &Error{Code: "max_spend_exceeded"} ErrUnsupportedNetwork = &Error{Code: "unsupported_network"} ErrUserRejectedSigning = &Error{Code: "user_rejected_signing"} ErrBackend = &Error{Code: "backend_error"} ErrPaymentInvalid = &Error{Code: "payment_invalid"} ErrSettlementFailed = &Error{Code: "settlement_failed"} ErrChallengeInvalid = &Error{Code: "challenge_invalid"} ErrWalletMismatch = &Error{Code: "wallet_mismatch"} ErrPaymentExpired = &Error{Code: "payment_expired"} )
Sentinels for errors.Is matching.
Functions ¶
This section is empty.
Types ¶
type Attestation ¶
type ChallengeSigner ¶
type ChallengeSigner interface {
Address() string
SignMessage(ctx context.Context, message string) (signature string, err error)
}
ChallengeSigner signs the wallet-ownership challenge for the wallet being verified. For EVM, the signature is hex; for Solana, base58 ed25519.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func (*Client) Quote ¶
func (c *Client) Quote(ctx context.Context) (*PaymentRequirements, error)
Quote returns the payment requirements without paying (x402 mode).
func (*Client) Verify ¶
func (c *Client) Verify(ctx context.Context, p VerifyParams) (*VerificationResult, error)
Verify is the one-liner: check the wallet and return the attestation.
type EIP712Domain ¶
EIP712Domain for the EIP-3009 TransferWithAuthorization signature.
type Error ¶
type Error struct {
Code string
Message string
Status int // HTTP status for backend errors, 0 otherwise
}
Error is the single error type returned by the SDK. Match on Code with errors.Is(err, castar.ErrMaxSpendExceeded) or inspect the fields directly.
type Options ¶
type Options struct {
BaseURL string
Mode Mode
// apiKey mode
APIKey string
// x402 mode
Payer PaymentSigner
SubjectSigner ChallengeSigner // optional; defaults to Payer if it can sign messages and is the wallet
MaxSpend string // atomic units; "" = no cap
AllowedNetworks []string // e.g. []string{"eip155:57073"}; nil = any
HTTPClient *http.Client
OnPaymentRequired func(PaymentRequirements)
}
Options configure a Client. Build it with New.
type PaymentRequirements ¶
type PaymentRequirements struct {
Scheme string `json:"scheme"`
Network string `json:"network"`
Amount string `json:"amount"`
Asset string `json:"asset"`
PayTo string `json:"payTo"`
Resource string `json:"resource"`
MaxTimeoutSeconds int `json:"maxTimeoutSeconds"`
Description string `json:"description"`
Extra struct {
Name string `json:"name"`
Version string `json:"version"`
AssetTransferMethod string `json:"assetTransferMethod"`
} `json:"extra"`
}
PaymentRequirements is the exact-scheme requirement returned in the 402.
type PaymentSigner ¶
type PaymentSigner interface {
Address() string
SignTransferWithAuthorization(ctx context.Context, auth TransferAuthorization, domain EIP712Domain) (signatureHex string, err error)
}
PaymentSigner signs the x402 payment. Implement it with go-ethereum (see the README); the SDK does not pull in a crypto dependency itself.
type TransferAuthorization ¶
type TransferAuthorization struct {
From string
To string
Value string
ValidAfter string
ValidBefore string
Nonce string
}
TransferAuthorization is the EIP-3009 message the payer signs.
type VerificationResult ¶
type VerificationResult struct {
Eligible bool
BalanceAt string
Attestation *Attestation
PaymentID string // x402 only
SettlementTx string // x402 only
}
VerificationResult is what Verify returns.