@aztec-labs/foundation 6.0.0-nightly.20260829
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/README.md +1 -0
- package/dest/array/array.d.ts +68 -0
- package/dest/array/array.d.ts.map +1 -0
- package/dest/array/array.js +100 -0
- package/dest/array/index.d.ts +3 -0
- package/dest/array/index.d.ts.map +1 -0
- package/dest/array/index.js +2 -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/async-map/index.d.ts +13 -0
- package/dest/async-map/index.d.ts.map +1 -0
- package/dest/async-map/index.js +17 -0
- package/dest/async-pool/index.d.ts +3 -0
- package/dest/async-pool/index.d.ts.map +1 -0
- package/dest/async-pool/index.js +48 -0
- package/dest/bigint/index.d.ts +7 -0
- package/dest/bigint/index.d.ts.map +1 -0
- package/dest/bigint/index.js +15 -0
- package/dest/bigint-buffer/index.d.ts +40 -0
- package/dest/bigint-buffer/index.d.ts.map +1 -0
- package/dest/bigint-buffer/index.js +81 -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 +89 -0
- package/dest/branded-types/buffer32_hash.d.ts +27 -0
- package/dest/branded-types/buffer32_hash.d.ts.map +1 -0
- package/dest/branded-types/buffer32_hash.js +12 -0
- package/dest/branded-types/checkpoint_number.d.ts +60 -0
- package/dest/branded-types/checkpoint_number.d.ts.map +1 -0
- package/dest/branded-types/checkpoint_number.js +88 -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 +8 -0
- package/dest/branded-types/index.d.ts.map +1 -0
- package/dest/branded-types/index.js +6 -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 +45 -0
- package/dest/branded-types/slot.d.ts.map +1 -0
- package/dest/branded-types/slot.js +62 -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 +82 -0
- package/dest/buffer/buffer16.d.ts.map +1 -0
- package/dest/buffer/buffer16.js +102 -0
- package/dest/buffer/buffer32.d.ts +54 -0
- package/dest/buffer/buffer32.d.ts.map +1 -0
- package/dest/buffer/buffer32.js +83 -0
- package/dest/buffer/index.d.ts +4 -0
- package/dest/buffer/index.d.ts.map +1 -0
- package/dest/buffer/index.js +3 -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 +135 -0
- package/dest/collection/array.d.ts.map +1 -0
- package/dest/collection/array.js +302 -0
- package/dest/collection/index.d.ts +5 -0
- package/dest/collection/index.d.ts.map +1 -0
- package/dest/collection/index.js +4 -0
- package/dest/collection/lru_map.d.ts +41 -0
- package/dest/collection/lru_map.d.ts.map +1 -0
- package/dest/collection/lru_map.js +119 -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/collection/object.d.ts +30 -0
- package/dest/collection/object.d.ts.map +1 -0
- package/dest/collection/object.js +57 -0
- package/dest/committable/committable.d.ts +28 -0
- package/dest/committable/committable.d.ts.map +1 -0
- package/dest/committable/committable.js +36 -0
- package/dest/committable/index.d.ts +2 -0
- package/dest/committable/index.d.ts.map +1 -0
- package/dest/committable/index.js +1 -0
- package/dest/config/env_var.d.ts +2 -0
- package/dest/config/env_var.d.ts.map +1 -0
- package/dest/config/env_var.js +1 -0
- package/dest/config/index.d.ts +154 -0
- package/dest/config/index.d.ts.map +1 -0
- package/dest/config/index.js +272 -0
- package/dest/config/network_config.d.ts +28 -0
- package/dest/config/network_config.d.ts.map +1 -0
- package/dest/config/network_config.js +14 -0
- package/dest/config/network_name.d.ts +3 -0
- package/dest/config/network_name.d.ts.map +1 -0
- package/dest/config/network_name.js +19 -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.d.ts +28 -0
- package/dest/config/secret_value.d.ts.map +1 -0
- package/dest/config/secret_value.js +36 -0
- package/dest/crypto/aes128/index.d.ts +33 -0
- package/dest/crypto/aes128/index.d.ts.map +1 -0
- package/dest/crypto/aes128/index.js +71 -0
- package/dest/crypto/bls/bn254_keystore.d.ts +129 -0
- package/dest/crypto/bls/bn254_keystore.d.ts.map +1 -0
- package/dest/crypto/bls/bn254_keystore.js +206 -0
- package/dest/crypto/bls/index.d.ts +13 -0
- package/dest/crypto/bls/index.d.ts.map +1 -0
- package/dest/crypto/bls/index.js +87 -0
- package/dest/crypto/bn254/index.d.ts +39 -0
- package/dest/crypto/bn254/index.d.ts.map +1 -0
- package/dest/crypto/bn254/index.js +56 -0
- package/dest/crypto/ecdsa/index.d.ts +39 -0
- package/dest/crypto/ecdsa/index.d.ts.map +1 -0
- package/dest/crypto/ecdsa/index.js +102 -0
- package/dest/crypto/ecdsa/signature.d.ts +69 -0
- package/dest/crypto/ecdsa/signature.d.ts.map +1 -0
- package/dest/crypto/ecdsa/signature.js +92 -0
- package/dest/crypto/grumpkin/index.d.ts +42 -0
- package/dest/crypto/grumpkin/index.d.ts.map +1 -0
- package/dest/crypto/grumpkin/index.js +160 -0
- package/dest/crypto/keccak/index.d.ts +26 -0
- package/dest/crypto/keccak/index.d.ts.map +1 -0
- package/dest/crypto/keccak/index.js +248 -0
- package/dest/crypto/keys/index.d.ts +4 -0
- package/dest/crypto/keys/index.d.ts.map +1 -0
- package/dest/crypto/keys/index.js +34 -0
- package/dest/crypto/pedersen/index.d.ts +2 -0
- package/dest/crypto/pedersen/index.d.ts.map +1 -0
- package/dest/crypto/pedersen/index.js +1 -0
- package/dest/crypto/pedersen/pedersen.noble.d.ts +9 -0
- package/dest/crypto/pedersen/pedersen.noble.d.ts.map +1 -0
- package/dest/crypto/pedersen/pedersen.noble.js +558 -0
- package/dest/crypto/pedersen/pedersen.wasm.d.ts +19 -0
- package/dest/crypto/pedersen/pedersen.wasm.d.ts.map +1 -0
- package/dest/crypto/pedersen/pedersen.wasm.js +51 -0
- package/dest/crypto/poseidon/index.d.ts +23 -0
- package/dest/crypto/poseidon/index.d.ts.map +1 -0
- package/dest/crypto/poseidon/index.js +71 -0
- package/dest/crypto/random/index.d.ts +23 -0
- package/dest/crypto/random/index.d.ts.map +1 -0
- package/dest/crypto/random/index.js +38 -0
- package/dest/crypto/random/randomness_singleton.d.ts +24 -0
- package/dest/crypto/random/randomness_singleton.d.ts.map +1 -0
- package/dest/crypto/random/randomness_singleton.js +55 -0
- package/dest/crypto/schnorr/index.d.ts +32 -0
- package/dest/crypto/schnorr/index.d.ts.map +1 -0
- package/dest/crypto/schnorr/index.js +60 -0
- package/dest/crypto/schnorr/signature.d.ts +48 -0
- package/dest/crypto/schnorr/signature.d.ts.map +1 -0
- package/dest/crypto/schnorr/signature.js +77 -0
- package/dest/crypto/secp256k1/index.d.ts +30 -0
- package/dest/crypto/secp256k1/index.d.ts.map +1 -0
- package/dest/crypto/secp256k1/index.js +121 -0
- package/dest/crypto/secp256k1-signer/index.d.ts +3 -0
- package/dest/crypto/secp256k1-signer/index.d.ts.map +1 -0
- package/dest/crypto/secp256k1-signer/index.js +2 -0
- package/dest/crypto/secp256k1-signer/secp256k1_signer.d.ts +24 -0
- package/dest/crypto/secp256k1-signer/secp256k1_signer.d.ts.map +1 -0
- package/dest/crypto/secp256k1-signer/secp256k1_signer.js +30 -0
- package/dest/crypto/secp256k1-signer/utils.d.ts +102 -0
- package/dest/crypto/secp256k1-signer/utils.d.ts.map +1 -0
- package/dest/crypto/secp256k1-signer/utils.js +196 -0
- package/dest/crypto/sha256/index.d.ts +37 -0
- package/dest/crypto/sha256/index.d.ts.map +1 -0
- package/dest/crypto/sha256/index.js +208 -0
- package/dest/crypto/sha512/index.d.ts +9 -0
- package/dest/crypto/sha512/index.d.ts.map +1 -0
- package/dest/crypto/sha512/index.js +12 -0
- package/dest/crypto/signature/index.d.ts +17 -0
- package/dest/crypto/signature/index.d.ts.map +1 -0
- package/dest/crypto/signature/index.js +3 -0
- package/dest/crypto/sync/index.d.ts +3 -0
- package/dest/crypto/sync/index.d.ts.map +1 -0
- package/dest/crypto/sync/index.js +4 -0
- package/dest/crypto/sync/pedersen/index.d.ts +19 -0
- package/dest/crypto/sync/pedersen/index.d.ts.map +1 -0
- package/dest/crypto/sync/pedersen/index.js +45 -0
- package/dest/crypto/sync/poseidon/index.d.ts +23 -0
- package/dest/crypto/sync/poseidon/index.d.ts.map +1 -0
- package/dest/crypto/sync/poseidon/index.js +60 -0
- package/dest/curves/bls12/field.d.ts +148 -0
- package/dest/curves/bls12/field.d.ts.map +1 -0
- package/dest/curves/bls12/field.js +357 -0
- 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/curves/bls12/point.d.ts +229 -0
- package/dest/curves/bls12/point.d.ts.map +1 -0
- package/dest/curves/bls12/point.js +400 -0
- package/dest/curves/bn254/field.d.ts +185 -0
- package/dest/curves/bn254/field.d.ts.map +1 -0
- package/dest/curves/bn254/field.js +420 -0
- 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/curves/grumpkin/point.d.ts +168 -0
- package/dest/curves/grumpkin/point.d.ts.map +1 -0
- package/dest/curves/grumpkin/point.js +263 -0
- package/dest/decorators/index.d.ts +2 -0
- package/dest/decorators/index.d.ts.map +1 -0
- package/dest/decorators/index.js +1 -0
- package/dest/decorators/memoize.d.ts +2 -0
- package/dest/decorators/memoize.d.ts.map +1 -0
- package/dest/decorators/memoize.js +11 -0
- package/dest/error/index.d.ts +21 -0
- package/dest/error/index.d.ts.map +1 -0
- package/dest/error/index.js +17 -0
- package/dest/eth-address/index.d.ts +143 -0
- package/dest/eth-address/index.d.ts.map +1 -0
- package/dest/eth-address/index.js +224 -0
- package/dest/eth-signature/eth_signature.d.ts +65 -0
- package/dest/eth-signature/eth_signature.d.ts.map +1 -0
- package/dest/eth-signature/eth_signature.js +110 -0
- package/dest/eth-signature/index.d.ts +2 -0
- package/dest/eth-signature/index.d.ts.map +1 -0
- package/dest/eth-signature/index.js +1 -0
- 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 +91 -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/fifo_set/fifo_set.d.ts +15 -0
- package/dest/fifo_set/fifo_set.d.ts.map +1 -0
- package/dest/fifo_set/fifo_set.js +39 -0
- package/dest/fifo_set/index.d.ts +2 -0
- package/dest/fifo_set/index.d.ts.map +1 -0
- package/dest/fifo_set/index.js +1 -0
- package/dest/fs/index.d.ts +3 -0
- package/dest/fs/index.d.ts.map +1 -0
- package/dest/fs/index.js +2 -0
- package/dest/fs/run_in_dir.d.ts +2 -0
- package/dest/fs/run_in_dir.d.ts.map +1 -0
- package/dest/fs/run_in_dir.js +31 -0
- package/dest/fs/try_rm_dir.d.ts +3 -0
- package/dest/fs/try_rm_dir.d.ts.map +1 -0
- package/dest/fs/try_rm_dir.js +16 -0
- package/dest/iterable/all.d.ts +9 -0
- package/dest/iterable/all.d.ts.map +1 -0
- package/dest/iterable/all.js +18 -0
- package/dest/iterable/filter.d.ts +10 -0
- package/dest/iterable/filter.d.ts.map +1 -0
- package/dest/iterable/filter.js +48 -0
- package/dest/iterable/first.d.ts +8 -0
- package/dest/iterable/first.d.ts.map +1 -0
- package/dest/iterable/first.js +11 -0
- package/dest/iterable/index.d.ts +9 -0
- package/dest/iterable/index.d.ts.map +1 -0
- package/dest/iterable/index.js +8 -0
- package/dest/iterable/isAsyncIt.d.ts +7 -0
- package/dest/iterable/isAsyncIt.d.ts.map +1 -0
- package/dest/iterable/isAsyncIt.js +7 -0
- package/dest/iterable/map.d.ts +12 -0
- package/dest/iterable/map.d.ts.map +1 -0
- package/dest/iterable/map.js +36 -0
- package/dest/iterable/peek.d.ts +19 -0
- package/dest/iterable/peek.d.ts.map +1 -0
- package/dest/iterable/peek.js +33 -0
- package/dest/iterable/sort.d.ts +14 -0
- package/dest/iterable/sort.d.ts.map +1 -0
- package/dest/iterable/sort.js +15 -0
- package/dest/iterable/take.d.ts +10 -0
- package/dest/iterable/take.d.ts.map +1 -0
- package/dest/iterable/take.js +32 -0
- package/dest/iterable/toArray.d.ts +2 -0
- package/dest/iterable/toArray.d.ts.map +1 -0
- package/dest/iterable/toArray.js +7 -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/env.js +48 -0
- package/dest/jest/setup.js +34 -0
- package/dest/jest/setupAfterEnv.js +3 -0
- package/dest/json-rpc/client/fetch.d.ts +37 -0
- package/dest/json-rpc/client/fetch.d.ts.map +1 -0
- package/dest/json-rpc/client/fetch.js +67 -0
- package/dest/json-rpc/client/index.d.ts +3 -0
- package/dest/json-rpc/client/index.d.ts.map +1 -0
- package/dest/json-rpc/client/index.js +2 -0
- package/dest/json-rpc/client/safe_json_rpc_client.d.ts +33 -0
- package/dest/json-rpc/client/safe_json_rpc_client.d.ts.map +1 -0
- package/dest/json-rpc/client/safe_json_rpc_client.js +218 -0
- package/dest/json-rpc/client/undici.d.ts +16 -0
- package/dest/json-rpc/client/undici.d.ts.map +1 -0
- package/dest/json-rpc/client/undici.js +112 -0
- package/dest/json-rpc/convert.d.ts +20 -0
- package/dest/json-rpc/convert.d.ts.map +1 -0
- package/dest/json-rpc/convert.js +40 -0
- package/dest/json-rpc/errors.d.ts +4 -0
- package/dest/json-rpc/errors.d.ts.map +1 -0
- package/dest/json-rpc/errors.js +6 -0
- package/dest/json-rpc/fixtures/class_a.d.ts +13 -0
- package/dest/json-rpc/fixtures/class_a.d.ts.map +1 -0
- package/dest/json-rpc/fixtures/class_a.js +20 -0
- package/dest/json-rpc/fixtures/class_b.d.ts +13 -0
- package/dest/json-rpc/fixtures/class_b.d.ts.map +1 -0
- package/dest/json-rpc/fixtures/class_b.js +20 -0
- package/dest/json-rpc/fixtures/test_state.d.ts +85 -0
- package/dest/json-rpc/fixtures/test_state.d.ts.map +1 -0
- package/dest/json-rpc/fixtures/test_state.js +171 -0
- package/dest/json-rpc/index.d.ts +3 -0
- package/dest/json-rpc/index.d.ts.map +1 -0
- package/dest/json-rpc/index.js +2 -0
- package/dest/json-rpc/js_utils.d.ts +13 -0
- package/dest/json-rpc/js_utils.d.ts.map +1 -0
- package/dest/json-rpc/js_utils.js +16 -0
- 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 +3 -0
- package/dest/json-rpc/server/index.d.ts.map +1 -0
- package/dest/json-rpc/server/index.js +2 -0
- package/dest/json-rpc/server/safe_json_rpc_server.d.ts +177 -0
- package/dest/json-rpc/server/safe_json_rpc_server.d.ts.map +1 -0
- package/dest/json-rpc/server/safe_json_rpc_server.js +570 -0
- package/dest/json-rpc/test/index.d.ts +2 -0
- package/dest/json-rpc/test/index.d.ts.map +1 -0
- package/dest/json-rpc/test/index.js +1 -0
- package/dest/json-rpc/test/integration.d.ts +14 -0
- package/dest/json-rpc/test/integration.d.ts.map +1 -0
- package/dest/json-rpc/test/integration.js +21 -0
- package/dest/log/aws-logger-config.d.ts +8 -0
- package/dest/log/aws-logger-config.d.ts.map +1 -0
- package/dest/log/aws-logger-config.js +55 -0
- 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/console.d.ts +11 -0
- package/dest/log/console.d.ts.map +1 -0
- package/dest/log/console.js +36 -0
- package/dest/log/gcloud-logger-config.d.ts +13 -0
- package/dest/log/gcloud-logger-config.d.ts.map +1 -0
- package/dest/log/gcloud-logger-config.js +61 -0
- package/dest/log/index.d.ts +7 -0
- package/dest/log/index.d.ts.map +1 -0
- package/dest/log/index.js +6 -0
- package/dest/log/libp2p_logger.d.ts +10 -0
- package/dest/log/libp2p_logger.d.ts.map +1 -0
- package/dest/log/libp2p_logger.js +76 -0
- package/dest/log/log-filters.d.ts +20 -0
- package/dest/log/log-filters.d.ts.map +1 -0
- package/dest/log/log-filters.js +73 -0
- package/dest/log/log-levels.d.ts +3 -0
- package/dest/log/log-levels.d.ts.map +1 -0
- package/dest/log/log-levels.js +10 -0
- package/dest/log/log_fn.d.ts +7 -0
- package/dest/log/log_fn.d.ts.map +1 -0
- package/dest/log/log_fn.js +1 -0
- package/dest/log/noir_debug_log_util.d.ts +14 -0
- package/dest/log/noir_debug_log_util.d.ts.map +1 -0
- package/dest/log/noir_debug_log_util.js +14 -0
- 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 +86 -0
- package/dest/log/pino-logger.d.ts.map +1 -0
- package/dest/log/pino-logger.js +347 -0
- package/dest/message/index.d.ts +32 -0
- package/dest/message/index.d.ts.map +1 -0
- package/dest/message/index.js +27 -0
- package/dest/mutex/index.d.ts +53 -0
- package/dest/mutex/index.d.ts.map +1 -0
- package/dest/mutex/index.js +78 -0
- package/dest/mutex/mutex_database.d.ts +10 -0
- package/dest/mutex/mutex_database.d.ts.map +1 -0
- package/dest/mutex/mutex_database.js +4 -0
- package/dest/noir/index.d.ts +2 -0
- package/dest/noir/index.d.ts.map +1 -0
- package/dest/noir/index.js +1 -0
- package/dest/noir/noir_package_config.d.ts +44 -0
- package/dest/noir/noir_package_config.d.ts.map +1 -0
- package/dest/noir/noir_package_config.js +36 -0
- package/dest/number/index.d.ts +3 -0
- package/dest/number/index.d.ts.map +1 -0
- package/dest/number/index.js +12 -0
- package/dest/profiler/index.d.ts +2 -0
- package/dest/profiler/index.d.ts.map +1 -0
- package/dest/profiler/index.js +1 -0
- package/dest/profiler/profiler.d.ts +8 -0
- package/dest/profiler/profiler.d.ts.map +1 -0
- package/dest/profiler/profiler.js +97 -0
- package/dest/promise/index.d.ts +3 -0
- package/dest/promise/index.d.ts.map +1 -0
- package/dest/promise/index.js +2 -0
- package/dest/promise/running-promise.d.ts +53 -0
- package/dest/promise/running-promise.d.ts.map +1 -0
- package/dest/promise/running-promise.js +122 -0
- package/dest/promise/utils.d.ts +25 -0
- package/dest/promise/utils.d.ts.map +1 -0
- package/dest/promise/utils.js +40 -0
- package/dest/queue/base_memory_queue.d.ts +65 -0
- package/dest/queue/base_memory_queue.d.ts.map +1 -0
- package/dest/queue/base_memory_queue.js +116 -0
- package/dest/queue/batch_queue.d.ts +47 -0
- package/dest/queue/batch_queue.d.ts.map +1 -0
- package/dest/queue/batch_queue.js +106 -0
- package/dest/queue/bounded_serial_queue.d.ts +56 -0
- package/dest/queue/bounded_serial_queue.d.ts.map +1 -0
- package/dest/queue/bounded_serial_queue.js +84 -0
- package/dest/queue/fifo_memory_queue.d.ts +21 -0
- package/dest/queue/fifo_memory_queue.d.ts.map +1 -0
- package/dest/queue/fifo_memory_queue.js +29 -0
- package/dest/queue/index.d.ts +7 -0
- package/dest/queue/index.d.ts.map +1 -0
- package/dest/queue/index.js +6 -0
- package/dest/queue/priority_memory_queue.d.ts +13 -0
- package/dest/queue/priority_memory_queue.d.ts.map +1 -0
- package/dest/queue/priority_memory_queue.js +16 -0
- package/dest/queue/priority_queue.d.ts +14 -0
- package/dest/queue/priority_queue.d.ts.map +1 -0
- package/dest/queue/priority_queue.js +29 -0
- package/dest/queue/semaphore.d.ts +27 -0
- package/dest/queue/semaphore.d.ts.map +1 -0
- package/dest/queue/semaphore.js +26 -0
- package/dest/queue/serial_queue.d.ts +49 -0
- package/dest/queue/serial_queue.d.ts.map +1 -0
- package/dest/queue/serial_queue.js +74 -0
- package/dest/retry/index.d.ts +83 -0
- package/dest/retry/index.d.ts.map +1 -0
- package/dest/retry/index.js +146 -0
- package/dest/running-promise/index.d.ts +2 -0
- package/dest/running-promise/index.d.ts.map +1 -0
- package/dest/running-promise/index.js +1 -0
- package/dest/schemas/api.d.ts +23 -0
- package/dest/schemas/api.d.ts.map +1 -0
- package/dest/schemas/api.js +9 -0
- package/dest/schemas/index.d.ts +6 -0
- package/dest/schemas/index.d.ts.map +1 -0
- package/dest/schemas/index.js +5 -0
- package/dest/schemas/parse.d.ts +9 -0
- package/dest/schemas/parse.d.ts.map +1 -0
- package/dest/schemas/parse.js +23 -0
- package/dest/schemas/schemas.d.ts +46 -0
- package/dest/schemas/schemas.d.ts.map +1 -0
- package/dest/schemas/schemas.js +56 -0
- package/dest/schemas/types.d.ts +33 -0
- package/dest/schemas/types.d.ts.map +1 -0
- package/dest/schemas/types.js +25 -0
- package/dest/schemas/utils.d.ts +47 -0
- package/dest/schemas/utils.d.ts.map +1 -0
- package/dest/schemas/utils.js +54 -0
- package/dest/serialize/buffer_reader.d.ts +274 -0
- package/dest/serialize/buffer_reader.d.ts.map +1 -0
- package/dest/serialize/buffer_reader.js +359 -0
- package/dest/serialize/buffer_sink.d.ts +134 -0
- package/dest/serialize/buffer_sink.d.ts.map +1 -0
- package/dest/serialize/buffer_sink.js +297 -0
- package/dest/serialize/field_reader.d.ts +121 -0
- package/dest/serialize/field_reader.d.ts.map +1 -0
- package/dest/serialize/field_reader.js +164 -0
- package/dest/serialize/free_funcs.d.ts +107 -0
- package/dest/serialize/free_funcs.d.ts.map +1 -0
- package/dest/serialize/free_funcs.js +183 -0
- package/dest/serialize/index.d.ts +8 -0
- package/dest/serialize/index.d.ts.map +1 -0
- package/dest/serialize/index.js +7 -0
- package/dest/serialize/serialize.d.ts +168 -0
- package/dest/serialize/serialize.d.ts.map +1 -0
- package/dest/serialize/serialize.js +258 -0
- package/dest/serialize/type_registry.d.ts +23 -0
- package/dest/serialize/type_registry.d.ts.map +1 -0
- package/dest/serialize/type_registry.js +61 -0
- package/dest/serialize/types.d.ts +33 -0
- package/dest/serialize/types.d.ts.map +1 -0
- package/dest/serialize/types.js +21 -0
- package/dest/sleep/index.d.ts +54 -0
- package/dest/sleep/index.d.ts.map +1 -0
- package/dest/sleep/index.js +80 -0
- package/dest/string/index.d.ts +18 -0
- package/dest/string/index.d.ts.map +1 -0
- package/dest/string/index.js +62 -0
- package/dest/testing/files/index.d.ts +20 -0
- package/dest/testing/files/index.d.ts.map +1 -0
- package/dest/testing/files/index.js +59 -0
- package/dest/testing/formatting.d.ts +4 -0
- package/dest/testing/formatting.d.ts.map +1 -0
- package/dest/testing/formatting.js +3 -0
- package/dest/testing/index.d.ts +5 -0
- package/dest/testing/index.d.ts.map +1 -0
- package/dest/testing/index.js +4 -0
- package/dest/testing/port_allocator.d.ts +10 -0
- package/dest/testing/port_allocator.d.ts.map +1 -0
- package/dest/testing/port_allocator.js +29 -0
- package/dest/testing/snapshot_serializer.d.ts +5 -0
- package/dest/testing/snapshot_serializer.d.ts.map +1 -0
- package/dest/testing/snapshot_serializer.js +32 -0
- package/dest/testing/test_data.d.ts +7 -0
- package/dest/testing/test_data.d.ts.map +1 -0
- package/dest/testing/test_data.js +29 -0
- package/dest/timer/date.d.ts +39 -0
- package/dest/timer/date.d.ts.map +1 -0
- package/dest/timer/date.js +62 -0
- package/dest/timer/elapsed.d.ts +13 -0
- package/dest/timer/elapsed.d.ts.map +1 -0
- package/dest/timer/elapsed.js +25 -0
- package/dest/timer/index.d.ts +5 -0
- package/dest/timer/index.d.ts.map +1 -0
- package/dest/timer/index.js +4 -0
- package/dest/timer/timeout.d.ts +56 -0
- package/dest/timer/timeout.d.ts.map +1 -0
- package/dest/timer/timeout.js +113 -0
- package/dest/timer/timer.d.ts +37 -0
- package/dest/timer/timer.d.ts.map +1 -0
- package/dest/timer/timer.js +40 -0
- package/dest/transport/dispatch/create_dispatch_proxy.d.ts +111 -0
- package/dest/transport/dispatch/create_dispatch_proxy.d.ts.map +1 -0
- package/dest/transport/dispatch/create_dispatch_proxy.js +59 -0
- package/dest/transport/dispatch/messages.d.ts +52 -0
- package/dest/transport/dispatch/messages.d.ts.map +1 -0
- package/dest/transport/dispatch/messages.js +13 -0
- package/dest/transport/index.d.ts +10 -0
- package/dest/transport/index.d.ts.map +1 -0
- package/dest/transport/index.js +9 -0
- package/dest/transport/interface/connector.d.ts +8 -0
- package/dest/transport/interface/connector.d.ts.map +1 -0
- package/dest/transport/interface/connector.js +3 -0
- package/dest/transport/interface/listener.d.ts +12 -0
- package/dest/transport/interface/listener.d.ts.map +1 -0
- package/dest/transport/interface/listener.js +4 -0
- package/dest/transport/interface/socket.d.ts +13 -0
- package/dest/transport/interface/socket.d.ts.map +1 -0
- package/dest/transport/interface/socket.js +7 -0
- package/dest/transport/interface/transferable.d.ts +68 -0
- package/dest/transport/interface/transferable.d.ts.map +1 -0
- package/dest/transport/interface/transferable.js +63 -0
- package/dest/transport/node/index.d.ts +3 -0
- package/dest/transport/node/index.d.ts.map +1 -0
- package/dest/transport/node/index.js +2 -0
- package/dest/transport/node/node_connector.d.ts +27 -0
- package/dest/transport/node/node_connector.d.ts.map +1 -0
- package/dest/transport/node/node_connector.js +26 -0
- package/dest/transport/node/node_connector_socket.d.ts +41 -0
- package/dest/transport/node/node_connector_socket.d.ts.map +1 -0
- package/dest/transport/node/node_connector_socket.js +44 -0
- package/dest/transport/node/node_listener.d.ts +25 -0
- package/dest/transport/node/node_listener.d.ts.map +1 -0
- package/dest/transport/node/node_listener.js +26 -0
- package/dest/transport/node/node_listener_socket.d.ts +36 -0
- package/dest/transport/node/node_listener_socket.d.ts.map +1 -0
- package/dest/transport/node/node_listener_socket.js +40 -0
- package/dest/transport/transport_client.d.ts +60 -0
- package/dest/transport/transport_client.d.ts.map +1 -0
- package/dest/transport/transport_client.js +96 -0
- package/dest/transport/transport_server.d.ts +47 -0
- package/dest/transport/transport_server.d.ts.map +1 -0
- package/dest/transport/transport_server.js +114 -0
- 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_root.js +50 -0
- package/dest/trees/hasher.d.ts +40 -0
- package/dest/trees/hasher.d.ts.map +1 -0
- package/dest/trees/hasher.js +10 -0
- package/dest/trees/index.d.ts +13 -0
- package/dest/trees/index.d.ts.map +1 -0
- package/dest/trees/index.js +12 -0
- package/dest/trees/indexed_merkle_tree.d.ts +11 -0
- package/dest/trees/indexed_merkle_tree.d.ts.map +1 -0
- package/dest/trees/indexed_merkle_tree.js +27 -0
- package/dest/trees/indexed_merkle_tree_calculator.d.ts +21 -0
- package/dest/trees/indexed_merkle_tree_calculator.d.ts.map +1 -0
- package/dest/trees/indexed_merkle_tree_calculator.js +87 -0
- package/dest/trees/indexed_tree_leaf.d.ts +55 -0
- package/dest/trees/indexed_tree_leaf.d.ts.map +1 -0
- package/dest/trees/indexed_tree_leaf.js +5 -0
- package/dest/trees/membership_witness.d.ts +63 -0
- package/dest/trees/membership_witness.d.ts.map +1 -0
- package/dest/trees/membership_witness.js +83 -0
- package/dest/trees/merkle_tree.d.ts +16 -0
- package/dest/trees/merkle_tree.d.ts.map +1 -0
- package/dest/trees/merkle_tree.js +58 -0
- package/dest/trees/merkle_tree_calculator.d.ts +16 -0
- package/dest/trees/merkle_tree_calculator.d.ts.map +1 -0
- package/dest/trees/merkle_tree_calculator.js +57 -0
- package/dest/trees/sibling_path.d.ts +96 -0
- package/dest/trees/sibling_path.d.ts.map +1 -0
- package/dest/trees/sibling_path.js +139 -0
- package/dest/trees/unbalanced_merkle_tree_calculator.d.ts +48 -0
- package/dest/trees/unbalanced_merkle_tree_calculator.d.ts.map +1 -0
- package/dest/trees/unbalanced_merkle_tree_calculator.js +154 -0
- package/dest/trees/unbalanced_merkle_tree_root.d.ts +27 -0
- package/dest/trees/unbalanced_merkle_tree_root.d.ts.map +1 -0
- package/dest/trees/unbalanced_merkle_tree_root.js +83 -0
- package/dest/trees/unbalanced_tree_store.d.ts +24 -0
- package/dest/trees/unbalanced_tree_store.d.ts.map +1 -0
- package/dest/trees/unbalanced_tree_store.js +148 -0
- package/dest/types/index.d.ts +68 -0
- package/dest/types/index.d.ts.map +1 -0
- package/dest/types/index.js +24 -0
- package/dest/url/index.d.ts +9 -0
- package/dest/url/index.d.ts.map +1 -0
- package/dest/url/index.js +62 -0
- package/dest/validation/index.d.ts +9 -0
- package/dest/validation/index.d.ts.map +1 -0
- package/dest/validation/index.js +15 -0
- package/package.json +213 -0
- package/src/array/array.ts +147 -0
- package/src/array/index.ts +2 -0
- package/src/array/sorted_array.ts +138 -0
- package/src/async-map/index.ts +18 -0
- package/src/async-pool/index.ts +51 -0
- package/src/bigint/index.ts +20 -0
- package/src/bigint-buffer/index.ts +92 -0
- package/src/branded-types/block_number.ts +135 -0
- package/src/branded-types/buffer32_hash.ts +38 -0
- package/src/branded-types/checkpoint_number.ts +130 -0
- package/src/branded-types/epoch.ts +88 -0
- package/src/branded-types/index.ts +8 -0
- package/src/branded-types/index_within_checkpoint.ts +88 -0
- package/src/branded-types/slot.ts +93 -0
- package/src/branded-types/types.ts +2 -0
- package/src/buffer/buffer16.ts +135 -0
- package/src/buffer/buffer32.ts +116 -0
- package/src/buffer/index.ts +3 -0
- package/src/buffer/utils.ts +8 -0
- package/src/collection/array.ts +351 -0
- package/src/collection/index.ts +4 -0
- package/src/collection/lru_map.ts +143 -0
- package/src/collection/lru_set.ts +115 -0
- package/src/collection/object.ts +89 -0
- package/src/committable/committable.ts +46 -0
- package/src/committable/index.ts +1 -0
- package/src/config/env_var.ts +412 -0
- package/src/config/index.ts +419 -0
- package/src/config/network_config.ts +21 -0
- package/src/config/network_name.ts +28 -0
- package/src/config/parse-env.ts +4 -0
- package/src/config/secret_value.ts +49 -0
- package/src/crypto/aes128/index.ts +77 -0
- package/src/crypto/bls/bn254_keystore.ts +276 -0
- package/src/crypto/bls/index.ts +76 -0
- package/src/crypto/bn254/index.ts +64 -0
- package/src/crypto/ecdsa/index.ts +88 -0
- package/src/crypto/ecdsa/signature.ts +100 -0
- package/src/crypto/grumpkin/index.ts +90 -0
- package/src/crypto/keccak/index.ts +283 -0
- package/src/crypto/keys/index.ts +26 -0
- package/src/crypto/pedersen/index.ts +1 -0
- package/src/crypto/pedersen/pedersen.noble.ts +573 -0
- package/src/crypto/pedersen/pedersen.wasm.ts +52 -0
- package/src/crypto/poseidon/index.ts +83 -0
- package/src/crypto/random/index.ts +47 -0
- package/src/crypto/random/randomness_singleton.ts +64 -0
- package/src/crypto/schnorr/index.ts +61 -0
- package/src/crypto/schnorr/signature.ts +87 -0
- package/src/crypto/secp256k1/index.ts +61 -0
- package/src/crypto/secp256k1-signer/index.ts +2 -0
- package/src/crypto/secp256k1-signer/secp256k1_signer.ts +38 -0
- package/src/crypto/secp256k1-signer/utils.ts +244 -0
- package/src/crypto/sha256/index.ts +194 -0
- package/src/crypto/sha512/index.ts +16 -0
- package/src/crypto/signature/index.ts +17 -0
- package/src/crypto/sync/index.ts +6 -0
- package/src/crypto/sync/pedersen/index.ts +46 -0
- package/src/crypto/sync/poseidon/index.ts +72 -0
- package/src/curves/bls12/field.ts +456 -0
- package/src/curves/bls12/index.ts +2 -0
- package/src/curves/bls12/point.ts +450 -0
- package/src/curves/bn254/field.ts +531 -0
- 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/curves/grumpkin/point.ts +300 -0
- package/src/decorators/index.ts +1 -0
- package/src/decorators/memoize.ts +11 -0
- package/src/error/index.ts +22 -0
- package/src/eth-address/index.ts +269 -0
- package/src/eth-signature/eth_signature.ts +155 -0
- package/src/eth-signature/index.ts +1 -0
- package/src/fifo/fifo_frame_reader.ts +113 -0
- package/src/fifo/index.ts +1 -0
- package/src/fifo_set/fifo_set.ts +52 -0
- package/src/fifo_set/index.ts +1 -0
- package/src/fs/index.ts +2 -0
- package/src/fs/run_in_dir.ts +33 -0
- package/src/fs/try_rm_dir.ts +15 -0
- package/src/iterable/all.ts +32 -0
- package/src/iterable/filter.ts +77 -0
- package/src/iterable/first.ts +14 -0
- package/src/iterable/index.ts +8 -0
- package/src/iterable/isAsyncIt.ts +8 -0
- package/src/iterable/map.ts +66 -0
- package/src/iterable/peek.ts +58 -0
- package/src/iterable/sort.ts +39 -0
- package/src/iterable/take.ts +54 -0
- package/src/iterable/toArray.ts +9 -0
- package/src/iterator/filter.ts +11 -0
- package/src/iterator/index.ts +1 -0
- package/src/jest/env.mjs +52 -0
- package/src/jest/setup.mjs +38 -0
- package/src/jest/setupAfterEnv.mjs +3 -0
- package/src/json-rpc/README.md +55 -0
- package/src/json-rpc/client/fetch.ts +98 -0
- package/src/json-rpc/client/index.ts +2 -0
- package/src/json-rpc/client/safe_json_rpc_client.ts +283 -0
- package/src/json-rpc/client/undici.ts +128 -0
- package/src/json-rpc/convert.ts +52 -0
- package/src/json-rpc/errors.ts +6 -0
- package/src/json-rpc/fixtures/class_a.ts +18 -0
- package/src/json-rpc/fixtures/class_b.ts +18 -0
- package/src/json-rpc/fixtures/test_state.ts +143 -0
- package/src/json-rpc/index.ts +2 -0
- package/src/json-rpc/js_utils.ts +21 -0
- package/src/json-rpc/server/api_key_auth.ts +63 -0
- package/src/json-rpc/server/index.ts +2 -0
- package/src/json-rpc/server/safe_json_rpc_server.ts +626 -0
- package/src/json-rpc/test/index.ts +1 -0
- package/src/json-rpc/test/integration.ts +35 -0
- package/src/log/aws-logger-config.ts +32 -0
- package/src/log/bigint-utils.ts +25 -0
- package/src/log/console.ts +42 -0
- package/src/log/gcloud-logger-config.ts +72 -0
- package/src/log/index.ts +6 -0
- package/src/log/libp2p_logger.ts +93 -0
- package/src/log/log-filters.ts +81 -0
- package/src/log/log-levels.ts +3 -0
- package/src/log/log_fn.ts +5 -0
- package/src/log/noir_debug_log_util.ts +21 -0
- package/src/log/pino-logger-server.ts +25 -0
- package/src/log/pino-logger.ts +406 -0
- package/src/message/index.ts +47 -0
- package/src/mutex/index.ts +84 -0
- package/src/mutex/mutex_database.ts +11 -0
- package/src/noir/index.ts +1 -0
- package/src/noir/noir_package_config.ts +66 -0
- package/src/number/index.ts +14 -0
- package/src/profiler/index.ts +1 -0
- package/src/profiler/profiler.ts +125 -0
- package/src/promise/index.ts +2 -0
- package/src/promise/running-promise.ts +138 -0
- package/src/promise/utils.ts +60 -0
- package/src/queue/base_memory_queue.ts +138 -0
- package/src/queue/batch_queue.ts +121 -0
- package/src/queue/bounded_serial_queue.ts +103 -0
- package/src/queue/fifo_memory_queue.ts +39 -0
- package/src/queue/index.ts +6 -0
- package/src/queue/priority_memory_queue.ts +20 -0
- package/src/queue/priority_queue.ts +34 -0
- package/src/queue/semaphore.ts +38 -0
- package/src/queue/serial_queue.ts +86 -0
- package/src/retry/index.ts +185 -0
- package/src/running-promise/index.ts +1 -0
- package/src/schemas/api.ts +47 -0
- package/src/schemas/index.ts +5 -0
- package/src/schemas/parse.ts +32 -0
- package/src/schemas/schemas.ts +93 -0
- package/src/schemas/types.ts +36 -0
- package/src/schemas/utils.ts +91 -0
- package/src/serialize/buffer_reader.ts +472 -0
- package/src/serialize/buffer_sink.ts +350 -0
- package/src/serialize/field_reader.ts +208 -0
- package/src/serialize/free_funcs.ts +198 -0
- package/src/serialize/index.ts +7 -0
- package/src/serialize/serialize.ts +320 -0
- package/src/serialize/type_registry.ts +75 -0
- package/src/serialize/types.ts +40 -0
- package/src/sleep/index.ts +90 -0
- package/src/string/index.ts +80 -0
- package/src/testing/files/index.ts +74 -0
- package/src/testing/formatting.ts +3 -0
- package/src/testing/index.ts +4 -0
- package/src/testing/port_allocator.ts +31 -0
- package/src/testing/snapshot_serializer.ts +33 -0
- package/src/testing/test_data.ts +36 -0
- package/src/timer/date.ts +82 -0
- package/src/timer/elapsed.ts +23 -0
- package/src/timer/index.ts +4 -0
- package/src/timer/timeout.ts +136 -0
- package/src/timer/timer.ts +48 -0
- package/src/transport/dispatch/create_dispatch_proxy.ts +151 -0
- package/src/transport/dispatch/messages.ts +58 -0
- package/src/transport/index.ts +9 -0
- package/src/transport/interface/connector.ts +8 -0
- package/src/transport/interface/listener.ts +15 -0
- package/src/transport/interface/socket.ts +14 -0
- package/src/transport/interface/transferable.ts +125 -0
- package/src/transport/node/index.ts +2 -0
- package/src/transport/node/node_connector.ts +30 -0
- package/src/transport/node/node_connector_socket.ts +52 -0
- package/src/transport/node/node_listener.ts +34 -0
- package/src/transport/node/node_listener_socket.ts +48 -0
- package/src/transport/transport_client.ts +130 -0
- package/src/transport/transport_server.ts +111 -0
- package/src/trees/balanced_merkle_tree_root.ts +65 -0
- package/src/trees/hasher.ts +51 -0
- package/src/trees/index.ts +12 -0
- package/src/trees/indexed_merkle_tree.ts +40 -0
- package/src/trees/indexed_merkle_tree_calculator.ts +98 -0
- package/src/trees/indexed_tree_leaf.ts +56 -0
- package/src/trees/membership_witness.ts +112 -0
- package/src/trees/merkle_tree.ts +75 -0
- package/src/trees/merkle_tree_calculator.ts +66 -0
- package/src/trees/sibling_path.ts +177 -0
- package/src/trees/unbalanced_merkle_tree_calculator.ts +176 -0
- package/src/trees/unbalanced_merkle_tree_root.ts +112 -0
- package/src/trees/unbalanced_tree_store.ts +161 -0
- package/src/types/index.ts +103 -0
- package/src/url/index.ts +72 -0
- package/src/validation/index.ts +18 -0
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
import { toBigIntBE, toBufferBE } from '../bigint-buffer/index.js';
|
|
2
|
+
import { Fr } from '../curves/bn254/field.js';
|
|
3
|
+
import { numToUInt32BE } from './free_funcs.js';
|
|
4
|
+
/**
|
|
5
|
+
* For serializing an array of fixed length buffers.
|
|
6
|
+
* @param arr - Array of bufferable.
|
|
7
|
+
* @param prefixLength - The length of the prefix (denominated in bytes).
|
|
8
|
+
* @returns The serialized buffers.
|
|
9
|
+
*/ export function serializeArrayOfBufferableToVector(objs, prefixLength = 4) {
|
|
10
|
+
const arr = serializeToBufferArray(objs);
|
|
11
|
+
let lengthBuf;
|
|
12
|
+
if (prefixLength === 1) {
|
|
13
|
+
lengthBuf = Buffer.alloc(1);
|
|
14
|
+
lengthBuf.writeUInt8(arr.length, 0);
|
|
15
|
+
} else if (prefixLength === 4) {
|
|
16
|
+
lengthBuf = Buffer.alloc(4);
|
|
17
|
+
lengthBuf.writeUInt32BE(arr.length, 0);
|
|
18
|
+
} else {
|
|
19
|
+
throw new Error(`Unsupported prefix length. Got ${prefixLength}, expected 1 or 4`);
|
|
20
|
+
}
|
|
21
|
+
return Buffer.concat([
|
|
22
|
+
lengthBuf,
|
|
23
|
+
...arr
|
|
24
|
+
]);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Cast a uint8 array to a number.
|
|
28
|
+
* @param array - The uint8 array.
|
|
29
|
+
* @returns The number.
|
|
30
|
+
*/ export function uint8ArrayToNum(array) {
|
|
31
|
+
const buf = Buffer.from(array);
|
|
32
|
+
return buf.readUint32LE();
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Serializes a boolean to a buffer.
|
|
36
|
+
* @param value - Value to serialize.
|
|
37
|
+
* @returns The serialized boolean.
|
|
38
|
+
*/ export function boolToBuffer(value, bufferSize = 1) {
|
|
39
|
+
const buf = Buffer.alloc(bufferSize);
|
|
40
|
+
buf.writeUInt8(value ? 1 : 0, bufferSize - 1);
|
|
41
|
+
return buf;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Deserialize the 256-bit number at address `offset`.
|
|
45
|
+
* @param buf - The buffer.
|
|
46
|
+
* @param offset - The address.
|
|
47
|
+
* @returns The deserialized 256-bit field.
|
|
48
|
+
*/ export function deserializeField(buf, offset = 0) {
|
|
49
|
+
const adv = 32;
|
|
50
|
+
return {
|
|
51
|
+
elem: buf.slice(offset, offset + adv),
|
|
52
|
+
adv
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Serializes a list of objects contiguously.
|
|
57
|
+
* @param objs - Objects to serialize.
|
|
58
|
+
* @returns A buffer list with the concatenation of all fields.
|
|
59
|
+
*/ export function serializeToBufferArray(...objs) {
|
|
60
|
+
const ret = [];
|
|
61
|
+
for (const obj of objs){
|
|
62
|
+
if (Array.isArray(obj)) {
|
|
63
|
+
ret.push(...serializeToBufferArray(...obj));
|
|
64
|
+
} else if (Buffer.isBuffer(obj)) {
|
|
65
|
+
ret.push(obj);
|
|
66
|
+
} else if (typeof obj === 'boolean') {
|
|
67
|
+
ret.push(boolToBuffer(obj));
|
|
68
|
+
} else if (typeof obj === 'bigint') {
|
|
69
|
+
// Throw if bigint does not fit into 32 bytes
|
|
70
|
+
if (obj > BigInt('0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff')) {
|
|
71
|
+
throw new Error(`BigInt ${obj} does not fit into 32 bytes`);
|
|
72
|
+
}
|
|
73
|
+
ret.push(serializeBigInt(obj));
|
|
74
|
+
} else if (typeof obj === 'number') {
|
|
75
|
+
// Note: barretenberg assumes everything is big-endian
|
|
76
|
+
ret.push(numToUInt32BE(obj)); // TODO: Are we always passing numbers as UInt32?
|
|
77
|
+
} else if (typeof obj === 'string') {
|
|
78
|
+
ret.push(numToUInt32BE(obj.length));
|
|
79
|
+
ret.push(Buffer.from(obj));
|
|
80
|
+
} else if ('toBuffer' in obj) {
|
|
81
|
+
ret.push(obj.toBuffer());
|
|
82
|
+
} else {
|
|
83
|
+
throw new Error(`Cannot serialize input to buffer: ${typeof obj} ${obj.constructor?.name}`);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return ret;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Serializes a list of objects contiguously.
|
|
90
|
+
* @param objs - Objects to serialize.
|
|
91
|
+
* @returns An array of fields with the concatenation of all fields.
|
|
92
|
+
*/ export function serializeToFields(...objs) {
|
|
93
|
+
const ret = [];
|
|
94
|
+
for (const obj of objs){
|
|
95
|
+
if (Array.isArray(obj)) {
|
|
96
|
+
ret.push(...serializeToFields(...obj));
|
|
97
|
+
} else if (obj instanceof Fr) {
|
|
98
|
+
ret.push(obj);
|
|
99
|
+
} else if (typeof obj === 'boolean' || typeof obj === 'number' || typeof obj === 'bigint') {
|
|
100
|
+
ret.push(new Fr(obj));
|
|
101
|
+
} else if ('toFields' in obj) {
|
|
102
|
+
ret.push(...obj.toFields());
|
|
103
|
+
} else if ('toFr' in obj) {
|
|
104
|
+
ret.push(obj.toFr());
|
|
105
|
+
} else if ('toField' in obj) {
|
|
106
|
+
ret.push(obj.toField());
|
|
107
|
+
} else if (Buffer.isBuffer(obj)) {
|
|
108
|
+
ret.push(Fr.fromBuffer(obj));
|
|
109
|
+
} else {
|
|
110
|
+
throw new Error(`Cannot serialize input to field: ${typeof obj} ${obj.constructor?.name}`);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return ret;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Serializes a list of objects contiguously.
|
|
117
|
+
* @param objs - Objects to serialize.
|
|
118
|
+
* @returns A single buffer with the concatenation of all fields.
|
|
119
|
+
*/ export function serializeToBuffer(...objs) {
|
|
120
|
+
return Buffer.concat(serializeToBufferArray(...objs));
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Returns a user-friendly JSON representation of an object, showing buffers as hex strings.
|
|
124
|
+
* @param obj - Object to json-stringify.
|
|
125
|
+
* @returns A JSON string.
|
|
126
|
+
*/ export function toFriendlyJSON(obj) {
|
|
127
|
+
return JSON.stringify(obj, (key, value)=>{
|
|
128
|
+
if (value !== null && typeof value === 'object' && value.type === 'Buffer' && Array.isArray(value.data)) {
|
|
129
|
+
return '0x' + Buffer.from(value.data).toString('hex');
|
|
130
|
+
} else if (typeof value === 'bigint') {
|
|
131
|
+
return value.toString();
|
|
132
|
+
} else if (value && value.toFriendlyJSON) {
|
|
133
|
+
return value.toFriendlyJSON();
|
|
134
|
+
} else if (value && value.type && [
|
|
135
|
+
'Fr',
|
|
136
|
+
'Fq',
|
|
137
|
+
'AztecAddress',
|
|
138
|
+
'EthAddress'
|
|
139
|
+
].includes(value.type)) {
|
|
140
|
+
return value.value;
|
|
141
|
+
} else {
|
|
142
|
+
return value;
|
|
143
|
+
}
|
|
144
|
+
}, 2);
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Serialize a BigInt value into a Buffer of specified width.
|
|
148
|
+
* The function converts the input BigInt into its big-endian representation and stores it in a Buffer of the given width.
|
|
149
|
+
* If the width is not provided, a default value of 32 bytes will be used. It is important to provide an appropriate width
|
|
150
|
+
* to avoid truncation or incorrect serialization of large BigInt values.
|
|
151
|
+
*
|
|
152
|
+
* @param n - The BigInt value to be serialized.
|
|
153
|
+
* @param width - The width (in bytes) of the output Buffer, optional with default value 32.
|
|
154
|
+
* @returns A Buffer containing the serialized BigInt value in big-endian format.
|
|
155
|
+
*/ export function serializeBigInt(n, width = 32) {
|
|
156
|
+
return toBufferBE(n, width);
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Serialize a signed BigInt value into a Buffer of specified width using two's complement.
|
|
160
|
+
* @param n - The signed BigInt value to be serialized.
|
|
161
|
+
* @param width - The width (in bytes) of the output Buffer, optional with default value 32.
|
|
162
|
+
* @returns A Buffer containing the serialized signed BigInt value in big-endian format.
|
|
163
|
+
*/ export function serializeSignedBigInt(n, width = 32) {
|
|
164
|
+
const widthBits = BigInt(width * 8);
|
|
165
|
+
const max = 1n << widthBits - 1n;
|
|
166
|
+
if (n < -max || n >= max) {
|
|
167
|
+
throw new Error(`Signed BigInt ${n.toString()} does not fit into ${width} bytes`);
|
|
168
|
+
}
|
|
169
|
+
const unsigned = n < 0n ? (1n << widthBits) + n : n;
|
|
170
|
+
return toBufferBE(unsigned, width);
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Deserialize a big integer from a buffer, given an offset and width.
|
|
174
|
+
* 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).
|
|
175
|
+
*
|
|
176
|
+
* @param buf - The buffer containing the big integer to be deserialized.
|
|
177
|
+
* @param offset - The position in the buffer where the big integer starts. Defaults to 0.
|
|
178
|
+
* @param width - The number of bytes to read from the buffer for the big integer. Defaults to 32.
|
|
179
|
+
* @returns An object containing the deserialized big integer value ('elem') and the number of bytes advanced ('adv').
|
|
180
|
+
*/ export function deserializeBigInt(buf, offset = 0, width = 32) {
|
|
181
|
+
return {
|
|
182
|
+
elem: toBigIntBE(buf.subarray(offset, offset + width)),
|
|
183
|
+
adv: width
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Deserialize a signed BigInt from a buffer (two's complement).
|
|
188
|
+
* @param buf - The buffer containing the signed big integer to be deserialized.
|
|
189
|
+
* @param offset - The position in the buffer where the integer starts. Defaults to 0.
|
|
190
|
+
* @param width - The number of bytes to read from the buffer for the integer. Defaults to 32.
|
|
191
|
+
* @returns An object containing the deserialized signed bigint value ('elem') and bytes advanced ('adv').
|
|
192
|
+
*/ export function deserializeSignedBigInt(buf, offset = 0, width = 32) {
|
|
193
|
+
const { elem, adv } = deserializeBigInt(buf, offset, width);
|
|
194
|
+
const widthBits = BigInt(width * 8);
|
|
195
|
+
const signBit = 1n << widthBits - 1n;
|
|
196
|
+
const fullRange = 1n << widthBits;
|
|
197
|
+
const signed = elem >= signBit ? elem - fullRange : elem;
|
|
198
|
+
return {
|
|
199
|
+
elem: signed,
|
|
200
|
+
adv
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Serializes a Date object into a Buffer containing its timestamp as a big integer value.
|
|
205
|
+
* The resulting Buffer has a fixed width of 8 bytes, representing a 64-bit big-endian integer.
|
|
206
|
+
* This function is useful for converting date values into a binary format that can be stored or transmitted easily.
|
|
207
|
+
*
|
|
208
|
+
* @param date - The Date object to be serialized.
|
|
209
|
+
* @returns A Buffer containing the serialized timestamp of the input Date object.
|
|
210
|
+
*/ export function serializeDate(date) {
|
|
211
|
+
return serializeBigInt(BigInt(date.getTime()), 8);
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Deserialize a boolean value from a given buffer at the specified offset.
|
|
215
|
+
* Reads a single byte at the provided offset in the buffer and returns
|
|
216
|
+
* the deserialized boolean value along with the number of bytes read (adv).
|
|
217
|
+
*
|
|
218
|
+
* @param buf - The buffer containing the serialized boolean value.
|
|
219
|
+
* @param offset - The position in the buffer to start reading the boolean value.
|
|
220
|
+
* @returns An object containing the deserialized boolean value (elem) and the number of bytes read (adv).
|
|
221
|
+
*/ export function deserializeBool(buf, offset = 0) {
|
|
222
|
+
const adv = 1;
|
|
223
|
+
return {
|
|
224
|
+
elem: buf.readUInt8(offset),
|
|
225
|
+
adv
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Deserialize a 4-byte unsigned integer from a buffer, starting at the specified offset.
|
|
230
|
+
* The deserialization reads 4 bytes from the given buffer and converts it into a number.
|
|
231
|
+
* Returns an object containing the deserialized unsigned integer and the number of bytes advanced (4).
|
|
232
|
+
*
|
|
233
|
+
* @param buf - The buffer containing the serialized unsigned integer.
|
|
234
|
+
* @param offset - The starting position in the buffer to deserialize from (default is 0).
|
|
235
|
+
* @returns An object with the deserialized unsigned integer as 'elem' and the number of bytes advanced ('adv') as 4.
|
|
236
|
+
*/ export function deserializeUInt32(buf, offset = 0) {
|
|
237
|
+
const adv = 4;
|
|
238
|
+
return {
|
|
239
|
+
elem: buf.readUInt32BE(offset),
|
|
240
|
+
adv
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Deserialize a signed 32-bit integer from a buffer at the given offset.
|
|
245
|
+
* The input 'buf' should be a Buffer containing binary data, and 'offset' should be the position in the buffer
|
|
246
|
+
* where the signed 32-bit integer starts. Returns an object with both the deserialized integer (elem) and the
|
|
247
|
+
* number of bytes advanced in the buffer (adv, always equal to 4).
|
|
248
|
+
*
|
|
249
|
+
* @param buf - The buffer containing the binary data.
|
|
250
|
+
* @param offset - Optional, the position in the buffer where the signed 32-bit integer starts (default is 0).
|
|
251
|
+
* @returns An object with the deserialized integer as 'elem' and the number of bytes advanced as 'adv'.
|
|
252
|
+
*/ export function deserializeInt32(buf, offset = 0) {
|
|
253
|
+
const adv = 4;
|
|
254
|
+
return {
|
|
255
|
+
elem: buf.readInt32BE(offset),
|
|
256
|
+
adv
|
|
257
|
+
};
|
|
258
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
type Deserializable = {
|
|
2
|
+
fromString(str: string): object;
|
|
3
|
+
};
|
|
4
|
+
/**
|
|
5
|
+
* Register a class here that has a toJSON method that returns:
|
|
6
|
+
* ```
|
|
7
|
+
* {
|
|
8
|
+
* "type": "ExampleClassName",
|
|
9
|
+
* "value": <result of ExampleClassName.toString()>
|
|
10
|
+
* }
|
|
11
|
+
* ```
|
|
12
|
+
* and has an e.g. ExampleClassName.fromString(string) method.
|
|
13
|
+
* This means you can then easily serialize/deserialize the type using JSON.stringify and JSON.parse.
|
|
14
|
+
*/
|
|
15
|
+
export declare class TypeRegistry {
|
|
16
|
+
private static registry;
|
|
17
|
+
static register(typeName: string, constructor: Deserializable): void;
|
|
18
|
+
static getConstructor(typeName: string): Deserializable | undefined;
|
|
19
|
+
}
|
|
20
|
+
export declare function resolver(_: any, value: any): any;
|
|
21
|
+
export declare function reviver(key: string, value: any): any;
|
|
22
|
+
export {};
|
|
23
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHlwZV9yZWdpc3RyeS5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL3NlcmlhbGl6ZS90eXBlX3JlZ2lzdHJ5LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUVBLEtBQUssY0FBYyxHQUFHO0lBQUUsVUFBVSxDQUFDLEdBQUcsRUFBRSxNQUFNLEdBQUcsTUFBTSxDQUFBO0NBQUUsQ0FBQztBQUUxRDs7Ozs7Ozs7OztHQVVHO0FBQ0gscUJBQWEsWUFBWTtJQUN2QixPQUFPLENBQUMsTUFBTSxDQUFDLFFBQVEsQ0FBMEM7SUFFakUsT0FBYyxRQUFRLENBQUMsUUFBUSxFQUFFLE1BQU0sRUFBRSxXQUFXLEVBQUUsY0FBYyxHQUFHLElBQUksQ0FFMUU7SUFFRCxPQUFjLGNBQWMsQ0FBQyxRQUFRLEVBQUUsTUFBTSxHQUFHLGNBQWMsR0FBRyxTQUFTLENBRXpFO0NBQ0Y7QUFtQkQsd0JBQWdCLFFBQVEsQ0FBQyxDQUFDLEVBQUUsR0FBRyxFQUFFLEtBQUssRUFBRSxHQUFHLE9BZ0IxQztBQUdELHdCQUFnQixPQUFPLENBQUMsR0FBRyxFQUFFLE1BQU0sRUFBRSxLQUFLLEVBQUUsR0FBRyxPQVc5QyJ9
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type_registry.d.ts","sourceRoot":"","sources":["../../src/serialize/type_registry.ts"],"names":[],"mappings":"AAEA,KAAK,cAAc,GAAG;IAAE,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,CAAC;AAE1D;;;;;;;;;;GAUG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAA0C;IAEjE,OAAc,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,cAAc,GAAG,IAAI,CAE1E;IAED,OAAc,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,cAAc,GAAG,SAAS,CAEzE;CACF;AAmBD,wBAAgB,QAAQ,CAAC,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,OAgB1C;AAGD,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,OAW9C"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { mapValues } from '../collection/object.js';
|
|
2
|
+
/**
|
|
3
|
+
* Register a class here that has a toJSON method that returns:
|
|
4
|
+
* ```
|
|
5
|
+
* {
|
|
6
|
+
* "type": "ExampleClassName",
|
|
7
|
+
* "value": <result of ExampleClassName.toString()>
|
|
8
|
+
* }
|
|
9
|
+
* ```
|
|
10
|
+
* and has an e.g. ExampleClassName.fromString(string) method.
|
|
11
|
+
* This means you can then easily serialize/deserialize the type using JSON.stringify and JSON.parse.
|
|
12
|
+
*/ export class TypeRegistry {
|
|
13
|
+
static registry = new Map();
|
|
14
|
+
static register(typeName, constructor) {
|
|
15
|
+
this.registry.set(typeName, constructor);
|
|
16
|
+
}
|
|
17
|
+
static getConstructor(typeName) {
|
|
18
|
+
return this.registry.get(typeName);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
function replace(value) {
|
|
22
|
+
if (value && typeof value === 'object' && 'toString' in value && TypeRegistry.getConstructor(value.constructor.name)) {
|
|
23
|
+
return {
|
|
24
|
+
type: value.constructor.name,
|
|
25
|
+
value: value.toString()
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
return value;
|
|
29
|
+
}
|
|
30
|
+
// Resolver function that enables JSON serialization of BigInts.
|
|
31
|
+
export function resolver(_, value) {
|
|
32
|
+
if (typeof value === 'bigint') {
|
|
33
|
+
return value.toString() + 'n';
|
|
34
|
+
}
|
|
35
|
+
if (typeof value === 'object' && value) {
|
|
36
|
+
if (Array.isArray(value)) {
|
|
37
|
+
return value.map(replace);
|
|
38
|
+
} else if (Buffer.isBuffer(value)) {
|
|
39
|
+
return {
|
|
40
|
+
type: 'buffer',
|
|
41
|
+
value: value.toString('hex')
|
|
42
|
+
};
|
|
43
|
+
} else {
|
|
44
|
+
return mapValues(value, replace);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return value;
|
|
48
|
+
}
|
|
49
|
+
// Reviver function that uses TypeRegistry to instantiate objects.
|
|
50
|
+
export function reviver(key, value) {
|
|
51
|
+
if (typeof value === 'string' && /^\d+n$/.test(value)) {
|
|
52
|
+
return BigInt(value.slice(0, -1));
|
|
53
|
+
}
|
|
54
|
+
if (value && typeof value === 'object' && 'type' in value && 'value' in value) {
|
|
55
|
+
const Constructor = TypeRegistry.getConstructor(value.type);
|
|
56
|
+
if (Constructor) {
|
|
57
|
+
return Constructor.fromString(value.value);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return value;
|
|
61
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents a fixed-length array.
|
|
3
|
+
*/
|
|
4
|
+
export type Tuple<T, N extends number> = N extends N ? (number extends N ? T[] : _Tuple<T, N, []>) : never;
|
|
5
|
+
/**
|
|
6
|
+
* Recursive type helper for constructing a fixed-length tuple of a given type.
|
|
7
|
+
* This is utilized internally by Tuple to create the final fixed-length tuple.
|
|
8
|
+
*/
|
|
9
|
+
type _Tuple<T, N extends number, R extends unknown[]> = R['length'] extends N ? R : _Tuple<T, N, [T, ...R]>;
|
|
10
|
+
/**
|
|
11
|
+
* Check an array size, and cast it to a tuple.
|
|
12
|
+
* @param array - The array.
|
|
13
|
+
* @param n - The size.
|
|
14
|
+
* @returns The case tuple, or throws Error.
|
|
15
|
+
*/
|
|
16
|
+
export declare function assertLength<T, N extends number>(array: T[], n: N): Tuple<T, N>;
|
|
17
|
+
/**
|
|
18
|
+
* Annoying, mapping a tuple does not preserve length.
|
|
19
|
+
* This is a helper to preserve length during a map operation.
|
|
20
|
+
* @typeparam T - The original array type.
|
|
21
|
+
*/
|
|
22
|
+
type MapTuple<T extends any[], F extends (item: any) => any> = {
|
|
23
|
+
[K in keyof T]: T[K] extends infer U ? (F extends (item: U) => infer V ? V : never) : never;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Annoyingly, mapping a tuple does not preserve length.
|
|
27
|
+
* This is a helper to preserve length during a map operation.
|
|
28
|
+
* @see https://github.com/microsoft/TypeScript/issues/29841.
|
|
29
|
+
* @param array - A tuple array.
|
|
30
|
+
*/
|
|
31
|
+
export declare function mapTuple<T extends any[], F extends (item: T[number]) => any>(tuple: T, fn: F): MapTuple<T, F>;
|
|
32
|
+
export {};
|
|
33
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHlwZXMuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9zZXJpYWxpemUvdHlwZXMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7O0dBRUc7QUFDSCxNQUFNLE1BQU0sS0FBSyxDQUFDLENBQUMsRUFBRSxDQUFDLFNBQVMsTUFBTSxJQUFJLENBQUMsU0FBUyxDQUFDLEdBQUcsQ0FBQyxNQUFNLFNBQVMsQ0FBQyxHQUFHLENBQUMsRUFBRSxHQUFHLE1BQU0sQ0FBQyxDQUFDLEVBQUUsQ0FBQyxFQUFFLEVBQUUsQ0FBQyxDQUFDLEdBQUcsS0FBSyxDQUFDO0FBQzNHOzs7R0FHRztBQUNILEtBQUssTUFBTSxDQUFDLENBQUMsRUFBRSxDQUFDLFNBQVMsTUFBTSxFQUFFLENBQUMsU0FBUyxP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CAAC,CAAC,EAAE,CAAC,CAAC,CAE7G"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents a fixed-length array.
|
|
3
|
+
*/ /**
|
|
4
|
+
* Check an array size, and cast it to a tuple.
|
|
5
|
+
* @param array - The array.
|
|
6
|
+
* @param n - The size.
|
|
7
|
+
* @returns The case tuple, or throws Error.
|
|
8
|
+
*/ export function assertLength(array, n) {
|
|
9
|
+
if (array.length !== n) {
|
|
10
|
+
throw new Error(`Wrong 'fixed array' size. Expected ${n}, got ${array.length}.`);
|
|
11
|
+
}
|
|
12
|
+
return array;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Annoyingly, mapping a tuple does not preserve length.
|
|
16
|
+
* This is a helper to preserve length during a map operation.
|
|
17
|
+
* @see https://github.com/microsoft/TypeScript/issues/29841.
|
|
18
|
+
* @param array - A tuple array.
|
|
19
|
+
*/ export function mapTuple(tuple, fn) {
|
|
20
|
+
return tuple.map(fn);
|
|
21
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* InterruptibleSleep is a utility class that allows you to create an interruptible sleep function.
|
|
3
|
+
* The sleep function can be interrupted at any time by calling the `interrupt` method, which can
|
|
4
|
+
* also specify whether the sleep should throw an error or just return. This is useful when you need
|
|
5
|
+
* to terminate long-running processes or perform cleanup tasks in response to external events.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* const sleeper = new InterruptibleSleep();
|
|
9
|
+
*
|
|
10
|
+
* async function longRunningTask() \{
|
|
11
|
+
* try \{
|
|
12
|
+
* await sleeper.sleep(3000);
|
|
13
|
+
* console.log('Task completed after 3 seconds');
|
|
14
|
+
* \} catch (e) \{
|
|
15
|
+
* console.log('Task was interrupted');
|
|
16
|
+
* \}
|
|
17
|
+
* \}
|
|
18
|
+
*
|
|
19
|
+
* setTimeout(() =\> sleeper.interrupt(true), 1500); // Interrupt the sleep after 1.5 seconds
|
|
20
|
+
*/
|
|
21
|
+
export declare class InterruptibleSleep {
|
|
22
|
+
private interrupts;
|
|
23
|
+
private timeoutIds;
|
|
24
|
+
/**
|
|
25
|
+
* Sleep for a specified amount of time in milliseconds.
|
|
26
|
+
* The sleep function will pause the execution of the current async function
|
|
27
|
+
* for the given time period, allowing other tasks to run before resuming.
|
|
28
|
+
*
|
|
29
|
+
* @param ms - The number of milliseconds to sleep.
|
|
30
|
+
* @returns A Promise that resolves after the specified time has passed.
|
|
31
|
+
*/
|
|
32
|
+
sleep(ms: number): Promise<void>;
|
|
33
|
+
/**
|
|
34
|
+
* Interrupts the current sleep operation and optionally throws an error if specified.
|
|
35
|
+
* By default, when interrupted, the sleep operation will resolve without throwing.
|
|
36
|
+
* If 'sleepShouldThrow' is set to true, the sleep operation will throw an InterruptError instead.
|
|
37
|
+
*
|
|
38
|
+
* @param sleepShouldThrow - A boolean value indicating whether the sleep operation should throw an error when interrupted. Default is false.
|
|
39
|
+
*/
|
|
40
|
+
interrupt(sleepShouldThrow?: boolean): void;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Puts the current execution context to sleep for a specified duration.
|
|
44
|
+
* This simulates a blocking sleep operation by using an asynchronous function and a Promise that resolves after the given duration.
|
|
45
|
+
* The sleep function can be interrupted by the 'interrupt' method of the InterruptibleSleep class.
|
|
46
|
+
*
|
|
47
|
+
* @param ms - The duration in milliseconds for which the sleep operation should last.
|
|
48
|
+
* @param returnValue - The return value of the promise.
|
|
49
|
+
* @returns A Promise that resolves after the specified duration, allowing the use of 'await' to pause execution.
|
|
50
|
+
*/
|
|
51
|
+
export declare function sleep<T>(ms: number, returnValue?: T): Promise<T>;
|
|
52
|
+
/** Sleeps until the target date */
|
|
53
|
+
export declare function sleepUntil<T>(target: Date, now: Date, returnValue?: T): Promise<T>;
|
|
54
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3Q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;;OAMG;IACI,SAAS,CAAC,gBAAgB,UAAQ,GAAG,IAAI,CAK/C;CACF;AAED;;;;;;;;GAQG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAEhE;AAED,mCAAmC;AACnC,wBAAgB,UAAU,CAAC,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,WAAW,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAGlF"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { InterruptError } from '../error/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* InterruptibleSleep is a utility class that allows you to create an interruptible sleep function.
|
|
4
|
+
* The sleep function can be interrupted at any time by calling the `interrupt` method, which can
|
|
5
|
+
* also specify whether the sleep should throw an error or just return. This is useful when you need
|
|
6
|
+
* to terminate long-running processes or perform cleanup tasks in response to external events.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* const sleeper = new InterruptibleSleep();
|
|
10
|
+
*
|
|
11
|
+
* async function longRunningTask() \{
|
|
12
|
+
* try \{
|
|
13
|
+
* await sleeper.sleep(3000);
|
|
14
|
+
* console.log('Task completed after 3 seconds');
|
|
15
|
+
* \} catch (e) \{
|
|
16
|
+
* console.log('Task was interrupted');
|
|
17
|
+
* \}
|
|
18
|
+
* \}
|
|
19
|
+
*
|
|
20
|
+
* setTimeout(() =\> sleeper.interrupt(true), 1500); // Interrupt the sleep after 1.5 seconds
|
|
21
|
+
*/ export class InterruptibleSleep {
|
|
22
|
+
interrupts = [];
|
|
23
|
+
timeoutIds = [];
|
|
24
|
+
/**
|
|
25
|
+
* Sleep for a specified amount of time in milliseconds.
|
|
26
|
+
* The sleep function will pause the execution of the current async function
|
|
27
|
+
* for the given time period, allowing other tasks to run before resuming.
|
|
28
|
+
*
|
|
29
|
+
* @param ms - The number of milliseconds to sleep.
|
|
30
|
+
* @returns A Promise that resolves after the specified time has passed.
|
|
31
|
+
*/ async sleep(ms) {
|
|
32
|
+
let interruptResolve;
|
|
33
|
+
const interruptPromise = new Promise((resolve)=>{
|
|
34
|
+
interruptResolve = resolve;
|
|
35
|
+
this.interrupts.push(resolve);
|
|
36
|
+
});
|
|
37
|
+
let timeoutId;
|
|
38
|
+
const timeoutPromise = new Promise((resolve)=>{
|
|
39
|
+
timeoutId = setTimeout(()=>resolve(false), ms);
|
|
40
|
+
this.timeoutIds.push(timeoutId);
|
|
41
|
+
});
|
|
42
|
+
const shouldThrow = await Promise.race([
|
|
43
|
+
interruptPromise,
|
|
44
|
+
timeoutPromise
|
|
45
|
+
]);
|
|
46
|
+
clearTimeout(timeoutId);
|
|
47
|
+
this.timeoutIds = this.timeoutIds.filter((id)=>id !== timeoutId);
|
|
48
|
+
this.interrupts = this.interrupts.filter((res)=>res !== interruptResolve);
|
|
49
|
+
if (shouldThrow) {
|
|
50
|
+
throw new InterruptError('Interrupted.');
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Interrupts the current sleep operation and optionally throws an error if specified.
|
|
55
|
+
* By default, when interrupted, the sleep operation will resolve without throwing.
|
|
56
|
+
* If 'sleepShouldThrow' is set to true, the sleep operation will throw an InterruptError instead.
|
|
57
|
+
*
|
|
58
|
+
* @param sleepShouldThrow - A boolean value indicating whether the sleep operation should throw an error when interrupted. Default is false.
|
|
59
|
+
*/ interrupt(sleepShouldThrow = false) {
|
|
60
|
+
this.interrupts.forEach((resolve)=>resolve(sleepShouldThrow));
|
|
61
|
+
this.interrupts = [];
|
|
62
|
+
this.timeoutIds.forEach((id)=>clearTimeout(id));
|
|
63
|
+
this.timeoutIds = [];
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Puts the current execution context to sleep for a specified duration.
|
|
68
|
+
* This simulates a blocking sleep operation by using an asynchronous function and a Promise that resolves after the given duration.
|
|
69
|
+
* The sleep function can be interrupted by the 'interrupt' method of the InterruptibleSleep class.
|
|
70
|
+
*
|
|
71
|
+
* @param ms - The duration in milliseconds for which the sleep operation should last.
|
|
72
|
+
* @param returnValue - The return value of the promise.
|
|
73
|
+
* @returns A Promise that resolves after the specified duration, allowing the use of 'await' to pause execution.
|
|
74
|
+
*/ export function sleep(ms, returnValue) {
|
|
75
|
+
return new Promise((resolve)=>setTimeout(()=>resolve(returnValue), ms));
|
|
76
|
+
}
|
|
77
|
+
/** Sleeps until the target date */ export function sleepUntil(target, now, returnValue) {
|
|
78
|
+
const ms = target.getTime() - now.getTime();
|
|
79
|
+
return sleep(ms, returnValue);
|
|
80
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** Parameterized hex string type for specific byte lengths */
|
|
2
|
+
export type Hex<TByteLength extends number> = `0x${string}` & {
|
|
3
|
+
readonly _length: TByteLength;
|
|
4
|
+
};
|
|
5
|
+
export declare function hasHexPrefix(str: string): str is `0x${string}`;
|
|
6
|
+
export declare function withoutHexPrefix(str: string): string;
|
|
7
|
+
export declare function withHexPrefix(str: string): `0x${string}`;
|
|
8
|
+
export declare function isHex(str: string): boolean;
|
|
9
|
+
export declare function hexToBuffer(str: string): Buffer;
|
|
10
|
+
export declare function bufferToHex(buffer: Buffer): `0x${string}`;
|
|
11
|
+
export declare function pluralize(str: string, count: number | bigint, plural?: string): string;
|
|
12
|
+
export declare function count(count: number | bigint, str: string, plural?: string): string;
|
|
13
|
+
export declare function truncate(str: string, length?: number): string;
|
|
14
|
+
/** Formats a duration in seconds into a compact human-readable string (e.g. `45s`, `12m`, `2h 5m`). */
|
|
15
|
+
export declare function formatSeconds(seconds: number): string;
|
|
16
|
+
export declare function isoDate(date?: Date): string;
|
|
17
|
+
export declare function urlJoin(...args: string[]): string;
|
|
18
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZ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AAM,GAAG,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAElF;AAED,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,GAAE,MAAW,GAAG,MAAM,CAEjE;AAED,uGAAuG;AACvG,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAWrD;AAED,wBAAgB,OAAO,CAAC,IAAI,CAAC,EAAE,IAAI,UAElC;AAED,wBAAgB,OAAO,CAAC,GAAG,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM,CAsBjD"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/** Parameterized hex string type for specific byte lengths */ export function hasHexPrefix(str) {
|
|
2
|
+
return str.startsWith('0x');
|
|
3
|
+
}
|
|
4
|
+
export function withoutHexPrefix(str) {
|
|
5
|
+
return hasHexPrefix(str) ? str.slice(2) : str;
|
|
6
|
+
}
|
|
7
|
+
export function withHexPrefix(str) {
|
|
8
|
+
return hasHexPrefix(str) ? str : `0x${str}`;
|
|
9
|
+
}
|
|
10
|
+
export function isHex(str) {
|
|
11
|
+
return /^(0x)?[0-9a-fA-F]*$/.test(str);
|
|
12
|
+
}
|
|
13
|
+
export function hexToBuffer(str) {
|
|
14
|
+
return Buffer.from(withoutHexPrefix(str), 'hex');
|
|
15
|
+
}
|
|
16
|
+
export function bufferToHex(buffer) {
|
|
17
|
+
return `0x${buffer.toString('hex')}`;
|
|
18
|
+
}
|
|
19
|
+
export function pluralize(str, count, plural) {
|
|
20
|
+
return count === 1 || count === 1n ? str : plural ?? `${str}s`;
|
|
21
|
+
}
|
|
22
|
+
export function count(count, str, plural) {
|
|
23
|
+
return `${count} ${pluralize(str, count, plural)}`;
|
|
24
|
+
}
|
|
25
|
+
export function truncate(str, length = 64) {
|
|
26
|
+
return str.length > length ? str.slice(0, length) + '...' : str;
|
|
27
|
+
}
|
|
28
|
+
/** Formats a duration in seconds into a compact human-readable string (e.g. `45s`, `12m`, `2h 5m`). */ export function formatSeconds(seconds) {
|
|
29
|
+
if (seconds < 60) {
|
|
30
|
+
return `${Math.round(seconds)}s`;
|
|
31
|
+
}
|
|
32
|
+
const minutes = Math.round(seconds / 60);
|
|
33
|
+
if (minutes < 60) {
|
|
34
|
+
return `${minutes}m`;
|
|
35
|
+
}
|
|
36
|
+
const hours = Math.floor(minutes / 60);
|
|
37
|
+
const remMinutes = minutes % 60;
|
|
38
|
+
return remMinutes > 0 ? `${hours}h ${remMinutes}m` : `${hours}h`;
|
|
39
|
+
}
|
|
40
|
+
export function isoDate(date) {
|
|
41
|
+
return (date ?? new Date()).toISOString().replace(/[-:T]/g, '').replace(/\..+$/, '');
|
|
42
|
+
}
|
|
43
|
+
export function urlJoin(...args) {
|
|
44
|
+
const processed = [];
|
|
45
|
+
for (const arg of args){
|
|
46
|
+
if (arg.length === 0) {
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
let start = 0;
|
|
50
|
+
let end = arg.length - 1;
|
|
51
|
+
while(start <= end && arg[start] === '/'){
|
|
52
|
+
start++;
|
|
53
|
+
}
|
|
54
|
+
while(end >= start && arg[end] === '/'){
|
|
55
|
+
end--;
|
|
56
|
+
}
|
|
57
|
+
if (start <= end) {
|
|
58
|
+
processed.push(arg.slice(start, end + 1));
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return processed.join('/');
|
|
62
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** Writes the contents specified to the target file if test data generation is enabled. */
|
|
2
|
+
export declare function writeTestData(targetFileFromRepoRoot: string, contents: string | Buffer, raw?: boolean): void;
|
|
3
|
+
export declare function readTestData(repoPath: string): Buffer;
|
|
4
|
+
/**
|
|
5
|
+
* Looks for a variable assignment in the target file and updates the value, only if test data generation is enabled.
|
|
6
|
+
* Note that a magic inline comment would be a cleaner approach, like `/* TEST-DATA-START *\/` and `/* TEST-DATA-END *\/`,
|
|
7
|
+
* but running nargo fmt on it panics since the comment would be erased, so we roll with this for now.
|
|
8
|
+
* @remarks Requires AZTEC_GENERATE_TEST_DATA=1 to be set
|
|
9
|
+
*/
|
|
10
|
+
export declare function updateInlineTestData(targetFileFromRepoRoot: string, itemName: string, value: string): void;
|
|
11
|
+
/**
|
|
12
|
+
* Updates the sample Prover.toml files in noir-projects/fnd/noir-protocol-circuits/crates/.
|
|
13
|
+
* @remarks Requires AZTEC_GENERATE_TEST_DATA=1 to be set. The block-root, block-merge, checkpoint,
|
|
14
|
+
* tx-merge, and root rollup samples are regenerated by the prover-client
|
|
15
|
+
* `regenerate_rollup_sample_inputs.test.ts` suite; the private-kernel and transaction-base rollup
|
|
16
|
+
* samples by the e2e 'AZTEC_GENERATE_TEST_DATA=1 FAKE_PROOFS=1 yarn test:e2e single-node/prover/server/full.test' dump.
|
|
17
|
+
*/
|
|
18
|
+
export declare function updateProtocolCircuitSampleInputs(circuitName: string, value: string): void;
|
|
19
|
+
export declare function getPathToFile(targetFileFromRepoRoot: string): string;
|
|
20
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy90ZXN0aW5nL2ZpbGVzL2luZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQU9BLDJGQUEyRjtBQUMzRix3QkFBZ0IsYUFBYSxDQUFDLHNCQUFzQixFQUFFLE1BQU0sRUFBRSxRQUFRLEVBQUUsTUFBTSxHQUFHLE1BQU0sRUFBRSxHQUFHLEdBQUUsT0FBZSxRQVM1RztBQUVELHdCQUFnQixZQUFZLENBQUMsUUFBUSxFQUFFLE1BQU0sR0FBRyxNQUFNLENBR3JEO0FBRUQ7Ozs7O0dBS0c7QUFDSCx3QkFBZ0Isb0JBQW9CLENBQUMsc0JBQXNCLEVBQUUsTUFBTSxFQUFFLFFBQVEsRUFBRSxNQUFNLEVBQUUsS0FBSyxFQUFFLE1BQU0sUUFtQm5HO0FBRUQ7Ozs7OztHQU1HO0FBQ0gsd0JBQWdCLGlDQUFpQyxDQUFDLFdBQVcsRUFBRSxNQUFNLEVBQUUsS0FBSyxFQUFFLE1BQU0sUUFNbkY7QUFFRCx3QkFBZ0IsYUFBYSxDQUFDLHNCQUFzQixFQUFFLE1BQU0sVUFPM0QifQ==
|