@aztec/foundation 0.0.0-test.1 → 0.0.1-commit.5476d83
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 +6 -9
- package/dest/array/array.d.ts.map +1 -1
- package/dest/array/array.js +11 -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/async-pool/index.d.ts.map +1 -1
- package/dest/async-pool/index.js +1 -0
- package/dest/bigint/index.d.ts +7 -0
- package/dest/bigint/index.d.ts.map +1 -0
- package/dest/bigint/index.js +15 -0
- package/dest/bigint-buffer/index.d.ts +1 -3
- package/dest/bigint-buffer/index.d.ts.map +1 -1
- 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 +4 -0
- package/dest/branded-types/index.d.ts.map +1 -0
- package/dest/branded-types/index.js +2 -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 +77 -0
- package/dest/buffer/buffer16.d.ts.map +1 -0
- package/dest/buffer/buffer16.js +100 -0
- package/dest/buffer/buffer32.d.ts +4 -11
- package/dest/buffer/buffer32.d.ts.map +1 -1
- package/dest/buffer/buffer32.js +6 -6
- package/dest/buffer/index.d.ts +2 -1
- package/dest/buffer/index.d.ts.map +1 -1
- package/dest/buffer/index.js +1 -0
- package/dest/collection/array.d.ts +17 -4
- package/dest/collection/array.d.ts.map +1 -1
- package/dest/collection/array.js +57 -3
- package/dest/collection/index.d.ts +1 -1
- package/dest/collection/object.d.ts +17 -1
- package/dest/collection/object.d.ts.map +1 -1
- package/dest/collection/object.js +25 -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 +49 -2
- package/dest/config/index.d.ts.map +1 -1
- package/dest/config/index.js +115 -7
- package/dest/config/network_config.d.ts +42 -0
- package/dest/config/network_config.d.ts.map +1 -0
- package/dest/config/network_config.js +9 -0
- package/dest/config/network_name.d.ts +3 -0
- package/dest/config/network_name.d.ts.map +1 -0
- package/dest/config/network_name.js +19 -0
- package/dest/config/secret_value.d.ts +28 -0
- package/dest/config/secret_value.d.ts.map +1 -0
- package/dest/config/secret_value.js +34 -0
- package/dest/crypto/aes128/index.d.ts +3 -5
- 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/bn254_utils.d.ts +39 -0
- package/dest/crypto/bn254/bn254_utils.d.ts.map +1 -0
- package/dest/crypto/bn254/bn254_utils.js +56 -0
- package/dest/crypto/bn254/index.d.ts +55 -0
- package/dest/crypto/bn254/index.d.ts.map +1 -0
- package/dest/crypto/bn254/index.js +145 -0
- package/dest/crypto/ecdsa/index.d.ts +3 -3
- package/dest/crypto/ecdsa/index.d.ts.map +1 -1
- package/dest/crypto/ecdsa/index.js +62 -48
- package/dest/crypto/ecdsa/signature.d.ts +2 -13
- package/dest/crypto/ecdsa/signature.d.ts.map +1 -1
- package/dest/crypto/grumpkin/index.d.ts +7 -14
- package/dest/crypto/grumpkin/index.d.ts.map +1 -1
- package/dest/crypto/grumpkin/index.js +59 -54
- package/dest/crypto/index.d.ts +3 -1
- package/dest/crypto/index.d.ts.map +1 -1
- package/dest/crypto/index.js +2 -0
- package/dest/crypto/keccak/index.d.ts +3 -5
- package/dest/crypto/keccak/index.d.ts.map +1 -1
- package/dest/crypto/keys/index.d.ts +1 -3
- package/dest/crypto/keys/index.d.ts.map +1 -1
- package/dest/crypto/keys/index.js +7 -4
- package/dest/crypto/pedersen/index.d.ts +1 -1
- package/dest/crypto/pedersen/pedersen.noble.d.ts +3 -5
- package/dest/crypto/pedersen/pedersen.noble.d.ts.map +1 -1
- package/dest/crypto/pedersen/pedersen.wasm.d.ts +3 -5
- package/dest/crypto/pedersen/pedersen.wasm.d.ts.map +1 -1
- package/dest/crypto/pedersen/pedersen.wasm.js +23 -13
- package/dest/crypto/poseidon/index.d.ts +1 -3
- package/dest/crypto/poseidon/index.d.ts.map +1 -1
- package/dest/crypto/poseidon/index.js +32 -17
- package/dest/crypto/random/index.d.ts +2 -4
- package/dest/crypto/random/index.d.ts.map +1 -1
- package/dest/crypto/random/index.js +2 -34
- package/dest/crypto/random/randomness_singleton.d.ts +1 -3
- package/dest/crypto/random/randomness_singleton.d.ts.map +1 -1
- package/dest/crypto/schnorr/index.d.ts +1 -1
- package/dest/crypto/schnorr/index.d.ts.map +1 -1
- package/dest/crypto/schnorr/index.js +29 -37
- package/dest/crypto/schnorr/signature.d.ts +4 -6
- package/dest/crypto/schnorr/signature.d.ts.map +1 -1
- package/dest/crypto/secp256k1/index.d.ts +5 -7
- 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 +56 -5
- package/dest/crypto/secp256k1-signer/utils.d.ts.map +1 -1
- package/dest/crypto/secp256k1-signer/utils.js +92 -6
- package/dest/crypto/serialize.d.ts +5 -7
- package/dest/crypto/serialize.d.ts.map +1 -1
- package/dest/crypto/sha256/index.d.ts +22 -5
- package/dest/crypto/sha256/index.d.ts.map +1 -1
- package/dest/crypto/sha256/index.js +42 -0
- package/dest/crypto/sha512/index.d.ts +2 -4
- package/dest/crypto/sha512/index.d.ts.map +1 -1
- package/dest/crypto/signature/index.d.ts +1 -3
- 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 +3 -5
- package/dest/crypto/sync/pedersen/index.d.ts.map +1 -1
- package/dest/crypto/sync/pedersen/index.js +17 -10
- package/dest/crypto/sync/poseidon/index.d.ts +1 -3
- package/dest/crypto/sync/poseidon/index.d.ts.map +1 -1
- package/dest/crypto/sync/poseidon/index.js +27 -12
- 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 +16 -8
- package/dest/eth-address/index.d.ts.map +1 -1
- package/dest/eth-address/index.js +22 -0
- package/dest/eth-signature/eth_signature.d.ts +17 -18
- package/dest/eth-signature/eth_signature.d.ts.map +1 -1
- package/dest/eth-signature/eth_signature.js +31 -17
- package/dest/eth-signature/index.d.ts +1 -1
- package/dest/fields/bls12_fields.d.ts +148 -0
- package/dest/fields/bls12_fields.d.ts.map +1 -0
- package/dest/fields/bls12_fields.js +359 -0
- package/dest/fields/bls12_point.d.ts +220 -0
- package/dest/fields/bls12_point.d.ts.map +1 -0
- package/dest/fields/bls12_point.js +398 -0
- package/dest/fields/coordinate.d.ts +1 -6
- package/dest/fields/coordinate.d.ts.map +1 -1
- package/dest/fields/fields.d.ts +16 -4
- package/dest/fields/fields.d.ts.map +1 -1
- package/dest/fields/fields.js +57 -15
- package/dest/fields/index.d.ts +3 -1
- package/dest/fields/index.d.ts.map +1 -1
- package/dest/fields/index.js +2 -0
- package/dest/fields/point.d.ts +13 -15
- package/dest/fields/point.d.ts.map +1 -1
- package/dest/fields/point.js +20 -3
- package/dest/fs/index.d.ts +2 -1
- package/dest/fs/index.d.ts.map +1 -1
- package/dest/fs/index.js +1 -0
- package/dest/fs/run_in_dir.d.ts +1 -1
- package/dest/fs/try_rm_dir.d.ts +3 -0
- package/dest/fs/try_rm_dir.d.ts.map +1 -0
- package/dest/fs/try_rm_dir.js +16 -0
- package/dest/index.d.ts +3 -3
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +2 -2
- package/dest/iterable/all.d.ts +1 -1
- package/dest/iterable/filter.d.ts +1 -1
- package/dest/iterable/filter.js +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/map.js +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/jest/env.js +48 -0
- package/dest/jest/setupAfterEnv.js +3 -0
- package/dest/json-rpc/client/fetch.d.ts +3 -3
- package/dest/json-rpc/client/fetch.d.ts.map +1 -1
- package/dest/json-rpc/client/fetch.js +16 -30
- package/dest/json-rpc/client/index.d.ts +1 -1
- package/dest/json-rpc/client/safe_json_rpc_client.d.ts +10 -4
- package/dest/json-rpc/client/safe_json_rpc_client.d.ts.map +1 -1
- package/dest/json-rpc/client/safe_json_rpc_client.js +173 -13
- package/dest/json-rpc/client/undici.d.ts +1 -1
- package/dest/json-rpc/client/undici.d.ts.map +1 -1
- package/dest/json-rpc/client/undici.js +6 -7
- package/dest/json-rpc/convert.d.ts +3 -10
- package/dest/json-rpc/convert.d.ts.map +1 -1
- package/dest/json-rpc/convert.js +1 -9
- package/dest/json-rpc/errors.d.ts +4 -0
- package/dest/json-rpc/errors.d.ts.map +1 -0
- package/dest/json-rpc/errors.js +6 -0
- package/dest/json-rpc/fixtures/class_a.d.ts +4 -2
- package/dest/json-rpc/fixtures/class_a.d.ts.map +1 -1
- package/dest/json-rpc/fixtures/class_b.d.ts +4 -2
- 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 +3 -2
- package/dest/json-rpc/index.d.ts.map +1 -1
- package/dest/json-rpc/index.js +2 -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 +22 -23
- package/dest/json-rpc/server/safe_json_rpc_server.d.ts.map +1 -1
- package/dest/json-rpc/server/safe_json_rpc_server.js +161 -56
- 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 +2 -3
- package/dest/json-rpc/test/integration.d.ts.map +1 -1
- package/dest/log/console.d.ts +1 -1
- package/dest/log/console.d.ts.map +1 -1
- package/dest/log/gcloud-logger-config.d.ts +1 -2
- package/dest/log/gcloud-logger-config.d.ts.map +1 -1
- package/dest/log/gcloud-logger-config.js +1 -9
- package/dest/log/index.d.ts +5 -5
- package/dest/log/index.d.ts.map +1 -1
- package/dest/log/index.js +4 -4
- package/dest/log/libp2p_logger.d.ts +1 -1
- package/dest/log/libp2p_logger.js +13 -2
- 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 +14 -0
- package/dest/log/noir_debug_log_util.d.ts.map +1 -0
- package/dest/log/noir_debug_log_util.js +14 -0
- package/dest/log/pino-logger.d.ts +4 -4
- package/dest/log/pino-logger.d.ts.map +1 -1
- package/dest/log/pino-logger.js +28 -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/mutex/mutex_database.d.ts.map +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 +3 -0
- package/dest/number/index.d.ts.map +1 -0
- package/dest/number/index.js +12 -0
- package/dest/profiler/index.d.ts +2 -0
- package/dest/profiler/index.d.ts.map +1 -0
- package/dest/profiler/index.js +1 -0
- package/dest/profiler/profiler.d.ts +8 -0
- package/dest/profiler/profiler.d.ts.map +1 -0
- package/dest/profiler/profiler.js +97 -0
- package/dest/promise/index.d.ts +1 -1
- package/dest/promise/running-promise.d.ts +2 -2
- package/dest/promise/running-promise.d.ts.map +1 -1
- package/dest/promise/running-promise.js +2 -2
- 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 +2 -2
- package/dest/queue/batch_queue.d.ts.map +1 -1
- package/dest/queue/batch_queue.js +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 +3 -3
- package/dest/queue/serial_queue.d.ts.map +1 -1
- package/dest/queue/serial_queue.js +7 -5
- package/dest/retry/index.d.ts +4 -3
- package/dest/retry/index.d.ts.map +1 -1
- package/dest/retry/index.js +2 -2
- package/dest/running-promise/index.d.ts +1 -1
- package/dest/schemas/api.d.ts +1 -1
- package/dest/schemas/api.d.ts.map +1 -1
- package/dest/schemas/index.d.ts +1 -1
- package/dest/schemas/parse.d.ts +1 -1
- package/dest/schemas/parse.js +1 -1
- package/dest/schemas/schemas.d.ts +15 -18
- package/dest/schemas/schemas.d.ts.map +1 -1
- package/dest/schemas/schemas.js +20 -8
- package/dest/schemas/types.d.ts +1 -1
- package/dest/schemas/utils.d.ts +4 -6
- package/dest/schemas/utils.d.ts.map +1 -1
- package/dest/schemas/utils.js +15 -5
- package/dest/serialize/buffer_reader.d.ts +28 -3
- package/dest/serialize/buffer_reader.d.ts.map +1 -1
- package/dest/serialize/buffer_reader.js +44 -2
- package/dest/serialize/field_reader.d.ts +11 -2
- package/dest/serialize/field_reader.d.ts.map +1 -1
- package/dest/serialize/field_reader.js +18 -1
- package/dest/serialize/free_funcs.d.ts +24 -22
- package/dest/serialize/free_funcs.d.ts.map +1 -1
- package/dest/serialize/free_funcs.js +21 -27
- package/dest/serialize/index.d.ts +1 -1
- package/dest/serialize/serialize.d.ts +5 -6
- package/dest/serialize/serialize.d.ts.map +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 +8 -3
- package/dest/string/index.d.ts.map +1 -1
- package/dest/string/index.js +27 -1
- package/dest/testing/files/index.d.ts +2 -3
- package/dest/testing/files/index.d.ts.map +1 -1
- package/dest/testing/files/index.js +3 -3
- 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 +3 -2
- package/dest/timer/date.d.ts.map +1 -1
- package/dest/timer/date.js +5 -3
- package/dest/timer/elapsed.d.ts +1 -1
- package/dest/timer/index.d.ts +2 -2
- package/dest/timer/index.d.ts.map +1 -1
- package/dest/timer/index.js +1 -1
- package/dest/timer/timeout.d.ts +19 -6
- package/dest/timer/timeout.d.ts.map +1 -1
- package/dest/timer/timeout.js +43 -22
- 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 -2
- package/dest/transport/index.d.ts.map +1 -1
- package/dest/transport/index.js +0 -1
- package/dest/transport/interface/connector.d.ts +1 -1
- package/dest/transport/interface/connector.d.ts.map +1 -1
- package/dest/transport/interface/listener.d.ts +1 -2
- package/dest/transport/interface/listener.d.ts.map +1 -1
- package/dest/transport/interface/socket.d.ts +1 -1
- package/dest/transport/interface/socket.d.ts.map +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 -2
- package/dest/transport/node/node_connector.d.ts.map +1 -1
- package/dest/transport/node/node_connector_socket.d.ts +1 -2
- package/dest/transport/node/node_connector_socket.d.ts.map +1 -1
- package/dest/transport/node/node_listener.d.ts +1 -2
- package/dest/transport/node/node_listener.d.ts.map +1 -1
- package/dest/transport/node/node_listener_socket.d.ts +1 -2
- package/dest/transport/node/node_listener_socket.d.ts.map +1 -1
- package/dest/transport/transport_client.d.ts +1 -2
- 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 +64 -0
- package/dest/trees/hasher.d.ts +5 -7
- package/dest/trees/hasher.d.ts.map +1 -1
- package/dest/trees/index.d.ts +3 -1
- package/dest/trees/index.d.ts.map +1 -1
- package/dest/trees/index.js +2 -0
- package/dest/trees/indexed_merkle_tree.d.ts +1 -3
- package/dest/trees/indexed_merkle_tree.d.ts.map +1 -1
- package/dest/trees/indexed_merkle_tree_calculator.d.ts +2 -4
- package/dest/trees/indexed_merkle_tree_calculator.d.ts.map +1 -1
- package/dest/trees/indexed_tree_leaf.d.ts +1 -3
- package/dest/trees/indexed_tree_leaf.d.ts.map +1 -1
- package/dest/trees/membership_witness.d.ts +5 -10
- package/dest/trees/membership_witness.d.ts.map +1 -1
- package/dest/trees/membership_witness.js +13 -0
- package/dest/trees/merkle_tree.d.ts +1 -3
- package/dest/trees/merkle_tree.d.ts.map +1 -1
- package/dest/trees/merkle_tree_calculator.d.ts +2 -4
- package/dest/trees/merkle_tree_calculator.d.ts.map +1 -1
- package/dest/trees/sibling_path.d.ts +5 -41
- package/dest/trees/sibling_path.d.ts.map +1 -1
- package/dest/trees/unbalanced_merkle_tree.d.ts +23 -10
- package/dest/trees/unbalanced_merkle_tree.d.ts.map +1 -1
- package/dest/trees/unbalanced_merkle_tree.js +72 -50
- package/dest/trees/unbalanced_merkle_tree_calculator.d.ts +49 -0
- package/dest/trees/unbalanced_merkle_tree_calculator.d.ts.map +1 -0
- package/dest/trees/unbalanced_merkle_tree_calculator.js +158 -0
- 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 +26 -3
- package/dest/types/index.d.ts.map +1 -1
- package/dest/url/index.d.ts +1 -1
- package/dest/url/index.d.ts.map +1 -1
- package/dest/url/index.js +1 -1
- package/dest/validation/index.d.ts +1 -1
- package/package.json +39 -43
- package/src/array/array.ts +13 -16
- package/src/async-pool/index.ts +1 -0
- package/src/bigint/index.ts +20 -0
- package/src/branded-types/epoch.ts +88 -0
- package/src/branded-types/index.ts +4 -0
- package/src/branded-types/slot.ts +88 -0
- package/src/branded-types/types.ts +2 -0
- package/src/buffer/buffer16.ts +133 -0
- package/src/buffer/buffer32.ts +8 -6
- package/src/buffer/index.ts +1 -0
- package/src/collection/array.ts +66 -4
- package/src/collection/object.ts +37 -0
- package/src/config/env_var.ts +152 -52
- package/src/config/index.ts +191 -8
- package/src/config/network_config.ts +16 -0
- package/src/config/network_name.ts +28 -0
- package/src/config/secret_value.ts +49 -0
- 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/bn254_utils.ts +64 -0
- package/src/crypto/bn254/index.ts +173 -0
- package/src/crypto/ecdsa/index.ts +41 -23
- package/src/crypto/grumpkin/index.ts +35 -45
- package/src/crypto/index.ts +2 -0
- package/src/crypto/keys/index.ts +5 -5
- package/src/crypto/pedersen/pedersen.wasm.ts +22 -18
- package/src/crypto/poseidon/index.ts +32 -24
- package/src/crypto/random/index.ts +2 -40
- package/src/crypto/schnorr/index.ts +20 -17
- package/src/crypto/secp256k1/index.ts +15 -11
- package/src/crypto/secp256k1-signer/utils.ts +120 -7
- package/src/crypto/sha256/index.ts +47 -0
- package/src/crypto/sync/index.ts +1 -1
- package/src/crypto/sync/pedersen/index.ts +16 -15
- package/src/crypto/sync/poseidon/index.ts +27 -22
- package/src/eth-address/index.ts +28 -2
- package/src/eth-signature/eth_signature.ts +44 -22
- package/src/fields/bls12_fields.ts +463 -0
- package/src/fields/bls12_point.ts +450 -0
- package/src/fields/fields.ts +53 -9
- package/src/fields/index.ts +2 -0
- package/src/fields/point.ts +20 -3
- package/src/fs/index.ts +1 -0
- package/src/fs/try_rm_dir.ts +15 -0
- package/src/index.ts +2 -2
- package/src/iterable/filter.ts +1 -1
- package/src/iterable/map.ts +1 -1
- package/src/jest/env.mjs +52 -0
- package/src/jest/setupAfterEnv.mjs +3 -0
- package/src/json-rpc/client/fetch.ts +14 -33
- package/src/json-rpc/client/safe_json_rpc_client.ts +226 -13
- package/src/json-rpc/client/undici.ts +8 -15
- package/src/json-rpc/convert.ts +3 -12
- package/src/json-rpc/errors.ts +6 -0
- package/src/json-rpc/fixtures/class_a.ts +4 -1
- package/src/json-rpc/fixtures/class_b.ts +4 -1
- package/src/json-rpc/index.ts +2 -1
- package/src/json-rpc/server/safe_json_rpc_server.ts +141 -48
- package/src/json-rpc/test/integration.ts +1 -1
- package/src/log/console.ts +4 -1
- package/src/log/gcloud-logger-config.ts +3 -7
- package/src/log/index.ts +4 -4
- package/src/log/libp2p_logger.ts +21 -2
- package/src/log/log_fn.ts +1 -1
- package/src/log/noir_debug_log_util.ts +21 -0
- package/src/log/pino-logger.ts +33 -2
- package/src/message/index.ts +5 -1
- package/src/mutex/mutex_database.ts +2 -3
- package/src/number/index.ts +14 -0
- package/src/profiler/index.ts +1 -0
- package/src/profiler/profiler.ts +125 -0
- package/src/promise/running-promise.ts +2 -2
- package/src/queue/batch_queue.ts +1 -1
- package/src/queue/bounded_serial_queue.ts +4 -1
- package/src/queue/serial_queue.ts +5 -5
- package/src/retry/index.ts +10 -5
- package/src/schemas/api.ts +4 -4
- package/src/schemas/parse.ts +1 -1
- package/src/schemas/schemas.ts +28 -10
- package/src/schemas/utils.ts +21 -8
- package/src/serialize/buffer_reader.ts +60 -3
- package/src/serialize/field_reader.ts +27 -3
- package/src/serialize/free_funcs.ts +25 -31
- package/src/serialize/serialize.ts +2 -0
- package/src/string/index.ts +36 -1
- package/src/testing/files/index.ts +7 -3
- package/src/testing/formatting.ts +3 -0
- package/src/testing/index.ts +1 -0
- package/src/timer/date.ts +9 -3
- package/src/timer/index.ts +1 -1
- package/src/timer/timeout.ts +54 -19
- package/src/transport/index.ts +0 -1
- package/src/transport/interface/connector.ts +0 -1
- package/src/transport/interface/listener.ts +2 -3
- package/src/transport/interface/socket.ts +2 -3
- package/src/transport/transport_client.ts +3 -4
- package/src/transport/transport_server.ts +4 -1
- package/src/trees/balanced_merkle_tree.ts +82 -0
- package/src/trees/hasher.ts +4 -4
- package/src/trees/index.ts +2 -0
- package/src/trees/indexed_merkle_tree.ts +5 -1
- package/src/trees/indexed_merkle_tree_calculator.ts +2 -2
- package/src/trees/membership_witness.ts +13 -0
- package/src/trees/merkle_tree.ts +4 -1
- package/src/trees/merkle_tree_calculator.ts +9 -4
- package/src/trees/unbalanced_merkle_tree.ts +98 -42
- package/src/trees/unbalanced_merkle_tree_calculator.ts +187 -0
- package/src/trees/unbalanced_tree_store.ts +5 -1
- package/src/types/index.ts +25 -4
- package/src/url/index.ts +0 -1
- package/dest/crypto/pedersen/pedersen.elliptic.d.ts +0 -13
- package/dest/crypto/pedersen/pedersen.elliptic.d.ts.map +0 -1
- package/dest/crypto/pedersen/pedersen.elliptic.js +0 -582
- package/dest/log/debug.d.ts +0 -56
- package/dest/log/debug.d.ts.map +0 -1
- package/dest/log/debug.js +0 -75
- package/dest/log/log_history.d.ts +0 -31
- package/dest/log/log_history.d.ts.map +0 -1
- package/dest/log/log_history.js +0 -38
- package/dest/transport/browser/index.d.ts +0 -5
- package/dest/transport/browser/index.d.ts.map +0 -1
- package/dest/transport/browser/index.js +0 -4
- package/dest/transport/browser/message_port_socket.d.ts +0 -37
- package/dest/transport/browser/message_port_socket.d.ts.map +0 -1
- package/dest/transport/browser/message_port_socket.js +0 -42
- package/dest/transport/browser/shared_worker_connector.d.ts +0 -19
- package/dest/transport/browser/shared_worker_connector.d.ts.map +0 -1
- package/dest/transport/browser/shared_worker_connector.js +0 -19
- package/dest/transport/browser/shared_worker_listener.d.ts +0 -38
- package/dest/transport/browser/shared_worker_listener.d.ts.map +0 -1
- package/dest/transport/browser/shared_worker_listener.js +0 -33
- package/dest/transport/browser/worker_connector.d.ts +0 -26
- package/dest/transport/browser/worker_connector.d.ts.map +0 -1
- package/dest/transport/browser/worker_connector.js +0 -30
- package/dest/transport/browser/worker_listener.d.ts +0 -39
- package/dest/transport/browser/worker_listener.d.ts.map +0 -1
- package/dest/transport/browser/worker_listener.js +0 -35
- package/dest/wasm/empty_wasi_sdk.d.ts +0 -130
- package/dest/wasm/empty_wasi_sdk.d.ts.map +0 -1
- package/dest/wasm/empty_wasi_sdk.js +0 -148
- package/dest/wasm/index.d.ts +0 -2
- package/dest/wasm/index.d.ts.map +0 -1
- package/dest/wasm/index.js +0 -1
- package/dest/wasm/wasm_module.d.ts +0 -136
- package/dest/wasm/wasm_module.d.ts.map +0 -1
- package/dest/wasm/wasm_module.js +0 -196
- package/dest/worker/browser/index.d.ts +0 -3
- package/dest/worker/browser/index.d.ts.map +0 -1
- package/dest/worker/browser/index.js +0 -2
- package/dest/worker/browser/start_web_module.d.ts +0 -7
- package/dest/worker/browser/start_web_module.d.ts.map +0 -1
- package/dest/worker/browser/start_web_module.js +0 -27
- package/dest/worker/browser/web_data_store.d.ts +0 -24
- package/dest/worker/browser/web_data_store.d.ts.map +0 -1
- package/dest/worker/browser/web_data_store.js +0 -29
- package/dest/worker/browser/web_worker.d.ts +0 -10
- package/dest/worker/browser/web_worker.d.ts.map +0 -1
- package/dest/worker/browser/web_worker.js +0 -25
- package/dest/worker/data_store.d.ts +0 -21
- package/dest/worker/data_store.d.ts.map +0 -1
- package/dest/worker/data_store.js +0 -3
- package/dest/worker/index.d.ts +0 -3
- package/dest/worker/index.d.ts.map +0 -1
- package/dest/worker/index.js +0 -1
- package/dest/worker/node/index.d.ts +0 -3
- package/dest/worker/node/index.d.ts.map +0 -1
- package/dest/worker/node/index.js +0 -2
- package/dest/worker/node/node_data_store.d.ts +0 -13
- package/dest/worker/node/node_data_store.d.ts.map +0 -1
- package/dest/worker/node/node_data_store.js +0 -20
- package/dest/worker/node/node_worker.d.ts +0 -6
- package/dest/worker/node/node_worker.d.ts.map +0 -1
- package/dest/worker/node/node_worker.js +0 -22
- package/dest/worker/node/start_node_module.d.ts +0 -7
- package/dest/worker/node/start_node_module.d.ts.map +0 -1
- package/dest/worker/node/start_node_module.js +0 -31
- package/dest/worker/wasm_worker.d.ts +0 -9
- package/dest/worker/wasm_worker.d.ts.map +0 -1
- package/dest/worker/wasm_worker.js +0 -3
- package/dest/worker/worker_pool.d.ts +0 -40
- package/dest/worker/worker_pool.d.ts.map +0 -1
- package/dest/worker/worker_pool.js +0 -51
- package/src/crypto/pedersen/pedersen.elliptic.ts +0 -584
- package/src/log/debug.ts +0 -104
- package/src/log/log_history.ts +0 -44
- package/src/transport/browser/index.ts +0 -4
- package/src/transport/browser/message_port_socket.ts +0 -48
- package/src/transport/browser/shared_worker_connector.ts +0 -21
- package/src/transport/browser/shared_worker_listener.ts +0 -53
- package/src/transport/browser/worker_connector.ts +0 -30
- package/src/transport/browser/worker_listener.ts +0 -54
- package/src/wasm/README.md +0 -6
- package/src/wasm/empty_wasi_sdk.ts +0 -166
- package/src/wasm/fixtures/gcd.wasm +0 -0
- package/src/wasm/fixtures/gcd.wat +0 -27
- package/src/wasm/index.ts +0 -1
- package/src/wasm/wasm_module.ts +0 -260
- package/src/worker/browser/index.ts +0 -2
- package/src/worker/browser/start_web_module.ts +0 -24
- package/src/worker/browser/web_data_store.ts +0 -38
- package/src/worker/browser/web_worker.ts +0 -25
- package/src/worker/data_store.ts +0 -19
- package/src/worker/index.ts +0 -2
- package/src/worker/node/index.ts +0 -2
- package/src/worker/node/node_data_store.ts +0 -27
- package/src/worker/node/node_worker.ts +0 -23
- package/src/worker/node/start_node_module.ts +0 -30
- package/src/worker/wasm_worker.ts +0 -7
- package/src/worker/worker_pool.ts +0 -73
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import type { ProjPointType } from '@noble/curves/abstract/weierstrass';
|
|
2
|
+
import { inspect } from 'util';
|
|
3
|
+
import { BufferReader } from '../serialize/index.js';
|
|
4
|
+
import { BLS12Fq, BLS12Fr } from './bls12_fields.js';
|
|
5
|
+
import { Fr } from './fields.js';
|
|
6
|
+
/**
|
|
7
|
+
* Represents a Point on an elliptic curve with x and y coordinates.
|
|
8
|
+
* The Point class provides methods for creating instances from different input types,
|
|
9
|
+
* converting instances to various output formats, and checking the equality of points.
|
|
10
|
+
* TODO(#7386): Clean up this class.
|
|
11
|
+
*/
|
|
12
|
+
export declare class BLS12Point {
|
|
13
|
+
readonly x: BLS12Fq;
|
|
14
|
+
readonly y: BLS12Fq;
|
|
15
|
+
readonly isInfinite: boolean;
|
|
16
|
+
static ZERO: BLS12Point;
|
|
17
|
+
static ONE: BLS12Point;
|
|
18
|
+
static SIZE_IN_BYTES: number;
|
|
19
|
+
static COMPRESSED_SIZE_IN_BYTES: number;
|
|
20
|
+
static COMPRESSED_ZERO: Buffer<ArrayBufferLike>;
|
|
21
|
+
constructor(
|
|
22
|
+
/**
|
|
23
|
+
* The point's x coordinate
|
|
24
|
+
*/
|
|
25
|
+
x: BLS12Fq,
|
|
26
|
+
/**
|
|
27
|
+
* The point's y coordinate
|
|
28
|
+
*/
|
|
29
|
+
y: BLS12Fq,
|
|
30
|
+
/**
|
|
31
|
+
* Whether the point is at infinity
|
|
32
|
+
*/
|
|
33
|
+
isInfinite: boolean);
|
|
34
|
+
toJSON(): `0x${string}`;
|
|
35
|
+
[inspect.custom](): string;
|
|
36
|
+
static get schema(): import("zod").ZodType<BLS12Point, any, string>;
|
|
37
|
+
/**
|
|
38
|
+
* Generate a random Point instance.
|
|
39
|
+
*
|
|
40
|
+
* @returns A randomly generated Point instance.
|
|
41
|
+
*/
|
|
42
|
+
static random(): BLS12Point;
|
|
43
|
+
/**
|
|
44
|
+
* Create a Point instance from a given buffer or BufferReader.
|
|
45
|
+
* The input 'buffer' should have exactly 96 bytes representing the x and y coordinates.
|
|
46
|
+
*
|
|
47
|
+
* @param buffer - The buffer or BufferReader containing the x and y coordinates of the point.
|
|
48
|
+
* @returns A Point instance.
|
|
49
|
+
*/
|
|
50
|
+
static fromBuffer(buffer: Buffer | BufferReader): BLS12Point;
|
|
51
|
+
/**
|
|
52
|
+
* Create a Point instance from a hex-encoded string.
|
|
53
|
+
* The input should be prefixed with '0x' or not, and have exactly 128 hex characters representing the x and y coordinates.
|
|
54
|
+
* Throws an error if the input length is invalid or coordinate values are out of range.
|
|
55
|
+
*
|
|
56
|
+
* @param str - The hex-encoded string representing the Point coordinates.
|
|
57
|
+
* @returns A Point instance.
|
|
58
|
+
*/
|
|
59
|
+
static fromString(str: string): BLS12Point;
|
|
60
|
+
/**
|
|
61
|
+
* Create a compressed buffer instance from a point.
|
|
62
|
+
* @dev NOTE: The compression standard for BLS12-381 differs from BN curves. Instead of
|
|
63
|
+
* one is_positive flag, we have three flags to prepend:
|
|
64
|
+
* - is_compressed: indicator that the point is compressed
|
|
65
|
+
* - is_infinity: whether the point the point at infinity
|
|
66
|
+
* - is_greater: only set if is_compressed && !is_infinity && y > (p - 1)/2
|
|
67
|
+
* See https://github.com/arkworks-rs/algebra/blob/master/curves/bls12_381/src/curves/g1.rs -> serialize_with_mode() -> encoding
|
|
68
|
+
* and noble-curves/src/bls12-381.ts -> setMask()
|
|
69
|
+
* @dev Most of the logic below is taken from noble-curves/src/bls12-381.ts -> toBytes()
|
|
70
|
+
* @param point A BLS12Point instance.
|
|
71
|
+
* @returns The buffer containing the x coordinate and the flags of the y coordinate.
|
|
72
|
+
*/
|
|
73
|
+
compress(): Buffer;
|
|
74
|
+
/**
|
|
75
|
+
* Create a Point instance from a compressed buffer.
|
|
76
|
+
* @dev See compress() above for compression encoding for BLS12-381.
|
|
77
|
+
* @dev Most of the logic below is taken from noble-curves/src/bls12-381.ts -> fromBytes()
|
|
78
|
+
* @param buffer - The buffer containing the x coordinate and the flags of the y coordinate.
|
|
79
|
+
* @returns A BLS12Point instance.
|
|
80
|
+
*/
|
|
81
|
+
static decompress(buffer: Buffer): BLS12Point;
|
|
82
|
+
/**
|
|
83
|
+
* Converts a Point to two BN254 Fr elements by storing its compressed form (48 bytes) as:
|
|
84
|
+
* +-------------------+------------------------+
|
|
85
|
+
* | 31 bytes | 17 bytes |
|
|
86
|
+
* +-------------------+------------------------+
|
|
87
|
+
* | Field Element 1 | Field Element 2 |
|
|
88
|
+
* | [0][bytes 0-30] | [0...0][bytes 31-47] |
|
|
89
|
+
* +-------------------+------------------------+
|
|
90
|
+
* Used in the rollup circuits to store blob commitments in the native field type. See blob.ts.
|
|
91
|
+
* @param point - A BLS12Point instance.
|
|
92
|
+
* @returns The point fields.
|
|
93
|
+
*/
|
|
94
|
+
toBN254Fields(): Fr[];
|
|
95
|
+
/**
|
|
96
|
+
* Creates a Point instance from 2 BN254 Fr fields as encoded in toBNFields() above.
|
|
97
|
+
* Used in the rollup circuits to store blob commitments in the native field type. See blob.ts.
|
|
98
|
+
* @param fields - The encoded BN254 fields.
|
|
99
|
+
* @returns The point fields.
|
|
100
|
+
*/
|
|
101
|
+
static fromBN254Fields(fields: [Fr, Fr]): BLS12Point;
|
|
102
|
+
/**
|
|
103
|
+
* Creates a point from an array of 2 fields.
|
|
104
|
+
* @returns The point
|
|
105
|
+
*/
|
|
106
|
+
static fromBLS12FqFields(fields: BLS12Fq[]): BLS12Point;
|
|
107
|
+
/**
|
|
108
|
+
* Creates a point from @noble/curves projective point definition.
|
|
109
|
+
* @returns The point
|
|
110
|
+
*/
|
|
111
|
+
static fromNobleProjectivePoint(point: ProjPointType<bigint>): BLS12Point;
|
|
112
|
+
/**
|
|
113
|
+
* Uses the x coordinate and isPositive flag (+/-) to reconstruct the point.
|
|
114
|
+
* @param x - The x coordinate of the point
|
|
115
|
+
* @param sign - The "sign" of the y coordinate - note that this is not a sign as is known in integer arithmetic.
|
|
116
|
+
* Instead it is a boolean flag that determines whether the y coordinate is <= (Fr.MODULUS - 1) / 2
|
|
117
|
+
* @returns The point as an array of 2 fields
|
|
118
|
+
*/
|
|
119
|
+
static fromXAndSign(x: BLS12Fq, sign: boolean): BLS12Point;
|
|
120
|
+
/**
|
|
121
|
+
* @param x - The x coordinate of the point
|
|
122
|
+
* @returns y^2 such that y^2 = x^3 + 4
|
|
123
|
+
*/
|
|
124
|
+
static YSquaredFromX(x: BLS12Fq): BLS12Fq;
|
|
125
|
+
/**
|
|
126
|
+
* @param x - The x coordinate of the point
|
|
127
|
+
* @returns The y coordinate of the point, if it exists on BLS12-381
|
|
128
|
+
*/
|
|
129
|
+
static YFromX(x: BLS12Fq): BLS12Fq | null;
|
|
130
|
+
/**
|
|
131
|
+
* @param x - The x coordinate of the point
|
|
132
|
+
* @param y - The y coordinate of the point
|
|
133
|
+
* @returns Whether the point exists on BLS12-381
|
|
134
|
+
*/
|
|
135
|
+
static isOnCurve(x: BLS12Fq, y: BLS12Fq): boolean;
|
|
136
|
+
/**
|
|
137
|
+
* Returns the contents of the point as an array of 2 fields.
|
|
138
|
+
* @returns The point as an array of 2 fields
|
|
139
|
+
*/
|
|
140
|
+
toBLS12FqFields(): BLS12Fq[];
|
|
141
|
+
/**
|
|
142
|
+
* Returns the x coordinate and the sign of the y coordinate.
|
|
143
|
+
* @dev The y sign can be determined by checking if the y coordinate is greater than half of the modulus.
|
|
144
|
+
* @returns The x coordinate and the sign of the y coordinate.
|
|
145
|
+
*/
|
|
146
|
+
toXAndSign(): [BLS12Fq, boolean];
|
|
147
|
+
/**
|
|
148
|
+
* Returns the contents of the point as BigInts.
|
|
149
|
+
* @returns The point as BigInts
|
|
150
|
+
*/
|
|
151
|
+
toBigInts(): {
|
|
152
|
+
x: bigint;
|
|
153
|
+
y: bigint;
|
|
154
|
+
isInfinite: bigint;
|
|
155
|
+
};
|
|
156
|
+
/**
|
|
157
|
+
* Converts the Point instance to a Buffer representation of the coordinates.
|
|
158
|
+
* @returns A Buffer representation of the Point instance.
|
|
159
|
+
* @dev Note that toBuffer does not include the isInfinite flag and other serialization methods do (e.g. toBigInts).
|
|
160
|
+
*/
|
|
161
|
+
toBuffer(): Buffer<ArrayBufferLike>;
|
|
162
|
+
/**
|
|
163
|
+
* Convert the Point instance to a hexadecimal string representation.
|
|
164
|
+
* The output string is prefixed with '0x' and consists of exactly 128 hex characters,
|
|
165
|
+
* representing the concatenated x and y coordinates of the point.
|
|
166
|
+
*
|
|
167
|
+
* @returns A hex-encoded string representing the Point instance.
|
|
168
|
+
*/
|
|
169
|
+
toString(): `0x${string}`;
|
|
170
|
+
/**
|
|
171
|
+
* Check if two Point instances are equal by comparing their buffer values.
|
|
172
|
+
* Returns true if the buffer values are the same, and false otherwise.
|
|
173
|
+
*
|
|
174
|
+
* @param rhs - The Point instance to compare with the current instance.
|
|
175
|
+
* @returns A boolean indicating whether the two Point instances are equal.
|
|
176
|
+
*/
|
|
177
|
+
equals(rhs: BLS12Point): boolean;
|
|
178
|
+
/**
|
|
179
|
+
* Check whether the point is zero.
|
|
180
|
+
*/
|
|
181
|
+
isZero(): boolean;
|
|
182
|
+
/**
|
|
183
|
+
* Check if this is point at infinity.
|
|
184
|
+
* Check this is consistent with how bb is encoding the point at infinity
|
|
185
|
+
*/
|
|
186
|
+
get inf(): boolean;
|
|
187
|
+
/** Arithmetic - wrapper around noble curves */
|
|
188
|
+
toNobleProjectivePoint(): ProjPointType<bigint>;
|
|
189
|
+
add(rhs: BLS12Point): BLS12Point;
|
|
190
|
+
negate(): BLS12Point;
|
|
191
|
+
sub(rhs: BLS12Point): BLS12Point;
|
|
192
|
+
/**
|
|
193
|
+
* @dev From noble curves package:
|
|
194
|
+
* Constant time multiplication. Uses wNAF method. Windowed method may be 10% faster,
|
|
195
|
+
* but takes 2x longer to generate and consumes 2x memory.
|
|
196
|
+
* Uses precomputes when available, uses endomorphism for Koblitz curves.
|
|
197
|
+
* @param scalar by which the point would be multiplied
|
|
198
|
+
* @returns New point
|
|
199
|
+
*/
|
|
200
|
+
mul(rhs: BLS12Fr): BLS12Point;
|
|
201
|
+
/**
|
|
202
|
+
* @dev From noble curves package:
|
|
203
|
+
* Non-constant-time multiplication. Uses double-and-add algorithm.
|
|
204
|
+
* It's faster, but should only be used when you don't care about an exposed private key e.g. sig verification, which works over *public* keys.
|
|
205
|
+
* @param scalar by which the point would be multiplied
|
|
206
|
+
* @returns New point
|
|
207
|
+
*/
|
|
208
|
+
mulUnsafe(rhs: BLS12Fr): BLS12Point;
|
|
209
|
+
/**
|
|
210
|
+
* @dev From noble curves package:
|
|
211
|
+
* Efficiently calculate `aP + bQ`. Unsafe, can expose private key, if used incorrectly.
|
|
212
|
+
* Not using Strauss-Shamir trick: precomputation tables are faster. The trick could be useful if both P and Q are not G (not in our case).
|
|
213
|
+
* @returns affine point
|
|
214
|
+
*/
|
|
215
|
+
mulAndAddUnsafe(a: BLS12Fr, b: BLS12Fr, Q: BLS12Point): BLS12Point;
|
|
216
|
+
}
|
|
217
|
+
export declare class BLSPointNotOnCurveError extends Error {
|
|
218
|
+
constructor(x: BLS12Fq, y?: BLS12Fq);
|
|
219
|
+
}
|
|
220
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYmxzMTJfcG9pbnQuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9maWVsZHMvYmxzMTJfcG9pbnQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxLQUFLLEVBQUUsYUFBYSxFQUFFLE1BQU0sb0NBQW9DLENBQUM7QUFHeEUsT0FBTyxFQUFFLE9BQU8sRUFBRSxNQUFNLE1BQU0sQ0FBQztBQUsvQixPQUFPLEVBQUUsWUFBWSxFQUFxQixNQUFNLHVCQUF1QixDQUFDO0FBRXhFLE9BQU8sRUFBRSxPQUFPLEVBQUUsT0FBTyxFQUFFLE1BQU0sbUJBQW1CLENBQUM7QUFDckQsT0FBTyxFQUFFLEVBQUUsRUFBRSxNQUFNLGFBQWEsQ0FBQztBQ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AAS,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,WAWtC;IAED;;;OAGG;IACH,eAAe,cAEd;IAED;;;;OAIG;IACH,UAAU,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,CAE/B;IAED;;;OAGG;IACH,SAAS;;;;MAMR;IAED;;;;OAIG;IACH,QAAQ,4BAMP;IAED;;;;;;OAMG;IACH,QAAQ,kBAEP;IAED;;;;;;OAMG;IACH,MAAM,CAAC,GAAG,EAAE,UAAU,WAErB;IAED;;OAEG;IACH,MAAM,YAEL;IAED;;;OAGG;IACH,IAAW,GAAG,YAEb;IAED,+CAA+C;IAE/C,sBAAsB,0BAErB;IAED,GAAG,CAAC,GAAG,EAAE,UAAU,cAElB;IAED,MAAM,eAEL;IAED,GAAG,CAAC,GAAG,EAAE,UAAU,cAElB;IAED;;;;;;;OAOG;IACH,GAAG,CAAC,GAAG,EAAE,OAAO,cAMf;IAED;;;;;;OAMG;IACH,SAAS,CAAC,GAAG,EAAE,OAAO,cAErB;IAED;;;;;OAKG;IACH,eAAe,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,UAAU,cAOpD;CACF;AAED,qBAAa,uBAAwB,SAAQ,KAAK;IAChD,YAAY,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,EAAE,OAAO,EAGlC;CACF"}
|
|
@@ -0,0 +1,398 @@
|
|
|
1
|
+
/* eslint-disable camelcase */ import { bls12_381 } from '@noble/curves/bls12-381';
|
|
2
|
+
import { inspect } from 'util';
|
|
3
|
+
import { toBufferBE } from '../bigint-buffer/index.js';
|
|
4
|
+
import { randomBoolean } from '../crypto/random/index.js';
|
|
5
|
+
import { hexSchemaFor } from '../schemas/utils.js';
|
|
6
|
+
import { BufferReader, serializeToBuffer } from '../serialize/index.js';
|
|
7
|
+
import { bufferToHex, hexToBuffer } from '../string/index.js';
|
|
8
|
+
import { BLS12Fq } from './bls12_fields.js';
|
|
9
|
+
import { Fr } from './fields.js';
|
|
10
|
+
/**
|
|
11
|
+
* Represents a Point on an elliptic curve with x and y coordinates.
|
|
12
|
+
* The Point class provides methods for creating instances from different input types,
|
|
13
|
+
* converting instances to various output formats, and checking the equality of points.
|
|
14
|
+
* TODO(#7386): Clean up this class.
|
|
15
|
+
*/ export class BLS12Point {
|
|
16
|
+
x;
|
|
17
|
+
y;
|
|
18
|
+
isInfinite;
|
|
19
|
+
static ZERO = new BLS12Point(BLS12Fq.ZERO, BLS12Fq.ZERO, true);
|
|
20
|
+
static ONE = new BLS12Point(new BLS12Fq(bls12_381.G1.CURVE.Gx), new BLS12Fq(bls12_381.G1.CURVE.Gy), false);
|
|
21
|
+
static SIZE_IN_BYTES = BLS12Fq.SIZE_IN_BYTES * 2;
|
|
22
|
+
static COMPRESSED_SIZE_IN_BYTES = BLS12Fq.SIZE_IN_BYTES;
|
|
23
|
+
static COMPRESSED_ZERO = setMask(Buffer.alloc(BLS12Fq.SIZE_IN_BYTES), {
|
|
24
|
+
infinity: true,
|
|
25
|
+
compressed: true
|
|
26
|
+
});
|
|
27
|
+
constructor(/**
|
|
28
|
+
* The point's x coordinate
|
|
29
|
+
*/ x, /**
|
|
30
|
+
* The point's y coordinate
|
|
31
|
+
*/ y, /**
|
|
32
|
+
* Whether the point is at infinity
|
|
33
|
+
*/ isInfinite){
|
|
34
|
+
this.x = x;
|
|
35
|
+
this.y = y;
|
|
36
|
+
this.isInfinite = isInfinite;
|
|
37
|
+
if (!BLS12Point.isOnCurve(x, y)) {
|
|
38
|
+
throw new BLSPointNotOnCurveError(x, y);
|
|
39
|
+
}
|
|
40
|
+
if (isInfinite && !(x.equals(BLS12Fq.ZERO) && y.equals(BLS12Fq.ZERO))) {
|
|
41
|
+
throw new Error(`BLS12-381 G1 point ( ${x.toString()}, ${y.toString()} ) is not infinite.`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
toJSON() {
|
|
45
|
+
return this.toString();
|
|
46
|
+
}
|
|
47
|
+
[inspect.custom]() {
|
|
48
|
+
return `BLS12Point {
|
|
49
|
+
x: ${inspect(this.x)},
|
|
50
|
+
y: ${inspect(this.y)},
|
|
51
|
+
isInfinite: ${inspect(this.isInfinite)},
|
|
52
|
+
}`;
|
|
53
|
+
}
|
|
54
|
+
static get schema() {
|
|
55
|
+
return hexSchemaFor(BLS12Point);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Generate a random Point instance.
|
|
59
|
+
*
|
|
60
|
+
* @returns A randomly generated Point instance.
|
|
61
|
+
*/ static random() {
|
|
62
|
+
while(true){
|
|
63
|
+
try {
|
|
64
|
+
return BLS12Point.fromXAndSign(BLS12Fq.random(), randomBoolean());
|
|
65
|
+
} catch (e) {
|
|
66
|
+
if (!(e instanceof BLSPointNotOnCurveError)) {
|
|
67
|
+
throw e;
|
|
68
|
+
}
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Create a Point instance from a given buffer or BufferReader.
|
|
75
|
+
* The input 'buffer' should have exactly 96 bytes representing the x and y coordinates.
|
|
76
|
+
*
|
|
77
|
+
* @param buffer - The buffer or BufferReader containing the x and y coordinates of the point.
|
|
78
|
+
* @returns A Point instance.
|
|
79
|
+
*/ static fromBuffer(buffer) {
|
|
80
|
+
const reader = BufferReader.asReader(buffer);
|
|
81
|
+
const [x, y] = [
|
|
82
|
+
BLS12Fq.fromBuffer(reader),
|
|
83
|
+
BLS12Fq.fromBuffer(reader)
|
|
84
|
+
];
|
|
85
|
+
return new this(x, y, x.isZero() && y.isZero());
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Create a Point instance from a hex-encoded string.
|
|
89
|
+
* The input should be prefixed with '0x' or not, and have exactly 128 hex characters representing the x and y coordinates.
|
|
90
|
+
* Throws an error if the input length is invalid or coordinate values are out of range.
|
|
91
|
+
*
|
|
92
|
+
* @param str - The hex-encoded string representing the Point coordinates.
|
|
93
|
+
* @returns A Point instance.
|
|
94
|
+
*/ static fromString(str) {
|
|
95
|
+
return this.fromBuffer(hexToBuffer(str));
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Create a compressed buffer instance from a point.
|
|
99
|
+
* @dev NOTE: The compression standard for BLS12-381 differs from BN curves. Instead of
|
|
100
|
+
* one is_positive flag, we have three flags to prepend:
|
|
101
|
+
* - is_compressed: indicator that the point is compressed
|
|
102
|
+
* - is_infinity: whether the point the point at infinity
|
|
103
|
+
* - is_greater: only set if is_compressed && !is_infinity && y > (p - 1)/2
|
|
104
|
+
* See https://github.com/arkworks-rs/algebra/blob/master/curves/bls12_381/src/curves/g1.rs -> serialize_with_mode() -> encoding
|
|
105
|
+
* and noble-curves/src/bls12-381.ts -> setMask()
|
|
106
|
+
* @dev Most of the logic below is taken from noble-curves/src/bls12-381.ts -> toBytes()
|
|
107
|
+
* @param point A BLS12Point instance.
|
|
108
|
+
* @returns The buffer containing the x coordinate and the flags of the y coordinate.
|
|
109
|
+
*/ compress() {
|
|
110
|
+
if (this.isZero()) {
|
|
111
|
+
return BLS12Point.COMPRESSED_ZERO;
|
|
112
|
+
}
|
|
113
|
+
const isGreater = this.y.isNegative();
|
|
114
|
+
return setMask(toBufferBE(this.x.toBigInt(), BLS12Fq.SIZE_IN_BYTES), {
|
|
115
|
+
compressed: true,
|
|
116
|
+
sort: isGreater
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Create a Point instance from a compressed buffer.
|
|
121
|
+
* @dev See compress() above for compression encoding for BLS12-381.
|
|
122
|
+
* @dev Most of the logic below is taken from noble-curves/src/bls12-381.ts -> fromBytes()
|
|
123
|
+
* @param buffer - The buffer containing the x coordinate and the flags of the y coordinate.
|
|
124
|
+
* @returns A BLS12Point instance.
|
|
125
|
+
*/ static decompress(buffer) {
|
|
126
|
+
const { compressed, infinity, sort, value: decompressed } = parseMask(buffer);
|
|
127
|
+
if (decompressed.length === BLS12Fq.SIZE_IN_BYTES && compressed) {
|
|
128
|
+
const x = new BLS12Fq(decompressed);
|
|
129
|
+
if (infinity) {
|
|
130
|
+
if (!x.isZero()) {
|
|
131
|
+
throw new Error('Non-empty compressed G1 point at infinity');
|
|
132
|
+
}
|
|
133
|
+
return new BLS12Point(x, BLS12Fq.ZERO, true);
|
|
134
|
+
}
|
|
135
|
+
let y = this.YFromX(x);
|
|
136
|
+
if (!y) {
|
|
137
|
+
throw new BLSPointNotOnCurveError(x);
|
|
138
|
+
}
|
|
139
|
+
if (y.isNegative() !== sort) {
|
|
140
|
+
y = y.negate();
|
|
141
|
+
}
|
|
142
|
+
return new BLS12Point(x, y, infinity);
|
|
143
|
+
} else {
|
|
144
|
+
throw new Error('Invalid compressed G1 point of BLS12-381');
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Converts a Point to two BN254 Fr elements by storing its compressed form (48 bytes) as:
|
|
149
|
+
* +-------------------+------------------------+
|
|
150
|
+
* | 31 bytes | 17 bytes |
|
|
151
|
+
* +-------------------+------------------------+
|
|
152
|
+
* | Field Element 1 | Field Element 2 |
|
|
153
|
+
* | [0][bytes 0-30] | [0...0][bytes 31-47] |
|
|
154
|
+
* +-------------------+------------------------+
|
|
155
|
+
* Used in the rollup circuits to store blob commitments in the native field type. See blob.ts.
|
|
156
|
+
* @param point - A BLS12Point instance.
|
|
157
|
+
* @returns The point fields.
|
|
158
|
+
*/ toBN254Fields() {
|
|
159
|
+
const compressed = this.compress();
|
|
160
|
+
return [
|
|
161
|
+
new Fr(compressed.subarray(0, 31)),
|
|
162
|
+
new Fr(compressed.subarray(31, 48))
|
|
163
|
+
];
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Creates a Point instance from 2 BN254 Fr fields as encoded in toBNFields() above.
|
|
167
|
+
* Used in the rollup circuits to store blob commitments in the native field type. See blob.ts.
|
|
168
|
+
* @param fields - The encoded BN254 fields.
|
|
169
|
+
* @returns The point fields.
|
|
170
|
+
*/ static fromBN254Fields(fields) {
|
|
171
|
+
return BLS12Point.decompress(Buffer.concat([
|
|
172
|
+
fields[0].toBuffer().subarray(1),
|
|
173
|
+
fields[1].toBuffer().subarray(-17)
|
|
174
|
+
]));
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Creates a point from an array of 2 fields.
|
|
178
|
+
* @returns The point
|
|
179
|
+
*/ static fromBLS12FqFields(fields) {
|
|
180
|
+
return new this(fields[0], fields[1], !fields[2].isEmpty());
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Creates a point from @noble/curves projective point definition.
|
|
184
|
+
* @returns The point
|
|
185
|
+
*/ static fromNobleProjectivePoint(point) {
|
|
186
|
+
const affine = point.toAffine();
|
|
187
|
+
return new BLS12Point(new BLS12Fq(affine.x), new BLS12Fq(affine.y), point.equals(bls12_381.G1.ProjectivePoint.ZERO));
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Uses the x coordinate and isPositive flag (+/-) to reconstruct the point.
|
|
191
|
+
* @param x - The x coordinate of the point
|
|
192
|
+
* @param sign - The "sign" of the y coordinate - note that this is not a sign as is known in integer arithmetic.
|
|
193
|
+
* Instead it is a boolean flag that determines whether the y coordinate is <= (Fr.MODULUS - 1) / 2
|
|
194
|
+
* @returns The point as an array of 2 fields
|
|
195
|
+
*/ static fromXAndSign(x, sign) {
|
|
196
|
+
const y = BLS12Point.YFromX(x);
|
|
197
|
+
if (y == null) {
|
|
198
|
+
throw new BLSPointNotOnCurveError(x);
|
|
199
|
+
}
|
|
200
|
+
const yPositiveBigInt = y.isNegative() ? BLS12Fq.MODULUS - y.toBigInt() : y.toBigInt();
|
|
201
|
+
const yNegativeBigInt = BLS12Fq.MODULUS - yPositiveBigInt;
|
|
202
|
+
// Choose the positive or negative root based on isPositive
|
|
203
|
+
const finalY = sign ? new BLS12Fq(yPositiveBigInt) : new BLS12Fq(yNegativeBigInt);
|
|
204
|
+
// Create and return the new Point
|
|
205
|
+
return new this(x, finalY, false);
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* @param x - The x coordinate of the point
|
|
209
|
+
* @returns y^2 such that y^2 = x^3 + 4
|
|
210
|
+
*/ static YSquaredFromX(x) {
|
|
211
|
+
return new BLS12Fq(bls12_381.G1.weierstrassEquation(x.toBigInt()));
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* @param x - The x coordinate of the point
|
|
215
|
+
* @returns The y coordinate of the point, if it exists on BLS12-381
|
|
216
|
+
*/ static YFromX(x) {
|
|
217
|
+
const ySquared = this.YSquaredFromX(x);
|
|
218
|
+
// y is then simply the square root. Note however that not all square roots exist in the field: if sqrt returns null
|
|
219
|
+
// then there is no point in the curve with this x coordinate.
|
|
220
|
+
return ySquared.sqrt();
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* @param x - The x coordinate of the point
|
|
224
|
+
* @param y - The y coordinate of the point
|
|
225
|
+
* @returns Whether the point exists on BLS12-381
|
|
226
|
+
*/ static isOnCurve(x, y) {
|
|
227
|
+
if (x.isZero() && y.isZero()) {
|
|
228
|
+
// Representation of inf point
|
|
229
|
+
return true;
|
|
230
|
+
}
|
|
231
|
+
// The BLS12-381 equation is y^2 = x^3 + 4. We could use `YFromX` and then compare to `this.y`, but this would
|
|
232
|
+
// involve computing the square root of y, of which there are two possible valid values. This method is also faster.
|
|
233
|
+
const lhs = y.square();
|
|
234
|
+
const rhs = this.YSquaredFromX(x);
|
|
235
|
+
return lhs.equals(rhs);
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Returns the contents of the point as an array of 2 fields.
|
|
239
|
+
* @returns The point as an array of 2 fields
|
|
240
|
+
*/ toBLS12FqFields() {
|
|
241
|
+
return [
|
|
242
|
+
this.x,
|
|
243
|
+
this.y,
|
|
244
|
+
new BLS12Fq(this.isInfinite ? 1 : 0)
|
|
245
|
+
];
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Returns the x coordinate and the sign of the y coordinate.
|
|
249
|
+
* @dev The y sign can be determined by checking if the y coordinate is greater than half of the modulus.
|
|
250
|
+
* @returns The x coordinate and the sign of the y coordinate.
|
|
251
|
+
*/ toXAndSign() {
|
|
252
|
+
return [
|
|
253
|
+
this.x,
|
|
254
|
+
!this.y.isNegative()
|
|
255
|
+
];
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Returns the contents of the point as BigInts.
|
|
259
|
+
* @returns The point as BigInts
|
|
260
|
+
*/ toBigInts() {
|
|
261
|
+
return {
|
|
262
|
+
x: this.x.toBigInt(),
|
|
263
|
+
y: this.y.toBigInt(),
|
|
264
|
+
isInfinite: this.isInfinite ? 1n : 0n
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Converts the Point instance to a Buffer representation of the coordinates.
|
|
269
|
+
* @returns A Buffer representation of the Point instance.
|
|
270
|
+
* @dev Note that toBuffer does not include the isInfinite flag and other serialization methods do (e.g. toBigInts).
|
|
271
|
+
*/ toBuffer() {
|
|
272
|
+
const buf = serializeToBuffer([
|
|
273
|
+
this.x,
|
|
274
|
+
this.y
|
|
275
|
+
]);
|
|
276
|
+
if (buf.length !== BLS12Point.SIZE_IN_BYTES) {
|
|
277
|
+
throw new Error(`Invalid buffer length for Point: ${buf.length}`);
|
|
278
|
+
}
|
|
279
|
+
return buf;
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Convert the Point instance to a hexadecimal string representation.
|
|
283
|
+
* The output string is prefixed with '0x' and consists of exactly 128 hex characters,
|
|
284
|
+
* representing the concatenated x and y coordinates of the point.
|
|
285
|
+
*
|
|
286
|
+
* @returns A hex-encoded string representing the Point instance.
|
|
287
|
+
*/ toString() {
|
|
288
|
+
return bufferToHex(this.toBuffer());
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Check if two Point instances are equal by comparing their buffer values.
|
|
292
|
+
* Returns true if the buffer values are the same, and false otherwise.
|
|
293
|
+
*
|
|
294
|
+
* @param rhs - The Point instance to compare with the current instance.
|
|
295
|
+
* @returns A boolean indicating whether the two Point instances are equal.
|
|
296
|
+
*/ equals(rhs) {
|
|
297
|
+
return this.x.equals(rhs.x) && this.y.equals(rhs.y);
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Check whether the point is zero.
|
|
301
|
+
*/ isZero() {
|
|
302
|
+
return this.x.isZero() && this.y.isZero();
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Check if this is point at infinity.
|
|
306
|
+
* Check this is consistent with how bb is encoding the point at infinity
|
|
307
|
+
*/ get inf() {
|
|
308
|
+
return this.isInfinite;
|
|
309
|
+
}
|
|
310
|
+
/** Arithmetic - wrapper around noble curves */ toNobleProjectivePoint() {
|
|
311
|
+
return bls12_381.G1.ProjectivePoint.fromAffine(this.toBigInts());
|
|
312
|
+
}
|
|
313
|
+
add(rhs) {
|
|
314
|
+
return BLS12Point.fromNobleProjectivePoint(this.toNobleProjectivePoint().add(rhs.toNobleProjectivePoint()));
|
|
315
|
+
}
|
|
316
|
+
negate() {
|
|
317
|
+
return new BLS12Point(this.x, this.y.negate(), this.isInfinite);
|
|
318
|
+
}
|
|
319
|
+
sub(rhs) {
|
|
320
|
+
return BLS12Point.fromNobleProjectivePoint(this.toNobleProjectivePoint().subtract(rhs.toNobleProjectivePoint()));
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* @dev From noble curves package:
|
|
324
|
+
* Constant time multiplication. Uses wNAF method. Windowed method may be 10% faster,
|
|
325
|
+
* but takes 2x longer to generate and consumes 2x memory.
|
|
326
|
+
* Uses precomputes when available, uses endomorphism for Koblitz curves.
|
|
327
|
+
* @param scalar by which the point would be multiplied
|
|
328
|
+
* @returns New point
|
|
329
|
+
*/ mul(rhs) {
|
|
330
|
+
// Note: noble curves throws on 0
|
|
331
|
+
if (rhs.isZero()) {
|
|
332
|
+
return BLS12Point.ZERO;
|
|
333
|
+
}
|
|
334
|
+
return BLS12Point.fromNobleProjectivePoint(this.toNobleProjectivePoint().multiply(rhs.toBigInt()));
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* @dev From noble curves package:
|
|
338
|
+
* Non-constant-time multiplication. Uses double-and-add algorithm.
|
|
339
|
+
* It's faster, but should only be used when you don't care about an exposed private key e.g. sig verification, which works over *public* keys.
|
|
340
|
+
* @param scalar by which the point would be multiplied
|
|
341
|
+
* @returns New point
|
|
342
|
+
*/ mulUnsafe(rhs) {
|
|
343
|
+
return BLS12Point.fromNobleProjectivePoint(this.toNobleProjectivePoint().multiplyUnsafe(rhs.toBigInt()));
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* @dev From noble curves package:
|
|
347
|
+
* Efficiently calculate `aP + bQ`. Unsafe, can expose private key, if used incorrectly.
|
|
348
|
+
* Not using Strauss-Shamir trick: precomputation tables are faster. The trick could be useful if both P and Q are not G (not in our case).
|
|
349
|
+
* @returns affine point
|
|
350
|
+
*/ mulAndAddUnsafe(a, b, Q) {
|
|
351
|
+
const res = this.toNobleProjectivePoint().multiplyAndAddUnsafe(Q.toNobleProjectivePoint(), a.toBigInt(), b.toBigInt());
|
|
352
|
+
return res ? BLS12Point.fromNobleProjectivePoint(res) : BLS12Point.ZERO;
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
export class BLSPointNotOnCurveError extends Error {
|
|
356
|
+
constructor(x, y){
|
|
357
|
+
super('The given G1 point is not on the BLS12-381 curve: (' + x.toString() + ', ' + (y ? y.toString() : '') + ')');
|
|
358
|
+
this.name = 'NotOnCurveError';
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* Lifted from noble curves bls12_381 since it's not exposed. Sets the flags
|
|
363
|
+
* for BLS12-381 point compression.
|
|
364
|
+
* @dev 'sort' refers to 'is_greater' i.e. y > (p - 1)/2
|
|
365
|
+
*/ function setMask(bytes, mask) {
|
|
366
|
+
if (bytes[0] & 0b1110_0000) {
|
|
367
|
+
throw new Error('setMask: non-empty mask');
|
|
368
|
+
}
|
|
369
|
+
if (mask.compressed) {
|
|
370
|
+
bytes[0] |= 0b1000_0000;
|
|
371
|
+
}
|
|
372
|
+
if (mask.infinity) {
|
|
373
|
+
bytes[0] |= 0b0100_0000;
|
|
374
|
+
}
|
|
375
|
+
if (mask.sort) {
|
|
376
|
+
bytes[0] |= 0b0010_0000;
|
|
377
|
+
}
|
|
378
|
+
return bytes;
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* Lifted from noble curves bls12_381 since it's not exposed. Reads the flags
|
|
382
|
+
* for BLS12-381 point compression.
|
|
383
|
+
* @dev 'sort' refers to 'is_greater' i.e. y > (p - 1)/2
|
|
384
|
+
*/ function parseMask(bytes) {
|
|
385
|
+
// Copy, so we can remove mask data without affecting input bytes.
|
|
386
|
+
const value = Buffer.from(bytes);
|
|
387
|
+
const mask = value[0] & 0b1110_0000;
|
|
388
|
+
const compressed = !!(mask >> 7 & 1); // compression bit (0b1000_0000)
|
|
389
|
+
const infinity = !!(mask >> 6 & 1); // point at infinity bit (0b0100_0000)
|
|
390
|
+
const sort = !!(mask >> 5 & 1); // sort bit (0b0010_0000)
|
|
391
|
+
value[0] &= 0b0001_1111; // clear mask (zero first 3 bits)
|
|
392
|
+
return {
|
|
393
|
+
compressed,
|
|
394
|
+
infinity,
|
|
395
|
+
sort,
|
|
396
|
+
value
|
|
397
|
+
};
|
|
398
|
+
}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
3
1
|
import type { Tuple } from '../serialize/types.js';
|
|
4
2
|
import { Fr } from './fields.js';
|
|
5
3
|
/**
|
|
@@ -11,9 +9,6 @@ import { Fr } from './fields.js';
|
|
|
11
9
|
* Calls to 'toFieldsBuffer' will return a 64 bytes buffer containing the serialized fields.
|
|
12
10
|
*/
|
|
13
11
|
export declare class Coordinate {
|
|
14
|
-
/**
|
|
15
|
-
* The fields of the coordinate value. Least significant limb at index 0.
|
|
16
|
-
*/
|
|
17
12
|
fields: Tuple<Fr, 2>;
|
|
18
13
|
static ZERO: Coordinate;
|
|
19
14
|
constructor(
|
|
@@ -65,4 +60,4 @@ export declare class Coordinate {
|
|
|
65
60
|
*/
|
|
66
61
|
static fromField(coordinate: Fr): Coordinate;
|
|
67
62
|
}
|
|
68
|
-
//# sourceMappingURL=
|
|
63
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29vcmRpbmF0ZS5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL2ZpZWxkcy9jb29yZGluYXRlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUNBLE9BQU8sS0FBSyxFQUFFLEtBQUssRUFBRSxNQUFNLHVCQUF1QixDQUFDO0FBQ25ELE9BQU8sRUFBRSxFQUFFLEVBQUUsTUFBTSxhQUFhLENBQUM7QUFFakM7Ozs7Ozs7R0FPRztBQUNILHFCQUFhLFVBQVU7SUFPWixNQUFNLEVBQUUsS0FBSyxDQUFDLEVBQUUsRUFBRSxDQUFDLENBQUM7SUFON0IsTUFBTSxDQUFDLElBQUksYUFBc0M7SUFFakQ7SUFDRTs7T0FFRztJQUNJLE1BQU0sRUFBRSxLQUFLLENBQUMsRUFBRSxFQUFFLENBQUMsQ0FBQyxFQUN6QjtJQUVKOzs7T0FHRztJQUNILFFBQVEsSUFBSSxLQUFLLENBQUMsRUFBRSxFQUFFLENBQUMsQ0FBQyxDQUV2QjtJQUVEOzs7T0FHRztJQUNILE1BQU0sQ0FBQyxNQUFNLElBQUksVUFBVSxDQUUxQjtJQUVEOzs7T0FHRztJQUNILGNBQWMsSUFBSSxNQUFNLENBRXZCO0lBRUQ7OztPQUdHO0lBQ0gsUUFBUSxJQUFJLE1BQU0sQ0FLakI7SUFFRDs7OztPQUlHO0lBQ0gsTUFBTSxDQUFDLEtBQUssRUFBRSxVQUFVLEdBQUcsT0FBTyxDQUVqQztJQUVEOzs7T0FHRztJQUNILFFBQVEsSUFBSSxNQUFNLENBRWpCO0lBRUQ7Ozs7T0FJRztJQUNILE1BQU0sQ0FBQyxVQUFVLENBQUMsVUFBVSxFQUFFLE1BQU0sY0FVbkM7SUFFRDs7OztPQUlHO0lBQ0gsTUFBTSxDQUFDLFNBQVMsQ0FBQyxVQUFVLEVBQUUsRUFBRSxjQU05QjtDQUNGIn0=
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"coordinate.d.ts","sourceRoot":"","sources":["../../src/fields/coordinate.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"coordinate.d.ts","sourceRoot":"","sources":["../../src/fields/coordinate.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AAEjC;;;;;;;GAOG;AACH,qBAAa,UAAU;IAOZ,MAAM,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC;IAN7B,MAAM,CAAC,IAAI,aAAsC;IAEjD;IACE;;OAEG;IACI,MAAM,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC,EACzB;IAEJ;;;OAGG;IACH,QAAQ,IAAI,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC,CAEvB;IAED;;;OAGG;IACH,MAAM,CAAC,MAAM,IAAI,UAAU,CAE1B;IAED;;;OAGG;IACH,cAAc,IAAI,MAAM,CAEvB;IAED;;;OAGG;IACH,QAAQ,IAAI,MAAM,CAKjB;IAED;;;;OAIG;IACH,MAAM,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAEjC;IAED;;;OAGG;IACH,QAAQ,IAAI,MAAM,CAEjB;IAED;;;;OAIG;IACH,MAAM,CAAC,UAAU,CAAC,UAAU,EAAE,MAAM,cAUnC;IAED;;;;OAIG;IACH,MAAM,CAAC,SAAS,CAAC,UAAU,EAAE,EAAE,cAM9B;CACF"}
|