@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,77 @@
|
|
|
1
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
2
|
+
import type { Hex } from '@aztec/foundation/string';
|
|
3
|
+
|
|
4
|
+
import { mod } from '@noble/curves/abstract/modular';
|
|
5
|
+
import { bytesToNumberBE } from '@noble/curves/abstract/utils';
|
|
6
|
+
import { hmac } from '@noble/hashes/hmac';
|
|
7
|
+
import { sha512 } from '@noble/hashes/sha2';
|
|
8
|
+
import { mnemonicToSeedSync } from '@scure/bip39';
|
|
9
|
+
|
|
10
|
+
export function deriveBlsPrivateKey(mnemonic: string | undefined, ikm: string | undefined, path: string): Hex<32> {
|
|
11
|
+
if (ikm) {
|
|
12
|
+
return deriveBlsKeyFromEntropy(ikm, path) as Hex<32>;
|
|
13
|
+
}
|
|
14
|
+
if (!mnemonic) {
|
|
15
|
+
throw new Error('Either mnemonic or ikm must be provided for BLS derivation');
|
|
16
|
+
}
|
|
17
|
+
return deriveBlsKeyFromMnemonic(mnemonic, path) as Hex<32>;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Deterministically derive a BN254 BLS private key from mnemonic and derivation path.
|
|
22
|
+
* Returns a 0x-prefixed 32-byte hex string representing an Fr in [1, r-1].
|
|
23
|
+
*/
|
|
24
|
+
export function deriveBlsKeyFromMnemonic(mnemonic: string, derivationPath: string, passphrase = ''): string {
|
|
25
|
+
const seed = Buffer.from(mnemonicToSeedSync(mnemonic, passphrase)); // 64 bytes
|
|
26
|
+
const data = Buffer.concat([Buffer.from([0x00]), seed, Buffer.from(derivationPath, 'utf8')]);
|
|
27
|
+
const sk = deriveBn254ScalarFromData(data);
|
|
28
|
+
return `0x${toFixed32(sk).toString('hex')}`;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Deterministically derive a BN254 BLS private key from input keying material (IKM) and derivation path.
|
|
33
|
+
* Returns a 0x-prefixed 32-byte hex string representing an Fr in [1, r-1].
|
|
34
|
+
*/
|
|
35
|
+
export function deriveBlsKeyFromEntropy(ikm: string, derivationPath: string): string {
|
|
36
|
+
const ikmBytes = parseIkm(ikm);
|
|
37
|
+
const data = Buffer.concat([Buffer.from([0x01]), ikmBytes, Buffer.from(derivationPath, 'utf8')]);
|
|
38
|
+
const sk = deriveBn254ScalarFromData(data);
|
|
39
|
+
return `0x${toFixed32(sk).toString('hex')}`;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function deriveBn254ScalarFromData(data: Buffer): bigint {
|
|
43
|
+
// Domain-separated HMAC-SHA512, then map to BN254 Fr using noble modular math. Retry on zero.
|
|
44
|
+
const domainKey = Buffer.from('Aztec bn254 key', 'utf8');
|
|
45
|
+
for (let counter = 0; ; counter = (counter + 1) & 0xff) {
|
|
46
|
+
const msg = counter === 0 ? data : Buffer.concat([data, Buffer.from([counter])]);
|
|
47
|
+
const digest = hmac(sha512, domainKey, msg); // 64 bytes
|
|
48
|
+
const x = bytesToNumberBE(digest);
|
|
49
|
+
const sk = mod(x, Fr.MODULUS);
|
|
50
|
+
if (sk !== 0n) {
|
|
51
|
+
return sk;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function parseIkm(ikm: string): Buffer {
|
|
57
|
+
const hexMatch = ikm.replace(/^0x/i, '');
|
|
58
|
+
if (/^[0-9a-fA-F]+$/.test(hexMatch) && hexMatch.length >= 2) {
|
|
59
|
+
const normalized = hexMatch.length % 2 === 1 ? `0${hexMatch}` : hexMatch;
|
|
60
|
+
return Buffer.from(normalized, 'hex');
|
|
61
|
+
}
|
|
62
|
+
return Buffer.from(ikm, 'utf8');
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function toFixed32(x: bigint): Buffer {
|
|
66
|
+
const hex = x.toString(16);
|
|
67
|
+
const padded = hex.length % 2 === 1 ? `0${hex}` : hex;
|
|
68
|
+
const buf = Buffer.from(padded, 'hex');
|
|
69
|
+
if (buf.length === 32) {
|
|
70
|
+
return buf;
|
|
71
|
+
}
|
|
72
|
+
if (buf.length < 32) {
|
|
73
|
+
return Buffer.concat([Buffer.alloc(32 - buf.length, 0), buf]);
|
|
74
|
+
}
|
|
75
|
+
// Should never happen since x < bn254.Fr.ORDER < 2^256, but guard anyway
|
|
76
|
+
return buf.subarray(buf.length - 32);
|
|
77
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { Fr } from '../../fields/fields.js';
|
|
2
|
+
import { Bn254G1Point, Bn254G2Point } from './index.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* BN254 utility functions for point operations.
|
|
6
|
+
* Provides compression, decompression, and public key generation for the BN254 curve.
|
|
7
|
+
* Uses the bb.js Barretenberg backend for point operations.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Generate a compressed BN254 G1 public key from a private key.
|
|
12
|
+
*
|
|
13
|
+
* @param privateKeyHex - Private key as 0x-prefixed hex string
|
|
14
|
+
* @returns Compressed G1 point (32 bytes with sign bit in MSB)
|
|
15
|
+
*/
|
|
16
|
+
export async function computeBn254G1PublicKeyCompressed(privateKeyHex: string): Promise<string> {
|
|
17
|
+
const sk = BigInt(privateKeyHex);
|
|
18
|
+
const skReduced = sk % Fr.MODULUS;
|
|
19
|
+
|
|
20
|
+
// Generate G1 point on BN254 curve using bb.js
|
|
21
|
+
const scalar = Fr.fromString(skReduced.toString());
|
|
22
|
+
const pk1 = await Bn254G1Point.generator(scalar);
|
|
23
|
+
|
|
24
|
+
// Compress the point using the primitive method
|
|
25
|
+
return '0x' + pk1.compress().toString('hex');
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Generate uncompressed BN254 G1 public key from a private key.
|
|
30
|
+
*
|
|
31
|
+
* @param privateKeyHex - Private key as 0x-prefixed hex string
|
|
32
|
+
* @returns G1 point in affine coordinates
|
|
33
|
+
*/
|
|
34
|
+
export async function computeBn254G1PublicKey(privateKeyHex: string): Promise<{ x: bigint; y: bigint }> {
|
|
35
|
+
const sk = BigInt(privateKeyHex);
|
|
36
|
+
const skReduced = sk % Fr.MODULUS;
|
|
37
|
+
|
|
38
|
+
const scalar = Fr.fromString(skReduced.toString());
|
|
39
|
+
const pk1 = await Bn254G1Point.generator(scalar);
|
|
40
|
+
|
|
41
|
+
return { x: pk1.x.toBigInt(), y: pk1.y.toBigInt() };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Generate BN254 G2 public key from a private key.
|
|
46
|
+
*
|
|
47
|
+
* @param privateKeyHex - Private key as 0x-prefixed hex string
|
|
48
|
+
* @returns G2 point in affine coordinates
|
|
49
|
+
*/
|
|
50
|
+
export async function computeBn254G2PublicKey(privateKeyHex: string): Promise<{
|
|
51
|
+
x: { c0: bigint; c1: bigint };
|
|
52
|
+
y: { c0: bigint; c1: bigint };
|
|
53
|
+
}> {
|
|
54
|
+
const sk = BigInt(privateKeyHex);
|
|
55
|
+
const skReduced = sk % Fr.MODULUS;
|
|
56
|
+
|
|
57
|
+
const scalar = Fr.fromString(skReduced.toString());
|
|
58
|
+
const pk2 = await Bn254G2Point.generator(scalar);
|
|
59
|
+
|
|
60
|
+
return {
|
|
61
|
+
x: { c0: pk2.x[0].toBigInt(), c1: pk2.x[1].toBigInt() },
|
|
62
|
+
y: { c0: pk2.y[0].toBigInt(), c1: pk2.y[1].toBigInt() },
|
|
63
|
+
};
|
|
64
|
+
}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BN254_G1_GENERATOR,
|
|
3
|
+
BN254_G2_GENERATOR,
|
|
4
|
+
BarretenbergSync,
|
|
5
|
+
type Bn254G1Point as BbApiBn254G1Point,
|
|
6
|
+
type Bn254G2Point as BbApiBn254G2Point,
|
|
7
|
+
} from '@aztec/bb.js';
|
|
8
|
+
|
|
9
|
+
import { Fq, Fr } from '../../fields/fields.js';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* BN254 G1 point using foundation field classes.
|
|
13
|
+
* Represents a point on the BN254 elliptic curve in affine coordinates.
|
|
14
|
+
*/
|
|
15
|
+
export class Bn254G1Point {
|
|
16
|
+
constructor(
|
|
17
|
+
public readonly x: Fq,
|
|
18
|
+
public readonly y: Fq,
|
|
19
|
+
) {}
|
|
20
|
+
|
|
21
|
+
private toBbApiPoint(): BbApiBn254G1Point {
|
|
22
|
+
return {
|
|
23
|
+
x: this.x.toBuffer(),
|
|
24
|
+
y: this.y.toBuffer(),
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
private static fromBbApiPoint(point: BbApiBn254G1Point): Bn254G1Point {
|
|
29
|
+
return new Bn254G1Point(Fq.fromBuffer(Buffer.from(point.x)), Fq.fromBuffer(Buffer.from(point.y)));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async isOnCurve(): Promise<boolean> {
|
|
33
|
+
await BarretenbergSync.initSingleton();
|
|
34
|
+
const api = BarretenbergSync.getSingleton();
|
|
35
|
+
|
|
36
|
+
const apiPoint = this.toBbApiPoint();
|
|
37
|
+
const response = api.bn254G1IsOnCurve({ point: apiPoint });
|
|
38
|
+
return response.isOnCurve;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Get the generator point for BN254 G1, or perform scalar multiplication.
|
|
43
|
+
* When called without arguments, returns the base generator point.
|
|
44
|
+
* When called with a scalar, returns scalar * generator (useful for public key derivation).
|
|
45
|
+
*/
|
|
46
|
+
static async generator(scalar?: Fr): Promise<Bn254G1Point> {
|
|
47
|
+
if (!scalar) {
|
|
48
|
+
return new Bn254G1Point(
|
|
49
|
+
Fq.fromBuffer(Buffer.from(BN254_G1_GENERATOR.x)),
|
|
50
|
+
Fq.fromBuffer(Buffer.from(BN254_G1_GENERATOR.y)),
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
await BarretenbergSync.initSingleton();
|
|
55
|
+
const api = BarretenbergSync.getSingleton();
|
|
56
|
+
|
|
57
|
+
const response = api.bn254G1Mul({
|
|
58
|
+
point: BN254_G1_GENERATOR,
|
|
59
|
+
scalar: scalar.toBuffer(),
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
return Bn254G1Point.fromBbApiPoint(response.point);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Decompress a BN254 G1 point from compressed form (32 bytes).
|
|
67
|
+
* The compressed format encodes the x-coordinate and the sign bit of the y-coordinate
|
|
68
|
+
* in the most significant bit.
|
|
69
|
+
*/
|
|
70
|
+
static async fromCompressed(compressed: Buffer): Promise<Bn254G1Point> {
|
|
71
|
+
await BarretenbergSync.initSingleton();
|
|
72
|
+
const api = BarretenbergSync.getSingleton();
|
|
73
|
+
|
|
74
|
+
const response = api.bn254G1FromCompressed({
|
|
75
|
+
compressed: new Uint8Array(compressed),
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
return Bn254G1Point.fromBbApiPoint(response.point);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Compress this BN254 G1 point to 32 bytes.
|
|
83
|
+
* The compressed format encodes the x-coordinate and the sign bit of the y-coordinate
|
|
84
|
+
* in the most significant bit (bit 255).
|
|
85
|
+
*/
|
|
86
|
+
compress(): Buffer {
|
|
87
|
+
const xBytes = this.x.toBuffer();
|
|
88
|
+
// Get the least significant bit of y to determine the sign
|
|
89
|
+
const yLsb = this.y.toBigInt() & 1n;
|
|
90
|
+
// If y is odd, set the most significant bit (bit 255) of the output
|
|
91
|
+
if (yLsb === 1n) {
|
|
92
|
+
xBytes[0] |= 0x80;
|
|
93
|
+
}
|
|
94
|
+
return xBytes;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
equals(other: Bn254G1Point): boolean {
|
|
98
|
+
return this.x.equals(other.x) && this.y.equals(other.y);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
toString(): string {
|
|
102
|
+
return `Bn254G1Point(x: ${this.x.toString()}, y: ${this.y.toString()})`;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* BN254 G2 point using foundation field classes.
|
|
108
|
+
* Represents a point on the BN254 G2 curve (twist curve) in affine coordinates.
|
|
109
|
+
* G2 points use extension field coordinates (Fq2).
|
|
110
|
+
*/
|
|
111
|
+
export class Bn254G2Point {
|
|
112
|
+
constructor(
|
|
113
|
+
public readonly x: [Fq, Fq],
|
|
114
|
+
public readonly y: [Fq, Fq],
|
|
115
|
+
) {}
|
|
116
|
+
|
|
117
|
+
private toBbApiPoint(): BbApiBn254G2Point {
|
|
118
|
+
return {
|
|
119
|
+
x: [this.x[0].toBuffer(), this.x[1].toBuffer()],
|
|
120
|
+
y: [this.y[0].toBuffer(), this.y[1].toBuffer()],
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
private static fromBbApiPoint(point: BbApiBn254G2Point): Bn254G2Point {
|
|
125
|
+
return new Bn254G2Point(
|
|
126
|
+
[Fq.fromBuffer(Buffer.from(point.x[0])), Fq.fromBuffer(Buffer.from(point.x[1]))],
|
|
127
|
+
[Fq.fromBuffer(Buffer.from(point.y[0])), Fq.fromBuffer(Buffer.from(point.y[1]))],
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Get the generator point for BN254 G2, or perform scalar multiplication.
|
|
133
|
+
* When called without arguments, returns the base generator point.
|
|
134
|
+
* When called with a scalar, returns scalar * generator.
|
|
135
|
+
*/
|
|
136
|
+
static async generator(scalar?: Fr): Promise<Bn254G2Point> {
|
|
137
|
+
if (!scalar) {
|
|
138
|
+
return new Bn254G2Point(
|
|
139
|
+
[Fq.fromBuffer(Buffer.from(BN254_G2_GENERATOR.x[0])), Fq.fromBuffer(Buffer.from(BN254_G2_GENERATOR.x[1]))],
|
|
140
|
+
[Fq.fromBuffer(Buffer.from(BN254_G2_GENERATOR.y[0])), Fq.fromBuffer(Buffer.from(BN254_G2_GENERATOR.y[1]))],
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
await BarretenbergSync.initSingleton();
|
|
145
|
+
const api = BarretenbergSync.getSingleton();
|
|
146
|
+
|
|
147
|
+
const response = api.bn254G2Mul({
|
|
148
|
+
point: BN254_G2_GENERATOR as BbApiBn254G2Point,
|
|
149
|
+
scalar: scalar.toBuffer(),
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
return Bn254G2Point.fromBbApiPoint(response.point);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
equals(other: Bn254G2Point): boolean {
|
|
156
|
+
return (
|
|
157
|
+
this.x[0].equals(other.x[0]) &&
|
|
158
|
+
this.x[1].equals(other.x[1]) &&
|
|
159
|
+
this.y[0].equals(other.y[0]) &&
|
|
160
|
+
this.y[1].equals(other.y[1])
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
toString(): string {
|
|
165
|
+
return `Bn254G2Point(x: (${this.x[0].toString()}, ${this.x[1].toString()}), y: (${this.y[0].toString()}, ${this.y[1].toString()}))`;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// Re-export BN254 point utility functions
|
|
170
|
+
export { computeBn254G1PublicKeyCompressed, computeBn254G1PublicKey, computeBn254G2PublicKey } from './bn254_utils.js';
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { BarretenbergSync } from '@aztec/bb.js';
|
|
2
|
-
import { numToInt32BE } from '@aztec/foundation/serialize';
|
|
3
2
|
|
|
4
|
-
import { concatenateUint8Arrays } from '../serialize.js';
|
|
5
3
|
import { EcdsaSignature } from './signature.js';
|
|
6
4
|
|
|
7
5
|
export * from './signature.js';
|
|
@@ -11,15 +9,20 @@ export * from './signature.js';
|
|
|
11
9
|
* TODO: Replace with codegen api on bb.js.
|
|
12
10
|
*/
|
|
13
11
|
export class Ecdsa {
|
|
12
|
+
constructor(private curve: 'secp256k1' | 'secp256r1' = 'secp256k1') {}
|
|
14
13
|
/**
|
|
15
14
|
* Computes a secp256k1 public key from a private key.
|
|
16
15
|
* @param privateKey - Secp256k1 private key.
|
|
17
16
|
* @returns A secp256k1 public key.
|
|
18
17
|
*/
|
|
19
18
|
public async computePublicKey(privateKey: Buffer): Promise<Buffer> {
|
|
20
|
-
|
|
21
|
-
const
|
|
22
|
-
|
|
19
|
+
await BarretenbergSync.initSingleton({ wasmPath: process.env.BB_WASM_PATH });
|
|
20
|
+
const api = BarretenbergSync.getSingleton();
|
|
21
|
+
const response =
|
|
22
|
+
this.curve === 'secp256r1'
|
|
23
|
+
? api.ecdsaSecp256r1ComputePublicKey({ privateKey })
|
|
24
|
+
: api.ecdsaSecp256k1ComputePublicKey({ privateKey });
|
|
25
|
+
return Buffer.concat([Buffer.from(response.publicKey.x), Buffer.from(response.publicKey.y)]);
|
|
23
26
|
}
|
|
24
27
|
|
|
25
28
|
/**
|
|
@@ -29,12 +32,13 @@ export class Ecdsa {
|
|
|
29
32
|
* @returns An ECDSA signature of the form (r, s, v).
|
|
30
33
|
*/
|
|
31
34
|
public async constructSignature(msg: Uint8Array, privateKey: Buffer) {
|
|
32
|
-
|
|
33
|
-
const
|
|
34
|
-
const
|
|
35
|
-
.
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
await BarretenbergSync.initSingleton({ wasmPath: process.env.BB_WASM_PATH });
|
|
36
|
+
const api = BarretenbergSync.getSingleton();
|
|
37
|
+
const response =
|
|
38
|
+
this.curve === 'secp256r1'
|
|
39
|
+
? api.ecdsaSecp256r1ConstructSignature({ message: msg, privateKey })
|
|
40
|
+
: api.ecdsaSecp256k1ConstructSignature({ message: msg, privateKey });
|
|
41
|
+
return new EcdsaSignature(Buffer.from(response.r), Buffer.from(response.s), Buffer.from([response.v]));
|
|
38
42
|
}
|
|
39
43
|
|
|
40
44
|
/**
|
|
@@ -44,12 +48,13 @@ export class Ecdsa {
|
|
|
44
48
|
* @returns The secp256k1 public key of the signer.
|
|
45
49
|
*/
|
|
46
50
|
public async recoverPublicKey(msg: Uint8Array, sig: EcdsaSignature): Promise<Buffer> {
|
|
47
|
-
|
|
48
|
-
const
|
|
49
|
-
const
|
|
50
|
-
.
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
await BarretenbergSync.initSingleton({ wasmPath: process.env.BB_WASM_PATH });
|
|
52
|
+
const api = BarretenbergSync.getSingleton();
|
|
53
|
+
const response =
|
|
54
|
+
this.curve === 'secp256r1'
|
|
55
|
+
? api.ecdsaSecp256r1RecoverPublicKey({ message: msg, r: sig.r, s: sig.s, v: sig.v[0] })
|
|
56
|
+
: api.ecdsaSecp256k1RecoverPublicKey({ message: msg, r: sig.r, s: sig.s, v: sig.v[0] });
|
|
57
|
+
return Buffer.concat([Buffer.from(response.publicKey.x), Buffer.from(response.publicKey.y)]);
|
|
53
58
|
}
|
|
54
59
|
|
|
55
60
|
/**
|
|
@@ -60,11 +65,24 @@ export class Ecdsa {
|
|
|
60
65
|
* @returns True or false.
|
|
61
66
|
*/
|
|
62
67
|
public async verifySignature(msg: Uint8Array, pubKey: Buffer, sig: EcdsaSignature) {
|
|
63
|
-
|
|
64
|
-
const
|
|
65
|
-
const
|
|
66
|
-
.
|
|
67
|
-
|
|
68
|
-
|
|
68
|
+
await BarretenbergSync.initSingleton({ wasmPath: process.env.BB_WASM_PATH });
|
|
69
|
+
const api = BarretenbergSync.getSingleton();
|
|
70
|
+
const response =
|
|
71
|
+
this.curve === 'secp256r1'
|
|
72
|
+
? api.ecdsaSecp256r1VerifySignature({
|
|
73
|
+
message: msg,
|
|
74
|
+
publicKey: { x: pubKey.subarray(0, 32), y: pubKey.subarray(32, 64) },
|
|
75
|
+
r: sig.r,
|
|
76
|
+
s: sig.s,
|
|
77
|
+
v: sig.v[0],
|
|
78
|
+
})
|
|
79
|
+
: api.ecdsaSecp256k1VerifySignature({
|
|
80
|
+
message: msg,
|
|
81
|
+
publicKey: { x: pubKey.subarray(0, 32), y: pubKey.subarray(32, 64) },
|
|
82
|
+
r: sig.r,
|
|
83
|
+
s: sig.s,
|
|
84
|
+
v: sig.v[0],
|
|
85
|
+
});
|
|
86
|
+
return response.verified;
|
|
69
87
|
}
|
|
70
88
|
}
|
|
@@ -6,31 +6,27 @@ import { Fr, type GrumpkinScalar, Point } from '@aztec/foundation/fields';
|
|
|
6
6
|
*/
|
|
7
7
|
export class Grumpkin {
|
|
8
8
|
// prettier-ignore
|
|
9
|
-
static generator = Point.fromBuffer(Buffer.from([
|
|
9
|
+
static readonly generator = Point.fromBuffer(Buffer.from([
|
|
10
10
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
11
11
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
|
|
12
12
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xcf, 0x13, 0x5e, 0x75, 0x06, 0xa4, 0x5d, 0x63,
|
|
13
13
|
0x2d, 0x27, 0x0d, 0x45, 0xf1, 0x18, 0x12, 0x94, 0x83, 0x3f, 0xc4, 0x8d, 0x82, 0x3f, 0x27, 0x2c,
|
|
14
14
|
]));
|
|
15
15
|
|
|
16
|
-
/**
|
|
17
|
-
* Point generator
|
|
18
|
-
* @returns The generator for the curve.
|
|
19
|
-
*/
|
|
20
|
-
public generator(): Point {
|
|
21
|
-
return Grumpkin.generator;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
16
|
/**
|
|
25
17
|
* Multiplies a point by a scalar (adds the point `scalar` amount of times).
|
|
26
18
|
* @param point - Point to multiply.
|
|
27
19
|
* @param scalar - Scalar to multiply by.
|
|
28
20
|
* @returns Result of the multiplication.
|
|
29
21
|
*/
|
|
30
|
-
public async mul(point: Point, scalar: GrumpkinScalar): Promise<Point> {
|
|
31
|
-
|
|
32
|
-
const
|
|
33
|
-
|
|
22
|
+
public static async mul(point: Point, scalar: GrumpkinScalar): Promise<Point> {
|
|
23
|
+
await BarretenbergSync.initSingleton({ wasmPath: process.env.BB_WASM_PATH });
|
|
24
|
+
const api = BarretenbergSync.getSingleton();
|
|
25
|
+
const response = api.grumpkinMul({
|
|
26
|
+
point: { x: point.x.toBuffer(), y: point.y.toBuffer() },
|
|
27
|
+
scalar: scalar.toBuffer(),
|
|
28
|
+
});
|
|
29
|
+
return Point.fromBuffer(Buffer.concat([Buffer.from(response.point.x), Buffer.from(response.point.y)]));
|
|
34
30
|
}
|
|
35
31
|
|
|
36
32
|
/**
|
|
@@ -39,10 +35,14 @@ export class Grumpkin {
|
|
|
39
35
|
* @param b - Point b to add to a
|
|
40
36
|
* @returns Result of the addition.
|
|
41
37
|
*/
|
|
42
|
-
public async add(a: Point, b: Point): Promise<Point> {
|
|
43
|
-
|
|
44
|
-
const
|
|
45
|
-
|
|
38
|
+
public static async add(a: Point, b: Point): Promise<Point> {
|
|
39
|
+
await BarretenbergSync.initSingleton({ wasmPath: process.env.BB_WASM_PATH });
|
|
40
|
+
const api = BarretenbergSync.getSingleton();
|
|
41
|
+
const response = api.grumpkinAdd({
|
|
42
|
+
pointA: { x: a.x.toBuffer(), y: a.y.toBuffer() },
|
|
43
|
+
pointB: { x: b.x.toBuffer(), y: b.y.toBuffer() },
|
|
44
|
+
});
|
|
45
|
+
return Point.fromBuffer(Buffer.concat([Buffer.from(response.point.x), Buffer.from(response.point.y)]));
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
/**
|
|
@@ -51,35 +51,26 @@ export class Grumpkin {
|
|
|
51
51
|
* @param scalar - Scalar to multiply by.
|
|
52
52
|
* @returns Points multiplied by the scalar.
|
|
53
53
|
*/
|
|
54
|
-
public async batchMul(points: Point[], scalar: GrumpkinScalar) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
.getWasm()
|
|
62
|
-
.callWasmExport(
|
|
63
|
-
'ecc_grumpkin__batch_mul',
|
|
64
|
-
[concatenatedPoints, scalar.toBuffer(), points.length],
|
|
65
|
-
[pointsByteLength],
|
|
66
|
-
);
|
|
54
|
+
public static async batchMul(points: Point[], scalar: GrumpkinScalar) {
|
|
55
|
+
await BarretenbergSync.initSingleton({ wasmPath: process.env.BB_WASM_PATH });
|
|
56
|
+
const api = BarretenbergSync.getSingleton();
|
|
57
|
+
const response = api.grumpkinBatchMul({
|
|
58
|
+
points: points.map(p => ({ x: p.x.toBuffer(), y: p.y.toBuffer() })),
|
|
59
|
+
scalar: scalar.toBuffer(),
|
|
60
|
+
});
|
|
67
61
|
|
|
68
|
-
|
|
69
|
-
for (let i = 0; i < pointsByteLength; i += 64) {
|
|
70
|
-
parsedResult.push(Point.fromBuffer(Buffer.from(result.subarray(i, i + 64))));
|
|
71
|
-
}
|
|
72
|
-
return parsedResult;
|
|
62
|
+
return response.points.map(p => Point.fromBuffer(Buffer.concat([Buffer.from(p.x), Buffer.from(p.y)])));
|
|
73
63
|
}
|
|
74
64
|
|
|
75
65
|
/**
|
|
76
66
|
* Gets a random field element.
|
|
77
67
|
* @returns Random field element.
|
|
78
68
|
*/
|
|
79
|
-
public async getRandomFr(): Promise<Fr> {
|
|
80
|
-
|
|
81
|
-
const
|
|
82
|
-
|
|
69
|
+
public static async getRandomFr(): Promise<Fr> {
|
|
70
|
+
await BarretenbergSync.initSingleton({ wasmPath: process.env.BB_WASM_PATH });
|
|
71
|
+
const api = BarretenbergSync.getSingleton();
|
|
72
|
+
const response = api.grumpkinGetRandomFr({ dummy: 0 });
|
|
73
|
+
return Fr.fromBuffer(Buffer.from(response.value));
|
|
83
74
|
}
|
|
84
75
|
|
|
85
76
|
/**
|
|
@@ -87,11 +78,10 @@ export class Grumpkin {
|
|
|
87
78
|
* @param uint512Buf - The buffer to convert.
|
|
88
79
|
* @returns Buffer representation of the field element.
|
|
89
80
|
*/
|
|
90
|
-
public async reduce512BufferToFr(uint512Buf: Buffer): Promise<Fr> {
|
|
91
|
-
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
return Fr.fromBuffer(Buffer.from(result));
|
|
81
|
+
public static async reduce512BufferToFr(uint512Buf: Buffer): Promise<Fr> {
|
|
82
|
+
await BarretenbergSync.initSingleton({ wasmPath: process.env.BB_WASM_PATH });
|
|
83
|
+
const api = BarretenbergSync.getSingleton();
|
|
84
|
+
const response = api.grumpkinReduce512({ input: uint512Buf });
|
|
85
|
+
return Fr.fromBuffer(Buffer.from(response.value));
|
|
96
86
|
}
|
|
97
87
|
}
|
package/src/crypto/index.ts
CHANGED
|
@@ -7,8 +7,10 @@ export * from './poseidon/index.js';
|
|
|
7
7
|
export * from './secp256k1-signer/index.js';
|
|
8
8
|
export * from './keys/index.js';
|
|
9
9
|
export * from './aes128/index.js';
|
|
10
|
+
export * from './bn254/index.js';
|
|
10
11
|
export * from './grumpkin/index.js';
|
|
11
12
|
export * from './ecdsa/index.js';
|
|
12
13
|
export * from './secp256k1/index.js';
|
|
13
14
|
export * from './schnorr/index.js';
|
|
14
15
|
export * from './signature/index.js';
|
|
16
|
+
export * from './bls/index.js';
|
package/src/crypto/keys/index.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { BarretenbergSync
|
|
1
|
+
import { BarretenbergSync } from '@aztec/bb.js';
|
|
2
2
|
|
|
3
3
|
import { Fr } from '../../fields/fields.js';
|
|
4
4
|
|
|
5
5
|
export async function vkAsFieldsMegaHonk(input: Buffer): Promise<Fr[]> {
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
return
|
|
6
|
+
await BarretenbergSync.initSingleton({ wasmPath: process.env.BB_WASM_PATH });
|
|
7
|
+
const api = BarretenbergSync.getSingleton();
|
|
8
|
+
const response = api.megaVkAsFields({ verificationKey: input });
|
|
9
|
+
return response.fields.map(field => Fr.fromBuffer(Buffer.from(field)));
|
|
10
10
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BarretenbergSync
|
|
1
|
+
import { BarretenbergSync } from '@aztec/bb.js';
|
|
2
2
|
|
|
3
3
|
import { Fr } from '../../fields/fields.js';
|
|
4
4
|
import { type Fieldable, serializeToFields } from '../../serialize/serialize.js';
|
|
@@ -12,14 +12,13 @@ export async function pedersenCommit(input: Buffer[], offset = 0) {
|
|
|
12
12
|
throw new Error('All Pedersen Commit input buffers must be <= 32 bytes.');
|
|
13
13
|
}
|
|
14
14
|
input = input.map(i => (i.length < 32 ? Buffer.concat([Buffer.alloc(32 - i.length, 0), i]) : i));
|
|
15
|
-
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
return [Buffer.from(point.x.toBuffer()), Buffer.from(point.y.toBuffer())];
|
|
15
|
+
await BarretenbergSync.initSingleton({ wasmPath: process.env.BB_WASM_PATH });
|
|
16
|
+
const api = BarretenbergSync.getSingleton();
|
|
17
|
+
const response = api.pedersenCommit({
|
|
18
|
+
inputs: input,
|
|
19
|
+
hashIndex: offset,
|
|
20
|
+
});
|
|
21
|
+
return [Buffer.from(response.point.x), Buffer.from(response.point.y)];
|
|
23
22
|
}
|
|
24
23
|
|
|
25
24
|
/**
|
|
@@ -30,19 +29,24 @@ export async function pedersenCommit(input: Buffer[], offset = 0) {
|
|
|
30
29
|
*/
|
|
31
30
|
export async function pedersenHash(input: Fieldable[], index = 0): Promise<Fr> {
|
|
32
31
|
const inputFields = serializeToFields(input);
|
|
33
|
-
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
32
|
+
await BarretenbergSync.initSingleton({ wasmPath: process.env.BB_WASM_PATH });
|
|
33
|
+
const api = BarretenbergSync.getSingleton();
|
|
34
|
+
const response = api.pedersenHash({
|
|
35
|
+
inputs: inputFields.map(i => i.toBuffer()),
|
|
36
|
+
hashIndex: index,
|
|
37
|
+
});
|
|
38
|
+
return Fr.fromBuffer(Buffer.from(response.hash));
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
/**
|
|
42
42
|
* Create a pedersen hash from an arbitrary length buffer.
|
|
43
43
|
*/
|
|
44
44
|
export async function pedersenHashBuffer(input: Buffer, index = 0) {
|
|
45
|
-
|
|
46
|
-
const
|
|
47
|
-
|
|
45
|
+
await BarretenbergSync.initSingleton({ wasmPath: process.env.BB_WASM_PATH });
|
|
46
|
+
const api = BarretenbergSync.getSingleton();
|
|
47
|
+
const response = api.pedersenHashBuffer({
|
|
48
|
+
input,
|
|
49
|
+
hashIndex: index,
|
|
50
|
+
});
|
|
51
|
+
return Buffer.from(response.hash);
|
|
48
52
|
}
|