@aztec/foundation 0.0.1-commit.b655e406 → 0.0.1-commit.bf2612ae
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/array.d.ts +1 -9
- package/dest/array/array.d.ts.map +1 -1
- package/dest/array/array.js +0 -11
- 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 +10 -0
- package/dest/array/sorted_array.d.ts.map +1 -0
- package/dest/array/sorted_array.js +106 -0
- package/dest/async-map/index.d.ts +1 -1
- package/dest/async-pool/index.d.ts +1 -1
- package/dest/bigint/index.d.ts +1 -1
- package/dest/bigint-buffer/index.d.ts +1 -1
- 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/checkpoint_number.d.ts +54 -0
- package/dest/branded-types/checkpoint_number.d.ts.map +1 -0
- package/dest/branded-types/checkpoint_number.js +77 -0
- package/dest/branded-types/epoch.d.ts +42 -0
- package/dest/branded-types/epoch.d.ts.map +1 -0
- package/dest/branded-types/epoch.js +59 -0
- package/dest/branded-types/index.d.ts +7 -0
- package/dest/branded-types/index.d.ts.map +1 -0
- package/dest/branded-types/index.js +5 -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 +42 -0
- package/dest/branded-types/slot.d.ts.map +1 -0
- package/dest/branded-types/slot.js +59 -0
- package/dest/branded-types/types.d.ts +5 -0
- package/dest/branded-types/types.d.ts.map +1 -0
- package/dest/branded-types/types.js +1 -0
- package/dest/buffer/buffer16.d.ts +2 -2
- package/dest/buffer/buffer16.d.ts.map +1 -1
- package/dest/buffer/buffer16.js +4 -2
- package/dest/buffer/buffer32.d.ts +2 -2
- package/dest/buffer/buffer32.d.ts.map +1 -1
- package/dest/buffer/buffer32.js +4 -2
- package/dest/buffer/index.d.ts +1 -1
- package/dest/collection/array.d.ts +6 -1
- package/dest/collection/array.d.ts.map +1 -1
- package/dest/collection/array.js +27 -0
- package/dest/collection/index.d.ts +1 -1
- package/dest/collection/object.d.ts +1 -1
- package/dest/committable/committable.d.ts +1 -1
- package/dest/committable/committable.d.ts.map +1 -1
- package/dest/committable/index.d.ts +1 -1
- 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 +15 -4
- package/dest/config/index.d.ts.map +1 -1
- package/dest/config/index.js +32 -9
- package/dest/config/network_config.d.ts +13 -1
- package/dest/config/network_config.d.ts.map +1 -1
- package/dest/config/network_config.js +3 -1
- package/dest/config/network_name.d.ts +1 -1
- 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.d.ts +1 -1
- package/dest/config/secret_value.d.ts.map +1 -1
- package/dest/config/secret_value.js +3 -1
- package/dest/crypto/aes128/index.d.ts +1 -1
- package/dest/crypto/aes128/index.d.ts.map +1 -1
- package/dest/crypto/aes128/index.js +2 -6
- package/dest/crypto/bls/bn254_keystore.d.ts +15 -15
- package/dest/crypto/bls/bn254_keystore.d.ts.map +1 -1
- package/dest/crypto/bls/bn254_keystore.js +1 -1
- package/dest/crypto/bls/index.d.ts +1 -1
- 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 -137
- package/dest/crypto/ecdsa/index.d.ts +1 -1
- package/dest/crypto/ecdsa/index.d.ts.map +1 -1
- package/dest/crypto/ecdsa/index.js +4 -12
- package/dest/crypto/ecdsa/signature.d.ts +2 -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 +7 -16
- package/dest/crypto/keccak/index.d.ts +1 -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 +2 -4
- package/dest/crypto/pedersen/index.d.ts +1 -1
- package/dest/crypto/pedersen/pedersen.noble.d.ts +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 +4 -10
- 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 +5 -24
- package/dest/crypto/random/index.d.ts +1 -1
- package/dest/crypto/random/index.d.ts.map +1 -1
- package/dest/crypto/random/randomness_singleton.d.ts +2 -2
- package/dest/crypto/random/randomness_singleton.d.ts.map +1 -1
- package/dest/crypto/random/randomness_singleton.js +3 -3
- 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 +4 -10
- 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/index.d.ts +1 -1
- package/dest/crypto/secp256k1/index.d.ts.map +1 -1
- package/dest/crypto/secp256k1/index.js +3 -9
- package/dest/crypto/secp256k1-signer/index.d.ts +1 -1
- package/dest/crypto/secp256k1-signer/secp256k1_signer.d.ts +1 -1
- package/dest/crypto/secp256k1-signer/secp256k1_signer.d.ts.map +1 -1
- package/dest/crypto/secp256k1-signer/utils.d.ts +1 -1
- package/dest/crypto/secp256k1-signer/utils.d.ts.map +1 -1
- package/dest/crypto/serialize.d.ts +1 -1
- 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 +3 -3
- 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/index.d.ts +1 -1
- package/dest/crypto/sync/index.js +1 -3
- 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} +12 -9
- 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} +4 -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} +16 -15
- package/dest/curves/bn254/field.d.ts.map +1 -0
- package/dest/{fields/fields.js → curves/bn254/field.js} +49 -49
- 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 +12 -3
- package/dest/curves/grumpkin/point.d.ts.map +1 -0
- package/dest/{fields → curves/grumpkin}/point.js +24 -7
- package/dest/decorators/index.d.ts +1 -1
- package/dest/decorators/memoize.d.ts +1 -1
- package/dest/decorators/memoize.d.ts.map +1 -1
- package/dest/error/index.d.ts +1 -1
- package/dest/eth-address/index.d.ts +12 -2
- package/dest/eth-address/index.d.ts.map +1 -1
- package/dest/eth-address/index.js +27 -3
- package/dest/eth-signature/eth_signature.d.ts +1 -1
- package/dest/eth-signature/eth_signature.d.ts.map +1 -1
- package/dest/eth-signature/index.d.ts +1 -1
- package/dest/fs/index.d.ts +1 -1
- package/dest/fs/run_in_dir.d.ts +1 -1
- package/dest/fs/try_rm_dir.d.ts +1 -1
- package/dest/iterable/all.d.ts +1 -1
- package/dest/iterable/filter.d.ts +1 -1
- package/dest/iterable/index.d.ts +1 -1
- package/dest/iterable/isAsyncIt.d.ts +1 -1
- package/dest/iterable/map.d.ts +1 -1
- package/dest/iterable/peek.d.ts +1 -1
- package/dest/iterable/sort.d.ts +1 -1
- package/dest/iterable/take.d.ts +1 -1
- package/dest/iterable/toArray.d.ts +1 -1
- 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/json-rpc/client/fetch.d.ts +1 -1
- package/dest/json-rpc/client/index.d.ts +1 -1
- package/dest/json-rpc/client/safe_json_rpc_client.d.ts +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 +21 -4
- package/dest/json-rpc/convert.d.ts +1 -1
- package/dest/json-rpc/errors.d.ts +1 -1
- package/dest/json-rpc/errors.d.ts.map +1 -1
- package/dest/json-rpc/fixtures/class_a.d.ts +1 -1
- package/dest/json-rpc/fixtures/class_a.d.ts.map +1 -1
- package/dest/json-rpc/fixtures/class_b.d.ts +1 -1
- package/dest/json-rpc/fixtures/class_b.d.ts.map +1 -1
- package/dest/json-rpc/fixtures/test_state.d.ts +1 -1
- package/dest/json-rpc/fixtures/test_state.d.ts.map +1 -1
- package/dest/json-rpc/index.d.ts +1 -1
- package/dest/json-rpc/js_utils.d.ts +1 -1
- package/dest/json-rpc/js_utils.d.ts.map +1 -1
- package/dest/json-rpc/server/index.d.ts +1 -1
- package/dest/json-rpc/server/safe_json_rpc_server.d.ts +1 -1
- package/dest/json-rpc/server/safe_json_rpc_server.d.ts.map +1 -1
- package/dest/json-rpc/server/safe_json_rpc_server.js +1 -1
- package/dest/json-rpc/test/index.d.ts +1 -1
- package/dest/json-rpc/test/integration.d.ts +1 -1
- package/dest/log/console.d.ts +1 -1
- package/dest/log/gcloud-logger-config.d.ts +1 -1
- package/dest/log/gcloud-logger-config.d.ts.map +1 -1
- package/dest/log/index.d.ts +1 -1
- package/dest/log/libp2p_logger.d.ts +1 -1
- package/dest/log/log-filters.d.ts +1 -1
- package/dest/log/log-levels.d.ts +1 -1
- package/dest/log/log_fn.d.ts +1 -1
- package/dest/log/noir_debug_log_util.d.ts +1 -1
- package/dest/log/pino-logger.d.ts +2 -2
- package/dest/log/pino-logger.d.ts.map +1 -1
- package/dest/log/pino-logger.js +1 -1
- package/dest/message/index.d.ts +1 -1
- package/dest/message/index.d.ts.map +1 -1
- package/dest/mutex/index.d.ts +1 -1
- package/dest/mutex/index.d.ts.map +1 -1
- package/dest/mutex/mutex_database.d.ts +1 -1
- package/dest/noir/index.d.ts +1 -1
- package/dest/noir/noir_package_config.d.ts +9 -9
- package/dest/number/index.d.ts +1 -1
- package/dest/profiler/index.d.ts +1 -1
- package/dest/profiler/profiler.d.ts +1 -1
- package/dest/promise/index.d.ts +1 -1
- package/dest/promise/running-promise.d.ts +1 -1
- package/dest/promise/running-promise.d.ts.map +1 -1
- package/dest/promise/utils.d.ts +1 -1
- package/dest/queue/base_memory_queue.d.ts +1 -1
- 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/bounded_serial_queue.d.ts +1 -1
- package/dest/queue/bounded_serial_queue.d.ts.map +1 -1
- package/dest/queue/fifo_memory_queue.d.ts +1 -1
- package/dest/queue/fifo_memory_queue.d.ts.map +1 -1
- package/dest/queue/index.d.ts +1 -1
- package/dest/queue/priority_memory_queue.d.ts +1 -1
- package/dest/queue/priority_memory_queue.d.ts.map +1 -1
- package/dest/queue/priority_queue.d.ts +1 -1
- package/dest/queue/priority_queue.d.ts.map +1 -1
- package/dest/queue/semaphore.d.ts +1 -1
- package/dest/queue/semaphore.d.ts.map +1 -1
- package/dest/queue/serial_queue.d.ts +1 -1
- package/dest/queue/serial_queue.d.ts.map +1 -1
- package/dest/retry/index.d.ts +11 -1
- package/dest/retry/index.d.ts.map +1 -1
- package/dest/retry/index.js +11 -0
- package/dest/running-promise/index.d.ts +1 -1
- package/dest/schemas/api.d.ts +1 -1
- package/dest/schemas/index.d.ts +1 -1
- package/dest/schemas/parse.d.ts +1 -1
- package/dest/schemas/schemas.d.ts +15 -17
- package/dest/schemas/schemas.d.ts.map +1 -1
- package/dest/schemas/schemas.js +14 -10
- 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/schemas/utils.d.ts +4 -4
- package/dest/schemas/utils.d.ts.map +1 -1
- package/dest/schemas/utils.js +15 -5
- package/dest/serialize/buffer_reader.d.ts +7 -4
- package/dest/serialize/buffer_reader.d.ts.map +1 -1
- package/dest/serialize/buffer_reader.js +13 -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/index.d.ts +1 -1
- package/dest/serialize/serialize.d.ts +2 -2
- package/dest/serialize/serialize.d.ts.map +1 -1
- package/dest/serialize/serialize.js +1 -1
- package/dest/serialize/type_registry.d.ts +1 -1
- package/dest/serialize/type_registry.d.ts.map +1 -1
- package/dest/serialize/types.d.ts +1 -1
- package/dest/sleep/index.d.ts +3 -1
- package/dest/sleep/index.d.ts.map +1 -1
- package/dest/sleep/index.js +4 -0
- package/dest/string/index.d.ts +1 -1
- package/dest/testing/files/index.d.ts +2 -1
- package/dest/testing/files/index.d.ts.map +1 -1
- package/dest/testing/files/index.js +1 -1
- package/dest/testing/formatting.d.ts +1 -1
- package/dest/testing/index.d.ts +1 -1
- package/dest/testing/port_allocator.d.ts +1 -1
- package/dest/testing/snapshot_serializer.d.ts +1 -1
- package/dest/testing/test_data.d.ts +1 -1
- package/dest/timer/date.d.ts +2 -1
- package/dest/timer/date.d.ts.map +1 -1
- package/dest/timer/date.js +3 -0
- package/dest/timer/elapsed.d.ts +1 -1
- package/dest/timer/index.d.ts +1 -1
- package/dest/timer/timeout.d.ts +1 -1
- package/dest/timer/timeout.d.ts.map +1 -1
- package/dest/timer/timer.d.ts +1 -1
- package/dest/timer/timer.d.ts.map +1 -1
- package/dest/transport/dispatch/create_dispatch_fn.d.ts +1 -1
- package/dest/transport/dispatch/create_dispatch_fn.d.ts.map +1 -1
- package/dest/transport/dispatch/create_dispatch_proxy.d.ts +1 -1
- package/dest/transport/dispatch/messages.d.ts +1 -1
- package/dest/transport/index.d.ts +1 -1
- package/dest/transport/interface/connector.d.ts +1 -1
- package/dest/transport/interface/listener.d.ts +1 -1
- package/dest/transport/interface/socket.d.ts +1 -1
- package/dest/transport/interface/transferable.d.ts +1 -1
- package/dest/transport/node/index.d.ts +1 -1
- package/dest/transport/node/node_connector.d.ts +1 -1
- package/dest/transport/node/node_connector.d.ts.map +1 -1
- package/dest/transport/node/node_connector_socket.d.ts +1 -1
- package/dest/transport/node/node_connector_socket.d.ts.map +1 -1
- package/dest/transport/node/node_listener.d.ts +1 -1
- package/dest/transport/node/node_listener.d.ts.map +1 -1
- package/dest/transport/node/node_listener_socket.d.ts +1 -1
- package/dest/transport/node/node_listener_socket.d.ts.map +1 -1
- package/dest/transport/transport_client.d.ts +1 -1
- package/dest/transport/transport_client.d.ts.map +1 -1
- package/dest/transport/transport_server.d.ts +1 -10
- package/dest/transport/transport_server.d.ts.map +1 -1
- package/dest/trees/balanced_merkle_tree_root.d.ts +17 -0
- package/dest/trees/balanced_merkle_tree_root.d.ts.map +1 -0
- package/dest/trees/balanced_merkle_tree_root.js +51 -0
- package/dest/trees/hasher.d.ts +3 -1
- package/dest/trees/hasher.d.ts.map +1 -1
- package/dest/trees/hasher.js +10 -5
- package/dest/trees/index.d.ts +4 -3
- package/dest/trees/index.d.ts.map +1 -1
- package/dest/trees/index.js +3 -2
- package/dest/trees/indexed_merkle_tree.d.ts +1 -1
- package/dest/trees/indexed_merkle_tree.d.ts.map +1 -1
- 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_tree_leaf.d.ts +1 -1
- package/dest/trees/membership_witness.d.ts +7 -18
- package/dest/trees/membership_witness.d.ts.map +1 -1
- package/dest/trees/membership_witness.js +10 -1
- package/dest/trees/merkle_tree.d.ts +1 -1
- package/dest/trees/merkle_tree.d.ts.map +1 -1
- package/dest/trees/merkle_tree_calculator.d.ts +2 -12
- package/dest/trees/merkle_tree_calculator.d.ts.map +1 -1
- package/dest/trees/merkle_tree_calculator.js +2 -32
- package/dest/trees/sibling_path.d.ts +5 -38
- package/dest/trees/sibling_path.d.ts.map +1 -1
- package/dest/trees/sibling_path.js +3 -3
- package/dest/trees/unbalanced_merkle_tree_calculator.d.ts +6 -6
- package/dest/trees/unbalanced_merkle_tree_calculator.d.ts.map +1 -1
- package/dest/trees/unbalanced_merkle_tree_calculator.js +34 -42
- package/dest/trees/unbalanced_merkle_tree_root.d.ts +28 -0
- package/dest/trees/unbalanced_merkle_tree_root.d.ts.map +1 -0
- package/dest/trees/unbalanced_merkle_tree_root.js +84 -0
- 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 +4 -2
- package/dest/types/index.d.ts.map +1 -1
- package/dest/types/index.js +3 -0
- package/dest/url/index.d.ts +1 -1
- package/dest/validation/index.d.ts +1 -1
- package/package.json +29 -9
- package/src/array/array.ts +0 -16
- package/src/array/index.ts +1 -0
- package/src/array/sorted_array.ts +133 -0
- package/src/branded-types/block_number.ts +117 -0
- package/src/branded-types/checkpoint_number.ts +115 -0
- package/src/branded-types/epoch.ts +88 -0
- package/src/branded-types/index.ts +7 -0
- package/src/branded-types/index_within_checkpoint.ts +88 -0
- package/src/branded-types/slot.ts +88 -0
- package/src/branded-types/types.ts +2 -0
- package/src/buffer/buffer16.ts +2 -2
- package/src/buffer/buffer32.ts +2 -2
- package/src/collection/array.ts +31 -0
- package/src/config/env_var.ts +44 -13
- package/src/config/index.ts +39 -6
- package/src/config/network_config.ts +2 -0
- package/src/config/parse-env.ts +4 -0
- package/src/crypto/aes128/index.ts +2 -2
- package/src/crypto/bls/bn254_keystore.ts +1 -1
- package/src/crypto/bls/index.ts +1 -1
- package/src/crypto/bn254/index.ts +50 -156
- package/src/crypto/ecdsa/index.ts +4 -4
- package/src/crypto/ecdsa/signature.ts +2 -2
- package/src/crypto/grumpkin/index.ts +8 -6
- package/src/crypto/keys/index.ts +2 -2
- package/src/crypto/pedersen/pedersen.wasm.ts +4 -4
- package/src/crypto/poseidon/index.ts +5 -15
- package/src/crypto/random/randomness_singleton.ts +2 -4
- package/src/crypto/schnorr/index.ts +5 -4
- package/src/crypto/schnorr/signature.ts +2 -2
- package/src/crypto/secp256k1/index.ts +3 -3
- 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/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} +6 -6
- 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} +49 -56
- 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 +26 -7
- package/src/eth-address/index.ts +27 -2
- package/src/iterator/filter.ts +11 -0
- package/src/iterator/index.ts +1 -0
- package/src/json-rpc/client/undici.ts +21 -3
- package/src/json-rpc/server/safe_json_rpc_server.ts +1 -1
- package/src/log/pino-logger.ts +2 -1
- package/src/retry/index.ts +18 -0
- package/src/schemas/schemas.ts +24 -13
- package/src/schemas/types.ts +33 -0
- package/src/schemas/utils.ts +21 -8
- package/src/serialize/buffer_reader.ts +21 -9
- package/src/serialize/field_reader.ts +1 -1
- package/src/serialize/free_funcs.ts +1 -1
- package/src/serialize/serialize.ts +1 -1
- package/src/sleep/index.ts +6 -0
- package/src/testing/files/index.ts +1 -1
- package/src/timer/date.ts +4 -0
- package/src/trees/balanced_merkle_tree_root.ts +68 -0
- package/src/trees/hasher.ts +9 -0
- package/src/trees/index.ts +3 -2
- package/src/trees/indexed_merkle_tree.ts +1 -1
- package/src/trees/membership_witness.ts +9 -1
- package/src/trees/merkle_tree_calculator.ts +2 -35
- package/src/trees/sibling_path.ts +3 -3
- package/src/trees/unbalanced_merkle_tree_calculator.ts +32 -50
- package/src/trees/unbalanced_merkle_tree_root.ts +115 -0
- package/src/trees/unbalanced_tree_store.ts +57 -2
- package/src/types/index.ts +6 -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/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 -66
- 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 -30
- package/dest/index.d.ts.map +0 -1
- package/dest/index.js +0 -30
- 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/trees/unbalanced_merkle_tree.d.ts +0 -28
- package/dest/trees/unbalanced_merkle_tree.d.ts.map +0 -1
- package/dest/trees/unbalanced_merkle_tree.js +0 -99
- package/src/crypto/bn254/bn254_utils.ts +0 -64
- package/src/crypto/index.ts +0 -16
- package/src/fields/coordinate.ts +0 -104
- package/src/fields/index.ts +0 -5
- package/src/index.ts +0 -30
- package/src/json-rpc/server/telemetry.ts +0 -0
- package/src/trees/unbalanced_merkle_tree.ts +0 -111
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BN254_G1_GENERATOR,
|
|
3
|
+
BN254_G2_GENERATOR,
|
|
4
|
+
BarretenbergSync,
|
|
5
|
+
type Bn254G1Point as BbApiBn254G1Point,
|
|
6
|
+
type Bn254G2Point as BbApiBn254G2Point,
|
|
7
|
+
} from '@aztec/bb.js';
|
|
8
|
+
|
|
9
|
+
import { Fq, Fr } from './field.js';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* BN254 G1 point using foundation field classes.
|
|
13
|
+
* Represents a point on the BN254 elliptic curve in affine coordinates.
|
|
14
|
+
*/
|
|
15
|
+
export class Bn254G1Point {
|
|
16
|
+
constructor(
|
|
17
|
+
public readonly x: Fq,
|
|
18
|
+
public readonly y: Fq,
|
|
19
|
+
) {}
|
|
20
|
+
|
|
21
|
+
private toBbApiPoint(): BbApiBn254G1Point {
|
|
22
|
+
return {
|
|
23
|
+
x: this.x.toBuffer(),
|
|
24
|
+
y: this.y.toBuffer(),
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
private static fromBbApiPoint(point: BbApiBn254G1Point): Bn254G1Point {
|
|
29
|
+
return new Bn254G1Point(Fq.fromBuffer(Buffer.from(point.x)), Fq.fromBuffer(Buffer.from(point.y)));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async isOnCurve(): Promise<boolean> {
|
|
33
|
+
await BarretenbergSync.initSingleton();
|
|
34
|
+
const api = BarretenbergSync.getSingleton();
|
|
35
|
+
|
|
36
|
+
const apiPoint = this.toBbApiPoint();
|
|
37
|
+
const response = api.bn254G1IsOnCurve({ point: apiPoint });
|
|
38
|
+
return response.isOnCurve;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Get the generator point for BN254 G1, or perform scalar multiplication.
|
|
43
|
+
* When called without arguments, returns the base generator point.
|
|
44
|
+
* When called with a scalar, returns scalar * generator (useful for public key derivation).
|
|
45
|
+
*/
|
|
46
|
+
static async generator(scalar?: Fr): Promise<Bn254G1Point> {
|
|
47
|
+
if (!scalar) {
|
|
48
|
+
return new Bn254G1Point(
|
|
49
|
+
Fq.fromBuffer(Buffer.from(BN254_G1_GENERATOR.x)),
|
|
50
|
+
Fq.fromBuffer(Buffer.from(BN254_G1_GENERATOR.y)),
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
await BarretenbergSync.initSingleton();
|
|
55
|
+
const api = BarretenbergSync.getSingleton();
|
|
56
|
+
|
|
57
|
+
const response = api.bn254G1Mul({
|
|
58
|
+
point: BN254_G1_GENERATOR,
|
|
59
|
+
scalar: scalar.toBuffer(),
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
return Bn254G1Point.fromBbApiPoint(response.point);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Decompress a BN254 G1 point from compressed form (32 bytes).
|
|
67
|
+
* The compressed format encodes the x-coordinate and the sign bit of the y-coordinate
|
|
68
|
+
* in the most significant bit.
|
|
69
|
+
*/
|
|
70
|
+
static async fromCompressed(compressed: Buffer): Promise<Bn254G1Point> {
|
|
71
|
+
if (compressed.length !== 32) {
|
|
72
|
+
throw new Error('Invalid compressed point length');
|
|
73
|
+
}
|
|
74
|
+
await BarretenbergSync.initSingleton();
|
|
75
|
+
const api = BarretenbergSync.getSingleton();
|
|
76
|
+
|
|
77
|
+
const response = api.bn254G1FromCompressed({
|
|
78
|
+
compressed: new Uint8Array(compressed),
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
return Bn254G1Point.fromBbApiPoint(response.point);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Compress this BN254 G1 point to 32 bytes.
|
|
86
|
+
* The compressed format encodes the x-coordinate and the sign bit of the y-coordinate
|
|
87
|
+
* in the most significant bit (bit 255).
|
|
88
|
+
*/
|
|
89
|
+
compress(): Buffer {
|
|
90
|
+
const xBytes = this.x.toBuffer();
|
|
91
|
+
// Get the least significant bit of y to determine the sign
|
|
92
|
+
const yLsb = this.y.toBigInt() & 1n;
|
|
93
|
+
// If y is odd, set the most significant bit (bit 255) of the output
|
|
94
|
+
if (yLsb === 1n) {
|
|
95
|
+
xBytes[0] |= 0x80;
|
|
96
|
+
}
|
|
97
|
+
return xBytes;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
equals(other: Bn254G1Point): boolean {
|
|
101
|
+
return this.x.equals(other.x) && this.y.equals(other.y);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
toString(): string {
|
|
105
|
+
return `Bn254G1Point(x: ${this.x.toString()}, y: ${this.y.toString()})`;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* BN254 G2 point using foundation field classes.
|
|
111
|
+
* Represents a point on the BN254 G2 curve (twist curve) in affine coordinates.
|
|
112
|
+
* G2 points use extension field coordinates (Fq2).
|
|
113
|
+
*/
|
|
114
|
+
export class Bn254G2Point {
|
|
115
|
+
constructor(
|
|
116
|
+
public readonly x: [Fq, Fq],
|
|
117
|
+
public readonly y: [Fq, Fq],
|
|
118
|
+
) {}
|
|
119
|
+
|
|
120
|
+
private toBbApiPoint(): BbApiBn254G2Point {
|
|
121
|
+
return {
|
|
122
|
+
x: [this.x[0].toBuffer(), this.x[1].toBuffer()],
|
|
123
|
+
y: [this.y[0].toBuffer(), this.y[1].toBuffer()],
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
private static fromBbApiPoint(point: BbApiBn254G2Point): Bn254G2Point {
|
|
128
|
+
return new Bn254G2Point(
|
|
129
|
+
[Fq.fromBuffer(Buffer.from(point.x[0])), Fq.fromBuffer(Buffer.from(point.x[1]))],
|
|
130
|
+
[Fq.fromBuffer(Buffer.from(point.y[0])), Fq.fromBuffer(Buffer.from(point.y[1]))],
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Get the generator point for BN254 G2, or perform scalar multiplication.
|
|
136
|
+
* When called without arguments, returns the base generator point.
|
|
137
|
+
* When called with a scalar, returns scalar * generator.
|
|
138
|
+
*/
|
|
139
|
+
static async generator(scalar?: Fr): Promise<Bn254G2Point> {
|
|
140
|
+
if (!scalar) {
|
|
141
|
+
return new Bn254G2Point(
|
|
142
|
+
[Fq.fromBuffer(Buffer.from(BN254_G2_GENERATOR.x[0])), Fq.fromBuffer(Buffer.from(BN254_G2_GENERATOR.x[1]))],
|
|
143
|
+
[Fq.fromBuffer(Buffer.from(BN254_G2_GENERATOR.y[0])), Fq.fromBuffer(Buffer.from(BN254_G2_GENERATOR.y[1]))],
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
await BarretenbergSync.initSingleton();
|
|
148
|
+
const api = BarretenbergSync.getSingleton();
|
|
149
|
+
|
|
150
|
+
const response = api.bn254G2Mul({
|
|
151
|
+
point: BN254_G2_GENERATOR as BbApiBn254G2Point,
|
|
152
|
+
scalar: scalar.toBuffer(),
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
return Bn254G2Point.fromBbApiPoint(response.point);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
equals(other: Bn254G2Point): boolean {
|
|
159
|
+
return (
|
|
160
|
+
this.x[0].equals(other.x[0]) &&
|
|
161
|
+
this.x[1].equals(other.x[1]) &&
|
|
162
|
+
this.y[0].equals(other.y[0]) &&
|
|
163
|
+
this.y[1].equals(other.y[1])
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
toString(): string {
|
|
168
|
+
return `Bn254G2Point(x: (${this.x[0].toString()}, ${this.x[1].toString()}), y: (${this.y[0].toString()}, ${this.y[1].toString()}))`;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Fq } from '../bn254/field.js';
|
|
2
|
+
|
|
3
|
+
export * from './point.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* GrumpkinScalar is an Fq.
|
|
7
|
+
* @remarks Called GrumpkinScalar because it is used to represent elements in Grumpkin's scalar field as defined in
|
|
8
|
+
* the Aztec Protocol Specs.
|
|
9
|
+
*/
|
|
10
|
+
export type GrumpkinScalar = Fq;
|
|
11
|
+
export const GrumpkinScalar = Fq;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { toBigIntBE } from '
|
|
2
|
-
import { poseidon2Hash } from '
|
|
3
|
-
import { randomBoolean } from '
|
|
4
|
-
import { hexSchemaFor } from '
|
|
5
|
-
import { BufferReader, FieldReader, serializeToBuffer } from '
|
|
6
|
-
import { bufferToHex, hexToBuffer } from '
|
|
7
|
-
import { Fr } from '
|
|
1
|
+
import { toBigIntBE } from '../../bigint-buffer/index.js';
|
|
2
|
+
import { poseidon2Hash } from '../../crypto/poseidon/index.js';
|
|
3
|
+
import { randomBoolean } from '../../crypto/random/index.js';
|
|
4
|
+
import { hexSchemaFor } from '../../schemas/utils.js';
|
|
5
|
+
import { BufferReader, FieldReader, serializeToBuffer } from '../../serialize/index.js';
|
|
6
|
+
import { bufferToHex, hexToBuffer } from '../../string/index.js';
|
|
7
|
+
import { Fr } from '../bn254/field.js';
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Represents a Point on an elliptic curve with x and y coordinates.
|
|
@@ -42,9 +42,28 @@ export class Point {
|
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
static get schema() {
|
|
45
|
+
// Serialization from hex string.
|
|
45
46
|
return hexSchemaFor(Point);
|
|
46
47
|
}
|
|
47
48
|
|
|
49
|
+
/**
|
|
50
|
+
* Creates a Point from a plain object without Zod validation.
|
|
51
|
+
* This method is optimized for performance and skips validation, making it suitable
|
|
52
|
+
* for deserializing trusted data (e.g., from C++ via MessagePack).
|
|
53
|
+
* Handles buffers, existing instances, or objects with x, y, and isInfinite fields.
|
|
54
|
+
* @param obj - Plain object, buffer, or Point instance
|
|
55
|
+
* @returns A Point instance
|
|
56
|
+
*/
|
|
57
|
+
static fromPlainObject(obj: any): Point {
|
|
58
|
+
if (obj instanceof Point) {
|
|
59
|
+
return obj;
|
|
60
|
+
}
|
|
61
|
+
if (obj instanceof Buffer || Buffer.isBuffer(obj)) {
|
|
62
|
+
return Point.fromBuffer(obj);
|
|
63
|
+
}
|
|
64
|
+
return new Point(Fr.fromPlainObject(obj.x), Fr.fromPlainObject(obj.y), obj.isInfinite ?? false);
|
|
65
|
+
}
|
|
66
|
+
|
|
48
67
|
/**
|
|
49
68
|
* Generate a random Point instance.
|
|
50
69
|
*
|
package/src/eth-address/index.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { inspect } from 'util';
|
|
|
2
2
|
|
|
3
3
|
import { keccak256String } from '../crypto/keccak/index.js';
|
|
4
4
|
import { randomBytes } from '../crypto/random/index.js';
|
|
5
|
-
import { Fr } from '../
|
|
5
|
+
import { Fr } from '../curves/bn254/index.js';
|
|
6
6
|
import { hexSchemaFor } from '../schemas/utils.js';
|
|
7
7
|
import { BufferReader, FieldReader } from '../serialize/index.js';
|
|
8
8
|
import { TypeRegistry } from '../serialize/type_registry.js';
|
|
@@ -41,6 +41,24 @@ export class EthAddress {
|
|
|
41
41
|
return new EthAddress(Buffer.from(address.replace(/^0x/i, ''), 'hex'));
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
+
/**
|
|
45
|
+
* Creates an EthAddress from a plain object without Zod validation.
|
|
46
|
+
* This method is optimized for performance and skips validation, making it suitable
|
|
47
|
+
* for deserializing trusted data (e.g., from C++ via MessagePack).
|
|
48
|
+
* Handles buffers (20 or 32 bytes), strings, or existing instances.
|
|
49
|
+
* @param obj - Plain object, buffer, string, or EthAddress instance
|
|
50
|
+
* @returns An EthAddress instance
|
|
51
|
+
*/
|
|
52
|
+
public static fromPlainObject(obj: any): EthAddress {
|
|
53
|
+
if (obj instanceof EthAddress) {
|
|
54
|
+
return obj;
|
|
55
|
+
}
|
|
56
|
+
if (obj instanceof Buffer || Buffer.isBuffer(obj)) {
|
|
57
|
+
return obj.length === 20 ? new EthAddress(obj) : EthAddress.fromField(new Fr(obj));
|
|
58
|
+
}
|
|
59
|
+
return EthAddress.fromString(obj);
|
|
60
|
+
}
|
|
61
|
+
|
|
44
62
|
/**
|
|
45
63
|
* Create a random EthAddress instance with 20 random bytes.
|
|
46
64
|
* This method generates a new Ethereum address with a randomly generated set of 20 bytes.
|
|
@@ -231,7 +249,7 @@ export class EthAddress {
|
|
|
231
249
|
/** Converts a number into an address. Useful for testing. */
|
|
232
250
|
static fromNumber(num: bigint | number): EthAddress {
|
|
233
251
|
const buffer = Buffer.alloc(EthAddress.SIZE_IN_BYTES);
|
|
234
|
-
buffer.writeBigUInt64BE(BigInt(num),
|
|
252
|
+
buffer.writeBigUInt64BE(BigInt(num), EthAddress.SIZE_IN_BYTES - 8);
|
|
235
253
|
return new EthAddress(buffer);
|
|
236
254
|
}
|
|
237
255
|
|
|
@@ -240,8 +258,15 @@ export class EthAddress {
|
|
|
240
258
|
}
|
|
241
259
|
|
|
242
260
|
static get schema() {
|
|
261
|
+
// Serialization from hex string.
|
|
243
262
|
return hexSchemaFor(EthAddress, EthAddress.isAddress);
|
|
244
263
|
}
|
|
264
|
+
|
|
265
|
+
static areEqual(a: EthAddress | string, b: EthAddress | string) {
|
|
266
|
+
const addrA = typeof a === 'string' ? EthAddress.fromString(a) : a;
|
|
267
|
+
const addrB = typeof b === 'string' ? EthAddress.fromString(b) : b;
|
|
268
|
+
return addrA.equals(addrB);
|
|
269
|
+
}
|
|
245
270
|
}
|
|
246
271
|
|
|
247
272
|
// For deserializing JSON.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Wraps an async iterable iterator such that it filters values based on a predicate. */
|
|
2
|
+
export async function* filter<T>(
|
|
3
|
+
iterator: AsyncIterableIterator<T>,
|
|
4
|
+
predicate: (item: T) => boolean | Promise<boolean>,
|
|
5
|
+
): AsyncIterableIterator<T> {
|
|
6
|
+
for await (const item of iterator) {
|
|
7
|
+
if (await predicate(item)) {
|
|
8
|
+
yield item;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { filter } from './filter.js';
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { promisify } from 'node:util';
|
|
2
|
+
import { gunzip as gunzipCb, gzip as gzipCb } from 'node:zlib';
|
|
1
3
|
import { Agent, type Dispatcher } from 'undici';
|
|
2
4
|
|
|
3
5
|
import { createLogger } from '../../log/pino-logger.js';
|
|
@@ -5,8 +7,14 @@ import { NoRetryError } from '../../retry/index.js';
|
|
|
5
7
|
import { jsonStringify } from '../convert.js';
|
|
6
8
|
import type { JsonRpcFetch } from './fetch.js';
|
|
7
9
|
|
|
10
|
+
const gzip = promisify(gzipCb);
|
|
11
|
+
const gunzip = promisify(gunzipCb);
|
|
12
|
+
|
|
8
13
|
const log = createLogger('json-rpc:json_rpc_client:undici');
|
|
9
14
|
|
|
15
|
+
/** Minimum request size in bytes to trigger compression. */
|
|
16
|
+
const COMPRESSION_THRESHOLD = 1024;
|
|
17
|
+
|
|
10
18
|
export { Agent };
|
|
11
19
|
|
|
12
20
|
export function makeUndiciFetch(client = new Agent()): JsonRpcFetch {
|
|
@@ -14,14 +22,18 @@ export function makeUndiciFetch(client = new Agent()): JsonRpcFetch {
|
|
|
14
22
|
log.trace(`JsonRpcClient.fetch: ${host}`, { host, body });
|
|
15
23
|
let resp: Dispatcher.ResponseData;
|
|
16
24
|
try {
|
|
25
|
+
const jsonBody = Buffer.from(jsonStringify(body));
|
|
26
|
+
const shouldCompress = jsonBody.length >= COMPRESSION_THRESHOLD;
|
|
17
27
|
resp = await client.request({
|
|
18
28
|
method: 'POST',
|
|
19
29
|
origin: new URL(host),
|
|
20
30
|
path: '/',
|
|
21
|
-
body:
|
|
31
|
+
body: shouldCompress ? await gzip(jsonBody) : jsonBody,
|
|
22
32
|
headers: {
|
|
23
33
|
...extraHeaders,
|
|
24
34
|
'content-type': 'application/json',
|
|
35
|
+
...(shouldCompress && { 'content-encoding': 'gzip' }),
|
|
36
|
+
'accept-encoding': 'gzip',
|
|
25
37
|
},
|
|
26
38
|
});
|
|
27
39
|
} catch (err) {
|
|
@@ -31,13 +43,19 @@ export function makeUndiciFetch(client = new Agent()): JsonRpcFetch {
|
|
|
31
43
|
|
|
32
44
|
let responseJson: any;
|
|
33
45
|
const responseOk = resp.statusCode >= 200 && resp.statusCode <= 299;
|
|
46
|
+
const contentEncoding = resp.headers['content-encoding'];
|
|
34
47
|
try {
|
|
35
|
-
|
|
48
|
+
if (contentEncoding === 'gzip') {
|
|
49
|
+
const jsonBuffer = await gunzip(await resp.body.arrayBuffer());
|
|
50
|
+
responseJson = JSON.parse(jsonBuffer.toString('utf-8'));
|
|
51
|
+
} else {
|
|
52
|
+
responseJson = await resp.body.json();
|
|
53
|
+
}
|
|
36
54
|
} catch {
|
|
37
55
|
if (!responseOk) {
|
|
38
56
|
throw new Error('HTTP ' + resp.statusCode);
|
|
39
57
|
}
|
|
40
|
-
throw new Error(`Failed to parse body as JSON: ${await resp.body.text()}`);
|
|
58
|
+
throw new Error(`Failed to parse body as JSON. encoding: ${contentEncoding}, body: ${await resp.body.text()}`);
|
|
41
59
|
}
|
|
42
60
|
|
|
43
61
|
if (!responseOk) {
|
package/src/log/pino-logger.ts
CHANGED
|
@@ -5,7 +5,8 @@ import type { Writable } from 'stream';
|
|
|
5
5
|
import { inspect } from 'util';
|
|
6
6
|
|
|
7
7
|
import { compactArray } from '../collection/array.js';
|
|
8
|
-
import {
|
|
8
|
+
import type { EnvVar } from '../config/index.js';
|
|
9
|
+
import { parseBooleanEnv } from '../config/parse-env.js';
|
|
9
10
|
import { GoogleCloudLoggerConfig } from './gcloud-logger-config.js';
|
|
10
11
|
import { getLogLevelFromFilters, parseEnv } from './log-filters.js';
|
|
11
12
|
import type { LogLevel } from './log-levels.js';
|
package/src/retry/index.ts
CHANGED
|
@@ -103,3 +103,21 @@ export async function retryUntil<T>(
|
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Convenience wrapper around retryUntil with fast polling for tests.
|
|
109
|
+
* Uses 10s timeout and 100ms polling interval by default.
|
|
110
|
+
*
|
|
111
|
+
* @param fn - The function to retry until it returns a truthy value.
|
|
112
|
+
* @param name - Description of what we're waiting for (for error messages).
|
|
113
|
+
* @param timeout - Optional timeout in seconds. Defaults to 10s.
|
|
114
|
+
* @param interval - Optional interval in seconds. Defaults to 0.1s (100ms).
|
|
115
|
+
*/
|
|
116
|
+
export function retryFastUntil<T>(
|
|
117
|
+
fn: () => (T | undefined) | Promise<T | undefined>,
|
|
118
|
+
name = '',
|
|
119
|
+
timeout = 10,
|
|
120
|
+
interval = 0.1,
|
|
121
|
+
) {
|
|
122
|
+
return retryUntil(fn, name, timeout, interval);
|
|
123
|
+
}
|
package/src/schemas/schemas.ts
CHANGED
|
@@ -1,14 +1,22 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
|
|
3
|
+
import { EpochNumber, EpochNumberSchema } from '../branded-types/epoch.js';
|
|
4
|
+
import { SlotNumber, SlotNumberSchema } from '../branded-types/slot.js';
|
|
3
5
|
import { Buffer32 } from '../buffer/buffer32.js';
|
|
4
6
|
import { SecretValue } from '../config/secret_value.js';
|
|
7
|
+
import { Fq, Fr } from '../curves/bn254/field.js';
|
|
8
|
+
import { Point } from '../curves/grumpkin/point.js';
|
|
5
9
|
import { EthAddress } from '../eth-address/index.js';
|
|
6
|
-
import {
|
|
7
|
-
import { Point } from '../fields/point.js';
|
|
8
|
-
import { isHex, withoutHexPrefix } from '../string/index.js';
|
|
10
|
+
import { isHex, withHexPrefix, withoutHexPrefix } from '../string/index.js';
|
|
9
11
|
import { bufferSchema, hexSchema } from './utils.js';
|
|
10
12
|
|
|
11
13
|
export const schemas = {
|
|
14
|
+
/** Accepts a number, bigint, or string as an EpochNumber. */
|
|
15
|
+
EpochNumber: EpochNumberSchema,
|
|
16
|
+
|
|
17
|
+
/** Accepts a number, bigint, or string as a SlotNumber. */
|
|
18
|
+
SlotNumber: SlotNumberSchema,
|
|
19
|
+
|
|
12
20
|
/** Accepts a hex string. */
|
|
13
21
|
EthAddress: EthAddress.schema,
|
|
14
22
|
|
|
@@ -50,19 +58,19 @@ export const schemas = {
|
|
|
50
58
|
.max(2 ** 32 - 1),
|
|
51
59
|
),
|
|
52
60
|
|
|
61
|
+
/** Coerces input to UInt64. */
|
|
62
|
+
UInt64: z.union([z.bigint(), z.number(), z.string()]).pipe(
|
|
63
|
+
z.coerce
|
|
64
|
+
.bigint()
|
|
65
|
+
.min(0n)
|
|
66
|
+
.max(2n ** 64n - 1n),
|
|
67
|
+
),
|
|
68
|
+
|
|
53
69
|
/** Accepts a hex string as a Buffer32 type. */
|
|
54
70
|
Buffer32: z.string().refine(isHex, 'Not a valid hex string').transform(Buffer32.fromString),
|
|
55
71
|
|
|
56
72
|
/** Accepts a base64 string or an object `{ type: 'Buffer', data: [byte, byte...] }` as a buffer. */
|
|
57
|
-
Buffer:
|
|
58
|
-
bufferSchema,
|
|
59
|
-
z
|
|
60
|
-
.object({
|
|
61
|
-
type: z.literal('Buffer'),
|
|
62
|
-
data: z.array(z.number().int().min(0).max(255)),
|
|
63
|
-
})
|
|
64
|
-
.transform(({ data }) => Buffer.from(data)),
|
|
65
|
-
]),
|
|
73
|
+
Buffer: bufferSchema,
|
|
66
74
|
|
|
67
75
|
/** Accepts a hex string as a buffer. */
|
|
68
76
|
BufferHex: z
|
|
@@ -74,9 +82,12 @@ export const schemas = {
|
|
|
74
82
|
/** Hex string with an optional 0x prefix which gets removed as part of the parsing. */
|
|
75
83
|
HexString: hexSchema,
|
|
76
84
|
|
|
85
|
+
/** Hex string with an optional 0x prefix which gets enforced as part of the parsing. */
|
|
86
|
+
HexStringWith0x: z.string().refine(isHex, 'Not a valid hex string').transform(withHexPrefix),
|
|
87
|
+
|
|
77
88
|
/** A secret config value */
|
|
78
89
|
SecretValue: SecretValue.schema,
|
|
79
90
|
};
|
|
80
91
|
|
|
81
92
|
// These are needed to avoid errors such as: "The inferred type of 'YourClassSchema' cannot be named without a reference to..."
|
|
82
|
-
export type { EthAddress, Fq, Fr, Point };
|
|
93
|
+
export type { EpochNumber, EthAddress, Fq, Fr, Point, SlotNumber };
|
package/src/schemas/types.ts
CHANGED
|
@@ -1,3 +1,36 @@
|
|
|
1
1
|
import type { ZodType } from 'zod';
|
|
2
2
|
|
|
3
3
|
export type ZodFor<T> = ZodType<T, any, any>;
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Creates a schema validator that enforces all properties of type T are present in the schema.
|
|
7
|
+
* This provides compile-time safety to ensure schemas don't miss optional properties.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* interface MyConfig {
|
|
12
|
+
* foo: string;
|
|
13
|
+
* bar?: number;
|
|
14
|
+
* }
|
|
15
|
+
*
|
|
16
|
+
* // ✅ This will work - all keys present
|
|
17
|
+
* const schema1 = zodFor<MyConfig>()(z.object({
|
|
18
|
+
* foo: z.string(),
|
|
19
|
+
* bar: z.number().optional(),
|
|
20
|
+
* }));
|
|
21
|
+
*
|
|
22
|
+
* // ❌ This will error - 'bar' is missing
|
|
23
|
+
* const schema2 = zodFor<MyConfig>()(z.object({
|
|
24
|
+
* foo: z.string(),
|
|
25
|
+
* }));
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export function zodFor<T>() {
|
|
29
|
+
return (schema => schema) as <S extends ZodType<any, any, any>>(
|
|
30
|
+
schema: keyof T extends keyof S['_output']
|
|
31
|
+
? keyof S['_output'] extends keyof T
|
|
32
|
+
? S
|
|
33
|
+
: S & { __error__: 'Schema has extra keys not in type'; __extra__: Exclude<keyof S['_output'], keyof T> }
|
|
34
|
+
: S & { __error__: 'Schema is missing keys from type'; __missing__: Exclude<keyof T, keyof S['_output']> },
|
|
35
|
+
) => S;
|
|
36
|
+
}
|
package/src/schemas/utils.ts
CHANGED
|
@@ -21,13 +21,25 @@ export const hexSchema = z.string().refine(isHex, 'Not a valid hex string').tran
|
|
|
21
21
|
// Copied from zod internals, which was copied from https://stackoverflow.com/questions/7860392/determine-if-string-is-in-base64-using-javascript
|
|
22
22
|
const base64Regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;
|
|
23
23
|
|
|
24
|
-
/** Schema for a buffer represented as a base64 string. */
|
|
25
|
-
export const bufferSchema = z
|
|
26
|
-
.
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
24
|
+
/** Schema for a buffer represented as a base64 string or a Buffer object. */
|
|
25
|
+
export const bufferSchema: ZodFor<Buffer> = z.union([
|
|
26
|
+
// Serialization from base64 string.
|
|
27
|
+
z
|
|
28
|
+
.string()
|
|
29
|
+
// We only test the str for base64 if it's shorter than 1024 bytes, otherwise we've run into maximum
|
|
30
|
+
// stack size exceeded errors when trying to validate excessively long strings (such as contract bytecode).
|
|
31
|
+
.refine(str => str.length > 1024 || base64Regex.test(str), 'Not a valid base64 string')
|
|
32
|
+
.transform(data => Buffer.from(data, 'base64')),
|
|
33
|
+
// Serialization from Buffer-annotated object.
|
|
34
|
+
z
|
|
35
|
+
.object({
|
|
36
|
+
type: z.literal('Buffer'),
|
|
37
|
+
data: z.array(z.number().int().min(0).max(255)),
|
|
38
|
+
})
|
|
39
|
+
.transform(({ data }) => Buffer.from(data)),
|
|
40
|
+
// Serialization from Buffer
|
|
41
|
+
z.instanceof(Buffer),
|
|
42
|
+
]);
|
|
31
43
|
|
|
32
44
|
export class ZodNullableOptional<T extends ZodTypeAny> extends ZodOptional<T> {
|
|
33
45
|
_isNullableOptional = true;
|
|
@@ -88,12 +100,13 @@ export function hexSchemaFor<TClass extends { fromString(str: string): any } | {
|
|
|
88
100
|
*/
|
|
89
101
|
export function bufferSchemaFor<TClass extends { fromBuffer(buf: Buffer): any }>(
|
|
90
102
|
klazz: TClass,
|
|
103
|
+
refinement?: (buf: Buffer) => boolean,
|
|
91
104
|
): ZodType<
|
|
92
105
|
TClass extends { fromBuffer(buf: Buffer): infer TInstance } ? ToJsonIs<TInstance, Buffer> : never,
|
|
93
106
|
any,
|
|
94
107
|
string
|
|
95
108
|
> {
|
|
96
|
-
return bufferSchema.transform(klazz.fromBuffer.bind(klazz));
|
|
109
|
+
return bufferSchema.refine(refinement ?? (() => true), 'Not a valid buffer').transform(klazz.fromBuffer.bind(klazz));
|
|
97
110
|
}
|
|
98
111
|
|
|
99
112
|
/** Creates a schema for a js Map type that matches the serialization used in jsonStringify. */
|
|
@@ -224,15 +224,22 @@ export class BufferReader {
|
|
|
224
224
|
* deserializing each one using the 'fromBuffer' method of 'itemDeserializer'.
|
|
225
225
|
*
|
|
226
226
|
* @param itemDeserializer - Object with 'fromBuffer' method to deserialize vector elements.
|
|
227
|
+
* @param maxSize - Optional maximum allowed size for the vector. If the size exceeds this, an error is thrown.
|
|
227
228
|
* @returns An array of deserialized elements of type T.
|
|
228
229
|
*/
|
|
229
|
-
public readVector<T>(
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
230
|
+
public readVector<T>(
|
|
231
|
+
itemDeserializer: {
|
|
232
|
+
/**
|
|
233
|
+
* A method to deserialize data from a buffer.
|
|
234
|
+
*/
|
|
235
|
+
fromBuffer: (reader: BufferReader) => T;
|
|
236
|
+
},
|
|
237
|
+
maxSize?: number,
|
|
238
|
+
): T[] {
|
|
235
239
|
const size = this.readNumber();
|
|
240
|
+
if (maxSize !== undefined && size > maxSize) {
|
|
241
|
+
throw new Error(`Vector size ${size} exceeds maximum allowed ${maxSize}`);
|
|
242
|
+
}
|
|
236
243
|
const result = new Array<T>(size);
|
|
237
244
|
for (let i = 0; i < size; i++) {
|
|
238
245
|
result[i] = itemDeserializer.fromBuffer(this);
|
|
@@ -344,10 +351,11 @@ export class BufferReader {
|
|
|
344
351
|
* The method first reads the size of the string, then reads the corresponding
|
|
345
352
|
* number of bytes from the buffer and converts them to a string.
|
|
346
353
|
*
|
|
354
|
+
* @param maxSize - Optional maximum allowed size for the string buffer. If the size exceeds this, an error is thrown.
|
|
347
355
|
* @returns The read string from the buffer.
|
|
348
356
|
*/
|
|
349
|
-
public readString(): string {
|
|
350
|
-
return this.readBuffer().toString();
|
|
357
|
+
public readString(maxSize?: number): string {
|
|
358
|
+
return this.readBuffer(maxSize).toString();
|
|
351
359
|
}
|
|
352
360
|
|
|
353
361
|
/**
|
|
@@ -356,10 +364,14 @@ export class BufferReader {
|
|
|
356
364
|
* a Buffer with that size containing the bytes. Useful for reading variable-length
|
|
357
365
|
* binary data encoded as (size, data) format.
|
|
358
366
|
*
|
|
367
|
+
* @param maxSize - Optional maximum allowed size for the buffer. If the size exceeds this, an error is thrown.
|
|
359
368
|
* @returns A Buffer containing the read bytes.
|
|
360
369
|
*/
|
|
361
|
-
public readBuffer(): Buffer {
|
|
370
|
+
public readBuffer(maxSize?: number): Buffer {
|
|
362
371
|
const size = this.readNumber();
|
|
372
|
+
if (maxSize !== undefined && size > maxSize) {
|
|
373
|
+
throw new Error(`Buffer size ${size} exceeds maximum allowed ${maxSize}`);
|
|
374
|
+
}
|
|
363
375
|
this.#rangeCheck(size);
|
|
364
376
|
return this.readBytes(size);
|
|
365
377
|
}
|
package/src/sleep/index.ts
CHANGED
|
@@ -73,3 +73,9 @@ export class InterruptibleSleep {
|
|
|
73
73
|
export function sleep<T>(ms: number, returnValue?: T): Promise<T> {
|
|
74
74
|
return new Promise(resolve => setTimeout(() => resolve(returnValue as T), ms));
|
|
75
75
|
}
|
|
76
|
+
|
|
77
|
+
/** Sleeps until the target date */
|
|
78
|
+
export function sleepUntil<T>(target: Date, now: Date, returnValue?: T): Promise<T> {
|
|
79
|
+
const ms = target.getTime() - now.getTime();
|
|
80
|
+
return sleep(ms, returnValue);
|
|
81
|
+
}
|
|
@@ -63,7 +63,7 @@ export function updateProtocolCircuitSampleInputs(circuitName: string, value: st
|
|
|
63
63
|
logger(`Updated test data in ${targetFile} for ${circuitName}`);
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
function getPathToFile(targetFileFromRepoRoot: string) {
|
|
66
|
+
export function getPathToFile(targetFileFromRepoRoot: string) {
|
|
67
67
|
const repoRoot = resolve(dirname(fileURLToPath(import.meta.url)), '../../../../../');
|
|
68
68
|
if (!existsSync(join(repoRoot, 'CODEOWNERS'))) {
|
|
69
69
|
throw new Error(`Path to repo root is incorrect (got ${repoRoot})`);
|