@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
package/src/log/pino-logger.ts
CHANGED
|
@@ -1,19 +1,65 @@
|
|
|
1
|
-
import { createColors, isColorSupported } from 'colorette';
|
|
1
|
+
import { type Color, createColors, isColorSupported } from 'colorette';
|
|
2
2
|
import isNode from 'detect-node';
|
|
3
3
|
import { pino, symbols } from 'pino';
|
|
4
4
|
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';
|
|
10
|
+
import { convertBigintsToStrings } from './bigint-utils.js';
|
|
9
11
|
import { GoogleCloudLoggerConfig } from './gcloud-logger-config.js';
|
|
10
|
-
import { getLogLevelFromFilters,
|
|
12
|
+
import { getLogLevelFromFilters, parseLogLevelEnvVar } from './log-filters.js';
|
|
11
13
|
import type { LogLevel } from './log-levels.js';
|
|
12
14
|
import type { LogData, LogFn } from './log_fn.js';
|
|
13
15
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
/** Optional bindings to pass to createLogger for additional context. */
|
|
17
|
+
export type LoggerBindings = {
|
|
18
|
+
/** Actor label shown in logs (e.g., 'MAIN', 'prover-node'). */
|
|
19
|
+
actor?: string;
|
|
20
|
+
/** Instance identifier for distinguishing multiple instances of the same component. */
|
|
21
|
+
instanceId?: string;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const MAX_MODULE_NAME_LENGTH = 256;
|
|
25
|
+
|
|
26
|
+
// Allow global hooks for providing default bindings.
|
|
27
|
+
// Used by withLoggerBindings in pino-logger-server to propagate bindings via AsyncLocalStorage.
|
|
28
|
+
type LogBindingsHandler = () => LoggerBindings | undefined;
|
|
29
|
+
const logBindingsHandlers: LogBindingsHandler[] = [];
|
|
30
|
+
|
|
31
|
+
export function addLogBindingsHandler(handler: LogBindingsHandler): void {
|
|
32
|
+
logBindingsHandlers.push(handler);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function removeLogBindingsHandler(handler: LogBindingsHandler) {
|
|
36
|
+
const index = logBindingsHandlers.indexOf(handler);
|
|
37
|
+
if (index !== -1) {
|
|
38
|
+
logBindingsHandlers.splice(index, 1);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function getBindingsFromHandlers(): LoggerBindings | undefined {
|
|
43
|
+
for (const handler of logBindingsHandlers) {
|
|
44
|
+
const bindings = handler();
|
|
45
|
+
if (bindings) {
|
|
46
|
+
return bindings;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return undefined;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function createLogger(module: string, bindings?: LoggerBindings): Logger {
|
|
53
|
+
module = module.slice(0, MAX_MODULE_NAME_LENGTH).replace(/^aztec:/, '');
|
|
54
|
+
|
|
55
|
+
const resolvedBindings = { ...getBindingsFromHandlers(), ...bindings };
|
|
56
|
+
const actor = resolvedBindings?.actor;
|
|
57
|
+
const instanceId = resolvedBindings?.instanceId;
|
|
58
|
+
|
|
59
|
+
const pinoLogger = logger.child(
|
|
60
|
+
{ module, ...(actor && { actor }), ...(instanceId && { instanceId }) },
|
|
61
|
+
{ level: getLogLevelFromFilters(logFilters, module) },
|
|
62
|
+
);
|
|
17
63
|
|
|
18
64
|
// We check manually for isLevelEnabled to avoid calling processLogData unnecessarily.
|
|
19
65
|
// Note that isLevelEnabled is missing from the browser version of pino.
|
|
@@ -43,11 +89,24 @@ export function createLogger(module: string): Logger {
|
|
|
43
89
|
isLevelEnabled: (level: LogLevel) => isLevelEnabled(pinoLogger, level),
|
|
44
90
|
/** Module name for the logger. */
|
|
45
91
|
module,
|
|
46
|
-
/** Creates another logger by extending this logger module name. */
|
|
47
|
-
createChild: (childModule: string) => createLogger(`${module}:${childModule}
|
|
92
|
+
/** Creates another logger by extending this logger module name and preserving bindings. */
|
|
93
|
+
createChild: (childModule: string) => createLogger(`${module}:${childModule}`, { actor, instanceId }),
|
|
94
|
+
/** Returns the bindings (actor, instanceId) for this logger. */
|
|
95
|
+
getBindings: () => ({ actor, instanceId }),
|
|
48
96
|
};
|
|
49
97
|
}
|
|
50
98
|
|
|
99
|
+
/**
|
|
100
|
+
* Returns a logger for the given module. If loggerOrBindings is already a Logger, returns it directly.
|
|
101
|
+
* Otherwise, creates a new logger with the given module name and bindings.
|
|
102
|
+
*/
|
|
103
|
+
export function resolveLogger(module: string, loggerOrBindings?: Logger | LoggerBindings): Logger {
|
|
104
|
+
if (loggerOrBindings && 'info' in loggerOrBindings) {
|
|
105
|
+
return loggerOrBindings as Logger;
|
|
106
|
+
}
|
|
107
|
+
return createLogger(module, loggerOrBindings);
|
|
108
|
+
}
|
|
109
|
+
|
|
51
110
|
// Allow global hooks for processing log data.
|
|
52
111
|
// Used for injecting OTEL trace_id in telemetry client.
|
|
53
112
|
type LogDataHandler = (data: LogData) => LogData;
|
|
@@ -61,31 +120,6 @@ function processLogData(data: LogData): LogData {
|
|
|
61
120
|
return logDataHandlers.reduce((accum, handler) => handler(accum), data);
|
|
62
121
|
}
|
|
63
122
|
|
|
64
|
-
// Allow global hooks for tweaking module names.
|
|
65
|
-
// Used in tests to add a uid to modules, so we can differentiate multiple nodes in the same process.
|
|
66
|
-
type LogNameHandler = (module: string) => string;
|
|
67
|
-
const logNameHandlers: LogNameHandler[] = [];
|
|
68
|
-
|
|
69
|
-
export function addLogNameHandler(handler: LogNameHandler): void {
|
|
70
|
-
logNameHandlers.push(handler);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export function removeLogNameHandler(handler: LogNameHandler) {
|
|
74
|
-
const index = logNameHandlers.indexOf(handler);
|
|
75
|
-
if (index !== -1) {
|
|
76
|
-
logNameHandlers.splice(index, 1);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/** Creates all loggers within the given callback with the suffix appended to the module name. */
|
|
81
|
-
export async function withLogNameSuffix<T>(suffix: string, callback: () => Promise<T>): Promise<T> {
|
|
82
|
-
const logNameHandler = (module: string) => `${module}:${suffix}`;
|
|
83
|
-
addLogNameHandler(logNameHandler);
|
|
84
|
-
const result = await callback();
|
|
85
|
-
removeLogNameHandler(logNameHandler);
|
|
86
|
-
return result;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
123
|
// Patch isLevelEnabled missing from pino/browser.
|
|
90
124
|
function isLevelEnabled(logger: pino.Logger<'verbose', boolean>, level: LogLevel): boolean {
|
|
91
125
|
return typeof logger.isLevelEnabled === 'function'
|
|
@@ -95,7 +129,7 @@ function isLevelEnabled(logger: pino.Logger<'verbose', boolean>, level: LogLevel
|
|
|
95
129
|
|
|
96
130
|
// Load log levels from environment variables.
|
|
97
131
|
const defaultLogLevel = process.env.NODE_ENV === 'test' ? 'silent' : 'info';
|
|
98
|
-
export const [logLevel, logFilters] =
|
|
132
|
+
export const [logLevel, logFilters] = parseLogLevelEnvVar(process.env.LOG_LEVEL, defaultLogLevel);
|
|
99
133
|
|
|
100
134
|
// Define custom logging levels for pino.
|
|
101
135
|
const customLevels = { verbose: 25 };
|
|
@@ -134,6 +168,9 @@ const pinoOpts: pino.LoggerOptions<keyof typeof customLevels> = {
|
|
|
134
168
|
...redactedPaths.map(p => `opts.${p}`),
|
|
135
169
|
],
|
|
136
170
|
},
|
|
171
|
+
formatters: {
|
|
172
|
+
log: obj => convertBigintsToStrings(obj) as Record<string, unknown>,
|
|
173
|
+
},
|
|
137
174
|
...(useGcloudLogging ? GoogleCloudLoggerConfig : {}),
|
|
138
175
|
};
|
|
139
176
|
|
|
@@ -145,22 +182,90 @@ export const levels = {
|
|
|
145
182
|
// Transport options for pretty logging to stderr via pino-pretty.
|
|
146
183
|
const colorEnv = process.env['FORCE_COLOR' satisfies EnvVar];
|
|
147
184
|
const useColor = colorEnv === undefined ? isColorSupported : parseBooleanEnv(colorEnv);
|
|
148
|
-
const { bold, reset
|
|
149
|
-
|
|
185
|
+
const { bold, reset, cyan, magenta, yellow, blue, green, magentaBright, yellowBright, blueBright, greenBright } =
|
|
186
|
+
createColors({ useColor });
|
|
187
|
+
|
|
188
|
+
// Per-actor coloring: each unique actor gets a different color for easier visual distinction.
|
|
189
|
+
// Disabled when LOG_NO_COLOR_PER_ACTOR is set to a truthy value.
|
|
190
|
+
const useColorPerActor = useColor && !parseBooleanEnv(process.env['LOG_NO_COLOR_PER_ACTOR' satisfies EnvVar]);
|
|
191
|
+
const actorColors: Color[] = [yellow, magenta, blue, green, magentaBright, yellowBright, blueBright, greenBright];
|
|
192
|
+
const actorColorMap = new Map<string, Color>();
|
|
193
|
+
let nextColorIndex = 0;
|
|
194
|
+
|
|
195
|
+
/** Returns the color function assigned to a given actor, assigning a new one if needed. */
|
|
196
|
+
export function getActorColor(actor: string): Color {
|
|
197
|
+
let color = actorColorMap.get(actor);
|
|
198
|
+
if (!color) {
|
|
199
|
+
color = actorColors[nextColorIndex % actorColors.length];
|
|
200
|
+
actorColorMap.set(actor, color);
|
|
201
|
+
nextColorIndex++;
|
|
202
|
+
}
|
|
203
|
+
return color;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/** Resets the actor-to-color mapping. Useful for testing. */
|
|
207
|
+
export function resetActorColors(): void {
|
|
208
|
+
actorColorMap.clear();
|
|
209
|
+
nextColorIndex = 0;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// String template for messageFormat (used in worker threads and when per-actor coloring is disabled).
|
|
213
|
+
const messageFormatString = `${bold('{module}')}{if actor} ${cyan('{actor}')}{end}{if instanceId} ${reset(cyan('{instanceId}'))}{end} ${reset('{msg}')}`;
|
|
214
|
+
|
|
215
|
+
// Function for messageFormat when per-actor coloring is enabled (can only be used in-process, not worker threads).
|
|
216
|
+
type LogObject = { actor?: string; module?: string; instanceId?: string; msg?: string };
|
|
217
|
+
|
|
218
|
+
/** Formats a log message with per-actor coloring. Actor, module, and instanceId share the same color. */
|
|
219
|
+
export function formatLogMessage(log: LogObject, messageKey: string): string {
|
|
220
|
+
const actor = log.actor;
|
|
221
|
+
const module = log.module ?? '';
|
|
222
|
+
const instanceId = log.instanceId;
|
|
223
|
+
const msg = log[messageKey as keyof LogObject] ?? '';
|
|
224
|
+
|
|
225
|
+
// Use actor color for actor, module, and instanceId when actor is present
|
|
226
|
+
const color = actor ? getActorColor(actor) : cyan;
|
|
227
|
+
|
|
228
|
+
let result = bold(color(module));
|
|
229
|
+
if (actor) {
|
|
230
|
+
result += ' ' + color(actor);
|
|
231
|
+
}
|
|
232
|
+
if (instanceId) {
|
|
233
|
+
result += ' ' + reset(color(instanceId));
|
|
234
|
+
}
|
|
235
|
+
result += ' ' + reset(String(msg));
|
|
236
|
+
return result;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// Base options for pino-pretty (shared between transport and direct use).
|
|
240
|
+
const pinoPrettyBaseOpts = {
|
|
150
241
|
destination: 2,
|
|
151
242
|
sync: true,
|
|
152
243
|
colorize: useColor,
|
|
153
|
-
ignore: 'module,pid,hostname,trace_id,span_id,trace_flags,severity',
|
|
154
|
-
messageFormat: `${bold('{module}')} ${reset('{msg}')}`,
|
|
244
|
+
ignore: 'module,actor,instanceId,pid,hostname,trace_id,span_id,trace_flags,severity',
|
|
155
245
|
customLevels: 'fatal:60,error:50,warn:40,info:30,verbose:25,debug:20,trace:10',
|
|
156
246
|
customColors: 'fatal:bgRed,error:red,warn:yellow,info:green,verbose:magenta,debug:blue,trace:gray',
|
|
157
247
|
minimumLevel: 'trace' as const,
|
|
158
248
|
singleLine: !parseBooleanEnv(process.env['LOG_MULTILINE' satisfies EnvVar]),
|
|
159
249
|
};
|
|
160
250
|
|
|
251
|
+
/**
|
|
252
|
+
* Pino-pretty options for direct use (e.g., jest/setup.mjs).
|
|
253
|
+
* Includes function-based messageFormat for per-actor coloring when enabled.
|
|
254
|
+
*/
|
|
255
|
+
export const pinoPrettyOpts = {
|
|
256
|
+
...pinoPrettyBaseOpts,
|
|
257
|
+
messageFormat: useColorPerActor ? formatLogMessage : messageFormatString,
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
// Transport options use string template only (functions can't be serialized to worker threads).
|
|
261
|
+
const prettyTransportOpts = {
|
|
262
|
+
...pinoPrettyBaseOpts,
|
|
263
|
+
messageFormat: messageFormatString,
|
|
264
|
+
};
|
|
265
|
+
|
|
161
266
|
const prettyTransport: pino.TransportTargetOptions = {
|
|
162
267
|
target: 'pino-pretty',
|
|
163
|
-
options:
|
|
268
|
+
options: prettyTransportOpts,
|
|
164
269
|
level: 'trace',
|
|
165
270
|
};
|
|
166
271
|
|
|
@@ -261,6 +366,8 @@ export type Logger = { [K in LogLevel]: LogFn } & { /** Error log function */ er
|
|
|
261
366
|
isLevelEnabled: (level: LogLevel) => boolean;
|
|
262
367
|
module: string;
|
|
263
368
|
createChild: (childModule: string) => Logger;
|
|
369
|
+
/** Returns the bindings (actor, instanceId) for this logger. */
|
|
370
|
+
getBindings: () => LoggerBindings;
|
|
264
371
|
};
|
|
265
372
|
|
|
266
373
|
/**
|
|
@@ -270,5 +377,20 @@ export type Logger = { [K in LogLevel]: LogFn } & { /** Error log function */ er
|
|
|
270
377
|
* @returns A string with both the log message and the error message.
|
|
271
378
|
*/
|
|
272
379
|
function formatErr(msg: string, err?: unknown): string {
|
|
273
|
-
|
|
380
|
+
if (!err) {
|
|
381
|
+
return msg;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
try {
|
|
385
|
+
return `${msg}: ${inspect(err)}`;
|
|
386
|
+
} catch {
|
|
387
|
+
// inspect can crash on error objects with broken property descriptors
|
|
388
|
+
try {
|
|
389
|
+
// eslint-disable-next-line @typescript-eslint/no-base-to-string
|
|
390
|
+
return `${msg}: ${err instanceof Error ? `${err.name}: ${err.message}` : String(err)}`;
|
|
391
|
+
} catch {
|
|
392
|
+
// if even String(err) fails, return the original message with a note about the error
|
|
393
|
+
return `${msg}: [unserializable error]`;
|
|
394
|
+
}
|
|
395
|
+
}
|
|
274
396
|
}
|
|
@@ -122,7 +122,7 @@ export abstract class BaseMemoryQueue<T> {
|
|
|
122
122
|
* @param handler - A function that takes an item of type T and returns a Promise<void> after processing the item.
|
|
123
123
|
* @returns A Promise<void> that resolves when the queue is finished processing.
|
|
124
124
|
*/
|
|
125
|
-
public async process(handler: (item: T) => Promise<void>) {
|
|
125
|
+
public async process(handler: (item: T) => Promise<void> | void) {
|
|
126
126
|
try {
|
|
127
127
|
while (true) {
|
|
128
128
|
const item = await this.get();
|
package/src/queue/batch_queue.ts
CHANGED
package/src/queue/semaphore.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { FifoMemoryQueue } from './fifo_memory_queue.js';
|
|
2
2
|
|
|
3
|
+
export interface ISemaphore {
|
|
4
|
+
acquire(): Promise<void>;
|
|
5
|
+
release(): void;
|
|
6
|
+
}
|
|
7
|
+
|
|
3
8
|
/**
|
|
4
9
|
* Allows the acquiring of up to `size` tokens before calls to acquire block, waiting for a call to release().
|
|
5
10
|
*/
|
package/src/retry/index.ts
CHANGED
|
@@ -103,3 +103,51 @@ export async function retryUntil<T>(
|
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Retry an asynchronous function until it returns a truthy value or the maximum number of retries is exceeded.
|
|
109
|
+
* The function is retried periodically with a fixed interval between attempts.
|
|
110
|
+
*
|
|
111
|
+
* @param fn - The asynchronous function to be retried, which should return a truthy value upon success or undefined otherwise.
|
|
112
|
+
* @param name - The optional name of the operation, used for generating error messages.
|
|
113
|
+
* @param maxRetries - The maximum number of retry attempts before throwing an error.
|
|
114
|
+
* @param retryInterval - The optional interval, in seconds, between retry attempts. Defaults to 1 second.
|
|
115
|
+
* @returns A Promise that resolves with the successful (truthy) result of the provided function, or rejects if retries are exhausted.
|
|
116
|
+
*/
|
|
117
|
+
export async function retryTimes<T>(
|
|
118
|
+
fn: () => (T | undefined) | Promise<T | undefined>,
|
|
119
|
+
name = '',
|
|
120
|
+
maxRetries: number,
|
|
121
|
+
retryInterval = 1,
|
|
122
|
+
) {
|
|
123
|
+
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
124
|
+
const result = await fn();
|
|
125
|
+
if (result) {
|
|
126
|
+
return result;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (attempt < maxRetries) {
|
|
130
|
+
await sleep(retryInterval * 1000);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
throw new Error(name ? `Retries exhausted awaiting ${name}` : 'Retries exhausted');
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Convenience wrapper around retryUntil with fast polling for tests.
|
|
139
|
+
* Uses 10s timeout and 100ms polling interval by default.
|
|
140
|
+
*
|
|
141
|
+
* @param fn - The function to retry until it returns a truthy value.
|
|
142
|
+
* @param name - Description of what we're waiting for (for error messages).
|
|
143
|
+
* @param timeout - Optional timeout in seconds. Defaults to 10s.
|
|
144
|
+
* @param interval - Optional interval in seconds. Defaults to 0.1s (100ms).
|
|
145
|
+
*/
|
|
146
|
+
export function retryFastUntil<T>(
|
|
147
|
+
fn: () => (T | undefined) | Promise<T | undefined>,
|
|
148
|
+
name = '',
|
|
149
|
+
timeout = 10,
|
|
150
|
+
interval = 0.1,
|
|
151
|
+
) {
|
|
152
|
+
return retryUntil(fn, name, timeout, interval);
|
|
153
|
+
}
|
package/src/schemas/api.ts
CHANGED
|
@@ -37,7 +37,10 @@ export type ApiSchema = {
|
|
|
37
37
|
};
|
|
38
38
|
|
|
39
39
|
/** Return whether an API schema defines a valid function schema for a given method name. */
|
|
40
|
-
export function schemaHasMethod
|
|
40
|
+
export function schemaHasMethod<T extends ApiSchema>(
|
|
41
|
+
schema: T,
|
|
42
|
+
methodName: string,
|
|
43
|
+
): methodName is Extract<keyof T, string> {
|
|
41
44
|
return (
|
|
42
45
|
typeof methodName === 'string' &&
|
|
43
46
|
Object.hasOwn(schema, methodName) &&
|
package/src/schemas/schemas.ts
CHANGED
|
@@ -4,10 +4,10 @@ import { EpochNumber, EpochNumberSchema } from '../branded-types/epoch.js';
|
|
|
4
4
|
import { SlotNumber, SlotNumberSchema } from '../branded-types/slot.js';
|
|
5
5
|
import { Buffer32 } from '../buffer/buffer32.js';
|
|
6
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';
|
|
7
9
|
import { EthAddress } from '../eth-address/index.js';
|
|
8
|
-
import {
|
|
9
|
-
import { Point } from '../fields/point.js';
|
|
10
|
-
import { isHex, withoutHexPrefix } from '../string/index.js';
|
|
10
|
+
import { isHex, withHexPrefix, withoutHexPrefix } from '../string/index.js';
|
|
11
11
|
import { bufferSchema, hexSchema } from './utils.js';
|
|
12
12
|
|
|
13
13
|
export const schemas = {
|
|
@@ -58,6 +58,14 @@ export const schemas = {
|
|
|
58
58
|
.max(2 ** 32 - 1),
|
|
59
59
|
),
|
|
60
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
|
+
|
|
61
69
|
/** Accepts a hex string as a Buffer32 type. */
|
|
62
70
|
Buffer32: z.string().refine(isHex, 'Not a valid hex string').transform(Buffer32.fromString),
|
|
63
71
|
|
|
@@ -74,6 +82,9 @@ 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
|
};
|
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
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { toBigIntBE } from '../bigint-buffer/index.js';
|
|
1
2
|
import type { Tuple } from './types.js';
|
|
2
3
|
|
|
3
4
|
/**
|
|
@@ -130,6 +131,20 @@ export class BufferReader {
|
|
|
130
131
|
return result;
|
|
131
132
|
}
|
|
132
133
|
|
|
134
|
+
/**
|
|
135
|
+
* Reads a 256-bit signed integer (two's complement) from the buffer at the current index position.
|
|
136
|
+
* Updates the index position by 32 bytes after reading the number.
|
|
137
|
+
*
|
|
138
|
+
* @returns The read 256 bit signed value as a bigint.
|
|
139
|
+
*/
|
|
140
|
+
public readInt256(): bigint {
|
|
141
|
+
this.#rangeCheck(32);
|
|
142
|
+
const unsigned = toBigIntBE(this.buffer.subarray(this.index, this.index + 32));
|
|
143
|
+
this.index += 32;
|
|
144
|
+
const signBit = 1n << 255n;
|
|
145
|
+
return unsigned >= signBit ? unsigned - (1n << 256n) : unsigned;
|
|
146
|
+
}
|
|
147
|
+
|
|
133
148
|
/** Alias for readUInt256 */
|
|
134
149
|
public readBigInt(): bigint {
|
|
135
150
|
return this.readUInt256();
|
|
@@ -224,15 +239,22 @@ export class BufferReader {
|
|
|
224
239
|
* deserializing each one using the 'fromBuffer' method of 'itemDeserializer'.
|
|
225
240
|
*
|
|
226
241
|
* @param itemDeserializer - Object with 'fromBuffer' method to deserialize vector elements.
|
|
242
|
+
* @param maxSize - Optional maximum allowed size for the vector. If the size exceeds this, an error is thrown.
|
|
227
243
|
* @returns An array of deserialized elements of type T.
|
|
228
244
|
*/
|
|
229
|
-
public readVector<T>(
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
245
|
+
public readVector<T>(
|
|
246
|
+
itemDeserializer: {
|
|
247
|
+
/**
|
|
248
|
+
* A method to deserialize data from a buffer.
|
|
249
|
+
*/
|
|
250
|
+
fromBuffer: (reader: BufferReader) => T;
|
|
251
|
+
},
|
|
252
|
+
maxSize?: number,
|
|
253
|
+
): T[] {
|
|
235
254
|
const size = this.readNumber();
|
|
255
|
+
if (maxSize !== undefined && size > maxSize) {
|
|
256
|
+
throw new Error(`Vector size ${size} exceeds maximum allowed ${maxSize}`);
|
|
257
|
+
}
|
|
236
258
|
const result = new Array<T>(size);
|
|
237
259
|
for (let i = 0; i < size; i++) {
|
|
238
260
|
result[i] = itemDeserializer.fromBuffer(this);
|
|
@@ -344,10 +366,11 @@ export class BufferReader {
|
|
|
344
366
|
* The method first reads the size of the string, then reads the corresponding
|
|
345
367
|
* number of bytes from the buffer and converts them to a string.
|
|
346
368
|
*
|
|
369
|
+
* @param maxSize - Optional maximum allowed size for the string buffer. If the size exceeds this, an error is thrown.
|
|
347
370
|
* @returns The read string from the buffer.
|
|
348
371
|
*/
|
|
349
|
-
public readString(): string {
|
|
350
|
-
return this.readBuffer().toString();
|
|
372
|
+
public readString(maxSize?: number): string {
|
|
373
|
+
return this.readBuffer(maxSize).toString();
|
|
351
374
|
}
|
|
352
375
|
|
|
353
376
|
/**
|
|
@@ -356,10 +379,14 @@ export class BufferReader {
|
|
|
356
379
|
* a Buffer with that size containing the bytes. Useful for reading variable-length
|
|
357
380
|
* binary data encoded as (size, data) format.
|
|
358
381
|
*
|
|
382
|
+
* @param maxSize - Optional maximum allowed size for the buffer. If the size exceeds this, an error is thrown.
|
|
359
383
|
* @returns A Buffer containing the read bytes.
|
|
360
384
|
*/
|
|
361
|
-
public readBuffer(): Buffer {
|
|
385
|
+
public readBuffer(maxSize?: number): Buffer {
|
|
362
386
|
const size = this.readNumber();
|
|
387
|
+
if (maxSize !== undefined && size > maxSize) {
|
|
388
|
+
throw new Error(`Buffer size ${size} exceeds maximum allowed ${maxSize}`);
|
|
389
|
+
}
|
|
363
390
|
this.#rangeCheck(size);
|
|
364
391
|
return this.readBytes(size);
|
|
365
392
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { toBigIntBE, toBufferBE } from '../bigint-buffer/index.js';
|
|
2
|
-
import { Fr } from '../
|
|
2
|
+
import { Fr } from '../curves/bn254/field.js';
|
|
3
3
|
import { numToUInt32BE } from './free_funcs.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -269,6 +269,22 @@ export function serializeBigInt(n: bigint, width = 32) {
|
|
|
269
269
|
return toBufferBE(n, width);
|
|
270
270
|
}
|
|
271
271
|
|
|
272
|
+
/**
|
|
273
|
+
* Serialize a signed BigInt value into a Buffer of specified width using two's complement.
|
|
274
|
+
* @param n - The signed BigInt value to be serialized.
|
|
275
|
+
* @param width - The width (in bytes) of the output Buffer, optional with default value 32.
|
|
276
|
+
* @returns A Buffer containing the serialized signed BigInt value in big-endian format.
|
|
277
|
+
*/
|
|
278
|
+
export function serializeSignedBigInt(n: bigint, width = 32) {
|
|
279
|
+
const widthBits = BigInt(width * 8);
|
|
280
|
+
const max = 1n << (widthBits - 1n);
|
|
281
|
+
if (n < -max || n >= max) {
|
|
282
|
+
throw new Error(`Signed BigInt ${n.toString()} does not fit into ${width} bytes`);
|
|
283
|
+
}
|
|
284
|
+
const unsigned = n < 0n ? (1n << widthBits) + n : n;
|
|
285
|
+
return toBufferBE(unsigned, width);
|
|
286
|
+
}
|
|
287
|
+
|
|
272
288
|
/**
|
|
273
289
|
* Deserialize a big integer from a buffer, given an offset and width.
|
|
274
290
|
* Reads the specified number of bytes from the buffer starting at the offset, converts it to a big integer, and returns the deserialized result along with the number of bytes read (advanced).
|
|
@@ -282,6 +298,22 @@ export function deserializeBigInt(buf: Buffer, offset = 0, width = 32) {
|
|
|
282
298
|
return { elem: toBigIntBE(buf.subarray(offset, offset + width)), adv: width };
|
|
283
299
|
}
|
|
284
300
|
|
|
301
|
+
/**
|
|
302
|
+
* Deserialize a signed BigInt from a buffer (two's complement).
|
|
303
|
+
* @param buf - The buffer containing the signed big integer to be deserialized.
|
|
304
|
+
* @param offset - The position in the buffer where the integer starts. Defaults to 0.
|
|
305
|
+
* @param width - The number of bytes to read from the buffer for the integer. Defaults to 32.
|
|
306
|
+
* @returns An object containing the deserialized signed bigint value ('elem') and bytes advanced ('adv').
|
|
307
|
+
*/
|
|
308
|
+
export function deserializeSignedBigInt(buf: Buffer, offset = 0, width = 32) {
|
|
309
|
+
const { elem, adv } = deserializeBigInt(buf, offset, width);
|
|
310
|
+
const widthBits = BigInt(width * 8);
|
|
311
|
+
const signBit = 1n << (widthBits - 1n);
|
|
312
|
+
const fullRange = 1n << widthBits;
|
|
313
|
+
const signed = elem >= signBit ? elem - fullRange : elem;
|
|
314
|
+
return { elem: signed, adv };
|
|
315
|
+
}
|
|
316
|
+
|
|
285
317
|
/**
|
|
286
318
|
* Serializes a Date object into a Buffer containing its timestamp as a big integer value.
|
|
287
319
|
* The resulting Buffer has a fixed width of 8 bytes, representing a 64-bit big-endian integer.
|
package/src/sleep/index.ts
CHANGED
|
@@ -22,6 +22,7 @@ import { InterruptError } from '../error/index.js';
|
|
|
22
22
|
*/
|
|
23
23
|
export class InterruptibleSleep {
|
|
24
24
|
private interrupts: Array<(shouldThrow: boolean) => void> = [];
|
|
25
|
+
private timeoutIds: NodeJS.Timeout[] = [];
|
|
25
26
|
|
|
26
27
|
/**
|
|
27
28
|
* Sleep for a specified amount of time in milliseconds.
|
|
@@ -38,9 +39,15 @@ export class InterruptibleSleep {
|
|
|
38
39
|
this.interrupts.push(resolve);
|
|
39
40
|
});
|
|
40
41
|
|
|
41
|
-
|
|
42
|
+
let timeoutId: NodeJS.Timeout;
|
|
43
|
+
const timeoutPromise = new Promise<boolean>(resolve => {
|
|
44
|
+
timeoutId = setTimeout(() => resolve(false), ms);
|
|
45
|
+
this.timeoutIds.push(timeoutId);
|
|
46
|
+
});
|
|
42
47
|
const shouldThrow = await Promise.race([interruptPromise, timeoutPromise]);
|
|
43
48
|
|
|
49
|
+
clearTimeout(timeoutId!);
|
|
50
|
+
this.timeoutIds = this.timeoutIds.filter(id => id !== timeoutId);
|
|
44
51
|
this.interrupts = this.interrupts.filter(res => res !== interruptResolve);
|
|
45
52
|
|
|
46
53
|
if (shouldThrow) {
|
|
@@ -58,6 +65,8 @@ export class InterruptibleSleep {
|
|
|
58
65
|
public interrupt(sleepShouldThrow = false): void {
|
|
59
66
|
this.interrupts.forEach(resolve => resolve(sleepShouldThrow));
|
|
60
67
|
this.interrupts = [];
|
|
68
|
+
this.timeoutIds.forEach(id => clearTimeout(id));
|
|
69
|
+
this.timeoutIds = [];
|
|
61
70
|
}
|
|
62
71
|
}
|
|
63
72
|
|
|
@@ -73,3 +82,9 @@ export class InterruptibleSleep {
|
|
|
73
82
|
export function sleep<T>(ms: number, returnValue?: T): Promise<T> {
|
|
74
83
|
return new Promise(resolve => setTimeout(() => resolve(returnValue as T), ms));
|
|
75
84
|
}
|
|
85
|
+
|
|
86
|
+
/** Sleeps until the target date */
|
|
87
|
+
export function sleepUntil<T>(target: Date, now: Date, returnValue?: T): Promise<T> {
|
|
88
|
+
const ms = target.getTime() - now.getTime();
|
|
89
|
+
return sleep(ms, returnValue);
|
|
90
|
+
}
|