Raxol.Payments.Req.Mandate (Raxol Payments v0.2.0)

Copy Markdown View Source

Req plugin that attaches a Xochi delegation envelope to outbound requests bound for Xochi endpoints.

The plugin maps the request path to a Mandate scope (/api/intent/quote -> "quote", /api/intent/execute -> "execute", /api/stealth/claim -> "stealth_claim"), looks up the soonest-expiring active Mandate for the agent in Raxol.Payments.Mandate.Store via Raxol.Payments.Mandate.Check, and sets X-Xochi-Delegation to the base64url envelope.

Requests to non-Xochi hosts pass through unchanged. Requests to unrecognized Xochi paths pass through unchanged. Missing/expired mandates pass through with no header -- the upstream will respond 401/402 and the caller can decide how to handle it.

Usage

Req.new(url: "https://api.xochi.fi/api/intent/quote")
|> Raxol.Payments.Req.Mandate.attach(
  agent_wallet: "0xabc...",
  # optional overrides
  hosts: ["xochi.fi", "api.xochi.fi"]
)
|> Req.post(json: quote_body)

Options

  • :agent_wallet (required) -- the agent address whose mandates should be considered.
  • :hosts -- list of host suffixes treated as Xochi. Default: ["xochi.fi", "api.xochi.fi"]. Suffix match, so staging.xochi.fi works.
  • :path_scopes -- map of path prefix to scope. Default: %{"/api/intent/quote" => "quote", "/api/intent/execute" => "execute", "/api/stealth/claim" => "stealth_claim"}.

The Mandate Store is a singleton (Raxol.Payments.Mandate.Store); start exactly one per node.

Summary

Functions

Attach the Mandate plugin to a Req request.

Functions

attach(req, opts)

@spec attach(
  Req.Request.t(),
  keyword()
) :: Req.Request.t()

Attach the Mandate plugin to a Req request.

Adds a request step that presents the delegation envelope, and a response step that prunes a revoked/exhausted mandate on a 410 Gone from Xochi.