@btx-tools SDK — BTX service-challenge admission control
    Preparing search index...
    • Build an Express RequestHandler that gates downstream handlers behind a BTX service challenge.

      Parameters

      Returns RequestHandler

      import express from 'express';
      import { BtxChallengeClient } from '@btx-tools/challenges-sdk';
      import { btxAdmission } from '@btx-tools/middleware-express';

      const client = new BtxChallengeClient({
      rpcUrl: 'http://127.0.0.1:19334',
      rpcAuth: { user: 'rpcuser', pass: 'rpcpass' },
      });

      const app = express();
      app.use(express.json());

      app.post('/v1/generate',
      btxAdmission({
      client,
      purpose: 'ai_inference_gate',
      resource: (req) => `model:${req.body.model}|route:${req.path}`,
      subject: (req) => `tenant:${req.body.tenant_id}`,
      issueParams: { target_solve_time_s: 1.0, expires_in_s: 60 },
      }),
      async (req, res) => {
      // req.btx?.result is populated with the redeem VerifyResult
      res.json({ ok: true, generated: '...' });
      },
      );