wolverine-ai 5.4.2 → 5.4.3

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wolverine-ai",
3
- "version": "5.4.2",
3
+ "version": "5.4.3",
4
4
  "description": "Self-healing Node.js server framework powered by AI. Catches crashes, diagnoses errors, generates fixes, verifies, and restarts — automatically.",
5
5
  "main": "src/index.js",
6
6
  "bin": {
@@ -22,6 +22,9 @@ if (clusterEnabled && cluster.isPrimary && workerCount > 1) {
22
22
  // Single worker or cluster worker — run the server
23
23
  const fastify = require("fastify")({ logger: false });
24
24
 
25
+ // x402 payment middleware (auto-detects vault, no-op if no vault)
26
+ try { fastify.register(require("wolverine-ai/src/middleware/x402-fastify")); } catch {}
27
+
25
28
  // Routes
26
29
  fastify.register(require("./routes/health"), { prefix: "/health" });
27
30
  fastify.register(require("./routes/api"), { prefix: "/api" });
@@ -1,26 +1,25 @@
1
1
  /**
2
- * Demo API routes — shows both free endpoints and x402 paid APIs.
2
+ * Demo API routes — free endpoints and x402 paid APIs.
3
3
  *
4
- * Wolverine's vault provides an encrypted Ethereum wallet (AES-256-GCM)
5
- * for each server instance. The wallet is used as the payment receiver
6
- * for x402 paid APIs on the Base network (USDC).
4
+ * x402 Setup (one-time):
5
+ * 1. wolverine --init-vault Create encrypted wallet
6
+ * 2. Set CDP_API_KEY_ID + CDP_API_KEY_SECRET in .env.local
7
+ * (free at https://cdp.coinbase.com)
8
+ * 3. Add { config: { x402: { price: "$0.01" } } } to any route
7
9
  *
8
- * Vault commands:
9
- * wolverine --init-vault Create encrypted wallet
10
- * wolverine --x402-info Show wallet address & config
10
+ * That's it — the route now requires USDC payment on Base.
11
+ * The middleware handles 402 responses, wallet signing, facilitator
12
+ * verification, and on-chain settlement automatically.
11
13
  *
12
- * The vault is stored in .wolverine/vault/ and is:
13
- * - Auto-backed up in every server snapshot
14
- * - Protected from agent access (sandbox-blocked)
15
- * - Private keys never exist as JS strings (Buffer only)
16
- * - Rollback-protected (never overwritten by restore)
17
- *
18
- * Dashboard: localhost:3001 — view wallet balances, x402 revenue,
19
- * payment history, and all server health metrics in real time.
14
+ * Protocol: https://docs.cdp.coinbase.com/x402/welcome
15
+ * Network: Base mainnet USDC payments
16
+ * Wallet: Auto-detected from vault
17
+ * Node: 22+ required
20
18
  */
21
19
 
22
20
  async function routes(fastify) {
23
- // ── Free endpoints ──
21
+ // ── Free endpoints (no x402 config = no payment required) ──
22
+
24
23
  fastify.get("/", async () => ({ message: "Hello from Wolverine API" }));
25
24
 
26
25
  fastify.get("/users", async () => ({
@@ -30,29 +29,19 @@ async function routes(fastify) {
30
29
  ],
31
30
  }));
32
31
 
33
- // ── x402 Paid API ──────────────────────────────────────────────
34
- // Any route becomes a paid API by adding x402 config.
35
- // Callers without a valid USDC payment get a 402 with payment instructions.
36
- // Callers with a valid Payment-Signature header get the response.
37
- //
38
- // Protocol: https://docs.cdp.coinbase.com/x402/welcome
39
- // Network: Base (eip155:8453) — USDC payments
40
- // Wallet: Auto-detected from vault (wolverine --init-vault)
41
- //
42
- // To change pricing live without restart:
43
- // Update the price in config and the next request picks it up.
44
- // Or use the dashboard command: "change /api/premium price to $0.05"
45
-
46
- // Fixed price — charge $0.01 per call:
32
+ // ── Paid endpoint — fixed price ──
33
+ // Just add x402 config. Handler only runs after USDC settles on-chain.
47
34
  fastify.get("/premium", {
48
35
  config: { x402: { price: "$0.01", description: "Premium data endpoint" } },
49
36
  }, async (req) => ({
50
37
  data: "This response cost $0.01 in USDC on Base",
51
- paid: req.x402?.amount,
52
- from: req.x402?.from,
38
+ paid: req.x402.amount,
39
+ from: req.x402.from,
40
+ txHash: req.x402.txHash,
53
41
  }));
54
42
 
55
- // Variable pricecaller chooses amount (e.g. buying credits):
43
+ // ── Paid endpoint variable price ──
44
+ // Caller specifies amount in request body. Good for credit purchases.
56
45
  // POST /api/purchase { "dollars": "5.00" }
57
46
  fastify.post("/purchase", {
58
47
  config: {
@@ -65,9 +54,10 @@ async function routes(fastify) {
65
54
  },
66
55
  },
67
56
  }, async (req) => ({
68
- message: `Received ${req.x402?.amount} USDC payment`,
69
- from: req.x402?.from,
70
- receipt: req.x402?.receipt ? "valid" : "none",
57
+ message: `Received ${req.x402.amount} USDC payment`,
58
+ from: req.x402.from,
59
+ txHash: req.x402.txHash,
60
+ settled: req.x402.settled,
71
61
  }));
72
62
  }
73
63