@nekzus/liop 1.0.0-alpha.1
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/LICENSE +201 -0
- package/NOTICE +24 -0
- package/README.md +641 -0
- package/dist/bin/agent.d.ts +1 -0
- package/dist/bin/agent.js +897 -0
- package/dist/bin/agent.js.map +1 -0
- package/dist/bridge.d.ts +105 -0
- package/dist/bridge.js +5 -0
- package/dist/bridge.js.map +1 -0
- package/dist/chunk-3L2O2XKG.js +723 -0
- package/dist/chunk-3L2O2XKG.js.map +1 -0
- package/dist/chunk-7BSCUYUE.js +421 -0
- package/dist/chunk-7BSCUYUE.js.map +1 -0
- package/dist/chunk-7PITYWOV.js +68 -0
- package/dist/chunk-7PITYWOV.js.map +1 -0
- package/dist/chunk-7RXOIDXP.js +877 -0
- package/dist/chunk-7RXOIDXP.js.map +1 -0
- package/dist/chunk-BOISQ45Z.js +558 -0
- package/dist/chunk-BOISQ45Z.js.map +1 -0
- package/dist/chunk-DZ2FQGJD.js +206712 -0
- package/dist/chunk-DZ2FQGJD.js.map +1 -0
- package/dist/chunk-EG46XMJT.js +77 -0
- package/dist/chunk-EG46XMJT.js.map +1 -0
- package/dist/chunk-ESRXG36Y.js +115 -0
- package/dist/chunk-ESRXG36Y.js.map +1 -0
- package/dist/chunk-FTF6AMF6.js +3 -0
- package/dist/chunk-FTF6AMF6.js.map +1 -0
- package/dist/chunk-HA6YZ42O.js +64 -0
- package/dist/chunk-HA6YZ42O.js.map +1 -0
- package/dist/chunk-HD2N3IJX.js +3634 -0
- package/dist/chunk-HD2N3IJX.js.map +1 -0
- package/dist/chunk-IK7CGWAZ.js +24 -0
- package/dist/chunk-IK7CGWAZ.js.map +1 -0
- package/dist/chunk-L6J72C5X.js +1477 -0
- package/dist/chunk-L6J72C5X.js.map +1 -0
- package/dist/chunk-PAICJCKJ.js +332 -0
- package/dist/chunk-PAICJCKJ.js.map +1 -0
- package/dist/chunk-PEN3KFLF.js +114 -0
- package/dist/chunk-PEN3KFLF.js.map +1 -0
- package/dist/chunk-T7R5HUFD.js +775 -0
- package/dist/chunk-T7R5HUFD.js.map +1 -0
- package/dist/chunk-TKRX6CFI.js +168 -0
- package/dist/chunk-TKRX6CFI.js.map +1 -0
- package/dist/chunk-UCVP3XAL.js +279 -0
- package/dist/chunk-UCVP3XAL.js.map +1 -0
- package/dist/chunk-VH4K4U45.js +180 -0
- package/dist/chunk-VH4K4U45.js.map +1 -0
- package/dist/chunk-Y62GORQF.js +51 -0
- package/dist/chunk-Y62GORQF.js.map +1 -0
- package/dist/chunk-ZP3VVXOI.js +66 -0
- package/dist/chunk-ZP3VVXOI.js.map +1 -0
- package/dist/client.d.ts +7 -0
- package/dist/client.js +13 -0
- package/dist/client.js.map +1 -0
- package/dist/gateway.d.ts +7 -0
- package/dist/gateway.js +13 -0
- package/dist/gateway.js.map +1 -0
- package/dist/hybrid-CrKB50nh.d.ts +170 -0
- package/dist/index-CX43dvMs.d.ts +170 -0
- package/dist/index-DoW2gzBZ.d.ts +566 -0
- package/dist/index.d.ts +810 -0
- package/dist/index.js +357 -0
- package/dist/index.js.map +1 -0
- package/dist/kyber-CGOA7Q6A.js +3 -0
- package/dist/kyber-CGOA7Q6A.js.map +1 -0
- package/dist/mesh.d.ts +32 -0
- package/dist/mesh.js +6 -0
- package/dist/mesh.js.map +1 -0
- package/dist/node-B0b2vUFS.d.ts +164 -0
- package/dist/protocol/liop_core.proto +47 -0
- package/dist/server.d.ts +5 -0
- package/dist/server.js +9 -0
- package/dist/server.js.map +1 -0
- package/dist/types-lJIxBlWF.d.ts +256 -0
- package/dist/types.d.ts +3 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/verifier-COnid_dg.d.ts +31 -0
- package/dist/verifier-HRFXBKT5.js +6 -0
- package/dist/verifier-HRFXBKT5.js.map +1 -0
- package/dist/workers/logic-execution.d.ts +26 -0
- package/dist/workers/logic-execution.js +272 -0
- package/dist/workers/logic-execution.js.map +1 -0
- package/dist/workers/zk-verifier.d.ts +26 -0
- package/dist/workers/zk-verifier.js +174 -0
- package/dist/workers/zk-verifier.js.map +1 -0
- package/package.json +230 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/runtime/routing-table.ts","../src/runtime/topology-probe.ts"],"names":[],"mappings":";;;AAoCO,IAAM,YAAA,GAAN,MAAM,aAAA,CAAa;AAAA,EACjB,MAAA,uBAAa,GAAA,EAAuB;AAAA,EAC5C,OAAwB,YAAA,GAAe,CAAA;AAAA;AAAA;AAAA;AAAA,EAKhC,oBAAA,CACN,KAAA,EACA,WAAA,EACA,YAAA,GAAe,IAAA,EACR;AACP,IAAA,KAAA,MAAW,QAAQ,KAAA,EAAO;AACzB,MAAA,MAAM,QAAA,GAAW,IAAA,CAAK,MAAA,CAAO,GAAA,CAAI,KAAK,IAAI,CAAA;AAC1C,MAAA,IAAA,CAAK,MAAA,CAAO,GAAA,CAAI,IAAA,CAAK,IAAA,EAAM;AAAA,QAC1B,MAAM,IAAA,CAAK,IAAA;AAAA,QACX,QAAA,EAAU,cAAA;AAAA,QACV,QAAA,EAAU,WAAA;AAAA,QACV,WAAA,EAAa,IAAA,CAAK,WAAA,IAAe,QAAA,EAAU,WAAA;AAAA,QAC3C,WAAA,EAAa,IAAA,CAAK,WAAA,IAAe,QAAA,EAAU,WAAA;AAAA,QAC3C,SAAA,EAAW,UAAU,SAAA,IAAa,CAAA;AAAA,QAClC,SAAA,EAAW,CAAA;AAAA,QACX,WAAA,EAAa,QAAA,EAAU,WAAA,IAAe,IAAA,CAAK,GAAA,EAAI;AAAA,QAC/C;AAAA,OACA,CAAA;AAAA,IACF;AACA,IAAA,GAAA,CAAI,IAAA;AAAA,MACH,CAAA,0BAAA,EAA6B,KAAA,CAAM,MAAM,CAAA,2BAAA,EAA8B,WAAW,CAAA,CAAA;AAAA,KACnF;AAAA,EACD;AAAA;AAAA;AAAA;AAAA,EAKO,iBAAA,CACN,KAA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AAS,IAAI,GAAA,CAAI,OAAA,CAAQ,MAAM,CAAA,CAAE,IAAI,CAAA;AAC9D,QAAA;AAED,MAAA,WAAA,GAAc,MAAM,eAAA,CAAgB,GAAA,EAAK,OAAO,CAAA;AAChD,MAAA,IAAI,WAAA,EAAa;AAAA,IAClB;AAAA,EACD;AAGA,EAAA,MAAM,cAAA,GAAiB,OAAA,CAAQ,cAAA,IAAkB,EAAC;AAClD,EAAA,MAAM,iBAAA,GAAoB,eAAe,MAAA,GAAS,CAAA;AAGlD,EAAA,IAAI,eAAe,iBAAA,EAAmB;AACrC,IAAA,GAAA,CAAI,IAAA;AAAA,MACH,CAAA,yDAAA,EAAuD,WAAA,CAAY,OAAO,CAAA,GAAA,EAAM,eAAe,MAAM,CAAA,gBAAA;AAAA,KACtG;AACA,IAAA,OAAO;AAAA,MACN,IAAA,EAAM,QAAA;AAAA,MACN,OAAA,EAAS,WAAA;AAAA,MACT,IAAA,EAAM;AAAA,QACL,cAAA;AAAA,QACA,cAAc,OAAA,CAAQ;AAAA;AACvB,KACD;AAAA,EACD;AAEA,EAAA,IAAI,WAAA,EAAa;AAChB,IAAA,GAAA,CAAI,IAAA;AAAA,MACH,CAAA,iFAAA,EAA6E,YAAY,OAAO,CAAA,CAAA;AAAA,KACjG;AACA,IAAA,OAAO;AAAA,MACN,IAAA,EAAM,SAAA;AAAA,MACN,OAAA,EAAS;AAAA,KACV;AAAA,EACD;AAEA,EAAA,GAAA,CAAI,IAAA;AAAA,IACH,CAAA,+EAAA,EAA2E,eAAe,MAAM,CAAA,CAAA;AAAA,GACjG;AACA,EAAA,OAAO;AAAA,IACN,IAAA,EAAM,MAAA;AAAA,IACN,IAAA,EAAM;AAAA,MACL,cAAA;AAAA,MACA,cAAc,OAAA,CAAQ;AAAA;AACvB,GACD;AACD","file":"chunk-UCVP3XAL.js","sourcesContent":["// Copyright 2026 Nekzus Solutions and contributors\n// SPDX-License-Identifier: Apache-2.0\n\n/**\n * LIOP Routing Table — Per-Tool Hybrid Routing & Resilience\n *\n * Maintains deterministic per-tool routes across heterogeneous transports:\n * - \"http-gateway\": Route through Border LIO Gateway or reverse proxy via HTTP/JSON-RPC.\n * - \"p2p-grpc\": Route directly to sovereign node via libp2p + gRPC (Kyber768/ZK-Receipt).\n * - \"local\": Handled in-process (e.g. LiopMeshStatus, diagnostic probes).\n *\n * Implements per-route latency tracking, failure backoff, and circuit breaking.\n */\n\nimport { log } from \"../utils/logger.js\";\n\nexport type TransportProvider = \"http-gateway\" | \"p2p-grpc\" | \"local\";\n\nexport interface ToolDefinition {\n\tname: string;\n\tdescription?: string;\n\tinputSchema?: Record<string, unknown>;\n}\n\nexport interface ToolRoute {\n\tname: string;\n\tprovider: TransportProvider;\n\tendpoint: string;\n\tdescription?: string;\n\tinputSchema?: Record<string, unknown>;\n\tlatencyMs: number;\n\tfailCount: number;\n\tlastSuccess: number;\n\tauthRequired?: boolean;\n}\n\nexport class RoutingTable {\n\tprivate routes = new Map<string, ToolRoute>();\n\tprivate static readonly MAX_FAILURES = 5;\n\n\t/**\n\t * Registers or updates a collection of tools exposed via an HTTP Gateway.\n\t */\n\tpublic registerGatewayTools(\n\t\ttools: ToolDefinition[],\n\t\tmcpEndpoint: string,\n\t\tauthRequired = true,\n\t): void {\n\t\tfor (const tool of tools) {\n\t\t\tconst existing = this.routes.get(tool.name);\n\t\t\tthis.routes.set(tool.name, {\n\t\t\t\tname: tool.name,\n\t\t\t\tprovider: \"http-gateway\",\n\t\t\t\tendpoint: mcpEndpoint,\n\t\t\t\tdescription: tool.description ?? existing?.description,\n\t\t\t\tinputSchema: tool.inputSchema ?? existing?.inputSchema,\n\t\t\t\tlatencyMs: existing?.latencyMs ?? 0,\n\t\t\t\tfailCount: 0,\n\t\t\t\tlastSuccess: existing?.lastSuccess ?? Date.now(),\n\t\t\t\tauthRequired,\n\t\t\t});\n\t\t}\n\t\tlog.info(\n\t\t\t`[RoutingTable] Registered ${tools.length} tool(s) via HTTP Gateway (${mcpEndpoint})`,\n\t\t);\n\t}\n\n\t/**\n\t * Registers tools discovered directly over the P2P Mesh (gRPC).\n\t */\n\tpublic registerMeshTools(\n\t\ttools: ToolDefinition[],\n\t\tgrpcTarget: string,\n\t\tauthRequired = false,\n\t): void {\n\t\tfor (const tool of tools) {\n\t\t\tconst existing = this.routes.get(tool.name);\n\t\t\t// Do not overwrite healthy gateway routes unless explicitly preferred\n\t\t\tif (\n\t\t\t\texisting &&\n\t\t\t\texisting.provider === \"http-gateway\" &&\n\t\t\t\texisting.failCount === 0\n\t\t\t) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tthis.routes.set(tool.name, {\n\t\t\t\tname: tool.name,\n\t\t\t\tprovider: \"p2p-grpc\",\n\t\t\t\tendpoint: grpcTarget,\n\t\t\t\tdescription: tool.description ?? existing?.description,\n\t\t\t\tinputSchema: tool.inputSchema ?? existing?.inputSchema,\n\t\t\t\tlatencyMs: existing?.latencyMs ?? 0,\n\t\t\t\tfailCount: 0,\n\t\t\t\tlastSuccess: existing?.lastSuccess ?? Date.now(),\n\t\t\t\tauthRequired,\n\t\t\t});\n\t\t}\n\t\tlog.info(\n\t\t\t`[RoutingTable] Registered ${tools.length} tool(s) via P2P Mesh gRPC (${grpcTarget})`,\n\t\t);\n\t}\n\n\t/**\n\t * Registers an in-process local tool (e.g. LiopMeshStatus).\n\t */\n\tpublic registerLocalTool(tool: ToolDefinition): void {\n\t\tthis.routes.set(tool.name, {\n\t\t\tname: tool.name,\n\t\t\tprovider: \"local\",\n\t\t\tendpoint: \"in-process\",\n\t\t\tdescription: tool.description,\n\t\t\tinputSchema: tool.inputSchema,\n\t\t\tlatencyMs: 0,\n\t\t\tfailCount: 0,\n\t\t\tlastSuccess: Date.now(),\n\t\t\tauthRequired: false,\n\t\t});\n\t}\n\n\t/**\n\t * Resolves the optimal route for a specific tool.\n\t */\n\tpublic resolve(toolName: string): ToolRoute | undefined {\n\t\tconst route = this.routes.get(toolName);\n\t\tif (!route) return undefined;\n\n\t\t// If circuit is tripped (excessive failures), still return route but log warning\n\t\tif (route.failCount >= RoutingTable.MAX_FAILURES) {\n\t\t\tlog.warn(\n\t\t\t\t`[RoutingTable] Tool '${toolName}' route has tripped circuit breaker (${route.failCount} consecutive failures).`,\n\t\t\t);\n\t\t}\n\n\t\treturn route;\n\t}\n\n\t/**\n\t * Records a successful invocation on a route, resetting failures and updating latency.\n\t */\n\tpublic recordSuccess(toolName: string, latencyMs: number): void {\n\t\tconst route = this.routes.get(toolName);\n\t\tif (route) {\n\t\t\troute.failCount = 0;\n\t\t\troute.latencyMs = latencyMs;\n\t\t\troute.lastSuccess = Date.now();\n\t\t}\n\t}\n\n\t/**\n\t * Records a failed invocation on a route.\n\t */\n\tpublic recordFailure(toolName: string): void {\n\t\tconst route = this.routes.get(toolName);\n\t\tif (route) {\n\t\t\troute.failCount += 1;\n\t\t\tlog.warn(\n\t\t\t\t`[RoutingTable] Failure recorded for tool '${toolName}' (failCount: ${route.failCount})`,\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Lists all registered tools in sorted format for tools/list.\n\t */\n\tpublic getAllToolDefinitions(): ToolDefinition[] {\n\t\tconst list: ToolDefinition[] = [];\n\t\tfor (const route of this.routes.values()) {\n\t\t\tlist.push({\n\t\t\t\tname: route.name,\n\t\t\t\tdescription: route.description,\n\t\t\t\tinputSchema: route.inputSchema,\n\t\t\t});\n\t\t}\n\t\treturn list.sort((a, b) => a.name.localeCompare(b.name));\n\t}\n\n\tpublic getRoute(toolName: string): ToolRoute | undefined {\n\t\treturn this.routes.get(toolName);\n\t}\n\n\tpublic size(): number {\n\t\treturn this.routes.size;\n\t}\n\n\tpublic clear(): void {\n\t\tthis.routes.clear();\n\t}\n}\n","// Copyright 2026 Nekzus Solutions and contributors\n// SPDX-License-Identifier: Apache-2.0\n\n/**\n * LIOP Topology Probe — RFC 9728 PRM Chain & Adaptive Network Detection\n *\n * Implements single-URL auto-discovery of multi-tier mesh environments:\n * 1. Probes RFC 9728 Protected Resource Metadata (PRM) or /health endpoint.\n * 2. Chains discovery to obtain OAuth 2.1 authorization server endpoints.\n * 3. Identifies whether the node should operate in \"gateway\", \"mesh\", or \"hybrid\" mode.\n *\n * Standards: RFC 9728, RFC 8414, RFC 8707, NIST SP 800-207\n */\n\nimport { log } from \"../utils/logger.js\";\n\nexport interface GatewayTopologyInfo {\n\tbaseUrl: string;\n\tmcpEndpoint: string;\n\thealthEndpoint: string;\n\ttokenEndpoint: string;\n\tissuer: string;\n\taudience: string;\n\tscopes: string[];\n\ttools: string[];\n\ttier: number;\n}\n\nexport interface MeshTopologyInfo {\n\tbootstrapNodes: string[];\n\tidentityPath?: string;\n}\n\nexport interface TopologyProbeResult {\n\tmode: \"gateway\" | \"mesh\" | \"hybrid\";\n\tgateway?: GatewayTopologyInfo;\n\tmesh?: MeshTopologyInfo;\n}\n\nexport interface TopologyProbeOptions {\n\tblgUrl?: string;\n\tnexusUrl?: string;\n\tclientId?: string;\n\tclientSecret?: string;\n\taudience?: string;\n\tstaticToken?: string;\n\tbootstrapNodes?: string[];\n\tidentityPath?: string;\n\tautoProbeLocal?: boolean;\n}\n\n/**\n * Executes the RFC 9728 PRM chain and health probe on a candidate Gateway URL.\n */\nasync function probeGatewayUrl(\n\tcandidateUrl: string,\n\toptions: TopologyProbeOptions,\n): Promise<GatewayTopologyInfo | null> {\n\tconst trimmedUrl = candidateUrl.replace(/\\/+$/, \"\");\n\tconst healthUrl = `${trimmedUrl}/health`;\n\n\ttry {\n\t\tlog.info(`[TopologyProbe] Probing candidate Gateway at: ${healthUrl}`);\n\t\tconst healthRes = await fetch(healthUrl, {\n\t\t\theaders: { Accept: \"application/json\" },\n\t\t\tsignal: AbortSignal.timeout(3000),\n\t\t});\n\n\t\tif (!healthRes.ok) {\n\t\t\tlog.info(\n\t\t\t\t`[TopologyProbe] Probe failed at ${healthUrl} [HTTP ${healthRes.status}]`,\n\t\t\t);\n\t\t\treturn null;\n\t\t}\n\n\t\tconst healthData = (await healthRes.json()) as {\n\t\t\tstatus?: string;\n\t\t\ttools?: string[];\n\t\t\tauth?: {\n\t\t\t\tissuer?: string;\n\t\t\t\ttoken_endpoint?: string;\n\t\t\t\tjwks_uri?: string;\n\t\t\t};\n\t\t\ttopology?: {\n\t\t\t\ttier?: number;\n\t\t\t};\n\t\t};\n\n\t\tif (healthData.status !== \"healthy\") {\n\t\t\treturn null;\n\t\t}\n\n\t\t// Discover OAuth metadata via PRM (RFC 9728)\n\t\tlet issuer = healthData.auth?.issuer || \"\";\n\t\tlet tokenEndpoint = healthData.auth?.token_endpoint || \"\";\n\t\tlet audience = options.audience || \"urn:liop:mesh:api\";\n\t\tlet scopes: string[] = [\n\t\t\t\"liop:tools:list\",\n\t\t\t\"liop:tools:call\",\n\t\t\t\"liop:resources:read\",\n\t\t\t\"liop:schema:read\",\n\t\t\t\"liop:mesh:query\",\n\t\t];\n\n\t\ttry {\n\t\t\tconst prmUrl = `${trimmedUrl}/.well-known/oauth-protected-resource`;\n\t\t\tconst prmRes = await fetch(prmUrl, {\n\t\t\t\theaders: { Accept: \"application/json\" },\n\t\t\t\tsignal: AbortSignal.timeout(2000),\n\t\t\t});\n\t\t\tif (prmRes.ok) {\n\t\t\t\tconst prmData = (await prmRes.json()) as {\n\t\t\t\t\tresource?: string;\n\t\t\t\t\tauthorization_servers?: string[];\n\t\t\t\t\tscopes_supported?: string[];\n\t\t\t\t};\n\t\t\t\tif (prmData.resource) audience = prmData.resource;\n\t\t\t\tif (prmData.authorization_servers?.length) {\n\t\t\t\t\tissuer = prmData.authorization_servers[0];\n\t\t\t\t}\n\t\t\t\tif (prmData.scopes_supported?.length) {\n\t\t\t\t\tscopes = prmData.scopes_supported;\n\t\t\t\t}\n\t\t\t}\n\t\t} catch {\n\t\t\t// Non-fatal if PRM endpoint is not present\n\t\t}\n\n\t\t// If token endpoint is not explicitly given, resolve from issuer\n\t\tif (!tokenEndpoint && issuer) {\n\t\t\tconst baseIssuer = issuer.endsWith(\"/oidc\") ? issuer : `${issuer}/oidc`;\n\t\t\ttokenEndpoint = `${baseIssuer}/token`;\n\t\t}\n\n\t\t// Normalize tokenEndpoint for Docker-to-Host bridge environments\n\t\tif (tokenEndpoint) {\n\t\t\ttry {\n\t\t\t\tconst parsedEndpoint = new URL(tokenEndpoint);\n\t\t\t\tif (options.nexusUrl) {\n\t\t\t\t\tconst nexusBase = options.nexusUrl.replace(/\\/+$/, \"\");\n\t\t\t\t\tconst nexusHost = new URL(nexusBase).host;\n\t\t\t\t\tparsedEndpoint.host = nexusHost;\n\t\t\t\t\ttokenEndpoint = parsedEndpoint.toString();\n\t\t\t\t} else if (\n\t\t\t\t\t(parsedEndpoint.hostname === \"nexus\" ||\n\t\t\t\t\t\tparsedEndpoint.hostname === \"nexus-prod\" ||\n\t\t\t\t\t\tparsedEndpoint.hostname.startsWith(\"172.\")) &&\n\t\t\t\t\ttrimmedUrl.includes(\"127.0.0.1\")\n\t\t\t\t) {\n\t\t\t\t\tparsedEndpoint.host = \"127.0.0.1:15000\";\n\t\t\t\t\ttokenEndpoint = parsedEndpoint.toString();\n\t\t\t\t}\n\t\t\t} catch {\n\t\t\t\t/* keep original tokenEndpoint */\n\t\t\t}\n\t\t}\n\n\t\tlog.info(\n\t\t\t`[TopologyProbe] ✅ Verified Gateway at ${trimmedUrl} (Tools: ${healthData.tools?.length ?? 0}, Tier: ${healthData.topology?.tier ?? 2})`,\n\t\t);\n\n\t\treturn {\n\t\t\tbaseUrl: trimmedUrl,\n\t\t\tmcpEndpoint: `${trimmedUrl}/mcp`,\n\t\t\thealthEndpoint: `${trimmedUrl}/health`,\n\t\t\ttokenEndpoint,\n\t\t\tissuer,\n\t\t\taudience,\n\t\t\tscopes,\n\t\t\ttools: healthData.tools || [],\n\t\t\ttier: healthData.topology?.tier ?? 2,\n\t\t};\n\t} catch (err) {\n\t\tlog.info(\n\t\t\t`[TopologyProbe] Gateway probe unreachable at ${trimmedUrl}: ${err instanceof Error ? err.message : String(err)}`,\n\t\t);\n\t\treturn null;\n\t}\n}\n\n/**\n * Probes the runtime environment and determines the optimal architecture mode.\n */\nexport async function probeTopology(\n\toptions: TopologyProbeOptions = {},\n): Promise<TopologyProbeResult> {\n\tlog.info(\"[TopologyProbe] Starting adaptive network topology discovery...\");\n\n\tlet gatewayInfo: GatewayTopologyInfo | null = null;\n\n\t// 1. Check explicit Border LIO Gateway URL (Highest priority)\n\tif (options.blgUrl) {\n\t\tgatewayInfo = await probeGatewayUrl(options.blgUrl, options);\n\t}\n\n\t// 2. Auto-probing known local infrastructure ports if enabled/unspecified\n\tif (!gatewayInfo && (options.autoProbeLocal ?? true)) {\n\t\tconst candidateUrls = [\n\t\t\t\"http://127.0.0.1:15018\", // Production BLG port\n\t\t\t\"http://127.0.0.1:15000\", // Production Nexus port\n\t\t\t\"http://127.0.0.1:13000\", // Demo Nexus port\n\t\t];\n\n\t\tfor (const url of candidateUrls) {\n\t\t\t// Skip if already probed\n\t\t\tif (options.blgUrl && url.includes(new URL(options.blgUrl).port))\n\t\t\t\tcontinue;\n\n\t\t\tgatewayInfo = await probeGatewayUrl(url, options);\n\t\t\tif (gatewayInfo) break;\n\t\t}\n\t}\n\n\t// 3. Evaluate P2P Mesh connectivity\n\tconst bootstrapNodes = options.bootstrapNodes || [];\n\tconst hasMeshBootstraps = bootstrapNodes.length > 0;\n\n\t// 4. Decide runtime mode\n\tif (gatewayInfo && hasMeshBootstraps) {\n\t\tlog.info(\n\t\t\t`[TopologyProbe] ⚡ Mode Determined: HYBRID (Gateway: ${gatewayInfo.baseUrl} + ${bootstrapNodes.length} P2P bootstraps)`,\n\t\t);\n\t\treturn {\n\t\t\tmode: \"hybrid\",\n\t\t\tgateway: gatewayInfo,\n\t\t\tmesh: {\n\t\t\t\tbootstrapNodes,\n\t\t\t\tidentityPath: options.identityPath,\n\t\t\t},\n\t\t};\n\t}\n\n\tif (gatewayInfo) {\n\t\tlog.info(\n\t\t\t`[TopologyProbe] 🚀 Mode Determined: GATEWAY (Zero-P2P overhead, direct to ${gatewayInfo.baseUrl})`,\n\t\t);\n\t\treturn {\n\t\t\tmode: \"gateway\",\n\t\t\tgateway: gatewayInfo,\n\t\t};\n\t}\n\n\tlog.info(\n\t\t`[TopologyProbe] 🌐 Mode Determined: MESH (Standard P2P DHT, Bootstraps: ${bootstrapNodes.length})`,\n\t);\n\treturn {\n\t\tmode: \"mesh\",\n\t\tmesh: {\n\t\t\tbootstrapNodes,\n\t\t\tidentityPath: options.identityPath,\n\t\t},\n\t};\n}\n"]}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { ml_dsa65 } from '@noble/post-quantum/ml-dsa.js';
|
|
2
|
+
|
|
3
|
+
// src/rpc/crypto/dilithium.ts
|
|
4
|
+
var DILITHIUM65_CONSTANTS = {
|
|
5
|
+
PUBLIC_KEY_BYTES: 1952,
|
|
6
|
+
SECRET_KEY_BYTES: 4032,
|
|
7
|
+
SIGNATURE_BYTES: 3309,
|
|
8
|
+
DEFAULT_CONTEXT: new TextEncoder().encode("LIOP-FIPS204-ML-DSA-65")
|
|
9
|
+
};
|
|
10
|
+
function normalizeMessage(message) {
|
|
11
|
+
if (typeof message === "string") {
|
|
12
|
+
return new TextEncoder().encode(message);
|
|
13
|
+
}
|
|
14
|
+
return message;
|
|
15
|
+
}
|
|
16
|
+
function canonicalizeJson(obj) {
|
|
17
|
+
if (obj === null || typeof obj !== "object") {
|
|
18
|
+
return JSON.stringify(obj);
|
|
19
|
+
}
|
|
20
|
+
if (Array.isArray(obj)) {
|
|
21
|
+
return `[${obj.map(canonicalizeJson).join(",")}]`;
|
|
22
|
+
}
|
|
23
|
+
const sortedKeys = Object.keys(obj).sort();
|
|
24
|
+
const entries = sortedKeys.map(
|
|
25
|
+
(key) => `${JSON.stringify(key)}:${canonicalizeJson(obj[key])}`
|
|
26
|
+
);
|
|
27
|
+
return `{${entries.join(",")}}`;
|
|
28
|
+
}
|
|
29
|
+
var Dilithium65Wrapper = {
|
|
30
|
+
/** Constants */
|
|
31
|
+
PUBLIC_KEY_BYTES: DILITHIUM65_CONSTANTS.PUBLIC_KEY_BYTES,
|
|
32
|
+
SECRET_KEY_BYTES: DILITHIUM65_CONSTANTS.SECRET_KEY_BYTES,
|
|
33
|
+
SIGNATURE_BYTES: DILITHIUM65_CONSTANTS.SIGNATURE_BYTES,
|
|
34
|
+
/**
|
|
35
|
+
* Generates a new ML-DSA-65 (FIPS 204) key pair.
|
|
36
|
+
* Optionally accepts a 32-byte seed for deterministic key generation.
|
|
37
|
+
*/
|
|
38
|
+
generateKeyPair(seed) {
|
|
39
|
+
if (seed && seed.length !== 32) {
|
|
40
|
+
throw new Error(
|
|
41
|
+
`ML-DSA-65 seed must be exactly 32 bytes (Received: ${seed.length})`
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
const keys = ml_dsa65.keygen(seed);
|
|
45
|
+
return {
|
|
46
|
+
publicKey: keys.publicKey,
|
|
47
|
+
secretKey: keys.secretKey
|
|
48
|
+
};
|
|
49
|
+
},
|
|
50
|
+
/**
|
|
51
|
+
* Validates and imports a raw ML-DSA-65 public key.
|
|
52
|
+
*/
|
|
53
|
+
importPublicKey(buffer) {
|
|
54
|
+
if (buffer.length !== DILITHIUM65_CONSTANTS.PUBLIC_KEY_BYTES) {
|
|
55
|
+
throw new Error(
|
|
56
|
+
`ML-DSA-65 Public Key must be exactly ${DILITHIUM65_CONSTANTS.PUBLIC_KEY_BYTES} bytes (Received: ${buffer.length})`
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
return buffer;
|
|
60
|
+
},
|
|
61
|
+
/**
|
|
62
|
+
* Signs a message using the post-quantum secret key.
|
|
63
|
+
* Supports optional domain separation context (up to 255 bytes).
|
|
64
|
+
*/
|
|
65
|
+
sign(message, secretKey, context) {
|
|
66
|
+
if (secretKey.length !== DILITHIUM65_CONSTANTS.SECRET_KEY_BYTES) {
|
|
67
|
+
throw new Error(
|
|
68
|
+
`ML-DSA-65 Secret Key must be exactly ${DILITHIUM65_CONSTANTS.SECRET_KEY_BYTES} bytes (Received: ${secretKey.length})`
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
const msgBytes = normalizeMessage(message);
|
|
72
|
+
const ctx = context ?? DILITHIUM65_CONSTANTS.DEFAULT_CONTEXT;
|
|
73
|
+
return ml_dsa65.sign(msgBytes, secretKey, { context: ctx });
|
|
74
|
+
},
|
|
75
|
+
/**
|
|
76
|
+
* Verifies an ML-DSA-65 post-quantum digital signature.
|
|
77
|
+
*/
|
|
78
|
+
verify(signature, message, publicKey, context) {
|
|
79
|
+
if (signature.length !== DILITHIUM65_CONSTANTS.SIGNATURE_BYTES) {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
if (publicKey.length !== DILITHIUM65_CONSTANTS.PUBLIC_KEY_BYTES) {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
try {
|
|
86
|
+
const msgBytes = normalizeMessage(message);
|
|
87
|
+
const ctx = context ?? DILITHIUM65_CONSTANTS.DEFAULT_CONTEXT;
|
|
88
|
+
return ml_dsa65.verify(signature, msgBytes, publicKey, { context: ctx });
|
|
89
|
+
} catch {
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
/**
|
|
94
|
+
* Signs a structured manifest (LiopManifest) using canonical JSON serialization.
|
|
95
|
+
* Returns base64-encoded signature and public key for transport over gRPC/MCP.
|
|
96
|
+
*/
|
|
97
|
+
signManifest(manifest, secretKey, publicKey) {
|
|
98
|
+
const { pqcSignature: _sig, pqcPublicKey: _pub, ...unsigned } = manifest;
|
|
99
|
+
const canonicalStr = canonicalizeJson(unsigned);
|
|
100
|
+
const sig = this.sign(canonicalStr, secretKey);
|
|
101
|
+
return {
|
|
102
|
+
signature: Buffer.from(sig).toString("base64"),
|
|
103
|
+
publicKey: Buffer.from(publicKey).toString("base64")
|
|
104
|
+
};
|
|
105
|
+
},
|
|
106
|
+
/**
|
|
107
|
+
* Verifies the post-quantum signature of a structured manifest.
|
|
108
|
+
*/
|
|
109
|
+
verifyManifest(manifest, signatureBase64, publicKeyBase64) {
|
|
110
|
+
try {
|
|
111
|
+
const sig = Buffer.from(signatureBase64, "base64");
|
|
112
|
+
const pub = Buffer.from(publicKeyBase64, "base64");
|
|
113
|
+
const { pqcSignature: _sig, pqcPublicKey: _pub, ...unsigned } = manifest;
|
|
114
|
+
const canonicalStr = canonicalizeJson(unsigned);
|
|
115
|
+
return this.verify(sig, canonicalStr, pub);
|
|
116
|
+
} catch {
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
// src/security/rbac.ts
|
|
123
|
+
var SCOPE_MAP = {
|
|
124
|
+
// Protocol lifecycle — unauthenticated (MCP spec compliance)
|
|
125
|
+
initialize: [],
|
|
126
|
+
"notifications/initialized": [],
|
|
127
|
+
"notifications/cancelled": [],
|
|
128
|
+
ping: [],
|
|
129
|
+
"server/discover": [],
|
|
130
|
+
"subscriptions/listen": [],
|
|
131
|
+
// Tool operations — require explicit authorization
|
|
132
|
+
"tools/list": ["liop:tools:list"],
|
|
133
|
+
"tools/call": ["liop:tools:call"],
|
|
134
|
+
// Resource operations — read-level access
|
|
135
|
+
"resources/list": ["liop:resources:read"],
|
|
136
|
+
"resources/read": ["liop:resources:read"],
|
|
137
|
+
"resources/templates/list": ["liop:resources:read"],
|
|
138
|
+
// Prompt/schema operations — schema-level access
|
|
139
|
+
"prompts/list": ["liop:schema:read"],
|
|
140
|
+
"prompts/get": ["liop:schema:read"]
|
|
141
|
+
};
|
|
142
|
+
function authorizeRequest(method, auth, additionalScopes) {
|
|
143
|
+
const methodScopes = SCOPE_MAP[method];
|
|
144
|
+
if (methodScopes !== void 0 && methodScopes.length === 0) {
|
|
145
|
+
return { allowed: true };
|
|
146
|
+
}
|
|
147
|
+
if (!auth) {
|
|
148
|
+
return {
|
|
149
|
+
allowed: false,
|
|
150
|
+
reason: `Authentication required for method: ${method}`
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
const needed = [...methodScopes ?? [], ...additionalScopes ?? []];
|
|
154
|
+
if (needed.length === 0) {
|
|
155
|
+
return {
|
|
156
|
+
allowed: false,
|
|
157
|
+
reason: `Unknown method: ${method}. Access denied (fail-closed).`
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
const clientScopes = new Set(auth.scopes);
|
|
161
|
+
const missing = needed.filter((s) => !clientScopes.has(s));
|
|
162
|
+
if (missing.length > 0) {
|
|
163
|
+
return {
|
|
164
|
+
allowed: false,
|
|
165
|
+
reason: `Insufficient scopes for ${method}. Missing: ${missing.join(", ")}`
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
return { allowed: true };
|
|
169
|
+
}
|
|
170
|
+
var LIOP_SCOPES = [
|
|
171
|
+
"liop:tools:list",
|
|
172
|
+
"liop:tools:call",
|
|
173
|
+
"liop:resources:read",
|
|
174
|
+
"liop:schema:read",
|
|
175
|
+
"liop:mesh:query"
|
|
176
|
+
];
|
|
177
|
+
|
|
178
|
+
export { DILITHIUM65_CONSTANTS, Dilithium65Wrapper, LIOP_SCOPES, authorizeRequest };
|
|
179
|
+
//# sourceMappingURL=chunk-VH4K4U45.js.map
|
|
180
|
+
//# sourceMappingURL=chunk-VH4K4U45.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/rpc/crypto/dilithium.ts","../src/security/rbac.ts"],"names":[],"mappings":";;;AAkBO,IAAM,qBAAA,GAAwB;AAAA,EACpC,gBAAA,EAAkB,IAAA;AAAA,EAClB,gBAAA,EAAkB,IAAA;AAAA,EAClB,eAAA,EAAiB,IAAA;AAAA,EACjB,eAAA,EAAiB,IAAI,WAAA,EAAY,CAAE,OAAO,wBAAwB;AACnE;AAKA,SAAS,iBAAiB,OAAA,EAA0C;AACnE,EAAA,IAAI,OAAO,YAAY,QAAA,EAAU;AAChC,IAAA,OAAO,IAAI,WAAA,EAAY,CAAE,MAAA,CAAO,OAAO,CAAA;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A,MACN,OAAA,EAAS,KAAA;AAAA,MACT,MAAA,EAAQ,mBAAmB,MAAM,CAAA,8BAAA;AAAA,KAClC;AAAA,EACD;AAGA,EAAA,MAAM,YAAA,GAAe,IAAI,GAAA,CAAI,IAAA,CAAK,MAAM,CAAA;AACxC,EAAA,MAAM,OAAA,GAAU,OAAO,MAAA,CAAO,CAAC,MAAM,CAAC,YAAA,CAAa,GAAA,CAAI,CAAC,CAAC,CAAA;AAEzD,EAAA,IAAI,OAAA,CAAQ,SAAS,CAAA,EAAG;AACvB,IAAA,OAAO;AAAA,MACN,OAAA,EAAS,KAAA;AAAA,MACT,QAAQ,CAAA,wBAAA,EAA2B,MAAM,cAAc,OAAA,CAAQ,IAAA,CAAK,IAAI,CAAC,CAAA;AAAA,KAC1E;AAAA,EACD;AAEA,EAAA,OAAO,EAAE,SAAS,IAAA,EAAK;AACxB;AAMO,IAAM,WAAA,GAAc;AAAA,EAC1B,iBAAA;AAAA,EACA,iBAAA;AAAA,EACA,qBAAA;AAAA,EACA,kBAAA;AAAA,EACA;AACD","file":"chunk-VH4K4U45.js","sourcesContent":["// Copyright 2026 Nekzus Solutions and contributors\n// SPDX-License-Identifier: Apache-2.0\n\n/**\n * LIOP Post-Quantum Digital Signature Wrapper\n * Implements ML-DSA-65 (CRYSTALS-Dilithium, NIST FIPS 204) for quantum-resistant\n * manifest attestation, node revocation receipts, and cryptographic integrity.\n *\n * Characteristics:\n * - Security Category: NIST Level 3 (~AES-192 equivalent quantum resistance)\n * - Public Key Length: 1952 bytes\n * - Secret Key Length: 4032 bytes\n * - Signature Length: 3309 bytes\n * - Implementation: Pure TypeScript/JS via @noble/post-quantum\n */\n\nimport { ml_dsa65 } from \"@noble/post-quantum/ml-dsa.js\";\n\nexport const DILITHIUM65_CONSTANTS = {\n\tPUBLIC_KEY_BYTES: 1952,\n\tSECRET_KEY_BYTES: 4032,\n\tSIGNATURE_BYTES: 3309,\n\tDEFAULT_CONTEXT: new TextEncoder().encode(\"LIOP-FIPS204-ML-DSA-65\"),\n} as const;\n\n/**\n * Deterministically normalizes a message into a Uint8Array.\n */\nfunction normalizeMessage(message: Uint8Array | string): Uint8Array {\n\tif (typeof message === \"string\") {\n\t\treturn new TextEncoder().encode(message);\n\t}\n\treturn message;\n}\n\n/**\n * Deterministic canonical JSON serializer to ensure stable cryptographic hashing\n * regardless of key ordering in JavaScript objects.\n */\nfunction canonicalizeJson(obj: unknown): string {\n\tif (obj === null || typeof obj !== \"object\") {\n\t\treturn JSON.stringify(obj);\n\t}\n\tif (Array.isArray(obj)) {\n\t\treturn `[${obj.map(canonicalizeJson).join(\",\")}]`;\n\t}\n\tconst sortedKeys = Object.keys(obj as Record<string, unknown>).sort();\n\tconst entries = sortedKeys.map(\n\t\t(key) =>\n\t\t\t`${JSON.stringify(key)}:${canonicalizeJson((obj as Record<string, unknown>)[key])}`,\n\t);\n\treturn `{${entries.join(\",\")}}`;\n}\n\nexport const Dilithium65Wrapper = {\n\t/** Constants */\n\tPUBLIC_KEY_BYTES: DILITHIUM65_CONSTANTS.PUBLIC_KEY_BYTES,\n\tSECRET_KEY_BYTES: DILITHIUM65_CONSTANTS.SECRET_KEY_BYTES,\n\tSIGNATURE_BYTES: DILITHIUM65_CONSTANTS.SIGNATURE_BYTES,\n\n\t/**\n\t * Generates a new ML-DSA-65 (FIPS 204) key pair.\n\t * Optionally accepts a 32-byte seed for deterministic key generation.\n\t */\n\tgenerateKeyPair(seed?: Uint8Array): {\n\t\tpublicKey: Uint8Array;\n\t\tsecretKey: Uint8Array;\n\t} {\n\t\tif (seed && seed.length !== 32) {\n\t\t\tthrow new Error(\n\t\t\t\t`ML-DSA-65 seed must be exactly 32 bytes (Received: ${seed.length})`,\n\t\t\t);\n\t\t}\n\t\tconst keys = ml_dsa65.keygen(seed);\n\t\treturn {\n\t\t\tpublicKey: keys.publicKey,\n\t\t\tsecretKey: keys.secretKey,\n\t\t};\n\t},\n\n\t/**\n\t * Validates and imports a raw ML-DSA-65 public key.\n\t */\n\timportPublicKey(buffer: Uint8Array): Uint8Array {\n\t\tif (buffer.length !== DILITHIUM65_CONSTANTS.PUBLIC_KEY_BYTES) {\n\t\t\tthrow new Error(\n\t\t\t\t`ML-DSA-65 Public Key must be exactly ${DILITHIUM65_CONSTANTS.PUBLIC_KEY_BYTES} bytes (Received: ${buffer.length})`,\n\t\t\t);\n\t\t}\n\t\treturn buffer;\n\t},\n\n\t/**\n\t * Signs a message using the post-quantum secret key.\n\t * Supports optional domain separation context (up to 255 bytes).\n\t */\n\tsign(\n\t\tmessage: Uint8Array | string,\n\t\tsecretKey: Uint8Array,\n\t\tcontext?: Uint8Array,\n\t): Uint8Array {\n\t\tif (secretKey.length !== DILITHIUM65_CONSTANTS.SECRET_KEY_BYTES) {\n\t\t\tthrow new Error(\n\t\t\t\t`ML-DSA-65 Secret Key must be exactly ${DILITHIUM65_CONSTANTS.SECRET_KEY_BYTES} bytes (Received: ${secretKey.length})`,\n\t\t\t);\n\t\t}\n\t\tconst msgBytes = normalizeMessage(message);\n\t\tconst ctx = context ?? DILITHIUM65_CONSTANTS.DEFAULT_CONTEXT;\n\t\treturn ml_dsa65.sign(msgBytes, secretKey, { context: ctx });\n\t},\n\n\t/**\n\t * Verifies an ML-DSA-65 post-quantum digital signature.\n\t */\n\tverify(\n\t\tsignature: Uint8Array,\n\t\tmessage: Uint8Array | string,\n\t\tpublicKey: Uint8Array,\n\t\tcontext?: Uint8Array,\n\t): boolean {\n\t\tif (signature.length !== DILITHIUM65_CONSTANTS.SIGNATURE_BYTES) {\n\t\t\treturn false;\n\t\t}\n\t\tif (publicKey.length !== DILITHIUM65_CONSTANTS.PUBLIC_KEY_BYTES) {\n\t\t\treturn false;\n\t\t}\n\t\ttry {\n\t\t\tconst msgBytes = normalizeMessage(message);\n\t\t\tconst ctx = context ?? DILITHIUM65_CONSTANTS.DEFAULT_CONTEXT;\n\t\t\treturn ml_dsa65.verify(signature, msgBytes, publicKey, { context: ctx });\n\t\t} catch {\n\t\t\treturn false;\n\t\t}\n\t},\n\n\t/**\n\t * Signs a structured manifest (LiopManifest) using canonical JSON serialization.\n\t * Returns base64-encoded signature and public key for transport over gRPC/MCP.\n\t */\n\tsignManifest(\n\t\tmanifest: Record<string, unknown>,\n\t\tsecretKey: Uint8Array,\n\t\tpublicKey: Uint8Array,\n\t): { signature: string; publicKey: string } {\n\t\tconst { pqcSignature: _sig, pqcPublicKey: _pub, ...unsigned } = manifest;\n\t\tconst canonicalStr = canonicalizeJson(unsigned);\n\t\tconst sig = this.sign(canonicalStr, secretKey);\n\t\treturn {\n\t\t\tsignature: Buffer.from(sig).toString(\"base64\"),\n\t\t\tpublicKey: Buffer.from(publicKey).toString(\"base64\"),\n\t\t};\n\t},\n\n\t/**\n\t * Verifies the post-quantum signature of a structured manifest.\n\t */\n\tverifyManifest(\n\t\tmanifest: Record<string, unknown>,\n\t\tsignatureBase64: string,\n\t\tpublicKeyBase64: string,\n\t): boolean {\n\t\ttry {\n\t\t\tconst sig = Buffer.from(signatureBase64, \"base64\");\n\t\t\tconst pub = Buffer.from(publicKeyBase64, \"base64\");\n\t\t\tconst { pqcSignature: _sig, pqcPublicKey: _pub, ...unsigned } = manifest;\n\t\t\tconst canonicalStr = canonicalizeJson(unsigned);\n\t\t\treturn this.verify(sig, canonicalStr, pub);\n\t\t} catch {\n\t\t\treturn false;\n\t\t}\n\t},\n};\n","// Copyright 2026 Nekzus Solutions and contributors\n// SPDX-License-Identifier: Apache-2.0\n\n/**\n * LIOP RBAC Engine — Scope-Based Authorization\n *\n * Maps MCP JSON-RPC methods to required LIOP OAuth scopes.\n * Enforces least-privilege access at the router level before\n * any tool execution or resource read occurs.\n *\n * Standards: NIST SP 800-207 §4.3 (least privilege), OWASP LLM06 (Excessive Agency),\n * OWASP API-A01 (Broken Access Control)\n */\n\nimport type { AuthInfo } from \"./jwt-validator.js\";\n\n/**\n * Maps MCP JSON-RPC methods to the LIOP scopes required to invoke them.\n * Empty array = no authentication required (public endpoints).\n */\nconst SCOPE_MAP: Readonly<Record<string, readonly string[]>> = {\n\t// Protocol lifecycle — unauthenticated (MCP spec compliance)\n\tinitialize: [],\n\t\"notifications/initialized\": [],\n\t\"notifications/cancelled\": [],\n\tping: [],\n\t\"server/discover\": [],\n\t\"subscriptions/listen\": [],\n\n\t// Tool operations — require explicit authorization\n\t\"tools/list\": [\"liop:tools:list\"],\n\t\"tools/call\": [\"liop:tools:call\"],\n\n\t// Resource operations — read-level access\n\t\"resources/list\": [\"liop:resources:read\"],\n\t\"resources/read\": [\"liop:resources:read\"],\n\t\"resources/templates/list\": [\"liop:resources:read\"],\n\n\t// Prompt/schema operations — schema-level access\n\t\"prompts/list\": [\"liop:schema:read\"],\n\t\"prompts/get\": [\"liop:schema:read\"],\n};\n\n/**\n * Authorization result with optional denial reason for audit logging.\n */\nexport interface AuthorizationResult {\n\tallowed: boolean;\n\treason?: string;\n}\n\n/**\n * Evaluates whether a request is authorized based on JWT scopes.\n *\n * Decision logic:\n * 1. Methods with no required scopes (initialize, ping) → always allowed.\n * 2. Methods with required scopes but no auth → denied.\n * 3. Methods with required scopes → all scopes must be present in the JWT.\n * 4. Unknown methods with no auth → denied (fail-closed per NIST SP 800-207).\n *\n * @param method - MCP JSON-RPC method name (e.g., \"tools/call\")\n * @param auth - Validated JWT context, or null if unauthenticated\n * @param additionalScopes - Extra scopes required by specific node configuration\n */\nexport function authorizeRequest(\n\tmethod: string,\n\tauth: AuthInfo | null,\n\tadditionalScopes?: readonly string[],\n): AuthorizationResult {\n\tconst methodScopes = SCOPE_MAP[method];\n\n\t// Methods explicitly marked as public (empty scope array) pass freely\n\tif (methodScopes !== undefined && methodScopes.length === 0) {\n\t\treturn { allowed: true };\n\t}\n\n\t// If no auth context and method requires scopes → deny\n\tif (!auth) {\n\t\treturn {\n\t\t\tallowed: false,\n\t\t\treason: `Authentication required for method: ${method}`,\n\t\t};\n\t}\n\n\t// Merge method-level scopes with node-level additional scopes\n\tconst needed = [...(methodScopes ?? []), ...(additionalScopes ?? [])];\n\n\t// If no scopes needed (unknown method, no additional) → fail-closed\n\tif (needed.length === 0) {\n\t\treturn {\n\t\t\tallowed: false,\n\t\t\treason: `Unknown method: ${method}. Access denied (fail-closed).`,\n\t\t};\n\t}\n\n\t// Verify all required scopes are present in the JWT\n\tconst clientScopes = new Set(auth.scopes);\n\tconst missing = needed.filter((s) => !clientScopes.has(s));\n\n\tif (missing.length > 0) {\n\t\treturn {\n\t\t\tallowed: false,\n\t\t\treason: `Insufficient scopes for ${method}. Missing: ${missing.join(\", \")}`,\n\t\t};\n\t}\n\n\treturn { allowed: true };\n}\n\n/**\n * All LIOP OAuth scopes supported by the protocol.\n * Used for PRM metadata and client registration.\n */\nexport const LIOP_SCOPES = [\n\t\"liop:tools:list\",\n\t\"liop:tools:call\",\n\t\"liop:resources:read\",\n\t\"liop:schema:read\",\n\t\"liop:mesh:query\",\n] as const;\n\nexport type LiopScope = (typeof LIOP_SCOPES)[number];\n"]}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// src/server/output-sanitizer.ts
|
|
2
|
+
var DEFAULT_CONFIG = {
|
|
3
|
+
maxDecimalPlaces: 4,
|
|
4
|
+
clampNonNegative: true
|
|
5
|
+
};
|
|
6
|
+
function sanitizeOutput(output, config) {
|
|
7
|
+
const merged = { ...DEFAULT_CONFIG, ...config };
|
|
8
|
+
const seen = /* @__PURE__ */ new WeakSet();
|
|
9
|
+
function walk(node) {
|
|
10
|
+
if (node === null || node === void 0) {
|
|
11
|
+
return node;
|
|
12
|
+
}
|
|
13
|
+
if (typeof node === "number") {
|
|
14
|
+
if (!Number.isFinite(node)) {
|
|
15
|
+
return node;
|
|
16
|
+
}
|
|
17
|
+
let value = node;
|
|
18
|
+
if (merged.clampNonNegative && value < 0) {
|
|
19
|
+
value = 0;
|
|
20
|
+
}
|
|
21
|
+
const factor = 10 ** merged.maxDecimalPlaces;
|
|
22
|
+
value = Math.round(value * factor) / factor;
|
|
23
|
+
return value;
|
|
24
|
+
}
|
|
25
|
+
if (typeof node === "string" || typeof node === "boolean") {
|
|
26
|
+
return node;
|
|
27
|
+
}
|
|
28
|
+
if (typeof node === "object") {
|
|
29
|
+
if (seen.has(node)) {
|
|
30
|
+
return node;
|
|
31
|
+
}
|
|
32
|
+
seen.add(node);
|
|
33
|
+
if (Array.isArray(node)) {
|
|
34
|
+
return node.map((item) => walk(item));
|
|
35
|
+
}
|
|
36
|
+
const result = {};
|
|
37
|
+
for (const [key, val] of Object.entries(
|
|
38
|
+
node
|
|
39
|
+
)) {
|
|
40
|
+
result[key] = walk(val);
|
|
41
|
+
}
|
|
42
|
+
return result;
|
|
43
|
+
}
|
|
44
|
+
return node;
|
|
45
|
+
}
|
|
46
|
+
return walk(output);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export { sanitizeOutput };
|
|
50
|
+
//# sourceMappingURL=chunk-Y62GORQF.js.map
|
|
51
|
+
//# sourceMappingURL=chunk-Y62GORQF.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/server/output-sanitizer.ts"],"names":[],"mappings":";AAkBA,IAAM,cAAA,GAAkD;AAAA,EACvD,gBAAA,EAAkB,CAAA;AAAA,EAClB,gBAAA,EAAkB;AACnB,CAAA;AASO,SAAS,cAAA,CACf,QACA,MAAA,EACU;AACV,EAAA,MAAM,MAAA,GAAS,EAAE,GAAG,cAAA,EAAgB,GAAG,MAAA,EAAO;AAC9C,EAAA,MAAM,IAAA,uBAAW,OAAA,EAAgB;AAEjC,EAAA,SAAS,KAAK,IAAA,EAAwB;AACrC,IAAA,IAAI,IAAA,KAAS,IAAA,IAAQ,IAAA,KAAS,MAAA,EAAW;AACxC,MAAA,OAAO,IAAA;AAAA,IACR;AAEA,IAAA,IAAI,OAAO,SAAS,QAAA,EAAU;AAC7B,MAAA,IAAI,CAAC,MAAA,CAAO,QAAA,CAAS,IAAI,CAAA,EAAG;AAC3B,QAAA,OAAO,IAAA;AAAA,MACR;AAEA,MAAA,IAAI,KAAA,GAAQ,IAAA;AAGZ,MAAA,IAAI,MAAA,CAAO,gBAAA,IAAoB,KAAA,GAAQ,CAAA,EAAG;AACzC,QAAA,KAAA,GAAQ,CAAA;AAAA,MACT;AAGA,MAAA,MAAM,MAAA,GAAS,MAAM,MAAA,CAAO,gBAAA;AAC5B,MAAA,KAAA,GAAQ,IAAA,CAAK,KAAA,CAAM,KAAA,GAAQ,MAAM,CAAA,GAAI,MAAA;AAErC,MAAA,OAAO,KAAA;AAAA,IACR;AAEA,IAAA,IAAI,OAAO,IAAA,KAAS,QAAA,IAAY,OAAO,SAAS,SAAA,EAAW;AAC1D,MAAA,OAAO,IAAA;AAAA,IACR;AAEA,IAAA,IAAI,OAAO,SAAS,QAAA,EAAU;AAE7B,MAAA,IAAI,IAAA,CAAK,GAAA,CAAI,IAAc,CAAA,EAAG;AAC7B,QAAA,OAAO,IAAA;AAAA,MACR;AACA,MAAA,IAAA,CAAK,IAAI,IAAc,CAAA;AAEvB,MAAA,IAAI,KAAA,CAAM,OAAA,CAAQ,IAAI,CAAA,EAAG;AACxB,QAAA,OAAO,KAAK,GAAA,CAAI,CAAC,IAAA,KAAS,IAAA,CAAK,IAAI,CAAC,CAAA;AAAA,MACrC;AAEA,MAAA,MAAM,SAAkC,EAAC;AACzC,MAAA,KAAA,MAAW,CAAC,GAAA,EAAK,GAAG,CAAA,IAAK,MAAA,CAAO,OAAA;AAAA,QAC/B;AAAA,OACD,EAAG;AACF,QAAA,MAAA,CAAO,GAAG,CAAA,GAAI,IAAA,CAAK,GAAG,CAAA;AAAA,MACvB;AACA,MAAA,OAAO,MAAA;AAAA,IACR;AAEA,IAAA,OAAO,IAAA;AAAA,EACR;AAEA,EAAA,OAAO,KAAK,MAAM,CAAA;AACnB","file":"chunk-Y62GORQF.js","sourcesContent":["// Copyright 2026 Nekzus Solutions and contributors\n// SPDX-License-Identifier: Apache-2.0\n\n/**\n * LIOP Egress Shield Output Sanitizer (NIST SP 800-226 and OWASP DLP 2025 compliant)\n * Recursively sanitizes execution outputs by rounding floating-point numbers\n * and clamping negative values to zero floor where appropriate.\n *\n * Implements absolute immutability, returning a fresh copy of the data.\n */\n\nexport interface OutputSanitizerConfig {\n\t/** Maximum decimal places for floating-point values (default: 4) */\n\tmaxDecimalPlaces?: number;\n\t/** Clamp negative values to zero floor (default: true) */\n\tclampNonNegative?: boolean;\n}\n\nconst DEFAULT_CONFIG: Required<OutputSanitizerConfig> = {\n\tmaxDecimalPlaces: 4,\n\tclampNonNegative: true,\n};\n\n/**\n * Recursively walks a JSON-like tree, rounding floats and clamping negative values.\n *\n * @param output - The raw or DP-modified output object/value to sanitize\n * @param config - Sanitization parameters (rounding depth, negative clamping)\n * @returns A sanitized deep copy of the output\n */\nexport function sanitizeOutput(\n\toutput: unknown,\n\tconfig?: OutputSanitizerConfig,\n): unknown {\n\tconst merged = { ...DEFAULT_CONFIG, ...config };\n\tconst seen = new WeakSet<object>();\n\n\tfunction walk(node: unknown): unknown {\n\t\tif (node === null || node === undefined) {\n\t\t\treturn node;\n\t\t}\n\n\t\tif (typeof node === \"number\") {\n\t\t\tif (!Number.isFinite(node)) {\n\t\t\t\treturn node;\n\t\t\t}\n\n\t\t\tlet value = node;\n\n\t\t\t// 1. Clamp negative values to 0 if configured\n\t\t\tif (merged.clampNonNegative && value < 0) {\n\t\t\t\tvalue = 0;\n\t\t\t}\n\n\t\t\t// 2. Round to maximum decimal places\n\t\t\tconst factor = 10 ** merged.maxDecimalPlaces;\n\t\t\tvalue = Math.round(value * factor) / factor;\n\n\t\t\treturn value;\n\t\t}\n\n\t\tif (typeof node === \"string\" || typeof node === \"boolean\") {\n\t\t\treturn node;\n\t\t}\n\n\t\tif (typeof node === \"object\") {\n\t\t\t// Circular reference protection\n\t\t\tif (seen.has(node as object)) {\n\t\t\t\treturn node;\n\t\t\t}\n\t\t\tseen.add(node as object);\n\n\t\t\tif (Array.isArray(node)) {\n\t\t\t\treturn node.map((item) => walk(item));\n\t\t\t}\n\n\t\t\tconst result: Record<string, unknown> = {};\n\t\t\tfor (const [key, val] of Object.entries(\n\t\t\t\tnode as Record<string, unknown>,\n\t\t\t)) {\n\t\t\t\tresult[key] = walk(val);\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\treturn node;\n\t}\n\n\treturn walk(output);\n}\n"]}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { Buffer } from 'buffer';
|
|
2
|
+
import { mkdir, writeFile, readFile } from 'fs/promises';
|
|
3
|
+
import { dirname } from 'path';
|
|
4
|
+
import { generateKey } from '@libp2p/pnet';
|
|
5
|
+
|
|
6
|
+
// src/mesh/swarm-key.ts
|
|
7
|
+
var SWARM_KEY_BYTE_LENGTH = 95;
|
|
8
|
+
function createSwarmKey() {
|
|
9
|
+
const psk = new Uint8Array(SWARM_KEY_BYTE_LENGTH);
|
|
10
|
+
generateKey(psk);
|
|
11
|
+
return psk;
|
|
12
|
+
}
|
|
13
|
+
function serializeSwarmKey(psk) {
|
|
14
|
+
if (psk.length !== SWARM_KEY_BYTE_LENGTH) {
|
|
15
|
+
throw new Error(
|
|
16
|
+
`Invalid Swarm Key length: expected ${SWARM_KEY_BYTE_LENGTH} bytes, got ${psk.length}`
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
return Buffer.from(psk).toString("base64");
|
|
20
|
+
}
|
|
21
|
+
function deserializeSwarmKey(base64Str) {
|
|
22
|
+
const trimmed = base64Str.trim();
|
|
23
|
+
const buf = Buffer.from(trimmed, "base64");
|
|
24
|
+
if (buf.length !== SWARM_KEY_BYTE_LENGTH) {
|
|
25
|
+
throw new Error(
|
|
26
|
+
`Invalid deserialized Swarm Key: expected ${SWARM_KEY_BYTE_LENGTH} bytes, got ${buf.length}`
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
30
|
+
}
|
|
31
|
+
function parseSwarmKey(rawText) {
|
|
32
|
+
const trimmed = rawText.trim();
|
|
33
|
+
if (trimmed.startsWith("/key/swarm/psk/")) {
|
|
34
|
+
const normalized = trimmed.replace(/\r\n/g, "\n").trimEnd();
|
|
35
|
+
const bytes = new TextEncoder().encode(normalized);
|
|
36
|
+
if (bytes.length === SWARM_KEY_BYTE_LENGTH) {
|
|
37
|
+
return bytes;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return deserializeSwarmKey(trimmed);
|
|
41
|
+
}
|
|
42
|
+
async function saveSwarmKey(psk, filePath) {
|
|
43
|
+
if (psk.length !== SWARM_KEY_BYTE_LENGTH) {
|
|
44
|
+
throw new Error(
|
|
45
|
+
`Cannot save invalid Swarm Key: expected ${SWARM_KEY_BYTE_LENGTH} bytes, got ${psk.length}`
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
await mkdir(dirname(filePath), { recursive: true });
|
|
49
|
+
await writeFile(filePath, psk);
|
|
50
|
+
}
|
|
51
|
+
async function loadSwarmKey(filePath) {
|
|
52
|
+
const fileBuffer = await readFile(filePath);
|
|
53
|
+
if (fileBuffer.length === SWARM_KEY_BYTE_LENGTH) {
|
|
54
|
+
return new Uint8Array(
|
|
55
|
+
fileBuffer.buffer,
|
|
56
|
+
fileBuffer.byteOffset,
|
|
57
|
+
fileBuffer.byteLength
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
const text = fileBuffer.toString("utf-8");
|
|
61
|
+
return parseSwarmKey(text);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export { SWARM_KEY_BYTE_LENGTH, createSwarmKey, deserializeSwarmKey, loadSwarmKey, parseSwarmKey, saveSwarmKey, serializeSwarmKey };
|
|
65
|
+
//# sourceMappingURL=chunk-ZP3VVXOI.js.map
|
|
66
|
+
//# sourceMappingURL=chunk-ZP3VVXOI.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/mesh/swarm-key.ts"],"names":[],"mappings":";;;;;;AAQO,IAAM,qBAAA,GAAwB;AAM9B,SAAS,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CAAM,WAAW,qBAAA,EAAuB;AAC3C,MAAA,OAAO,KAAA;AAAA,IACR;AAAA,EACD;AAEA,EAAA,OAAO,oBAAoB,OAAO,CAAA;AACnC;AAKA,eAAsB,YAAA,CACrB,KACA,QAAA,EACgB;AAChB,EAAA,IAAI,GAAA,CAAI,WAAW,qBAAA,EAAuB;AACzC,IAAA,MAAM,IAAI,KAAA;AAAA,MACT,CAAA,wCAAA,EAA2C,qBAAqB,CAAA,YAAA,EAAe,GAAA,CAAI,MAAM,CAAA;AAAA,KAC1F;AAAA,EACD;AACA,EAAA,MAAM,MAAM,OAAA,CAAQ,QAAQ,GAAG,EAAE,SAAA,EAAW,MAAM,CAAA;AAClD,EAAA,MAAM,SAAA,CAAU,UAAU,GAAG,CAAA;AAC9B;AAMA,eAAsB,aAAa,QAAA,EAAuC;AACzE,EAAA,MAAM,UAAA,GAAa,MAAM,QAAA,CAAS,QAAQ,CAAA;AAC1C,EAAA,IAAI,UAAA,CAAW,WAAW,qBAAA,EAAuB;AAChD,IAAA,OAAO,IAAI,UAAA;AAAA,MACV,UAAA,CAAW,MAAA;AAAA,MACX,UAAA,CAAW,UAAA;AAAA,MACX,UAAA,CAAW;AAAA,KACZ;AAAA,EACD;AACA,EAAA,MAAM,IAAA,GAAO,UAAA,CAAW,QAAA,CAAS,OAAO,CAAA;AACxC,EAAA,OAAO,cAAc,IAAI,CAAA;AAC1B","file":"chunk-ZP3VVXOI.js","sourcesContent":["// Copyright 2026 Nekzus Solutions and contributors\n// SPDX-License-Identifier: Apache-2.0\n\nimport { Buffer } from \"node:buffer\";\nimport { mkdir, readFile, writeFile } from \"node:fs/promises\";\nimport { dirname } from \"node:path\";\nimport { generateKey } from \"@libp2p/pnet\";\n\nexport const SWARM_KEY_BYTE_LENGTH = 95;\n\n/**\n * Creates a freshly generated 95-byte Pre-Shared Key (PSK) for libp2p Private Networks (pnet).\n * Follows the canonical format `/key/swarm/psk/1.0.0/\\n/base16/\\n<hex>\\n`.\n */\nexport function createSwarmKey(): Uint8Array {\n\tconst psk = new Uint8Array(SWARM_KEY_BYTE_LENGTH);\n\tgenerateKey(psk);\n\treturn psk;\n}\n\n/**\n * Serializes a 95-byte PSK into a Base64 string for safe environment variable passing or JSON config.\n */\nexport function serializeSwarmKey(psk: Uint8Array): string {\n\tif (psk.length !== SWARM_KEY_BYTE_LENGTH) {\n\t\tthrow new Error(\n\t\t\t`Invalid Swarm Key length: expected ${SWARM_KEY_BYTE_LENGTH} bytes, got ${psk.length}`,\n\t\t);\n\t}\n\treturn Buffer.from(psk).toString(\"base64\");\n}\n\n/**\n * Deserializes a Base64-encoded string into a 95-byte PSK Uint8Array.\n */\nexport function deserializeSwarmKey(base64Str: string): Uint8Array {\n\tconst trimmed = base64Str.trim();\n\tconst buf = Buffer.from(trimmed, \"base64\");\n\tif (buf.length !== SWARM_KEY_BYTE_LENGTH) {\n\t\tthrow new Error(\n\t\t\t`Invalid deserialized Swarm Key: expected ${SWARM_KEY_BYTE_LENGTH} bytes, got ${buf.length}`,\n\t\t);\n\t}\n\treturn new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);\n}\n\n/**\n * Parses raw text format PSK or Base64 string into a 95-byte PSK Uint8Array.\n * Allows loading either the canonical multiline text (`/key/swarm/psk/1.0.0/...`) or Base64.\n */\nexport function parseSwarmKey(rawText: string): Uint8Array {\n\tconst trimmed = rawText.trim();\n\t// Check if this is canonical raw text format\n\tif (trimmed.startsWith(\"/key/swarm/psk/\")) {\n\t\tconst normalized = trimmed.replace(/\\r\\n/g, \"\\n\").trimEnd();\n\t\tconst bytes = new TextEncoder().encode(normalized);\n\t\tif (bytes.length === SWARM_KEY_BYTE_LENGTH) {\n\t\t\treturn bytes;\n\t\t}\n\t}\n\t// Fallback to Base64 deserialization\n\treturn deserializeSwarmKey(trimmed);\n}\n\n/**\n * Saves a 95-byte Swarm Key to a file on disk (written as canonical text).\n */\nexport async function saveSwarmKey(\n\tpsk: Uint8Array,\n\tfilePath: string,\n): Promise<void> {\n\tif (psk.length !== SWARM_KEY_BYTE_LENGTH) {\n\t\tthrow new Error(\n\t\t\t`Cannot save invalid Swarm Key: expected ${SWARM_KEY_BYTE_LENGTH} bytes, got ${psk.length}`,\n\t\t);\n\t}\n\tawait mkdir(dirname(filePath), { recursive: true });\n\tawait writeFile(filePath, psk);\n}\n\n/**\n * Loads a 95-byte Swarm Key from a file on disk.\n * Supports both raw binary/canonical format and Base64-encoded text.\n */\nexport async function loadSwarmKey(filePath: string): Promise<Uint8Array> {\n\tconst fileBuffer = await readFile(filePath);\n\tif (fileBuffer.length === SWARM_KEY_BYTE_LENGTH) {\n\t\treturn new Uint8Array(\n\t\t\tfileBuffer.buffer,\n\t\t\tfileBuffer.byteOffset,\n\t\t\tfileBuffer.byteLength,\n\t\t);\n\t}\n\tconst text = fileBuffer.toString(\"utf-8\");\n\treturn parseSwarmKey(text);\n}\n"]}
|
package/dist/client.d.ts
ADDED
package/dist/client.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { LiopClient } from './chunk-T7R5HUFD.js';
|
|
2
|
+
import './chunk-ESRXG36Y.js';
|
|
3
|
+
import './chunk-DZ2FQGJD.js';
|
|
4
|
+
import './chunk-PEN3KFLF.js';
|
|
5
|
+
import './chunk-IK7CGWAZ.js';
|
|
6
|
+
import './chunk-7PITYWOV.js';
|
|
7
|
+
import './chunk-TKRX6CFI.js';
|
|
8
|
+
import './chunk-PAICJCKJ.js';
|
|
9
|
+
import './chunk-EG46XMJT.js';
|
|
10
|
+
import './chunk-7RXOIDXP.js';
|
|
11
|
+
import './chunk-HA6YZ42O.js';
|
|
12
|
+
//# sourceMappingURL=client.js.map
|
|
13
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"client.js"}
|
package/dist/gateway.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { LiopHybridGateway } from './chunk-3L2O2XKG.js';
|
|
2
|
+
import './chunk-L6J72C5X.js';
|
|
3
|
+
import './chunk-DZ2FQGJD.js';
|
|
4
|
+
import './chunk-PEN3KFLF.js';
|
|
5
|
+
import './chunk-IK7CGWAZ.js';
|
|
6
|
+
import './chunk-7PITYWOV.js';
|
|
7
|
+
import './chunk-VH4K4U45.js';
|
|
8
|
+
import './chunk-TKRX6CFI.js';
|
|
9
|
+
import './chunk-PAICJCKJ.js';
|
|
10
|
+
import './chunk-EG46XMJT.js';
|
|
11
|
+
import './chunk-HA6YZ42O.js';
|
|
12
|
+
//# sourceMappingURL=gateway.js.map
|
|
13
|
+
//# sourceMappingURL=gateway.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"gateway.js"}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { a as MeshNode } from './node-B0b2vUFS.js';
|
|
2
|
+
import { L as LiopServer } from './index-DoW2gzBZ.js';
|
|
3
|
+
import { L as LiopVerifier } from './verifier-COnid_dg.js';
|
|
4
|
+
import { b as McpRequest, M as McpEra, A as AuthInfo, c as McpResponse } from './types-lJIxBlWF.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* LIOP Sliding-Window Rate Limiter
|
|
8
|
+
*
|
|
9
|
+
* High-performance, zero-dependency in-memory rate limiter designed
|
|
10
|
+
* to protect the LIOP Hybrid Gateway and Mesh Nodes against Denial of Service (DoS),
|
|
11
|
+
* worker pool exhaustion, and brute-force attacks.
|
|
12
|
+
*
|
|
13
|
+
* Conforms to OWASP API Security Top 10 (API4:2023 - Unrestricted Resource Consumption).
|
|
14
|
+
*/
|
|
15
|
+
interface RateLimiterOptions {
|
|
16
|
+
/** Window duration in milliseconds (default: 60,000ms = 1 minute) */
|
|
17
|
+
windowMs?: number;
|
|
18
|
+
/** Maximum number of allowed requests per window (default: 120) */
|
|
19
|
+
maxRequests?: number;
|
|
20
|
+
}
|
|
21
|
+
interface RateLimitStatus {
|
|
22
|
+
allowed: boolean;
|
|
23
|
+
remaining: number;
|
|
24
|
+
limit: number;
|
|
25
|
+
resetMs: number;
|
|
26
|
+
}
|
|
27
|
+
declare class InMemoryRateLimiter {
|
|
28
|
+
private readonly windowMs;
|
|
29
|
+
private readonly maxRequests;
|
|
30
|
+
private readonly records;
|
|
31
|
+
private cleanupTimer?;
|
|
32
|
+
constructor(options?: RateLimiterOptions);
|
|
33
|
+
/**
|
|
34
|
+
* Evaluates whether a request from the given key (IP, token, or clientId) is permitted.
|
|
35
|
+
*
|
|
36
|
+
* @param key Identifier for the client (e.g., remote IP or OAuth client ID)
|
|
37
|
+
* @returns Status containing allowed boolean, remaining quota, and time until reset
|
|
38
|
+
*/
|
|
39
|
+
check(key: string): RateLimitStatus;
|
|
40
|
+
/**
|
|
41
|
+
* Explicitly resets the rate limit bucket for a given key.
|
|
42
|
+
*/
|
|
43
|
+
reset(key: string): void;
|
|
44
|
+
/**
|
|
45
|
+
* Cleans up expired rate-limiting buckets to prevent memory leaks.
|
|
46
|
+
*/
|
|
47
|
+
cleanup(): void;
|
|
48
|
+
/**
|
|
49
|
+
* Destroys internal timers and clears records.
|
|
50
|
+
*/
|
|
51
|
+
close(): void;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* LIOP MCP Router
|
|
56
|
+
*
|
|
57
|
+
* Core logic for routing MCP requests to local or remote LIOP providers.
|
|
58
|
+
* Decoupled from transport (HTTP/Stdio).
|
|
59
|
+
*
|
|
60
|
+
* All tool discovery and port resolution is DYNAMIC via the
|
|
61
|
+
* /liop/manifest/1.0.0 protocol stream over Kademlia DHT.
|
|
62
|
+
*/
|
|
63
|
+
declare class LiopMcpRouter {
|
|
64
|
+
private liopServer;
|
|
65
|
+
private meshNode;
|
|
66
|
+
private defaultRpcPort;
|
|
67
|
+
/** Cached manifests from remote peers. Key = PeerID */
|
|
68
|
+
private manifestCache;
|
|
69
|
+
/** Guards against concurrent discovery storms */
|
|
70
|
+
private currentDiscovery;
|
|
71
|
+
/** Verifier for Tier-0 integrity checks */
|
|
72
|
+
verifier: LiopVerifier;
|
|
73
|
+
/** Callback when new remote tools are discovered */
|
|
74
|
+
onToolsChanged?: () => void;
|
|
75
|
+
/** Circuit-breaker state for peers that repeatedly fail manifest queries. */
|
|
76
|
+
private manifestFailureState;
|
|
77
|
+
private static readonly MANIFEST_FAILURE_BASE_COOLDOWN_MS;
|
|
78
|
+
private static readonly MANIFEST_FAILURE_MAX_COOLDOWN_MS;
|
|
79
|
+
private static readonly MANIFEST_SKIP_LOG_THROTTLE_MS;
|
|
80
|
+
constructor(liopServer: LiopServer, meshNode?: MeshNode | null, defaultRpcPort?: number);
|
|
81
|
+
getManifestCacheSize(): number;
|
|
82
|
+
private shouldSkipManifestQuery;
|
|
83
|
+
private recordManifestQuerySuccess;
|
|
84
|
+
private recordManifestQueryFailure;
|
|
85
|
+
/**
|
|
86
|
+
* Detects the protocol era of an incoming request.
|
|
87
|
+
* Modern requests carry '_meta' with protocol version "2026-07-28" or use modern RPCs.
|
|
88
|
+
* Legacy requests use 'initialize' handshake or lack '_meta' envelopes.
|
|
89
|
+
*/
|
|
90
|
+
detectEra(request: McpRequest): McpEra;
|
|
91
|
+
dispatch(request: McpRequest, authInfo?: AuthInfo | null): Promise<McpResponse | null>;
|
|
92
|
+
/**
|
|
93
|
+
* MCP clients often send notifications/initialized then immediately tools/list.
|
|
94
|
+
* Start manifest discovery without blocking the notification handler.
|
|
95
|
+
*/
|
|
96
|
+
private kickDiscoveryAfterInitialized;
|
|
97
|
+
/**
|
|
98
|
+
* Discovers and caches manifests from all remote LIOP providers in the mesh.
|
|
99
|
+
* Uses Kademlia DHT to find "liop:manifest" providers, then opens
|
|
100
|
+
* /liop/manifest/1.0.0 protocol streams to retrieve their full metadata.
|
|
101
|
+
*/
|
|
102
|
+
refreshManifestCache(silent?: boolean): Promise<void>;
|
|
103
|
+
/**
|
|
104
|
+
* Returns the current manifest cache size for external telemetry.
|
|
105
|
+
* Used by the adaptive polling system to detect topology stabilization.
|
|
106
|
+
*/
|
|
107
|
+
getCacheSize(): number;
|
|
108
|
+
/**
|
|
109
|
+
* Returns all remote tools discovered via the manifest protocol.
|
|
110
|
+
*/
|
|
111
|
+
private getRemoteTools;
|
|
112
|
+
/**
|
|
113
|
+
* Returns all remote resources discovered via the manifest protocol.
|
|
114
|
+
*/
|
|
115
|
+
private getRemoteResources;
|
|
116
|
+
/**
|
|
117
|
+
* Resolves the gRPC target (host:port) AND the peerId for a given tool name
|
|
118
|
+
* by searching the manifest cache. Supports exact names and suffixed names.
|
|
119
|
+
*/
|
|
120
|
+
private resolveManifestTarget;
|
|
121
|
+
/**
|
|
122
|
+
* Redacts a PeerID for external-facing diagnostics.
|
|
123
|
+
* LIOP_DIAGNOSTIC_LEVEL controls verbosity:
|
|
124
|
+
* - "redacted" (default): truncated to last 8 chars
|
|
125
|
+
* - "full": complete PeerID (development only)
|
|
126
|
+
*/
|
|
127
|
+
private redactPeerId;
|
|
128
|
+
private transcodeMcpToLiop;
|
|
129
|
+
private routeToRemoteProvider;
|
|
130
|
+
/** Cached M2M token for dynamic gateway-to-node routing */
|
|
131
|
+
private meshAgentToken?;
|
|
132
|
+
/**
|
|
133
|
+
* Dynamically acquires an M2M access token from the Nexus Authorization Server.
|
|
134
|
+
* If peerId is provided, checks if there are node-specific environment tokens
|
|
135
|
+
* before falling back to the global static token or Nexus acquisition.
|
|
136
|
+
*/
|
|
137
|
+
private getOrAcquireMeshAgentToken;
|
|
138
|
+
private performTranscoding;
|
|
139
|
+
private encryptWithNonce;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* LIOP Hybrid Gateway
|
|
144
|
+
* High-level orchestration for connecting MCP (JSON-RPC) clients to the LIOP Mesh.
|
|
145
|
+
*/
|
|
146
|
+
declare class LiopHybridGateway {
|
|
147
|
+
private liopServer;
|
|
148
|
+
private meshNode;
|
|
149
|
+
private netServer;
|
|
150
|
+
private h2Server;
|
|
151
|
+
private h1Server;
|
|
152
|
+
private router;
|
|
153
|
+
private jwtValidator?;
|
|
154
|
+
private oauthProvider?;
|
|
155
|
+
private rateLimiter;
|
|
156
|
+
private isDraining;
|
|
157
|
+
private activeRequests;
|
|
158
|
+
constructor(liopServer: LiopServer, meshNode?: MeshNode | null, rpcPort?: number, rateLimiterOptions?: RateLimiterOptions);
|
|
159
|
+
private setupH2Routes;
|
|
160
|
+
private setupH1Routes;
|
|
161
|
+
private handleGrpcStream;
|
|
162
|
+
private handleMcpH2Stream;
|
|
163
|
+
listen(port: number, host?: string): Promise<number>;
|
|
164
|
+
isDrained(): boolean;
|
|
165
|
+
drain(timeoutMs?: number): Promise<void>;
|
|
166
|
+
stop(): Promise<void>;
|
|
167
|
+
getRouter(): LiopMcpRouter;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export { InMemoryRateLimiter as I, LiopHybridGateway as L, type RateLimitStatus as R, LiopMcpRouter as a, type RateLimiterOptions as b };
|