@aztec-labs/foundation 6.0.0-rc.3 → 6.0.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 (260) hide show
  1. package/dest/bigint-buffer/index.d.ts +2 -1
  2. package/dest/bigint-buffer/index.d.ts.map +1 -1
  3. package/dest/bigint-buffer/index.js +1 -0
  4. package/dest/buffer/buffer16.d.ts +3 -2
  5. package/dest/buffer/buffer16.d.ts.map +1 -1
  6. package/dest/buffer/buffer16.js +2 -1
  7. package/dest/buffer/buffer32.d.ts +3 -2
  8. package/dest/buffer/buffer32.d.ts.map +1 -1
  9. package/dest/buffer/buffer32.js +2 -1
  10. package/dest/config/env.d.ts +8 -0
  11. package/dest/config/env.d.ts.map +1 -0
  12. package/dest/config/env.js +15 -0
  13. package/dest/config/env_var.d.ts +2 -2
  14. package/dest/config/env_var.d.ts.map +1 -1
  15. package/dest/config/index.d.ts +5 -2
  16. package/dest/config/index.d.ts.map +1 -1
  17. package/dest/config/index.js +18 -19
  18. package/dest/config/network_name.d.ts +1 -1
  19. package/dest/config/network_name.d.ts.map +1 -1
  20. package/dest/config/network_name.js +2 -1
  21. package/dest/config/secret_value.d.ts +2 -2
  22. package/dest/config/secret_value.d.ts.map +1 -1
  23. package/dest/config/secret_value.js +1 -1
  24. package/dest/crypto/bls/bn254_keystore.d.ts +1 -1
  25. package/dest/crypto/bls/bn254_keystore.d.ts.map +1 -1
  26. package/dest/crypto/bls/bn254_keystore.js +1 -0
  27. package/dest/crypto/bls/index.d.ts +1 -1
  28. package/dest/crypto/bls/index.d.ts.map +1 -1
  29. package/dest/crypto/bls/index.js +1 -0
  30. package/dest/crypto/ecdsa/index.d.ts +2 -1
  31. package/dest/crypto/ecdsa/index.d.ts.map +1 -1
  32. package/dest/crypto/ecdsa/index.js +1 -0
  33. package/dest/crypto/ecdsa/signature.d.ts +2 -1
  34. package/dest/crypto/ecdsa/signature.d.ts.map +1 -1
  35. package/dest/crypto/ecdsa/signature.js +1 -0
  36. package/dest/crypto/grumpkin/index.d.ts +2 -1
  37. package/dest/crypto/grumpkin/index.d.ts.map +1 -1
  38. package/dest/crypto/grumpkin/index.js +1 -0
  39. package/dest/crypto/keys/index.d.ts +2 -1
  40. package/dest/crypto/keys/index.d.ts.map +1 -1
  41. package/dest/crypto/keys/index.js +1 -0
  42. package/dest/crypto/pedersen/pedersen.wasm.d.ts +2 -1
  43. package/dest/crypto/pedersen/pedersen.wasm.d.ts.map +1 -1
  44. package/dest/crypto/pedersen/pedersen.wasm.js +1 -0
  45. package/dest/crypto/poseidon/index.d.ts +2 -1
  46. package/dest/crypto/poseidon/index.d.ts.map +1 -1
  47. package/dest/crypto/poseidon/index.js +1 -0
  48. package/dest/crypto/random/index.d.ts +2 -1
  49. package/dest/crypto/random/index.d.ts.map +1 -1
  50. package/dest/crypto/random/index.js +1 -0
  51. package/dest/crypto/random/randomness_singleton.d.ts +2 -1
  52. package/dest/crypto/random/randomness_singleton.d.ts.map +1 -1
  53. package/dest/crypto/random/randomness_singleton.js +4 -1
  54. package/dest/crypto/schnorr/index.d.ts +1 -1
  55. package/dest/crypto/schnorr/index.d.ts.map +1 -1
  56. package/dest/crypto/schnorr/index.js +1 -0
  57. package/dest/crypto/schnorr/signature.d.ts +2 -1
  58. package/dest/crypto/schnorr/signature.d.ts.map +1 -1
  59. package/dest/crypto/schnorr/signature.js +1 -0
  60. package/dest/crypto/secp256k1/index.d.ts +2 -1
  61. package/dest/crypto/secp256k1/index.d.ts.map +1 -1
  62. package/dest/crypto/secp256k1/index.js +1 -0
  63. package/dest/crypto/secp256k1-signer/utils.d.ts +2 -1
  64. package/dest/crypto/secp256k1-signer/utils.d.ts.map +1 -1
  65. package/dest/crypto/secp256k1-signer/utils.js +1 -0
  66. package/dest/crypto/sha256/index.d.ts +2 -1
  67. package/dest/crypto/sha256/index.d.ts.map +1 -1
  68. package/dest/crypto/sha256/index.js +2 -1
  69. package/dest/crypto/sha512/index.d.ts +2 -1
  70. package/dest/crypto/sha512/index.d.ts.map +1 -1
  71. package/dest/crypto/sha512/index.js +1 -0
  72. package/dest/crypto/sync/pedersen/index.d.ts +2 -1
  73. package/dest/crypto/sync/pedersen/index.d.ts.map +1 -1
  74. package/dest/crypto/sync/pedersen/index.js +1 -0
  75. package/dest/crypto/sync/poseidon/index.d.ts +2 -1
  76. package/dest/crypto/sync/poseidon/index.d.ts.map +1 -1
  77. package/dest/crypto/sync/poseidon/index.js +1 -0
  78. package/dest/curves/bls12/field.d.ts +3 -2
  79. package/dest/curves/bls12/field.d.ts.map +1 -1
  80. package/dest/curves/bls12/field.js +2 -1
  81. package/dest/curves/bls12/point.d.ts +3 -2
  82. package/dest/curves/bls12/point.d.ts.map +1 -1
  83. package/dest/curves/bls12/point.js +2 -1
  84. package/dest/curves/bn254/field.d.ts +3 -2
  85. package/dest/curves/bn254/field.d.ts.map +1 -1
  86. package/dest/curves/bn254/field.js +4 -2
  87. package/dest/curves/bn254/point.d.ts +2 -1
  88. package/dest/curves/bn254/point.d.ts.map +1 -1
  89. package/dest/curves/bn254/point.js +1 -0
  90. package/dest/curves/grumpkin/point.d.ts +2 -1
  91. package/dest/curves/grumpkin/point.d.ts.map +1 -1
  92. package/dest/curves/grumpkin/point.js +1 -0
  93. package/dest/eth-address/index.d.ts +3 -2
  94. package/dest/eth-address/index.d.ts.map +1 -1
  95. package/dest/eth-address/index.js +2 -1
  96. package/dest/fifo/fifo_frame_reader.d.ts +2 -1
  97. package/dest/fifo/fifo_frame_reader.d.ts.map +1 -1
  98. package/dest/fifo/fifo_frame_reader.js +1 -0
  99. package/dest/inspect/index.d.ts +11 -0
  100. package/dest/inspect/index.d.ts.map +1 -0
  101. package/dest/inspect/index.js +11 -0
  102. package/dest/inspect/inspect_without_node.d.ts +10 -0
  103. package/dest/inspect/inspect_without_node.d.ts.map +1 -0
  104. package/dest/inspect/inspect_without_node.js +39 -0
  105. package/dest/json-rpc/client/fetch.d.ts +1 -1
  106. package/dest/json-rpc/client/fetch.d.ts.map +1 -1
  107. package/dest/json-rpc/client/fetch.js +5 -2
  108. package/dest/json-rpc/client/safe_json_rpc_client.d.ts +1 -1
  109. package/dest/json-rpc/client/safe_json_rpc_client.d.ts.map +1 -1
  110. package/dest/json-rpc/client/safe_json_rpc_client.js +8 -3
  111. package/dest/json-rpc/client/undici.d.ts +1 -1
  112. package/dest/json-rpc/client/undici.d.ts.map +1 -1
  113. package/dest/json-rpc/client/undici.js +1 -0
  114. package/dest/json-rpc/server/api_key_auth.d.ts +2 -1
  115. package/dest/json-rpc/server/api_key_auth.d.ts.map +1 -1
  116. package/dest/json-rpc/server/api_key_auth.js +1 -0
  117. package/dest/json-rpc/server/safe_json_rpc_server.d.ts +1 -1
  118. package/dest/json-rpc/server/safe_json_rpc_server.d.ts.map +1 -1
  119. package/dest/json-rpc/server/safe_json_rpc_server.js +2 -1
  120. package/dest/log/index.d.ts +2 -1
  121. package/dest/log/index.d.ts.map +1 -1
  122. package/dest/log/index.js +1 -0
  123. package/dest/log/libp2p_logger.d.ts +1 -1
  124. package/dest/log/libp2p_logger.d.ts.map +1 -1
  125. package/dest/log/libp2p_logger.js +11 -17
  126. package/dest/log/log-filters.d.ts +8 -1
  127. package/dest/log/log-filters.d.ts.map +1 -1
  128. package/dest/log/log-filters.js +28 -4
  129. package/dest/log/pino-logger.d.ts +23 -2
  130. package/dest/log/pino-logger.d.ts.map +1 -1
  131. package/dest/log/pino-logger.js +78 -26
  132. package/dest/queue/index.d.ts +2 -1
  133. package/dest/queue/index.d.ts.map +1 -1
  134. package/dest/queue/index.js +1 -0
  135. package/dest/queue/read_write_lock.d.ts +21 -0
  136. package/dest/queue/read_write_lock.d.ts.map +1 -0
  137. package/dest/queue/read_write_lock.js +44 -0
  138. package/dest/queue/semaphore.d.ts +17 -2
  139. package/dest/queue/semaphore.d.ts.map +1 -1
  140. package/dest/queue/semaphore.js +22 -2
  141. package/dest/schemas/schemas.d.ts +2 -1
  142. package/dest/schemas/schemas.d.ts.map +1 -1
  143. package/dest/schemas/schemas.js +1 -0
  144. package/dest/schemas/utils.d.ts +2 -1
  145. package/dest/schemas/utils.d.ts.map +1 -1
  146. package/dest/schemas/utils.js +1 -0
  147. package/dest/serialize/buffer_reader.d.ts +2 -1
  148. package/dest/serialize/buffer_reader.d.ts.map +1 -1
  149. package/dest/serialize/buffer_reader.js +1 -0
  150. package/dest/serialize/buffer_sink.d.ts +2 -1
  151. package/dest/serialize/buffer_sink.d.ts.map +1 -1
  152. package/dest/serialize/buffer_sink.js +2 -4
  153. package/dest/serialize/free_funcs.d.ts +2 -1
  154. package/dest/serialize/free_funcs.d.ts.map +1 -1
  155. package/dest/serialize/free_funcs.js +1 -0
  156. package/dest/serialize/serialize.d.ts +2 -1
  157. package/dest/serialize/serialize.d.ts.map +1 -1
  158. package/dest/serialize/serialize.js +1 -0
  159. package/dest/serialize/type_registry.d.ts +1 -1
  160. package/dest/serialize/type_registry.d.ts.map +1 -1
  161. package/dest/serialize/type_registry.js +1 -0
  162. package/dest/string/index.d.ts +2 -1
  163. package/dest/string/index.d.ts.map +1 -1
  164. package/dest/string/index.js +2 -1
  165. package/dest/testing/files/index.d.ts +1 -1
  166. package/dest/testing/files/index.d.ts.map +1 -1
  167. package/dest/testing/files/index.js +2 -1
  168. package/dest/testing/snapshot_serializer.d.ts +1 -1
  169. package/dest/testing/snapshot_serializer.d.ts.map +1 -1
  170. package/dest/testing/snapshot_serializer.js +2 -1
  171. package/dest/testing/test_data.d.ts +1 -1
  172. package/dest/testing/test_data.d.ts.map +1 -1
  173. package/dest/testing/test_data.js +2 -1
  174. package/dest/trees/hasher.d.ts +2 -1
  175. package/dest/trees/hasher.d.ts.map +1 -1
  176. package/dest/trees/hasher.js +1 -0
  177. package/dest/trees/indexed_merkle_tree.d.ts +2 -1
  178. package/dest/trees/indexed_merkle_tree.d.ts.map +1 -1
  179. package/dest/trees/indexed_merkle_tree.js +1 -0
  180. package/dest/trees/indexed_merkle_tree_calculator.d.ts +2 -1
  181. package/dest/trees/indexed_merkle_tree_calculator.d.ts.map +1 -1
  182. package/dest/trees/indexed_merkle_tree_calculator.js +1 -0
  183. package/dest/trees/merkle_tree.d.ts +2 -1
  184. package/dest/trees/merkle_tree.d.ts.map +1 -1
  185. package/dest/trees/merkle_tree.js +1 -0
  186. package/dest/trees/merkle_tree_calculator.d.ts +2 -1
  187. package/dest/trees/merkle_tree_calculator.d.ts.map +1 -1
  188. package/dest/trees/merkle_tree_calculator.js +1 -0
  189. package/dest/trees/unbalanced_merkle_tree_calculator.d.ts +2 -1
  190. package/dest/trees/unbalanced_merkle_tree_calculator.d.ts.map +1 -1
  191. package/dest/trees/unbalanced_merkle_tree_calculator.js +1 -0
  192. package/dest/trees/unbalanced_merkle_tree_root.d.ts +2 -1
  193. package/dest/trees/unbalanced_merkle_tree_root.d.ts.map +1 -1
  194. package/dest/trees/unbalanced_merkle_tree_root.js +1 -0
  195. package/package.json +8 -5
  196. package/src/bigint-buffer/index.ts +2 -0
  197. package/src/buffer/buffer16.ts +2 -1
  198. package/src/buffer/buffer32.ts +2 -1
  199. package/src/config/env.ts +16 -0
  200. package/src/config/env_var.ts +3 -1
  201. package/src/config/index.ts +25 -18
  202. package/src/config/network_name.ts +3 -1
  203. package/src/config/secret_value.ts +2 -1
  204. package/src/crypto/bls/bn254_keystore.ts +1 -0
  205. package/src/crypto/bls/index.ts +1 -0
  206. package/src/crypto/ecdsa/index.ts +2 -0
  207. package/src/crypto/ecdsa/signature.ts +1 -0
  208. package/src/crypto/grumpkin/index.ts +1 -0
  209. package/src/crypto/keys/index.ts +2 -0
  210. package/src/crypto/pedersen/pedersen.wasm.ts +2 -0
  211. package/src/crypto/poseidon/index.ts +2 -0
  212. package/src/crypto/random/index.ts +2 -0
  213. package/src/crypto/random/randomness_singleton.ts +5 -1
  214. package/src/crypto/schnorr/index.ts +1 -0
  215. package/src/crypto/schnorr/signature.ts +1 -0
  216. package/src/crypto/secp256k1/index.ts +2 -0
  217. package/src/crypto/secp256k1-signer/utils.ts +1 -0
  218. package/src/crypto/sha256/index.ts +1 -0
  219. package/src/crypto/sha512/index.ts +1 -0
  220. package/src/crypto/sync/pedersen/index.ts +2 -0
  221. package/src/crypto/sync/poseidon/index.ts +2 -0
  222. package/src/curves/bls12/field.ts +2 -1
  223. package/src/curves/bls12/point.ts +2 -1
  224. package/src/curves/bn254/field.ts +4 -2
  225. package/src/curves/bn254/point.ts +2 -0
  226. package/src/curves/grumpkin/point.ts +2 -0
  227. package/src/eth-address/index.ts +2 -1
  228. package/src/fifo/fifo_frame_reader.ts +1 -0
  229. package/src/inspect/index.ts +14 -0
  230. package/src/inspect/inspect_without_node.ts +45 -0
  231. package/src/json-rpc/client/fetch.ts +5 -3
  232. package/src/json-rpc/client/safe_json_rpc_client.ts +8 -4
  233. package/src/json-rpc/client/undici.ts +1 -0
  234. package/src/json-rpc/server/api_key_auth.ts +1 -0
  235. package/src/json-rpc/server/safe_json_rpc_server.ts +2 -1
  236. package/src/log/index.ts +1 -0
  237. package/src/log/libp2p_logger.ts +8 -10
  238. package/src/log/log-filters.ts +27 -7
  239. package/src/log/pino-logger.ts +81 -22
  240. package/src/queue/index.ts +1 -0
  241. package/src/queue/read_write_lock.ts +53 -0
  242. package/src/queue/semaphore.ts +26 -2
  243. package/src/schemas/schemas.ts +1 -0
  244. package/src/schemas/utils.ts +1 -0
  245. package/src/serialize/buffer_reader.ts +2 -0
  246. package/src/serialize/buffer_sink.ts +2 -0
  247. package/src/serialize/free_funcs.ts +2 -0
  248. package/src/serialize/serialize.ts +2 -0
  249. package/src/serialize/type_registry.ts +2 -0
  250. package/src/string/index.ts +2 -0
  251. package/src/testing/files/index.ts +2 -1
  252. package/src/testing/snapshot_serializer.ts +3 -1
  253. package/src/testing/test_data.ts +3 -1
  254. package/src/trees/hasher.ts +2 -0
  255. package/src/trees/indexed_merkle_tree.ts +2 -0
  256. package/src/trees/indexed_merkle_tree_calculator.ts +1 -0
  257. package/src/trees/merkle_tree.ts +2 -0
  258. package/src/trees/merkle_tree_calculator.ts +2 -0
  259. package/src/trees/unbalanced_merkle_tree_calculator.ts +2 -0
  260. package/src/trees/unbalanced_merkle_tree_root.ts +2 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aztec-labs/foundation",
3
- "version": "6.0.0-rc.3",
3
+ "version": "6.0.0",
4
4
  "type": "module",
5
5
  "main": "./dest/index.js",
6
6
  "types": "./dest/index.d.ts",
@@ -35,6 +35,7 @@
35
35
  "./branded-types": "./dest/branded-types/index.js",
36
36
  "./collection": "./dest/collection/index.js",
37
37
  "./config": "./dest/config/index.js",
38
+ "./config/env": "./dest/config/env.js",
38
39
  "./crypto/aes128": "./dest/crypto/aes128/index.js",
39
40
  "./crypto/bls": "./dest/crypto/bls/index.js",
40
41
  "./crypto/bls/bn254_keystore": "./dest/crypto/bls/bn254_keystore.js",
@@ -70,6 +71,7 @@
70
71
  "./json-rpc/server": "./dest/json-rpc/server/index.js",
71
72
  "./json-rpc/undici": "./dest/json-rpc/client/undici.js",
72
73
  "./json-rpc/test": "./dest/json-rpc/test/index.js",
74
+ "./inspect": "./dest/inspect/index.js",
73
75
  "./iterable": "./dest/iterable/index.js",
74
76
  "./iterator": "./dest/iterator/index.js",
75
77
  "./log": "./dest/log/index.js",
@@ -146,12 +148,13 @@
146
148
  "testEnvironment": "../../foundation/src/jest/env.mjs"
147
149
  },
148
150
  "dependencies": {
149
- "@aztec-foundation/bb.js": "6.0.0-rc.6",
151
+ "@aztec-foundation/bb.js": "6.0.0",
150
152
  "@koa/cors": "^5.0.0",
151
153
  "@noble/curves": "=1.7.0",
152
154
  "@noble/hashes": "^1.6.1",
153
155
  "@scure/bip39": "^2.0.1",
154
156
  "bn.js": "^5.2.3",
157
+ "buffer": "^6.0.3",
155
158
  "colorette": "^2.0.20",
156
159
  "detect-node": "^2.1.0",
157
160
  "hash.js": "^1.1.7",
@@ -166,7 +169,7 @@
166
169
  "pino": "^9.5.0",
167
170
  "pino-pretty": "^13.0.0",
168
171
  "sha3": "^2.1.4",
169
- "undici": "^5.28.5",
172
+ "undici": "^6.29.0",
170
173
  "zod": "~4.4.3"
171
174
  },
172
175
  "devDependencies": {
@@ -200,7 +203,7 @@
200
203
  "ts-node": "^10.9.1",
201
204
  "typescript": "^5.3.3",
202
205
  "typescript-eslint": "^8.32.1",
203
- "viem": "npm:@aztec/viem@2.38.3"
206
+ "viem": "2.57.1"
204
207
  },
205
208
  "files": [
206
209
  "dest",
@@ -208,6 +211,6 @@
208
211
  "!*.test.*"
209
212
  ],
210
213
  "engines": {
211
- "node": ">=20.10"
214
+ "node": ">=20.16"
212
215
  }
213
216
  }
@@ -1,3 +1,5 @@
1
+ import { Buffer } from 'buffer';
2
+
1
3
  /**
2
4
  * Convert a little-endian buffer into a BigInt.
3
5
  * @param buf - The little-endian buffer to convert.
@@ -1,8 +1,9 @@
1
1
  import { randomBytes } from '@aztec-labs/foundation/crypto/random';
2
2
  import type { Fr } from '@aztec-labs/foundation/curves/bn254';
3
3
  import { BufferReader, deserializeBigInt, serializeBigInt } from '@aztec-labs/foundation/serialize';
4
- import { inspect } from 'util';
4
+ import { Buffer } from 'buffer';
5
5
 
6
+ import { inspect } from '../inspect/index.js';
6
7
  import { bufferToHex } from '../string/index.js';
7
8
 
8
9
  /**
@@ -1,8 +1,9 @@
1
1
  import { randomBytes } from '@aztec-labs/foundation/crypto/random';
2
2
  import type { Fr } from '@aztec-labs/foundation/curves/bn254';
3
3
  import { BufferReader, deserializeBigInt, serializeBigInt } from '@aztec-labs/foundation/serialize';
4
- import { inspect } from 'util';
4
+ import { Buffer } from 'buffer';
5
5
 
6
+ import { inspect } from '../inspect/index.js';
6
7
  import { bufferToHex } from '../string/index.js';
7
8
 
8
9
  /**
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Returns the environment variables of the current runtime, or an empty record where it has none.
3
+ *
4
+ * In a browser this reads whatever a bundler substitutes for the whole `process.env`, so an app must define that
5
+ * entire object; a definition of an individual `process.env.X` is not seen here and is silently absent.
6
+ */
7
+ export function getEnv(): Record<string, string | undefined> {
8
+ // `process.env` is written out literally because bundlers substitute that exact text with the variables an app
9
+ // defines, which a `typeof process` guard would discard in a runtime that has no `process`.
10
+ try {
11
+ // eslint-disable-next-line no-restricted-properties
12
+ return process.env ?? {};
13
+ } catch {
14
+ return {};
15
+ }
16
+ }
@@ -198,6 +198,7 @@ export type EnvVar =
198
198
  | 'PROVER_PROOF_STORE'
199
199
  | 'PROVER_FAILED_PROOF_STORE'
200
200
  | 'PROVER_NODE_FAILED_EPOCH_STORE'
201
+ | 'PROVER_NODE_DISABLE_FULL_EPOCH_PROVING'
201
202
  | 'PROVER_NODE_DISABLE_PROOF_PUBLISH'
202
203
  | 'PROVER_NODE_PROOF_SUBMISSION_TARGET_ADDRESS'
203
204
  | 'PROVER_ID'
@@ -212,7 +213,6 @@ export type EnvVar =
212
213
  | 'PROVER_PUBLISHER_PRIVATE_KEYS'
213
214
  | 'PROVER_PUBLISHER_ADDRESSES'
214
215
  | 'PROVER_PUBLISHER_ALLOW_INVALID_STATES'
215
- | 'PROVER_PUBLISHER_FORWARDER_ADDRESS'
216
216
  | 'PROVER_REAL_PROOFS'
217
217
  | 'PROVER_TEST_DELAY_FACTOR'
218
218
  | 'PROVER_TEST_DELAY_MS'
@@ -257,6 +257,7 @@ export type EnvVar =
257
257
  | 'SEQ_PUBLISHER_PREVIOUS_L1_BLOCK_WAIT_POLL_INTERVAL_MS'
258
258
  | 'PUBLISHER_FUNDING_THRESHOLD'
259
259
  | 'PUBLISHER_FUNDING_AMOUNT'
260
+ | 'PUBLISHER_LOW_BALANCE_WARNING_MULTIPLIER'
260
261
  | 'SEQ_POLLING_INTERVAL_MS'
261
262
  | 'SEQ_L1_PUBLISHING_TIME_ALLOWANCE_IN_SLOT'
262
263
  | 'SEQ_ATTESTATION_PROPAGATION_TIME'
@@ -331,6 +332,7 @@ export type EnvVar =
331
332
  | 'WS_BLOCK_REQUEST_BATCH_SIZE'
332
333
  | 'L1_READER_VIEM_POLLING_INTERVAL_MS'
333
334
  | 'WS_DATA_DIRECTORY'
335
+ | 'WS_HISTORY_RETENTION'
334
336
  | 'WS_NUM_HISTORIC_CHECKPOINTS'
335
337
  | 'WS_NUM_HISTORIC_BLOCKS'
336
338
  | 'ETHEREUM_SLOT_DURATION'
@@ -1,5 +1,6 @@
1
1
  import { Fq, Fr } from '../curves/bn254/field.js';
2
2
  import { createConsoleLogger } from '../log/console.js';
3
+ import { getEnv } from './env.js';
3
4
  import type { EnvVar } from './env_var.js';
4
5
  import { type NetworkNames, getActiveNetworkName } from './network_name.js';
5
6
  import { parseBooleanEnv } from './parse-env.js';
@@ -23,7 +24,12 @@ export interface ConfigMapping<T> {
23
24
  * List of deprecated env vars that are still supported but will log a warning.
24
25
  * These should also be included in the fallback array for parsing.
25
26
  */
26
- deprecatedFallback?: { env: EnvVar; message?: string }[];
27
+ deprecatedFallback?: {
28
+ env: EnvVar;
29
+ message?: string;
30
+ /** Convert a legacy value to the syntax accepted by parseEnv. */
31
+ transform?: (value: string) => string;
32
+ }[];
27
33
  }
28
34
 
29
35
  export function isBooleanConfigValue<T>(obj: T, key: keyof T): boolean {
@@ -42,6 +48,7 @@ export type ConfigMappingsType<T> = {
42
48
  * @param fallback - Optional array of fallback environment variable names
43
49
  * @param parseFunc - Optional function to parse the environment variable value
44
50
  * @param defaultValue - Optional default value to use if no environment variable is set
51
+ * @param deprecatedFallback - Deprecated aliases, with optional value migrations
45
52
  * @returns The parsed value from environment variables or the default value
46
53
  */
47
54
  export function getValueFromEnvWithFallback<T>(
@@ -49,25 +56,36 @@ export function getValueFromEnvWithFallback<T>(
49
56
  parseFunc: ((val: string) => T) | undefined,
50
57
  defaultValue: T | undefined,
51
58
  fallback?: EnvVar[],
59
+ deprecatedFallback?: ConfigMapping<T>['deprecatedFallback'],
52
60
  ): T | undefined {
53
61
  let value: string | undefined;
54
62
 
55
63
  // Try primary env var
56
64
  if (env) {
57
- value = process.env[env];
65
+ value = getEnv()[env];
58
66
  }
59
67
 
60
68
  // If primary not found, try fallbacks
61
- if (value === undefined && fallback && fallback.length > 0) {
69
+ if (!value && fallback && fallback.length > 0) {
62
70
  for (const fallbackEnv of fallback) {
63
- const fallbackVal = process.env[fallbackEnv];
64
- if (fallbackVal !== undefined) {
65
- value = fallbackVal;
71
+ const fallbackVal = getEnv()[fallbackEnv];
72
+ if (fallbackVal !== undefined && fallbackVal !== '') {
73
+ const transform = deprecatedFallback?.find(entry => entry.env === fallbackEnv)?.transform;
74
+ value = transform?.(fallbackVal) ?? fallbackVal;
66
75
  break;
67
76
  }
68
77
  }
69
78
  }
70
79
 
80
+ for (const { env: deprecatedEnv, message } of deprecatedFallback ?? []) {
81
+ if (getEnv()[deprecatedEnv]) {
82
+ createConsoleLogger('[DEPRECATED]')(
83
+ message ?? `Environment variable ${deprecatedEnv} is deprecated. Please use ${env} instead.`,
84
+ { deprecatedEnvVar: deprecatedEnv, newEnvVar: env },
85
+ );
86
+ }
87
+ }
88
+
71
89
  // Parse the value if needed. Empty strings are treated as "not set".
72
90
  if (value !== undefined && value !== '') {
73
91
  return parseFunc ? parseFunc(value) : (value as unknown as T);
@@ -83,21 +101,10 @@ export function getConfigFromMappings<T>(configMappings: ConfigMappingsType<T>):
83
101
  for (const key in configMappings) {
84
102
  const { env, parseEnv, defaultValue, fallback, deprecatedFallback } = configMappings[key];
85
103
  try {
86
- (config as any)[key] = getValueFromEnvWithFallback(env, parseEnv, defaultValue, fallback);
104
+ (config as any)[key] = getValueFromEnvWithFallback(env, parseEnv, defaultValue, fallback, deprecatedFallback);
87
105
  } catch (e: any) {
88
106
  throw new Error(`Failed to parse config '${key}' (env: ${env ?? 'none'}): ${e.message}`);
89
107
  }
90
-
91
- if (deprecatedFallback?.length) {
92
- const userLog = createConsoleLogger('[DEPRECATED]');
93
- for (const { env: deprecatedEnv, message } of deprecatedFallback) {
94
- if (process.env[deprecatedEnv]) {
95
- const warningMessage =
96
- message ?? `Environment variable ${deprecatedEnv} is deprecated. Please use ${env} instead.`;
97
- userLog(warningMessage, { deprecatedEnvVar: deprecatedEnv, newEnvVar: env });
98
- }
99
- }
100
- }
101
108
  }
102
109
 
103
110
  return config;
@@ -1,3 +1,5 @@
1
+ import { getEnv } from './env.js';
2
+
1
3
  export type NetworkNames =
2
4
  | 'local'
3
5
  | 'staging'
@@ -8,7 +10,7 @@ export type NetworkNames =
8
10
  | `v${number}-devnet-${number}`;
9
11
 
10
12
  export function getActiveNetworkName(name?: string): NetworkNames {
11
- const network = name || process.env.NETWORK;
13
+ const network = name || getEnv().NETWORK;
12
14
  if (!network || network === '' || network === 'local') {
13
15
  return 'local';
14
16
  } else if (network === 'staging') {
@@ -1,6 +1,7 @@
1
- import { inspect } from 'util';
2
1
  import type { ZodType } from 'zod';
3
2
 
3
+ import { inspect } from '../inspect/index.js';
4
+
4
5
  /**
5
6
  * A class wrapping a secret value to protect it from accidently being leaked in logs
6
7
  */
@@ -1,4 +1,5 @@
1
1
  import { randomBytes } from '@aztec-labs/foundation/crypto/random';
2
+ import { Buffer } from 'buffer';
2
3
  import { createCipheriv, createDecipheriv, createHash, pbkdf2, pbkdf2Sync, randomUUID } from 'crypto';
3
4
  import { readFileSync } from 'fs';
4
5
  import { promisify } from 'util';
@@ -5,6 +5,7 @@ import { bytesToNumberBE } from '@noble/curves/abstract/utils';
5
5
  import { hmac } from '@noble/hashes/hmac';
6
6
  import { sha512 } from '@noble/hashes/sha2';
7
7
  import { mnemonicToSeedSync } from '@scure/bip39';
8
+ import { Buffer } from 'buffer';
8
9
 
9
10
  export function deriveBlsPrivateKey(mnemonic: string | undefined, ikm: string | undefined, path: string): Hex<32> {
10
11
  if (ikm) {
@@ -1,5 +1,7 @@
1
1
  import { BarretenbergSync } from '@aztec-foundation/bb.js';
2
2
 
3
+ import { Buffer } from 'buffer';
4
+
3
5
  import { EcdsaSignature } from './signature.js';
4
6
 
5
7
  export * from './signature.js';
@@ -2,6 +2,7 @@ import { toBufferBE } from '@aztec-labs/foundation/bigint-buffer';
2
2
  import { randomBytes } from '@aztec-labs/foundation/crypto/random';
3
3
  import { Fr } from '@aztec-labs/foundation/curves/bn254';
4
4
  import { mapTuple } from '@aztec-labs/foundation/serialize';
5
+ import { Buffer } from 'buffer';
5
6
 
6
7
  import type { Signature } from '../signature/index.js';
7
8
 
@@ -3,6 +3,7 @@ import { BarretenbergSync } from '@aztec-foundation/bb.js';
3
3
  import { Fr } from '@aztec-labs/foundation/curves/bn254';
4
4
  import type { GrumpkinScalar } from '@aztec-labs/foundation/curves/grumpkin';
5
5
  import { Point } from '@aztec-labs/foundation/curves/grumpkin';
6
+ import { Buffer } from 'buffer';
6
7
 
7
8
  /**
8
9
  * Grumpkin elliptic curve operations.
@@ -1,5 +1,7 @@
1
1
  import { BarretenbergSync, CircuitKind } from '@aztec-foundation/bb.js';
2
2
 
3
+ import { Buffer } from 'buffer';
4
+
3
5
  import { Fr } from '../../curves/bn254/field.js';
4
6
 
5
7
  export async function vkAsFields(input: Buffer, kind: CircuitKind): Promise<Fr[]> {
@@ -1,5 +1,7 @@
1
1
  import { BarretenbergSync } from '@aztec-foundation/bb.js';
2
2
 
3
+ import { Buffer } from 'buffer';
4
+
3
5
  import { Fr } from '../../curves/bn254/field.js';
4
6
  import { type Fieldable, serializeToFields } from '../../serialize/serialize.js';
5
7
 
@@ -1,5 +1,7 @@
1
1
  import { Barretenberg, BarretenbergSync } from '@aztec-foundation/bb.js';
2
2
 
3
+ import { Buffer } from 'buffer';
4
+
3
5
  import { Fr } from '../../curves/bn254/field.js';
4
6
  import { type Fieldable, serializeToFields } from '../../serialize/serialize.js';
5
7
 
@@ -1,5 +1,7 @@
1
1
  import { randomBytes as bbRandomBytes } from '@aztec-foundation/bb.js';
2
2
 
3
+ import { Buffer } from 'buffer';
4
+
3
5
  import { RandomnessSingleton } from './randomness_singleton.js';
4
6
 
5
7
  export const randomBytes = (len: number) => {
@@ -1,3 +1,6 @@
1
+ import { Buffer } from 'buffer';
2
+
3
+ import { getEnv } from '../../config/env.js';
1
4
  import { type Logger, type LoggerBindings, createLogger } from '../../log/pino-logger.js';
2
5
 
3
6
  /**
@@ -29,7 +32,8 @@ export class RandomnessSingleton {
29
32
 
30
33
  public static getInstance(bindings?: LoggerBindings): RandomnessSingleton {
31
34
  if (!RandomnessSingleton.instance) {
32
- const seed = process.env.SEED ? Number(process.env.SEED) : undefined;
35
+ const { SEED } = getEnv();
36
+ const seed = SEED ? Number(SEED) : undefined;
33
37
  RandomnessSingleton.instance = new RandomnessSingleton(seed, bindings);
34
38
  }
35
39
 
@@ -3,6 +3,7 @@ import { BarretenbergSync } from '@aztec-foundation/bb.js';
3
3
  import type { Fr } from '@aztec-labs/foundation/curves/bn254';
4
4
  import type { GrumpkinScalar } from '@aztec-labs/foundation/curves/grumpkin';
5
5
  import { Point } from '@aztec-labs/foundation/curves/grumpkin';
6
+ import { Buffer } from 'buffer';
6
7
 
7
8
  import { SchnorrSignature } from './signature.js';
8
9
 
@@ -1,5 +1,6 @@
1
1
  import { Fr } from '@aztec-labs/foundation/curves/bn254';
2
2
  import { mapTuple } from '@aztec-labs/foundation/serialize';
3
+ import { Buffer } from 'buffer';
3
4
 
4
5
  import type { Signature } from '../signature/index.js';
5
6
 
@@ -1,5 +1,7 @@
1
1
  import { BarretenbergSync } from '@aztec-foundation/bb.js';
2
2
 
3
+ import { Buffer } from 'buffer';
4
+
3
5
  /**
4
6
  * Secp256k1 elliptic curve operations.
5
7
  */
@@ -1,4 +1,5 @@
1
1
  import { secp256k1 } from '@noble/curves/secp256k1';
2
+ import { Buffer } from 'buffer';
2
3
 
3
4
  import { Buffer32 } from '../../buffer/buffer32.js';
4
5
  import { EthAddress } from '../../eth-address/index.js';
@@ -1,4 +1,5 @@
1
1
  /* eslint-disable camelcase */
2
+ import { Buffer } from 'buffer';
2
3
  import { default as hash } from 'hash.js';
3
4
 
4
5
  import { Fr } from '../../curves/bn254/field.js';
@@ -1,3 +1,4 @@
1
+ import { Buffer } from 'buffer';
1
2
  import { default as hash } from 'hash.js';
2
3
 
3
4
  import { GrumpkinScalar } from '../../curves/grumpkin/index.js';
@@ -1,5 +1,7 @@
1
1
  import { BarretenbergSync } from '@aztec-foundation/bb.js';
2
2
 
3
+ import { Buffer } from 'buffer';
4
+
3
5
  import { Fr } from '../../../curves/bn254/field.js';
4
6
  import { type Fieldable, serializeToFields } from '../../../serialize/serialize.js';
5
7
 
@@ -1,5 +1,7 @@
1
1
  import { BarretenbergSync } from '@aztec-foundation/bb.js';
2
2
 
3
+ import { Buffer } from 'buffer';
4
+
3
5
  import { Fr } from '../../../curves/bn254/field.js';
4
6
  import { type Fieldable, serializeToFields } from '../../../serialize/serialize.js';
5
7
 
@@ -1,9 +1,10 @@
1
1
  /* eslint-disable camelcase */
2
2
  import { bls12_381 } from '@noble/curves/bls12-381';
3
- import { inspect } from 'util';
3
+ import { Buffer } from 'buffer';
4
4
 
5
5
  import { toBigIntBE, toBufferBE } from '../../bigint-buffer/index.js';
6
6
  import { randomBytes } from '../../crypto/random/index.js';
7
+ import { inspect } from '../../inspect/index.js';
7
8
  import { hexSchemaFor } from '../../schemas/utils.js';
8
9
  import { BufferReader } from '../../serialize/buffer_reader.js';
9
10
  import { Fr } from '../bn254/field.js';
@@ -1,10 +1,11 @@
1
1
  import type { ProjPointType } from '@noble/curves/abstract/weierstrass';
2
2
  /* eslint-disable camelcase */
3
3
  import { bls12_381 } from '@noble/curves/bls12-381';
4
- import { inspect } from 'util';
4
+ import { Buffer } from 'buffer';
5
5
 
6
6
  import { toBufferBE } from '../../bigint-buffer/index.js';
7
7
  import { randomBoolean } from '../../crypto/random/index.js';
8
+ import { inspect } from '../../inspect/index.js';
8
9
  import { hexSchemaFor } from '../../schemas/utils.js';
9
10
  import { BufferReader, serializeToBuffer } from '../../serialize/index.js';
10
11
  import { bufferToHex, hexToBuffer } from '../../string/index.js';
@@ -1,9 +1,11 @@
1
1
  import { BarretenbergSync } from '@aztec-foundation/bb.js';
2
2
 
3
- import { inspect } from 'util';
3
+ import { Buffer } from 'buffer';
4
4
 
5
5
  import { toBigIntBE, toBufferBE } from '../../bigint-buffer/index.js';
6
+ import { getEnv } from '../../config/env.js';
6
7
  import { randomBytes } from '../../crypto/random/index.js';
8
+ import { inspect } from '../../inspect/index.js';
7
9
  import { hexSchemaFor } from '../../schemas/utils.js';
8
10
  import { BufferReader } from '../../serialize/buffer_reader.js';
9
11
  import type { BufferSink } from '../../serialize/buffer_sink.js';
@@ -507,7 +509,7 @@ export function reduceFn<TInput, TField extends BaseField>(fn: (input: TInput) =
507
509
  }
508
510
 
509
511
  /** If we are in test mode, we register a special equality for fields. */
510
- if (process.env.NODE_ENV === 'test') {
512
+ if (getEnv().NODE_ENV === 'test') {
511
513
  const areFieldsEqual = (a: unknown, b: unknown): boolean | undefined => {
512
514
  const isAField = a instanceof BaseField;
513
515
  const isBField = b instanceof BaseField;
@@ -6,6 +6,8 @@ import {
6
6
  type Bn254G2Point as BbApiBn254G2Point,
7
7
  } from '@aztec-foundation/bb.js';
8
8
 
9
+ import { Buffer } from 'buffer';
10
+
9
11
  import { Fq, Fr } from './field.js';
10
12
 
11
13
  /**
@@ -1,3 +1,5 @@
1
+ import { Buffer } from 'buffer';
2
+
1
3
  import { toBigIntBE } from '../../bigint-buffer/index.js';
2
4
  import { randomBoolean } from '../../crypto/random/index.js';
3
5
  import { hexSchemaFor } from '../../schemas/utils.js';
@@ -1,8 +1,9 @@
1
- import { inspect } from 'util';
1
+ import { Buffer } from 'buffer';
2
2
 
3
3
  import { keccak256String } from '../crypto/keccak/index.js';
4
4
  import { randomBytes } from '../crypto/random/index.js';
5
5
  import { Fr } from '../curves/bn254/index.js';
6
+ import { inspect } from '../inspect/index.js';
6
7
  import { hexSchemaFor } from '../schemas/utils.js';
7
8
  import { BufferReader, FieldReader } from '../serialize/index.js';
8
9
  import { bufferToHex } from '../string/index.js';
@@ -1,3 +1,4 @@
1
+ import { Buffer } from 'buffer';
1
2
  import EventEmitter from 'node:events';
2
3
  import * as fs from 'node:fs';
3
4
  import * as net from 'node:net';
@@ -0,0 +1,14 @@
1
+ import { custom, inspectWithoutNode } from './inspect_without_node.js';
2
+
3
+ // A static import of `util` cannot be resolved by a bundler targeting a browser, so the builtin is looked up at runtime.
4
+ const nodeInspect: ((value: unknown) => string) | undefined = globalThis.process?.getBuiltinModule?.('util')?.inspect;
5
+
6
+ /**
7
+ * Returns a string representation of a value, for log and error messages.
8
+ *
9
+ * Where the `util` module of Node.js is available this is the output of `util.inspect`. Elsewhere it is a simpler
10
+ * representation, which still honors a class's own `[inspect.custom]` method.
11
+ */
12
+ export const inspect = Object.assign((value: unknown): string => (nodeInspect ?? inspectWithoutNode)(value), {
13
+ custom,
14
+ } as const);
@@ -0,0 +1,45 @@
1
+ import { tryJsonStringify } from '../json-rpc/convert.js';
2
+
3
+ /** The key of the method through which a class controls how its instances are represented. */
4
+ export const custom = Symbol.for('nodejs.util.inspect.custom');
5
+
6
+ function hasCustomInspect(value: object): value is { [custom]: () => unknown } {
7
+ return custom in value && typeof value[custom] === 'function';
8
+ }
9
+
10
+ function describeError(error: Error, seen: WeakSet<Error> = new WeakSet()): string {
11
+ const description = `${error.name}: ${error.message}`;
12
+ // A `cause` can point back into its own chain; tracking visited errors keeps a cycle from overflowing the stack.
13
+ if (error.cause === undefined || seen.has(error)) {
14
+ return description;
15
+ }
16
+ seen.add(error);
17
+ const cause = error.cause instanceof Error ? describeError(error.cause, seen) : inspectWithoutNode(error.cause);
18
+ return `${description} [cause]: ${cause}`;
19
+ }
20
+
21
+ /**
22
+ * Returns a string representation of a value without relying on Node.js.
23
+ *
24
+ * Honors a class's own `[custom]` method. Any other object is represented as JSON, with buffers as base64 and maps and
25
+ * sets as arrays.
26
+ */
27
+ export function inspectWithoutNode(value: unknown): string {
28
+ if (typeof value === 'string') {
29
+ return `'${value}'`;
30
+ }
31
+ if (typeof value === 'bigint') {
32
+ return `${value}n`;
33
+ }
34
+ if (typeof value !== 'object' || value === null) {
35
+ return String(value);
36
+ }
37
+ if (hasCustomInspect(value)) {
38
+ return String(value[custom]());
39
+ }
40
+ if (value instanceof Error) {
41
+ return describeError(value);
42
+ }
43
+ // Undefined for values that JSON cannot represent, such as ones with circular references.
44
+ return tryJsonStringify(value) ?? Object.prototype.toString.call(value);
45
+ }
@@ -1,5 +1,4 @@
1
- import { format, inspect } from 'util';
2
-
1
+ import { inspect } from '../../inspect/index.js';
3
2
  import { type Logger, createLogger } from '../../log/index.js';
4
3
  import { NoRetryError, makeBackoff, retry } from '../../retry/index.js';
5
4
  import { jsonStringify } from '../convert.js';
@@ -35,7 +34,10 @@ export async function defaultFetch(
35
34
  noRetry = false,
36
35
  config: JsonRpcFetchConfig = {},
37
36
  ): Promise<{ response: any; headers: { get: (header: string) => string | null | undefined } }> {
38
- log.debug(format(`JsonRpcClient.fetch`, host, '->', body));
37
+ // Inspecting a large payload such as a Tx is expensive, so it is only done when the message will be logged.
38
+ if (log.isLevelEnabled('debug')) {
39
+ log.debug(`JsonRpcClient.fetch ${host} -> ${inspect(body)}`);
40
+ }
39
41
  let resp: Response;
40
42
  try {
41
43
  resp = await fetch(host, {
@@ -1,5 +1,4 @@
1
- import { format } from 'util';
2
-
1
+ import { inspect } from '../../inspect/index.js';
3
2
  import { type Logger, createLogger } from '../../log/pino-logger.js';
4
3
  import { type PromiseWithResolvers, promiseWithResolvers } from '../../promise/utils.js';
5
4
  import { type ApiSchema, type ApiSchemaFor, getSchemaReturnType, schemaHasMethod } from '../../schemas/api.js';
@@ -226,9 +225,14 @@ export function createSafeJsonRpcClient<T extends object>(
226
225
  sendBatchTimeoutHandle = setTimeout(sendBatch, batchWindowMS);
227
226
  }
228
227
 
229
- log.debug(format(`request`, method, params));
228
+ // Inspecting a large payload such as a Tx is expensive, so it is only done when the message will be logged.
229
+ if (log.isLevelEnabled('debug')) {
230
+ log.debug(`request ${method} ${inspect(params)}`);
231
+ }
230
232
  const response = await deferred.promise;
231
- log.debug(format(`result`, method, response));
233
+ if (log.isLevelEnabled('debug')) {
234
+ log.debug(`result ${method} ${inspect(response)}`);
235
+ }
232
236
 
233
237
  if ('error' in response) {
234
238
  throw new Error(response.error.message, { cause: response.error });
@@ -1,3 +1,4 @@
1
+ import { Buffer } from 'buffer';
1
2
  import { promisify } from 'node:util';
2
3
  import { gunzip as gunzipCb, gzip as gzipCb } from 'node:zlib';
3
4
  import { Agent, type Dispatcher } from 'undici';
@@ -1,3 +1,4 @@
1
+ import { Buffer } from 'buffer';
1
2
  import { timingSafeEqual } from 'crypto';
2
3
  import type Koa from 'koa';
3
4
 
@@ -5,9 +5,10 @@ import bodyParser from 'koa-bodyparser';
5
5
  import compress from 'koa-compress';
6
6
  import Router from 'koa-router';
7
7
  import type { AddressInfo } from 'net';
8
- import { format, inspect } from 'util';
8
+ import { format } from 'util';
9
9
  import { ZodError } from 'zod';
10
10
 
11
+ import { inspect } from '../../inspect/index.js';
11
12
  import { type Logger, createLogger } from '../../log/index.js';
12
13
  import { promiseWithResolvers } from '../../promise/utils.js';
13
14
  import {