@aztec/foundation 0.0.1-commit.d431d1c → 0.0.1-commit.d58ff9d0

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 (338) hide show
  1. package/dest/array/sorted_array.d.ts +6 -1
  2. package/dest/array/sorted_array.d.ts.map +1 -1
  3. package/dest/array/sorted_array.js +18 -15
  4. package/dest/bigint-buffer/index.d.ts +1 -1
  5. package/dest/bigint-buffer/index.d.ts.map +1 -1
  6. package/dest/bigint-buffer/index.js +6 -1
  7. package/dest/branded-types/block_number.d.ts +3 -3
  8. package/dest/branded-types/block_number.d.ts.map +1 -1
  9. package/dest/branded-types/block_number.js +15 -4
  10. package/dest/branded-types/buffer32_hash.d.ts +27 -0
  11. package/dest/branded-types/buffer32_hash.d.ts.map +1 -0
  12. package/dest/branded-types/buffer32_hash.js +12 -0
  13. package/dest/branded-types/checkpoint_number.d.ts +9 -3
  14. package/dest/branded-types/checkpoint_number.d.ts.map +1 -1
  15. package/dest/branded-types/checkpoint_number.js +11 -0
  16. package/dest/branded-types/epoch.d.ts +2 -2
  17. package/dest/branded-types/epoch.d.ts.map +1 -1
  18. package/dest/branded-types/index.d.ts +2 -1
  19. package/dest/branded-types/index.d.ts.map +1 -1
  20. package/dest/branded-types/index.js +1 -0
  21. package/dest/branded-types/index_within_checkpoint.d.ts +2 -2
  22. package/dest/branded-types/index_within_checkpoint.d.ts.map +1 -1
  23. package/dest/branded-types/slot.d.ts +5 -2
  24. package/dest/branded-types/slot.d.ts.map +1 -1
  25. package/dest/branded-types/slot.js +3 -0
  26. package/dest/buffer/buffer16.d.ts +3 -1
  27. package/dest/buffer/buffer16.d.ts.map +1 -1
  28. package/dest/buffer/buffer32.d.ts +28 -61
  29. package/dest/buffer/buffer32.d.ts.map +1 -1
  30. package/dest/buffer/buffer32.js +29 -63
  31. package/dest/buffer/index.d.ts +2 -1
  32. package/dest/buffer/index.d.ts.map +1 -1
  33. package/dest/buffer/index.js +1 -0
  34. package/dest/buffer/utils.d.ts +3 -0
  35. package/dest/buffer/utils.d.ts.map +1 -0
  36. package/dest/buffer/utils.js +7 -0
  37. package/dest/collection/array.d.ts +22 -1
  38. package/dest/collection/array.d.ts.map +1 -1
  39. package/dest/collection/array.js +84 -0
  40. package/dest/collection/index.d.ts +3 -1
  41. package/dest/collection/index.d.ts.map +1 -1
  42. package/dest/collection/index.js +2 -0
  43. package/dest/collection/lru_map.d.ts +41 -0
  44. package/dest/collection/lru_map.d.ts.map +1 -0
  45. package/dest/collection/lru_map.js +119 -0
  46. package/dest/collection/lru_set.d.ts +35 -0
  47. package/dest/collection/lru_set.d.ts.map +1 -0
  48. package/dest/collection/lru_set.js +95 -0
  49. package/dest/committable/committable.js +1 -1
  50. package/dest/config/env_var.d.ts +2 -2
  51. package/dest/config/env_var.d.ts.map +1 -1
  52. package/dest/config/index.d.ts +67 -37
  53. package/dest/config/index.d.ts.map +1 -1
  54. package/dest/config/index.js +86 -70
  55. package/dest/config/network_config.d.ts +15 -41
  56. package/dest/config/network_config.d.ts.map +1 -1
  57. package/dest/config/network_config.js +4 -1
  58. package/dest/config/network_name.d.ts +2 -2
  59. package/dest/config/network_name.d.ts.map +1 -1
  60. package/dest/config/network_name.js +3 -3
  61. package/dest/config/secret_value.d.ts +2 -2
  62. package/dest/config/secret_value.d.ts.map +1 -1
  63. package/dest/crypto/aes128/index.d.ts +2 -1
  64. package/dest/crypto/aes128/index.d.ts.map +1 -1
  65. package/dest/crypto/aes128/index.js +11 -2
  66. package/dest/crypto/bls/bn254_keystore.d.ts +10 -177
  67. package/dest/crypto/bls/bn254_keystore.d.ts.map +1 -1
  68. package/dest/crypto/bls/bn254_keystore.js +22 -34
  69. package/dest/crypto/keys/index.d.ts +3 -2
  70. package/dest/crypto/keys/index.d.ts.map +1 -1
  71. package/dest/crypto/keys/index.js +30 -6
  72. package/dest/crypto/poseidon/index.d.ts +1 -2
  73. package/dest/crypto/poseidon/index.d.ts.map +1 -1
  74. package/dest/crypto/poseidon/index.js +40 -42
  75. package/dest/crypto/random/randomness_singleton.d.ts +4 -3
  76. package/dest/crypto/random/randomness_singleton.d.ts.map +1 -1
  77. package/dest/crypto/random/randomness_singleton.js +4 -4
  78. package/dest/crypto/schnorr/index.d.ts +8 -7
  79. package/dest/crypto/schnorr/index.d.ts.map +1 -1
  80. package/dest/crypto/schnorr/index.js +6 -6
  81. package/dest/crypto/schnorr/signature.d.ts +9 -29
  82. package/dest/crypto/schnorr/signature.d.ts.map +1 -1
  83. package/dest/crypto/schnorr/signature.js +20 -36
  84. package/dest/crypto/secp256k1-signer/utils.d.ts +12 -1
  85. package/dest/crypto/secp256k1-signer/utils.d.ts.map +1 -1
  86. package/dest/crypto/secp256k1-signer/utils.js +26 -0
  87. package/dest/crypto/sync/poseidon/index.d.ts +1 -2
  88. package/dest/crypto/sync/poseidon/index.d.ts.map +1 -1
  89. package/dest/crypto/sync/poseidon/index.js +0 -8
  90. package/dest/curves/bls12/field.d.ts +3 -3
  91. package/dest/curves/bls12/field.d.ts.map +1 -1
  92. package/dest/curves/bls12/field.js +0 -5
  93. package/dest/curves/bls12/point.d.ts +2 -2
  94. package/dest/curves/bls12/point.d.ts.map +1 -1
  95. package/dest/curves/bn254/field.d.ts +24 -19
  96. package/dest/curves/bn254/field.d.ts.map +1 -1
  97. package/dest/curves/bn254/field.js +28 -19
  98. package/dest/curves/grumpkin/point.d.ts +14 -28
  99. package/dest/curves/grumpkin/point.d.ts.map +1 -1
  100. package/dest/curves/grumpkin/point.js +29 -43
  101. package/dest/eth-address/index.d.ts +2 -2
  102. package/dest/eth-address/index.d.ts.map +1 -1
  103. package/dest/eth-address/index.js +0 -3
  104. package/dest/eth-signature/eth_signature.d.ts +3 -2
  105. package/dest/eth-signature/eth_signature.d.ts.map +1 -1
  106. package/dest/eth-signature/eth_signature.js +7 -2
  107. package/dest/fifo/fifo_frame_reader.d.ts +41 -0
  108. package/dest/fifo/fifo_frame_reader.d.ts.map +1 -0
  109. package/dest/fifo/fifo_frame_reader.js +91 -0
  110. package/dest/fifo/index.d.ts +2 -0
  111. package/dest/fifo/index.d.ts.map +1 -0
  112. package/dest/fifo/index.js +1 -0
  113. package/dest/fifo_set/fifo_set.d.ts +15 -0
  114. package/dest/fifo_set/fifo_set.d.ts.map +1 -0
  115. package/dest/fifo_set/fifo_set.js +39 -0
  116. package/dest/fifo_set/index.d.ts +2 -0
  117. package/dest/fifo_set/index.d.ts.map +1 -0
  118. package/dest/fifo_set/index.js +1 -0
  119. package/dest/jest/setup.js +28 -1
  120. package/dest/json-rpc/client/fetch.d.ts +1 -1
  121. package/dest/json-rpc/client/fetch.d.ts.map +1 -1
  122. package/dest/json-rpc/client/fetch.js +4 -3
  123. package/dest/json-rpc/client/safe_json_rpc_client.d.ts +2 -1
  124. package/dest/json-rpc/client/safe_json_rpc_client.d.ts.map +1 -1
  125. package/dest/json-rpc/client/safe_json_rpc_client.js +3 -3
  126. package/dest/json-rpc/client/undici.d.ts +1 -1
  127. package/dest/json-rpc/client/undici.d.ts.map +1 -1
  128. package/dest/json-rpc/client/undici.js +23 -4
  129. package/dest/json-rpc/fixtures/test_state.d.ts +4 -8
  130. package/dest/json-rpc/fixtures/test_state.d.ts.map +1 -1
  131. package/dest/json-rpc/fixtures/test_state.js +57 -17
  132. package/dest/json-rpc/server/api_key_auth.d.ts +19 -0
  133. package/dest/json-rpc/server/api_key_auth.d.ts.map +1 -0
  134. package/dest/json-rpc/server/api_key_auth.js +57 -0
  135. package/dest/json-rpc/server/index.d.ts +2 -1
  136. package/dest/json-rpc/server/index.d.ts.map +1 -1
  137. package/dest/json-rpc/server/index.js +1 -0
  138. package/dest/json-rpc/server/safe_json_rpc_server.d.ts +8 -3
  139. package/dest/json-rpc/server/safe_json_rpc_server.d.ts.map +1 -1
  140. package/dest/json-rpc/server/safe_json_rpc_server.js +28 -14
  141. package/dest/log/bigint-utils.d.ts +5 -0
  142. package/dest/log/bigint-utils.d.ts.map +1 -0
  143. package/dest/log/bigint-utils.js +21 -0
  144. package/dest/log/gcloud-logger-config.d.ts +1 -1
  145. package/dest/log/gcloud-logger-config.d.ts.map +1 -1
  146. package/dest/log/gcloud-logger-config.js +3 -0
  147. package/dest/log/libp2p_logger.d.ts +5 -2
  148. package/dest/log/libp2p_logger.d.ts.map +1 -1
  149. package/dest/log/libp2p_logger.js +14 -4
  150. package/dest/log/log-filters.d.ts +17 -4
  151. package/dest/log/log-filters.d.ts.map +1 -1
  152. package/dest/log/log-filters.js +26 -12
  153. package/dest/log/pino-logger-server.d.ts +9 -0
  154. package/dest/log/pino-logger-server.d.ts.map +1 -0
  155. package/dest/log/pino-logger-server.js +18 -0
  156. package/dest/log/pino-logger.d.ts +37 -8
  157. package/dest/log/pino-logger.d.ts.map +1 -1
  158. package/dest/log/pino-logger.js +137 -29
  159. package/dest/noir/noir_package_config.d.ts +19 -104
  160. package/dest/noir/noir_package_config.d.ts.map +1 -1
  161. package/dest/noir/noir_package_config.js +1 -1
  162. package/dest/promise/running-promise.d.ts +5 -4
  163. package/dest/promise/running-promise.d.ts.map +1 -1
  164. package/dest/promise/running-promise.js +7 -3
  165. package/dest/queue/base_memory_queue.d.ts +2 -2
  166. package/dest/queue/base_memory_queue.d.ts.map +1 -1
  167. package/dest/queue/batch_queue.d.ts +1 -1
  168. package/dest/queue/batch_queue.d.ts.map +1 -1
  169. package/dest/queue/batch_queue.js +1 -0
  170. package/dest/queue/semaphore.d.ts +5 -1
  171. package/dest/queue/semaphore.d.ts.map +1 -1
  172. package/dest/retry/index.d.ts +31 -3
  173. package/dest/retry/index.d.ts.map +1 -1
  174. package/dest/retry/index.js +44 -2
  175. package/dest/schemas/api.d.ts +12 -10
  176. package/dest/schemas/api.d.ts.map +1 -1
  177. package/dest/schemas/api.js +7 -1
  178. package/dest/schemas/parse.d.ts +4 -4
  179. package/dest/schemas/parse.d.ts.map +1 -1
  180. package/dest/schemas/parse.js +6 -5
  181. package/dest/schemas/schemas.d.ts +15 -15
  182. package/dest/schemas/types.d.ts +3 -3
  183. package/dest/schemas/types.d.ts.map +1 -1
  184. package/dest/schemas/utils.d.ts +7 -11
  185. package/dest/schemas/utils.d.ts.map +1 -1
  186. package/dest/schemas/utils.js +2 -18
  187. package/dest/serialize/buffer_reader.d.ts +8 -1
  188. package/dest/serialize/buffer_reader.d.ts.map +1 -1
  189. package/dest/serialize/buffer_reader.js +13 -0
  190. package/dest/serialize/buffer_sink.d.ts +134 -0
  191. package/dest/serialize/buffer_sink.d.ts.map +1 -0
  192. package/dest/serialize/buffer_sink.js +297 -0
  193. package/dest/serialize/index.d.ts +2 -1
  194. package/dest/serialize/index.d.ts.map +1 -1
  195. package/dest/serialize/index.js +1 -0
  196. package/dest/serialize/serialize.d.ts +19 -1
  197. package/dest/serialize/serialize.d.ts.map +1 -1
  198. package/dest/serialize/serialize.js +31 -0
  199. package/dest/sleep/index.d.ts +2 -1
  200. package/dest/sleep/index.d.ts.map +1 -1
  201. package/dest/sleep/index.js +10 -1
  202. package/dest/string/index.js +1 -1
  203. package/dest/testing/files/index.d.ts +2 -3
  204. package/dest/testing/files/index.d.ts.map +1 -1
  205. package/dest/testing/files/index.js +1 -2
  206. package/dest/timer/date.d.ts +25 -1
  207. package/dest/timer/date.d.ts.map +1 -1
  208. package/dest/timer/date.js +33 -0
  209. package/dest/timer/index.d.ts +2 -2
  210. package/dest/timer/index.d.ts.map +1 -1
  211. package/dest/timer/index.js +1 -1
  212. package/dest/timer/timeout.d.ts +3 -1
  213. package/dest/timer/timeout.d.ts.map +1 -1
  214. package/dest/timer/timeout.js +26 -0
  215. package/dest/transport/dispatch/create_dispatch_proxy.d.ts +11 -2
  216. package/dest/transport/dispatch/create_dispatch_proxy.d.ts.map +1 -1
  217. package/dest/transport/index.d.ts +1 -2
  218. package/dest/transport/index.d.ts.map +1 -1
  219. package/dest/transport/index.js +0 -1
  220. package/dest/transport/transport_client.js +2 -2
  221. package/dest/trees/balanced_merkle_tree_root.d.ts +3 -5
  222. package/dest/trees/balanced_merkle_tree_root.d.ts.map +1 -1
  223. package/dest/trees/balanced_merkle_tree_root.js +3 -5
  224. package/dest/trees/hasher.d.ts +3 -3
  225. package/dest/trees/hasher.d.ts.map +1 -1
  226. package/dest/trees/hasher.js +5 -10
  227. package/dest/trees/indexed_merkle_tree_calculator.d.ts +1 -1
  228. package/dest/trees/indexed_merkle_tree_calculator.d.ts.map +1 -1
  229. package/dest/trees/indexed_merkle_tree_calculator.js +5 -1
  230. package/dest/trees/membership_witness.d.ts +2 -2
  231. package/dest/trees/membership_witness.d.ts.map +1 -1
  232. package/dest/trees/merkle_tree_calculator.d.ts +4 -2
  233. package/dest/trees/merkle_tree_calculator.d.ts.map +1 -1
  234. package/dest/trees/merkle_tree_calculator.js +1 -5
  235. package/dest/trees/sibling_path.d.ts +5 -4
  236. package/dest/trees/sibling_path.d.ts.map +1 -1
  237. package/dest/trees/sibling_path.js +10 -8
  238. package/dest/trees/unbalanced_merkle_tree_root.d.ts +2 -3
  239. package/dest/trees/unbalanced_merkle_tree_root.d.ts.map +1 -1
  240. package/dest/trees/unbalanced_merkle_tree_root.js +2 -3
  241. package/dest/types/index.d.ts +25 -1
  242. package/dest/types/index.d.ts.map +1 -1
  243. package/dest/types/index.js +18 -0
  244. package/package.json +27 -4
  245. package/src/array/sorted_array.ts +22 -17
  246. package/src/bigint-buffer/index.ts +6 -1
  247. package/src/branded-types/block_number.ts +20 -2
  248. package/src/branded-types/buffer32_hash.ts +38 -0
  249. package/src/branded-types/checkpoint_number.ts +16 -1
  250. package/src/branded-types/epoch.ts +1 -1
  251. package/src/branded-types/index.ts +1 -0
  252. package/src/branded-types/index_within_checkpoint.ts +1 -1
  253. package/src/branded-types/slot.ts +6 -1
  254. package/src/buffer/buffer16.ts +3 -0
  255. package/src/buffer/buffer32.ts +39 -68
  256. package/src/buffer/index.ts +1 -0
  257. package/src/buffer/utils.ts +8 -0
  258. package/src/collection/array.ts +86 -0
  259. package/src/collection/index.ts +2 -0
  260. package/src/collection/lru_map.ts +143 -0
  261. package/src/collection/lru_set.ts +115 -0
  262. package/src/committable/committable.ts +1 -1
  263. package/src/config/env_var.ts +97 -23
  264. package/src/config/index.ts +157 -121
  265. package/src/config/network_config.ts +3 -0
  266. package/src/config/network_name.ts +6 -6
  267. package/src/config/secret_value.ts +1 -1
  268. package/src/crypto/aes128/index.ts +11 -2
  269. package/src/crypto/bls/bn254_keystore.ts +33 -43
  270. package/src/crypto/keys/index.ts +20 -4
  271. package/src/crypto/poseidon/index.ts +42 -44
  272. package/src/crypto/random/randomness_singleton.ts +9 -5
  273. package/src/crypto/schnorr/index.ts +9 -8
  274. package/src/crypto/schnorr/signature.ts +17 -46
  275. package/src/crypto/secp256k1-signer/utils.ts +32 -0
  276. package/src/crypto/sync/poseidon/index.ts +0 -9
  277. package/src/curves/bls12/field.ts +0 -7
  278. package/src/curves/bn254/field.ts +41 -36
  279. package/src/curves/grumpkin/point.ts +23 -40
  280. package/src/eth-address/index.ts +0 -4
  281. package/src/eth-signature/eth_signature.ts +7 -1
  282. package/src/fifo/fifo_frame_reader.ts +113 -0
  283. package/src/fifo/index.ts +1 -0
  284. package/src/fifo_set/fifo_set.ts +52 -0
  285. package/src/fifo_set/index.ts +1 -0
  286. package/src/jest/setup.mjs +31 -1
  287. package/src/json-rpc/client/fetch.ts +4 -3
  288. package/src/json-rpc/client/safe_json_rpc_client.ts +4 -2
  289. package/src/json-rpc/client/undici.ts +23 -3
  290. package/src/json-rpc/fixtures/test_state.ts +10 -10
  291. package/src/json-rpc/server/api_key_auth.ts +63 -0
  292. package/src/json-rpc/server/index.ts +1 -0
  293. package/src/json-rpc/server/safe_json_rpc_server.ts +32 -14
  294. package/src/log/bigint-utils.ts +25 -0
  295. package/src/log/gcloud-logger-config.ts +5 -0
  296. package/src/log/libp2p_logger.ts +12 -5
  297. package/src/log/log-filters.ts +29 -11
  298. package/src/log/pino-logger-server.ts +25 -0
  299. package/src/log/pino-logger.ts +160 -39
  300. package/src/noir/noir_package_config.ts +32 -20
  301. package/src/promise/running-promise.ts +8 -5
  302. package/src/queue/base_memory_queue.ts +1 -1
  303. package/src/queue/batch_queue.ts +1 -0
  304. package/src/queue/semaphore.ts +5 -0
  305. package/src/retry/index.ts +66 -4
  306. package/src/schemas/api.ts +25 -25
  307. package/src/schemas/parse.ts +9 -6
  308. package/src/schemas/schemas.ts +4 -4
  309. package/src/schemas/types.ts +2 -2
  310. package/src/schemas/utils.ts +4 -38
  311. package/src/serialize/buffer_reader.ts +15 -0
  312. package/src/serialize/buffer_sink.ts +350 -0
  313. package/src/serialize/index.ts +1 -0
  314. package/src/serialize/serialize.ts +32 -0
  315. package/src/sleep/index.ts +10 -1
  316. package/src/string/index.ts +1 -1
  317. package/src/testing/files/index.ts +1 -2
  318. package/src/timer/date.ts +48 -0
  319. package/src/timer/index.ts +1 -1
  320. package/src/timer/timeout.ts +31 -0
  321. package/src/transport/dispatch/create_dispatch_proxy.ts +11 -1
  322. package/src/transport/index.ts +0 -1
  323. package/src/transport/transport_client.ts +2 -2
  324. package/src/trees/balanced_merkle_tree_root.ts +3 -9
  325. package/src/trees/hasher.ts +6 -7
  326. package/src/trees/indexed_merkle_tree_calculator.ts +5 -1
  327. package/src/trees/merkle_tree_calculator.ts +4 -10
  328. package/src/trees/sibling_path.ts +11 -6
  329. package/src/trees/unbalanced_merkle_tree_root.ts +2 -5
  330. package/src/types/index.ts +52 -0
  331. package/dest/crypto/serialize.d.ts +0 -51
  332. package/dest/crypto/serialize.d.ts.map +0 -1
  333. package/dest/crypto/serialize.js +0 -68
  334. package/dest/transport/dispatch/create_dispatch_fn.d.ts +0 -25
  335. package/dest/transport/dispatch/create_dispatch_fn.d.ts.map +0 -1
  336. package/dest/transport/dispatch/create_dispatch_fn.js +0 -17
  337. package/src/crypto/serialize.ts +0 -85
  338. package/src/transport/dispatch/create_dispatch_fn.ts +0 -35
package/package.json CHANGED
@@ -1,9 +1,29 @@
1
1
  {
2
2
  "name": "@aztec/foundation",
3
- "version": "0.0.1-commit.d431d1c",
3
+ "version": "0.0.1-commit.d58ff9d0",
4
4
  "type": "module",
5
5
  "main": "./dest/index.js",
6
6
  "types": "./dest/index.d.ts",
7
+ "typedocOptions": {
8
+ "entryPoints": [
9
+ "./src/buffer/index.ts",
10
+ "./src/collection/index.ts",
11
+ "./src/config/index.ts",
12
+ "./src/crypto/random/index.ts",
13
+ "./src/error/index.ts",
14
+ "./src/eth-address/index.ts",
15
+ "./src/json-rpc/index.ts",
16
+ "./src/log/index.ts",
17
+ "./src/retry/index.ts",
18
+ "./src/schemas/index.ts",
19
+ "./src/serialize/index.ts",
20
+ "./src/sleep/index.ts",
21
+ "./src/timer/index.ts",
22
+ "./src/types/index.ts"
23
+ ],
24
+ "name": "Foundation",
25
+ "tsconfig": "./tsconfig.json"
26
+ },
7
27
  "exports": {
8
28
  "./eslint": "./eslint.config.js",
9
29
  "./eslint.docs": "./eslint.config.docs.js",
@@ -41,6 +61,8 @@
41
61
  "./eth-address": "./dest/eth-address/index.js",
42
62
  "./eth-signature": "./dest/eth-signature/index.js",
43
63
  "./queue": "./dest/queue/index.js",
64
+ "./fifo": "./dest/fifo/index.js",
65
+ "./fifo-set": "./dest/fifo_set/index.js",
44
66
  "./fs": "./dest/fs/index.js",
45
67
  "./buffer": "./dest/buffer/index.js",
46
68
  "./json-rpc": "./dest/json-rpc/index.js",
@@ -51,6 +73,7 @@
51
73
  "./iterable": "./dest/iterable/index.js",
52
74
  "./iterator": "./dest/iterator/index.js",
53
75
  "./log": "./dest/log/index.js",
76
+ "./log/server": "./dest/log/pino-logger-server.js",
54
77
  "./mutex": "./dest/mutex/index.js",
55
78
  "./retry": "./dest/retry/index.js",
56
79
  "./running-promise": "./dest/running-promise/index.js",
@@ -123,12 +146,12 @@
123
146
  "testEnvironment": "../../foundation/src/jest/env.mjs"
124
147
  },
125
148
  "dependencies": {
126
- "@aztec/bb.js": "0.0.1-commit.d431d1c",
149
+ "@aztec/bb.js": "0.0.1-commit.d58ff9d0",
127
150
  "@koa/cors": "^5.0.0",
128
151
  "@noble/curves": "=1.7.0",
129
152
  "@noble/hashes": "^1.6.1",
130
153
  "@scure/bip39": "^2.0.1",
131
- "bn.js": "^5.2.1",
154
+ "bn.js": "^5.2.3",
132
155
  "colorette": "^2.0.20",
133
156
  "detect-node": "^2.1.0",
134
157
  "hash.js": "^1.1.7",
@@ -144,7 +167,7 @@
144
167
  "pino-pretty": "^13.0.0",
145
168
  "sha3": "^2.1.4",
146
169
  "undici": "^5.28.5",
147
- "zod": "^3.23.8"
170
+ "zod": "^4"
148
171
  },
149
172
  "devDependencies": {
150
173
  "@jest/globals": "^30.0.0",
@@ -21,34 +21,39 @@ export function dedupeSortedArray<T>(arr: T[], cmp: Cmp<T>): void {
21
21
  }
22
22
 
23
23
  export function insertIntoSortedArray<T>(arr: T[], item: T, cmp: Cmp<T>, allowDuplicates = true): boolean {
24
+ const index = findInsertionIndexInSortedArray(arr, item, cmp);
25
+
26
+ if (!allowDuplicates) {
27
+ // Check element before insertion point (upper bound returns index after equal elements)
28
+ if (index > 0 && cmp(arr[index - 1], item) === 0) {
29
+ return false;
30
+ }
31
+ }
32
+
33
+ arr.splice(index, 0, item);
34
+ return true;
35
+ }
36
+
37
+ /**
38
+ * Finds the index where needle would be inserted to maintain sorted order.
39
+ * Returns the count of elements less than or equal to needle.
40
+ */
41
+ export function findInsertionIndexInSortedArray<T, N>(values: T[], needle: N, cmp: (a: T, b: N) => number): number {
24
42
  let start = 0;
25
- let end = arr.length;
43
+ let end = values.length;
26
44
 
27
45
  while (start < end) {
28
46
  const mid = start + (((end - start) / 2) | 0);
29
- const comparison = cmp(arr[mid], item);
47
+ const comparison = cmp(values[mid], needle);
30
48
 
31
- if (comparison < 0) {
49
+ if (comparison <= 0) {
32
50
  start = mid + 1;
33
51
  } else {
34
52
  end = mid;
35
53
  }
36
54
  }
37
55
 
38
- if (!allowDuplicates) {
39
- // Check element at insertion point
40
- if (start < arr.length && cmp(arr[start], item) === 0) {
41
- return false;
42
- }
43
-
44
- // Check element before insertion point (in case we landed after duplicates)
45
- if (start > 0 && cmp(arr[start - 1], item) === 0) {
46
- return false;
47
- }
48
- }
49
-
50
- arr.splice(start, 0, item);
51
- return true;
56
+ return start;
52
57
  }
53
58
 
54
59
  export function findIndexInSortedArray<T, N>(values: T[], needle: N, cmp: (a: T, b: N) => number): number {
@@ -49,9 +49,14 @@ export function toBufferLE(num: bigint, width: number): Buffer {
49
49
  * @returns A big-endian buffer representation of num.
50
50
  */
51
51
  export function toBufferBE(num: bigint, width: number): Buffer {
52
- if (num < BigInt(0)) {
52
+ if (num < 0n) {
53
53
  throw new Error(`Cannot convert negative bigint ${num.toString()} to buffer with toBufferBE.`);
54
54
  }
55
+ // The values serialized in the hot paths are overwhelmingly zero (field elements are mostly
56
+ // zero-padding in protocol structs), and the hex round-trip is wasteful for them.
57
+ if (num === 0n) {
58
+ return Buffer.alloc(width);
59
+ }
55
60
  const hex = num.toString(16);
56
61
  const buffer = Buffer.from(hex.padStart(width * 2, '0').slice(0, width * 2), 'hex');
57
62
  if (buffer.length > width) {
@@ -98,9 +98,27 @@ BlockNumber.add = function (bn: BlockNumber, increment: number): BlockNumber {
98
98
  BlockNumber.ZERO = BlockNumber(0);
99
99
 
100
100
  function makeBlockNumberSchema(minValue: number) {
101
+ const max = Number.MAX_SAFE_INTEGER;
101
102
  return z
102
- .union([z.number(), z.bigint(), z.string()])
103
- .pipe(z.coerce.number().int().min(minValue))
103
+ .union([
104
+ z.number().int().min(minValue).max(max),
105
+ z
106
+ .bigint()
107
+ .min(BigInt(minValue))
108
+ .max(BigInt(max))
109
+ .transform(v => Number(v)),
110
+ z
111
+ .string()
112
+ .regex(/^\d+$/, 'BlockNumber string must be a non-negative decimal integer')
113
+ .transform((v, ctx) => {
114
+ const parsed = Number(v);
115
+ if (!Number.isInteger(parsed) || parsed > max || parsed < minValue) {
116
+ ctx.addIssue({ code: z.ZodIssueCode.custom, message: `BlockNumber out of range: ${v}` });
117
+ return z.NEVER;
118
+ }
119
+ return parsed;
120
+ }),
121
+ ])
104
122
  .transform(value => BlockNumber(value));
105
123
  }
106
124
 
@@ -0,0 +1,38 @@
1
+ import type { Branded } from './types.js';
2
+
3
+ /**
4
+ * A branded `0x`-prefixed hex string representing a checkpoint proposal payload hash.
5
+ *
6
+ * A `CheckpointProposal` and the matching `CheckpointAttestation` sign the same
7
+ * `ConsensusPayload`, so they share this hash type. Used by the p2p attestation
8
+ * pool to dedup signed payloads and detect equivocations.
9
+ */
10
+ export type CheckpointProposalHash = Branded<`0x${string}`, 'CheckpointProposalHash'>;
11
+
12
+ /** Brands a `0x`-prefixed hex string as a CheckpointProposalHash. */
13
+ export function CheckpointProposalHash(s: `0x${string}`): CheckpointProposalHash {
14
+ return s as CheckpointProposalHash;
15
+ }
16
+
17
+ /** Constructs a CheckpointProposalHash from a raw 32-byte hash buffer. */
18
+ CheckpointProposalHash.fromBuffer = function (buf: Buffer): CheckpointProposalHash {
19
+ return `0x${buf.toString('hex')}` as CheckpointProposalHash;
20
+ };
21
+
22
+ /**
23
+ * A branded `0x`-prefixed hex string representing a block proposal payload hash.
24
+ *
25
+ * Used by the p2p attestation pool to dedup signed payloads at a given
26
+ * `(slot, indexWithinCheckpoint)` and detect equivocations.
27
+ */
28
+ export type BlockProposalHash = Branded<`0x${string}`, 'BlockProposalHash'>;
29
+
30
+ /** Brands a `0x`-prefixed hex string as a BlockProposalHash. */
31
+ export function BlockProposalHash(s: `0x${string}`): BlockProposalHash {
32
+ return s as BlockProposalHash;
33
+ }
34
+
35
+ /** Constructs a BlockProposalHash from a raw 32-byte hash buffer. */
36
+ BlockProposalHash.fromBuffer = function (buf: Buffer): BlockProposalHash {
37
+ return `0x${buf.toString('hex')}` as BlockProposalHash;
38
+ };
@@ -1,5 +1,6 @@
1
1
  import { z } from 'zod';
2
2
 
3
+ import { isDefined } from '../types/index.js';
3
4
  import type { BlockNumber } from './block_number.js';
4
5
  import type { Branded } from './types.js';
5
6
 
@@ -85,6 +86,20 @@ CheckpointNumber.isValid = function (value: unknown): value is CheckpointNumber
85
86
  return typeof value === 'number' && Number.isInteger(value) && value >= 0;
86
87
  };
87
88
 
89
+ /** Increments a CheckpointNumber by a given value. */
90
+ CheckpointNumber.add = function (n: CheckpointNumber, increment: number): CheckpointNumber {
91
+ return CheckpointNumber(n + increment);
92
+ };
93
+
94
+ /** Computes max of a set of checkpoint numbers, ignoring undefined values. */
95
+ CheckpointNumber.max = function (...values: (CheckpointNumber | undefined)[]): CheckpointNumber | undefined {
96
+ const filtered = values.filter(isDefined);
97
+ if (filtered.length === 0) {
98
+ return undefined;
99
+ }
100
+ return CheckpointNumber(Math.max(...filtered));
101
+ };
102
+
88
103
  /** The zero checkpoint value. */
89
104
  CheckpointNumber.ZERO = CheckpointNumber(0);
90
105
 
@@ -98,7 +113,7 @@ CheckpointNumber.INITIAL = CheckpointNumber(1);
98
113
  function makeCheckpointNumberSchema(minValue: number) {
99
114
  return z
100
115
  .union([z.number(), z.bigint(), z.string()])
101
- .pipe(z.coerce.number().int().min(minValue))
116
+ .pipe(z.coerce.number<string | number | bigint>().int().min(minValue))
102
117
  .transform(value => CheckpointNumber(value));
103
118
  }
104
119
 
@@ -84,5 +84,5 @@ EpochNumber.ZERO = EpochNumber(0);
84
84
  */
85
85
  export const EpochNumberSchema = z
86
86
  .union([z.number(), z.bigint(), z.string()])
87
- .pipe(z.coerce.number().int().min(0))
87
+ .pipe(z.coerce.number<string | number | bigint>().int().min(0))
88
88
  .transform(value => EpochNumber(value));
@@ -1,4 +1,5 @@
1
1
  export { BlockNumber, BlockNumberSchema, BlockNumberPositiveSchema } from './block_number.js';
2
+ export { BlockProposalHash, CheckpointProposalHash } from './buffer32_hash.js';
2
3
  export { CheckpointNumber, CheckpointNumberSchema, CheckpointNumberPositiveSchema } from './checkpoint_number.js';
3
4
  export { EpochNumber, EpochNumberSchema } from './epoch.js';
4
5
  export { IndexWithinCheckpoint, IndexWithinCheckpointSchema } from './index_within_checkpoint.js';
@@ -84,5 +84,5 @@ IndexWithinCheckpoint.ZERO = IndexWithinCheckpoint(0);
84
84
  */
85
85
  export const IndexWithinCheckpointSchema = z
86
86
  .union([z.number(), z.bigint(), z.string()])
87
- .pipe(z.coerce.number().int().min(0))
87
+ .pipe(z.coerce.number<string | number | bigint>().int().min(0))
88
88
  .transform(value => IndexWithinCheckpoint(value));
@@ -73,6 +73,11 @@ SlotNumber.isValid = function (value: unknown): value is SlotNumber {
73
73
  return typeof value === 'number' && Number.isInteger(value) && value >= 0;
74
74
  };
75
75
 
76
+ /** Increments a SlotNumber by a given value. */
77
+ SlotNumber.add = function (sn: SlotNumber, increment: number): SlotNumber {
78
+ return SlotNumber(sn + increment);
79
+ };
80
+
76
81
  /**
77
82
  * The zero slot value.
78
83
  */
@@ -84,5 +89,5 @@ SlotNumber.ZERO = SlotNumber(0);
84
89
  */
85
90
  export const SlotNumberSchema = z
86
91
  .union([z.number(), z.bigint(), z.string()])
87
- .pipe(z.coerce.number().int().min(0))
92
+ .pipe(z.coerce.number<string | number | bigint>().int().min(0))
88
93
  .transform(value => SlotNumber(value));
@@ -10,6 +10,9 @@ import { bufferToHex } from '../string/index.js';
10
10
  * A class representing a 16 byte Buffer.
11
11
  */
12
12
  export class Buffer16 {
13
+ /** Branding for nominal typing. */
14
+ declare private readonly _branding: 'Buffer16';
15
+
13
16
  /**
14
17
  * The size of the hash in bytes.
15
18
  */
@@ -7,69 +7,39 @@ import { inspect } from 'util';
7
7
  import { bufferToHex } from '../string/index.js';
8
8
 
9
9
  /**
10
- * A class representing a 32 byte Buffer.
10
+ * Abstract unbranded base class for 32-byte buffers.
11
+ * Extend this instead of Buffer32 when defining a branded subtype
12
+ * to avoid inheriting Buffer32's `_branding`.
11
13
  */
12
- export class Buffer32 {
13
- /**
14
- * The size of the hash in bytes.
15
- */
14
+ export abstract class BaseBuffer32 {
15
+ /** The size of the buffer in bytes. */
16
16
  public static SIZE = 32;
17
17
 
18
- /**
19
- * Buffer32 with value zero.
20
- */
21
- public static ZERO = new Buffer32(Buffer.alloc(Buffer32.SIZE));
22
-
23
18
  constructor(
24
- /**
25
- * The buffer containing the hash.
26
- */
19
+ /** The buffer containing the data. */
27
20
  public buffer: Buffer,
28
21
  ) {
29
- if (buffer.length !== Buffer32.SIZE) {
30
- throw new Error(`Expected buffer to have length ${Buffer32.SIZE} but was ${buffer.length}`);
22
+ if (buffer.length !== BaseBuffer32.SIZE) {
23
+ throw new Error(`Expected buffer to have length ${BaseBuffer32.SIZE} but was ${buffer.length}`);
31
24
  }
32
25
  }
33
26
 
34
- /**
35
- * Returns the raw buffer of the hash.
36
- * @returns The buffer containing the hash.
37
- */
27
+ /** Returns the raw buffer. */
38
28
  public toBuffer() {
39
29
  return this.buffer;
40
30
  }
41
31
 
42
- /**
43
- * Creates a Buffer32 from a buffer.
44
- * @param buffer - The buffer to create from.
45
- * @returns A new Buffer32 object.
46
- */
47
- public static fromBuffer(buffer: Buffer | BufferReader) {
48
- const reader = BufferReader.asReader(buffer);
49
- return new Buffer32(reader.readBytes(Buffer32.SIZE));
50
- }
51
-
52
- /**
53
- * Checks if this hash and another hash are equal.
54
- * @param hash - A hash to compare with.
55
- * @returns True if the hashes are equal, false otherwise.
56
- */
57
- public equals(hash: Buffer32): boolean {
32
+ /** Checks if this and another buffer are equal. */
33
+ public equals(hash: BaseBuffer32): boolean {
58
34
  return this.buffer.equals(hash.buffer);
59
35
  }
60
36
 
61
- /**
62
- * Returns true if this hash is zero.
63
- * @returns True if this hash is zero.
64
- */
37
+ /** Returns true if all bytes are zero. */
65
38
  public isZero(): boolean {
66
39
  return this.buffer.equals(Buffer.alloc(32, 0));
67
40
  }
68
41
 
69
- /**
70
- * Convert this hash to a hex string.
71
- * @returns The hex string.
72
- */
42
+ /** Convert to a hex string. */
73
43
  public toString() {
74
44
  return bufferToHex(this.buffer);
75
45
  }
@@ -82,16 +52,27 @@ export class Buffer32 {
82
52
  return this.toString();
83
53
  }
84
54
 
85
- /**
86
- * Convert this hash to a big int.
87
- * @returns The big int.
88
- */
55
+ /** Convert to a big int. */
89
56
  public toBigInt() {
90
- return deserializeBigInt(this.buffer, 0, Buffer32.SIZE).elem;
57
+ return deserializeBigInt(this.buffer, 0, BaseBuffer32.SIZE).elem;
91
58
  }
92
- /**
93
- * Creates a Buffer32 from a bigint.
94
- */
59
+ }
60
+
61
+ /** A branded 32-byte buffer. */
62
+ export class Buffer32 extends BaseBuffer32 {
63
+ /** Branding for nominal typing. */
64
+ declare private readonly _branding: 'Buffer32';
65
+
66
+ /** Buffer32 with value zero. */
67
+ public static ZERO = new Buffer32(Buffer.alloc(Buffer32.SIZE));
68
+
69
+ /** Creates a Buffer32 from a buffer. */
70
+ public static fromBuffer(buffer: Buffer | BufferReader) {
71
+ const reader = BufferReader.asReader(buffer);
72
+ return new Buffer32(reader.readBytes(Buffer32.SIZE));
73
+ }
74
+
75
+ /** Creates a Buffer32 from a bigint. */
95
76
  public static fromBigInt(hash: bigint) {
96
77
  return new Buffer32(serializeBigInt(hash, Buffer32.SIZE));
97
78
  }
@@ -101,8 +82,7 @@ export class Buffer32 {
101
82
  }
102
83
 
103
84
  /**
104
- * Converts this hash from a buffer of 28 bytes.
105
- * Verifies the input is 28 bytes.
85
+ * Converts from a buffer of 28 bytes.
106
86
  * @param buffer - The 28 byte buffer to construct from.
107
87
  * @returns A Buffer32 created from the input buffer with 4 bytes 0 padding at the front.
108
88
  */
@@ -110,36 +90,27 @@ export class Buffer32 {
110
90
  if (buffer.length != 28) {
111
91
  throw new Error(`Expected Buffer32 input buffer to be 28 bytes`);
112
92
  }
113
- const padded = Buffer.concat([Buffer.alloc(this.SIZE - 28), buffer]);
93
+ const padded = Buffer.concat([Buffer.alloc(Buffer32.SIZE - 28), buffer]);
114
94
  return new Buffer32(padded);
115
95
  }
116
96
 
117
- /**
118
- * Converts a string into a Buffer32 object.
119
- */
97
+ /** Converts a string into a Buffer32 object. */
120
98
  public static fromString(str: string): Buffer32 {
121
99
  if (str.startsWith('0x')) {
122
100
  str = str.slice(2);
123
101
  }
124
- if (str.length !== this.SIZE * 2) {
125
- throw new Error(`Expected string to be ${this.SIZE * 2} characters long, but was ${str.length}`);
102
+ if (str.length !== Buffer32.SIZE * 2) {
103
+ throw new Error(`Expected string to be ${Buffer32.SIZE * 2} characters long, but was ${str.length}`);
126
104
  }
127
105
  return new Buffer32(Buffer.from(str, 'hex'));
128
106
  }
129
107
 
130
- /**
131
- * Converts a number into a Buffer32 object.
132
- * @param num - The number to convert.
133
- * @returns A new Buffer32 object.
134
- */
108
+ /** Converts a number into a Buffer32 object. */
135
109
  public static fromNumber(num: number): Buffer32 {
136
110
  return new Buffer32(serializeBigInt(BigInt(num), Buffer32.SIZE));
137
111
  }
138
112
 
139
- /**
140
- * Generates a random Buffer32.
141
- * @returns A new Buffer32 object.
142
- */
113
+ /** Generates a random Buffer32. */
143
114
  public static random(): Buffer32 {
144
115
  return new Buffer32(Buffer.from(randomBytes(Buffer32.SIZE)));
145
116
  }
@@ -1,2 +1,3 @@
1
1
  export * from './buffer32.js';
2
2
  export * from './buffer16.js';
3
+ export * from './utils.js';
@@ -0,0 +1,8 @@
1
+ /** Returns the number of bytes in the buffer, excluding any trailing zero bytes. */
2
+ export function trimmedBytesLength(buf: Uint8Array): number {
3
+ let end = buf.length;
4
+ while (end > 0 && buf[end - 1] === 0) {
5
+ end--;
6
+ }
7
+ return end;
8
+ }
@@ -138,6 +138,26 @@ export function unique<T>(arr: T[]): T[] {
138
138
  return [...new Set(arr)];
139
139
  }
140
140
 
141
+ /**
142
+ * Removes duplicates from the given array using a key function. The first occurrence of each key is kept.
143
+ * @param arr - The array.
144
+ * @param keyFn - A function that returns a primitive key for each element. Elements with the same key are
145
+ * considered duplicates.
146
+ * @returns A new array.
147
+ */
148
+ export function uniqueBy<T, K extends string | number | bigint>(arr: T[], keyFn: (item: T) => K): T[] {
149
+ const seen = new Set<K>();
150
+ const result: T[] = [];
151
+ for (const item of arr) {
152
+ const key = keyFn(item);
153
+ if (!seen.has(key)) {
154
+ seen.add(key);
155
+ result.push(item);
156
+ }
157
+ }
158
+ return result;
159
+ }
160
+
141
161
  /**
142
162
  * Removes all undefined elements from the array.
143
163
  * @param arr - The array.
@@ -250,6 +270,58 @@ export function chunk<T>(items: T[], chunkSize: number): T[][] {
250
270
  return chunks;
251
271
  }
252
272
 
273
+ /**
274
+ * Splits the given array into chunks of the given size, wrapping around to the beginning
275
+ * if the last chunk would be smaller than the requested size.
276
+ * Returns empty array for empty input. Returns single chunk with all items if chunkSize <= 0.
277
+ */
278
+ export function chunkWrapAround<T>(items: T[], chunkSize: number): T[][] {
279
+ if (items.length === 0) {
280
+ return [];
281
+ }
282
+ if (chunkSize <= 0 || items.length <= chunkSize) {
283
+ return [items];
284
+ }
285
+ const remainder = items.length % chunkSize;
286
+ if (remainder === 0) {
287
+ return chunk(items, chunkSize);
288
+ }
289
+ const wrapAroundCount = chunkSize - remainder;
290
+ const wrappedItems = [...items, ...items.slice(0, wrapAroundCount)];
291
+ return chunk(wrappedItems, chunkSize);
292
+ }
293
+
294
+ const UNINITIALIZED = Symbol('uninitialized');
295
+
296
+ /**
297
+ * Splits the given iterable into chunks based on the key returned by the given function.
298
+ * Items must be contiguous to be included in the same chunk.
299
+ */
300
+ export function chunkBy<T, U>(items: T[], fn: (item: T) => U): T[][] {
301
+ const chunks: T[][] = [];
302
+ let currentChunk: T[] = [];
303
+ let currentKey: U | typeof UNINITIALIZED = UNINITIALIZED;
304
+
305
+ for (const item of items) {
306
+ const key = fn(item);
307
+ if (currentKey === UNINITIALIZED || key !== currentKey) {
308
+ if (currentChunk.length > 0) {
309
+ chunks.push(currentChunk);
310
+ }
311
+ currentChunk = [item];
312
+ currentKey = key;
313
+ } else {
314
+ currentChunk.push(item);
315
+ }
316
+ }
317
+
318
+ if (currentChunk.length > 0) {
319
+ chunks.push(currentChunk);
320
+ }
321
+
322
+ return chunks;
323
+ }
324
+
253
325
  /** Partitions the given iterable into two arrays based on the predicate. */
254
326
  export function partition<T>(items: T[], predicate: (item: T) => boolean): [T[], T[]] {
255
327
  const pass: T[] = [];
@@ -263,3 +335,17 @@ export function partition<T>(items: T[], predicate: (item: T) => boolean): [T[],
263
335
  }
264
336
  return [pass, fail];
265
337
  }
338
+
339
+ /** Partitions the given iterable into two arrays based on the predicate. */
340
+ export async function partitionAsync<T>(items: T[], predicate: (item: T) => Promise<boolean>): Promise<[T[], T[]]> {
341
+ const pass: T[] = [];
342
+ const fail: T[] = [];
343
+ for (const item of items) {
344
+ if (await predicate(item)) {
345
+ pass.push(item);
346
+ } else {
347
+ fail.push(item);
348
+ }
349
+ }
350
+ return [pass, fail];
351
+ }
@@ -1,2 +1,4 @@
1
1
  export * from './array.js';
2
+ export * from './lru_map.js';
3
+ export * from './lru_set.js';
2
4
  export * from './object.js';