@aztec/foundation 0.0.1-commit.4ad48494d → 0.0.1-commit.4d3c002

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 (163) hide show
  1. package/dest/branded-types/slot.d.ts +4 -1
  2. package/dest/branded-types/slot.d.ts.map +1 -1
  3. package/dest/branded-types/slot.js +3 -0
  4. package/dest/buffer/buffer16.d.ts +3 -1
  5. package/dest/buffer/buffer16.d.ts.map +1 -1
  6. package/dest/buffer/buffer32.d.ts +3 -1
  7. package/dest/buffer/buffer32.d.ts.map +1 -1
  8. package/dest/buffer/index.d.ts +2 -1
  9. package/dest/buffer/index.d.ts.map +1 -1
  10. package/dest/buffer/index.js +1 -0
  11. package/dest/buffer/utils.d.ts +3 -0
  12. package/dest/buffer/utils.d.ts.map +1 -0
  13. package/dest/buffer/utils.js +7 -0
  14. package/dest/collection/array.d.ts +3 -1
  15. package/dest/collection/array.d.ts.map +1 -1
  16. package/dest/collection/array.js +15 -0
  17. package/dest/collection/index.d.ts +2 -1
  18. package/dest/collection/index.d.ts.map +1 -1
  19. package/dest/collection/index.js +1 -0
  20. package/dest/collection/lru_set.d.ts +35 -0
  21. package/dest/collection/lru_set.d.ts.map +1 -0
  22. package/dest/collection/lru_set.js +95 -0
  23. package/dest/config/env_var.d.ts +2 -2
  24. package/dest/config/env_var.d.ts.map +1 -1
  25. package/dest/config/index.d.ts +1 -1
  26. package/dest/config/index.d.ts.map +1 -1
  27. package/dest/config/index.js +15 -0
  28. package/dest/config/network_config.d.ts +19 -1
  29. package/dest/config/network_config.d.ts.map +1 -1
  30. package/dest/config/network_config.js +4 -1
  31. package/dest/config/network_name.d.ts +2 -2
  32. package/dest/config/network_name.d.ts.map +1 -1
  33. package/dest/config/network_name.js +2 -0
  34. package/dest/crypto/aes128/index.d.ts +2 -1
  35. package/dest/crypto/aes128/index.d.ts.map +1 -1
  36. package/dest/crypto/aes128/index.js +11 -2
  37. package/dest/crypto/bls/bn254_keystore.d.ts +1 -10
  38. package/dest/crypto/bls/bn254_keystore.d.ts.map +1 -1
  39. package/dest/crypto/bls/bn254_keystore.js +0 -17
  40. package/dest/crypto/poseidon/index.d.ts +1 -1
  41. package/dest/crypto/poseidon/index.d.ts.map +1 -1
  42. package/dest/crypto/poseidon/index.js +40 -33
  43. package/dest/crypto/secp256k1-signer/utils.d.ts +12 -1
  44. package/dest/crypto/secp256k1-signer/utils.d.ts.map +1 -1
  45. package/dest/crypto/secp256k1-signer/utils.js +26 -0
  46. package/dest/curves/bn254/field.d.ts +2 -1
  47. package/dest/curves/bn254/field.d.ts.map +1 -1
  48. package/dest/curves/bn254/field.js +5 -2
  49. package/dest/curves/grumpkin/point.d.ts +1 -1
  50. package/dest/curves/grumpkin/point.js +1 -1
  51. package/dest/eth-signature/eth_signature.d.ts +2 -1
  52. package/dest/eth-signature/eth_signature.d.ts.map +1 -1
  53. package/dest/eth-signature/eth_signature.js +7 -2
  54. package/dest/fifo/fifo_frame_reader.d.ts +41 -0
  55. package/dest/fifo/fifo_frame_reader.d.ts.map +1 -0
  56. package/dest/fifo/fifo_frame_reader.js +74 -0
  57. package/dest/fifo/index.d.ts +2 -0
  58. package/dest/fifo/index.d.ts.map +1 -0
  59. package/dest/fifo/index.js +1 -0
  60. package/dest/jest/setup.js +24 -0
  61. package/dest/json-rpc/client/fetch.d.ts +1 -1
  62. package/dest/json-rpc/client/fetch.d.ts.map +1 -1
  63. package/dest/json-rpc/client/fetch.js +4 -3
  64. package/dest/json-rpc/client/safe_json_rpc_client.d.ts +2 -1
  65. package/dest/json-rpc/client/safe_json_rpc_client.d.ts.map +1 -1
  66. package/dest/json-rpc/client/safe_json_rpc_client.js +1 -1
  67. package/dest/json-rpc/client/undici.d.ts +1 -1
  68. package/dest/json-rpc/client/undici.d.ts.map +1 -1
  69. package/dest/json-rpc/client/undici.js +5 -3
  70. package/dest/json-rpc/server/api_key_auth.d.ts +19 -0
  71. package/dest/json-rpc/server/api_key_auth.d.ts.map +1 -0
  72. package/dest/json-rpc/server/api_key_auth.js +57 -0
  73. package/dest/json-rpc/server/index.d.ts +2 -1
  74. package/dest/json-rpc/server/index.d.ts.map +1 -1
  75. package/dest/json-rpc/server/index.js +1 -0
  76. package/dest/log/bigint-utils.d.ts +5 -0
  77. package/dest/log/bigint-utils.d.ts.map +1 -0
  78. package/dest/log/bigint-utils.js +21 -0
  79. package/dest/log/gcloud-logger-config.d.ts +1 -1
  80. package/dest/log/gcloud-logger-config.d.ts.map +1 -1
  81. package/dest/log/gcloud-logger-config.js +3 -0
  82. package/dest/log/pino-logger.d.ts +1 -1
  83. package/dest/log/pino-logger.d.ts.map +1 -1
  84. package/dest/log/pino-logger.js +6 -1
  85. package/dest/queue/batch_queue.d.ts +1 -1
  86. package/dest/queue/batch_queue.d.ts.map +1 -1
  87. package/dest/queue/batch_queue.js +1 -0
  88. package/dest/retry/index.d.ts +12 -1
  89. package/dest/retry/index.d.ts.map +1 -1
  90. package/dest/retry/index.js +21 -0
  91. package/dest/schemas/api.d.ts +2 -2
  92. package/dest/schemas/api.d.ts.map +1 -1
  93. package/dest/serialize/buffer_reader.d.ts +8 -1
  94. package/dest/serialize/buffer_reader.d.ts.map +1 -1
  95. package/dest/serialize/buffer_reader.js +13 -0
  96. package/dest/serialize/serialize.d.ts +19 -1
  97. package/dest/serialize/serialize.d.ts.map +1 -1
  98. package/dest/serialize/serialize.js +31 -0
  99. package/dest/sleep/index.d.ts +2 -1
  100. package/dest/sleep/index.d.ts.map +1 -1
  101. package/dest/sleep/index.js +10 -1
  102. package/dest/timer/date.d.ts +3 -1
  103. package/dest/timer/date.d.ts.map +1 -1
  104. package/dest/timer/date.js +4 -0
  105. package/dest/transport/dispatch/create_dispatch_proxy.d.ts +11 -2
  106. package/dest/transport/dispatch/create_dispatch_proxy.d.ts.map +1 -1
  107. package/dest/transport/index.d.ts +1 -2
  108. package/dest/transport/index.d.ts.map +1 -1
  109. package/dest/transport/index.js +0 -1
  110. package/dest/transport/transport_client.js +2 -2
  111. package/dest/trees/indexed_merkle_tree_calculator.d.ts +1 -1
  112. package/dest/trees/indexed_merkle_tree_calculator.d.ts.map +1 -1
  113. package/dest/trees/indexed_merkle_tree_calculator.js +5 -1
  114. package/package.json +3 -2
  115. package/src/branded-types/slot.ts +5 -0
  116. package/src/buffer/buffer16.ts +3 -0
  117. package/src/buffer/buffer32.ts +3 -0
  118. package/src/buffer/index.ts +1 -0
  119. package/src/buffer/utils.ts +8 -0
  120. package/src/collection/array.ts +14 -0
  121. package/src/collection/index.ts +1 -0
  122. package/src/collection/lru_set.ts +115 -0
  123. package/src/config/env_var.ts +33 -7
  124. package/src/config/index.ts +15 -0
  125. package/src/config/network_config.ts +3 -0
  126. package/src/config/network_name.ts +4 -1
  127. package/src/crypto/aes128/index.ts +11 -2
  128. package/src/crypto/bls/bn254_keystore.ts +0 -23
  129. package/src/crypto/poseidon/index.ts +42 -34
  130. package/src/crypto/secp256k1-signer/utils.ts +32 -0
  131. package/src/curves/bn254/field.ts +6 -2
  132. package/src/curves/grumpkin/point.ts +1 -1
  133. package/src/eth-signature/eth_signature.ts +7 -1
  134. package/src/fifo/fifo_frame_reader.ts +98 -0
  135. package/src/fifo/index.ts +1 -0
  136. package/src/jest/setup.mjs +27 -0
  137. package/src/json-rpc/client/fetch.ts +4 -3
  138. package/src/json-rpc/client/safe_json_rpc_client.ts +2 -0
  139. package/src/json-rpc/client/undici.ts +5 -3
  140. package/src/json-rpc/server/api_key_auth.ts +63 -0
  141. package/src/json-rpc/server/index.ts +1 -0
  142. package/src/log/bigint-utils.ts +25 -0
  143. package/src/log/gcloud-logger-config.ts +5 -0
  144. package/src/log/pino-logger.ts +7 -1
  145. package/src/queue/batch_queue.ts +1 -0
  146. package/src/retry/index.ts +30 -0
  147. package/src/schemas/api.ts +4 -1
  148. package/src/serialize/buffer_reader.ts +15 -0
  149. package/src/serialize/serialize.ts +32 -0
  150. package/src/sleep/index.ts +10 -1
  151. package/src/timer/date.ts +6 -0
  152. package/src/transport/dispatch/create_dispatch_proxy.ts +11 -1
  153. package/src/transport/index.ts +0 -1
  154. package/src/transport/transport_client.ts +2 -2
  155. package/src/trees/indexed_merkle_tree_calculator.ts +5 -1
  156. package/dest/crypto/serialize.d.ts +0 -51
  157. package/dest/crypto/serialize.d.ts.map +0 -1
  158. package/dest/crypto/serialize.js +0 -68
  159. package/dest/transport/dispatch/create_dispatch_fn.d.ts +0 -25
  160. package/dest/transport/dispatch/create_dispatch_fn.d.ts.map +0 -1
  161. package/dest/transport/dispatch/create_dispatch_fn.js +0 -17
  162. package/src/crypto/serialize.ts +0 -85
  163. package/src/transport/dispatch/create_dispatch_fn.ts +0 -35
@@ -12,6 +12,9 @@ export type EnvVar =
12
12
  | 'ARCHIVER_VIEM_POLLING_INTERVAL_MS'
13
13
  | 'ARCHIVER_BATCH_SIZE'
14
14
  | 'AZTEC_ADMIN_PORT'
15
+ | 'AZTEC_ADMIN_API_KEY_HASH'
16
+ | 'AZTEC_DISABLE_ADMIN_API_KEY'
17
+ | 'AZTEC_RESET_ADMIN_API_KEY'
15
18
  | 'AZTEC_NODE_ADMIN_URL'
16
19
  | 'AZTEC_NODE_URL'
17
20
  | 'AZTEC_PORT'
@@ -20,6 +23,8 @@ export type EnvVar =
20
23
  | 'BB_WORKING_DIRECTORY'
21
24
  | 'BB_NUM_IVC_VERIFIERS'
22
25
  | 'BB_IVC_CONCURRENCY'
26
+ | 'BB_CHONK_VERIFY_MAX_BATCH'
27
+ | 'BB_CHONK_VERIFY_BATCH_CONCURRENCY'
23
28
  | 'BOOTSTRAP_NODES'
24
29
  | 'BLOB_ARCHIVE_API_URL'
25
30
  | 'BLOB_FILE_STORE_URLS'
@@ -47,7 +52,10 @@ export type EnvVar =
47
52
  | 'BOT_TX_MINED_WAIT_SECONDS'
48
53
  | 'BOT_MAX_CONSECUTIVE_ERRORS'
49
54
  | 'BOT_STOP_WHEN_UNHEALTHY'
50
- | 'BOT_AMM_TXS'
55
+ | 'BOT_MODE'
56
+ | 'BOT_L2_TO_L1_MESSAGES_PER_TX'
57
+ | 'BOT_L1_TO_L2_SEED_COUNT'
58
+ | 'BOT_L1_TO_L2_SEED_INTERVAL'
51
59
  | 'COINBASE'
52
60
  | 'CRS_PATH'
53
61
  | 'DATA_DIRECTORY'
@@ -56,6 +64,7 @@ export type EnvVar =
56
64
  | 'BLOB_SINK_MAP_SIZE_KB'
57
65
  | 'P2P_STORE_MAP_SIZE_KB'
58
66
  | 'PROVER_BROKER_STORE_MAP_SIZE_KB'
67
+ | 'SIGNING_PROTECTION_MAP_SIZE_KB'
59
68
  | 'WS_DB_MAP_SIZE_KB'
60
69
  | 'ARCHIVE_TREE_MAP_SIZE_KB'
61
70
  | 'NULLIFIER_TREE_MAP_SIZE_KB'
@@ -64,6 +73,7 @@ export type EnvVar =
64
73
  | 'PUBLIC_DATA_TREE_MAP_SIZE_KB'
65
74
  | 'DEBUG'
66
75
  | 'DEBUG_P2P_DISABLE_COLOCATION_PENALTY'
76
+ | 'ENABLE_PROVER_NODE'
67
77
  | 'ETHEREUM_HOSTS'
68
78
  | 'ETHEREUM_DEBUG_HOSTS'
69
79
  | 'ETHEREUM_ALLOW_NO_DEBUG_HOSTS'
@@ -73,8 +83,10 @@ export type EnvVar =
73
83
  | 'KEY_STORE_DIRECTORY'
74
84
  | 'L1_CHAIN_ID'
75
85
  | 'L1_CONSENSUS_HOST_URLS'
86
+ | 'ETHEREUM_HTTP_TIMEOUT_MS'
76
87
  | 'L1_CONSENSUS_HOST_API_KEYS'
77
88
  | 'L1_CONSENSUS_HOST_API_KEY_HEADERS'
89
+ | 'L1_TX_FAILED_STORE'
78
90
  | 'LOG_JSON'
79
91
  | 'LOG_MULTILINE'
80
92
  | 'LOG_NO_COLOR_PER_ACTOR'
@@ -121,6 +133,7 @@ export type EnvVar =
121
133
  | 'P2P_L2_QUEUE_SIZE'
122
134
  | 'P2P_MAX_PEERS'
123
135
  | 'P2P_PEER_CHECK_INTERVAL_MS'
136
+ | 'P2P_PEER_FAILED_BAN_TIME_MS'
124
137
  | 'P2P_PEER_PENALTY_VALUES'
125
138
  | 'P2P_QUERY_FOR_IP'
126
139
  | 'P2P_REQRESP_INDIVIDUAL_REQUEST_TIMEOUT_MS'
@@ -141,10 +154,10 @@ export type EnvVar =
141
154
  | 'P2P_PREFERRED_PEERS'
142
155
  | 'P2P_MAX_PENDING_TX_COUNT'
143
156
  | 'P2P_SEEN_MSG_CACHE_SIZE'
144
- | 'P2P_DROP_TX'
145
157
  | 'P2P_DROP_TX_CHANCE'
146
158
  | 'P2P_TX_POOL_DELETE_TXS_AFTER_REORG'
147
159
  | 'P2P_MIN_TX_POOL_AGE_MS'
160
+ | 'P2P_RPC_PRICE_BUMP_PERCENTAGE'
148
161
  | 'DEBUG_P2P_INSTRUMENT_MESSAGES'
149
162
  | 'PEER_ID_PRIVATE_KEY'
150
163
  | 'PEER_ID_PRIVATE_KEY_PATH'
@@ -160,6 +173,7 @@ export type EnvVar =
160
173
  | 'PROVER_BROKER_MAX_EPOCHS_TO_KEEP_RESULTS_FOR'
161
174
  | 'PROVER_BROKER_DEBUG_REPLAY_ENABLED'
162
175
  | 'PROVER_CANCEL_JOBS_ON_STOP'
176
+ | 'PROVER_ENQUEUE_CONCURRENCY'
163
177
  | 'PROVER_COORDINATION_NODE_URLS'
164
178
  | 'PROVER_PROOF_STORE'
165
179
  | 'PROVER_FAILED_PROOF_STORE'
@@ -193,25 +207,32 @@ export type EnvVar =
193
207
  | 'SENTINEL_ENABLED'
194
208
  | 'SENTINEL_HISTORY_LENGTH_IN_EPOCHS'
195
209
  | 'SENTINEL_HISTORIC_PROVEN_PERFORMANCE_LENGTH_IN_EPOCHS'
196
- | 'SEQ_MAX_BLOCK_SIZE_IN_BYTES'
210
+ | 'SEQ_ENABLE_PROPOSER_PIPELINING'
197
211
  | 'SEQ_MAX_TX_PER_BLOCK'
212
+ | 'SEQ_MAX_TX_PER_CHECKPOINT'
198
213
  | 'SEQ_MIN_TX_PER_BLOCK'
199
214
  | 'SEQ_PUBLISH_TXS_WITH_PROPOSALS'
200
215
  | 'SEQ_MAX_DA_BLOCK_GAS'
201
216
  | 'SEQ_MAX_L2_BLOCK_GAS'
217
+ | 'SEQ_PER_BLOCK_ALLOCATION_MULTIPLIER'
218
+ | 'SEQ_REDISTRIBUTE_CHECKPOINT_BUDGET'
202
219
  | 'SEQ_PUBLISHER_PRIVATE_KEY'
203
220
  | 'SEQ_PUBLISHER_PRIVATE_KEYS'
204
221
  | 'SEQ_PUBLISHER_ADDRESSES'
205
222
  | 'SEQ_PUBLISHER_ALLOW_INVALID_STATES'
206
223
  | 'SEQ_PUBLISHER_FORWARDER_ADDRESS'
224
+ | 'PUBLISHER_FUNDING_THRESHOLD'
225
+ | 'PUBLISHER_FUNDING_AMOUNT'
207
226
  | 'SEQ_POLLING_INTERVAL_MS'
208
227
  | 'SEQ_ENFORCE_TIME_TABLE'
209
228
  | 'SEQ_L1_PUBLISHING_TIME_ALLOWANCE_IN_SLOT'
210
229
  | 'SEQ_ATTESTATION_PROPAGATION_TIME'
211
230
  | 'SEQ_BLOCK_DURATION_MS'
231
+ | 'SEQ_EXPECTED_BLOCK_PROPOSALS_PER_SLOT'
212
232
  | 'SEQ_BUILD_CHECKPOINT_IF_EMPTY'
213
233
  | 'SEQ_SECONDS_BEFORE_INVALIDATING_BLOCK_AS_COMMITTEE_MEMBER'
214
234
  | 'SEQ_SECONDS_BEFORE_INVALIDATING_BLOCK_AS_NON_COMMITTEE_MEMBER'
235
+ | 'SEQ_SKIP_CHECKPOINT_PUBLISH_PERCENT'
215
236
  | 'SLASH_MIN_PENALTY_PERCENTAGE'
216
237
  | 'SLASH_MAX_PENALTY_PERCENTAGE'
217
238
  | 'SLASH_VALIDATORS_ALWAYS'
@@ -238,6 +259,7 @@ export type EnvVar =
238
259
  | 'TELEMETRY'
239
260
  | 'TEST_ACCOUNTS'
240
261
  | 'SPONSORED_FPC'
262
+ | 'PREFUND_ADDRESSES'
241
263
  | 'TX_COLLECTION_FAST_NODES_TIMEOUT_BEFORE_REQ_RESP_MS'
242
264
  | 'TX_COLLECTION_SLOW_NODES_INTERVAL_MS'
243
265
  | 'TX_COLLECTION_SLOW_REQ_RESP_INTERVAL_MS'
@@ -267,15 +289,19 @@ export type EnvVar =
267
289
  | 'TRANSACTIONS_DISABLED'
268
290
  | 'VALIDATOR_ATTESTATIONS_POLLING_INTERVAL_MS'
269
291
  | 'VALIDATOR_DISABLED'
292
+ | 'VALIDATOR_MAX_DA_BLOCK_GAS'
293
+ | 'VALIDATOR_MAX_L2_BLOCK_GAS'
294
+ | 'VALIDATOR_MAX_TX_PER_BLOCK'
295
+ | 'VALIDATOR_MAX_TX_PER_CHECKPOINT'
270
296
  | 'VALIDATOR_PRIVATE_KEYS'
271
297
  | 'VALIDATOR_PRIVATE_KEY'
272
- | 'VALIDATOR_REEXECUTE'
273
298
  | 'VALIDATOR_ADDRESSES'
274
299
  | 'ROLLUP_VERSION'
275
300
  | 'WS_BLOCK_CHECK_INTERVAL_MS'
276
301
  | 'WS_BLOCK_REQUEST_BATCH_SIZE'
277
302
  | 'L1_READER_VIEM_POLLING_INTERVAL_MS'
278
303
  | 'WS_DATA_DIRECTORY'
304
+ | 'WS_NUM_HISTORIC_CHECKPOINTS'
279
305
  | 'WS_NUM_HISTORIC_BLOCKS'
280
306
  | 'ETHEREUM_SLOT_DURATION'
281
307
  | 'AZTEC_SLOT_DURATION'
@@ -330,12 +356,12 @@ export type EnvVar =
330
356
  | 'K8S_POD_NAME'
331
357
  | 'K8S_POD_UID'
332
358
  | 'K8S_NAMESPACE_NAME'
333
- | 'VALIDATOR_REEXECUTE_DEADLINE_MS'
334
- | 'AUTO_UPDATE'
335
- | 'AUTO_UPDATE_URL'
359
+ | 'ENABLE_VERSION_CHECK'
336
360
  | 'WEB3_SIGNER_URL'
337
361
  | 'SKIP_ARCHIVER_INITIAL_SYNC'
338
362
  | 'BLOB_ALLOW_EMPTY_SOURCES'
363
+ | 'BLOB_PREFER_FILESTORES'
364
+ | 'BLOB_FILE_STORE_TIMEOUT_MS'
339
365
  | 'FISHERMAN_MODE'
340
366
  | 'MAX_ALLOWED_ETH_CLIENT_DRIFT_SECONDS'
341
367
  | 'LEGACY_BLS_CLI'
@@ -177,6 +177,21 @@ export function bigintConfigHelper(defaultVal?: bigint): Pick<ConfigMapping, 'pa
177
177
  if (val === '') {
178
178
  return defaultVal;
179
179
  }
180
+ // Handle scientific notation (e.g. "1e+23", "2E23") which BigInt() doesn't accept directly.
181
+ // We parse it losslessly using bigint arithmetic instead of going through float64.
182
+ if (/[eE]/.test(val)) {
183
+ const match = val.match(/^(-?\d+(?:\.(\d+))?)[eE]([+-]?\d+)$/);
184
+ if (!match) {
185
+ throw new Error(`Cannot convert '${val}' to a BigInt`);
186
+ }
187
+ const digits = match[1].replace('.', '');
188
+ const decimalPlaces = match[2]?.length ?? 0;
189
+ const exponent = parseInt(match[3], 10) - decimalPlaces;
190
+ if (exponent < 0) {
191
+ throw new Error(`Cannot convert '${val}' to a BigInt: result is not an integer`);
192
+ }
193
+ return BigInt(digits) * 10n ** BigInt(exponent);
194
+ }
180
195
  return BigInt(val);
181
196
  },
182
197
  defaultValue: defaultVal,
@@ -5,10 +5,13 @@ export const NetworkConfigSchema = z
5
5
  bootnodes: z.array(z.string()),
6
6
  snapshots: z.array(z.string()),
7
7
  blobFileStoreUrls: z.array(z.string()).optional(),
8
+ txCollectionFileStoreUrls: z.array(z.string()).optional(),
8
9
  registryAddress: z.string(),
9
10
  feeAssetHandlerAddress: z.string().optional(),
10
11
  l1ChainId: z.number(),
11
12
  blockDurationMs: z.number().positive().optional(),
13
+ txPublicSetupAllowListExtend: z.string().optional(),
14
+ nodeVersion: z.string().optional(),
12
15
  })
13
16
  .passthrough(); // Allow additional unknown fields to pass through
14
17
 
@@ -5,7 +5,8 @@ export type NetworkNames =
5
5
  | 'testnet'
6
6
  | 'mainnet'
7
7
  | 'next-net'
8
- | 'devnet';
8
+ | 'devnet'
9
+ | `v${number}-devnet-${number}`;
9
10
 
10
11
  export function getActiveNetworkName(name?: string): NetworkNames {
11
12
  const network = name || process.env.NETWORK;
@@ -23,6 +24,8 @@ export function getActiveNetworkName(name?: string): NetworkNames {
23
24
  return 'next-net';
24
25
  } else if (network === 'devnet') {
25
26
  return 'devnet';
27
+ } else if (/^v\d+-devnet-\d+$/.test(network)) {
28
+ return network as `v${number}-devnet-${number}`;
26
29
  }
27
30
  throw new Error(`Unknown network: ${network}`);
28
31
  }
@@ -59,10 +59,19 @@ export class Aes128 {
59
59
  * @param iv - AES initialization vector.
60
60
  * @param key - Key to decrypt with.
61
61
  * @returns Decrypted data.
62
+ * @throws If the decrypted buffer has invalid PKCS#7 padding.
62
63
  */
63
64
  public async decryptBufferCBC(data: Uint8Array, iv: Uint8Array, key: Uint8Array) {
64
65
  const paddedBuffer = await this.decryptBufferCBCKeepPadding(data, iv, key);
65
- const paddingToRemove = paddedBuffer[paddedBuffer.length - 1];
66
- return paddedBuffer.subarray(0, paddedBuffer.length - paddingToRemove);
66
+ const paddingLen = paddedBuffer[paddedBuffer.length - 1];
67
+ if (paddingLen === 0 || paddingLen > 16) {
68
+ throw new Error(`Invalid PKCS#7 padding length: ${paddingLen}`);
69
+ }
70
+ for (let i = paddedBuffer.length - paddingLen; i < paddedBuffer.length; i++) {
71
+ if (paddedBuffer[i] !== paddingLen) {
72
+ throw new Error('Invalid PKCS#7 padding');
73
+ }
74
+ }
75
+ return paddedBuffer.subarray(0, paddedBuffer.length - paddingLen);
67
76
  }
68
77
  }
@@ -262,26 +262,3 @@ export function decryptBn254KeystoreFromObject(keystore: Bn254Keystore, password
262
262
  throw new Bn254KeystoreError(`Failed to decrypt keystore: ${String(error)}`, error as Error);
263
263
  }
264
264
  }
265
-
266
- /**
267
- * Validates that a decrypted private key matches the public key in the keystore.
268
- *
269
- * @param privateKeyHex - Decrypted private key (0x-prefixed)
270
- * @param expectedPubkey - Expected public key from keystore
271
- * @param computePublicKey - Function to compute public key from private key
272
- * @returns true if keys match, false otherwise
273
- */
274
- export function verifyBn254Keypair(
275
- privateKeyHex: string,
276
- expectedPubkey: string,
277
- computePublicKey: (privateKey: string) => string,
278
- ): boolean {
279
- try {
280
- const computedPubkey = computePublicKey(privateKeyHex);
281
- const normalizedExpected = expectedPubkey.toLowerCase().replace(/^0x/i, '');
282
- const normalizedComputed = computedPubkey.toLowerCase().replace(/^0x/i, '');
283
- return normalizedExpected === normalizedComputed;
284
- } catch {
285
- return false;
286
- }
287
- }
@@ -1,21 +1,35 @@
1
- import { BarretenbergSync } from '@aztec/bb.js';
1
+ import { Barretenberg, BarretenbergSync } from '@aztec/bb.js';
2
2
 
3
3
  import { Fr } from '../../curves/bn254/field.js';
4
4
  import { type Fieldable, serializeToFields } from '../../serialize/serialize.js';
5
5
 
6
+ const IS_BROWSER = typeof self !== 'undefined';
7
+
8
+ async function poseidon2HashFields(inputFields: Fr[]): Promise<Fr> {
9
+ if (IS_BROWSER) {
10
+ await BarretenbergSync.initSingleton();
11
+ const api = BarretenbergSync.getSingleton();
12
+ const response = api.poseidon2Hash({
13
+ inputs: inputFields.map(i => i.toBuffer()),
14
+ });
15
+ return Fr.fromBuffer(Buffer.from(response.hash));
16
+ } else {
17
+ await Barretenberg.initSingleton();
18
+ const api = Barretenberg.getSingleton();
19
+ const response = await api.poseidon2Hash({
20
+ inputs: inputFields.map(i => i.toBuffer()),
21
+ });
22
+ return Fr.fromBuffer(Buffer.from(response.hash));
23
+ }
24
+ }
25
+
6
26
  /**
7
27
  * Create a poseidon hash (field) from an array of input fields.
8
28
  * @param input - The input fields to hash.
9
29
  * @returns The poseidon hash.
10
30
  */
11
- export async function poseidon2Hash(input: Fieldable[]): Promise<Fr> {
12
- const inputFields = serializeToFields(input);
13
- await BarretenbergSync.initSingleton();
14
- const api = BarretenbergSync.getSingleton();
15
- const response = api.poseidon2Hash({
16
- inputs: inputFields.map(i => i.toBuffer()),
17
- });
18
- return Fr.fromBuffer(Buffer.from(response.hash));
31
+ export function poseidon2Hash(input: Fieldable[]): Promise<Fr> {
32
+ return poseidon2HashFields(serializeToFields(input));
19
33
  }
20
34
 
21
35
  /**
@@ -24,15 +38,10 @@ export async function poseidon2Hash(input: Fieldable[]): Promise<Fr> {
24
38
  * @param separator - The domain separator.
25
39
  * @returns The poseidon hash.
26
40
  */
27
- export async function poseidon2HashWithSeparator(input: Fieldable[], separator: number): Promise<Fr> {
41
+ export function poseidon2HashWithSeparator(input: Fieldable[], separator: number): Promise<Fr> {
28
42
  const inputFields = serializeToFields(input);
29
43
  inputFields.unshift(new Fr(separator));
30
- await BarretenbergSync.initSingleton();
31
- const api = BarretenbergSync.getSingleton();
32
- const response = api.poseidon2Hash({
33
- inputs: inputFields.map(i => i.toBuffer()),
34
- });
35
- return Fr.fromBuffer(Buffer.from(response.hash));
44
+ return poseidon2HashFields(inputFields);
36
45
  }
37
46
 
38
47
  /**
@@ -42,19 +51,24 @@ export async function poseidon2HashWithSeparator(input: Fieldable[], separator:
42
51
  */
43
52
  export async function poseidon2Permutation(input: Fieldable[]): Promise<Fr[]> {
44
53
  const inputFields = serializeToFields(input);
45
- // We'd like this assertion but it's not possible to use it in the browser.
46
- // assert(input.length === 4, 'Input state must be of size 4');
47
- await BarretenbergSync.initSingleton();
48
- const api = BarretenbergSync.getSingleton();
49
- const response = api.poseidon2Permutation({
50
- inputs: inputFields.map(i => i.toBuffer()),
51
- });
52
- // We'd like this assertion but it's not possible to use it in the browser.
53
- // assert(response.outputs.length === 4, 'Output state must be of size 4');
54
- return response.outputs.map(o => Fr.fromBuffer(Buffer.from(o)));
54
+ if (IS_BROWSER) {
55
+ await BarretenbergSync.initSingleton();
56
+ const api = BarretenbergSync.getSingleton();
57
+ const response = api.poseidon2Permutation({
58
+ inputs: inputFields.map(i => i.toBuffer()),
59
+ });
60
+ return response.outputs.map(o => Fr.fromBuffer(Buffer.from(o)));
61
+ } else {
62
+ await Barretenberg.initSingleton();
63
+ const api = Barretenberg.getSingleton();
64
+ const response = await api.poseidon2Permutation({
65
+ inputs: inputFields.map(i => i.toBuffer()),
66
+ });
67
+ return response.outputs.map(o => Fr.fromBuffer(Buffer.from(o)));
68
+ }
55
69
  }
56
70
 
57
- export async function poseidon2HashBytes(input: Buffer): Promise<Fr> {
71
+ export function poseidon2HashBytes(input: Buffer): Promise<Fr> {
58
72
  const inputFields = [];
59
73
  for (let i = 0; i < input.length; i += 31) {
60
74
  const fieldBytes = Buffer.alloc(32, 0);
@@ -65,11 +79,5 @@ export async function poseidon2HashBytes(input: Buffer): Promise<Fr> {
65
79
  inputFields.push(Fr.fromBuffer(fieldBytes));
66
80
  }
67
81
 
68
- await BarretenbergSync.initSingleton();
69
- const api = BarretenbergSync.getSingleton();
70
- const response = api.poseidon2Hash({
71
- inputs: inputFields.map(i => i.toBuffer()),
72
- });
73
-
74
- return Fr.fromBuffer(Buffer.from(response.hash));
82
+ return poseidon2HashFields(inputFields);
75
83
  }
@@ -210,3 +210,35 @@ export function recoverPublicKey(hash: Buffer32, signature: Signature, opts: Rec
210
210
  const publicKey = sig.recoverPublicKey(hash.buffer).toHex(false);
211
211
  return Buffer.from(publicKey, 'hex');
212
212
  }
213
+
214
+ /** Arbitrary hash used for testing signature recoverability. */
215
+ const PROBE_HASH = Buffer32.fromBuffer(keccak256(Buffer.from('signature-recoverability-probe')));
216
+
217
+ /**
218
+ * Generates a random valid ECDSA signature that is recoverable to some address.
219
+ * Since Signature.random() produces real signatures via secp256k1 signing, the result is always
220
+ * recoverable, but we verify defensively by checking tryRecoverAddress.
221
+ */
222
+ export function generateRecoverableSignature(): Signature {
223
+ for (let i = 0; i < 100; i++) {
224
+ const sig = Signature.random();
225
+ if (tryRecoverAddress(PROBE_HASH, sig) !== undefined) {
226
+ return sig;
227
+ }
228
+ }
229
+ throw new Secp256k1Error('Failed to generate a recoverable signature after 100 attempts');
230
+ }
231
+
232
+ /**
233
+ * Generates a random signature where ECDSA address recovery fails.
234
+ * Uses random r/s values (not from real signing) so that r is unlikely to be a valid secp256k1 x-coordinate.
235
+ */
236
+ export function generateUnrecoverableSignature(): Signature {
237
+ for (let i = 0; i < 100; i++) {
238
+ const sig = new Signature(Buffer32.random(), Buffer32.random(), 27);
239
+ if (tryRecoverAddress(PROBE_HASH, sig) === undefined) {
240
+ return sig;
241
+ }
242
+ }
243
+ throw new Secp256k1Error('Failed to generate an unrecoverable signature after 100 attempts');
244
+ }
@@ -118,14 +118,18 @@ abstract class BaseField {
118
118
  }
119
119
 
120
120
  cmp(rhs: BaseField): -1 | 0 | 1 {
121
- const rhsBigInt = rhs.asBigInt;
122
- return this.asBigInt === rhsBigInt ? 0 : this.asBigInt < rhsBigInt ? -1 : 1;
121
+ return BaseField.cmpAsBigInt(this.asBigInt, rhs.asBigInt);
123
122
  }
124
123
 
125
124
  static cmp(lhs: BaseField, rhs: BaseField): -1 | 0 | 1 {
126
125
  return lhs.cmp(rhs);
127
126
  }
128
127
 
128
+ // Actual bigint comparison. Arguments must have been validated previously.
129
+ static cmpAsBigInt(lhs: bigint, rhs: bigint): -1 | 0 | 1 {
130
+ return lhs === rhs ? 0 : lhs < rhs ? -1 : 1;
131
+ }
132
+
129
133
  isZero(): boolean {
130
134
  return this.asBigInt === 0n;
131
135
  }
@@ -65,7 +65,7 @@ export class Point {
65
65
  }
66
66
 
67
67
  /**
68
- * Generate a random Point instance.
68
+ * Generate a random Point instance that is on the curve.
69
69
  *
70
70
  * @returns A randomly generated Point instance.
71
71
  */
@@ -1,8 +1,10 @@
1
1
  import { Buffer32 } from '@aztec/foundation/buffer';
2
2
  import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
3
3
 
4
+ import { secp256k1 } from '@noble/curves/secp256k1';
4
5
  import { z } from 'zod';
5
6
 
7
+ import { randomBytes } from '../crypto/random/index.js';
6
8
  import { hasHexPrefix, hexToBuffer } from '../string/index.js';
7
9
 
8
10
  /**
@@ -77,8 +79,12 @@ export class Signature {
77
79
  return new Signature(Buffer32.fromBuffer(hexToBuffer(sig.r)), Buffer32.fromBuffer(hexToBuffer(sig.s)), sig.yParity);
78
80
  }
79
81
 
82
+ /** Generates a random valid ECDSA signature with a low s-value by signing a random message with a random key. */
80
83
  static random(): Signature {
81
- return new Signature(Buffer32.random(), Buffer32.random(), 1);
84
+ const privateKey = randomBytes(32);
85
+ const message = randomBytes(32);
86
+ const { r, s, recovery } = secp256k1.sign(message, privateKey);
87
+ return new Signature(Buffer32.fromBigInt(r), Buffer32.fromBigInt(s), recovery ? 28 : 27);
82
88
  }
83
89
 
84
90
  static empty(): Signature {
@@ -0,0 +1,98 @@
1
+ import EventEmitter from 'node:events';
2
+ import * as fs from 'node:fs';
3
+ import type { Readable } from 'node:stream';
4
+
5
+ /**
6
+ * Events emitted by FifoFrameReader.
7
+ *
8
+ * - `frame`: A complete frame payload (without the 4-byte length header).
9
+ * - `error`: An unrecoverable error (invalid frame length, stream error).
10
+ * - `end`: The underlying stream has ended.
11
+ */
12
+ export interface FifoFrameReaderEvents {
13
+ frame: [payload: Buffer];
14
+ error: [error: Error];
15
+ end: [];
16
+ }
17
+
18
+ /**
19
+ * Reads length-delimited frames from a readable stream (typically a named FIFO pipe).
20
+ *
21
+ * Wire format: `[4-byte big-endian payload length][payload bytes]`
22
+ *
23
+ * Emits a `frame` event for each complete frame with the raw payload buffer.
24
+ * Callers are responsible for deserializing the payload (e.g., via msgpack).
25
+ *
26
+ * On encountering an invalid payload length (0 or >maxPayloadSize), emits `error`
27
+ * and destroys the stream.
28
+ */
29
+ export class FifoFrameReader extends EventEmitter<FifoFrameReaderEvents> {
30
+ private stream: Readable | null = null;
31
+ private pendingBuf: Buffer = Buffer.alloc(0);
32
+ private running = false;
33
+
34
+ constructor(private readonly maxPayloadSize = 10 * 1024 * 1024) {
35
+ super();
36
+ }
37
+
38
+ /** Open a FIFO at the given path and start reading frames. */
39
+ start(fifoPath: string, highWaterMark = 64 * 1024): void {
40
+ this.startFromStream(fs.createReadStream(fifoPath, { highWaterMark }));
41
+ }
42
+
43
+ /** Start reading frames from an existing readable stream. */
44
+ startFromStream(stream: Readable): void {
45
+ if (this.running) {
46
+ throw new Error('FifoFrameReader is already running');
47
+ }
48
+ this.running = true;
49
+ this.pendingBuf = Buffer.alloc(0);
50
+ this.stream = stream;
51
+
52
+ stream.on('data', (chunk: Buffer | string) => {
53
+ const buf = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
54
+ this.pendingBuf = this.pendingBuf.length > 0 ? Buffer.concat([this.pendingBuf, buf]) : buf;
55
+ this.drainFrames();
56
+ });
57
+
58
+ stream.on('error', (err: Error) => {
59
+ if (this.running) {
60
+ this.emit('error', err);
61
+ }
62
+ });
63
+
64
+ stream.on('end', () => {
65
+ this.emit('end');
66
+ });
67
+ }
68
+
69
+ /** Stop reading and destroy the underlying stream. */
70
+ stop(): void {
71
+ this.running = false;
72
+ if (this.stream) {
73
+ this.stream.destroy();
74
+ this.stream = null;
75
+ }
76
+ }
77
+
78
+ /** Parse complete frames out of the pending buffer. */
79
+ private drainFrames(): void {
80
+ while (this.pendingBuf.length >= 4) {
81
+ const payloadLen = this.pendingBuf.readUInt32BE(0);
82
+ if (payloadLen === 0 || payloadLen > this.maxPayloadSize) {
83
+ this.emit('error', new Error(`Invalid payload length: ${payloadLen}`));
84
+ this.stop();
85
+ return;
86
+ }
87
+
88
+ const frameLen = 4 + payloadLen;
89
+ if (this.pendingBuf.length < frameLen) {
90
+ break; // Wait for more data
91
+ }
92
+
93
+ const payload = this.pendingBuf.subarray(4, frameLen);
94
+ this.pendingBuf = this.pendingBuf.subarray(frameLen);
95
+ this.emit('frame', Buffer.from(payload));
96
+ }
97
+ }
98
+ }
@@ -0,0 +1 @@
1
+ export { FifoFrameReader } from './fifo_frame_reader.js';
@@ -10,3 +10,30 @@ import pretty from 'pino-pretty';
10
10
  if (!parseBooleanEnv(process.env.LOG_JSON)) {
11
11
  overwriteLoggingStream(pretty(pinoPrettyOpts));
12
12
  }
13
+
14
+ // Prevent timers from keeping the process alive after tests complete.
15
+ // Libraries like viem create internal polling loops (via setTimeout) that
16
+ // reschedule themselves indefinitely. In test environments we never want a
17
+ // timer to be the reason the process can't exit. We also unref stdout/stderr
18
+ // which, when they are pipes (as in Jest workers), remain ref'd by default.
19
+ {
20
+ const origSetTimeout = globalThis.setTimeout;
21
+ const origSetInterval = globalThis.setInterval;
22
+ globalThis.setTimeout = function unrefSetTimeout(...args) {
23
+ const id = origSetTimeout.apply(this, args);
24
+ id?.unref?.();
25
+ return id;
26
+ };
27
+ // Preserve .unref, .__promisify__ etc. that may exist on the original
28
+ Object.setPrototypeOf(globalThis.setTimeout, origSetTimeout);
29
+
30
+ globalThis.setInterval = function unrefSetInterval(...args) {
31
+ const id = origSetInterval.apply(this, args);
32
+ id?.unref?.();
33
+ return id;
34
+ };
35
+ Object.setPrototypeOf(globalThis.setInterval, origSetInterval);
36
+
37
+ if (process.stdout?._handle?.unref) process.stdout._handle.unref();
38
+ if (process.stderr?._handle?.unref) process.stderr._handle.unref();
39
+ }
@@ -43,17 +43,18 @@ export async function defaultFetch(
43
43
  }
44
44
 
45
45
  let responseJson;
46
+ const responseText = await resp.text();
46
47
  try {
47
- responseJson = await resp.json();
48
+ responseJson = JSON.parse(responseText);
48
49
  } catch {
49
50
  if (!resp.ok) {
50
51
  throw new Error(resp.statusText);
51
52
  }
52
- throw new Error(`Failed to parse body as JSON: ${await resp.text()}`);
53
+ throw new Error(`Failed to parse body as JSON: ${responseText}`);
53
54
  }
54
55
 
55
56
  if (!resp.ok) {
56
- const errorMessage = `Error ${resp.status} from server ${host}: ${responseJson.error.message}`;
57
+ const errorMessage = `Error ${resp.status} from server ${host}: ${responseJson?.error?.message ?? JSON.stringify(responseJson)}`;
57
58
  if (noRetry || (resp.status >= 400 && resp.status < 500)) {
58
59
  throw new NoRetryError(errorMessage);
59
60
  } else {
@@ -24,6 +24,7 @@ export type SafeJsonRpcClientOptions = {
24
24
  batchWindowMS?: number;
25
25
  maxBatchSize?: number;
26
26
  maxRequestBodySize?: number;
27
+ extraHeaders?: Record<string, string>;
27
28
  onResponse?: (res: {
28
29
  response: any;
29
30
  headers: { get: (header: string) => string | null | undefined };
@@ -129,6 +130,7 @@ export function createSafeJsonRpcClient<T extends object>(
129
130
  const { response, headers } = await fetch(
130
131
  host,
131
132
  rpcCalls.map(({ request }) => request),
133
+ config.extraHeaders,
132
134
  );
133
135
 
134
136
  if (config.onResponse) {
@@ -44,18 +44,20 @@ export function makeUndiciFetch(client = new Agent()): JsonRpcFetch {
44
44
  let responseJson: any;
45
45
  const responseOk = resp.statusCode >= 200 && resp.statusCode <= 299;
46
46
  const contentEncoding = resp.headers['content-encoding'];
47
+ let responseText: string;
47
48
  try {
48
49
  if (contentEncoding === 'gzip') {
49
50
  const jsonBuffer = await gunzip(await resp.body.arrayBuffer());
50
- responseJson = JSON.parse(jsonBuffer.toString('utf-8'));
51
+ responseText = jsonBuffer.toString('utf-8');
51
52
  } else {
52
- responseJson = await resp.body.json();
53
+ responseText = await resp.body.text();
53
54
  }
55
+ responseJson = JSON.parse(responseText);
54
56
  } catch {
55
57
  if (!responseOk) {
56
58
  throw new Error('HTTP ' + resp.statusCode);
57
59
  }
58
- throw new Error(`Failed to parse body as JSON. encoding: ${contentEncoding}, body: ${await resp.body.text()}`);
60
+ throw new Error(`Failed to parse body as JSON. encoding: ${contentEncoding}, body: ${responseText!}`);
59
61
  }
60
62
 
61
63
  if (!responseOk) {