x402-trust-layer 5.1.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/CHANGELOG.md +55 -0
- package/DEPLOY.md +53 -0
- package/Dockerfile +30 -0
- package/LICENSE +21 -0
- package/README.md +294 -0
- package/dist/agents/a2a-payment.d.ts +37 -0
- package/dist/agents/a2a-payment.js +105 -0
- package/dist/agents/agent-escrow.d.ts +30 -0
- package/dist/agents/agent-escrow.js +23 -0
- package/dist/agents/agent-verify.d.ts +15 -0
- package/dist/agents/agent-verify.js +112 -0
- package/dist/agents/api-router.d.ts +32 -0
- package/dist/agents/api-router.js +228 -0
- package/dist/agents/attestation-registry.d.ts +35 -0
- package/dist/agents/attestation-registry.js +76 -0
- package/dist/agents/audition-coach.d.ts +45 -0
- package/dist/agents/audition-coach.js +257 -0
- package/dist/agents/bedrock-bridge.d.ts +3 -0
- package/dist/agents/bedrock-bridge.js +60 -0
- package/dist/agents/budget-allocator.d.ts +24 -0
- package/dist/agents/budget-allocator.js +31 -0
- package/dist/agents/compliance-ledger.d.ts +66 -0
- package/dist/agents/compliance-ledger.js +80 -0
- package/dist/agents/dispute-resolver.d.ts +62 -0
- package/dist/agents/dispute-resolver.js +124 -0
- package/dist/agents/evidence-locker.d.ts +30 -0
- package/dist/agents/evidence-locker.js +47 -0
- package/dist/agents/facilitator-failover.d.ts +15 -0
- package/dist/agents/facilitator-failover.js +18 -0
- package/dist/agents/identity-gate.d.ts +20 -0
- package/dist/agents/identity-gate.js +79 -0
- package/dist/agents/mandate-compiler.d.ts +51 -0
- package/dist/agents/mandate-compiler.js +73 -0
- package/dist/agents/mandate-diff.d.ts +41 -0
- package/dist/agents/mandate-diff.js +170 -0
- package/dist/agents/market-buy-advisor.d.ts +65 -0
- package/dist/agents/market-buy-advisor.js +234 -0
- package/dist/agents/merchant-trust.d.ts +38 -0
- package/dist/agents/merchant-trust.js +171 -0
- package/dist/agents/mpp-session-broker.d.ts +27 -0
- package/dist/agents/mpp-session-broker.js +29 -0
- package/dist/agents/mpp-session-v2.d.ts +76 -0
- package/dist/agents/mpp-session-v2.js +269 -0
- package/dist/agents/payment-intent-compiler.d.ts +21 -0
- package/dist/agents/payment-intent-compiler.js +45 -0
- package/dist/agents/pipeline-execute.d.ts +40 -0
- package/dist/agents/pipeline-execute.js +100 -0
- package/dist/agents/pipeline-trust-v2.d.ts +31 -0
- package/dist/agents/pipeline-trust-v2.js +111 -0
- package/dist/agents/pre-x402-guard.d.ts +35 -0
- package/dist/agents/pre-x402-guard.js +84 -0
- package/dist/agents/quality-escrow-semantic.d.ts +88 -0
- package/dist/agents/quality-escrow-semantic.js +137 -0
- package/dist/agents/quality-escrow.d.ts +65 -0
- package/dist/agents/quality-escrow.js +104 -0
- package/dist/agents/quality-monitor.d.ts +32 -0
- package/dist/agents/quality-monitor.js +77 -0
- package/dist/agents/rail-optimizer.d.ts +33 -0
- package/dist/agents/rail-optimizer.js +133 -0
- package/dist/agents/receipt-auditor.d.ts +14 -0
- package/dist/agents/receipt-auditor.js +145 -0
- package/dist/agents/refund-arbiter.d.ts +24 -0
- package/dist/agents/refund-arbiter.js +70 -0
- package/dist/agents/research-brief.d.ts +14 -0
- package/dist/agents/research-brief.js +66 -0
- package/dist/agents/risk-gate.d.ts +11 -0
- package/dist/agents/risk-gate.js +78 -0
- package/dist/agents/settlement-graph.d.ts +16 -0
- package/dist/agents/settlement-graph.js +38 -0
- package/dist/agents/spend-governor.d.ts +2 -0
- package/dist/agents/spend-governor.js +70 -0
- package/dist/agents/trust-network.d.ts +138 -0
- package/dist/agents/trust-network.js +244 -0
- package/dist/agents/x402-proxy.d.ts +32 -0
- package/dist/agents/x402-proxy.js +90 -0
- package/dist/client/demo-alchemy-live.d.ts +1 -0
- package/dist/client/demo-alchemy-live.js +226 -0
- package/dist/client/demo-tail.d.ts +1 -0
- package/dist/client/demo-tail.js +100 -0
- package/dist/client/demo.d.ts +1 -0
- package/dist/client/demo.js +293 -0
- package/dist/config.d.ts +94 -0
- package/dist/config.js +223 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +389 -0
- package/dist/lib/agent-response.d.ts +14 -0
- package/dist/lib/agent-response.js +13 -0
- package/dist/lib/agentic-gateways.d.ts +5 -0
- package/dist/lib/agentic-gateways.js +15 -0
- package/dist/lib/agentic-probes.d.ts +10 -0
- package/dist/lib/agentic-probes.js +49 -0
- package/dist/lib/alchemy-x402-fetch.d.ts +16 -0
- package/dist/lib/alchemy-x402-fetch.js +95 -0
- package/dist/lib/apply-verifier-body.d.ts +7 -0
- package/dist/lib/apply-verifier-body.js +179 -0
- package/dist/lib/attestation.d.ts +30 -0
- package/dist/lib/attestation.js +107 -0
- package/dist/lib/bazaar-extension.d.ts +15 -0
- package/dist/lib/bazaar-extension.js +265 -0
- package/dist/lib/bazaar.d.ts +100 -0
- package/dist/lib/bazaar.js +341 -0
- package/dist/lib/certified-sellers.d.ts +41 -0
- package/dist/lib/certified-sellers.js +129 -0
- package/dist/lib/chains.d.ts +20 -0
- package/dist/lib/chains.js +78 -0
- package/dist/lib/db-persistence.d.ts +7 -0
- package/dist/lib/db-persistence.js +65 -0
- package/dist/lib/db.d.ts +5 -0
- package/dist/lib/db.js +113 -0
- package/dist/lib/discovery-page.d.ts +2 -0
- package/dist/lib/discovery-page.js +71 -0
- package/dist/lib/ecosystem-telemetry.d.ts +20 -0
- package/dist/lib/ecosystem-telemetry.js +80 -0
- package/dist/lib/erc8004/agent-card.d.ts +34 -0
- package/dist/lib/erc8004/agent-card.js +151 -0
- package/dist/lib/erc8004/cache.d.ts +3 -0
- package/dist/lib/erc8004/cache.js +17 -0
- package/dist/lib/erc8004/constants.d.ts +22 -0
- package/dist/lib/erc8004/constants.js +35 -0
- package/dist/lib/erc8004/registry.d.ts +19 -0
- package/dist/lib/erc8004/registry.js +171 -0
- package/dist/lib/erc8004/resolve-agent.d.ts +7 -0
- package/dist/lib/erc8004/resolve-agent.js +70 -0
- package/dist/lib/erc8004/trust-score.d.ts +33 -0
- package/dist/lib/erc8004/trust-score.js +136 -0
- package/dist/lib/escrow-ledger.d.ts +14 -0
- package/dist/lib/escrow-ledger.js +54 -0
- package/dist/lib/escrow-unified.d.ts +15 -0
- package/dist/lib/escrow-unified.js +28 -0
- package/dist/lib/facilitator-extra.d.ts +13 -0
- package/dist/lib/facilitator-extra.js +52 -0
- package/dist/lib/facilitators.d.ts +20 -0
- package/dist/lib/facilitators.js +89 -0
- package/dist/lib/host-policy.d.ts +4 -0
- package/dist/lib/host-policy.js +20 -0
- package/dist/lib/idempotency.d.ts +4 -0
- package/dist/lib/idempotency.js +120 -0
- package/dist/lib/ledger.d.ts +2 -0
- package/dist/lib/ledger.js +17 -0
- package/dist/lib/logger.d.ts +6 -0
- package/dist/lib/logger.js +24 -0
- package/dist/lib/mandate-vc.d.ts +20 -0
- package/dist/lib/mandate-vc.js +25 -0
- package/dist/lib/mandate.d.ts +44 -0
- package/dist/lib/mandate.js +190 -0
- package/dist/lib/marketplace.d.ts +7 -0
- package/dist/lib/marketplace.js +127 -0
- package/dist/lib/migrations.d.ts +2 -0
- package/dist/lib/migrations.js +130 -0
- package/dist/lib/nonce-store.d.ts +6 -0
- package/dist/lib/nonce-store.js +109 -0
- package/dist/lib/openapi-agentcash.d.ts +5 -0
- package/dist/lib/openapi-agentcash.js +288 -0
- package/dist/lib/openapi-meta.d.ts +5 -0
- package/dist/lib/openapi-meta.js +235 -0
- package/dist/lib/otel.d.ts +2 -0
- package/dist/lib/otel.js +25 -0
- package/dist/lib/paid-resource-url.d.ts +6 -0
- package/dist/lib/paid-resource-url.js +47 -0
- package/dist/lib/parse-with-verifier-fallback.d.ts +3 -0
- package/dist/lib/parse-with-verifier-fallback.js +13 -0
- package/dist/lib/payment-request-context.d.ts +10 -0
- package/dist/lib/payment-request-context.js +5 -0
- package/dist/lib/payment-response.d.ts +13 -0
- package/dist/lib/payment-response.js +39 -0
- package/dist/lib/payto-guard.d.ts +10 -0
- package/dist/lib/payto-guard.js +20 -0
- package/dist/lib/probe.d.ts +29 -0
- package/dist/lib/probe.js +157 -0
- package/dist/lib/problem-detail.d.ts +10 -0
- package/dist/lib/problem-detail.js +14 -0
- package/dist/lib/rate-limit.d.ts +12 -0
- package/dist/lib/rate-limit.js +126 -0
- package/dist/lib/replay-middleware.d.ts +3 -0
- package/dist/lib/replay-middleware.js +27 -0
- package/dist/lib/response-guard.d.ts +5 -0
- package/dist/lib/response-guard.js +40 -0
- package/dist/lib/safe-fetch.d.ts +5 -0
- package/dist/lib/safe-fetch.js +19 -0
- package/dist/lib/security.d.ts +13 -0
- package/dist/lib/security.js +61 -0
- package/dist/lib/semantic-judge.d.ts +14 -0
- package/dist/lib/semantic-judge.js +107 -0
- package/dist/lib/semantic-judge.test.d.ts +1 -0
- package/dist/lib/semantic-judge.test.js +11 -0
- package/dist/lib/ssrf.d.ts +10 -0
- package/dist/lib/ssrf.js +130 -0
- package/dist/lib/ssrf.test.d.ts +1 -0
- package/dist/lib/ssrf.test.js +16 -0
- package/dist/lib/suite-catalog.d.ts +83 -0
- package/dist/lib/suite-catalog.js +131 -0
- package/dist/lib/telemetry.d.ts +5 -0
- package/dist/lib/telemetry.js +37 -0
- package/dist/lib/verifier-fast-path.d.ts +10 -0
- package/dist/lib/verifier-fast-path.js +44 -0
- package/dist/lib/verifier-probe-protocol.d.ts +7 -0
- package/dist/lib/verifier-probe-protocol.js +115 -0
- package/dist/lib/verify-examples.d.ts +2 -0
- package/dist/lib/verify-examples.js +438 -0
- package/dist/lib/version.d.ts +2 -0
- package/dist/lib/version.js +2 -0
- package/dist/lib/webhook-auth.d.ts +3 -0
- package/dist/lib/webhook-auth.js +34 -0
- package/dist/lib/webhook-routes.d.ts +2 -0
- package/dist/lib/webhook-routes.js +112 -0
- package/dist/lib/webhooks.d.ts +23 -0
- package/dist/lib/webhooks.js +123 -0
- package/dist/lib/webhooks.test.d.ts +1 -0
- package/dist/lib/webhooks.test.js +16 -0
- package/dist/lib/x402-client-options.d.ts +28 -0
- package/dist/lib/x402-client-options.js +138 -0
- package/dist/lib/x402-headers.d.ts +10 -0
- package/dist/lib/x402-headers.js +27 -0
- package/dist/lib/x402-paid.d.ts +5 -0
- package/dist/lib/x402-paid.js +252 -0
- package/dist/lib/x402-payment-replay.d.ts +22 -0
- package/dist/lib/x402-payment-replay.js +57 -0
- package/dist/lib/x402gle-host-verify.d.ts +3 -0
- package/dist/lib/x402gle-host-verify.js +27 -0
- package/dist/protocol/agent-passport.d.ts +34 -0
- package/dist/protocol/agent-passport.js +44 -0
- package/dist/protocol/compliance-v2.d.ts +21 -0
- package/dist/protocol/compliance-v2.js +19 -0
- package/dist/protocol/credit-bureau.d.ts +18 -0
- package/dist/protocol/credit-bureau.js +44 -0
- package/dist/protocol/crypto.d.ts +6 -0
- package/dist/protocol/crypto.js +41 -0
- package/dist/protocol/escrow-fsm.d.ts +33 -0
- package/dist/protocol/escrow-fsm.js +99 -0
- package/dist/protocol/fraud-engine.d.ts +28 -0
- package/dist/protocol/fraud-engine.js +77 -0
- package/dist/protocol/observability.d.ts +14 -0
- package/dist/protocol/observability.js +21 -0
- package/dist/protocol/pipeline-full-trust.d.ts +40 -0
- package/dist/protocol/pipeline-full-trust.js +96 -0
- package/dist/protocol/proof-of-execution.d.ts +36 -0
- package/dist/protocol/proof-of-execution.js +48 -0
- package/dist/protocol/reasoning-audit.d.ts +27 -0
- package/dist/protocol/reasoning-audit.js +51 -0
- package/dist/protocol/replay-guard.d.ts +28 -0
- package/dist/protocol/replay-guard.js +76 -0
- package/dist/protocol/replay-guard.test.d.ts +1 -0
- package/dist/protocol/replay-guard.test.js +10 -0
- package/dist/protocol/security-audit.d.ts +18 -0
- package/dist/protocol/security-audit.js +45 -0
- package/dist/protocol/store.d.ts +5 -0
- package/dist/protocol/store.js +59 -0
- package/dist/protocol/threat-catalog.d.ts +13 -0
- package/dist/protocol/threat-catalog.js +75 -0
- package/dist/protocol/trust-oracle.d.ts +23 -0
- package/dist/protocol/trust-oracle.js +30 -0
- package/dist/protocol/trust-score-v2.d.ts +33 -0
- package/dist/protocol/trust-score-v2.js +78 -0
- package/dist/protocol/zk-proofs.d.ts +24 -0
- package/dist/protocol/zk-proofs.js +32 -0
- package/dist/routes/a2a-agent-card.d.ts +3 -0
- package/dist/routes/a2a-agent-card.js +28 -0
- package/dist/routes/catalog.d.ts +5 -0
- package/dist/routes/catalog.js +47 -0
- package/dist/routes/register-all.d.ts +3 -0
- package/dist/routes/register-all.js +1240 -0
- package/dist/routes/schemas.d.ts +83 -0
- package/dist/routes/schemas.js +38 -0
- package/dist/routes/shared.d.ts +16 -0
- package/dist/routes/shared.js +27 -0
- package/dist/routes-protocol.d.ts +10 -0
- package/dist/routes-protocol.js +322 -0
- package/dist/routes.d.ts +2 -0
- package/dist/routes.js +2 -0
- package/dist/types.d.ts +66 -0
- package/dist/types.js +1 -0
- package/openapi.json +7940 -0
- package/package.json +124 -0
- package/public/.well-known/ai-plugin.json +12 -0
- package/public/assets/aegis-logo-blue.png +0 -0
- package/public/assets/aegis-logo-gold.png +0 -0
- package/public/assets/aegis-logo-green.png +0 -0
- package/public/assets/aegis-logo-purple.png +0 -0
- package/public/assets/aegis-logo-red.png +0 -0
- package/public/assets/aegis-logo-white.png +0 -0
- package/public/assets/aegis-logo.png +0 -0
- package/public/assets/x402-trustlayer-logo.png +0 -0
- package/public/assets/x402-trustlayer-logo.svg +5 -0
- package/public/data/agents.json +1528 -0
- package/public/index.html +198 -0
- package/public/landing.css +342 -0
- package/public/landing.js +405 -0
- package/public/llms-full.txt +582 -0
- package/public/llms.txt +132 -0
- package/public/skill.md +135 -0
- package/railway.toml +9 -0
- package/scripts/docker-entrypoint.sh +7 -0
- package/scripts/patch-facilitator-timeout.mjs +61 -0
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
import { config } from "../config.js";
|
|
2
|
+
import { listEndpoints } from "../routes.js";
|
|
3
|
+
import { SUITE_VERSION } from "./version.js";
|
|
4
|
+
const SERVICE_NAME = "x402 Trust Layer";
|
|
5
|
+
const SERVICE_DESCRIPTION = "55 paid x402 trust infrastructure APIs: guard, semantic escrow, mandate diff, certified sellers, ERC-8004, plus Agent Trust Protocol v4 (passport, trust v2, fraud, oracle, PoE, escrow FSM, replay, zk, credit bureau).";
|
|
6
|
+
const ENDPOINT_META = {
|
|
7
|
+
"/api/x402/proxy": {
|
|
8
|
+
summary: "One-call preflight: guard + security grade + attestation + probe",
|
|
9
|
+
category: "Infrastructure",
|
|
10
|
+
tags: ["x402", "proxy", "preflight", "guard"],
|
|
11
|
+
},
|
|
12
|
+
"/api/mpp/session": {
|
|
13
|
+
summary: "MPP session open, voucher, and close for batch settlement savings",
|
|
14
|
+
category: "Infrastructure",
|
|
15
|
+
tags: ["mpp", "batch", "solana"],
|
|
16
|
+
},
|
|
17
|
+
"/api/attestation/issue": {
|
|
18
|
+
summary: "Issue signed preflight attestation for trust networks",
|
|
19
|
+
category: "Trust",
|
|
20
|
+
tags: ["attestation", "trust", "security"],
|
|
21
|
+
},
|
|
22
|
+
"/api/attestation/verify": {
|
|
23
|
+
summary: "Verify attestation signature before downstream payment",
|
|
24
|
+
category: "Trust",
|
|
25
|
+
tags: ["attestation", "verify"],
|
|
26
|
+
},
|
|
27
|
+
"/api/attestation/registry": {
|
|
28
|
+
summary: "Query active attestations registry",
|
|
29
|
+
category: "Trust",
|
|
30
|
+
tags: ["attestation", "registry"],
|
|
31
|
+
},
|
|
32
|
+
"/api/guard/pre-x402": {
|
|
33
|
+
summary: "Spend + identity + risk + security grade before any x402 pay",
|
|
34
|
+
category: "Infrastructure",
|
|
35
|
+
tags: ["guard", "preflight", "policy"],
|
|
36
|
+
},
|
|
37
|
+
"/api/agent/verify": {
|
|
38
|
+
summary: "ERC-8004 TrustScore on Base mainnet — agent identity and reputation",
|
|
39
|
+
category: "Trust",
|
|
40
|
+
tags: ["erc-8004", "identity", "trust-score", "agent"],
|
|
41
|
+
},
|
|
42
|
+
"/api/pipeline/execute": {
|
|
43
|
+
summary: "Full agent pipeline: guard, plan, facilitator, routing in one call",
|
|
44
|
+
category: "Orchestration",
|
|
45
|
+
tags: ["pipeline", "orchestration"],
|
|
46
|
+
},
|
|
47
|
+
"/api/payment-intent/compile": {
|
|
48
|
+
summary: "Compile multi-step x402 execution plan from natural language",
|
|
49
|
+
category: "Orchestration",
|
|
50
|
+
tags: ["plan", "compiler"],
|
|
51
|
+
},
|
|
52
|
+
"/api/facilitator/failover": {
|
|
53
|
+
summary: "Rank facilitators and recommend failover path",
|
|
54
|
+
category: "Infrastructure",
|
|
55
|
+
tags: ["facilitator", "failover"],
|
|
56
|
+
},
|
|
57
|
+
"/api/mpp/session-plan": {
|
|
58
|
+
summary: "Estimate MPP session vs per-call settlement savings",
|
|
59
|
+
category: "Infrastructure",
|
|
60
|
+
tags: ["mpp", "estimate"],
|
|
61
|
+
},
|
|
62
|
+
"/api/spend-governor/check": {
|
|
63
|
+
summary: "Enforce agent daily and per-call spend caps",
|
|
64
|
+
category: "Policy",
|
|
65
|
+
tags: ["spend", "budget", "policy"],
|
|
66
|
+
},
|
|
67
|
+
"/api/identity-gate/check": {
|
|
68
|
+
summary: "Wallet identity tier and risk scoring",
|
|
69
|
+
category: "Policy",
|
|
70
|
+
tags: ["identity", "wallet", "kyc"],
|
|
71
|
+
},
|
|
72
|
+
"/api/risk-gate/scan": {
|
|
73
|
+
summary: "Probe URL security, HTTPS, and x402 payment requirements",
|
|
74
|
+
category: "Security",
|
|
75
|
+
tags: ["risk", "scan", "security"],
|
|
76
|
+
},
|
|
77
|
+
"/api/router/route": {
|
|
78
|
+
summary: "Route capability query to best x402 API (suite-first)",
|
|
79
|
+
category: "Discovery",
|
|
80
|
+
tags: ["router", "marketplace"],
|
|
81
|
+
},
|
|
82
|
+
"/api/research/brief": {
|
|
83
|
+
summary: "Research pipeline plan and cost estimate",
|
|
84
|
+
category: "Research",
|
|
85
|
+
tags: ["research", "brief"],
|
|
86
|
+
},
|
|
87
|
+
"/api/receipt-auditor/verify": {
|
|
88
|
+
summary: "Verify x402 settlement receipt on-chain",
|
|
89
|
+
category: "Audit",
|
|
90
|
+
tags: ["receipt", "audit", "settlement"],
|
|
91
|
+
},
|
|
92
|
+
"/api/refund-arbiter/evaluate": {
|
|
93
|
+
summary: "Evaluate refund eligibility from verification signals",
|
|
94
|
+
category: "Trust",
|
|
95
|
+
tags: ["refund", "arbiter"],
|
|
96
|
+
},
|
|
97
|
+
"/api/budget-allocator/run": {
|
|
98
|
+
summary: "Allocate shared USDC pool across agent fleet",
|
|
99
|
+
category: "Enterprise",
|
|
100
|
+
tags: ["budget", "fleet"],
|
|
101
|
+
},
|
|
102
|
+
"/api/settlement-graph/next": {
|
|
103
|
+
summary: "Recommend next paid APIs after a settlement",
|
|
104
|
+
category: "Intelligence",
|
|
105
|
+
tags: ["graph", "recommendations"],
|
|
106
|
+
},
|
|
107
|
+
"/api/quality-monitor/probe": {
|
|
108
|
+
summary: "Regression probe up to 10 x402 endpoints",
|
|
109
|
+
category: "Quality",
|
|
110
|
+
tags: ["monitor", "quality"],
|
|
111
|
+
},
|
|
112
|
+
"/api/evidence-locker/export": {
|
|
113
|
+
summary: "Export compliance audit bundle for settlements",
|
|
114
|
+
category: "Enterprise",
|
|
115
|
+
tags: ["compliance", "audit"],
|
|
116
|
+
},
|
|
117
|
+
"/api/agent-escrow": {
|
|
118
|
+
summary: "Create, status, or release agent-to-agent USDC escrow",
|
|
119
|
+
category: "Enterprise",
|
|
120
|
+
tags: ["escrow", "agents"],
|
|
121
|
+
},
|
|
122
|
+
"/api/market/buy-advisor": {
|
|
123
|
+
summary: "x402 buy quote: rank paid APIs, policy, chain, MPP before you pay",
|
|
124
|
+
category: "Discovery",
|
|
125
|
+
tags: ["marketplace", "quote", "discovery"],
|
|
126
|
+
},
|
|
127
|
+
"/api/seller/audition-coach": {
|
|
128
|
+
summary: "Seller audition coach: OpenAPI, 402 probes, x402gle fixes before ingest",
|
|
129
|
+
category: "Quality",
|
|
130
|
+
tags: ["seller", "audition", "discovery", "quality"],
|
|
131
|
+
},
|
|
132
|
+
"/api/merchant-trust/score": {
|
|
133
|
+
summary: "Know-Your-Merchant trust + wash-trading score before payment",
|
|
134
|
+
category: "Trust",
|
|
135
|
+
tags: ["trust", "kym", "wash-trade", "preflight"],
|
|
136
|
+
},
|
|
137
|
+
"/api/mandate/compile": {
|
|
138
|
+
summary: "Compile signed AP2-style payment mandate from human intent",
|
|
139
|
+
category: "Trust",
|
|
140
|
+
tags: ["mandate", "ap2", "intent", "governance"],
|
|
141
|
+
},
|
|
142
|
+
"/api/mandate/verify": {
|
|
143
|
+
summary: "Verify mandate signature and scope a proposed payment",
|
|
144
|
+
category: "Trust",
|
|
145
|
+
tags: ["mandate", "verify", "governance"],
|
|
146
|
+
},
|
|
147
|
+
"/api/rail-optimizer/route": {
|
|
148
|
+
summary: "Choose best rail: Visa CLI, Stripe MPP, Circle, Base, Solana",
|
|
149
|
+
category: "Infrastructure",
|
|
150
|
+
tags: ["rail", "router", "visa-cli", "mpp"],
|
|
151
|
+
},
|
|
152
|
+
"/api/compliance/ledger": {
|
|
153
|
+
summary: "CFO/SOC2-grade spend reconciliation with tamper-evident hash",
|
|
154
|
+
category: "Enterprise",
|
|
155
|
+
tags: ["compliance", "audit", "cfo", "ledger"],
|
|
156
|
+
},
|
|
157
|
+
"/api/dispute/resolve": {
|
|
158
|
+
summary: "Visa chargeback dossier or on-chain refund claim builder",
|
|
159
|
+
category: "Trust",
|
|
160
|
+
tags: ["dispute", "chargeback", "visa", "refund"],
|
|
161
|
+
},
|
|
162
|
+
"/api/quality-escrow/settle": {
|
|
163
|
+
summary: "Quality-gated escrow with response verification and auto-refund",
|
|
164
|
+
category: "Trust",
|
|
165
|
+
tags: ["escrow", "quality", "refund", "trust"],
|
|
166
|
+
},
|
|
167
|
+
"/api/quality-escrow/semantic-settle": {
|
|
168
|
+
summary: "Semantic delivery escrow: intent rubric + schema match before release/refund",
|
|
169
|
+
category: "Trust",
|
|
170
|
+
tags: ["escrow", "semantic", "delivery", "trust"],
|
|
171
|
+
},
|
|
172
|
+
"/api/mandate/diff": {
|
|
173
|
+
summary: "Intent diff: mandate scope vs MCP tool trace before payment",
|
|
174
|
+
category: "Trust",
|
|
175
|
+
tags: ["mandate", "intent", "diff", "governance"],
|
|
176
|
+
},
|
|
177
|
+
"/api/merchant-trust/certify": {
|
|
178
|
+
summary: "Certify x402 seller with badge and buyer access policy",
|
|
179
|
+
category: "Trust",
|
|
180
|
+
tags: ["certification", "seller", "kym", "trust-network"],
|
|
181
|
+
},
|
|
182
|
+
"/api/trust-network/buyer-gate": {
|
|
183
|
+
summary: "Buyer gate for certified sellers: attestation + tier check",
|
|
184
|
+
category: "Trust",
|
|
185
|
+
tags: ["trust-network", "attestation", "buyer", "gate"],
|
|
186
|
+
},
|
|
187
|
+
"/api/pipeline/trust-v2": {
|
|
188
|
+
summary: "One-shot: mandate diff + KYM ingest + guard + certified buyer gate",
|
|
189
|
+
category: "Orchestration",
|
|
190
|
+
tags: ["pipeline", "trust-v2", "orchestration"],
|
|
191
|
+
},
|
|
192
|
+
"/api/trust-network/bond/slash": {
|
|
193
|
+
summary: "Slash certified seller virtual bond after failed delivery",
|
|
194
|
+
category: "Trust",
|
|
195
|
+
tags: ["bond", "slash", "seller", "trust-network"],
|
|
196
|
+
},
|
|
197
|
+
"/api/protocol/pipeline/full-trust": {
|
|
198
|
+
summary: "Full Agent Trust Protocol v4 pipeline before x402 payment",
|
|
199
|
+
category: "Protocol",
|
|
200
|
+
tags: ["protocol", "trust", "pipeline"],
|
|
201
|
+
},
|
|
202
|
+
"/api/protocol/passport/issue": {
|
|
203
|
+
summary: "Issue Agent Passport DID verifiable credential",
|
|
204
|
+
category: "Protocol",
|
|
205
|
+
tags: ["did", "identity", "passport"],
|
|
206
|
+
},
|
|
207
|
+
"/api/protocol/trust-score/v2": {
|
|
208
|
+
summary: "Tamper-resistant TrustScore v2 with HMAC proof",
|
|
209
|
+
category: "Protocol",
|
|
210
|
+
tags: ["trust-score", "erc8004"],
|
|
211
|
+
},
|
|
212
|
+
"/api/protocol/fraud/scan": {
|
|
213
|
+
summary: "Graph fraud scan: Sybil, wash trading, circular payments",
|
|
214
|
+
category: "Protocol",
|
|
215
|
+
tags: ["fraud", "risk"],
|
|
216
|
+
},
|
|
217
|
+
"/api/protocol/execution/issue": {
|
|
218
|
+
summary: "Proof of Execution receipt with tool and settlement proofs",
|
|
219
|
+
category: "Protocol",
|
|
220
|
+
tags: ["poe", "receipt", "audit"],
|
|
221
|
+
},
|
|
222
|
+
"/api/protocol/escrow/create": {
|
|
223
|
+
summary: "Create escrow state machine (CREATED)",
|
|
224
|
+
category: "Protocol",
|
|
225
|
+
tags: ["escrow", "fsm"],
|
|
226
|
+
},
|
|
227
|
+
"/api/protocol/replay/bind": {
|
|
228
|
+
summary: "Replay-safe binding: nonce + resource hash + request hash",
|
|
229
|
+
category: "Protocol",
|
|
230
|
+
tags: ["replay", "security"],
|
|
231
|
+
},
|
|
232
|
+
"/api/protocol/credit/score": {
|
|
233
|
+
summary: "AI Agent Credit Bureau score 300-900",
|
|
234
|
+
category: "Protocol",
|
|
235
|
+
tags: ["credit", "bureau"],
|
|
236
|
+
},
|
|
237
|
+
};
|
|
238
|
+
function parseEndpointEntry(entry) {
|
|
239
|
+
const [method, route] = entry.path.split(" ");
|
|
240
|
+
const priceUsdc = Number(entry.price.replace(/^\$/, "")) || 0;
|
|
241
|
+
return { method: method ?? "POST", path: route ?? entry.path, priceUsdc };
|
|
242
|
+
}
|
|
243
|
+
export function buildBazaarRoutes() {
|
|
244
|
+
return listEndpoints().map((entry) => {
|
|
245
|
+
const { method, path, priceUsdc } = parseEndpointEntry(entry);
|
|
246
|
+
const meta = ENDPOINT_META[path] ?? {
|
|
247
|
+
summary: entry.path,
|
|
248
|
+
category: "Infrastructure",
|
|
249
|
+
tags: ["x402"],
|
|
250
|
+
};
|
|
251
|
+
const resource = `${config.publicBaseUrl}${path}`;
|
|
252
|
+
return {
|
|
253
|
+
resource,
|
|
254
|
+
method,
|
|
255
|
+
path,
|
|
256
|
+
priceUsdc,
|
|
257
|
+
priceDisplay: entry.price,
|
|
258
|
+
tier: entry.tier,
|
|
259
|
+
summary: meta.summary,
|
|
260
|
+
category: meta.category,
|
|
261
|
+
tags: meta.tags,
|
|
262
|
+
networks: config.networks,
|
|
263
|
+
payTo: config.payTo,
|
|
264
|
+
facilitatorUrl: config.facilitatorUrl,
|
|
265
|
+
extensions: {
|
|
266
|
+
bazaar: {
|
|
267
|
+
discoverable: true,
|
|
268
|
+
category: meta.category,
|
|
269
|
+
tags: meta.tags,
|
|
270
|
+
},
|
|
271
|
+
},
|
|
272
|
+
};
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
export function buildServicesManifest() {
|
|
276
|
+
return {
|
|
277
|
+
x402Version: 2,
|
|
278
|
+
name: SERVICE_NAME,
|
|
279
|
+
description: SERVICE_DESCRIPTION,
|
|
280
|
+
baseUrl: config.publicBaseUrl,
|
|
281
|
+
facilitatorUrl: config.facilitatorUrl,
|
|
282
|
+
payTo: config.payTo,
|
|
283
|
+
networks: config.networks,
|
|
284
|
+
openapi: `${config.publicBaseUrl}/openapi.json`,
|
|
285
|
+
discover: `${config.publicBaseUrl}/x402/api/discover`,
|
|
286
|
+
routes: buildBazaarRoutes(),
|
|
287
|
+
updatedAt: new Date().toISOString(),
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
export function buildWellKnownX402() {
|
|
291
|
+
const payToMap = {};
|
|
292
|
+
for (const network of config.networks) {
|
|
293
|
+
if (network.startsWith("solana:"))
|
|
294
|
+
payToMap[network] = config.payTo;
|
|
295
|
+
else
|
|
296
|
+
payToMap[network] = config.payToEvm || config.payTo;
|
|
297
|
+
}
|
|
298
|
+
return {
|
|
299
|
+
x402Version: 2,
|
|
300
|
+
name: SERVICE_NAME,
|
|
301
|
+
version: SUITE_VERSION,
|
|
302
|
+
description: SERVICE_DESCRIPTION,
|
|
303
|
+
baseUrl: config.publicBaseUrl,
|
|
304
|
+
paymentRequired: true,
|
|
305
|
+
facilitator: config.facilitatorUrl,
|
|
306
|
+
payTo: payToMap,
|
|
307
|
+
networks: config.networks,
|
|
308
|
+
discovery: {
|
|
309
|
+
services: `${config.publicBaseUrl}/x402/api/services.json`,
|
|
310
|
+
discover: `${config.publicBaseUrl}/x402/api/discover`,
|
|
311
|
+
openapi: `${config.publicBaseUrl}/openapi.json`,
|
|
312
|
+
},
|
|
313
|
+
agenticMarket: {
|
|
314
|
+
validateUrl: "https://agentic.market/",
|
|
315
|
+
note: "Use Validate Endpoint per resource URL; settlements via CDP facilitator index faster on Agentic Market",
|
|
316
|
+
},
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
export function buildDiscoverCatalog() {
|
|
320
|
+
const routes = buildBazaarRoutes();
|
|
321
|
+
return {
|
|
322
|
+
service: SERVICE_NAME,
|
|
323
|
+
version: SUITE_VERSION,
|
|
324
|
+
endpointCount: routes.length,
|
|
325
|
+
resources: routes.map((r) => ({
|
|
326
|
+
url: r.resource,
|
|
327
|
+
method: r.method,
|
|
328
|
+
description: r.summary,
|
|
329
|
+
priceUsdc: r.priceUsdc,
|
|
330
|
+
category: r.category,
|
|
331
|
+
tags: r.tags,
|
|
332
|
+
accepts: r.networks.map((network) => ({
|
|
333
|
+
scheme: "exact",
|
|
334
|
+
network,
|
|
335
|
+
payTo: config.payTo,
|
|
336
|
+
amountUsdc: r.priceUsdc,
|
|
337
|
+
})),
|
|
338
|
+
extensions: r.extensions,
|
|
339
|
+
})),
|
|
340
|
+
};
|
|
341
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export type AgentTier = "BRONZE" | "SILVER" | "GOLD" | "PLATINUM";
|
|
2
|
+
export type SellerAccessPolicy = {
|
|
3
|
+
requireAttestation: boolean;
|
|
4
|
+
minAgentTier: AgentTier;
|
|
5
|
+
minTrustScore: number;
|
|
6
|
+
minSecurityGrade: "A" | "B" | "C" | "D";
|
|
7
|
+
};
|
|
8
|
+
export type CertifiedSellerRecord = {
|
|
9
|
+
host: string;
|
|
10
|
+
badgeId: string;
|
|
11
|
+
certifiedAt: string;
|
|
12
|
+
expiresAt: string;
|
|
13
|
+
trustScoreAtCert: number;
|
|
14
|
+
grade: string;
|
|
15
|
+
recommendation: string;
|
|
16
|
+
policy: SellerAccessPolicy;
|
|
17
|
+
goodResponseProfile?: {
|
|
18
|
+
requiredKeys?: string[];
|
|
19
|
+
minLengthBytes?: number;
|
|
20
|
+
forbidEmpty?: boolean;
|
|
21
|
+
};
|
|
22
|
+
/** USDC bond (virtual ledger) — slash on failed delivery claims */
|
|
23
|
+
bondUsdc?: number;
|
|
24
|
+
bondRemainingUsdc?: number;
|
|
25
|
+
signature: string;
|
|
26
|
+
};
|
|
27
|
+
export declare function tierMeets(min: AgentTier, actual: AgentTier): boolean;
|
|
28
|
+
export declare function gradeMeets(min: SellerAccessPolicy["minSecurityGrade"], actual: string): boolean;
|
|
29
|
+
export declare function upsertCertification(input: Omit<CertifiedSellerRecord, "badgeId" | "certifiedAt" | "expiresAt" | "signature"> & {
|
|
30
|
+
ttlDays?: number;
|
|
31
|
+
bondUsdc?: number;
|
|
32
|
+
}): Promise<CertifiedSellerRecord>;
|
|
33
|
+
export declare function getCertifiedHost(host: string): Promise<CertifiedSellerRecord | null>;
|
|
34
|
+
export declare function slashSellerBond(host: string, amountUsdc: number, reason: string): Promise<{
|
|
35
|
+
ok: boolean;
|
|
36
|
+
host: string;
|
|
37
|
+
slashedUsdc: number;
|
|
38
|
+
bondRemainingUsdc: number;
|
|
39
|
+
reason: string;
|
|
40
|
+
}>;
|
|
41
|
+
export declare function listCertifiedHosts(limit?: number): Promise<CertifiedSellerRecord[]>;
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { createHmac, randomBytes } from "node:crypto";
|
|
2
|
+
import { readFile, writeFile, mkdir } from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import { config } from "../config.js";
|
|
6
|
+
const root = path.dirname(fileURLToPath(import.meta.url));
|
|
7
|
+
const storePath = path.join(root, "..", "..", "data", "certified-sellers.json");
|
|
8
|
+
const TIER_ORDER = ["BRONZE", "SILVER", "GOLD", "PLATINUM"];
|
|
9
|
+
const GRADE_ORDER = ["A", "B", "C", "D", "F"];
|
|
10
|
+
export function tierMeets(min, actual) {
|
|
11
|
+
return TIER_ORDER.indexOf(actual) >= TIER_ORDER.indexOf(min);
|
|
12
|
+
}
|
|
13
|
+
export function gradeMeets(min, actual) {
|
|
14
|
+
const a = GRADE_ORDER.indexOf(min);
|
|
15
|
+
const b = GRADE_ORDER.indexOf(actual);
|
|
16
|
+
if (a < 0 || b < 0)
|
|
17
|
+
return false;
|
|
18
|
+
return b <= a;
|
|
19
|
+
}
|
|
20
|
+
async function loadStore() {
|
|
21
|
+
try {
|
|
22
|
+
const raw = await readFile(storePath, "utf8");
|
|
23
|
+
const parsed = JSON.parse(raw);
|
|
24
|
+
return Array.isArray(parsed) ? parsed : [];
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return [];
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
async function saveStore(rows) {
|
|
31
|
+
await mkdir(path.dirname(storePath), { recursive: true });
|
|
32
|
+
await writeFile(storePath, JSON.stringify(rows.slice(-200), null, 2), "utf8");
|
|
33
|
+
}
|
|
34
|
+
function canonical(record) {
|
|
35
|
+
return JSON.stringify({
|
|
36
|
+
host: record.host,
|
|
37
|
+
badgeId: record.badgeId,
|
|
38
|
+
certifiedAt: record.certifiedAt,
|
|
39
|
+
expiresAt: record.expiresAt,
|
|
40
|
+
trustScoreAtCert: record.trustScoreAtCert,
|
|
41
|
+
policy: record.policy,
|
|
42
|
+
bondRemainingUsdc: record.bondRemainingUsdc ?? 0,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
function sign(payload) {
|
|
46
|
+
return createHmac("sha256", config.attestationHmacSecret).update(payload).digest("hex");
|
|
47
|
+
}
|
|
48
|
+
export async function upsertCertification(input) {
|
|
49
|
+
const host = input.host.toLowerCase();
|
|
50
|
+
const badgeId = `cert_${randomBytes(6).toString("hex")}`;
|
|
51
|
+
const certifiedAt = new Date().toISOString();
|
|
52
|
+
const ttlDays = input.ttlDays ?? 30;
|
|
53
|
+
const expiresAt = new Date(Date.now() + ttlDays * 24 * 60 * 60_000).toISOString();
|
|
54
|
+
const bondUsdc = input.bondUsdc ?? 0;
|
|
55
|
+
const base = {
|
|
56
|
+
host,
|
|
57
|
+
badgeId,
|
|
58
|
+
certifiedAt,
|
|
59
|
+
expiresAt,
|
|
60
|
+
trustScoreAtCert: input.trustScoreAtCert,
|
|
61
|
+
grade: input.grade,
|
|
62
|
+
recommendation: input.recommendation,
|
|
63
|
+
policy: input.policy,
|
|
64
|
+
goodResponseProfile: input.goodResponseProfile,
|
|
65
|
+
bondUsdc: bondUsdc > 0 ? bondUsdc : undefined,
|
|
66
|
+
bondRemainingUsdc: bondUsdc > 0 ? bondUsdc : undefined,
|
|
67
|
+
};
|
|
68
|
+
const signature = sign(canonical(base));
|
|
69
|
+
const record = { ...base, signature };
|
|
70
|
+
const rows = await loadStore().then((r) => r.filter((x) => x.host !== host));
|
|
71
|
+
rows.push(record);
|
|
72
|
+
await saveStore(rows);
|
|
73
|
+
return record;
|
|
74
|
+
}
|
|
75
|
+
export async function getCertifiedHost(host) {
|
|
76
|
+
const h = host.toLowerCase();
|
|
77
|
+
const rows = await loadStore();
|
|
78
|
+
const record = rows.find((r) => r.host === h) ?? null;
|
|
79
|
+
if (!record)
|
|
80
|
+
return null;
|
|
81
|
+
if (new Date(record.expiresAt) < new Date())
|
|
82
|
+
return null;
|
|
83
|
+
const expected = sign(canonical({
|
|
84
|
+
host: record.host,
|
|
85
|
+
badgeId: record.badgeId,
|
|
86
|
+
certifiedAt: record.certifiedAt,
|
|
87
|
+
expiresAt: record.expiresAt,
|
|
88
|
+
trustScoreAtCert: record.trustScoreAtCert,
|
|
89
|
+
grade: record.grade,
|
|
90
|
+
recommendation: record.recommendation,
|
|
91
|
+
policy: record.policy,
|
|
92
|
+
goodResponseProfile: record.goodResponseProfile,
|
|
93
|
+
bondUsdc: record.bondUsdc,
|
|
94
|
+
bondRemainingUsdc: record.bondRemainingUsdc,
|
|
95
|
+
}));
|
|
96
|
+
if (expected !== record.signature)
|
|
97
|
+
return null;
|
|
98
|
+
return record;
|
|
99
|
+
}
|
|
100
|
+
export async function slashSellerBond(host, amountUsdc, reason) {
|
|
101
|
+
const h = host.toLowerCase();
|
|
102
|
+
const rows = await loadStore();
|
|
103
|
+
const idx = rows.findIndex((r) => r.host === h);
|
|
104
|
+
if (idx < 0) {
|
|
105
|
+
return { ok: false, host: h, slashedUsdc: 0, bondRemainingUsdc: 0, reason: "not_certified" };
|
|
106
|
+
}
|
|
107
|
+
const record = rows[idx];
|
|
108
|
+
const remaining = Math.max(0, (record.bondRemainingUsdc ?? 0) - amountUsdc);
|
|
109
|
+
const slashed = Math.min(amountUsdc, record.bondRemainingUsdc ?? 0);
|
|
110
|
+
const updated = {
|
|
111
|
+
...record,
|
|
112
|
+
bondRemainingUsdc: remaining,
|
|
113
|
+
signature: sign(canonical({
|
|
114
|
+
...record,
|
|
115
|
+
bondRemainingUsdc: remaining,
|
|
116
|
+
})),
|
|
117
|
+
};
|
|
118
|
+
rows[idx] = updated;
|
|
119
|
+
await saveStore(rows);
|
|
120
|
+
return { ok: slashed > 0, host: h, slashedUsdc: slashed, bondRemainingUsdc: remaining, reason };
|
|
121
|
+
}
|
|
122
|
+
export async function listCertifiedHosts(limit = 50) {
|
|
123
|
+
const now = Date.now();
|
|
124
|
+
const rows = await loadStore();
|
|
125
|
+
return rows
|
|
126
|
+
.filter((r) => new Date(r.expiresAt).getTime() > now)
|
|
127
|
+
.slice(-limit)
|
|
128
|
+
.reverse();
|
|
129
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** Supported x402 settlement networks (CAIP-2) */
|
|
2
|
+
export declare const CHAIN_IDS: {
|
|
3
|
+
readonly solana: "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp";
|
|
4
|
+
readonly base: "eip155:8453";
|
|
5
|
+
readonly polygon: "eip155:137";
|
|
6
|
+
readonly base_sepolia: "eip155:84532";
|
|
7
|
+
readonly solana_devnet: "solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1";
|
|
8
|
+
};
|
|
9
|
+
export type ChainKey = keyof typeof CHAIN_IDS;
|
|
10
|
+
/** USDC token address / mint per chain (Agentic + CDP expect network-correct asset) */
|
|
11
|
+
export declare const USDC_ASSET: Record<ChainKey, string>;
|
|
12
|
+
export declare function usdcAssetForCaip2(network: string): string | undefined;
|
|
13
|
+
export declare function parseChainList(raw: string | undefined): ChainKey[];
|
|
14
|
+
export declare function caip2Networks(chains: ChainKey[]): string[];
|
|
15
|
+
/** Human chain keys → CAIP-2 (x402 v2 discovery). */
|
|
16
|
+
export declare const NETWORK_ALIAS_TO_CAIP2: Record<string, string>;
|
|
17
|
+
export declare function normalizeToCaip2(network: string): string;
|
|
18
|
+
export declare function isEvmChain(chain: ChainKey): boolean;
|
|
19
|
+
export declare function isTestnetChain(chain: ChainKey): boolean;
|
|
20
|
+
export declare function detectChainFromAddress(address: string): ChainKey | null;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/** Supported x402 settlement networks (CAIP-2) */
|
|
2
|
+
export const CHAIN_IDS = {
|
|
3
|
+
solana: "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",
|
|
4
|
+
base: "eip155:8453",
|
|
5
|
+
polygon: "eip155:137",
|
|
6
|
+
base_sepolia: "eip155:84532",
|
|
7
|
+
solana_devnet: "solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1",
|
|
8
|
+
};
|
|
9
|
+
/** USDC token address / mint per chain (Agentic + CDP expect network-correct asset) */
|
|
10
|
+
export const USDC_ASSET = {
|
|
11
|
+
solana: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
|
|
12
|
+
base: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
|
|
13
|
+
polygon: "0x3c499c542cEF5E3811e1192ce70d8cC03d5c335",
|
|
14
|
+
base_sepolia: "0x036CbD53842c5426634e7929541eC2318f3dCF7e",
|
|
15
|
+
solana_devnet: "4zMMC9srt5Ri5X14GAgXhaHii3GnPEPBNLW2nN2H4V2",
|
|
16
|
+
};
|
|
17
|
+
export function usdcAssetForCaip2(network) {
|
|
18
|
+
for (const key of Object.keys(CHAIN_IDS)) {
|
|
19
|
+
if (CHAIN_IDS[key] === network)
|
|
20
|
+
return USDC_ASSET[key];
|
|
21
|
+
}
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
const CHAIN_ALIASES = {
|
|
25
|
+
"base-sepolia": "base_sepolia",
|
|
26
|
+
base_sepolia: "base_sepolia",
|
|
27
|
+
"solana-devnet": "solana_devnet",
|
|
28
|
+
solana_devnet: "solana_devnet",
|
|
29
|
+
};
|
|
30
|
+
export function parseChainList(raw) {
|
|
31
|
+
if (!raw || raw === "all")
|
|
32
|
+
return ["base", "solana", "polygon"];
|
|
33
|
+
const keys = raw
|
|
34
|
+
.split(",")
|
|
35
|
+
.map((s) => s.trim().toLowerCase())
|
|
36
|
+
.filter(Boolean);
|
|
37
|
+
const out = [];
|
|
38
|
+
for (const k of keys) {
|
|
39
|
+
const resolved = (CHAIN_ALIASES[k] ?? k);
|
|
40
|
+
if (resolved in CHAIN_IDS && !out.includes(resolved))
|
|
41
|
+
out.push(resolved);
|
|
42
|
+
}
|
|
43
|
+
// Preserve the operator-specified order so NETWORKS controls which chain is
|
|
44
|
+
// advertised first in the 402 `accepts` list (and therefore preferred by payers).
|
|
45
|
+
return out.length ? out : ["solana"];
|
|
46
|
+
}
|
|
47
|
+
export function caip2Networks(chains) {
|
|
48
|
+
return chains.map((c) => CHAIN_IDS[c]);
|
|
49
|
+
}
|
|
50
|
+
/** Human chain keys → CAIP-2 (x402 v2 discovery). */
|
|
51
|
+
export const NETWORK_ALIAS_TO_CAIP2 = {
|
|
52
|
+
base: CHAIN_IDS.base,
|
|
53
|
+
solana: CHAIN_IDS.solana,
|
|
54
|
+
polygon: CHAIN_IDS.polygon,
|
|
55
|
+
"base-sepolia": CHAIN_IDS.base_sepolia,
|
|
56
|
+
base_sepolia: CHAIN_IDS.base_sepolia,
|
|
57
|
+
"solana-devnet": CHAIN_IDS.solana_devnet,
|
|
58
|
+
solana_devnet: CHAIN_IDS.solana_devnet,
|
|
59
|
+
};
|
|
60
|
+
export function normalizeToCaip2(network) {
|
|
61
|
+
const trimmed = network.trim();
|
|
62
|
+
if (trimmed.includes(":"))
|
|
63
|
+
return trimmed;
|
|
64
|
+
return NETWORK_ALIAS_TO_CAIP2[trimmed.toLowerCase()] ?? trimmed;
|
|
65
|
+
}
|
|
66
|
+
export function isEvmChain(chain) {
|
|
67
|
+
return chain === "base" || chain === "polygon" || chain === "base_sepolia";
|
|
68
|
+
}
|
|
69
|
+
export function isTestnetChain(chain) {
|
|
70
|
+
return chain === "base_sepolia" || chain === "solana_devnet";
|
|
71
|
+
}
|
|
72
|
+
export function detectChainFromAddress(address) {
|
|
73
|
+
if (/^0x[a-fA-F0-9]{40}$/.test(address.trim()))
|
|
74
|
+
return "base";
|
|
75
|
+
if (/^[1-9A-HJ-NP-Za-km-z]{32,44}$/.test(address.trim()))
|
|
76
|
+
return "solana";
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { MppSession } from "../agents/mpp-session-v2.js";
|
|
2
|
+
import type { EscrowRecord } from "./escrow-ledger.js";
|
|
3
|
+
export declare function saveMppSessionToDb(session: MppSession): void;
|
|
4
|
+
export declare function loadMppSessionsFromDb(agentId?: string): MppSession[];
|
|
5
|
+
export declare function getMppSessionFromDb(sessionId: string): MppSession | null;
|
|
6
|
+
export declare function saveEscrowToDb(record: EscrowRecord): void;
|
|
7
|
+
export declare function getEscrowFromDb(id: string): EscrowRecord | null;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { db } from "./db.js";
|
|
2
|
+
const getMpp = db.prepare("SELECT session_id, agent_id, budget_usdc, spent_usdc, status, created_at, closed_at, payload FROM mpp_sessions WHERE session_id = ?");
|
|
3
|
+
const upsertMpp = db.prepare(`
|
|
4
|
+
INSERT INTO mpp_sessions (session_id, agent_id, budget_usdc, spent_usdc, status, created_at, closed_at, payload)
|
|
5
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
|
6
|
+
ON CONFLICT(session_id) DO UPDATE SET
|
|
7
|
+
spent_usdc = excluded.spent_usdc,
|
|
8
|
+
status = excluded.status,
|
|
9
|
+
closed_at = excluded.closed_at,
|
|
10
|
+
payload = excluded.payload
|
|
11
|
+
`);
|
|
12
|
+
const listMppByAgent = db.prepare("SELECT payload FROM mpp_sessions WHERE agent_id = ? ORDER BY created_at DESC LIMIT 50");
|
|
13
|
+
const getEscrow = db.prepare("SELECT escrow_id, buyer_agent_id, seller_agent_id, amount_usdc, condition_hash, status, created_at, released_at, payload FROM escrow_records WHERE escrow_id = ?");
|
|
14
|
+
const upsertEscrow = db.prepare(`
|
|
15
|
+
INSERT INTO escrow_records (escrow_id, buyer_agent_id, seller_agent_id, amount_usdc, condition_hash, status, created_at, released_at, payload)
|
|
16
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
17
|
+
ON CONFLICT(escrow_id) DO UPDATE SET
|
|
18
|
+
status = excluded.status,
|
|
19
|
+
released_at = excluded.released_at,
|
|
20
|
+
payload = excluded.payload
|
|
21
|
+
`);
|
|
22
|
+
export function saveMppSessionToDb(session) {
|
|
23
|
+
const spent = session.callsUsed * session.avgPricePerCallUsdc;
|
|
24
|
+
upsertMpp.run(session.sessionId, session.agentId, session.maxBudgetUsdc, spent, session.status, Math.floor(new Date(session.openedAt).getTime() / 1000), session.closedAt ? Math.floor(new Date(session.closedAt).getTime() / 1000) : null, JSON.stringify(session));
|
|
25
|
+
}
|
|
26
|
+
export function loadMppSessionsFromDb(agentId) {
|
|
27
|
+
if (!agentId)
|
|
28
|
+
return [];
|
|
29
|
+
const rows = listMppByAgent.all(agentId);
|
|
30
|
+
const out = [];
|
|
31
|
+
for (const row of rows) {
|
|
32
|
+
try {
|
|
33
|
+
out.push(JSON.parse(row.payload));
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
/* skip corrupt */
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return out;
|
|
40
|
+
}
|
|
41
|
+
export function getMppSessionFromDb(sessionId) {
|
|
42
|
+
const row = getMpp.get(sessionId);
|
|
43
|
+
if (!row?.payload)
|
|
44
|
+
return null;
|
|
45
|
+
try {
|
|
46
|
+
return JSON.parse(row.payload);
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
export function saveEscrowToDb(record) {
|
|
53
|
+
upsertEscrow.run(record.id, record.payerAgentId, record.payeeAgentId, record.amountUsdc, record.releaseCondition.slice(0, 128), record.status, Math.floor(new Date(record.createdAt).getTime() / 1000), record.releasedAt ? Math.floor(new Date(record.releasedAt).getTime() / 1000) : null, JSON.stringify(record));
|
|
54
|
+
}
|
|
55
|
+
export function getEscrowFromDb(id) {
|
|
56
|
+
const row = getEscrow.get(id);
|
|
57
|
+
if (!row?.payload)
|
|
58
|
+
return null;
|
|
59
|
+
try {
|
|
60
|
+
return JSON.parse(row.payload);
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
}
|