@aztec/foundation 0.0.1-commit.9b94fc1 → 0.0.1-commit.9badcec54
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.
- package/dest/array/index.d.ts +2 -1
- package/dest/array/index.d.ts.map +1 -1
- package/dest/array/index.js +1 -0
- package/dest/array/sorted_array.d.ts +15 -0
- package/dest/array/sorted_array.d.ts.map +1 -0
- package/dest/array/sorted_array.js +109 -0
- package/dest/branded-types/block_number.d.ts +56 -0
- package/dest/branded-types/block_number.d.ts.map +1 -0
- package/dest/branded-types/block_number.js +78 -0
- package/dest/branded-types/buffer32_hash.d.ts +24 -0
- package/dest/branded-types/buffer32_hash.d.ts.map +1 -0
- package/dest/branded-types/buffer32_hash.js +19 -0
- package/dest/branded-types/checkpoint_number.d.ts +57 -0
- package/dest/branded-types/checkpoint_number.d.ts.map +1 -0
- package/dest/branded-types/checkpoint_number.js +80 -0
- package/dest/branded-types/index.d.ts +5 -1
- package/dest/branded-types/index.d.ts.map +1 -1
- package/dest/branded-types/index.js +4 -0
- package/dest/branded-types/index_within_checkpoint.d.ts +42 -0
- package/dest/branded-types/index_within_checkpoint.d.ts.map +1 -0
- package/dest/branded-types/index_within_checkpoint.js +59 -0
- package/dest/branded-types/slot.d.ts +4 -1
- package/dest/branded-types/slot.d.ts.map +1 -1
- package/dest/branded-types/slot.js +3 -0
- package/dest/buffer/buffer16.d.ts +7 -2
- package/dest/buffer/buffer16.d.ts.map +1 -1
- package/dest/buffer/buffer16.js +4 -2
- package/dest/buffer/buffer32.d.ts +29 -59
- package/dest/buffer/buffer32.d.ts.map +1 -1
- package/dest/buffer/buffer32.js +30 -62
- package/dest/buffer/index.d.ts +2 -1
- package/dest/buffer/index.d.ts.map +1 -1
- package/dest/buffer/index.js +1 -0
- package/dest/buffer/utils.d.ts +3 -0
- package/dest/buffer/utils.d.ts.map +1 -0
- package/dest/buffer/utils.js +7 -0
- package/dest/collection/array.d.ts +14 -1
- package/dest/collection/array.d.ts.map +1 -1
- package/dest/collection/array.js +66 -0
- package/dest/collection/index.d.ts +2 -1
- package/dest/collection/index.d.ts.map +1 -1
- package/dest/collection/index.js +1 -0
- package/dest/collection/lru_set.d.ts +35 -0
- package/dest/collection/lru_set.d.ts.map +1 -0
- package/dest/collection/lru_set.js +95 -0
- package/dest/config/env_var.d.ts +2 -2
- package/dest/config/env_var.d.ts.map +1 -1
- package/dest/config/index.d.ts +61 -32
- package/dest/config/index.d.ts.map +1 -1
- package/dest/config/index.js +66 -37
- package/dest/config/network_config.d.ts +31 -1
- package/dest/config/network_config.d.ts.map +1 -1
- package/dest/config/network_config.js +6 -1
- package/dest/config/network_name.d.ts +2 -2
- package/dest/config/network_name.d.ts.map +1 -1
- package/dest/config/network_name.js +2 -0
- package/dest/config/parse-env.d.ts +3 -0
- package/dest/config/parse-env.d.ts.map +1 -0
- package/dest/config/parse-env.js +7 -0
- package/dest/config/secret_value.js +3 -1
- package/dest/crypto/aes128/index.d.ts +2 -1
- package/dest/crypto/aes128/index.d.ts.map +1 -1
- package/dest/crypto/aes128/index.js +11 -2
- package/dest/crypto/bls/bn254_keystore.d.ts +1 -10
- package/dest/crypto/bls/bn254_keystore.d.ts.map +1 -1
- package/dest/crypto/bls/bn254_keystore.js +1 -18
- package/dest/crypto/bls/index.js +1 -1
- package/dest/crypto/bn254/index.d.ts +35 -51
- package/dest/crypto/bn254/index.d.ts.map +1 -1
- package/dest/crypto/bn254/index.js +51 -140
- package/dest/crypto/ecdsa/signature.d.ts +11 -2
- package/dest/crypto/ecdsa/signature.d.ts.map +1 -1
- package/dest/crypto/ecdsa/signature.js +2 -2
- package/dest/crypto/grumpkin/index.d.ts +4 -2
- package/dest/crypto/grumpkin/index.d.ts.map +1 -1
- package/dest/crypto/grumpkin/index.js +2 -1
- package/dest/crypto/keys/index.d.ts +2 -2
- package/dest/crypto/keys/index.d.ts.map +1 -1
- package/dest/crypto/keys/index.js +1 -1
- package/dest/crypto/pedersen/pedersen.wasm.d.ts +2 -2
- package/dest/crypto/pedersen/pedersen.wasm.d.ts.map +1 -1
- package/dest/crypto/pedersen/pedersen.wasm.js +1 -1
- package/dest/crypto/poseidon/index.d.ts +2 -3
- package/dest/crypto/poseidon/index.d.ts.map +1 -1
- package/dest/crypto/poseidon/index.js +41 -43
- package/dest/crypto/random/randomness_singleton.d.ts +4 -3
- package/dest/crypto/random/randomness_singleton.d.ts.map +1 -1
- package/dest/crypto/random/randomness_singleton.js +5 -5
- package/dest/crypto/schnorr/index.d.ts +3 -2
- package/dest/crypto/schnorr/index.d.ts.map +1 -1
- package/dest/crypto/schnorr/index.js +1 -1
- package/dest/crypto/schnorr/signature.d.ts +2 -2
- package/dest/crypto/schnorr/signature.d.ts.map +1 -1
- package/dest/crypto/schnorr/signature.js +2 -2
- package/dest/crypto/secp256k1-signer/utils.d.ts +12 -1
- package/dest/crypto/secp256k1-signer/utils.d.ts.map +1 -1
- package/dest/crypto/secp256k1-signer/utils.js +26 -0
- package/dest/crypto/sha256/index.d.ts +2 -2
- package/dest/crypto/sha256/index.d.ts.map +1 -1
- package/dest/crypto/sha256/index.js +1 -1
- package/dest/crypto/sha512/index.d.ts +2 -2
- package/dest/crypto/sha512/index.d.ts.map +1 -1
- package/dest/crypto/sha512/index.js +1 -1
- package/dest/crypto/signature/index.d.ts +2 -2
- package/dest/crypto/signature/index.d.ts.map +1 -1
- package/dest/crypto/sync/pedersen/index.d.ts +2 -2
- package/dest/crypto/sync/pedersen/index.d.ts.map +1 -1
- package/dest/crypto/sync/pedersen/index.js +1 -1
- package/dest/crypto/sync/poseidon/index.d.ts +2 -3
- package/dest/crypto/sync/poseidon/index.d.ts.map +1 -1
- package/dest/crypto/sync/poseidon/index.js +1 -9
- package/dest/{fields/bls12_fields.d.ts → curves/bls12/field.d.ts} +3 -3
- package/dest/curves/bls12/field.d.ts.map +1 -0
- package/dest/{fields/bls12_fields.js → curves/bls12/field.js} +11 -13
- package/dest/curves/bls12/index.d.ts +3 -0
- package/dest/curves/bls12/index.d.ts.map +1 -0
- package/dest/curves/bls12/index.js +2 -0
- package/dest/{fields/bls12_point.d.ts → curves/bls12/point.d.ts} +13 -4
- package/dest/curves/bls12/point.d.ts.map +1 -0
- package/dest/{fields/bls12_point.js → curves/bls12/point.js} +10 -8
- package/dest/{fields/fields.d.ts → curves/bn254/field.d.ts} +24 -30
- package/dest/curves/bn254/field.d.ts.map +1 -0
- package/dest/{fields/fields.js → curves/bn254/field.js} +55 -61
- package/dest/curves/bn254/index.d.ts +3 -0
- package/dest/curves/bn254/index.d.ts.map +1 -0
- package/dest/curves/bn254/index.js +2 -0
- package/dest/curves/bn254/point.d.ts +54 -0
- package/dest/curves/bn254/point.d.ts.map +1 -0
- package/dest/curves/bn254/point.js +143 -0
- package/dest/curves/grumpkin/index.d.ts +10 -0
- package/dest/curves/grumpkin/index.d.ts.map +1 -0
- package/dest/curves/grumpkin/index.js +3 -0
- package/dest/{fields → curves/grumpkin}/point.d.ts +16 -7
- package/dest/curves/grumpkin/point.d.ts.map +1 -0
- package/dest/{fields → curves/grumpkin}/point.js +14 -11
- package/dest/error/index.d.ts +4 -4
- package/dest/error/index.d.ts.map +1 -1
- package/dest/eth-address/index.d.ts +3 -2
- package/dest/eth-address/index.d.ts.map +1 -1
- package/dest/eth-address/index.js +10 -6
- package/dest/eth-signature/eth_signature.d.ts +5 -1
- package/dest/eth-signature/eth_signature.d.ts.map +1 -1
- package/dest/eth-signature/eth_signature.js +7 -2
- package/dest/fifo/fifo_frame_reader.d.ts +41 -0
- package/dest/fifo/fifo_frame_reader.d.ts.map +1 -0
- package/dest/fifo/fifo_frame_reader.js +74 -0
- package/dest/fifo/index.d.ts +2 -0
- package/dest/fifo/index.d.ts.map +1 -0
- package/dest/fifo/index.js +1 -0
- package/dest/iterator/filter.d.ts +3 -0
- package/dest/iterator/filter.d.ts.map +1 -0
- package/dest/iterator/filter.js +7 -0
- package/dest/iterator/index.d.ts +2 -0
- package/dest/iterator/index.d.ts.map +1 -0
- package/dest/iterator/index.js +1 -0
- package/dest/jest/setup.js +28 -1
- package/dest/json-rpc/client/fetch.d.ts +1 -1
- package/dest/json-rpc/client/fetch.d.ts.map +1 -1
- package/dest/json-rpc/client/fetch.js +4 -3
- package/dest/json-rpc/client/safe_json_rpc_client.d.ts +2 -1
- package/dest/json-rpc/client/safe_json_rpc_client.d.ts.map +1 -1
- package/dest/json-rpc/client/safe_json_rpc_client.js +1 -1
- package/dest/json-rpc/client/undici.d.ts +1 -1
- package/dest/json-rpc/client/undici.d.ts.map +1 -1
- package/dest/json-rpc/client/undici.js +23 -4
- package/dest/json-rpc/fixtures/class_a.d.ts +3 -3
- package/dest/json-rpc/fixtures/class_a.d.ts.map +1 -1
- package/dest/json-rpc/fixtures/class_b.d.ts +3 -3
- package/dest/json-rpc/fixtures/class_b.d.ts.map +1 -1
- package/dest/json-rpc/server/api_key_auth.d.ts +19 -0
- package/dest/json-rpc/server/api_key_auth.d.ts.map +1 -0
- package/dest/json-rpc/server/api_key_auth.js +57 -0
- package/dest/json-rpc/server/index.d.ts +2 -1
- package/dest/json-rpc/server/index.d.ts.map +1 -1
- package/dest/json-rpc/server/index.js +1 -0
- package/dest/json-rpc/server/safe_json_rpc_server.js +1 -1
- package/dest/log/bigint-utils.d.ts +5 -0
- package/dest/log/bigint-utils.d.ts.map +1 -0
- package/dest/log/bigint-utils.js +21 -0
- package/dest/log/gcloud-logger-config.d.ts +1 -1
- package/dest/log/gcloud-logger-config.d.ts.map +1 -1
- package/dest/log/gcloud-logger-config.js +3 -0
- package/dest/log/libp2p_logger.d.ts +5 -2
- package/dest/log/libp2p_logger.d.ts.map +1 -1
- package/dest/log/libp2p_logger.js +14 -4
- package/dest/log/log-filters.d.ts +17 -4
- package/dest/log/log-filters.d.ts.map +1 -1
- package/dest/log/log-filters.js +26 -12
- package/dest/log/pino-logger-server.d.ts +9 -0
- package/dest/log/pino-logger-server.d.ts.map +1 -0
- package/dest/log/pino-logger-server.js +18 -0
- package/dest/log/pino-logger.d.ts +37 -8
- package/dest/log/pino-logger.d.ts.map +1 -1
- package/dest/log/pino-logger.js +138 -30
- package/dest/queue/base_memory_queue.d.ts +2 -2
- package/dest/queue/base_memory_queue.d.ts.map +1 -1
- package/dest/queue/batch_queue.d.ts +1 -1
- package/dest/queue/batch_queue.d.ts.map +1 -1
- package/dest/queue/batch_queue.js +1 -0
- package/dest/queue/semaphore.d.ts +5 -1
- package/dest/queue/semaphore.d.ts.map +1 -1
- package/dest/retry/index.d.ts +22 -1
- package/dest/retry/index.d.ts.map +1 -1
- package/dest/retry/index.js +32 -0
- package/dest/schemas/api.d.ts +2 -2
- package/dest/schemas/api.d.ts.map +1 -1
- package/dest/schemas/schemas.d.ts +7 -3
- package/dest/schemas/schemas.d.ts.map +1 -1
- package/dest/schemas/schemas.js +9 -3
- package/dest/schemas/types.d.ts +31 -1
- package/dest/schemas/types.d.ts.map +1 -1
- package/dest/schemas/types.js +25 -1
- package/dest/serialize/buffer_reader.d.ts +14 -4
- package/dest/serialize/buffer_reader.d.ts.map +1 -1
- package/dest/serialize/buffer_reader.js +26 -4
- package/dest/serialize/field_reader.d.ts +2 -2
- package/dest/serialize/field_reader.d.ts.map +1 -1
- package/dest/serialize/field_reader.js +1 -1
- package/dest/serialize/free_funcs.d.ts +2 -2
- package/dest/serialize/free_funcs.d.ts.map +1 -1
- package/dest/serialize/free_funcs.js +1 -1
- package/dest/serialize/serialize.d.ts +20 -2
- package/dest/serialize/serialize.d.ts.map +1 -1
- package/dest/serialize/serialize.js +32 -1
- package/dest/sleep/index.d.ts +4 -1
- package/dest/sleep/index.d.ts.map +1 -1
- package/dest/sleep/index.js +14 -1
- package/dest/string/index.js +1 -1
- package/dest/timer/date.d.ts +26 -1
- package/dest/timer/date.d.ts.map +1 -1
- package/dest/timer/date.js +36 -0
- package/dest/transport/dispatch/create_dispatch_proxy.d.ts +11 -2
- package/dest/transport/dispatch/create_dispatch_proxy.d.ts.map +1 -1
- package/dest/transport/index.d.ts +1 -2
- package/dest/transport/index.d.ts.map +1 -1
- package/dest/transport/index.js +0 -1
- package/dest/transport/transport_client.js +2 -2
- package/dest/trees/balanced_merkle_tree_root.d.ts +16 -0
- package/dest/trees/balanced_merkle_tree_root.d.ts.map +1 -0
- package/dest/trees/{balanced_merkle_tree.js → balanced_merkle_tree_root.js} +3 -17
- package/dest/trees/hasher.d.ts +4 -1
- package/dest/trees/hasher.d.ts.map +1 -1
- package/dest/trees/hasher.js +10 -5
- package/dest/trees/index.d.ts +4 -4
- package/dest/trees/index.d.ts.map +1 -1
- package/dest/trees/index.js +3 -3
- package/dest/trees/indexed_merkle_tree.js +1 -1
- package/dest/trees/indexed_merkle_tree_calculator.d.ts +1 -1
- package/dest/trees/indexed_merkle_tree_calculator.d.ts.map +1 -1
- package/dest/trees/indexed_merkle_tree_calculator.js +5 -1
- package/dest/trees/membership_witness.d.ts +12 -2
- package/dest/trees/membership_witness.d.ts.map +1 -1
- package/dest/trees/membership_witness.js +10 -1
- package/dest/trees/merkle_tree_calculator.d.ts +4 -2
- package/dest/trees/merkle_tree_calculator.d.ts.map +1 -1
- package/dest/trees/merkle_tree_calculator.js +1 -5
- package/dest/trees/sibling_path.d.ts +4 -3
- package/dest/trees/sibling_path.d.ts.map +1 -1
- package/dest/trees/sibling_path.js +2 -6
- package/dest/trees/unbalanced_merkle_tree_calculator.d.ts +2 -3
- package/dest/trees/unbalanced_merkle_tree_calculator.d.ts.map +1 -1
- package/dest/trees/unbalanced_merkle_tree_calculator.js +1 -5
- package/dest/trees/{unbalanced_merkle_tree.d.ts → unbalanced_merkle_tree_root.d.ts} +4 -7
- package/dest/trees/unbalanced_merkle_tree_root.d.ts.map +1 -0
- package/dest/trees/{unbalanced_merkle_tree.js → unbalanced_merkle_tree_root.js} +12 -51
- package/dest/trees/unbalanced_tree_store.d.ts +5 -1
- package/dest/trees/unbalanced_tree_store.d.ts.map +1 -1
- package/dest/trees/unbalanced_tree_store.js +49 -1
- package/dest/types/index.d.ts +6 -2
- package/dest/types/index.d.ts.map +1 -1
- package/dest/types/index.js +6 -0
- package/package.json +49 -9
- package/src/array/index.ts +1 -0
- package/src/array/sorted_array.ts +138 -0
- package/src/branded-types/block_number.ts +117 -0
- package/src/branded-types/buffer32_hash.ts +42 -0
- package/src/branded-types/checkpoint_number.ts +120 -0
- package/src/branded-types/index.ts +4 -0
- package/src/branded-types/index_within_checkpoint.ts +88 -0
- package/src/branded-types/slot.ts +5 -0
- package/src/buffer/buffer16.ts +5 -2
- package/src/buffer/buffer32.ts +38 -67
- package/src/buffer/index.ts +1 -0
- package/src/buffer/utils.ts +8 -0
- package/src/collection/array.ts +66 -0
- package/src/collection/index.ts +1 -0
- package/src/collection/lru_set.ts +115 -0
- package/src/config/env_var.ts +95 -24
- package/src/config/index.ts +148 -88
- package/src/config/network_config.ts +5 -0
- package/src/config/network_name.ts +4 -1
- package/src/config/parse-env.ts +4 -0
- package/src/crypto/aes128/index.ts +11 -2
- package/src/crypto/bls/bn254_keystore.ts +1 -24
- package/src/crypto/bls/index.ts +1 -1
- package/src/crypto/bn254/index.ts +50 -159
- package/src/crypto/ecdsa/signature.ts +2 -2
- package/src/crypto/grumpkin/index.ts +3 -1
- package/src/crypto/keys/index.ts +1 -1
- package/src/crypto/pedersen/pedersen.wasm.ts +1 -1
- package/src/crypto/poseidon/index.ts +43 -45
- package/src/crypto/random/randomness_singleton.ts +6 -4
- package/src/crypto/schnorr/index.ts +2 -1
- package/src/crypto/schnorr/signature.ts +2 -2
- package/src/crypto/secp256k1-signer/utils.ts +32 -0
- package/src/crypto/sha256/index.ts +1 -1
- package/src/crypto/sha512/index.ts +1 -1
- package/src/crypto/signature/index.ts +1 -1
- package/src/crypto/sync/pedersen/index.ts +1 -1
- package/src/crypto/sync/poseidon/index.ts +1 -10
- package/src/{fields/bls12_fields.ts → curves/bls12/field.ts} +5 -12
- package/src/curves/bls12/index.ts +2 -0
- package/src/{fields/bls12_point.ts → curves/bls12/point.ts} +7 -7
- package/src/{fields/fields.ts → curves/bn254/field.ts} +61 -86
- package/src/curves/bn254/index.ts +2 -0
- package/src/curves/bn254/point.ts +170 -0
- package/src/curves/grumpkin/index.ts +11 -0
- package/src/{fields → curves/grumpkin}/point.ts +13 -10
- package/src/eth-address/index.ts +8 -6
- package/src/eth-signature/eth_signature.ts +7 -1
- package/src/fifo/fifo_frame_reader.ts +98 -0
- package/src/fifo/index.ts +1 -0
- package/src/iterator/filter.ts +11 -0
- package/src/iterator/index.ts +1 -0
- package/src/jest/setup.mjs +31 -1
- package/src/json-rpc/client/fetch.ts +4 -3
- package/src/json-rpc/client/safe_json_rpc_client.ts +2 -0
- package/src/json-rpc/client/undici.ts +23 -3
- package/src/json-rpc/server/api_key_auth.ts +63 -0
- package/src/json-rpc/server/index.ts +1 -0
- package/src/json-rpc/server/safe_json_rpc_server.ts +1 -1
- package/src/log/bigint-utils.ts +25 -0
- package/src/log/gcloud-logger-config.ts +5 -0
- package/src/log/libp2p_logger.ts +12 -5
- package/src/log/log-filters.ts +29 -11
- package/src/log/pino-logger-server.ts +25 -0
- package/src/log/pino-logger.ts +162 -40
- package/src/queue/base_memory_queue.ts +1 -1
- package/src/queue/batch_queue.ts +1 -0
- package/src/queue/semaphore.ts +5 -0
- package/src/retry/index.ts +48 -0
- package/src/schemas/api.ts +4 -1
- package/src/schemas/schemas.ts +14 -3
- package/src/schemas/types.ts +33 -0
- package/src/serialize/buffer_reader.ts +36 -9
- package/src/serialize/field_reader.ts +1 -1
- package/src/serialize/free_funcs.ts +1 -1
- package/src/serialize/serialize.ts +33 -1
- package/src/sleep/index.ts +16 -1
- package/src/string/index.ts +1 -1
- package/src/timer/date.ts +52 -0
- package/src/transport/dispatch/create_dispatch_proxy.ts +11 -1
- package/src/transport/index.ts +0 -1
- package/src/transport/transport_client.ts +2 -2
- package/src/trees/{balanced_merkle_tree.ts → balanced_merkle_tree_root.ts} +3 -20
- package/src/trees/hasher.ts +12 -0
- package/src/trees/index.ts +3 -3
- package/src/trees/indexed_merkle_tree.ts +1 -1
- package/src/trees/indexed_merkle_tree_calculator.ts +5 -1
- package/src/trees/membership_witness.ts +9 -1
- package/src/trees/merkle_tree_calculator.ts +4 -10
- package/src/trees/sibling_path.ts +2 -3
- package/src/trees/unbalanced_merkle_tree_calculator.ts +1 -12
- package/src/trees/{unbalanced_merkle_tree.ts → unbalanced_merkle_tree_root.ts} +17 -64
- package/src/trees/unbalanced_tree_store.ts +57 -2
- package/src/types/index.ts +11 -1
- package/dest/crypto/bn254/bn254_utils.d.ts +0 -39
- package/dest/crypto/bn254/bn254_utils.d.ts.map +0 -1
- package/dest/crypto/bn254/bn254_utils.js +0 -56
- package/dest/crypto/index.d.ts +0 -17
- package/dest/crypto/index.d.ts.map +0 -1
- package/dest/crypto/index.js +0 -16
- package/dest/crypto/serialize.d.ts +0 -51
- package/dest/crypto/serialize.d.ts.map +0 -1
- package/dest/crypto/serialize.js +0 -68
- package/dest/fields/bls12_fields.d.ts.map +0 -1
- package/dest/fields/bls12_point.d.ts.map +0 -1
- package/dest/fields/coordinate.d.ts +0 -63
- package/dest/fields/coordinate.d.ts.map +0 -1
- package/dest/fields/coordinate.js +0 -96
- package/dest/fields/fields.d.ts.map +0 -1
- package/dest/fields/index.d.ts +0 -6
- package/dest/fields/index.d.ts.map +0 -1
- package/dest/fields/index.js +0 -5
- package/dest/fields/point.d.ts.map +0 -1
- package/dest/index.d.ts +0 -31
- package/dest/index.d.ts.map +0 -1
- package/dest/index.js +0 -31
- package/dest/json-rpc/server/telemetry.d.ts +0 -2
- package/dest/json-rpc/server/telemetry.d.ts.map +0 -1
- package/dest/json-rpc/server/telemetry.js +0 -0
- package/dest/transport/dispatch/create_dispatch_fn.d.ts +0 -25
- package/dest/transport/dispatch/create_dispatch_fn.d.ts.map +0 -1
- package/dest/transport/dispatch/create_dispatch_fn.js +0 -17
- package/dest/trees/balanced_merkle_tree.d.ts +0 -22
- package/dest/trees/balanced_merkle_tree.d.ts.map +0 -1
- package/dest/trees/unbalanced_merkle_tree.d.ts.map +0 -1
- package/src/crypto/bn254/bn254_utils.ts +0 -64
- package/src/crypto/index.ts +0 -16
- package/src/crypto/serialize.ts +0 -85
- package/src/fields/coordinate.ts +0 -104
- package/src/fields/index.ts +0 -5
- package/src/index.ts +0 -31
- package/src/json-rpc/server/telemetry.ts +0 -0
- package/src/transport/dispatch/create_dispatch_fn.ts +0 -35
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { findLeafLevelAndIndex } from './unbalanced_merkle_tree.js';
|
|
2
1
|
export class UnbalancedTreeStore {
|
|
3
2
|
#nodeMapping = new Map();
|
|
4
3
|
#numLeaves;
|
|
@@ -98,3 +97,52 @@ export class UnbalancedTreeStore {
|
|
|
98
97
|
return `${location.level}-${location.index}`;
|
|
99
98
|
}
|
|
100
99
|
}
|
|
100
|
+
/// Get the depth of the maximum balanced tree that can be created with the given number of leaves. The subtree will be
|
|
101
|
+
/// the left most subtree of the unbalanced tree with a total of `numLeaves` leaves.
|
|
102
|
+
///
|
|
103
|
+
/// Note: All the leaves may not be used to form the tree. For example, if there are 5 leaves, the maximum depth is 2,
|
|
104
|
+
/// only 4 leaves are used to form a balanced tree.
|
|
105
|
+
function getMaxBalancedSubtreeDepth(numLeaves) {
|
|
106
|
+
return Math.floor(Math.log2(numLeaves));
|
|
107
|
+
}
|
|
108
|
+
/// Get the maximum depth of an unbalanced tree that can be created with the given number of leaves.
|
|
109
|
+
function getMaxUnbalancedTreeDepth(numLeaves) {
|
|
110
|
+
return Math.ceil(Math.log2(numLeaves));
|
|
111
|
+
}
|
|
112
|
+
function findPosition(rootLevel, leafLevel, numLeaves, indexOffset, targetIndex) {
|
|
113
|
+
if (numLeaves <= 1) {
|
|
114
|
+
// Single leaf.
|
|
115
|
+
return {
|
|
116
|
+
level: rootLevel,
|
|
117
|
+
indexAtLevel: indexOffset
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
// The largest balanced tree that can be created with the given number of leaves.
|
|
121
|
+
const maxBalancedTreeDepth = getMaxBalancedSubtreeDepth(numLeaves);
|
|
122
|
+
const numBalancedLeaves = 2 ** maxBalancedTreeDepth;
|
|
123
|
+
const numRemainingLeaves = numLeaves - numBalancedLeaves;
|
|
124
|
+
if (targetIndex < numBalancedLeaves) {
|
|
125
|
+
// Target is in the balanced tree.
|
|
126
|
+
// - If numRemainingLeaves is 0: this balanced tree is grown from the current root.
|
|
127
|
+
// - If numRemainingLeaves is not 0: the remaining leaves will form another tree, which will become the right child of the root.
|
|
128
|
+
// And the balanced tree will be the left child of the root.
|
|
129
|
+
// There will be an extra level between the root of the balanced tree and the current root.
|
|
130
|
+
const extraLevel = numRemainingLeaves ? 1 : 0;
|
|
131
|
+
return {
|
|
132
|
+
level: rootLevel + maxBalancedTreeDepth + extraLevel,
|
|
133
|
+
indexAtLevel: indexOffset + targetIndex
|
|
134
|
+
};
|
|
135
|
+
} else {
|
|
136
|
+
// Target is in the right branch.
|
|
137
|
+
const rightBranchMaxLevel = getMaxUnbalancedTreeDepth(numRemainingLeaves);
|
|
138
|
+
const shiftedUp = leafLevel - rootLevel - rightBranchMaxLevel - 1;
|
|
139
|
+
const nextLeafLevel = leafLevel - shiftedUp;
|
|
140
|
+
const newIndexOffset = indexOffset + numBalancedLeaves >> shiftedUp;
|
|
141
|
+
const shiftedTargetIndex = targetIndex - numBalancedLeaves;
|
|
142
|
+
return findPosition(rootLevel + 1, nextLeafLevel, numRemainingLeaves, newIndexOffset, shiftedTargetIndex);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
export function findLeafLevelAndIndex(numLeaves, leafIndex) {
|
|
146
|
+
const maxLevel = getMaxUnbalancedTreeDepth(numLeaves);
|
|
147
|
+
return findPosition(0, maxLevel, numLeaves, 0, leafIndex);
|
|
148
|
+
}
|
package/dest/types/index.d.ts
CHANGED
|
@@ -14,6 +14,10 @@ export type Writeable<T> = {
|
|
|
14
14
|
};
|
|
15
15
|
/** Removes readonly modifiers for an object. */
|
|
16
16
|
export declare function unfreeze<T>(obj: T): Writeable<T>;
|
|
17
|
+
/** Is defined type guard */
|
|
18
|
+
export declare function isDefined<T>(value: T | undefined): value is T;
|
|
19
|
+
/** Type guard for error classes */
|
|
20
|
+
export declare function isErrorClass<T extends Error>(value: unknown, errorClass: new (...args: any[]) => T): value is T;
|
|
17
21
|
/** Resolves a record-like type. Lifted from viem. */
|
|
18
22
|
export type Prettify<T> = {
|
|
19
23
|
[K in keyof T]: T[K];
|
|
@@ -22,7 +26,7 @@ export type Prettify<T> = {
|
|
|
22
26
|
* Type-safe Event Emitter type
|
|
23
27
|
* @example
|
|
24
28
|
* export type ArchiverEmitter = TypedEventEmitter<{
|
|
25
|
-
* [L2BlockSourceEvents.
|
|
29
|
+
* [L2BlockSourceEvents.L2PruneUnproven]: (args: L2BlockSourceEvent) => void;
|
|
26
30
|
* [L2BlockSourceEvents.L2BlockProven]: (args: L2BlockSourceEvent) => void;
|
|
27
31
|
* }>;
|
|
28
32
|
* class Archiver extends (EventEmitter as new () => ArchiverEmitter) {
|
|
@@ -39,4 +43,4 @@ export interface TypedEventEmitter<TEventMap extends {
|
|
|
39
43
|
removeListener<K extends keyof TEventMap>(event: K, listener: TEventMap[K]): this;
|
|
40
44
|
removeAllListeners<K extends keyof TEventMap>(event: K): this;
|
|
41
45
|
}
|
|
42
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
46
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy90eXBlcy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxnQ0FBZ0M7QUFDaEMsTUFBTSxNQUFNLFFBQVEsQ0FBQyxDQUFDLElBQUk7S0FDdkIsQ0FBQyxJQUFJLE1BQU0sQ0FBQyxJQUFJLENBQUMsQ0FBQyxDQUFDLENBQUMsU0FBUyxRQUFRLEdBQUcsS0FBSyxH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,SAAS,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI;CAAE;IACzG,IAAI,CAAC,CAAC,SAAS,MAAM,SAAS,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IACxE,EAAE,CAAC,CAAC,SAAS,MAAM,SAAS,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IACtE,GAAG,CAAC,CAAC,SAAS,MAAM,SAAS,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IACvE,IAAI,CAAC,CAAC,SAAS,MAAM,SAAS,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,IAAI,EAAE,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC;IACtF,cAAc,CAAC,CAAC,SAAS,MAAM,SAAS,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IAClF,kBAAkB,CAAC,CAAC,SAAS,MAAM,SAAS,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI,CAAC;CAE/D"}
|
package/dest/types/index.js
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
1
|
/** Strips methods of a type. */ /** Removes readonly modifiers for an object. */ export function unfreeze(obj) {
|
|
2
2
|
return obj;
|
|
3
3
|
}
|
|
4
|
+
/** Is defined type guard */ export function isDefined(value) {
|
|
5
|
+
return value !== undefined;
|
|
6
|
+
}
|
|
7
|
+
/** Type guard for error classes */ export function isErrorClass(value, errorClass) {
|
|
8
|
+
return value instanceof errorClass || value instanceof Error && value.name === errorClass.name;
|
|
9
|
+
}
|
package/package.json
CHANGED
|
@@ -1,9 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/foundation",
|
|
3
|
-
"version": "0.0.1-commit.
|
|
3
|
+
"version": "0.0.1-commit.9badcec54",
|
|
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",
|
|
@@ -15,14 +35,33 @@
|
|
|
15
35
|
"./branded-types": "./dest/branded-types/index.js",
|
|
16
36
|
"./collection": "./dest/collection/index.js",
|
|
17
37
|
"./config": "./dest/config/index.js",
|
|
18
|
-
"./crypto": "./dest/crypto/index.js",
|
|
19
|
-
"./crypto/
|
|
38
|
+
"./crypto/aes128": "./dest/crypto/aes128/index.js",
|
|
39
|
+
"./crypto/bls": "./dest/crypto/bls/index.js",
|
|
20
40
|
"./crypto/bls/bn254_keystore": "./dest/crypto/bls/bn254_keystore.js",
|
|
41
|
+
"./crypto/bn254": "./dest/crypto/bn254/index.js",
|
|
42
|
+
"./crypto/ecdsa": "./dest/crypto/ecdsa/index.js",
|
|
43
|
+
"./crypto/grumpkin": "./dest/crypto/grumpkin/index.js",
|
|
44
|
+
"./crypto/keccak": "./dest/crypto/keccak/index.js",
|
|
45
|
+
"./crypto/keys": "./dest/crypto/keys/index.js",
|
|
46
|
+
"./crypto/pedersen": "./dest/crypto/pedersen/index.js",
|
|
47
|
+
"./crypto/poseidon": "./dest/crypto/poseidon/index.js",
|
|
48
|
+
"./crypto/random": "./dest/crypto/random/index.js",
|
|
49
|
+
"./crypto/schnorr": "./dest/crypto/schnorr/index.js",
|
|
50
|
+
"./crypto/secp256k1": "./dest/crypto/secp256k1/index.js",
|
|
51
|
+
"./crypto/secp256k1-signer": "./dest/crypto/secp256k1-signer/index.js",
|
|
52
|
+
"./crypto/sha256": "./dest/crypto/sha256/index.js",
|
|
53
|
+
"./crypto/sha512": "./dest/crypto/sha512/index.js",
|
|
54
|
+
"./crypto/signature": "./dest/crypto/signature/index.js",
|
|
55
|
+
"./crypto/sync": "./dest/crypto/sync/index.js",
|
|
56
|
+
"./curves/bn254": "./dest/curves/bn254/index.js",
|
|
57
|
+
"./curves/grumpkin": "./dest/curves/grumpkin/index.js",
|
|
58
|
+
"./curves/bls12": "./dest/curves/bls12/index.js",
|
|
21
59
|
"./decorators": "./dest/decorators/index.js",
|
|
22
60
|
"./error": "./dest/error/index.js",
|
|
23
61
|
"./eth-address": "./dest/eth-address/index.js",
|
|
24
62
|
"./eth-signature": "./dest/eth-signature/index.js",
|
|
25
63
|
"./queue": "./dest/queue/index.js",
|
|
64
|
+
"./fifo": "./dest/fifo/index.js",
|
|
26
65
|
"./fs": "./dest/fs/index.js",
|
|
27
66
|
"./buffer": "./dest/buffer/index.js",
|
|
28
67
|
"./json-rpc": "./dest/json-rpc/index.js",
|
|
@@ -31,9 +70,10 @@
|
|
|
31
70
|
"./json-rpc/undici": "./dest/json-rpc/client/undici.js",
|
|
32
71
|
"./json-rpc/test": "./dest/json-rpc/test/index.js",
|
|
33
72
|
"./iterable": "./dest/iterable/index.js",
|
|
73
|
+
"./iterator": "./dest/iterator/index.js",
|
|
34
74
|
"./log": "./dest/log/index.js",
|
|
75
|
+
"./log/server": "./dest/log/pino-logger-server.js",
|
|
35
76
|
"./mutex": "./dest/mutex/index.js",
|
|
36
|
-
"./fields": "./dest/fields/index.js",
|
|
37
77
|
"./retry": "./dest/retry/index.js",
|
|
38
78
|
"./running-promise": "./dest/running-promise/index.js",
|
|
39
79
|
"./serialize": "./dest/serialize/index.js",
|
|
@@ -58,8 +98,8 @@
|
|
|
58
98
|
"./number": "./dest/number/index.js"
|
|
59
99
|
},
|
|
60
100
|
"scripts": {
|
|
61
|
-
"build": "yarn clean &&
|
|
62
|
-
"build:dev": "
|
|
101
|
+
"build": "yarn clean && ../scripts/tsc.sh",
|
|
102
|
+
"build:dev": "../scripts/tsc.sh --watch",
|
|
63
103
|
"clean": "rm -rf ./dest .tsbuildinfo",
|
|
64
104
|
"generate": "true",
|
|
65
105
|
"test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}"
|
|
@@ -105,7 +145,7 @@
|
|
|
105
145
|
"testEnvironment": "../../foundation/src/jest/env.mjs"
|
|
106
146
|
},
|
|
107
147
|
"dependencies": {
|
|
108
|
-
"@aztec/bb.js": "0.0.1-commit.
|
|
148
|
+
"@aztec/bb.js": "0.0.1-commit.9badcec54",
|
|
109
149
|
"@koa/cors": "^5.0.0",
|
|
110
150
|
"@noble/curves": "=1.7.0",
|
|
111
151
|
"@noble/hashes": "^1.6.1",
|
|
@@ -144,11 +184,11 @@
|
|
|
144
184
|
"@types/node": "^22.15.17",
|
|
145
185
|
"@types/pako": "^2.0.0",
|
|
146
186
|
"@types/supertest": "^2.0.12",
|
|
147
|
-
"@typescript/native-preview": "7.0.0-dev.
|
|
187
|
+
"@typescript/native-preview": "7.0.0-dev.20260113.1",
|
|
148
188
|
"comlink": "^4.4.1",
|
|
149
189
|
"eslint": "^9.26.0",
|
|
150
190
|
"eslint-config-prettier": "^10.1.5",
|
|
151
|
-
"eslint-plugin-import": "^
|
|
191
|
+
"eslint-plugin-import-x": "^4.6.1",
|
|
152
192
|
"eslint-plugin-jsdoc": "^50.6.14",
|
|
153
193
|
"eslint-plugin-no-only-tests": "^3.3.0",
|
|
154
194
|
"eslint-plugin-tsdoc": "^0.4.0",
|
package/src/array/index.ts
CHANGED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
type Cmp<T> = (a: T, b: T) => -1 | 0 | 1;
|
|
2
|
+
|
|
3
|
+
export function dedupeSortedArray<T>(arr: T[], cmp: Cmp<T>): void {
|
|
4
|
+
for (let i = 0; i < arr.length; i++) {
|
|
5
|
+
let j = i + 1;
|
|
6
|
+
for (; j < arr.length; j++) {
|
|
7
|
+
const res = cmp(arr[i], arr[j]);
|
|
8
|
+
if (res === 0) {
|
|
9
|
+
continue;
|
|
10
|
+
} else if (res < 0) {
|
|
11
|
+
break;
|
|
12
|
+
} else {
|
|
13
|
+
throw new Error('Array not sorted');
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (j - i > 1) {
|
|
18
|
+
arr.splice(i + 1, j - i - 1);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
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 {
|
|
42
|
+
let start = 0;
|
|
43
|
+
let end = values.length;
|
|
44
|
+
|
|
45
|
+
while (start < end) {
|
|
46
|
+
const mid = start + (((end - start) / 2) | 0);
|
|
47
|
+
const comparison = cmp(values[mid], needle);
|
|
48
|
+
|
|
49
|
+
if (comparison <= 0) {
|
|
50
|
+
start = mid + 1;
|
|
51
|
+
} else {
|
|
52
|
+
end = mid;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return start;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function findIndexInSortedArray<T, N>(values: T[], needle: N, cmp: (a: T, b: N) => number): number {
|
|
60
|
+
let start = 0;
|
|
61
|
+
let end = values.length - 1;
|
|
62
|
+
|
|
63
|
+
while (start <= end) {
|
|
64
|
+
const mid = start + (((end - start) / 2) | 0);
|
|
65
|
+
const comparison = cmp(values[mid], needle);
|
|
66
|
+
|
|
67
|
+
if (comparison === 0) {
|
|
68
|
+
return mid;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (comparison > 0) {
|
|
72
|
+
end = mid - 1;
|
|
73
|
+
} else {
|
|
74
|
+
start = mid + 1;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return -1;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export function findInSortedArray<T, N>(values: T[], needle: N, cmp: (a: T, b: N) => number): T | undefined {
|
|
82
|
+
const idx = findIndexInSortedArray(values, needle, cmp);
|
|
83
|
+
return idx > -1 ? values[idx] : undefined;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function removeAnyOf<T, N>(arr: T[], vals: N[], cmp: (a: T, b: N) => -1 | 0 | 1): void {
|
|
87
|
+
let writeIdx = 0;
|
|
88
|
+
let readIdx = 0;
|
|
89
|
+
let valIdx = 0;
|
|
90
|
+
|
|
91
|
+
while (readIdx < arr.length && valIdx < vals.length) {
|
|
92
|
+
const comparison = cmp(arr[readIdx], vals[valIdx]);
|
|
93
|
+
|
|
94
|
+
if (comparison < 0) {
|
|
95
|
+
arr[writeIdx++] = arr[readIdx++];
|
|
96
|
+
} else if (comparison > 0) {
|
|
97
|
+
valIdx++;
|
|
98
|
+
} else {
|
|
99
|
+
readIdx++;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
while (readIdx < arr.length) {
|
|
104
|
+
arr[writeIdx++] = arr[readIdx++];
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
arr.length = writeIdx;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export function removeFromSortedArray<T, N>(arr: T[], val: N, cmp: (a: T, b: N) => -1 | 0 | 1) {
|
|
111
|
+
const idx = findIndexInSortedArray(arr, val, cmp);
|
|
112
|
+
if (idx > -1) {
|
|
113
|
+
arr.splice(idx, 1);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export function merge<T>(arr: T[], toInsert: T[], cmp: (a: T, b: T) => -1 | 0 | 1): void {
|
|
118
|
+
const result = new Array<T>(arr.length + toInsert.length);
|
|
119
|
+
let i = 0,
|
|
120
|
+
j = 0,
|
|
121
|
+
k = 0;
|
|
122
|
+
|
|
123
|
+
while (i < arr.length && j < toInsert.length) {
|
|
124
|
+
result[k++] = cmp(arr[i], toInsert[j]) <= 0 ? arr[i++] : toInsert[j++];
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
while (i < arr.length) {
|
|
128
|
+
result[k++] = arr[i++];
|
|
129
|
+
}
|
|
130
|
+
while (j < toInsert.length) {
|
|
131
|
+
result[k++] = toInsert[j++];
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
for (i = 0; i < result.length; i++) {
|
|
135
|
+
arr[i] = result[i];
|
|
136
|
+
}
|
|
137
|
+
arr.length = result.length;
|
|
138
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
import type { CheckpointNumber } from './checkpoint_number.js';
|
|
4
|
+
import type { Branded } from './types.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A branded type representing an Aztec (L2) block number.
|
|
8
|
+
* Block numbers are sequential identifiers for blocks in the Aztec rollup chain.
|
|
9
|
+
*
|
|
10
|
+
* This is a nominal type backed by a number, but TypeScript will treat it as
|
|
11
|
+
* incompatible with plain numbers and other branded numeric types (like EpochNumber, SlotNumber, etc.).
|
|
12
|
+
*
|
|
13
|
+
* Note: This type should ONLY be used for Aztec L2 block numbers, NOT for Ethereum L1 block numbers.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* const blockNumber = BlockNumber(100);
|
|
18
|
+
* const plainNumber: number = blockNumber; // OK - BlockNumber is assignable to number
|
|
19
|
+
* const blockFromNumber: BlockNumber = 100; // ERROR - number is not assignable to BlockNumber
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export type BlockNumber = Branded<number, 'BlockNumber'>;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Creates a BlockNumber from a number.
|
|
26
|
+
* @param value - The block number (must be a non-negative integer)
|
|
27
|
+
* @returns The branded BlockNumber value
|
|
28
|
+
* @throws If the value is negative or not an integer
|
|
29
|
+
*/
|
|
30
|
+
export function BlockNumber(value: number): BlockNumber {
|
|
31
|
+
if (!Number.isInteger(value)) {
|
|
32
|
+
throw new Error(`BlockNumber must be an integer, got ${value}`);
|
|
33
|
+
}
|
|
34
|
+
if (value < 0) {
|
|
35
|
+
throw new Error(`BlockNumber must be non-negative, got ${value}`);
|
|
36
|
+
}
|
|
37
|
+
return value as BlockNumber;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Creates a BlockNumber from a bigint.
|
|
42
|
+
* @param value - The block number as bigint (must be a non-negative integer within safe integer range)
|
|
43
|
+
* @returns The branded BlockNumber value
|
|
44
|
+
* @throws If the value is negative or exceeds Number.MAX_SAFE_INTEGER
|
|
45
|
+
*/
|
|
46
|
+
BlockNumber.fromBigInt = function (value: bigint): BlockNumber {
|
|
47
|
+
if (value < 0n) {
|
|
48
|
+
throw new Error(`BlockNumber must be non-negative, got ${value}`);
|
|
49
|
+
}
|
|
50
|
+
if (value > BigInt(Number.MAX_SAFE_INTEGER)) {
|
|
51
|
+
throw new Error(`BlockNumber ${value} exceeds MAX_SAFE_INTEGER`);
|
|
52
|
+
}
|
|
53
|
+
return Number(value) as BlockNumber;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Creates a BlockNumber from a string.
|
|
58
|
+
* @param value - The block number as a string
|
|
59
|
+
* @returns The branded BlockNumber value
|
|
60
|
+
* @throws If the string cannot be parsed as a valid block number
|
|
61
|
+
*/
|
|
62
|
+
BlockNumber.fromString = function (value: string): BlockNumber {
|
|
63
|
+
const parsed = parseInt(value, 10);
|
|
64
|
+
if (isNaN(parsed)) {
|
|
65
|
+
throw new Error(`Cannot parse BlockNumber from string: ${value}`);
|
|
66
|
+
}
|
|
67
|
+
return BlockNumber(parsed);
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Converts a CheckpointNumber to a BlockNumber.
|
|
72
|
+
* This is used in checkpoint-based systems where checkpoint numbers align with block numbers.
|
|
73
|
+
* WARNING: This should only be used when you know the checkpoint number corresponds to a block number.
|
|
74
|
+
* @param value - The checkpoint number to convert
|
|
75
|
+
* @returns The corresponding BlockNumber
|
|
76
|
+
*/
|
|
77
|
+
BlockNumber.fromCheckpointNumber = function (value: CheckpointNumber): BlockNumber {
|
|
78
|
+
return value as unknown as BlockNumber;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Type guard to check if a value is a valid BlockNumber.
|
|
83
|
+
* Note: At runtime, a BlockNumber is just a number, so this checks if the value
|
|
84
|
+
* is a non-negative integer.
|
|
85
|
+
*/
|
|
86
|
+
BlockNumber.isValid = function (value: unknown): value is BlockNumber {
|
|
87
|
+
return typeof value === 'number' && Number.isInteger(value) && value >= 0;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
/** Increments a BlockNumber by a given value. */
|
|
91
|
+
BlockNumber.add = function (bn: BlockNumber, increment: number): BlockNumber {
|
|
92
|
+
return BlockNumber(bn + increment);
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* The zero block value (genesis block).
|
|
97
|
+
*/
|
|
98
|
+
BlockNumber.ZERO = BlockNumber(0);
|
|
99
|
+
|
|
100
|
+
function makeBlockNumberSchema(minValue: number) {
|
|
101
|
+
return z
|
|
102
|
+
.union([z.number(), z.bigint(), z.string()])
|
|
103
|
+
.pipe(z.coerce.number().int().min(minValue))
|
|
104
|
+
.transform(value => BlockNumber(value));
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Zod schema for parsing and validating BlockNumber values.
|
|
109
|
+
* Accepts numbers, bigints, or strings and coerces them to BlockNumber.
|
|
110
|
+
*/
|
|
111
|
+
export const BlockNumberSchema = makeBlockNumberSchema(0);
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Zod schema for parsing and validating BlockNumber values that are strictly positive.
|
|
115
|
+
* Accepts numbers, bigints, or strings and coerces them to BlockNumber.
|
|
116
|
+
*/
|
|
117
|
+
export const BlockNumberPositiveSchema = makeBlockNumberSchema(1);
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { BaseBuffer32 } from '../buffer/buffer32.js';
|
|
2
|
+
import { Buffer32 } from '../buffer/buffer32.js';
|
|
3
|
+
import type { Branded } from './types.js';
|
|
4
|
+
|
|
5
|
+
/** A branded Buffer32 representing a block proposal hash, used for p2p deduplication. */
|
|
6
|
+
export type BlockProposalHash = Branded<BaseBuffer32, 'BlockProposalHash'>;
|
|
7
|
+
|
|
8
|
+
/** Creates a BlockProposalHash from a BaseBuffer32. */
|
|
9
|
+
export function BlockProposalHash(buf: BaseBuffer32): BlockProposalHash {
|
|
10
|
+
return buf as BlockProposalHash;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** Creates a BlockProposalHash from a raw Buffer. */
|
|
14
|
+
BlockProposalHash.fromBuffer = function (buf: Buffer): BlockProposalHash {
|
|
15
|
+
return new Buffer32(buf) as unknown as BlockProposalHash;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/** A branded Buffer32 representing a checkpoint proposal hash, used for p2p deduplication. */
|
|
19
|
+
export type CheckpointProposalHash = Branded<BaseBuffer32, 'CheckpointProposalHash'>;
|
|
20
|
+
|
|
21
|
+
/** Creates a CheckpointProposalHash from a BaseBuffer32. */
|
|
22
|
+
export function CheckpointProposalHash(buf: BaseBuffer32): CheckpointProposalHash {
|
|
23
|
+
return buf as CheckpointProposalHash;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Creates a CheckpointProposalHash from a raw Buffer. */
|
|
27
|
+
CheckpointProposalHash.fromBuffer = function (buf: Buffer): CheckpointProposalHash {
|
|
28
|
+
return new Buffer32(buf) as unknown as CheckpointProposalHash;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
/** A branded Buffer32 representing a checkpoint attestation hash, used for p2p deduplication. */
|
|
32
|
+
export type CheckpointAttestationHash = Branded<BaseBuffer32, 'CheckpointAttestationHash'>;
|
|
33
|
+
|
|
34
|
+
/** Creates a CheckpointAttestationHash from a BaseBuffer32. */
|
|
35
|
+
export function CheckpointAttestationHash(buf: BaseBuffer32): CheckpointAttestationHash {
|
|
36
|
+
return buf as CheckpointAttestationHash;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Creates a CheckpointAttestationHash from a raw Buffer. */
|
|
40
|
+
CheckpointAttestationHash.fromBuffer = function (buf: Buffer): CheckpointAttestationHash {
|
|
41
|
+
return new Buffer32(buf) as unknown as CheckpointAttestationHash;
|
|
42
|
+
};
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
import type { BlockNumber } from './block_number.js';
|
|
4
|
+
import type { Branded } from './types.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A branded type representing an checkpoint number.
|
|
8
|
+
* Checkpoints are used in the Aztec protocol to group L2 blocks.
|
|
9
|
+
*
|
|
10
|
+
* This is a nominal type backed by a number, but TypeScript will treat it as
|
|
11
|
+
* incompatible with plain numbers and other branded numeric types (like Slot, BlockNumber, etc.).
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* const checkpoint = CheckpointNumber(5);
|
|
16
|
+
* const plainNumber: number = checkpoint; // OK - CheckpointNumber is assignable to number
|
|
17
|
+
* const checkpointFromNumber: CheckpointNumber = 5; // ERROR - number is not assignable to CheckpointNumber
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export type CheckpointNumber = Branded<number, 'CheckpointNumber'>;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Creates an CheckpointNumber from a number.
|
|
24
|
+
* @param value - The checkpoint number (must be a non-negative integer)
|
|
25
|
+
* @returns The branded CheckpointNumber value
|
|
26
|
+
* @throws If the value is negative or not an integer
|
|
27
|
+
*/
|
|
28
|
+
export function CheckpointNumber(value: number): CheckpointNumber {
|
|
29
|
+
if (!Number.isInteger(value)) {
|
|
30
|
+
throw new Error(`CheckpointNumber must be an integer, got ${value}`);
|
|
31
|
+
}
|
|
32
|
+
if (value < 0) {
|
|
33
|
+
throw new Error(`CheckpointNumber must be non-negative, got ${value}`);
|
|
34
|
+
}
|
|
35
|
+
return value as CheckpointNumber;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* @param value - The block number
|
|
40
|
+
* @returns The branded CheckpointNumber value
|
|
41
|
+
*
|
|
42
|
+
* @deprecated Checkpoint number and block number should no longer convert to each other once we support multiple blocks
|
|
43
|
+
* per checkpoint everywhere.
|
|
44
|
+
*/
|
|
45
|
+
CheckpointNumber.fromBlockNumber = function (value: BlockNumber): CheckpointNumber {
|
|
46
|
+
return CheckpointNumber(value);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Creates an CheckpointNumber from a bigint.
|
|
51
|
+
* @param value - The checkpoint number as bigint (must be a non-negative integer within safe integer range)
|
|
52
|
+
* @returns The branded CheckpointNumber value
|
|
53
|
+
* @throws If the value is negative or exceeds Number.MAX_SAFE_INTEGER
|
|
54
|
+
*/
|
|
55
|
+
CheckpointNumber.fromBigInt = function (value: bigint): CheckpointNumber {
|
|
56
|
+
if (value < 0n) {
|
|
57
|
+
throw new Error(`CheckpointNumber must be non-negative, got ${value}`);
|
|
58
|
+
}
|
|
59
|
+
if (value > BigInt(Number.MAX_SAFE_INTEGER)) {
|
|
60
|
+
throw new Error(`CheckpointNumber ${value} exceeds MAX_SAFE_INTEGER`);
|
|
61
|
+
}
|
|
62
|
+
return Number(value) as CheckpointNumber;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Creates an CheckpointNumber from a string.
|
|
67
|
+
* @param value - The checkpoint number as a string
|
|
68
|
+
* @returns The branded CheckpointNumber value
|
|
69
|
+
* @throws If the string cannot be parsed as a valid checkpoint
|
|
70
|
+
*/
|
|
71
|
+
CheckpointNumber.fromString = function (value: string): CheckpointNumber {
|
|
72
|
+
const parsed = parseInt(value, 10);
|
|
73
|
+
if (isNaN(parsed)) {
|
|
74
|
+
throw new Error(`Cannot parse CheckpointNumber from string: ${value}`);
|
|
75
|
+
}
|
|
76
|
+
return CheckpointNumber(parsed);
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Type guard to check if a value is a valid CheckpointNumber.
|
|
81
|
+
* Note: At runtime, an CheckpointNumber is just a number, so this checks if the value
|
|
82
|
+
* is a non-negative integer.
|
|
83
|
+
*/
|
|
84
|
+
CheckpointNumber.isValid = function (value: unknown): value is CheckpointNumber {
|
|
85
|
+
return typeof value === 'number' && Number.isInteger(value) && value >= 0;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
/** Increments a CheckpointNumber by a given value. */
|
|
89
|
+
CheckpointNumber.add = function (n: CheckpointNumber, increment: number): CheckpointNumber {
|
|
90
|
+
return CheckpointNumber(n + increment);
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
/** The zero checkpoint value. */
|
|
94
|
+
CheckpointNumber.ZERO = CheckpointNumber(0);
|
|
95
|
+
|
|
96
|
+
/** Initial checkpoint. */
|
|
97
|
+
CheckpointNumber.INITIAL = CheckpointNumber(1);
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Zod schema for parsing and validating CheckpointNumber values.
|
|
101
|
+
* Accepts numbers, bigints, or strings and coerces them to CheckpointNumber.
|
|
102
|
+
*/
|
|
103
|
+
function makeCheckpointNumberSchema(minValue: number) {
|
|
104
|
+
return z
|
|
105
|
+
.union([z.number(), z.bigint(), z.string()])
|
|
106
|
+
.pipe(z.coerce.number().int().min(minValue))
|
|
107
|
+
.transform(value => CheckpointNumber(value));
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Zod schema for parsing and validating Checkpoint values.
|
|
112
|
+
* Accepts numbers, bigints, or strings and coerces them to CheckpointNumber.
|
|
113
|
+
*/
|
|
114
|
+
export const CheckpointNumberSchema = makeCheckpointNumberSchema(0);
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Zod schema for parsing and validating CheckpointNumber values that are strictly positive.
|
|
118
|
+
* Accepts numbers, bigints, or strings and coerces them to CheckpointNumber.
|
|
119
|
+
*/
|
|
120
|
+
export const CheckpointNumberPositiveSchema = makeCheckpointNumberSchema(1);
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
+
export { BlockNumber, BlockNumberSchema, BlockNumberPositiveSchema } from './block_number.js';
|
|
2
|
+
export { BlockProposalHash, CheckpointAttestationHash, CheckpointProposalHash } from './buffer32_hash.js';
|
|
3
|
+
export { CheckpointNumber, CheckpointNumberSchema, CheckpointNumberPositiveSchema } from './checkpoint_number.js';
|
|
1
4
|
export { EpochNumber, EpochNumberSchema } from './epoch.js';
|
|
5
|
+
export { IndexWithinCheckpoint, IndexWithinCheckpointSchema } from './index_within_checkpoint.js';
|
|
2
6
|
export { SlotNumber, SlotNumberSchema } from './slot.js';
|
|
3
7
|
|
|
4
8
|
export type { Branded } from './types.js';
|