@aztec/foundation 3.0.0-devnet.6 → 3.0.0-devnet.6-patch.1
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 +1 -1
- 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 +1 -1
- package/dest/buffer/buffer32.d.ts +2 -5
- package/dest/buffer/buffer32.d.ts.map +1 -1
- package/dest/buffer/buffer32.js +1 -1
- 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 +1 -1
- package/dest/committable/committable.d.ts +1 -1
- package/dest/committable/committable.d.ts.map +1 -1
- package/dest/committable/index.d.ts +1 -1
- package/dest/config/env_var.d.ts +2 -2
- package/dest/config/env_var.d.ts.map +1 -1
- package/dest/config/index.d.ts +10 -2
- package/dest/config/index.d.ts.map +1 -1
- package/dest/config/index.js +16 -2
- package/dest/config/network_config.d.ts +1 -1
- package/dest/config/network_name.d.ts +1 -1
- package/dest/config/secret_value.d.ts +1 -1
- package/dest/config/secret_value.d.ts.map +1 -1
- package/dest/crypto/aes128/index.d.ts +1 -1
- package/dest/crypto/aes128/index.d.ts.map +1 -1
- package/dest/crypto/aes128/index.js +2 -6
- package/dest/crypto/bls/bn254_keystore.d.ts +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 +4 -12
- 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 +12 -27
- package/dest/crypto/keccak/index.d.ts +1 -1
- package/dest/crypto/keys/index.d.ts +2 -2
- package/dest/crypto/keys/index.d.ts.map +1 -1
- package/dest/crypto/keys/index.js +2 -4
- package/dest/crypto/pedersen/index.d.ts +1 -1
- package/dest/crypto/pedersen/pedersen.noble.d.ts +1 -1
- package/dest/crypto/pedersen/pedersen.wasm.d.ts +2 -2
- package/dest/crypto/pedersen/pedersen.wasm.d.ts.map +1 -1
- package/dest/crypto/pedersen/pedersen.wasm.js +4 -10
- package/dest/crypto/poseidon/index.d.ts +2 -2
- package/dest/crypto/poseidon/index.d.ts.map +1 -1
- package/dest/crypto/poseidon/index.js +6 -16
- 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 +4 -10
- package/dest/crypto/schnorr/signature.d.ts +2 -2
- package/dest/crypto/schnorr/signature.d.ts.map +1 -1
- package/dest/crypto/schnorr/signature.js +2 -2
- package/dest/crypto/secp256k1/index.d.ts +1 -1
- package/dest/crypto/secp256k1/index.d.ts.map +1 -1
- package/dest/crypto/secp256k1/index.js +3 -9
- package/dest/crypto/secp256k1-signer/index.d.ts +1 -1
- package/dest/crypto/secp256k1-signer/secp256k1_signer.d.ts +1 -1
- package/dest/crypto/secp256k1-signer/secp256k1_signer.d.ts.map +1 -1
- package/dest/crypto/secp256k1-signer/utils.d.ts +43 -5
- package/dest/crypto/secp256k1-signer/utils.d.ts.map +1 -1
- package/dest/crypto/secp256k1-signer/utils.js +76 -8
- package/dest/crypto/serialize.d.ts +1 -1
- package/dest/crypto/sha256/index.d.ts +2 -2
- package/dest/crypto/sha256/index.d.ts.map +1 -1
- package/dest/crypto/sha256/index.js +1 -1
- package/dest/crypto/sha512/index.d.ts +3 -3
- package/dest/crypto/sha512/index.d.ts.map +1 -1
- package/dest/crypto/sha512/index.js +1 -1
- package/dest/crypto/signature/index.d.ts +2 -2
- package/dest/crypto/signature/index.d.ts.map +1 -1
- package/dest/crypto/sync/index.d.ts +1 -1
- package/dest/crypto/sync/index.js +1 -3
- package/dest/crypto/sync/pedersen/index.d.ts +2 -2
- package/dest/crypto/sync/pedersen/index.d.ts.map +1 -1
- package/dest/crypto/sync/pedersen/index.js +1 -1
- package/dest/crypto/sync/poseidon/index.d.ts +2 -2
- package/dest/crypto/sync/poseidon/index.d.ts.map +1 -1
- package/dest/crypto/sync/poseidon/index.js +1 -1
- 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} +6 -6
- package/dest/curves/bls12/index.d.ts +3 -0
- package/dest/curves/bls12/index.d.ts.map +1 -0
- package/dest/curves/bls12/index.js +2 -0
- package/dest/{fields/bls12_point.d.ts → curves/bls12/point.d.ts} +4 -13
- package/dest/curves/bls12/point.d.ts.map +1 -0
- package/dest/{fields/bls12_point.js → curves/bls12/point.js} +7 -7
- package/dest/{fields/fields.d.ts → curves/bn254/field.d.ts} +16 -9
- package/dest/curves/bn254/field.d.ts.map +1 -0
- package/dest/{fields/fields.js → curves/bn254/field.js} +35 -9
- 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 +12 -2
- package/dest/eth-address/index.d.ts.map +1 -1
- package/dest/eth-address/index.js +23 -1
- 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/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/json-rpc/client/fetch.d.ts +1 -1
- package/dest/json-rpc/client/index.d.ts +1 -1
- package/dest/json-rpc/client/safe_json_rpc_client.d.ts +1 -1
- package/dest/json-rpc/client/undici.d.ts +1 -1
- package/dest/json-rpc/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/server/telemetry.d.ts +1 -1
- package/dest/json-rpc/test/index.d.ts +1 -1
- package/dest/json-rpc/test/integration.d.ts +1 -1
- package/dest/log/console.d.ts +1 -1
- package/dest/log/gcloud-logger-config.d.ts +1 -1
- package/dest/log/gcloud-logger-config.d.ts.map +1 -1
- package/dest/log/index.d.ts +1 -1
- package/dest/log/libp2p_logger.d.ts +1 -1
- package/dest/log/log-filters.d.ts +1 -1
- package/dest/log/log-levels.d.ts +1 -1
- package/dest/log/log_fn.d.ts +1 -1
- package/dest/log/noir_debug_log_util.d.ts +1 -1
- package/dest/log/pino-logger.d.ts +2 -2
- package/dest/message/index.d.ts +1 -1
- package/dest/message/index.d.ts.map +1 -1
- package/dest/mutex/index.d.ts +1 -1
- package/dest/mutex/index.d.ts.map +1 -1
- package/dest/mutex/mutex_database.d.ts +1 -1
- package/dest/noir/index.d.ts +1 -1
- package/dest/noir/noir_package_config.d.ts +9 -9
- package/dest/number/index.d.ts +1 -1
- package/dest/profiler/index.d.ts +1 -1
- package/dest/profiler/profiler.d.ts +1 -1
- package/dest/promise/index.d.ts +1 -1
- package/dest/promise/running-promise.d.ts +1 -1
- package/dest/promise/running-promise.d.ts.map +1 -1
- package/dest/promise/utils.d.ts +1 -1
- package/dest/queue/base_memory_queue.d.ts +1 -1
- package/dest/queue/base_memory_queue.d.ts.map +1 -1
- package/dest/queue/batch_queue.d.ts +1 -1
- package/dest/queue/batch_queue.d.ts.map +1 -1
- package/dest/queue/bounded_serial_queue.d.ts +1 -1
- package/dest/queue/bounded_serial_queue.d.ts.map +1 -1
- package/dest/queue/fifo_memory_queue.d.ts +1 -1
- package/dest/queue/fifo_memory_queue.d.ts.map +1 -1
- package/dest/queue/index.d.ts +1 -1
- package/dest/queue/priority_memory_queue.d.ts +1 -1
- package/dest/queue/priority_memory_queue.d.ts.map +1 -1
- package/dest/queue/priority_queue.d.ts +1 -1
- package/dest/queue/priority_queue.d.ts.map +1 -1
- package/dest/queue/semaphore.d.ts +1 -1
- package/dest/queue/semaphore.d.ts.map +1 -1
- package/dest/queue/serial_queue.d.ts +1 -1
- package/dest/queue/serial_queue.d.ts.map +1 -1
- package/dest/retry/index.d.ts +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 +13 -17
- package/dest/schemas/schemas.d.ts.map +1 -1
- package/dest/schemas/schemas.js +9 -10
- package/dest/schemas/types.d.ts +1 -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 +1 -1
- package/dest/serialize/buffer_reader.d.ts.map +1 -1
- 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 +1 -1
- package/dest/sleep/index.d.ts.map +1 -1
- package/dest/string/index.d.ts +5 -1
- package/dest/string/index.d.ts.map +1 -1
- package/dest/string/index.js +1 -1
- package/dest/testing/files/index.d.ts +2 -1
- package/dest/testing/files/index.d.ts.map +1 -1
- package/dest/testing/files/index.js +1 -1
- package/dest/testing/formatting.d.ts +1 -1
- package/dest/testing/index.d.ts +1 -1
- package/dest/testing/port_allocator.d.ts +1 -1
- package/dest/testing/snapshot_serializer.d.ts +1 -1
- package/dest/testing/test_data.d.ts +1 -1
- package/dest/timer/date.d.ts +1 -1
- package/dest/timer/date.d.ts.map +1 -1
- 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 -3
- package/dest/trees/unbalanced_merkle_tree.d.ts.map +1 -1
- package/dest/trees/unbalanced_merkle_tree.js +32 -9
- package/dest/trees/unbalanced_merkle_tree_calculator.d.ts +6 -5
- package/dest/trees/unbalanced_merkle_tree_calculator.d.ts.map +1 -1
- package/dest/trees/unbalanced_merkle_tree_calculator.js +36 -40
- package/dest/trees/unbalanced_tree_store.d.ts +1 -1
- package/dest/trees/unbalanced_tree_store.d.ts.map +1 -1
- package/dest/types/index.d.ts +1 -1
- package/dest/url/index.d.ts +1 -1
- package/dest/validation/index.d.ts +1 -1
- package/package.json +29 -7
- package/src/array/array.ts +0 -16
- 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/config/env_var.ts +20 -2
- package/src/config/index.ts +20 -2
- package/src/crypto/aes128/index.ts +2 -2
- 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 +4 -4
- package/src/crypto/ecdsa/signature.ts +2 -2
- package/src/crypto/grumpkin/index.ts +14 -20
- package/src/crypto/keys/index.ts +2 -2
- package/src/crypto/pedersen/pedersen.wasm.ts +4 -4
- package/src/crypto/poseidon/index.ts +6 -6
- package/src/crypto/schnorr/index.ts +5 -4
- package/src/crypto/schnorr/signature.ts +2 -2
- package/src/crypto/secp256k1/index.ts +3 -3
- package/src/crypto/secp256k1-signer/utils.ts +102 -10
- package/src/crypto/sha256/index.ts +1 -1
- package/src/crypto/sha512/index.ts +1 -1
- package/src/crypto/signature/index.ts +1 -1
- package/src/crypto/sync/index.ts +1 -1
- package/src/crypto/sync/pedersen/index.ts +1 -1
- package/src/crypto/sync/poseidon/index.ts +1 -1
- package/src/{fields/bls12_fields.ts → curves/bls12/field.ts} +6 -6
- package/src/curves/bls12/index.ts +2 -0
- package/src/{fields/bls12_point.ts → curves/bls12/point.ts} +7 -7
- package/src/{fields/fields.ts → curves/bn254/field.ts} +37 -14
- 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 +26 -1
- package/src/schemas/schemas.ts +16 -13
- package/src/schemas/utils.ts +21 -8
- 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/string/index.ts +3 -0
- package/src/testing/files/index.ts +1 -1
- 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 +54 -6
- package/src/trees/unbalanced_merkle_tree_calculator.ts +34 -41
- 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.map +0 -1
- package/dest/fields/index.d.ts +0 -6
- package/dest/fields/index.d.ts.map +0 -1
- package/dest/fields/index.js +0 -5
- package/dest/fields/point.d.ts.map +0 -1
- package/dest/index.d.ts +0 -30
- package/dest/index.d.ts.map +0 -1
- package/dest/index.js +0 -30
- package/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 -30
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { BarretenbergSync } from '@aztec/bb.js';
|
|
2
|
-
import {
|
|
2
|
+
import type { GrumpkinScalar } from '@aztec/foundation/curves/grumpkin';
|
|
3
|
+
import { Point } from '@aztec/foundation/curves/grumpkin';
|
|
3
4
|
|
|
4
5
|
import { SchnorrSignature } from './signature.js';
|
|
5
6
|
|
|
@@ -15,7 +16,7 @@ export class Schnorr {
|
|
|
15
16
|
* @returns A grumpkin public key.
|
|
16
17
|
*/
|
|
17
18
|
public async computePublicKey(privateKey: GrumpkinScalar): Promise<Point> {
|
|
18
|
-
await BarretenbergSync.initSingleton(
|
|
19
|
+
await BarretenbergSync.initSingleton();
|
|
19
20
|
const api = BarretenbergSync.getSingleton();
|
|
20
21
|
const response = api.schnorrComputePublicKey({ privateKey: privateKey.toBuffer() });
|
|
21
22
|
return Point.fromBuffer(Buffer.concat([Buffer.from(response.publicKey.x), Buffer.from(response.publicKey.y)]));
|
|
@@ -28,7 +29,7 @@ export class Schnorr {
|
|
|
28
29
|
* @returns A Schnorr signature of the form (s, e).
|
|
29
30
|
*/
|
|
30
31
|
public async constructSignature(msg: Uint8Array, privateKey: GrumpkinScalar) {
|
|
31
|
-
await BarretenbergSync.initSingleton(
|
|
32
|
+
await BarretenbergSync.initSingleton();
|
|
32
33
|
const api = BarretenbergSync.getSingleton();
|
|
33
34
|
const response = api.schnorrConstructSignature({
|
|
34
35
|
message: msg,
|
|
@@ -45,7 +46,7 @@ export class Schnorr {
|
|
|
45
46
|
* @returns True or false.
|
|
46
47
|
*/
|
|
47
48
|
public async verifySignature(msg: Uint8Array, pubKey: Point, sig: SchnorrSignature) {
|
|
48
|
-
await BarretenbergSync.initSingleton(
|
|
49
|
+
await BarretenbergSync.initSingleton();
|
|
49
50
|
const api = BarretenbergSync.getSingleton();
|
|
50
51
|
const response = api.schnorrVerifySignature({
|
|
51
52
|
message: msg,
|
|
@@ -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,7 +27,7 @@ export class Secp256k1 {
|
|
|
27
27
|
* @returns Result of the multiplication.
|
|
28
28
|
*/
|
|
29
29
|
public async mul(point: Uint8Array, scalar: Uint8Array) {
|
|
30
|
-
await BarretenbergSync.initSingleton(
|
|
30
|
+
await BarretenbergSync.initSingleton();
|
|
31
31
|
const api = BarretenbergSync.getSingleton();
|
|
32
32
|
const response = api.secp256k1Mul({
|
|
33
33
|
point: { x: point.subarray(0, 32), y: point.subarray(32, 64) },
|
|
@@ -41,7 +41,7 @@ export class Secp256k1 {
|
|
|
41
41
|
* @returns Random field element.
|
|
42
42
|
*/
|
|
43
43
|
public async getRandomFr() {
|
|
44
|
-
await BarretenbergSync.initSingleton(
|
|
44
|
+
await BarretenbergSync.initSingleton();
|
|
45
45
|
const api = BarretenbergSync.getSingleton();
|
|
46
46
|
const response = api.secp256k1GetRandomFr({ dummy: 0 });
|
|
47
47
|
return Buffer.from(response.value);
|
|
@@ -53,7 +53,7 @@ export class Secp256k1 {
|
|
|
53
53
|
* @returns Buffer representation of the field element.
|
|
54
54
|
*/
|
|
55
55
|
public async reduce512BufferToFr(uint512Buf: Buffer) {
|
|
56
|
-
await BarretenbergSync.initSingleton(
|
|
56
|
+
await BarretenbergSync.initSingleton();
|
|
57
57
|
const api = BarretenbergSync.getSingleton();
|
|
58
58
|
const response = api.secp256k1Reduce512({ input: uint512Buf });
|
|
59
59
|
return Buffer.from(response.value);
|
|
@@ -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,16 +67,18 @@ 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.
|
|
50
|
-
* @throws Error if signature recovery fails.
|
|
72
|
+
* @throws Error if signature recovery fails or if signature is malleable and allowMalleable is false.
|
|
51
73
|
*/
|
|
52
|
-
export function recoverAddress(hash: Buffer32, signature: Signature): EthAddress {
|
|
74
|
+
export function recoverAddress(hash: Buffer32, signature: Signature, opts?: RecoveryOpts): EthAddress {
|
|
53
75
|
try {
|
|
54
|
-
const publicKey = recoverPublicKey(hash, signature);
|
|
76
|
+
const publicKey = recoverPublicKey(hash, signature, opts);
|
|
55
77
|
return publicKeyToAddress(publicKey);
|
|
56
|
-
} catch (err) {
|
|
57
|
-
throw new
|
|
58
|
-
`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 },
|
|
59
82
|
);
|
|
60
83
|
}
|
|
61
84
|
}
|
|
@@ -64,11 +87,12 @@ export function recoverAddress(hash: Buffer32, signature: Signature): EthAddress
|
|
|
64
87
|
* Safely attempts to recover an address from a hash and a signature.
|
|
65
88
|
* @param hash - The hash to recover the address from.
|
|
66
89
|
* @param signature - The signature to recover the address from.
|
|
90
|
+
* @param opts - Recovery options.
|
|
67
91
|
* @returns The address if recovery succeeds, undefined otherwise.
|
|
68
92
|
*/
|
|
69
|
-
export function tryRecoverAddress(hash: Buffer32, signature: Signature): EthAddress | undefined {
|
|
93
|
+
export function tryRecoverAddress(hash: Buffer32, signature: Signature, opts?: RecoveryOpts): EthAddress | undefined {
|
|
70
94
|
try {
|
|
71
|
-
const publicKey = recoverPublicKey(hash, signature);
|
|
95
|
+
const publicKey = recoverPublicKey(hash, signature, opts);
|
|
72
96
|
return publicKeyToAddress(publicKey);
|
|
73
97
|
} catch {
|
|
74
98
|
return undefined;
|
|
@@ -91,7 +115,7 @@ export function toRecoveryBit(yParityOrV: number) {
|
|
|
91
115
|
if (yParityOrV === 28) {
|
|
92
116
|
return 1;
|
|
93
117
|
}
|
|
94
|
-
throw new
|
|
118
|
+
throw new Secp256k1Error(`Invalid yParityOrV value ${yParityOrV}`);
|
|
95
119
|
}
|
|
96
120
|
|
|
97
121
|
/**
|
|
@@ -105,16 +129,84 @@ export function signMessage(message: Buffer32, privateKey: Buffer) {
|
|
|
105
129
|
return new Signature(Buffer32.fromBigInt(r), Buffer32.fromBigInt(s), recovery ? 28 : 27);
|
|
106
130
|
}
|
|
107
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
|
+
|
|
108
194
|
/**
|
|
109
195
|
* Recovers a public key from a hash and a signature.
|
|
110
196
|
* @param hash - The hash to recover the public key from.
|
|
111
197
|
* @param signature - The signature to recover the public key from.
|
|
112
198
|
* @returns The public key.
|
|
113
199
|
*/
|
|
114
|
-
export function recoverPublicKey(hash: Buffer32, signature: Signature): Buffer {
|
|
200
|
+
export function recoverPublicKey(hash: Buffer32, signature: Signature, opts: RecoveryOpts = {}): Buffer {
|
|
115
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
|
+
}
|
|
116
205
|
const recoveryBit = toRecoveryBit(v);
|
|
117
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
|
+
}
|
|
118
210
|
const publicKey = sig.recoverPublicKey(hash.buffer).toHex(false);
|
|
119
211
|
return Buffer.from(publicKey, 'hex');
|
|
120
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
|
@@ -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.
|
|
@@ -2,11 +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 '
|
|
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
10
|
|
|
11
11
|
const ZERO_BUFFER = Buffer.alloc(32);
|
|
12
12
|
|
|
@@ -321,7 +321,7 @@ export class Fr extends BaseField {
|
|
|
321
321
|
* @returns A square root of the field element (null if it does not exist).
|
|
322
322
|
*/
|
|
323
323
|
async sqrt(): Promise<Fr | null> {
|
|
324
|
-
await BarretenbergSync.initSingleton(
|
|
324
|
+
await BarretenbergSync.initSingleton();
|
|
325
325
|
const api = BarretenbergSync.getSingleton();
|
|
326
326
|
const response = api.bn254FrSqrt({ input: this.toBuffer() });
|
|
327
327
|
if (!response.isSquareRoot) {
|
|
@@ -335,7 +335,23 @@ export class Fr extends BaseField {
|
|
|
335
335
|
return this.toString();
|
|
336
336
|
}
|
|
337
337
|
|
|
338
|
+
/**
|
|
339
|
+
* Creates an Fr instance from a plain object without Zod validation.
|
|
340
|
+
* This method is optimized for performance and skips validation, making it suitable
|
|
341
|
+
* for deserializing trusted data (e.g., from C++ via MessagePack).
|
|
342
|
+
* Handles buffers, strings, numbers, bigints, or existing instances.
|
|
343
|
+
* @param obj - Plain object, buffer, string, number, bigint, boolean, or Fr instance
|
|
344
|
+
* @returns An Fr instance
|
|
345
|
+
*/
|
|
346
|
+
static fromPlainObject(obj: any): Fr {
|
|
347
|
+
if (obj instanceof Fr) {
|
|
348
|
+
return obj;
|
|
349
|
+
}
|
|
350
|
+
return new Fr(obj);
|
|
351
|
+
}
|
|
352
|
+
|
|
338
353
|
static get schema() {
|
|
354
|
+
// Serialization from hex string.
|
|
339
355
|
return hexSchemaFor(Fr);
|
|
340
356
|
}
|
|
341
357
|
}
|
|
@@ -434,6 +450,21 @@ export class Fq extends BaseField {
|
|
|
434
450
|
return new Fq((this.toBigInt() + rhs.toBigInt()) % Fq.MODULUS);
|
|
435
451
|
}
|
|
436
452
|
|
|
453
|
+
/**
|
|
454
|
+
* Computes a square root of the field element.
|
|
455
|
+
* @returns A square root of the field element (null if it does not exist).
|
|
456
|
+
*/
|
|
457
|
+
async sqrt(): Promise<Fq | null> {
|
|
458
|
+
await BarretenbergSync.initSingleton();
|
|
459
|
+
const api = BarretenbergSync.getSingleton();
|
|
460
|
+
const response = api.bn254FqSqrt({ input: this.toBuffer() });
|
|
461
|
+
if (!response.isSquareRoot) {
|
|
462
|
+
// Field element is not a quadratic residue mod p so it has no square root.
|
|
463
|
+
return null;
|
|
464
|
+
}
|
|
465
|
+
return Fq.fromBuffer(Buffer.from(response.value));
|
|
466
|
+
}
|
|
467
|
+
|
|
437
468
|
toJSON() {
|
|
438
469
|
return this.toString();
|
|
439
470
|
}
|
|
@@ -480,14 +511,6 @@ function extendedEuclidean(a: bigint, modulus: bigint): [bigint, bigint, bigint]
|
|
|
480
511
|
}
|
|
481
512
|
}
|
|
482
513
|
|
|
483
|
-
/**
|
|
484
|
-
* GrumpkinScalar is an Fq.
|
|
485
|
-
* @remarks Called GrumpkinScalar because it is used to represent elements in Grumpkin's scalar field as defined in
|
|
486
|
-
* the Aztec Protocol Specs.
|
|
487
|
-
*/
|
|
488
|
-
export type GrumpkinScalar = Fq;
|
|
489
|
-
export const GrumpkinScalar = Fq;
|
|
490
|
-
|
|
491
514
|
/** Wraps a function that returns a buffer so that all results are reduced into a field of the given type. */
|
|
492
515
|
export function reduceFn<TInput, TField extends BaseField>(fn: (input: TInput) => Buffer, field: DerivedField<TField>) {
|
|
493
516
|
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;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { toBigIntBE } from '
|
|
2
|
-
import { poseidon2Hash } from '
|
|
3
|
-
import { randomBoolean } from '
|
|
4
|
-
import { hexSchemaFor } from '
|
|
5
|
-
import { BufferReader, FieldReader, serializeToBuffer } from '
|
|
6
|
-
import { bufferToHex, hexToBuffer } from '
|
|
7
|
-
import { Fr } from '
|
|
1
|
+
import { toBigIntBE } from '../../bigint-buffer/index.js';
|
|
2
|
+
import { poseidon2Hash } from '../../crypto/poseidon/index.js';
|
|
3
|
+
import { randomBoolean } from '../../crypto/random/index.js';
|
|
4
|
+
import { hexSchemaFor } from '../../schemas/utils.js';
|
|
5
|
+
import { BufferReader, FieldReader, serializeToBuffer } from '../../serialize/index.js';
|
|
6
|
+
import { bufferToHex, hexToBuffer } from '../../string/index.js';
|
|
7
|
+
import { Fr } from '../bn254/field.js';
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Represents a Point on an elliptic curve with x and y coordinates.
|
|
@@ -42,9 +42,28 @@ export class Point {
|
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
static get schema() {
|
|
45
|
+
// Serialization from hex string.
|
|
45
46
|
return hexSchemaFor(Point);
|
|
46
47
|
}
|
|
47
48
|
|
|
49
|
+
/**
|
|
50
|
+
* Creates a Point from a plain object without Zod validation.
|
|
51
|
+
* This method is optimized for performance and skips validation, making it suitable
|
|
52
|
+
* for deserializing trusted data (e.g., from C++ via MessagePack).
|
|
53
|
+
* Handles buffers, existing instances, or objects with x, y, and isInfinite fields.
|
|
54
|
+
* @param obj - Plain object, buffer, or Point instance
|
|
55
|
+
* @returns A Point instance
|
|
56
|
+
*/
|
|
57
|
+
static fromPlainObject(obj: any): Point {
|
|
58
|
+
if (obj instanceof Point) {
|
|
59
|
+
return obj;
|
|
60
|
+
}
|
|
61
|
+
if (obj instanceof Buffer || Buffer.isBuffer(obj)) {
|
|
62
|
+
return Point.fromBuffer(obj);
|
|
63
|
+
}
|
|
64
|
+
return new Point(Fr.fromPlainObject(obj.x), Fr.fromPlainObject(obj.y), obj.isInfinite ?? false);
|
|
65
|
+
}
|
|
66
|
+
|
|
48
67
|
/**
|
|
49
68
|
* Generate a random Point instance.
|
|
50
69
|
*
|