@aztec/foundation 0.0.0-test.1 → 0.0.1-commit.b655e406
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 +5 -0
- package/dest/array/array.d.ts.map +1 -1
- package/dest/array/array.js +11 -0
- 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 +0 -2
- package/dest/bigint-buffer/index.d.ts.map +1 -1
- package/dest/buffer/buffer16.d.ts +80 -0
- package/dest/buffer/buffer16.d.ts.map +1 -0
- package/dest/buffer/buffer16.js +100 -0
- package/dest/buffer/buffer32.d.ts +3 -7
- package/dest/buffer/buffer32.d.ts.map +1 -1
- package/dest/buffer/buffer32.js +6 -6
- package/dest/buffer/index.d.ts +1 -0
- package/dest/buffer/index.d.ts.map +1 -1
- package/dest/buffer/index.js +1 -0
- package/dest/collection/array.d.ts +16 -3
- package/dest/collection/array.d.ts.map +1 -1
- package/dest/collection/array.js +57 -3
- package/dest/collection/object.d.ts +16 -0
- package/dest/collection/object.d.ts.map +1 -1
- package/dest/collection/object.js +25 -0
- package/dest/config/env_var.d.ts +1 -1
- package/dest/config/env_var.d.ts.map +1 -1
- package/dest/config/index.d.ts +48 -1
- 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 +2 -4
- package/dest/crypto/aes128/index.d.ts.map +1 -1
- package/dest/crypto/aes128/index.js +23 -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 +142 -0
- package/dest/crypto/ecdsa/index.d.ts +2 -2
- package/dest/crypto/ecdsa/index.d.ts.map +1 -1
- package/dest/crypto/ecdsa/index.js +70 -48
- package/dest/crypto/ecdsa/signature.d.ts +1 -3
- package/dest/crypto/ecdsa/signature.d.ts.map +1 -1
- package/dest/crypto/grumpkin/index.d.ts +6 -13
- package/dest/crypto/grumpkin/index.d.ts.map +1 -1
- package/dest/crypto/grumpkin/index.js +69 -54
- package/dest/crypto/index.d.ts +2 -0
- package/dest/crypto/index.d.ts.map +1 -1
- package/dest/crypto/index.js +2 -0
- package/dest/crypto/keccak/index.d.ts +2 -4
- package/dest/crypto/keccak/index.d.ts.map +1 -1
- package/dest/crypto/keys/index.d.ts +0 -2
- package/dest/crypto/keys/index.d.ts.map +1 -1
- package/dest/crypto/keys/index.js +9 -4
- package/dest/crypto/pedersen/pedersen.noble.d.ts +2 -4
- package/dest/crypto/pedersen/pedersen.noble.d.ts.map +1 -1
- package/dest/crypto/pedersen/pedersen.wasm.d.ts +2 -4
- package/dest/crypto/pedersen/pedersen.wasm.d.ts.map +1 -1
- package/dest/crypto/pedersen/pedersen.wasm.js +29 -13
- package/dest/crypto/poseidon/index.d.ts +0 -2
- package/dest/crypto/poseidon/index.d.ts.map +1 -1
- package/dest/crypto/poseidon/index.js +42 -17
- package/dest/crypto/random/index.d.ts +1 -3
- 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 +0 -2
- package/dest/crypto/random/randomness_singleton.d.ts.map +1 -1
- package/dest/crypto/schnorr/index.d.ts.map +1 -1
- package/dest/crypto/schnorr/index.js +35 -37
- package/dest/crypto/schnorr/signature.d.ts +3 -5
- package/dest/crypto/schnorr/signature.d.ts.map +1 -1
- package/dest/crypto/secp256k1/index.d.ts +4 -6
- package/dest/crypto/secp256k1/index.d.ts.map +1 -1
- package/dest/crypto/secp256k1/index.js +29 -18
- package/dest/crypto/secp256k1-signer/utils.d.ts +55 -4
- 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 +4 -6
- package/dest/crypto/serialize.d.ts.map +1 -1
- package/dest/crypto/sha256/index.d.ts +21 -4
- 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 +1 -3
- package/dest/crypto/sha512/index.d.ts.map +1 -1
- package/dest/crypto/signature/index.d.ts +0 -2
- package/dest/crypto/signature/index.d.ts.map +1 -1
- package/dest/crypto/sync/index.js +3 -1
- package/dest/crypto/sync/pedersen/index.d.ts +2 -4
- 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 +0 -2
- package/dest/crypto/sync/poseidon/index.d.ts.map +1 -1
- package/dest/crypto/sync/poseidon/index.js +27 -12
- package/dest/decorators/memoize.d.ts.map +1 -1
- package/dest/eth-address/index.d.ts +6 -7
- package/dest/eth-address/index.d.ts.map +1 -1
- package/dest/eth-address/index.js +5 -0
- package/dest/eth-signature/eth_signature.d.ts +16 -14
- package/dest/eth-signature/eth_signature.d.ts.map +1 -1
- package/dest/eth-signature/eth_signature.js +31 -17
- 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 +229 -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 +0 -2
- package/dest/fields/coordinate.d.ts.map +1 -1
- package/dest/fields/fields.d.ts +6 -3
- package/dest/fields/fields.d.ts.map +1 -1
- package/dest/fields/fields.js +43 -15
- package/dest/fields/index.d.ts +2 -0
- package/dest/fields/index.d.ts.map +1 -1
- package/dest/fields/index.js +2 -0
- package/dest/fields/point.d.ts +2 -4
- package/dest/fields/point.d.ts.map +1 -1
- package/dest/fields/point.js +3 -3
- package/dest/fs/index.d.ts +1 -0
- package/dest/fs/index.d.ts.map +1 -1
- package/dest/fs/index.js +1 -0
- package/dest/fs/try_rm_dir.d.ts +3 -0
- package/dest/fs/try_rm_dir.d.ts.map +1 -0
- package/dest/fs/try_rm_dir.js +16 -0
- package/dest/index.d.ts +1 -2
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -2
- package/dest/iterable/filter.js +1 -1
- package/dest/iterable/map.js +1 -1
- package/dest/jest/env.js +48 -0
- package/dest/jest/setupAfterEnv.js +3 -0
- package/dest/json-rpc/client/fetch.d.ts +2 -2
- 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/safe_json_rpc_client.d.ts +9 -3
- 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.map +1 -1
- package/dest/json-rpc/client/undici.js +6 -7
- package/dest/json-rpc/convert.d.ts +2 -9
- 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 +5 -3
- package/dest/json-rpc/fixtures/class_a.d.ts.map +1 -1
- package/dest/json-rpc/fixtures/class_b.d.ts +5 -3
- package/dest/json-rpc/fixtures/class_b.d.ts.map +1 -1
- package/dest/json-rpc/index.d.ts +2 -1
- 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.map +1 -1
- package/dest/json-rpc/server/safe_json_rpc_server.d.ts +21 -22
- 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/test/integration.d.ts +1 -2
- package/dest/json-rpc/test/integration.d.ts.map +1 -1
- package/dest/log/console.d.ts.map +1 -1
- package/dest/log/gcloud-logger-config.d.ts +0 -1
- 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 +4 -4
- package/dest/log/index.d.ts.map +1 -1
- package/dest/log/index.js +4 -4
- package/dest/log/libp2p_logger.js +13 -2
- package/dest/log/log_fn.d.ts +1 -1
- 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 +2 -2
- package/dest/log/pino-logger.d.ts.map +1 -1
- package/dest/log/pino-logger.js +28 -2
- package/dest/message/index.d.ts.map +1 -1
- package/dest/mutex/mutex_database.d.ts.map +1 -1
- package/dest/noir/noir_package_config.d.ts +4 -4
- 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/running-promise.d.ts +1 -1
- package/dest/promise/running-promise.d.ts.map +1 -1
- package/dest/promise/running-promise.js +2 -2
- package/dest/queue/batch_queue.d.ts +1 -1
- package/dest/queue/batch_queue.js +1 -1
- package/dest/queue/bounded_serial_queue.d.ts.map +1 -1
- package/dest/queue/serial_queue.d.ts +2 -2
- package/dest/queue/serial_queue.d.ts.map +1 -1
- package/dest/queue/serial_queue.js +7 -5
- package/dest/retry/index.d.ts +3 -2
- package/dest/retry/index.d.ts.map +1 -1
- package/dest/retry/index.js +2 -2
- package/dest/schemas/api.d.ts.map +1 -1
- package/dest/schemas/parse.js +1 -1
- package/dest/schemas/schemas.d.ts +9 -6
- package/dest/schemas/schemas.d.ts.map +1 -1
- package/dest/schemas/schemas.js +15 -1
- package/dest/schemas/utils.d.ts +1 -3
- package/dest/schemas/utils.d.ts.map +1 -1
- package/dest/serialize/buffer_reader.d.ts +27 -2
- 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 +10 -1
- 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 +23 -21
- package/dest/serialize/free_funcs.d.ts.map +1 -1
- package/dest/serialize/free_funcs.js +21 -27
- package/dest/serialize/serialize.d.ts +4 -5
- package/dest/serialize/serialize.d.ts.map +1 -1
- package/dest/string/index.d.ts +7 -2
- package/dest/string/index.d.ts.map +1 -1
- package/dest/string/index.js +27 -1
- package/dest/testing/files/index.d.ts +0 -2
- package/dest/testing/files/index.d.ts.map +1 -1
- package/dest/testing/files/index.js +2 -2
- 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 +1 -0
- package/dest/testing/index.d.ts.map +1 -1
- package/dest/testing/index.js +1 -0
- package/dest/timer/date.d.ts +2 -1
- package/dest/timer/date.d.ts.map +1 -1
- package/dest/timer/date.js +5 -3
- package/dest/timer/index.d.ts +1 -1
- package/dest/timer/index.d.ts.map +1 -1
- package/dest/timer/index.js +1 -1
- package/dest/timer/timeout.d.ts +18 -5
- package/dest/timer/timeout.d.ts.map +1 -1
- package/dest/timer/timeout.js +43 -22
- package/dest/transport/dispatch/create_dispatch_fn.d.ts.map +1 -1
- package/dest/transport/index.d.ts +0 -1
- package/dest/transport/index.d.ts.map +1 -1
- package/dest/transport/index.js +0 -1
- package/dest/transport/interface/connector.d.ts.map +1 -1
- package/dest/transport/interface/listener.d.ts +0 -1
- package/dest/transport/interface/listener.d.ts.map +1 -1
- package/dest/transport/interface/socket.d.ts.map +1 -1
- package/dest/transport/node/node_connector.d.ts +0 -1
- package/dest/transport/node/node_connector.d.ts.map +1 -1
- package/dest/transport/node/node_connector_socket.d.ts +0 -1
- package/dest/transport/node/node_connector_socket.d.ts.map +1 -1
- package/dest/transport/node/node_listener.d.ts +0 -1
- package/dest/transport/node/node_listener.d.ts.map +1 -1
- package/dest/transport/node/node_listener_socket.d.ts +0 -1
- package/dest/transport/node/node_listener_socket.d.ts.map +1 -1
- package/dest/transport/transport_client.d.ts +0 -1
- package/dest/transport/transport_client.d.ts.map +1 -1
- package/dest/transport/transport_server.d.ts.map +1 -1
- package/dest/trees/hasher.d.ts +4 -6
- package/dest/trees/hasher.d.ts.map +1 -1
- package/dest/trees/index.d.ts +1 -0
- package/dest/trees/index.d.ts.map +1 -1
- package/dest/trees/index.js +1 -0
- package/dest/trees/indexed_merkle_tree.d.ts +0 -2
- package/dest/trees/indexed_merkle_tree.d.ts.map +1 -1
- package/dest/trees/indexed_merkle_tree_calculator.d.ts +1 -3
- package/dest/trees/indexed_merkle_tree_calculator.d.ts.map +1 -1
- package/dest/trees/indexed_tree_leaf.d.ts +0 -2
- package/dest/trees/indexed_tree_leaf.d.ts.map +1 -1
- package/dest/trees/membership_witness.d.ts +19 -3
- 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 +0 -2
- package/dest/trees/merkle_tree.d.ts.map +1 -1
- package/dest/trees/merkle_tree_calculator.d.ts +11 -3
- package/dest/trees/merkle_tree_calculator.d.ts.map +1 -1
- package/dest/trees/merkle_tree_calculator.js +31 -1
- package/dest/trees/sibling_path.d.ts +6 -8
- package/dest/trees/sibling_path.d.ts.map +1 -1
- package/dest/trees/unbalanced_merkle_tree.d.ts +19 -8
- package/dest/trees/unbalanced_merkle_tree.d.ts.map +1 -1
- package/dest/trees/unbalanced_merkle_tree.js +49 -50
- package/dest/trees/unbalanced_merkle_tree_calculator.d.ts +48 -0
- package/dest/trees/unbalanced_merkle_tree_calculator.d.ts.map +1 -0
- package/dest/trees/unbalanced_merkle_tree_calculator.js +162 -0
- package/dest/trees/unbalanced_tree_store.d.ts +1 -0
- 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 +25 -2
- package/dest/types/index.d.ts.map +1 -1
- package/dest/url/index.d.ts.map +1 -1
- package/dest/url/index.js +1 -1
- package/package.json +35 -41
- package/src/array/array.ts +13 -0
- package/src/async-pool/index.ts +1 -0
- package/src/bigint/index.ts +20 -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 +142 -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 +170 -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 +9 -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 +37 -9
- package/src/fields/index.ts +2 -0
- package/src/fields/point.ts +1 -3
- package/src/fs/index.ts +1 -0
- package/src/fs/try_rm_dir.ts +15 -0
- package/src/index.ts +1 -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 +19 -1
- 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 +6 -2
- 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/hasher.ts +4 -4
- package/src/trees/index.ts +1 -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 +43 -5
- package/src/trees/unbalanced_merkle_tree.ts +50 -42
- package/src/trees/unbalanced_merkle_tree_calculator.ts +194 -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,450 @@
|
|
|
1
|
+
import type { ProjPointType } from '@noble/curves/abstract/weierstrass';
|
|
2
|
+
/* eslint-disable camelcase */
|
|
3
|
+
import { bls12_381 } from '@noble/curves/bls12-381';
|
|
4
|
+
import { inspect } from 'util';
|
|
5
|
+
|
|
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 { BLS12Fq, BLS12Fr } from './bls12_fields.js';
|
|
12
|
+
import { Fr } from './fields.js';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Represents a Point on an elliptic curve with x and y coordinates.
|
|
16
|
+
* The Point class provides methods for creating instances from different input types,
|
|
17
|
+
* converting instances to various output formats, and checking the equality of points.
|
|
18
|
+
* TODO(#7386): Clean up this class.
|
|
19
|
+
*/
|
|
20
|
+
export class BLS12Point {
|
|
21
|
+
static ZERO = new BLS12Point(BLS12Fq.ZERO, BLS12Fq.ZERO, true);
|
|
22
|
+
static ONE = new BLS12Point(new BLS12Fq(bls12_381.G1.CURVE.Gx), new BLS12Fq(bls12_381.G1.CURVE.Gy), false);
|
|
23
|
+
static SIZE_IN_BYTES = BLS12Fq.SIZE_IN_BYTES * 2;
|
|
24
|
+
static COMPRESSED_SIZE_IN_BYTES = BLS12Fq.SIZE_IN_BYTES;
|
|
25
|
+
static COMPRESSED_ZERO = setMask(Buffer.alloc(BLS12Fq.SIZE_IN_BYTES), { infinity: true, compressed: true });
|
|
26
|
+
|
|
27
|
+
constructor(
|
|
28
|
+
/**
|
|
29
|
+
* The point's x coordinate
|
|
30
|
+
*/
|
|
31
|
+
public readonly x: BLS12Fq,
|
|
32
|
+
/**
|
|
33
|
+
* The point's y coordinate
|
|
34
|
+
*/
|
|
35
|
+
public readonly y: BLS12Fq,
|
|
36
|
+
/**
|
|
37
|
+
* Whether the point is at infinity
|
|
38
|
+
*/
|
|
39
|
+
public readonly isInfinite: boolean,
|
|
40
|
+
) {
|
|
41
|
+
if (!BLS12Point.isOnCurve(x, y)) {
|
|
42
|
+
throw new BLSPointNotOnCurveError(x, y);
|
|
43
|
+
}
|
|
44
|
+
if (isInfinite && !(x.equals(BLS12Fq.ZERO) && y.equals(BLS12Fq.ZERO))) {
|
|
45
|
+
throw new Error(`BLS12-381 G1 point ( ${x.toString()}, ${y.toString()} ) is not infinite.`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
toJSON() {
|
|
50
|
+
return this.toString();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
[inspect.custom]() {
|
|
54
|
+
return `BLS12Point {
|
|
55
|
+
x: ${inspect(this.x)},
|
|
56
|
+
y: ${inspect(this.y)},
|
|
57
|
+
isInfinite: ${inspect(this.isInfinite)},
|
|
58
|
+
}`;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
static get schema() {
|
|
62
|
+
return hexSchemaFor(BLS12Point);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Generate a random Point instance.
|
|
67
|
+
*
|
|
68
|
+
* @returns A randomly generated Point instance.
|
|
69
|
+
*/
|
|
70
|
+
static random() {
|
|
71
|
+
while (true) {
|
|
72
|
+
try {
|
|
73
|
+
return BLS12Point.fromXAndSign(BLS12Fq.random(), randomBoolean());
|
|
74
|
+
} catch (e: any) {
|
|
75
|
+
if (!(e instanceof BLSPointNotOnCurveError)) {
|
|
76
|
+
throw e;
|
|
77
|
+
}
|
|
78
|
+
// The random point is not on the curve - we try again
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Create a Point instance from a given buffer or BufferReader.
|
|
86
|
+
* The input 'buffer' should have exactly 96 bytes representing the x and y coordinates.
|
|
87
|
+
*
|
|
88
|
+
* @param buffer - The buffer or BufferReader containing the x and y coordinates of the point.
|
|
89
|
+
* @returns A Point instance.
|
|
90
|
+
*/
|
|
91
|
+
static fromBuffer(buffer: Buffer | BufferReader) {
|
|
92
|
+
const reader = BufferReader.asReader(buffer);
|
|
93
|
+
const [x, y] = [BLS12Fq.fromBuffer(reader), BLS12Fq.fromBuffer(reader)];
|
|
94
|
+
return new this(x, y, x.isZero() && y.isZero());
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Create a Point instance from a hex-encoded string.
|
|
99
|
+
* The input should be prefixed with '0x' or not, and have exactly 128 hex characters representing the x and y coordinates.
|
|
100
|
+
* Throws an error if the input length is invalid or coordinate values are out of range.
|
|
101
|
+
*
|
|
102
|
+
* @param str - The hex-encoded string representing the Point coordinates.
|
|
103
|
+
* @returns A Point instance.
|
|
104
|
+
*/
|
|
105
|
+
static fromString(str: string) {
|
|
106
|
+
return this.fromBuffer(hexToBuffer(str));
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Create a compressed buffer instance from a point.
|
|
111
|
+
* @dev NOTE: The compression standard for BLS12-381 differs from BN curves. Instead of
|
|
112
|
+
* one is_positive flag, we have three flags to prepend:
|
|
113
|
+
* - is_compressed: indicator that the point is compressed
|
|
114
|
+
* - is_infinity: whether the point the point at infinity
|
|
115
|
+
* - is_greater: only set if is_compressed && !is_infinity && y > (p - 1)/2
|
|
116
|
+
* See https://github.com/arkworks-rs/algebra/blob/master/curves/bls12_381/src/curves/g1.rs -> serialize_with_mode() -> encoding
|
|
117
|
+
* and noble-curves/src/bls12-381.ts -> setMask()
|
|
118
|
+
* @dev Most of the logic below is taken from noble-curves/src/bls12-381.ts -> toBytes()
|
|
119
|
+
* @param point A BLS12Point instance.
|
|
120
|
+
* @returns The buffer containing the x coordinate and the flags of the y coordinate.
|
|
121
|
+
*/
|
|
122
|
+
compress(): Buffer {
|
|
123
|
+
if (this.isZero()) {
|
|
124
|
+
return BLS12Point.COMPRESSED_ZERO;
|
|
125
|
+
}
|
|
126
|
+
const isGreater = this.y.isNegative();
|
|
127
|
+
return setMask(toBufferBE(this.x.toBigInt(), BLS12Fq.SIZE_IN_BYTES), { compressed: true, sort: isGreater });
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Create a Point instance from a compressed buffer.
|
|
132
|
+
* @dev See compress() above for compression encoding for BLS12-381.
|
|
133
|
+
* @dev Most of the logic below is taken from noble-curves/src/bls12-381.ts -> fromBytes()
|
|
134
|
+
* @param buffer - The buffer containing the x coordinate and the flags of the y coordinate.
|
|
135
|
+
* @returns A BLS12Point instance.
|
|
136
|
+
*/
|
|
137
|
+
static decompress(buffer: Buffer): BLS12Point {
|
|
138
|
+
const { compressed, infinity, sort, value: decompressed } = parseMask(buffer);
|
|
139
|
+
if (decompressed.length === BLS12Fq.SIZE_IN_BYTES && compressed) {
|
|
140
|
+
const x = new BLS12Fq(decompressed);
|
|
141
|
+
if (infinity) {
|
|
142
|
+
if (!x.isZero()) {
|
|
143
|
+
throw new Error('Non-empty compressed G1 point at infinity');
|
|
144
|
+
}
|
|
145
|
+
return new BLS12Point(x, BLS12Fq.ZERO, true);
|
|
146
|
+
}
|
|
147
|
+
let y = this.YFromX(x);
|
|
148
|
+
if (!y) {
|
|
149
|
+
throw new BLSPointNotOnCurveError(x);
|
|
150
|
+
}
|
|
151
|
+
if (y.isNegative() !== sort) {
|
|
152
|
+
y = y.negate();
|
|
153
|
+
}
|
|
154
|
+
return new BLS12Point(x, y, infinity);
|
|
155
|
+
} else {
|
|
156
|
+
throw new Error('Invalid compressed G1 point of BLS12-381');
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Converts a Point to two BN254 Fr elements by storing its compressed form (48 bytes) as:
|
|
162
|
+
* +-------------------+------------------------+
|
|
163
|
+
* | 31 bytes | 17 bytes |
|
|
164
|
+
* +-------------------+------------------------+
|
|
165
|
+
* | Field Element 1 | Field Element 2 |
|
|
166
|
+
* | [0][bytes 0-30] | [0...0][bytes 31-47] |
|
|
167
|
+
* +-------------------+------------------------+
|
|
168
|
+
* Used in the rollup circuits to store blob commitments in the native field type. See blob.ts.
|
|
169
|
+
* @param point - A BLS12Point instance.
|
|
170
|
+
* @returns The point fields.
|
|
171
|
+
*/
|
|
172
|
+
toBN254Fields() {
|
|
173
|
+
const compressed = this.compress();
|
|
174
|
+
return [new Fr(compressed.subarray(0, 31)), new Fr(compressed.subarray(31, 48))];
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Creates a Point instance from 2 BN254 Fr fields as encoded in toBNFields() above.
|
|
179
|
+
* Used in the rollup circuits to store blob commitments in the native field type. See blob.ts.
|
|
180
|
+
* @param fields - The encoded BN254 fields.
|
|
181
|
+
* @returns The point fields.
|
|
182
|
+
*/
|
|
183
|
+
static fromBN254Fields(fields: [Fr, Fr]) {
|
|
184
|
+
return BLS12Point.decompress(Buffer.concat([fields[0].toBuffer().subarray(1), fields[1].toBuffer().subarray(-17)]));
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Creates a point from an array of 2 fields.
|
|
189
|
+
* @returns The point
|
|
190
|
+
*/
|
|
191
|
+
static fromBLS12FqFields(fields: BLS12Fq[]) {
|
|
192
|
+
return new this(fields[0], fields[1], !fields[2].isEmpty());
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Creates a point from @noble/curves projective point definition.
|
|
197
|
+
* @returns The point
|
|
198
|
+
*/
|
|
199
|
+
static fromNobleProjectivePoint(point: ProjPointType<bigint>) {
|
|
200
|
+
const affine = point.toAffine();
|
|
201
|
+
return new BLS12Point(
|
|
202
|
+
new BLS12Fq(affine.x),
|
|
203
|
+
new BLS12Fq(affine.y),
|
|
204
|
+
point.equals(bls12_381.G1.ProjectivePoint.ZERO),
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Uses the x coordinate and isPositive flag (+/-) to reconstruct the point.
|
|
210
|
+
* @param x - The x coordinate of the point
|
|
211
|
+
* @param sign - The "sign" of the y coordinate - note that this is not a sign as is known in integer arithmetic.
|
|
212
|
+
* Instead it is a boolean flag that determines whether the y coordinate is <= (Fr.MODULUS - 1) / 2
|
|
213
|
+
* @returns The point as an array of 2 fields
|
|
214
|
+
*/
|
|
215
|
+
static fromXAndSign(x: BLS12Fq, sign: boolean) {
|
|
216
|
+
const y = BLS12Point.YFromX(x);
|
|
217
|
+
if (y == null) {
|
|
218
|
+
throw new BLSPointNotOnCurveError(x);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
const yPositiveBigInt = y.isNegative() ? BLS12Fq.MODULUS - y.toBigInt() : y.toBigInt();
|
|
222
|
+
const yNegativeBigInt = BLS12Fq.MODULUS - yPositiveBigInt;
|
|
223
|
+
|
|
224
|
+
// Choose the positive or negative root based on isPositive
|
|
225
|
+
const finalY = sign ? new BLS12Fq(yPositiveBigInt) : new BLS12Fq(yNegativeBigInt);
|
|
226
|
+
|
|
227
|
+
// Create and return the new Point
|
|
228
|
+
return new this(x, finalY, false);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* @param x - The x coordinate of the point
|
|
233
|
+
* @returns y^2 such that y^2 = x^3 + 4
|
|
234
|
+
*/
|
|
235
|
+
static YSquaredFromX(x: BLS12Fq): BLS12Fq {
|
|
236
|
+
return new BLS12Fq(bls12_381.G1.weierstrassEquation(x.toBigInt()));
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* @param x - The x coordinate of the point
|
|
241
|
+
* @returns The y coordinate of the point, if it exists on BLS12-381
|
|
242
|
+
*/
|
|
243
|
+
static YFromX(x: BLS12Fq): BLS12Fq | null {
|
|
244
|
+
const ySquared = this.YSquaredFromX(x);
|
|
245
|
+
// y is then simply the square root. Note however that not all square roots exist in the field: if sqrt returns null
|
|
246
|
+
// then there is no point in the curve with this x coordinate.
|
|
247
|
+
return ySquared.sqrt();
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* @param x - The x coordinate of the point
|
|
252
|
+
* @param y - The y coordinate of the point
|
|
253
|
+
* @returns Whether the point exists on BLS12-381
|
|
254
|
+
*/
|
|
255
|
+
static isOnCurve(x: BLS12Fq, y: BLS12Fq) {
|
|
256
|
+
if (x.isZero() && y.isZero()) {
|
|
257
|
+
// Representation of inf point
|
|
258
|
+
return true;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// The BLS12-381 equation is y^2 = x^3 + 4. We could use `YFromX` and then compare to `this.y`, but this would
|
|
262
|
+
// involve computing the square root of y, of which there are two possible valid values. This method is also faster.
|
|
263
|
+
const lhs = y.square();
|
|
264
|
+
const rhs = this.YSquaredFromX(x);
|
|
265
|
+
return lhs.equals(rhs);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Returns the contents of the point as an array of 2 fields.
|
|
270
|
+
* @returns The point as an array of 2 fields
|
|
271
|
+
*/
|
|
272
|
+
toBLS12FqFields() {
|
|
273
|
+
return [this.x, this.y, new BLS12Fq(this.isInfinite ? 1 : 0)];
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Returns the x coordinate and the sign of the y coordinate.
|
|
278
|
+
* @dev The y sign can be determined by checking if the y coordinate is greater than half of the modulus.
|
|
279
|
+
* @returns The x coordinate and the sign of the y coordinate.
|
|
280
|
+
*/
|
|
281
|
+
toXAndSign(): [BLS12Fq, boolean] {
|
|
282
|
+
return [this.x, !this.y.isNegative()];
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* Returns the contents of the point as BigInts.
|
|
287
|
+
* @returns The point as BigInts
|
|
288
|
+
*/
|
|
289
|
+
toBigInts() {
|
|
290
|
+
return {
|
|
291
|
+
x: this.x.toBigInt(),
|
|
292
|
+
y: this.y.toBigInt(),
|
|
293
|
+
isInfinite: this.isInfinite ? 1n : 0n,
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* Converts the Point instance to a Buffer representation of the coordinates.
|
|
299
|
+
* @returns A Buffer representation of the Point instance.
|
|
300
|
+
* @dev Note that toBuffer does not include the isInfinite flag and other serialization methods do (e.g. toBigInts).
|
|
301
|
+
*/
|
|
302
|
+
toBuffer() {
|
|
303
|
+
const buf = serializeToBuffer([this.x, this.y]);
|
|
304
|
+
if (buf.length !== BLS12Point.SIZE_IN_BYTES) {
|
|
305
|
+
throw new Error(`Invalid buffer length for Point: ${buf.length}`);
|
|
306
|
+
}
|
|
307
|
+
return buf;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* Convert the Point instance to a hexadecimal string representation.
|
|
312
|
+
* The output string is prefixed with '0x' and consists of exactly 128 hex characters,
|
|
313
|
+
* representing the concatenated x and y coordinates of the point.
|
|
314
|
+
*
|
|
315
|
+
* @returns A hex-encoded string representing the Point instance.
|
|
316
|
+
*/
|
|
317
|
+
toString() {
|
|
318
|
+
return bufferToHex(this.toBuffer());
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* Check if two Point instances are equal by comparing their buffer values.
|
|
323
|
+
* Returns true if the buffer values are the same, and false otherwise.
|
|
324
|
+
*
|
|
325
|
+
* @param rhs - The Point instance to compare with the current instance.
|
|
326
|
+
* @returns A boolean indicating whether the two Point instances are equal.
|
|
327
|
+
*/
|
|
328
|
+
equals(rhs: BLS12Point) {
|
|
329
|
+
return this.x.equals(rhs.x) && this.y.equals(rhs.y);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* Check whether the point is zero.
|
|
334
|
+
*/
|
|
335
|
+
isZero() {
|
|
336
|
+
return this.x.isZero() && this.y.isZero();
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* Check if this is point at infinity.
|
|
341
|
+
* Check this is consistent with how bb is encoding the point at infinity
|
|
342
|
+
*/
|
|
343
|
+
public get inf() {
|
|
344
|
+
return this.isInfinite;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
/** Arithmetic - wrapper around noble curves */
|
|
348
|
+
|
|
349
|
+
toNobleProjectivePoint() {
|
|
350
|
+
return bls12_381.G1.ProjectivePoint.fromAffine(this.toBigInts());
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
add(rhs: BLS12Point) {
|
|
354
|
+
return BLS12Point.fromNobleProjectivePoint(this.toNobleProjectivePoint().add(rhs.toNobleProjectivePoint()));
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
negate() {
|
|
358
|
+
return new BLS12Point(this.x, this.y.negate(), this.isInfinite);
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
sub(rhs: BLS12Point) {
|
|
362
|
+
return BLS12Point.fromNobleProjectivePoint(this.toNobleProjectivePoint().subtract(rhs.toNobleProjectivePoint()));
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* @dev From noble curves package:
|
|
367
|
+
* Constant time multiplication. Uses wNAF method. Windowed method may be 10% faster,
|
|
368
|
+
* but takes 2x longer to generate and consumes 2x memory.
|
|
369
|
+
* Uses precomputes when available, uses endomorphism for Koblitz curves.
|
|
370
|
+
* @param scalar by which the point would be multiplied
|
|
371
|
+
* @returns New point
|
|
372
|
+
*/
|
|
373
|
+
mul(rhs: BLS12Fr) {
|
|
374
|
+
// Note: noble curves throws on 0
|
|
375
|
+
if (rhs.isZero()) {
|
|
376
|
+
return BLS12Point.ZERO;
|
|
377
|
+
}
|
|
378
|
+
return BLS12Point.fromNobleProjectivePoint(this.toNobleProjectivePoint().multiply(rhs.toBigInt()));
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
/**
|
|
382
|
+
* @dev From noble curves package:
|
|
383
|
+
* Non-constant-time multiplication. Uses double-and-add algorithm.
|
|
384
|
+
* 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.
|
|
385
|
+
* @param scalar by which the point would be multiplied
|
|
386
|
+
* @returns New point
|
|
387
|
+
*/
|
|
388
|
+
mulUnsafe(rhs: BLS12Fr) {
|
|
389
|
+
return BLS12Point.fromNobleProjectivePoint(this.toNobleProjectivePoint().multiplyUnsafe(rhs.toBigInt()));
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
/**
|
|
393
|
+
* @dev From noble curves package:
|
|
394
|
+
* Efficiently calculate `aP + bQ`. Unsafe, can expose private key, if used incorrectly.
|
|
395
|
+
* 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).
|
|
396
|
+
* @returns affine point
|
|
397
|
+
*/
|
|
398
|
+
mulAndAddUnsafe(a: BLS12Fr, b: BLS12Fr, Q: BLS12Point) {
|
|
399
|
+
const res = this.toNobleProjectivePoint().multiplyAndAddUnsafe(
|
|
400
|
+
Q.toNobleProjectivePoint(),
|
|
401
|
+
a.toBigInt(),
|
|
402
|
+
b.toBigInt(),
|
|
403
|
+
);
|
|
404
|
+
return res ? BLS12Point.fromNobleProjectivePoint(res) : BLS12Point.ZERO;
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
export class BLSPointNotOnCurveError extends Error {
|
|
409
|
+
constructor(x: BLS12Fq, y?: BLS12Fq) {
|
|
410
|
+
super('The given G1 point is not on the BLS12-381 curve: (' + x.toString() + ', ' + (y ? y.toString() : '') + ')');
|
|
411
|
+
this.name = 'NotOnCurveError';
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
/**
|
|
416
|
+
* Lifted from noble curves bls12_381 since it's not exposed. Sets the flags
|
|
417
|
+
* for BLS12-381 point compression.
|
|
418
|
+
* @dev 'sort' refers to 'is_greater' i.e. y > (p - 1)/2
|
|
419
|
+
*/
|
|
420
|
+
function setMask(bytes: Buffer, mask: { compressed?: boolean; infinity?: boolean; sort?: boolean }) {
|
|
421
|
+
if (bytes[0] & 0b1110_0000) {
|
|
422
|
+
throw new Error('setMask: non-empty mask');
|
|
423
|
+
}
|
|
424
|
+
if (mask.compressed) {
|
|
425
|
+
bytes[0] |= 0b1000_0000;
|
|
426
|
+
}
|
|
427
|
+
if (mask.infinity) {
|
|
428
|
+
bytes[0] |= 0b0100_0000;
|
|
429
|
+
}
|
|
430
|
+
if (mask.sort) {
|
|
431
|
+
bytes[0] |= 0b0010_0000;
|
|
432
|
+
}
|
|
433
|
+
return bytes;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
/**
|
|
437
|
+
* Lifted from noble curves bls12_381 since it's not exposed. Reads the flags
|
|
438
|
+
* for BLS12-381 point compression.
|
|
439
|
+
* @dev 'sort' refers to 'is_greater' i.e. y > (p - 1)/2
|
|
440
|
+
*/
|
|
441
|
+
function parseMask(bytes: Buffer) {
|
|
442
|
+
// Copy, so we can remove mask data without affecting input bytes.
|
|
443
|
+
const value = Buffer.from(bytes);
|
|
444
|
+
const mask = value[0] & 0b1110_0000;
|
|
445
|
+
const compressed = !!((mask >> 7) & 1); // compression bit (0b1000_0000)
|
|
446
|
+
const infinity = !!((mask >> 6) & 1); // point at infinity bit (0b0100_0000)
|
|
447
|
+
const sort = !!((mask >> 5) & 1); // sort bit (0b0010_0000)
|
|
448
|
+
value[0] &= 0b0001_1111; // clear mask (zero first 3 bits)
|
|
449
|
+
return { compressed, infinity, sort, value };
|
|
450
|
+
}
|
package/src/fields/fields.ts
CHANGED
|
@@ -60,6 +60,8 @@ abstract class BaseField {
|
|
|
60
60
|
this.asBigInt = BigInt(value);
|
|
61
61
|
if (this.asBigInt >= this.modulus()) {
|
|
62
62
|
throw new Error(`Value 0x${this.asBigInt.toString(16)} is greater or equal to field modulus.`);
|
|
63
|
+
} else if (this.asBigInt < 0n) {
|
|
64
|
+
throw new Error(`Value 0x${this.asBigInt.toString(16)} is negative.`);
|
|
63
65
|
}
|
|
64
66
|
} else if (value instanceof BaseField) {
|
|
65
67
|
this.asBuffer = value.asBuffer;
|
|
@@ -319,15 +321,14 @@ export class Fr extends BaseField {
|
|
|
319
321
|
* @returns A square root of the field element (null if it does not exist).
|
|
320
322
|
*/
|
|
321
323
|
async sqrt(): Promise<Fr | null> {
|
|
322
|
-
|
|
323
|
-
const
|
|
324
|
-
const
|
|
325
|
-
|
|
326
|
-
if (!isSqrt) {
|
|
324
|
+
await BarretenbergSync.initSingleton();
|
|
325
|
+
const api = BarretenbergSync.getSingleton();
|
|
326
|
+
const response = api.bn254FrSqrt({ input: this.toBuffer() });
|
|
327
|
+
if (!response.isSquareRoot) {
|
|
327
328
|
// Field element is not a quadratic residue mod p so it has no square root.
|
|
328
329
|
return null;
|
|
329
330
|
}
|
|
330
|
-
return
|
|
331
|
+
return Fr.fromBuffer(Buffer.from(response.value));
|
|
331
332
|
}
|
|
332
333
|
|
|
333
334
|
toJSON() {
|
|
@@ -433,10 +434,32 @@ export class Fq extends BaseField {
|
|
|
433
434
|
return new Fq((this.toBigInt() + rhs.toBigInt()) % Fq.MODULUS);
|
|
434
435
|
}
|
|
435
436
|
|
|
437
|
+
/**
|
|
438
|
+
* Computes a square root of the field element.
|
|
439
|
+
* @returns A square root of the field element (null if it does not exist).
|
|
440
|
+
*/
|
|
441
|
+
async sqrt(): Promise<Fq | null> {
|
|
442
|
+
await BarretenbergSync.initSingleton();
|
|
443
|
+
const api = BarretenbergSync.getSingleton();
|
|
444
|
+
const response = api.bn254FqSqrt({ input: this.toBuffer() });
|
|
445
|
+
if (!response.isSquareRoot) {
|
|
446
|
+
// Field element is not a quadratic residue mod p so it has no square root.
|
|
447
|
+
return null;
|
|
448
|
+
}
|
|
449
|
+
return Fq.fromBuffer(Buffer.from(response.value));
|
|
450
|
+
}
|
|
451
|
+
|
|
436
452
|
toJSON() {
|
|
437
453
|
return this.toString();
|
|
438
454
|
}
|
|
439
455
|
|
|
456
|
+
toFields() {
|
|
457
|
+
// The following has to match the order of the limbs in EmbeddedCurveScalar struct in noir::std. This is because
|
|
458
|
+
// this function is used when returning Scalar from the getAddressSecret oracle and in Noir the values get deserialized
|
|
459
|
+
// using the intrinsic serialization of Noir (which follows the order of the fields/members in the struct).
|
|
460
|
+
return [this.lo, this.hi];
|
|
461
|
+
}
|
|
462
|
+
|
|
440
463
|
static get schema() {
|
|
441
464
|
return hexSchemaFor(Fq);
|
|
442
465
|
}
|
|
@@ -486,7 +509,7 @@ export function reduceFn<TInput, TField extends BaseField>(fn: (input: TInput) =
|
|
|
486
509
|
}
|
|
487
510
|
|
|
488
511
|
/** If we are in test mode, we register a special equality for fields. */
|
|
489
|
-
if (process.env.NODE_ENV === 'test'
|
|
512
|
+
if (process.env.NODE_ENV === 'test') {
|
|
490
513
|
const areFieldsEqual = (a: unknown, b: unknown): boolean | undefined => {
|
|
491
514
|
const isAField = a instanceof BaseField;
|
|
492
515
|
const isBField = b instanceof BaseField;
|
|
@@ -500,6 +523,11 @@ if (process.env.NODE_ENV === 'test' && typeof expect !== 'undefined') {
|
|
|
500
523
|
}
|
|
501
524
|
};
|
|
502
525
|
|
|
503
|
-
|
|
504
|
-
|
|
526
|
+
if (typeof expect !== 'undefined') {
|
|
527
|
+
// `addEqualityTesters` doesn't seem to be in the types yet.
|
|
528
|
+
(expect as any).addEqualityTesters([areFieldsEqual]);
|
|
529
|
+
} else {
|
|
530
|
+
(globalThis as any).__extraEqualityTesters ??= [];
|
|
531
|
+
(globalThis as any).__extraEqualityTesters.push(areFieldsEqual);
|
|
532
|
+
}
|
|
505
533
|
}
|
package/src/fields/index.ts
CHANGED
package/src/fields/point.ts
CHANGED
|
@@ -188,7 +188,7 @@ export class Point {
|
|
|
188
188
|
*/
|
|
189
189
|
toBuffer() {
|
|
190
190
|
if (this.isInfinite) {
|
|
191
|
-
throw new Error('Cannot serialize infinite point
|
|
191
|
+
throw new Error('Cannot serialize infinite point with isInfinite flag');
|
|
192
192
|
}
|
|
193
193
|
const buf = serializeToBuffer([this.x, this.y]);
|
|
194
194
|
if (buf.length !== Point.SIZE_IN_BYTES) {
|
|
@@ -246,9 +246,7 @@ export class Point {
|
|
|
246
246
|
|
|
247
247
|
// Used for IvpkM, OvpkM, NpkM and TpkM. TODO(#8124): Consider removing this method.
|
|
248
248
|
toWrappedNoirStruct() {
|
|
249
|
-
/* eslint-disable camelcase */
|
|
250
249
|
return { inner: this.toNoirStruct() };
|
|
251
|
-
/* eslint-enable camelcase */
|
|
252
250
|
}
|
|
253
251
|
|
|
254
252
|
/**
|
package/src/fs/index.ts
CHANGED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { rm } from 'fs/promises';
|
|
2
|
+
|
|
3
|
+
import type { Logger } from '../log/index.js';
|
|
4
|
+
|
|
5
|
+
export async function tryRmDir(dir: string | undefined, logger?: Logger): Promise<void> {
|
|
6
|
+
if (dir === undefined) {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
try {
|
|
10
|
+
logger?.debug(`Cleaning up directory at ${dir}`);
|
|
11
|
+
await rm(dir, { recursive: true, force: true, maxRetries: 3 });
|
|
12
|
+
} catch (err) {
|
|
13
|
+
logger?.warn(`Failed to delete directory at ${dir}: ${err}`);
|
|
14
|
+
}
|
|
15
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -23,9 +23,8 @@ export * as transport from './transport/index.js';
|
|
|
23
23
|
export * as trees from './trees/index.js';
|
|
24
24
|
export * as types from './types/index.js';
|
|
25
25
|
export * as url from './url/index.js';
|
|
26
|
-
export * as wasm from './wasm/index.js';
|
|
27
|
-
export * as worker from './worker/index.js';
|
|
28
26
|
export * as testing from './testing/index.js';
|
|
27
|
+
export * as profiler from './profiler/index.js';
|
|
29
28
|
export * as config from './config/index.js';
|
|
30
29
|
export * as buffer from './buffer/index.js';
|
|
31
30
|
export * as ethSignature from './eth-signature/index.js';
|
package/src/iterable/filter.ts
CHANGED
package/src/iterable/map.ts
CHANGED
package/src/jest/env.mjs
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { TestEnvironment } from 'jest-environment-node';
|
|
2
|
+
|
|
3
|
+
// What errors should be ignored in after hooks
|
|
4
|
+
const IgnoredErrors = ['HttpRequestError', 'CodeError'];
|
|
5
|
+
|
|
6
|
+
/** Custom Jest environment that ignores any whitelisted unhandled rejections that occur during `after` hooks */
|
|
7
|
+
export default class CustomEnvironment extends TestEnvironment {
|
|
8
|
+
constructor(config, context) {
|
|
9
|
+
super(config, context);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
async handleTestEvent(event, state) {
|
|
13
|
+
if (event.name === 'setup') {
|
|
14
|
+
// Jest 29 reports both unhandledRejection and uncaughtException events as plain `error`, without any means to differentiate them
|
|
15
|
+
// (see https://github.com/jestjs/jest/issues/9210). Jest 30 fixes it as part of a larger change (see
|
|
16
|
+
// https://github.com/jestjs/jest/pull/14315/files#diff-9bdc1fdb60c8631b1e346eff6e4899c4e64ae3a44f4f12d0d7ac70c2aabd1d93R12-R29),
|
|
17
|
+
// but we cannot update to 30 as it is still in beta at the time of writing this code. So we remove jest's unhandledRejection listener,
|
|
18
|
+
// replace it with our own, and delegate to the original listener only if the error is not in the ignored list.
|
|
19
|
+
const parentProcess = event.parentProcess;
|
|
20
|
+
const [jestListener] = parentProcess.listeners('unhandledRejection');
|
|
21
|
+
parentProcess.removeAllListeners('unhandledRejection');
|
|
22
|
+
const patchedListener = (err, _promise) => {
|
|
23
|
+
if (state.isInAfterHook && IgnoredErrors.some(error => err && err.name && err.name.includes(error))) {
|
|
24
|
+
// Ignore the error only if it was an unhandled async rejection (not sync exception), it's on the IgnoredErrors list, and we're in an after hook.
|
|
25
|
+
console.error('Ignoring unhandled rejection in after hook:', err);
|
|
26
|
+
} else if (state.isInAfterHook) {
|
|
27
|
+
// Log non-ignored unhandled rejection in an after hook, and pass the error to the original jest listener to fail the test.
|
|
28
|
+
console.error(`Unhandled rejection in after hook:`, err);
|
|
29
|
+
jestListener && jestListener(err);
|
|
30
|
+
} else {
|
|
31
|
+
// Otherwise, just delegate to the original jest listener, to emit the `error` event under the hood.
|
|
32
|
+
jestListener && jestListener(err);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
parentProcess.on('unhandledRejection', patchedListener);
|
|
36
|
+
state.patchedListener = patchedListener;
|
|
37
|
+
} else if (event.name === 'teardown') {
|
|
38
|
+
// Remove the patched handler we added in setup.
|
|
39
|
+
const parentProcess = state.parentProcess;
|
|
40
|
+
parentProcess.removeListener('unhandledRejection', state.patchedListener);
|
|
41
|
+
} else if (event.name === 'hook_start' && event.hook.type.startsWith('after')) {
|
|
42
|
+
// Track that we have entered an after hook.
|
|
43
|
+
state.isInAfterHook = true;
|
|
44
|
+
} else if (
|
|
45
|
+
(event.name === 'hook_success' || event.name === 'hook_failure') &&
|
|
46
|
+
event.hook.type.startsWith('after')
|
|
47
|
+
) {
|
|
48
|
+
// Reset the flag that we are in an after hook when we exit it.
|
|
49
|
+
state.isInAfterHook = false;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|