@nekzus/liop 2.4.0-alpha.25 → 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 (61) hide show
  1. package/dist/bin/agent.js +27 -933
  2. package/dist/bridge.js +1 -5
  3. package/dist/chunk-2XHSALII.js +3 -0
  4. package/dist/chunk-2ZYX736J.js +2 -0
  5. package/dist/chunk-3WRKTVOF.js +2 -0
  6. package/dist/chunk-6KFKO6ZX.js +2 -0
  7. package/dist/chunk-6VK2XALI.js +2 -0
  8. package/dist/chunk-AYDF3IFZ.js +2 -0
  9. package/dist/chunk-CTTTLCGL.js +31 -0
  10. package/dist/chunk-ECRS6N33.js +4 -0
  11. package/dist/chunk-FDJMH4CB.js +2 -0
  12. package/dist/chunk-FTF6AMF6.js +0 -1
  13. package/dist/chunk-GWVSCZUS.js +2 -0
  14. package/dist/chunk-LEXMMIQI.js +15 -0
  15. package/dist/chunk-LM26HOJ6.js +31 -0
  16. package/dist/chunk-MQ5SU26J.js +2 -0
  17. package/dist/chunk-N35BC62H.js +2 -0
  18. package/dist/chunk-P6IJ3VBD.js +3 -0
  19. package/dist/chunk-TKLRW52V.js +2 -0
  20. package/dist/chunk-V35CXJQN.js +2 -0
  21. package/dist/chunk-WP5ER7RH.js +3 -0
  22. package/dist/chunk-XLVEDKM6.js +2 -0
  23. package/dist/chunk-Y675R34Z.js +2 -0
  24. package/dist/chunk-YD2AF2M6.js +46 -0
  25. package/dist/chunk-YLCNV764.js +3 -0
  26. package/dist/chunk-ZZMSFCJP.js +3 -0
  27. package/dist/client.js +1 -12
  28. package/dist/gateway.js +1 -13
  29. package/dist/index.js +4 -320
  30. package/dist/kyber-PULV7PQX.js +2 -0
  31. package/dist/mesh.js +1 -5
  32. package/dist/server.js +1 -10
  33. package/dist/types.js +1 -3
  34. package/dist/verifier-J4NQYZX5.js +2 -0
  35. package/dist/workers/logic-execution.js +1 -355
  36. package/dist/workers/zk-verifier.js +1 -275
  37. package/package.json +1 -1
  38. package/dist/chunk-3664H3CV.js +0 -136
  39. package/dist/chunk-3QH44NKZ.js +0 -115
  40. package/dist/chunk-6MYJBM2E.js +0 -818
  41. package/dist/chunk-7PITYWOV.js +0 -68
  42. package/dist/chunk-DSOB2JKM.js +0 -1507
  43. package/dist/chunk-ET6VRUK2.js +0 -58
  44. package/dist/chunk-FIVRGOA4.js +0 -280
  45. package/dist/chunk-IHKKWXHJ.js +0 -876
  46. package/dist/chunk-IK7CGWAZ.js +0 -24
  47. package/dist/chunk-JPWC6XG6.js +0 -941
  48. package/dist/chunk-K3DGJLUY.js +0 -106
  49. package/dist/chunk-KR5UZUEY.js +0 -98
  50. package/dist/chunk-NXCAFF73.js +0 -59
  51. package/dist/chunk-Q3FKHJ3B.js +0 -345
  52. package/dist/chunk-R52TZEIL.js +0 -426
  53. package/dist/chunk-S3RAZTEM.js +0 -807
  54. package/dist/chunk-V47P2AQR.js +0 -281
  55. package/dist/chunk-WXOWJXY6.js +0 -564
  56. package/dist/chunk-WXYDFCIW.js +0 -293
  57. package/dist/chunk-Y62GORQF.js +0 -51
  58. package/dist/chunk-ZP3VVXOI.js +0 -66
  59. package/dist/chunk-ZU3WVVLC.js +0 -3752
  60. package/dist/kyber-CGOA7Q6A.js +0 -3
  61. package/dist/verifier-55HW6AFN.js +0 -6
@@ -1,136 +0,0 @@
1
- import { ml_dsa65 } from '@noble/post-quantum/ml-dsa.js';
2
-
3
- // src/rpc/crypto/dilithium.ts
4
- var DILITHIUM65_CONSTANTS = {
5
- PUBLIC_KEY_BYTES: 1952,
6
- SECRET_KEY_BYTES: 4032,
7
- SIGNATURE_BYTES: 3309,
8
- DEFAULT_CONTEXT: new TextEncoder().encode("LIOP-FIPS204-ML-DSA-65")
9
- };
10
- function normalizeMessage(message) {
11
- if (typeof message === "string") {
12
- return new TextEncoder().encode(message);
13
- }
14
- return message;
15
- }
16
- function canonicalizeJson(obj) {
17
- if (obj === null || typeof obj !== "object") {
18
- return JSON.stringify(obj);
19
- }
20
- if (Array.isArray(obj)) {
21
- return `[${obj.map(canonicalizeJson).join(",")}]`;
22
- }
23
- const record = obj;
24
- const sortedKeys = Object.keys(record).filter((key) => record[key] !== void 0).sort();
25
- const entries = sortedKeys.map(
26
- (key) => `${JSON.stringify(key)}:${canonicalizeJson(record[key])}`
27
- );
28
- return `{${entries.join(",")}}`;
29
- }
30
- var Dilithium65Wrapper = {
31
- /** Constants */
32
- PUBLIC_KEY_BYTES: DILITHIUM65_CONSTANTS.PUBLIC_KEY_BYTES,
33
- SECRET_KEY_BYTES: DILITHIUM65_CONSTANTS.SECRET_KEY_BYTES,
34
- SIGNATURE_BYTES: DILITHIUM65_CONSTANTS.SIGNATURE_BYTES,
35
- /**
36
- * Generates a new ML-DSA-65 (FIPS 204) key pair.
37
- * Optionally accepts a 32-byte seed for deterministic key generation.
38
- */
39
- generateKeyPair(seed) {
40
- if (seed && seed.length !== 32) {
41
- throw new Error(
42
- `ML-DSA-65 seed must be exactly 32 bytes (Received: ${seed.length})`
43
- );
44
- }
45
- const keys = ml_dsa65.keygen(seed);
46
- return {
47
- publicKey: keys.publicKey,
48
- secretKey: keys.secretKey
49
- };
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
- },
62
- /**
63
- * Validates and imports a raw ML-DSA-65 public key.
64
- */
65
- importPublicKey(buffer) {
66
- if (buffer.length !== DILITHIUM65_CONSTANTS.PUBLIC_KEY_BYTES) {
67
- throw new Error(
68
- `ML-DSA-65 Public Key must be exactly ${DILITHIUM65_CONSTANTS.PUBLIC_KEY_BYTES} bytes (Received: ${buffer.length})`
69
- );
70
- }
71
- return buffer;
72
- },
73
- /**
74
- * Signs a message using the post-quantum secret key.
75
- * Supports optional domain separation context (up to 255 bytes).
76
- */
77
- sign(message, secretKey, context) {
78
- if (secretKey.length !== DILITHIUM65_CONSTANTS.SECRET_KEY_BYTES) {
79
- throw new Error(
80
- `ML-DSA-65 Secret Key must be exactly ${DILITHIUM65_CONSTANTS.SECRET_KEY_BYTES} bytes (Received: ${secretKey.length})`
81
- );
82
- }
83
- const msgBytes = normalizeMessage(message);
84
- const ctx = context ?? DILITHIUM65_CONSTANTS.DEFAULT_CONTEXT;
85
- return ml_dsa65.sign(msgBytes, secretKey, { context: ctx });
86
- },
87
- /**
88
- * Verifies an ML-DSA-65 post-quantum digital signature.
89
- */
90
- verify(signature, message, publicKey, context) {
91
- if (signature.length !== DILITHIUM65_CONSTANTS.SIGNATURE_BYTES) {
92
- return false;
93
- }
94
- if (publicKey.length !== DILITHIUM65_CONSTANTS.PUBLIC_KEY_BYTES) {
95
- return false;
96
- }
97
- try {
98
- const msgBytes = normalizeMessage(message);
99
- const ctx = context ?? DILITHIUM65_CONSTANTS.DEFAULT_CONTEXT;
100
- return ml_dsa65.verify(signature, msgBytes, publicKey, { context: ctx });
101
- } catch {
102
- return false;
103
- }
104
- },
105
- /**
106
- * Signs a structured manifest (LiopManifest) using canonical JSON serialization.
107
- * Returns base64-encoded signature and public key for transport over gRPC/MCP.
108
- */
109
- signManifest(manifest, secretKey, publicKey) {
110
- const { pqcSignature: _sig, pqcPublicKey: _pub, ...unsigned } = manifest;
111
- const canonicalStr = canonicalizeJson(unsigned);
112
- const sig = this.sign(canonicalStr, secretKey);
113
- return {
114
- signature: Buffer.from(sig).toString("base64"),
115
- publicKey: Buffer.from(publicKey).toString("base64")
116
- };
117
- },
118
- /**
119
- * Verifies the post-quantum signature of a structured manifest.
120
- */
121
- verifyManifest(manifest, signatureBase64, publicKeyBase64) {
122
- try {
123
- const sig = Buffer.from(signatureBase64, "base64");
124
- const pub = Buffer.from(publicKeyBase64, "base64");
125
- const { pqcSignature: _sig, pqcPublicKey: _pub, ...unsigned } = manifest;
126
- const canonicalStr = canonicalizeJson(unsigned);
127
- return this.verify(sig, canonicalStr, pub);
128
- } catch {
129
- return false;
130
- }
131
- }
132
- };
133
-
134
- export { DILITHIUM65_CONSTANTS, Dilithium65Wrapper };
135
- //# sourceMappingURL=chunk-3664H3CV.js.map
136
- //# sourceMappingURL=chunk-3664H3CV.js.map
@@ -1,115 +0,0 @@
1
- import { log } from './chunk-K3DGJLUY.js';
2
-
3
- // src/runtime/token-manager.ts
4
- var TokenManager = class _TokenManager {
5
- cachedToken = null;
6
- expiresAt = 0;
7
- // Epoch ms
8
- pendingPromise = null;
9
- tokenEndpoint;
10
- clientId;
11
- clientSecret;
12
- audience;
13
- scope;
14
- staticToken;
15
- // Preemptive refresh threshold: 30 seconds before expiration
16
- static REFRESH_BUFFER_MS = 3e4;
17
- constructor(options) {
18
- this.tokenEndpoint = options.tokenEndpoint;
19
- this.clientId = options.clientId;
20
- this.clientSecret = options.clientSecret;
21
- this.audience = options.audience ?? "urn:liop:mesh:api";
22
- this.scope = Array.isArray(options.scopes) ? options.scopes.join(" ") : options.scopes ?? "liop:tools:call liop:tools:list liop:resources:read liop:schema:read liop:mesh:query";
23
- this.staticToken = options.staticToken;
24
- }
25
- /**
26
- * Returns a valid OAuth 2.1 access token.
27
- * Automatically performs preemptive refresh if the token is close to expiry.
28
- */
29
- async getToken() {
30
- if (this.staticToken) {
31
- return this.staticToken;
32
- }
33
- const now = Date.now();
34
- if (this.cachedToken && now < this.expiresAt - _TokenManager.REFRESH_BUFFER_MS) {
35
- return this.cachedToken;
36
- }
37
- if (this.pendingPromise) {
38
- return this.pendingPromise;
39
- }
40
- this.pendingPromise = (async () => {
41
- try {
42
- const token = await this.fetchNewToken();
43
- this.cachedToken = token;
44
- return token;
45
- } finally {
46
- this.pendingPromise = null;
47
- }
48
- })();
49
- return this.pendingPromise;
50
- }
51
- /**
52
- * Force-invalidates cached token, e.g. after receiving a 401 Unauthorized response.
53
- */
54
- invalidate() {
55
- this.cachedToken = null;
56
- this.expiresAt = 0;
57
- if (this.clientId && this.clientSecret) {
58
- this.staticToken = void 0;
59
- }
60
- log.info("[TokenManager] Cached OAuth access token invalidated.");
61
- }
62
- /**
63
- * Returns true if the token is absent or has passed the refresh threshold.
64
- */
65
- isExpired() {
66
- if (this.staticToken) return false;
67
- return !this.cachedToken || Date.now() >= this.expiresAt - _TokenManager.REFRESH_BUFFER_MS;
68
- }
69
- getExpiresAt() {
70
- return this.expiresAt;
71
- }
72
- async fetchNewToken() {
73
- log.info(
74
- `[TokenManager] Requesting M2M token from ${this.tokenEndpoint} for client '${this.clientId}'...`
75
- );
76
- const params = new URLSearchParams({
77
- grant_type: "client_credentials",
78
- client_id: this.clientId,
79
- client_secret: this.clientSecret,
80
- resource: this.audience,
81
- scope: this.scope
82
- });
83
- const response = await fetch(this.tokenEndpoint, {
84
- method: "POST",
85
- headers: {
86
- "Content-Type": "application/x-www-form-urlencoded",
87
- Accept: "application/json"
88
- },
89
- body: params.toString(),
90
- signal: AbortSignal.timeout(1e4)
91
- });
92
- if (!response.ok) {
93
- const errorText = await response.text();
94
- throw new Error(
95
- `OAuth token request failed [HTTP ${response.status}]: ${errorText}`
96
- );
97
- }
98
- const data = await response.json();
99
- if (!data.access_token) {
100
- throw new Error(
101
- "OAuth token response did not contain an 'access_token' field."
102
- );
103
- }
104
- const expiresInSec = typeof data.expires_in === "number" ? data.expires_in : 3600;
105
- this.expiresAt = Date.now() + expiresInSec * 1e3;
106
- log.info(
107
- `[TokenManager] Acquired access token successfully. Expires in ${expiresInSec}s.`
108
- );
109
- return data.access_token;
110
- }
111
- };
112
-
113
- export { TokenManager };
114
- //# sourceMappingURL=chunk-3QH44NKZ.js.map
115
- //# sourceMappingURL=chunk-3QH44NKZ.js.map