@aztec/foundation 0.0.1-commit.b655e406 → 0.0.1-commit.fce3e4f
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/array/array.d.ts +1 -9
- package/dest/array/array.d.ts.map +1 -1
- package/dest/array/array.js +0 -11
- package/dest/array/index.d.ts +1 -1
- package/dest/async-map/index.d.ts +1 -1
- package/dest/async-pool/index.d.ts +1 -1
- package/dest/bigint/index.d.ts +1 -1
- package/dest/bigint-buffer/index.d.ts +1 -1
- package/dest/branded-types/epoch.d.ts +42 -0
- package/dest/branded-types/epoch.d.ts.map +1 -0
- package/dest/branded-types/epoch.js +59 -0
- package/dest/branded-types/index.d.ts +4 -0
- package/dest/branded-types/index.d.ts.map +1 -0
- package/dest/branded-types/index.js +2 -0
- package/dest/branded-types/slot.d.ts +42 -0
- package/dest/branded-types/slot.d.ts.map +1 -0
- package/dest/branded-types/slot.js +59 -0
- package/dest/branded-types/types.d.ts +5 -0
- package/dest/branded-types/types.d.ts.map +1 -0
- package/dest/branded-types/types.js +1 -0
- package/dest/buffer/buffer16.d.ts +1 -4
- package/dest/buffer/buffer16.d.ts.map +1 -1
- package/dest/buffer/buffer32.d.ts +1 -4
- package/dest/buffer/buffer32.d.ts.map +1 -1
- package/dest/buffer/index.d.ts +1 -1
- package/dest/collection/array.d.ts +1 -1
- package/dest/collection/index.d.ts +1 -1
- package/dest/collection/object.d.ts +1 -1
- package/dest/committable/committable.d.ts +1 -1
- package/dest/committable/committable.d.ts.map +1 -1
- package/dest/committable/index.d.ts +1 -1
- package/dest/config/env_var.d.ts +2 -2
- package/dest/config/env_var.d.ts.map +1 -1
- package/dest/config/index.d.ts +1 -1
- package/dest/config/network_config.d.ts +1 -1
- package/dest/config/network_name.d.ts +1 -1
- package/dest/config/secret_value.d.ts +1 -1
- package/dest/config/secret_value.d.ts.map +1 -1
- package/dest/crypto/aes128/index.d.ts +1 -1
- package/dest/crypto/aes128/index.d.ts.map +1 -1
- package/dest/crypto/aes128/index.js +2 -6
- package/dest/crypto/bls/bn254_keystore.d.ts +15 -15
- package/dest/crypto/bls/bn254_keystore.d.ts.map +1 -1
- package/dest/crypto/bls/index.d.ts +1 -1
- package/dest/crypto/bn254/bn254_utils.d.ts +1 -1
- package/dest/crypto/bn254/index.d.ts +1 -1
- package/dest/crypto/bn254/index.d.ts.map +1 -1
- package/dest/crypto/bn254/index.js +3 -0
- package/dest/crypto/ecdsa/index.d.ts +1 -1
- package/dest/crypto/ecdsa/index.d.ts.map +1 -1
- package/dest/crypto/ecdsa/index.js +4 -12
- package/dest/crypto/ecdsa/signature.d.ts +1 -10
- package/dest/crypto/ecdsa/signature.d.ts.map +1 -1
- package/dest/crypto/grumpkin/index.d.ts +1 -1
- package/dest/crypto/grumpkin/index.d.ts.map +1 -1
- package/dest/crypto/grumpkin/index.js +5 -15
- package/dest/crypto/index.d.ts +1 -1
- package/dest/crypto/keccak/index.d.ts +1 -1
- package/dest/crypto/keys/index.d.ts +1 -1
- package/dest/crypto/keys/index.js +1 -3
- package/dest/crypto/pedersen/index.d.ts +1 -1
- package/dest/crypto/pedersen/pedersen.noble.d.ts +1 -1
- package/dest/crypto/pedersen/pedersen.wasm.d.ts +1 -1
- package/dest/crypto/pedersen/pedersen.wasm.js +3 -9
- package/dest/crypto/poseidon/index.d.ts +1 -1
- package/dest/crypto/poseidon/index.js +5 -15
- package/dest/crypto/random/index.d.ts +1 -1
- package/dest/crypto/random/index.d.ts.map +1 -1
- package/dest/crypto/random/randomness_singleton.d.ts +1 -1
- package/dest/crypto/random/randomness_singleton.d.ts.map +1 -1
- package/dest/crypto/schnorr/index.d.ts +1 -1
- package/dest/crypto/schnorr/index.d.ts.map +1 -1
- package/dest/crypto/schnorr/index.js +3 -9
- package/dest/crypto/schnorr/signature.d.ts +1 -1
- package/dest/crypto/schnorr/signature.d.ts.map +1 -1
- package/dest/crypto/secp256k1/index.d.ts +1 -1
- package/dest/crypto/secp256k1/index.d.ts.map +1 -1
- package/dest/crypto/secp256k1/index.js +3 -9
- package/dest/crypto/secp256k1-signer/index.d.ts +1 -1
- package/dest/crypto/secp256k1-signer/secp256k1_signer.d.ts +1 -1
- package/dest/crypto/secp256k1-signer/secp256k1_signer.d.ts.map +1 -1
- package/dest/crypto/secp256k1-signer/utils.d.ts +1 -1
- package/dest/crypto/secp256k1-signer/utils.d.ts.map +1 -1
- package/dest/crypto/serialize.d.ts +1 -1
- package/dest/crypto/sha256/index.d.ts +1 -1
- package/dest/crypto/sha256/index.d.ts.map +1 -1
- package/dest/crypto/sha512/index.d.ts +2 -2
- package/dest/crypto/sha512/index.d.ts.map +1 -1
- package/dest/crypto/signature/index.d.ts +1 -1
- package/dest/crypto/sync/index.d.ts +1 -1
- package/dest/crypto/sync/index.js +1 -3
- package/dest/crypto/sync/pedersen/index.d.ts +1 -1
- package/dest/crypto/sync/poseidon/index.d.ts +1 -1
- package/dest/decorators/index.d.ts +1 -1
- package/dest/decorators/memoize.d.ts +1 -1
- package/dest/decorators/memoize.d.ts.map +1 -1
- package/dest/error/index.d.ts +4 -4
- package/dest/error/index.d.ts.map +1 -1
- package/dest/eth-address/index.d.ts +10 -1
- package/dest/eth-address/index.d.ts.map +1 -1
- package/dest/eth-address/index.js +17 -0
- package/dest/eth-signature/eth_signature.d.ts +1 -4
- package/dest/eth-signature/eth_signature.d.ts.map +1 -1
- package/dest/eth-signature/index.d.ts +1 -1
- package/dest/fields/bls12_fields.d.ts +1 -1
- package/dest/fields/bls12_fields.d.ts.map +1 -1
- package/dest/fields/bls12_point.d.ts +1 -10
- package/dest/fields/bls12_point.d.ts.map +1 -1
- package/dest/fields/coordinate.d.ts +1 -4
- package/dest/fields/coordinate.d.ts.map +1 -1
- package/dest/fields/fields.d.ts +10 -1
- package/dest/fields/fields.d.ts.map +1 -1
- package/dest/fields/fields.js +14 -0
- package/dest/fields/index.d.ts +1 -1
- package/dest/fields/point.d.ts +11 -11
- package/dest/fields/point.d.ts.map +1 -1
- package/dest/fields/point.js +17 -0
- package/dest/fs/index.d.ts +1 -1
- package/dest/fs/run_in_dir.d.ts +1 -1
- package/dest/fs/try_rm_dir.d.ts +1 -1
- package/dest/index.d.ts +2 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -0
- package/dest/iterable/all.d.ts +1 -1
- package/dest/iterable/filter.d.ts +1 -1
- package/dest/iterable/index.d.ts +1 -1
- package/dest/iterable/isAsyncIt.d.ts +1 -1
- package/dest/iterable/map.d.ts +1 -1
- package/dest/iterable/peek.d.ts +1 -1
- package/dest/iterable/sort.d.ts +1 -1
- package/dest/iterable/take.d.ts +1 -1
- package/dest/iterable/toArray.d.ts +1 -1
- package/dest/json-rpc/client/fetch.d.ts +1 -1
- package/dest/json-rpc/client/index.d.ts +1 -1
- package/dest/json-rpc/client/safe_json_rpc_client.d.ts +1 -1
- package/dest/json-rpc/client/undici.d.ts +1 -1
- package/dest/json-rpc/convert.d.ts +1 -1
- package/dest/json-rpc/errors.d.ts +1 -1
- package/dest/json-rpc/errors.d.ts.map +1 -1
- package/dest/json-rpc/fixtures/class_a.d.ts +3 -3
- package/dest/json-rpc/fixtures/class_a.d.ts.map +1 -1
- package/dest/json-rpc/fixtures/class_b.d.ts +3 -3
- package/dest/json-rpc/fixtures/class_b.d.ts.map +1 -1
- package/dest/json-rpc/fixtures/test_state.d.ts +1 -1
- package/dest/json-rpc/fixtures/test_state.d.ts.map +1 -1
- package/dest/json-rpc/index.d.ts +1 -1
- package/dest/json-rpc/js_utils.d.ts +1 -1
- package/dest/json-rpc/js_utils.d.ts.map +1 -1
- package/dest/json-rpc/server/index.d.ts +1 -1
- package/dest/json-rpc/server/safe_json_rpc_server.d.ts +1 -1
- package/dest/json-rpc/server/safe_json_rpc_server.d.ts.map +1 -1
- package/dest/json-rpc/server/telemetry.d.ts +1 -1
- package/dest/json-rpc/test/index.d.ts +1 -1
- package/dest/json-rpc/test/integration.d.ts +1 -1
- package/dest/log/console.d.ts +1 -1
- package/dest/log/gcloud-logger-config.d.ts +1 -1
- package/dest/log/gcloud-logger-config.d.ts.map +1 -1
- package/dest/log/index.d.ts +1 -1
- package/dest/log/libp2p_logger.d.ts +1 -1
- package/dest/log/log-filters.d.ts +1 -1
- package/dest/log/log-levels.d.ts +1 -1
- package/dest/log/log_fn.d.ts +1 -1
- package/dest/log/noir_debug_log_util.d.ts +1 -1
- package/dest/log/pino-logger.d.ts +2 -2
- package/dest/message/index.d.ts +1 -1
- package/dest/message/index.d.ts.map +1 -1
- package/dest/mutex/index.d.ts +1 -1
- package/dest/mutex/index.d.ts.map +1 -1
- package/dest/mutex/mutex_database.d.ts +1 -1
- package/dest/noir/index.d.ts +1 -1
- package/dest/noir/noir_package_config.d.ts +9 -9
- package/dest/number/index.d.ts +1 -1
- package/dest/profiler/index.d.ts +1 -1
- package/dest/profiler/profiler.d.ts +1 -1
- package/dest/promise/index.d.ts +1 -1
- package/dest/promise/running-promise.d.ts +1 -1
- package/dest/promise/running-promise.d.ts.map +1 -1
- package/dest/promise/utils.d.ts +1 -1
- package/dest/queue/base_memory_queue.d.ts +1 -1
- package/dest/queue/base_memory_queue.d.ts.map +1 -1
- package/dest/queue/batch_queue.d.ts +1 -1
- package/dest/queue/batch_queue.d.ts.map +1 -1
- package/dest/queue/bounded_serial_queue.d.ts +1 -1
- package/dest/queue/bounded_serial_queue.d.ts.map +1 -1
- package/dest/queue/fifo_memory_queue.d.ts +1 -1
- package/dest/queue/fifo_memory_queue.d.ts.map +1 -1
- package/dest/queue/index.d.ts +1 -1
- package/dest/queue/priority_memory_queue.d.ts +1 -1
- package/dest/queue/priority_memory_queue.d.ts.map +1 -1
- package/dest/queue/priority_queue.d.ts +1 -1
- package/dest/queue/priority_queue.d.ts.map +1 -1
- package/dest/queue/semaphore.d.ts +1 -1
- package/dest/queue/semaphore.d.ts.map +1 -1
- package/dest/queue/serial_queue.d.ts +1 -1
- package/dest/queue/serial_queue.d.ts.map +1 -1
- package/dest/retry/index.d.ts +1 -1
- package/dest/running-promise/index.d.ts +1 -1
- package/dest/schemas/api.d.ts +1 -1
- package/dest/schemas/index.d.ts +1 -1
- package/dest/schemas/parse.d.ts +1 -1
- package/dest/schemas/schemas.d.ts +9 -15
- package/dest/schemas/schemas.d.ts.map +1 -1
- package/dest/schemas/schemas.js +5 -7
- package/dest/schemas/types.d.ts +1 -1
- package/dest/schemas/utils.d.ts +4 -4
- package/dest/schemas/utils.d.ts.map +1 -1
- package/dest/schemas/utils.js +15 -5
- package/dest/serialize/buffer_reader.d.ts +1 -1
- package/dest/serialize/buffer_reader.d.ts.map +1 -1
- package/dest/serialize/field_reader.d.ts +1 -1
- package/dest/serialize/field_reader.d.ts.map +1 -1
- package/dest/serialize/free_funcs.d.ts +1 -1
- package/dest/serialize/index.d.ts +1 -1
- package/dest/serialize/serialize.d.ts +1 -1
- package/dest/serialize/type_registry.d.ts +1 -1
- package/dest/serialize/type_registry.d.ts.map +1 -1
- package/dest/serialize/types.d.ts +1 -1
- package/dest/sleep/index.d.ts +1 -1
- package/dest/sleep/index.d.ts.map +1 -1
- package/dest/string/index.d.ts +1 -1
- package/dest/testing/files/index.d.ts +2 -1
- package/dest/testing/files/index.d.ts.map +1 -1
- package/dest/testing/files/index.js +1 -1
- package/dest/testing/formatting.d.ts +1 -1
- package/dest/testing/index.d.ts +1 -1
- package/dest/testing/port_allocator.d.ts +1 -1
- package/dest/testing/snapshot_serializer.d.ts +1 -1
- package/dest/testing/test_data.d.ts +1 -1
- package/dest/timer/date.d.ts +1 -1
- package/dest/timer/date.d.ts.map +1 -1
- package/dest/timer/elapsed.d.ts +1 -1
- package/dest/timer/index.d.ts +1 -1
- package/dest/timer/timeout.d.ts +1 -1
- package/dest/timer/timeout.d.ts.map +1 -1
- package/dest/timer/timer.d.ts +1 -1
- package/dest/timer/timer.d.ts.map +1 -1
- package/dest/transport/dispatch/create_dispatch_fn.d.ts +1 -1
- package/dest/transport/dispatch/create_dispatch_fn.d.ts.map +1 -1
- package/dest/transport/dispatch/create_dispatch_proxy.d.ts +1 -1
- package/dest/transport/dispatch/messages.d.ts +1 -1
- package/dest/transport/index.d.ts +1 -1
- package/dest/transport/interface/connector.d.ts +1 -1
- package/dest/transport/interface/listener.d.ts +1 -1
- package/dest/transport/interface/socket.d.ts +1 -1
- package/dest/transport/interface/transferable.d.ts +1 -1
- package/dest/transport/node/index.d.ts +1 -1
- package/dest/transport/node/node_connector.d.ts +1 -1
- package/dest/transport/node/node_connector.d.ts.map +1 -1
- package/dest/transport/node/node_connector_socket.d.ts +1 -1
- package/dest/transport/node/node_connector_socket.d.ts.map +1 -1
- package/dest/transport/node/node_listener.d.ts +1 -1
- package/dest/transport/node/node_listener.d.ts.map +1 -1
- package/dest/transport/node/node_listener_socket.d.ts +1 -1
- package/dest/transport/node/node_listener_socket.d.ts.map +1 -1
- package/dest/transport/transport_client.d.ts +1 -1
- package/dest/transport/transport_client.d.ts.map +1 -1
- package/dest/transport/transport_server.d.ts +1 -10
- package/dest/transport/transport_server.d.ts.map +1 -1
- package/dest/trees/balanced_merkle_tree.d.ts +22 -0
- package/dest/trees/balanced_merkle_tree.d.ts.map +1 -0
- package/dest/trees/balanced_merkle_tree.js +64 -0
- package/dest/trees/hasher.d.ts +1 -1
- package/dest/trees/index.d.ts +2 -1
- package/dest/trees/index.d.ts.map +1 -1
- package/dest/trees/index.js +1 -0
- package/dest/trees/indexed_merkle_tree.d.ts +1 -1
- package/dest/trees/indexed_merkle_tree.d.ts.map +1 -1
- package/dest/trees/indexed_merkle_tree_calculator.d.ts +1 -1
- package/dest/trees/indexed_merkle_tree_calculator.d.ts.map +1 -1
- package/dest/trees/indexed_tree_leaf.d.ts +1 -1
- package/dest/trees/membership_witness.d.ts +2 -23
- package/dest/trees/membership_witness.d.ts.map +1 -1
- package/dest/trees/merkle_tree.d.ts +1 -1
- package/dest/trees/merkle_tree.d.ts.map +1 -1
- package/dest/trees/merkle_tree_calculator.d.ts +2 -12
- package/dest/trees/merkle_tree_calculator.d.ts.map +1 -1
- package/dest/trees/merkle_tree_calculator.js +1 -31
- package/dest/trees/sibling_path.d.ts +4 -38
- package/dest/trees/sibling_path.d.ts.map +1 -1
- package/dest/trees/unbalanced_merkle_tree.d.ts +5 -3
- package/dest/trees/unbalanced_merkle_tree.d.ts.map +1 -1
- package/dest/trees/unbalanced_merkle_tree.js +32 -9
- package/dest/trees/unbalanced_merkle_tree_calculator.d.ts +6 -5
- package/dest/trees/unbalanced_merkle_tree_calculator.d.ts.map +1 -1
- package/dest/trees/unbalanced_merkle_tree_calculator.js +36 -40
- package/dest/trees/unbalanced_tree_store.d.ts +1 -1
- package/dest/trees/unbalanced_tree_store.d.ts.map +1 -1
- package/dest/types/index.d.ts +1 -1
- package/dest/url/index.d.ts +1 -1
- package/dest/validation/index.d.ts +1 -1
- package/package.json +7 -5
- package/src/array/array.ts +0 -16
- package/src/branded-types/epoch.ts +88 -0
- package/src/branded-types/index.ts +4 -0
- package/src/branded-types/slot.ts +88 -0
- package/src/branded-types/types.ts +2 -0
- package/src/config/env_var.ts +12 -2
- package/src/crypto/aes128/index.ts +2 -2
- package/src/crypto/bn254/index.ts +3 -0
- package/src/crypto/ecdsa/index.ts +4 -4
- package/src/crypto/grumpkin/index.ts +5 -5
- package/src/crypto/keys/index.ts +1 -1
- package/src/crypto/pedersen/pedersen.wasm.ts +3 -3
- package/src/crypto/poseidon/index.ts +5 -5
- package/src/crypto/schnorr/index.ts +3 -3
- package/src/crypto/secp256k1/index.ts +3 -3
- package/src/crypto/sync/index.ts +1 -1
- package/src/eth-address/index.ts +19 -0
- package/src/fields/fields.ts +16 -0
- package/src/fields/point.ts +19 -0
- package/src/index.ts +1 -0
- package/src/schemas/schemas.ts +10 -10
- package/src/schemas/utils.ts +21 -8
- package/src/testing/files/index.ts +1 -1
- package/src/trees/balanced_merkle_tree.ts +82 -0
- package/src/trees/index.ts +1 -0
- package/src/trees/merkle_tree_calculator.ts +1 -34
- package/src/trees/unbalanced_merkle_tree.ts +54 -6
- package/src/trees/unbalanced_merkle_tree_calculator.ts +34 -41
package/src/config/env_var.ts
CHANGED
|
@@ -86,6 +86,7 @@ export type EnvVar =
|
|
|
86
86
|
| 'OTEL_EXPORTER_OTLP_LOGS_ENDPOINT'
|
|
87
87
|
| 'OTEL_COLLECT_INTERVAL_MS'
|
|
88
88
|
| 'OTEL_EXCLUDE_METRICS'
|
|
89
|
+
| 'OTEL_INCLUDE_METRICS'
|
|
89
90
|
| 'OTEL_EXPORT_TIMEOUT_MS'
|
|
90
91
|
| 'PUBLIC_OTEL_EXPORTER_OTLP_METRICS_ENDPOINT'
|
|
91
92
|
| 'PUBLIC_OTEL_INCLUDE_METRICS'
|
|
@@ -136,6 +137,7 @@ export type EnvVar =
|
|
|
136
137
|
| 'P2P_DROP_TX'
|
|
137
138
|
| 'P2P_DROP_TX_CHANCE'
|
|
138
139
|
| 'P2P_TX_POOL_DELETE_TXS_AFTER_REORG'
|
|
140
|
+
| 'DEBUG_P2P_INSTRUMENT_MESSAGES'
|
|
139
141
|
| 'PEER_ID_PRIVATE_KEY'
|
|
140
142
|
| 'PEER_ID_PRIVATE_KEY_PATH'
|
|
141
143
|
| 'PROVER_AGENT_COUNT'
|
|
@@ -168,6 +170,7 @@ export type EnvVar =
|
|
|
168
170
|
| 'PROVER_TEST_DELAY_FACTOR'
|
|
169
171
|
| 'PROVER_TEST_DELAY_MS'
|
|
170
172
|
| 'PROVER_TEST_DELAY_TYPE'
|
|
173
|
+
| 'PROVER_TEST_VERIFICATION_DELAY_MS'
|
|
171
174
|
| 'PXE_L2_BLOCK_BATCH_SIZE'
|
|
172
175
|
| 'PXE_PROVER_ENABLED'
|
|
173
176
|
| 'RPC_MAX_BATCH_SIZE'
|
|
@@ -247,7 +250,8 @@ export type EnvVar =
|
|
|
247
250
|
| 'AZTEC_SLOT_DURATION'
|
|
248
251
|
| 'AZTEC_EPOCH_DURATION'
|
|
249
252
|
| 'AZTEC_TARGET_COMMITTEE_SIZE'
|
|
250
|
-
| '
|
|
253
|
+
| 'AZTEC_LAG_IN_EPOCHS_FOR_VALIDATOR_SET'
|
|
254
|
+
| 'AZTEC_LAG_IN_EPOCHS_FOR_RANDAO'
|
|
251
255
|
| 'AZTEC_PROOF_SUBMISSION_EPOCHS'
|
|
252
256
|
| 'AZTEC_ACTIVATION_THRESHOLD'
|
|
253
257
|
| 'AZTEC_EJECTION_THRESHOLD'
|
|
@@ -270,10 +274,13 @@ export type EnvVar =
|
|
|
270
274
|
| 'AZTEC_EXIT_DELAY_SECONDS'
|
|
271
275
|
| 'L1_GAS_LIMIT_BUFFER_PERCENTAGE'
|
|
272
276
|
| 'L1_GAS_PRICE_MAX'
|
|
277
|
+
| 'L1_FEE_PER_GAS_GWEI_MAX'
|
|
273
278
|
| 'L1_BLOB_FEE_PER_GAS_MAX'
|
|
279
|
+
| 'L1_BLOB_FEE_PER_GAS_GWEI_MAX'
|
|
274
280
|
| 'L1_PRIORITY_FEE_BUMP_PERCENTAGE'
|
|
275
281
|
| 'L1_PRIORITY_FEE_RETRY_BUMP_PERCENTAGE'
|
|
276
282
|
| 'L1_FIXED_PRIORITY_FEE_PER_GAS'
|
|
283
|
+
| 'L1_FIXED_PRIORITY_FEE_PER_GAS_GWEI'
|
|
277
284
|
| 'L1_TX_MONITOR_MAX_ATTEMPTS'
|
|
278
285
|
| 'L1_TX_MONITOR_CHECK_INTERVAL_MS'
|
|
279
286
|
| 'L1_TX_MONITOR_STALL_TIME_MS'
|
|
@@ -294,4 +301,7 @@ export type EnvVar =
|
|
|
294
301
|
| 'AUTO_UPDATE_URL'
|
|
295
302
|
| 'WEB3_SIGNER_URL'
|
|
296
303
|
| 'SKIP_ARCHIVER_INITIAL_SYNC'
|
|
297
|
-
| 'BLOB_ALLOW_EMPTY_SOURCES'
|
|
304
|
+
| 'BLOB_ALLOW_EMPTY_SOURCES'
|
|
305
|
+
| 'FISHERMAN_MODE'
|
|
306
|
+
| 'MAX_ALLOWED_ETH_CLIENT_DRIFT_SECONDS'
|
|
307
|
+
| 'LEGACY_BLS_CLI';
|
|
@@ -22,7 +22,7 @@ export class Aes128 {
|
|
|
22
22
|
paddingBuffer.fill(numPaddingBytes);
|
|
23
23
|
const input = Buffer.concat([data, paddingBuffer]);
|
|
24
24
|
|
|
25
|
-
await BarretenbergSync.initSingleton(
|
|
25
|
+
await BarretenbergSync.initSingleton();
|
|
26
26
|
const api = BarretenbergSync.getSingleton();
|
|
27
27
|
const response = api.aesEncrypt({
|
|
28
28
|
plaintext: input,
|
|
@@ -42,7 +42,7 @@ export class Aes128 {
|
|
|
42
42
|
* @returns Decrypted data.
|
|
43
43
|
*/
|
|
44
44
|
public async decryptBufferCBCKeepPadding(data: Uint8Array, iv: Uint8Array, key: Uint8Array): Promise<Buffer> {
|
|
45
|
-
await BarretenbergSync.initSingleton(
|
|
45
|
+
await BarretenbergSync.initSingleton();
|
|
46
46
|
const api = BarretenbergSync.getSingleton();
|
|
47
47
|
const response = api.aesDecrypt({
|
|
48
48
|
ciphertext: data,
|
|
@@ -68,6 +68,9 @@ export class Bn254G1Point {
|
|
|
68
68
|
* in the most significant bit.
|
|
69
69
|
*/
|
|
70
70
|
static async fromCompressed(compressed: Buffer): Promise<Bn254G1Point> {
|
|
71
|
+
if (compressed.length !== 32) {
|
|
72
|
+
throw new Error('Invalid compressed point length');
|
|
73
|
+
}
|
|
71
74
|
await BarretenbergSync.initSingleton();
|
|
72
75
|
const api = BarretenbergSync.getSingleton();
|
|
73
76
|
|
|
@@ -16,7 +16,7 @@ export class Ecdsa {
|
|
|
16
16
|
* @returns A secp256k1 public key.
|
|
17
17
|
*/
|
|
18
18
|
public async computePublicKey(privateKey: Buffer): Promise<Buffer> {
|
|
19
|
-
await BarretenbergSync.initSingleton(
|
|
19
|
+
await BarretenbergSync.initSingleton();
|
|
20
20
|
const api = BarretenbergSync.getSingleton();
|
|
21
21
|
const response =
|
|
22
22
|
this.curve === 'secp256r1'
|
|
@@ -32,7 +32,7 @@ export class Ecdsa {
|
|
|
32
32
|
* @returns An ECDSA signature of the form (r, s, v).
|
|
33
33
|
*/
|
|
34
34
|
public async constructSignature(msg: Uint8Array, privateKey: Buffer) {
|
|
35
|
-
await BarretenbergSync.initSingleton(
|
|
35
|
+
await BarretenbergSync.initSingleton();
|
|
36
36
|
const api = BarretenbergSync.getSingleton();
|
|
37
37
|
const response =
|
|
38
38
|
this.curve === 'secp256r1'
|
|
@@ -48,7 +48,7 @@ export class Ecdsa {
|
|
|
48
48
|
* @returns The secp256k1 public key of the signer.
|
|
49
49
|
*/
|
|
50
50
|
public async recoverPublicKey(msg: Uint8Array, sig: EcdsaSignature): Promise<Buffer> {
|
|
51
|
-
await BarretenbergSync.initSingleton(
|
|
51
|
+
await BarretenbergSync.initSingleton();
|
|
52
52
|
const api = BarretenbergSync.getSingleton();
|
|
53
53
|
const response =
|
|
54
54
|
this.curve === 'secp256r1'
|
|
@@ -65,7 +65,7 @@ export class Ecdsa {
|
|
|
65
65
|
* @returns True or false.
|
|
66
66
|
*/
|
|
67
67
|
public async verifySignature(msg: Uint8Array, pubKey: Buffer, sig: EcdsaSignature) {
|
|
68
|
-
await BarretenbergSync.initSingleton(
|
|
68
|
+
await BarretenbergSync.initSingleton();
|
|
69
69
|
const api = BarretenbergSync.getSingleton();
|
|
70
70
|
const response =
|
|
71
71
|
this.curve === 'secp256r1'
|
|
@@ -20,7 +20,7 @@ export class Grumpkin {
|
|
|
20
20
|
* @returns Result of the multiplication.
|
|
21
21
|
*/
|
|
22
22
|
public static async mul(point: Point, scalar: GrumpkinScalar): Promise<Point> {
|
|
23
|
-
await BarretenbergSync.initSingleton(
|
|
23
|
+
await BarretenbergSync.initSingleton();
|
|
24
24
|
const api = BarretenbergSync.getSingleton();
|
|
25
25
|
const response = api.grumpkinMul({
|
|
26
26
|
point: { x: point.x.toBuffer(), y: point.y.toBuffer() },
|
|
@@ -36,7 +36,7 @@ export class Grumpkin {
|
|
|
36
36
|
* @returns Result of the addition.
|
|
37
37
|
*/
|
|
38
38
|
public static async add(a: Point, b: Point): Promise<Point> {
|
|
39
|
-
await BarretenbergSync.initSingleton(
|
|
39
|
+
await BarretenbergSync.initSingleton();
|
|
40
40
|
const api = BarretenbergSync.getSingleton();
|
|
41
41
|
const response = api.grumpkinAdd({
|
|
42
42
|
pointA: { x: a.x.toBuffer(), y: a.y.toBuffer() },
|
|
@@ -52,7 +52,7 @@ export class Grumpkin {
|
|
|
52
52
|
* @returns Points multiplied by the scalar.
|
|
53
53
|
*/
|
|
54
54
|
public static async batchMul(points: Point[], scalar: GrumpkinScalar) {
|
|
55
|
-
await BarretenbergSync.initSingleton(
|
|
55
|
+
await BarretenbergSync.initSingleton();
|
|
56
56
|
const api = BarretenbergSync.getSingleton();
|
|
57
57
|
const response = api.grumpkinBatchMul({
|
|
58
58
|
points: points.map(p => ({ x: p.x.toBuffer(), y: p.y.toBuffer() })),
|
|
@@ -67,7 +67,7 @@ export class Grumpkin {
|
|
|
67
67
|
* @returns Random field element.
|
|
68
68
|
*/
|
|
69
69
|
public static async getRandomFr(): Promise<Fr> {
|
|
70
|
-
await BarretenbergSync.initSingleton(
|
|
70
|
+
await BarretenbergSync.initSingleton();
|
|
71
71
|
const api = BarretenbergSync.getSingleton();
|
|
72
72
|
const response = api.grumpkinGetRandomFr({ dummy: 0 });
|
|
73
73
|
return Fr.fromBuffer(Buffer.from(response.value));
|
|
@@ -79,7 +79,7 @@ export class Grumpkin {
|
|
|
79
79
|
* @returns Buffer representation of the field element.
|
|
80
80
|
*/
|
|
81
81
|
public static async reduce512BufferToFr(uint512Buf: Buffer): Promise<Fr> {
|
|
82
|
-
await BarretenbergSync.initSingleton(
|
|
82
|
+
await BarretenbergSync.initSingleton();
|
|
83
83
|
const api = BarretenbergSync.getSingleton();
|
|
84
84
|
const response = api.grumpkinReduce512({ input: uint512Buf });
|
|
85
85
|
return Fr.fromBuffer(Buffer.from(response.value));
|
package/src/crypto/keys/index.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { BarretenbergSync } from '@aztec/bb.js';
|
|
|
3
3
|
import { Fr } from '../../fields/fields.js';
|
|
4
4
|
|
|
5
5
|
export async function vkAsFieldsMegaHonk(input: Buffer): Promise<Fr[]> {
|
|
6
|
-
await BarretenbergSync.initSingleton(
|
|
6
|
+
await BarretenbergSync.initSingleton();
|
|
7
7
|
const api = BarretenbergSync.getSingleton();
|
|
8
8
|
const response = api.megaVkAsFields({ verificationKey: input });
|
|
9
9
|
return response.fields.map(field => Fr.fromBuffer(Buffer.from(field)));
|
|
@@ -12,7 +12,7 @@ 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
|
-
await BarretenbergSync.initSingleton(
|
|
15
|
+
await BarretenbergSync.initSingleton();
|
|
16
16
|
const api = BarretenbergSync.getSingleton();
|
|
17
17
|
const response = api.pedersenCommit({
|
|
18
18
|
inputs: input,
|
|
@@ -29,7 +29,7 @@ export async function pedersenCommit(input: Buffer[], offset = 0) {
|
|
|
29
29
|
*/
|
|
30
30
|
export async function pedersenHash(input: Fieldable[], index = 0): Promise<Fr> {
|
|
31
31
|
const inputFields = serializeToFields(input);
|
|
32
|
-
await BarretenbergSync.initSingleton(
|
|
32
|
+
await BarretenbergSync.initSingleton();
|
|
33
33
|
const api = BarretenbergSync.getSingleton();
|
|
34
34
|
const response = api.pedersenHash({
|
|
35
35
|
inputs: inputFields.map(i => i.toBuffer()),
|
|
@@ -42,7 +42,7 @@ export async function pedersenHash(input: Fieldable[], index = 0): Promise<Fr> {
|
|
|
42
42
|
* Create a pedersen hash from an arbitrary length buffer.
|
|
43
43
|
*/
|
|
44
44
|
export async function pedersenHashBuffer(input: Buffer, index = 0) {
|
|
45
|
-
await BarretenbergSync.initSingleton(
|
|
45
|
+
await BarretenbergSync.initSingleton();
|
|
46
46
|
const api = BarretenbergSync.getSingleton();
|
|
47
47
|
const response = api.pedersenHashBuffer({
|
|
48
48
|
input,
|
|
@@ -10,7 +10,7 @@ import { type Fieldable, serializeToFields } from '../../serialize/serialize.js'
|
|
|
10
10
|
*/
|
|
11
11
|
export async function poseidon2Hash(input: Fieldable[]): Promise<Fr> {
|
|
12
12
|
const inputFields = serializeToFields(input);
|
|
13
|
-
await BarretenbergSync.initSingleton(
|
|
13
|
+
await BarretenbergSync.initSingleton();
|
|
14
14
|
const api = BarretenbergSync.getSingleton();
|
|
15
15
|
const response = api.poseidon2Hash({
|
|
16
16
|
inputs: inputFields.map(i => i.toBuffer()),
|
|
@@ -27,7 +27,7 @@ export async function poseidon2Hash(input: Fieldable[]): Promise<Fr> {
|
|
|
27
27
|
export async function poseidon2HashWithSeparator(input: Fieldable[], separator: number): Promise<Fr> {
|
|
28
28
|
const inputFields = serializeToFields(input);
|
|
29
29
|
inputFields.unshift(new Fr(separator));
|
|
30
|
-
await BarretenbergSync.initSingleton(
|
|
30
|
+
await BarretenbergSync.initSingleton();
|
|
31
31
|
const api = BarretenbergSync.getSingleton();
|
|
32
32
|
const response = api.poseidon2Hash({
|
|
33
33
|
inputs: inputFields.map(i => i.toBuffer()),
|
|
@@ -37,7 +37,7 @@ export async function poseidon2HashWithSeparator(input: Fieldable[], separator:
|
|
|
37
37
|
|
|
38
38
|
export async function poseidon2HashAccumulate(input: Fieldable[]): Promise<Fr> {
|
|
39
39
|
const inputFields = serializeToFields(input);
|
|
40
|
-
await BarretenbergSync.initSingleton(
|
|
40
|
+
await BarretenbergSync.initSingleton();
|
|
41
41
|
const api = BarretenbergSync.getSingleton();
|
|
42
42
|
const response = api.poseidon2HashAccumulate({
|
|
43
43
|
inputs: inputFields.map(i => i.toBuffer()),
|
|
@@ -54,7 +54,7 @@ export async function poseidon2Permutation(input: Fieldable[]): Promise<Fr[]> {
|
|
|
54
54
|
const inputFields = serializeToFields(input);
|
|
55
55
|
// We'd like this assertion but it's not possible to use it in the browser.
|
|
56
56
|
// assert(input.length === 4, 'Input state must be of size 4');
|
|
57
|
-
await BarretenbergSync.initSingleton(
|
|
57
|
+
await BarretenbergSync.initSingleton();
|
|
58
58
|
const api = BarretenbergSync.getSingleton();
|
|
59
59
|
const response = api.poseidon2Permutation({
|
|
60
60
|
inputs: inputFields.map(i => i.toBuffer()),
|
|
@@ -75,7 +75,7 @@ export async function poseidon2HashBytes(input: Buffer): Promise<Fr> {
|
|
|
75
75
|
inputFields.push(Fr.fromBuffer(fieldBytes));
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
-
await BarretenbergSync.initSingleton(
|
|
78
|
+
await BarretenbergSync.initSingleton();
|
|
79
79
|
const api = BarretenbergSync.getSingleton();
|
|
80
80
|
const response = api.poseidon2Hash({
|
|
81
81
|
inputs: inputFields.map(i => i.toBuffer()),
|
|
@@ -15,7 +15,7 @@ export class Schnorr {
|
|
|
15
15
|
* @returns A grumpkin public key.
|
|
16
16
|
*/
|
|
17
17
|
public async computePublicKey(privateKey: GrumpkinScalar): Promise<Point> {
|
|
18
|
-
await BarretenbergSync.initSingleton(
|
|
18
|
+
await BarretenbergSync.initSingleton();
|
|
19
19
|
const api = BarretenbergSync.getSingleton();
|
|
20
20
|
const response = api.schnorrComputePublicKey({ privateKey: privateKey.toBuffer() });
|
|
21
21
|
return Point.fromBuffer(Buffer.concat([Buffer.from(response.publicKey.x), Buffer.from(response.publicKey.y)]));
|
|
@@ -28,7 +28,7 @@ export class Schnorr {
|
|
|
28
28
|
* @returns A Schnorr signature of the form (s, e).
|
|
29
29
|
*/
|
|
30
30
|
public async constructSignature(msg: Uint8Array, privateKey: GrumpkinScalar) {
|
|
31
|
-
await BarretenbergSync.initSingleton(
|
|
31
|
+
await BarretenbergSync.initSingleton();
|
|
32
32
|
const api = BarretenbergSync.getSingleton();
|
|
33
33
|
const response = api.schnorrConstructSignature({
|
|
34
34
|
message: msg,
|
|
@@ -45,7 +45,7 @@ export class Schnorr {
|
|
|
45
45
|
* @returns True or false.
|
|
46
46
|
*/
|
|
47
47
|
public async verifySignature(msg: Uint8Array, pubKey: Point, sig: SchnorrSignature) {
|
|
48
|
-
await BarretenbergSync.initSingleton(
|
|
48
|
+
await BarretenbergSync.initSingleton();
|
|
49
49
|
const api = BarretenbergSync.getSingleton();
|
|
50
50
|
const response = api.schnorrVerifySignature({
|
|
51
51
|
message: msg,
|
|
@@ -27,7 +27,7 @@ export class Secp256k1 {
|
|
|
27
27
|
* @returns Result of the multiplication.
|
|
28
28
|
*/
|
|
29
29
|
public async mul(point: Uint8Array, scalar: Uint8Array) {
|
|
30
|
-
await BarretenbergSync.initSingleton(
|
|
30
|
+
await BarretenbergSync.initSingleton();
|
|
31
31
|
const api = BarretenbergSync.getSingleton();
|
|
32
32
|
const response = api.secp256k1Mul({
|
|
33
33
|
point: { x: point.subarray(0, 32), y: point.subarray(32, 64) },
|
|
@@ -41,7 +41,7 @@ export class Secp256k1 {
|
|
|
41
41
|
* @returns Random field element.
|
|
42
42
|
*/
|
|
43
43
|
public async getRandomFr() {
|
|
44
|
-
await BarretenbergSync.initSingleton(
|
|
44
|
+
await BarretenbergSync.initSingleton();
|
|
45
45
|
const api = BarretenbergSync.getSingleton();
|
|
46
46
|
const response = api.secp256k1GetRandomFr({ dummy: 0 });
|
|
47
47
|
return Buffer.from(response.value);
|
|
@@ -53,7 +53,7 @@ export class Secp256k1 {
|
|
|
53
53
|
* @returns Buffer representation of the field element.
|
|
54
54
|
*/
|
|
55
55
|
public async reduce512BufferToFr(uint512Buf: Buffer) {
|
|
56
|
-
await BarretenbergSync.initSingleton(
|
|
56
|
+
await BarretenbergSync.initSingleton();
|
|
57
57
|
const api = BarretenbergSync.getSingleton();
|
|
58
58
|
const response = api.secp256k1Reduce512({ input: uint512Buf });
|
|
59
59
|
return Buffer.from(response.value);
|
package/src/crypto/sync/index.ts
CHANGED
package/src/eth-address/index.ts
CHANGED
|
@@ -41,6 +41,24 @@ export class EthAddress {
|
|
|
41
41
|
return new EthAddress(Buffer.from(address.replace(/^0x/i, ''), 'hex'));
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
+
/**
|
|
45
|
+
* Creates an EthAddress from a plain object without Zod validation.
|
|
46
|
+
* This method is optimized for performance and skips validation, making it suitable
|
|
47
|
+
* for deserializing trusted data (e.g., from C++ via MessagePack).
|
|
48
|
+
* Handles buffers (20 or 32 bytes), strings, or existing instances.
|
|
49
|
+
* @param obj - Plain object, buffer, string, or EthAddress instance
|
|
50
|
+
* @returns An EthAddress instance
|
|
51
|
+
*/
|
|
52
|
+
public static fromPlainObject(obj: any): EthAddress {
|
|
53
|
+
if (obj instanceof EthAddress) {
|
|
54
|
+
return obj;
|
|
55
|
+
}
|
|
56
|
+
if (obj instanceof Buffer || Buffer.isBuffer(obj)) {
|
|
57
|
+
return obj.length === 20 ? new EthAddress(obj) : EthAddress.fromField(new Fr(obj));
|
|
58
|
+
}
|
|
59
|
+
return EthAddress.fromString(obj);
|
|
60
|
+
}
|
|
61
|
+
|
|
44
62
|
/**
|
|
45
63
|
* Create a random EthAddress instance with 20 random bytes.
|
|
46
64
|
* This method generates a new Ethereum address with a randomly generated set of 20 bytes.
|
|
@@ -240,6 +258,7 @@ export class EthAddress {
|
|
|
240
258
|
}
|
|
241
259
|
|
|
242
260
|
static get schema() {
|
|
261
|
+
// Serialization from hex string.
|
|
243
262
|
return hexSchemaFor(EthAddress, EthAddress.isAddress);
|
|
244
263
|
}
|
|
245
264
|
}
|
package/src/fields/fields.ts
CHANGED
|
@@ -335,7 +335,23 @@ export class Fr extends BaseField {
|
|
|
335
335
|
return this.toString();
|
|
336
336
|
}
|
|
337
337
|
|
|
338
|
+
/**
|
|
339
|
+
* Creates an Fr instance from a plain object without Zod validation.
|
|
340
|
+
* This method is optimized for performance and skips validation, making it suitable
|
|
341
|
+
* for deserializing trusted data (e.g., from C++ via MessagePack).
|
|
342
|
+
* Handles buffers, strings, numbers, bigints, or existing instances.
|
|
343
|
+
* @param obj - Plain object, buffer, string, number, bigint, boolean, or Fr instance
|
|
344
|
+
* @returns An Fr instance
|
|
345
|
+
*/
|
|
346
|
+
static fromPlainObject(obj: any): Fr {
|
|
347
|
+
if (obj instanceof Fr) {
|
|
348
|
+
return obj;
|
|
349
|
+
}
|
|
350
|
+
return new Fr(obj);
|
|
351
|
+
}
|
|
352
|
+
|
|
338
353
|
static get schema() {
|
|
354
|
+
// Serialization from hex string.
|
|
339
355
|
return hexSchemaFor(Fr);
|
|
340
356
|
}
|
|
341
357
|
}
|
package/src/fields/point.ts
CHANGED
|
@@ -42,9 +42,28 @@ export class Point {
|
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
static get schema() {
|
|
45
|
+
// Serialization from hex string.
|
|
45
46
|
return hexSchemaFor(Point);
|
|
46
47
|
}
|
|
47
48
|
|
|
49
|
+
/**
|
|
50
|
+
* Creates a Point from a plain object without Zod validation.
|
|
51
|
+
* This method is optimized for performance and skips validation, making it suitable
|
|
52
|
+
* for deserializing trusted data (e.g., from C++ via MessagePack).
|
|
53
|
+
* Handles buffers, existing instances, or objects with x, y, and isInfinite fields.
|
|
54
|
+
* @param obj - Plain object, buffer, or Point instance
|
|
55
|
+
* @returns A Point instance
|
|
56
|
+
*/
|
|
57
|
+
static fromPlainObject(obj: any): Point {
|
|
58
|
+
if (obj instanceof Point) {
|
|
59
|
+
return obj;
|
|
60
|
+
}
|
|
61
|
+
if (obj instanceof Buffer || Buffer.isBuffer(obj)) {
|
|
62
|
+
return Point.fromBuffer(obj);
|
|
63
|
+
}
|
|
64
|
+
return new Point(Fr.fromPlainObject(obj.x), Fr.fromPlainObject(obj.y), obj.isInfinite ?? false);
|
|
65
|
+
}
|
|
66
|
+
|
|
48
67
|
/**
|
|
49
68
|
* Generate a random Point instance.
|
|
50
69
|
*
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// Reexport all folders at the root for packages targeting CommonJS
|
|
2
2
|
export * as asyncMap from './async-map/index.js';
|
|
3
|
+
export * as brandedTypes from './branded-types/index.js';
|
|
3
4
|
export * as bigintBuffer from './bigint-buffer/index.js';
|
|
4
5
|
export * as collection from './collection/index.js';
|
|
5
6
|
export * as committable from './committable/index.js';
|
package/src/schemas/schemas.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
|
|
3
|
+
import { EpochNumber, EpochNumberSchema } from '../branded-types/epoch.js';
|
|
4
|
+
import { SlotNumber, SlotNumberSchema } from '../branded-types/slot.js';
|
|
3
5
|
import { Buffer32 } from '../buffer/buffer32.js';
|
|
4
6
|
import { SecretValue } from '../config/secret_value.js';
|
|
5
7
|
import { EthAddress } from '../eth-address/index.js';
|
|
@@ -9,6 +11,12 @@ import { isHex, withoutHexPrefix } from '../string/index.js';
|
|
|
9
11
|
import { bufferSchema, hexSchema } from './utils.js';
|
|
10
12
|
|
|
11
13
|
export const schemas = {
|
|
14
|
+
/** Accepts a number, bigint, or string as an EpochNumber. */
|
|
15
|
+
EpochNumber: EpochNumberSchema,
|
|
16
|
+
|
|
17
|
+
/** Accepts a number, bigint, or string as a SlotNumber. */
|
|
18
|
+
SlotNumber: SlotNumberSchema,
|
|
19
|
+
|
|
12
20
|
/** Accepts a hex string. */
|
|
13
21
|
EthAddress: EthAddress.schema,
|
|
14
22
|
|
|
@@ -54,15 +62,7 @@ export const schemas = {
|
|
|
54
62
|
Buffer32: z.string().refine(isHex, 'Not a valid hex string').transform(Buffer32.fromString),
|
|
55
63
|
|
|
56
64
|
/** Accepts a base64 string or an object `{ type: 'Buffer', data: [byte, byte...] }` as a buffer. */
|
|
57
|
-
Buffer:
|
|
58
|
-
bufferSchema,
|
|
59
|
-
z
|
|
60
|
-
.object({
|
|
61
|
-
type: z.literal('Buffer'),
|
|
62
|
-
data: z.array(z.number().int().min(0).max(255)),
|
|
63
|
-
})
|
|
64
|
-
.transform(({ data }) => Buffer.from(data)),
|
|
65
|
-
]),
|
|
65
|
+
Buffer: bufferSchema,
|
|
66
66
|
|
|
67
67
|
/** Accepts a hex string as a buffer. */
|
|
68
68
|
BufferHex: z
|
|
@@ -79,4 +79,4 @@ export const schemas = {
|
|
|
79
79
|
};
|
|
80
80
|
|
|
81
81
|
// These are needed to avoid errors such as: "The inferred type of 'YourClassSchema' cannot be named without a reference to..."
|
|
82
|
-
export type { EthAddress, Fq, Fr, Point };
|
|
82
|
+
export type { EpochNumber, EthAddress, Fq, Fr, Point, SlotNumber };
|
package/src/schemas/utils.ts
CHANGED
|
@@ -21,13 +21,25 @@ export const hexSchema = z.string().refine(isHex, 'Not a valid hex string').tran
|
|
|
21
21
|
// Copied from zod internals, which was copied from https://stackoverflow.com/questions/7860392/determine-if-string-is-in-base64-using-javascript
|
|
22
22
|
const base64Regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;
|
|
23
23
|
|
|
24
|
-
/** Schema for a buffer represented as a base64 string. */
|
|
25
|
-
export const bufferSchema = z
|
|
26
|
-
.
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
24
|
+
/** Schema for a buffer represented as a base64 string or a Buffer object. */
|
|
25
|
+
export const bufferSchema: ZodFor<Buffer> = z.union([
|
|
26
|
+
// Serialization from base64 string.
|
|
27
|
+
z
|
|
28
|
+
.string()
|
|
29
|
+
// We only test the str for base64 if it's shorter than 1024 bytes, otherwise we've run into maximum
|
|
30
|
+
// stack size exceeded errors when trying to validate excessively long strings (such as contract bytecode).
|
|
31
|
+
.refine(str => str.length > 1024 || base64Regex.test(str), 'Not a valid base64 string')
|
|
32
|
+
.transform(data => Buffer.from(data, 'base64')),
|
|
33
|
+
// Serialization from Buffer-annotated object.
|
|
34
|
+
z
|
|
35
|
+
.object({
|
|
36
|
+
type: z.literal('Buffer'),
|
|
37
|
+
data: z.array(z.number().int().min(0).max(255)),
|
|
38
|
+
})
|
|
39
|
+
.transform(({ data }) => Buffer.from(data)),
|
|
40
|
+
// Serialization from Buffer
|
|
41
|
+
z.instanceof(Buffer),
|
|
42
|
+
]);
|
|
31
43
|
|
|
32
44
|
export class ZodNullableOptional<T extends ZodTypeAny> extends ZodOptional<T> {
|
|
33
45
|
_isNullableOptional = true;
|
|
@@ -88,12 +100,13 @@ export function hexSchemaFor<TClass extends { fromString(str: string): any } | {
|
|
|
88
100
|
*/
|
|
89
101
|
export function bufferSchemaFor<TClass extends { fromBuffer(buf: Buffer): any }>(
|
|
90
102
|
klazz: TClass,
|
|
103
|
+
refinement?: (buf: Buffer) => boolean,
|
|
91
104
|
): ZodType<
|
|
92
105
|
TClass extends { fromBuffer(buf: Buffer): infer TInstance } ? ToJsonIs<TInstance, Buffer> : never,
|
|
93
106
|
any,
|
|
94
107
|
string
|
|
95
108
|
> {
|
|
96
|
-
return bufferSchema.transform(klazz.fromBuffer.bind(klazz));
|
|
109
|
+
return bufferSchema.refine(refinement ?? (() => true), 'Not a valid buffer').transform(klazz.fromBuffer.bind(klazz));
|
|
97
110
|
}
|
|
98
111
|
|
|
99
112
|
/** Creates a schema for a js Map type that matches the serialization used in jsonStringify. */
|
|
@@ -63,7 +63,7 @@ export function updateProtocolCircuitSampleInputs(circuitName: string, value: st
|
|
|
63
63
|
logger(`Updated test data in ${targetFile} for ${circuitName}`);
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
function getPathToFile(targetFileFromRepoRoot: string) {
|
|
66
|
+
export function getPathToFile(targetFileFromRepoRoot: string) {
|
|
67
67
|
const repoRoot = resolve(dirname(fileURLToPath(import.meta.url)), '../../../../../');
|
|
68
68
|
if (!existsSync(join(repoRoot, 'CODEOWNERS'))) {
|
|
69
69
|
throw new Error(`Path to repo root is incorrect (got ${repoRoot})`);
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { pedersenHash as pedersenHashArray, poseidon2Hash, sha256Trunc } from '@aztec/foundation/crypto';
|
|
2
|
+
|
|
3
|
+
import type { AsyncHasher, Hasher } from './hasher.js';
|
|
4
|
+
|
|
5
|
+
export const shaMerkleHash: Hasher['hash'] = (left: Buffer, right: Buffer) =>
|
|
6
|
+
sha256Trunc(Buffer.concat([left, right])) as Buffer<ArrayBuffer>;
|
|
7
|
+
|
|
8
|
+
export const pedersenMerkleHash: AsyncHasher['hash'] = async (left: Buffer, right: Buffer) =>
|
|
9
|
+
(await pedersenHashArray([left, right])).toBuffer() as Buffer<ArrayBuffer>;
|
|
10
|
+
|
|
11
|
+
export const poseidonMerkleHash: AsyncHasher['hash'] = async (left: Buffer, right: Buffer) =>
|
|
12
|
+
(await poseidon2Hash([left, right])).toBuffer() as Buffer<ArrayBuffer>;
|
|
13
|
+
|
|
14
|
+
export const computeBalancedShaRoot = (leaves: Buffer[]) => computeBalancedMerkleTreeRoot(leaves);
|
|
15
|
+
|
|
16
|
+
export const computeBalancedPedersenRoot = async (leaves: Buffer[]) =>
|
|
17
|
+
await computeBalancedMerkleTreeRootAsync(leaves, pedersenMerkleHash);
|
|
18
|
+
|
|
19
|
+
export const computeBalancedPoseidonRoot = async (leaves: Buffer[]) =>
|
|
20
|
+
await computeBalancedMerkleTreeRootAsync(leaves, poseidonMerkleHash);
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Computes the Merkle root with the provided leaves **synchronously**.
|
|
24
|
+
* This method uses a synchronous hash function (defaults to `sha256Trunc`).
|
|
25
|
+
*
|
|
26
|
+
* @throws If the number of leaves is not a power of two.
|
|
27
|
+
*/
|
|
28
|
+
export function computeBalancedMerkleTreeRoot(leaves: Buffer[], hasher = shaMerkleHash): Buffer {
|
|
29
|
+
const height = getTreeHeight(leaves);
|
|
30
|
+
let nodes = leaves.slice();
|
|
31
|
+
|
|
32
|
+
for (let i = 0; i < height; ++i) {
|
|
33
|
+
let j = 0;
|
|
34
|
+
for (; j < nodes.length / 2; ++j) {
|
|
35
|
+
const l = nodes[j * 2];
|
|
36
|
+
const r = nodes[j * 2 + 1];
|
|
37
|
+
nodes[j] = hasher(l, r);
|
|
38
|
+
}
|
|
39
|
+
nodes = nodes.slice(0, j);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return nodes[0];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Computes the Merkle root with the provided leaves **asynchronously**.
|
|
47
|
+
* This method uses an asynchronous hash function (defaults to `pedersenHash`).
|
|
48
|
+
*
|
|
49
|
+
* @throws If the number of leaves is not a power of two.
|
|
50
|
+
*/
|
|
51
|
+
export async function computeBalancedMerkleTreeRootAsync(
|
|
52
|
+
leaves: Buffer[],
|
|
53
|
+
hasher = poseidonMerkleHash,
|
|
54
|
+
): Promise<Buffer> {
|
|
55
|
+
const height = getTreeHeight(leaves);
|
|
56
|
+
let nodes = leaves.slice();
|
|
57
|
+
|
|
58
|
+
for (let i = 0; i < height; ++i) {
|
|
59
|
+
let j = 0;
|
|
60
|
+
for (; j < nodes.length / 2; ++j) {
|
|
61
|
+
const l = nodes[j * 2];
|
|
62
|
+
const r = nodes[j * 2 + 1];
|
|
63
|
+
nodes[j] = await hasher(l, r);
|
|
64
|
+
}
|
|
65
|
+
nodes = nodes.slice(0, j);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return nodes[0];
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function getTreeHeight(leaves: Buffer[]) {
|
|
72
|
+
if (leaves.length === 0) {
|
|
73
|
+
throw new Error('Cannot compute a Merkle root with no leaves');
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const height = Math.log2(leaves.length);
|
|
77
|
+
if (!Number.isInteger(height)) {
|
|
78
|
+
throw new Error('Cannot compute a Merkle root with a non-power-of-two number of leaves');
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return height;
|
|
82
|
+
}
|
package/src/trees/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { pedersenHash
|
|
1
|
+
import { pedersenHash } from '@aztec/foundation/crypto';
|
|
2
2
|
|
|
3
3
|
import type { AsyncHasher } from './hasher.js';
|
|
4
4
|
import { MerkleTree } from './merkle_tree.js';
|
|
@@ -69,37 +69,4 @@ export class MerkleTreeCalculator {
|
|
|
69
69
|
|
|
70
70
|
return leaves[0];
|
|
71
71
|
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Computes the Merkle root with the provided leaves **synchronously**.
|
|
75
|
-
*
|
|
76
|
-
* This method uses a synchronous hash function (defaults to `sha256Trunc`) and **does not** allow for padding.
|
|
77
|
-
* If the number of leaves is not a power of two, it throws an error.
|
|
78
|
-
* This contrasts with the above non-static async method `computeTreeRoot`, which can handle any number of leaves by
|
|
79
|
-
* padding with zero hashes.
|
|
80
|
-
*/
|
|
81
|
-
static computeTreeRootSync(leaves: Buffer[], hasher = sha256Trunc): Buffer {
|
|
82
|
-
if (leaves.length === 0) {
|
|
83
|
-
throw new Error('Cannot compute a Merkle root with no leaves');
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
const height = Math.log2(leaves.length);
|
|
87
|
-
if (!Number.isInteger(height)) {
|
|
88
|
-
throw new Error('Cannot compute a Merkle root with a non-power-of-two number of leaves');
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
let nodes = leaves.slice();
|
|
92
|
-
|
|
93
|
-
for (let i = 0; i < height; ++i) {
|
|
94
|
-
let j = 0;
|
|
95
|
-
for (; j < nodes.length / 2; ++j) {
|
|
96
|
-
const l = nodes[j * 2];
|
|
97
|
-
const r = nodes[j * 2 + 1];
|
|
98
|
-
nodes[j] = hasher(Buffer.concat([l, r]));
|
|
99
|
-
}
|
|
100
|
-
nodes = nodes.slice(0, j);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
return nodes[0];
|
|
104
|
-
}
|
|
105
72
|
}
|