@aztec/foundation 0.0.1-commit.993d52e → 0.0.1-commit.9a89641

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 (292) hide show
  1. package/dest/bigint-buffer/index.d.ts +1 -1
  2. package/dest/bigint-buffer/index.d.ts.map +1 -1
  3. package/dest/bigint-buffer/index.js +6 -1
  4. package/dest/branded-types/block_number.d.ts +3 -3
  5. package/dest/branded-types/block_number.d.ts.map +1 -1
  6. package/dest/branded-types/block_number.js +15 -4
  7. package/dest/branded-types/buffer32_hash.d.ts +27 -0
  8. package/dest/branded-types/buffer32_hash.d.ts.map +1 -0
  9. package/dest/branded-types/buffer32_hash.js +12 -0
  10. package/dest/branded-types/checkpoint_number.d.ts +9 -3
  11. package/dest/branded-types/checkpoint_number.d.ts.map +1 -1
  12. package/dest/branded-types/checkpoint_number.js +11 -0
  13. package/dest/branded-types/epoch.d.ts +2 -2
  14. package/dest/branded-types/epoch.d.ts.map +1 -1
  15. package/dest/branded-types/index.d.ts +2 -1
  16. package/dest/branded-types/index.d.ts.map +1 -1
  17. package/dest/branded-types/index.js +1 -0
  18. package/dest/branded-types/index_within_checkpoint.d.ts +2 -2
  19. package/dest/branded-types/index_within_checkpoint.d.ts.map +1 -1
  20. package/dest/branded-types/slot.d.ts +5 -2
  21. package/dest/branded-types/slot.d.ts.map +1 -1
  22. package/dest/branded-types/slot.js +3 -0
  23. package/dest/buffer/buffer16.d.ts +3 -1
  24. package/dest/buffer/buffer16.d.ts.map +1 -1
  25. package/dest/buffer/buffer32.d.ts +28 -61
  26. package/dest/buffer/buffer32.d.ts.map +1 -1
  27. package/dest/buffer/buffer32.js +29 -63
  28. package/dest/buffer/index.d.ts +2 -1
  29. package/dest/buffer/index.d.ts.map +1 -1
  30. package/dest/buffer/index.js +1 -0
  31. package/dest/buffer/utils.d.ts +3 -0
  32. package/dest/buffer/utils.d.ts.map +1 -0
  33. package/dest/buffer/utils.js +7 -0
  34. package/dest/collection/array.d.ts +11 -1
  35. package/dest/collection/array.d.ts.map +1 -1
  36. package/dest/collection/array.js +33 -0
  37. package/dest/collection/index.d.ts +3 -1
  38. package/dest/collection/index.d.ts.map +1 -1
  39. package/dest/collection/index.js +2 -0
  40. package/dest/collection/lru_map.d.ts +41 -0
  41. package/dest/collection/lru_map.d.ts.map +1 -0
  42. package/dest/collection/lru_map.js +119 -0
  43. package/dest/collection/lru_set.d.ts +35 -0
  44. package/dest/collection/lru_set.d.ts.map +1 -0
  45. package/dest/collection/lru_set.js +95 -0
  46. package/dest/committable/committable.js +1 -1
  47. package/dest/config/env_var.d.ts +2 -2
  48. package/dest/config/env_var.d.ts.map +1 -1
  49. package/dest/config/index.d.ts +67 -37
  50. package/dest/config/index.d.ts.map +1 -1
  51. package/dest/config/index.js +72 -71
  52. package/dest/config/network_config.d.ts +13 -45
  53. package/dest/config/network_config.d.ts.map +1 -1
  54. package/dest/config/network_config.js +2 -0
  55. package/dest/config/network_name.d.ts +2 -2
  56. package/dest/config/network_name.d.ts.map +1 -1
  57. package/dest/config/network_name.js +3 -3
  58. package/dest/config/secret_value.d.ts +2 -2
  59. package/dest/config/secret_value.d.ts.map +1 -1
  60. package/dest/crypto/aes128/index.d.ts +2 -1
  61. package/dest/crypto/aes128/index.d.ts.map +1 -1
  62. package/dest/crypto/aes128/index.js +11 -2
  63. package/dest/crypto/bls/bn254_keystore.d.ts +10 -177
  64. package/dest/crypto/bls/bn254_keystore.d.ts.map +1 -1
  65. package/dest/crypto/bls/bn254_keystore.js +22 -34
  66. package/dest/crypto/keys/index.d.ts +3 -2
  67. package/dest/crypto/keys/index.d.ts.map +1 -1
  68. package/dest/crypto/keys/index.js +30 -6
  69. package/dest/crypto/poseidon/index.d.ts +1 -1
  70. package/dest/crypto/poseidon/index.d.ts.map +1 -1
  71. package/dest/crypto/poseidon/index.js +40 -33
  72. package/dest/crypto/schnorr/index.d.ts +8 -7
  73. package/dest/crypto/schnorr/index.d.ts.map +1 -1
  74. package/dest/crypto/schnorr/index.js +6 -6
  75. package/dest/crypto/schnorr/signature.d.ts +9 -29
  76. package/dest/crypto/schnorr/signature.d.ts.map +1 -1
  77. package/dest/crypto/schnorr/signature.js +20 -36
  78. package/dest/curves/bls12/field.d.ts +3 -3
  79. package/dest/curves/bls12/field.d.ts.map +1 -1
  80. package/dest/curves/bls12/field.js +0 -5
  81. package/dest/curves/bls12/point.d.ts +2 -2
  82. package/dest/curves/bls12/point.d.ts.map +1 -1
  83. package/dest/curves/bn254/field.d.ts +23 -19
  84. package/dest/curves/bn254/field.d.ts.map +1 -1
  85. package/dest/curves/bn254/field.js +23 -17
  86. package/dest/curves/grumpkin/point.d.ts +14 -28
  87. package/dest/curves/grumpkin/point.d.ts.map +1 -1
  88. package/dest/curves/grumpkin/point.js +29 -43
  89. package/dest/eth-address/index.d.ts +2 -2
  90. package/dest/eth-address/index.d.ts.map +1 -1
  91. package/dest/eth-address/index.js +0 -3
  92. package/dest/eth-signature/eth_signature.d.ts +2 -2
  93. package/dest/eth-signature/eth_signature.d.ts.map +1 -1
  94. package/dest/fifo/fifo_frame_reader.d.ts +41 -0
  95. package/dest/fifo/fifo_frame_reader.d.ts.map +1 -0
  96. package/dest/fifo/fifo_frame_reader.js +91 -0
  97. package/dest/fifo/index.d.ts +2 -0
  98. package/dest/fifo/index.d.ts.map +1 -0
  99. package/dest/fifo/index.js +1 -0
  100. package/dest/fifo_set/fifo_set.d.ts +15 -0
  101. package/dest/fifo_set/fifo_set.d.ts.map +1 -0
  102. package/dest/fifo_set/fifo_set.js +39 -0
  103. package/dest/fifo_set/index.d.ts +2 -0
  104. package/dest/fifo_set/index.d.ts.map +1 -0
  105. package/dest/fifo_set/index.js +1 -0
  106. package/dest/jest/setup.js +24 -0
  107. package/dest/json-rpc/client/fetch.d.ts +1 -1
  108. package/dest/json-rpc/client/fetch.d.ts.map +1 -1
  109. package/dest/json-rpc/client/fetch.js +4 -3
  110. package/dest/json-rpc/client/safe_json_rpc_client.d.ts +1 -1
  111. package/dest/json-rpc/client/safe_json_rpc_client.d.ts.map +1 -1
  112. package/dest/json-rpc/client/safe_json_rpc_client.js +5 -4
  113. package/dest/json-rpc/client/undici.d.ts +1 -1
  114. package/dest/json-rpc/client/undici.d.ts.map +1 -1
  115. package/dest/json-rpc/client/undici.js +5 -3
  116. package/dest/json-rpc/fixtures/test_state.d.ts +4 -8
  117. package/dest/json-rpc/fixtures/test_state.d.ts.map +1 -1
  118. package/dest/json-rpc/fixtures/test_state.js +57 -17
  119. package/dest/json-rpc/server/safe_json_rpc_server.d.ts +8 -3
  120. package/dest/json-rpc/server/safe_json_rpc_server.d.ts.map +1 -1
  121. package/dest/json-rpc/server/safe_json_rpc_server.js +32 -14
  122. package/dest/log/aws-logger-config.d.ts +8 -0
  123. package/dest/log/aws-logger-config.d.ts.map +1 -0
  124. package/dest/log/aws-logger-config.js +55 -0
  125. package/dest/log/pino-logger.d.ts +1 -1
  126. package/dest/log/pino-logger.d.ts.map +1 -1
  127. package/dest/log/pino-logger.js +29 -8
  128. package/dest/noir/noir_package_config.d.ts +19 -104
  129. package/dest/noir/noir_package_config.d.ts.map +1 -1
  130. package/dest/noir/noir_package_config.js +1 -1
  131. package/dest/promise/running-promise.d.ts +5 -4
  132. package/dest/promise/running-promise.d.ts.map +1 -1
  133. package/dest/promise/running-promise.js +7 -3
  134. package/dest/queue/batch_queue.d.ts +1 -1
  135. package/dest/queue/batch_queue.d.ts.map +1 -1
  136. package/dest/queue/batch_queue.js +1 -0
  137. package/dest/retry/index.d.ts +31 -3
  138. package/dest/retry/index.d.ts.map +1 -1
  139. package/dest/retry/index.js +44 -2
  140. package/dest/schemas/api.d.ts +12 -10
  141. package/dest/schemas/api.d.ts.map +1 -1
  142. package/dest/schemas/api.js +7 -1
  143. package/dest/schemas/parse.d.ts +4 -4
  144. package/dest/schemas/parse.d.ts.map +1 -1
  145. package/dest/schemas/parse.js +6 -5
  146. package/dest/schemas/schemas.d.ts +15 -15
  147. package/dest/schemas/types.d.ts +3 -3
  148. package/dest/schemas/types.d.ts.map +1 -1
  149. package/dest/schemas/utils.d.ts +7 -11
  150. package/dest/schemas/utils.d.ts.map +1 -1
  151. package/dest/schemas/utils.js +2 -18
  152. package/dest/serialize/buffer_reader.d.ts +1 -1
  153. package/dest/serialize/buffer_reader.d.ts.map +1 -1
  154. package/dest/serialize/buffer_reader.js +5 -0
  155. package/dest/serialize/buffer_sink.d.ts +134 -0
  156. package/dest/serialize/buffer_sink.d.ts.map +1 -0
  157. package/dest/serialize/buffer_sink.js +297 -0
  158. package/dest/serialize/index.d.ts +2 -1
  159. package/dest/serialize/index.d.ts.map +1 -1
  160. package/dest/serialize/index.js +1 -0
  161. package/dest/serialize/serialize.d.ts +1 -32
  162. package/dest/serialize/serialize.d.ts.map +1 -1
  163. package/dest/serialize/serialize.js +0 -21
  164. package/dest/sleep/index.d.ts +2 -1
  165. package/dest/sleep/index.d.ts.map +1 -1
  166. package/dest/sleep/index.js +10 -1
  167. package/dest/string/index.d.ts +3 -1
  168. package/dest/string/index.d.ts.map +1 -1
  169. package/dest/string/index.js +13 -1
  170. package/dest/testing/files/index.d.ts +3 -4
  171. package/dest/testing/files/index.d.ts.map +1 -1
  172. package/dest/testing/files/index.js +3 -4
  173. package/dest/timer/date.d.ts +3 -1
  174. package/dest/timer/date.d.ts.map +1 -1
  175. package/dest/timer/date.js +4 -0
  176. package/dest/timer/index.d.ts +2 -2
  177. package/dest/timer/index.d.ts.map +1 -1
  178. package/dest/timer/index.js +1 -1
  179. package/dest/timer/timeout.d.ts +3 -1
  180. package/dest/timer/timeout.d.ts.map +1 -1
  181. package/dest/timer/timeout.js +26 -0
  182. package/dest/transport/dispatch/create_dispatch_proxy.d.ts +11 -2
  183. package/dest/transport/dispatch/create_dispatch_proxy.d.ts.map +1 -1
  184. package/dest/transport/index.d.ts +1 -2
  185. package/dest/transport/index.d.ts.map +1 -1
  186. package/dest/transport/index.js +0 -1
  187. package/dest/trees/balanced_merkle_tree_root.d.ts +2 -3
  188. package/dest/trees/balanced_merkle_tree_root.d.ts.map +1 -1
  189. package/dest/trees/balanced_merkle_tree_root.js +2 -3
  190. package/dest/trees/hasher.d.ts +3 -2
  191. package/dest/trees/hasher.d.ts.map +1 -1
  192. package/dest/trees/hasher.js +5 -5
  193. package/dest/trees/indexed_merkle_tree_calculator.d.ts +1 -1
  194. package/dest/trees/indexed_merkle_tree_calculator.d.ts.map +1 -1
  195. package/dest/trees/indexed_merkle_tree_calculator.js +5 -1
  196. package/dest/trees/membership_witness.d.ts +2 -6
  197. package/dest/trees/membership_witness.d.ts.map +1 -1
  198. package/dest/trees/membership_witness.js +0 -9
  199. package/dest/trees/merkle_tree_calculator.d.ts +4 -2
  200. package/dest/trees/merkle_tree_calculator.d.ts.map +1 -1
  201. package/dest/trees/merkle_tree_calculator.js +1 -5
  202. package/dest/trees/sibling_path.d.ts +13 -14
  203. package/dest/trees/sibling_path.d.ts.map +1 -1
  204. package/dest/trees/sibling_path.js +23 -28
  205. package/dest/trees/unbalanced_merkle_tree_root.d.ts +2 -3
  206. package/dest/trees/unbalanced_merkle_tree_root.d.ts.map +1 -1
  207. package/dest/trees/unbalanced_merkle_tree_root.js +2 -3
  208. package/dest/types/index.d.ts +23 -1
  209. package/dest/types/index.d.ts.map +1 -1
  210. package/dest/types/index.js +15 -0
  211. package/package.json +6 -4
  212. package/src/bigint-buffer/index.ts +6 -1
  213. package/src/branded-types/block_number.ts +20 -2
  214. package/src/branded-types/buffer32_hash.ts +38 -0
  215. package/src/branded-types/checkpoint_number.ts +16 -1
  216. package/src/branded-types/epoch.ts +1 -1
  217. package/src/branded-types/index.ts +1 -0
  218. package/src/branded-types/index_within_checkpoint.ts +1 -1
  219. package/src/branded-types/slot.ts +6 -1
  220. package/src/buffer/buffer16.ts +3 -0
  221. package/src/buffer/buffer32.ts +39 -68
  222. package/src/buffer/index.ts +1 -0
  223. package/src/buffer/utils.ts +8 -0
  224. package/src/collection/array.ts +34 -0
  225. package/src/collection/index.ts +2 -0
  226. package/src/collection/lru_map.ts +143 -0
  227. package/src/collection/lru_set.ts +115 -0
  228. package/src/committable/committable.ts +1 -1
  229. package/src/config/env_var.ts +63 -25
  230. package/src/config/index.ts +143 -122
  231. package/src/config/network_config.ts +2 -0
  232. package/src/config/network_name.ts +6 -6
  233. package/src/config/secret_value.ts +1 -1
  234. package/src/crypto/aes128/index.ts +11 -2
  235. package/src/crypto/bls/bn254_keystore.ts +33 -43
  236. package/src/crypto/keys/index.ts +20 -4
  237. package/src/crypto/poseidon/index.ts +42 -34
  238. package/src/crypto/schnorr/index.ts +9 -8
  239. package/src/crypto/schnorr/signature.ts +17 -46
  240. package/src/curves/bls12/field.ts +0 -7
  241. package/src/curves/bn254/field.ts +35 -34
  242. package/src/curves/grumpkin/point.ts +23 -40
  243. package/src/eth-address/index.ts +0 -4
  244. package/src/fifo/fifo_frame_reader.ts +113 -0
  245. package/src/fifo/index.ts +1 -0
  246. package/src/fifo_set/fifo_set.ts +52 -0
  247. package/src/fifo_set/index.ts +1 -0
  248. package/src/jest/setup.mjs +27 -0
  249. package/src/json-rpc/client/fetch.ts +4 -3
  250. package/src/json-rpc/client/safe_json_rpc_client.ts +5 -4
  251. package/src/json-rpc/client/undici.ts +5 -3
  252. package/src/json-rpc/fixtures/test_state.ts +10 -10
  253. package/src/json-rpc/server/safe_json_rpc_server.ts +36 -14
  254. package/src/log/aws-logger-config.ts +32 -0
  255. package/src/log/pino-logger.ts +33 -6
  256. package/src/noir/noir_package_config.ts +32 -20
  257. package/src/promise/running-promise.ts +8 -5
  258. package/src/queue/batch_queue.ts +1 -0
  259. package/src/retry/index.ts +66 -4
  260. package/src/schemas/api.ts +25 -25
  261. package/src/schemas/parse.ts +9 -6
  262. package/src/schemas/schemas.ts +4 -4
  263. package/src/schemas/types.ts +2 -2
  264. package/src/schemas/utils.ts +4 -38
  265. package/src/serialize/buffer_reader.ts +5 -0
  266. package/src/serialize/buffer_sink.ts +350 -0
  267. package/src/serialize/index.ts +1 -0
  268. package/src/serialize/serialize.ts +0 -50
  269. package/src/sleep/index.ts +10 -1
  270. package/src/string/index.ts +15 -1
  271. package/src/testing/files/index.ts +3 -4
  272. package/src/timer/date.ts +6 -0
  273. package/src/timer/index.ts +1 -1
  274. package/src/timer/timeout.ts +31 -0
  275. package/src/transport/dispatch/create_dispatch_proxy.ts +11 -1
  276. package/src/transport/index.ts +0 -1
  277. package/src/trees/balanced_merkle_tree_root.ts +2 -5
  278. package/src/trees/hasher.ts +6 -3
  279. package/src/trees/indexed_merkle_tree_calculator.ts +5 -1
  280. package/src/trees/membership_witness.ts +0 -8
  281. package/src/trees/merkle_tree_calculator.ts +4 -10
  282. package/src/trees/sibling_path.ts +24 -30
  283. package/src/trees/unbalanced_merkle_tree_root.ts +2 -5
  284. package/src/types/index.ts +47 -0
  285. package/dest/crypto/serialize.d.ts +0 -51
  286. package/dest/crypto/serialize.d.ts.map +0 -1
  287. package/dest/crypto/serialize.js +0 -68
  288. package/dest/transport/dispatch/create_dispatch_fn.d.ts +0 -25
  289. package/dest/transport/dispatch/create_dispatch_fn.d.ts.map +0 -1
  290. package/dest/transport/dispatch/create_dispatch_fn.js +0 -17
  291. package/src/crypto/serialize.ts +0 -85
  292. package/src/transport/dispatch/create_dispatch_fn.ts +0 -35
@@ -10,14 +10,14 @@ export type { EnvVar, NetworkNames };
10
10
  export type { NetworkConfig, NetworkConfigMap } from './network_config.js';
11
11
  export { NetworkConfigMapSchema, NetworkConfigSchema } from './network_config.js';
12
12
 
13
- export interface ConfigMapping {
13
+ export interface ConfigMapping<T> {
14
14
  env?: EnvVar;
15
- parseEnv?: (val: string) => any;
16
- defaultValue?: any;
15
+ /** Parse an env-var string into `T`. Throws on invalid input. */
16
+ parseEnv?: (val: string) => T;
17
+ defaultValue?: T;
17
18
  printDefault?: (val: any) => string;
18
19
  description: string;
19
20
  isBoolean?: boolean;
20
- nested?: Record<string, ConfigMapping>;
21
21
  fallback?: EnvVar[];
22
22
  /**
23
23
  * List of deprecated env vars that are still supported but will log a warning.
@@ -30,7 +30,9 @@ export function isBooleanConfigValue<T>(obj: T, key: keyof T): boolean {
30
30
  return typeof obj[key] === 'boolean';
31
31
  }
32
32
 
33
- export type ConfigMappingsType<T> = Record<keyof T, ConfigMapping>;
33
+ export type ConfigMappingsType<T> = {
34
+ [K in keyof T]-?: ConfigMapping<Required<T>[K]>;
35
+ };
34
36
 
35
37
  /**
36
38
  * Shared utility function to get a value from environment variables with fallback support.
@@ -66,8 +68,8 @@ export function getValueFromEnvWithFallback<T>(
66
68
  }
67
69
  }
68
70
 
69
- // Parse the value if needed
70
- if (value !== undefined) {
71
+ // Parse the value if needed. Empty strings are treated as "not set".
72
+ if (value !== undefined && value !== '') {
71
73
  return parseFunc ? parseFunc(value) : (value as unknown as T);
72
74
  }
73
75
 
@@ -79,22 +81,20 @@ export function getConfigFromMappings<T>(configMappings: ConfigMappingsType<T>):
79
81
  const config = {} as T;
80
82
 
81
83
  for (const key in configMappings) {
82
- const { env, parseEnv, defaultValue, nested, fallback, deprecatedFallback } = configMappings[key];
83
- if (nested) {
84
- (config as any)[key] = getConfigFromMappings(nested);
85
- } else {
86
- // Use the shared utility function
84
+ const { env, parseEnv, defaultValue, fallback, deprecatedFallback } = configMappings[key];
85
+ try {
87
86
  (config as any)[key] = getValueFromEnvWithFallback(env, parseEnv, defaultValue, fallback);
87
+ } catch (e: any) {
88
+ throw new Error(`Failed to parse config '${key}' (env: ${env ?? 'none'}): ${e.message}`);
89
+ }
88
90
 
89
- // Check for deprecated env vars and warn if logger is set
90
- if (deprecatedFallback?.length) {
91
- const userLog = createConsoleLogger('[DEPRECATED]');
92
- for (const { env: deprecatedEnv, message } of deprecatedFallback) {
93
- if (process.env[deprecatedEnv]) {
94
- const warningMessage =
95
- message ?? `Environment variable ${deprecatedEnv} is deprecated. Please use ${env} instead.`;
96
- userLog(warningMessage, { deprecatedEnvVar: deprecatedEnv, newEnvVar: env });
97
- }
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
98
  }
99
99
  }
100
100
  }
@@ -119,29 +119,37 @@ export function omitConfigMappings<T, K extends keyof T>(
119
119
  }
120
120
 
121
121
  /**
122
- * Generates parseEnv and default values for a numerical config value.
123
- * @param defaultVal - The default numerical value to use if the environment variable is not set or is invalid
124
- * @returns Object with parseEnv and default values for a numerical config value
122
+ * Generates parseEnv and default values for an integer config value.
123
+ *
124
+ * The default is used only when the environment variable is unset or empty. A set-but-invalid
125
+ * value (non-numeric, fractional, or outside the safe-integer range) throws rather than silently
126
+ * falling back to the default.
127
+ * @param defaultVal - The default value to use when the environment variable is unset
128
+ * @returns Object with parseEnv and default values for an integer config value
125
129
  */
126
- export function numberConfigHelper(defaultVal: number): Pick<ConfigMapping, 'parseEnv' | 'defaultValue'> {
130
+ export function numberConfigHelper(defaultVal: number): Pick<ConfigMapping<number>, 'parseEnv' | 'defaultValue'> {
127
131
  return {
128
- parseEnv: (val: string) => safeParseNumber(val, defaultVal),
132
+ parseEnv: (val: string) => parseSafeInteger(val),
129
133
  defaultValue: defaultVal,
130
134
  };
131
135
  }
132
136
 
133
137
  /**
134
- * Generates parseEnv and default values for a numerical config value.
135
- * @param defaultVal - The default numerical value to use if the environment variable is not set or is invalid
136
- * @returns Object with parseEnv and default values for a numerical config value
138
+ * Generates parseEnv and default values for a floating-point config value.
139
+ *
140
+ * The default is used only when the environment variable is unset or empty. A set-but-invalid
141
+ * value (not a finite number) throws rather than silently falling back to the default.
142
+ * @param defaultVal - The default value to use when the environment variable is unset
143
+ * @param validationFn - Optional extra validation applied to the parsed value; should throw on invalid input
144
+ * @returns Object with parseEnv and default values for a floating-point config value
137
145
  */
138
146
  export function floatConfigHelper(
139
147
  defaultVal: number,
140
148
  validationFn?: (val: number) => void,
141
- ): Pick<ConfigMapping, 'parseEnv' | 'defaultValue'> {
149
+ ): Pick<ConfigMapping<number>, 'parseEnv' | 'defaultValue'> {
142
150
  return {
143
151
  parseEnv: (val: string): number => {
144
- const parsed = safeParseFloat(val, defaultVal);
152
+ const parsed = parseFiniteNumber(val);
145
153
  validationFn?.(parsed);
146
154
  return parsed;
147
155
  },
@@ -150,12 +158,17 @@ export function floatConfigHelper(
150
158
  }
151
159
 
152
160
  /**
153
- * Parses an environment variable to a 0-1 percentage value
161
+ * Generates parseEnv and default values for a 0-1 percentage config value.
162
+ *
163
+ * The default is used only when the environment variable is unset or empty. A set-but-invalid
164
+ * value (not a finite number, or outside the 0-1 range) throws rather than silently falling back
165
+ * to the default.
166
+ * @param defaultVal - The default value to use when the environment variable is unset
154
167
  */
155
- export function percentageConfigHelper(defaultVal: number): Pick<ConfigMapping, 'parseEnv' | 'defaultValue'> {
168
+ export function percentageConfigHelper(defaultVal: number): Pick<ConfigMapping<number>, 'parseEnv' | 'defaultValue'> {
156
169
  return {
157
170
  parseEnv: (val: string): number => {
158
- const parsed = safeParseFloat(val, defaultVal);
171
+ const parsed = parseFiniteNumber(val);
159
172
  if (parsed < 0 || parsed > 1) {
160
173
  throw new TypeError(`Invalid percentage value: ${parsed} should be between 0 and 1`);
161
174
  }
@@ -171,12 +184,13 @@ export function percentageConfigHelper(defaultVal: number): Pick<ConfigMapping,
171
184
  * @param defaultVal - The default numerical value to use if the environment variable is not set or is invalid
172
185
  * @returns Object with parseEnv and default values for a numerical config value
173
186
  */
174
- export function bigintConfigHelper(defaultVal?: bigint): Pick<ConfigMapping, 'parseEnv' | 'defaultValue'> {
187
+ export function bigintConfigHelper(defaultVal: bigint): Pick<ConfigMapping<bigint>, 'parseEnv' | 'defaultValue'>;
188
+ export function bigintConfigHelper(): Pick<ConfigMapping<bigint | undefined>, 'parseEnv' | 'defaultValue'>;
189
+ export function bigintConfigHelper(
190
+ defaultVal?: bigint,
191
+ ): Pick<ConfigMapping<bigint | undefined>, 'parseEnv' | 'defaultValue'> {
175
192
  return {
176
193
  parseEnv: (val: string) => {
177
- if (val === '') {
178
- return defaultVal;
179
- }
180
194
  // Handle scientific notation (e.g. "1e+23", "2E23") which BigInt() doesn't accept directly.
181
195
  // We parse it losslessly using bigint arithmetic instead of going through float64.
182
196
  if (/[eE]/.test(val)) {
@@ -200,32 +214,31 @@ export function bigintConfigHelper(defaultVal?: bigint): Pick<ConfigMapping, 'pa
200
214
 
201
215
  /**
202
216
  * Generates parseEnv for an optional numerical config value.
217
+ * Empty strings are already handled by getValueFromEnvWithFallback.
203
218
  */
204
- export function optionalNumberConfigHelper(): Pick<ConfigMapping, 'parseEnv'> {
219
+ export function optionalNumberConfigHelper(): Pick<ConfigMapping<number>, 'parseEnv'> {
205
220
  return {
206
- parseEnv: (val: string | undefined) => {
207
- if (val !== undefined && val.length > 0) {
208
- const parsedValue = parseInt(val);
209
- return Number.isSafeInteger(parsedValue) ? parsedValue : undefined;
210
- }
211
- return undefined;
212
- },
221
+ parseEnv: (val: string) => parseSafeInteger(val),
213
222
  };
214
223
  }
215
224
 
216
225
  /** Generates parseEnv for an enum-like config value. */
226
+ export function enumConfigHelper<T extends string>(
227
+ values: T[],
228
+ defaultValue: NoInfer<T>,
229
+ ): Pick<ConfigMapping<T>, 'parseEnv' | 'defaultValue'>;
230
+ export function enumConfigHelper<T extends string>(
231
+ values: T[],
232
+ ): Pick<ConfigMapping<T | undefined>, 'parseEnv' | 'defaultValue'>;
217
233
  export function enumConfigHelper<T extends string>(
218
234
  values: T[],
219
235
  defaultValue?: NoInfer<T>,
220
- ): Pick<ConfigMapping, 'parseEnv' | 'defaultValue'> {
236
+ ): Pick<ConfigMapping<T | undefined>, 'parseEnv' | 'defaultValue'> {
221
237
  return {
222
238
  parseEnv: (val: string) => {
223
- const sanitizedVal = (val ?? '').trim().toLowerCase();
224
- if (values.includes(sanitizedVal as T)) {
225
- return sanitizedVal as T;
226
- }
227
- if (!val && defaultValue) {
228
- return defaultValue;
239
+ const sanitizedVal = val.trim().toLowerCase();
240
+ if (values.some(v => v.toLowerCase() === sanitizedVal)) {
241
+ return values.find(v => v.toLowerCase() === sanitizedVal)!;
229
242
  }
230
243
  throw new Error(`Invalid config value '${val}' (must be one of ${values.join(', ')})`);
231
244
  },
@@ -240,7 +253,9 @@ export function enumConfigHelper<T extends string>(
240
253
  */
241
254
  export function booleanConfigHelper(
242
255
  defaultVal = false,
243
- ): Required<Pick<ConfigMapping, 'parseEnv' | 'defaultValue' | 'isBoolean'> & { parseVal: (val: string) => boolean }> {
256
+ ): Required<
257
+ Pick<ConfigMapping<boolean>, 'parseEnv' | 'defaultValue' | 'isBoolean'> & { parseVal: (val: string) => boolean }
258
+ > {
244
259
  const parse = (val: string | boolean) => (typeof val === 'boolean' ? val : parseBooleanEnv(val));
245
260
  return {
246
261
  parseEnv: parse,
@@ -250,116 +265,122 @@ export function booleanConfigHelper(
250
265
  };
251
266
  }
252
267
 
253
- export function secretValueConfigHelper<T>(parse: (val: string | undefined) => T): Required<
254
- Pick<ConfigMapping, 'parseEnv' | 'defaultValue' | 'isBoolean'> & {
255
- parseVal: (val: string) => SecretValue<T>;
256
- }
257
- > {
268
+ export function secretValueConfigHelper<T>(parse: (val: string | undefined) => T): Pick<
269
+ ConfigMapping<SecretValue<T>>,
270
+ 'parseEnv' | 'defaultValue'
271
+ > & {
272
+ parseVal: (val: string) => SecretValue<T>;
273
+ } {
258
274
  const wrap = (val: string) => new SecretValue(parse(val));
259
275
  return {
260
276
  parseEnv: wrap,
261
277
  parseVal: wrap,
262
278
  defaultValue: new SecretValue(parse(undefined)),
263
- isBoolean: true,
264
279
  };
265
280
  }
266
281
 
267
282
  export { parseBooleanEnv } from './parse-env.js';
268
283
 
269
- export function secretStringConfigHelper(): Required<
270
- Pick<ConfigMapping, 'parseEnv' | 'defaultValue' | 'isBoolean'> & {
271
- parseVal: (val: string) => SecretValue<string | undefined>;
272
- }
273
- >;
274
- export function secretStringConfigHelper(defaultValue: string): Required<
275
- Pick<ConfigMapping, 'parseEnv' | 'defaultValue' | 'isBoolean'> & {
276
- parseVal: (val: string) => SecretValue<string>;
277
- }
278
- >;
279
- export function secretStringConfigHelper(defaultValue?: string): Required<
280
- Pick<ConfigMapping, 'parseEnv' | 'defaultValue' | 'isBoolean'> & {
281
- parseVal: (val: string) => SecretValue<string | typeof defaultValue>;
282
- }
283
- > {
284
+ export function secretStringConfigHelper(): {
285
+ parseEnv: (val: string) => SecretValue<string>;
286
+ parseVal: (val: string) => SecretValue<string>;
287
+ defaultValue: undefined;
288
+ };
289
+ export function secretStringConfigHelper(defaultValue: string): {
290
+ parseEnv: (val: string) => SecretValue<string>;
291
+ parseVal: (val: string) => SecretValue<string>;
292
+ defaultValue: SecretValue<string>;
293
+ };
294
+ export function secretStringConfigHelper(defaultValue?: string): {
295
+ parseEnv: (val: string) => SecretValue<string>;
296
+ parseVal: (val: string) => SecretValue<string>;
297
+ defaultValue: SecretValue<string> | undefined;
298
+ } {
284
299
  const parse = (val: string) => new SecretValue(val);
285
300
  return {
286
301
  parseEnv: parse,
287
302
  parseVal: parse,
288
303
  defaultValue: defaultValue !== undefined ? new SecretValue(defaultValue) : undefined,
289
- isBoolean: true,
290
304
  };
291
305
  }
292
306
 
293
- export function secretFrConfigHelper(): Required<
294
- Pick<ConfigMapping, 'parseEnv' | 'defaultValue' | 'isBoolean'> & {
295
- parseVal: (val: string) => SecretValue<Fr | undefined>;
296
- }
297
- >;
298
- export function secretFrConfigHelper(defaultValue: Fr): Required<
299
- Pick<ConfigMapping, 'parseEnv' | 'defaultValue' | 'isBoolean'> & {
300
- parseVal: (val: string) => SecretValue<Fr>;
301
- }
302
- >;
303
- export function secretFrConfigHelper(defaultValue?: Fr): Required<
304
- Pick<ConfigMapping, 'parseEnv' | 'defaultValue' | 'isBoolean'> & {
305
- parseVal: (val: string) => SecretValue<Fr | typeof defaultValue>;
306
- }
307
- > {
307
+ export function secretFrConfigHelper(): {
308
+ parseEnv: (val: string) => SecretValue<Fr>;
309
+ parseVal: (val: string) => SecretValue<Fr>;
310
+ defaultValue: undefined;
311
+ };
312
+ export function secretFrConfigHelper(defaultValue: Fr): {
313
+ parseEnv: (val: string) => SecretValue<Fr>;
314
+ parseVal: (val: string) => SecretValue<Fr>;
315
+ defaultValue: SecretValue<Fr>;
316
+ };
317
+ export function secretFrConfigHelper(defaultValue?: Fr): {
318
+ parseEnv: (val: string) => SecretValue<Fr>;
319
+ parseVal: (val: string) => SecretValue<Fr>;
320
+ defaultValue: SecretValue<Fr> | undefined;
321
+ } {
308
322
  const parse = (val: string) => new SecretValue(Fr.fromHexString(val));
309
323
  return {
310
324
  parseEnv: parse,
311
325
  parseVal: parse,
312
326
  defaultValue: defaultValue !== undefined ? new SecretValue(defaultValue) : undefined,
313
- isBoolean: true,
314
327
  };
315
328
  }
316
329
 
317
- export function secretFqConfigHelper(defaultValue: Fq): Required<
318
- Pick<ConfigMapping, 'parseEnv' | 'defaultValue' | 'isBoolean'> & {
319
- parseVal: (val: string) => SecretValue<Fq>;
320
- }
321
- >;
322
- export function secretFqConfigHelper(): Required<
323
- Pick<ConfigMapping, 'parseEnv' | 'defaultValue' | 'isBoolean'> & {
324
- parseVal: (val: string) => SecretValue<Fq | undefined>;
325
- }
326
- >;
327
- export function secretFqConfigHelper(defaultValue?: Fq): Required<
328
- Pick<ConfigMapping, 'parseEnv' | 'defaultValue' | 'isBoolean'> & {
329
- parseVal: (val: string) => SecretValue<Fq | typeof defaultValue>;
330
- }
331
- > {
330
+ export function secretFqConfigHelper(): {
331
+ parseEnv: (val: string) => SecretValue<Fq>;
332
+ parseVal: (val: string) => SecretValue<Fq>;
333
+ defaultValue: undefined;
334
+ };
335
+ export function secretFqConfigHelper(defaultValue: Fq): {
336
+ parseEnv: (val: string) => SecretValue<Fq>;
337
+ parseVal: (val: string) => SecretValue<Fq>;
338
+ defaultValue: SecretValue<Fq>;
339
+ };
340
+ export function secretFqConfigHelper(defaultValue?: Fq): {
341
+ parseEnv: (val: string) => SecretValue<Fq>;
342
+ parseVal: (val: string) => SecretValue<Fq>;
343
+ defaultValue: SecretValue<Fq> | undefined;
344
+ } {
332
345
  const parse = (val: string) => new SecretValue(Fq.fromHexString(val));
333
346
  return {
334
347
  parseEnv: parse,
335
348
  parseVal: parse,
336
- defaultValue: typeof defaultValue !== 'undefined' ? new SecretValue(defaultValue) : undefined,
337
- isBoolean: true,
349
+ defaultValue: defaultValue !== undefined ? new SecretValue(defaultValue) : undefined,
338
350
  };
339
351
  }
340
352
 
341
353
  /**
342
- * Safely parses a number from a string.
343
- * If the value is not a number or is not a safe integer, the default value is returned.
354
+ * Parses a string into a safe integer, throwing if the value is numeric but not an integer.
355
+ *
356
+ * Unlike `parseInt`, this does not silently truncate decimals: `'0.8'` throws rather than
357
+ * becoming `0`. A fractional value indicates the caller intended a non-integer where only
358
+ * integers are supported (use `floatConfigHelper`/`percentageConfigHelper` for those).
344
359
  * @param value - The string value to parse
345
- * @param defaultValue - The default value to return
346
- * @returns Either parsed value or default value
360
+ * @returns The parsed integer value
347
361
  */
348
- function safeParseNumber(value: string, defaultValue: number): number {
349
- const parsedValue = parseInt(value, 10);
350
- return Number.isSafeInteger(parsedValue) ? parsedValue : defaultValue;
362
+ function parseSafeInteger(value: string): number {
363
+ const parsedValue = parseFloat(value);
364
+ if (!Number.isSafeInteger(parsedValue)) {
365
+ throw new Error(`Invalid integer config value '${value}'; expected a whole number`);
366
+ }
367
+ return parsedValue;
351
368
  }
352
369
 
353
370
  /**
354
- * Safely parses a floating point number from a string.
355
- * If the value is not a number, the default value is returned.
371
+ * Parses a string into a finite floating-point number, throwing if the value is not a finite number.
372
+ *
373
+ * Invalid input (e.g. `'abc'`, or an overflow to `Infinity`) throws rather than being silently
374
+ * swallowed, so a misconfigured value fails loudly instead of falling back to the config default.
356
375
  * @param value - The string value to parse
357
- * @param defaultValue - The default value to return
358
- * @returns Either parsed value or default value
376
+ * @returns The parsed number
359
377
  */
360
- function safeParseFloat(value: string, defaultValue: number): number {
378
+ function parseFiniteNumber(value: string): number {
361
379
  const parsedValue = parseFloat(value);
362
- return Number.isNaN(parsedValue) ? defaultValue : parsedValue;
380
+ if (!Number.isFinite(parsedValue)) {
381
+ throw new Error(`Invalid number config value '${value}'`);
382
+ }
383
+ return parsedValue;
363
384
  }
364
385
 
365
386
  /**
@@ -5,10 +5,12 @@ 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(),
12
14
  nodeVersion: z.string().optional(),
13
15
  })
14
16
  .passthrough(); // Allow additional unknown fields to pass through
@@ -1,19 +1,17 @@
1
1
  export type NetworkNames =
2
2
  | 'local'
3
- | 'staging-ignition'
4
- | 'staging-public'
3
+ | 'staging'
5
4
  | 'testnet'
6
5
  | 'mainnet'
7
6
  | 'next-net'
8
- | 'devnet';
7
+ | 'devnet'
8
+ | `v${number}-devnet-${number}`;
9
9
 
10
10
  export function getActiveNetworkName(name?: string): NetworkNames {
11
11
  const network = name || process.env.NETWORK;
12
12
  if (!network || network === '' || network === 'local') {
13
13
  return 'local';
14
- } else if (network === 'staging-ignition') {
15
- return network;
16
- } else if (network === 'staging-public') {
14
+ } else if (network === 'staging') {
17
15
  return network;
18
16
  } else if (network === 'testnet' || network === 'alpha-testnet') {
19
17
  return 'testnet';
@@ -23,6 +21,8 @@ export function getActiveNetworkName(name?: string): NetworkNames {
23
21
  return 'next-net';
24
22
  } else if (network === 'devnet') {
25
23
  return 'devnet';
24
+ } else if (/^v\d+-devnet-\d+$/.test(network)) {
25
+ return network as `v${number}-devnet-${number}`;
26
26
  }
27
27
  throw new Error(`Unknown network: ${network}`);
28
28
  }
@@ -43,7 +43,7 @@ export class SecretValue<T> {
43
43
  /**
44
44
  * Returns a Zod schema
45
45
  */
46
- static schema<O>(valueSchema: ZodType<O, any, any>): ZodType<SecretValue<O>, any, any> {
46
+ static schema<O>(valueSchema: ZodType<O, any>): ZodType<SecretValue<O>, any> {
47
47
  return valueSchema.transform(value => new SecretValue<O>(value));
48
48
  }
49
49
  }
@@ -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
  }
@@ -1,7 +1,8 @@
1
1
  import { randomBytes } from '@aztec/foundation/crypto/random';
2
2
 
3
- import { createCipheriv, createDecipheriv, createHash, pbkdf2Sync, randomUUID } from 'crypto';
3
+ import { createCipheriv, createDecipheriv, createHash, pbkdf2, pbkdf2Sync, randomUUID } from 'crypto';
4
4
  import { readFileSync } from 'fs';
5
+ import { promisify } from 'util';
5
6
  import { z } from 'zod';
6
7
 
7
8
  /**
@@ -100,24 +101,15 @@ export interface Bn254KeystoreInterface {
100
101
  version: number;
101
102
  }
102
103
 
103
- /**
104
- * Creates a BN254 keystore object for a BN254 BLS private key.
105
- *
106
- * Uses PBKDF2 with SHA-256 for key derivation and AES-128-CTR for encryption,
107
- * following the EIP-2335 specification format.
108
- *
109
- * @param password - Password for encrypting the private key
110
- * @param privateKeyHex - Private key as 0x-prefixed hex string (32 bytes)
111
- * @param pubkeyHex - Public key as hex string (compressed or uncompressed)
112
- * @param derivationPath - BIP-44 style derivation path (e.g., "m/12381/3600/0/0/0")
113
- * @returns BN254 keystore object ready to be serialized to JSON
114
- * @throws Error if private key is not 32-byte hex
115
- */
116
- export function createBn254Keystore(
117
- password: string,
104
+ const pbkdf2Async = promisify(pbkdf2);
105
+
106
+ function createBn254KeystoreFromDerivedKey(
118
107
  privateKeyHex: string,
119
108
  pubkeyHex: string,
120
109
  derivationPath: string,
110
+ salt: Buffer,
111
+ iv: Buffer,
112
+ dk: Buffer,
121
113
  ): Bn254Keystore {
122
114
  const ensureHex = (hex: string) => hex.replace(/^0x/i, '');
123
115
  const privHex = ensureHex(privateKeyHex);
@@ -125,11 +117,7 @@ export function createBn254Keystore(
125
117
  throw new Error('BLS private key must be 32-byte hex');
126
118
  }
127
119
 
128
- const salt = randomBytes(32);
129
- const iv = randomBytes(16);
130
- const dk = pbkdf2Sync(Buffer.from(password.normalize('NFKD'), 'utf8'), salt, 262144, 32, 'sha256');
131
120
  const cipherKey = dk.subarray(0, 16);
132
-
133
121
  const cipher = createCipheriv('aes-128-ctr', cipherKey, iv);
134
122
  const plaintext = Buffer.from(privHex, 'hex');
135
123
  const ciphertext = Buffer.concat([cipher.update(plaintext), cipher.final()]);
@@ -166,6 +154,31 @@ export function createBn254Keystore(
166
154
  };
167
155
  }
168
156
 
157
+ /**
158
+ * Creates a BN254 keystore object for a BN254 BLS private key.
159
+ *
160
+ * Uses PBKDF2 with SHA-256 for key derivation and AES-128-CTR for encryption,
161
+ * following the EIP-2335 specification format.
162
+ *
163
+ * @param password - Password for encrypting the private key
164
+ * @param privateKeyHex - Private key as 0x-prefixed hex string (32 bytes)
165
+ * @param pubkeyHex - Public key as hex string (compressed or uncompressed)
166
+ * @param derivationPath - BIP-44 style derivation path (e.g., "m/12381/3600/0/0/0")
167
+ * @returns BN254 keystore object ready to be serialized to JSON
168
+ * @throws Error if private key is not 32-byte hex
169
+ */
170
+ export async function createBn254Keystore(
171
+ password: string,
172
+ privateKeyHex: string,
173
+ pubkeyHex: string,
174
+ derivationPath: string,
175
+ ): Promise<Bn254Keystore> {
176
+ const salt = randomBytes(32);
177
+ const iv = randomBytes(16);
178
+ const dk = await pbkdf2Async(Buffer.from(password.normalize('NFKD'), 'utf8'), salt, 262144, 32, 'sha256');
179
+ return createBn254KeystoreFromDerivedKey(privateKeyHex, pubkeyHex, derivationPath, salt, iv, dk);
180
+ }
181
+
169
182
  /**
170
183
  * Loads and validates a BN254 keystore file.
171
184
  *
@@ -262,26 +275,3 @@ export function decryptBn254KeystoreFromObject(keystore: Bn254Keystore, password
262
275
  throw new Bn254KeystoreError(`Failed to decrypt keystore: ${String(error)}`, error as Error);
263
276
  }
264
277
  }
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,10 +1,26 @@
1
- import { BarretenbergSync } from '@aztec/bb.js';
1
+ import { BarretenbergSync, CircuitKind } from '@aztec/bb.js';
2
2
 
3
3
  import { Fr } from '../../curves/bn254/field.js';
4
4
 
5
- export async function vkAsFieldsMegaHonk(input: Buffer): Promise<Fr[]> {
5
+ export async function vkAsFields(input: Buffer, kind: CircuitKind): Promise<Fr[]> {
6
6
  await BarretenbergSync.initSingleton();
7
7
  const api = BarretenbergSync.getSingleton();
8
- const response = api.megaVkAsFields({ verificationKey: input });
9
- return response.fields.map(field => Fr.fromBuffer(Buffer.from(field)));
8
+ switch (kind) {
9
+ case CircuitKind.App: {
10
+ const response = api.megaAppVkAsFields({ verificationKey: input });
11
+ return response.fields.map(field => Fr.fromBuffer(Buffer.from(field)));
12
+ }
13
+ case CircuitKind.Kernel: {
14
+ const response = api.megaKernelVkAsFields({ verificationKey: input });
15
+ return response.fields.map(field => Fr.fromBuffer(Buffer.from(field)));
16
+ }
17
+ case CircuitKind.HidingKernel: {
18
+ const response = api.megaZKVkAsFields({ verificationKey: input });
19
+ return response.fields.map(field => Fr.fromBuffer(Buffer.from(field)));
20
+ }
21
+ default: {
22
+ const _exhaustive: never = kind;
23
+ throw new Error(`vkAsFields: unhandled CircuitKind ${_exhaustive}`);
24
+ }
25
+ }
10
26
  }