@aztec/aztec 0.0.1-commit.f2ce05ee → 0.0.1-commit.f5a9928

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 (190) hide show
  1. package/dest/bin/index.js +9 -3
  2. package/dest/cli/admin_api_key_store.d.ts +45 -0
  3. package/dest/cli/admin_api_key_store.d.ts.map +1 -0
  4. package/dest/cli/admin_api_key_store.js +98 -0
  5. package/dest/cli/aztec_start_action.d.ts +1 -1
  6. package/dest/cli/aztec_start_action.d.ts.map +1 -1
  7. package/dest/cli/aztec_start_action.js +79 -34
  8. package/dest/cli/aztec_start_options.d.ts +2 -2
  9. package/dest/cli/aztec_start_options.d.ts.map +1 -1
  10. package/dest/cli/aztec_start_options.js +45 -24
  11. package/dest/cli/cli.d.ts +1 -1
  12. package/dest/cli/cli.d.ts.map +1 -1
  13. package/dest/cli/cli.js +3 -4
  14. package/dest/cli/cmds/compile.d.ts +4 -0
  15. package/dest/cli/cmds/compile.d.ts.map +1 -0
  16. package/dest/cli/cmds/compile.js +174 -0
  17. package/dest/cli/cmds/profile.d.ts +4 -0
  18. package/dest/cli/cmds/profile.d.ts.map +1 -0
  19. package/dest/cli/cmds/profile.js +8 -0
  20. package/dest/cli/cmds/profile_flamegraph.d.ts +4 -0
  21. package/dest/cli/cmds/profile_flamegraph.d.ts.map +1 -0
  22. package/dest/cli/cmds/profile_flamegraph.js +52 -0
  23. package/dest/cli/cmds/profile_gates.d.ts +4 -0
  24. package/dest/cli/cmds/profile_gates.d.ts.map +1 -0
  25. package/dest/cli/cmds/profile_gates.js +76 -0
  26. package/dest/cli/cmds/profile_utils.d.ts +18 -0
  27. package/dest/cli/cmds/profile_utils.d.ts.map +1 -0
  28. package/dest/cli/cmds/profile_utils.js +50 -0
  29. package/dest/cli/cmds/prover.d.ts +4 -0
  30. package/dest/cli/cmds/prover.d.ts.map +1 -0
  31. package/dest/cli/cmds/prover.js +24 -0
  32. package/dest/cli/cmds/standby.d.ts +56 -0
  33. package/dest/cli/cmds/standby.d.ts.map +1 -0
  34. package/dest/cli/cmds/standby.js +140 -0
  35. package/dest/cli/cmds/start_bot.d.ts +3 -3
  36. package/dest/cli/cmds/start_bot.d.ts.map +1 -1
  37. package/dest/cli/cmds/start_bot.js +17 -9
  38. package/dest/cli/cmds/start_node.d.ts +3 -2
  39. package/dest/cli/cmds/start_node.d.ts.map +1 -1
  40. package/dest/cli/cmds/start_node.js +83 -51
  41. package/dest/cli/cmds/start_prover_agent.d.ts +1 -1
  42. package/dest/cli/cmds/start_prover_agent.d.ts.map +1 -1
  43. package/dest/cli/cmds/start_prover_agent.js +5 -17
  44. package/dest/cli/cmds/start_prover_broker.d.ts +1 -1
  45. package/dest/cli/cmds/start_prover_broker.d.ts.map +1 -1
  46. package/dest/cli/cmds/start_prover_broker.js +22 -13
  47. package/dest/cli/cmds/start_txe.d.ts +2 -2
  48. package/dest/cli/cmds/start_txe.d.ts.map +1 -1
  49. package/dest/cli/cmds/start_txe.js +6 -5
  50. package/dest/cli/cmds/utils/artifacts.d.ts +26 -0
  51. package/dest/cli/cmds/utils/artifacts.d.ts.map +1 -0
  52. package/dest/cli/cmds/utils/artifacts.js +24 -0
  53. package/dest/cli/cmds/utils/collect_crate_dirs.d.ts +21 -0
  54. package/dest/cli/cmds/utils/collect_crate_dirs.d.ts.map +1 -0
  55. package/dest/cli/cmds/utils/collect_crate_dirs.js +114 -0
  56. package/dest/cli/cmds/utils/needs_recompile.d.ts +10 -0
  57. package/dest/cli/cmds/utils/needs_recompile.d.ts.map +1 -0
  58. package/dest/cli/cmds/utils/needs_recompile.js +90 -0
  59. package/dest/cli/cmds/utils/spawn.d.ts +3 -0
  60. package/dest/cli/cmds/utils/spawn.d.ts.map +1 -0
  61. package/dest/cli/cmds/utils/spawn.js +16 -0
  62. package/dest/cli/cmds/utils/warn_if_aztec_version_mismatch.d.ts +4 -0
  63. package/dest/cli/cmds/utils/warn_if_aztec_version_mismatch.d.ts.map +1 -0
  64. package/dest/cli/cmds/utils/warn_if_aztec_version_mismatch.js +61 -0
  65. package/dest/cli/util.d.ts +13 -19
  66. package/dest/cli/util.d.ts.map +1 -1
  67. package/dest/cli/util.js +37 -100
  68. package/dest/deploy/bridging.d.ts +84 -0
  69. package/dest/deploy/bridging.d.ts.map +1 -0
  70. package/dest/deploy/bridging.js +121 -0
  71. package/dest/deploy/fees.d.ts +120 -0
  72. package/dest/deploy/fees.d.ts.map +1 -0
  73. package/dest/deploy/fees.js +278 -0
  74. package/dest/deploy/graph.d.ts +40 -0
  75. package/dest/deploy/graph.d.ts.map +1 -0
  76. package/dest/deploy/graph.js +120 -0
  77. package/dest/deploy/index.d.ts +19 -0
  78. package/dest/deploy/index.d.ts.map +1 -0
  79. package/dest/deploy/index.js +15 -0
  80. package/dest/deploy/reporter.d.ts +106 -0
  81. package/dest/deploy/reporter.d.ts.map +1 -0
  82. package/dest/deploy/reporter.js +76 -0
  83. package/dest/deploy/runner.d.ts +8 -0
  84. package/dest/deploy/runner.d.ts.map +1 -0
  85. package/dest/deploy/runner.js +886 -0
  86. package/dest/deploy/state.d.ts +19 -0
  87. package/dest/deploy/state.d.ts.map +1 -0
  88. package/dest/deploy/state.js +59 -0
  89. package/dest/deploy/types.d.ts +233 -0
  90. package/dest/deploy/types.d.ts.map +1 -0
  91. package/dest/deploy/types.js +9 -0
  92. package/dest/examples/token.js +9 -9
  93. package/dest/local-network/auth_registry.d.ts +5 -0
  94. package/dest/local-network/auth_registry.d.ts.map +1 -0
  95. package/dest/local-network/auth_registry.js +17 -0
  96. package/dest/local-network/banana_fpc.d.ts +3 -2
  97. package/dest/local-network/banana_fpc.d.ts.map +1 -1
  98. package/dest/local-network/banana_fpc.js +12 -8
  99. package/dest/local-network/local-network.d.ts +12 -32
  100. package/dest/local-network/local-network.d.ts.map +1 -1
  101. package/dest/local-network/local-network.js +83 -72
  102. package/dest/testing/cheat_codes.d.ts +17 -23
  103. package/dest/testing/cheat_codes.d.ts.map +1 -1
  104. package/dest/testing/cheat_codes.js +17 -43
  105. package/dest/testing/epoch_test_settler.d.ts +2 -2
  106. package/dest/testing/epoch_test_settler.d.ts.map +1 -1
  107. package/dest/testing/epoch_test_settler.js +6 -26
  108. package/dest/testing/index.d.ts +3 -2
  109. package/dest/testing/index.d.ts.map +1 -1
  110. package/dest/testing/index.js +2 -1
  111. package/dest/testing/local-network.d.ts +51 -0
  112. package/dest/testing/local-network.d.ts.map +1 -0
  113. package/dest/testing/local-network.js +60 -0
  114. package/dest/testing/token_allowed_setup.d.ts +12 -0
  115. package/dest/testing/token_allowed_setup.d.ts.map +1 -0
  116. package/dest/testing/token_allowed_setup.js +24 -0
  117. package/package.json +38 -35
  118. package/scripts/add_crate.sh +53 -0
  119. package/scripts/aztec.sh +15 -5
  120. package/scripts/init.sh +23 -19
  121. package/scripts/new.sh +48 -24
  122. package/scripts/setup_workspace.sh +69 -0
  123. package/scripts/templates/blank/contract/Nargo.toml +6 -0
  124. package/scripts/templates/blank/contract/src/main.nr +10 -0
  125. package/scripts/templates/blank/test/Nargo.toml +7 -0
  126. package/scripts/templates/blank/test/src/lib.nr +11 -0
  127. package/scripts/templates/counter/contract/Nargo.toml +7 -0
  128. package/scripts/templates/counter/contract/src/main.nr +48 -0
  129. package/scripts/templates/counter/test/Nargo.toml +7 -0
  130. package/scripts/templates/counter/test/src/lib.nr +32 -0
  131. package/src/bin/index.ts +9 -3
  132. package/src/cli/admin_api_key_store.ts +128 -0
  133. package/src/cli/aztec_start_action.ts +87 -26
  134. package/src/cli/aztec_start_options.ts +53 -30
  135. package/src/cli/cli.ts +3 -4
  136. package/src/cli/cmds/compile.ts +205 -0
  137. package/src/cli/cmds/profile.ts +26 -0
  138. package/src/cli/cmds/profile_flamegraph.ts +64 -0
  139. package/src/cli/cmds/profile_gates.ts +84 -0
  140. package/src/cli/cmds/profile_utils.ts +58 -0
  141. package/src/cli/cmds/prover.ts +42 -0
  142. package/src/cli/cmds/standby.ts +184 -0
  143. package/src/cli/cmds/start_bot.ts +17 -11
  144. package/src/cli/cmds/start_node.ts +96 -53
  145. package/src/cli/cmds/start_prover_agent.ts +5 -8
  146. package/src/cli/cmds/start_prover_broker.ts +23 -24
  147. package/src/cli/cmds/start_txe.ts +7 -5
  148. package/src/cli/cmds/utils/artifacts.ts +49 -0
  149. package/src/cli/cmds/utils/collect_crate_dirs.ts +118 -0
  150. package/src/cli/cmds/utils/needs_recompile.ts +98 -0
  151. package/src/cli/cmds/utils/spawn.ts +16 -0
  152. package/src/cli/cmds/utils/warn_if_aztec_version_mismatch.ts +76 -0
  153. package/src/cli/util.ts +39 -118
  154. package/src/deploy/bridging.ts +191 -0
  155. package/src/deploy/fees.ts +322 -0
  156. package/src/deploy/graph.ts +137 -0
  157. package/src/deploy/index.ts +41 -0
  158. package/src/deploy/reporter.ts +184 -0
  159. package/src/deploy/runner.ts +936 -0
  160. package/src/deploy/state.ts +66 -0
  161. package/src/deploy/types.ts +244 -0
  162. package/src/examples/token.ts +19 -9
  163. package/src/local-network/auth_registry.ts +19 -0
  164. package/src/local-network/banana_fpc.ts +13 -9
  165. package/src/local-network/local-network.ts +96 -81
  166. package/src/testing/cheat_codes.ts +18 -49
  167. package/src/testing/epoch_test_settler.ts +8 -32
  168. package/src/testing/index.ts +2 -1
  169. package/src/testing/local-network.ts +97 -0
  170. package/src/testing/token_allowed_setup.ts +26 -0
  171. package/dest/cli/cmds/start_archiver.d.ts +0 -9
  172. package/dest/cli/cmds/start_archiver.d.ts.map +0 -1
  173. package/dest/cli/cmds/start_archiver.js +0 -48
  174. package/dest/cli/cmds/start_prover_node.d.ts +0 -7
  175. package/dest/cli/cmds/start_prover_node.d.ts.map +0 -1
  176. package/dest/cli/cmds/start_prover_node.js +0 -108
  177. package/dest/cli/release_version.d.ts +0 -2
  178. package/dest/cli/release_version.d.ts.map +0 -1
  179. package/dest/cli/release_version.js +0 -14
  180. package/dest/testing/anvil_test_watcher.d.ts +0 -34
  181. package/dest/testing/anvil_test_watcher.d.ts.map +0 -1
  182. package/dest/testing/anvil_test_watcher.js +0 -144
  183. package/scripts/compile.sh +0 -44
  184. package/scripts/extract_function.js +0 -47
  185. package/scripts/flamegraph.sh +0 -59
  186. package/scripts/setup_project.sh +0 -31
  187. package/src/cli/cmds/start_archiver.ts +0 -50
  188. package/src/cli/cmds/start_prover_node.ts +0 -124
  189. package/src/cli/release_version.ts +0 -21
  190. package/src/testing/anvil_test_watcher.ts +0 -166
@@ -0,0 +1,128 @@
1
+ import { randomBytes } from '@aztec/foundation/crypto/random';
2
+ import { sha256Hash } from '@aztec/foundation/json-rpc/server';
3
+ import type { Logger } from '@aztec/foundation/log';
4
+
5
+ import { promises as fs } from 'fs';
6
+ import { join } from 'path';
7
+
8
+ /** Subdirectory under dataDirectory for admin API key storage. */
9
+ const ADMIN_STORE_DIR = 'admin';
10
+ const HASH_FILE_NAME = 'api_key_hash';
11
+
12
+ /**
13
+ * Result of resolving the admin API key.
14
+ * Contains the SHA-256 hex hash of the API key to be used by the auth middleware,
15
+ * and optionally the raw key when newly generated (so the caller can display it).
16
+ */
17
+ export interface AdminApiKeyResolution {
18
+ /** The SHA-256 hash of the API key. */
19
+ apiKeyHash: Buffer;
20
+ /**
21
+ * The raw API key, only present when a new key was generated during this call.
22
+ * The caller MUST display this to the operator — it will not be stored or returned again.
23
+ */
24
+ rawKey?: string;
25
+ }
26
+
27
+ export interface ResolveAdminApiKeyOptions {
28
+ /** SHA-256 hex hash of a pre-generated API key. When set, the node uses this hash directly. */
29
+ adminApiKeyHash?: string;
30
+ /** If true, disable admin API key auth entirely. */
31
+ disableAdminApiKey?: boolean;
32
+ /** If true, force-generate a new key even if one is already persisted. */
33
+ resetAdminApiKey?: boolean;
34
+ /** Root data directory for persistent storage. */
35
+ dataDirectory?: string;
36
+ }
37
+
38
+ /**
39
+ * Resolves the admin API key for the admin RPC endpoint.
40
+ *
41
+ * Strategy:
42
+ * 1. If opt-out flag is set (`disableAdminApiKey`), return undefined (no auth).
43
+ * 2. If a pre-generated hash is provided (`adminApiKeyHash`), use it directly.
44
+ * 3. If a data directory exists, look for a persisted hash file
45
+ * at `<dataDirectory>/admin/api_key_hash`:
46
+ * - If `resetAdminApiKey` is set, skip loading and force-generate a new key.
47
+ * - Found: use the stored hash (operator already saved the key from first run).
48
+ * - Not found: auto-generate a random key, display it once, persist the hash.
49
+ * 3. If no data directory: generate a random key
50
+ * each run and display it (cannot persist).
51
+ *
52
+ * @param options - The options for resolving the admin API key.
53
+ * @param log - Logger for outputting the key and status messages.
54
+ * @returns The resolved API key hash, or undefined if auth is disabled.
55
+ */
56
+ export async function resolveAdminApiKey(
57
+ options: ResolveAdminApiKeyOptions,
58
+ log: Logger,
59
+ ): Promise<AdminApiKeyResolution | undefined> {
60
+ // Operator explicitly opted out of admin auth
61
+ if (options.disableAdminApiKey) {
62
+ log.warn('Admin API key authentication is DISABLED (--disable-admin-api-key / AZTEC_DISABLE_ADMIN_API_KEY)');
63
+ return undefined;
64
+ }
65
+
66
+ // Operator provided a pre-generated hash (e.g. via AZTEC_ADMIN_API_KEY_HASH env var)
67
+ if (options.adminApiKeyHash) {
68
+ const hex = options.adminApiKeyHash.trim();
69
+ if (hex.length !== 64 || !/^[0-9a-f]{64}$/.test(hex)) {
70
+ throw new Error(`Invalid admin API key hash: expected 64-char hex string, got "${hex}"`);
71
+ }
72
+ log.info('Admin API key authentication enabled (using pre-configured key hash)');
73
+ return { apiKeyHash: Buffer.from(hex, 'hex') };
74
+ }
75
+
76
+ // Persistent storage available, load or generate key
77
+ if (options.dataDirectory) {
78
+ const adminDir = join(options.dataDirectory, ADMIN_STORE_DIR);
79
+ const hashFilePath = join(adminDir, HASH_FILE_NAME);
80
+
81
+ // Unless a reset is forced, try to load the existing hash from disk
82
+ if (!options.resetAdminApiKey) {
83
+ try {
84
+ const storedHash = (await fs.readFile(hashFilePath, 'utf-8')).trim();
85
+ if (storedHash.length === 64) {
86
+ log.info('Admin API key authentication enabled (loaded stored key hash from disk)');
87
+ return { apiKeyHash: Buffer.from(storedHash, 'hex') };
88
+ }
89
+ log.warn(`Invalid stored admin API key hash at ${hashFilePath}, regenerating...`);
90
+ } catch (err: any) {
91
+ if (err.code !== 'ENOENT') {
92
+ log.warn(`Failed to read admin API key hash from ${hashFilePath}: ${err.message}`);
93
+ }
94
+ // File doesn't exist — fall through to generate
95
+ }
96
+ } else {
97
+ log.warn('Admin API key reset requested — generating a new key');
98
+ }
99
+
100
+ // Generate a new key, persist the hash, and return the raw key for the caller to display
101
+ const { rawKey, hash } = generateApiKey();
102
+ await fs.mkdir(adminDir, { recursive: true });
103
+ await fs.writeFile(hashFilePath, hash.toString('hex'), 'utf-8');
104
+ // Set restrictive permissions (owner read/write only)
105
+ await fs.chmod(hashFilePath, 0o600);
106
+
107
+ log.info('Admin API key authentication enabled (new key generated and hash persisted to disk)');
108
+ return { apiKeyHash: hash, rawKey };
109
+ }
110
+
111
+ // No data directory, generate a temporary key per session
112
+ const { rawKey, hash } = generateApiKey();
113
+
114
+ log.warn('No data directory configured — admin API key cannot be persisted.');
115
+ log.warn('A temporary key has been generated for this session only.');
116
+
117
+ return { apiKeyHash: hash, rawKey };
118
+ }
119
+
120
+ /**
121
+ * Generates a cryptographically random API key and its SHA-256 hash.
122
+ * @returns The raw key (hex string) and its SHA-256 hash as a Buffer.
123
+ */
124
+ function generateApiKey(): { rawKey: string; hash: Buffer } {
125
+ const rawKey = randomBytes(32).toString('hex');
126
+ const hash = sha256Hash(rawKey);
127
+ return { rawKey, hash };
128
+ }
@@ -1,17 +1,24 @@
1
+ import { registerAztecNodeRpcHandlers } from '@aztec/aztec-node';
2
+ import { getActiveNetworkName } from '@aztec/foundation/config';
1
3
  import {
2
4
  type NamespacedApiHandlers,
3
5
  createNamespacedSafeJsonRpcServer,
6
+ getApiKeyAuthMiddleware,
4
7
  startHttpRpcServer,
5
8
  } from '@aztec/foundation/json-rpc/server';
6
9
  import type { LogFn, Logger } from '@aztec/foundation/log';
7
- import type { ChainConfig } from '@aztec/stdlib/config';
8
- import { AztecNodeApiSchema } from '@aztec/stdlib/interfaces/client';
10
+ import { type ChainConfig, getRpcCorsAllowedOrigins } from '@aztec/stdlib/config';
11
+ import { getPackageVersion } from '@aztec/stdlib/update-checker';
9
12
  import { getVersioningMiddleware } from '@aztec/stdlib/versioning';
10
- import { getOtelJsonRpcPropagationMiddleware } from '@aztec/telemetry-client';
13
+ import {
14
+ getOtelJsonRpcDiagnosticsMiddleware,
15
+ getOtelJsonRpcPropagationMiddleware,
16
+ getOtelJsonRpcServerMetricsMiddleware,
17
+ } from '@aztec/telemetry-client';
11
18
 
12
19
  import { createLocalNetwork } from '../local-network/index.js';
13
20
  import { github, splash } from '../splash.js';
14
- import { getCliVersion } from './release_version.js';
21
+ import { resolveAdminApiKey } from './admin_api_key_store.js';
15
22
  import { extractNamespacedOptions, installSignalHandlers } from './util.js';
16
23
  import { getVersions } from './versioning.js';
17
24
 
@@ -20,46 +27,39 @@ export async function aztecStart(options: any, userLog: LogFn, debugLogger: Logg
20
27
  const signalHandlers: Array<() => Promise<void>> = [];
21
28
  const services: NamespacedApiHandlers = {};
22
29
  const adminServices: NamespacedApiHandlers = {};
30
+ const packageVersion = getPackageVersion();
23
31
  let config: ChainConfig | undefined = undefined;
24
32
 
25
33
  if (options.localNetwork) {
26
- const cliVersion = getCliVersion();
27
- const localNetwork = extractNamespacedOptions(options, 'local-network');
28
- localNetwork.testAccounts = true;
34
+ const localNetwork = extractNamespacedOptions(options, 'localNetwork');
29
35
  userLog(`${splash}\n${github}\n\n`);
30
- userLog(`Setting up Aztec local network ${cliVersion}, please stand by...`);
36
+ userLog(`Setting up Aztec local network ${packageVersion}, please stand by...`);
31
37
 
32
38
  const { node, stop } = await createLocalNetwork(
33
39
  {
34
40
  l1Mnemonic: localNetwork.l1Mnemonic,
35
41
  l1RpcUrls: options.l1RpcUrls,
36
42
  testAccounts: localNetwork.testAccounts,
37
- realProofs: false,
38
- // Setting the epoch duration to 4 by default for local network. This allows the epoch to be "proven" faster, so
39
- // the users can consume out hash without having to wait for a long time.
40
- // Note: We are not proving anything in the local network (realProofs == false). But in `createLocalNetwork`,
41
- // the EpochTestSettler will set the out hash to the outbox when an epoch is complete.
42
- aztecEpochDuration: 4,
43
43
  },
44
44
  userLog,
45
45
  );
46
46
 
47
47
  // Start Node and PXE JSON-RPC server
48
48
  signalHandlers.push(stop);
49
- services.node = [node, AztecNodeApiSchema];
49
+ registerAztecNodeRpcHandlers(node, services, adminServices, { debug: true });
50
50
  } else {
51
+ // Route --prover-node through startNode
52
+ if (options.proverNode && !options.node) {
53
+ options.node = true;
54
+ }
55
+
51
56
  if (options.node) {
52
57
  const { startNode } = await import('./cmds/start_node.js');
53
- ({ config } = await startNode(options, signalHandlers, services, adminServices, userLog));
58
+ const networkName = getActiveNetworkName(options.network);
59
+ ({ config } = await startNode(options, signalHandlers, services, adminServices, userLog, networkName));
54
60
  } else if (options.bot) {
55
61
  const { startBot } = await import('./cmds/start_bot.js');
56
62
  await startBot(options, signalHandlers, services, userLog);
57
- } else if (options.proverNode) {
58
- const { startProverNode } = await import('./cmds/start_prover_node.js');
59
- ({ config } = await startProverNode(options, signalHandlers, services, userLog));
60
- } else if (options.archiver) {
61
- const { startArchiver } = await import('./cmds/start_archiver.js');
62
- ({ config } = await startArchiver(options, signalHandlers, services));
63
63
  } else if (options.p2pBootstrap) {
64
64
  const { startP2PBootstrap } = await import('./cmds/start_p2p_bootstrap.js');
65
65
  ({ config } = await startP2PBootstrap(options, signalHandlers, services, userLog));
@@ -71,7 +71,7 @@ export async function aztecStart(options: any, userLog: LogFn, debugLogger: Logg
71
71
  await startProverBroker(options, signalHandlers, services, userLog);
72
72
  } else if (options.txe) {
73
73
  const { startTXE } = await import('./cmds/start_txe.js');
74
- await startTXE(options, debugLogger);
74
+ await startTXE(options, signalHandlers, debugLogger);
75
75
  } else if (options.sequencer) {
76
76
  userLog(`Cannot run a standalone sequencer without a node`);
77
77
  process.exit(1);
@@ -83,30 +83,91 @@ export async function aztecStart(options: any, userLog: LogFn, debugLogger: Logg
83
83
 
84
84
  installSignalHandlers(debugLogger.info, signalHandlers);
85
85
  const versions = getVersions(config);
86
+ const versioningOpts = { packageVersion };
86
87
 
87
88
  // Start the main JSON-RPC server
88
89
  if (Object.entries(services).length > 0) {
90
+ if (services.aztec) {
91
+ const { BarretenbergSync } = await import('@aztec/bb.js');
92
+ // JSON-RPC schema parsing may decompress compressed Chonk proofs before the node handler runs.
93
+ await BarretenbergSync.initSingleton();
94
+ }
95
+
89
96
  const rpcServer = createNamespacedSafeJsonRpcServer(services, {
97
+ diagnostic: getOtelJsonRpcDiagnosticsMiddleware(),
90
98
  http200OnError: false,
91
99
  log: debugLogger,
92
- middlewares: [getOtelJsonRpcPropagationMiddleware(), getVersioningMiddleware(versions)],
100
+ middlewares: [
101
+ getOtelJsonRpcServerMetricsMiddleware(),
102
+ getOtelJsonRpcPropagationMiddleware(),
103
+ getVersioningMiddleware(versions, versioningOpts),
104
+ ],
93
105
  maxBatchSize: options.rpcMaxBatchSize,
94
106
  maxBodySizeBytes: options.rpcMaxBodySize,
107
+ corsAllowedHeaders: options.rpcCorsAllowedHeaders ?? [],
108
+ corsAllowedOrigins: getRpcCorsAllowedOrigins(options),
109
+ });
110
+ const { port } = await startHttpRpcServer(rpcServer, {
111
+ port: options.port,
112
+ keepAliveTimeoutMs: options.rpcHttpKeepAliveTimeoutMs,
113
+ headersTimeoutMs: options.rpcHttpHeadersTimeoutMs,
95
114
  });
96
- const { port } = await startHttpRpcServer(rpcServer, { port: options.port });
97
115
  debugLogger.info(`Aztec Server listening on port ${port}`, versions);
98
116
  }
99
117
 
100
118
  // If there are any admin services, start a separate JSON-RPC server for them
101
119
  if (Object.entries(adminServices).length > 0) {
120
+ // Resolve the admin API key (auto-generated and persisted, or opt-out)
121
+ const apiKeyResolution = await resolveAdminApiKey(
122
+ {
123
+ adminApiKeyHash: options.adminApiKeyHash,
124
+ disableAdminApiKey: options.disableAdminApiKey,
125
+ resetAdminApiKey: options.resetAdminApiKey,
126
+ dataDirectory: options.dataDirectory,
127
+ },
128
+ debugLogger,
129
+ );
130
+ if (!apiKeyResolution) {
131
+ debugLogger.warn('No admin API key set — admin endpoint is unauthenticated');
132
+ }
133
+ const adminMiddlewares = [
134
+ getOtelJsonRpcServerMetricsMiddleware(),
135
+ ...(apiKeyResolution ? [getApiKeyAuthMiddleware(apiKeyResolution.apiKeyHash)] : []),
136
+ getOtelJsonRpcPropagationMiddleware(),
137
+ getVersioningMiddleware(versions, versioningOpts),
138
+ ];
139
+
102
140
  const rpcServer = createNamespacedSafeJsonRpcServer(adminServices, {
141
+ diagnostic: getOtelJsonRpcDiagnosticsMiddleware(),
103
142
  http200OnError: false,
104
143
  log: debugLogger,
105
- middlewares: [getOtelJsonRpcPropagationMiddleware(), getVersioningMiddleware(versions)],
144
+ middlewares: adminMiddlewares,
106
145
  maxBatchSize: options.rpcMaxBatchSize,
107
146
  maxBodySizeBytes: options.rpcMaxBodySize,
108
147
  });
109
148
  const { port } = await startHttpRpcServer(rpcServer, { port: options.adminPort });
110
149
  debugLogger.info(`Aztec Server admin API listening on port ${port}`, versions);
150
+
151
+ // Display the API key after the server has started
152
+ // Uses userLog which is never filtered by LOG_LEVEL.
153
+ if (apiKeyResolution?.rawKey) {
154
+ const separator = '='.repeat(70);
155
+ userLog('');
156
+ userLog(separator);
157
+ userLog(' ADMIN API KEY (save this — it will NOT be shown again)');
158
+ userLog('');
159
+ userLog(` ${apiKeyResolution.rawKey}`);
160
+ userLog('');
161
+ userLog(` Use via header: x-api-key: <key>`);
162
+ userLog(` Or via header: Authorization: Bearer <key>`);
163
+ if (options.dataDirectory) {
164
+ userLog('');
165
+ userLog(' The key hash has been persisted — on next restart, the same key will be used.');
166
+ }
167
+ userLog('');
168
+ userLog(' To disable admin auth: --disable-admin-api-key or AZTEC_DISABLE_ADMIN_API_KEY=true');
169
+ userLog(separator);
170
+ userLog('');
171
+ }
111
172
  }
112
173
  }
@@ -12,7 +12,6 @@ import {
12
12
  isBooleanConfigValue,
13
13
  omitConfigMappings,
14
14
  } from '@aztec/foundation/config';
15
- import { dataConfigMappings } from '@aztec/kv-store/config';
16
15
  import { sharedNodeConfigMappings } from '@aztec/node-lib/config';
17
16
  import { bootnodeConfigMappings, p2pConfigMappings } from '@aztec/p2p/config';
18
17
  import { proverAgentConfigMappings, proverBrokerConfigMappings } from '@aztec/prover-client/broker/config';
@@ -20,6 +19,7 @@ import { proverNodeConfigMappings } from '@aztec/prover-node/config';
20
19
  import { allPxeConfigMappings } from '@aztec/pxe/config';
21
20
  import { sequencerClientConfigMappings } from '@aztec/sequencer-client/config';
22
21
  import { chainConfigMappings, nodeRpcConfigMappings } from '@aztec/stdlib/config';
22
+ import { dataConfigMappings } from '@aztec/stdlib/kv-store';
23
23
  import { telemetryClientConfigMappings } from '@aztec/telemetry-client/config';
24
24
  import { worldStateConfigMappings } from '@aztec/world-state/config';
25
25
 
@@ -36,7 +36,7 @@ export interface AztecStartOption {
36
36
  parseVal?: (val: string) => any;
37
37
  }
38
38
 
39
- export const getOptions = (namespace: string, configMappings: Record<string, ConfigMapping>) => {
39
+ export const getOptions = (namespace: string, configMappings: Record<string, ConfigMapping<unknown>>) => {
40
40
  const options: AztecStartOption[] = [];
41
41
  for (const [key, { env, defaultValue: def, parseEnv, description, printDefault, fallback }] of Object.entries(
42
42
  configMappings,
@@ -58,7 +58,11 @@ export const getOptions = (namespace: string, configMappings: Record<string, Con
58
58
  return options;
59
59
  };
60
60
 
61
- const configToFlag = (flag: string, configMapping: ConfigMapping, overrideDefaultValue?: any): AztecStartOption => {
61
+ const configToFlag = (
62
+ flag: string,
63
+ configMapping: ConfigMapping<unknown>,
64
+ overrideDefaultValue?: any,
65
+ ): AztecStartOption => {
62
66
  if (!configMapping.isBoolean) {
63
67
  flag += ' <value>';
64
68
  }
@@ -105,8 +109,7 @@ export const aztecStartOptions: { [key: string]: AztecStartOption[] } = {
105
109
  env: 'NETWORK',
106
110
  },
107
111
 
108
- configToFlag('--auto-update', sharedNodeConfigMappings.autoUpdate),
109
- configToFlag('--auto-update-url', sharedNodeConfigMappings.autoUpdateUrl),
112
+ configToFlag('--enable-auto-shutdown', sharedNodeConfigMappings.enableAutoShutdown),
110
113
 
111
114
  configToFlag('--sync-mode', sharedNodeConfigMappings.syncMode),
112
115
  configToFlag('--snapshots-urls', sharedNodeConfigMappings.snapshotsUrls),
@@ -126,6 +129,12 @@ export const aztecStartOptions: { [key: string]: AztecStartOption[] } = {
126
129
  defaultValue: DefaultMnemonic,
127
130
  env: 'MNEMONIC',
128
131
  },
132
+ {
133
+ flag: '--local-network.testAccounts',
134
+ description: 'Deploy test accounts on local network start',
135
+ env: 'TEST_ACCOUNTS',
136
+ ...booleanConfigHelper(true),
137
+ },
129
138
  ],
130
139
  API: [
131
140
  {
@@ -142,6 +151,37 @@ export const aztecStartOptions: { [key: string]: AztecStartOption[] } = {
142
151
  env: 'AZTEC_ADMIN_PORT',
143
152
  parseVal: val => parseInt(val, 10),
144
153
  },
154
+ {
155
+ flag: '--admin-api-key-hash <value>',
156
+ description:
157
+ 'SHA-256 hex hash of a pre-generated admin API key. When set, the node uses this hash for authentication instead of auto-generating a key.',
158
+ defaultValue: undefined,
159
+ env: 'AZTEC_ADMIN_API_KEY_HASH',
160
+ },
161
+ {
162
+ flag: '--disable-admin-api-key',
163
+ description:
164
+ 'Disable API key authentication on the admin RPC endpoint. By default, a key is auto-generated, displayed once, and its hash is persisted.',
165
+ defaultValue: false,
166
+ env: 'AZTEC_DISABLE_ADMIN_API_KEY',
167
+ // undefined means the flag was passed without a value (boolean toggle), treat as true.
168
+ parseVal: val => val === undefined || val === 'true' || val === '1',
169
+ },
170
+ {
171
+ flag: '--reset-admin-api-key',
172
+ description:
173
+ 'Force-generate a new admin API key, replacing any previously persisted key hash. The new key is displayed once at startup.',
174
+ defaultValue: false,
175
+ env: 'AZTEC_RESET_ADMIN_API_KEY',
176
+ parseVal: val => val === 'true' || val === '1',
177
+ },
178
+ {
179
+ flag: '--node-debug',
180
+ description: 'Expose debug endpoints (e.g. mineBlock) on the main RPC port',
181
+ defaultValue: false,
182
+ env: 'AZTEC_NODE_DEBUG',
183
+ parseVal: val => val === undefined || val === 'true' || val === '1',
184
+ },
145
185
  {
146
186
  flag: '--api-prefix <value>',
147
187
  description: 'Prefix for API routes on any service that is started',
@@ -150,6 +190,11 @@ export const aztecStartOptions: { [key: string]: AztecStartOption[] } = {
150
190
  },
151
191
  configToFlag('--rpcMaxBatchSize', nodeRpcConfigMappings.rpcMaxBatchSize),
152
192
  configToFlag('--rpcMaxBodySize', nodeRpcConfigMappings.rpcMaxBodySize),
193
+ configToFlag('--rpc-http-keep-alive-timeout-ms', nodeRpcConfigMappings.rpcHttpKeepAliveTimeoutMs),
194
+ configToFlag('--rpc-http-headers-timeout-ms', nodeRpcConfigMappings.rpcHttpHeadersTimeoutMs),
195
+ configToFlag('--rpc-cors-allowed-headers', nodeRpcConfigMappings.rpcCorsAllowedHeaders),
196
+ configToFlag('--rpc-cors-allowed-origins', nodeRpcConfigMappings.rpcCorsAllowedOrigins),
197
+ configToFlag('--rpc-cors-allow-any-origin', nodeRpcConfigMappings.rpcCorsAllowAnyOrigin),
153
198
  ],
154
199
  ETHEREUM: [
155
200
  configToFlag('--l1-chain-id', l1ReaderConfigMappings.l1ChainId),
@@ -170,7 +215,7 @@ export const aztecStartOptions: { [key: string]: AztecStartOption[] } = {
170
215
  'WORLD STATE': [
171
216
  configToFlag('--world-state-data-directory', worldStateConfigMappings.worldStateDataDirectory),
172
217
  configToFlag('--world-state-db-map-size-kb', worldStateConfigMappings.worldStateDbMapSizeKb),
173
- configToFlag('--world-state-block-history', worldStateConfigMappings.worldStateBlockHistory),
218
+ configToFlag('--world-state-checkpoint-history', worldStateConfigMappings.worldStateCheckpointHistory),
174
219
  ],
175
220
  // We can't easily auto-generate node options as they're parts of modules defined below
176
221
  'AZTEC NODE': [
@@ -182,12 +227,6 @@ export const aztecStartOptions: { [key: string]: AztecStartOption[] } = {
182
227
  },
183
228
  ],
184
229
  ARCHIVER: [
185
- {
186
- flag: '--archiver',
187
- description: 'Starts Aztec Archiver with options',
188
- defaultValue: undefined,
189
- env: undefined,
190
- },
191
230
  ...getOptions(
192
231
  'archiver',
193
232
  omitConfigMappings(archiverConfigMappings, Object.keys(l1ContractsConfigMappings) as (keyof ArchiverConfig)[]),
@@ -222,12 +261,8 @@ export const aztecStartOptions: { [key: string]: AztecStartOption[] } = {
222
261
  'proverNode',
223
262
  omitConfigMappings(proverNodeConfigMappings, [
224
263
  // filter out options passed separately
225
- ...getKeys(archiverConfigMappings),
226
264
  ...getKeys(proverBrokerConfigMappings),
227
265
  ...getKeys(proverAgentConfigMappings),
228
- ...getKeys(p2pConfigMappings),
229
- ...getKeys(worldStateConfigMappings),
230
- ...getKeys(sharedNodeConfigMappings),
231
266
  ]),
232
267
  ),
233
268
  ],
@@ -238,11 +273,7 @@ export const aztecStartOptions: { [key: string]: AztecStartOption[] } = {
238
273
  defaultValue: undefined,
239
274
  env: undefined,
240
275
  },
241
- ...getOptions(
242
- 'proverBroker',
243
- // filter out archiver options from prover node options as they're passed separately in --archiver
244
- proverBrokerConfigMappings,
245
- ),
276
+ ...getOptions('proverBroker', proverBrokerConfigMappings),
246
277
  ],
247
278
  'PROVER AGENT': [
248
279
  {
@@ -290,15 +321,7 @@ export const aztecStartOptions: { [key: string]: AztecStartOption[] } = {
290
321
  },
291
322
  ...getOptions('bot', botConfigMappings),
292
323
  ],
293
- PXE: [
294
- {
295
- flag: '--pxe',
296
- description: 'Starts Aztec PXE with options',
297
- defaultValue: undefined,
298
- env: undefined,
299
- },
300
- ...getOptions('pxe', allPxeConfigMappings),
301
- ],
324
+ PXE: [...getOptions('pxe', allPxeConfigMappings)],
302
325
  TXE: [
303
326
  {
304
327
  flag: '--txe',
package/src/cli/cli.ts CHANGED
@@ -37,10 +37,9 @@ export function injectAztecCommands(program: Command, userLog: LogFn, debugLogge
37
37
  `
38
38
  Additional commands:
39
39
 
40
- init [folder] [options] creates a new Aztec Noir project.
41
- new <path> [options] creates a new Aztec Noir project in a new directory.
42
- compile [options] compiles Aztec Noir contracts.
43
- test [options] starts a TXE and runs "nargo test" using it as the oracle resolver.
40
+ init creates a new Aztec Noir workspace in the current directory.
41
+ new <name> creates a new Aztec Noir workspace in its own directory (or creates a new contract-test crates pair and adds it to the current workspace if run in workspace).
42
+ test [options] starts a TXE and runs "nargo test" using it as the oracle resolver.
44
43
  `,
45
44
  );
46
45
  }