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

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 (74) hide show
  1. package/README.md +21 -10
  2. package/dist/bin/agent.js +7 -6
  3. package/dist/bridge.d.ts +3 -3
  4. package/dist/bridge.js +2 -2
  5. package/dist/{chunk-WPTOJYN5.js → chunk-3664H3CV.js} +14 -59
  6. package/dist/{chunk-53QKIQNF.js → chunk-6MYJBM2E.js} +4 -4
  7. package/dist/{chunk-IDTXJQBH.js → chunk-DSOB2JKM.js} +6 -5
  8. package/dist/{chunk-OHMZZMMC.js → chunk-ET6VRUK2.js} +3 -3
  9. package/dist/{chunk-P34HDRN5.js → chunk-FIVRGOA4.js} +69 -2
  10. package/dist/chunk-JPWC6XG6.js +941 -0
  11. package/dist/chunk-NXCAFF73.js +59 -0
  12. package/dist/{chunk-7BSCUYUE.js → chunk-R52TZEIL.js} +8 -3
  13. package/dist/{chunk-ZJGVKM7G.js → chunk-S3RAZTEM.js} +9 -5
  14. package/dist/{chunk-2VQS2XRH.js → chunk-WXOWJXY6.js} +3 -3
  15. package/dist/{chunk-ZRWNMP5L.js → chunk-WXYDFCIW.js} +139 -11
  16. package/dist/{chunk-JWFLXXZS.js → chunk-ZU3WVVLC.js} +20 -11
  17. package/dist/client.d.ts +4 -4
  18. package/dist/client.js +4 -4
  19. package/dist/gateway.d.ts +5 -5
  20. package/dist/gateway.js +7 -6
  21. package/dist/{hybrid-Cb95yJFg.d.ts → hybrid-BZpCiUaV.d.ts} +3 -3
  22. package/dist/{index-DtovobWb.d.ts → index-BYDtRGue.d.ts} +3 -3
  23. package/dist/{index-D2P6Z_hP.d.ts → index-ByzjpRCk.d.ts} +6 -1
  24. package/dist/index.d.ts +15 -10
  25. package/dist/index.js +12 -11
  26. package/dist/server.d.ts +3 -3
  27. package/dist/server.js +5 -4
  28. package/dist/{types-rxL19f0l.d.ts → types-29zv9X1V.d.ts} +1 -1
  29. package/dist/types.d.ts +2 -2
  30. package/dist/types.js +1 -1
  31. package/dist/verifier-55HW6AFN.js +6 -0
  32. package/dist/{verifier-EgKmGrh7.d.ts → verifier-DqZ9MQ9l.d.ts} +34 -5
  33. package/dist/workers/logic-execution.d.ts +2 -1
  34. package/dist/workers/logic-execution.js +38 -9
  35. package/dist/workers/zk-verifier.d.ts +1 -1
  36. package/dist/workers/zk-verifier.js +35 -5
  37. package/dist/{zk-CYImPsa6.d.ts → zk-DzYNWBgo.d.ts} +14 -1
  38. package/package.json +6 -2
  39. package/dist/bin/agent.js.map +0 -1
  40. package/dist/bridge.js.map +0 -1
  41. package/dist/chunk-2VQS2XRH.js.map +0 -1
  42. package/dist/chunk-3QH44NKZ.js.map +0 -1
  43. package/dist/chunk-53QKIQNF.js.map +0 -1
  44. package/dist/chunk-7BSCUYUE.js.map +0 -1
  45. package/dist/chunk-7PITYWOV.js.map +0 -1
  46. package/dist/chunk-FTF6AMF6.js.map +0 -1
  47. package/dist/chunk-GFGSHQN5.js +0 -206884
  48. package/dist/chunk-GFGSHQN5.js.map +0 -1
  49. package/dist/chunk-IDTXJQBH.js.map +0 -1
  50. package/dist/chunk-IHKKWXHJ.js.map +0 -1
  51. package/dist/chunk-IK7CGWAZ.js.map +0 -1
  52. package/dist/chunk-JWFLXXZS.js.map +0 -1
  53. package/dist/chunk-K3DGJLUY.js.map +0 -1
  54. package/dist/chunk-KR5UZUEY.js.map +0 -1
  55. package/dist/chunk-OHMZZMMC.js.map +0 -1
  56. package/dist/chunk-P34HDRN5.js.map +0 -1
  57. package/dist/chunk-Q3FKHJ3B.js.map +0 -1
  58. package/dist/chunk-V47P2AQR.js.map +0 -1
  59. package/dist/chunk-WPTOJYN5.js.map +0 -1
  60. package/dist/chunk-Y62GORQF.js.map +0 -1
  61. package/dist/chunk-ZJGVKM7G.js.map +0 -1
  62. package/dist/chunk-ZP3VVXOI.js.map +0 -1
  63. package/dist/chunk-ZRWNMP5L.js.map +0 -1
  64. package/dist/client.js.map +0 -1
  65. package/dist/gateway.js.map +0 -1
  66. package/dist/index.js.map +0 -1
  67. package/dist/kyber-CGOA7Q6A.js.map +0 -1
  68. package/dist/mesh.js.map +0 -1
  69. package/dist/server.js.map +0 -1
  70. package/dist/types.js.map +0 -1
  71. package/dist/verifier-UBJTZQSA.js +0 -6
  72. package/dist/verifier-UBJTZQSA.js.map +0 -1
  73. package/dist/workers/logic-execution.js.map +0 -1
  74. package/dist/workers/zk-verifier.js.map +0 -1
package/README.md CHANGED
@@ -60,8 +60,8 @@ This addresses the data privacy, bandwidth, and latency bottlenecks of distribut
60
60
  | **Resilient Hybrid Routing** | Deterministic per-tool multiplexing across `http-gateway`, `p2p-grpc`, and `local` with 5-failure circuit breaker (`RoutingTable`).|
61
61
  | **OAuth 2.1 M2M Lifecycle** | Concurrency in-flight de-duplication, 30-second preemptive refresh buffer, and reactive invalidation (`TokenManager`). |
62
62
  | **Sliding-Window Rate Limiter**| In-memory OWASP API4:2023 rate limiting with background cleanup unreferenced intervals (`InMemoryRateLimiter`). |
63
- | **PII Shield** | Multi-layer egress filter with Regional Presets, custom keys, and recursive floats sanitization (`sanitizeOutput`). |
64
- | **ZK-Receipts** | Sovereign Zero-Knowledge Proofs: Groth16 BN254 with 144-byte binary journal (v2) and legacy HMAC-SHA256 (v1). Enforces `ZK_BLOCKING` on Tier 1 Enclaves. |
63
+ | **ZK-Receipts** | Tri-modal Zero-Knowledge proofs: HMAC-SHA256 (v1), Groth16 BN254 with 144-byte binary journal (v2), and dual-layer ML-DSA-65 post-quantum hybrid receipts (v2.1). Enforces `ZK_BLOCKING` on Tier 1 Enclaves. |
64
+ | **Hardware TEE Attestation** | Pre-flight validation of confidential hardware root-of-trust evidence for AMD SEV-SNP (1,184-byte report) and AWS Nitro Enclaves (`verifyTeeAttestationDetailed`). |
65
65
  | **Worker Pool** | Heavy computation (crypto, sandboxing) dispatched to OS threads via `piscina` with background async warmup. |
66
66
  | **Post-Quantum Ready** | ML-KEM-768 (Kyber) + ML-DSA-65 (Dilithium) with 1-hour session lifetime and AES-256-GCM encryption. |
67
67
  | **Enterprise Observability** | Immutable SOC 2 Hash-Chain audit log (`AuditLogger`), physical wire egress tracking, Prometheus metrics (`/metrics`), and K8s probes. |
@@ -451,25 +451,28 @@ To block arbitrary command execution (e.g., Shellshock) and prevent exposure of
451
451
  - **Unix/Linux Allowlist**: `HOME`, `LOGNAME`, `PATH`, `SHELL`, `TERM`, `USER`.
452
452
  Variables starting with shell functions `()` are dropped.
453
453
 
454
- ### Sovereign ZK-Receipts & Groth16 Attestation
454
+ ### Sovereign Tri-Modal ZK-Receipts & Hardware Attestation
455
455
 
456
- LIOP ZK-Receipts provide cryptographic evidence that a computation was executed honestly under zero-trust bounds. Version 2 receipts introduce true Zero-Knowledge Groth16 proofs over the BN254 pairing-friendly elliptic curve, packing a 144-byte binary journal:
456
+ LIOP ZK-Receipts provide cryptographic evidence that a computation was executed honestly under zero-trust bounds. The protocol implements three complementary cryptographic modes:
457
+ - **Mode 0 (`HMAC_LEGACY`, v1)**: Session commitments sealed with the ML-KEM-768 quantum-resistant shared key.
458
+ - **Mode 2 (`GROTH16`, v2)**: Compact Zero-Knowledge SNARK proofs over the BN254 pairing-friendly elliptic curve packing a 144-byte binary journal (~252 bytes total).
459
+ - **Mode 3 (`GROTH16_PQC_HYBRID`, v2.1)**: Dual-layer receipts combining Groth16 BN254 mathematical proofs with an ML-DSA-65 post-quantum digital signature conforming to NIST FIPS 204 (~5.6 KB total).
457
460
 
458
461
  - **144-Byte Binary Journal Layout**:
459
462
  - `guest_image_id` (32 bytes): Sovereign enclave guest runtime image identifier
460
463
  - `logic_digest` (32 bytes): SHA-256 fingerprint of the executed JavaScript/WASM logic
461
464
  - `dataset_digest` (32 bytes): SHA-256 fingerprint of the origin dataset at execution time
462
465
  - `output_digest` (32 bytes): SHA-256 fingerprint of the sanitized computation result
463
- - `fuel_consumed` (8 bytes uint64 BE): AST fuel metering units consumed
466
+ - `fuel_consumed` (8 bytes uint64 BE): Quantized instruction-level AST fuel units consumed
464
467
  - `execution_timestamp` (8 bytes uint64 BE): Epoch timestamp in milliseconds
465
- - **Tampering & Replay Mitigation**: The client computes the local SHA-256 hash of the received output and asserts strict equality with `journal.outputDigest`. Any modified bit in either the journal or curve proof causes immediate rejection.
466
- - **Enclave Policy Invariant (`ZK_BLOCKING`)**: Tier 1 Sovereign Enclaves configure `zkMode: "required"`, rejecting queries if a valid Groth16 proof cannot be synthesized.
468
+ - **Tampering & Replay Mitigation**: The client computes the local SHA-256 hash of the received output and asserts strict equality with `journal.outputDigest`. Any modified bit in either the journal, curve proof, or post-quantum signature causes immediate rejection.
469
+ - **Enclave Policy Invariant (`ZK_BLOCKING`)**: Tier 1 Sovereign Enclaves configure `zkMode: "required"`, rejecting queries if a valid Groth16 proof cannot be synthesized or if mock proofs are supplied. When `pqcSign: true` is configured, the enclave emits a Version 2.1 hybrid receipt co-signed with ML-DSA-65.
467
470
 
468
471
  ```typescript
469
472
  import { LiopServer } from "@nekzus/liop/server";
470
- import { LiopVerifier } from "@nekzus/liop";
473
+ import { LiopVerifier, verifyTeeAttestationDetailed } from "@nekzus/liop";
471
474
 
472
- // 1. Enclave configuration with ZK_BLOCKING policy
475
+ // 1. Enclave configuration with ZK_BLOCKING and PQC signing
473
476
  const server = new LiopServer({ name: "bank-enclave", version: "1.0.0" });
474
477
  server.tool(
475
478
  "calculate_payroll_aggregate",
@@ -478,6 +481,7 @@ server.tool(
478
481
  async () => ({ content: [{ type: "text", text: "ok" }] }),
479
482
  {
480
483
  zkMode: "required", // Enforces Groth16 proof generation (ZK_BLOCKING)
484
+ pqcSign: true, // Enables ML-DSA-65 digital signature (Receipt v2.1)
481
485
  circuitName: "sum",
482
486
  }
483
487
  );
@@ -490,6 +494,13 @@ const isValid = await verifier.verifyZkReceipt(
490
494
  rawReceiptBuffer,
491
495
  { zkPolicy: "required" }
492
496
  );
497
+
498
+ // 3. Pre-flight Hardware TEE Attestation (AMD SEV-SNP / AWS Nitro Enclaves)
499
+ const teeStatus = await verifyTeeAttestationDetailed(
500
+ attestationBytes,
501
+ expectedNonce,
502
+ { requireHardwareSigned: true }
503
+ );
493
504
  ```
494
505
 
495
506
  ---
@@ -505,7 +516,7 @@ The following shows a complete Logic-Injection-on-Origin execution cycle (handle
505
516
  4. Code executes inside a V8 isolate with CPU fuel limits (no Node.js globals)
506
517
  5. Taint Analyzer blocks PII side-channel derivation (charCodeAt, boolean inference)
507
518
  6. PII Shield scans output for forbidden data and keys
508
- 7. ZK-Receipt generated (SHA-256 ImageID + HMAC-SHA256 seal)
519
+ 7. ZK-Receipt generated (Tri-modal: HMAC v1, Groth16 v2, or Groth16 + ML-DSA-65 v2.1)
509
520
  8. Result + receipt returned to the LLM (raw data never exposed)
510
521
  ```
511
522
 
package/dist/bin/agent.js CHANGED
@@ -1,17 +1,18 @@
1
1
  #!/usr/bin/env node
2
2
  import { probeTopology, RoutingTable } from '../chunk-V47P2AQR.js';
3
3
  import { TokenManager } from '../chunk-3QH44NKZ.js';
4
- import { LiopServer } from '../chunk-JWFLXXZS.js';
4
+ import { LiopServer } from '../chunk-ZU3WVVLC.js';
5
5
  import '../chunk-Y62GORQF.js';
6
- import { LiopMcpRouter } from '../chunk-IDTXJQBH.js';
7
- import '../chunk-ZRWNMP5L.js';
6
+ import { LiopMcpRouter } from '../chunk-DSOB2JKM.js';
7
+ import '../chunk-WXYDFCIW.js';
8
8
  import '../chunk-IK7CGWAZ.js';
9
9
  import '../chunk-7PITYWOV.js';
10
- import '../chunk-WPTOJYN5.js';
11
- import '../chunk-GFGSHQN5.js';
10
+ import '../chunk-NXCAFF73.js';
11
+ import '../chunk-3664H3CV.js';
12
+ import '../chunk-JPWC6XG6.js';
12
13
  import '../chunk-Q3FKHJ3B.js';
13
14
  import { normalizeToolArguments, TOOL_ALIASES, isLegacyRequest } from '../chunk-KR5UZUEY.js';
14
- import '../chunk-P34HDRN5.js';
15
+ import '../chunk-FIVRGOA4.js';
15
16
  import '../chunk-FTF6AMF6.js';
16
17
  import '../chunk-ZP3VVXOI.js';
17
18
  import { MeshNode } from '../chunk-IHKKWXHJ.js';
package/dist/bridge.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
- import { L as LiopServer, a as LiopServerOptions } from './index-D2P6Z_hP.js';
2
+ import { L as LiopServer, a as LiopServerOptions } from './index-ByzjpRCk.js';
3
3
  import 'zod';
4
4
  import './node-Djzm6UYd.js';
5
- import './types-rxL19f0l.js';
6
- import './zk-CYImPsa6.js';
5
+ import './types-29zv9X1V.js';
6
+ import './zk-DzYNWBgo.js';
7
7
  import 'jose';
8
8
 
9
9
  /**
package/dist/bridge.js CHANGED
@@ -1,6 +1,6 @@
1
- export { LiopMcpBridge, LiopStreamBridge } from './chunk-2VQS2XRH.js';
1
+ export { LiopMcpBridge, LiopStreamBridge } from './chunk-WXOWJXY6.js';
2
2
  import './chunk-KR5UZUEY.js';
3
- import './chunk-P34HDRN5.js';
3
+ import './chunk-FIVRGOA4.js';
4
4
  import './chunk-K3DGJLUY.js';
5
5
  //# sourceMappingURL=bridge.js.map
6
6
  //# sourceMappingURL=bridge.js.map
@@ -48,6 +48,17 @@ var Dilithium65Wrapper = {
48
48
  secretKey: keys.secretKey
49
49
  };
50
50
  },
51
+ /**
52
+ * Derives the ML-DSA-65 public key from a given secret key.
53
+ */
54
+ getPublicKey(secretKey) {
55
+ if (secretKey.length !== DILITHIUM65_CONSTANTS.SECRET_KEY_BYTES) {
56
+ throw new Error(
57
+ `ML-DSA-65 Secret Key must be exactly ${DILITHIUM65_CONSTANTS.SECRET_KEY_BYTES} bytes (Received: ${secretKey.length})`
58
+ );
59
+ }
60
+ return ml_dsa65.getPublicKey(secretKey);
61
+ },
51
62
  /**
52
63
  * Validates and imports a raw ML-DSA-65 public key.
53
64
  */
@@ -120,62 +131,6 @@ var Dilithium65Wrapper = {
120
131
  }
121
132
  };
122
133
 
123
- // src/security/rbac.ts
124
- var SCOPE_MAP = {
125
- // Protocol lifecycle — unauthenticated (MCP spec compliance)
126
- initialize: [],
127
- "notifications/initialized": [],
128
- "notifications/cancelled": [],
129
- ping: [],
130
- "server/discover": [],
131
- "subscriptions/listen": [],
132
- // Tool operations — require explicit authorization
133
- "tools/list": ["liop:tools:list"],
134
- "tools/call": ["liop:tools:call"],
135
- // Resource operations — read-level access
136
- "resources/list": ["liop:resources:read"],
137
- "resources/read": ["liop:resources:read"],
138
- "resources/templates/list": ["liop:resources:read"],
139
- // Prompt/schema operations — schema-level access
140
- "prompts/list": ["liop:schema:read"],
141
- "prompts/get": ["liop:schema:read"]
142
- };
143
- function authorizeRequest(method, auth, additionalScopes) {
144
- const methodScopes = SCOPE_MAP[method];
145
- if (methodScopes !== void 0 && methodScopes.length === 0) {
146
- return { allowed: true };
147
- }
148
- if (!auth) {
149
- return {
150
- allowed: false,
151
- reason: `Authentication required for method: ${method}`
152
- };
153
- }
154
- const needed = [...methodScopes ?? [], ...additionalScopes ?? []];
155
- if (needed.length === 0) {
156
- return {
157
- allowed: false,
158
- reason: `Unknown method: ${method}. Access denied (fail-closed).`
159
- };
160
- }
161
- const clientScopes = new Set(auth.scopes);
162
- const missing = needed.filter((s) => !clientScopes.has(s));
163
- if (missing.length > 0) {
164
- return {
165
- allowed: false,
166
- reason: `Insufficient scopes for ${method}. Missing: ${missing.join(", ")}`
167
- };
168
- }
169
- return { allowed: true };
170
- }
171
- var LIOP_SCOPES = [
172
- "liop:tools:list",
173
- "liop:tools:call",
174
- "liop:resources:read",
175
- "liop:schema:read",
176
- "liop:mesh:query"
177
- ];
178
-
179
- export { DILITHIUM65_CONSTANTS, Dilithium65Wrapper, LIOP_SCOPES, authorizeRequest };
180
- //# sourceMappingURL=chunk-WPTOJYN5.js.map
181
- //# sourceMappingURL=chunk-WPTOJYN5.js.map
134
+ export { DILITHIUM65_CONSTANTS, Dilithium65Wrapper };
135
+ //# sourceMappingURL=chunk-3664H3CV.js.map
136
+ //# sourceMappingURL=chunk-3664H3CV.js.map
@@ -1,5 +1,5 @@
1
- import { LiopMcpRouter } from './chunk-IDTXJQBH.js';
2
- import { LIOP_SCOPES } from './chunk-WPTOJYN5.js';
1
+ import { LiopMcpRouter } from './chunk-DSOB2JKM.js';
2
+ import { LIOP_SCOPES } from './chunk-NXCAFF73.js';
3
3
  import { meshPeersConnected, manifestCacheSize, protocolMetrics } from './chunk-Q3FKHJ3B.js';
4
4
  import { log } from './chunk-K3DGJLUY.js';
5
5
  import * as http from 'http';
@@ -814,5 +814,5 @@ var LiopHybridGateway = class {
814
814
  };
815
815
 
816
816
  export { GRPC_WEB_CONSTANTS, InMemoryRateLimiter, LiopHybridGateway, buildProtectedResourceMetadata, decodeFrames, dispatchGrpcWebRequest, encodeDataFrame, encodeTrailerFrame, executeGatewayInterceptor, isGrpcWebRequest };
817
- //# sourceMappingURL=chunk-53QKIQNF.js.map
818
- //# sourceMappingURL=chunk-53QKIQNF.js.map
817
+ //# sourceMappingURL=chunk-6MYJBM2E.js.map
818
+ //# sourceMappingURL=chunk-6MYJBM2E.js.map
@@ -1,7 +1,8 @@
1
- import { LiopVerifier } from './chunk-ZRWNMP5L.js';
1
+ import { LiopVerifier } from './chunk-WXYDFCIW.js';
2
2
  import { Kyber768Wrapper } from './chunk-7PITYWOV.js';
3
- import { authorizeRequest, Dilithium65Wrapper } from './chunk-WPTOJYN5.js';
4
- import { TokenTelemetryEngine, liopV1, createChannelCredentials, GRPC_CHANNEL_OPTIONS } from './chunk-GFGSHQN5.js';
3
+ import { authorizeRequest } from './chunk-NXCAFF73.js';
4
+ import { Dilithium65Wrapper } from './chunk-3664H3CV.js';
5
+ import { TokenTelemetryEngine, liopV1, createChannelCredentials, GRPC_CHANNEL_OPTIONS } from './chunk-JPWC6XG6.js';
5
6
  import { toolCallsTotal, toolCallErrorsTotal, pqcHandshakeDurationMs, pqcHandshakesTotal, zkVerificationsTotal, wireEgressBytesTotal } from './chunk-Q3FKHJ3B.js';
6
7
  import { MCP_PROTOCOL_VERSION, MCP_LEGACY_SUPPORT_ENABLED, isLegacyRequest, adaptResponseForLegacyClient, MCP_PROTOCOL_VERSION_LEGACY, buildLegacyInitializeResponse, TOOL_ALIASES, normalizeToolArguments } from './chunk-KR5UZUEY.js';
7
8
  import { log } from './chunk-K3DGJLUY.js';
@@ -1502,5 +1503,5 @@ ${cachedToolList}` : "\nNo remote tools discovered yet.",
1502
1503
  };
1503
1504
 
1504
1505
  export { LiopMcpRouter };
1505
- //# sourceMappingURL=chunk-IDTXJQBH.js.map
1506
- //# sourceMappingURL=chunk-IDTXJQBH.js.map
1506
+ //# sourceMappingURL=chunk-DSOB2JKM.js.map
1507
+ //# sourceMappingURL=chunk-DSOB2JKM.js.map
@@ -1,4 +1,4 @@
1
- import { ZkVerificationError } from './chunk-P34HDRN5.js';
1
+ import { ZkVerificationError } from './chunk-FIVRGOA4.js';
2
2
  import { bn254, stringBigints } from 'micro-zk-proofs';
3
3
 
4
4
  var VERIFICATION_LATENCY_BUDGET_MS = 250;
@@ -54,5 +54,5 @@ function deserializeGrothProof(buf) {
54
54
  }
55
55
 
56
56
  export { VERIFICATION_LATENCY_BUDGET_MS, deserializeGrothProof, deserializeVKey, serializeGrothProof, serializeVKey, verifyGroth16Proof };
57
- //# sourceMappingURL=chunk-OHMZZMMC.js.map
58
- //# sourceMappingURL=chunk-OHMZZMMC.js.map
57
+ //# sourceMappingURL=chunk-ET6VRUK2.js.map
58
+ //# sourceMappingURL=chunk-ET6VRUK2.js.map
@@ -4,6 +4,7 @@ import crypto from 'crypto';
4
4
  var ProofType = /* @__PURE__ */ ((ProofType2) => {
5
5
  ProofType2[ProofType2["HMAC_LEGACY"] = 0] = "HMAC_LEGACY";
6
6
  ProofType2[ProofType2["GROTH16"] = 2] = "GROTH16";
7
+ ProofType2[ProofType2["GROTH16_PQC_HYBRID"] = 3] = "GROTH16_PQC_HYBRID";
7
8
  return ProofType2;
8
9
  })(ProofType || {});
9
10
  var RECEIPT_VERSION_V1 = 1;
@@ -74,6 +75,36 @@ var receiptCodec = {
74
75
  const checksum = crypto.createHash("sha256").update(payload).digest();
75
76
  return Buffer.concat([payload, checksum]);
76
77
  },
78
+ /**
79
+ * Encodes a version 2.1 Hybrid Binary Receipt (Groth16 + ML-DSA-65 co-sign).
80
+ * Layout:
81
+ * [0x02][0x03 ProofType.GROTH16_PQC_HYBRID][journalLen: 4B UInt32BE][journal: 144B]
82
+ * [proofLen: 2B UInt16BE][groth16 proof: ~260B]
83
+ * [sigLen: 2B UInt16BE][signature: 3309B]
84
+ * [publicKey: 1952B]
85
+ * [checksum: 32B SHA-256]
86
+ */
87
+ encodeHybridV2(journal, proof, pqcSignature, pqcPublicKey) {
88
+ const header = Buffer.alloc(6);
89
+ header.writeUInt8(RECEIPT_VERSION_V2, 0);
90
+ header.writeUInt8(3 /* GROTH16_PQC_HYBRID */, 1);
91
+ header.writeUInt32BE(journal.length, 2);
92
+ const proofLenBuf = Buffer.alloc(2);
93
+ proofLenBuf.writeUInt16BE(proof.length, 0);
94
+ const sigLenBuf = Buffer.alloc(2);
95
+ sigLenBuf.writeUInt16BE(pqcSignature.length, 0);
96
+ const payload = Buffer.concat([
97
+ header,
98
+ journal,
99
+ proofLenBuf,
100
+ proof,
101
+ sigLenBuf,
102
+ pqcSignature,
103
+ pqcPublicKey
104
+ ]);
105
+ const checksum = crypto.createHash("sha256").update(payload).digest();
106
+ return Buffer.concat([payload, checksum]);
107
+ },
77
108
  /**
78
109
  * Decodes any LIOP Binary Receipt (v1 HMAC or v2 ZK).
79
110
  */
@@ -128,6 +159,42 @@ var receiptCodec = {
128
159
  throw new ZkVerificationError("Receipt checksum verification failed.");
129
160
  }
130
161
  const journal = Buffer.from(raw.subarray(6, 6 + journalLen));
162
+ if (proofType === 3 /* GROTH16_PQC_HYBRID */) {
163
+ let offset = 6 + journalLen;
164
+ if (raw.length < offset + 2 + 32) {
165
+ throw new ZkVerificationError(
166
+ "Malformed hybrid receipt: missing proof length header."
167
+ );
168
+ }
169
+ const proofLen = raw.readUInt16BE(offset);
170
+ offset += 2;
171
+ if (raw.length < offset + proofLen + 2 + 32) {
172
+ throw new ZkVerificationError(
173
+ "Malformed hybrid receipt: truncated Groth16 proof."
174
+ );
175
+ }
176
+ const proof2 = Buffer.from(raw.subarray(offset, offset + proofLen));
177
+ offset += proofLen;
178
+ const sigLen = raw.readUInt16BE(offset);
179
+ offset += 2;
180
+ if (raw.length < offset + sigLen + 32) {
181
+ throw new ZkVerificationError(
182
+ "Malformed hybrid receipt: truncated ML-DSA-65 signature."
183
+ );
184
+ }
185
+ const pqcSignature = Buffer.from(raw.subarray(offset, offset + sigLen));
186
+ offset += sigLen;
187
+ const pqcPublicKey = Buffer.from(raw.subarray(offset, raw.length - 32));
188
+ return {
189
+ version: RECEIPT_VERSION_V2,
190
+ proofType,
191
+ journal,
192
+ proof: proof2,
193
+ pqcSignature,
194
+ pqcPublicKey,
195
+ raw
196
+ };
197
+ }
131
198
  const proof = Buffer.from(raw.subarray(6 + journalLen, raw.length - 32));
132
199
  return {
133
200
  version: RECEIPT_VERSION_V2,
@@ -209,5 +276,5 @@ var ZkVerifier = {
209
276
  };
210
277
 
211
278
  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
279
+ //# sourceMappingURL=chunk-FIVRGOA4.js.map
280
+ //# sourceMappingURL=chunk-FIVRGOA4.js.map