feat(gateway): OpenAI-compatible custodial gateway

New multi-tenant gateway package: external developers point any OpenAI SDK at
the marketplace. Each API key is its own custodial buyer wallet (AES-256-GCM
sealed under GATEWAY_MASTER_KEY); every request posts an on-chain escrow from
that user's wallet.

- POST /openai/v1/chat/completions (one escrow/call, llm.text.generate.v1,
  buffered + pseudo-stream), chat sessions (one escrow/session, llm.chat.v1,
  real SSE), GET /openai/v1/models, /signup, /account, /account/withdraw.
- Settles by resolving the Submitted ref via the indexer + awaited Accept;
  state-aware reclaim sweeper + per-wallet auto-consolidation for collateral.
- Reuses the buyer Marketplace SDK via new buyer exports ./sdk; new shared
  buildWithdrawTx (custodial exit). Runs via tsx; Dockerfile + mainnet compose.

Design in docs/gateway.md. Typecheck passes for all packages; 20 vitest tests
pass. Not yet exercised against a live chain.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
david
2026-06-22 10:19:12 +02:00
parent 900b2259e0
commit 6de62b8cf0
41 changed files with 3165 additions and 0 deletions

40
pnpm-lock.yaml generated
View File

@@ -160,6 +160,46 @@ importers:
specifier: ^5.4.0
version: 5.4.21(@types/node@25.6.0)
gateway:
dependencies:
'@marketplace/buyer':
specifier: workspace:*
version: link:../buyer
'@marketplace/shared':
specifier: workspace:*
version: link:../packages/shared
'@noble/ed25519':
specifier: ^2.3.0
version: 2.3.0
'@noble/hashes':
specifier: ^1.8.0
version: 1.8.0
bech32:
specifier: ^2.0.0
version: 2.0.0
better-sqlite3:
specifier: ^11.9.1
version: 11.10.0
express:
specifier: ^4.21.2
version: 4.22.1
devDependencies:
'@types/better-sqlite3':
specifier: ^7.6.12
version: 7.6.13
'@types/express':
specifier: ^5.0.3
version: 5.0.6
supertest:
specifier: ^7.0.0
version: 7.2.2
tsx:
specifier: ^4.19.0
version: 4.21.0
typescript:
specifier: ^5.7.2
version: 5.9.3
indexer:
dependencies:
'@marketplace/shared':