Skip to content

Go API reference

Package path: github.com/ajbeach2/stoka-go

Types

type Env

String alias picking which stoka deployment to target.

ValueMeaning
stoka.Productionhttps://api.stoka.space on stellar:pubnet
stoka.Testnethttps://test.api.stoka.space on stellar:testnet

Env.BaseURL() returns the canonical origin.

type Options

FieldTypePurpose
EnvEnvDeployment picker. Default: Production.
BaseURLstringOverrides Env's URL. Used for forks / CI.
SecretstringStellar S… seed. Used to sign x402 payments.
SignerSignerCustom payment signer (HSM, remote, test stub). Wins over native.
HTTPClient*http.ClientTransport. Default: 60s-timeout stdlib client.
RPCURLstringSoroban RPC override. Required for pubnet.

type Signer

go
type Signer interface {
    SignPayment(ctx context.Context, pr x402.PaymentRequirements) (string, error)
}

Implementations must be safe for concurrent use. Return the base64 X-PAYMENT header value.

type Client

The main entry point. Construct with stoka.New(Options{…}). Clients are goroutine-safe. Methods:

MethodPurpose
StorePOST /v1/store — create a new blob. Paid.
UpdatePUT /v1/object/{key} — overwrite an existing blob. Paid.
RetrieveGET /v1/retrieve/{key} — fetch a blob. Paid.
DeleteDELETE /v1/object/{key} — free, wallet-signed (not yet wired).
WellKnownGET /.well-known/stoka.json — manifest + pricing. Free.
PublicKey()Return the G… address derived from Secret.
BaseURL()Return the HTTP origin in use.
Close()Release idle transport connections.

type StoreOptions

go
type StoreOptions struct {
    TTLSeconds int // 0 = server default (30 days)
}

type RetrieveOptions

go
type RetrieveOptions struct {
    OwnerHint string // "-" to skip the X-Stoka-Owner hint
}

type StoreResponse

go
type StoreResponse struct {
    OwnerPubkey   string          `json:"owner_pubkey"`
    Key           string          `json:"key"`
    ExpiresAt     time.Time       `json:"expires_at"`
    TTLSeconds    int             `json:"ttl_seconds"`
    ChargedAtomic int64           `json:"charged_atomic"`
    Raw           json.RawMessage `json:"-"`
}

Errors

type StokaError

Non-2xx the client cannot retry. .Status and .Body carry the server's response verbatim.

type PaymentRequired

Returned when the server responds 402 and the client cannot auto-pay (no signer, insufficient funds, unknown asset). .Requirements is the parsed accepts[0] entry.

Subpackages

github.com/ajbeach2/stoka-go/x402

Standalone x402 "exact" scheme signer for Stellar. Usable outside stoka if you're integrating x402 into your own service.

go
res, err := x402.BuildExactPayment(ctx, secret, x402.PaymentRequirements{
    Scheme:            "exact",
    Network:           "stellar:testnet",
    Asset:             "CBIE…",
    PayTo:             "GAA…",
    MaxAmountRequired: "1170",
    Extra:             map[string]any{"areFeesSponsored": true},
}, x402.Options{})

req.Header.Set("X-PAYMENT", res.XPayment)

MIT Licensed.