@aztec/foundation 4.0.0-nightly.20250907 → 4.0.0-nightly.20260107
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 +2 -1
- package/dest/array/index.d.ts.map +1 -1
- package/dest/array/index.js +1 -0
- package/dest/array/sorted_array.d.ts +10 -0
- package/dest/array/sorted_array.d.ts.map +1 -0
- package/dest/array/sorted_array.js +106 -0
- package/dest/async-map/index.d.ts +1 -1
- package/dest/async-pool/index.d.ts +1 -1
- package/dest/bigint/index.d.ts +1 -1
- package/dest/bigint-buffer/index.d.ts +1 -1
- package/dest/branded-types/block_number.d.ts +53 -0
- package/dest/branded-types/block_number.d.ts.map +1 -0
- package/dest/branded-types/block_number.js +75 -0
- package/dest/branded-types/checkpoint_number.d.ts +46 -0
- package/dest/branded-types/checkpoint_number.d.ts.map +1 -0
- package/dest/branded-types/checkpoint_number.js +68 -0
- package/dest/branded-types/epoch.d.ts +42 -0
- package/dest/branded-types/epoch.d.ts.map +1 -0
- package/dest/branded-types/epoch.js +59 -0
- package/dest/branded-types/index.d.ts +6 -0
- package/dest/branded-types/index.d.ts.map +1 -0
- package/dest/branded-types/index.js +4 -0
- package/dest/branded-types/slot.d.ts +42 -0
- package/dest/branded-types/slot.d.ts.map +1 -0
- package/dest/branded-types/slot.js +59 -0
- package/dest/branded-types/types.d.ts +5 -0
- package/dest/branded-types/types.d.ts.map +1 -0
- package/dest/branded-types/types.js +1 -0
- package/dest/buffer/buffer16.d.ts +2 -5
- package/dest/buffer/buffer16.d.ts.map +1 -1
- package/dest/buffer/buffer16.js +4 -2
- package/dest/buffer/buffer32.d.ts +2 -5
- package/dest/buffer/buffer32.d.ts.map +1 -1
- package/dest/buffer/buffer32.js +4 -2
- package/dest/buffer/index.d.ts +1 -1
- package/dest/collection/array.d.ts +3 -1
- package/dest/collection/array.d.ts.map +1 -1
- package/dest/collection/array.js +12 -3
- package/dest/collection/index.d.ts +1 -1
- package/dest/collection/object.d.ts +5 -1
- package/dest/collection/object.d.ts.map +1 -1
- package/dest/collection/object.js +6 -0
- package/dest/committable/committable.d.ts +1 -1
- package/dest/committable/committable.d.ts.map +1 -1
- package/dest/committable/index.d.ts +1 -1
- package/dest/config/env_var.d.ts +2 -2
- package/dest/config/env_var.d.ts.map +1 -1
- package/dest/config/index.d.ts +12 -2
- package/dest/config/index.d.ts.map +1 -1
- package/dest/config/index.js +17 -2
- package/dest/config/network_config.d.ts +54 -0
- package/dest/config/network_config.d.ts.map +1 -0
- package/dest/config/network_config.js +11 -0
- package/dest/config/network_name.d.ts +2 -2
- package/dest/config/network_name.d.ts.map +1 -1
- package/dest/config/network_name.js +10 -2
- package/dest/config/secret_value.d.ts +1 -1
- package/dest/config/secret_value.d.ts.map +1 -1
- package/dest/config/secret_value.js +3 -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 +19 -6
- package/dest/crypto/bls/bn254_keystore.d.ts +296 -0
- package/dest/crypto/bls/bn254_keystore.d.ts.map +1 -0
- package/dest/crypto/bls/bn254_keystore.js +218 -0
- package/dest/crypto/bls/index.d.ts +13 -0
- package/dest/crypto/bls/index.d.ts.map +1 -0
- package/dest/crypto/bls/index.js +87 -0
- package/dest/crypto/bn254/index.d.ts +39 -0
- package/dest/crypto/bn254/index.d.ts.map +1 -0
- package/dest/crypto/bn254/index.js +56 -0
- package/dest/crypto/ecdsa/index.d.ts +1 -1
- package/dest/crypto/ecdsa/index.d.ts.map +1 -1
- package/dest/crypto/ecdsa/index.js +58 -48
- package/dest/crypto/ecdsa/signature.d.ts +2 -11
- package/dest/crypto/ecdsa/signature.d.ts.map +1 -1
- package/dest/crypto/ecdsa/signature.js +2 -2
- package/dest/crypto/grumpkin/index.d.ts +10 -13
- package/dest/crypto/grumpkin/index.d.ts.map +1 -1
- package/dest/crypto/grumpkin/index.js +61 -55
- package/dest/crypto/keccak/index.d.ts +1 -1
- package/dest/crypto/keys/index.d.ts +2 -2
- package/dest/crypto/keys/index.d.ts.map +1 -1
- package/dest/crypto/keys/index.js +8 -5
- package/dest/crypto/pedersen/index.d.ts +1 -1
- package/dest/crypto/pedersen/pedersen.noble.d.ts +1 -1
- package/dest/crypto/pedersen/pedersen.wasm.d.ts +2 -2
- package/dest/crypto/pedersen/pedersen.wasm.d.ts.map +1 -1
- package/dest/crypto/pedersen/pedersen.wasm.js +24 -14
- package/dest/crypto/poseidon/index.d.ts +2 -2
- package/dest/crypto/poseidon/index.d.ts.map +1 -1
- package/dest/crypto/poseidon/index.js +33 -18
- package/dest/crypto/random/index.d.ts +1 -1
- package/dest/crypto/random/index.d.ts.map +1 -1
- package/dest/crypto/random/randomness_singleton.d.ts +1 -1
- package/dest/crypto/random/randomness_singleton.d.ts.map +1 -1
- package/dest/crypto/schnorr/index.d.ts +3 -2
- package/dest/crypto/schnorr/index.d.ts.map +1 -1
- package/dest/crypto/schnorr/index.js +30 -38
- package/dest/crypto/schnorr/signature.d.ts +2 -2
- package/dest/crypto/schnorr/signature.d.ts.map +1 -1
- package/dest/crypto/schnorr/signature.js +2 -2
- package/dest/crypto/secp256k1/index.d.ts +1 -1
- package/dest/crypto/secp256k1/index.d.ts.map +1 -1
- package/dest/crypto/secp256k1/index.js +23 -18
- package/dest/crypto/secp256k1-signer/index.d.ts +1 -1
- package/dest/crypto/secp256k1-signer/secp256k1_signer.d.ts +1 -1
- package/dest/crypto/secp256k1-signer/secp256k1_signer.d.ts.map +1 -1
- package/dest/crypto/secp256k1-signer/utils.d.ts +49 -3
- package/dest/crypto/secp256k1-signer/utils.d.ts.map +1 -1
- package/dest/crypto/secp256k1-signer/utils.js +87 -5
- package/dest/crypto/serialize.d.ts +1 -1
- package/dest/crypto/sha256/index.d.ts +2 -2
- package/dest/crypto/sha256/index.d.ts.map +1 -1
- package/dest/crypto/sha256/index.js +1 -1
- package/dest/crypto/sha512/index.d.ts +3 -3
- package/dest/crypto/sha512/index.d.ts.map +1 -1
- package/dest/crypto/sha512/index.js +1 -1
- package/dest/crypto/signature/index.d.ts +2 -2
- package/dest/crypto/signature/index.d.ts.map +1 -1
- package/dest/crypto/sync/index.d.ts +1 -1
- package/dest/crypto/sync/index.js +1 -1
- package/dest/crypto/sync/pedersen/index.d.ts +2 -2
- package/dest/crypto/sync/pedersen/index.d.ts.map +1 -1
- package/dest/crypto/sync/pedersen/index.js +18 -11
- package/dest/crypto/sync/poseidon/index.d.ts +2 -2
- package/dest/crypto/sync/poseidon/index.d.ts.map +1 -1
- package/dest/crypto/sync/poseidon/index.js +28 -13
- package/dest/{fields/bls12_fields.d.ts → curves/bls12/field.d.ts} +3 -3
- package/dest/curves/bls12/field.d.ts.map +1 -0
- package/dest/{fields/bls12_fields.js → curves/bls12/field.js} +12 -9
- package/dest/curves/bls12/index.d.ts +3 -0
- package/dest/curves/bls12/index.d.ts.map +1 -0
- package/dest/curves/bls12/index.js +2 -0
- package/dest/{fields/bls12_point.d.ts → curves/bls12/point.d.ts} +11 -20
- package/dest/curves/bls12/point.d.ts.map +1 -0
- package/dest/{fields/bls12_point.js → curves/bls12/point.js} +17 -15
- package/dest/curves/bn254/field.d.ts +180 -0
- package/dest/curves/bn254/field.d.ts.map +1 -0
- package/dest/{fields/fields.js → curves/bn254/field.js} +71 -59
- package/dest/curves/bn254/index.d.ts +3 -0
- package/dest/curves/bn254/index.d.ts.map +1 -0
- package/dest/curves/bn254/index.js +2 -0
- package/dest/curves/bn254/point.d.ts +54 -0
- package/dest/curves/bn254/point.d.ts.map +1 -0
- package/dest/curves/bn254/point.js +143 -0
- package/dest/curves/grumpkin/index.d.ts +10 -0
- package/dest/curves/grumpkin/index.d.ts.map +1 -0
- package/dest/curves/grumpkin/index.js +3 -0
- package/dest/{fields → curves/grumpkin}/point.d.ts +13 -13
- package/dest/curves/grumpkin/point.d.ts.map +1 -0
- package/dest/{fields → curves/grumpkin}/point.js +24 -7
- package/dest/decorators/index.d.ts +1 -1
- package/dest/decorators/memoize.d.ts +1 -1
- package/dest/decorators/memoize.d.ts.map +1 -1
- package/dest/error/index.d.ts +4 -4
- package/dest/error/index.d.ts.map +1 -1
- package/dest/eth-address/index.d.ts +14 -4
- package/dest/eth-address/index.d.ts.map +1 -1
- package/dest/eth-address/index.js +26 -2
- 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/eth_signature.js +2 -4
- package/dest/eth-signature/index.d.ts +1 -1
- package/dest/fs/index.d.ts +1 -1
- package/dest/fs/run_in_dir.d.ts +1 -1
- package/dest/fs/try_rm_dir.d.ts +1 -1
- package/dest/iterable/all.d.ts +1 -1
- package/dest/iterable/filter.d.ts +1 -1
- package/dest/iterable/index.d.ts +1 -1
- package/dest/iterable/isAsyncIt.d.ts +1 -1
- package/dest/iterable/map.d.ts +1 -1
- package/dest/iterable/peek.d.ts +1 -1
- package/dest/iterable/sort.d.ts +1 -1
- package/dest/iterable/take.d.ts +1 -1
- package/dest/iterable/toArray.d.ts +1 -1
- package/dest/iterator/filter.d.ts +3 -0
- package/dest/iterator/filter.d.ts.map +1 -0
- package/dest/iterator/filter.js +7 -0
- package/dest/iterator/index.d.ts +2 -0
- package/dest/iterator/index.d.ts.map +1 -0
- package/dest/iterator/index.js +1 -0
- 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/safe_json_rpc_client.d.ts.map +1 -1
- package/dest/json-rpc/client/safe_json_rpc_client.js +9 -0
- 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/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 +2 -2
- package/dest/log/log_fn.d.ts.map +1 -1
- package/dest/log/noir_debug_log_util.d.ts +1 -1
- 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 +0 -1
- 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 +2 -0
- package/dest/profiler/index.d.ts.map +1 -0
- package/dest/profiler/index.js +1 -0
- package/dest/profiler/profiler.d.ts +8 -0
- package/dest/profiler/profiler.d.ts.map +1 -0
- package/dest/profiler/profiler.js +97 -0
- package/dest/promise/index.d.ts +1 -1
- package/dest/promise/running-promise.d.ts +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 +15 -17
- package/dest/schemas/schemas.d.ts.map +1 -1
- package/dest/schemas/schemas.js +14 -10
- package/dest/schemas/types.d.ts +31 -1
- package/dest/schemas/types.d.ts.map +1 -1
- package/dest/schemas/types.js +25 -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 +3 -1
- package/dest/serialize/buffer_reader.d.ts.map +1 -1
- package/dest/serialize/buffer_reader.js +3 -0
- package/dest/serialize/field_reader.d.ts +2 -2
- package/dest/serialize/field_reader.d.ts.map +1 -1
- package/dest/serialize/field_reader.js +1 -1
- package/dest/serialize/free_funcs.d.ts +2 -2
- package/dest/serialize/free_funcs.d.ts.map +1 -1
- package/dest/serialize/free_funcs.js +1 -1
- package/dest/serialize/index.d.ts +1 -1
- package/dest/serialize/serialize.d.ts +2 -2
- package/dest/serialize/serialize.d.ts.map +1 -1
- package/dest/serialize/serialize.js +1 -1
- package/dest/serialize/type_registry.d.ts +1 -1
- package/dest/serialize/type_registry.d.ts.map +1 -1
- package/dest/serialize/types.d.ts +1 -1
- package/dest/sleep/index.d.ts +3 -1
- package/dest/sleep/index.d.ts.map +1 -1
- package/dest/sleep/index.js +4 -0
- package/dest/string/index.d.ts +5 -1
- package/dest/string/index.d.ts.map +1 -1
- package/dest/string/index.js +19 -2
- 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 +4 -0
- package/dest/testing/formatting.d.ts.map +1 -0
- package/dest/testing/formatting.js +3 -0
- package/dest/testing/index.d.ts +2 -1
- package/dest/testing/index.d.ts.map +1 -1
- package/dest/testing/index.js +1 -0
- package/dest/testing/port_allocator.d.ts +1 -1
- package/dest/testing/snapshot_serializer.d.ts +1 -1
- package/dest/testing/test_data.d.ts +1 -1
- package/dest/timer/date.d.ts +2 -1
- package/dest/timer/date.d.ts.map +1 -1
- package/dest/timer/date.js +3 -0
- package/dest/timer/elapsed.d.ts +1 -1
- package/dest/timer/index.d.ts +1 -1
- package/dest/timer/timeout.d.ts +1 -1
- package/dest/timer/timeout.d.ts.map +1 -1
- package/dest/timer/timer.d.ts +1 -1
- package/dest/timer/timer.d.ts.map +1 -1
- package/dest/transport/dispatch/create_dispatch_fn.d.ts +1 -1
- package/dest/transport/dispatch/create_dispatch_fn.d.ts.map +1 -1
- package/dest/transport/dispatch/create_dispatch_proxy.d.ts +1 -1
- package/dest/transport/dispatch/messages.d.ts +1 -1
- package/dest/transport/index.d.ts +1 -1
- package/dest/transport/interface/connector.d.ts +1 -1
- package/dest/transport/interface/listener.d.ts +1 -1
- package/dest/transport/interface/socket.d.ts +1 -1
- package/dest/transport/interface/transferable.d.ts +1 -1
- package/dest/transport/node/index.d.ts +1 -1
- package/dest/transport/node/node_connector.d.ts +1 -1
- package/dest/transport/node/node_connector.d.ts.map +1 -1
- package/dest/transport/node/node_connector_socket.d.ts +1 -1
- package/dest/transport/node/node_connector_socket.d.ts.map +1 -1
- package/dest/transport/node/node_listener.d.ts +1 -1
- package/dest/transport/node/node_listener.d.ts.map +1 -1
- package/dest/transport/node/node_listener_socket.d.ts +1 -1
- package/dest/transport/node/node_listener_socket.d.ts.map +1 -1
- package/dest/transport/transport_client.d.ts +1 -1
- package/dest/transport/transport_client.d.ts.map +1 -1
- package/dest/transport/transport_server.d.ts +1 -10
- package/dest/transport/transport_server.d.ts.map +1 -1
- package/dest/trees/balanced_merkle_tree.d.ts +22 -0
- package/dest/trees/balanced_merkle_tree.d.ts.map +1 -0
- package/dest/trees/balanced_merkle_tree.js +66 -0
- package/dest/trees/hasher.d.ts +1 -1
- package/dest/trees/index.d.ts +2 -1
- package/dest/trees/index.d.ts.map +1 -1
- package/dest/trees/index.js +1 -0
- package/dest/trees/indexed_merkle_tree.d.ts +1 -1
- package/dest/trees/indexed_merkle_tree.d.ts.map +1 -1
- package/dest/trees/indexed_merkle_tree.js +1 -1
- package/dest/trees/indexed_merkle_tree_calculator.d.ts +1 -1
- package/dest/trees/indexed_merkle_tree_calculator.d.ts.map +1 -1
- package/dest/trees/indexed_tree_leaf.d.ts +1 -1
- package/dest/trees/membership_witness.d.ts +3 -24
- package/dest/trees/membership_witness.d.ts.map +1 -1
- package/dest/trees/membership_witness.js +1 -1
- package/dest/trees/merkle_tree.d.ts +1 -1
- package/dest/trees/merkle_tree.d.ts.map +1 -1
- package/dest/trees/merkle_tree_calculator.d.ts +2 -12
- package/dest/trees/merkle_tree_calculator.d.ts.map +1 -1
- package/dest/trees/merkle_tree_calculator.js +1 -31
- package/dest/trees/sibling_path.d.ts +5 -39
- package/dest/trees/sibling_path.d.ts.map +1 -1
- package/dest/trees/sibling_path.js +2 -2
- package/dest/trees/unbalanced_merkle_tree.d.ts +5 -4
- package/dest/trees/unbalanced_merkle_tree.d.ts.map +1 -1
- package/dest/trees/unbalanced_merkle_tree.js +33 -10
- package/dest/trees/unbalanced_merkle_tree_calculator.d.ts +27 -23
- package/dest/trees/unbalanced_merkle_tree_calculator.d.ts.map +1 -1
- package/dest/trees/unbalanced_merkle_tree_calculator.js +123 -97
- package/dest/trees/unbalanced_tree_store.d.ts +2 -1
- package/dest/trees/unbalanced_tree_store.d.ts.map +1 -1
- package/dest/trees/unbalanced_tree_store.js +6 -0
- package/dest/types/index.d.ts +3 -1
- package/dest/types/index.d.ts.map +1 -1
- package/dest/types/index.js +3 -0
- package/dest/url/index.d.ts +1 -1
- package/dest/validation/index.d.ts +1 -1
- package/package.json +32 -8
- package/src/array/array.ts +0 -16
- package/src/array/index.ts +1 -0
- package/src/array/sorted_array.ts +133 -0
- package/src/branded-types/block_number.ts +112 -0
- package/src/branded-types/checkpoint_number.ts +100 -0
- package/src/branded-types/epoch.ts +88 -0
- package/src/branded-types/index.ts +6 -0
- package/src/branded-types/slot.ts +88 -0
- package/src/branded-types/types.ts +2 -0
- package/src/buffer/buffer16.ts +2 -2
- package/src/buffer/buffer32.ts +2 -2
- package/src/collection/array.ts +15 -3
- package/src/collection/object.ts +8 -0
- package/src/config/env_var.ts +44 -10
- package/src/config/index.ts +22 -2
- package/src/config/network_config.ts +18 -0
- package/src/config/network_name.ts +18 -3
- 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/index.ts +64 -0
- package/src/crypto/ecdsa/index.ts +40 -37
- package/src/crypto/ecdsa/signature.ts +2 -2
- package/src/crypto/grumpkin/index.ts +38 -46
- package/src/crypto/keys/index.ts +6 -6
- package/src/crypto/pedersen/pedersen.wasm.ts +23 -19
- package/src/crypto/poseidon/index.ts +33 -25
- package/src/crypto/schnorr/index.ts +22 -18
- package/src/crypto/schnorr/signature.ts +2 -2
- package/src/crypto/secp256k1/index.ts +15 -11
- package/src/crypto/secp256k1-signer/utils.ts +115 -7
- package/src/crypto/sha256/index.ts +1 -1
- package/src/crypto/sha512/index.ts +1 -1
- package/src/crypto/signature/index.ts +1 -1
- package/src/crypto/sync/index.ts +1 -1
- package/src/crypto/sync/pedersen/index.ts +17 -16
- package/src/crypto/sync/poseidon/index.ts +28 -23
- package/src/{fields/bls12_fields.ts → curves/bls12/field.ts} +6 -6
- package/src/curves/bls12/index.ts +2 -0
- package/src/{fields/bls12_point.ts → curves/bls12/point.ts} +14 -14
- package/src/{fields/fields.ts → curves/bn254/field.ts} +69 -62
- package/src/curves/bn254/index.ts +2 -0
- package/src/curves/bn254/point.ts +170 -0
- package/src/curves/grumpkin/index.ts +11 -0
- package/src/{fields → curves/grumpkin}/point.ts +26 -7
- package/src/eth-address/index.ts +28 -3
- package/src/eth-signature/eth_signature.ts +2 -4
- package/src/iterator/filter.ts +11 -0
- package/src/iterator/index.ts +1 -0
- package/src/json-rpc/client/safe_json_rpc_client.ts +9 -0
- package/src/log/log_fn.ts +1 -1
- package/src/log/pino-logger.ts +0 -1
- package/src/profiler/index.ts +1 -0
- package/src/profiler/profiler.ts +125 -0
- package/src/schemas/schemas.ts +24 -13
- package/src/schemas/types.ts +33 -0
- package/src/schemas/utils.ts +21 -8
- package/src/serialize/buffer_reader.ts +5 -0
- package/src/serialize/field_reader.ts +1 -1
- package/src/serialize/free_funcs.ts +1 -1
- package/src/serialize/serialize.ts +1 -1
- package/src/sleep/index.ts +6 -0
- package/src/string/index.ts +24 -1
- package/src/testing/files/index.ts +1 -1
- package/src/testing/formatting.ts +3 -0
- package/src/testing/index.ts +1 -0
- package/src/timer/date.ts +4 -0
- package/src/trees/balanced_merkle_tree.ts +84 -0
- package/src/trees/index.ts +1 -0
- package/src/trees/indexed_merkle_tree.ts +1 -1
- package/src/trees/membership_witness.ts +1 -1
- package/src/trees/merkle_tree_calculator.ts +1 -34
- package/src/trees/sibling_path.ts +2 -2
- package/src/trees/unbalanced_merkle_tree.ts +55 -7
- package/src/trees/unbalanced_merkle_tree_calculator.ts +134 -93
- package/src/trees/unbalanced_tree_store.ts +5 -1
- package/src/types/index.ts +5 -0
- package/dest/crypto/index.d.ts +0 -15
- package/dest/crypto/index.d.ts.map +0 -1
- package/dest/crypto/index.js +0 -14
- package/dest/fields/bls12_fields.d.ts.map +0 -1
- package/dest/fields/bls12_point.d.ts.map +0 -1
- package/dest/fields/coordinate.d.ts +0 -66
- package/dest/fields/coordinate.d.ts.map +0 -1
- package/dest/fields/coordinate.js +0 -96
- package/dest/fields/fields.d.ts +0 -174
- package/dest/fields/fields.d.ts.map +0 -1
- package/dest/fields/index.d.ts +0 -6
- package/dest/fields/index.d.ts.map +0 -1
- package/dest/fields/index.js +0 -5
- package/dest/fields/point.d.ts.map +0 -1
- package/dest/index.d.ts +0 -29
- package/dest/index.d.ts.map +0 -1
- package/dest/index.js +0 -29
- package/dest/json-rpc/server/telemetry.d.ts +0 -2
- package/dest/json-rpc/server/telemetry.d.ts.map +0 -1
- package/dest/json-rpc/server/telemetry.js +0 -0
- package/src/crypto/index.ts +0 -14
- package/src/fields/coordinate.ts +0 -104
- package/src/fields/index.ts +0 -5
- package/src/index.ts +0 -29
- package/src/json-rpc/server/telemetry.ts +0 -0
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export type NetworkNames = 'local' | '
|
|
1
|
+
export type NetworkNames = 'local' | 'staging-ignition' | 'staging-public' | 'testnet' | 'mainnet' | 'next-net' | 'devnet';
|
|
2
2
|
export declare function getActiveNetworkName(name?: string): NetworkNames;
|
|
3
|
-
//# sourceMappingURL=
|
|
3
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibmV0d29ya19uYW1lLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvY29uZmlnL25ldHdvcmtfbmFtZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxNQUFNLE1BQU0sWUFBWSxHQUNwQixPQUFPLEdBQ1Asa0JBQWtCLEdBQ2xCLGdCQUFnQixHQUNoQixTQUFTLEdBQ1QsU0FBUyxHQUNULFVBQVUsR0FDVixRQUFRLENBQUM7QUFFYix3QkFBZ0Isb0JBQW9CLENBQUMsSUFBSSxDQUFDLEVBQUUsTUFBTSxHQUFHLFlBQVksQ0FrQmhFIn0=
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"network_name.d.ts","sourceRoot":"","sources":["../../src/config/network_name.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,
|
|
1
|
+
{"version":3,"file":"network_name.d.ts","sourceRoot":"","sources":["../../src/config/network_name.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,GACpB,OAAO,GACP,kBAAkB,GAClB,gBAAgB,GAChB,SAAS,GACT,SAAS,GACT,UAAU,GACV,QAAQ,CAAC;AAEb,wBAAgB,oBAAoB,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,YAAY,CAkBhE"}
|
|
@@ -2,10 +2,18 @@ export function getActiveNetworkName(name) {
|
|
|
2
2
|
const network = name || process.env.NETWORK;
|
|
3
3
|
if (!network || network === '' || network === 'local') {
|
|
4
4
|
return 'local';
|
|
5
|
-
} else if (network === '
|
|
5
|
+
} else if (network === 'staging-ignition') {
|
|
6
6
|
return network;
|
|
7
|
-
} else if (network === '
|
|
7
|
+
} else if (network === 'staging-public') {
|
|
8
8
|
return network;
|
|
9
|
+
} else if (network === 'testnet' || network === 'alpha-testnet') {
|
|
10
|
+
return 'testnet';
|
|
11
|
+
} else if (network === 'mainnet') {
|
|
12
|
+
return 'mainnet';
|
|
13
|
+
} else if (network === 'next-net') {
|
|
14
|
+
return 'next-net';
|
|
15
|
+
} else if (network === 'devnet') {
|
|
16
|
+
return 'devnet';
|
|
9
17
|
}
|
|
10
18
|
throw new Error(`Unknown network: ${network}`);
|
|
11
19
|
}
|
|
@@ -25,4 +25,4 @@ export declare class SecretValue<T> {
|
|
|
25
25
|
*/
|
|
26
26
|
static schema<O>(valueSchema: ZodType<O, any, any>): ZodType<SecretValue<O>, any, any>;
|
|
27
27
|
}
|
|
28
|
-
//# sourceMappingURL=
|
|
28
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2VjcmV0X3ZhbHVlLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvY29uZmlnL3NlY3JldF92YWx1ZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUUsT0FBTyxFQUFFLE1BQU0sTUFBTSxDQUFDO0FBQy9CLE9BQU8sS0FBSyxFQUFFLE9BQU8sRUFBRSxNQUFNLEtBQUssQ0FBQztBQUVuQzs7R0FFRztBQUNILHFCQUFhLFdBQVcsQ0FBQyxDQUFDOztJQU10QixPQUFPLENBQUMsUUFBUSxDQUFDLGFBQWE7SUFGaEMsWUFDRSxLQUFLLEVBQUUsQ0FBQyxFQUNTLGFBQWEsU0FBZSxFQUc5QztJQUVEOztPQUVHO0lBQ0ksUUFBUSxJQUFJLENBQUMsQ0FFbkI7SUFFRDs7T0FFRztJQUNJLFFBQVEsSUFBSSxNQUFNLENBRXhCO0lBRUQ7O09BRUc7SUFDSSxNQUFNLElBQUksTUFBTSxDQUV0QjtJQUVNLENBQUMsT0FBTyxDQUFDLE1BQU0sQ0FBQyxXQUV0QjtJQUVEOztPQUVHO0lBQ0gsTUFBTSxDQUFDLE1BQU0sQ0FBQyxDQUFDLEVBQUUsV0FBVyxFQUFFLE9BQU8sQ0FBQyxDQUFDLEVBQUUsR0FBRyxFQUFFLEdBQUcsQ0FBQyxHQUFHLE9BQU8sQ0FBQyxXQUFXLENBQUMsQ0FBQyxDQUFDLEVBQUUsR0FBRyxFQUFFLEdBQUcsQ0FBQyxDQUVyRjtDQUNGIn0=
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"secret_value.d.ts","sourceRoot":"","sources":["../../src/config/secret_value.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAC/B,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AAEnC;;GAEG;AACH,qBAAa,WAAW,CAAC,CAAC;;IAMtB,OAAO,CAAC,QAAQ,CAAC,aAAa;
|
|
1
|
+
{"version":3,"file":"secret_value.d.ts","sourceRoot":"","sources":["../../src/config/secret_value.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAC/B,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AAEnC;;GAEG;AACH,qBAAa,WAAW,CAAC,CAAC;;IAMtB,OAAO,CAAC,QAAQ,CAAC,aAAa;IAFhC,YACE,KAAK,EAAE,CAAC,EACS,aAAa,SAAe,EAG9C;IAED;;OAEG;IACI,QAAQ,IAAI,CAAC,CAEnB;IAED;;OAEG;IACI,QAAQ,IAAI,MAAM,CAExB;IAED;;OAEG;IACI,MAAM,IAAI,MAAM,CAEtB;IAEM,CAAC,OAAO,CAAC,MAAM,CAAC,WAEtB;IAED;;OAEG;IACH,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,WAAW,EAAE,OAAO,CAAC,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC,CAErF;CACF"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
var _computedKey;
|
|
1
2
|
import { inspect } from 'util';
|
|
3
|
+
_computedKey = inspect.custom;
|
|
2
4
|
/**
|
|
3
5
|
* A class wrapping a secret value to protect it from accidently being leaked in logs
|
|
4
6
|
*/ export class SecretValue {
|
|
@@ -23,7 +25,7 @@ import { inspect } from 'util';
|
|
|
23
25
|
*/ toJSON() {
|
|
24
26
|
return this.redactedValue;
|
|
25
27
|
}
|
|
26
|
-
[
|
|
28
|
+
[_computedKey]() {
|
|
27
29
|
return this.toString();
|
|
28
30
|
}
|
|
29
31
|
/**
|
|
@@ -29,4 +29,4 @@ export declare class Aes128 {
|
|
|
29
29
|
*/
|
|
30
30
|
decryptBufferCBC(data: Uint8Array, iv: Uint8Array, key: Uint8Array): Promise<Buffer<ArrayBufferLike>>;
|
|
31
31
|
}
|
|
32
|
-
//# sourceMappingURL=
|
|
32
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9jcnlwdG8vYWVzMTI4L2luZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUVBLE9BQU8sRUFBRSxNQUFNLEVBQUUsTUFBTSxRQUFRLENBQUM7QUFFaEM7O0dBRUc7QUFDSCxxQkFBYSxNQUFNO0lBQ2pCOzs7Ozs7T0FNRztJQUNVLGdCQUFnQixDQUFDLElBQUksRUFBRSxVQUFVLEVBQUUsRUFBRSxFQUFFLFVBQVUsRUFBRSxHQUFHLEVBQUUsVUFBVSxnQ0FrQjlFO0lBRUQ7Ozs7Ozs7T0FPRztJQUNVLDJCQUEyQixDQUFDLElBQUksRUFBRSxVQUFVLEVBQUUsRUFBRSxFQUFFLFVBQVUsRUFBRSxHQUFHLEVBQUUsVUFBVSxHQUFHLE9BQU8sQ0FBQyxNQUFNLENBQUMsQ0FVM0c7SUFFRDs7Ozs7O09BTUc7SUFDVSxnQkFBZ0IsQ0FBQyxJQUFJLEVBQUUsVUFBVSxFQUFFLEVBQUUsRUFBRSxVQUFVLEVBQUUsR0FBRyxFQUFFLFVBQVUsb0NBSTlFO0NBQ0YifQ==
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/crypto/aes128/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC;;GAEG;AACH,qBAAa,MAAM;IACjB;;;;;;OAMG;IACU,gBAAgB,CAAC,IAAI,EAAE,UAAU,EAAE,EAAE,EAAE,UAAU,EAAE,GAAG,EAAE,UAAU;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/crypto/aes128/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC;;GAEG;AACH,qBAAa,MAAM;IACjB;;;;;;OAMG;IACU,gBAAgB,CAAC,IAAI,EAAE,UAAU,EAAE,EAAE,EAAE,UAAU,EAAE,GAAG,EAAE,UAAU,gCAkB9E;IAED;;;;;;;OAOG;IACU,2BAA2B,CAAC,IAAI,EAAE,UAAU,EAAE,EAAE,EAAE,UAAU,EAAE,GAAG,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,CAU3G;IAED;;;;;;OAMG;IACU,gBAAgB,CAAC,IAAI,EAAE,UAAU,EAAE,EAAE,EAAE,UAAU,EAAE,GAAG,EAAE,UAAU,oCAI9E;CACF"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BarretenbergSync
|
|
1
|
+
import { BarretenbergSync } from '@aztec/bb.js';
|
|
2
2
|
import { Buffer } from 'buffer';
|
|
3
3
|
/**
|
|
4
4
|
* AES-128-CBC encryption/decryption.
|
|
@@ -20,8 +20,15 @@ import { Buffer } from 'buffer';
|
|
|
20
20
|
data,
|
|
21
21
|
paddingBuffer
|
|
22
22
|
]);
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
await BarretenbergSync.initSingleton();
|
|
24
|
+
const api = BarretenbergSync.getSingleton();
|
|
25
|
+
const response = api.aesEncrypt({
|
|
26
|
+
plaintext: input,
|
|
27
|
+
iv,
|
|
28
|
+
key,
|
|
29
|
+
length: input.length
|
|
30
|
+
});
|
|
31
|
+
return Buffer.from(response.ciphertext);
|
|
25
32
|
}
|
|
26
33
|
/**
|
|
27
34
|
* Decrypt a buffer using AES-128-CBC.
|
|
@@ -31,9 +38,15 @@ import { Buffer } from 'buffer';
|
|
|
31
38
|
* @param key - Key to decrypt with.
|
|
32
39
|
* @returns Decrypted data.
|
|
33
40
|
*/ async decryptBufferCBCKeepPadding(data, iv, key) {
|
|
34
|
-
|
|
35
|
-
const
|
|
36
|
-
|
|
41
|
+
await BarretenbergSync.initSingleton();
|
|
42
|
+
const api = BarretenbergSync.getSingleton();
|
|
43
|
+
const response = api.aesDecrypt({
|
|
44
|
+
ciphertext: data,
|
|
45
|
+
iv,
|
|
46
|
+
key,
|
|
47
|
+
length: data.length
|
|
48
|
+
});
|
|
49
|
+
return Buffer.from(response.plaintext);
|
|
37
50
|
}
|
|
38
51
|
/**
|
|
39
52
|
* Decrypt a buffer using AES-128-CBC.
|
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* BN254 Keystore Format
|
|
4
|
+
*
|
|
5
|
+
* Implements encryption and decryption of keystores for BN254 BLS private keys
|
|
6
|
+
* using PBKDF2 and AES-128-CTR. This format is inspired by EIP-2335 but adapted
|
|
7
|
+
* for BN254 keys rather than BLS12-381.
|
|
8
|
+
*
|
|
9
|
+
* @see https://eips.ethereum.org/EIPS/eip-2335
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Zod schema for validating BN254 keystore structure
|
|
13
|
+
*/
|
|
14
|
+
declare const bn254KeystoreSchema: z.ZodObject<{
|
|
15
|
+
crypto: z.ZodObject<{
|
|
16
|
+
kdf: z.ZodObject<{
|
|
17
|
+
function: z.ZodLiteral<"pbkdf2">;
|
|
18
|
+
params: z.ZodObject<{
|
|
19
|
+
dklen: z.ZodNumber;
|
|
20
|
+
c: z.ZodNumber;
|
|
21
|
+
prf: z.ZodString;
|
|
22
|
+
salt: z.ZodString;
|
|
23
|
+
}, "strip", z.ZodTypeAny, {
|
|
24
|
+
dklen: number;
|
|
25
|
+
c: number;
|
|
26
|
+
prf: string;
|
|
27
|
+
salt: string;
|
|
28
|
+
}, {
|
|
29
|
+
dklen: number;
|
|
30
|
+
c: number;
|
|
31
|
+
prf: string;
|
|
32
|
+
salt: string;
|
|
33
|
+
}>;
|
|
34
|
+
message: z.ZodString;
|
|
35
|
+
}, "strip", z.ZodTypeAny, {
|
|
36
|
+
function: "pbkdf2";
|
|
37
|
+
params: {
|
|
38
|
+
dklen: number;
|
|
39
|
+
c: number;
|
|
40
|
+
prf: string;
|
|
41
|
+
salt: string;
|
|
42
|
+
};
|
|
43
|
+
message: string;
|
|
44
|
+
}, {
|
|
45
|
+
function: "pbkdf2";
|
|
46
|
+
params: {
|
|
47
|
+
dklen: number;
|
|
48
|
+
c: number;
|
|
49
|
+
prf: string;
|
|
50
|
+
salt: string;
|
|
51
|
+
};
|
|
52
|
+
message: string;
|
|
53
|
+
}>;
|
|
54
|
+
checksum: z.ZodObject<{
|
|
55
|
+
function: z.ZodLiteral<"sha256">;
|
|
56
|
+
params: z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>;
|
|
57
|
+
message: z.ZodString;
|
|
58
|
+
}, "strip", z.ZodTypeAny, {
|
|
59
|
+
function: "sha256";
|
|
60
|
+
params: {};
|
|
61
|
+
message: string;
|
|
62
|
+
}, {
|
|
63
|
+
function: "sha256";
|
|
64
|
+
params: {};
|
|
65
|
+
message: string;
|
|
66
|
+
}>;
|
|
67
|
+
cipher: z.ZodObject<{
|
|
68
|
+
function: z.ZodLiteral<"aes-128-ctr">;
|
|
69
|
+
params: z.ZodObject<{
|
|
70
|
+
iv: z.ZodString;
|
|
71
|
+
}, "strip", z.ZodTypeAny, {
|
|
72
|
+
iv: string;
|
|
73
|
+
}, {
|
|
74
|
+
iv: string;
|
|
75
|
+
}>;
|
|
76
|
+
message: z.ZodString;
|
|
77
|
+
}, "strip", z.ZodTypeAny, {
|
|
78
|
+
function: "aes-128-ctr";
|
|
79
|
+
params: {
|
|
80
|
+
iv: string;
|
|
81
|
+
};
|
|
82
|
+
message: string;
|
|
83
|
+
}, {
|
|
84
|
+
function: "aes-128-ctr";
|
|
85
|
+
params: {
|
|
86
|
+
iv: string;
|
|
87
|
+
};
|
|
88
|
+
message: string;
|
|
89
|
+
}>;
|
|
90
|
+
}, "strip", z.ZodTypeAny, {
|
|
91
|
+
kdf: {
|
|
92
|
+
function: "pbkdf2";
|
|
93
|
+
params: {
|
|
94
|
+
dklen: number;
|
|
95
|
+
c: number;
|
|
96
|
+
prf: string;
|
|
97
|
+
salt: string;
|
|
98
|
+
};
|
|
99
|
+
message: string;
|
|
100
|
+
};
|
|
101
|
+
checksum: {
|
|
102
|
+
function: "sha256";
|
|
103
|
+
params: {};
|
|
104
|
+
message: string;
|
|
105
|
+
};
|
|
106
|
+
cipher: {
|
|
107
|
+
function: "aes-128-ctr";
|
|
108
|
+
params: {
|
|
109
|
+
iv: string;
|
|
110
|
+
};
|
|
111
|
+
message: string;
|
|
112
|
+
};
|
|
113
|
+
}, {
|
|
114
|
+
kdf: {
|
|
115
|
+
function: "pbkdf2";
|
|
116
|
+
params: {
|
|
117
|
+
dklen: number;
|
|
118
|
+
c: number;
|
|
119
|
+
prf: string;
|
|
120
|
+
salt: string;
|
|
121
|
+
};
|
|
122
|
+
message: string;
|
|
123
|
+
};
|
|
124
|
+
checksum: {
|
|
125
|
+
function: "sha256";
|
|
126
|
+
params: {};
|
|
127
|
+
message: string;
|
|
128
|
+
};
|
|
129
|
+
cipher: {
|
|
130
|
+
function: "aes-128-ctr";
|
|
131
|
+
params: {
|
|
132
|
+
iv: string;
|
|
133
|
+
};
|
|
134
|
+
message: string;
|
|
135
|
+
};
|
|
136
|
+
}>;
|
|
137
|
+
description: z.ZodOptional<z.ZodString>;
|
|
138
|
+
pubkey: z.ZodString;
|
|
139
|
+
path: z.ZodString;
|
|
140
|
+
uuid: z.ZodString;
|
|
141
|
+
version: z.ZodNumber;
|
|
142
|
+
}, "strip", z.ZodTypeAny, {
|
|
143
|
+
crypto: {
|
|
144
|
+
kdf: {
|
|
145
|
+
function: "pbkdf2";
|
|
146
|
+
params: {
|
|
147
|
+
dklen: number;
|
|
148
|
+
c: number;
|
|
149
|
+
prf: string;
|
|
150
|
+
salt: string;
|
|
151
|
+
};
|
|
152
|
+
message: string;
|
|
153
|
+
};
|
|
154
|
+
checksum: {
|
|
155
|
+
function: "sha256";
|
|
156
|
+
params: {};
|
|
157
|
+
message: string;
|
|
158
|
+
};
|
|
159
|
+
cipher: {
|
|
160
|
+
function: "aes-128-ctr";
|
|
161
|
+
params: {
|
|
162
|
+
iv: string;
|
|
163
|
+
};
|
|
164
|
+
message: string;
|
|
165
|
+
};
|
|
166
|
+
};
|
|
167
|
+
description?: string | undefined;
|
|
168
|
+
pubkey: string;
|
|
169
|
+
path: string;
|
|
170
|
+
uuid: string;
|
|
171
|
+
version: number;
|
|
172
|
+
}, {
|
|
173
|
+
crypto: {
|
|
174
|
+
kdf: {
|
|
175
|
+
function: "pbkdf2";
|
|
176
|
+
params: {
|
|
177
|
+
dklen: number;
|
|
178
|
+
c: number;
|
|
179
|
+
prf: string;
|
|
180
|
+
salt: string;
|
|
181
|
+
};
|
|
182
|
+
message: string;
|
|
183
|
+
};
|
|
184
|
+
checksum: {
|
|
185
|
+
function: "sha256";
|
|
186
|
+
params: {};
|
|
187
|
+
message: string;
|
|
188
|
+
};
|
|
189
|
+
cipher: {
|
|
190
|
+
function: "aes-128-ctr";
|
|
191
|
+
params: {
|
|
192
|
+
iv: string;
|
|
193
|
+
};
|
|
194
|
+
message: string;
|
|
195
|
+
};
|
|
196
|
+
};
|
|
197
|
+
description?: string | undefined;
|
|
198
|
+
pubkey: string;
|
|
199
|
+
path: string;
|
|
200
|
+
uuid: string;
|
|
201
|
+
version: number;
|
|
202
|
+
}>;
|
|
203
|
+
/**
|
|
204
|
+
* Error thrown when BN254 keystore operations fail
|
|
205
|
+
*/
|
|
206
|
+
export declare class Bn254KeystoreError extends Error {
|
|
207
|
+
cause?: Error | undefined;
|
|
208
|
+
constructor(message: string, cause?: Error | undefined);
|
|
209
|
+
}
|
|
210
|
+
export type Bn254Keystore = z.infer<typeof bn254KeystoreSchema>;
|
|
211
|
+
/**
|
|
212
|
+
* The JSON structure of a BN254 keystore file.
|
|
213
|
+
* @deprecated Use the inferred type from bn254KeystoreSchema instead
|
|
214
|
+
*/
|
|
215
|
+
export interface Bn254KeystoreInterface {
|
|
216
|
+
crypto: {
|
|
217
|
+
kdf: {
|
|
218
|
+
function: 'pbkdf2';
|
|
219
|
+
params: {
|
|
220
|
+
dklen: number;
|
|
221
|
+
c: number;
|
|
222
|
+
prf: string;
|
|
223
|
+
salt: string;
|
|
224
|
+
};
|
|
225
|
+
message: string;
|
|
226
|
+
};
|
|
227
|
+
checksum: {
|
|
228
|
+
function: 'sha256';
|
|
229
|
+
params: Record<string, never>;
|
|
230
|
+
message: string;
|
|
231
|
+
};
|
|
232
|
+
cipher: {
|
|
233
|
+
function: 'aes-128-ctr';
|
|
234
|
+
params: {
|
|
235
|
+
iv: string;
|
|
236
|
+
};
|
|
237
|
+
message: string;
|
|
238
|
+
};
|
|
239
|
+
};
|
|
240
|
+
description: string;
|
|
241
|
+
pubkey: string;
|
|
242
|
+
path: string;
|
|
243
|
+
uuid: string;
|
|
244
|
+
version: number;
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Creates a BN254 keystore object for a BN254 BLS private key.
|
|
248
|
+
*
|
|
249
|
+
* Uses PBKDF2 with SHA-256 for key derivation and AES-128-CTR for encryption,
|
|
250
|
+
* following the EIP-2335 specification format.
|
|
251
|
+
*
|
|
252
|
+
* @param password - Password for encrypting the private key
|
|
253
|
+
* @param privateKeyHex - Private key as 0x-prefixed hex string (32 bytes)
|
|
254
|
+
* @param pubkeyHex - Public key as hex string (compressed or uncompressed)
|
|
255
|
+
* @param derivationPath - BIP-44 style derivation path (e.g., "m/12381/3600/0/0/0")
|
|
256
|
+
* @returns BN254 keystore object ready to be serialized to JSON
|
|
257
|
+
* @throws Error if private key is not 32-byte hex
|
|
258
|
+
*/
|
|
259
|
+
export declare function createBn254Keystore(password: string, privateKeyHex: string, pubkeyHex: string, derivationPath: string): Bn254Keystore;
|
|
260
|
+
/**
|
|
261
|
+
* Loads and validates a BN254 keystore file.
|
|
262
|
+
*
|
|
263
|
+
* @param filePath - Path to the BN254 keystore JSON file
|
|
264
|
+
* @returns Validated keystore object
|
|
265
|
+
* @throws Bn254KeystoreError if file cannot be read or validated
|
|
266
|
+
*/
|
|
267
|
+
export declare function loadBn254Keystore(filePath: string): Bn254Keystore;
|
|
268
|
+
/**
|
|
269
|
+
* Decrypts a BN254 BLS private key from a keystore file.
|
|
270
|
+
*
|
|
271
|
+
* @param filePath - Path to the BN254 keystore JSON file
|
|
272
|
+
* @param password - Password to decrypt the keystore
|
|
273
|
+
* @returns Decrypted private key as 0x-prefixed hex string (32 bytes)
|
|
274
|
+
* @throws Bn254KeystoreError if decryption fails or checksum is invalid
|
|
275
|
+
*/
|
|
276
|
+
export declare function decryptBn254Keystore(filePath: string, password: string): string;
|
|
277
|
+
/**
|
|
278
|
+
* Decrypts a BN254 BLS private key from a keystore object.
|
|
279
|
+
*
|
|
280
|
+
* @param keystore - BN254 keystore object
|
|
281
|
+
* @param password - Password to decrypt the keystore
|
|
282
|
+
* @returns Decrypted private key as 0x-prefixed hex string (32 bytes)
|
|
283
|
+
* @throws Bn254KeystoreError if decryption fails or checksum is invalid
|
|
284
|
+
*/
|
|
285
|
+
export declare function decryptBn254KeystoreFromObject(keystore: Bn254Keystore, password: string): string;
|
|
286
|
+
/**
|
|
287
|
+
* Validates that a decrypted private key matches the public key in the keystore.
|
|
288
|
+
*
|
|
289
|
+
* @param privateKeyHex - Decrypted private key (0x-prefixed)
|
|
290
|
+
* @param expectedPubkey - Expected public key from keystore
|
|
291
|
+
* @param computePublicKey - Function to compute public key from private key
|
|
292
|
+
* @returns true if keys match, false otherwise
|
|
293
|
+
*/
|
|
294
|
+
export declare function verifyBn254Keypair(privateKeyHex: string, expectedPubkey: string, computePublicKey: (privateKey: string) => string): boolean;
|
|
295
|
+
export {};
|
|
296
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYm4yNTRfa2V5c3RvcmUuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9jcnlwdG8vYmxzL2JuMjU0X2tleXN0b3JlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUlBLE9BQU8sRUFBRSxDQUFDLEVBQUUsTUFBTSxLQUFLLENBQUM7QUFFeEI7Ozs7Ozs7O0dBUUc7QUFFSDs7R0FFRztBQUNILFFBQUEsTUFBTSxtQkFBbUI7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7O0VBOEJ2QixDQUFDO0FBRUg7O0dBRUc7QUFDSCxxQkFBYSxrQkFBbUIsU0FBUSxLQUFLO0lBR3pCLEtBQUssQ0FBQztJQUZ4QixZQUNFLE9BQU8sRUFBRSxNQUFNLEVBQ0MsS0FBSyxDQUFDLG1CQUFPLEVBSTlCO0NBQ0Y7QUFFRCxNQUFNLE1BQU0sYUFBYSxHQUFHLENBQUMsQ0FBQyxLQUFLLENBQUMsT0FBTyxtQkFBbUIsQ0FBQyxDQUFDO0FBRWhFOzs7R0FHRztBQUNILE1BQU0sV0FBVyxzQkFBc0I7SUFDckMsTUFBTSxFQUFFO1FBQ04sR0FBRyxFQUFFO1lBQ0gsUUFBUSxFQUFFLFFBQVEsQ0FBQztZQUNuQixNQUFNLEVBQUU7Z0JBQ04sS0FBSyxFQUFFLE1BQU0sQ0FBQztnQkFDZCxDQUFDLEVBQUUsTUFBTSxDQUFDO2dCQUNWLEdBQUcsRUFBRSxNQUFNLENBQUM7Z0JBQ1osSUFBSSxFQUFFLE1BQU0sQ0FBQzthQUNkLENBQUM7WUFDRixPQUFPLEVBQUUsTUFBTSxDQUFDO1NBQ2pCLENBQUM7UUFDRixRQUFRLEVBQUU7WUFDUixRQUFRLEVBQUUsUUFBUSxDQUFDO1lBQ25CLE1BQU0sRUFBRSxNQUFNLENBQUMsTUFBTSxFQUFFLEtBQUssQ0FBQyxDQUFDO1lBQzlCLE9BQU8sRUFBRSxNQUFNLENBQUM7U0FDakIsQ0FBQztRQUNGLE1BQU0sRUFBRTtZQUNOLFFBQVEsRUFBRSxhQUFhLENBQUM7WUFDeEIsTUFBTSxFQUFFO2dCQUNOLEVBQUUsRUFBRSxNQUFNLENBQUM7YUFDWixDQUFDO1lBQ0YsT0FBTyxFQUFFLE1BQU0sQ0FBQztTQUNqQixDQUFDO0tBQ0gsQ0FBQztJQUNGLFdBQVcsRUFBRSxNQUFNLENBQUM7SUFDcEIsTUFBTSxFQUFFLE1BQU0sQ0FBQztJQUNmLElBQUksRUFBRSxNQUFNLENBQUM7SUFDYixJQUFJLEVBQUUsTUFBTSxDQUFDO0lBQ2IsT0FBTyxFQUFFLE1BQU0sQ0FBQztDQUNqQjtBQUVEOzs7Ozs7Ozs7Ozs7R0FZRztBQUNILHdCQUFnQixtQkFBbUIsQ0FDakMsUUFBUSxFQUFFLE1BQU0sRUFDaEIsYUFBYSxFQUFFLE1BQU0sRUFDckIsU0FBUyxFQUFFLE1BQU0sRUFDakIsY0FBYyxFQUFFLE1BQU0sR0FDckIsYUFBYSxDQThDZjtBQUVEOzs7Ozs7R0FNRztBQUNILHdCQUFnQixpQkFBaUIsQ0FBQyxRQUFRLEVBQUUsTUFBTSxHQUFHLGFBQWEsQ0FnQmpFO0FBRUQ7Ozs7Ozs7R0FPRztBQUNILHdCQUFnQixvQkFBb0IsQ0FBQyxRQUFRLEVBQUUsTUFBTSxFQUFFLFFBQVEsRUFBRSxNQUFNLEdBQUcsTUFBTSxDQUcvRTtBQUVEOzs7Ozs7O0dBT0c7QUFDSCx3QkFBZ0IsOEJBQThCLENBQUMsUUFBUSxFQUFFLGFBQWEsRUFBRSxRQUFRLEVBQUUsTUFBTSxHQUFHLE1BQU0sQ0FpRGhHO0FBRUQ7Ozs7Ozs7R0FPRztBQUNILHdCQUFnQixrQkFBa0IsQ0FDaEMsYUFBYSxFQUFFLE1BQU0sRUFDckIsY0FBYyxFQUFFLE1BQU0sRUFDdEIsZ0JBQWdCLEVBQUUsQ0FBQyxVQUFVLEVBQUUsTUFBTSxLQUFLLE1BQU0sR0FDL0MsT0FBTyxDQVNUIn0=
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bn254_keystore.d.ts","sourceRoot":"","sources":["../../../src/crypto/bls/bn254_keystore.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;;;;;GAQG;AAEH;;GAEG;AACH,QAAA,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA8BvB,CAAC;AAEH;;GAEG;AACH,qBAAa,kBAAmB,SAAQ,KAAK;IAGzB,KAAK,CAAC;IAFxB,YACE,OAAO,EAAE,MAAM,EACC,KAAK,CAAC,mBAAO,EAI9B;CACF;AAED,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAEhE;;;GAGG;AACH,MAAM,WAAW,sBAAsB;IACrC,MAAM,EAAE;QACN,GAAG,EAAE;YACH,QAAQ,EAAE,QAAQ,CAAC;YACnB,MAAM,EAAE;gBACN,KAAK,EAAE,MAAM,CAAC;gBACd,CAAC,EAAE,MAAM,CAAC;gBACV,GAAG,EAAE,MAAM,CAAC;gBACZ,IAAI,EAAE,MAAM,CAAC;aACd,CAAC;YACF,OAAO,EAAE,MAAM,CAAC;SACjB,CAAC;QACF,QAAQ,EAAE;YACR,QAAQ,EAAE,QAAQ,CAAC;YACnB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;YAC9B,OAAO,EAAE,MAAM,CAAC;SACjB,CAAC;QACF,MAAM,EAAE;YACN,QAAQ,EAAE,aAAa,CAAC;YACxB,MAAM,EAAE;gBACN,EAAE,EAAE,MAAM,CAAC;aACZ,CAAC;YACF,OAAO,EAAE,MAAM,CAAC;SACjB,CAAC;KACH,CAAC;IACF,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,mBAAmB,CACjC,QAAQ,EAAE,MAAM,EAChB,aAAa,EAAE,MAAM,EACrB,SAAS,EAAE,MAAM,EACjB,cAAc,EAAE,MAAM,GACrB,aAAa,CA8Cf;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,aAAa,CAgBjE;AAED;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAG/E;AAED;;;;;;;GAOG;AACH,wBAAgB,8BAA8B,CAAC,QAAQ,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAiDhG;AAED;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAChC,aAAa,EAAE,MAAM,EACrB,cAAc,EAAE,MAAM,EACtB,gBAAgB,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,MAAM,GAC/C,OAAO,CAST"}
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import { randomBytes } from '@aztec/foundation/crypto/random';
|
|
2
|
+
import { createCipheriv, createDecipheriv, createHash, pbkdf2Sync, randomUUID } from 'crypto';
|
|
3
|
+
import { readFileSync } from 'fs';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
/**
|
|
6
|
+
* BN254 Keystore Format
|
|
7
|
+
*
|
|
8
|
+
* Implements encryption and decryption of keystores for BN254 BLS private keys
|
|
9
|
+
* using PBKDF2 and AES-128-CTR. This format is inspired by EIP-2335 but adapted
|
|
10
|
+
* for BN254 keys rather than BLS12-381.
|
|
11
|
+
*
|
|
12
|
+
* @see https://eips.ethereum.org/EIPS/eip-2335
|
|
13
|
+
*/ /**
|
|
14
|
+
* Zod schema for validating BN254 keystore structure
|
|
15
|
+
*/ const bn254KeystoreSchema = z.object({
|
|
16
|
+
crypto: z.object({
|
|
17
|
+
kdf: z.object({
|
|
18
|
+
function: z.literal('pbkdf2'),
|
|
19
|
+
params: z.object({
|
|
20
|
+
dklen: z.number(),
|
|
21
|
+
c: z.number(),
|
|
22
|
+
prf: z.string(),
|
|
23
|
+
salt: z.string()
|
|
24
|
+
}),
|
|
25
|
+
message: z.string()
|
|
26
|
+
}),
|
|
27
|
+
checksum: z.object({
|
|
28
|
+
function: z.literal('sha256'),
|
|
29
|
+
params: z.object({}),
|
|
30
|
+
message: z.string()
|
|
31
|
+
}),
|
|
32
|
+
cipher: z.object({
|
|
33
|
+
function: z.literal('aes-128-ctr'),
|
|
34
|
+
params: z.object({
|
|
35
|
+
iv: z.string()
|
|
36
|
+
}),
|
|
37
|
+
message: z.string()
|
|
38
|
+
})
|
|
39
|
+
}),
|
|
40
|
+
description: z.string().optional(),
|
|
41
|
+
pubkey: z.string(),
|
|
42
|
+
path: z.string(),
|
|
43
|
+
uuid: z.string(),
|
|
44
|
+
version: z.number()
|
|
45
|
+
});
|
|
46
|
+
/**
|
|
47
|
+
* Error thrown when BN254 keystore operations fail
|
|
48
|
+
*/ export class Bn254KeystoreError extends Error {
|
|
49
|
+
cause;
|
|
50
|
+
constructor(message, cause){
|
|
51
|
+
super(message), this.cause = cause;
|
|
52
|
+
this.name = 'Bn254KeystoreError';
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Creates a BN254 keystore object for a BN254 BLS private key.
|
|
57
|
+
*
|
|
58
|
+
* Uses PBKDF2 with SHA-256 for key derivation and AES-128-CTR for encryption,
|
|
59
|
+
* following the EIP-2335 specification format.
|
|
60
|
+
*
|
|
61
|
+
* @param password - Password for encrypting the private key
|
|
62
|
+
* @param privateKeyHex - Private key as 0x-prefixed hex string (32 bytes)
|
|
63
|
+
* @param pubkeyHex - Public key as hex string (compressed or uncompressed)
|
|
64
|
+
* @param derivationPath - BIP-44 style derivation path (e.g., "m/12381/3600/0/0/0")
|
|
65
|
+
* @returns BN254 keystore object ready to be serialized to JSON
|
|
66
|
+
* @throws Error if private key is not 32-byte hex
|
|
67
|
+
*/ export function createBn254Keystore(password, privateKeyHex, pubkeyHex, derivationPath) {
|
|
68
|
+
const ensureHex = (hex)=>hex.replace(/^0x/i, '');
|
|
69
|
+
const privHex = ensureHex(privateKeyHex);
|
|
70
|
+
if (!/^[0-9a-fA-F]{64}$/.test(privHex)) {
|
|
71
|
+
throw new Error('BLS private key must be 32-byte hex');
|
|
72
|
+
}
|
|
73
|
+
const salt = randomBytes(32);
|
|
74
|
+
const iv = randomBytes(16);
|
|
75
|
+
const dk = pbkdf2Sync(Buffer.from(password.normalize('NFKD'), 'utf8'), salt, 262144, 32, 'sha256');
|
|
76
|
+
const cipherKey = dk.subarray(0, 16);
|
|
77
|
+
const cipher = createCipheriv('aes-128-ctr', cipherKey, iv);
|
|
78
|
+
const plaintext = Buffer.from(privHex, 'hex');
|
|
79
|
+
const ciphertext = Buffer.concat([
|
|
80
|
+
cipher.update(plaintext),
|
|
81
|
+
cipher.final()
|
|
82
|
+
]);
|
|
83
|
+
const checksum = createHash('sha256').update(Buffer.concat([
|
|
84
|
+
dk.subarray(16, 32),
|
|
85
|
+
ciphertext
|
|
86
|
+
])).digest();
|
|
87
|
+
const uuid = randomUUID();
|
|
88
|
+
return {
|
|
89
|
+
crypto: {
|
|
90
|
+
kdf: {
|
|
91
|
+
function: 'pbkdf2',
|
|
92
|
+
params: {
|
|
93
|
+
dklen: 32,
|
|
94
|
+
c: 262144,
|
|
95
|
+
prf: 'hmac-sha256',
|
|
96
|
+
salt: salt.toString('hex')
|
|
97
|
+
},
|
|
98
|
+
message: ''
|
|
99
|
+
},
|
|
100
|
+
checksum: {
|
|
101
|
+
function: 'sha256',
|
|
102
|
+
params: {},
|
|
103
|
+
message: checksum.toString('hex')
|
|
104
|
+
},
|
|
105
|
+
cipher: {
|
|
106
|
+
function: 'aes-128-ctr',
|
|
107
|
+
params: {
|
|
108
|
+
iv: iv.toString('hex')
|
|
109
|
+
},
|
|
110
|
+
message: ciphertext.toString('hex')
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
description: ensureHex(pubkeyHex),
|
|
114
|
+
pubkey: pubkeyHex,
|
|
115
|
+
path: derivationPath ?? '',
|
|
116
|
+
uuid,
|
|
117
|
+
version: 4
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Loads and validates a BN254 keystore file.
|
|
122
|
+
*
|
|
123
|
+
* @param filePath - Path to the BN254 keystore JSON file
|
|
124
|
+
* @returns Validated keystore object
|
|
125
|
+
* @throws Bn254KeystoreError if file cannot be read or validated
|
|
126
|
+
*/ export function loadBn254Keystore(filePath) {
|
|
127
|
+
try {
|
|
128
|
+
const content = readFileSync(filePath, 'utf-8');
|
|
129
|
+
const json = JSON.parse(content);
|
|
130
|
+
return bn254KeystoreSchema.parse(json);
|
|
131
|
+
} catch (error) {
|
|
132
|
+
if (error instanceof SyntaxError) {
|
|
133
|
+
throw new Bn254KeystoreError(`Invalid JSON in keystore file: ${filePath}`, error);
|
|
134
|
+
}
|
|
135
|
+
if (error && typeof error === 'object' && 'issues' in error) {
|
|
136
|
+
const issues = error.issues ?? [];
|
|
137
|
+
const message = issues.map((e)=>`${e.message} at ${e.path?.join('.') ?? 'root'}`).join('; ');
|
|
138
|
+
throw new Bn254KeystoreError(`Invalid BN254 keystore format: ${message}`);
|
|
139
|
+
}
|
|
140
|
+
throw new Bn254KeystoreError(`Failed to load keystore from ${filePath}: ${String(error)}`, error);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Decrypts a BN254 BLS private key from a keystore file.
|
|
145
|
+
*
|
|
146
|
+
* @param filePath - Path to the BN254 keystore JSON file
|
|
147
|
+
* @param password - Password to decrypt the keystore
|
|
148
|
+
* @returns Decrypted private key as 0x-prefixed hex string (32 bytes)
|
|
149
|
+
* @throws Bn254KeystoreError if decryption fails or checksum is invalid
|
|
150
|
+
*/ export function decryptBn254Keystore(filePath, password) {
|
|
151
|
+
const keystore = loadBn254Keystore(filePath);
|
|
152
|
+
return decryptBn254KeystoreFromObject(keystore, password);
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Decrypts a BN254 BLS private key from a keystore object.
|
|
156
|
+
*
|
|
157
|
+
* @param keystore - BN254 keystore object
|
|
158
|
+
* @param password - Password to decrypt the keystore
|
|
159
|
+
* @returns Decrypted private key as 0x-prefixed hex string (32 bytes)
|
|
160
|
+
* @throws Bn254KeystoreError if decryption fails or checksum is invalid
|
|
161
|
+
*/ export function decryptBn254KeystoreFromObject(keystore, password) {
|
|
162
|
+
try {
|
|
163
|
+
const { crypto } = keystore;
|
|
164
|
+
// Only support PBKDF2 + AES-128-CTR (as per our implementation)
|
|
165
|
+
if (crypto.kdf.function !== 'pbkdf2') {
|
|
166
|
+
throw new Bn254KeystoreError(`Unsupported KDF function: ${crypto.kdf.function}`);
|
|
167
|
+
}
|
|
168
|
+
if (crypto.cipher.function !== 'aes-128-ctr') {
|
|
169
|
+
throw new Bn254KeystoreError(`Unsupported cipher function: ${crypto.cipher.function}`);
|
|
170
|
+
}
|
|
171
|
+
// Derive decryption key using PBKDF2
|
|
172
|
+
const salt = Buffer.from(crypto.kdf.params.salt, 'hex');
|
|
173
|
+
const dk = pbkdf2Sync(Buffer.from(password.normalize('NFKD'), 'utf8'), salt, crypto.kdf.params.c, crypto.kdf.params.dklen, 'sha256');
|
|
174
|
+
const cipherKey = dk.subarray(0, 16);
|
|
175
|
+
const checksumKey = dk.subarray(16, 32);
|
|
176
|
+
// Decrypt the ciphertext
|
|
177
|
+
const iv = Buffer.from(crypto.cipher.params.iv, 'hex');
|
|
178
|
+
const ciphertext = Buffer.from(crypto.cipher.message, 'hex');
|
|
179
|
+
const decipher = createDecipheriv('aes-128-ctr', cipherKey, iv);
|
|
180
|
+
const decrypted = Buffer.concat([
|
|
181
|
+
decipher.update(ciphertext),
|
|
182
|
+
decipher.final()
|
|
183
|
+
]);
|
|
184
|
+
// Verify checksum
|
|
185
|
+
const computedChecksum = createHash('sha256').update(Buffer.concat([
|
|
186
|
+
checksumKey,
|
|
187
|
+
ciphertext
|
|
188
|
+
])).digest();
|
|
189
|
+
const expectedChecksum = Buffer.from(crypto.checksum.message, 'hex');
|
|
190
|
+
if (!computedChecksum.equals(expectedChecksum)) {
|
|
191
|
+
throw new Bn254KeystoreError('Checksum verification failed - incorrect password or corrupted keystore');
|
|
192
|
+
}
|
|
193
|
+
// Return as 0x-prefixed hex
|
|
194
|
+
return '0x' + decrypted.toString('hex');
|
|
195
|
+
} catch (error) {
|
|
196
|
+
if (error instanceof Bn254KeystoreError) {
|
|
197
|
+
throw error;
|
|
198
|
+
}
|
|
199
|
+
throw new Bn254KeystoreError(`Failed to decrypt keystore: ${String(error)}`, error);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Validates that a decrypted private key matches the public key in the keystore.
|
|
204
|
+
*
|
|
205
|
+
* @param privateKeyHex - Decrypted private key (0x-prefixed)
|
|
206
|
+
* @param expectedPubkey - Expected public key from keystore
|
|
207
|
+
* @param computePublicKey - Function to compute public key from private key
|
|
208
|
+
* @returns true if keys match, false otherwise
|
|
209
|
+
*/ export function verifyBn254Keypair(privateKeyHex, expectedPubkey, computePublicKey) {
|
|
210
|
+
try {
|
|
211
|
+
const computedPubkey = computePublicKey(privateKeyHex);
|
|
212
|
+
const normalizedExpected = expectedPubkey.toLowerCase().replace(/^0x/i, '');
|
|
213
|
+
const normalizedComputed = computedPubkey.toLowerCase().replace(/^0x/i, '');
|
|
214
|
+
return normalizedExpected === normalizedComputed;
|
|
215
|
+
} catch {
|
|
216
|
+
return false;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Hex } from '@aztec/foundation/string';
|
|
2
|
+
export declare function deriveBlsPrivateKey(mnemonic: string | undefined, ikm: string | undefined, path: string): Hex<32>;
|
|
3
|
+
/**
|
|
4
|
+
* Deterministically derive a BN254 BLS private key from mnemonic and derivation path.
|
|
5
|
+
* Returns a 0x-prefixed 32-byte hex string representing an Fr in [1, r-1].
|
|
6
|
+
*/
|
|
7
|
+
export declare function deriveBlsKeyFromMnemonic(mnemonic: string, derivationPath: string, passphrase?: string): string;
|
|
8
|
+
/**
|
|
9
|
+
* Deterministically derive a BN254 BLS private key from input keying material (IKM) and derivation path.
|
|
10
|
+
* Returns a 0x-prefixed 32-byte hex string representing an Fr in [1, r-1].
|
|
11
|
+
*/
|
|
12
|
+
export declare function deriveBlsKeyFromEntropy(ikm: string, derivationPath: string): string;
|
|
13
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9jcnlwdG8vYmxzL2luZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUNBLE9BQU8sS0FBSyxFQUFFLEdBQUcsRUFBRSxNQUFNLDBCQUEwQixDQUFDO0FBUXBELHdCQUFnQixtQkFBbUIsQ0FBQyxRQUFRLEVBQUUsTUFBTSxHQUFHLFNBQVMsRUFBRSxHQUFHLEVBQUUsTUFBTSxHQUFHLFNBQVMsRUFBRSxJQUFJLEVBQUUsTUFBTSxHQUFHLEdBQUcsQ0FBQyxFQUFFLENBQUMsQ0FRaEg7QUFFRDs7O0dBR0c7QUFDSCx3QkFBZ0Isd0JBQXdCLENBQUMsUUFBUSxFQUFFLE1BQU0sRUFBRSxjQUFjLEVBQUUsTUFBTSxFQUFFLFVBQVUsU0FBSyxHQUFHLE1BQU0sQ0FLMUc7QUFFRDs7O0dBR0c7QUFDSCx3QkFBZ0IsdUJBQXVCLENBQUMsR0FBRyxFQUFFLE1BQU0sRUFBRSxjQUFjLEVBQUUsTUFBTSxHQUFHLE1BQU0sQ0FLbkYifQ==
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/crypto/bls/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,0BAA0B,CAAC;AAQpD,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,EAAE,GAAG,EAAE,MAAM,GAAG,SAAS,EAAE,IAAI,EAAE,MAAM,GAAG,GAAG,CAAC,EAAE,CAAC,CAQhH;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,EAAE,UAAU,SAAK,GAAG,MAAM,CAK1G;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,GAAG,MAAM,CAKnF"}
|