@helm-protocol/ttt-mcp 0.4.1 → 0.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/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.1" });
108
+ const s = new import_mcp.McpServer({ name: "ttt-mcp", version: "0.4.3" });
109
109
  const registerTool = s.tool.bind(s);
110
110
  registerTool(
111
111
  "pot_generate",
@@ -304,7 +304,7 @@ 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.1" }));
307
+ res.end(JSON.stringify({ status: "ok", server: "ttt-mcp", version: "0.4.3" }));
308
308
  return;
309
309
  }
310
310
  if (req.method === "POST") {
package/dist/tools.js CHANGED
@@ -445,20 +445,23 @@ function trustedKeyList(envName) {
445
445
  return (process.env[envName] ?? "").split(",").map((s) => s.trim()).filter((s) => /^[0-9a-fA-F]{64}$/.test(s)).map((h) => Buffer.from(h, "hex"));
446
446
  }
447
447
  let roughtimeAdmitCache = null;
448
- async function roughtimeQuorumOk() {
448
+ async function roughtimeChainStatus() {
449
449
  const url = process.env.TTTPS_ADMISSION_STATUS_URL ?? "https://api.kenosian.com/pot/status";
450
450
  const ttlMs = Number.parseInt(process.env.TTTPS_ADMISSION_TTL_MS ?? "5000", 10);
451
- if (roughtimeAdmitCache && Date.now() - roughtimeAdmitCache.at < ttlMs) return roughtimeAdmitCache.ok;
451
+ if (roughtimeAdmitCache && Date.now() - roughtimeAdmitCache.at < ttlMs) {
452
+ return { ok: roughtimeAdmitCache.ok, digest: roughtimeAdmitCache.digest };
453
+ }
452
454
  try {
453
455
  const timeoutMs = Number.parseInt(process.env.TTTPS_ADMISSION_TIMEOUT_MS ?? "1500", 10);
454
456
  const res = await fetch(url, { signal: AbortSignal.timeout(timeoutMs) });
455
457
  const j = await res.json();
456
- const ok = j?.roughtime_ok === true;
457
- roughtimeAdmitCache = { ok, at: Date.now() };
458
- return ok;
458
+ const ok = j?.chain_valid === true || j?.chain_valid === void 0 && j?.roughtime_ok === true;
459
+ const digest = typeof j?.d_chain_digest === "string" ? j.d_chain_digest : "";
460
+ roughtimeAdmitCache = { ok, digest, at: Date.now() };
461
+ return { ok, digest };
459
462
  } catch {
460
- roughtimeAdmitCache = { ok: false, at: Date.now() };
461
- return false;
463
+ roughtimeAdmitCache = { ok: false, digest: "", at: Date.now() };
464
+ return { ok: false, digest: "" };
462
465
  }
463
466
  }
464
467
  async function potVerifyV2Core(args) {
@@ -469,13 +472,14 @@ async function potVerifyV2Core(args) {
469
472
  }
470
473
  const record = Buffer.from(args.potRecordV2, "hex");
471
474
  if (process.env.TTTPS_REQUIRE_ROUGHTIME_QUORUM === "1") {
472
- if (!await roughtimeQuorumOk()) {
473
- return serialize({ verdict: "rejected", reason: "roughtime quorum unavailable" });
475
+ const chain = await roughtimeChainStatus();
476
+ if (!chain.ok) {
477
+ return serialize({ verdict: "rejected", reason: "roughtime chain quorum unavailable" });
474
478
  }
475
479
  }
476
- 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;
477
481
  const trustedIssuers = trustedKeyList("TTTPS_TRUSTED_ISSUERS");
478
- const pinSelfIssuer = process.env.TTTPS_PIN_SELF_ISSUER === "1";
482
+ const pinSelfIssuer = process.env.TTTPS_PIN_SELF_ISSUER !== "0";
479
483
  const candidates = trustedIssuers.length > 0 ? trustedIssuers : pinSelfIssuer ? [potSignerPublicKeyRawV08] : [args.issuerPubKey ? Buffer.from(args.issuerPubKey, "hex") : potSignerPublicKeyRawV08];
480
484
  let result = (0, import_pot_record_v2.verifyPotRecordV2)(record, candidates[0], freshness);
481
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.1",
3
+ "version": "0.4.3",
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": {