@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.
- package/dist/bin/agent.js +27 -933
- package/dist/bridge.js +1 -5
- package/dist/chunk-2XHSALII.js +3 -0
- package/dist/chunk-2ZYX736J.js +2 -0
- package/dist/chunk-3WRKTVOF.js +2 -0
- package/dist/chunk-6KFKO6ZX.js +2 -0
- package/dist/chunk-6VK2XALI.js +2 -0
- package/dist/chunk-AYDF3IFZ.js +2 -0
- package/dist/chunk-CTTTLCGL.js +31 -0
- package/dist/chunk-ECRS6N33.js +4 -0
- package/dist/chunk-FDJMH4CB.js +2 -0
- package/dist/chunk-FTF6AMF6.js +0 -1
- package/dist/chunk-GWVSCZUS.js +2 -0
- package/dist/chunk-LEXMMIQI.js +15 -0
- package/dist/chunk-LM26HOJ6.js +31 -0
- package/dist/chunk-MQ5SU26J.js +2 -0
- package/dist/chunk-N35BC62H.js +2 -0
- package/dist/chunk-P6IJ3VBD.js +3 -0
- package/dist/chunk-TKLRW52V.js +2 -0
- package/dist/chunk-V35CXJQN.js +2 -0
- package/dist/chunk-WP5ER7RH.js +3 -0
- package/dist/chunk-XLVEDKM6.js +2 -0
- package/dist/chunk-Y675R34Z.js +2 -0
- package/dist/chunk-YD2AF2M6.js +46 -0
- package/dist/chunk-YLCNV764.js +3 -0
- package/dist/chunk-ZZMSFCJP.js +3 -0
- package/dist/client.js +1 -12
- package/dist/gateway.js +1 -13
- package/dist/index.js +4 -320
- package/dist/kyber-PULV7PQX.js +2 -0
- package/dist/mesh.js +1 -5
- package/dist/server.js +1 -10
- package/dist/types.js +1 -3
- package/dist/verifier-J4NQYZX5.js +2 -0
- package/dist/workers/logic-execution.js +1 -355
- package/dist/workers/zk-verifier.js +1 -275
- package/package.json +1 -1
- package/dist/chunk-3664H3CV.js +0 -136
- package/dist/chunk-3QH44NKZ.js +0 -115
- package/dist/chunk-6MYJBM2E.js +0 -818
- package/dist/chunk-7PITYWOV.js +0 -68
- package/dist/chunk-DSOB2JKM.js +0 -1507
- package/dist/chunk-ET6VRUK2.js +0 -58
- package/dist/chunk-FIVRGOA4.js +0 -280
- package/dist/chunk-IHKKWXHJ.js +0 -876
- package/dist/chunk-IK7CGWAZ.js +0 -24
- package/dist/chunk-JPWC6XG6.js +0 -941
- package/dist/chunk-K3DGJLUY.js +0 -106
- package/dist/chunk-KR5UZUEY.js +0 -98
- package/dist/chunk-NXCAFF73.js +0 -59
- package/dist/chunk-Q3FKHJ3B.js +0 -345
- package/dist/chunk-R52TZEIL.js +0 -426
- package/dist/chunk-S3RAZTEM.js +0 -807
- package/dist/chunk-V47P2AQR.js +0 -281
- package/dist/chunk-WXOWJXY6.js +0 -564
- package/dist/chunk-WXYDFCIW.js +0 -293
- package/dist/chunk-Y62GORQF.js +0 -51
- package/dist/chunk-ZP3VVXOI.js +0 -66
- package/dist/chunk-ZU3WVVLC.js +0 -3752
- package/dist/kyber-CGOA7Q6A.js +0 -3
- package/dist/verifier-55HW6AFN.js +0 -6
package/dist/chunk-ET6VRUK2.js
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { ZkVerificationError } from './chunk-FIVRGOA4.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-ET6VRUK2.js.map
|
|
58
|
-
//# sourceMappingURL=chunk-ET6VRUK2.js.map
|
package/dist/chunk-FIVRGOA4.js
DELETED
|
@@ -1,280 +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
|
-
ProofType2[ProofType2["GROTH16_PQC_HYBRID"] = 3] = "GROTH16_PQC_HYBRID";
|
|
8
|
-
return ProofType2;
|
|
9
|
-
})(ProofType || {});
|
|
10
|
-
var RECEIPT_VERSION_V1 = 1;
|
|
11
|
-
var RECEIPT_VERSION_V2 = 2;
|
|
12
|
-
var ZK_JOURNAL_V2_SIZE = 144;
|
|
13
|
-
var ZkVerificationError = class extends Error {
|
|
14
|
-
constructor(message) {
|
|
15
|
-
super(`ZK Verification Failed: ${message}`);
|
|
16
|
-
this.name = "ZkVerificationError";
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
function encodeJournalV2(fields) {
|
|
20
|
-
if (fields.guestImageId.length !== 32) {
|
|
21
|
-
throw new ZkVerificationError(
|
|
22
|
-
`Invalid guestImageId size: expected 32 bytes, got ${fields.guestImageId.length}`
|
|
23
|
-
);
|
|
24
|
-
}
|
|
25
|
-
if (fields.logicDigest.length !== 32) {
|
|
26
|
-
throw new ZkVerificationError(
|
|
27
|
-
`Invalid logicDigest size: expected 32 bytes, got ${fields.logicDigest.length}`
|
|
28
|
-
);
|
|
29
|
-
}
|
|
30
|
-
if (fields.datasetDigest.length !== 32) {
|
|
31
|
-
throw new ZkVerificationError(
|
|
32
|
-
`Invalid datasetDigest size: expected 32 bytes, got ${fields.datasetDigest.length}`
|
|
33
|
-
);
|
|
34
|
-
}
|
|
35
|
-
if (fields.outputDigest.length !== 32) {
|
|
36
|
-
throw new ZkVerificationError(
|
|
37
|
-
`Invalid outputDigest size: expected 32 bytes, got ${fields.outputDigest.length}`
|
|
38
|
-
);
|
|
39
|
-
}
|
|
40
|
-
const buf = Buffer.alloc(ZK_JOURNAL_V2_SIZE);
|
|
41
|
-
fields.guestImageId.copy(buf, 0);
|
|
42
|
-
fields.logicDigest.copy(buf, 32);
|
|
43
|
-
fields.datasetDigest.copy(buf, 64);
|
|
44
|
-
fields.outputDigest.copy(buf, 96);
|
|
45
|
-
buf.writeBigUInt64BE(BigInt(fields.fuelConsumed), 128);
|
|
46
|
-
buf.writeBigUInt64BE(BigInt(fields.executionTimestamp), 136);
|
|
47
|
-
return buf;
|
|
48
|
-
}
|
|
49
|
-
function decodeJournalV2(buf) {
|
|
50
|
-
if (buf.length !== ZK_JOURNAL_V2_SIZE) {
|
|
51
|
-
throw new ZkVerificationError(
|
|
52
|
-
`Invalid ZkJournalV2 size: expected ${ZK_JOURNAL_V2_SIZE} bytes, got ${buf.length}`
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
return {
|
|
56
|
-
guestImageId: Buffer.from(buf.subarray(0, 32)),
|
|
57
|
-
logicDigest: Buffer.from(buf.subarray(32, 64)),
|
|
58
|
-
datasetDigest: Buffer.from(buf.subarray(64, 96)),
|
|
59
|
-
outputDigest: Buffer.from(buf.subarray(96, 128)),
|
|
60
|
-
fuelConsumed: buf.readBigUInt64BE(128),
|
|
61
|
-
executionTimestamp: buf.readBigUInt64BE(136)
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
var receiptCodec = {
|
|
65
|
-
/**
|
|
66
|
-
* Encodes a version 2 Binary Receipt with trailing SHA-256 checksum.
|
|
67
|
-
* Layout: [0x02][proofType: 1B][journalLen: 4B UInt32BE][journal][proof][checksum: 32B]
|
|
68
|
-
*/
|
|
69
|
-
encodeV2(proofType, journal, proof) {
|
|
70
|
-
const header = Buffer.alloc(6);
|
|
71
|
-
header.writeUInt8(RECEIPT_VERSION_V2, 0);
|
|
72
|
-
header.writeUInt8(proofType, 1);
|
|
73
|
-
header.writeUInt32BE(journal.length, 2);
|
|
74
|
-
const payload = Buffer.concat([header, journal, proof]);
|
|
75
|
-
const checksum = crypto.createHash("sha256").update(payload).digest();
|
|
76
|
-
return Buffer.concat([payload, checksum]);
|
|
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
|
-
},
|
|
108
|
-
/**
|
|
109
|
-
* Decodes any LIOP Binary Receipt (v1 HMAC or v2 ZK).
|
|
110
|
-
*/
|
|
111
|
-
decode(raw) {
|
|
112
|
-
if (!raw || raw.length === 0) {
|
|
113
|
-
throw new ZkVerificationError(
|
|
114
|
-
"Empty or malformed zero-knowledge proof array."
|
|
115
|
-
);
|
|
116
|
-
}
|
|
117
|
-
const version = raw[0];
|
|
118
|
-
if (version === RECEIPT_VERSION_V1) {
|
|
119
|
-
if (raw.length < 35) {
|
|
120
|
-
throw new ZkVerificationError(
|
|
121
|
-
"Malformed receipt: invalid header or length."
|
|
122
|
-
);
|
|
123
|
-
}
|
|
124
|
-
const journalLen = raw.readUInt16BE(1);
|
|
125
|
-
if (raw.length < 3 + journalLen + 32) {
|
|
126
|
-
throw new ZkVerificationError(
|
|
127
|
-
"Malformed receipt: truncated journal or seal."
|
|
128
|
-
);
|
|
129
|
-
}
|
|
130
|
-
const journal = Buffer.from(raw.subarray(3, 3 + journalLen));
|
|
131
|
-
const seal = Buffer.from(
|
|
132
|
-
raw.subarray(3 + journalLen, 3 + journalLen + 32)
|
|
133
|
-
);
|
|
134
|
-
return {
|
|
135
|
-
version: RECEIPT_VERSION_V1,
|
|
136
|
-
proofType: 0 /* HMAC_LEGACY */,
|
|
137
|
-
journal,
|
|
138
|
-
proof: seal,
|
|
139
|
-
raw
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
if (version === RECEIPT_VERSION_V2) {
|
|
143
|
-
if (raw.length < 38) {
|
|
144
|
-
throw new ZkVerificationError(
|
|
145
|
-
"Malformed receipt v2: buffer too short (< 38 bytes)."
|
|
146
|
-
);
|
|
147
|
-
}
|
|
148
|
-
const proofType = raw[1];
|
|
149
|
-
const journalLen = raw.readUInt32BE(2);
|
|
150
|
-
if (raw.length < 6 + journalLen + 32) {
|
|
151
|
-
throw new ZkVerificationError(
|
|
152
|
-
"Malformed receipt v2: truncated payload."
|
|
153
|
-
);
|
|
154
|
-
}
|
|
155
|
-
const payload = raw.subarray(0, raw.length - 32);
|
|
156
|
-
const expectedChecksum = raw.subarray(raw.length - 32);
|
|
157
|
-
const actualChecksum = crypto.createHash("sha256").update(payload).digest();
|
|
158
|
-
if (!crypto.timingSafeEqual(expectedChecksum, actualChecksum)) {
|
|
159
|
-
throw new ZkVerificationError("Receipt checksum verification failed.");
|
|
160
|
-
}
|
|
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
|
-
}
|
|
198
|
-
const proof = Buffer.from(raw.subarray(6 + journalLen, raw.length - 32));
|
|
199
|
-
return {
|
|
200
|
-
version: RECEIPT_VERSION_V2,
|
|
201
|
-
proofType,
|
|
202
|
-
journal,
|
|
203
|
-
proof,
|
|
204
|
-
raw
|
|
205
|
-
};
|
|
206
|
-
}
|
|
207
|
-
throw new ZkVerificationError(
|
|
208
|
-
`Unsupported receipt version: 0x${version.toString(16)}`
|
|
209
|
-
);
|
|
210
|
-
}
|
|
211
|
-
};
|
|
212
|
-
var ZkVerifier = {
|
|
213
|
-
/**
|
|
214
|
-
* Validates a ZK receipt using structural Binary Receipt verification.
|
|
215
|
-
* Parses the HMAC-SHA256 commitment format (v1) and verifies journal integrity.
|
|
216
|
-
*
|
|
217
|
-
* @param receipt - Complete ZkReceipt to verify
|
|
218
|
-
* @param expectedImageId - Hash or ImageID of the WASM file dispatched to the host
|
|
219
|
-
* @throws ZkVerificationError if the proof is invalid or image IDs mismatch
|
|
220
|
-
* @returns true if the proof mathematically verifies the execution
|
|
221
|
-
*/
|
|
222
|
-
verify(receipt, expectedImageId, sessionSecret) {
|
|
223
|
-
if (!receipt.imageId.equals(expectedImageId)) {
|
|
224
|
-
throw new ZkVerificationError(
|
|
225
|
-
"ImageID mismatch. The remote origin executed a different WASM payload."
|
|
226
|
-
);
|
|
227
|
-
}
|
|
228
|
-
if (receipt.proof.length === 0) {
|
|
229
|
-
throw new ZkVerificationError(
|
|
230
|
-
"Empty or malformed zero-knowledge proof array."
|
|
231
|
-
);
|
|
232
|
-
}
|
|
233
|
-
const proofBuf = Buffer.from(receipt.proof);
|
|
234
|
-
if (proofBuf.length < 35 || proofBuf[0] !== 1) {
|
|
235
|
-
throw new ZkVerificationError(
|
|
236
|
-
"Malformed receipt: invalid header or length."
|
|
237
|
-
);
|
|
238
|
-
}
|
|
239
|
-
const journalLen = proofBuf.readUInt16BE(1);
|
|
240
|
-
const journal = proofBuf.subarray(3, 3 + journalLen);
|
|
241
|
-
const seal = proofBuf.subarray(3 + journalLen);
|
|
242
|
-
if (seal.length !== 32) {
|
|
243
|
-
throw new ZkVerificationError(
|
|
244
|
-
"Invalid seal: expected 32-byte HMAC-SHA256."
|
|
245
|
-
);
|
|
246
|
-
}
|
|
247
|
-
try {
|
|
248
|
-
const journalData = JSON.parse(journal.toString());
|
|
249
|
-
if (journalData.image_id !== receipt.imageId.toString("hex")) {
|
|
250
|
-
throw new ZkVerificationError(
|
|
251
|
-
"Journal imageId does not match receipt header."
|
|
252
|
-
);
|
|
253
|
-
}
|
|
254
|
-
} catch (_e) {
|
|
255
|
-
throw new ZkVerificationError("Failed to parse journal data.");
|
|
256
|
-
}
|
|
257
|
-
if (sessionSecret && sessionSecret.length > 0) {
|
|
258
|
-
const expectedSeal = crypto.createHmac("sha256", sessionSecret).update(journal).digest();
|
|
259
|
-
if (!crypto.timingSafeEqual(seal, expectedSeal)) {
|
|
260
|
-
throw new ZkVerificationError(
|
|
261
|
-
"Invalid seal: HMAC verification failed."
|
|
262
|
-
);
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
return true;
|
|
266
|
-
},
|
|
267
|
-
/**
|
|
268
|
-
* Derives a predictable ImageID (usually a Hash) from a raw WASM binary.
|
|
269
|
-
*
|
|
270
|
-
* @param wasmBytes - The raw bytes of the WASM logic file
|
|
271
|
-
* @returns The SHA-256 ImageID of the logic
|
|
272
|
-
*/
|
|
273
|
-
deriveImageId(wasmBytes) {
|
|
274
|
-
return crypto.createHash("sha256").update(wasmBytes).digest();
|
|
275
|
-
}
|
|
276
|
-
};
|
|
277
|
-
|
|
278
|
-
export { ProofType, RECEIPT_VERSION_V1, RECEIPT_VERSION_V2, ZK_JOURNAL_V2_SIZE, ZkVerificationError, ZkVerifier, decodeJournalV2, encodeJournalV2, receiptCodec };
|
|
279
|
-
//# sourceMappingURL=chunk-FIVRGOA4.js.map
|
|
280
|
-
//# sourceMappingURL=chunk-FIVRGOA4.js.map
|