@aztec/foundation 0.0.1-commit.b655e406 → 0.0.1-commit.fce3e4f

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 (319) hide show
  1. package/dest/array/array.d.ts +1 -9
  2. package/dest/array/array.d.ts.map +1 -1
  3. package/dest/array/array.js +0 -11
  4. package/dest/array/index.d.ts +1 -1
  5. package/dest/async-map/index.d.ts +1 -1
  6. package/dest/async-pool/index.d.ts +1 -1
  7. package/dest/bigint/index.d.ts +1 -1
  8. package/dest/bigint-buffer/index.d.ts +1 -1
  9. package/dest/branded-types/epoch.d.ts +42 -0
  10. package/dest/branded-types/epoch.d.ts.map +1 -0
  11. package/dest/branded-types/epoch.js +59 -0
  12. package/dest/branded-types/index.d.ts +4 -0
  13. package/dest/branded-types/index.d.ts.map +1 -0
  14. package/dest/branded-types/index.js +2 -0
  15. package/dest/branded-types/slot.d.ts +42 -0
  16. package/dest/branded-types/slot.d.ts.map +1 -0
  17. package/dest/branded-types/slot.js +59 -0
  18. package/dest/branded-types/types.d.ts +5 -0
  19. package/dest/branded-types/types.d.ts.map +1 -0
  20. package/dest/branded-types/types.js +1 -0
  21. package/dest/buffer/buffer16.d.ts +1 -4
  22. package/dest/buffer/buffer16.d.ts.map +1 -1
  23. package/dest/buffer/buffer32.d.ts +1 -4
  24. package/dest/buffer/buffer32.d.ts.map +1 -1
  25. package/dest/buffer/index.d.ts +1 -1
  26. package/dest/collection/array.d.ts +1 -1
  27. package/dest/collection/index.d.ts +1 -1
  28. package/dest/collection/object.d.ts +1 -1
  29. package/dest/committable/committable.d.ts +1 -1
  30. package/dest/committable/committable.d.ts.map +1 -1
  31. package/dest/committable/index.d.ts +1 -1
  32. package/dest/config/env_var.d.ts +2 -2
  33. package/dest/config/env_var.d.ts.map +1 -1
  34. package/dest/config/index.d.ts +1 -1
  35. package/dest/config/network_config.d.ts +1 -1
  36. package/dest/config/network_name.d.ts +1 -1
  37. package/dest/config/secret_value.d.ts +1 -1
  38. package/dest/config/secret_value.d.ts.map +1 -1
  39. package/dest/crypto/aes128/index.d.ts +1 -1
  40. package/dest/crypto/aes128/index.d.ts.map +1 -1
  41. package/dest/crypto/aes128/index.js +2 -6
  42. package/dest/crypto/bls/bn254_keystore.d.ts +15 -15
  43. package/dest/crypto/bls/bn254_keystore.d.ts.map +1 -1
  44. package/dest/crypto/bls/index.d.ts +1 -1
  45. package/dest/crypto/bn254/bn254_utils.d.ts +1 -1
  46. package/dest/crypto/bn254/index.d.ts +1 -1
  47. package/dest/crypto/bn254/index.d.ts.map +1 -1
  48. package/dest/crypto/bn254/index.js +3 -0
  49. package/dest/crypto/ecdsa/index.d.ts +1 -1
  50. package/dest/crypto/ecdsa/index.d.ts.map +1 -1
  51. package/dest/crypto/ecdsa/index.js +4 -12
  52. package/dest/crypto/ecdsa/signature.d.ts +1 -10
  53. package/dest/crypto/ecdsa/signature.d.ts.map +1 -1
  54. package/dest/crypto/grumpkin/index.d.ts +1 -1
  55. package/dest/crypto/grumpkin/index.d.ts.map +1 -1
  56. package/dest/crypto/grumpkin/index.js +5 -15
  57. package/dest/crypto/index.d.ts +1 -1
  58. package/dest/crypto/keccak/index.d.ts +1 -1
  59. package/dest/crypto/keys/index.d.ts +1 -1
  60. package/dest/crypto/keys/index.js +1 -3
  61. package/dest/crypto/pedersen/index.d.ts +1 -1
  62. package/dest/crypto/pedersen/pedersen.noble.d.ts +1 -1
  63. package/dest/crypto/pedersen/pedersen.wasm.d.ts +1 -1
  64. package/dest/crypto/pedersen/pedersen.wasm.js +3 -9
  65. package/dest/crypto/poseidon/index.d.ts +1 -1
  66. package/dest/crypto/poseidon/index.js +5 -15
  67. package/dest/crypto/random/index.d.ts +1 -1
  68. package/dest/crypto/random/index.d.ts.map +1 -1
  69. package/dest/crypto/random/randomness_singleton.d.ts +1 -1
  70. package/dest/crypto/random/randomness_singleton.d.ts.map +1 -1
  71. package/dest/crypto/schnorr/index.d.ts +1 -1
  72. package/dest/crypto/schnorr/index.d.ts.map +1 -1
  73. package/dest/crypto/schnorr/index.js +3 -9
  74. package/dest/crypto/schnorr/signature.d.ts +1 -1
  75. package/dest/crypto/schnorr/signature.d.ts.map +1 -1
  76. package/dest/crypto/secp256k1/index.d.ts +1 -1
  77. package/dest/crypto/secp256k1/index.d.ts.map +1 -1
  78. package/dest/crypto/secp256k1/index.js +3 -9
  79. package/dest/crypto/secp256k1-signer/index.d.ts +1 -1
  80. package/dest/crypto/secp256k1-signer/secp256k1_signer.d.ts +1 -1
  81. package/dest/crypto/secp256k1-signer/secp256k1_signer.d.ts.map +1 -1
  82. package/dest/crypto/secp256k1-signer/utils.d.ts +1 -1
  83. package/dest/crypto/secp256k1-signer/utils.d.ts.map +1 -1
  84. package/dest/crypto/serialize.d.ts +1 -1
  85. package/dest/crypto/sha256/index.d.ts +1 -1
  86. package/dest/crypto/sha256/index.d.ts.map +1 -1
  87. package/dest/crypto/sha512/index.d.ts +2 -2
  88. package/dest/crypto/sha512/index.d.ts.map +1 -1
  89. package/dest/crypto/signature/index.d.ts +1 -1
  90. package/dest/crypto/sync/index.d.ts +1 -1
  91. package/dest/crypto/sync/index.js +1 -3
  92. package/dest/crypto/sync/pedersen/index.d.ts +1 -1
  93. package/dest/crypto/sync/poseidon/index.d.ts +1 -1
  94. package/dest/decorators/index.d.ts +1 -1
  95. package/dest/decorators/memoize.d.ts +1 -1
  96. package/dest/decorators/memoize.d.ts.map +1 -1
  97. package/dest/error/index.d.ts +4 -4
  98. package/dest/error/index.d.ts.map +1 -1
  99. package/dest/eth-address/index.d.ts +10 -1
  100. package/dest/eth-address/index.d.ts.map +1 -1
  101. package/dest/eth-address/index.js +17 -0
  102. package/dest/eth-signature/eth_signature.d.ts +1 -4
  103. package/dest/eth-signature/eth_signature.d.ts.map +1 -1
  104. package/dest/eth-signature/index.d.ts +1 -1
  105. package/dest/fields/bls12_fields.d.ts +1 -1
  106. package/dest/fields/bls12_fields.d.ts.map +1 -1
  107. package/dest/fields/bls12_point.d.ts +1 -10
  108. package/dest/fields/bls12_point.d.ts.map +1 -1
  109. package/dest/fields/coordinate.d.ts +1 -4
  110. package/dest/fields/coordinate.d.ts.map +1 -1
  111. package/dest/fields/fields.d.ts +10 -1
  112. package/dest/fields/fields.d.ts.map +1 -1
  113. package/dest/fields/fields.js +14 -0
  114. package/dest/fields/index.d.ts +1 -1
  115. package/dest/fields/point.d.ts +11 -11
  116. package/dest/fields/point.d.ts.map +1 -1
  117. package/dest/fields/point.js +17 -0
  118. package/dest/fs/index.d.ts +1 -1
  119. package/dest/fs/run_in_dir.d.ts +1 -1
  120. package/dest/fs/try_rm_dir.d.ts +1 -1
  121. package/dest/index.d.ts +2 -1
  122. package/dest/index.d.ts.map +1 -1
  123. package/dest/index.js +1 -0
  124. package/dest/iterable/all.d.ts +1 -1
  125. package/dest/iterable/filter.d.ts +1 -1
  126. package/dest/iterable/index.d.ts +1 -1
  127. package/dest/iterable/isAsyncIt.d.ts +1 -1
  128. package/dest/iterable/map.d.ts +1 -1
  129. package/dest/iterable/peek.d.ts +1 -1
  130. package/dest/iterable/sort.d.ts +1 -1
  131. package/dest/iterable/take.d.ts +1 -1
  132. package/dest/iterable/toArray.d.ts +1 -1
  133. package/dest/json-rpc/client/fetch.d.ts +1 -1
  134. package/dest/json-rpc/client/index.d.ts +1 -1
  135. package/dest/json-rpc/client/safe_json_rpc_client.d.ts +1 -1
  136. package/dest/json-rpc/client/undici.d.ts +1 -1
  137. package/dest/json-rpc/convert.d.ts +1 -1
  138. package/dest/json-rpc/errors.d.ts +1 -1
  139. package/dest/json-rpc/errors.d.ts.map +1 -1
  140. package/dest/json-rpc/fixtures/class_a.d.ts +3 -3
  141. package/dest/json-rpc/fixtures/class_a.d.ts.map +1 -1
  142. package/dest/json-rpc/fixtures/class_b.d.ts +3 -3
  143. package/dest/json-rpc/fixtures/class_b.d.ts.map +1 -1
  144. package/dest/json-rpc/fixtures/test_state.d.ts +1 -1
  145. package/dest/json-rpc/fixtures/test_state.d.ts.map +1 -1
  146. package/dest/json-rpc/index.d.ts +1 -1
  147. package/dest/json-rpc/js_utils.d.ts +1 -1
  148. package/dest/json-rpc/js_utils.d.ts.map +1 -1
  149. package/dest/json-rpc/server/index.d.ts +1 -1
  150. package/dest/json-rpc/server/safe_json_rpc_server.d.ts +1 -1
  151. package/dest/json-rpc/server/safe_json_rpc_server.d.ts.map +1 -1
  152. package/dest/json-rpc/server/telemetry.d.ts +1 -1
  153. package/dest/json-rpc/test/index.d.ts +1 -1
  154. package/dest/json-rpc/test/integration.d.ts +1 -1
  155. package/dest/log/console.d.ts +1 -1
  156. package/dest/log/gcloud-logger-config.d.ts +1 -1
  157. package/dest/log/gcloud-logger-config.d.ts.map +1 -1
  158. package/dest/log/index.d.ts +1 -1
  159. package/dest/log/libp2p_logger.d.ts +1 -1
  160. package/dest/log/log-filters.d.ts +1 -1
  161. package/dest/log/log-levels.d.ts +1 -1
  162. package/dest/log/log_fn.d.ts +1 -1
  163. package/dest/log/noir_debug_log_util.d.ts +1 -1
  164. package/dest/log/pino-logger.d.ts +2 -2
  165. package/dest/message/index.d.ts +1 -1
  166. package/dest/message/index.d.ts.map +1 -1
  167. package/dest/mutex/index.d.ts +1 -1
  168. package/dest/mutex/index.d.ts.map +1 -1
  169. package/dest/mutex/mutex_database.d.ts +1 -1
  170. package/dest/noir/index.d.ts +1 -1
  171. package/dest/noir/noir_package_config.d.ts +9 -9
  172. package/dest/number/index.d.ts +1 -1
  173. package/dest/profiler/index.d.ts +1 -1
  174. package/dest/profiler/profiler.d.ts +1 -1
  175. package/dest/promise/index.d.ts +1 -1
  176. package/dest/promise/running-promise.d.ts +1 -1
  177. package/dest/promise/running-promise.d.ts.map +1 -1
  178. package/dest/promise/utils.d.ts +1 -1
  179. package/dest/queue/base_memory_queue.d.ts +1 -1
  180. package/dest/queue/base_memory_queue.d.ts.map +1 -1
  181. package/dest/queue/batch_queue.d.ts +1 -1
  182. package/dest/queue/batch_queue.d.ts.map +1 -1
  183. package/dest/queue/bounded_serial_queue.d.ts +1 -1
  184. package/dest/queue/bounded_serial_queue.d.ts.map +1 -1
  185. package/dest/queue/fifo_memory_queue.d.ts +1 -1
  186. package/dest/queue/fifo_memory_queue.d.ts.map +1 -1
  187. package/dest/queue/index.d.ts +1 -1
  188. package/dest/queue/priority_memory_queue.d.ts +1 -1
  189. package/dest/queue/priority_memory_queue.d.ts.map +1 -1
  190. package/dest/queue/priority_queue.d.ts +1 -1
  191. package/dest/queue/priority_queue.d.ts.map +1 -1
  192. package/dest/queue/semaphore.d.ts +1 -1
  193. package/dest/queue/semaphore.d.ts.map +1 -1
  194. package/dest/queue/serial_queue.d.ts +1 -1
  195. package/dest/queue/serial_queue.d.ts.map +1 -1
  196. package/dest/retry/index.d.ts +1 -1
  197. package/dest/running-promise/index.d.ts +1 -1
  198. package/dest/schemas/api.d.ts +1 -1
  199. package/dest/schemas/index.d.ts +1 -1
  200. package/dest/schemas/parse.d.ts +1 -1
  201. package/dest/schemas/schemas.d.ts +9 -15
  202. package/dest/schemas/schemas.d.ts.map +1 -1
  203. package/dest/schemas/schemas.js +5 -7
  204. package/dest/schemas/types.d.ts +1 -1
  205. package/dest/schemas/utils.d.ts +4 -4
  206. package/dest/schemas/utils.d.ts.map +1 -1
  207. package/dest/schemas/utils.js +15 -5
  208. package/dest/serialize/buffer_reader.d.ts +1 -1
  209. package/dest/serialize/buffer_reader.d.ts.map +1 -1
  210. package/dest/serialize/field_reader.d.ts +1 -1
  211. package/dest/serialize/field_reader.d.ts.map +1 -1
  212. package/dest/serialize/free_funcs.d.ts +1 -1
  213. package/dest/serialize/index.d.ts +1 -1
  214. package/dest/serialize/serialize.d.ts +1 -1
  215. package/dest/serialize/type_registry.d.ts +1 -1
  216. package/dest/serialize/type_registry.d.ts.map +1 -1
  217. package/dest/serialize/types.d.ts +1 -1
  218. package/dest/sleep/index.d.ts +1 -1
  219. package/dest/sleep/index.d.ts.map +1 -1
  220. package/dest/string/index.d.ts +1 -1
  221. package/dest/testing/files/index.d.ts +2 -1
  222. package/dest/testing/files/index.d.ts.map +1 -1
  223. package/dest/testing/files/index.js +1 -1
  224. package/dest/testing/formatting.d.ts +1 -1
  225. package/dest/testing/index.d.ts +1 -1
  226. package/dest/testing/port_allocator.d.ts +1 -1
  227. package/dest/testing/snapshot_serializer.d.ts +1 -1
  228. package/dest/testing/test_data.d.ts +1 -1
  229. package/dest/timer/date.d.ts +1 -1
  230. package/dest/timer/date.d.ts.map +1 -1
  231. package/dest/timer/elapsed.d.ts +1 -1
  232. package/dest/timer/index.d.ts +1 -1
  233. package/dest/timer/timeout.d.ts +1 -1
  234. package/dest/timer/timeout.d.ts.map +1 -1
  235. package/dest/timer/timer.d.ts +1 -1
  236. package/dest/timer/timer.d.ts.map +1 -1
  237. package/dest/transport/dispatch/create_dispatch_fn.d.ts +1 -1
  238. package/dest/transport/dispatch/create_dispatch_fn.d.ts.map +1 -1
  239. package/dest/transport/dispatch/create_dispatch_proxy.d.ts +1 -1
  240. package/dest/transport/dispatch/messages.d.ts +1 -1
  241. package/dest/transport/index.d.ts +1 -1
  242. package/dest/transport/interface/connector.d.ts +1 -1
  243. package/dest/transport/interface/listener.d.ts +1 -1
  244. package/dest/transport/interface/socket.d.ts +1 -1
  245. package/dest/transport/interface/transferable.d.ts +1 -1
  246. package/dest/transport/node/index.d.ts +1 -1
  247. package/dest/transport/node/node_connector.d.ts +1 -1
  248. package/dest/transport/node/node_connector.d.ts.map +1 -1
  249. package/dest/transport/node/node_connector_socket.d.ts +1 -1
  250. package/dest/transport/node/node_connector_socket.d.ts.map +1 -1
  251. package/dest/transport/node/node_listener.d.ts +1 -1
  252. package/dest/transport/node/node_listener.d.ts.map +1 -1
  253. package/dest/transport/node/node_listener_socket.d.ts +1 -1
  254. package/dest/transport/node/node_listener_socket.d.ts.map +1 -1
  255. package/dest/transport/transport_client.d.ts +1 -1
  256. package/dest/transport/transport_client.d.ts.map +1 -1
  257. package/dest/transport/transport_server.d.ts +1 -10
  258. package/dest/transport/transport_server.d.ts.map +1 -1
  259. package/dest/trees/balanced_merkle_tree.d.ts +22 -0
  260. package/dest/trees/balanced_merkle_tree.d.ts.map +1 -0
  261. package/dest/trees/balanced_merkle_tree.js +64 -0
  262. package/dest/trees/hasher.d.ts +1 -1
  263. package/dest/trees/index.d.ts +2 -1
  264. package/dest/trees/index.d.ts.map +1 -1
  265. package/dest/trees/index.js +1 -0
  266. package/dest/trees/indexed_merkle_tree.d.ts +1 -1
  267. package/dest/trees/indexed_merkle_tree.d.ts.map +1 -1
  268. package/dest/trees/indexed_merkle_tree_calculator.d.ts +1 -1
  269. package/dest/trees/indexed_merkle_tree_calculator.d.ts.map +1 -1
  270. package/dest/trees/indexed_tree_leaf.d.ts +1 -1
  271. package/dest/trees/membership_witness.d.ts +2 -23
  272. package/dest/trees/membership_witness.d.ts.map +1 -1
  273. package/dest/trees/merkle_tree.d.ts +1 -1
  274. package/dest/trees/merkle_tree.d.ts.map +1 -1
  275. package/dest/trees/merkle_tree_calculator.d.ts +2 -12
  276. package/dest/trees/merkle_tree_calculator.d.ts.map +1 -1
  277. package/dest/trees/merkle_tree_calculator.js +1 -31
  278. package/dest/trees/sibling_path.d.ts +4 -38
  279. package/dest/trees/sibling_path.d.ts.map +1 -1
  280. package/dest/trees/unbalanced_merkle_tree.d.ts +5 -3
  281. package/dest/trees/unbalanced_merkle_tree.d.ts.map +1 -1
  282. package/dest/trees/unbalanced_merkle_tree.js +32 -9
  283. package/dest/trees/unbalanced_merkle_tree_calculator.d.ts +6 -5
  284. package/dest/trees/unbalanced_merkle_tree_calculator.d.ts.map +1 -1
  285. package/dest/trees/unbalanced_merkle_tree_calculator.js +36 -40
  286. package/dest/trees/unbalanced_tree_store.d.ts +1 -1
  287. package/dest/trees/unbalanced_tree_store.d.ts.map +1 -1
  288. package/dest/types/index.d.ts +1 -1
  289. package/dest/url/index.d.ts +1 -1
  290. package/dest/validation/index.d.ts +1 -1
  291. package/package.json +7 -5
  292. package/src/array/array.ts +0 -16
  293. package/src/branded-types/epoch.ts +88 -0
  294. package/src/branded-types/index.ts +4 -0
  295. package/src/branded-types/slot.ts +88 -0
  296. package/src/branded-types/types.ts +2 -0
  297. package/src/config/env_var.ts +12 -2
  298. package/src/crypto/aes128/index.ts +2 -2
  299. package/src/crypto/bn254/index.ts +3 -0
  300. package/src/crypto/ecdsa/index.ts +4 -4
  301. package/src/crypto/grumpkin/index.ts +5 -5
  302. package/src/crypto/keys/index.ts +1 -1
  303. package/src/crypto/pedersen/pedersen.wasm.ts +3 -3
  304. package/src/crypto/poseidon/index.ts +5 -5
  305. package/src/crypto/schnorr/index.ts +3 -3
  306. package/src/crypto/secp256k1/index.ts +3 -3
  307. package/src/crypto/sync/index.ts +1 -1
  308. package/src/eth-address/index.ts +19 -0
  309. package/src/fields/fields.ts +16 -0
  310. package/src/fields/point.ts +19 -0
  311. package/src/index.ts +1 -0
  312. package/src/schemas/schemas.ts +10 -10
  313. package/src/schemas/utils.ts +21 -8
  314. package/src/testing/files/index.ts +1 -1
  315. package/src/trees/balanced_merkle_tree.ts +82 -0
  316. package/src/trees/index.ts +1 -0
  317. package/src/trees/merkle_tree_calculator.ts +1 -34
  318. package/src/trees/unbalanced_merkle_tree.ts +54 -6
  319. package/src/trees/unbalanced_merkle_tree_calculator.ts +34 -41
@@ -12,7 +12,6 @@ import type { Hasher } from './hasher.js';
12
12
  * And the elements would be ordered as: [ leaf_at_index_2, node_at_level_2_index_0, node_at_level_1_index_1 ].
13
13
  */
14
14
  export declare class SiblingPath<N extends number> {
15
- /** Size of the sibling path (number of fields it contains). */
16
15
  pathSize: N;
17
16
  private data;
18
17
  /**
@@ -25,41 +24,8 @@ export declare class SiblingPath<N extends number> {
25
24
  pathSize: N,
26
25
  /** The sibling path data. */
27
26
  path: Buffer[]);
28
- static get schema(): import("zod").ZodEffects<import("zod").ZodUnion<[import("zod").ZodEffects<import("zod").ZodEffects<import("zod").ZodString, string, string>, Buffer<ArrayBuffer>, string>, import("zod").ZodEffects<import("zod").ZodObject<{
29
- type: import("zod").ZodLiteral<"Buffer">;
30
- data: import("zod").ZodArray<import("zod").ZodNumber, "many">;
31
- }, "strip", import("zod").ZodTypeAny, {
32
- type: "Buffer";
33
- data: number[];
34
- }, {
35
- type: "Buffer";
36
- data: number[];
37
- }>, Buffer<ArrayBuffer>, {
38
- type: "Buffer";
39
- data: number[];
40
- }>]>, SiblingPath<number>, string | {
41
- type: "Buffer";
42
- data: number[];
43
- }>;
44
- static schemaFor<N extends number>(size: N): import("zod").ZodEffects<import("zod").ZodEffects<import("zod").ZodUnion<[import("zod").ZodEffects<import("zod").ZodEffects<import("zod").ZodString, string, string>, Buffer<ArrayBuffer>, string>, import("zod").ZodEffects<import("zod").ZodObject<{
45
- type: import("zod").ZodLiteral<"Buffer">;
46
- data: import("zod").ZodArray<import("zod").ZodNumber, "many">;
47
- }, "strip", import("zod").ZodTypeAny, {
48
- type: "Buffer";
49
- data: number[];
50
- }, {
51
- type: "Buffer";
52
- data: number[];
53
- }>, Buffer<ArrayBuffer>, {
54
- type: "Buffer";
55
- data: number[];
56
- }>]>, SiblingPath<N>, string | {
57
- type: "Buffer";
58
- data: number[];
59
- }>, SiblingPath<N>, string | {
60
- type: "Buffer";
61
- data: number[];
62
- }>;
27
+ static get schema(): import("zod").ZodEffects<import("../schemas/types.js").ZodFor<Buffer<ArrayBufferLike>>, SiblingPath<number>, any>;
28
+ static schemaFor<N extends number>(size: N): import("zod").ZodEffects<import("zod").ZodEffects<import("../schemas/types.js").ZodFor<Buffer<ArrayBufferLike>>, SiblingPath<N>, any>, SiblingPath<N>, any>;
63
29
  toJSON(): Buffer<ArrayBufferLike>;
64
30
  /**
65
31
  * Returns sibling path hashed up from the a element.
@@ -126,5 +92,5 @@ export declare class SiblingPath<N extends number> {
126
92
  getSubtreeSiblingPath<SubtreeHeight extends number, SubtreeSiblingPathHeight extends number>(subtreeHeight: SubtreeHeight): SiblingPath<SubtreeSiblingPathHeight>;
127
93
  }
128
94
  /** Computes the expected root of a merkle tree given a leaf and its sibling path. */
129
- export declare function computeRootFromSiblingPath(leaf: Buffer, siblingPath: Buffer[], index: number, hasher?: (left: Buffer, right: Buffer) => Promise<Buffer<ArrayBufferLike>>): Promise<Buffer<ArrayBufferLike>>;
130
- //# sourceMappingURL=sibling_path.d.ts.map
95
+ export declare function computeRootFromSiblingPath(leaf: Buffer, siblingPath: Buffer[], index: number, hasher?: (left: Buffer<ArrayBufferLike>, right: Buffer<ArrayBufferLike>) => Promise<Buffer<ArrayBufferLike>>): Promise<Buffer<ArrayBufferLike>>;
96
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2libGluZ19wYXRoLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvdHJlZXMvc2libGluZ19wYXRoLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUVBLE9BQU8sRUFBRSxFQUFFLEVBQUUsTUFBTSxvQkFBb0IsQ0FBQztBQUV4QyxPQUFPLEVBQ0wsS0FBSyxLQUFLLEVBSVgsTUFBTSx1QkFBdUIsQ0FBQztBQUUvQixPQUFPLEtBQUssRUFBRSxNQUFNLEVBQUUsTUFBTSxhQUFhLENBQUM7QUFFMUM7Ozs7Ozs7OztHQVNHO0FBQ0gscUJBQWEsV0FBVyxDQUFDLENBQUMsU0FBUyxNQUFNO0lBVTlCLFFBQVEsRUFBRSxDQUFDO0lBVHBCLE9BQU8sQ0FBQyxJQUFJLENBQW1CO0lBRS9COzs7O09BSUc7SUFDSDtJQUNFLCtEQUErRDtJQUN4RCxRQUFRLEVBQUUsQ0FBQztJQUNsQiw2QkFBNkI7SUFDN0IsSUFBSSxFQUFFLE1BQU0sRUFBRSxFQUdmO0lBRUQsTUFBTSxLQUFLLE1BQU0sc0hBRWhCO0lBRUQsTUFBTSxDQUFDLFNBQVMsQ0FBQyxDQUFDLFNBQVMsTUFBTSxFQUFFLElBQUksRUFBRSxDQUF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qB,CAAC,aAAa,SAAS,MAAM,EAAE,wBAAwB,SAAS,MAAM,EAChG,aAAa,EAAE,aAAa,GAC3B,WAAW,CAAC,wBAAwB,CAAC,CAKvC;CACF;AAED,qFAAqF;AACrF,wBAAsB,0BAA0B,CAC9C,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,MAAM,EAAE,EACrB,KAAK,EAAE,MAAM,EACb,MAAM,sGAAwF,oCAQ/F"}
@@ -1,4 +1,5 @@
1
- import { sha256Trunc } from '../crypto/sha256/index.js';
1
+ export declare const computeUnbalancedShaRoot: (leaves: Buffer<ArrayBufferLike>[]) => Buffer<ArrayBufferLike>;
2
+ export declare const computeUnbalancedPoseidonRoot: (leaves: Buffer<ArrayBufferLike>[]) => Promise<Buffer<ArrayBufferLike>>;
2
3
  /**
3
4
  * Computes the Merkle root of an unbalanced tree.
4
5
  *
@@ -20,9 +21,10 @@ import { sha256Trunc } from '../crypto/sha256/index.js';
20
21
  * But if we instead combine the size-4 and size-8 subtrees first (depth 4), and then merge with the size-2 subtree
21
22
  * (depth 1), the final tree has a depth of 5.
22
23
  */
23
- export declare function computeUnbalancedMerkleTreeRoot(leaves: Buffer[], hasher?: typeof sha256Trunc): Buffer;
24
+ export declare function computeUnbalancedMerkleTreeRoot(leaves: Buffer[], hasher?: (lhs: Uint8Array<ArrayBufferLike>, rhs: Uint8Array<ArrayBufferLike>) => Buffer<ArrayBuffer>, emptyRoot?: Buffer<ArrayBuffer>): Buffer;
25
+ export declare function computeUnbalancedMerkleTreeRootAsync(leaves: Buffer[], hasher?: (lhs: Uint8Array<ArrayBufferLike>, rhs: Uint8Array<ArrayBufferLike>) => Promise<Buffer<ArrayBuffer>>, emptyRoot?: Buffer<ArrayBuffer>): Promise<Buffer>;
24
26
  export declare function findLeafLevelAndIndex(numLeaves: number, leafIndex: number): {
25
27
  level: number;
26
28
  indexAtLevel: number;
27
29
  };
28
- //# sourceMappingURL=unbalanced_merkle_tree.d.ts.map
30
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidW5iYWxhbmNlZF9tZXJrbGVfdHJlZS5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL3RyZWVzL3VuYmFsYW5jZWRfbWVya2xlX3RyZWUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBT0EsZUFBTyxNQUFNLHdCQUF3QixnRUFBK0UsQ0FBQztBQUVySCxlQUFPLE1BQU0sNkJBQTZCLHlFQUM4QixDQUFDO0FBRXpFOzs7Ozs7Ozs7Ozs7Ozs7Ozs7OztHQW9CRztBQUNILHdCQUFnQiwrQkFBK0IsQ0FDN0MsTUFBTSxFQUFFLE1BQU0sRUFBRSxFQUNoQixNQUFNLDhGQUFnQixFQUN0QixTQUFTLHNCQUFtQixHQUMzQixNQUFNLENBNkJSO0FBRUQsd0JBQXNCLG9DQUFvQyxDQUN4RCxNQUFNLEVBQUUsTUFBTSxFQUFFLEVBQ2hCLE1BQU0sdUdBQXFCLEVBQzNCLFNBQVMsc0JBQW1CLEdBQzNCLE9BQU8sQ0FBQyxNQUFNLENBQUMsQ0E2QmpCO0FBc0RELHdCQUFnQixxQkFBcUIsQ0FBQyxTQUFTLEVBQUUsTUFBTSxFQUFFLFNBQVMsRUFBRSxNQUFNOzs7RUFHekUifQ==
@@ -1 +1 @@
1
- {"version":3,"file":"unbalanced_merkle_tree.d.ts","sourceRoot":"","sources":["../../src/trees/unbalanced_merkle_tree.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAGxD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,+BAA+B,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,MAAM,qBAAc,GAAG,MAAM,CA6B9F;AAsDD,wBAAgB,qBAAqB,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM;WAhC9D,MAAM;kBAAgB,MAAM;EAmCvC"}
1
+ {"version":3,"file":"unbalanced_merkle_tree.d.ts","sourceRoot":"","sources":["../../src/trees/unbalanced_merkle_tree.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,wBAAwB,gEAA+E,CAAC;AAErH,eAAO,MAAM,6BAA6B,yEAC8B,CAAC;AAEzE;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,+BAA+B,CAC7C,MAAM,EAAE,MAAM,EAAE,EAChB,MAAM,8FAAgB,EACtB,SAAS,sBAAmB,GAC3B,MAAM,CA6BR;AAED,wBAAsB,oCAAoC,CACxD,MAAM,EAAE,MAAM,EAAE,EAChB,MAAM,uGAAqB,EAC3B,SAAS,sBAAmB,GAC3B,OAAO,CAAC,MAAM,CAAC,CA6BjB;AAsDD,wBAAgB,qBAAqB,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM;;;EAGzE"}
@@ -1,5 +1,6 @@
1
- import { sha256Trunc } from '../crypto/sha256/index.js';
2
- import { MerkleTreeCalculator } from './merkle_tree_calculator.js';
1
+ import { computeBalancedMerkleTreeRoot, computeBalancedMerkleTreeRootAsync, poseidonMerkleHash, shaMerkleHash } from './balanced_merkle_tree.js';
2
+ export const computeUnbalancedShaRoot = (leaves)=>computeUnbalancedMerkleTreeRoot(leaves, shaMerkleHash);
3
+ export const computeUnbalancedPoseidonRoot = async (leaves)=>await computeUnbalancedMerkleTreeRootAsync(leaves, poseidonMerkleHash);
3
4
  /**
4
5
  * Computes the Merkle root of an unbalanced tree.
5
6
  *
@@ -20,9 +21,9 @@ import { MerkleTreeCalculator } from './merkle_tree_calculator.js';
20
21
  *
21
22
  * But if we instead combine the size-4 and size-8 subtrees first (depth 4), and then merge with the size-2 subtree
22
23
  * (depth 1), the final tree has a depth of 5.
23
- */ export function computeUnbalancedMerkleTreeRoot(leaves, hasher = sha256Trunc) {
24
+ */ export function computeUnbalancedMerkleTreeRoot(leaves, hasher = shaMerkleHash, emptyRoot = Buffer.alloc(32)) {
24
25
  if (!leaves.length) {
25
- throw new Error('Cannot compute a Merkle root with no leaves');
26
+ return emptyRoot;
26
27
  }
27
28
  if (leaves.length === 1) {
28
29
  return leaves[0];
@@ -33,14 +34,36 @@ import { MerkleTreeCalculator } from './merkle_tree_calculator.js';
33
34
  while(numRemainingLeaves > 1){
34
35
  if ((numRemainingLeaves & subtreeSize) !== 0) {
35
36
  const subtreeLeaves = leaves.slice(numRemainingLeaves - subtreeSize, numRemainingLeaves);
36
- const subtreeRoot = MerkleTreeCalculator.computeTreeRootSync(subtreeLeaves, hasher);
37
+ const subtreeRoot = computeBalancedMerkleTreeRoot(subtreeLeaves, hasher);
37
38
  if (!root) {
38
39
  root = subtreeRoot;
39
40
  } else {
40
- root = hasher(Buffer.concat([
41
- subtreeRoot,
42
- root
43
- ]));
41
+ root = hasher(subtreeRoot, root);
42
+ }
43
+ numRemainingLeaves -= subtreeSize;
44
+ }
45
+ subtreeSize *= 2;
46
+ }
47
+ return root;
48
+ }
49
+ export async function computeUnbalancedMerkleTreeRootAsync(leaves, hasher = poseidonMerkleHash, emptyRoot = Buffer.alloc(32)) {
50
+ if (!leaves.length) {
51
+ return emptyRoot;
52
+ }
53
+ if (leaves.length === 1) {
54
+ return leaves[0];
55
+ }
56
+ let numRemainingLeaves = leaves.length;
57
+ let subtreeSize = 1;
58
+ let root;
59
+ while(numRemainingLeaves > 1){
60
+ if ((numRemainingLeaves & subtreeSize) !== 0) {
61
+ const subtreeLeaves = leaves.slice(numRemainingLeaves - subtreeSize, numRemainingLeaves);
62
+ const subtreeRoot = await computeBalancedMerkleTreeRootAsync(subtreeLeaves, hasher);
63
+ if (!root) {
64
+ root = subtreeRoot;
65
+ } else {
66
+ root = await hasher(subtreeRoot, root);
44
67
  }
45
68
  numRemainingLeaves -= subtreeSize;
46
69
  }
@@ -1,7 +1,7 @@
1
1
  import type { Hasher } from './hasher.js';
2
2
  import { SiblingPath } from './sibling_path.js';
3
3
  import { type TreeNodeLocation } from './unbalanced_tree_store.js';
4
- export declare function computeCompressedUnbalancedMerkleTreeRoot(leaves: Buffer[], valueToCompress?: Buffer<ArrayBuffer>, hasher?: Hasher['hash']): Buffer;
4
+ export declare function computeCompressedUnbalancedMerkleTreeRoot(leaves: Buffer[], valueToCompress?: Buffer<ArrayBuffer>, emptyRoot?: Buffer<ArrayBuffer>, hasher?: Hasher['hash']): Buffer;
5
5
  /**
6
6
  * An ephemeral unbalanced Merkle tree implementation.
7
7
  * Follows the rollup implementation which greedily hashes pairs of nodes up the tree.
@@ -13,11 +13,12 @@ export declare function computeCompressedUnbalancedMerkleTreeRoot(leaves: Buffer
13
13
  export declare class UnbalancedMerkleTreeCalculator {
14
14
  private readonly leaves;
15
15
  private readonly valueToCompress;
16
+ private readonly emptyRoot;
16
17
  private readonly hasher;
17
18
  private store;
18
19
  private leafLocations;
19
- constructor(leaves: Buffer[], valueToCompress: Buffer, hasher: Hasher['hash']);
20
- static create(leaves: Buffer[], valueToCompress?: Buffer<ArrayBuffer>, hasher?: (left: Buffer, right: Buffer) => Buffer<ArrayBuffer>): UnbalancedMerkleTreeCalculator;
20
+ constructor(leaves: Buffer[], valueToCompress: Buffer, emptyRoot: Buffer, hasher: Hasher['hash']);
21
+ static create(leaves: Buffer[], valueToCompress?: Buffer<ArrayBuffer>, emptyRoot?: Buffer<ArrayBuffer>, hasher?: (lhs: Uint8Array<ArrayBufferLike>, rhs: Uint8Array<ArrayBufferLike>) => Buffer<ArrayBuffer>): UnbalancedMerkleTreeCalculator;
21
22
  /**
22
23
  * Returns the root of the tree.
23
24
  * @returns The root of the tree.
@@ -43,6 +44,6 @@ export declare class UnbalancedMerkleTreeCalculator {
43
44
  */
44
45
  private buildTree;
45
46
  private shiftNodeUp;
46
- private shiftChildrenUp;
47
+ private collectNodesToShift;
47
48
  }
48
- //# sourceMappingURL=unbalanced_merkle_tree_calculator.d.ts.map
49
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidW5iYWxhbmNl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FLE1BQU0sRUFBRSxFQUNoQixlQUFlLHNCQUFrQixFQUNqQyxTQUFTLHNCQUFtQixFQUM1QixNQUFNLDhGQUFnQixrQ0FHdkI7SUFFRDs7O09BR0c7SUFDSSxPQUFPLElBQUksTUFBTSxDQUV2QjtJQUVEOzs7OztPQUtHO0lBQ0ksY0FBYyxDQUFDLENBQUMsU0FBUyxNQUFNLEVBQUUsS0FBSyxFQUFFLE1BQU0sR0FBRyxXQUFXLENBQUMsQ0FBQyxDQUFDLENBT3JFO0lBRUQ7Ozs7T0FJRztJQUNJLHlCQUF5QixDQUFDLENBQUMsU0FBUyxNQUFNLEVBQUUsU0FBUyxFQUFFLE1BQU0sR0FBRyxXQUFXLENBQUMsQ0FBQyxDQUFDLENBbUJwRjtJQUVNLGVBQWUsQ0FBQyxTQUFTLEVBQUUsTUFBTSxvQkFFdkM7SUFFRDs7O09BR0c7SUFDSCxPQUFPLENBQUMsU0FBUztJQStDakIsT0FBTyxDQUFDLFdBQVc7SUFZbkIsT0FBTyxDQUFDLG1CQUFtQjtDQW1CNUIifQ==
@@ -1 +1 @@
1
- {"version":3,"file":"unbalanced_merkle_tree_calculator.d.ts","sourceRoot":"","sources":["../../src/trees/unbalanced_merkle_tree_calculator.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,KAAK,gBAAgB,EAAuB,MAAM,4BAA4B,CAAC;AAExF,wBAAgB,yCAAyC,CACvD,MAAM,EAAE,MAAM,EAAE,EAChB,eAAe,sBAAmB,EAClC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC,GACtB,MAAM,CAGR;AAOD;;;;;;;GAOG;AACH,qBAAa,8BAA8B;IAKvC,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,eAAe;IAChC,OAAO,CAAC,QAAQ,C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vB,OAAO,CAAC,QAAQ,CAAC,eAAe;IAChC,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,MAAM;IAPzB,OAAO,CAAC,KAAK,CAAgC;IAC7C,OAAO,CAAC,aAAa,CAA0B;IAE/C,YACmB,MAAM,EAAE,MAAM,EAAE,EAChB,eAAe,EAAE,MAAM,EACvB,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,EAIxC;IAED,MAAM,CAAC,MAAM,CACX,MAAM,EAAE,MAAM,EAAE,EAChB,eAAe,sBAAkB,EACjC,SAAS,sBAAmB,EAC5B,MAAM,8FAAgB,kCAGvB;IAED;;;OAGG;IACI,OAAO,IAAI,MAAM,CAEvB;IAED;;;;;OAKG;IACI,cAAc,CAAC,CAAC,SAAS,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,WAAW,CAAC,CAAC,CAAC,CAOrE;IAED;;;;OAIG;IACI,yBAAyB,CAAC,CAAC,SAAS,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,WAAW,CAAC,CAAC,CAAC,CAmBpF;IAEM,eAAe,CAAC,SAAS,EAAE,MAAM,oBAEvC;IAED;;;OAGG;IACH,OAAO,CAAC,SAAS;IA+CjB,OAAO,CAAC,WAAW;IAYnB,OAAO,CAAC,mBAAmB;CAmB5B"}
@@ -1,8 +1,8 @@
1
- import { sha256Trunc } from '../crypto/index.js';
1
+ import { shaMerkleHash } from './balanced_merkle_tree.js';
2
2
  import { SiblingPath } from './sibling_path.js';
3
3
  import { UnbalancedTreeStore } from './unbalanced_tree_store.js';
4
- export function computeCompressedUnbalancedMerkleTreeRoot(leaves, valueToCompress = Buffer.alloc(32), hasher) {
5
- const calculator = UnbalancedMerkleTreeCalculator.create(leaves, valueToCompress, hasher);
4
+ export function computeCompressedUnbalancedMerkleTreeRoot(leaves, valueToCompress = Buffer.alloc(32), emptyRoot = Buffer.alloc(32), hasher) {
5
+ const calculator = UnbalancedMerkleTreeCalculator.create(leaves, valueToCompress, emptyRoot, hasher);
6
6
  return calculator.getRoot();
7
7
  }
8
8
  /**
@@ -15,25 +15,21 @@ export function computeCompressedUnbalancedMerkleTreeRoot(leaves, valueToCompres
15
15
  */ export class UnbalancedMerkleTreeCalculator {
16
16
  leaves;
17
17
  valueToCompress;
18
+ emptyRoot;
18
19
  hasher;
19
20
  store;
20
21
  leafLocations;
21
- constructor(leaves, valueToCompress, hasher){
22
+ constructor(leaves, valueToCompress, emptyRoot, hasher){
22
23
  this.leaves = leaves;
23
24
  this.valueToCompress = valueToCompress;
25
+ this.emptyRoot = emptyRoot;
24
26
  this.hasher = hasher;
25
27
  this.leafLocations = [];
26
- if (leaves.length === 0) {
27
- throw Error('Cannot create a compressed unbalanced tree with 0 leaves.');
28
- }
29
28
  this.store = new UnbalancedTreeStore(leaves.length);
30
29
  this.buildTree();
31
30
  }
32
- static create(leaves, valueToCompress = Buffer.alloc(0), hasher = (left, right)=>sha256Trunc(Buffer.concat([
33
- left,
34
- right
35
- ]))) {
36
- return new UnbalancedMerkleTreeCalculator(leaves, valueToCompress, hasher);
31
+ static create(leaves, valueToCompress = Buffer.alloc(0), emptyRoot = Buffer.alloc(32), hasher = shaMerkleHash) {
32
+ return new UnbalancedMerkleTreeCalculator(leaves, valueToCompress, emptyRoot, hasher);
37
33
  }
38
34
  /**
39
35
  * Returns the root of the tree.
@@ -88,12 +84,12 @@ export function computeCompressedUnbalancedMerkleTreeRoot(leaves, valueToCompres
88
84
  // Start with the leaves that are not compressed.
89
85
  let toProcess = this.leafLocations.filter((_, i)=>!this.leaves[i].equals(this.valueToCompress));
90
86
  if (!toProcess.length) {
91
- // All leaves are compressed. Set 0 to the root.
87
+ // All leaves are compressed. Set empty root to the root.
92
88
  this.store.setNode({
93
89
  level: 0,
94
90
  index: 0
95
91
  }, {
96
- value: Buffer.alloc(32)
92
+ value: this.emptyRoot
97
93
  });
98
94
  return;
99
95
  }
@@ -114,10 +110,7 @@ export function computeCompressedUnbalancedMerkleTreeRoot(leaves, valueToCompres
114
110
  const shouldShiftUp = !sibling || sibling.value.equals(this.valueToCompress);
115
111
  if (shouldShiftUp) {
116
112
  // The node becomes the parent if the sibling is a compressed leaf.
117
- const isLeaf = this.shiftNodeUp(location, parentLocation);
118
- if (!isLeaf) {
119
- this.shiftChildrenUp(location);
120
- }
113
+ this.shiftNodeUp(location, parentLocation);
121
114
  } else {
122
115
  // Hash the value with the (right) sibling and update the parent node.
123
116
  const node = this.store.getNode(location);
@@ -132,31 +125,34 @@ export function computeCompressedUnbalancedMerkleTreeRoot(leaves, valueToCompres
132
125
  toProcess = toProcessNext;
133
126
  }
134
127
  }
135
- shiftNodeUp(fromLocation, toLocation) {
136
- const node = this.store.getNode(fromLocation);
137
- this.store.setNode(toLocation, node);
138
- const isLeaf = node.leafIndex !== undefined;
139
- if (isLeaf) {
140
- // Update the location if the node is a leaf.
141
- this.leafLocations[node.leafIndex] = toLocation;
128
+ shiftNodeUp(from, to) {
129
+ // Collect all nodes that need to shift.
130
+ const nodesToShift = this.collectNodesToShift(from, to);
131
+ // Move all nodes to their new locations.
132
+ for (const { node, newLocation } of nodesToShift){
133
+ this.store.setNode(newLocation, node);
134
+ if (node.leafIndex !== undefined) {
135
+ this.leafLocations[node.leafIndex] = newLocation;
136
+ }
142
137
  }
143
- return isLeaf;
144
138
  }
145
- shiftChildrenUp(parent) {
146
- const [left, right] = this.store.getChildLocations(parent);
147
- const level = parent.level;
148
- const groupSize = 2 ** level;
149
- const computeNewLocation = (index)=>({
150
- level,
151
- index: Math.floor(index / (groupSize * 2)) * groupSize + index % groupSize
152
- });
153
- const isLeftLeaf = this.shiftNodeUp(left, computeNewLocation(left.index));
154
- const isRightLeaf = this.shiftNodeUp(right, computeNewLocation(right.index));
155
- if (!isLeftLeaf) {
156
- this.shiftChildrenUp(left);
139
+ collectNodesToShift(from, to) {
140
+ const node = this.store.getNode(from);
141
+ if (!node) {
142
+ return [];
157
143
  }
158
- if (!isRightLeaf) {
159
- this.shiftChildrenUp(right);
144
+ let result = [
145
+ {
146
+ node,
147
+ newLocation: to
148
+ }
149
+ ];
150
+ // If not a leaf, collect its children.
151
+ if (node.leafIndex === undefined) {
152
+ const [leftChild, rightChild] = this.store.getChildLocations(from);
153
+ const [leftChildNew, rightChildNew] = this.store.getChildLocations(to);
154
+ result = result.concat(this.collectNodesToShift(leftChild, leftChildNew)).concat(this.collectNodesToShift(rightChild, rightChildNew));
160
155
  }
156
+ return result;
161
157
  }
162
158
  }
@@ -17,4 +17,4 @@ export declare class UnbalancedTreeStore<T> {
17
17
  getSibling(location: TreeNodeLocation): T | undefined;
18
18
  getChildren(location: TreeNodeLocation): [T | undefined, T | undefined];
19
19
  }
20
- //# sourceMappingURL=unbalanced_tree_store.d.ts.map
20
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidW5iYWxhbmNlZF90cmVlX3N0b3JlLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvdHJlZXMvdW5iYWxhbmNlZF90cmVlX3N0b3JlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUVBLE1BQU0sV0FBVyxnQkFBZ0I7SUFDL0IsS0FBSyxFQUFFLE1BQU0sQ0FBQztJQUNkLEtBQUssRUFBRSxNQUFNLENBQUM7Q0FDZjtBQU9ELHFCQUFhLG1CQUFtQixDQUFDLENBQUM7O0lBSWhDLFlBQVksU0FBUyxFQUFFLE1BQU0sRUFFNUI7SUFFRCxPQUFPLENBQUMsU0FBUyxFQUFFLE1BQU0sRUFBRSxLQUFLLEVBQUUsQ0FBQyxHQUFHLGdCQUFnQixDQWVyRDtJQUVELE9BQU8sQ0FBQyxFQUFFLEtBQUssRUFBRSxLQUFLLEVBQUUsRUFBRSxnQkFBZ0IsRUFBRSxLQUFLLEVBQUUsQ0FBQyxRQVNuRDtJQUVELGlCQUFpQixDQUFDLEVBQUUsS0FBSyx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EAAE,EAAE,gBAAgB,GAAG,gBAAgB,CAMtE;IAED,kBAAkB,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,gBAAgB,GAAG,gBAAgB,CAMvE;IAED,iBAAiB,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,gBAAgB,GAAG,CAAC,gBAAgB,EAAE,gBAAgB,CAAC,CAI1F;IAED,OAAO,CAAC,SAAS,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS,CAOxC;IAED,OAAO,CAAC,QAAQ,EAAE,gBAAgB,GAAG,CAAC,GAAG,SAAS,CAEjD;IAED,OAAO,IAAI,CAAC,GAAG,SAAS,CAEvB;IAED,SAAS,CAAC,QAAQ,EAAE,gBAAgB,GAAG,CAAC,GAAG,SAAS,CAGnD;IAED,UAAU,CAAC,QAAQ,EAAE,gBAAgB,GAAG,CAAC,GAAG,SAAS,CAGpD;IAED,WAAW,CAAC,QAAQ,EAAE,gBAAgB,GAAG,CAAC,CAAC,GAAG,SAAS,EAAE,CAAC,GAAG,SAAS,CAAC,CAGtE;CAKF"}
@@ -39,4 +39,4 @@ export interface TypedEventEmitter<TEventMap extends {
39
39
  removeListener<K extends keyof TEventMap>(event: K, listener: TEventMap[K]): this;
40
40
  removeAllListeners<K extends keyof TEventMap>(event: K): this;
41
41
  }
42
- //# sourceMappingURL=index.d.ts.map
42
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy90eXBlcy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxnQ0FBZ0M7QUFDaEMsTUFBTSxNQUFNLFFBQVEsQ0FBQyxDQUFDLElBQUk7S0FDdkIsQ0FBQyxJQUFJLE1BQU0sQ0FBQyxJQUFJLENBQUMsQ0FBQyxDQUFDLENBQUMsU0FBUyxRQUFRLEdBQUcsS0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/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy91cmwvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBbUJBOzs7Ozs7R0FNRztBQUVILHdCQUFnQixhQUFhLENBQUMsR0FBRyxFQUFFLE1BQU0sR0FBRyxNQUFNLENBNENqRCJ9
@@ -6,4 +6,4 @@ export declare function required<T>(value: T | undefined, errMsg?: string): T;
6
6
  * @param err - Error message to throw if x isn't met.
7
7
  */
8
8
  export declare function assert(x: any, err: string): asserts x;
9
- //# sourceMappingURL=index.d.ts.map
9
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy92YWxpZGF0aW9uL2luZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLHlFQUF5RTtBQUN6RSx3QkFBZ0IsUUFBUSxDQUFDLENBQUMsRUFBRSxLQUFLLEVBQUUsQ0FBQyxHQUFHLFNBQVMsRUFBRSxNQUFNLENBQUMsRUFBRSxNQUFNLEdBQUcsQ0FBQyxDQUtwRTtBQUVEOzs7O0dBSUc7QUFDSCx3QkFBZ0IsTUFBTSxDQUFDLENBQUMsRUFBRSxHQUFHLEVBQUUsR0FBRyxFQUFFLE1BQU0sR0FBRyxPQUFPLENBQUMsQ0FBQyxDQUlyRCJ9
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aztec/foundation",
3
- "version": "0.0.1-commit.b655e406",
3
+ "version": "0.0.1-commit.fce3e4f",
4
4
  "type": "module",
5
5
  "main": "./dest/index.js",
6
6
  "types": "./dest/index.d.ts",
@@ -12,6 +12,7 @@
12
12
  "./async-map": "./dest/async-map/index.js",
13
13
  "./async-pool": "./dest/async-pool/index.js",
14
14
  "./bigint": "./dest/bigint/index.js",
15
+ "./branded-types": "./dest/branded-types/index.js",
15
16
  "./collection": "./dest/collection/index.js",
16
17
  "./config": "./dest/config/index.js",
17
18
  "./crypto": "./dest/crypto/index.js",
@@ -57,8 +58,8 @@
57
58
  "./number": "./dest/number/index.js"
58
59
  },
59
60
  "scripts": {
60
- "build": "yarn clean && tsc -b",
61
- "build:dev": "tsc -b --watch",
61
+ "build": "yarn clean && tsgo -b",
62
+ "build:dev": "tsgo -b --watch",
62
63
  "clean": "rm -rf ./dest .tsbuildinfo",
63
64
  "generate": "true",
64
65
  "test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}"
@@ -104,7 +105,7 @@
104
105
  "testEnvironment": "../../foundation/src/jest/env.mjs"
105
106
  },
106
107
  "dependencies": {
107
- "@aztec/bb.js": "0.0.1-commit.b655e406",
108
+ "@aztec/bb.js": "0.0.1-commit.fce3e4f",
108
109
  "@koa/cors": "^5.0.0",
109
110
  "@noble/curves": "=1.7.0",
110
111
  "@noble/hashes": "^1.6.1",
@@ -143,6 +144,7 @@
143
144
  "@types/node": "^22.15.17",
144
145
  "@types/pako": "^2.0.0",
145
146
  "@types/supertest": "^2.0.12",
147
+ "@typescript/native-preview": "7.0.0-dev.20251126.1",
146
148
  "comlink": "^4.4.1",
147
149
  "eslint": "^9.26.0",
148
150
  "eslint-config-prettier": "^10.1.5",
@@ -157,7 +159,7 @@
157
159
  "ts-node": "^10.9.1",
158
160
  "typescript": "^5.3.3",
159
161
  "typescript-eslint": "^8.32.1",
160
- "viem": "npm:@spalladino/viem@2.38.2-eip7594.0"
162
+ "viem": "npm:@aztec/viem@2.38.2"
161
163
  },
162
164
  "files": [
163
165
  "dest",
@@ -42,22 +42,6 @@ export async function makeTupleAsync<T, N extends number>(length: N, fn: (i: num
42
42
  )) as Tuple<T, N>;
43
43
  }
44
44
 
45
- /**
46
- * Create an array over an integer range, filled with a function 'fn'. However, the latter half of the array are set to zeros.
47
- * see `makeTuple` above.
48
- * @param n - The number of integers.
49
- * @param fn - The generator function.
50
- * @returns The array of numbers.
51
- */
52
- export function makeHalfFullTuple<T, N extends number>(
53
- length: N,
54
- fn: (i: number) => T,
55
- offset = 0,
56
- makeEmpty: () => T,
57
- ) {
58
- return Array.from({ length }, (_: any, i: number) => (i < length / 2 ? fn(i + offset) : makeEmpty())) as Tuple<T, N>;
59
- }
60
-
61
45
  /**
62
46
  * Assert a member of an object is a certain length.
63
47
  * @param obj - An object.
@@ -0,0 +1,88 @@
1
+ import { z } from 'zod';
2
+
3
+ import type { Branded } from './types.js';
4
+
5
+ /**
6
+ * A branded type representing an epoch number.
7
+ * Epochs are used in the Aztec protocol to group slots and manage validator committees.
8
+ *
9
+ * This is a nominal type backed by a number, but TypeScript will treat it as
10
+ * incompatible with plain numbers and other branded numeric types (like Slot, BlockNumber, etc.).
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * const epoch = EpochNumber(5);
15
+ * const plainNumber: number = epoch; // OK - EpochNumber is assignable to number
16
+ * const epochFromNumber: EpochNumber = 5; // ERROR - number is not assignable to EpochNumber
17
+ * ```
18
+ */
19
+ export type EpochNumber = Branded<number, 'EpochNumber'>;
20
+
21
+ /**
22
+ * Creates an EpochNumber from a number.
23
+ * @param value - The epoch number (must be a non-negative integer)
24
+ * @returns The branded EpochNumber value
25
+ * @throws If the value is negative or not an integer
26
+ */
27
+ export function EpochNumber(value: number): EpochNumber {
28
+ if (!Number.isInteger(value)) {
29
+ throw new Error(`EpochNumber must be an integer, got ${value}`);
30
+ }
31
+ if (value < 0) {
32
+ throw new Error(`EpochNumber must be non-negative, got ${value}`);
33
+ }
34
+ return value as EpochNumber;
35
+ }
36
+
37
+ /**
38
+ * Creates an EpochNumber from a bigint.
39
+ * @param value - The epoch number as bigint (must be a non-negative integer within safe integer range)
40
+ * @returns The branded EpochNumber value
41
+ * @throws If the value is negative or exceeds Number.MAX_SAFE_INTEGER
42
+ */
43
+ EpochNumber.fromBigInt = function (value: bigint): EpochNumber {
44
+ if (value < 0n) {
45
+ throw new Error(`EpochNumber must be non-negative, got ${value}`);
46
+ }
47
+ if (value > BigInt(Number.MAX_SAFE_INTEGER)) {
48
+ throw new Error(`EpochNumber ${value} exceeds MAX_SAFE_INTEGER`);
49
+ }
50
+ return Number(value) as EpochNumber;
51
+ };
52
+
53
+ /**
54
+ * Creates an EpochNumber from a string.
55
+ * @param value - The epoch number as a string
56
+ * @returns The branded EpochNumber value
57
+ * @throws If the string cannot be parsed as a valid epoch
58
+ */
59
+ EpochNumber.fromString = function (value: string): EpochNumber {
60
+ const parsed = parseInt(value, 10);
61
+ if (isNaN(parsed)) {
62
+ throw new Error(`Cannot parse EpochNumber from string: ${value}`);
63
+ }
64
+ return EpochNumber(parsed);
65
+ };
66
+
67
+ /**
68
+ * Type guard to check if a value is a valid EpochNumber.
69
+ * Note: At runtime, an EpochNumber is just a number, so this checks if the value
70
+ * is a non-negative integer.
71
+ */
72
+ EpochNumber.isValid = function (value: unknown): value is EpochNumber {
73
+ return typeof value === 'number' && Number.isInteger(value) && value >= 0;
74
+ };
75
+
76
+ /**
77
+ * The zero epoch value.
78
+ */
79
+ EpochNumber.ZERO = EpochNumber(0);
80
+
81
+ /**
82
+ * Zod schema for parsing and validating EpochNumber values.
83
+ * Accepts numbers, bigints, or strings and coerces them to EpochNumber.
84
+ */
85
+ export const EpochNumberSchema = z
86
+ .union([z.number(), z.bigint(), z.string()])
87
+ .pipe(z.coerce.number().int().min(0))
88
+ .transform(value => EpochNumber(value));
@@ -0,0 +1,4 @@
1
+ export { EpochNumber, EpochNumberSchema } from './epoch.js';
2
+ export { SlotNumber, SlotNumberSchema } from './slot.js';
3
+
4
+ export type { Branded } from './types.js';
@@ -0,0 +1,88 @@
1
+ import { z } from 'zod';
2
+
3
+ import type { Branded } from './types.js';
4
+
5
+ /**
6
+ * A branded type representing a slot number.
7
+ * Slots are the fundamental time unit in the Aztec protocol, with multiple slots comprising an epoch.
8
+ *
9
+ * This is a nominal type backed by a number, but TypeScript will treat it as
10
+ * incompatible with plain numbers and other branded numeric types (like EpochNumber, BlockNumber, etc.).
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * const slot = SlotNumber(5);
15
+ * const plainNumber: number = slot; // OK - SlotNumber is assignable to number
16
+ * const slotFromNumber: SlotNumber = 5; // ERROR - number is not assignable to SlotNumber
17
+ * ```
18
+ */
19
+ export type SlotNumber = Branded<number, 'SlotNumber'>;
20
+
21
+ /**
22
+ * Creates a SlotNumber from a number.
23
+ * @param value - The slot number (must be a non-negative integer)
24
+ * @returns The branded SlotNumber value
25
+ * @throws If the value is negative or not an integer
26
+ */
27
+ export function SlotNumber(value: number): SlotNumber {
28
+ if (!Number.isInteger(value)) {
29
+ throw new Error(`SlotNumber must be an integer, got ${value}`);
30
+ }
31
+ if (value < 0) {
32
+ throw new Error(`SlotNumber must be non-negative, got ${value}`);
33
+ }
34
+ return value as SlotNumber;
35
+ }
36
+
37
+ /**
38
+ * Creates a SlotNumber from a bigint.
39
+ * @param value - The slot number as bigint (must be a non-negative integer within safe integer range)
40
+ * @returns The branded SlotNumber value
41
+ * @throws If the value is negative or exceeds Number.MAX_SAFE_INTEGER
42
+ */
43
+ SlotNumber.fromBigInt = function (value: bigint): SlotNumber {
44
+ if (value < 0n) {
45
+ throw new Error(`SlotNumber must be non-negative, got ${value}`);
46
+ }
47
+ if (value > BigInt(Number.MAX_SAFE_INTEGER)) {
48
+ throw new Error(`SlotNumber ${value} exceeds MAX_SAFE_INTEGER`);
49
+ }
50
+ return Number(value) as SlotNumber;
51
+ };
52
+
53
+ /**
54
+ * Creates a SlotNumber from a string.
55
+ * @param value - The slot number as a string
56
+ * @returns The branded SlotNumber value
57
+ * @throws If the string cannot be parsed as a valid slot
58
+ */
59
+ SlotNumber.fromString = function (value: string): SlotNumber {
60
+ const parsed = parseInt(value, 10);
61
+ if (isNaN(parsed)) {
62
+ throw new Error(`Cannot parse SlotNumber from string: ${value}`);
63
+ }
64
+ return SlotNumber(parsed);
65
+ };
66
+
67
+ /**
68
+ * Type guard to check if a value is a valid SlotNumber.
69
+ * Note: At runtime, a SlotNumber is just a number, so this checks if the value
70
+ * is a non-negative integer.
71
+ */
72
+ SlotNumber.isValid = function (value: unknown): value is SlotNumber {
73
+ return typeof value === 'number' && Number.isInteger(value) && value >= 0;
74
+ };
75
+
76
+ /**
77
+ * The zero slot value.
78
+ */
79
+ SlotNumber.ZERO = SlotNumber(0);
80
+
81
+ /**
82
+ * Zod schema for parsing and validating SlotNumber values.
83
+ * Accepts numbers, bigints, or strings and coerces them to SlotNumber.
84
+ */
85
+ export const SlotNumberSchema = z
86
+ .union([z.number(), z.bigint(), z.string()])
87
+ .pipe(z.coerce.number().int().min(0))
88
+ .transform(value => SlotNumber(value));