@btx-tools/challenges-sdk 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +56 -13
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -156,17 +156,27 @@ For RPC mode at advertised latency (~1–4 seconds), point it at a **dedicated b
156
156
 
157
157
  ## Performance
158
158
 
159
- Pure-JS solver bench at production matmul shape (n=512, b=16, r=8) on M-series Mac / Node 22 (2026-05-21):
159
+ Pure-JS solver bench at production matmul shape (n=512, b=16, r=8) on M-series Mac arm64 (2026-05-22, 5-sample mean):
160
160
 
161
- | Statistic | Wall-clock per attempt |
162
- |---|---|
163
- | mean | **4.6 s** |
164
- | median | 4.6 s |
165
- | min / max | 4.6 / 4.7 s |
161
+ | Engine | Mean / attempt | vs Node 22 |
162
+ |---|---|---|
163
+ | **Node 22.20 / V8** | **4.6 s** | 1.0× (baseline) |
164
+ | Deno 2.7 / V8 | 4.2 s | 0.92× (slightly faster, within noise) |
165
+ | Bun 1.3 / JavaScriptCore | 9.8 s | **2. slower** |
166
+ | Firefox SpiderMonkey | untested | — |
167
+ | Safari JavaScriptCore | untested | — |
168
+
169
+ `mul` and the `dot` accumulator use `bigint` because the worst-case M31 product (`(2^31-1)^2 ≈ 2^62`) exceeds `Number`'s 2^53 precision. The `bigint`-bounded inner loop is the dominant cost. **Bun's JavaScriptCore engine is ~2× slower than V8 for `bigint`-heavy workloads** — if Bun is your runtime, factor that into your `target_solve_time_s` calibration.
170
+
171
+ Expected end-to-end solve time depends on challenge difficulty. At btxd's lowest service-challenge difficulty (`target_solve_time_s = min_solve_time_s = 0.001`), per-attempt success ≈ 1.3·10⁻³, so expected ≈ 770 attempts:
166
172
 
167
- `mul` and the `dot` accumulator use `bigint` because the worst-case M31 product (`(2^31-1)^2 ≈ 2^62`) exceeds `Number`'s 2^53 precision. The `bigint`-bounded inner loop is the dominant cost.
173
+ | Engine | Expected solve at floor difficulty |
174
+ |---|---|
175
+ | Node 22 / V8 | ~59 min |
176
+ | Deno 2.7 / V8 | ~54 min |
177
+ | Bun 1.3 / JSC | ~2.1 hr |
168
178
 
169
- Expected end-to-end solve time depends on challenge difficulty. At btxd's lowest service-challenge difficulty (`target_solve_time_s = min_solve_time_s = 0.001`), per-attempt success ≈ 1.3·10⁻³, so expected ≈ 770 attempts ≈ **1 hour** wall-clock. **Default difficulty is too slow for online browser use.** Workable today for:
179
+ **Default difficulty is too slow for online browser use.** Workable today for:
170
180
 
171
181
  - Server-side gating where you control difficulty (calibrate via `target_solve_time_s` for your target user wait)
172
182
  - Backend cron / batch jobs
@@ -177,10 +187,42 @@ Day 2.6 will add a WASM port of the matmul kernel + the `field.mul`/`field.dot`
177
187
  Reproduce the bench:
178
188
 
179
189
  ```bash
180
- npx tsx packages/core/tests/perf/solver-bench.ts 10 # 10 attempts
190
+ npx tsx packages/core/tests/perf/solver-bench.ts 10 # Node
191
+ deno run --allow-all --unstable-sloppy-imports tests/perf/solver-bench.ts 10 # Deno
192
+ bun tests/perf/solver-bench.ts 10 # Bun
193
+ ```
194
+
195
+ ## Drop-in middleware
196
+
197
+ For Express apps, install the companion package:
198
+
199
+ ```bash
200
+ npm install @btx-tools/middleware-express
201
+ ```
202
+
203
+ ```typescript
204
+ import express from 'express';
205
+ import { BtxChallengeClient } from '@btx-tools/challenges-sdk';
206
+ import { btxAdmission } from '@btx-tools/middleware-express';
207
+
208
+ const client = new BtxChallengeClient({ rpcUrl: '...', rpcAuth: { ... } });
209
+ const app = express();
210
+
211
+ app.post(
212
+ '/v1/generate',
213
+ btxAdmission({
214
+ client,
215
+ purpose: 'ai_inference_gate',
216
+ resource: (req) => `model:${req.body.model}|route:${req.path}`,
217
+ subject: (req) => `tenant:${req.body.tenant_id}`,
218
+ }),
219
+ (req, res) => res.json({ ok: true, generated: '...' }),
220
+ );
181
221
  ```
182
222
 
183
- > **Cross-engine note**: bench captured on **Node 22 / V8 / M-series Mac arm64** (2026-05-21). `bigint` performance varies significantly by JS engine — Bun, Deno, Firefox SpiderMonkey, Safari JavaScriptCore are untested. If you run the SDK in those environments, please file an issue with your `solver-bench.ts` output so we can track real-world numbers across engines.
223
+ That's it one line, your route is gated by a BTX service challenge. Full docs at [`@btx-tools/middleware-express`](https://www.npmjs.com/package/@btx-tools/middleware-express) or in the [package README](https://github.com/btx-tools/btx-challenges-sdk/tree/main/packages/middleware-express#readme).
224
+
225
+ Fastify + Hono adapters queued as `@btx-tools/middleware-fastify` + `@btx-tools/middleware-hono`.
184
226
 
185
227
  ## Roadmap
186
228
 
@@ -189,11 +231,12 @@ npx tsx packages/core/tests/perf/solver-bench.ts 10 # 10 attempts
189
231
  | ✅ | Day 1: RPC client + types + audit Wave A/B/C fixes |
190
232
  | ✅ | Day 2: Solver class with mode dispatch (RPC mode ships) |
191
233
  | ✅ | Day 2.5: Pure-JS MatMul solver port, cross-validated against btxd goldens |
234
+ | ✅ | Day 3 (partial): Express middleware → `@btx-tools/middleware-express@0.1.0` |
192
235
  | ⏳ | Day 2.6: WASM port of matmul kernel (perf) |
193
- | ⏳ | Day 3: Express / Fastify / Hono middleware (separate sub-packages) |
236
+ | ⏳ | Day 3 (rest): Fastify + Hono adapters (separate sub-packages) |
194
237
  | ⏳ | Day 4: Browser demo + Node examples |
195
- | ⏳ | Day 5-6: `@btx/mcp-gateway` companion package |
196
- | ⏳ | Day 7-8: Docs + npm publish |
238
+ | ⏳ | Day 5-6: `@btx-tools/mcp-gateway` companion package |
239
+ | ⏳ | Day 7-8: Docs + announce |
197
240
  | ⏳ | Day 9: Findings + handoff |
198
241
 
199
242
  ## Testing
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@btx-tools/challenges-sdk",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "TypeScript SDK for BTX service challenges — chain-anchored proof-of-work admission control for APIs, agent gateways, and form submissions",
5
5
  "author": "visitor-code <visitor@friction.market>",
6
6
  "license": "MIT",