Skip to content

Feature: add @x402/elysia adapter#2

Open
ctibo wants to merge 2 commits into
GoPlausible:mainfrom
supeer-io:feat/http-elysia
Open

Feature: add @x402/elysia adapter#2
ctibo wants to merge 2 commits into
GoPlausible:mainfrom
supeer-io:feat/http-elysia

Conversation

@ctibo
Copy link
Copy Markdown

@ctibo ctibo commented Apr 22, 2026

Summary

  • Adds a new @x402/elysia package under typescript/packages/http/elysia/, providing an Elysia framework adapter for the x402 payment protocol.
  • Mirrors the @x402/hono API surface and package shape (same scripts, tooling, exports, and test patterns).
  • No changes to existing packages or workspace configuration.

What's included

File Purpose
src/adapter.ts ElysiaAdapter implementing HTTPAdapter from @x402/core
src/middleware.ts paymentMiddleware, paymentMiddlewareFromHTTPServer, paymentMiddlewareFromConfig
src/settlement-headers.ts setSettlementOverrides helper + header utilities
src/response-buffer.ts Converts Elysia handler return values to Buffer for settlement
src/index.ts Public API re-exports
src/adapter.test.ts 21 vitest tests for ElysiaAdapter
src/index.test.ts 17 vitest tests for middleware behaviours

Key design decisions

  • Hook scoping: hooks are registered with { as: 'global' } — required in Elysia 1.x so the plugin guards routes added to the parent app after .use(). Without this, hooks are scoped locally to the plugin only.
  • Settlement overrides header: SETTLEMENT_OVERRIDES_HEADER is declared locally (not imported from @x402/core) because it is not yet exported from core. A comment notes where to switch once upstream exports it.
  • responseHeaders in transport context: passed for parity with x402-foundation/express v2.9.0. Cast through as unknown as HTTPTransportContext until @x402/core's type is updated to include the field.
  • Return types: exported factory functions infer their Elysia plugin return type rather than annotating Elysia explicitly — avoids TypeScript errors caused by the .state() call widening the store type.

Changeset

.changeset/elysia-adapter-initial.md declares a minor bump for @x402/elysia.

Test plan

  • pnpm --filter @x402/elysia build — ESM + CJS + DTS all succeed
  • pnpm --filter @x402/elysia test — 38/38 vitest tests pass
  • pnpm --filter @x402/elysia lint:check — ESLint clean
  • pnpm --filter @x402/elysia format:check — Prettier clean

New package `@x402/elysia` providing an Elysia plugin for the x402
payment protocol. Mirrors the `@x402/hono` API surface:

- `paymentMiddleware` – Elysia plugin guarding routes with x402 checks
- `paymentMiddlewareFromHTTPServer` – lower-level variant
- `paymentMiddlewareFromConfig` – convenience variant
- `ElysiaAdapter` – HTTPAdapter implementation wrapping Elysia Context
- `setSettlementOverrides` – helper for per-request settlement overrides

Hooks are registered with `{ as: 'global' }` so the plugin guards routes
added to the parent app (required for Elysia 1.x plugin scoping).

38 vitest tests, build (ESM + CJS + DTS), lint, and format all pass.

Made-with: Cursor
- Document setSettlementOverrides / SETTLEMENT_OVERRIDES_HEADER /
  SettlementOverrides as forward-compat shims (no-op in this fork's
  @x402/core today); noted in settlement-headers.ts, middleware.ts,
  README, CHANGELOG, and changeset
- Narrow peerDependencies.elysia from ^1.0.0 to ^1.2.0 to reflect
  the minimum version where { as: 'global' } scoping and .state()
  typing are reliable
- Add Supeer Labs to contributors in package.json

Made-with: Cursor
@ctibo
Copy link
Copy Markdown
Author

ctibo commented Apr 22, 2026

Additional precisions added in this commit:

Settlement overrides — forward-compat shim

setSettlementOverrides, SETTLEMENT_OVERRIDES_HEADER, and SettlementOverrides are forward-compat shims for parity with x402-foundation/express v2.9.0. This fork's @x402/core does not yet consume the Settlement-Overrides header nor responseHeaders on HTTPTransportContext, so these helpers are currently no-ops. The API surface is stable and will activate automatically when core adopts the upstream field. This is now documented at the file level in settlement-headers.ts, in the inline comment around the transport context cast in middleware.ts, in the README, the changelog, and the changeset.

Peer dep narrowed to ^1.2.0

peerDependencies.elysia is set to ^1.2.0 to reflect the minimum version where { as: "global" } hook scoping and .state() typing are reliable. Noted in the README above the installation section.

Contributors

Added Supeer Labs to the contributors array in package.json.

@ctibo ctibo changed the title feat(http): add @x402/elysia adapter Feature: add @x402/elysia adapter Apr 22, 2026
@emg110
Copy link
Copy Markdown

emg110 commented May 3, 2026

Hey @ctibo , as per our discussions on meeting, we take this in and go for adding it as new customized x402 tolling packages that are useful to all chains and serve ALgorand as well but do not exist on Coinbase.
Thank you very much , this is awesome. I may ask to send this same PR to another branch. Will be in touch on Slack.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants