@helm-protocol/ttt-mcp 0.4.2 → 0.4.4

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/dist/auth.js CHANGED
@@ -29,6 +29,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
29
29
  var auth_exports = {};
30
30
  __export(auth_exports, {
31
31
  FREE_TIER_LIMIT: () => FREE_TIER_LIMIT,
32
+ FREE_TIER_PER_MIN: () => FREE_TIER_PER_MIN,
32
33
  checkRateLimit: () => checkRateLimit,
33
34
  resolveApiKey: () => resolveApiKey
34
35
  });
@@ -37,6 +38,8 @@ var fs = __toESM(require("fs"));
37
38
  var path = __toESM(require("path"));
38
39
  var os = __toESM(require("os"));
39
40
  const FREE_TIER_LIMIT = parseInt(process.env.FREE_TIER_LIMIT ?? "100", 10);
41
+ const FREE_TIER_PER_MIN = parseInt(process.env.FREE_TIER_PER_MIN ?? "120", 10);
42
+ const perMinBuckets = /* @__PURE__ */ new Map();
40
43
  const USAGE_DIR = path.join(os.homedir(), ".ttt-mcp");
41
44
  const USAGE_FILE = path.join(USAGE_DIR, "usage.json");
42
45
  const buckets = /* @__PURE__ */ new Map();
@@ -81,6 +84,18 @@ function checkRateLimit(apiKey, clientIp) {
81
84
  writeUsageFile(entry2);
82
85
  return { allowed: true, remaining: FREE_TIER_LIMIT - entry2.count, tier: "free" };
83
86
  }
87
+ if (FREE_TIER_PER_MIN > 0) {
88
+ const mk = `ip:${clientIp}`;
89
+ let m = perMinBuckets.get(mk);
90
+ if (!m || now >= m.resetAt) {
91
+ m = { count: 0, resetAt: now + 6e4 };
92
+ perMinBuckets.set(mk, m);
93
+ }
94
+ m.count += 1;
95
+ if (m.count > FREE_TIER_PER_MIN) {
96
+ return { allowed: false, remaining: 0, tier: "free" };
97
+ }
98
+ }
84
99
  const bucketKey = `ip:${clientIp}`;
85
100
  let entry = buckets.get(bucketKey);
86
101
  if (!entry || now >= entry.resetAt) {
@@ -99,6 +114,7 @@ function resolveApiKey(headerValue) {
99
114
  // Annotate the CommonJS export names for ESM import in node:
100
115
  0 && (module.exports = {
101
116
  FREE_TIER_LIMIT,
117
+ FREE_TIER_PER_MIN,
102
118
  checkRateLimit,
103
119
  resolveApiKey
104
120
  });
package/dist/index.js CHANGED
@@ -105,7 +105,7 @@ function toolSuccess(result) {
105
105
  return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
106
106
  }
107
107
  function buildMcpServer() {
108
- const s = new import_mcp.McpServer({ name: "ttt-mcp", version: "0.4.2" });
108
+ const s = new import_mcp.McpServer({ name: "ttt-mcp", version: "0.4.4" });
109
109
  const registerTool = s.tool.bind(s);
110
110
  registerTool(
111
111
  "pot_generate",
@@ -304,12 +304,13 @@ async function main() {
304
304
  const requestHandler = async (req, res) => {
305
305
  if (req.method === "GET" && (req.url === "/health" || req.url === "/ping")) {
306
306
  res.writeHead(200, { "Content-Type": "application/json" });
307
- res.end(JSON.stringify({ status: "ok", server: "ttt-mcp", version: "0.4.2" }));
307
+ res.end(JSON.stringify({ status: "ok", server: "ttt-mcp", version: "0.4.4" }));
308
308
  return;
309
309
  }
310
310
  if (req.method === "POST") {
311
311
  const apiKey = (0, import_auth.resolveApiKey)(req.headers["x-api-key"]);
312
- const clientIp = req.headers["x-forwarded-for"]?.split(",")[0].trim() || req.socket.remoteAddress || "unknown";
312
+ const trustProxy = process.env.TTTPS_TRUST_PROXY === "1";
313
+ const clientIp = (trustProxy ? req.headers["x-forwarded-for"]?.split(",")[0].trim() : "") || req.socket.remoteAddress || "unknown";
313
314
  const rl = (0, import_auth.checkRateLimit)(apiKey, clientIp);
314
315
  if (!rl.allowed) {
315
316
  res.writeHead(429, {
package/dist/tools.js CHANGED
@@ -477,9 +477,9 @@ async function potVerifyV2Core(args) {
477
477
  return serialize({ verdict: "rejected", reason: "roughtime chain quorum unavailable" });
478
478
  }
479
479
  }
480
- const freshness = process.env.TTTPS_ENFORCE_FRESHNESS === "1" ? { nowTaiUs: BigInt(Date.now()) * 1000n, maxSkewUs: BigInt(process.env.TTTPS_MAX_SKEW_US ?? "60000000") } : args.nowTaiUs !== void 0 && args.maxSkewUs !== void 0 ? { nowTaiUs: BigInt(args.nowTaiUs), maxSkewUs: BigInt(args.maxSkewUs) } : void 0;
480
+ const freshness = process.env.TTTPS_ENFORCE_FRESHNESS !== "0" ? { nowTaiUs: BigInt(Date.now()) * 1000n, maxSkewUs: BigInt(process.env.TTTPS_MAX_SKEW_US ?? "60000000") } : args.nowTaiUs !== void 0 && args.maxSkewUs !== void 0 ? { nowTaiUs: BigInt(args.nowTaiUs), maxSkewUs: BigInt(args.maxSkewUs) } : void 0;
481
481
  const trustedIssuers = trustedKeyList("TTTPS_TRUSTED_ISSUERS");
482
- const pinSelfIssuer = process.env.TTTPS_PIN_SELF_ISSUER === "1";
482
+ const pinSelfIssuer = process.env.TTTPS_PIN_SELF_ISSUER !== "0";
483
483
  const candidates = trustedIssuers.length > 0 ? trustedIssuers : pinSelfIssuer ? [potSignerPublicKeyRawV08] : [args.issuerPubKey ? Buffer.from(args.issuerPubKey, "hex") : potSignerPublicKeyRawV08];
484
484
  let result = (0, import_pot_record_v2.verifyPotRecordV2)(record, candidates[0], freshness);
485
485
  for (let i = 1; i < candidates.length && result.verdict === "rejected" && result.reason === "issuer signature invalid"; i++) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@helm-protocol/ttt-mcp",
3
- "version": "0.4.2",
3
+ "version": "0.4.4",
4
4
  "description": "Proof-of-Time attestation — Ed25519-signed timestamps with multi-source corroboration and explicit error bounds. IETF draft-helmprotocol-tttps",
5
5
  "main": "dist/index.js",
6
6
  "bin": {