@aztec/foundation 4.0.0-nightly.20250907 → 4.0.0-nightly.20260108
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
1
|
import { toBufferBE } from '@aztec/foundation/bigint-buffer';
|
|
2
|
-
import { randomBytes } from '@aztec/foundation/crypto';
|
|
3
|
-
import { Fr } from '@aztec/foundation/
|
|
2
|
+
import { randomBytes } from '@aztec/foundation/crypto/random';
|
|
3
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
4
4
|
import { mapTuple } from '@aztec/foundation/serialize';
|
|
5
5
|
|
|
6
6
|
import type { Signature } from '../signature/index.js';
|
|
@@ -1,36 +1,34 @@
|
|
|
1
1
|
import { BarretenbergSync } from '@aztec/bb.js';
|
|
2
|
-
import { Fr
|
|
2
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
|
+
import type { GrumpkinScalar } from '@aztec/foundation/curves/grumpkin';
|
|
4
|
+
import { Point } from '@aztec/foundation/curves/grumpkin';
|
|
3
5
|
|
|
4
6
|
/**
|
|
5
7
|
* Grumpkin elliptic curve operations.
|
|
6
8
|
*/
|
|
7
9
|
export class Grumpkin {
|
|
8
10
|
// prettier-ignore
|
|
9
|
-
static generator = Point.fromBuffer(Buffer.from([
|
|
11
|
+
static readonly generator = Point.fromBuffer(Buffer.from([
|
|
10
12
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
11
13
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
|
|
12
14
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xcf, 0x13, 0x5e, 0x75, 0x06, 0xa4, 0x5d, 0x63,
|
|
13
15
|
0x2d, 0x27, 0x0d, 0x45, 0xf1, 0x18, 0x12, 0x94, 0x83, 0x3f, 0xc4, 0x8d, 0x82, 0x3f, 0x27, 0x2c,
|
|
14
16
|
]));
|
|
15
17
|
|
|
16
|
-
/**
|
|
17
|
-
* Point generator
|
|
18
|
-
* @returns The generator for the curve.
|
|
19
|
-
*/
|
|
20
|
-
public generator(): Point {
|
|
21
|
-
return Grumpkin.generator;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
18
|
/**
|
|
25
19
|
* Multiplies a point by a scalar (adds the point `scalar` amount of times).
|
|
26
20
|
* @param point - Point to multiply.
|
|
27
21
|
* @param scalar - Scalar to multiply by.
|
|
28
22
|
* @returns Result of the multiplication.
|
|
29
23
|
*/
|
|
30
|
-
public async mul(point: Point, scalar: GrumpkinScalar): Promise<Point> {
|
|
31
|
-
|
|
32
|
-
const
|
|
33
|
-
|
|
24
|
+
public static async mul(point: Point, scalar: GrumpkinScalar): Promise<Point> {
|
|
25
|
+
await BarretenbergSync.initSingleton();
|
|
26
|
+
const api = BarretenbergSync.getSingleton();
|
|
27
|
+
const response = api.grumpkinMul({
|
|
28
|
+
point: { x: point.x.toBuffer(), y: point.y.toBuffer() },
|
|
29
|
+
scalar: scalar.toBuffer(),
|
|
30
|
+
});
|
|
31
|
+
return Point.fromBuffer(Buffer.concat([Buffer.from(response.point.x), Buffer.from(response.point.y)]));
|
|
34
32
|
}
|
|
35
33
|
|
|
36
34
|
/**
|
|
@@ -39,10 +37,14 @@ export class Grumpkin {
|
|
|
39
37
|
* @param b - Point b to add to a
|
|
40
38
|
* @returns Result of the addition.
|
|
41
39
|
*/
|
|
42
|
-
public async add(a: Point, b: Point): Promise<Point> {
|
|
43
|
-
|
|
44
|
-
const
|
|
45
|
-
|
|
40
|
+
public static async add(a: Point, b: Point): Promise<Point> {
|
|
41
|
+
await BarretenbergSync.initSingleton();
|
|
42
|
+
const api = BarretenbergSync.getSingleton();
|
|
43
|
+
const response = api.grumpkinAdd({
|
|
44
|
+
pointA: { x: a.x.toBuffer(), y: a.y.toBuffer() },
|
|
45
|
+
pointB: { x: b.x.toBuffer(), y: b.y.toBuffer() },
|
|
46
|
+
});
|
|
47
|
+
return Point.fromBuffer(Buffer.concat([Buffer.from(response.point.x), Buffer.from(response.point.y)]));
|
|
46
48
|
}
|
|
47
49
|
|
|
48
50
|
/**
|
|
@@ -51,35 +53,26 @@ export class Grumpkin {
|
|
|
51
53
|
* @param scalar - Scalar to multiply by.
|
|
52
54
|
* @returns Points multiplied by the scalar.
|
|
53
55
|
*/
|
|
54
|
-
public async batchMul(points: Point[], scalar: GrumpkinScalar) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
.getWasm()
|
|
62
|
-
.callWasmExport(
|
|
63
|
-
'ecc_grumpkin__batch_mul',
|
|
64
|
-
[concatenatedPoints, scalar.toBuffer(), points.length],
|
|
65
|
-
[pointsByteLength],
|
|
66
|
-
);
|
|
56
|
+
public static async batchMul(points: Point[], scalar: GrumpkinScalar) {
|
|
57
|
+
await BarretenbergSync.initSingleton();
|
|
58
|
+
const api = BarretenbergSync.getSingleton();
|
|
59
|
+
const response = api.grumpkinBatchMul({
|
|
60
|
+
points: points.map(p => ({ x: p.x.toBuffer(), y: p.y.toBuffer() })),
|
|
61
|
+
scalar: scalar.toBuffer(),
|
|
62
|
+
});
|
|
67
63
|
|
|
68
|
-
|
|
69
|
-
for (let i = 0; i < pointsByteLength; i += 64) {
|
|
70
|
-
parsedResult.push(Point.fromBuffer(Buffer.from(result.subarray(i, i + 64))));
|
|
71
|
-
}
|
|
72
|
-
return parsedResult;
|
|
64
|
+
return response.points.map(p => Point.fromBuffer(Buffer.concat([Buffer.from(p.x), Buffer.from(p.y)])));
|
|
73
65
|
}
|
|
74
66
|
|
|
75
67
|
/**
|
|
76
68
|
* Gets a random field element.
|
|
77
69
|
* @returns Random field element.
|
|
78
70
|
*/
|
|
79
|
-
public async getRandomFr(): Promise<Fr> {
|
|
80
|
-
|
|
81
|
-
const
|
|
82
|
-
|
|
71
|
+
public static async getRandomFr(): Promise<Fr> {
|
|
72
|
+
await BarretenbergSync.initSingleton();
|
|
73
|
+
const api = BarretenbergSync.getSingleton();
|
|
74
|
+
const response = api.grumpkinGetRandomFr({ dummy: 0 });
|
|
75
|
+
return Fr.fromBuffer(Buffer.from(response.value));
|
|
83
76
|
}
|
|
84
77
|
|
|
85
78
|
/**
|
|
@@ -87,11 +80,10 @@ export class Grumpkin {
|
|
|
87
80
|
* @param uint512Buf - The buffer to convert.
|
|
88
81
|
* @returns Buffer representation of the field element.
|
|
89
82
|
*/
|
|
90
|
-
public async reduce512BufferToFr(uint512Buf: Buffer): Promise<Fr> {
|
|
91
|
-
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
return Fr.fromBuffer(Buffer.from(result));
|
|
83
|
+
public static async reduce512BufferToFr(uint512Buf: Buffer): Promise<Fr> {
|
|
84
|
+
await BarretenbergSync.initSingleton();
|
|
85
|
+
const api = BarretenbergSync.getSingleton();
|
|
86
|
+
const response = api.grumpkinReduce512({ input: uint512Buf });
|
|
87
|
+
return Fr.fromBuffer(Buffer.from(response.value));
|
|
96
88
|
}
|
|
97
89
|
}
|
package/src/crypto/keys/index.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
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
|
|
|
5
5
|
export async function vkAsFieldsMegaHonk(input: Buffer): Promise<Fr[]> {
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
return
|
|
6
|
+
await BarretenbergSync.initSingleton();
|
|
7
|
+
const api = BarretenbergSync.getSingleton();
|
|
8
|
+
const response = api.megaVkAsFields({ verificationKey: input });
|
|
9
|
+
return response.fields.map(field => Fr.fromBuffer(Buffer.from(field)));
|
|
10
10
|
}
|
|
@@ -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,14 +12,13 @@ export async 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
|
-
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
return [Buffer.from(point.x.toBuffer()), Buffer.from(point.y.toBuffer())];
|
|
15
|
+
await BarretenbergSync.initSingleton();
|
|
16
|
+
const api = BarretenbergSync.getSingleton();
|
|
17
|
+
const response = api.pedersenCommit({
|
|
18
|
+
inputs: input,
|
|
19
|
+
hashIndex: offset,
|
|
20
|
+
});
|
|
21
|
+
return [Buffer.from(response.point.x), Buffer.from(response.point.y)];
|
|
23
22
|
}
|
|
24
23
|
|
|
25
24
|
/**
|
|
@@ -30,19 +29,24 @@ export async function pedersenCommit(input: Buffer[], offset = 0) {
|
|
|
30
29
|
*/
|
|
31
30
|
export async function pedersenHash(input: Fieldable[], index = 0): Promise<Fr> {
|
|
32
31
|
const inputFields = serializeToFields(input);
|
|
33
|
-
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
32
|
+
await BarretenbergSync.initSingleton();
|
|
33
|
+
const api = BarretenbergSync.getSingleton();
|
|
34
|
+
const response = api.pedersenHash({
|
|
35
|
+
inputs: inputFields.map(i => i.toBuffer()),
|
|
36
|
+
hashIndex: index,
|
|
37
|
+
});
|
|
38
|
+
return Fr.fromBuffer(Buffer.from(response.hash));
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
/**
|
|
42
42
|
* Create a pedersen hash from an arbitrary length buffer.
|
|
43
43
|
*/
|
|
44
44
|
export async function pedersenHashBuffer(input: Buffer, index = 0) {
|
|
45
|
-
|
|
46
|
-
const
|
|
47
|
-
|
|
45
|
+
await BarretenbergSync.initSingleton();
|
|
46
|
+
const api = BarretenbergSync.getSingleton();
|
|
47
|
+
const response = api.pedersenHashBuffer({
|
|
48
|
+
input,
|
|
49
|
+
hashIndex: index,
|
|
50
|
+
});
|
|
51
|
+
return Buffer.from(response.hash);
|
|
48
52
|
}
|
|
@@ -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,11 +10,12 @@ import { type Fieldable, serializeToFields } from '../../serialize/serialize.js'
|
|
|
10
10
|
*/
|
|
11
11
|
export async function poseidon2Hash(input: Fieldable[]): Promise<Fr> {
|
|
12
12
|
const inputFields = serializeToFields(input);
|
|
13
|
-
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
await BarretenbergSync.initSingleton();
|
|
14
|
+
const api = BarretenbergSync.getSingleton();
|
|
15
|
+
const response = api.poseidon2Hash({
|
|
16
|
+
inputs: inputFields.map(i => i.toBuffer()),
|
|
17
|
+
});
|
|
18
|
+
return Fr.fromBuffer(Buffer.from(response.hash));
|
|
18
19
|
}
|
|
19
20
|
|
|
20
21
|
/**
|
|
@@ -26,19 +27,22 @@ export async function poseidon2Hash(input: Fieldable[]): Promise<Fr> {
|
|
|
26
27
|
export async function poseidon2HashWithSeparator(input: Fieldable[], separator: number): Promise<Fr> {
|
|
27
28
|
const inputFields = serializeToFields(input);
|
|
28
29
|
inputFields.unshift(new Fr(separator));
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
const
|
|
32
|
-
inputFields.map(i =>
|
|
33
|
-
);
|
|
34
|
-
return Fr.fromBuffer(Buffer.from(hash
|
|
30
|
+
await BarretenbergSync.initSingleton();
|
|
31
|
+
const api = BarretenbergSync.getSingleton();
|
|
32
|
+
const response = api.poseidon2Hash({
|
|
33
|
+
inputs: inputFields.map(i => i.toBuffer()),
|
|
34
|
+
});
|
|
35
|
+
return Fr.fromBuffer(Buffer.from(response.hash));
|
|
35
36
|
}
|
|
36
37
|
|
|
37
38
|
export async function poseidon2HashAccumulate(input: Fieldable[]): Promise<Fr> {
|
|
38
39
|
const inputFields = serializeToFields(input);
|
|
39
|
-
|
|
40
|
-
const
|
|
41
|
-
|
|
40
|
+
await BarretenbergSync.initSingleton();
|
|
41
|
+
const api = BarretenbergSync.getSingleton();
|
|
42
|
+
const response = api.poseidon2HashAccumulate({
|
|
43
|
+
inputs: inputFields.map(i => i.toBuffer()),
|
|
44
|
+
});
|
|
45
|
+
return Fr.fromBuffer(Buffer.from(response.hash));
|
|
42
46
|
}
|
|
43
47
|
|
|
44
48
|
/**
|
|
@@ -50,11 +54,14 @@ export async function poseidon2Permutation(input: Fieldable[]): Promise<Fr[]> {
|
|
|
50
54
|
const inputFields = serializeToFields(input);
|
|
51
55
|
// We'd like this assertion but it's not possible to use it in the browser.
|
|
52
56
|
// assert(input.length === 4, 'Input state must be of size 4');
|
|
53
|
-
|
|
54
|
-
const
|
|
57
|
+
await BarretenbergSync.initSingleton();
|
|
58
|
+
const api = BarretenbergSync.getSingleton();
|
|
59
|
+
const response = api.poseidon2Permutation({
|
|
60
|
+
inputs: inputFields.map(i => i.toBuffer()),
|
|
61
|
+
});
|
|
55
62
|
// We'd like this assertion but it's not possible to use it in the browser.
|
|
56
|
-
// assert(
|
|
57
|
-
return
|
|
63
|
+
// assert(response.outputs.length === 4, 'Output state must be of size 4');
|
|
64
|
+
return response.outputs.map(o => Fr.fromBuffer(Buffer.from(o)));
|
|
58
65
|
}
|
|
59
66
|
|
|
60
67
|
export async function poseidon2HashBytes(input: Buffer): Promise<Fr> {
|
|
@@ -68,10 +75,11 @@ export async function poseidon2HashBytes(input: Buffer): Promise<Fr> {
|
|
|
68
75
|
inputFields.push(Fr.fromBuffer(fieldBytes));
|
|
69
76
|
}
|
|
70
77
|
|
|
71
|
-
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
78
|
+
await BarretenbergSync.initSingleton();
|
|
79
|
+
const api = BarretenbergSync.getSingleton();
|
|
80
|
+
const response = api.poseidon2Hash({
|
|
81
|
+
inputs: inputFields.map(i => i.toBuffer()),
|
|
82
|
+
});
|
|
75
83
|
|
|
76
|
-
return Fr.fromBuffer(Buffer.from(
|
|
84
|
+
return Fr.fromBuffer(Buffer.from(response.hash));
|
|
77
85
|
}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { BarretenbergSync } from '@aztec/bb.js';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import type { GrumpkinScalar } from '@aztec/foundation/curves/grumpkin';
|
|
3
|
+
import { Point } from '@aztec/foundation/curves/grumpkin';
|
|
4
4
|
|
|
5
|
-
import { concatenateUint8Arrays } from '../serialize.js';
|
|
6
5
|
import { SchnorrSignature } from './signature.js';
|
|
7
6
|
|
|
8
7
|
export * from './signature.js';
|
|
@@ -17,9 +16,10 @@ export class Schnorr {
|
|
|
17
16
|
* @returns A grumpkin public key.
|
|
18
17
|
*/
|
|
19
18
|
public async computePublicKey(privateKey: GrumpkinScalar): Promise<Point> {
|
|
20
|
-
|
|
21
|
-
const
|
|
22
|
-
|
|
19
|
+
await BarretenbergSync.initSingleton();
|
|
20
|
+
const api = BarretenbergSync.getSingleton();
|
|
21
|
+
const response = api.schnorrComputePublicKey({ privateKey: privateKey.toBuffer() });
|
|
22
|
+
return Point.fromBuffer(Buffer.concat([Buffer.from(response.publicKey.x), Buffer.from(response.publicKey.y)]));
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
/**
|
|
@@ -29,12 +29,13 @@ export class Schnorr {
|
|
|
29
29
|
* @returns A Schnorr signature of the form (s, e).
|
|
30
30
|
*/
|
|
31
31
|
public async constructSignature(msg: Uint8Array, privateKey: GrumpkinScalar) {
|
|
32
|
-
|
|
33
|
-
const
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
32
|
+
await BarretenbergSync.initSingleton();
|
|
33
|
+
const api = BarretenbergSync.getSingleton();
|
|
34
|
+
const response = api.schnorrConstructSignature({
|
|
35
|
+
message: msg,
|
|
36
|
+
privateKey: privateKey.toBuffer(),
|
|
37
|
+
});
|
|
38
|
+
return new SchnorrSignature(Buffer.from([...response.s, ...response.e]));
|
|
38
39
|
}
|
|
39
40
|
|
|
40
41
|
/**
|
|
@@ -45,11 +46,14 @@ export class Schnorr {
|
|
|
45
46
|
* @returns True or false.
|
|
46
47
|
*/
|
|
47
48
|
public async verifySignature(msg: Uint8Array, pubKey: Point, sig: SchnorrSignature) {
|
|
48
|
-
|
|
49
|
-
const
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
.
|
|
53
|
-
|
|
49
|
+
await BarretenbergSync.initSingleton();
|
|
50
|
+
const api = BarretenbergSync.getSingleton();
|
|
51
|
+
const response = api.schnorrVerifySignature({
|
|
52
|
+
message: msg,
|
|
53
|
+
publicKey: { x: pubKey.x.toBuffer(), y: pubKey.y.toBuffer() },
|
|
54
|
+
s: sig.s,
|
|
55
|
+
e: sig.e,
|
|
56
|
+
});
|
|
57
|
+
return response.verified;
|
|
54
58
|
}
|
|
55
59
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { randomBytes } from '@aztec/foundation/crypto';
|
|
2
|
-
import { Fr } from '@aztec/foundation/
|
|
1
|
+
import { randomBytes } from '@aztec/foundation/crypto/random';
|
|
2
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
3
|
import { BufferReader, mapTuple } from '@aztec/foundation/serialize';
|
|
4
4
|
|
|
5
5
|
import type { Signature } from '../signature/index.js';
|
|
@@ -27,9 +27,13 @@ export class Secp256k1 {
|
|
|
27
27
|
* @returns Result of the multiplication.
|
|
28
28
|
*/
|
|
29
29
|
public async mul(point: Uint8Array, scalar: Uint8Array) {
|
|
30
|
-
|
|
31
|
-
const
|
|
32
|
-
|
|
30
|
+
await BarretenbergSync.initSingleton();
|
|
31
|
+
const api = BarretenbergSync.getSingleton();
|
|
32
|
+
const response = api.secp256k1Mul({
|
|
33
|
+
point: { x: point.subarray(0, 32), y: point.subarray(32, 64) },
|
|
34
|
+
scalar,
|
|
35
|
+
});
|
|
36
|
+
return Buffer.concat([Buffer.from(response.point.x), Buffer.from(response.point.y)]);
|
|
33
37
|
}
|
|
34
38
|
|
|
35
39
|
/**
|
|
@@ -37,9 +41,10 @@ export class Secp256k1 {
|
|
|
37
41
|
* @returns Random field element.
|
|
38
42
|
*/
|
|
39
43
|
public async getRandomFr() {
|
|
40
|
-
|
|
41
|
-
const
|
|
42
|
-
|
|
44
|
+
await BarretenbergSync.initSingleton();
|
|
45
|
+
const api = BarretenbergSync.getSingleton();
|
|
46
|
+
const response = api.secp256k1GetRandomFr({ dummy: 0 });
|
|
47
|
+
return Buffer.from(response.value);
|
|
43
48
|
}
|
|
44
49
|
|
|
45
50
|
/**
|
|
@@ -48,10 +53,9 @@ export class Secp256k1 {
|
|
|
48
53
|
* @returns Buffer representation of the field element.
|
|
49
54
|
*/
|
|
50
55
|
public async reduce512BufferToFr(uint512Buf: Buffer) {
|
|
51
|
-
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
return Buffer.from(result);
|
|
56
|
+
await BarretenbergSync.initSingleton();
|
|
57
|
+
const api = BarretenbergSync.getSingleton();
|
|
58
|
+
const response = api.secp256k1Reduce512({ input: uint512Buf });
|
|
59
|
+
return Buffer.from(response.value);
|
|
56
60
|
}
|
|
57
61
|
}
|
|
@@ -7,6 +7,27 @@ import { keccak256 } from '../keccak/index.js';
|
|
|
7
7
|
|
|
8
8
|
const ETH_SIGN_PREFIX = '\x19Ethereum Signed Message:\n32';
|
|
9
9
|
|
|
10
|
+
/** Signature recovery options */
|
|
11
|
+
type RecoveryOpts = {
|
|
12
|
+
/**
|
|
13
|
+
* Whether to allow s-values in the high half of the curve (s >= CURVE.n/2).
|
|
14
|
+
* These are discouraged by EIP2 to prevent signature malleability, and outright
|
|
15
|
+
* rejected in OpenZeppelin's ECDSA recover, which we use in our Rollup contract.
|
|
16
|
+
*/
|
|
17
|
+
allowMalleable?: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Whether to allow an y-parity 0-1 bit instead of the standard v value 27-28.
|
|
20
|
+
*/
|
|
21
|
+
allowYParityAsV?: boolean;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export class Secp256k1Error extends Error {
|
|
25
|
+
constructor(message: string, opts?: { cause: unknown }) {
|
|
26
|
+
super(message, opts);
|
|
27
|
+
this.name = 'Secp256k1Error';
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
10
31
|
// We just hash the message to make it easier to work with in the smart contract.
|
|
11
32
|
export function makeEthSignDigest(message: Buffer32): Buffer32 {
|
|
12
33
|
const prefix = Buffer.from(ETH_SIGN_PREFIX);
|
|
@@ -46,19 +67,38 @@ export function addressFromPrivateKey(privateKey: Buffer): EthAddress {
|
|
|
46
67
|
* Recovers an address from a hash and a signature.
|
|
47
68
|
* @param hash - The hash to recover the address from.
|
|
48
69
|
* @param signature - The signature to recover the address from.
|
|
70
|
+
* @param opts - Recovery options.
|
|
49
71
|
* @returns The address.
|
|
72
|
+
* @throws Error if signature recovery fails or if signature is malleable and allowMalleable is false.
|
|
50
73
|
*/
|
|
51
|
-
export function recoverAddress(hash: Buffer32, signature: Signature): EthAddress {
|
|
74
|
+
export function recoverAddress(hash: Buffer32, signature: Signature, opts?: RecoveryOpts): EthAddress {
|
|
52
75
|
try {
|
|
53
|
-
const publicKey = recoverPublicKey(hash, signature);
|
|
76
|
+
const publicKey = recoverPublicKey(hash, signature, opts);
|
|
54
77
|
return publicKeyToAddress(publicKey);
|
|
55
|
-
} catch (err) {
|
|
56
|
-
throw new
|
|
57
|
-
`Error recovering Ethereum address from hash ${hash.toString()} and signature ${signature.toString()}
|
|
78
|
+
} catch (err: unknown) {
|
|
79
|
+
throw new Secp256k1Error(
|
|
80
|
+
`Error recovering Ethereum address from hash ${hash.toString()} and signature ${signature.toString()}`,
|
|
81
|
+
{ cause: err },
|
|
58
82
|
);
|
|
59
83
|
}
|
|
60
84
|
}
|
|
61
85
|
|
|
86
|
+
/**
|
|
87
|
+
* Safely attempts to recover an address from a hash and a signature.
|
|
88
|
+
* @param hash - The hash to recover the address from.
|
|
89
|
+
* @param signature - The signature to recover the address from.
|
|
90
|
+
* @param opts - Recovery options.
|
|
91
|
+
* @returns The address if recovery succeeds, undefined otherwise.
|
|
92
|
+
*/
|
|
93
|
+
export function tryRecoverAddress(hash: Buffer32, signature: Signature, opts?: RecoveryOpts): EthAddress | undefined {
|
|
94
|
+
try {
|
|
95
|
+
const publicKey = recoverPublicKey(hash, signature, opts);
|
|
96
|
+
return publicKeyToAddress(publicKey);
|
|
97
|
+
} catch {
|
|
98
|
+
return undefined;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
62
102
|
/**
|
|
63
103
|
* @attribution - viem
|
|
64
104
|
* Converts a yParityOrV value to a recovery bit.
|
|
@@ -75,7 +115,7 @@ export function toRecoveryBit(yParityOrV: number) {
|
|
|
75
115
|
if (yParityOrV === 28) {
|
|
76
116
|
return 1;
|
|
77
117
|
}
|
|
78
|
-
throw new
|
|
118
|
+
throw new Secp256k1Error(`Invalid yParityOrV value ${yParityOrV}`);
|
|
79
119
|
}
|
|
80
120
|
|
|
81
121
|
/**
|
|
@@ -89,16 +129,84 @@ export function signMessage(message: Buffer32, privateKey: Buffer) {
|
|
|
89
129
|
return new Signature(Buffer32.fromBigInt(r), Buffer32.fromBigInt(s), recovery ? 28 : 27);
|
|
90
130
|
}
|
|
91
131
|
|
|
132
|
+
/**
|
|
133
|
+
* Flips an ECDSA signature.
|
|
134
|
+
* If the signature has a low s-value (s < CURVE.n/2), it flips it to high s-value (CURVE.n - s) and vice versa.
|
|
135
|
+
* Also flips the v value accordingly (27 <-> 28, or 0 <-> 1).
|
|
136
|
+
* This is useful for testing signature malleability handling.
|
|
137
|
+
* @param signature - The signature to flip.
|
|
138
|
+
* @returns A new signature with flipped s-value and v-value.
|
|
139
|
+
*/
|
|
140
|
+
export function flipSignature(signature: Signature): Signature {
|
|
141
|
+
const { r, s, v } = signature;
|
|
142
|
+
const sig = new secp256k1.Signature(r.toBigInt(), s.toBigInt());
|
|
143
|
+
const flippedS = secp256k1.CURVE.n - sig.s;
|
|
144
|
+
|
|
145
|
+
return new Signature(r, Buffer32.fromBigInt(flippedS), flipV(v));
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Normalizes an ECDSA signature.
|
|
150
|
+
* If the signature has a high s-value (s >= CURVE.n/2), it flips it to low s-value (CURVE.n - s), and flips v accordingly.
|
|
151
|
+
* If the signature uses a recovery bit of 0/1, it is converted to a v-value 27/28 for ecrecover.
|
|
152
|
+
* @remarks This does not handle post EIP155 tx signatures which embed the chain id in v. Use it only for feeding into ECRECOVER precompiles.
|
|
153
|
+
* @param signature - The signature to normalize.
|
|
154
|
+
*/
|
|
155
|
+
export function normalizeSignature(signature: Signature): Signature {
|
|
156
|
+
const { r, s, v } = signature;
|
|
157
|
+
const sig = new secp256k1.Signature(r.toBigInt(), s.toBigInt());
|
|
158
|
+
if (sig.hasHighS()) {
|
|
159
|
+
const newV = flipV(v);
|
|
160
|
+
const newS = sig.normalizeS().s;
|
|
161
|
+
return new Signature(r, Buffer32.fromBigInt(newS), toVFromYParityOrV(newV));
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
return new Signature(r, s, toVFromYParityOrV(v));
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/** Converts a yParityOrV value to a pre-EIP155 v-value 27-28. */
|
|
168
|
+
function toVFromYParityOrV(yParityOrV: number): number {
|
|
169
|
+
if (yParityOrV === 0 || yParityOrV === 1) {
|
|
170
|
+
return yParityOrV + 27;
|
|
171
|
+
} else if (yParityOrV === 27 || yParityOrV === 28) {
|
|
172
|
+
return yParityOrV;
|
|
173
|
+
} else {
|
|
174
|
+
throw new Secp256k1Error(`Invalid yParityOrV value ${yParityOrV}`);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/** Flips the recovery bit or v-value */
|
|
179
|
+
function flipV(v: number): number {
|
|
180
|
+
switch (v) {
|
|
181
|
+
case 27:
|
|
182
|
+
return 28;
|
|
183
|
+
case 28:
|
|
184
|
+
return 27;
|
|
185
|
+
case 0:
|
|
186
|
+
return 1;
|
|
187
|
+
case 1:
|
|
188
|
+
return 0;
|
|
189
|
+
default:
|
|
190
|
+
throw new Secp256k1Error(`Invalid v value ${v}`);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
92
194
|
/**
|
|
93
195
|
* Recovers a public key from a hash and a signature.
|
|
94
196
|
* @param hash - The hash to recover the public key from.
|
|
95
197
|
* @param signature - The signature to recover the public key from.
|
|
96
198
|
* @returns The public key.
|
|
97
199
|
*/
|
|
98
|
-
export function recoverPublicKey(hash: Buffer32, signature: Signature): Buffer {
|
|
200
|
+
export function recoverPublicKey(hash: Buffer32, signature: Signature, opts: RecoveryOpts = {}): Buffer {
|
|
99
201
|
const { r, s, v } = signature;
|
|
202
|
+
if (!opts.allowYParityAsV && v !== 27 && v !== 28) {
|
|
203
|
+
throw new Secp256k1Error(`Invalid v value ${v} (expected 27 or 28)`);
|
|
204
|
+
}
|
|
100
205
|
const recoveryBit = toRecoveryBit(v);
|
|
101
206
|
const sig = new secp256k1.Signature(r.toBigInt(), s.toBigInt()).addRecoveryBit(recoveryBit);
|
|
207
|
+
if (!opts.allowMalleable && sig.hasHighS()) {
|
|
208
|
+
throw new Secp256k1Error('Signature has high s-value (malleable signature)');
|
|
209
|
+
}
|
|
102
210
|
const publicKey = sig.recoverPublicKey(hash.buffer).toHex(false);
|
|
103
211
|
return Buffer.from(publicKey, 'hex');
|
|
104
212
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* eslint-disable camelcase */
|
|
2
2
|
import { default as hash } from 'hash.js';
|
|
3
3
|
|
|
4
|
-
import { Fr } from '../../
|
|
4
|
+
import { Fr } from '../../curves/bn254/field.js';
|
|
5
5
|
import { truncateAndPad } from '../../serialize/free_funcs.js';
|
|
6
6
|
import { type Bufferable, serializeToBuffer } from '../../serialize/serialize.js';
|
|
7
7
|
import type { Hasher } from '../../trees/hasher.js';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { default as hash } from 'hash.js';
|
|
2
2
|
|
|
3
|
-
import { GrumpkinScalar } from '../../
|
|
3
|
+
import { GrumpkinScalar } from '../../curves/grumpkin/index.js';
|
|
4
4
|
import { type Bufferable, serializeToBuffer } from '../../serialize/serialize.js';
|
|
5
5
|
|
|
6
6
|
export const sha512 = (data: Buffer) => Buffer.from(hash.sha512().update(data).digest());
|
package/src/crypto/sync/index.ts
CHANGED