@aztec/foundation 0.0.0-test.1 → 0.0.1-commit.b655e406
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/array/array.d.ts +5 -0
- package/dest/array/array.d.ts.map +1 -1
- package/dest/array/array.js +11 -0
- package/dest/async-pool/index.d.ts.map +1 -1
- package/dest/async-pool/index.js +1 -0
- package/dest/bigint/index.d.ts +7 -0
- package/dest/bigint/index.d.ts.map +1 -0
- package/dest/bigint/index.js +15 -0
- package/dest/bigint-buffer/index.d.ts +0 -2
- package/dest/bigint-buffer/index.d.ts.map +1 -1
- package/dest/buffer/buffer16.d.ts +80 -0
- package/dest/buffer/buffer16.d.ts.map +1 -0
- package/dest/buffer/buffer16.js +100 -0
- package/dest/buffer/buffer32.d.ts +3 -7
- package/dest/buffer/buffer32.d.ts.map +1 -1
- package/dest/buffer/buffer32.js +6 -6
- package/dest/buffer/index.d.ts +1 -0
- package/dest/buffer/index.d.ts.map +1 -1
- package/dest/buffer/index.js +1 -0
- package/dest/collection/array.d.ts +16 -3
- package/dest/collection/array.d.ts.map +1 -1
- package/dest/collection/array.js +57 -3
- package/dest/collection/object.d.ts +16 -0
- package/dest/collection/object.d.ts.map +1 -1
- package/dest/collection/object.js +25 -0
- package/dest/config/env_var.d.ts +1 -1
- package/dest/config/env_var.d.ts.map +1 -1
- package/dest/config/index.d.ts +48 -1
- package/dest/config/index.d.ts.map +1 -1
- package/dest/config/index.js +115 -7
- package/dest/config/network_config.d.ts +42 -0
- package/dest/config/network_config.d.ts.map +1 -0
- package/dest/config/network_config.js +9 -0
- package/dest/config/network_name.d.ts +3 -0
- package/dest/config/network_name.d.ts.map +1 -0
- package/dest/config/network_name.js +19 -0
- package/dest/config/secret_value.d.ts +28 -0
- package/dest/config/secret_value.d.ts.map +1 -0
- package/dest/config/secret_value.js +34 -0
- package/dest/crypto/aes128/index.d.ts +2 -4
- package/dest/crypto/aes128/index.d.ts.map +1 -1
- package/dest/crypto/aes128/index.js +23 -6
- package/dest/crypto/bls/bn254_keystore.d.ts +296 -0
- package/dest/crypto/bls/bn254_keystore.d.ts.map +1 -0
- package/dest/crypto/bls/bn254_keystore.js +218 -0
- package/dest/crypto/bls/index.d.ts +13 -0
- package/dest/crypto/bls/index.d.ts.map +1 -0
- package/dest/crypto/bls/index.js +87 -0
- package/dest/crypto/bn254/bn254_utils.d.ts +39 -0
- package/dest/crypto/bn254/bn254_utils.d.ts.map +1 -0
- package/dest/crypto/bn254/bn254_utils.js +56 -0
- package/dest/crypto/bn254/index.d.ts +55 -0
- package/dest/crypto/bn254/index.d.ts.map +1 -0
- package/dest/crypto/bn254/index.js +142 -0
- package/dest/crypto/ecdsa/index.d.ts +2 -2
- package/dest/crypto/ecdsa/index.d.ts.map +1 -1
- package/dest/crypto/ecdsa/index.js +70 -48
- package/dest/crypto/ecdsa/signature.d.ts +1 -3
- package/dest/crypto/ecdsa/signature.d.ts.map +1 -1
- package/dest/crypto/grumpkin/index.d.ts +6 -13
- package/dest/crypto/grumpkin/index.d.ts.map +1 -1
- package/dest/crypto/grumpkin/index.js +69 -54
- package/dest/crypto/index.d.ts +2 -0
- package/dest/crypto/index.d.ts.map +1 -1
- package/dest/crypto/index.js +2 -0
- package/dest/crypto/keccak/index.d.ts +2 -4
- package/dest/crypto/keccak/index.d.ts.map +1 -1
- package/dest/crypto/keys/index.d.ts +0 -2
- package/dest/crypto/keys/index.d.ts.map +1 -1
- package/dest/crypto/keys/index.js +9 -4
- package/dest/crypto/pedersen/pedersen.noble.d.ts +2 -4
- package/dest/crypto/pedersen/pedersen.noble.d.ts.map +1 -1
- package/dest/crypto/pedersen/pedersen.wasm.d.ts +2 -4
- package/dest/crypto/pedersen/pedersen.wasm.d.ts.map +1 -1
- package/dest/crypto/pedersen/pedersen.wasm.js +29 -13
- package/dest/crypto/poseidon/index.d.ts +0 -2
- package/dest/crypto/poseidon/index.d.ts.map +1 -1
- package/dest/crypto/poseidon/index.js +42 -17
- package/dest/crypto/random/index.d.ts +1 -3
- package/dest/crypto/random/index.d.ts.map +1 -1
- package/dest/crypto/random/index.js +2 -34
- package/dest/crypto/random/randomness_singleton.d.ts +0 -2
- package/dest/crypto/random/randomness_singleton.d.ts.map +1 -1
- package/dest/crypto/schnorr/index.d.ts.map +1 -1
- package/dest/crypto/schnorr/index.js +35 -37
- package/dest/crypto/schnorr/signature.d.ts +3 -5
- package/dest/crypto/schnorr/signature.d.ts.map +1 -1
- package/dest/crypto/secp256k1/index.d.ts +4 -6
- package/dest/crypto/secp256k1/index.d.ts.map +1 -1
- package/dest/crypto/secp256k1/index.js +29 -18
- package/dest/crypto/secp256k1-signer/utils.d.ts +55 -4
- package/dest/crypto/secp256k1-signer/utils.d.ts.map +1 -1
- package/dest/crypto/secp256k1-signer/utils.js +92 -6
- package/dest/crypto/serialize.d.ts +4 -6
- package/dest/crypto/serialize.d.ts.map +1 -1
- package/dest/crypto/sha256/index.d.ts +21 -4
- package/dest/crypto/sha256/index.d.ts.map +1 -1
- package/dest/crypto/sha256/index.js +42 -0
- package/dest/crypto/sha512/index.d.ts +1 -3
- package/dest/crypto/sha512/index.d.ts.map +1 -1
- package/dest/crypto/signature/index.d.ts +0 -2
- package/dest/crypto/signature/index.d.ts.map +1 -1
- package/dest/crypto/sync/index.js +3 -1
- package/dest/crypto/sync/pedersen/index.d.ts +2 -4
- package/dest/crypto/sync/pedersen/index.d.ts.map +1 -1
- package/dest/crypto/sync/pedersen/index.js +17 -10
- package/dest/crypto/sync/poseidon/index.d.ts +0 -2
- package/dest/crypto/sync/poseidon/index.d.ts.map +1 -1
- package/dest/crypto/sync/poseidon/index.js +27 -12
- package/dest/decorators/memoize.d.ts.map +1 -1
- package/dest/eth-address/index.d.ts +6 -7
- package/dest/eth-address/index.d.ts.map +1 -1
- package/dest/eth-address/index.js +5 -0
- package/dest/eth-signature/eth_signature.d.ts +16 -14
- package/dest/eth-signature/eth_signature.d.ts.map +1 -1
- package/dest/eth-signature/eth_signature.js +31 -17
- package/dest/fields/bls12_fields.d.ts +148 -0
- package/dest/fields/bls12_fields.d.ts.map +1 -0
- package/dest/fields/bls12_fields.js +359 -0
- package/dest/fields/bls12_point.d.ts +229 -0
- package/dest/fields/bls12_point.d.ts.map +1 -0
- package/dest/fields/bls12_point.js +398 -0
- package/dest/fields/coordinate.d.ts +0 -2
- package/dest/fields/coordinate.d.ts.map +1 -1
- package/dest/fields/fields.d.ts +6 -3
- package/dest/fields/fields.d.ts.map +1 -1
- package/dest/fields/fields.js +43 -15
- package/dest/fields/index.d.ts +2 -0
- package/dest/fields/index.d.ts.map +1 -1
- package/dest/fields/index.js +2 -0
- package/dest/fields/point.d.ts +2 -4
- package/dest/fields/point.d.ts.map +1 -1
- package/dest/fields/point.js +3 -3
- package/dest/fs/index.d.ts +1 -0
- package/dest/fs/index.d.ts.map +1 -1
- package/dest/fs/index.js +1 -0
- package/dest/fs/try_rm_dir.d.ts +3 -0
- package/dest/fs/try_rm_dir.d.ts.map +1 -0
- package/dest/fs/try_rm_dir.js +16 -0
- package/dest/index.d.ts +1 -2
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -2
- package/dest/iterable/filter.js +1 -1
- package/dest/iterable/map.js +1 -1
- package/dest/jest/env.js +48 -0
- package/dest/jest/setupAfterEnv.js +3 -0
- package/dest/json-rpc/client/fetch.d.ts +2 -2
- package/dest/json-rpc/client/fetch.d.ts.map +1 -1
- package/dest/json-rpc/client/fetch.js +16 -30
- package/dest/json-rpc/client/safe_json_rpc_client.d.ts +9 -3
- package/dest/json-rpc/client/safe_json_rpc_client.d.ts.map +1 -1
- package/dest/json-rpc/client/safe_json_rpc_client.js +173 -13
- package/dest/json-rpc/client/undici.d.ts.map +1 -1
- package/dest/json-rpc/client/undici.js +6 -7
- package/dest/json-rpc/convert.d.ts +2 -9
- package/dest/json-rpc/convert.d.ts.map +1 -1
- package/dest/json-rpc/convert.js +1 -9
- package/dest/json-rpc/errors.d.ts +4 -0
- package/dest/json-rpc/errors.d.ts.map +1 -0
- package/dest/json-rpc/errors.js +6 -0
- package/dest/json-rpc/fixtures/class_a.d.ts +5 -3
- package/dest/json-rpc/fixtures/class_a.d.ts.map +1 -1
- package/dest/json-rpc/fixtures/class_b.d.ts +5 -3
- package/dest/json-rpc/fixtures/class_b.d.ts.map +1 -1
- package/dest/json-rpc/index.d.ts +2 -1
- package/dest/json-rpc/index.d.ts.map +1 -1
- package/dest/json-rpc/index.js +2 -1
- package/dest/json-rpc/js_utils.d.ts.map +1 -1
- package/dest/json-rpc/server/safe_json_rpc_server.d.ts +21 -22
- package/dest/json-rpc/server/safe_json_rpc_server.d.ts.map +1 -1
- package/dest/json-rpc/server/safe_json_rpc_server.js +161 -56
- package/dest/json-rpc/test/integration.d.ts +1 -2
- package/dest/json-rpc/test/integration.d.ts.map +1 -1
- package/dest/log/console.d.ts.map +1 -1
- package/dest/log/gcloud-logger-config.d.ts +0 -1
- package/dest/log/gcloud-logger-config.d.ts.map +1 -1
- package/dest/log/gcloud-logger-config.js +1 -9
- package/dest/log/index.d.ts +4 -4
- package/dest/log/index.d.ts.map +1 -1
- package/dest/log/index.js +4 -4
- package/dest/log/libp2p_logger.js +13 -2
- package/dest/log/log_fn.d.ts +1 -1
- package/dest/log/log_fn.d.ts.map +1 -1
- package/dest/log/noir_debug_log_util.d.ts +14 -0
- package/dest/log/noir_debug_log_util.d.ts.map +1 -0
- package/dest/log/noir_debug_log_util.js +14 -0
- package/dest/log/pino-logger.d.ts +2 -2
- package/dest/log/pino-logger.d.ts.map +1 -1
- package/dest/log/pino-logger.js +28 -2
- package/dest/message/index.d.ts.map +1 -1
- package/dest/mutex/mutex_database.d.ts.map +1 -1
- package/dest/noir/noir_package_config.d.ts +4 -4
- package/dest/number/index.d.ts +3 -0
- package/dest/number/index.d.ts.map +1 -0
- package/dest/number/index.js +12 -0
- package/dest/profiler/index.d.ts +2 -0
- package/dest/profiler/index.d.ts.map +1 -0
- package/dest/profiler/index.js +1 -0
- package/dest/profiler/profiler.d.ts +8 -0
- package/dest/profiler/profiler.d.ts.map +1 -0
- package/dest/profiler/profiler.js +97 -0
- package/dest/promise/running-promise.d.ts +1 -1
- package/dest/promise/running-promise.d.ts.map +1 -1
- package/dest/promise/running-promise.js +2 -2
- package/dest/queue/batch_queue.d.ts +1 -1
- package/dest/queue/batch_queue.js +1 -1
- package/dest/queue/bounded_serial_queue.d.ts.map +1 -1
- package/dest/queue/serial_queue.d.ts +2 -2
- package/dest/queue/serial_queue.d.ts.map +1 -1
- package/dest/queue/serial_queue.js +7 -5
- package/dest/retry/index.d.ts +3 -2
- package/dest/retry/index.d.ts.map +1 -1
- package/dest/retry/index.js +2 -2
- package/dest/schemas/api.d.ts.map +1 -1
- package/dest/schemas/parse.js +1 -1
- package/dest/schemas/schemas.d.ts +9 -6
- package/dest/schemas/schemas.d.ts.map +1 -1
- package/dest/schemas/schemas.js +15 -1
- package/dest/schemas/utils.d.ts +1 -3
- package/dest/schemas/utils.d.ts.map +1 -1
- package/dest/serialize/buffer_reader.d.ts +27 -2
- package/dest/serialize/buffer_reader.d.ts.map +1 -1
- package/dest/serialize/buffer_reader.js +44 -2
- package/dest/serialize/field_reader.d.ts +10 -1
- package/dest/serialize/field_reader.d.ts.map +1 -1
- package/dest/serialize/field_reader.js +18 -1
- package/dest/serialize/free_funcs.d.ts +23 -21
- package/dest/serialize/free_funcs.d.ts.map +1 -1
- package/dest/serialize/free_funcs.js +21 -27
- package/dest/serialize/serialize.d.ts +4 -5
- package/dest/serialize/serialize.d.ts.map +1 -1
- package/dest/string/index.d.ts +7 -2
- package/dest/string/index.d.ts.map +1 -1
- package/dest/string/index.js +27 -1
- package/dest/testing/files/index.d.ts +0 -2
- package/dest/testing/files/index.d.ts.map +1 -1
- package/dest/testing/files/index.js +2 -2
- package/dest/testing/formatting.d.ts +4 -0
- package/dest/testing/formatting.d.ts.map +1 -0
- package/dest/testing/formatting.js +3 -0
- package/dest/testing/index.d.ts +1 -0
- package/dest/testing/index.d.ts.map +1 -1
- package/dest/testing/index.js +1 -0
- package/dest/timer/date.d.ts +2 -1
- package/dest/timer/date.d.ts.map +1 -1
- package/dest/timer/date.js +5 -3
- package/dest/timer/index.d.ts +1 -1
- package/dest/timer/index.d.ts.map +1 -1
- package/dest/timer/index.js +1 -1
- package/dest/timer/timeout.d.ts +18 -5
- package/dest/timer/timeout.d.ts.map +1 -1
- package/dest/timer/timeout.js +43 -22
- package/dest/transport/dispatch/create_dispatch_fn.d.ts.map +1 -1
- package/dest/transport/index.d.ts +0 -1
- package/dest/transport/index.d.ts.map +1 -1
- package/dest/transport/index.js +0 -1
- package/dest/transport/interface/connector.d.ts.map +1 -1
- package/dest/transport/interface/listener.d.ts +0 -1
- package/dest/transport/interface/listener.d.ts.map +1 -1
- package/dest/transport/interface/socket.d.ts.map +1 -1
- package/dest/transport/node/node_connector.d.ts +0 -1
- package/dest/transport/node/node_connector.d.ts.map +1 -1
- package/dest/transport/node/node_connector_socket.d.ts +0 -1
- package/dest/transport/node/node_connector_socket.d.ts.map +1 -1
- package/dest/transport/node/node_listener.d.ts +0 -1
- package/dest/transport/node/node_listener.d.ts.map +1 -1
- package/dest/transport/node/node_listener_socket.d.ts +0 -1
- package/dest/transport/node/node_listener_socket.d.ts.map +1 -1
- package/dest/transport/transport_client.d.ts +0 -1
- package/dest/transport/transport_client.d.ts.map +1 -1
- package/dest/transport/transport_server.d.ts.map +1 -1
- package/dest/trees/hasher.d.ts +4 -6
- package/dest/trees/hasher.d.ts.map +1 -1
- package/dest/trees/index.d.ts +1 -0
- package/dest/trees/index.d.ts.map +1 -1
- package/dest/trees/index.js +1 -0
- package/dest/trees/indexed_merkle_tree.d.ts +0 -2
- package/dest/trees/indexed_merkle_tree.d.ts.map +1 -1
- package/dest/trees/indexed_merkle_tree_calculator.d.ts +1 -3
- package/dest/trees/indexed_merkle_tree_calculator.d.ts.map +1 -1
- package/dest/trees/indexed_tree_leaf.d.ts +0 -2
- package/dest/trees/indexed_tree_leaf.d.ts.map +1 -1
- package/dest/trees/membership_witness.d.ts +19 -3
- package/dest/trees/membership_witness.d.ts.map +1 -1
- package/dest/trees/membership_witness.js +13 -0
- package/dest/trees/merkle_tree.d.ts +0 -2
- package/dest/trees/merkle_tree.d.ts.map +1 -1
- package/dest/trees/merkle_tree_calculator.d.ts +11 -3
- package/dest/trees/merkle_tree_calculator.d.ts.map +1 -1
- package/dest/trees/merkle_tree_calculator.js +31 -1
- package/dest/trees/sibling_path.d.ts +6 -8
- package/dest/trees/sibling_path.d.ts.map +1 -1
- package/dest/trees/unbalanced_merkle_tree.d.ts +19 -8
- package/dest/trees/unbalanced_merkle_tree.d.ts.map +1 -1
- package/dest/trees/unbalanced_merkle_tree.js +49 -50
- package/dest/trees/unbalanced_merkle_tree_calculator.d.ts +48 -0
- package/dest/trees/unbalanced_merkle_tree_calculator.d.ts.map +1 -0
- package/dest/trees/unbalanced_merkle_tree_calculator.js +162 -0
- package/dest/trees/unbalanced_tree_store.d.ts +1 -0
- package/dest/trees/unbalanced_tree_store.d.ts.map +1 -1
- package/dest/trees/unbalanced_tree_store.js +6 -0
- package/dest/types/index.d.ts +25 -2
- package/dest/types/index.d.ts.map +1 -1
- package/dest/url/index.d.ts.map +1 -1
- package/dest/url/index.js +1 -1
- package/package.json +35 -41
- package/src/array/array.ts +13 -0
- package/src/async-pool/index.ts +1 -0
- package/src/bigint/index.ts +20 -0
- package/src/buffer/buffer16.ts +133 -0
- package/src/buffer/buffer32.ts +8 -6
- package/src/buffer/index.ts +1 -0
- package/src/collection/array.ts +66 -4
- package/src/collection/object.ts +37 -0
- package/src/config/env_var.ts +142 -52
- package/src/config/index.ts +191 -8
- package/src/config/network_config.ts +16 -0
- package/src/config/network_name.ts +28 -0
- package/src/config/secret_value.ts +49 -0
- package/src/crypto/aes128/index.ts +19 -10
- package/src/crypto/bls/bn254_keystore.ts +287 -0
- package/src/crypto/bls/index.ts +77 -0
- package/src/crypto/bn254/bn254_utils.ts +64 -0
- package/src/crypto/bn254/index.ts +170 -0
- package/src/crypto/ecdsa/index.ts +41 -23
- package/src/crypto/grumpkin/index.ts +35 -45
- package/src/crypto/index.ts +2 -0
- package/src/crypto/keys/index.ts +5 -5
- package/src/crypto/pedersen/pedersen.wasm.ts +22 -18
- package/src/crypto/poseidon/index.ts +32 -24
- package/src/crypto/random/index.ts +2 -40
- package/src/crypto/schnorr/index.ts +20 -17
- package/src/crypto/secp256k1/index.ts +15 -11
- package/src/crypto/secp256k1-signer/utils.ts +120 -7
- package/src/crypto/sha256/index.ts +47 -0
- package/src/crypto/sync/index.ts +1 -1
- package/src/crypto/sync/pedersen/index.ts +16 -15
- package/src/crypto/sync/poseidon/index.ts +27 -22
- package/src/eth-address/index.ts +9 -2
- package/src/eth-signature/eth_signature.ts +44 -22
- package/src/fields/bls12_fields.ts +463 -0
- package/src/fields/bls12_point.ts +450 -0
- package/src/fields/fields.ts +37 -9
- package/src/fields/index.ts +2 -0
- package/src/fields/point.ts +1 -3
- package/src/fs/index.ts +1 -0
- package/src/fs/try_rm_dir.ts +15 -0
- package/src/index.ts +1 -2
- package/src/iterable/filter.ts +1 -1
- package/src/iterable/map.ts +1 -1
- package/src/jest/env.mjs +52 -0
- package/src/jest/setupAfterEnv.mjs +3 -0
- package/src/json-rpc/client/fetch.ts +14 -33
- package/src/json-rpc/client/safe_json_rpc_client.ts +226 -13
- package/src/json-rpc/client/undici.ts +8 -15
- package/src/json-rpc/convert.ts +3 -12
- package/src/json-rpc/errors.ts +6 -0
- package/src/json-rpc/fixtures/class_a.ts +4 -1
- package/src/json-rpc/fixtures/class_b.ts +4 -1
- package/src/json-rpc/index.ts +2 -1
- package/src/json-rpc/server/safe_json_rpc_server.ts +141 -48
- package/src/json-rpc/test/integration.ts +1 -1
- package/src/log/console.ts +4 -1
- package/src/log/gcloud-logger-config.ts +3 -7
- package/src/log/index.ts +4 -4
- package/src/log/libp2p_logger.ts +21 -2
- package/src/log/log_fn.ts +1 -1
- package/src/log/noir_debug_log_util.ts +21 -0
- package/src/log/pino-logger.ts +33 -2
- package/src/message/index.ts +5 -1
- package/src/mutex/mutex_database.ts +2 -3
- package/src/number/index.ts +14 -0
- package/src/profiler/index.ts +1 -0
- package/src/profiler/profiler.ts +125 -0
- package/src/promise/running-promise.ts +2 -2
- package/src/queue/batch_queue.ts +1 -1
- package/src/queue/bounded_serial_queue.ts +4 -1
- package/src/queue/serial_queue.ts +5 -5
- package/src/retry/index.ts +10 -5
- package/src/schemas/api.ts +4 -4
- package/src/schemas/parse.ts +1 -1
- package/src/schemas/schemas.ts +19 -1
- package/src/serialize/buffer_reader.ts +60 -3
- package/src/serialize/field_reader.ts +27 -3
- package/src/serialize/free_funcs.ts +25 -31
- package/src/serialize/serialize.ts +2 -0
- package/src/string/index.ts +36 -1
- package/src/testing/files/index.ts +6 -2
- package/src/testing/formatting.ts +3 -0
- package/src/testing/index.ts +1 -0
- package/src/timer/date.ts +9 -3
- package/src/timer/index.ts +1 -1
- package/src/timer/timeout.ts +54 -19
- package/src/transport/index.ts +0 -1
- package/src/transport/interface/connector.ts +0 -1
- package/src/transport/interface/listener.ts +2 -3
- package/src/transport/interface/socket.ts +2 -3
- package/src/transport/transport_client.ts +3 -4
- package/src/transport/transport_server.ts +4 -1
- package/src/trees/hasher.ts +4 -4
- package/src/trees/index.ts +1 -0
- package/src/trees/indexed_merkle_tree.ts +5 -1
- package/src/trees/indexed_merkle_tree_calculator.ts +2 -2
- package/src/trees/membership_witness.ts +13 -0
- package/src/trees/merkle_tree.ts +4 -1
- package/src/trees/merkle_tree_calculator.ts +43 -5
- package/src/trees/unbalanced_merkle_tree.ts +50 -42
- package/src/trees/unbalanced_merkle_tree_calculator.ts +194 -0
- package/src/trees/unbalanced_tree_store.ts +5 -1
- package/src/types/index.ts +25 -4
- package/src/url/index.ts +0 -1
- package/dest/crypto/pedersen/pedersen.elliptic.d.ts +0 -13
- package/dest/crypto/pedersen/pedersen.elliptic.d.ts.map +0 -1
- package/dest/crypto/pedersen/pedersen.elliptic.js +0 -582
- package/dest/log/debug.d.ts +0 -56
- package/dest/log/debug.d.ts.map +0 -1
- package/dest/log/debug.js +0 -75
- package/dest/log/log_history.d.ts +0 -31
- package/dest/log/log_history.d.ts.map +0 -1
- package/dest/log/log_history.js +0 -38
- package/dest/transport/browser/index.d.ts +0 -5
- package/dest/transport/browser/index.d.ts.map +0 -1
- package/dest/transport/browser/index.js +0 -4
- package/dest/transport/browser/message_port_socket.d.ts +0 -37
- package/dest/transport/browser/message_port_socket.d.ts.map +0 -1
- package/dest/transport/browser/message_port_socket.js +0 -42
- package/dest/transport/browser/shared_worker_connector.d.ts +0 -19
- package/dest/transport/browser/shared_worker_connector.d.ts.map +0 -1
- package/dest/transport/browser/shared_worker_connector.js +0 -19
- package/dest/transport/browser/shared_worker_listener.d.ts +0 -38
- package/dest/transport/browser/shared_worker_listener.d.ts.map +0 -1
- package/dest/transport/browser/shared_worker_listener.js +0 -33
- package/dest/transport/browser/worker_connector.d.ts +0 -26
- package/dest/transport/browser/worker_connector.d.ts.map +0 -1
- package/dest/transport/browser/worker_connector.js +0 -30
- package/dest/transport/browser/worker_listener.d.ts +0 -39
- package/dest/transport/browser/worker_listener.d.ts.map +0 -1
- package/dest/transport/browser/worker_listener.js +0 -35
- package/dest/wasm/empty_wasi_sdk.d.ts +0 -130
- package/dest/wasm/empty_wasi_sdk.d.ts.map +0 -1
- package/dest/wasm/empty_wasi_sdk.js +0 -148
- package/dest/wasm/index.d.ts +0 -2
- package/dest/wasm/index.d.ts.map +0 -1
- package/dest/wasm/index.js +0 -1
- package/dest/wasm/wasm_module.d.ts +0 -136
- package/dest/wasm/wasm_module.d.ts.map +0 -1
- package/dest/wasm/wasm_module.js +0 -196
- package/dest/worker/browser/index.d.ts +0 -3
- package/dest/worker/browser/index.d.ts.map +0 -1
- package/dest/worker/browser/index.js +0 -2
- package/dest/worker/browser/start_web_module.d.ts +0 -7
- package/dest/worker/browser/start_web_module.d.ts.map +0 -1
- package/dest/worker/browser/start_web_module.js +0 -27
- package/dest/worker/browser/web_data_store.d.ts +0 -24
- package/dest/worker/browser/web_data_store.d.ts.map +0 -1
- package/dest/worker/browser/web_data_store.js +0 -29
- package/dest/worker/browser/web_worker.d.ts +0 -10
- package/dest/worker/browser/web_worker.d.ts.map +0 -1
- package/dest/worker/browser/web_worker.js +0 -25
- package/dest/worker/data_store.d.ts +0 -21
- package/dest/worker/data_store.d.ts.map +0 -1
- package/dest/worker/data_store.js +0 -3
- package/dest/worker/index.d.ts +0 -3
- package/dest/worker/index.d.ts.map +0 -1
- package/dest/worker/index.js +0 -1
- package/dest/worker/node/index.d.ts +0 -3
- package/dest/worker/node/index.d.ts.map +0 -1
- package/dest/worker/node/index.js +0 -2
- package/dest/worker/node/node_data_store.d.ts +0 -13
- package/dest/worker/node/node_data_store.d.ts.map +0 -1
- package/dest/worker/node/node_data_store.js +0 -20
- package/dest/worker/node/node_worker.d.ts +0 -6
- package/dest/worker/node/node_worker.d.ts.map +0 -1
- package/dest/worker/node/node_worker.js +0 -22
- package/dest/worker/node/start_node_module.d.ts +0 -7
- package/dest/worker/node/start_node_module.d.ts.map +0 -1
- package/dest/worker/node/start_node_module.js +0 -31
- package/dest/worker/wasm_worker.d.ts +0 -9
- package/dest/worker/wasm_worker.d.ts.map +0 -1
- package/dest/worker/wasm_worker.js +0 -3
- package/dest/worker/worker_pool.d.ts +0 -40
- package/dest/worker/worker_pool.d.ts.map +0 -1
- package/dest/worker/worker_pool.js +0 -51
- package/src/crypto/pedersen/pedersen.elliptic.ts +0 -584
- package/src/log/debug.ts +0 -104
- package/src/log/log_history.ts +0 -44
- package/src/transport/browser/index.ts +0 -4
- package/src/transport/browser/message_port_socket.ts +0 -48
- package/src/transport/browser/shared_worker_connector.ts +0 -21
- package/src/transport/browser/shared_worker_listener.ts +0 -53
- package/src/transport/browser/worker_connector.ts +0 -30
- package/src/transport/browser/worker_listener.ts +0 -54
- package/src/wasm/README.md +0 -6
- package/src/wasm/empty_wasi_sdk.ts +0 -166
- package/src/wasm/fixtures/gcd.wasm +0 -0
- package/src/wasm/fixtures/gcd.wat +0 -27
- package/src/wasm/index.ts +0 -1
- package/src/wasm/wasm_module.ts +0 -260
- package/src/worker/browser/index.ts +0 -2
- package/src/worker/browser/start_web_module.ts +0 -24
- package/src/worker/browser/web_data_store.ts +0 -38
- package/src/worker/browser/web_worker.ts +0 -25
- package/src/worker/data_store.ts +0 -19
- package/src/worker/index.ts +0 -2
- package/src/worker/node/index.ts +0 -2
- package/src/worker/node/node_data_store.ts +0 -27
- package/src/worker/node/node_worker.ts +0 -23
- package/src/worker/node/start_node_module.ts +0 -30
- package/src/worker/wasm_worker.ts +0 -7
- package/src/worker/worker_pool.ts +0 -73
package/src/config/index.ts
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
|
+
import { Fq, Fr } from '../fields/fields.js';
|
|
1
2
|
import type { EnvVar } from './env_var.js';
|
|
3
|
+
import { type NetworkNames, getActiveNetworkName } from './network_name.js';
|
|
4
|
+
import { SecretValue } from './secret_value.js';
|
|
2
5
|
|
|
3
|
-
export {
|
|
6
|
+
export { SecretValue, getActiveNetworkName };
|
|
7
|
+
export type { EnvVar, NetworkNames };
|
|
8
|
+
export type { NetworkConfig, NetworkConfigMap } from './network_config.js';
|
|
9
|
+
export { NetworkConfigMapSchema, NetworkConfigSchema } from './network_config.js';
|
|
4
10
|
|
|
5
11
|
export interface ConfigMapping {
|
|
6
12
|
env?: EnvVar;
|
|
@@ -10,6 +16,7 @@ export interface ConfigMapping {
|
|
|
10
16
|
description: string;
|
|
11
17
|
isBoolean?: boolean;
|
|
12
18
|
nested?: Record<string, ConfigMapping>;
|
|
19
|
+
fallback?: EnvVar[];
|
|
13
20
|
}
|
|
14
21
|
|
|
15
22
|
export function isBooleanConfigValue<T>(obj: T, key: keyof T): boolean {
|
|
@@ -18,20 +25,59 @@ export function isBooleanConfigValue<T>(obj: T, key: keyof T): boolean {
|
|
|
18
25
|
|
|
19
26
|
export type ConfigMappingsType<T> = Record<keyof T, ConfigMapping>;
|
|
20
27
|
|
|
28
|
+
/**
|
|
29
|
+
* Shared utility function to get a value from environment variables with fallback support.
|
|
30
|
+
* This can be used by both getConfigFromMappings and CLI utilities.
|
|
31
|
+
*
|
|
32
|
+
* @param env - The primary environment variable name
|
|
33
|
+
* @param fallback - Optional array of fallback environment variable names
|
|
34
|
+
* @param parseFunc - Optional function to parse the environment variable value
|
|
35
|
+
* @param defaultValue - Optional default value to use if no environment variable is set
|
|
36
|
+
* @returns The parsed value from environment variables or the default value
|
|
37
|
+
*/
|
|
38
|
+
export function getValueFromEnvWithFallback<T>(
|
|
39
|
+
env: EnvVar | undefined,
|
|
40
|
+
parseFunc: ((val: string) => T) | undefined,
|
|
41
|
+
defaultValue: T | undefined,
|
|
42
|
+
fallback?: EnvVar[],
|
|
43
|
+
): T | undefined {
|
|
44
|
+
let value: string | undefined;
|
|
45
|
+
|
|
46
|
+
// Try primary env var
|
|
47
|
+
if (env) {
|
|
48
|
+
value = process.env[env];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// If primary not found, try fallbacks
|
|
52
|
+
if (value === undefined && fallback && fallback.length > 0) {
|
|
53
|
+
for (const fallbackEnv of fallback) {
|
|
54
|
+
const fallbackVal = process.env[fallbackEnv];
|
|
55
|
+
if (fallbackVal !== undefined) {
|
|
56
|
+
value = fallbackVal;
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Parse the value if needed
|
|
63
|
+
if (value !== undefined) {
|
|
64
|
+
return parseFunc ? parseFunc(value) : (value as unknown as T);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Return default if no env var found
|
|
68
|
+
return defaultValue;
|
|
69
|
+
}
|
|
70
|
+
|
|
21
71
|
export function getConfigFromMappings<T>(configMappings: ConfigMappingsType<T>): T {
|
|
22
72
|
const config = {} as T;
|
|
23
73
|
|
|
24
74
|
for (const key in configMappings) {
|
|
25
|
-
const { env, parseEnv, defaultValue
|
|
75
|
+
const { env, parseEnv, defaultValue, nested, fallback } = configMappings[key];
|
|
26
76
|
if (nested) {
|
|
27
77
|
(config as any)[key] = getConfigFromMappings(nested);
|
|
28
78
|
} else {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
(config as any)[key] = parseEnv ? parseEnv(val) : val;
|
|
32
|
-
} else if (def !== undefined) {
|
|
33
|
-
(config as any)[key] = def;
|
|
34
|
-
}
|
|
79
|
+
// Use the shared utility function
|
|
80
|
+
(config as any)[key] = getValueFromEnvWithFallback(env, parseEnv, defaultValue, fallback);
|
|
35
81
|
}
|
|
36
82
|
}
|
|
37
83
|
|
|
@@ -65,6 +111,25 @@ export function numberConfigHelper(defaultVal: number): Pick<ConfigMapping, 'par
|
|
|
65
111
|
};
|
|
66
112
|
}
|
|
67
113
|
|
|
114
|
+
/**
|
|
115
|
+
* Generates parseEnv and default values for a numerical config value.
|
|
116
|
+
* @param defaultVal - The default numerical value to use if the environment variable is not set or is invalid
|
|
117
|
+
* @returns Object with parseEnv and default values for a numerical config value
|
|
118
|
+
*/
|
|
119
|
+
export function floatConfigHelper(
|
|
120
|
+
defaultVal: number,
|
|
121
|
+
validationFn?: (val: number) => void,
|
|
122
|
+
): Pick<ConfigMapping, 'parseEnv' | 'defaultValue'> {
|
|
123
|
+
return {
|
|
124
|
+
parseEnv: (val: string): number => {
|
|
125
|
+
const parsed = safeParseFloat(val, defaultVal);
|
|
126
|
+
validationFn?.(parsed);
|
|
127
|
+
return parsed;
|
|
128
|
+
},
|
|
129
|
+
defaultValue: defaultVal,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
|
|
68
133
|
/**
|
|
69
134
|
* Generates parseEnv and default values for a numerical config value.
|
|
70
135
|
* @param defaultVal - The default numerical value to use if the environment variable is not set or is invalid
|
|
@@ -97,6 +162,26 @@ export function optionalNumberConfigHelper(): Pick<ConfigMapping, 'parseEnv'> {
|
|
|
97
162
|
};
|
|
98
163
|
}
|
|
99
164
|
|
|
165
|
+
/** Generates parseEnv for an enum-like config value. */
|
|
166
|
+
export function enumConfigHelper<T extends string>(
|
|
167
|
+
values: T[],
|
|
168
|
+
defaultValue?: NoInfer<T>,
|
|
169
|
+
): Pick<ConfigMapping, 'parseEnv' | 'defaultValue'> {
|
|
170
|
+
return {
|
|
171
|
+
parseEnv: (val: string) => {
|
|
172
|
+
const sanitizedVal = (val ?? '').trim().toLowerCase();
|
|
173
|
+
if (values.includes(sanitizedVal as T)) {
|
|
174
|
+
return sanitizedVal as T;
|
|
175
|
+
}
|
|
176
|
+
if (!val && defaultValue) {
|
|
177
|
+
return defaultValue;
|
|
178
|
+
}
|
|
179
|
+
throw new Error(`Invalid config value '${val}' (must be one of ${values.join(', ')})`);
|
|
180
|
+
},
|
|
181
|
+
defaultValue,
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
|
|
100
185
|
/**
|
|
101
186
|
* Generates parseEnv and default values for a boolean config value.
|
|
102
187
|
* @param defaultVal - The default value to use if the environment variable is not set or is invalid
|
|
@@ -114,11 +199,97 @@ export function booleanConfigHelper(
|
|
|
114
199
|
};
|
|
115
200
|
}
|
|
116
201
|
|
|
202
|
+
export function secretValueConfigHelper<T>(parse: (val: string | undefined) => T): Required<
|
|
203
|
+
Pick<ConfigMapping, 'parseEnv' | 'defaultValue' | 'isBoolean'> & {
|
|
204
|
+
parseVal: (val: string) => SecretValue<T>;
|
|
205
|
+
}
|
|
206
|
+
> {
|
|
207
|
+
const wrap = (val: string) => new SecretValue(parse(val));
|
|
208
|
+
return {
|
|
209
|
+
parseEnv: wrap,
|
|
210
|
+
parseVal: wrap,
|
|
211
|
+
defaultValue: new SecretValue(parse(undefined)),
|
|
212
|
+
isBoolean: true,
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
|
|
117
216
|
/** Parses an env var as boolean. Returns true only if value is 1, true, or TRUE. */
|
|
118
217
|
export function parseBooleanEnv(val: string | undefined): boolean {
|
|
119
218
|
return val !== undefined && ['1', 'true', 'TRUE'].includes(val);
|
|
120
219
|
}
|
|
121
220
|
|
|
221
|
+
export function secretStringConfigHelper(): Required<
|
|
222
|
+
Pick<ConfigMapping, 'parseEnv' | 'defaultValue' | 'isBoolean'> & {
|
|
223
|
+
parseVal: (val: string) => SecretValue<string | undefined>;
|
|
224
|
+
}
|
|
225
|
+
>;
|
|
226
|
+
export function secretStringConfigHelper(defaultValue: string): Required<
|
|
227
|
+
Pick<ConfigMapping, 'parseEnv' | 'defaultValue' | 'isBoolean'> & {
|
|
228
|
+
parseVal: (val: string) => SecretValue<string>;
|
|
229
|
+
}
|
|
230
|
+
>;
|
|
231
|
+
export function secretStringConfigHelper(defaultValue?: string): Required<
|
|
232
|
+
Pick<ConfigMapping, 'parseEnv' | 'defaultValue' | 'isBoolean'> & {
|
|
233
|
+
parseVal: (val: string) => SecretValue<string | typeof defaultValue>;
|
|
234
|
+
}
|
|
235
|
+
> {
|
|
236
|
+
const parse = (val: string) => new SecretValue(val);
|
|
237
|
+
return {
|
|
238
|
+
parseEnv: parse,
|
|
239
|
+
parseVal: parse,
|
|
240
|
+
defaultValue: defaultValue !== undefined ? new SecretValue(defaultValue) : undefined,
|
|
241
|
+
isBoolean: true,
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
export function secretFrConfigHelper(): Required<
|
|
246
|
+
Pick<ConfigMapping, 'parseEnv' | 'defaultValue' | 'isBoolean'> & {
|
|
247
|
+
parseVal: (val: string) => SecretValue<Fr | undefined>;
|
|
248
|
+
}
|
|
249
|
+
>;
|
|
250
|
+
export function secretFrConfigHelper(defaultValue: Fr): Required<
|
|
251
|
+
Pick<ConfigMapping, 'parseEnv' | 'defaultValue' | 'isBoolean'> & {
|
|
252
|
+
parseVal: (val: string) => SecretValue<Fr>;
|
|
253
|
+
}
|
|
254
|
+
>;
|
|
255
|
+
export function secretFrConfigHelper(defaultValue?: Fr): Required<
|
|
256
|
+
Pick<ConfigMapping, 'parseEnv' | 'defaultValue' | 'isBoolean'> & {
|
|
257
|
+
parseVal: (val: string) => SecretValue<Fr | typeof defaultValue>;
|
|
258
|
+
}
|
|
259
|
+
> {
|
|
260
|
+
const parse = (val: string) => new SecretValue(Fr.fromHexString(val));
|
|
261
|
+
return {
|
|
262
|
+
parseEnv: parse,
|
|
263
|
+
parseVal: parse,
|
|
264
|
+
defaultValue: defaultValue !== undefined ? new SecretValue(defaultValue) : undefined,
|
|
265
|
+
isBoolean: true,
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
export function secretFqConfigHelper(defaultValue: Fq): Required<
|
|
270
|
+
Pick<ConfigMapping, 'parseEnv' | 'defaultValue' | 'isBoolean'> & {
|
|
271
|
+
parseVal: (val: string) => SecretValue<Fq>;
|
|
272
|
+
}
|
|
273
|
+
>;
|
|
274
|
+
export function secretFqConfigHelper(): Required<
|
|
275
|
+
Pick<ConfigMapping, 'parseEnv' | 'defaultValue' | 'isBoolean'> & {
|
|
276
|
+
parseVal: (val: string) => SecretValue<Fq | undefined>;
|
|
277
|
+
}
|
|
278
|
+
>;
|
|
279
|
+
export function secretFqConfigHelper(defaultValue?: Fq): Required<
|
|
280
|
+
Pick<ConfigMapping, 'parseEnv' | 'defaultValue' | 'isBoolean'> & {
|
|
281
|
+
parseVal: (val: string) => SecretValue<Fq | typeof defaultValue>;
|
|
282
|
+
}
|
|
283
|
+
> {
|
|
284
|
+
const parse = (val: string) => new SecretValue(Fq.fromHexString(val));
|
|
285
|
+
return {
|
|
286
|
+
parseEnv: parse,
|
|
287
|
+
parseVal: parse,
|
|
288
|
+
defaultValue: typeof defaultValue !== 'undefined' ? new SecretValue(defaultValue) : undefined,
|
|
289
|
+
isBoolean: true,
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
|
|
122
293
|
/**
|
|
123
294
|
* Safely parses a number from a string.
|
|
124
295
|
* If the value is not a number or is not a safe integer, the default value is returned.
|
|
@@ -131,6 +302,18 @@ function safeParseNumber(value: string, defaultValue: number): number {
|
|
|
131
302
|
return Number.isSafeInteger(parsedValue) ? parsedValue : defaultValue;
|
|
132
303
|
}
|
|
133
304
|
|
|
305
|
+
/**
|
|
306
|
+
* Safely parses a floating point number from a string.
|
|
307
|
+
* If the value is not a number, the default value is returned.
|
|
308
|
+
* @param value - The string value to parse
|
|
309
|
+
* @param defaultValue - The default value to return
|
|
310
|
+
* @returns Either parsed value or default value
|
|
311
|
+
*/
|
|
312
|
+
function safeParseFloat(value: string, defaultValue: number): number {
|
|
313
|
+
const parsedValue = parseFloat(value);
|
|
314
|
+
return Number.isNaN(parsedValue) ? defaultValue : parsedValue;
|
|
315
|
+
}
|
|
316
|
+
|
|
134
317
|
/**
|
|
135
318
|
* Picks specific keys from the given configuration mappings.
|
|
136
319
|
*
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
export const NetworkConfigSchema = z
|
|
4
|
+
.object({
|
|
5
|
+
bootnodes: z.array(z.string()),
|
|
6
|
+
snapshots: z.array(z.string()),
|
|
7
|
+
registryAddress: z.string(),
|
|
8
|
+
feeAssetHandlerAddress: z.string().optional(),
|
|
9
|
+
l1ChainId: z.number(),
|
|
10
|
+
})
|
|
11
|
+
.passthrough(); // Allow additional unknown fields to pass through
|
|
12
|
+
|
|
13
|
+
export const NetworkConfigMapSchema = z.record(z.string(), NetworkConfigSchema);
|
|
14
|
+
|
|
15
|
+
export type NetworkConfig = z.infer<typeof NetworkConfigSchema>;
|
|
16
|
+
export type NetworkConfigMap = z.infer<typeof NetworkConfigMapSchema>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export type NetworkNames =
|
|
2
|
+
| 'local'
|
|
3
|
+
| 'staging-ignition'
|
|
4
|
+
| 'staging-public'
|
|
5
|
+
| 'testnet'
|
|
6
|
+
| 'mainnet'
|
|
7
|
+
| 'next-net'
|
|
8
|
+
| 'devnet';
|
|
9
|
+
|
|
10
|
+
export function getActiveNetworkName(name?: string): NetworkNames {
|
|
11
|
+
const network = name || process.env.NETWORK;
|
|
12
|
+
if (!network || network === '' || network === 'local') {
|
|
13
|
+
return 'local';
|
|
14
|
+
} else if (network === 'staging-ignition') {
|
|
15
|
+
return network;
|
|
16
|
+
} else if (network === 'staging-public') {
|
|
17
|
+
return network;
|
|
18
|
+
} else if (network === 'testnet' || network === 'alpha-testnet') {
|
|
19
|
+
return 'testnet';
|
|
20
|
+
} else if (network === 'mainnet') {
|
|
21
|
+
return 'mainnet';
|
|
22
|
+
} else if (network === 'next-net') {
|
|
23
|
+
return 'next-net';
|
|
24
|
+
} else if (network === 'devnet') {
|
|
25
|
+
return 'devnet';
|
|
26
|
+
}
|
|
27
|
+
throw new Error(`Unknown network: ${network}`);
|
|
28
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { inspect } from 'util';
|
|
2
|
+
import type { ZodType } from 'zod';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A class wrapping a secret value to protect it from accidently being leaked in logs
|
|
6
|
+
*/
|
|
7
|
+
export class SecretValue<T> {
|
|
8
|
+
/** The secret value. Use a private member field so that it's not visible to the outside */
|
|
9
|
+
#value: T;
|
|
10
|
+
|
|
11
|
+
constructor(
|
|
12
|
+
value: T,
|
|
13
|
+
private readonly redactedValue = '[Redacted]',
|
|
14
|
+
) {
|
|
15
|
+
this.#value = value;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Returns the wrapped value
|
|
20
|
+
*/
|
|
21
|
+
public getValue(): T {
|
|
22
|
+
return this.#value;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Returns a redacted string representation of the value
|
|
27
|
+
*/
|
|
28
|
+
public toString(): string {
|
|
29
|
+
return this.redactedValue;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Returns a redacted string representation of the value
|
|
34
|
+
*/
|
|
35
|
+
public toJSON(): string {
|
|
36
|
+
return this.redactedValue;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
public [inspect.custom]() {
|
|
40
|
+
return this.toString();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Returns a Zod schema
|
|
45
|
+
*/
|
|
46
|
+
static schema<O>(valueSchema: ZodType<O, any, any>): ZodType<SecretValue<O>, any, any> {
|
|
47
|
+
return valueSchema.transform(value => new SecretValue<O>(value));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BarretenbergSync
|
|
1
|
+
import { BarretenbergSync } from '@aztec/bb.js';
|
|
2
2
|
|
|
3
3
|
import { Buffer } from 'buffer';
|
|
4
4
|
|
|
@@ -22,10 +22,15 @@ export class Aes128 {
|
|
|
22
22
|
paddingBuffer.fill(numPaddingBytes);
|
|
23
23
|
const input = Buffer.concat([data, paddingBuffer]);
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
await BarretenbergSync.initSingleton({ wasmPath: process.env.BB_WASM_PATH });
|
|
26
|
+
const api = BarretenbergSync.getSingleton();
|
|
27
|
+
const response = api.aesEncrypt({
|
|
28
|
+
plaintext: input,
|
|
29
|
+
iv,
|
|
30
|
+
key,
|
|
31
|
+
length: input.length,
|
|
32
|
+
});
|
|
33
|
+
return Buffer.from(response.ciphertext);
|
|
29
34
|
}
|
|
30
35
|
|
|
31
36
|
/**
|
|
@@ -37,11 +42,15 @@ export class Aes128 {
|
|
|
37
42
|
* @returns Decrypted data.
|
|
38
43
|
*/
|
|
39
44
|
public async decryptBufferCBCKeepPadding(data: Uint8Array, iv: Uint8Array, key: Uint8Array): Promise<Buffer> {
|
|
40
|
-
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
+
await BarretenbergSync.initSingleton({ wasmPath: process.env.BB_WASM_PATH });
|
|
46
|
+
const api = BarretenbergSync.getSingleton();
|
|
47
|
+
const response = api.aesDecrypt({
|
|
48
|
+
ciphertext: data,
|
|
49
|
+
iv,
|
|
50
|
+
key,
|
|
51
|
+
length: data.length,
|
|
52
|
+
});
|
|
53
|
+
return Buffer.from(response.plaintext);
|
|
45
54
|
}
|
|
46
55
|
|
|
47
56
|
/**
|
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
import { randomBytes } from '@aztec/foundation/crypto';
|
|
2
|
+
|
|
3
|
+
import { createCipheriv, createDecipheriv, createHash, pbkdf2Sync, randomUUID } from 'crypto';
|
|
4
|
+
import { readFileSync } from 'fs';
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* BN254 Keystore Format
|
|
9
|
+
*
|
|
10
|
+
* Implements encryption and decryption of keystores for BN254 BLS private keys
|
|
11
|
+
* using PBKDF2 and AES-128-CTR. This format is inspired by EIP-2335 but adapted
|
|
12
|
+
* for BN254 keys rather than BLS12-381.
|
|
13
|
+
*
|
|
14
|
+
* @see https://eips.ethereum.org/EIPS/eip-2335
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Zod schema for validating BN254 keystore structure
|
|
19
|
+
*/
|
|
20
|
+
const bn254KeystoreSchema = z.object({
|
|
21
|
+
crypto: z.object({
|
|
22
|
+
kdf: z.object({
|
|
23
|
+
function: z.literal('pbkdf2'),
|
|
24
|
+
params: z.object({
|
|
25
|
+
dklen: z.number(),
|
|
26
|
+
c: z.number(),
|
|
27
|
+
prf: z.string(),
|
|
28
|
+
salt: z.string(),
|
|
29
|
+
}),
|
|
30
|
+
message: z.string(),
|
|
31
|
+
}),
|
|
32
|
+
checksum: z.object({
|
|
33
|
+
function: z.literal('sha256'),
|
|
34
|
+
params: z.object({}),
|
|
35
|
+
message: z.string(),
|
|
36
|
+
}),
|
|
37
|
+
cipher: z.object({
|
|
38
|
+
function: z.literal('aes-128-ctr'),
|
|
39
|
+
params: z.object({
|
|
40
|
+
iv: z.string(),
|
|
41
|
+
}),
|
|
42
|
+
message: z.string(),
|
|
43
|
+
}),
|
|
44
|
+
}),
|
|
45
|
+
description: z.string().optional(),
|
|
46
|
+
pubkey: z.string(),
|
|
47
|
+
path: z.string(),
|
|
48
|
+
uuid: z.string(),
|
|
49
|
+
version: z.number(),
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Error thrown when BN254 keystore operations fail
|
|
54
|
+
*/
|
|
55
|
+
export class Bn254KeystoreError extends Error {
|
|
56
|
+
constructor(
|
|
57
|
+
message: string,
|
|
58
|
+
public override cause?: Error,
|
|
59
|
+
) {
|
|
60
|
+
super(message);
|
|
61
|
+
this.name = 'Bn254KeystoreError';
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export type Bn254Keystore = z.infer<typeof bn254KeystoreSchema>;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* The JSON structure of a BN254 keystore file.
|
|
69
|
+
* @deprecated Use the inferred type from bn254KeystoreSchema instead
|
|
70
|
+
*/
|
|
71
|
+
export interface Bn254KeystoreInterface {
|
|
72
|
+
crypto: {
|
|
73
|
+
kdf: {
|
|
74
|
+
function: 'pbkdf2';
|
|
75
|
+
params: {
|
|
76
|
+
dklen: number;
|
|
77
|
+
c: number;
|
|
78
|
+
prf: string;
|
|
79
|
+
salt: string;
|
|
80
|
+
};
|
|
81
|
+
message: string;
|
|
82
|
+
};
|
|
83
|
+
checksum: {
|
|
84
|
+
function: 'sha256';
|
|
85
|
+
params: Record<string, never>;
|
|
86
|
+
message: string;
|
|
87
|
+
};
|
|
88
|
+
cipher: {
|
|
89
|
+
function: 'aes-128-ctr';
|
|
90
|
+
params: {
|
|
91
|
+
iv: string;
|
|
92
|
+
};
|
|
93
|
+
message: string;
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
description: string;
|
|
97
|
+
pubkey: string;
|
|
98
|
+
path: string;
|
|
99
|
+
uuid: string;
|
|
100
|
+
version: number;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Creates a BN254 keystore object for a BN254 BLS private key.
|
|
105
|
+
*
|
|
106
|
+
* Uses PBKDF2 with SHA-256 for key derivation and AES-128-CTR for encryption,
|
|
107
|
+
* following the EIP-2335 specification format.
|
|
108
|
+
*
|
|
109
|
+
* @param password - Password for encrypting the private key
|
|
110
|
+
* @param privateKeyHex - Private key as 0x-prefixed hex string (32 bytes)
|
|
111
|
+
* @param pubkeyHex - Public key as hex string (compressed or uncompressed)
|
|
112
|
+
* @param derivationPath - BIP-44 style derivation path (e.g., "m/12381/3600/0/0/0")
|
|
113
|
+
* @returns BN254 keystore object ready to be serialized to JSON
|
|
114
|
+
* @throws Error if private key is not 32-byte hex
|
|
115
|
+
*/
|
|
116
|
+
export function createBn254Keystore(
|
|
117
|
+
password: string,
|
|
118
|
+
privateKeyHex: string,
|
|
119
|
+
pubkeyHex: string,
|
|
120
|
+
derivationPath: string,
|
|
121
|
+
): Bn254Keystore {
|
|
122
|
+
const ensureHex = (hex: string) => hex.replace(/^0x/i, '');
|
|
123
|
+
const privHex = ensureHex(privateKeyHex);
|
|
124
|
+
if (!/^[0-9a-fA-F]{64}$/.test(privHex)) {
|
|
125
|
+
throw new Error('BLS private key must be 32-byte hex');
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const salt = randomBytes(32);
|
|
129
|
+
const iv = randomBytes(16);
|
|
130
|
+
const dk = pbkdf2Sync(Buffer.from(password.normalize('NFKD'), 'utf8'), salt, 262144, 32, 'sha256');
|
|
131
|
+
const cipherKey = dk.subarray(0, 16);
|
|
132
|
+
|
|
133
|
+
const cipher = createCipheriv('aes-128-ctr', cipherKey, iv);
|
|
134
|
+
const plaintext = Buffer.from(privHex, 'hex');
|
|
135
|
+
const ciphertext = Buffer.concat([cipher.update(plaintext), cipher.final()]);
|
|
136
|
+
|
|
137
|
+
const checksum = createHash('sha256')
|
|
138
|
+
.update(Buffer.concat([dk.subarray(16, 32), ciphertext]))
|
|
139
|
+
.digest();
|
|
140
|
+
|
|
141
|
+
const uuid = randomUUID();
|
|
142
|
+
|
|
143
|
+
return {
|
|
144
|
+
crypto: {
|
|
145
|
+
kdf: {
|
|
146
|
+
function: 'pbkdf2',
|
|
147
|
+
params: { dklen: 32, c: 262144, prf: 'hmac-sha256', salt: salt.toString('hex') },
|
|
148
|
+
message: '',
|
|
149
|
+
},
|
|
150
|
+
checksum: {
|
|
151
|
+
function: 'sha256',
|
|
152
|
+
params: {},
|
|
153
|
+
message: checksum.toString('hex'),
|
|
154
|
+
},
|
|
155
|
+
cipher: {
|
|
156
|
+
function: 'aes-128-ctr',
|
|
157
|
+
params: { iv: iv.toString('hex') },
|
|
158
|
+
message: ciphertext.toString('hex'),
|
|
159
|
+
},
|
|
160
|
+
},
|
|
161
|
+
description: ensureHex(pubkeyHex),
|
|
162
|
+
pubkey: pubkeyHex,
|
|
163
|
+
path: derivationPath ?? '',
|
|
164
|
+
uuid,
|
|
165
|
+
version: 4,
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Loads and validates a BN254 keystore file.
|
|
171
|
+
*
|
|
172
|
+
* @param filePath - Path to the BN254 keystore JSON file
|
|
173
|
+
* @returns Validated keystore object
|
|
174
|
+
* @throws Bn254KeystoreError if file cannot be read or validated
|
|
175
|
+
*/
|
|
176
|
+
export function loadBn254Keystore(filePath: string): Bn254Keystore {
|
|
177
|
+
try {
|
|
178
|
+
const content = readFileSync(filePath, 'utf-8');
|
|
179
|
+
const json = JSON.parse(content);
|
|
180
|
+
return bn254KeystoreSchema.parse(json);
|
|
181
|
+
} catch (error) {
|
|
182
|
+
if (error instanceof SyntaxError) {
|
|
183
|
+
throw new Bn254KeystoreError(`Invalid JSON in keystore file: ${filePath}`, error);
|
|
184
|
+
}
|
|
185
|
+
if (error && typeof error === 'object' && 'issues' in error) {
|
|
186
|
+
const issues = (error as any).issues ?? [];
|
|
187
|
+
const message = issues.map((e: any) => `${e.message} at ${e.path?.join('.') ?? 'root'}`).join('; ');
|
|
188
|
+
throw new Bn254KeystoreError(`Invalid BN254 keystore format: ${message}`);
|
|
189
|
+
}
|
|
190
|
+
throw new Bn254KeystoreError(`Failed to load keystore from ${filePath}: ${String(error)}`, error as Error);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Decrypts a BN254 BLS private key from a keystore file.
|
|
196
|
+
*
|
|
197
|
+
* @param filePath - Path to the BN254 keystore JSON file
|
|
198
|
+
* @param password - Password to decrypt the keystore
|
|
199
|
+
* @returns Decrypted private key as 0x-prefixed hex string (32 bytes)
|
|
200
|
+
* @throws Bn254KeystoreError if decryption fails or checksum is invalid
|
|
201
|
+
*/
|
|
202
|
+
export function decryptBn254Keystore(filePath: string, password: string): string {
|
|
203
|
+
const keystore = loadBn254Keystore(filePath);
|
|
204
|
+
return decryptBn254KeystoreFromObject(keystore, password);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Decrypts a BN254 BLS private key from a keystore object.
|
|
209
|
+
*
|
|
210
|
+
* @param keystore - BN254 keystore object
|
|
211
|
+
* @param password - Password to decrypt the keystore
|
|
212
|
+
* @returns Decrypted private key as 0x-prefixed hex string (32 bytes)
|
|
213
|
+
* @throws Bn254KeystoreError if decryption fails or checksum is invalid
|
|
214
|
+
*/
|
|
215
|
+
export function decryptBn254KeystoreFromObject(keystore: Bn254Keystore, password: string): string {
|
|
216
|
+
try {
|
|
217
|
+
const { crypto } = keystore;
|
|
218
|
+
|
|
219
|
+
// Only support PBKDF2 + AES-128-CTR (as per our implementation)
|
|
220
|
+
if (crypto.kdf.function !== 'pbkdf2') {
|
|
221
|
+
throw new Bn254KeystoreError(`Unsupported KDF function: ${crypto.kdf.function}`);
|
|
222
|
+
}
|
|
223
|
+
if (crypto.cipher.function !== 'aes-128-ctr') {
|
|
224
|
+
throw new Bn254KeystoreError(`Unsupported cipher function: ${crypto.cipher.function}`);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// Derive decryption key using PBKDF2
|
|
228
|
+
const salt = Buffer.from(crypto.kdf.params.salt, 'hex');
|
|
229
|
+
const dk = pbkdf2Sync(
|
|
230
|
+
Buffer.from(password.normalize('NFKD'), 'utf8'),
|
|
231
|
+
salt,
|
|
232
|
+
crypto.kdf.params.c,
|
|
233
|
+
crypto.kdf.params.dklen,
|
|
234
|
+
'sha256',
|
|
235
|
+
);
|
|
236
|
+
|
|
237
|
+
const cipherKey = dk.subarray(0, 16);
|
|
238
|
+
const checksumKey = dk.subarray(16, 32);
|
|
239
|
+
|
|
240
|
+
// Decrypt the ciphertext
|
|
241
|
+
const iv = Buffer.from(crypto.cipher.params.iv, 'hex');
|
|
242
|
+
const ciphertext = Buffer.from(crypto.cipher.message, 'hex');
|
|
243
|
+
const decipher = createDecipheriv('aes-128-ctr', cipherKey, iv);
|
|
244
|
+
const decrypted = Buffer.concat([decipher.update(ciphertext), decipher.final()]);
|
|
245
|
+
|
|
246
|
+
// Verify checksum
|
|
247
|
+
const computedChecksum = createHash('sha256')
|
|
248
|
+
.update(Buffer.concat([checksumKey, ciphertext]))
|
|
249
|
+
.digest();
|
|
250
|
+
const expectedChecksum = Buffer.from(crypto.checksum.message, 'hex');
|
|
251
|
+
|
|
252
|
+
if (!computedChecksum.equals(expectedChecksum)) {
|
|
253
|
+
throw new Bn254KeystoreError('Checksum verification failed - incorrect password or corrupted keystore');
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
// Return as 0x-prefixed hex
|
|
257
|
+
return '0x' + decrypted.toString('hex');
|
|
258
|
+
} catch (error) {
|
|
259
|
+
if (error instanceof Bn254KeystoreError) {
|
|
260
|
+
throw error;
|
|
261
|
+
}
|
|
262
|
+
throw new Bn254KeystoreError(`Failed to decrypt keystore: ${String(error)}`, error as Error);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Validates that a decrypted private key matches the public key in the keystore.
|
|
268
|
+
*
|
|
269
|
+
* @param privateKeyHex - Decrypted private key (0x-prefixed)
|
|
270
|
+
* @param expectedPubkey - Expected public key from keystore
|
|
271
|
+
* @param computePublicKey - Function to compute public key from private key
|
|
272
|
+
* @returns true if keys match, false otherwise
|
|
273
|
+
*/
|
|
274
|
+
export function verifyBn254Keypair(
|
|
275
|
+
privateKeyHex: string,
|
|
276
|
+
expectedPubkey: string,
|
|
277
|
+
computePublicKey: (privateKey: string) => string,
|
|
278
|
+
): boolean {
|
|
279
|
+
try {
|
|
280
|
+
const computedPubkey = computePublicKey(privateKeyHex);
|
|
281
|
+
const normalizedExpected = expectedPubkey.toLowerCase().replace(/^0x/i, '');
|
|
282
|
+
const normalizedComputed = computedPubkey.toLowerCase().replace(/^0x/i, '');
|
|
283
|
+
return normalizedExpected === normalizedComputed;
|
|
284
|
+
} catch {
|
|
285
|
+
return false;
|
|
286
|
+
}
|
|
287
|
+
}
|