@lionden/leo-compiler 0.1.0

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 (67) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +23 -0
  3. package/dist/abi-hash.d.ts +15 -0
  4. package/dist/abi-hash.d.ts.map +1 -0
  5. package/dist/abi-hash.js +75 -0
  6. package/dist/abi-hash.js.map +1 -0
  7. package/dist/abi-parser.d.ts +38 -0
  8. package/dist/abi-parser.d.ts.map +1 -0
  9. package/dist/abi-parser.js +513 -0
  10. package/dist/abi-parser.js.map +1 -0
  11. package/dist/abi-types.d.ts +111 -0
  12. package/dist/abi-types.d.ts.map +1 -0
  13. package/dist/abi-types.js +5 -0
  14. package/dist/abi-types.js.map +1 -0
  15. package/dist/cache.d.ts +27 -0
  16. package/dist/cache.d.ts.map +1 -0
  17. package/dist/cache.js +74 -0
  18. package/dist/cache.js.map +1 -0
  19. package/dist/codegen/codegen-error.d.ts +10 -0
  20. package/dist/codegen/codegen-error.d.ts.map +1 -0
  21. package/dist/codegen/codegen-error.js +14 -0
  22. package/dist/codegen/codegen-error.js.map +1 -0
  23. package/dist/codegen/contract-wrapper.d.ts +6 -0
  24. package/dist/codegen/contract-wrapper.d.ts.map +1 -0
  25. package/dist/codegen/contract-wrapper.js +2482 -0
  26. package/dist/codegen/contract-wrapper.js.map +1 -0
  27. package/dist/codegen/type-mapper.d.ts +46 -0
  28. package/dist/codegen/type-mapper.d.ts.map +1 -0
  29. package/dist/codegen/type-mapper.js +132 -0
  30. package/dist/codegen/type-mapper.js.map +1 -0
  31. package/dist/codegen/typescript-generator.d.ts +65 -0
  32. package/dist/codegen/typescript-generator.d.ts.map +1 -0
  33. package/dist/codegen/typescript-generator.js +2076 -0
  34. package/dist/codegen/typescript-generator.js.map +1 -0
  35. package/dist/compiler.d.ts +43 -0
  36. package/dist/compiler.d.ts.map +1 -0
  37. package/dist/compiler.js +532 -0
  38. package/dist/compiler.js.map +1 -0
  39. package/dist/dependency-resolver.d.ts +33 -0
  40. package/dist/dependency-resolver.d.ts.map +1 -0
  41. package/dist/dependency-resolver.js +142 -0
  42. package/dist/dependency-resolver.js.map +1 -0
  43. package/dist/import-parser.d.ts +17 -0
  44. package/dist/import-parser.d.ts.map +1 -0
  45. package/dist/import-parser.js +46 -0
  46. package/dist/import-parser.js.map +1 -0
  47. package/dist/index.d.ts +15 -0
  48. package/dist/index.d.ts.map +1 -0
  49. package/dist/index.js +22 -0
  50. package/dist/index.js.map +1 -0
  51. package/dist/package-materializer.d.ts +29 -0
  52. package/dist/package-materializer.d.ts.map +1 -0
  53. package/dist/package-materializer.js +160 -0
  54. package/dist/package-materializer.js.map +1 -0
  55. package/dist/source-discovery.d.ts +24 -0
  56. package/dist/source-discovery.d.ts.map +1 -0
  57. package/dist/source-discovery.js +131 -0
  58. package/dist/source-discovery.js.map +1 -0
  59. package/dist/source-scrubber.d.ts +22 -0
  60. package/dist/source-scrubber.d.ts.map +1 -0
  61. package/dist/source-scrubber.js +71 -0
  62. package/dist/source-scrubber.js.map +1 -0
  63. package/dist/types.d.ts +72 -0
  64. package/dist/types.d.ts.map +1 -0
  65. package/dist/types.js +8 -0
  66. package/dist/types.js.map +1 -0
  67. package/package.json +34 -0
@@ -0,0 +1,532 @@
1
+ import { execFile } from "node:child_process";
2
+ import * as crypto from "node:crypto";
3
+ import * as fs from "node:fs";
4
+ import * as path from "node:path";
5
+ import { promisify } from "node:util";
6
+ import { normalizeProgramId } from "@lionden/config";
7
+ import { fingerprintFile, KEY_ARTIFACTS_FORMAT, keyArtifactsMetadataPath, sha256Json, sha256Text, writeKeyArtifactsMetadata, } from "@lionden/core";
8
+ import { parseAbi } from "./abi-parser.js";
9
+ import { computeUnitHash, isCached, writeCache } from "./cache.js";
10
+ import { resolveDependencies } from "./dependency-resolver.js";
11
+ import { effectiveUnitId, getCachedNetworkDep, linkNetworkDependency, materializePackage, } from "./package-materializer.js";
12
+ import { discoverUnits } from "./source-discovery.js";
13
+ import { unitId } from "./types.js";
14
+ const execFileAsync = promisify(execFile);
15
+ /**
16
+ * Default network dependency fetcher.
17
+ * Fetches program source from a node's REST API: GET /{network}/program/{id}
18
+ */
19
+ export async function defaultFetchNetworkDep(programId, endpoint, networkHint) {
20
+ // When the caller provides a network hint (derived from config), only try
21
+ // that network. Cross-network fallback would silently return source from
22
+ // the wrong network and cache it under the hinted scope, poisoning future
23
+ // compiles. Only fall back across networks when no hint is given (rare —
24
+ // means no config network was resolved).
25
+ const networks = networkHint
26
+ ? [networkHint]
27
+ : ["testnet", "mainnet", "canary"];
28
+ const errors = [];
29
+ for (const network of networks) {
30
+ const url = `${endpoint}/${network}/program/${programId}`;
31
+ try {
32
+ const response = await fetch(url);
33
+ if (response.ok) {
34
+ return await response.text();
35
+ }
36
+ errors.push({ network, reason: `HTTP ${response.status}` });
37
+ }
38
+ catch (err) {
39
+ errors.push({
40
+ network,
41
+ reason: err instanceof Error ? err.message : String(err),
42
+ });
43
+ }
44
+ }
45
+ const details = errors.map((e) => ` ${e.network}: ${e.reason}`).join("\n");
46
+ throw new Error(`Failed to fetch network dependency "${programId}" from ${endpoint}:\n${details}\n` +
47
+ `Ensure the endpoint is reachable and the program is deployed.`);
48
+ }
49
+ export class CompilationError extends Error {
50
+ unitId;
51
+ stderr;
52
+ constructor(unitId, message, stderr) {
53
+ super(`Compilation failed for "${unitId}": ${message}`);
54
+ this.unitId = unitId;
55
+ this.stderr = stderr;
56
+ this.name = "CompilationError";
57
+ }
58
+ }
59
+ /**
60
+ * Derive the network-dependency cache scope for a given network, plus the
61
+ * endpoint + hint used to fetch from it.
62
+ *
63
+ * `compilePipeline` scopes the network-dep cache by effective network+endpoint
64
+ * (`${networkHint}-${sha256(endpoint).slice(0,8)}`) so switching networks does
65
+ * not serve stale source. This is the single source of truth for that
66
+ * derivation — callers that need to pre-seed or locate the cache (e.g. tests)
67
+ * must use this rather than re-deriving the scope, so the two can never drift.
68
+ */
69
+ export function networkDepCacheScope(config, networkName) {
70
+ const networkConfig = config.networks[networkName];
71
+ const endpoint = networkConfig?.type === "http"
72
+ ? networkConfig.endpoint
73
+ : networkConfig?.type === "devnode"
74
+ ? `http://${networkConfig.socketAddr}`
75
+ : "http://127.0.0.1:3030";
76
+ const networkHint = networkConfig?.network;
77
+ // Network+endpoint scope for cache isolation — devnode testnet and HTTP
78
+ // testnet share the same network name but different sources.
79
+ const endpointHash = crypto.createHash("sha256").update(endpoint).digest("hex").slice(0, 8);
80
+ const scope = `${networkHint ?? "default"}-${endpointHash}`;
81
+ return { endpoint, networkHint, scope };
82
+ }
83
+ /**
84
+ * Run the full compilation pipeline:
85
+ * 1. Discover units
86
+ * 2. Resolve dependencies (topological order)
87
+ * 3. Materialize packages
88
+ * 4. Compile in order (with caching)
89
+ * 5. Return results with ABIs for programs
90
+ */
91
+ export async function compilePipeline(config, options = {}, fetchNetworkDep = defaultFetchNetworkDep) {
92
+ if (options.rename !== undefined && !options.program) {
93
+ throw new Error("Compile option `rename` requires `program` so the source program is explicit.");
94
+ }
95
+ // Resolve the effective network for network-dep fetch + `.env`. A programmatic
96
+ // `{ network }` (forwarded from deploy/recipe/upgrade) retargets these from
97
+ // `config.defaultNetwork` so imported on-chain sources are fetched from the
98
+ // deploying network. Validate whenever an override is *present* (not just
99
+ // truthy) before deriving the endpoint/hint — an explicit `""` is still an
100
+ // unknown network and must throw here rather than slipping through to the
101
+ // `""`-keyed `config.networks` miss and the `127.0.0.1:3030` fallback below.
102
+ if (options.network !== undefined && !config.networks[options.network]) {
103
+ throw new Error(`Network "${options.network}" is not defined in config.networks. ` +
104
+ `Available networks: ${Object.keys(config.networks).join(", ") || "(none)"}`);
105
+ }
106
+ const effectiveNetwork = options.network ?? config.defaultNetwork;
107
+ // 1. Discover
108
+ const allUnits = discoverUnits(config.paths.programs);
109
+ // 2. Resolve dependencies
110
+ const graph = resolveDependencies(allUnits);
111
+ // Filter to specific program if requested
112
+ let compileOrder = graph.order;
113
+ let renamePlan;
114
+ if (options.program) {
115
+ const target = compileOrder.find((u) => unitId(u) === options.program || unitId(u) === `${options.program}.aleo`);
116
+ if (!target) {
117
+ throw new CompilationError(options.program, `Program "${options.program}" not found in ${config.paths.programs}`);
118
+ }
119
+ if (options.rename !== undefined) {
120
+ renamePlan = {
121
+ sourceProgramId: unitId(target),
122
+ targetProgramId: normalizeProgramId(options.rename),
123
+ };
124
+ }
125
+ // Include the target and all its transitive dependencies
126
+ compileOrder = collectTransitiveDeps(target, graph, allUnits);
127
+ }
128
+ // 3. Materialize all packages (needed for dependency linking)
129
+ const packageDirs = new Map();
130
+ for (const unit of compileOrder) {
131
+ const dir = materializePackage(unit, config, graph, effectiveNetwork, renamePlan);
132
+ packageDirs.set(unitId(unit), dir);
133
+ }
134
+ // 4. Fetch and link network dependencies
135
+ // Derive the set of network deps actually needed by compileOrder
136
+ // (avoids fetching unrelated deps when --program filters the set).
137
+ const cacheDir = path.join(config.paths.artifacts, ".cache");
138
+ const selectedNetworkDeps = new Set();
139
+ for (const unit of compileOrder) {
140
+ for (const dep of graph.imports.get(unitId(unit)) ?? []) {
141
+ if (graph.networkDeps.has(dep))
142
+ selectedNetworkDeps.add(dep);
143
+ }
144
+ }
145
+ if (selectedNetworkDeps.size > 0) {
146
+ const { endpoint, networkHint, scope: networkScope, } = networkDepCacheScope(config, effectiveNetwork);
147
+ for (const dep of selectedNetworkDeps) {
148
+ // Fetch once per dep; skip cache when --force is set
149
+ let aleoSource = options.force ? null : getCachedNetworkDep(cacheDir, dep, networkScope);
150
+ if (!aleoSource) {
151
+ aleoSource = await fetchNetworkDep(dep, endpoint, networkHint);
152
+ }
153
+ // Link to every unit that imports this dep
154
+ for (const unit of compileOrder) {
155
+ const imports = graph.imports.get(unitId(unit)) ?? [];
156
+ if (!imports.includes(dep))
157
+ continue;
158
+ const pkgDir = packageDirs.get(unitId(unit));
159
+ linkNetworkDependency(pkgDir, dep, aleoSource, cacheDir, networkScope);
160
+ }
161
+ }
162
+ }
163
+ // 5. Compile in topological order
164
+ const results = [];
165
+ const depHashes = new Map();
166
+ for (const unit of compileOrder) {
167
+ const id = unitId(unit);
168
+ const effectiveId = effectiveUnitId(unit, renamePlan);
169
+ const cacheId = effectiveId === id ? id : `${id}__as__${effectiveId}`;
170
+ const pkgDir = packageDirs.get(id);
171
+ const buildDir = path.join(pkgDir, "build");
172
+ // Partition imports into local vs network deps for cache hashing.
173
+ // Local deps need no staging: `leo build` resolves them from the `path`
174
+ // entry in the dependent's program.json (written by materializePackage)
175
+ // and re-emits each dependency's bytecode under the dependent's own
176
+ // build/ dir. Network deps are staged into imports/ by linkNetworkDependency.
177
+ const imports = graph.imports.get(id) ?? [];
178
+ const localDepIds = [];
179
+ const networkDepIds = [];
180
+ for (const dep of imports) {
181
+ if (graph.networkDeps.has(dep)) {
182
+ networkDepIds.push(dep);
183
+ }
184
+ else {
185
+ localDepIds.push(dep);
186
+ }
187
+ }
188
+ // Compute hash and check cache
189
+ const hash = computeUnitHash(unit, pkgDir, localDepIds, depHashes, networkDepIds);
190
+ depHashes.set(id, hash);
191
+ const hashMatches = !options.force && isCached(cacheDir, cacheId, hash);
192
+ // A program hash hit only counts if the build output it still needs (ABI +
193
+ // compiled .aleo) survived in the preserved build/ dir; otherwise the later
194
+ // ABI read / artifact copy would fail. Libraries are inline `fn` helpers
195
+ // that emit no build artifacts, so there is nothing to revalidate.
196
+ const cached = hashMatches &&
197
+ (unit.kind !== "program" || hasRequiredProgramArtifacts(buildDir, effectiveId));
198
+ if (!cached) {
199
+ await runLeoBuild(pkgDir, effectiveId, config);
200
+ }
201
+ if (unit.kind === "program") {
202
+ const abi = readProgramAbi(buildDir, effectiveId);
203
+ // Copy final artifacts to artifactsDir/<programId>/
204
+ const artifactDir = path.join(config.paths.artifacts, effectiveId);
205
+ const normalized = copyArtifacts(buildDir, artifactDir, effectiveId, {
206
+ requireAbi: true,
207
+ requireAleo: true,
208
+ });
209
+ writeKeyArtifactsMetadata(keyArtifactsMetadataPath(config.paths.artifacts, effectiveId), buildKeyArtifactsMetadata(pkgDir, artifactDir, effectiveId, unit.programId, abi));
210
+ results.push({
211
+ unit,
212
+ sourceProgramId: unit.programId,
213
+ programId: effectiveId,
214
+ cached,
215
+ packageDir: pkgDir,
216
+ buildDir,
217
+ abi,
218
+ aleoSource: normalized.aleoPath,
219
+ });
220
+ }
221
+ else {
222
+ // Libraries are inline `fn` helpers: `leo build` emits no .aleo for them,
223
+ // and dependents inline the source from the library's package `path` in
224
+ // program.json — never from a staged .aleo. So there is nothing to
225
+ // normalize or stage for a library.
226
+ results.push({
227
+ unit,
228
+ cached,
229
+ packageDir: pkgDir,
230
+ buildDir,
231
+ });
232
+ }
233
+ if (!cached) {
234
+ writeCache(cacheDir, cacheId, hash);
235
+ }
236
+ }
237
+ return { results, graph };
238
+ }
239
+ /**
240
+ * Leo 4.2 removed the `--enable-dce` and `--conditional-block-max-depth` build
241
+ * flags (dead-code elimination is now unconditional, and the conditional-depth
242
+ * knob is gone). Passing either to a 4.2 `leo build` is a hard "unexpected
243
+ * argument" failure, so they are emitted only for the older 4.1/4.0/3.5 lines
244
+ * that still accept them. An unparseable/unknown version is treated as modern
245
+ * (4.2+) — the product default — since emitting a removed flag breaks the build
246
+ * outright, whereas omitting it on an older line only changes DCE behavior.
247
+ */
248
+ function emitsLegacyBuildFlags(leoVersion) {
249
+ const match = /^(\d+)\.(\d+)\./.exec(leoVersion);
250
+ if (!match)
251
+ return false;
252
+ const major = Number(match[1]);
253
+ const minor = Number(match[2]);
254
+ return major < 4 || (major === 4 && minor < 2);
255
+ }
256
+ async function runLeoBuild(packageDir, id, config) {
257
+ const args = ["--disable-update-check", "build", "--path", packageDir];
258
+ const legacyFlags = emitsLegacyBuildFlags(config.leoVersion);
259
+ if (legacyFlags && config.compiler.enableDce) {
260
+ args.push("--enable-dce");
261
+ }
262
+ if (legacyFlags && config.compiler.conditionalBlockMaxDepth !== 10) {
263
+ args.push("--conditional-block-max-depth", String(config.compiler.conditionalBlockMaxDepth));
264
+ }
265
+ if (config.compiler.buildTests) {
266
+ args.push("--build-tests");
267
+ }
268
+ for (const flag of config.compiler.extraFlags) {
269
+ args.push(flag);
270
+ }
271
+ try {
272
+ await execFileAsync(config.leoBinary, args, {
273
+ timeout: 120_000,
274
+ env: { ...process.env },
275
+ });
276
+ }
277
+ catch (err) {
278
+ const e = err;
279
+ throw new CompilationError(id, e.message ?? "Unknown error", e.stderr);
280
+ }
281
+ }
282
+ function readProgramAbi(buildDir, id) {
283
+ const artifacts = resolveBuildArtifacts(buildDir, id);
284
+ if (!artifacts.abiPath) {
285
+ throw new CompilationError(id, `ABI file not found under ${buildDir}. Did leo build succeed?`);
286
+ }
287
+ const abi = parseAbi(fs.readFileSync(artifacts.abiPath, "utf-8"));
288
+ if (abi.program !== id) {
289
+ throw new CompilationError(id, `Resolved ABI belongs to program "${abi.program}", expected "${id}".`);
290
+ }
291
+ return abi;
292
+ }
293
+ function hasRequiredProgramArtifacts(buildDir, id) {
294
+ const artifacts = resolveBuildArtifacts(buildDir, id);
295
+ return Boolean(artifacts.abiPath && artifacts.aleoPath);
296
+ }
297
+ function copyArtifacts(buildDir, destDir, id, options) {
298
+ const artifacts = resolveBuildArtifacts(buildDir, id);
299
+ if (options.requireAbi && !artifacts.abiPath) {
300
+ throw new CompilationError(id, `ABI file not found under ${buildDir}. Did leo build succeed?`);
301
+ }
302
+ if (options.requireAleo && !artifacts.aleoPath) {
303
+ throw new CompilationError(id, `Compiled Aleo source not found under ${buildDir}. Did leo build succeed?`);
304
+ }
305
+ // `artifacts/<programId>` is compiler-owned output. Recreate it from
306
+ // scratch so stale legacy/per-unit artifacts cannot survive normalization.
307
+ fs.rmSync(destDir, { recursive: true, force: true });
308
+ fs.mkdirSync(destDir, { recursive: true });
309
+ const normalized = {};
310
+ if (artifacts.abiPath) {
311
+ normalized.abiPath = path.join(destDir, "abi.json");
312
+ fs.copyFileSync(artifacts.abiPath, normalized.abiPath);
313
+ }
314
+ if (artifacts.aleoPath) {
315
+ normalized.aleoPath = path.join(destDir, "main.aleo");
316
+ fs.copyFileSync(artifacts.aleoPath, normalized.aleoPath);
317
+ }
318
+ for (const file of artifacts.keyFiles) {
319
+ fs.copyFileSync(file, path.join(destDir, path.basename(file)));
320
+ }
321
+ for (const interfacesDir of artifacts.interfacesDirs) {
322
+ copyDirectory(interfacesDir, path.join(destDir, "interfaces"));
323
+ }
324
+ return normalized;
325
+ }
326
+ function resolveBuildArtifacts(buildDir, id) {
327
+ if (!fs.existsSync(buildDir)) {
328
+ return { keyFiles: [], interfacesDirs: [] };
329
+ }
330
+ const unitDir = findBuildUnitDir(buildDir, id);
331
+ const abiPath = existingFile(path.join(unitDir, "abi.json"));
332
+ const aleoPath = findAleoOutput(unitDir, id);
333
+ const keyFiles = fs.existsSync(unitDir)
334
+ ? fs
335
+ .readdirSync(unitDir)
336
+ .filter((file) => file.endsWith(".prover") || file.endsWith(".verifier"))
337
+ .map((file) => path.join(unitDir, file))
338
+ .sort((a, b) => a.localeCompare(b))
339
+ : [];
340
+ const interfacesDirs = [
341
+ path.join(unitDir, "interfaces"),
342
+ path.join(buildDir, "interfaces"),
343
+ ].filter((dir, index, dirs) => fs.existsSync(dir) && fs.statSync(dir).isDirectory() && dirs.indexOf(dir) === index);
344
+ return { abiPath, aleoPath, keyFiles, interfacesDirs };
345
+ }
346
+ function findBuildUnitDir(buildDir, id) {
347
+ const preferred = preferredBuildUnitDirs(buildDir, id);
348
+ return newestBuildArtifactMatch(preferred, id) ?? buildDir;
349
+ }
350
+ function preferredBuildUnitDirs(buildDir, id) {
351
+ const base = id.endsWith(".aleo") ? id.slice(0, -".aleo".length) : id;
352
+ return uniqueExistingDirs([buildDir, path.join(buildDir, id), path.join(buildDir, base)]);
353
+ }
354
+ function newestBuildArtifactMatch(dirs, id) {
355
+ const matches = dirs
356
+ .map((dir, index) => {
357
+ const abiPath = existingFile(path.join(dir, "abi.json"));
358
+ const aleoPath = findAleoOutput(dir, id);
359
+ const artifactPath = abiPath ?? aleoPath;
360
+ return artifactPath ? { dir, index, mtimeMs: fs.statSync(artifactPath).mtimeMs } : null;
361
+ })
362
+ .filter((match) => match !== null)
363
+ .sort((a, b) => b.mtimeMs - a.mtimeMs || a.index - b.index);
364
+ return matches[0]?.dir;
365
+ }
366
+ function uniqueExistingDirs(dirs) {
367
+ return [...new Set(dirs)].filter((dir) => fs.existsSync(dir) && fs.statSync(dir).isDirectory());
368
+ }
369
+ function findAleoOutput(dir, id) {
370
+ const base = id.endsWith(".aleo") ? id.slice(0, -".aleo".length) : id;
371
+ const candidateNames = ["main.aleo", id.endsWith(".aleo") ? id : `${id}.aleo`, `${base}.aleo`];
372
+ for (const name of [...new Set(candidateNames)]) {
373
+ const file = existingFile(path.join(dir, name));
374
+ if (file)
375
+ return file;
376
+ }
377
+ if (!fs.existsSync(dir))
378
+ return undefined;
379
+ const aleoFiles = fs
380
+ .readdirSync(dir)
381
+ .filter((file) => file.endsWith(".aleo") && fs.statSync(path.join(dir, file)).isFile())
382
+ .sort((a, b) => a.localeCompare(b));
383
+ return aleoFiles.length > 0 ? path.join(dir, aleoFiles[0]) : undefined;
384
+ }
385
+ function existingFile(filePath) {
386
+ return fs.existsSync(filePath) && fs.statSync(filePath).isFile() ? filePath : undefined;
387
+ }
388
+ function copyDirectory(srcDir, destDir) {
389
+ for (const entry of fs.readdirSync(srcDir, { withFileTypes: true })) {
390
+ const src = path.join(srcDir, entry.name);
391
+ const dest = path.join(destDir, entry.name);
392
+ if (entry.isDirectory()) {
393
+ copyDirectory(src, dest);
394
+ }
395
+ else if (entry.isFile()) {
396
+ fs.mkdirSync(path.dirname(dest), { recursive: true });
397
+ fs.copyFileSync(src, dest);
398
+ }
399
+ }
400
+ }
401
+ function buildKeyArtifactsMetadata(packageDir, artifactDir, programId, sourceProgramId, abi) {
402
+ const sourcePath = path.join(artifactDir, "main.aleo");
403
+ const sourceHash = fs.existsSync(sourcePath)
404
+ ? sha256Text(fs.readFileSync(sourcePath, "utf-8"))
405
+ : sha256Text("");
406
+ const functions = collectKeyArtifactFunctionRefs(artifactDir, programId, abi);
407
+ return {
408
+ format: KEY_ARTIFACTS_FORMAT,
409
+ programId,
410
+ sourceProgramId,
411
+ sourceHash,
412
+ importsHash: hashPackageImports(path.join(packageDir, "imports")),
413
+ ...(functions.length === 0 ? {} : { functions }),
414
+ };
415
+ }
416
+ /**
417
+ * Hash the materialized package `imports/` directory for the key-artifacts
418
+ * sidecar. Local program deps are not staged here; Leo resolves them through
419
+ * the `path` entries in program.json. See docs/research/key-caching.md for the
420
+ * distinction between this compile-time hash and the runtime key-cache hash.
421
+ */
422
+ function hashPackageImports(importsDir) {
423
+ if (!fs.existsSync(importsDir)) {
424
+ return sha256Json({ imports: [] });
425
+ }
426
+ const imports = listFilesRecursive(importsDir).map((filePath) => {
427
+ const relativePath = toPortablePath(path.relative(importsDir, filePath));
428
+ return {
429
+ path: relativePath,
430
+ sourceHash: sha256Text(fs.readFileSync(filePath, "utf-8")),
431
+ };
432
+ });
433
+ return sha256Json({ imports });
434
+ }
435
+ function listFilesRecursive(root) {
436
+ const out = [];
437
+ for (const entry of fs.readdirSync(root, { withFileTypes: true })) {
438
+ const entryPath = path.join(root, entry.name);
439
+ if (entry.isDirectory()) {
440
+ out.push(...listFilesRecursive(entryPath));
441
+ }
442
+ else if (entry.isFile()) {
443
+ out.push(entryPath);
444
+ }
445
+ }
446
+ return out.sort((a, b) => a.localeCompare(b));
447
+ }
448
+ function collectKeyArtifactFunctionRefs(artifactDir, programId, abi) {
449
+ if (!fs.existsSync(artifactDir))
450
+ return [];
451
+ const proverByStem = new Map();
452
+ const verifierByStem = new Map();
453
+ for (const file of fs.readdirSync(artifactDir)) {
454
+ const filePath = path.join(artifactDir, file);
455
+ if (!fs.statSync(filePath).isFile())
456
+ continue;
457
+ if (file.endsWith(".prover")) {
458
+ proverByStem.set(file.slice(0, -".prover".length), file);
459
+ }
460
+ else if (file.endsWith(".verifier")) {
461
+ verifierByStem.set(file.slice(0, -".verifier".length), file);
462
+ }
463
+ }
464
+ const pairedStems = [...proverByStem.keys()]
465
+ .filter((stem) => verifierByStem.has(stem))
466
+ .sort((a, b) => a.localeCompare(b));
467
+ if (pairedStems.length === 0)
468
+ return [];
469
+ return abi.transitions.flatMap((transition) => {
470
+ const stem = findUnambiguousKeyStem(pairedStems, programId, transition.name, abi.transitions.length);
471
+ if (!stem)
472
+ return [];
473
+ const prover = proverByStem.get(stem);
474
+ const verifier = verifierByStem.get(stem);
475
+ if (!prover || !verifier)
476
+ return [];
477
+ return [
478
+ {
479
+ transition: transition.name,
480
+ prover: keyFileRef(artifactDir, prover),
481
+ verifier: keyFileRef(artifactDir, verifier),
482
+ },
483
+ ];
484
+ });
485
+ }
486
+ function findUnambiguousKeyStem(pairedStems, programId, transition, transitionCount) {
487
+ const programBase = programId.endsWith(".aleo") ? programId.slice(0, -".aleo".length) : programId;
488
+ const candidates = [
489
+ transition,
490
+ `${programBase}.${transition}`,
491
+ `${programId}.${transition}`,
492
+ `${programBase}_${transition}`,
493
+ ];
494
+ for (const candidate of candidates) {
495
+ if (pairedStems.includes(candidate))
496
+ return candidate;
497
+ }
498
+ return transitionCount === 1 && pairedStems.length === 1 ? pairedStems[0] : undefined;
499
+ }
500
+ function keyFileRef(artifactDir, file) {
501
+ const filePath = path.join(artifactDir, file);
502
+ return {
503
+ path: toPortablePath(path.relative(artifactDir, filePath)),
504
+ fingerprint: fingerprintFile(filePath),
505
+ };
506
+ }
507
+ function toPortablePath(p) {
508
+ return p.split(path.sep).join("/");
509
+ }
510
+ /**
511
+ * Collect a unit and all its transitive local dependencies in topological order.
512
+ */
513
+ function collectTransitiveDeps(target, graph, allUnits) {
514
+ const needed = new Set();
515
+ const unitMap = new Map();
516
+ for (const u of allUnits)
517
+ unitMap.set(unitId(u), u);
518
+ function collect(id) {
519
+ if (needed.has(id))
520
+ return;
521
+ needed.add(id);
522
+ for (const dep of graph.imports.get(id) ?? []) {
523
+ if (!graph.networkDeps.has(dep) && unitMap.has(dep)) {
524
+ collect(dep);
525
+ }
526
+ }
527
+ }
528
+ collect(unitId(target));
529
+ // Return in original topological order, filtered to needed
530
+ return graph.order.filter((u) => needed.has(unitId(u)));
531
+ }
532
+ //# sourceMappingURL=compiler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compiler.js","sourceRoot":"","sources":["../src/compiler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AACtC,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAA8B,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACjF,OAAO,EACL,eAAe,EACf,oBAAoB,EAIpB,wBAAwB,EACxB,UAAU,EACV,UAAU,EACV,yBAAyB,GAC1B,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAE3C,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACnE,OAAO,EAAwB,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AACrF,OAAO,EACL,eAAe,EACf,mBAAmB,EACnB,qBAAqB,EACrB,kBAAkB,GACnB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAStD,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAEpC,MAAM,aAAa,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC;AAQ1C;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAC1C,SAAiB,EACjB,QAAgB,EAChB,WAAoB;IAEpB,0EAA0E;IAC1E,0EAA0E;IAC1E,0EAA0E;IAC1E,0EAA0E;IAC1E,yCAAyC;IACzC,MAAM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IACH,CAAC;IAED,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;IAExB,2DAA2D;IAC3D,OAAO,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC1D,CAAC"}
@@ -0,0 +1,33 @@
1
+ import type { DiscoveredUnit } from "./types.js";
2
+ export declare class CircularDependencyError extends Error {
3
+ readonly cycle: string[];
4
+ constructor(cycle: string[]);
5
+ }
6
+ export declare class UnitNameCollisionError extends Error {
7
+ readonly key: string;
8
+ readonly firstUnit: DiscoveredUnit;
9
+ readonly secondUnit: DiscoveredUnit;
10
+ constructor(key: string, firstUnit: DiscoveredUnit, secondUnit: DiscoveredUnit);
11
+ }
12
+ export declare class ReservedUnitNameError extends Error {
13
+ readonly reservedId: string;
14
+ readonly unit: DiscoveredUnit;
15
+ constructor(reservedId: string, unit: DiscoveredUnit);
16
+ }
17
+ export interface DependencyGraph {
18
+ /** Units in topological compile order (dependencies before dependents) */
19
+ readonly order: DiscoveredUnit[];
20
+ /** Map from unit ID to its external dependency IDs (both local and network) */
21
+ readonly imports: ReadonlyMap<string, string[]>;
22
+ /** Set of network dependencies (not local units, e.g. "credits.aleo") */
23
+ readonly networkDeps: ReadonlySet<string>;
24
+ }
25
+ /**
26
+ * Build a dependency graph from discovered units by parsing imports from all
27
+ * .leo source files. Returns units in topological compile order.
28
+ *
29
+ * Local project units (programs and libraries) are resolved as local deps.
30
+ * All other imports (e.g. credits.aleo) are classified as network deps.
31
+ */
32
+ export declare function resolveDependencies(units: DiscoveredUnit[]): DependencyGraph;
33
+ //# sourceMappingURL=dependency-resolver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dependency-resolver.d.ts","sourceRoot":"","sources":["../src/dependency-resolver.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAGjD,qBAAa,uBAAwB,SAAQ,KAAK;aACpB,KAAK,EAAE,MAAM,EAAE;gBAAf,KAAK,EAAE,MAAM,EAAE;CAI5C;AAED,qBAAa,sBAAuB,SAAQ,KAAK;aAE7B,GAAG,EAAE,MAAM;aACX,SAAS,EAAE,cAAc;aACzB,UAAU,EAAE,cAAc;gBAF1B,GAAG,EAAE,MAAM,EACX,SAAS,EAAE,cAAc,EACzB,UAAU,EAAE,cAAc;CAS7C;AAUD,qBAAa,qBAAsB,SAAQ,KAAK;aAE5B,UAAU,EAAE,MAAM;aAClB,IAAI,EAAE,cAAc;gBADpB,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,cAAc;CASvC;AAED,MAAM,WAAW,eAAe;IAC9B,0EAA0E;IAC1E,QAAQ,CAAC,KAAK,EAAE,cAAc,EAAE,CAAC;IACjC,+EAA+E;IAC/E,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IAChD,yEAAyE;IACzE,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;CAC3C;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,cAAc,EAAE,GAAG,eAAe,CA4E5E"}