crypto-quant-signal-mcp 1.24.1 → 1.25.0
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/README.md +14 -12
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +253 -68
- package/dist/index.js.map +1 -1
- package/dist/lib/account-handlers.d.ts.map +1 -1
- package/dist/lib/account-handlers.js +30 -0
- package/dist/lib/account-handlers.js.map +1 -1
- package/dist/lib/adapters/aster.d.ts.map +1 -1
- package/dist/lib/adapters/aster.js +7 -1
- package/dist/lib/adapters/aster.js.map +1 -1
- package/dist/lib/adapters/gateio.d.ts.map +1 -1
- package/dist/lib/adapters/gateio.js +3 -0
- package/dist/lib/adapters/gateio.js.map +1 -1
- package/dist/lib/adapters/kucoin.d.ts.map +1 -1
- package/dist/lib/adapters/kucoin.js +4 -0
- package/dist/lib/adapters/kucoin.js.map +1 -1
- package/dist/lib/adapters/okx.d.ts +8 -0
- package/dist/lib/adapters/okx.d.ts.map +1 -1
- package/dist/lib/adapters/okx.js +42 -4
- package/dist/lib/adapters/okx.js.map +1 -1
- package/dist/lib/admin-auth.d.ts +62 -0
- package/dist/lib/admin-auth.d.ts.map +1 -0
- package/dist/lib/admin-auth.js +67 -0
- package/dist/lib/admin-auth.js.map +1 -0
- package/dist/lib/agent-activity-format.d.ts +20 -3
- package/dist/lib/agent-activity-format.d.ts.map +1 -1
- package/dist/lib/agent-activity-format.js +44 -5
- package/dist/lib/agent-activity-format.js.map +1 -1
- package/dist/lib/analytics.d.ts +30 -0
- package/dist/lib/analytics.d.ts.map +1 -1
- package/dist/lib/analytics.js +192 -7
- package/dist/lib/analytics.js.map +1 -1
- package/dist/lib/builder-code-constants.d.ts +42 -0
- package/dist/lib/builder-code-constants.d.ts.map +1 -0
- package/dist/lib/builder-code-constants.js +97 -0
- package/dist/lib/builder-code-constants.js.map +1 -0
- package/dist/lib/call-class.d.ts +107 -0
- package/dist/lib/call-class.d.ts.map +1 -0
- package/dist/lib/call-class.js +159 -0
- package/dist/lib/call-class.js.map +1 -0
- package/dist/lib/candle-basis-flag.d.ts +35 -0
- package/dist/lib/candle-basis-flag.d.ts.map +1 -0
- package/dist/lib/candle-basis-flag.js +23 -0
- package/dist/lib/candle-basis-flag.js.map +1 -0
- package/dist/lib/candle-basis-shadow.d.ts +88 -0
- package/dist/lib/candle-basis-shadow.d.ts.map +1 -0
- package/dist/lib/candle-basis-shadow.js +179 -0
- package/dist/lib/candle-basis-shadow.js.map +1 -0
- package/dist/lib/candle-window.d.ts +58 -0
- package/dist/lib/candle-window.d.ts.map +1 -0
- package/dist/lib/candle-window.js +78 -0
- package/dist/lib/candle-window.js.map +1 -0
- package/dist/lib/chat-rate-limit.d.ts +57 -0
- package/dist/lib/chat-rate-limit.d.ts.map +1 -1
- package/dist/lib/chat-rate-limit.js +73 -0
- package/dist/lib/chat-rate-limit.js.map +1 -1
- package/dist/lib/circle-gateway.d.ts +8 -2
- package/dist/lib/circle-gateway.d.ts.map +1 -1
- package/dist/lib/circle-gateway.js +81 -10
- package/dist/lib/circle-gateway.js.map +1 -1
- package/dist/lib/client-ip.d.ts +13 -4
- package/dist/lib/client-ip.d.ts.map +1 -1
- package/dist/lib/client-ip.js +13 -4
- package/dist/lib/client-ip.js.map +1 -1
- package/dist/lib/client-registry.d.ts +85 -0
- package/dist/lib/client-registry.d.ts.map +1 -0
- package/dist/lib/client-registry.js +150 -0
- package/dist/lib/client-registry.js.map +1 -0
- package/dist/lib/deferred-signup.d.ts +1 -1
- package/dist/lib/deferred-signup.d.ts.map +1 -1
- package/dist/lib/deferred-signup.js +22 -7
- package/dist/lib/deferred-signup.js.map +1 -1
- package/dist/lib/email.d.ts +40 -0
- package/dist/lib/email.d.ts.map +1 -1
- package/dist/lib/email.js +124 -0
- package/dist/lib/email.js.map +1 -1
- package/dist/lib/equities/equity-tool-formatters.d.ts.map +1 -1
- package/dist/lib/equities/equity-tool-formatters.js +12 -4
- package/dist/lib/equities/equity-tool-formatters.js.map +1 -1
- package/dist/lib/errors.d.ts +45 -1
- package/dist/lib/errors.d.ts.map +1 -1
- package/dist/lib/errors.js +79 -11
- package/dist/lib/errors.js.map +1 -1
- package/dist/lib/exchange-universe.d.ts +17 -0
- package/dist/lib/exchange-universe.d.ts.map +1 -1
- package/dist/lib/exchange-universe.js +21 -0
- package/dist/lib/exchange-universe.js.map +1 -1
- package/dist/lib/forum-post-content.d.ts +37 -2
- package/dist/lib/forum-post-content.d.ts.map +1 -1
- package/dist/lib/forum-post-content.js +26 -31
- package/dist/lib/forum-post-content.js.map +1 -1
- package/dist/lib/forum-post-gate.d.ts +102 -0
- package/dist/lib/forum-post-gate.d.ts.map +1 -0
- package/dist/lib/forum-post-gate.js +172 -0
- package/dist/lib/forum-post-gate.js.map +1 -0
- package/dist/lib/free-keys-store.d.ts +16 -2
- package/dist/lib/free-keys-store.d.ts.map +1 -1
- package/dist/lib/free-keys-store.js +68 -3
- package/dist/lib/free-keys-store.js.map +1 -1
- package/dist/lib/funnel-dashboard-html.js +1 -1
- package/dist/lib/funnel-dashboard-html.js.map +1 -1
- package/dist/lib/funnel-scoreboard.d.ts.map +1 -1
- package/dist/lib/funnel-scoreboard.js.map +1 -1
- package/dist/lib/license.d.ts +28 -1
- package/dist/lib/license.d.ts.map +1 -1
- package/dist/lib/license.js +49 -14
- package/dist/lib/license.js.map +1 -1
- package/dist/lib/log-redact.d.ts +25 -0
- package/dist/lib/log-redact.d.ts.map +1 -0
- package/dist/lib/log-redact.js +134 -0
- package/dist/lib/log-redact.js.map +1 -0
- package/dist/lib/market-insight-post.d.ts +37 -0
- package/dist/lib/market-insight-post.d.ts.map +1 -0
- package/dist/lib/market-insight-post.js +78 -0
- package/dist/lib/market-insight-post.js.map +1 -0
- package/dist/lib/nudge-copy.d.ts +1 -18
- package/dist/lib/nudge-copy.d.ts.map +1 -1
- package/dist/lib/nudge-copy.js +9 -26
- package/dist/lib/nudge-copy.js.map +1 -1
- package/dist/lib/okx-a2mcp.d.ts.map +1 -1
- package/dist/lib/okx-a2mcp.js +50 -37
- package/dist/lib/okx-a2mcp.js.map +1 -1
- package/dist/lib/performance-db.d.ts +20 -0
- package/dist/lib/performance-db.d.ts.map +1 -1
- package/dist/lib/performance-db.js +99 -14
- package/dist/lib/performance-db.js.map +1 -1
- package/dist/lib/plans.d.ts +55 -0
- package/dist/lib/plans.d.ts.map +1 -0
- package/dist/lib/plans.js +65 -0
- package/dist/lib/plans.js.map +1 -0
- package/dist/lib/pql.d.ts.map +1 -1
- package/dist/lib/pql.js +7 -1
- package/dist/lib/pql.js.map +1 -1
- package/dist/lib/quota-notice.d.ts +96 -0
- package/dist/lib/quota-notice.d.ts.map +1 -0
- package/dist/lib/quota-notice.js +208 -0
- package/dist/lib/quota-notice.js.map +1 -0
- package/dist/lib/referral-pages.d.ts +0 -1
- package/dist/lib/referral-pages.d.ts.map +1 -1
- package/dist/lib/referral-pages.js +5 -2
- package/dist/lib/referral-pages.js.map +1 -1
- package/dist/lib/referral-payout.d.ts +19 -5
- package/dist/lib/referral-payout.d.ts.map +1 -1
- package/dist/lib/referral-payout.js +58 -11
- package/dist/lib/referral-payout.js.map +1 -1
- package/dist/lib/referral-store.d.ts +28 -0
- package/dist/lib/referral-store.d.ts.map +1 -1
- package/dist/lib/referral-store.js +71 -0
- package/dist/lib/referral-store.js.map +1 -1
- package/dist/lib/scan-digest.d.ts +40 -0
- package/dist/lib/scan-digest.d.ts.map +1 -1
- package/dist/lib/scan-digest.js +52 -1
- package/dist/lib/scan-digest.js.map +1 -1
- package/dist/lib/signup-emails-store.js +14 -11
- package/dist/lib/signup-emails-store.js.map +1 -1
- package/dist/lib/signup-flow.d.ts.map +1 -1
- package/dist/lib/signup-flow.js +15 -9
- package/dist/lib/signup-flow.js.map +1 -1
- package/dist/lib/stripe-events-store.d.ts.map +1 -1
- package/dist/lib/stripe-events-store.js +32 -22
- package/dist/lib/stripe-events-store.js.map +1 -1
- package/dist/lib/stripe.d.ts +9 -0
- package/dist/lib/stripe.d.ts.map +1 -1
- package/dist/lib/stripe.js +13 -1
- package/dist/lib/stripe.js.map +1 -1
- package/dist/lib/subscriber-notify.d.ts +112 -0
- package/dist/lib/subscriber-notify.d.ts.map +1 -0
- package/dist/lib/subscriber-notify.js +282 -0
- package/dist/lib/subscriber-notify.js.map +1 -0
- package/dist/lib/telegram.d.ts +14 -0
- package/dist/lib/telegram.d.ts.map +1 -1
- package/dist/lib/telegram.js +47 -13
- package/dist/lib/telegram.js.map +1 -1
- package/dist/lib/tier-warning.d.ts +26 -0
- package/dist/lib/tier-warning.d.ts.map +1 -1
- package/dist/lib/tier-warning.js +39 -0
- package/dist/lib/tier-warning.js.map +1 -1
- package/dist/lib/track-token.d.ts +5 -2
- package/dist/lib/track-token.d.ts.map +1 -1
- package/dist/lib/track-token.js.map +1 -1
- package/dist/lib/trade-call-scanner.d.ts +6 -6
- package/dist/lib/trade-call-scanner.d.ts.map +1 -1
- package/dist/lib/trade-call-scanner.js +61 -0
- package/dist/lib/trade-call-scanner.js.map +1 -1
- package/dist/lib/tradfi-funding.d.ts +4 -1
- package/dist/lib/tradfi-funding.d.ts.map +1 -1
- package/dist/lib/tradfi-funding.js +4 -1
- package/dist/lib/tradfi-funding.js.map +1 -1
- package/dist/lib/traffic-classifier.d.ts.map +1 -1
- package/dist/lib/traffic-classifier.js +49 -19
- package/dist/lib/traffic-classifier.js.map +1 -1
- package/dist/lib/webhook-api.d.ts.map +1 -1
- package/dist/lib/webhook-api.js +8 -0
- package/dist/lib/webhook-api.js.map +1 -1
- package/dist/lib/webhook-delivery.d.ts +11 -3
- package/dist/lib/webhook-delivery.d.ts.map +1 -1
- package/dist/lib/webhook-delivery.js +112 -5
- package/dist/lib/webhook-delivery.js.map +1 -1
- package/dist/lib/webhook-quarantine-policy.d.ts +49 -0
- package/dist/lib/webhook-quarantine-policy.d.ts.map +1 -0
- package/dist/lib/webhook-quarantine-policy.js +94 -0
- package/dist/lib/webhook-quarantine-policy.js.map +1 -0
- package/dist/lib/webhooks-store.d.ts +0 -1
- package/dist/lib/webhooks-store.d.ts.map +1 -1
- package/dist/lib/webhooks-store.js +0 -1
- package/dist/lib/webhooks-store.js.map +1 -1
- package/dist/lib/welcome-page.d.ts.map +1 -1
- package/dist/lib/welcome-page.js +2 -1
- package/dist/lib/welcome-page.js.map +1 -1
- package/dist/lib/x402-http-routes.d.ts +65 -1
- package/dist/lib/x402-http-routes.d.ts.map +1 -1
- package/dist/lib/x402-http-routes.js +119 -6
- package/dist/lib/x402-http-routes.js.map +1 -1
- package/dist/lib/x402.d.ts.map +1 -1
- package/dist/lib/x402.js +70 -24
- package/dist/lib/x402.js.map +1 -1
- package/dist/scripts/agent-forum-post.js +383 -60
- package/dist/scripts/agent-forum-post.js.map +1 -1
- package/dist/scripts/candle-basis-measure.d.ts +202 -0
- package/dist/scripts/candle-basis-measure.d.ts.map +1 -0
- package/dist/scripts/candle-basis-measure.js +453 -0
- package/dist/scripts/candle-basis-measure.js.map +1 -0
- package/dist/scripts/geo-weekly-cron.js +25 -10
- package/dist/scripts/geo-weekly-cron.js.map +1 -1
- package/dist/scripts/monitor.js +9 -2
- package/dist/scripts/monitor.js.map +1 -1
- package/dist/scripts/nightly-carry-labeler.d.ts +2 -0
- package/dist/scripts/nightly-carry-labeler.d.ts.map +1 -1
- package/dist/scripts/nightly-carry-labeler.js +24 -3
- package/dist/scripts/nightly-carry-labeler.js.map +1 -1
- package/dist/scripts/publish-merkle-batch.js +23 -1
- package/dist/scripts/publish-merkle-batch.js.map +1 -1
- package/dist/scripts/rate-limit-digest-weekly.js +7 -5
- package/dist/scripts/rate-limit-digest-weekly.js.map +1 -1
- package/dist/scripts/register-erc8004-agent.js +7 -4
- package/dist/scripts/register-erc8004-agent.js.map +1 -1
- package/dist/scripts/seed-shadow-venues-w3a.js +7 -4
- package/dist/scripts/seed-shadow-venues-w3a.js.map +1 -1
- package/dist/scripts/seed-shadow-venues-w3b.js +7 -4
- package/dist/scripts/seed-shadow-venues-w3b.js.map +1 -1
- package/dist/tool-descriptions.d.ts +1 -0
- package/dist/tool-descriptions.d.ts.map +1 -1
- package/dist/tool-descriptions.js +6 -1
- package/dist/tool-descriptions.js.map +1 -1
- package/dist/tools/get-market-regime.d.ts +60 -1
- package/dist/tools/get-market-regime.d.ts.map +1 -1
- package/dist/tools/get-market-regime.js +267 -101
- package/dist/tools/get-market-regime.js.map +1 -1
- package/dist/tools/get-trade-call.d.ts +45 -1
- package/dist/tools/get-trade-call.d.ts.map +1 -1
- package/dist/tools/get-trade-call.js +281 -125
- package/dist/tools/get-trade-call.js.map +1 -1
- package/dist/tools/scan-funding-arb.d.ts.map +1 -1
- package/dist/tools/scan-funding-arb.js +44 -9
- package/dist/tools/scan-funding-arb.js.map +1 -1
- package/dist/tools/scan-trade-calls.d.ts +17 -1
- package/dist/tools/scan-trade-calls.d.ts.map +1 -1
- package/dist/tools/scan-trade-calls.js +51 -7
- package/dist/tools/scan-trade-calls.js.map +1 -1
- package/dist/types.d.ts +43 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +10 -9
- package/server.json +2 -2
package/README.md
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
</p>
|
|
12
12
|
|
|
13
13
|
<p align="center">
|
|
14
|
-
<span data-tr-field="pfe_wr">91.
|
|
14
|
+
<span data-tr-field="pfe_wr">91.7%</span> PFE win rate across <span data-tr-field="total_calls">435,841</span>+ verified calls. Merkle-verified on Base L2. Don't trust — verify. <!-- SNAPSHOT-LINE -->
|
|
15
15
|
</p>
|
|
16
16
|
|
|
17
17
|
<p align="center">
|
|
@@ -112,7 +112,7 @@ The `_algovault` block makes outputs composable: downstream risk and backtest to
|
|
|
112
112
|
scripts/snapshot-landing-data.mjs at npm-publish + Hetzner-deploy. Do NOT hand-edit the
|
|
113
113
|
numbers; edit "What's new" by hand. Wired by OPS-NPM-README-SINGLE-SOT-W1 (2026-05-31). -->
|
|
114
114
|
<p align="center">
|
|
115
|
-
<strong><span data-tr-field="pfe_wr">91.
|
|
115
|
+
<strong><span data-tr-field="pfe_wr">91.7%</span> PFE Win Rate</strong> · <strong><span data-tr-field="total_calls">435,841</span> trade calls</strong> · <strong><span data-tr-field="merkle_batches">114</span> on-chain batches</strong> · <strong><span data-tr-field="hold_rate">99.2%</span> HOLD rate</strong> <!-- SNAPSHOT-LINE -->
|
|
116
116
|
</p>
|
|
117
117
|
|
|
118
118
|
<p align="center">
|
|
@@ -234,7 +234,7 @@ Quota-only tiers. Every tier gets all venues, all assets, all timeframes — you
|
|
|
234
234
|
| Feature | Free | Starter ($9.99/mo) | Pro ($49/mo) | Enterprise ($299/mo) | x402 (per call) |
|
|
235
235
|
|---------|------|-------------------|-------------|---------------------|-----------------|
|
|
236
236
|
| Exchanges | All 15 | All 15 | All 15 | All 15 | All 15 | <!-- SNAPSHOT-LINE-TABLE -->
|
|
237
|
-
| Assets | All
|
|
237
|
+
| Assets | All 1490+ | All 1490+ | All 1490+ | All 1490+ | All 1490+ | <!-- SNAPSHOT-LINE-TABLE -->
|
|
238
238
|
| Asset classes | Crypto + TradFi | Crypto + TradFi | Crypto + TradFi | Crypto + TradFi | Crypto + TradFi |
|
|
239
239
|
| Timeframes | All 11 | All 11 | All 11 | All 11 | All 11 |
|
|
240
240
|
| Funding arb results | Top 5 | Unlimited | Unlimited | Unlimited | Unlimited |
|
|
@@ -252,12 +252,19 @@ Quota-only tiers. Every tier gets all venues, all assets, all timeframes — you
|
|
|
252
252
|
|
|
253
253
|
---
|
|
254
254
|
|
|
255
|
-
## What's new in v1.
|
|
255
|
+
## What's new in v1.25.0
|
|
256
256
|
|
|
257
|
-
-
|
|
258
|
-
-
|
|
257
|
+
- **🎯 Screen the scan universe by liquidity.** `scan_trade_calls` now takes an optional `minLiquidityUsd` floor — filter to names with real depth, by notional open interest or 24h volume. Omit it for no floor.
|
|
258
|
+
- **💳 Charge-correctness on the paid path.** A paid request whose body was dropped could return a defaults-only result. Every payable route now rejects a dropped body, and a rejected request explains why.
|
|
259
|
+
- **⛓️ Pay per call on a second rail.** x402 settlement now runs over Circle Gateway on Optimism alongside Base — point your agent at either advertised rail.
|
|
260
|
+
- **📊 Truer funding comparisons.** Funding rates annualize at each contract's own period, so cross-venue spreads compare like with like.
|
|
261
|
+
|
|
262
|
+
> New optional parameter — MCP clients cache `tools/list` at session start. Toggle the connector off/on (or restart the MCP connection) to see `minLiquidityUsd`.
|
|
259
263
|
|
|
260
|
-
|
|
264
|
+
### v1.24.0 highlights (recap)
|
|
265
|
+
|
|
266
|
+
- **🌐 Three new exchanges: WhiteBIT, BitMart, XT.** AlgoVault's signal engine spans more perpetual-futures venues. Point any tool at the new venues via the `exchange` parameter.
|
|
267
|
+
- **🔌 New venue integration pages.** Per-venue connect guides at [algovault.com/integrations](https://algovault.com/integrations).
|
|
261
268
|
|
|
262
269
|
### v1.23.1 highlights (recap)
|
|
263
270
|
|
|
@@ -270,11 +277,6 @@ Quota-only tiers. Every tier gets all venues, all assets, all timeframes — you
|
|
|
270
277
|
|
|
271
278
|
> MCP clients cache `tools/list` at session start — toggle the connector off/on (or restart the MCP connection) to pick up the updated `scan_funding_arb`.
|
|
272
279
|
|
|
273
|
-
### v1.22.0 highlights (recap)
|
|
274
|
-
|
|
275
|
-
- **🌐 <span data-tr-field="exchange_count">12</span> exchanges live.** **ASTER, BingX, Gate, HTX, KuCoin, MEXC, and Phemex** join Hyperliquid, Binance, Bybit, OKX, and Bitget on the verified, Merkle-anchored public track record — composite trade calls, market-regime detection, and the per-venue PFE leaderboard now span every promoted venue.
|
|
276
|
-
- **🏆 Per-venue leaderboard.** The live [track-record leaderboard](https://algovault.com/track-record) ranks per-venue PFE win rate across every venue — filter to any newly-added one.
|
|
277
|
-
- **🔁 Forward-stable coverage.** The venue count reads live everywhere it appears, so coverage stays accurate as we keep adding venues.
|
|
278
280
|
|
|
279
281
|
> **Refresh your MCP client to pick up this release.** MCP clients cache `tools/list` at session start — Claude.ai/Desktop: toggle the connector off+on; Cursor/Cline: restart the MCP server connection.
|
|
280
282
|
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAWA,OAAO,EAAE,SAAS,EAAuC,MAAM,yCAAyC,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAWA,OAAO,EAAE,SAAS,EAAuC,MAAM,yCAAyC,CAAC;AA+SzG;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,2BAA2B,CACzC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChC,MAAM,EAAE,MAAM,GACb,MAAM,CAOR;AAED;;;;;;;GAOG;AACH,wBAAsB,kBAAkB,CACtC,GAAG,EAAE,OAAO,SAAS,EAAE,OAAO,EAC9B,GAAG,EAAE,OAAO,SAAS,EAAE,QAAQ,EAC/B,UAAU,EAAE,MAAM,SAAS,GAC1B,OAAO,CAAC,IAAI,CAAC,CAYf;AAguID,wBAAgB,mBAAmB,cAElC"}
|
package/dist/index.js
CHANGED
|
@@ -60,6 +60,7 @@ const scan_trade_calls_js_1 = require("./tools/scan-trade-calls.js");
|
|
|
60
60
|
const signal_performance_js_1 = require("./resources/signal-performance.js");
|
|
61
61
|
const cross_asset_grid_js_1 = require("./lib/cross-asset-grid.js");
|
|
62
62
|
const footer_content_js_1 = require("./lib/footer-content.js");
|
|
63
|
+
const admin_auth_js_1 = require("./lib/admin-auth.js");
|
|
63
64
|
const performance_db_js_1 = require("./lib/performance-db.js");
|
|
64
65
|
const webhook_api_js_1 = require("./lib/webhook-api.js");
|
|
65
66
|
const venue_public_formatter_js_1 = require("./lib/venue-public-formatter.js");
|
|
@@ -280,11 +281,8 @@ function chatTierFor(licenseTier) {
|
|
|
280
281
|
// 'enterprise' | 'internal' | 'x402' | any other paid tier
|
|
281
282
|
return 'enterprise';
|
|
282
283
|
}
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
// traffic doesn't share a single global counter.
|
|
286
|
-
return licenseKey ?? `ip:${ipHash ?? 'unknown'}`;
|
|
287
|
-
}
|
|
284
|
+
// chatQuotaApiKey moved to src/lib/chat-rate-limit.ts by OPS-AUDIT-REMEDIATION-HIGH-W1 (SEC-03):
|
|
285
|
+
// index.ts boots the server at import, so a resolver defined here cannot be unit-tested.
|
|
288
286
|
/**
|
|
289
287
|
* OPS-MCP-SESSION-RESILIENCE-W1: single shared session-correlation resolver
|
|
290
288
|
* (single-derivation rule). Used by BOTH the funnel / skill-attribution emit AND
|
|
@@ -519,7 +517,14 @@ function createServer() {
|
|
|
519
517
|
try {
|
|
520
518
|
const license = (0, license_js_1.getRequestLicense)();
|
|
521
519
|
// Quota tracking is handled inside getMarketRegime
|
|
522
|
-
|
|
520
|
+
// OPS-QUOTA-EXHAUSTION-NOTICE-W1: forward the RESOLVED license. It was read on the line
|
|
521
|
+
// above and then used only for logRequest, so `getMarketRegime` fell back to its
|
|
522
|
+
// `{tier:'free', key:null}` default and metered every caller against the IP-derived free
|
|
523
|
+
// bucket instead of their own. Found live post-deploy: a keyed free caller whose key
|
|
524
|
+
// bucket read 100/100 was still SERVED by this tool (its IP bucket read 8/100), so the
|
|
525
|
+
// operator-frozen cutoff did not actually hold here — and a PAID caller's regime calls
|
|
526
|
+
// were metered, and would eventually be refused, against the free 100 cap.
|
|
527
|
+
const result = await (0, upstream_weight_budget_js_1.runAsCaller)('get_market_regime', () => (0, get_market_regime_js_1.getMarketRegime)({ coin, timeframe, exchange, license }));
|
|
523
528
|
(0, analytics_js_1.logRequest)({
|
|
524
529
|
sessionId: (0, license_js_1.getRequestSessionId)(),
|
|
525
530
|
toolName: 'get_market_regime',
|
|
@@ -605,11 +610,11 @@ function createServer() {
|
|
|
605
610
|
// ── Tool: scan_trade_calls (SCAN-TRADE-CALLS-W1) — cross-asset market scanner ──
|
|
606
611
|
// Thin handler: quota gate + envelope live in src/tools/scan-trade-calls.ts
|
|
607
612
|
// (runScanTradeCall); the scanner compute is src/lib/trade-call-scanner.ts.
|
|
608
|
-
register('scan_trade_calls', scan_trade_calls_js_1.SCAN_TRADE_CALLS_DESCRIPTION, scan_trade_calls_js_1.SCAN_TRADE_CALLS_SCHEMA, { title: 'Market Scanner', ...tool_annotations_js_1.PUBLIC_READONLY_TOOL_ANNOTATIONS }, async ({ topN, timeframe, exchange, minConfidence, includeHolds, limit, rankBy, includeReasoning, oiChangeWindow, oiBasis }) => {
|
|
613
|
+
register('scan_trade_calls', scan_trade_calls_js_1.SCAN_TRADE_CALLS_DESCRIPTION, scan_trade_calls_js_1.SCAN_TRADE_CALLS_SCHEMA, { title: 'Market Scanner', ...tool_annotations_js_1.PUBLIC_READONLY_TOOL_ANNOTATIONS }, async ({ topN, timeframe, exchange, minConfidence, includeHolds, limit, rankBy, includeReasoning, oiChangeWindow, oiBasis, minLiquidityUsd }) => {
|
|
609
614
|
const startMs = Date.now();
|
|
610
615
|
try {
|
|
611
616
|
const license = (0, license_js_1.getRequestLicense)();
|
|
612
|
-
const scan = () => (0, scan_trade_calls_js_1.runScanTradeCall)({ topN, timeframe, exchange, minConfidence, includeHolds, limit, rankBy, includeReasoning, oiChangeWindow, oiBasis }, license);
|
|
617
|
+
const scan = () => (0, scan_trade_calls_js_1.runScanTradeCall)({ topN, timeframe, exchange, minConfidence, includeHolds, limit, rankBy, includeReasoning, oiChangeWindow, oiBasis, minLiquidityUsd }, license);
|
|
613
618
|
// OPS-HL-INTERACTIVE-PRIORITY-W1: a background-priority caller (today: the bot's
|
|
614
619
|
// weekly scan-showcase cron) runs its venue fan-out in the BATCH lane, so it waits
|
|
615
620
|
// for capacity instead of consuming HL's interactive reserve. That reserve exists
|
|
@@ -711,10 +716,9 @@ function createServer() {
|
|
|
711
716
|
const license = (0, license_js_1.getRequestLicense)();
|
|
712
717
|
const { index, chatEngine, rateLimit, llm } = await getChatStack();
|
|
713
718
|
const tier = chatTierFor(license.tier);
|
|
714
|
-
const quotaKey = chatQuotaApiKey(license.key, (0, license_js_1.getRequestIpHash)() ?? null);
|
|
719
|
+
const quotaKey = (0, chat_rate_limit_js_1.chatQuotaApiKey)(license.key, (0, license_js_1.getRequestIpHash)() ?? null);
|
|
715
720
|
const check = await rateLimit.check(quotaKey, tier);
|
|
716
721
|
if (!check.allowed) {
|
|
717
|
-
const days = Math.max(1, Math.ceil((check.resetAt.getTime() - Date.now()) / (24 * 60 * 60 * 1000)));
|
|
718
722
|
// CHAT-USAGE-ANALYTICS-W1: quota-exhausted recorded as event (errorCode, cost=0)
|
|
719
723
|
(0, chat_analytics_js_1.recordChatEvent)({
|
|
720
724
|
apiKeyId: license.key,
|
|
@@ -729,14 +733,7 @@ function createServer() {
|
|
|
729
733
|
latencyMs: Date.now() - startMs,
|
|
730
734
|
errorCode: 'CHAT_QUOTA_EXHAUSTED',
|
|
731
735
|
});
|
|
732
|
-
const payload =
|
|
733
|
-
code: 'CHAT_QUOTA_EXHAUSTED',
|
|
734
|
-
message: `Monthly chat quota exhausted for tier ${tier} (${check.limit}/mo). Resets in ${days} day(s).`,
|
|
735
|
-
retry_after_days: days,
|
|
736
|
-
limit: check.limit,
|
|
737
|
-
tier,
|
|
738
|
-
upgrade_url: 'https://algovault.com/#pricing',
|
|
739
|
-
};
|
|
736
|
+
const payload = (0, chat_rate_limit_js_1.buildChatQuotaNotice)(tier, check);
|
|
740
737
|
return { content: [{ type: 'text', text: JSON.stringify(payload) }], isError: true };
|
|
741
738
|
}
|
|
742
739
|
const result = await (0, upstream_weight_budget_js_1.runAsCaller)('chat_knowledge', () => chatEngine.chat(question, { model }));
|
|
@@ -1023,6 +1020,28 @@ async function startHttp() {
|
|
|
1023
1020
|
return res.sendStatus(204);
|
|
1024
1021
|
next();
|
|
1025
1022
|
});
|
|
1023
|
+
// Security headers (OPS-AUDIT-REMEDIATION-CRITICAL-W1, SEC-38).
|
|
1024
|
+
// Covers api.algovault.com AND the apex pages Caddy reverse-proxies here
|
|
1025
|
+
// (/referral, /join, /track-record, /referral-terms). The apex STATIC pages
|
|
1026
|
+
// — /verify included — are served by Caddy's file_server and never reach
|
|
1027
|
+
// Express, so they carry the mirrored header set in the Caddyfile instead.
|
|
1028
|
+
// Keep the two in sync: a policy added here without the Caddy twin silently
|
|
1029
|
+
// leaves every static apex page uncovered, which is how SEC-01 stayed exposed.
|
|
1030
|
+
app.use((_req, res, next) => {
|
|
1031
|
+
res.setHeader('X-Content-Type-Options', 'nosniff');
|
|
1032
|
+
res.setHeader('X-Frame-Options', 'DENY');
|
|
1033
|
+
res.setHeader('Referrer-Policy', 'strict-origin-when-cross-origin');
|
|
1034
|
+
// 'unsafe-inline' mirrors the Caddy policy: the function-rendered pages emit
|
|
1035
|
+
// inline <script> hydration and inline style="" attributes.
|
|
1036
|
+
res.setHeader('Content-Security-Policy', "default-src 'self'; " +
|
|
1037
|
+
"script-src 'self' 'unsafe-inline' https://cdn.tailwindcss.com; " +
|
|
1038
|
+
"style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; " +
|
|
1039
|
+
"font-src 'self' https://fonts.gstatic.com data:; " +
|
|
1040
|
+
"img-src 'self' data: https:; " +
|
|
1041
|
+
"connect-src 'self' https://api.algovault.com https://plausible.algovault.com; " +
|
|
1042
|
+
"frame-ancestors 'none'; base-uri 'self'; form-action 'self'; object-src 'none'");
|
|
1043
|
+
next();
|
|
1044
|
+
});
|
|
1026
1045
|
// Rate limiting
|
|
1027
1046
|
app.use('/mcp', rateLimit({ windowMs: 60_000, max: 120, standardHeaders: true, legacyHeaders: false }));
|
|
1028
1047
|
app.use('/analytics', rateLimit({ windowMs: 60_000, max: 30, standardHeaders: true, legacyHeaders: false }));
|
|
@@ -1197,6 +1216,24 @@ async function startHttp() {
|
|
|
1197
1216
|
return res.status(400).json({ error: 'Stripe not configured' });
|
|
1198
1217
|
switch (event.type) {
|
|
1199
1218
|
case 'customer.subscription.created': {
|
|
1219
|
+
// Idempotency BEFORE side-effect (SEC-20, OPS-AUDIT-REMEDIATION-MEDIUM-W1 Ch2).
|
|
1220
|
+
// handleSubscriptionCreated MINTS AN API KEY, overwrites customer.metadata and
|
|
1221
|
+
// sends the welcome email. Stripe retries any non-2xx and can deliver at-least-
|
|
1222
|
+
// once, so without a claim a redelivery generated a SECOND key, silently
|
|
1223
|
+
// invalidating the one the paying customer had already installed, and emailed
|
|
1224
|
+
// them a different one. Same shape as checkout.session.completed below.
|
|
1225
|
+
const isNewSub = await (0, stripe_events_store_js_1.tryClaimEvent)({
|
|
1226
|
+
event_id: event.id,
|
|
1227
|
+
event_type: event.type,
|
|
1228
|
+
customer_email: null,
|
|
1229
|
+
metadata: { source: 'customer.subscription.created' },
|
|
1230
|
+
});
|
|
1231
|
+
if (!isNewSub) {
|
|
1232
|
+
console.log(`Stripe webhook: duplicate customer.subscription.created (event ${event.id}) — already processed`);
|
|
1233
|
+
// 200, never 500: a non-2xx makes Stripe retry harder against an event we
|
|
1234
|
+
// have already fully processed.
|
|
1235
|
+
return res.json({ received: true, status: 'duplicate' });
|
|
1236
|
+
}
|
|
1200
1237
|
const conv = await (0, stripe_js_1.handleSubscriptionCreated)(event);
|
|
1201
1238
|
// REFERRAL-LIGHT-W1 (C3): if this paid signup carried a ref code (stamped
|
|
1202
1239
|
// on the subscription by createCheckoutSession), attribute the conversion +
|
|
@@ -1685,16 +1722,94 @@ async function startHttp() {
|
|
|
1685
1722
|
}
|
|
1686
1723
|
return true;
|
|
1687
1724
|
}
|
|
1688
|
-
/**
|
|
1725
|
+
/**
|
|
1726
|
+
* Check admin auth: Bearer token or session cookie.
|
|
1727
|
+
*
|
|
1728
|
+
* SEC-10 (OPS-AUDIT-REMEDIATION-MEDIUM-W1 / Ch1): `req.query.key` was REMOVED as
|
|
1729
|
+
* an authorization source. A URL key may only BOOTSTRAP a session (see
|
|
1730
|
+
* `adminKeyBootstrap`); it can no longer authorize a request, so an admin URL
|
|
1731
|
+
* leaked into a ticket, screenshot or access log is not replayable. The
|
|
1732
|
+
* predicate itself lives in ./lib/admin-auth.ts — it takes no query input at
|
|
1733
|
+
* all, so URL-key auth cannot be reintroduced by a future caller.
|
|
1734
|
+
*/
|
|
1689
1735
|
function isAdminAuthorized(req) {
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1736
|
+
return (0, admin_auth_js_1.resolveAdminAuth)({ authorization: req.headers['authorization'], cookie: req.headers.cookie }, { adminKey, compare: safeCompare, isValidSession: isValidAdminSession }).authorized;
|
|
1737
|
+
}
|
|
1738
|
+
/**
|
|
1739
|
+
* The ONE sanctioned place a URL key is read: exchange `?key=` for an HttpOnly
|
|
1740
|
+
* session cookie and 303 to the clean path, so the credential never survives in
|
|
1741
|
+
* the address bar and never reaches a rendered page. Returns true if it handled
|
|
1742
|
+
* the response (caller must return immediately).
|
|
1743
|
+
*/
|
|
1744
|
+
function adminKeyBootstrap(req, res, cleanPath) {
|
|
1745
|
+
const key = typeof req.query.key === 'string' ? req.query.key : '';
|
|
1746
|
+
if (!key || !safeCompare(key, adminKey))
|
|
1747
|
+
return false;
|
|
1748
|
+
res.setHeader('Set-Cookie', (0, admin_auth_js_1.buildAdminSessionCookie)(createAdminSession(), {
|
|
1749
|
+
secure: req.secure,
|
|
1750
|
+
ttlMs: ADMIN_SESSION_TTL,
|
|
1751
|
+
}));
|
|
1752
|
+
// Strip ONLY `key`; every other param survives the redirect, so an operator
|
|
1753
|
+
// opening e.g. /admin/geo-dashboard?weeks=52&key=… still lands on weeks=52.
|
|
1754
|
+
const rest = new URLSearchParams();
|
|
1755
|
+
for (const [k, v] of Object.entries(req.query)) {
|
|
1756
|
+
if (k === 'key')
|
|
1757
|
+
continue;
|
|
1758
|
+
if (typeof v === 'string')
|
|
1759
|
+
rest.append(k, v);
|
|
1760
|
+
else if (Array.isArray(v))
|
|
1761
|
+
for (const item of v)
|
|
1762
|
+
if (typeof item === 'string')
|
|
1763
|
+
rest.append(k, item);
|
|
1764
|
+
}
|
|
1765
|
+
const qs = rest.toString();
|
|
1766
|
+
res.redirect(303, qs ? `${cleanPath}?${qs}` : cleanPath);
|
|
1767
|
+
return true;
|
|
1697
1768
|
}
|
|
1769
|
+
/**
|
|
1770
|
+
* OPS-SEC-CLIENT-IP-VERIFY-W1 — permanent client-IP echo (admin-gated).
|
|
1771
|
+
*
|
|
1772
|
+
* SEC-07 shipped a proxy-header change whose end-to-end effect could not be confirmed,
|
|
1773
|
+
* because it was INFERRED from `ipHash` values instead of read from the header. The follow-up
|
|
1774
|
+
* then nearly repeated the mistake from the other side: a Caddy access log reported
|
|
1775
|
+
* `Cf-Connecting-Ip` masked to /24 while `X-Forwarded-For` in the SAME log line was unmasked
|
|
1776
|
+
* — the signature of a log formatter, not of the wire value.
|
|
1777
|
+
*
|
|
1778
|
+
* So this route makes "what address does the app actually see?" a ONE-REQUEST question,
|
|
1779
|
+
* answered at the layer that consumes it with no log formatter in between. Admin-auth'd
|
|
1780
|
+
* (never an open info leak), and it echoes VALUES rather than hashes — hashing is precisely
|
|
1781
|
+
* what made the two previous attempts unfalsifiable.
|
|
1782
|
+
*/
|
|
1783
|
+
app.get('/debug/client-ip', (req, res) => {
|
|
1784
|
+
if (!isAdminAuthorized(req)) {
|
|
1785
|
+
return res.status(401).json({ error: 'Unauthorized' });
|
|
1786
|
+
}
|
|
1787
|
+
const raw = (n) => req.headers[n] ?? null;
|
|
1788
|
+
const resolved = (0, client_ip_js_1.clientIp)(req);
|
|
1789
|
+
res.setHeader('Cache-Control', 'no-store');
|
|
1790
|
+
return res.json({
|
|
1791
|
+
_note: 'OPS-SEC-CLIENT-IP-VERIFY-W1 — raw wire values as Express sees them. Admin-only.',
|
|
1792
|
+
headers: {
|
|
1793
|
+
'cf-connecting-ip': raw('cf-connecting-ip'),
|
|
1794
|
+
'x-forwarded-for': raw('x-forwarded-for'),
|
|
1795
|
+
'x-real-ip': raw('x-real-ip'),
|
|
1796
|
+
'true-client-ip': raw('true-client-ip'),
|
|
1797
|
+
'cf-ray': raw('cf-ray'),
|
|
1798
|
+
},
|
|
1799
|
+
express: {
|
|
1800
|
+
reqIp: req.ip ?? null,
|
|
1801
|
+
reqIps: req.ips ?? [], // parsed XFF chain, left→right
|
|
1802
|
+
socketRemote: req.socket?.remoteAddress ?? null,
|
|
1803
|
+
},
|
|
1804
|
+
derived: {
|
|
1805
|
+
clientIp: resolved,
|
|
1806
|
+
ipHash: (0, analytics_js_1.hashIp)(resolved || 'unknown'),
|
|
1807
|
+
// OPS-SEC-IPHASH-SALT-W1: surface the derivation version explicitly, so "which namespace
|
|
1808
|
+
// is this bucket in?" is answerable from the echo rather than by parsing the prefix.
|
|
1809
|
+
ipHashVersion: analytics_js_1.IP_HASH_VERSION,
|
|
1810
|
+
},
|
|
1811
|
+
});
|
|
1812
|
+
});
|
|
1698
1813
|
// JSON API
|
|
1699
1814
|
app.get('/analytics', async (req, res) => {
|
|
1700
1815
|
if (!isAdminAuthorized(req)) {
|
|
@@ -1710,15 +1825,10 @@ async function startHttp() {
|
|
|
1710
1825
|
});
|
|
1711
1826
|
// Visual dashboard — key in URL sets a session cookie, then redirects to clean URL
|
|
1712
1827
|
app.get('/dashboard', (req, res) => {
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
// Authenticate: set session cookie, redirect to clean URL
|
|
1716
|
-
const sessionToken = createAdminSession();
|
|
1717
|
-
res.setHeader('Set-Cookie', `${ADMIN_COOKIE_NAME}=${sessionToken}; HttpOnly; SameSite=Strict; Path=/; Max-Age=${ADMIN_SESSION_TTL / 1000}${req.secure ? '; Secure' : ''}`);
|
|
1718
|
-
return res.redirect(303, '/dashboard');
|
|
1719
|
-
}
|
|
1828
|
+
if (adminKeyBootstrap(req, res, '/dashboard'))
|
|
1829
|
+
return;
|
|
1720
1830
|
if (!isValidAdminSession(req.headers.cookie)) {
|
|
1721
|
-
return res.status(401).send(
|
|
1831
|
+
return res.status(401).send(admin_auth_js_1.ADMIN_UNAUTHORIZED_PAGE);
|
|
1722
1832
|
}
|
|
1723
1833
|
res.send(getDashboardHtml());
|
|
1724
1834
|
});
|
|
@@ -1802,8 +1912,10 @@ async function startHttp() {
|
|
|
1802
1912
|
// LLM-PROVIDER-A/B-W1 trigger status (≥100 queries/day × 7 consecutive
|
|
1803
1913
|
// days) and stub-provider banner alert (Cowork Q-4 Path B).
|
|
1804
1914
|
app.get('/admin/chat-analytics', async (req, res) => {
|
|
1915
|
+
if (adminKeyBootstrap(req, res, '/admin/chat-analytics'))
|
|
1916
|
+
return; // SEC-10
|
|
1805
1917
|
if (!isAdminAuthorized(req)) {
|
|
1806
|
-
return res.status(401).send(
|
|
1918
|
+
return res.status(401).send(admin_auth_js_1.ADMIN_UNAUTHORIZED_PAGE);
|
|
1807
1919
|
}
|
|
1808
1920
|
try {
|
|
1809
1921
|
const lookback = Math.max(1, Math.min(180, parseInt(String(req.query.days ?? '90'), 10) || 90));
|
|
@@ -1821,8 +1933,10 @@ async function startHttp() {
|
|
|
1821
1933
|
// LLMs recommend AlgoVault when asked about crypto trading agents. Mirrors
|
|
1822
1934
|
// chat-analytics auth pattern: inline isAdminAuthorized(req) check.
|
|
1823
1935
|
app.get('/admin/geo-dashboard', async (req, res) => {
|
|
1936
|
+
if (adminKeyBootstrap(req, res, '/admin/geo-dashboard'))
|
|
1937
|
+
return; // SEC-10
|
|
1824
1938
|
if (!isAdminAuthorized(req)) {
|
|
1825
|
-
return res.status(401).send(
|
|
1939
|
+
return res.status(401).send(admin_auth_js_1.ADMIN_UNAUTHORIZED_PAGE);
|
|
1826
1940
|
}
|
|
1827
1941
|
try {
|
|
1828
1942
|
const lookbackWeeks = Math.max(1, Math.min(52, parseInt(String(req.query.weeks ?? '12'), 10) || 12));
|
|
@@ -1838,14 +1952,10 @@ async function startHttp() {
|
|
|
1838
1952
|
});
|
|
1839
1953
|
// Signal performance dashboard (admin-only)
|
|
1840
1954
|
app.get('/performance-dashboard', (req, res) => {
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
const sessionToken = createAdminSession();
|
|
1844
|
-
res.setHeader('Set-Cookie', `${ADMIN_COOKIE_NAME}=${sessionToken}; HttpOnly; SameSite=Strict; Path=/; Max-Age=${ADMIN_SESSION_TTL / 1000}${req.secure ? '; Secure' : ''}`);
|
|
1845
|
-
return res.redirect(303, '/performance-dashboard');
|
|
1846
|
-
}
|
|
1955
|
+
if (adminKeyBootstrap(req, res, '/performance-dashboard'))
|
|
1956
|
+
return;
|
|
1847
1957
|
if (!isValidAdminSession(req.headers.cookie)) {
|
|
1848
|
-
return res.status(401).send(
|
|
1958
|
+
return res.status(401).send(admin_auth_js_1.ADMIN_UNAUTHORIZED_PAGE);
|
|
1849
1959
|
}
|
|
1850
1960
|
res.send(getPerformanceDashboardHtml());
|
|
1851
1961
|
});
|
|
@@ -1879,8 +1989,11 @@ async function startHttp() {
|
|
|
1879
1989
|
// REFERRAL-LIGHT-W1 (C4): referral admin surfaces — same isAdminAuthorized gate
|
|
1880
1990
|
// (Bearer / ?key= / admin cookie) as the precedents.
|
|
1881
1991
|
app.get('/admin/referrals', async (req, res) => {
|
|
1992
|
+
// SEC-10: `?key=` is exchanged for the session cookie and stripped from the URL.
|
|
1993
|
+
if (adminKeyBootstrap(req, res, '/admin/referrals'))
|
|
1994
|
+
return;
|
|
1882
1995
|
if (!isAdminAuthorized(req)) {
|
|
1883
|
-
return res.status(401).send(
|
|
1996
|
+
return res.status(401).send(admin_auth_js_1.ADMIN_UNAUTHORIZED_PAGE);
|
|
1884
1997
|
}
|
|
1885
1998
|
try {
|
|
1886
1999
|
const { topReferrers, listRecentLedger } = await import('./lib/referral-store.js');
|
|
@@ -1903,8 +2016,14 @@ async function startHttp() {
|
|
|
1903
2016
|
}
|
|
1904
2017
|
});
|
|
1905
2018
|
app.get('/admin/referrals/payouts', async (req, res) => {
|
|
2019
|
+
// SEC-10: `?key=` is exchanged for the session cookie and stripped from the URL,
|
|
2020
|
+
// so the credential authorizing the irreversible USDC send never persists in the
|
|
2021
|
+
// address bar, browser history, or an access log — and is never re-embedded in
|
|
2022
|
+
// the rendered form action below.
|
|
2023
|
+
if (adminKeyBootstrap(req, res, '/admin/referrals/payouts'))
|
|
2024
|
+
return;
|
|
1906
2025
|
if (!isAdminAuthorized(req)) {
|
|
1907
|
-
return res.status(401).send(
|
|
2026
|
+
return res.status(401).send(admin_auth_js_1.ADMIN_UNAUTHORIZED_PAGE);
|
|
1908
2027
|
}
|
|
1909
2028
|
try {
|
|
1910
2029
|
const { pendingPayouts } = await import('./lib/referral-store.js');
|
|
@@ -1916,7 +2035,6 @@ async function startHttp() {
|
|
|
1916
2035
|
res.send(renderAdminPayoutsPage({
|
|
1917
2036
|
pending: pending.map((p) => ({ code: p.code, ownerEmail: p.owner_email, payoutAddress: p.payout_address, pendingUsdE2: p.pending_usd_e2, rowCount: p.row_count, ledgerIds: p.ledger_ids })),
|
|
1918
2037
|
batchTotalUsdE2: pending.reduce((s, p) => s + p.pending_usd_e2, 0),
|
|
1919
|
-
adminKey: typeof req.query.key === 'string' ? req.query.key : undefined,
|
|
1920
2038
|
}));
|
|
1921
2039
|
}
|
|
1922
2040
|
catch (err) {
|
|
@@ -1928,8 +2046,11 @@ async function startHttp() {
|
|
|
1928
2046
|
// PayoutSender (C2 = Stub → reports not-configured; C3 = CDP server-wallet send),
|
|
1929
2047
|
// then re-render the (reduced) queue with a result flash. Operator-triggered only.
|
|
1930
2048
|
app.post('/admin/referrals/payouts/approve-all', async (req, res) => {
|
|
2049
|
+
// SEC-10: no bootstrap on a POST — this is authorized by the session cookie the
|
|
2050
|
+
// payouts page set (SameSite=Strict is still sent on a same-site form submit),
|
|
2051
|
+
// or by an explicit Bearer header. A key in the URL no longer authorizes it.
|
|
1931
2052
|
if (!isAdminAuthorized(req)) {
|
|
1932
|
-
return res.status(401).send(
|
|
2053
|
+
return res.status(401).send(admin_auth_js_1.ADMIN_UNAUTHORIZED_API);
|
|
1933
2054
|
}
|
|
1934
2055
|
try {
|
|
1935
2056
|
const { pendingPayouts } = await import('./lib/referral-store.js');
|
|
@@ -1946,7 +2067,6 @@ async function startHttp() {
|
|
|
1946
2067
|
res.send(renderAdminPayoutsPage({
|
|
1947
2068
|
pending: pending.map((p) => ({ code: p.code, ownerEmail: p.owner_email, payoutAddress: p.payout_address, pendingUsdE2: p.pending_usd_e2, rowCount: p.row_count, ledgerIds: p.ledger_ids })),
|
|
1948
2069
|
batchTotalUsdE2: pending.reduce((s, p) => s + p.pending_usd_e2, 0),
|
|
1949
|
-
adminKey: typeof req.query.key === 'string' ? req.query.key : undefined,
|
|
1950
2070
|
result: {
|
|
1951
2071
|
senderKind: result.senderKind,
|
|
1952
2072
|
paidCount: result.paid.length,
|
|
@@ -2066,14 +2186,10 @@ async function startHttp() {
|
|
|
2066
2186
|
// the session cookie then redirects). The served HTML embeds no data; it fetches
|
|
2067
2187
|
// the gated JSON above via a same-origin XHR carrying the admin cookie.
|
|
2068
2188
|
app.get('/dashboard/funnel', (req, res) => {
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
const sessionToken = createAdminSession();
|
|
2072
|
-
res.setHeader('Set-Cookie', `${ADMIN_COOKIE_NAME}=${sessionToken}; HttpOnly; SameSite=Strict; Path=/; Max-Age=${ADMIN_SESSION_TTL / 1000}${req.secure ? '; Secure' : ''}`);
|
|
2073
|
-
return res.redirect(303, '/dashboard/funnel');
|
|
2074
|
-
}
|
|
2189
|
+
if (adminKeyBootstrap(req, res, '/dashboard/funnel'))
|
|
2190
|
+
return;
|
|
2075
2191
|
if (!isValidAdminSession(req.headers.cookie)) {
|
|
2076
|
-
return res.status(401).send(
|
|
2192
|
+
return res.status(401).send(admin_auth_js_1.ADMIN_UNAUTHORIZED_PAGE);
|
|
2077
2193
|
}
|
|
2078
2194
|
res.setHeader('Cache-Control', 'no-store');
|
|
2079
2195
|
res.setHeader('Content-Type', 'text/html; charset=utf-8');
|
|
@@ -2628,7 +2744,16 @@ async function startHttp() {
|
|
|
2628
2744
|
// ALL new-signup routes are behind NEW_SIGNUP_ENABLED (default OFF → 404, invisible).
|
|
2629
2745
|
// The legacy email-first flow above stays intact. MCP/TG surfaces untouched.
|
|
2630
2746
|
// Value BEFORE email: mint an ephemeral key + return a real signal, no email required.
|
|
2631
|
-
|
|
2747
|
+
// OPS-AUDIT-REMEDIATION-HIGH-W1 (SEC-05): burst bound on an UNAUTHENTICATED credential-issuing
|
|
2748
|
+
// route. Same shape as signupEmailLimiter, tighter max — this one hands out API keys.
|
|
2749
|
+
const startFreeLimiter = rateLimit({
|
|
2750
|
+
windowMs: 60 * 60 * 1000,
|
|
2751
|
+
max: 5,
|
|
2752
|
+
standardHeaders: true,
|
|
2753
|
+
legacyHeaders: false,
|
|
2754
|
+
message: { ok: false, error: 'rate_limited' },
|
|
2755
|
+
});
|
|
2756
|
+
app.post('/api/start-free', startFreeLimiter, express.json({ limit: '2kb' }), async (req, res) => {
|
|
2632
2757
|
const { isNewSignupEnabled } = await import('./lib/auth-providers.js');
|
|
2633
2758
|
if (!isNewSignupEnabled())
|
|
2634
2759
|
return res.status(404).json({ ok: false, error: 'not_found' });
|
|
@@ -2643,11 +2768,19 @@ async function startHttp() {
|
|
|
2643
2768
|
utm_source: str(q.utm_source) ?? str(b.utm_source),
|
|
2644
2769
|
utm_campaign: str(q.utm_campaign) ?? str(b.utm_campaign),
|
|
2645
2770
|
landing_path: str(q.landing_path),
|
|
2771
|
+
// SEC-05: caller identity the ISSUANCE cap bounds on (the limiter above is the separate
|
|
2772
|
+
// burst bound). Was never passed, so mintEphemeralKey had nothing to bound against.
|
|
2773
|
+
ip_hash: (0, analytics_js_1.hashIp)((0, client_ip_js_1.clientIp)(req) || 'unknown'),
|
|
2774
|
+
user_agent: typeof req.headers['user-agent'] === 'string' ? req.headers['user-agent'].slice(0, 300) : null,
|
|
2646
2775
|
});
|
|
2647
2776
|
res.setHeader('Cache-Control', 'no-store');
|
|
2648
2777
|
return res.status(200).json({ ok: true, ...result });
|
|
2649
2778
|
}
|
|
2650
2779
|
catch (err) {
|
|
2780
|
+
if (err instanceof Error && err.code === 'EPHEMERAL_MINT_CAP') {
|
|
2781
|
+
res.setHeader('Cache-Control', 'no-store');
|
|
2782
|
+
return res.status(429).json({ ok: false, error: 'rate_limited' });
|
|
2783
|
+
}
|
|
2651
2784
|
console.error(`[/api/start-free] internal error: ${err instanceof Error ? err.message : err}`);
|
|
2652
2785
|
return res.status(500).json({ ok: false, error: 'internal_error' });
|
|
2653
2786
|
}
|
|
@@ -2782,16 +2915,22 @@ async function startHttp() {
|
|
|
2782
2915
|
model = body.model;
|
|
2783
2916
|
_analyticsModel = model;
|
|
2784
2917
|
}
|
|
2785
|
-
|
|
2918
|
+
// OPS-AUDIT-REMEDIATION-HIGH-W1 (SEC-03): resolve the caller FROM THE REQUEST.
|
|
2919
|
+
// getRequestLicense()/getRequestIpHash() read the AsyncLocalStorage store, which is only
|
|
2920
|
+
// entered for /mcp (see the note at the /signup handler) — so on this route they returned
|
|
2921
|
+
// the env fallback and `undefined`, collapsing every anonymous caller into one shared
|
|
2922
|
+
// `ip:unknown` quota bucket AND metering paying customers as free. Resolving here (the
|
|
2923
|
+
// same helpers /mcp uses) fixes the quota key and the tier together.
|
|
2924
|
+
const { license } = await (0, license_js_1.resolveLicense)(req.headers);
|
|
2925
|
+
const ipHash = (0, analytics_js_1.hashIp)((0, client_ip_js_1.clientIp)(req) || 'unknown');
|
|
2786
2926
|
const { index, chatEngine, rateLimit, llm } = await getChatStack();
|
|
2787
2927
|
_analyticsProvider = llm.name;
|
|
2788
2928
|
const tier = chatTierFor(license.tier);
|
|
2789
2929
|
_analyticsApiKey = license.key;
|
|
2790
2930
|
_analyticsTier = tier;
|
|
2791
|
-
const quotaKey =
|
|
2931
|
+
const quotaKey = (0, chat_rate_limit_js_1.chatQuotaApiKey)(license.key, ipHash);
|
|
2792
2932
|
const check = await rateLimit.check(quotaKey, tier);
|
|
2793
2933
|
if (!check.allowed) {
|
|
2794
|
-
const days = Math.max(1, Math.ceil((check.resetAt.getTime() - Date.now()) / (24 * 60 * 60 * 1000)));
|
|
2795
2934
|
// CHAT-USAGE-ANALYTICS-W1: quota-exhausted recorded as event
|
|
2796
2935
|
(0, chat_analytics_js_1.recordChatEvent)({
|
|
2797
2936
|
apiKeyId: _analyticsApiKey,
|
|
@@ -2806,14 +2945,7 @@ async function startHttp() {
|
|
|
2806
2945
|
latencyMs: Date.now() - startMs,
|
|
2807
2946
|
errorCode: 'CHAT_QUOTA_EXHAUSTED',
|
|
2808
2947
|
});
|
|
2809
|
-
return res.status(429).json(
|
|
2810
|
-
code: 'CHAT_QUOTA_EXHAUSTED',
|
|
2811
|
-
message: `Monthly chat quota exhausted for tier ${tier} (${check.limit}/mo). Resets in ${days} day(s).`,
|
|
2812
|
-
retry_after_days: days,
|
|
2813
|
-
limit: check.limit,
|
|
2814
|
-
tier,
|
|
2815
|
-
upgrade_url: 'https://algovault.com/#pricing',
|
|
2816
|
-
});
|
|
2948
|
+
return res.status(429).json((0, chat_rate_limit_js_1.buildChatQuotaNotice)(tier, check));
|
|
2817
2949
|
}
|
|
2818
2950
|
const result = await chatEngine.chat(question, model ? { model } : undefined);
|
|
2819
2951
|
await rateLimit.record(quotaKey, result.usage);
|
|
@@ -3070,7 +3202,11 @@ async function startHttp() {
|
|
|
3070
3202
|
const backgroundPriority = (0, license_js_1.resolveBackgroundPriority)(req.headers, license.tier);
|
|
3071
3203
|
// Run the entire request handling inside AsyncLocalStorage context
|
|
3072
3204
|
// so tool handlers read the correct per-request license
|
|
3073
|
-
|
|
3205
|
+
// OPS-CLIENT-ATTRIBUTION-W1: thread the raw UA — the SAME string classifyTraffic just
|
|
3206
|
+
// consumed for `requestAuthenticity` — so logRequest stamps user_agent + client_name from
|
|
3207
|
+
// one value. Previously the UA was read here and discarded, leaving a heavy caller
|
|
3208
|
+
// classifiable but unnameable (30 candidate hashes missed in OPS-TOP-IP-FORENSICS-W1).
|
|
3209
|
+
await license_js_1.requestContext.run({ license, sessionId, ipHash, isAutomated: requestAuthenticity.is_automated, userAgent: req.headers['user-agent'] ?? null, source: attributionSource, background: backgroundPriority }, async () => {
|
|
3074
3210
|
try {
|
|
3075
3211
|
const sessionId = req.headers['mcp-session-id'];
|
|
3076
3212
|
// OPS-X402-MCP-PRICE-BINDING-W1: an x402 proof was presented for a priced
|
|
@@ -3199,6 +3335,39 @@ async function startHttp() {
|
|
|
3199
3335
|
console.log(`Virtuals ACP seller worker started (mode=${r.mode})`);
|
|
3200
3336
|
})
|
|
3201
3337
|
.catch((e) => console.error('[ACP] worker bootstrap error (ACP stays dark):', e instanceof Error ? e.message : e));
|
|
3338
|
+
// ── SEC-27 (OPS-AUDIT-REMEDIATION-LOW-W1): terminal error handler ─────────────
|
|
3339
|
+
// Until this existed there was NO error-handling middleware at all, so Express's DEFAULT
|
|
3340
|
+
// handler answered every unhandled throw — and that handler includes the stack trace
|
|
3341
|
+
// whenever NODE_ENV !== 'production'. NODE_ENV was unset in the production container, so a
|
|
3342
|
+
// malformed unauthenticated POST to https://api.algovault.com/mcp returned an HTML page
|
|
3343
|
+
// containing /app/node_modules/... frames to anyone on the internet. Reproduced live on
|
|
3344
|
+
// 2026-08-02 against both /mcp and /api/chat.
|
|
3345
|
+
//
|
|
3346
|
+
// This is deliberately CODE, not just an env fix. Setting NODE_ENV=production closes it
|
|
3347
|
+
// today and reopens it the next time an env file is rewritten, a container is recreated
|
|
3348
|
+
// without it, or a new host is provisioned — the class has to be impossible, not merely
|
|
3349
|
+
// absent. Express identifies an error handler by its FOUR-argument arity; `next` must stay
|
|
3350
|
+
// in the signature even though it is unused, or this silently becomes a normal middleware
|
|
3351
|
+
// and stops catching anything.
|
|
3352
|
+
//
|
|
3353
|
+
// Diagnostics stay server-side in the log; the wire gets a stable machine-readable `code`.
|
|
3354
|
+
app.use((err, req, res, _next) => {
|
|
3355
|
+
// body-parser marks a malformed-JSON SyntaxError by hanging a `body` property on it; that
|
|
3356
|
+
// is a 400 (the caller sent bad input), not a 500.
|
|
3357
|
+
const isSyntax = err instanceof SyntaxError && 'body' in err;
|
|
3358
|
+
const status = isSyntax ? 400 : 500;
|
|
3359
|
+
console.error(`[http-error] ${req.method} ${req.path} -> ${status}:`, err instanceof Error ? `${err.name}: ${err.message}\n${err.stack ?? ''}` : String(err));
|
|
3360
|
+
if (res.headersSent)
|
|
3361
|
+
return;
|
|
3362
|
+
res.status(status).json({
|
|
3363
|
+
error: isSyntax ? 'invalid_request' : 'internal_error',
|
|
3364
|
+
code: isSyntax ? 'MALFORMED_JSON_BODY' : 'INTERNAL_ERROR',
|
|
3365
|
+
message: isSyntax
|
|
3366
|
+
? 'Request body is not valid JSON.'
|
|
3367
|
+
: 'An internal error occurred. If this persists, contact support with the timestamp.',
|
|
3368
|
+
timestamp: new Date().toISOString(),
|
|
3369
|
+
});
|
|
3370
|
+
});
|
|
3202
3371
|
const httpServer = app.listen(port, () => {
|
|
3203
3372
|
console.log(`crypto-quant-signal-mcp running on http://0.0.0.0:${port}/mcp`);
|
|
3204
3373
|
console.log(`Health check: http://0.0.0.0:${port}/health`);
|
|
@@ -4366,6 +4535,10 @@ if (require.main === module) {
|
|
|
4366
4535
|
(0, track_token_js_1.captureArgvTrackToken)();
|
|
4367
4536
|
const transport = (process.env.TRANSPORT || 'http').toLowerCase();
|
|
4368
4537
|
if (transport === 'stdio') {
|
|
4538
|
+
// OPS-SEC-IPHASH-SALT-W1: NO ip-hash key requirement here, deliberately. Every hashIp call
|
|
4539
|
+
// site takes an Express `req`, so the stdio/npx path never reaches it — demanding a key would
|
|
4540
|
+
// break every published `npx crypto-quant-signal-mcp` install for a protection stdio users are
|
|
4541
|
+
// not exposed to. The guard below covers the deployment that actually stores pseudonyms.
|
|
4369
4542
|
startStdio().catch((err) => {
|
|
4370
4543
|
console.error('Fatal:', err);
|
|
4371
4544
|
(0, performance_db_js_1.closeDb)();
|
|
@@ -4373,6 +4546,18 @@ if (require.main === module) {
|
|
|
4373
4546
|
});
|
|
4374
4547
|
}
|
|
4375
4548
|
else {
|
|
4549
|
+
// OPS-SEC-IPHASH-SALT-W1: crash-fast BEFORE binding a port. The HTTP transport is the one that
|
|
4550
|
+
// writes ip_hash / free:<hash> / ip:<hash> buckets, so a deploy that landed before the key was
|
|
4551
|
+
// installed must die loudly here — not lazily on the first request, which would leave a window
|
|
4552
|
+
// where the server looks healthy while unable to meter anyone.
|
|
4553
|
+
try {
|
|
4554
|
+
(0, analytics_js_1.assertIpHashKeyConfigured)();
|
|
4555
|
+
}
|
|
4556
|
+
catch (err) {
|
|
4557
|
+
console.error(`Fatal: ${err instanceof Error ? err.message : err}`);
|
|
4558
|
+
(0, performance_db_js_1.closeDb)();
|
|
4559
|
+
process.exit(1);
|
|
4560
|
+
}
|
|
4376
4561
|
startHttp().catch((err) => {
|
|
4377
4562
|
console.error('Fatal:', err);
|
|
4378
4563
|
(0, performance_db_js_1.closeDb)();
|