Felix FaerberandClaude Opus 4.7 fcf184b016 gateway: persistent PSS key + retry resolveSelfOverlay
Two bugs that together blackholed every reverse-PSS message from the
provider when the api ran more than one replica:

1) `pssKeys = generatePssKeypair()` ran per-container, so each replica
   had a different ECIES identity. Provider encrypts its reply to ONE
   of those keys, only that replica can decrypt — so two replicas =
   ~50% of chats hang forever.

2) `resolveSelfOverlay` swallowed errors and returned 0x00…00 when
   Bee wasn't ready yet at boot. That zeroed overlay landed in the
   gateway context AND in the job_notify envelope sent to the provider
   — provider then sent PSS replies into the void.

Fix: load PSS key from PSS_KEY_PATH (shared volume across replicas);
retry getNodeAddresses up to 5 minutes and throw if still zero.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-28 11:49:54 +03:00
2026-05-20 15:08:45 +03:00
2026-05-20 15:08:45 +03:00
2026-05-20 15:08:45 +03:00
2026-05-20 15:08:45 +03:00
2026-05-20 15:08:45 +03:00
2026-05-20 15:08:45 +03:00
2026-05-20 15:08:45 +03:00
2026-05-20 15:08:45 +03:00
2026-05-20 15:08:45 +03:00
2026-05-20 15:08:45 +03:00
2026-05-20 15:08:45 +03:00
2026-05-20 15:08:45 +03:00

Hosted T4T Gateway

Multi-tenant frontend for the Token4Token inference network. Users sign up with Google / email, get 50 free virtual xBZZ, and call OpenAI-compatible endpoints without touching a wallet, Bee node, or Gnosis RPC.

Custody model: one operator wallet handles all on-chain transactions and Swarm operations. Tenants are off-chain ledger entries denominated in xBZZ. Providers see one on-chain client address (the operator's), not per-tenant addresses.

See docs in t4t/ for the wider design context.

Stack

  • Bun + Elysia (HTTP)
  • viem (Gnosis Chain bindings) — shared with t4t-container
  • bee-js (Swarm) — shared with t4t-container
  • Prisma + Postgres (multi-tenant ledger)
  • BullMQ + Redis (queues + distributed locks + operator-wallet nonce)

The gateway engine code (provider selection, chain I/O, PSS routing, ECIES envelope) is vendored from t4t/container/src/ into src/t4t/. See src/t4t/VENDORED.md for the drift policy.

Quick start

cp .env.example .env
# fill in OPERATOR_PRIVATE_KEY, REGISTRY/ESCROW/XBZZ addresses, JWT_SECRET_KEY

docker compose up -d postgres redis bee
bun install
bunx prisma migrate deploy
bun run dev:api
# in another shell:
bun run dev:worker

Layout

src/
  api.ts               # Elysia HTTP entry
  worker.ts            # BullMQ workers + claim watcher
  db.ts                # model.<entity> CUD wrappers (write + enqueue)
  env.ts               # zod-validated process.env
  auth/                # JWT, Google OAuth, email signup
  users/, accounts/, apiKeys/, pricing/, gateway/, chain/
  queue/               # connection, registry, lock, processor base, service
  t4t/                 # VENDORED from t4t-container
prisma/schema.prisma
test/                  # E2E specs
S
Description
No description provided
Readme
161 KiB
0 Stars 1 Watchers 0 Forks
Languages
TypeScript 99.7%
Dockerfile 0.3%