@nekzus/liop 2.4.0-alpha.24 → 2.4.0-alpha.26

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.
Files changed (109) hide show
  1. package/README.md +21 -10
  2. package/dist/bin/agent.js +27 -932
  3. package/dist/bridge.d.ts +3 -3
  4. package/dist/bridge.js +1 -5
  5. package/dist/chunk-2XHSALII.js +3 -0
  6. package/dist/chunk-2ZYX736J.js +2 -0
  7. package/dist/chunk-3WRKTVOF.js +2 -0
  8. package/dist/chunk-6KFKO6ZX.js +2 -0
  9. package/dist/chunk-6VK2XALI.js +2 -0
  10. package/dist/chunk-AYDF3IFZ.js +2 -0
  11. package/dist/chunk-CTTTLCGL.js +31 -0
  12. package/dist/chunk-ECRS6N33.js +4 -0
  13. package/dist/chunk-FDJMH4CB.js +2 -0
  14. package/dist/chunk-FTF6AMF6.js +0 -1
  15. package/dist/chunk-GWVSCZUS.js +2 -0
  16. package/dist/chunk-LEXMMIQI.js +15 -0
  17. package/dist/chunk-LM26HOJ6.js +31 -0
  18. package/dist/chunk-MQ5SU26J.js +2 -0
  19. package/dist/chunk-N35BC62H.js +2 -0
  20. package/dist/chunk-P6IJ3VBD.js +3 -0
  21. package/dist/chunk-TKLRW52V.js +2 -0
  22. package/dist/chunk-V35CXJQN.js +2 -0
  23. package/dist/chunk-WP5ER7RH.js +3 -0
  24. package/dist/chunk-XLVEDKM6.js +2 -0
  25. package/dist/chunk-Y675R34Z.js +2 -0
  26. package/dist/chunk-YD2AF2M6.js +46 -0
  27. package/dist/chunk-YLCNV764.js +3 -0
  28. package/dist/chunk-ZZMSFCJP.js +3 -0
  29. package/dist/client.d.ts +4 -4
  30. package/dist/client.js +1 -12
  31. package/dist/gateway.d.ts +5 -5
  32. package/dist/gateway.js +1 -12
  33. package/dist/{hybrid-Cb95yJFg.d.ts → hybrid-BZpCiUaV.d.ts} +3 -3
  34. package/dist/{index-DtovobWb.d.ts → index-BYDtRGue.d.ts} +3 -3
  35. package/dist/{index-D2P6Z_hP.d.ts → index-ByzjpRCk.d.ts} +6 -1
  36. package/dist/index.d.ts +15 -10
  37. package/dist/index.js +4 -319
  38. package/dist/kyber-PULV7PQX.js +2 -0
  39. package/dist/mesh.js +1 -5
  40. package/dist/server.d.ts +3 -3
  41. package/dist/server.js +1 -9
  42. package/dist/{types-rxL19f0l.d.ts → types-29zv9X1V.d.ts} +1 -1
  43. package/dist/types.d.ts +2 -2
  44. package/dist/types.js +1 -3
  45. package/dist/{verifier-EgKmGrh7.d.ts → verifier-DqZ9MQ9l.d.ts} +34 -5
  46. package/dist/verifier-J4NQYZX5.js +2 -0
  47. package/dist/workers/logic-execution.d.ts +2 -1
  48. package/dist/workers/logic-execution.js +1 -326
  49. package/dist/workers/zk-verifier.d.ts +1 -1
  50. package/dist/workers/zk-verifier.js +1 -245
  51. package/dist/{zk-CYImPsa6.d.ts → zk-DzYNWBgo.d.ts} +14 -1
  52. package/package.json +6 -2
  53. package/dist/bin/agent.js.map +0 -1
  54. package/dist/bridge.js.map +0 -1
  55. package/dist/chunk-2VQS2XRH.js +0 -564
  56. package/dist/chunk-2VQS2XRH.js.map +0 -1
  57. package/dist/chunk-3QH44NKZ.js +0 -115
  58. package/dist/chunk-3QH44NKZ.js.map +0 -1
  59. package/dist/chunk-53QKIQNF.js +0 -818
  60. package/dist/chunk-53QKIQNF.js.map +0 -1
  61. package/dist/chunk-7BSCUYUE.js +0 -421
  62. package/dist/chunk-7BSCUYUE.js.map +0 -1
  63. package/dist/chunk-7PITYWOV.js +0 -68
  64. package/dist/chunk-7PITYWOV.js.map +0 -1
  65. package/dist/chunk-FTF6AMF6.js.map +0 -1
  66. package/dist/chunk-GFGSHQN5.js +0 -206884
  67. package/dist/chunk-GFGSHQN5.js.map +0 -1
  68. package/dist/chunk-IDTXJQBH.js +0 -1506
  69. package/dist/chunk-IDTXJQBH.js.map +0 -1
  70. package/dist/chunk-IHKKWXHJ.js +0 -876
  71. package/dist/chunk-IHKKWXHJ.js.map +0 -1
  72. package/dist/chunk-IK7CGWAZ.js +0 -24
  73. package/dist/chunk-IK7CGWAZ.js.map +0 -1
  74. package/dist/chunk-JWFLXXZS.js +0 -3743
  75. package/dist/chunk-JWFLXXZS.js.map +0 -1
  76. package/dist/chunk-K3DGJLUY.js +0 -106
  77. package/dist/chunk-K3DGJLUY.js.map +0 -1
  78. package/dist/chunk-KR5UZUEY.js +0 -98
  79. package/dist/chunk-KR5UZUEY.js.map +0 -1
  80. package/dist/chunk-OHMZZMMC.js +0 -58
  81. package/dist/chunk-OHMZZMMC.js.map +0 -1
  82. package/dist/chunk-P34HDRN5.js +0 -213
  83. package/dist/chunk-P34HDRN5.js.map +0 -1
  84. package/dist/chunk-Q3FKHJ3B.js +0 -345
  85. package/dist/chunk-Q3FKHJ3B.js.map +0 -1
  86. package/dist/chunk-V47P2AQR.js +0 -281
  87. package/dist/chunk-V47P2AQR.js.map +0 -1
  88. package/dist/chunk-WPTOJYN5.js +0 -181
  89. package/dist/chunk-WPTOJYN5.js.map +0 -1
  90. package/dist/chunk-Y62GORQF.js +0 -51
  91. package/dist/chunk-Y62GORQF.js.map +0 -1
  92. package/dist/chunk-ZJGVKM7G.js +0 -803
  93. package/dist/chunk-ZJGVKM7G.js.map +0 -1
  94. package/dist/chunk-ZP3VVXOI.js +0 -66
  95. package/dist/chunk-ZP3VVXOI.js.map +0 -1
  96. package/dist/chunk-ZRWNMP5L.js +0 -165
  97. package/dist/chunk-ZRWNMP5L.js.map +0 -1
  98. package/dist/client.js.map +0 -1
  99. package/dist/gateway.js.map +0 -1
  100. package/dist/index.js.map +0 -1
  101. package/dist/kyber-CGOA7Q6A.js +0 -3
  102. package/dist/kyber-CGOA7Q6A.js.map +0 -1
  103. package/dist/mesh.js.map +0 -1
  104. package/dist/server.js.map +0 -1
  105. package/dist/types.js.map +0 -1
  106. package/dist/verifier-UBJTZQSA.js +0 -6
  107. package/dist/verifier-UBJTZQSA.js.map +0 -1
  108. package/dist/workers/logic-execution.js.map +0 -1
  109. package/dist/workers/zk-verifier.js.map +0 -1
@@ -1,106 +0,0 @@
1
- // src/utils/logger.ts
2
- var LiopLogger = class _LiopLogger {
3
- static instance;
4
- level = "info";
5
- interceptor;
6
- _isIntercepting = false;
7
- constructor() {
8
- this.setLevelFromEnv();
9
- }
10
- static getInstance() {
11
- if (!_LiopLogger.instance) {
12
- _LiopLogger.instance = new _LiopLogger();
13
- }
14
- return _LiopLogger.instance;
15
- }
16
- setLevelFromEnv() {
17
- const envLevel = process.env.LIOP_LOG_LEVEL?.toLowerCase();
18
- if (envLevel === "silent" || envLevel === "error" || envLevel === "warn" || envLevel === "info" || envLevel === "debug") {
19
- this.level = envLevel;
20
- } else {
21
- this.level = "info";
22
- }
23
- }
24
- setLevel(level) {
25
- this.level = level;
26
- }
27
- /**
28
- * Registers a technology-agnostic log interceptor.
29
- * Pass `undefined` to disable interception (zero overhead).
30
- */
31
- setInterceptor(interceptor) {
32
- this.interceptor = interceptor;
33
- }
34
- shouldLog(targetLevel) {
35
- const levels = {
36
- silent: 0,
37
- error: 1,
38
- warn: 2,
39
- info: 3,
40
- debug: 4
41
- };
42
- return levels[this.level] >= levels[targetLevel];
43
- }
44
- formatMessage(level, message) {
45
- const ts = (/* @__PURE__ */ new Date()).toISOString();
46
- return `[${ts}] [${level}] ${message}`;
47
- }
48
- /**
49
- * Fire-and-forget async dispatch to the registered interceptor.
50
- * Recursion guard prevents infinite loops when the interceptor
51
- * itself triggers logging (directly or transitively).
52
- */
53
- emitToInterceptor(level, formattedMessage, args) {
54
- if (!this.interceptor || this._isIntercepting) return;
55
- this._isIntercepting = true;
56
- const event = Object.freeze({
57
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
58
- level,
59
- message: formattedMessage,
60
- args: Object.freeze([...args])
61
- });
62
- try {
63
- const result = this.interceptor(event);
64
- if (result && typeof result === "object" && "catch" in result) {
65
- result.catch(() => {
66
- });
67
- }
68
- } catch {
69
- } finally {
70
- this._isIntercepting = false;
71
- }
72
- }
73
- error(message, ...args) {
74
- if (this.shouldLog("error")) {
75
- const formatted = this.formatMessage("ERROR", message);
76
- console.error(formatted, ...args);
77
- this.emitToInterceptor("error", formatted, args);
78
- }
79
- }
80
- warn(message, ...args) {
81
- if (this.shouldLog("warn")) {
82
- const formatted = this.formatMessage("WARN", message);
83
- console.error(formatted, ...args);
84
- this.emitToInterceptor("warn", formatted, args);
85
- }
86
- }
87
- info(message, ...args) {
88
- if (this.shouldLog("info")) {
89
- const formatted = this.formatMessage("INFO", message);
90
- console.error(formatted, ...args);
91
- this.emitToInterceptor("info", formatted, args);
92
- }
93
- }
94
- debug(message, ...args) {
95
- if (this.shouldLog("debug")) {
96
- const formatted = this.formatMessage("DEBUG", message);
97
- console.error(formatted, ...args);
98
- this.emitToInterceptor("debug", formatted, args);
99
- }
100
- }
101
- };
102
- var log = LiopLogger.getInstance();
103
-
104
- export { LiopLogger, log };
105
- //# sourceMappingURL=chunk-K3DGJLUY.js.map
106
- //# sourceMappingURL=chunk-K3DGJLUY.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/utils/logger.ts"],"names":[],"mappings":";AAYO,IAAM,UAAA,GAAN,MAAM,WAAA,CAAW;AAAA,EACvB,OAAe,QAAA;AAAA,EACP,KAAA,GAAkB,MAAA;AAAA,EAClB,WAAA;AAAA,EACA,eAAA,GAAkB,KAAA;AAAA,EAElB,WAAA,GAAc;AACrB,IAAA,IAAA,CAAK,eAAA,EAAgB;AAAA,EACtB;AAAA,EAEA,OAAc,WAAA,GAA0B;AACvC,IAAA,IAAI,CAAC,YAAW,QAAA,EAAU;AACzB,MAAA,WAAA,CAAW,QAAA,GAAW,IAAI,WAAA,EAAW;AAAA,IACtC;AACA,IAAA,OAAO,WAAA,CAAW,QAAA;AAAA,EACnB;AAAA,EAEQ,eAAA,GAAkB;AACzB,IAAA,MAAM,QAAA,GAAW,OAAA,CAAQ,GAAA,CAAI,cAAA,EAAgB,WAAA,EAAY;AACzD,IA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AA,EACD;AAAA,EAEO,IAAA,CAAK,YAAoB,IAAA,EAAiB;AAChD,IAAA,IAAI,IAAA,CAAK,SAAA,CAAU,MAAM,CAAA,EAAG;AAC3B,MAAA,MAAM,SAAA,GAAY,IAAA,CAAK,aAAA,CAAc,MAAA,EAAQ,OAAO,CAAA;AACpD,MAAA,OAAA,CAAQ,KAAA,CAAM,SAAA,EAAW,GAAG,IAAI,CAAA;AAChC,MAAA,IAAA,CAAK,iBAAA,CAAkB,MAAA,EAAQ,SAAA,EAAW,IAAI,CAAA;AAAA,IAC/C;AAAA,EACD;AAAA,EAEO,KAAA,CAAM,YAAoB,IAAA,EAAiB;AACjD,IAAA,IAAI,IAAA,CAAK,SAAA,CAAU,OAAO,CAAA,EAAG;AAC5B,MAAA,MAAM,SAAA,GAAY,IAAA,CAAK,aAAA,CAAc,OAAA,EAAS,OAAO,CAAA;AACrD,MAAA,OAAA,CAAQ,KAAA,CAAM,SAAA,EAAW,GAAG,IAAI,CAAA;AAChC,MAAA,IAAA,CAAK,iBAAA,CAAkB,OAAA,EAAS,SAAA,EAAW,IAAI,CAAA;AAAA,IAChD;AAAA,EACD;AACD;AAEO,IAAM,GAAA,GAAM,WAAW,WAAA","file":"chunk-K3DGJLUY.js","sourcesContent":["// Copyright 2026 Nekzus Solutions and contributors\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { LogInterceptor } from \"../interceptors/log-interceptor.js\";\n\nexport type LogLevel = \"silent\" | \"error\" | \"warn\" | \"info\" | \"debug\";\n\n/**\n * LiopLogger - Structured Logging Abstraction\n * Configurable via `process.env.LIOP_LOG_LEVEL`.\n * Emits strictly to stderr to comply with MCP stdio protocols.\n */\nexport class LiopLogger {\n\tprivate static instance: LiopLogger;\n\tprivate level: LogLevel = \"info\";\n\tprivate interceptor?: LogInterceptor;\n\tprivate _isIntercepting = false;\n\n\tprivate constructor() {\n\t\tthis.setLevelFromEnv();\n\t}\n\n\tpublic static getInstance(): LiopLogger {\n\t\tif (!LiopLogger.instance) {\n\t\t\tLiopLogger.instance = new LiopLogger();\n\t\t}\n\t\treturn LiopLogger.instance;\n\t}\n\n\tprivate setLevelFromEnv() {\n\t\tconst envLevel = process.env.LIOP_LOG_LEVEL?.toLowerCase();\n\t\tif (\n\t\t\tenvLevel === \"silent\" ||\n\t\t\tenvLevel === \"error\" ||\n\t\t\tenvLevel === \"warn\" ||\n\t\t\tenvLevel === \"info\" ||\n\t\t\tenvLevel === \"debug\"\n\t\t) {\n\t\t\tthis.level = envLevel as LogLevel;\n\t\t} else {\n\t\t\t// Default level: info\n\t\t\tthis.level = \"info\";\n\t\t}\n\t}\n\n\tpublic setLevel(level: LogLevel) {\n\t\tthis.level = level;\n\t}\n\n\t/**\n\t * Registers a technology-agnostic log interceptor.\n\t * Pass `undefined` to disable interception (zero overhead).\n\t */\n\tpublic setInterceptor(interceptor: LogInterceptor | undefined) {\n\t\tthis.interceptor = interceptor;\n\t}\n\n\tprivate shouldLog(targetLevel: LogLevel): boolean {\n\t\tconst levels: Record<LogLevel, number> = {\n\t\t\tsilent: 0,\n\t\t\terror: 1,\n\t\t\twarn: 2,\n\t\t\tinfo: 3,\n\t\t\tdebug: 4,\n\t\t};\n\t\treturn levels[this.level] >= levels[targetLevel];\n\t}\n\n\tprivate formatMessage(level: string, message: string): string {\n\t\tconst ts = new Date().toISOString();\n\t\treturn `[${ts}] [${level}] ${message}`;\n\t}\n\n\t/**\n\t * Fire-and-forget async dispatch to the registered interceptor.\n\t * Recursion guard prevents infinite loops when the interceptor\n\t * itself triggers logging (directly or transitively).\n\t */\n\tprivate emitToInterceptor(\n\t\tlevel: LogLevel,\n\t\tformattedMessage: string,\n\t\targs: unknown[],\n\t): void {\n\t\tif (!this.interceptor || this._isIntercepting) return;\n\t\tthis._isIntercepting = true;\n\t\tconst event: Readonly<{\n\t\t\ttimestamp: string;\n\t\t\tlevel: LogLevel;\n\t\t\tmessage: string;\n\t\t\targs: readonly unknown[];\n\t\t}> = Object.freeze({\n\t\t\ttimestamp: new Date().toISOString(),\n\t\t\tlevel,\n\t\t\tmessage: formattedMessage,\n\t\t\targs: Object.freeze([...args]),\n\t\t});\n\t\ttry {\n\t\t\tconst result = this.interceptor(event);\n\t\t\tif (result && typeof result === \"object\" && \"catch\" in result) {\n\t\t\t\t(result as Promise<void>).catch(() => {});\n\t\t\t}\n\t\t} catch {\n\t\t\t// Interceptor errors are silenced to protect protocol throughput\n\t\t} finally {\n\t\t\tthis._isIntercepting = false;\n\t\t}\n\t}\n\n\tpublic error(message: string, ...args: unknown[]) {\n\t\tif (this.shouldLog(\"error\")) {\n\t\t\tconst formatted = this.formatMessage(\"ERROR\", message);\n\t\t\tconsole.error(formatted, ...args);\n\t\t\tthis.emitToInterceptor(\"error\", formatted, args);\n\t\t}\n\t}\n\n\tpublic warn(message: string, ...args: unknown[]) {\n\t\tif (this.shouldLog(\"warn\")) {\n\t\t\tconst formatted = this.formatMessage(\"WARN\", message);\n\t\t\tconsole.error(formatted, ...args);\n\t\t\tthis.emitToInterceptor(\"warn\", formatted, args);\n\t\t}\n\t}\n\n\tpublic info(message: string, ...args: unknown[]) {\n\t\tif (this.shouldLog(\"info\")) {\n\t\t\tconst formatted = this.formatMessage(\"INFO\", message);\n\t\t\tconsole.error(formatted, ...args);\n\t\t\tthis.emitToInterceptor(\"info\", formatted, args);\n\t\t}\n\t}\n\n\tpublic debug(message: string, ...args: unknown[]) {\n\t\tif (this.shouldLog(\"debug\")) {\n\t\t\tconst formatted = this.formatMessage(\"DEBUG\", message);\n\t\t\tconsole.error(formatted, ...args);\n\t\t\tthis.emitToInterceptor(\"debug\", formatted, args);\n\t\t}\n\t}\n}\n\nexport const log = LiopLogger.getInstance();\n"]}
@@ -1,98 +0,0 @@
1
- import { z } from 'zod';
2
-
3
- // src/types.ts
4
-
5
- // src/gateway/mcp-compat.ts
6
- var MCP_LEGACY_SUPPORT_ENABLED = true;
7
- var MCP_PROTOCOL_VERSION_LEGACY = "2025-11-25";
8
- function buildLegacyInitializeResponse(serverInfo, id) {
9
- return {
10
- jsonrpc: "2.0",
11
- id: id ?? null,
12
- result: {
13
- protocolVersion: MCP_PROTOCOL_VERSION_LEGACY,
14
- capabilities: {
15
- tools: { listChanged: true },
16
- resources: { listChanged: true },
17
- prompts: { listChanged: true }
18
- },
19
- serverInfo
20
- }
21
- };
22
- }
23
- function isLegacyRequest(request) {
24
- if (request.method === "initialize" || request.method === "notifications/initialized") {
25
- return true;
26
- }
27
- const params = request.params;
28
- const meta = params?._meta;
29
- const version = meta?.["io.modelcontextprotocol/protocolVersion"];
30
- if (!version || version === MCP_PROTOCOL_VERSION_LEGACY) {
31
- return true;
32
- }
33
- return false;
34
- }
35
- function adaptResponseForLegacyClient(response) {
36
- if (!response.result || typeof response.result !== "object") {
37
- return response;
38
- }
39
- const rawResult = { ...response.result };
40
- delete rawResult.resultType;
41
- delete rawResult.ttlMs;
42
- delete rawResult.cacheScope;
43
- return {
44
- ...response,
45
- result: rawResult
46
- };
47
- }
48
- var TOOL_ALIASES = {
49
- bank_tool: "Analyze_Synthetic_Bank_Transactions",
50
- bank_tool_XDwd: "Analyze_Synthetic_Bank_Transactions",
51
- vault_tool: "Analyze_Synthetic_Medical_Records",
52
- vault_tool_E8wP: "Analyze_Synthetic_Medical_Records",
53
- oracle_tool: "Analyze_HFT_Market_Data",
54
- compute_aggregate: "Analyze_Synthetic_Bank_Transactions"
55
- };
56
- function normalizeToolArguments(args) {
57
- if (!args) return {};
58
- const normalized = { ...args };
59
- if (normalized.data !== void 0) {
60
- if (normalized.payload === void 0) {
61
- normalized.payload = normalized.data;
62
- }
63
- if (normalized.envelope === void 0) {
64
- normalized.envelope = normalized.data;
65
- }
66
- }
67
- return normalized;
68
- }
69
-
70
- // src/types.ts
71
- var MCP_PROTOCOL_VERSION = "2026-07-28";
72
- var ToolSchema = z.object({
73
- name: z.string(),
74
- description: z.string().optional(),
75
- inputSchema: z.record(z.string(), z.unknown())
76
- // Represents a JSON Schema
77
- });
78
- var ResourceSchema = z.object({
79
- uri: z.string(),
80
- name: z.string(),
81
- description: z.string().optional(),
82
- mimeType: z.string().optional()
83
- });
84
- var PromptSchema = z.object({
85
- name: z.string(),
86
- description: z.string().optional(),
87
- arguments: z.array(
88
- z.object({
89
- name: z.string(),
90
- description: z.string().optional(),
91
- required: z.boolean().optional()
92
- })
93
- ).optional()
94
- });
95
-
96
- export { MCP_LEGACY_SUPPORT_ENABLED, MCP_PROTOCOL_VERSION, MCP_PROTOCOL_VERSION_LEGACY, PromptSchema, ResourceSchema, TOOL_ALIASES, ToolSchema, adaptResponseForLegacyClient, buildLegacyInitializeResponse, isLegacyRequest, normalizeToolArguments };
97
- //# sourceMappingURL=chunk-KR5UZUEY.js.map
98
- //# sourceMappingURL=chunk-KR5UZUEY.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/gateway/mcp-compat.ts","../src/types.ts"],"names":[],"mappings":";;;;;AAiBO,IAAM,0BAAA,GAA6B;AAKnC,IAAM,2BAAA,GAA8B;AAKpC,SAAS,6BAAA,CACf,YACA,EAAA,EACc;AACd,EAAA,OAAO;AAAA,IACN,OAAA,EAAS,KAAA;AAAA,IACT,IAAI,EAAA,IAAM,IAAA;AAAA,IACV,MAAA,EAAQ;AAAA,MACP,eAAA,EAAiB,2BAAA;AAAA,MACjB,YAAA,EAAc;AAAA,QACb,KAAA,EAAO,EAAE,WAAA,EAAa,IAAA,EAAK;AAAA,QAC3B,SAAA,EAAW,EAAE,WAAA,EAAa,IAAA,EAAK;AAAA,QAC/B,OAAA,EAAS,EAAE,WAAA,EAAa,IAAA;AAAK,OAC9B;AAAA,MACA;AAAA;AACD,GACD;AACD;AAOO,SAAS,gBAAgB,OAAA,EAA8B;AAC7D,EAAA,IACC,OAAA,CAAQ,MAAA,KAAW,YAAA,IACnB,OAAA,CAAQ,WAAW,2BAAA,EAClB;AACD,IAAA,OAAO,IAAA;AAAA,EACR;AAEA,EAAA,MAAM,SAAS,OAAA,CAAQ,MAAA;AACvB,EAAA,MAAM,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D;AACA,EAAA,OAAO,UAAA;AACR;;;ACrHO,IAAM,oBAAA,GAAuB;AAyD7B,IAAM,UAAA,GAAa,EAAE,MAAA,CAAO;AAAA,EAClC,IAAA,EAAM,EAAE,MAAA,EAAO;AAAA,EACf,WAAA,EAAa,CAAA,CAAE,MAAA,EAAO,CAAE,QAAA,EAAS;AAAA,EACjC,WAAA,EAAa,EAAE,MAAA,CAAO,CAAA,CAAE,QAAO,EAAG,CAAA,CAAE,SAAS;AAAA;AAC9C,CAAC;AAIM,IAAM,cAAA,GAAiB,EAAE,MAAA,CAAO;AAAA,EACtC,GAAA,EAAK,EAAE,MAAA,EAAO;AAAA,EACd,IAAA,EAAM,EAAE,MAAA,EAAO;AAAA,EACf,WAAA,EAAa,CAAA,CAAE,MAAA,EAAO,CAAE,QAAA,EAAS;AAAA,EACjC,QAAA,EAAU,CAAA,CAAE,MAAA,EAAO,CAAE,QAAA;AACtB,CAAC;AAIM,IAAM,YAAA,GAAe,EAAE,MAAA,CAAO;AAAA,EACpC,IAAA,EAAM,EAAE,MAAA,EAAO;AAAA,EACf,WAAA,EAAa,CAAA,CAAE,MAAA,EAAO,CAAE,QAAA,EAAS;AAAA,EACjC,WAAW,CAAA,CACT,KAAA;AAAA,IACA,EAAE,MAAA,CAAO;AAAA,MACR,IAAA,EAAM,EAAE,MAAA,EAAO;AAAA,MACf,WAAA,EAAa,CAAA,CAAE,MAAA,EAAO,CAAE,QAAA,EAAS;AAAA,MACjC,QAAA,EAAU,CAAA,CAAE,OAAA,EAAQ,CAAE,QAAA;AAAS,KAC/B;AAAA,IAED,QAAA;AACH,CAAC","file":"chunk-KR5UZUEY.js","sourcesContent":["// Copyright 2026 Nekzus Solutions and contributors\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { McpRequest, McpResponse, ServerInfo } from \"../types.js\";\n\n/**\n * @mcp-legacy ENTIRE FILE — MCP 2025-era backward compatibility layer.\n * Remove this file when MCP v1 (2025-11-25) reaches EOL.\n *\n * SUNSET INSTRUCTION: Delete this file, then grep for \"@mcp-legacy\" in the\n * codebase to find and remove all remaining legacy seams.\n */\n\n/**\n * @mcp-legacy Master kill switch for MCP 2025-era backward compatibility.\n * Set to `false` when MCP v1 reaches End-of-Life (EOL) to disable all legacy seams.\n */\nexport const MCP_LEGACY_SUPPORT_ENABLED = true;\n\n/**\n * @mcp-legacy Legacy protocol version constant.\n */\nexport const MCP_PROTOCOL_VERSION_LEGACY = \"2025-11-25\" as const;\n\n/**\n * @mcp-legacy Build the legacy initialize handshake response.\n */\nexport function buildLegacyInitializeResponse(\n\tserverInfo: ServerInfo,\n\tid?: string | number | null,\n): McpResponse {\n\treturn {\n\t\tjsonrpc: \"2.0\",\n\t\tid: id ?? null,\n\t\tresult: {\n\t\t\tprotocolVersion: MCP_PROTOCOL_VERSION_LEGACY,\n\t\t\tcapabilities: {\n\t\t\t\ttools: { listChanged: true },\n\t\t\t\tresources: { listChanged: true },\n\t\t\t\tprompts: { listChanged: true },\n\t\t\t},\n\t\t\tserverInfo,\n\t\t},\n\t};\n}\n\n/**\n * @mcp-legacy Detect if a request is strictly from a 2025-era legacy client.\n * Legacy requests either invoke 'initialize', 'notifications/initialized',\n * or lack modern '_meta' protocol envelopes.\n */\nexport function isLegacyRequest(request: McpRequest): boolean {\n\tif (\n\t\trequest.method === \"initialize\" ||\n\t\trequest.method === \"notifications/initialized\"\n\t) {\n\t\treturn true;\n\t}\n\n\tconst params = request.params as Record<string, unknown> | undefined;\n\tconst meta = params?._meta as Record<string, unknown> | undefined;\n\tconst version = meta?.[\"io.modelcontextprotocol/protocolVersion\"];\n\n\tif (!version || version === MCP_PROTOCOL_VERSION_LEGACY) {\n\t\treturn true;\n\t}\n\n\treturn false;\n}\n\n/**\n * @mcp-legacy Wrap and strip modern-era fields (resultType, ttlMs, cacheScope, etc.)\n * from a response to ensure 100% wire-compatibility with strict 2025 MCP clients.\n */\nexport function adaptResponseForLegacyClient(\n\tresponse: McpResponse,\n): McpResponse {\n\tif (!response.result || typeof response.result !== \"object\") {\n\t\treturn response;\n\t}\n\n\tconst rawResult = { ...(response.result as Record<string, unknown>) };\n\n\t// Strip modern-only envelope tags\n\tdelete rawResult.resultType;\n\tdelete rawResult.ttlMs;\n\tdelete rawResult.cacheScope;\n\n\treturn {\n\t\t...response,\n\t\tresult: rawResult,\n\t};\n}\n\n/**\n * Canonical tool aliases mapping legacy or shorthand tool names\n * to production enclave capabilities.\n */\nexport const TOOL_ALIASES: Record<string, string> = {\n\tbank_tool: \"Analyze_Synthetic_Bank_Transactions\",\n\tbank_tool_XDwd: \"Analyze_Synthetic_Bank_Transactions\",\n\tvault_tool: \"Analyze_Synthetic_Medical_Records\",\n\tvault_tool_E8wP: \"Analyze_Synthetic_Medical_Records\",\n\toracle_tool: \"Analyze_HFT_Market_Data\",\n\tcompute_aggregate: \"Analyze_Synthetic_Bank_Transactions\",\n};\n\n/**\n * Normalizes tool invocation parameters to satisfy dual parameter conventions.\n * If data is passed instead of payload or envelope, maps data to both fields.\n */\nexport function normalizeToolArguments(\n\targs?: Record<string, unknown>,\n): Record<string, unknown> {\n\tif (!args) return {};\n\tconst normalized = { ...args };\n\tif (normalized.data !== undefined) {\n\t\tif (normalized.payload === undefined) {\n\t\t\tnormalized.payload = normalized.data;\n\t\t}\n\t\tif (normalized.envelope === undefined) {\n\t\t\tnormalized.envelope = normalized.data;\n\t\t}\n\t}\n\treturn normalized;\n}\n","// Copyright 2026 Nekzus Solutions and contributors\n// SPDX-License-Identifier: Apache-2.0\n\nimport { z } from \"zod\";\n\n/**\n * Protocol Version Identifiers\n */\nexport const MCP_PROTOCOL_VERSION = \"2026-07-28\" as const;\n\nexport {\n\tMCP_LEGACY_SUPPORT_ENABLED,\n\tMCP_PROTOCOL_VERSION_LEGACY,\n} from \"./gateway/mcp-compat.js\";\n\n/**\n * Protocol Era Classification\n */\nexport type McpEra = \"legacy\" | \"modern\";\n\n/**\n * Caching Hints for MCP 2026-07-28 Spec\n */\nexport interface CacheableResult {\n\tttlMs?: number;\n\tcacheScope?: \"public\" | \"private\";\n}\n\n/**\n * Multi-Round-Trip Requests (MRTR) Specification Types\n */\nexport interface InputRequest {\n\tid: string;\n\tmessage: string;\n\tschema?: Record<string, unknown>;\n}\n\nexport interface InputResponse {\n\tid: string;\n\tvalue: unknown;\n}\n\nexport interface InputRequiredResult {\n\tresultType: \"input_required\";\n\tinputRequests: InputRequest[];\n\trequestState?: string;\n}\n\n/**\n * Modern Envelope Metadata (_meta)\n */\nexport interface McpRequestMeta {\n\t\"io.modelcontextprotocol/protocolVersion\"?: string;\n\t\"io.modelcontextprotocol/clientInfo\"?: {\n\t\tname: string;\n\t\tversion: string;\n\t};\n\t\"io.modelcontextprotocol/clientCapabilities\"?: Record<string, unknown>;\n\t[key: string]: unknown;\n}\n\n/**\n * Base Protocol Types representing parity with Model Context Protocol\n */\n\nexport const ToolSchema = z.object({\n\tname: z.string(),\n\tdescription: z.string().optional(),\n\tinputSchema: z.record(z.string(), z.unknown()), // Represents a JSON Schema\n});\n\nexport type Tool = z.infer<typeof ToolSchema>;\n\nexport const ResourceSchema = z.object({\n\turi: z.string(),\n\tname: z.string(),\n\tdescription: z.string().optional(),\n\tmimeType: z.string().optional(),\n});\n\nexport type Resource = z.infer<typeof ResourceSchema>;\n\nexport const PromptSchema = z.object({\n\tname: z.string(),\n\tdescription: z.string().optional(),\n\targuments: z\n\t\t.array(\n\t\t\tz.object({\n\t\t\t\tname: z.string(),\n\t\t\t\tdescription: z.string().optional(),\n\t\t\t\trequired: z.boolean().optional(),\n\t\t\t}),\n\t\t)\n\t\t.optional(),\n});\n\nexport type Prompt = z.infer<typeof PromptSchema>;\n\nexport interface CallToolRequest {\n\tname: string;\n\targuments?: Record<string, unknown>;\n}\n\nexport interface CallToolResult {\n\tcontent: Array<{\n\t\ttype: \"text\" | \"image\" | \"resource\";\n\t\ttext?: string;\n\t\tdata?: string;\n\t\tmimeType?: string;\n\t\tresource?: {\n\t\t\turi: string;\n\t\t\ttext?: string;\n\t\t\tblob?: string;\n\t\t};\n\t}>;\n\tisError?: boolean;\n\tzkVerified?: boolean;\n\tzkProofType?: import(\"./security/zk.js\").ProofType;\n}\n\nexport interface GetPromptRequest {\n\tname: string;\n\targuments?: Record<string, string>;\n}\n\nexport interface GetPromptResult {\n\tdescription?: string;\n\tmessages: Array<{\n\t\trole: \"user\" | \"assistant\";\n\t\tcontent:\n\t\t\t| { type: \"text\"; text: string }\n\t\t\t| { type: \"image\"; data: string; mimeType: string }\n\t\t\t| {\n\t\t\t\t\ttype: \"resource\";\n\t\t\t\t\tresource: { uri: string; text?: string; blob?: string };\n\t\t\t };\n\t}>;\n}\n\nexport interface ServerInfo {\n\tname: string;\n\tversion: string;\n\tcapabilities?: {\n\t\tprompts?: { listChanged?: boolean };\n\t\tresources?: { subscribe?: boolean; listChanged?: boolean };\n\t\ttools?: { listChanged?: boolean };\n\t\t/** @mcp-legacy @deprecated Deprecated in MCP 2026-07-28 spec */\n\t\tlogging?: Record<string, unknown>;\n\t};\n}\n\nexport interface DiscoverResult {\n\tresultType: \"complete\";\n\tsupportedVersions: string[];\n\tcapabilities: ServerInfo[\"capabilities\"];\n\tserverInfo: ServerInfo;\n\tinstructions?: string;\n}\n\nexport interface McpRequest {\n\tmethod: string;\n\tparams?: unknown;\n\tid?: string | number | null;\n\tjsonrpc?: \"2.0\";\n}\n\nexport interface McpResponse {\n\tjsonrpc: \"2.0\";\n\tid?: string | number | null;\n\tresult?: unknown;\n\terror?: {\n\t\tcode: number;\n\t\tmessage: string;\n\t\tdata?: unknown;\n\t};\n}\n\n/**\n * Re-export Gateway Interceptor types for consumer convenience.\n */\nexport type {\n\tGatewayAdmissionResult,\n\tGatewayInterceptor,\n\tGatewayInterceptorContext,\n\tGatewayInterceptorOptions,\n} from \"./gateway/interceptor.js\";\nexport type { AuditInterceptor } from \"./interceptors/audit-interceptor.js\";\n/**\n * Re-export Log & Audit Interceptor types for consumer convenience.\n */\nexport type {\n\tLogEvent,\n\tLogInterceptor,\n} from \"./interceptors/log-interceptor.js\";\n/**\n * Re-export AuthInfo from the security module for convenience.\n * Compatible with MCP TypeScript SDK AuthInfo interface shape.\n */\nexport type { AuthInfo } from \"./security/jwt-validator.js\";\nexport type {\n\tZkJournalV2,\n\tZkPolicy,\n\tZkReceipt,\n} from \"./security/zk.js\";\n/**\n * Re-export Zero-Knowledge Proof & Verification types for consumer convenience.\n */\nexport {\n\tProofType,\n\tRECEIPT_VERSION_V1,\n\tRECEIPT_VERSION_V2,\n\tZK_JOURNAL_V2_SIZE,\n} from \"./security/zk.js\";\n"]}
@@ -1,58 +0,0 @@
1
- import { ZkVerificationError } from './chunk-P34HDRN5.js';
2
- import { bn254, stringBigints } from 'micro-zk-proofs';
3
-
4
- var VERIFICATION_LATENCY_BUDGET_MS = 250;
5
- function verifyGroth16Proof(vkey, proofWithSignals) {
6
- if (!vkey || !proofWithSignals?.proof) {
7
- return false;
8
- }
9
- try {
10
- return bn254.groth.verifyProof(vkey, proofWithSignals);
11
- } catch (_error) {
12
- return false;
13
- }
14
- }
15
- function serializeVKey(vkey) {
16
- try {
17
- const encoded = stringBigints.encode(vkey);
18
- return Buffer.from(JSON.stringify(encoded), "utf-8");
19
- } catch (error) {
20
- throw new ZkVerificationError(
21
- `Failed to serialize VerificationKey: ${error instanceof Error ? error.message : String(error)}`
22
- );
23
- }
24
- }
25
- function deserializeVKey(buf) {
26
- try {
27
- const parsed = JSON.parse(buf.toString("utf-8"));
28
- return stringBigints.decode(parsed);
29
- } catch (error) {
30
- throw new ZkVerificationError(
31
- `Failed to deserialize VerificationKey: ${error instanceof Error ? error.message : String(error)}`
32
- );
33
- }
34
- }
35
- function serializeGrothProof(proofWithSignals) {
36
- try {
37
- const encoded = stringBigints.encode(proofWithSignals);
38
- return Buffer.from(JSON.stringify(encoded), "utf-8");
39
- } catch (error) {
40
- throw new ZkVerificationError(
41
- `Failed to serialize GrothProof: ${error instanceof Error ? error.message : String(error)}`
42
- );
43
- }
44
- }
45
- function deserializeGrothProof(buf) {
46
- try {
47
- const parsed = JSON.parse(buf.toString("utf-8"));
48
- return stringBigints.decode(parsed);
49
- } catch (error) {
50
- throw new ZkVerificationError(
51
- `Failed to deserialize GrothProof: ${error instanceof Error ? error.message : String(error)}`
52
- );
53
- }
54
- }
55
-
56
- export { VERIFICATION_LATENCY_BUDGET_MS, deserializeGrothProof, deserializeVKey, serializeGrothProof, serializeVKey, verifyGroth16Proof };
57
- //# sourceMappingURL=chunk-OHMZZMMC.js.map
58
- //# sourceMappingURL=chunk-OHMZZMMC.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/crypto/groth16-verifier.ts"],"names":[],"mappings":";;;AAWO,IAAM,8BAAA,GAAiC;AAQvC,SAAS,kBAAA,CACf,MACA,gBAAA,EACU;AACV,EAAA,IAAI,CAAC,IAAA,IAAQ,CAAC,gBAAA,EAAkB,KAAA,EAAO;AACtC,IAAA,OAAO,KAAA;AAAA,EACR;AAEA,EAAA,IAAI;AACH,IAAA,OAAO,KAAA,CAAM,KAAA,CAAM,WAAA,CAAY,IAAA,EAAM,gBAAgB,CAAA;AAAA,EACtD,SAAS,MAAA,EAAQ;AAEhB,IAAA,OAAO,KAAA;AAAA,EACR;AACD;AAKO,SAAS,cAAc,IAAA,EAA+B;AAC5D,EAAA,IAAI;AACH,IAAA,MAAM,OAAA,GAAU,aAAA,CAAc,MAAA,CAAO,IAAI,CAAA;AACzC,IAAA,OAAO,OAAO,IAAA,CAAK,IAAA,CAAK,SAAA,CAAU,OAAO,GAAG,OAAO,CAAA;AAAA,EACpD,SAAS,KAAA,EAAO;AACf,IAAA,MAAM,IAAI,mBAAA;AAAA,MACT,wCAAwC,KAAA,YAAiB,KAAA,GAAQ,MAAM,OAAA,GAAU,MAAA,CAAO,KAAK,CAAC,CAAA;AAAA,KAC/F;AAAA,EACD;AACD;AAKO,SAAS,gBAAgB,GAAA,EAA8B;AAC7D,EAAA,IAAI;AACH,IAAA,MAAM,SAAS,IAAA,CAAK,KAAA,CAAM,GAAA,CAAI,QAAA,CAAS,OAAO,CAAC,CAAA;AAC/C,IAAA,OAAO,aAAA,CAAc,OAAO,MAAM,CAAA;AAAA,EACnC,SAAS,KAAA,EAAO;AACf,IAAA,MAAM,IAAI,mBAAA;AAAA,MACT,0CAA0C,KAAA,YAAiB,KAAA,GAAQ,MAAM,OAAA,GAAU,MAAA,CAAO,KAAK,CAAC,CAAA;AAAA,KACjG;AAAA,EACD;AACD;AAKO,SAAS,oBACf,gBAAA,EACS;AACT,EAAA,IAAI;AACH,IAAA,MAAM,OAAA,GAAU,aAAA,CAAc,MAAA,CAAO,gBAAgB,CAAA;AACrD,IAAA,OAAO,OAAO,IAAA,CAAK,IAAA,CAAK,SAAA,CAAU,OAAO,GAAG,OAAO,CAAA;AAAA,EACpD,SAAS,KAAA,EAAO;AACf,IAAA,MAAM,IAAI,mBAAA;AAAA,MACT,mCAAmC,KAAA,YAAiB,KAAA,GAAQ,MAAM,OAAA,GAAU,MAAA,CAAO,KAAK,CAAC,CAAA;AAAA,KAC1F;AAAA,EACD;AACD;AAKO,SAAS,sBAAsB,GAAA,EAA+B;AACpE,EAAA,IAAI;AACH,IAAA,MAAM,SAAS,IAAA,CAAK,KAAA,CAAM,GAAA,CAAI,QAAA,CAAS,OAAO,CAAC,CAAA;AAC/C,IAAA,OAAO,aAAA,CAAc,OAAO,MAAM,CAAA;AAAA,EACnC,SAAS,KAAA,EAAO;AACf,IAAA,MAAM,IAAI,mBAAA;AAAA,MACT,qCAAqC,KAAA,YAAiB,KAAA,GAAQ,MAAM,OAAA,GAAU,MAAA,CAAO,KAAK,CAAC,CAAA;AAAA,KAC5F;AAAA,EACD;AACD","file":"chunk-OHMZZMMC.js","sourcesContent":["// Copyright 2026 Nekzus Solutions and contributors\n// SPDX-License-Identifier: Apache-2.0\n\nimport {\n\tbn254,\n\ttype ProofWithSignals,\n\tstringBigints,\n\ttype VerificationKey,\n} from \"micro-zk-proofs\";\nimport { ZkVerificationError } from \"../security/zk.js\";\n\nexport const VERIFICATION_LATENCY_BUDGET_MS = 250;\n\nexport type { ProofWithSignals, VerificationKey };\n\n/**\n * Verifies a Groth16 Zero-Knowledge proof against a verification key.\n * Traps curve validation errors gracefully to ensure safe verification.\n */\nexport function verifyGroth16Proof(\n\tvkey: VerificationKey,\n\tproofWithSignals: ProofWithSignals,\n): boolean {\n\tif (!vkey || !proofWithSignals?.proof) {\n\t\treturn false;\n\t}\n\n\ttry {\n\t\treturn bn254.groth.verifyProof(vkey, proofWithSignals);\n\t} catch (_error) {\n\t\t// Curve point validation or pairing failure (e.g. invalid curve point, subgroup violation)\n\t\treturn false;\n\t}\n}\n\n/**\n * Serializes a VerificationKey into a Buffer.\n */\nexport function serializeVKey(vkey: VerificationKey): Buffer {\n\ttry {\n\t\tconst encoded = stringBigints.encode(vkey);\n\t\treturn Buffer.from(JSON.stringify(encoded), \"utf-8\");\n\t} catch (error) {\n\t\tthrow new ZkVerificationError(\n\t\t\t`Failed to serialize VerificationKey: ${error instanceof Error ? error.message : String(error)}`,\n\t\t);\n\t}\n}\n\n/**\n * Deserializes a Buffer into a typed VerificationKey.\n */\nexport function deserializeVKey(buf: Buffer): VerificationKey {\n\ttry {\n\t\tconst parsed = JSON.parse(buf.toString(\"utf-8\"));\n\t\treturn stringBigints.decode(parsed) as VerificationKey;\n\t} catch (error) {\n\t\tthrow new ZkVerificationError(\n\t\t\t`Failed to deserialize VerificationKey: ${error instanceof Error ? error.message : String(error)}`,\n\t\t);\n\t}\n}\n\n/**\n * Serializes a ProofWithSignals into a Buffer.\n */\nexport function serializeGrothProof(\n\tproofWithSignals: ProofWithSignals,\n): Buffer {\n\ttry {\n\t\tconst encoded = stringBigints.encode(proofWithSignals);\n\t\treturn Buffer.from(JSON.stringify(encoded), \"utf-8\");\n\t} catch (error) {\n\t\tthrow new ZkVerificationError(\n\t\t\t`Failed to serialize GrothProof: ${error instanceof Error ? error.message : String(error)}`,\n\t\t);\n\t}\n}\n\n/**\n * Deserializes a Buffer into a typed ProofWithSignals.\n */\nexport function deserializeGrothProof(buf: Buffer): ProofWithSignals {\n\ttry {\n\t\tconst parsed = JSON.parse(buf.toString(\"utf-8\"));\n\t\treturn stringBigints.decode(parsed) as ProofWithSignals;\n\t} catch (error) {\n\t\tthrow new ZkVerificationError(\n\t\t\t`Failed to deserialize GrothProof: ${error instanceof Error ? error.message : String(error)}`,\n\t\t);\n\t}\n}\n"]}
@@ -1,213 +0,0 @@
1
- import crypto from 'crypto';
2
-
3
- // src/security/zk.ts
4
- var ProofType = /* @__PURE__ */ ((ProofType2) => {
5
- ProofType2[ProofType2["HMAC_LEGACY"] = 0] = "HMAC_LEGACY";
6
- ProofType2[ProofType2["GROTH16"] = 2] = "GROTH16";
7
- return ProofType2;
8
- })(ProofType || {});
9
- var RECEIPT_VERSION_V1 = 1;
10
- var RECEIPT_VERSION_V2 = 2;
11
- var ZK_JOURNAL_V2_SIZE = 144;
12
- var ZkVerificationError = class extends Error {
13
- constructor(message) {
14
- super(`ZK Verification Failed: ${message}`);
15
- this.name = "ZkVerificationError";
16
- }
17
- };
18
- function encodeJournalV2(fields) {
19
- if (fields.guestImageId.length !== 32) {
20
- throw new ZkVerificationError(
21
- `Invalid guestImageId size: expected 32 bytes, got ${fields.guestImageId.length}`
22
- );
23
- }
24
- if (fields.logicDigest.length !== 32) {
25
- throw new ZkVerificationError(
26
- `Invalid logicDigest size: expected 32 bytes, got ${fields.logicDigest.length}`
27
- );
28
- }
29
- if (fields.datasetDigest.length !== 32) {
30
- throw new ZkVerificationError(
31
- `Invalid datasetDigest size: expected 32 bytes, got ${fields.datasetDigest.length}`
32
- );
33
- }
34
- if (fields.outputDigest.length !== 32) {
35
- throw new ZkVerificationError(
36
- `Invalid outputDigest size: expected 32 bytes, got ${fields.outputDigest.length}`
37
- );
38
- }
39
- const buf = Buffer.alloc(ZK_JOURNAL_V2_SIZE);
40
- fields.guestImageId.copy(buf, 0);
41
- fields.logicDigest.copy(buf, 32);
42
- fields.datasetDigest.copy(buf, 64);
43
- fields.outputDigest.copy(buf, 96);
44
- buf.writeBigUInt64BE(BigInt(fields.fuelConsumed), 128);
45
- buf.writeBigUInt64BE(BigInt(fields.executionTimestamp), 136);
46
- return buf;
47
- }
48
- function decodeJournalV2(buf) {
49
- if (buf.length !== ZK_JOURNAL_V2_SIZE) {
50
- throw new ZkVerificationError(
51
- `Invalid ZkJournalV2 size: expected ${ZK_JOURNAL_V2_SIZE} bytes, got ${buf.length}`
52
- );
53
- }
54
- return {
55
- guestImageId: Buffer.from(buf.subarray(0, 32)),
56
- logicDigest: Buffer.from(buf.subarray(32, 64)),
57
- datasetDigest: Buffer.from(buf.subarray(64, 96)),
58
- outputDigest: Buffer.from(buf.subarray(96, 128)),
59
- fuelConsumed: buf.readBigUInt64BE(128),
60
- executionTimestamp: buf.readBigUInt64BE(136)
61
- };
62
- }
63
- var receiptCodec = {
64
- /**
65
- * Encodes a version 2 Binary Receipt with trailing SHA-256 checksum.
66
- * Layout: [0x02][proofType: 1B][journalLen: 4B UInt32BE][journal][proof][checksum: 32B]
67
- */
68
- encodeV2(proofType, journal, proof) {
69
- const header = Buffer.alloc(6);
70
- header.writeUInt8(RECEIPT_VERSION_V2, 0);
71
- header.writeUInt8(proofType, 1);
72
- header.writeUInt32BE(journal.length, 2);
73
- const payload = Buffer.concat([header, journal, proof]);
74
- const checksum = crypto.createHash("sha256").update(payload).digest();
75
- return Buffer.concat([payload, checksum]);
76
- },
77
- /**
78
- * Decodes any LIOP Binary Receipt (v1 HMAC or v2 ZK).
79
- */
80
- decode(raw) {
81
- if (!raw || raw.length === 0) {
82
- throw new ZkVerificationError(
83
- "Empty or malformed zero-knowledge proof array."
84
- );
85
- }
86
- const version = raw[0];
87
- if (version === RECEIPT_VERSION_V1) {
88
- if (raw.length < 35) {
89
- throw new ZkVerificationError(
90
- "Malformed receipt: invalid header or length."
91
- );
92
- }
93
- const journalLen = raw.readUInt16BE(1);
94
- if (raw.length < 3 + journalLen + 32) {
95
- throw new ZkVerificationError(
96
- "Malformed receipt: truncated journal or seal."
97
- );
98
- }
99
- const journal = Buffer.from(raw.subarray(3, 3 + journalLen));
100
- const seal = Buffer.from(
101
- raw.subarray(3 + journalLen, 3 + journalLen + 32)
102
- );
103
- return {
104
- version: RECEIPT_VERSION_V1,
105
- proofType: 0 /* HMAC_LEGACY */,
106
- journal,
107
- proof: seal,
108
- raw
109
- };
110
- }
111
- if (version === RECEIPT_VERSION_V2) {
112
- if (raw.length < 38) {
113
- throw new ZkVerificationError(
114
- "Malformed receipt v2: buffer too short (< 38 bytes)."
115
- );
116
- }
117
- const proofType = raw[1];
118
- const journalLen = raw.readUInt32BE(2);
119
- if (raw.length < 6 + journalLen + 32) {
120
- throw new ZkVerificationError(
121
- "Malformed receipt v2: truncated payload."
122
- );
123
- }
124
- const payload = raw.subarray(0, raw.length - 32);
125
- const expectedChecksum = raw.subarray(raw.length - 32);
126
- const actualChecksum = crypto.createHash("sha256").update(payload).digest();
127
- if (!crypto.timingSafeEqual(expectedChecksum, actualChecksum)) {
128
- throw new ZkVerificationError("Receipt checksum verification failed.");
129
- }
130
- const journal = Buffer.from(raw.subarray(6, 6 + journalLen));
131
- const proof = Buffer.from(raw.subarray(6 + journalLen, raw.length - 32));
132
- return {
133
- version: RECEIPT_VERSION_V2,
134
- proofType,
135
- journal,
136
- proof,
137
- raw
138
- };
139
- }
140
- throw new ZkVerificationError(
141
- `Unsupported receipt version: 0x${version.toString(16)}`
142
- );
143
- }
144
- };
145
- var ZkVerifier = {
146
- /**
147
- * Validates a ZK receipt using structural Binary Receipt verification.
148
- * Parses the HMAC-SHA256 commitment format (v1) and verifies journal integrity.
149
- *
150
- * @param receipt - Complete ZkReceipt to verify
151
- * @param expectedImageId - Hash or ImageID of the WASM file dispatched to the host
152
- * @throws ZkVerificationError if the proof is invalid or image IDs mismatch
153
- * @returns true if the proof mathematically verifies the execution
154
- */
155
- verify(receipt, expectedImageId, sessionSecret) {
156
- if (!receipt.imageId.equals(expectedImageId)) {
157
- throw new ZkVerificationError(
158
- "ImageID mismatch. The remote origin executed a different WASM payload."
159
- );
160
- }
161
- if (receipt.proof.length === 0) {
162
- throw new ZkVerificationError(
163
- "Empty or malformed zero-knowledge proof array."
164
- );
165
- }
166
- const proofBuf = Buffer.from(receipt.proof);
167
- if (proofBuf.length < 35 || proofBuf[0] !== 1) {
168
- throw new ZkVerificationError(
169
- "Malformed receipt: invalid header or length."
170
- );
171
- }
172
- const journalLen = proofBuf.readUInt16BE(1);
173
- const journal = proofBuf.subarray(3, 3 + journalLen);
174
- const seal = proofBuf.subarray(3 + journalLen);
175
- if (seal.length !== 32) {
176
- throw new ZkVerificationError(
177
- "Invalid seal: expected 32-byte HMAC-SHA256."
178
- );
179
- }
180
- try {
181
- const journalData = JSON.parse(journal.toString());
182
- if (journalData.image_id !== receipt.imageId.toString("hex")) {
183
- throw new ZkVerificationError(
184
- "Journal imageId does not match receipt header."
185
- );
186
- }
187
- } catch (_e) {
188
- throw new ZkVerificationError("Failed to parse journal data.");
189
- }
190
- if (sessionSecret && sessionSecret.length > 0) {
191
- const expectedSeal = crypto.createHmac("sha256", sessionSecret).update(journal).digest();
192
- if (!crypto.timingSafeEqual(seal, expectedSeal)) {
193
- throw new ZkVerificationError(
194
- "Invalid seal: HMAC verification failed."
195
- );
196
- }
197
- }
198
- return true;
199
- },
200
- /**
201
- * Derives a predictable ImageID (usually a Hash) from a raw WASM binary.
202
- *
203
- * @param wasmBytes - The raw bytes of the WASM logic file
204
- * @returns The SHA-256 ImageID of the logic
205
- */
206
- deriveImageId(wasmBytes) {
207
- return crypto.createHash("sha256").update(wasmBytes).digest();
208
- }
209
- };
210
-
211
- export { ProofType, RECEIPT_VERSION_V1, RECEIPT_VERSION_V2, ZK_JOURNAL_V2_SIZE, ZkVerificationError, ZkVerifier, decodeJournalV2, encodeJournalV2, receiptCodec };
212
- //# sourceMappingURL=chunk-P34HDRN5.js.map
213
- //# sourceMappingURL=chunk-P34HDRN5.js.map
@@ -1 +0,0 @@
1
-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AAAA;AAAA;AAAA,EAQA,cAAc,SAAA,EAA2B;AACxC,IAAA,OAAO,OAAO,UAAA,CAAW,QAAQ,EAAE,MAAA,CAAO,SAAS,EAAE,MAAA,EAAO;AAAA,EAC7D;AACD","file":"chunk-P34HDRN5.js","sourcesContent":["// Copyright 2026 Nekzus Solutions and contributors\n// SPDX-License-Identifier: Apache-2.0\n\nimport crypto from \"node:crypto\";\n\nexport enum ProofType {\n\tHMAC_LEGACY = 0x00,\n\tGROTH16 = 0x02,\n}\n\nexport const RECEIPT_VERSION_V1 = 0x01;\nexport const RECEIPT_VERSION_V2 = 0x02;\nexport const ZK_JOURNAL_V2_SIZE = 144;\n\nexport interface ZkJournalV2 {\n\t/** Image ID (SHA-256) of the guest interpreter */\n\tguestImageId: Buffer;\n\t/** SHA-256 digest of injected logic */\n\tlogicDigest: Buffer;\n\t/** SHA-256 digest of dataset records */\n\tdatasetDigest: Buffer;\n\t/** SHA-256 digest of sanitized output */\n\toutputDigest: Buffer;\n\t/** Micro-instruction fuel consumed */\n\tfuelConsumed: bigint;\n\t/** Timestamp in milliseconds since unix epoch */\n\texecutionTimestamp: bigint;\n}\n\nexport type ZkPolicy = \"none\" | \"optimistic\" | \"required\";\n\nexport interface ZkReceipt {\n\t/** Cryptographic proof generated by a zero-knowledge VM (e.g., RISC Zero, SP1) or Groth16 */\n\tproof: Buffer;\n\t/** The public inputs/outputs of the execution (the \"Journal\" in RISC Zero terminology) */\n\tjournal: Buffer;\n\t/** The expected image ID / verification key of the WASM binary that was executed */\n\timageId: Buffer;\n\t/** Type of cryptographic proof (HMAC legacy or Groth16) */\n\tproofType?: ProofType;\n\t/** Binary receipt version (0x01 or 0x02) */\n\tversion?: number;\n}\n\nexport class ZkVerificationError extends Error {\n\tconstructor(message: string) {\n\t\tsuper(`ZK Verification Failed: ${message}`);\n\t\tthis.name = \"ZkVerificationError\";\n\t}\n}\n\n/**\n * Serializes a structured ZkJournalV2 into a strictly validated 144-byte binary layout.\n */\nexport function encodeJournalV2(fields: ZkJournalV2): Buffer {\n\tif (fields.guestImageId.length !== 32) {\n\t\tthrow new ZkVerificationError(\n\t\t\t`Invalid guestImageId size: expected 32 bytes, got ${fields.guestImageId.length}`,\n\t\t);\n\t}\n\tif (fields.logicDigest.length !== 32) {\n\t\tthrow new ZkVerificationError(\n\t\t\t`Invalid logicDigest size: expected 32 bytes, got ${fields.logicDigest.length}`,\n\t\t);\n\t}\n\tif (fields.datasetDigest.length !== 32) {\n\t\tthrow new ZkVerificationError(\n\t\t\t`Invalid datasetDigest size: expected 32 bytes, got ${fields.datasetDigest.length}`,\n\t\t);\n\t}\n\tif (fields.outputDigest.length !== 32) {\n\t\tthrow new ZkVerificationError(\n\t\t\t`Invalid outputDigest size: expected 32 bytes, got ${fields.outputDigest.length}`,\n\t\t);\n\t}\n\n\tconst buf = Buffer.alloc(ZK_JOURNAL_V2_SIZE);\n\tfields.guestImageId.copy(buf, 0);\n\tfields.logicDigest.copy(buf, 32);\n\tfields.datasetDigest.copy(buf, 64);\n\tfields.outputDigest.copy(buf, 96);\n\tbuf.writeBigUInt64BE(BigInt(fields.fuelConsumed), 128);\n\tbuf.writeBigUInt64BE(BigInt(fields.executionTimestamp), 136);\n\n\treturn buf;\n}\n\n/**\n * Deserializes and validates a 144-byte binary buffer into a typed ZkJournalV2.\n */\nexport function decodeJournalV2(buf: Buffer): ZkJournalV2 {\n\tif (buf.length !== ZK_JOURNAL_V2_SIZE) {\n\t\tthrow new ZkVerificationError(\n\t\t\t`Invalid ZkJournalV2 size: expected ${ZK_JOURNAL_V2_SIZE} bytes, got ${buf.length}`,\n\t\t);\n\t}\n\n\treturn {\n\t\tguestImageId: Buffer.from(buf.subarray(0, 32)),\n\t\tlogicDigest: Buffer.from(buf.subarray(32, 64)),\n\t\tdatasetDigest: Buffer.from(buf.subarray(64, 96)),\n\t\toutputDigest: Buffer.from(buf.subarray(96, 128)),\n\t\tfuelConsumed: buf.readBigUInt64BE(128),\n\t\texecutionTimestamp: buf.readBigUInt64BE(136),\n\t};\n}\n\nexport interface DecodedReceipt {\n\tversion: number;\n\tproofType: ProofType;\n\tjournal: Buffer;\n\tproof: Buffer;\n\traw: Buffer;\n}\n\nexport const receiptCodec = {\n\t/**\n\t * Encodes a version 2 Binary Receipt with trailing SHA-256 checksum.\n\t * Layout: [0x02][proofType: 1B][journalLen: 4B UInt32BE][journal][proof][checksum: 32B]\n\t */\n\tencodeV2(proofType: ProofType, journal: Buffer, proof: Buffer): Buffer {\n\t\tconst header = Buffer.alloc(6);\n\t\theader.writeUInt8(RECEIPT_VERSION_V2, 0);\n\t\theader.writeUInt8(proofType, 1);\n\t\theader.writeUInt32BE(journal.length, 2);\n\n\t\tconst payload = Buffer.concat([header, journal, proof]);\n\t\tconst checksum = crypto.createHash(\"sha256\").update(payload).digest();\n\n\t\treturn Buffer.concat([payload, checksum]);\n\t},\n\n\t/**\n\t * Decodes any LIOP Binary Receipt (v1 HMAC or v2 ZK).\n\t */\n\tdecode(raw: Buffer): DecodedReceipt {\n\t\tif (!raw || raw.length === 0) {\n\t\t\tthrow new ZkVerificationError(\n\t\t\t\t\"Empty or malformed zero-knowledge proof array.\",\n\t\t\t);\n\t\t}\n\n\t\tconst version = raw[0];\n\n\t\tif (version === RECEIPT_VERSION_V1) {\n\t\t\tif (raw.length < 35) {\n\t\t\t\tthrow new ZkVerificationError(\n\t\t\t\t\t\"Malformed receipt: invalid header or length.\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst journalLen = raw.readUInt16BE(1);\n\t\t\tif (raw.length < 3 + journalLen + 32) {\n\t\t\t\tthrow new ZkVerificationError(\n\t\t\t\t\t\"Malformed receipt: truncated journal or seal.\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst journal = Buffer.from(raw.subarray(3, 3 + journalLen));\n\t\t\tconst seal = Buffer.from(\n\t\t\t\traw.subarray(3 + journalLen, 3 + journalLen + 32),\n\t\t\t);\n\n\t\t\treturn {\n\t\t\t\tversion: RECEIPT_VERSION_V1,\n\t\t\t\tproofType: ProofType.HMAC_LEGACY,\n\t\t\t\tjournal,\n\t\t\t\tproof: seal,\n\t\t\t\traw,\n\t\t\t};\n\t\t}\n\n\t\tif (version === RECEIPT_VERSION_V2) {\n\t\t\t// Minimum size: 1 (version) + 1 (proofType) + 4 (journalLen) + 0 (journal) + 0 (proof) + 32 (checksum) = 38\n\t\t\tif (raw.length < 38) {\n\t\t\t\tthrow new ZkVerificationError(\n\t\t\t\t\t\"Malformed receipt v2: buffer too short (< 38 bytes).\",\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst proofType = raw[1] as ProofType;\n\t\t\tconst journalLen = raw.readUInt32BE(2);\n\n\t\t\tif (raw.length < 6 + journalLen + 32) {\n\t\t\t\tthrow new ZkVerificationError(\n\t\t\t\t\t\"Malformed receipt v2: truncated payload.\",\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst payload = raw.subarray(0, raw.length - 32);\n\t\t\tconst expectedChecksum = raw.subarray(raw.length - 32);\n\t\t\tconst actualChecksum = crypto\n\t\t\t\t.createHash(\"sha256\")\n\t\t\t\t.update(payload)\n\t\t\t\t.digest();\n\n\t\t\tif (!crypto.timingSafeEqual(expectedChecksum, actualChecksum)) {\n\t\t\t\tthrow new ZkVerificationError(\"Receipt checksum verification failed.\");\n\t\t\t}\n\n\t\t\tconst journal = Buffer.from(raw.subarray(6, 6 + journalLen));\n\t\t\tconst proof = Buffer.from(raw.subarray(6 + journalLen, raw.length - 32));\n\n\t\t\treturn {\n\t\t\t\tversion: RECEIPT_VERSION_V2,\n\t\t\t\tproofType,\n\t\t\t\tjournal,\n\t\t\t\tproof,\n\t\t\t\traw,\n\t\t\t};\n\t\t}\n\n\t\tthrow new ZkVerificationError(\n\t\t\t`Unsupported receipt version: 0x${version.toString(16)}`,\n\t\t);\n\t},\n};\n\n/**\n * ZK-Proofs Verifier for Logic-Injection-on-Origin Protocol (LIOP)\n *\n * Validates that an executed Logic (WASM) actually produced the reported output,\n * verifying the Zero-Knowledge receipt generated by the remote host's Trusted Execution\n * Environment (TEE) or zkVM (Zero-Knowledge Virtual Machine).\n */\nexport const ZkVerifier = {\n\t/**\n\t * Validates a ZK receipt using structural Binary Receipt verification.\n\t * Parses the HMAC-SHA256 commitment format (v1) and verifies journal integrity.\n\t *\n\t * @param receipt - Complete ZkReceipt to verify\n\t * @param expectedImageId - Hash or ImageID of the WASM file dispatched to the host\n\t * @throws ZkVerificationError if the proof is invalid or image IDs mismatch\n\t * @returns true if the proof mathematically verifies the execution\n\t */\n\tverify(\n\t\treceipt: ZkReceipt,\n\t\texpectedImageId: Buffer,\n\t\tsessionSecret?: Buffer,\n\t): boolean {\n\t\t// 1. Verify Image ID (Ensures the host executed the exact logic we sent, not a malicious one)\n\t\tif (!receipt.imageId.equals(expectedImageId)) {\n\t\t\tthrow new ZkVerificationError(\n\t\t\t\t\"ImageID mismatch. The remote origin executed a different WASM payload.\",\n\t\t\t);\n\t\t}\n\n\t\t// 2. Validate Proof Structure\n\t\tif (receipt.proof.length === 0) {\n\t\t\tthrow new ZkVerificationError(\n\t\t\t\t\"Empty or malformed zero-knowledge proof array.\",\n\t\t\t);\n\t\t}\n\n\t\t// 3. Cryptographic Validation (Binary Receipt)\n\t\tconst proofBuf = Buffer.from(receipt.proof);\n\t\tif (proofBuf.length < 35 || proofBuf[0] !== 0x01) {\n\t\t\tthrow new ZkVerificationError(\n\t\t\t\t\"Malformed receipt: invalid header or length.\",\n\t\t\t);\n\t\t}\n\t\tconst journalLen = proofBuf.readUInt16BE(1);\n\t\tconst journal = proofBuf.subarray(3, 3 + journalLen);\n\t\tconst seal = proofBuf.subarray(3 + journalLen);\n\n\t\tif (seal.length !== 32) {\n\t\t\tthrow new ZkVerificationError(\n\t\t\t\t\"Invalid seal: expected 32-byte HMAC-SHA256.\",\n\t\t\t);\n\t\t}\n\n\t\t// Verify journal contains matching imageId\n\t\ttry {\n\t\t\tconst journalData = JSON.parse(journal.toString());\n\t\t\tif (journalData.image_id !== receipt.imageId.toString(\"hex\")) {\n\t\t\t\tthrow new ZkVerificationError(\n\t\t\t\t\t\"Journal imageId does not match receipt header.\",\n\t\t\t\t);\n\t\t\t}\n\t\t} catch (_e) {\n\t\t\tthrow new ZkVerificationError(\"Failed to parse journal data.\");\n\t\t}\n\n\t\t// 4. Mathematical Verification (HMAC-SHA256)\n\t\tif (sessionSecret && sessionSecret.length > 0) {\n\t\t\tconst expectedSeal = crypto\n\t\t\t\t.createHmac(\"sha256\", sessionSecret)\n\t\t\t\t.update(journal)\n\t\t\t\t.digest();\n\t\t\tif (!crypto.timingSafeEqual(seal, expectedSeal)) {\n\t\t\t\tthrow new ZkVerificationError(\n\t\t\t\t\t\"Invalid seal: HMAC verification failed.\",\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\treturn true;\n\t},\n\n\t/**\n\t * Derives a predictable ImageID (usually a Hash) from a raw WASM binary.\n\t *\n\t * @param wasmBytes - The raw bytes of the WASM logic file\n\t * @returns The SHA-256 ImageID of the logic\n\t */\n\tderiveImageId(wasmBytes: Buffer): Buffer {\n\t\treturn crypto.createHash(\"sha256\").update(wasmBytes).digest();\n\t},\n};\n"]}