@nekzus/liop 1.3.0-alpha.1 → 2.0.0-alpha.2

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 (122) hide show
  1. package/README.md +41 -17
  2. package/dist/bin/agent.d.ts +0 -1
  3. package/dist/bin/agent.js +5 -306
  4. package/dist/bin/agent.js.map +1 -0
  5. package/dist/{bridge/stream.d.ts → bridge.d.ts} +44 -3
  6. package/dist/bridge.js +2 -0
  7. package/dist/bridge.js.map +1 -0
  8. package/dist/chunk-4ABAFG44.js +33 -0
  9. package/dist/chunk-4ABAFG44.js.map +1 -0
  10. package/dist/chunk-ANFXJGMP.js +2 -0
  11. package/dist/chunk-ANFXJGMP.js.map +1 -0
  12. package/dist/chunk-DBXGYHKY.js +2 -0
  13. package/dist/chunk-DBXGYHKY.js.map +1 -0
  14. package/dist/chunk-HM77MWB6.js +2 -0
  15. package/dist/chunk-HM77MWB6.js.map +1 -0
  16. package/dist/chunk-HNDVAKEK.js +24 -0
  17. package/dist/chunk-HNDVAKEK.js.map +1 -0
  18. package/dist/chunk-HQZHZM6U.js +2 -0
  19. package/dist/chunk-HQZHZM6U.js.map +1 -0
  20. package/dist/chunk-P52IE4L6.js +2 -0
  21. package/dist/chunk-P52IE4L6.js.map +1 -0
  22. package/dist/chunk-PIBCW4BD.js +13 -0
  23. package/dist/chunk-PIBCW4BD.js.map +1 -0
  24. package/dist/chunk-PPCOS2NU.js +2 -0
  25. package/dist/chunk-PPCOS2NU.js.map +1 -0
  26. package/dist/chunk-RWRRBYG4.js +2 -0
  27. package/dist/chunk-RWRRBYG4.js.map +1 -0
  28. package/dist/chunk-S6RJHZV2.js +2 -0
  29. package/dist/chunk-S6RJHZV2.js.map +1 -0
  30. package/dist/chunk-UVTEJYHN.js +2 -0
  31. package/dist/chunk-UVTEJYHN.js.map +1 -0
  32. package/dist/chunk-X6FJATUE.js +29 -0
  33. package/dist/chunk-X6FJATUE.js.map +1 -0
  34. package/dist/chunk-XLVRRGOX.js +3 -0
  35. package/dist/chunk-XLVRRGOX.js.map +1 -0
  36. package/dist/client.d.ts +5 -0
  37. package/dist/client.js +2 -0
  38. package/dist/client.js.map +1 -0
  39. package/dist/{gateway/router.d.ts → gateway.d.ts} +37 -5
  40. package/dist/gateway.js +2 -0
  41. package/dist/gateway.js.map +1 -0
  42. package/dist/{client/index.d.ts → index-CyxNLlz7.d.ts} +24 -5
  43. package/dist/index.d.ts +313 -12
  44. package/dist/index.js +31 -12
  45. package/dist/index.js.map +1 -0
  46. package/dist/kyber-2WDOTUQX.js +2 -0
  47. package/dist/kyber-2WDOTUQX.js.map +1 -0
  48. package/dist/{mesh/node.d.ts → mesh.d.ts} +5 -3
  49. package/dist/mesh.js +2 -0
  50. package/dist/mesh.js.map +1 -0
  51. package/dist/{server/index.d.ts → server.d.ts} +145 -10
  52. package/dist/server.js +2 -0
  53. package/dist/server.js.map +1 -0
  54. package/dist/types.d.ts +17 -14
  55. package/dist/types.js +2 -26
  56. package/dist/types.js.map +1 -0
  57. package/dist/{crypto/verifier.d.ts → verifier-DTCD9imJ.d.ts} +3 -1
  58. package/dist/verifier-RQRYXA4C.js +2 -0
  59. package/dist/verifier-RQRYXA4C.js.map +1 -0
  60. package/dist/workers/logic-execution.d.ts +4 -2
  61. package/dist/workers/logic-execution.js +2 -123
  62. package/dist/workers/logic-execution.js.map +1 -0
  63. package/dist/workers/zk-verifier.d.ts +4 -2
  64. package/dist/workers/zk-verifier.js +2 -98
  65. package/dist/workers/zk-verifier.js.map +1 -0
  66. package/package.json +31 -17
  67. package/dist/bridge/index.d.ts +0 -37
  68. package/dist/bridge/index.js +0 -249
  69. package/dist/bridge/stream.js +0 -210
  70. package/dist/client/index.js +0 -275
  71. package/dist/crypto/logic-image-id.d.ts +0 -3
  72. package/dist/crypto/logic-image-id.js +0 -27
  73. package/dist/crypto/verifier.js +0 -97
  74. package/dist/economy/estimator.d.ts +0 -53
  75. package/dist/economy/estimator.js +0 -69
  76. package/dist/economy/index.d.ts +0 -5
  77. package/dist/economy/index.js +0 -3
  78. package/dist/economy/otel.d.ts +0 -38
  79. package/dist/economy/otel.js +0 -100
  80. package/dist/economy/telemetry.d.ts +0 -77
  81. package/dist/economy/telemetry.js +0 -224
  82. package/dist/errors.d.ts +0 -14
  83. package/dist/errors.js +0 -19
  84. package/dist/gateway/hybrid.d.ts +0 -23
  85. package/dist/gateway/hybrid.js +0 -199
  86. package/dist/gateway/router.js +0 -1036
  87. package/dist/mesh/index.d.ts +0 -1
  88. package/dist/mesh/index.js +0 -1
  89. package/dist/mesh/node.js +0 -853
  90. package/dist/prompts/adapters.d.ts +0 -16
  91. package/dist/prompts/adapters.js +0 -55
  92. package/dist/rpc/client.d.ts +0 -22
  93. package/dist/rpc/client.js +0 -40
  94. package/dist/rpc/codec/lpm.d.ts +0 -20
  95. package/dist/rpc/codec/lpm.js +0 -36
  96. package/dist/rpc/crypto/aes.d.ts +0 -22
  97. package/dist/rpc/crypto/aes.js +0 -47
  98. package/dist/rpc/crypto/kyber.d.ts +0 -27
  99. package/dist/rpc/crypto/kyber.js +0 -70
  100. package/dist/rpc/proto.d.ts +0 -2
  101. package/dist/rpc/proto.js +0 -33
  102. package/dist/rpc/server.d.ts +0 -13
  103. package/dist/rpc/server.js +0 -50
  104. package/dist/rpc/tls.d.ts +0 -26
  105. package/dist/rpc/tls.js +0 -54
  106. package/dist/rpc/types.d.ts +0 -28
  107. package/dist/rpc/types.js +0 -5
  108. package/dist/sandbox/guardian.d.ts +0 -18
  109. package/dist/sandbox/guardian.js +0 -58
  110. package/dist/sandbox/wasi.d.ts +0 -36
  111. package/dist/sandbox/wasi.js +0 -209
  112. package/dist/security/guardian.d.ts +0 -22
  113. package/dist/security/guardian.js +0 -52
  114. package/dist/security/zk.d.ts +0 -37
  115. package/dist/security/zk.js +0 -76
  116. package/dist/server/index.js +0 -937
  117. package/dist/server/pii.d.ts +0 -40
  118. package/dist/server/pii.js +0 -266
  119. package/dist/utils/logger.d.ts +0 -21
  120. package/dist/utils/logger.js +0 -70
  121. package/dist/utils/mcpCompact.d.ts +0 -11
  122. package/dist/utils/mcpCompact.js +0 -29
@@ -1,16 +0,0 @@
1
- /**
2
- * LIOP Cross-AI Prompt Adapters (Fase 92)
3
- *
4
- * Normalizes system instructions for different LLM providers (Claude, OpenAI, Gemini)
5
- * to ensure they understand how to generate "Logic-on-Origin" WASM-compatible payload structures.
6
- */
7
- export type AIProvider = "claude" | "openai" | "gemini";
8
- export interface PromptConfig {
9
- xmlStandard: boolean;
10
- jsonSchemaPreferred: boolean;
11
- }
12
- /**
13
- * Generates specific System Prompts optimized for the provided AI.
14
- * This instructs the LLM on how to bypass Context-Pulling and use Logic-Injection (Zero-Shot).
15
- */
16
- export declare function generateSystemInstructions(provider: AIProvider): string;
@@ -1,55 +0,0 @@
1
- /**
2
- * LIOP Cross-AI Prompt Adapters (Fase 92)
3
- *
4
- * Normalizes system instructions for different LLM providers (Claude, OpenAI, Gemini)
5
- * to ensure they understand how to generate "Logic-on-Origin" WASM-compatible payload structures.
6
- */
7
- const PROVIDER_CONFIGS = {
8
- claude: { xmlStandard: true, jsonSchemaPreferred: false },
9
- openai: { xmlStandard: false, jsonSchemaPreferred: true },
10
- gemini: { xmlStandard: false, jsonSchemaPreferred: true },
11
- };
12
- /**
13
- * Generates specific System Prompts optimized for the provided AI.
14
- * This instructs the LLM on how to bypass Context-Pulling and use Logic-Injection (Zero-Shot).
15
- */
16
- export function generateSystemInstructions(provider) {
17
- const config = PROVIDER_CONFIGS[provider];
18
- let instructions = `[LIOP-PROTO-V1: LOGIC-ON-ORIGIN SPECIFICATION]
19
- You are interacting with a Logic-Injection-on-Origin Protocol (LIOP) Mesh Network.
20
- Unlike standard MCP where you pull context to evaluate it remotely, in LIOP you WRITE code that executes on the data's origin.
21
-
22
- ### CORE PARADIGM
23
- When you call a tool or resource, you MUST provide a payload that represents secure sandboxed logic to be executed on the remote Node.
24
- The node will execute your logic securely on the raw secure data, and return only the RESULT, avoiding PII data egress.
25
-
26
- ### EXECUTION RULES
27
- 1. Provide a self-contained JavaScript syntax block that we will compile to WASM-Sandboxed logic.
28
- 2. Rely only on standard ECMA script features (No Node.js polyfills).
29
- 3. The logic must end by returning the calculated insights, not the raw data.
30
- `;
31
- if (config.xmlStandard) {
32
- instructions += `
33
- ### PAYLOAD FORMATTING (CLAUDE-XML PREFERRED)
34
- You must wrap your logic precisely within <liop_logic> tags.
35
- Example:
36
- <liop_logic>
37
- const records = await liop.readResource("liop://vault/patients");
38
- const filtered = records.filter(r => r.disease === "Hypertension");
39
- return { alert: "High risk demographic", targetCount: filtered.length };
40
- </liop_logic>
41
- `;
42
- }
43
- else if (config.jsonSchemaPreferred) {
44
- instructions += `
45
- ### PAYLOAD FORMATTING (JSON PARSING PREFERRED)
46
- You must provide your logic strictly within a JSON string key called \`"logic_blob"\` inside your tool call parameters.
47
- Example:
48
- {
49
- "target": "liop://vault/patients",
50
- "logic_blob": "const records = await liop.readResource(args.target); return { targetCount: records.filter(r => r.disease === 'Hypertension').length };"
51
- }
52
- `;
53
- }
54
- return instructions;
55
- }
@@ -1,22 +0,0 @@
1
- import type * as grpc from "@grpc/grpc-js";
2
- import { type LiopTlsOptions } from "./tls.js";
3
- import type { IntentRequest, IntentResponse, LogicRequest, LogicResponse } from "./types.js";
4
- /**
5
- * LIOP gRPC Client Implementation
6
- * Provides a high-level interface for secure intent negotiation and logic execution.
7
- */
8
- export declare class LiopRpcClient {
9
- private client;
10
- constructor(address: string, tls?: LiopTlsOptions);
11
- /**
12
- * Negotiates intent with the remote host.
13
- * Returns the ephemeral Kyber public key for payload encryption.
14
- */
15
- negotiateIntent(request: IntentRequest): Promise<IntentResponse>;
16
- /**
17
- * Pushes the encrypted Logic-on-Origin payload to the origin.
18
- * Returns a stream of semantic responses and ZK proofs.
19
- */
20
- executeLogic(request: LogicRequest): grpc.ClientReadableStream<LogicResponse>;
21
- close(): void;
22
- }
@@ -1,40 +0,0 @@
1
- import { liopV1 } from "./proto.js";
2
- import { createChannelCredentials } from "./tls.js";
3
- /**
4
- * LIOP gRPC Client Implementation
5
- * Provides a high-level interface for secure intent negotiation and logic execution.
6
- */
7
- export class LiopRpcClient {
8
- // biome-ignore lint/suspicious/noExplicitAny: internal gRPC client type
9
- client;
10
- constructor(address, tls) {
11
- const credentials = createChannelCredentials(tls);
12
- this.client = new liopV1.LogicMesh(address, credentials);
13
- }
14
- /**
15
- * Negotiates intent with the remote host.
16
- * Returns the ephemeral Kyber public key for payload encryption.
17
- */
18
- async negotiateIntent(request) {
19
- return new Promise((resolve, reject) => {
20
- this.client.NegotiateIntent(request, (error, response) => {
21
- if (error) {
22
- reject(error);
23
- }
24
- else {
25
- resolve(response);
26
- }
27
- });
28
- });
29
- }
30
- /**
31
- * Pushes the encrypted Logic-on-Origin payload to the origin.
32
- * Returns a stream of semantic responses and ZK proofs.
33
- */
34
- executeLogic(request) {
35
- return this.client.ExecuteLogic(request);
36
- }
37
- close() {
38
- this.client.close();
39
- }
40
- }
@@ -1,20 +0,0 @@
1
- /**
2
- * LIOP gRPC Length-Prefixed Message (LPM) Codec
3
- *
4
- * Implements the standard gRPC-over-HTTP2 framing:
5
- * [1 byte: Compressed Flag] [4 bytes: Message Length] [Data]
6
- */
7
- export declare class LpmCodec {
8
- /**
9
- * Encodes a data buffer into a gRPC Length-Prefixed Message
10
- */
11
- static encode(data: Uint8Array): Uint8Array;
12
- /**
13
- * Decodes a gRPC Length-Prefixed Message from a buffer
14
- * Returns the data and the remaining buffer
15
- */
16
- static decode(buffer: Uint8Array): {
17
- data: Uint8Array | null;
18
- remaining: Uint8Array;
19
- };
20
- }
@@ -1,36 +0,0 @@
1
- /**
2
- * LIOP gRPC Length-Prefixed Message (LPM) Codec
3
- *
4
- * Implements the standard gRPC-over-HTTP2 framing:
5
- * [1 byte: Compressed Flag] [4 bytes: Message Length] [Data]
6
- */
7
- // biome-ignore lint/complexity/noStaticOnlyClass: organizational class pattern
8
- export class LpmCodec {
9
- /**
10
- * Encodes a data buffer into a gRPC Length-Prefixed Message
11
- */
12
- static encode(data) {
13
- const result = new Uint8Array(5 + data.length);
14
- result[0] = 0; // Compressed flag
15
- const dv = new DataView(result.buffer);
16
- dv.setUint32(1, data.length); // Big-endian by default
17
- result.set(data, 5);
18
- return result;
19
- }
20
- /**
21
- * Decodes a gRPC Length-Prefixed Message from a buffer
22
- * Returns the data and the remaining buffer
23
- */
24
- static decode(buffer) {
25
- if (buffer.length < 5)
26
- return { data: null, remaining: buffer };
27
- const dv = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
28
- const length = dv.getUint32(1);
29
- if (buffer.length < 5 + length) {
30
- return { data: null, remaining: buffer };
31
- }
32
- const data = buffer.slice(5, 5 + length);
33
- const remaining = buffer.slice(5 + length);
34
- return { data, remaining };
35
- }
36
- }
@@ -1,22 +0,0 @@
1
- /**
2
- * LIOP Symmetric Payload Encryption Wrapper
3
- * Uses AES-256-GCM to secure WASM Code transport over Zero-Trust networks.
4
- * Fully compatible with the `aes-gcm` Rust crate used by Wasmtime.
5
- */
6
- export declare const AesGcmWrapper: {
7
- /**
8
- * Encrypts a raw WASM payload using the shared secret negotiated via Kyber768.
9
- *
10
- * @param payload Raw incoming WASM byte array or string.
11
- * @param sharedSecret A perfectly derived 32-byte (256-bit) shared secret array
12
- * @returns The encrypted buffer to push to the GRPc stream, along with the 12-byte initialization vector natively generated.
13
- */
14
- encryptPayload(payload: Uint8Array | Buffer, sharedSecret: Uint8Array): {
15
- ciphertext: Buffer;
16
- nonce: Buffer;
17
- };
18
- /**
19
- * Decrypts a remote Zero-Knowledge receipt using AES-256-GCM.
20
- */
21
- decryptPayload(ciphertextBuffer: Buffer, nonce: Buffer, sharedSecret: Uint8Array): Buffer;
22
- };
@@ -1,47 +0,0 @@
1
- import { createCipheriv, createDecipheriv, randomBytes } from "node:crypto";
2
- /**
3
- * LIOP Symmetric Payload Encryption Wrapper
4
- * Uses AES-256-GCM to secure WASM Code transport over Zero-Trust networks.
5
- * Fully compatible with the `aes-gcm` Rust crate used by Wasmtime.
6
- */
7
- export const AesGcmWrapper = {
8
- /**
9
- * Encrypts a raw WASM payload using the shared secret negotiated via Kyber768.
10
- *
11
- * @param payload Raw incoming WASM byte array or string.
12
- * @param sharedSecret A perfectly derived 32-byte (256-bit) shared secret array
13
- * @returns The encrypted buffer to push to the GRPc stream, along with the 12-byte initialization vector natively generated.
14
- */
15
- encryptPayload(payload, sharedSecret) {
16
- if (sharedSecret.length !== 32) {
17
- throw new Error("Symmetric Key must be exactly 32 bytes (256 bits).");
18
- }
19
- // LIOP standard demands 96-bit (12 byte) IVs/Nonces for AES-GCM
20
- const nonce = randomBytes(12);
21
- const cipher = createCipheriv("aes-256-gcm", sharedSecret, nonce);
22
- // Encrypt the payload and seal the tag
23
- const encrypted = Buffer.concat([cipher.update(payload), cipher.final()]);
24
- const authTag = cipher.getAuthTag(); // 16 bytes for GCM integrity
25
- // In LIOP, the auth tag is strictly appended to the end of the ciphertext bytes
26
- // mirroring the default serialization logic within `aes_gcm::Aes256Gcm` in Rust
27
- const finalCiphertext = Buffer.concat([encrypted, authTag]);
28
- return {
29
- ciphertext: finalCiphertext,
30
- nonce: nonce,
31
- };
32
- },
33
- /**
34
- * Decrypts a remote Zero-Knowledge receipt using AES-256-GCM.
35
- */
36
- decryptPayload(ciphertextBuffer, nonce, sharedSecret) {
37
- if (ciphertextBuffer.length < 16) {
38
- throw new Error("Invalid GCM Ciphertext; missing authentication tag length");
39
- }
40
- // The last 16 bytes represent the AuthTag appended by rust-aes-gcm
41
- const encryptedData = ciphertextBuffer.subarray(0, -16);
42
- const authTag = ciphertextBuffer.subarray(-16);
43
- const decipher = createDecipheriv("aes-256-gcm", sharedSecret, nonce);
44
- decipher.setAuthTag(authTag);
45
- return Buffer.concat([decipher.update(encryptedData), decipher.final()]);
46
- },
47
- };
@@ -1,27 +0,0 @@
1
- export declare const Kyber768Wrapper: {
2
- /**
3
- * Extracts and validates the 1184-byte Public Key from the Rust LIOP Data Node
4
- * @param buffer Raw buffer sent via gRPC IntentResponse
5
- */
6
- importPublicKey(buffer: Uint8Array): Uint8Array;
7
- /**
8
- * Encapsulates a shared secret using the server's public key.
9
- * Returns the 1088-byte ciphertext to be sent back, and the 32-byte shared AES secret.
10
- */
11
- encapsulateAsymmetric(publicKey: Uint8Array): Promise<{
12
- ciphertext: Uint8Array;
13
- sharedSecret: Uint8Array;
14
- }>;
15
- /**
16
- * Generates a Kyber768 KeyPair for the server to accept intents.
17
- */
18
- generateKeyPair(): Promise<{
19
- publicKey: Uint8Array;
20
- secretKey: Uint8Array;
21
- }>;
22
- /**
23
- * Decapsulates the shared secret using the server's secret key.
24
- * Zero-fills the shared secret buffer after extraction for side-channel protection.
25
- */
26
- decapsulateSymmetric(ciphertext: Uint8Array, secretKey: Uint8Array): Promise<Uint8Array>;
27
- };
@@ -1,70 +0,0 @@
1
- import { createMlKem768 } from "mlkem";
2
- /**
3
- * LIOP Post-Quantum Cryptography Wrapper
4
- * Implements ML-KEM-768 (NIST FIPS 203) for Zero-Trust secure key encapsulation
5
- * directly compatible with `pqcrypto-kyber` on the Mesh-Node Backend.
6
- *
7
- * Uses the `mlkem` package which provides:
8
- * - FIPS 203 compliance (ML-KEM standard)
9
- * - Constant-time validation (KyberSlash patched)
10
- * - ~3.5x performance improvement over legacy crystals-kyber
11
- */
12
- /** Lazy-initialized singleton for the ML-KEM-768 engine */
13
- let kemInstance = null;
14
- async function getKemInstance() {
15
- if (!kemInstance) {
16
- kemInstance = await createMlKem768();
17
- }
18
- return kemInstance;
19
- }
20
- export const Kyber768Wrapper = {
21
- /**
22
- * Extracts and validates the 1184-byte Public Key from the Rust LIOP Data Node
23
- * @param buffer Raw buffer sent via gRPC IntentResponse
24
- */
25
- importPublicKey(buffer) {
26
- if (buffer.length !== 1184) {
27
- throw new Error(`Kyber768 Public Key must be exactly 1184 bytes (Received: ${buffer.length})`);
28
- }
29
- return buffer;
30
- },
31
- /**
32
- * Encapsulates a shared secret using the server's public key.
33
- * Returns the 1088-byte ciphertext to be sent back, and the 32-byte shared AES secret.
34
- */
35
- async encapsulateAsymmetric(publicKey) {
36
- try {
37
- if (publicKey.length !== 1184) {
38
- throw new Error("Kyber768 Public Key must be exactly 1184 bytes.");
39
- }
40
- const kem = await getKemInstance();
41
- const [ct, ss] = kem.encap(publicKey);
42
- return {
43
- ciphertext: ct,
44
- sharedSecret: ss,
45
- };
46
- }
47
- catch (error) {
48
- throw new Error(`Failed to perform PQC encapsulation: ${error.message}`);
49
- }
50
- },
51
- /**
52
- * Generates a Kyber768 KeyPair for the server to accept intents.
53
- */
54
- async generateKeyPair() {
55
- const kem = await getKemInstance();
56
- const [pk, sk] = kem.generateKeyPair();
57
- return {
58
- publicKey: pk,
59
- secretKey: sk,
60
- };
61
- },
62
- /**
63
- * Decapsulates the shared secret using the server's secret key.
64
- * Zero-fills the shared secret buffer after extraction for side-channel protection.
65
- */
66
- async decapsulateSymmetric(ciphertext, secretKey) {
67
- const kem = await getKemInstance();
68
- return kem.decap(ciphertext, secretKey);
69
- },
70
- };
@@ -1,2 +0,0 @@
1
- export declare const liopProto: any;
2
- export declare const liopV1: any;
package/dist/rpc/proto.js DELETED
@@ -1,33 +0,0 @@
1
- import path from "node:path";
2
- import { fileURLToPath } from "node:url";
3
- import * as grpc from "@grpc/grpc-js";
4
- import * as protoLoader from "@grpc/proto-loader";
5
- const __filename = fileURLToPath(import.meta.url);
6
- const __dirname = path.dirname(__filename);
7
- import * as fs from "node:fs";
8
- import { log } from "../utils/logger.js";
9
- // Selection logic
10
- const PROD_PROTO_PATH = path.resolve(__dirname, "../protocol/liop_core.proto");
11
- // 2. Fallback to monorepo development path
12
- const DEV_PROTO_PATH = path.resolve(__dirname, "../../../../protocol/proto/liop_core.proto");
13
- // Selection logic
14
- const PROTO_PATH = fs.existsSync(PROD_PROTO_PATH)
15
- ? PROD_PROTO_PATH
16
- : DEV_PROTO_PATH;
17
- if (!fs.existsSync(PROTO_PATH)) {
18
- log.error(`[LIOP-Proto] CRITICAL: Proto file not found at ${PROTO_PATH}`);
19
- }
20
- /**
21
- * LIOP Proto Loader
22
- * Loads the core gRPC definitions for the Logic-Injection-on-Origin Protocol.
23
- */
24
- const packageDefinition = protoLoader.loadSync(PROTO_PATH, {
25
- keepCase: true,
26
- longs: String,
27
- enums: String,
28
- defaults: true,
29
- oneofs: true,
30
- });
31
- // biome-ignore lint/suspicious/noExplicitAny: gRPC dynamic loading requires any for the service definition map
32
- export const liopProto = grpc.loadPackageDefinition(packageDefinition);
33
- export const liopV1 = liopProto.liop.v1;
@@ -1,13 +0,0 @@
1
- import * as grpc from "@grpc/grpc-js";
2
- import { type LiopTlsOptions } from "./tls.js";
3
- import type { IntentRequest, IntentResponse, LogicRequest, LogicResponse } from "./types.js";
4
- export declare class LiopRpcServer {
5
- private server;
6
- constructor();
7
- addService(handlers: {
8
- negotiateIntent: (call: grpc.ServerUnaryCall<IntentRequest, IntentResponse>, callback: grpc.sendUnaryData<IntentResponse>) => void;
9
- executeLogic: (call: grpc.ServerWritableStream<LogicRequest, LogicResponse>) => void;
10
- }): void;
11
- listen(port?: number, tls?: LiopTlsOptions): Promise<number>;
12
- stop(): Promise<void>;
13
- }
@@ -1,50 +0,0 @@
1
- import * as grpc from "@grpc/grpc-js";
2
- import { log } from "../utils/logger.js";
3
- import { liopV1 } from "./proto.js";
4
- import { createServerCredentials } from "./tls.js";
5
- /**
6
- * LIOP gRPC Service Implementation
7
- * Handles intent negotiation and secure logic execution.
8
- */
9
- /** Production-grade gRPC channel options per official grpc-node recommendations */
10
- const GRPC_CHANNEL_OPTIONS = {
11
- "grpc.keepalive_time_ms": 30_000,
12
- "grpc.keepalive_timeout_ms": 10_000,
13
- "grpc.keepalive_permit_without_calls": 1,
14
- "grpc.max_send_message_length": -1,
15
- "grpc.max_receive_message_length": -1,
16
- "grpc.enable_retries": 1,
17
- };
18
- export class LiopRpcServer {
19
- server;
20
- constructor() {
21
- this.server = new grpc.Server(GRPC_CHANNEL_OPTIONS);
22
- }
23
- addService(handlers) {
24
- this.server.addService(liopV1.LogicMesh.service, {
25
- NegotiateIntent: handlers.negotiateIntent,
26
- ExecuteLogic: handlers.executeLogic,
27
- });
28
- }
29
- async listen(port = 50051, tls) {
30
- const credentials = createServerCredentials(tls);
31
- return new Promise((resolve, reject) => {
32
- this.server.bindAsync(`0.0.0.0:${port}`, credentials, (error, assignedPort) => {
33
- if (error) {
34
- reject(error);
35
- return;
36
- }
37
- log.info(`[LIOP-RPC] Server listening on port ${assignedPort}`);
38
- resolve(assignedPort);
39
- });
40
- });
41
- }
42
- async stop() {
43
- return new Promise((resolve) => {
44
- this.server.tryShutdown(() => {
45
- log.info("[LIOP-RPC] Server shut down");
46
- resolve();
47
- });
48
- });
49
- }
50
- }
package/dist/rpc/tls.d.ts DELETED
@@ -1,26 +0,0 @@
1
- /**
2
- * LIOP TLS Configuration
3
- *
4
- * Provides conditional TLS credential factories for gRPC connections.
5
- * When TLS options are provided, connections are secured with mutual TLS.
6
- * Otherwise, falls back to insecure credentials (alpha/development mode).
7
- */
8
- import * as grpc from "@grpc/grpc-js";
9
- export interface LiopTlsOptions {
10
- /** Path to the root CA certificate (PEM format) */
11
- rootCert?: string;
12
- /** Path to the server/client certificate (PEM format) */
13
- certChain?: string;
14
- /** Path to the private key (PEM format) */
15
- privateKey?: string;
16
- }
17
- /**
18
- * Creates gRPC server credentials from TLS options.
19
- * Falls back to insecure if no options are provided.
20
- */
21
- export declare function createServerCredentials(tls?: LiopTlsOptions): grpc.ServerCredentials;
22
- /**
23
- * Creates gRPC channel credentials from TLS options.
24
- * Falls back to insecure if no options are provided.
25
- */
26
- export declare function createChannelCredentials(tls?: LiopTlsOptions): grpc.ChannelCredentials;
package/dist/rpc/tls.js DELETED
@@ -1,54 +0,0 @@
1
- /**
2
- * LIOP TLS Configuration
3
- *
4
- * Provides conditional TLS credential factories for gRPC connections.
5
- * When TLS options are provided, connections are secured with mutual TLS.
6
- * Otherwise, falls back to insecure credentials (alpha/development mode).
7
- */
8
- import * as fs from "node:fs";
9
- import * as grpc from "@grpc/grpc-js";
10
- import { log } from "../utils/logger.js";
11
- /**
12
- * Creates gRPC server credentials from TLS options.
13
- * Falls back to insecure if no options are provided.
14
- */
15
- export function createServerCredentials(tls) {
16
- if (!tls?.certChain || !tls?.privateKey) {
17
- return grpc.ServerCredentials.createInsecure();
18
- }
19
- try {
20
- const rootCert = tls.rootCert ? fs.readFileSync(tls.rootCert) : null;
21
- const certChain = fs.readFileSync(tls.certChain);
22
- const privateKey = fs.readFileSync(tls.privateKey);
23
- return grpc.ServerCredentials.createSsl(rootCert, [
24
- { cert_chain: certChain, private_key: privateKey },
25
- ]);
26
- }
27
- catch (error) {
28
- log.info(`[LIOP-TLS] Failed to load certificates, falling back to insecure: ${error}`);
29
- return grpc.ServerCredentials.createInsecure();
30
- }
31
- }
32
- /**
33
- * Creates gRPC channel credentials from TLS options.
34
- * Falls back to insecure if no options are provided.
35
- */
36
- export function createChannelCredentials(tls) {
37
- if (!tls?.rootCert) {
38
- return grpc.credentials.createInsecure();
39
- }
40
- try {
41
- const rootCert = fs.readFileSync(tls.rootCert);
42
- const certChain = tls.certChain
43
- ? fs.readFileSync(tls.certChain)
44
- : undefined;
45
- const privateKey = tls.privateKey
46
- ? fs.readFileSync(tls.privateKey)
47
- : undefined;
48
- return grpc.credentials.createSsl(rootCert, privateKey, certChain);
49
- }
50
- catch (error) {
51
- log.info(`[LIOP-TLS] Failed to load certificates, falling back to insecure: ${error}`);
52
- return grpc.credentials.createInsecure();
53
- }
54
- }
@@ -1,28 +0,0 @@
1
- /**
2
- * TypeScript interfaces reflecting liop_core.proto (LIOP v1)
3
- * Optimized for logic-on-origin and high-performance serialization.
4
- */
5
- export interface IntentRequest {
6
- agent_did: string;
7
- capability_hash: string;
8
- proof_of_intent: Uint8Array;
9
- }
10
- export interface IntentResponse {
11
- accepted: boolean;
12
- session_token: string;
13
- error_message: string;
14
- kyber_public_key: Uint8Array;
15
- }
16
- export interface LogicRequest {
17
- session_token: string;
18
- wasm_binary: Uint8Array;
19
- inputs: Record<string, Uint8Array>;
20
- pqc_ciphertext: Uint8Array;
21
- aes_nonce: Uint8Array;
22
- }
23
- export interface LogicResponse {
24
- semantic_evidence: string;
25
- cryptographic_proof: Uint8Array;
26
- zk_receipt: Uint8Array;
27
- is_error: boolean;
28
- }
package/dist/rpc/types.js DELETED
@@ -1,5 +0,0 @@
1
- /**
2
- * TypeScript interfaces reflecting liop_core.proto (LIOP v1)
3
- * Optimized for logic-on-origin and high-performance serialization.
4
- */
5
- export {};
@@ -1,18 +0,0 @@
1
- export declare class GuardianError extends Error {
2
- constructor(message: string);
3
- }
4
- /**
5
- * The Guardian-TS Module
6
- * Scans the Abstract Syntax Tree (AST) imports of incoming WASM
7
- * before it reaches the V8 Wasmtime engine to prevent sandbox-escape
8
- * zero-days, resource exhaustion bombs, and evasive execution.
9
- */
10
- export declare const ASTGuardian: {
11
- /**
12
- * Analyzes the WebAssembly Module interface proactively.
13
- *
14
- * @param module - The compiled WebAssembly.Module to inspect
15
- * @throws {GuardianError} If illegal imports or capabilities are detected
16
- */
17
- analyze(module: WebAssembly.Module): void;
18
- };
@@ -1,58 +0,0 @@
1
- export class GuardianError extends Error {
2
- constructor(message) {
3
- super(`AST Sec-Policy Violation: ${message}`);
4
- this.name = "GuardianError";
5
- }
6
- }
7
- /**
8
- * The Guardian-TS Module
9
- * Scans the Abstract Syntax Tree (AST) imports of incoming WASM
10
- * before it reaches the V8 Wasmtime engine to prevent sandbox-escape
11
- * zero-days, resource exhaustion bombs, and evasive execution.
12
- */
13
- export const ASTGuardian = {
14
- /**
15
- * Analyzes the WebAssembly Module interface proactively.
16
- *
17
- * @param module - The compiled WebAssembly.Module to inspect
18
- * @throws {GuardianError} If illegal imports or capabilities are detected
19
- */
20
- analyze(module) {
21
- const imports = WebAssembly.Module.imports(module);
22
- let _importCount = 0;
23
- const ALLOWED_WASI_FUNCTIONS = new Set([
24
- "fd_write",
25
- "fd_read",
26
- "fd_close",
27
- "fd_seek",
28
- "environ_get",
29
- "environ_sizes_get",
30
- "args_get",
31
- "args_sizes_get",
32
- "clock_time_get",
33
- "random_get",
34
- "proc_exit",
35
- "fd_prestat_get",
36
- "fd_prestat_dir_name",
37
- "fd_fdstat_get",
38
- ]);
39
- for (const imp of imports) {
40
- // Strict Sandbox Validation: Only allow WASI preview 1 specific whitelisted functions.
41
- if (imp.module === "wasi_snapshot_preview1") {
42
- if (!ALLOWED_WASI_FUNCTIONS.has(imp.name)) {
43
- throw new GuardianError(`Banned WASI Import Detected: ${imp.module}/${imp.name}`);
44
- }
45
- }
46
- else {
47
- throw new GuardianError(`Banned Host Import Module Detected: ${imp.module}`);
48
- }
49
- _importCount++;
50
- if (_importCount > 128) {
51
- throw new GuardianError("Import limit exceeded. Possible resource exhaustion attack.");
52
- }
53
- }
54
- // In Node.js / V8, the maximum module size and function limits
55
- // are natively enforced by the engine during compilation.
56
- // A successfully compiled WebAssembly.Module already passed structural checks.
57
- },
58
- };