Skip to content

Migrate x402 payment rail to the official OKX Payment SDK - #17

Merged
edycutjong merged 1 commit into
mainfrom
fix/official-okx-payment-sdk
Aug 2, 2026
Merged

Migrate x402 payment rail to the official OKX Payment SDK#17
edycutjong merged 1 commit into
mainfrom
fix/official-okx-payment-sdk

Conversation

@edycutjong

Copy link
Copy Markdown
Owner

Why

CLV Scout was delisted from OKX.AI β€” reason: "your service is not integrated with the official OKX Payment SDK, which prevents us from completing verification." The rail hand-rolled the x402 wire protocol with viem + express instead of the published @okxweb3/x402-* packages.

The live endpoint confirms this: POST /api/grade still returns the old hand-rolled challenge (error:"payment_required"), not the SDK's.

What

Replace the hand-rolled rail with the official SDK, mirroring the sibling EdgeLedger build that passed review:

  • deps: @okxweb3/x402-express, @okxweb3/x402-core, @okxweb3/x402-evm
  • api/rails/okx.ts: okxPayGate() = SDK paymentMiddleware over x402ResourceServer + server-side ExactEvmScheme + OKXFacilitatorClient; per-route pricing (grade $0.01, audit $0.20); warmFacilitator() boot check
  • api/rails/localFacilitator.ts (new): drop-in FacilitatorClient for no-cred mode β€” real EIP-712/EIP-3009 recovery, honest pending/local: settlement
  • api/server.ts: force Accept: application/json, mirror X-PAYMENT↔PAYMENT-SIGNATURE and PAYMENT-RESPONSEβ†’X-PAYMENT-RESPONSE, mirror challenge into 402 body; method-less gating so GET probes return 402
  • api/main.ts: boot warm-up Β· routes.ts: recover payer from the payment header (SDK doesn't attach req.x402)
  • tests + docs updated to the SDK integration

Verified

  • npm run ci green β€” lint + typecheck + 130/130 tests, 99.5% coverage
  • Live local round-trip via scripts/buyer.ts: 402 β†’ EIP-3009 sign β†’ SDK verify β†’ settle β†’ HTTP 200 on both routes

Deploy note

Set OKX_API_KEY / OKX_SECRET_KEY / OKX_PASSPHRASE in Railway env so production settles via the real OKXFacilitatorClient. Then resubmit the OKX.AI listing.

CLV Scout was delisted from OKX.AI because its payment rail hand-rolled the
x402 wire protocol instead of using the official SDK, so the marketplace could
not verify it. Replace the hand-rolled rail with the published packages β€”
mirroring the sibling EdgeLedger build that passed review.

- deps: add @okxweb3/x402-express, @okxweb3/x402-core, @okxweb3/x402-evm
- api/rails/okx.ts: okxPayGate() is now the SDK paymentMiddleware over an
  x402ResourceServer + server-side ExactEvmScheme + OKXFacilitatorClient;
  per-route pricing (grade $0.01, audit $0.20); warmFacilitator() boot check
- api/rails/localFacilitator.ts (new): drop-in FacilitatorClient for no-cred
  mode β€” real EIP-712/EIP-3009 recovery, honest pending/local: settlement
- api/server.ts: force Accept: application/json, mirror X-PAYMENT ->
  PAYMENT-SIGNATURE and PAYMENT-RESPONSE -> X-PAYMENT-RESPONSE, mirror the
  challenge into the 402 body; method-less gating so GET probes return 402
- api/main.ts: boot-time facilitator warm-up; routes.ts: recover payer from
  the payment header (SDK does not attach req.x402)
- tests + docs updated to the SDK integration

Verified: npm run ci green (lint + typecheck + 130/130 tests, 99.5% coverage);
live server round-trip via scripts/buyer.ts returns HTTP 200 on both routes.
@edycutjong
edycutjong merged commit 9080154 into main Aug 2, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant