@aztec/foundation 4.0.0-nightly.20250907 → 4.0.0-nightly.20260107
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/array/array.d.ts +1 -9
- package/dest/array/array.d.ts.map +1 -1
- package/dest/array/array.js +0 -11
- package/dest/array/index.d.ts +2 -1
- package/dest/array/index.d.ts.map +1 -1
- package/dest/array/index.js +1 -0
- package/dest/array/sorted_array.d.ts +10 -0
- package/dest/array/sorted_array.d.ts.map +1 -0
- package/dest/array/sorted_array.js +106 -0
- package/dest/async-map/index.d.ts +1 -1
- package/dest/async-pool/index.d.ts +1 -1
- package/dest/bigint/index.d.ts +1 -1
- package/dest/bigint-buffer/index.d.ts +1 -1
- package/dest/branded-types/block_number.d.ts +53 -0
- package/dest/branded-types/block_number.d.ts.map +1 -0
- package/dest/branded-types/block_number.js +75 -0
- package/dest/branded-types/checkpoint_number.d.ts +46 -0
- package/dest/branded-types/checkpoint_number.d.ts.map +1 -0
- package/dest/branded-types/checkpoint_number.js +68 -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 +6 -0
- package/dest/branded-types/index.d.ts.map +1 -0
- package/dest/branded-types/index.js +4 -0
- package/dest/branded-types/slot.d.ts +42 -0
- package/dest/branded-types/slot.d.ts.map +1 -0
- package/dest/branded-types/slot.js +59 -0
- package/dest/branded-types/types.d.ts +5 -0
- package/dest/branded-types/types.d.ts.map +1 -0
- package/dest/branded-types/types.js +1 -0
- package/dest/buffer/buffer16.d.ts +2 -5
- package/dest/buffer/buffer16.d.ts.map +1 -1
- package/dest/buffer/buffer16.js +4 -2
- package/dest/buffer/buffer32.d.ts +2 -5
- package/dest/buffer/buffer32.d.ts.map +1 -1
- package/dest/buffer/buffer32.js +4 -2
- package/dest/buffer/index.d.ts +1 -1
- package/dest/collection/array.d.ts +3 -1
- package/dest/collection/array.d.ts.map +1 -1
- package/dest/collection/array.js +12 -3
- package/dest/collection/index.d.ts +1 -1
- package/dest/collection/object.d.ts +5 -1
- package/dest/collection/object.d.ts.map +1 -1
- package/dest/collection/object.js +6 -0
- package/dest/committable/committable.d.ts +1 -1
- package/dest/committable/committable.d.ts.map +1 -1
- package/dest/committable/index.d.ts +1 -1
- package/dest/config/env_var.d.ts +2 -2
- package/dest/config/env_var.d.ts.map +1 -1
- package/dest/config/index.d.ts +12 -2
- package/dest/config/index.d.ts.map +1 -1
- package/dest/config/index.js +17 -2
- package/dest/config/network_config.d.ts +54 -0
- package/dest/config/network_config.d.ts.map +1 -0
- package/dest/config/network_config.js +11 -0
- 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 +10 -2
- package/dest/config/secret_value.d.ts +1 -1
- package/dest/config/secret_value.d.ts.map +1 -1
- package/dest/config/secret_value.js +3 -1
- package/dest/crypto/aes128/index.d.ts +1 -1
- package/dest/crypto/aes128/index.d.ts.map +1 -1
- package/dest/crypto/aes128/index.js +19 -6
- package/dest/crypto/bls/bn254_keystore.d.ts +296 -0
- package/dest/crypto/bls/bn254_keystore.d.ts.map +1 -0
- package/dest/crypto/bls/bn254_keystore.js +218 -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 +1 -1
- package/dest/crypto/ecdsa/index.d.ts.map +1 -1
- package/dest/crypto/ecdsa/index.js +58 -48
- package/dest/crypto/ecdsa/signature.d.ts +2 -11
- 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 +10 -13
- package/dest/crypto/grumpkin/index.d.ts.map +1 -1
- package/dest/crypto/grumpkin/index.js +61 -55
- package/dest/crypto/keccak/index.d.ts +1 -1
- package/dest/crypto/keys/index.d.ts +2 -2
- package/dest/crypto/keys/index.d.ts.map +1 -1
- package/dest/crypto/keys/index.js +8 -5
- package/dest/crypto/pedersen/index.d.ts +1 -1
- package/dest/crypto/pedersen/pedersen.noble.d.ts +1 -1
- package/dest/crypto/pedersen/pedersen.wasm.d.ts +2 -2
- package/dest/crypto/pedersen/pedersen.wasm.d.ts.map +1 -1
- package/dest/crypto/pedersen/pedersen.wasm.js +24 -14
- package/dest/crypto/poseidon/index.d.ts +2 -2
- package/dest/crypto/poseidon/index.d.ts.map +1 -1
- package/dest/crypto/poseidon/index.js +33 -18
- package/dest/crypto/random/index.d.ts +1 -1
- package/dest/crypto/random/index.d.ts.map +1 -1
- package/dest/crypto/random/randomness_singleton.d.ts +1 -1
- package/dest/crypto/random/randomness_singleton.d.ts.map +1 -1
- 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 +30 -38
- package/dest/crypto/schnorr/signature.d.ts +2 -2
- package/dest/crypto/schnorr/signature.d.ts.map +1 -1
- package/dest/crypto/schnorr/signature.js +2 -2
- package/dest/crypto/secp256k1/index.d.ts +1 -1
- package/dest/crypto/secp256k1/index.d.ts.map +1 -1
- package/dest/crypto/secp256k1/index.js +23 -18
- package/dest/crypto/secp256k1-signer/index.d.ts +1 -1
- package/dest/crypto/secp256k1-signer/secp256k1_signer.d.ts +1 -1
- package/dest/crypto/secp256k1-signer/secp256k1_signer.d.ts.map +1 -1
- package/dest/crypto/secp256k1-signer/utils.d.ts +49 -3
- package/dest/crypto/secp256k1-signer/utils.d.ts.map +1 -1
- package/dest/crypto/secp256k1-signer/utils.js +87 -5
- package/dest/crypto/serialize.d.ts +1 -1
- package/dest/crypto/sha256/index.d.ts +2 -2
- package/dest/crypto/sha256/index.d.ts.map +1 -1
- package/dest/crypto/sha256/index.js +1 -1
- package/dest/crypto/sha512/index.d.ts +3 -3
- package/dest/crypto/sha512/index.d.ts.map +1 -1
- package/dest/crypto/sha512/index.js +1 -1
- package/dest/crypto/signature/index.d.ts +2 -2
- package/dest/crypto/signature/index.d.ts.map +1 -1
- package/dest/crypto/sync/index.d.ts +1 -1
- package/dest/crypto/sync/index.js +1 -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 +18 -11
- package/dest/crypto/sync/poseidon/index.d.ts +2 -2
- package/dest/crypto/sync/poseidon/index.d.ts.map +1 -1
- package/dest/crypto/sync/poseidon/index.js +28 -13
- package/dest/{fields/bls12_fields.d.ts → curves/bls12/field.d.ts} +3 -3
- package/dest/curves/bls12/field.d.ts.map +1 -0
- package/dest/{fields/bls12_fields.js → curves/bls12/field.js} +12 -9
- package/dest/curves/bls12/index.d.ts +3 -0
- package/dest/curves/bls12/index.d.ts.map +1 -0
- package/dest/curves/bls12/index.js +2 -0
- package/dest/{fields/bls12_point.d.ts → curves/bls12/point.d.ts} +11 -20
- package/dest/curves/bls12/point.d.ts.map +1 -0
- package/dest/{fields/bls12_point.js → curves/bls12/point.js} +17 -15
- package/dest/curves/bn254/field.d.ts +180 -0
- package/dest/curves/bn254/field.d.ts.map +1 -0
- package/dest/{fields/fields.js → curves/bn254/field.js} +71 -59
- 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 +13 -13
- package/dest/curves/grumpkin/point.d.ts.map +1 -0
- package/dest/{fields → curves/grumpkin}/point.js +24 -7
- package/dest/decorators/index.d.ts +1 -1
- package/dest/decorators/memoize.d.ts +1 -1
- package/dest/decorators/memoize.d.ts.map +1 -1
- package/dest/error/index.d.ts +4 -4
- package/dest/error/index.d.ts.map +1 -1
- package/dest/eth-address/index.d.ts +14 -4
- package/dest/eth-address/index.d.ts.map +1 -1
- package/dest/eth-address/index.js +26 -2
- package/dest/eth-signature/eth_signature.d.ts +1 -4
- package/dest/eth-signature/eth_signature.d.ts.map +1 -1
- package/dest/eth-signature/eth_signature.js +2 -4
- package/dest/eth-signature/index.d.ts +1 -1
- package/dest/fs/index.d.ts +1 -1
- package/dest/fs/run_in_dir.d.ts +1 -1
- package/dest/fs/try_rm_dir.d.ts +1 -1
- package/dest/iterable/all.d.ts +1 -1
- package/dest/iterable/filter.d.ts +1 -1
- package/dest/iterable/index.d.ts +1 -1
- package/dest/iterable/isAsyncIt.d.ts +1 -1
- package/dest/iterable/map.d.ts +1 -1
- package/dest/iterable/peek.d.ts +1 -1
- package/dest/iterable/sort.d.ts +1 -1
- package/dest/iterable/take.d.ts +1 -1
- package/dest/iterable/toArray.d.ts +1 -1
- package/dest/iterator/filter.d.ts +3 -0
- package/dest/iterator/filter.d.ts.map +1 -0
- package/dest/iterator/filter.js +7 -0
- package/dest/iterator/index.d.ts +2 -0
- package/dest/iterator/index.d.ts.map +1 -0
- package/dest/iterator/index.js +1 -0
- package/dest/json-rpc/client/fetch.d.ts +1 -1
- package/dest/json-rpc/client/index.d.ts +1 -1
- package/dest/json-rpc/client/safe_json_rpc_client.d.ts +1 -1
- package/dest/json-rpc/client/safe_json_rpc_client.d.ts.map +1 -1
- package/dest/json-rpc/client/safe_json_rpc_client.js +9 -0
- package/dest/json-rpc/client/undici.d.ts +1 -1
- package/dest/json-rpc/convert.d.ts +1 -1
- package/dest/json-rpc/errors.d.ts +1 -1
- package/dest/json-rpc/errors.d.ts.map +1 -1
- package/dest/json-rpc/fixtures/class_a.d.ts +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/fixtures/test_state.d.ts +1 -1
- package/dest/json-rpc/fixtures/test_state.d.ts.map +1 -1
- package/dest/json-rpc/index.d.ts +1 -1
- package/dest/json-rpc/js_utils.d.ts +1 -1
- package/dest/json-rpc/js_utils.d.ts.map +1 -1
- package/dest/json-rpc/server/index.d.ts +1 -1
- package/dest/json-rpc/server/safe_json_rpc_server.d.ts +1 -1
- package/dest/json-rpc/server/safe_json_rpc_server.d.ts.map +1 -1
- package/dest/json-rpc/test/index.d.ts +1 -1
- package/dest/json-rpc/test/integration.d.ts +1 -1
- package/dest/log/console.d.ts +1 -1
- package/dest/log/gcloud-logger-config.d.ts +1 -1
- package/dest/log/gcloud-logger-config.d.ts.map +1 -1
- package/dest/log/index.d.ts +1 -1
- package/dest/log/libp2p_logger.d.ts +1 -1
- package/dest/log/log-filters.d.ts +1 -1
- package/dest/log/log-levels.d.ts +1 -1
- package/dest/log/log_fn.d.ts +2 -2
- package/dest/log/log_fn.d.ts.map +1 -1
- package/dest/log/noir_debug_log_util.d.ts +1 -1
- package/dest/log/pino-logger.d.ts +2 -2
- package/dest/log/pino-logger.d.ts.map +1 -1
- package/dest/log/pino-logger.js +0 -1
- package/dest/message/index.d.ts +1 -1
- package/dest/message/index.d.ts.map +1 -1
- package/dest/mutex/index.d.ts +1 -1
- package/dest/mutex/index.d.ts.map +1 -1
- package/dest/mutex/mutex_database.d.ts +1 -1
- package/dest/noir/index.d.ts +1 -1
- package/dest/noir/noir_package_config.d.ts +9 -9
- package/dest/number/index.d.ts +1 -1
- package/dest/profiler/index.d.ts +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 +1 -1
- package/dest/promise/running-promise.d.ts +1 -1
- package/dest/promise/running-promise.d.ts.map +1 -1
- package/dest/promise/utils.d.ts +1 -1
- package/dest/queue/base_memory_queue.d.ts +1 -1
- package/dest/queue/base_memory_queue.d.ts.map +1 -1
- package/dest/queue/batch_queue.d.ts +1 -1
- package/dest/queue/batch_queue.d.ts.map +1 -1
- package/dest/queue/bounded_serial_queue.d.ts +1 -1
- package/dest/queue/bounded_serial_queue.d.ts.map +1 -1
- package/dest/queue/fifo_memory_queue.d.ts +1 -1
- package/dest/queue/fifo_memory_queue.d.ts.map +1 -1
- package/dest/queue/index.d.ts +1 -1
- package/dest/queue/priority_memory_queue.d.ts +1 -1
- package/dest/queue/priority_memory_queue.d.ts.map +1 -1
- package/dest/queue/priority_queue.d.ts +1 -1
- package/dest/queue/priority_queue.d.ts.map +1 -1
- package/dest/queue/semaphore.d.ts +1 -1
- package/dest/queue/semaphore.d.ts.map +1 -1
- package/dest/queue/serial_queue.d.ts +1 -1
- package/dest/queue/serial_queue.d.ts.map +1 -1
- package/dest/retry/index.d.ts +1 -1
- package/dest/running-promise/index.d.ts +1 -1
- package/dest/schemas/api.d.ts +1 -1
- package/dest/schemas/index.d.ts +1 -1
- package/dest/schemas/parse.d.ts +1 -1
- package/dest/schemas/schemas.d.ts +15 -17
- package/dest/schemas/schemas.d.ts.map +1 -1
- package/dest/schemas/schemas.js +14 -10
- package/dest/schemas/types.d.ts +31 -1
- package/dest/schemas/types.d.ts.map +1 -1
- package/dest/schemas/types.js +25 -1
- package/dest/schemas/utils.d.ts +4 -4
- package/dest/schemas/utils.d.ts.map +1 -1
- package/dest/schemas/utils.js +15 -5
- package/dest/serialize/buffer_reader.d.ts +3 -1
- package/dest/serialize/buffer_reader.d.ts.map +1 -1
- package/dest/serialize/buffer_reader.js +3 -0
- package/dest/serialize/field_reader.d.ts +2 -2
- package/dest/serialize/field_reader.d.ts.map +1 -1
- package/dest/serialize/field_reader.js +1 -1
- package/dest/serialize/free_funcs.d.ts +2 -2
- package/dest/serialize/free_funcs.d.ts.map +1 -1
- package/dest/serialize/free_funcs.js +1 -1
- package/dest/serialize/index.d.ts +1 -1
- package/dest/serialize/serialize.d.ts +2 -2
- package/dest/serialize/serialize.d.ts.map +1 -1
- package/dest/serialize/serialize.js +1 -1
- package/dest/serialize/type_registry.d.ts +1 -1
- package/dest/serialize/type_registry.d.ts.map +1 -1
- package/dest/serialize/types.d.ts +1 -1
- package/dest/sleep/index.d.ts +3 -1
- package/dest/sleep/index.d.ts.map +1 -1
- package/dest/sleep/index.js +4 -0
- package/dest/string/index.d.ts +5 -1
- package/dest/string/index.d.ts.map +1 -1
- package/dest/string/index.js +19 -2
- package/dest/testing/files/index.d.ts +2 -1
- package/dest/testing/files/index.d.ts.map +1 -1
- package/dest/testing/files/index.js +1 -1
- package/dest/testing/formatting.d.ts +4 -0
- package/dest/testing/formatting.d.ts.map +1 -0
- package/dest/testing/formatting.js +3 -0
- package/dest/testing/index.d.ts +2 -1
- package/dest/testing/index.d.ts.map +1 -1
- package/dest/testing/index.js +1 -0
- package/dest/testing/port_allocator.d.ts +1 -1
- package/dest/testing/snapshot_serializer.d.ts +1 -1
- package/dest/testing/test_data.d.ts +1 -1
- package/dest/timer/date.d.ts +2 -1
- package/dest/timer/date.d.ts.map +1 -1
- package/dest/timer/date.js +3 -0
- package/dest/timer/elapsed.d.ts +1 -1
- package/dest/timer/index.d.ts +1 -1
- package/dest/timer/timeout.d.ts +1 -1
- package/dest/timer/timeout.d.ts.map +1 -1
- package/dest/timer/timer.d.ts +1 -1
- package/dest/timer/timer.d.ts.map +1 -1
- package/dest/transport/dispatch/create_dispatch_fn.d.ts +1 -1
- package/dest/transport/dispatch/create_dispatch_fn.d.ts.map +1 -1
- package/dest/transport/dispatch/create_dispatch_proxy.d.ts +1 -1
- package/dest/transport/dispatch/messages.d.ts +1 -1
- package/dest/transport/index.d.ts +1 -1
- package/dest/transport/interface/connector.d.ts +1 -1
- package/dest/transport/interface/listener.d.ts +1 -1
- package/dest/transport/interface/socket.d.ts +1 -1
- package/dest/transport/interface/transferable.d.ts +1 -1
- package/dest/transport/node/index.d.ts +1 -1
- package/dest/transport/node/node_connector.d.ts +1 -1
- package/dest/transport/node/node_connector.d.ts.map +1 -1
- package/dest/transport/node/node_connector_socket.d.ts +1 -1
- package/dest/transport/node/node_connector_socket.d.ts.map +1 -1
- package/dest/transport/node/node_listener.d.ts +1 -1
- package/dest/transport/node/node_listener.d.ts.map +1 -1
- package/dest/transport/node/node_listener_socket.d.ts +1 -1
- package/dest/transport/node/node_listener_socket.d.ts.map +1 -1
- package/dest/transport/transport_client.d.ts +1 -1
- package/dest/transport/transport_client.d.ts.map +1 -1
- package/dest/transport/transport_server.d.ts +1 -10
- package/dest/transport/transport_server.d.ts.map +1 -1
- package/dest/trees/balanced_merkle_tree.d.ts +22 -0
- package/dest/trees/balanced_merkle_tree.d.ts.map +1 -0
- package/dest/trees/balanced_merkle_tree.js +66 -0
- package/dest/trees/hasher.d.ts +1 -1
- package/dest/trees/index.d.ts +2 -1
- package/dest/trees/index.d.ts.map +1 -1
- package/dest/trees/index.js +1 -0
- package/dest/trees/indexed_merkle_tree.d.ts +1 -1
- package/dest/trees/indexed_merkle_tree.d.ts.map +1 -1
- package/dest/trees/indexed_merkle_tree.js +1 -1
- package/dest/trees/indexed_merkle_tree_calculator.d.ts +1 -1
- package/dest/trees/indexed_merkle_tree_calculator.d.ts.map +1 -1
- package/dest/trees/indexed_tree_leaf.d.ts +1 -1
- package/dest/trees/membership_witness.d.ts +3 -24
- package/dest/trees/membership_witness.d.ts.map +1 -1
- package/dest/trees/membership_witness.js +1 -1
- package/dest/trees/merkle_tree.d.ts +1 -1
- package/dest/trees/merkle_tree.d.ts.map +1 -1
- package/dest/trees/merkle_tree_calculator.d.ts +2 -12
- package/dest/trees/merkle_tree_calculator.d.ts.map +1 -1
- package/dest/trees/merkle_tree_calculator.js +1 -31
- package/dest/trees/sibling_path.d.ts +5 -39
- package/dest/trees/sibling_path.d.ts.map +1 -1
- package/dest/trees/sibling_path.js +2 -2
- package/dest/trees/unbalanced_merkle_tree.d.ts +5 -4
- package/dest/trees/unbalanced_merkle_tree.d.ts.map +1 -1
- package/dest/trees/unbalanced_merkle_tree.js +33 -10
- package/dest/trees/unbalanced_merkle_tree_calculator.d.ts +27 -23
- package/dest/trees/unbalanced_merkle_tree_calculator.d.ts.map +1 -1
- package/dest/trees/unbalanced_merkle_tree_calculator.js +123 -97
- package/dest/trees/unbalanced_tree_store.d.ts +2 -1
- package/dest/trees/unbalanced_tree_store.d.ts.map +1 -1
- package/dest/trees/unbalanced_tree_store.js +6 -0
- package/dest/types/index.d.ts +3 -1
- package/dest/types/index.d.ts.map +1 -1
- package/dest/types/index.js +3 -0
- package/dest/url/index.d.ts +1 -1
- package/dest/validation/index.d.ts +1 -1
- package/package.json +32 -8
- package/src/array/array.ts +0 -16
- package/src/array/index.ts +1 -0
- package/src/array/sorted_array.ts +133 -0
- package/src/branded-types/block_number.ts +112 -0
- package/src/branded-types/checkpoint_number.ts +100 -0
- package/src/branded-types/epoch.ts +88 -0
- package/src/branded-types/index.ts +6 -0
- package/src/branded-types/slot.ts +88 -0
- package/src/branded-types/types.ts +2 -0
- package/src/buffer/buffer16.ts +2 -2
- package/src/buffer/buffer32.ts +2 -2
- package/src/collection/array.ts +15 -3
- package/src/collection/object.ts +8 -0
- package/src/config/env_var.ts +44 -10
- package/src/config/index.ts +22 -2
- package/src/config/network_config.ts +18 -0
- package/src/config/network_name.ts +18 -3
- package/src/crypto/aes128/index.ts +19 -10
- package/src/crypto/bls/bn254_keystore.ts +287 -0
- package/src/crypto/bls/index.ts +77 -0
- package/src/crypto/bn254/index.ts +64 -0
- package/src/crypto/ecdsa/index.ts +40 -37
- package/src/crypto/ecdsa/signature.ts +2 -2
- package/src/crypto/grumpkin/index.ts +38 -46
- package/src/crypto/keys/index.ts +6 -6
- package/src/crypto/pedersen/pedersen.wasm.ts +23 -19
- package/src/crypto/poseidon/index.ts +33 -25
- package/src/crypto/schnorr/index.ts +22 -18
- package/src/crypto/schnorr/signature.ts +2 -2
- package/src/crypto/secp256k1/index.ts +15 -11
- package/src/crypto/secp256k1-signer/utils.ts +115 -7
- package/src/crypto/sha256/index.ts +1 -1
- package/src/crypto/sha512/index.ts +1 -1
- package/src/crypto/signature/index.ts +1 -1
- package/src/crypto/sync/index.ts +1 -1
- package/src/crypto/sync/pedersen/index.ts +17 -16
- package/src/crypto/sync/poseidon/index.ts +28 -23
- package/src/{fields/bls12_fields.ts → curves/bls12/field.ts} +6 -6
- package/src/curves/bls12/index.ts +2 -0
- package/src/{fields/bls12_point.ts → curves/bls12/point.ts} +14 -14
- package/src/{fields/fields.ts → curves/bn254/field.ts} +69 -62
- package/src/curves/bn254/index.ts +2 -0
- package/src/curves/bn254/point.ts +170 -0
- package/src/curves/grumpkin/index.ts +11 -0
- package/src/{fields → curves/grumpkin}/point.ts +26 -7
- package/src/eth-address/index.ts +28 -3
- package/src/eth-signature/eth_signature.ts +2 -4
- package/src/iterator/filter.ts +11 -0
- package/src/iterator/index.ts +1 -0
- package/src/json-rpc/client/safe_json_rpc_client.ts +9 -0
- package/src/log/log_fn.ts +1 -1
- package/src/log/pino-logger.ts +0 -1
- package/src/profiler/index.ts +1 -0
- package/src/profiler/profiler.ts +125 -0
- package/src/schemas/schemas.ts +24 -13
- package/src/schemas/types.ts +33 -0
- package/src/schemas/utils.ts +21 -8
- package/src/serialize/buffer_reader.ts +5 -0
- package/src/serialize/field_reader.ts +1 -1
- package/src/serialize/free_funcs.ts +1 -1
- package/src/serialize/serialize.ts +1 -1
- package/src/sleep/index.ts +6 -0
- package/src/string/index.ts +24 -1
- package/src/testing/files/index.ts +1 -1
- package/src/testing/formatting.ts +3 -0
- package/src/testing/index.ts +1 -0
- package/src/timer/date.ts +4 -0
- package/src/trees/balanced_merkle_tree.ts +84 -0
- package/src/trees/index.ts +1 -0
- package/src/trees/indexed_merkle_tree.ts +1 -1
- package/src/trees/membership_witness.ts +1 -1
- package/src/trees/merkle_tree_calculator.ts +1 -34
- package/src/trees/sibling_path.ts +2 -2
- package/src/trees/unbalanced_merkle_tree.ts +55 -7
- package/src/trees/unbalanced_merkle_tree_calculator.ts +134 -93
- package/src/trees/unbalanced_tree_store.ts +5 -1
- package/src/types/index.ts +5 -0
- package/dest/crypto/index.d.ts +0 -15
- package/dest/crypto/index.d.ts.map +0 -1
- package/dest/crypto/index.js +0 -14
- package/dest/fields/bls12_fields.d.ts.map +0 -1
- package/dest/fields/bls12_point.d.ts.map +0 -1
- package/dest/fields/coordinate.d.ts +0 -66
- package/dest/fields/coordinate.d.ts.map +0 -1
- package/dest/fields/coordinate.js +0 -96
- package/dest/fields/fields.d.ts +0 -174
- 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 -29
- package/dest/index.d.ts.map +0 -1
- package/dest/index.js +0 -29
- 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/src/crypto/index.ts +0 -14
- package/src/fields/coordinate.ts +0 -104
- package/src/fields/index.ts +0 -5
- package/src/index.ts +0 -29
- package/src/json-rpc/server/telemetry.ts +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { BarretenbergSync
|
|
1
|
+
import { BarretenbergSync } from '@aztec/bb.js';
|
|
2
2
|
|
|
3
|
-
import { Fr } from '../../../
|
|
3
|
+
import { Fr } from '../../../curves/bn254/field.js';
|
|
4
4
|
import { type Fieldable, serializeToFields } from '../../../serialize/serialize.js';
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -12,13 +12,11 @@ export function pedersenCommit(input: Buffer[], offset = 0) {
|
|
|
12
12
|
throw new Error('All Pedersen Commit input buffers must be <= 32 bytes.');
|
|
13
13
|
}
|
|
14
14
|
input = input.map(i => (i.length < 32 ? Buffer.concat([Buffer.alloc(32 - i.length, 0), i]) : i));
|
|
15
|
-
const
|
|
16
|
-
input
|
|
17
|
-
offset,
|
|
18
|
-
);
|
|
19
|
-
|
|
20
|
-
// TODO: rename toTypedArray()?
|
|
21
|
-
return [Buffer.from(point.x.toBuffer()), Buffer.from(point.y.toBuffer())];
|
|
15
|
+
const response = BarretenbergSync.getSingleton().pedersenCommit({
|
|
16
|
+
inputs: input,
|
|
17
|
+
hashIndex: offset,
|
|
18
|
+
});
|
|
19
|
+
return [Buffer.from(response.point.x), Buffer.from(response.point.y)];
|
|
22
20
|
}
|
|
23
21
|
|
|
24
22
|
/**
|
|
@@ -29,17 +27,20 @@ export function pedersenCommit(input: Buffer[], offset = 0) {
|
|
|
29
27
|
*/
|
|
30
28
|
export function pedersenHash(input: Fieldable[], index = 0): Fr {
|
|
31
29
|
const inputFields = serializeToFields(input);
|
|
32
|
-
const
|
|
33
|
-
inputFields.map(i =>
|
|
34
|
-
index,
|
|
35
|
-
);
|
|
36
|
-
return Fr.fromBuffer(Buffer.from(hash
|
|
30
|
+
const response = BarretenbergSync.getSingleton().pedersenHash({
|
|
31
|
+
inputs: inputFields.map(i => i.toBuffer()),
|
|
32
|
+
hashIndex: index,
|
|
33
|
+
});
|
|
34
|
+
return Fr.fromBuffer(Buffer.from(response.hash));
|
|
37
35
|
}
|
|
38
36
|
|
|
39
37
|
/**
|
|
40
38
|
* Create a pedersen hash from an arbitrary length buffer.
|
|
41
39
|
*/
|
|
42
40
|
export function pedersenHashBuffer(input: Buffer, index = 0) {
|
|
43
|
-
const
|
|
44
|
-
|
|
41
|
+
const response = BarretenbergSync.getSingleton().pedersenHashBuffer({
|
|
42
|
+
input,
|
|
43
|
+
hashIndex: index,
|
|
44
|
+
});
|
|
45
|
+
return Buffer.from(response.hash);
|
|
45
46
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { BarretenbergSync
|
|
1
|
+
import { BarretenbergSync } from '@aztec/bb.js';
|
|
2
2
|
|
|
3
|
-
import { Fr } from '../../../
|
|
3
|
+
import { Fr } from '../../../curves/bn254/field.js';
|
|
4
4
|
import { type Fieldable, serializeToFields } from '../../../serialize/serialize.js';
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -10,10 +10,11 @@ import { type Fieldable, serializeToFields } from '../../../serialize/serialize.
|
|
|
10
10
|
*/
|
|
11
11
|
export function poseidon2Hash(input: Fieldable[]): Fr {
|
|
12
12
|
const inputFields = serializeToFields(input);
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
const api = BarretenbergSync.getSingleton();
|
|
14
|
+
const response = api.poseidon2Hash({
|
|
15
|
+
inputs: inputFields.map(i => i.toBuffer()),
|
|
16
|
+
});
|
|
17
|
+
return Fr.fromBuffer(Buffer.from(response.hash));
|
|
17
18
|
}
|
|
18
19
|
|
|
19
20
|
/**
|
|
@@ -26,18 +27,20 @@ export function poseidon2HashWithSeparator(input: Fieldable[], separator: number
|
|
|
26
27
|
const inputFields = serializeToFields(input);
|
|
27
28
|
inputFields.unshift(new Fr(separator));
|
|
28
29
|
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
const api = BarretenbergSync.getSingleton();
|
|
31
|
+
const response = api.poseidon2Hash({
|
|
32
|
+
inputs: inputFields.map(i => i.toBuffer()),
|
|
33
|
+
});
|
|
34
|
+
return Fr.fromBuffer(Buffer.from(response.hash));
|
|
33
35
|
}
|
|
34
36
|
|
|
35
37
|
export function poseidon2HashAccumulate(input: Fieldable[]): Fr {
|
|
36
38
|
const inputFields = serializeToFields(input);
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
const api = BarretenbergSync.getSingleton();
|
|
40
|
+
const response = api.poseidon2HashAccumulate({
|
|
41
|
+
inputs: inputFields.map(i => i.toBuffer()),
|
|
42
|
+
});
|
|
43
|
+
return Fr.fromBuffer(Buffer.from(response.hash));
|
|
41
44
|
}
|
|
42
45
|
|
|
43
46
|
/**
|
|
@@ -49,12 +52,13 @@ export function poseidon2Permutation(input: Fieldable[]): Fr[] {
|
|
|
49
52
|
const inputFields = serializeToFields(input);
|
|
50
53
|
// We'd like this assertion but it's not possible to use it in the browser.
|
|
51
54
|
// assert(input.length === 4, 'Input state must be of size 4');
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
+
const api = BarretenbergSync.getSingleton();
|
|
56
|
+
const response = api.poseidon2Permutation({
|
|
57
|
+
inputs: inputFields.map(i => i.toBuffer()),
|
|
58
|
+
});
|
|
55
59
|
// We'd like this assertion but it's not possible to use it in the browser.
|
|
56
|
-
// assert(
|
|
57
|
-
return
|
|
60
|
+
// assert(response.outputs.length === 4, 'Output state must be of size 4');
|
|
61
|
+
return response.outputs.map(o => Fr.fromBuffer(Buffer.from(o)));
|
|
58
62
|
}
|
|
59
63
|
|
|
60
64
|
export function poseidon2HashBytes(input: Buffer): Fr {
|
|
@@ -68,9 +72,10 @@ export function poseidon2HashBytes(input: Buffer): Fr {
|
|
|
68
72
|
inputFields.push(Fr.fromBuffer(fieldBytes));
|
|
69
73
|
}
|
|
70
74
|
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
|
|
75
|
+
const api = BarretenbergSync.getSingleton();
|
|
76
|
+
const response = api.poseidon2Hash({
|
|
77
|
+
inputs: inputFields.map(i => i.toBuffer()),
|
|
78
|
+
});
|
|
74
79
|
|
|
75
|
-
return Fr.fromBuffer(Buffer.from(
|
|
80
|
+
return Fr.fromBuffer(Buffer.from(response.hash));
|
|
76
81
|
}
|
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
import { bls12_381 } from '@noble/curves/bls12-381';
|
|
3
3
|
import { inspect } from 'util';
|
|
4
4
|
|
|
5
|
-
import { toBigIntBE, toBufferBE } from '
|
|
6
|
-
import { randomBytes } from '
|
|
7
|
-
import { hexSchemaFor } from '
|
|
8
|
-
import { BufferReader } from '
|
|
9
|
-
import { TypeRegistry } from '
|
|
10
|
-
import { Fr } from '
|
|
5
|
+
import { toBigIntBE, toBufferBE } from '../../bigint-buffer/index.js';
|
|
6
|
+
import { randomBytes } from '../../crypto/random/index.js';
|
|
7
|
+
import { hexSchemaFor } from '../../schemas/utils.js';
|
|
8
|
+
import { BufferReader } from '../../serialize/buffer_reader.js';
|
|
9
|
+
import { TypeRegistry } from '../../serialize/type_registry.js';
|
|
10
|
+
import { Fr } from '../bn254/field.js';
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Represents a field derived from BLS12Field.
|
|
@@ -3,13 +3,13 @@ import type { ProjPointType } from '@noble/curves/abstract/weierstrass';
|
|
|
3
3
|
import { bls12_381 } from '@noble/curves/bls12-381';
|
|
4
4
|
import { inspect } from 'util';
|
|
5
5
|
|
|
6
|
-
import { toBufferBE } from '
|
|
7
|
-
import { randomBoolean } from '
|
|
8
|
-
import { hexSchemaFor } from '
|
|
9
|
-
import { BufferReader, serializeToBuffer } from '
|
|
10
|
-
import { bufferToHex, hexToBuffer } from '
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
6
|
+
import { toBufferBE } from '../../bigint-buffer/index.js';
|
|
7
|
+
import { randomBoolean } from '../../crypto/random/index.js';
|
|
8
|
+
import { hexSchemaFor } from '../../schemas/utils.js';
|
|
9
|
+
import { BufferReader, serializeToBuffer } from '../../serialize/index.js';
|
|
10
|
+
import { bufferToHex, hexToBuffer } from '../../string/index.js';
|
|
11
|
+
import { Fr } from '../bn254/field.js';
|
|
12
|
+
import { BLS12Fq, BLS12Fr } from './field.js';
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* Represents a Point on an elliptic curve with x and y coordinates.
|
|
@@ -158,13 +158,13 @@ export class BLS12Point {
|
|
|
158
158
|
}
|
|
159
159
|
|
|
160
160
|
/**
|
|
161
|
-
* Converts a Point to two BN254 Fr elements by storing its compressed form as:
|
|
162
|
-
*
|
|
163
|
-
* |
|
|
164
|
-
*
|
|
165
|
-
*
|
|
166
|
-
* |
|
|
167
|
-
*
|
|
161
|
+
* Converts a Point to two BN254 Fr elements by storing its compressed form (48 bytes) as:
|
|
162
|
+
* +-------------------+------------------------+
|
|
163
|
+
* | 31 bytes | 17 bytes |
|
|
164
|
+
* +-------------------+------------------------+
|
|
165
|
+
* | Field Element 1 | Field Element 2 |
|
|
166
|
+
* | [0][bytes 0-30] | [0...0][bytes 31-47] |
|
|
167
|
+
* +-------------------+------------------------+
|
|
168
168
|
* Used in the rollup circuits to store blob commitments in the native field type. See blob.ts.
|
|
169
169
|
* @param point - A BLS12Point instance.
|
|
170
170
|
* @returns The point fields.
|
|
@@ -2,13 +2,11 @@ import { BarretenbergSync } from '@aztec/bb.js';
|
|
|
2
2
|
|
|
3
3
|
import { inspect } from 'util';
|
|
4
4
|
|
|
5
|
-
import { toBigIntBE, toBufferBE } from '
|
|
6
|
-
import { randomBytes } from '
|
|
7
|
-
import { hexSchemaFor } from '
|
|
8
|
-
import { BufferReader } from '
|
|
9
|
-
import { TypeRegistry } from '
|
|
10
|
-
|
|
11
|
-
const ZERO_BUFFER = Buffer.alloc(32);
|
|
5
|
+
import { toBigIntBE, toBufferBE } from '../../bigint-buffer/index.js';
|
|
6
|
+
import { randomBytes } from '../../crypto/random/index.js';
|
|
7
|
+
import { hexSchemaFor } from '../../schemas/utils.js';
|
|
8
|
+
import { BufferReader } from '../../serialize/buffer_reader.js';
|
|
9
|
+
import { TypeRegistry } from '../../serialize/type_registry.js';
|
|
12
10
|
|
|
13
11
|
/* eslint-disable @typescript-eslint/no-unsafe-declaration-merging */
|
|
14
12
|
|
|
@@ -25,14 +23,12 @@ type DerivedField<T extends BaseField> = {
|
|
|
25
23
|
|
|
26
24
|
/**
|
|
27
25
|
* Base field class.
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
* We only check we are within the field modulus when initializing with bigint.
|
|
26
|
+
* Uses bigint as the internal representation.
|
|
27
|
+
* Buffers are generated on demand from the bigint value.
|
|
31
28
|
*/
|
|
32
29
|
abstract class BaseField {
|
|
33
30
|
static SIZE_IN_BYTES = 32;
|
|
34
|
-
private
|
|
35
|
-
private asBigInt?: bigint;
|
|
31
|
+
private readonly asBigInt: bigint;
|
|
36
32
|
|
|
37
33
|
/**
|
|
38
34
|
* Return bigint representation.
|
|
@@ -52,53 +48,41 @@ abstract class BaseField {
|
|
|
52
48
|
if (value.length > BaseField.SIZE_IN_BYTES) {
|
|
53
49
|
throw new Error(`Value length ${value.length} exceeds ${BaseField.SIZE_IN_BYTES}`);
|
|
54
50
|
}
|
|
55
|
-
this.
|
|
56
|
-
value.length === BaseField.SIZE_IN_BYTES
|
|
57
|
-
? value
|
|
58
|
-
: Buffer.concat([Buffer.alloc(BaseField.SIZE_IN_BYTES - value.length), value]);
|
|
51
|
+
this.asBigInt = toBigIntBE(value);
|
|
59
52
|
} else if (typeof value === 'bigint' || typeof value === 'number' || typeof value === 'boolean') {
|
|
60
53
|
this.asBigInt = BigInt(value);
|
|
61
|
-
if (this.asBigInt >= this.modulus()) {
|
|
62
|
-
throw new Error(`Value 0x${this.asBigInt.toString(16)} is greater or equal to field modulus.`);
|
|
63
|
-
} else if (this.asBigInt < 0n) {
|
|
64
|
-
throw new Error(`Value 0x${this.asBigInt.toString(16)} is negative.`);
|
|
65
|
-
}
|
|
66
54
|
} else if (value instanceof BaseField) {
|
|
67
|
-
this.asBuffer = value.asBuffer;
|
|
68
55
|
this.asBigInt = value.asBigInt;
|
|
69
56
|
} else {
|
|
70
57
|
throw new Error(`Type '${typeof value}' with value '${value}' passed to BaseField ctor.`);
|
|
71
58
|
}
|
|
59
|
+
|
|
60
|
+
if (this.asBigInt < 0n) {
|
|
61
|
+
throw new Error(`Value 0x${this.asBigInt.toString(16)} is negative.`);
|
|
62
|
+
} else if (this.asBigInt >= this.modulus()) {
|
|
63
|
+
throw new Error(`Value 0x${this.asBigInt.toString(16)} is greater or equal to field modulus.`);
|
|
64
|
+
}
|
|
72
65
|
}
|
|
73
66
|
|
|
74
67
|
protected abstract modulus(): bigint;
|
|
75
68
|
|
|
76
69
|
/**
|
|
77
|
-
*
|
|
70
|
+
* Converts the bigint to a Buffer.
|
|
78
71
|
*/
|
|
79
72
|
toBuffer(): Buffer {
|
|
80
|
-
|
|
81
|
-
this.asBuffer = toBufferBE(this.asBigInt!, 32);
|
|
82
|
-
}
|
|
83
|
-
return Buffer.from(this.asBuffer);
|
|
73
|
+
return toBufferBE(this.asBigInt, 32);
|
|
84
74
|
}
|
|
85
75
|
|
|
86
76
|
toString(): `0x${string}` {
|
|
87
|
-
return `0x${this.
|
|
77
|
+
return `0x${this.asBigInt.toString(16).padStart(64, '0')}`;
|
|
88
78
|
}
|
|
89
79
|
|
|
90
80
|
toBigInt(): bigint {
|
|
91
|
-
if (this.asBigInt === undefined) {
|
|
92
|
-
this.asBigInt = toBigIntBE(this.asBuffer!);
|
|
93
|
-
if (this.asBigInt >= this.modulus()) {
|
|
94
|
-
throw new Error(`Value 0x${this.asBigInt.toString(16)} is greater or equal to field modulus.`);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
81
|
return this.asBigInt;
|
|
98
82
|
}
|
|
99
83
|
|
|
100
84
|
toBool(): boolean {
|
|
101
|
-
return
|
|
85
|
+
return this.asBigInt !== 0n;
|
|
102
86
|
}
|
|
103
87
|
|
|
104
88
|
/**
|
|
@@ -106,11 +90,10 @@ abstract class BaseField {
|
|
|
106
90
|
* Throws if the underlying value is greater than MAX_SAFE_INTEGER.
|
|
107
91
|
*/
|
|
108
92
|
toNumber(): number {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
throw new Error(`Value ${value.toString(16)} greater than than max safe integer`);
|
|
93
|
+
if (this.asBigInt > Number.MAX_SAFE_INTEGER) {
|
|
94
|
+
throw new Error(`Value ${this.asBigInt.toString(16)} greater than than max safe integer`);
|
|
112
95
|
}
|
|
113
|
-
return Number(
|
|
96
|
+
return Number(this.asBigInt);
|
|
114
97
|
}
|
|
115
98
|
|
|
116
99
|
/**
|
|
@@ -118,8 +101,7 @@ abstract class BaseField {
|
|
|
118
101
|
* May cause loss of precision if the underlying value is greater than MAX_SAFE_INTEGER.
|
|
119
102
|
*/
|
|
120
103
|
toNumberUnsafe(): number {
|
|
121
|
-
|
|
122
|
-
return Number(value);
|
|
104
|
+
return Number(this.asBigInt);
|
|
123
105
|
}
|
|
124
106
|
|
|
125
107
|
toShortString(): string {
|
|
@@ -128,21 +110,24 @@ abstract class BaseField {
|
|
|
128
110
|
}
|
|
129
111
|
|
|
130
112
|
equals(rhs: BaseField): boolean {
|
|
131
|
-
return this.
|
|
113
|
+
return this.asBigInt === rhs.asBigInt;
|
|
132
114
|
}
|
|
133
115
|
|
|
134
116
|
lt(rhs: BaseField): boolean {
|
|
135
|
-
return this.
|
|
117
|
+
return this.asBigInt < rhs.asBigInt;
|
|
136
118
|
}
|
|
137
119
|
|
|
138
120
|
cmp(rhs: BaseField): -1 | 0 | 1 {
|
|
139
|
-
const
|
|
140
|
-
|
|
141
|
-
|
|
121
|
+
const rhsBigInt = rhs.asBigInt;
|
|
122
|
+
return this.asBigInt === rhsBigInt ? 0 : this.asBigInt < rhsBigInt ? -1 : 1;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
static cmp(lhs: BaseField, rhs: BaseField): -1 | 0 | 1 {
|
|
126
|
+
return lhs.cmp(rhs);
|
|
142
127
|
}
|
|
143
128
|
|
|
144
129
|
isZero(): boolean {
|
|
145
|
-
return this.
|
|
130
|
+
return this.asBigInt === 0n;
|
|
146
131
|
}
|
|
147
132
|
|
|
148
133
|
isEmpty(): boolean {
|
|
@@ -195,7 +180,7 @@ function fromHexString<T extends BaseField>(buf: string, f: DerivedField<T>) {
|
|
|
195
180
|
|
|
196
181
|
const buffer = Buffer.from(checked.length % 2 === 1 ? '0' + checked : checked, 'hex');
|
|
197
182
|
|
|
198
|
-
return new f(buffer);
|
|
183
|
+
return new f(toBigIntBE(buffer));
|
|
199
184
|
}
|
|
200
185
|
|
|
201
186
|
/** Branding to ensure fields are not interchangeable types. */
|
|
@@ -321,22 +306,37 @@ export class Fr extends BaseField {
|
|
|
321
306
|
* @returns A square root of the field element (null if it does not exist).
|
|
322
307
|
*/
|
|
323
308
|
async sqrt(): Promise<Fr | null> {
|
|
324
|
-
|
|
325
|
-
const
|
|
326
|
-
const
|
|
327
|
-
|
|
328
|
-
if (!isSqrt) {
|
|
309
|
+
await BarretenbergSync.initSingleton();
|
|
310
|
+
const api = BarretenbergSync.getSingleton();
|
|
311
|
+
const response = api.bn254FrSqrt({ input: this.toBuffer() });
|
|
312
|
+
if (!response.isSquareRoot) {
|
|
329
313
|
// Field element is not a quadratic residue mod p so it has no square root.
|
|
330
314
|
return null;
|
|
331
315
|
}
|
|
332
|
-
return
|
|
316
|
+
return Fr.fromBuffer(Buffer.from(response.value));
|
|
333
317
|
}
|
|
334
318
|
|
|
335
319
|
toJSON() {
|
|
336
320
|
return this.toString();
|
|
337
321
|
}
|
|
338
322
|
|
|
323
|
+
/**
|
|
324
|
+
* Creates an Fr instance from a plain object without Zod validation.
|
|
325
|
+
* This method is optimized for performance and skips validation, making it suitable
|
|
326
|
+
* for deserializing trusted data (e.g., from C++ via MessagePack).
|
|
327
|
+
* Handles buffers, strings, numbers, bigints, or existing instances.
|
|
328
|
+
* @param obj - Plain object, buffer, string, number, bigint, boolean, or Fr instance
|
|
329
|
+
* @returns An Fr instance
|
|
330
|
+
*/
|
|
331
|
+
static fromPlainObject(obj: any): Fr {
|
|
332
|
+
if (obj instanceof Fr) {
|
|
333
|
+
return obj;
|
|
334
|
+
}
|
|
335
|
+
return new Fr(obj);
|
|
336
|
+
}
|
|
337
|
+
|
|
339
338
|
static get schema() {
|
|
339
|
+
// Serialization from hex string.
|
|
340
340
|
return hexSchemaFor(Fr);
|
|
341
341
|
}
|
|
342
342
|
}
|
|
@@ -435,6 +435,21 @@ export class Fq extends BaseField {
|
|
|
435
435
|
return new Fq((this.toBigInt() + rhs.toBigInt()) % Fq.MODULUS);
|
|
436
436
|
}
|
|
437
437
|
|
|
438
|
+
/**
|
|
439
|
+
* Computes a square root of the field element.
|
|
440
|
+
* @returns A square root of the field element (null if it does not exist).
|
|
441
|
+
*/
|
|
442
|
+
async sqrt(): Promise<Fq | null> {
|
|
443
|
+
await BarretenbergSync.initSingleton();
|
|
444
|
+
const api = BarretenbergSync.getSingleton();
|
|
445
|
+
const response = api.bn254FqSqrt({ input: this.toBuffer() });
|
|
446
|
+
if (!response.isSquareRoot) {
|
|
447
|
+
// Field element is not a quadratic residue mod p so it has no square root.
|
|
448
|
+
return null;
|
|
449
|
+
}
|
|
450
|
+
return Fq.fromBuffer(Buffer.from(response.value));
|
|
451
|
+
}
|
|
452
|
+
|
|
438
453
|
toJSON() {
|
|
439
454
|
return this.toString();
|
|
440
455
|
}
|
|
@@ -481,14 +496,6 @@ function extendedEuclidean(a: bigint, modulus: bigint): [bigint, bigint, bigint]
|
|
|
481
496
|
}
|
|
482
497
|
}
|
|
483
498
|
|
|
484
|
-
/**
|
|
485
|
-
* GrumpkinScalar is an Fq.
|
|
486
|
-
* @remarks Called GrumpkinScalar because it is used to represent elements in Grumpkin's scalar field as defined in
|
|
487
|
-
* the Aztec Protocol Specs.
|
|
488
|
-
*/
|
|
489
|
-
export type GrumpkinScalar = Fq;
|
|
490
|
-
export const GrumpkinScalar = Fq;
|
|
491
|
-
|
|
492
499
|
/** Wraps a function that returns a buffer so that all results are reduced into a field of the given type. */
|
|
493
500
|
export function reduceFn<TInput, TField extends BaseField>(fn: (input: TInput) => Buffer, field: DerivedField<TField>) {
|
|
494
501
|
return (input: TInput) => fromBufferReduce(fn(input), field);
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BN254_G1_GENERATOR,
|
|
3
|
+
BN254_G2_GENERATOR,
|
|
4
|
+
BarretenbergSync,
|
|
5
|
+
type Bn254G1Point as BbApiBn254G1Point,
|
|
6
|
+
type Bn254G2Point as BbApiBn254G2Point,
|
|
7
|
+
} from '@aztec/bb.js';
|
|
8
|
+
|
|
9
|
+
import { Fq, Fr } from './field.js';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* BN254 G1 point using foundation field classes.
|
|
13
|
+
* Represents a point on the BN254 elliptic curve in affine coordinates.
|
|
14
|
+
*/
|
|
15
|
+
export class Bn254G1Point {
|
|
16
|
+
constructor(
|
|
17
|
+
public readonly x: Fq,
|
|
18
|
+
public readonly y: Fq,
|
|
19
|
+
) {}
|
|
20
|
+
|
|
21
|
+
private toBbApiPoint(): BbApiBn254G1Point {
|
|
22
|
+
return {
|
|
23
|
+
x: this.x.toBuffer(),
|
|
24
|
+
y: this.y.toBuffer(),
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
private static fromBbApiPoint(point: BbApiBn254G1Point): Bn254G1Point {
|
|
29
|
+
return new Bn254G1Point(Fq.fromBuffer(Buffer.from(point.x)), Fq.fromBuffer(Buffer.from(point.y)));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async isOnCurve(): Promise<boolean> {
|
|
33
|
+
await BarretenbergSync.initSingleton();
|
|
34
|
+
const api = BarretenbergSync.getSingleton();
|
|
35
|
+
|
|
36
|
+
const apiPoint = this.toBbApiPoint();
|
|
37
|
+
const response = api.bn254G1IsOnCurve({ point: apiPoint });
|
|
38
|
+
return response.isOnCurve;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Get the generator point for BN254 G1, or perform scalar multiplication.
|
|
43
|
+
* When called without arguments, returns the base generator point.
|
|
44
|
+
* When called with a scalar, returns scalar * generator (useful for public key derivation).
|
|
45
|
+
*/
|
|
46
|
+
static async generator(scalar?: Fr): Promise<Bn254G1Point> {
|
|
47
|
+
if (!scalar) {
|
|
48
|
+
return new Bn254G1Point(
|
|
49
|
+
Fq.fromBuffer(Buffer.from(BN254_G1_GENERATOR.x)),
|
|
50
|
+
Fq.fromBuffer(Buffer.from(BN254_G1_GENERATOR.y)),
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
await BarretenbergSync.initSingleton();
|
|
55
|
+
const api = BarretenbergSync.getSingleton();
|
|
56
|
+
|
|
57
|
+
const response = api.bn254G1Mul({
|
|
58
|
+
point: BN254_G1_GENERATOR,
|
|
59
|
+
scalar: scalar.toBuffer(),
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
return Bn254G1Point.fromBbApiPoint(response.point);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Decompress a BN254 G1 point from compressed form (32 bytes).
|
|
67
|
+
* The compressed format encodes the x-coordinate and the sign bit of the y-coordinate
|
|
68
|
+
* in the most significant bit.
|
|
69
|
+
*/
|
|
70
|
+
static async fromCompressed(compressed: Buffer): Promise<Bn254G1Point> {
|
|
71
|
+
if (compressed.length !== 32) {
|
|
72
|
+
throw new Error('Invalid compressed point length');
|
|
73
|
+
}
|
|
74
|
+
await BarretenbergSync.initSingleton();
|
|
75
|
+
const api = BarretenbergSync.getSingleton();
|
|
76
|
+
|
|
77
|
+
const response = api.bn254G1FromCompressed({
|
|
78
|
+
compressed: new Uint8Array(compressed),
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
return Bn254G1Point.fromBbApiPoint(response.point);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Compress this BN254 G1 point to 32 bytes.
|
|
86
|
+
* The compressed format encodes the x-coordinate and the sign bit of the y-coordinate
|
|
87
|
+
* in the most significant bit (bit 255).
|
|
88
|
+
*/
|
|
89
|
+
compress(): Buffer {
|
|
90
|
+
const xBytes = this.x.toBuffer();
|
|
91
|
+
// Get the least significant bit of y to determine the sign
|
|
92
|
+
const yLsb = this.y.toBigInt() & 1n;
|
|
93
|
+
// If y is odd, set the most significant bit (bit 255) of the output
|
|
94
|
+
if (yLsb === 1n) {
|
|
95
|
+
xBytes[0] |= 0x80;
|
|
96
|
+
}
|
|
97
|
+
return xBytes;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
equals(other: Bn254G1Point): boolean {
|
|
101
|
+
return this.x.equals(other.x) && this.y.equals(other.y);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
toString(): string {
|
|
105
|
+
return `Bn254G1Point(x: ${this.x.toString()}, y: ${this.y.toString()})`;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* BN254 G2 point using foundation field classes.
|
|
111
|
+
* Represents a point on the BN254 G2 curve (twist curve) in affine coordinates.
|
|
112
|
+
* G2 points use extension field coordinates (Fq2).
|
|
113
|
+
*/
|
|
114
|
+
export class Bn254G2Point {
|
|
115
|
+
constructor(
|
|
116
|
+
public readonly x: [Fq, Fq],
|
|
117
|
+
public readonly y: [Fq, Fq],
|
|
118
|
+
) {}
|
|
119
|
+
|
|
120
|
+
private toBbApiPoint(): BbApiBn254G2Point {
|
|
121
|
+
return {
|
|
122
|
+
x: [this.x[0].toBuffer(), this.x[1].toBuffer()],
|
|
123
|
+
y: [this.y[0].toBuffer(), this.y[1].toBuffer()],
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
private static fromBbApiPoint(point: BbApiBn254G2Point): Bn254G2Point {
|
|
128
|
+
return new Bn254G2Point(
|
|
129
|
+
[Fq.fromBuffer(Buffer.from(point.x[0])), Fq.fromBuffer(Buffer.from(point.x[1]))],
|
|
130
|
+
[Fq.fromBuffer(Buffer.from(point.y[0])), Fq.fromBuffer(Buffer.from(point.y[1]))],
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Get the generator point for BN254 G2, or perform scalar multiplication.
|
|
136
|
+
* When called without arguments, returns the base generator point.
|
|
137
|
+
* When called with a scalar, returns scalar * generator.
|
|
138
|
+
*/
|
|
139
|
+
static async generator(scalar?: Fr): Promise<Bn254G2Point> {
|
|
140
|
+
if (!scalar) {
|
|
141
|
+
return new Bn254G2Point(
|
|
142
|
+
[Fq.fromBuffer(Buffer.from(BN254_G2_GENERATOR.x[0])), Fq.fromBuffer(Buffer.from(BN254_G2_GENERATOR.x[1]))],
|
|
143
|
+
[Fq.fromBuffer(Buffer.from(BN254_G2_GENERATOR.y[0])), Fq.fromBuffer(Buffer.from(BN254_G2_GENERATOR.y[1]))],
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
await BarretenbergSync.initSingleton();
|
|
148
|
+
const api = BarretenbergSync.getSingleton();
|
|
149
|
+
|
|
150
|
+
const response = api.bn254G2Mul({
|
|
151
|
+
point: BN254_G2_GENERATOR as BbApiBn254G2Point,
|
|
152
|
+
scalar: scalar.toBuffer(),
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
return Bn254G2Point.fromBbApiPoint(response.point);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
equals(other: Bn254G2Point): boolean {
|
|
159
|
+
return (
|
|
160
|
+
this.x[0].equals(other.x[0]) &&
|
|
161
|
+
this.x[1].equals(other.x[1]) &&
|
|
162
|
+
this.y[0].equals(other.y[0]) &&
|
|
163
|
+
this.y[1].equals(other.y[1])
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
toString(): string {
|
|
168
|
+
return `Bn254G2Point(x: (${this.x[0].toString()}, ${this.x[1].toString()}), y: (${this.y[0].toString()}, ${this.y[1].toString()}))`;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Fq } from '../bn254/field.js';
|
|
2
|
+
|
|
3
|
+
export * from './point.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* GrumpkinScalar is an Fq.
|
|
7
|
+
* @remarks Called GrumpkinScalar because it is used to represent elements in Grumpkin's scalar field as defined in
|
|
8
|
+
* the Aztec Protocol Specs.
|
|
9
|
+
*/
|
|
10
|
+
export type GrumpkinScalar = Fq;
|
|
11
|
+
export const GrumpkinScalar = Fq;
|