@aztec/foundation 0.0.0-test.0
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/README.md +1 -0
- package/dest/array/array.d.ts +71 -0
- package/dest/array/array.d.ts.map +1 -0
- package/dest/array/array.js +100 -0
- package/dest/array/index.d.ts +2 -0
- package/dest/array/index.d.ts.map +1 -0
- package/dest/array/index.js +1 -0
- package/dest/async-map/index.d.ts +13 -0
- package/dest/async-map/index.d.ts.map +1 -0
- package/dest/async-map/index.js +17 -0
- package/dest/async-pool/index.d.ts +3 -0
- package/dest/async-pool/index.d.ts.map +1 -0
- package/dest/async-pool/index.js +47 -0
- package/dest/bigint-buffer/index.d.ts +42 -0
- package/dest/bigint-buffer/index.d.ts.map +1 -0
- package/dest/bigint-buffer/index.js +76 -0
- package/dest/buffer/buffer32.d.ts +91 -0
- package/dest/buffer/buffer32.d.ts.map +1 -0
- package/dest/buffer/buffer32.js +115 -0
- package/dest/buffer/index.d.ts +2 -0
- package/dest/buffer/index.d.ts.map +1 -0
- package/dest/buffer/index.js +1 -0
- package/dest/collection/array.d.ts +101 -0
- package/dest/collection/array.d.ts.map +1 -0
- package/dest/collection/array.js +164 -0
- package/dest/collection/index.d.ts +3 -0
- package/dest/collection/index.d.ts.map +1 -0
- package/dest/collection/index.js +2 -0
- package/dest/collection/object.d.ts +14 -0
- package/dest/collection/object.d.ts.map +1 -0
- package/dest/collection/object.js +32 -0
- package/dest/committable/committable.d.ts +28 -0
- package/dest/committable/committable.d.ts.map +1 -0
- package/dest/committable/committable.js +36 -0
- package/dest/committable/index.d.ts +2 -0
- package/dest/committable/index.d.ts.map +1 -0
- package/dest/committable/index.js +1 -0
- package/dest/config/env_var.d.ts +2 -0
- package/dest/config/env_var.d.ts.map +1 -0
- package/dest/config/env_var.js +1 -0
- package/dest/config/index.d.ts +66 -0
- package/dest/config/index.d.ts.map +1 -0
- package/dest/config/index.js +125 -0
- package/dest/crypto/aes128/index.d.ts +34 -0
- package/dest/crypto/aes128/index.d.ts.map +1 -0
- package/dest/crypto/aes128/index.js +49 -0
- package/dest/crypto/ecdsa/index.d.ts +39 -0
- package/dest/crypto/ecdsa/index.d.ts.map +1 -0
- package/dest/crypto/ecdsa/index.js +88 -0
- package/dest/crypto/ecdsa/signature.d.ts +71 -0
- package/dest/crypto/ecdsa/signature.d.ts.map +1 -0
- package/dest/crypto/ecdsa/signature.js +92 -0
- package/dest/crypto/grumpkin/index.d.ts +47 -0
- package/dest/crypto/grumpkin/index.d.ts.map +1 -0
- package/dest/crypto/grumpkin/index.js +154 -0
- package/dest/crypto/index.d.ts +15 -0
- package/dest/crypto/index.d.ts.map +1 -0
- package/dest/crypto/index.js +14 -0
- package/dest/crypto/keccak/index.d.ts +28 -0
- package/dest/crypto/keccak/index.d.ts.map +1 -0
- package/dest/crypto/keccak/index.js +248 -0
- package/dest/crypto/keys/index.d.ts +5 -0
- package/dest/crypto/keys/index.d.ts.map +1 -0
- package/dest/crypto/keys/index.js +7 -0
- package/dest/crypto/pedersen/index.d.ts +2 -0
- package/dest/crypto/pedersen/index.d.ts.map +1 -0
- package/dest/crypto/pedersen/index.js +1 -0
- package/dest/crypto/pedersen/pedersen.elliptic.d.ts +13 -0
- package/dest/crypto/pedersen/pedersen.elliptic.d.ts.map +1 -0
- package/dest/crypto/pedersen/pedersen.elliptic.js +582 -0
- package/dest/crypto/pedersen/pedersen.noble.d.ts +11 -0
- package/dest/crypto/pedersen/pedersen.noble.d.ts.map +1 -0
- package/dest/crypto/pedersen/pedersen.noble.js +558 -0
- package/dest/crypto/pedersen/pedersen.wasm.d.ts +21 -0
- package/dest/crypto/pedersen/pedersen.wasm.d.ts.map +1 -0
- package/dest/crypto/pedersen/pedersen.wasm.js +41 -0
- package/dest/crypto/poseidon/index.d.ts +26 -0
- package/dest/crypto/poseidon/index.d.ts.map +1 -0
- package/dest/crypto/poseidon/index.js +58 -0
- package/dest/crypto/random/index.d.ts +25 -0
- package/dest/crypto/random/index.d.ts.map +1 -0
- package/dest/crypto/random/index.js +70 -0
- package/dest/crypto/random/randomness_singleton.d.ts +25 -0
- package/dest/crypto/random/randomness_singleton.d.ts.map +1 -0
- package/dest/crypto/random/randomness_singleton.js +55 -0
- package/dest/crypto/schnorr/index.d.ts +30 -0
- package/dest/crypto/schnorr/index.d.ts.map +1 -0
- package/dest/crypto/schnorr/index.js +68 -0
- package/dest/crypto/schnorr/signature.d.ts +70 -0
- package/dest/crypto/schnorr/signature.d.ts.map +1 -0
- package/dest/crypto/schnorr/signature.js +93 -0
- package/dest/crypto/secp256k1/index.d.ts +32 -0
- package/dest/crypto/secp256k1/index.d.ts.map +1 -0
- package/dest/crypto/secp256k1/index.js +116 -0
- package/dest/crypto/secp256k1-signer/index.d.ts +3 -0
- package/dest/crypto/secp256k1-signer/index.d.ts.map +1 -0
- package/dest/crypto/secp256k1-signer/index.js +2 -0
- package/dest/crypto/secp256k1-signer/secp256k1_signer.d.ts +24 -0
- package/dest/crypto/secp256k1-signer/secp256k1_signer.d.ts.map +1 -0
- package/dest/crypto/secp256k1-signer/secp256k1_signer.js +30 -0
- package/dest/crypto/secp256k1-signer/utils.d.ts +40 -0
- package/dest/crypto/secp256k1-signer/utils.d.ts.map +1 -0
- package/dest/crypto/secp256k1-signer/utils.js +84 -0
- package/dest/crypto/serialize.d.ts +53 -0
- package/dest/crypto/serialize.d.ts.map +1 -0
- package/dest/crypto/serialize.js +68 -0
- package/dest/crypto/sha256/index.d.ts +20 -0
- package/dest/crypto/sha256/index.d.ts.map +1 -0
- package/dest/crypto/sha256/index.js +166 -0
- package/dest/crypto/sha512/index.d.ts +11 -0
- package/dest/crypto/sha512/index.d.ts.map +1 -0
- package/dest/crypto/sha512/index.js +12 -0
- package/dest/crypto/signature/index.d.ts +19 -0
- package/dest/crypto/signature/index.d.ts.map +1 -0
- package/dest/crypto/signature/index.js +3 -0
- package/dest/crypto/sync/index.d.ts +3 -0
- package/dest/crypto/sync/index.d.ts.map +1 -0
- package/dest/crypto/sync/index.js +4 -0
- package/dest/crypto/sync/pedersen/index.d.ts +21 -0
- package/dest/crypto/sync/pedersen/index.d.ts.map +1 -0
- package/dest/crypto/sync/pedersen/index.js +38 -0
- package/dest/crypto/sync/poseidon/index.d.ts +26 -0
- package/dest/crypto/sync/poseidon/index.d.ts.map +1 -0
- package/dest/crypto/sync/poseidon/index.js +53 -0
- package/dest/decorators/index.d.ts +2 -0
- package/dest/decorators/index.d.ts.map +1 -0
- package/dest/decorators/index.js +1 -0
- package/dest/decorators/memoize.d.ts +2 -0
- package/dest/decorators/memoize.d.ts.map +1 -0
- package/dest/decorators/memoize.js +11 -0
- package/dest/error/index.d.ts +21 -0
- package/dest/error/index.d.ts.map +1 -0
- package/dest/error/index.js +17 -0
- package/dest/eth-address/index.d.ts +134 -0
- package/dest/eth-address/index.d.ts.map +1 -0
- package/dest/eth-address/index.js +198 -0
- package/dest/eth-signature/eth_signature.d.ts +62 -0
- package/dest/eth-signature/eth_signature.d.ts.map +1 -0
- package/dest/eth-signature/eth_signature.js +91 -0
- package/dest/eth-signature/index.d.ts +2 -0
- package/dest/eth-signature/index.d.ts.map +1 -0
- package/dest/eth-signature/index.js +1 -0
- package/dest/fields/coordinate.d.ts +68 -0
- package/dest/fields/coordinate.d.ts.map +1 -0
- package/dest/fields/coordinate.js +96 -0
- package/dest/fields/fields.d.ts +176 -0
- package/dest/fields/fields.d.ts.map +1 -0
- package/dest/fields/fields.js +383 -0
- package/dest/fields/index.d.ts +4 -0
- package/dest/fields/index.d.ts.map +1 -0
- package/dest/fields/index.js +3 -0
- package/dest/fields/point.d.ts +175 -0
- package/dest/fields/point.d.ts.map +1 -0
- package/dest/fields/point.js +260 -0
- package/dest/fs/index.d.ts +2 -0
- package/dest/fs/index.d.ts.map +1 -0
- package/dest/fs/index.js +1 -0
- package/dest/fs/run_in_dir.d.ts +2 -0
- package/dest/fs/run_in_dir.d.ts.map +1 -0
- package/dest/fs/run_in_dir.js +31 -0
- package/dest/index.d.ts +31 -0
- package/dest/index.d.ts.map +1 -0
- package/dest/index.js +31 -0
- package/dest/iterable/all.d.ts +9 -0
- package/dest/iterable/all.d.ts.map +1 -0
- package/dest/iterable/all.js +18 -0
- package/dest/iterable/filter.d.ts +10 -0
- package/dest/iterable/filter.d.ts.map +1 -0
- package/dest/iterable/filter.js +48 -0
- package/dest/iterable/index.d.ts +8 -0
- package/dest/iterable/index.d.ts.map +1 -0
- package/dest/iterable/index.js +7 -0
- package/dest/iterable/isAsyncIt.d.ts +7 -0
- package/dest/iterable/isAsyncIt.d.ts.map +1 -0
- package/dest/iterable/isAsyncIt.js +7 -0
- package/dest/iterable/map.d.ts +12 -0
- package/dest/iterable/map.d.ts.map +1 -0
- package/dest/iterable/map.js +36 -0
- package/dest/iterable/peek.d.ts +19 -0
- package/dest/iterable/peek.d.ts.map +1 -0
- package/dest/iterable/peek.js +33 -0
- package/dest/iterable/sort.d.ts +14 -0
- package/dest/iterable/sort.d.ts.map +1 -0
- package/dest/iterable/sort.js +15 -0
- package/dest/iterable/take.d.ts +10 -0
- package/dest/iterable/take.d.ts.map +1 -0
- package/dest/iterable/take.js +32 -0
- package/dest/iterable/toArray.d.ts +2 -0
- package/dest/iterable/toArray.d.ts.map +1 -0
- package/dest/iterable/toArray.js +7 -0
- package/dest/jest/setup.js +7 -0
- package/dest/json-rpc/client/fetch.d.ts +32 -0
- package/dest/json-rpc/client/fetch.d.ts.map +1 -0
- package/dest/json-rpc/client/fetch.js +77 -0
- package/dest/json-rpc/client/index.d.ts +3 -0
- package/dest/json-rpc/client/index.d.ts.map +1 -0
- package/dest/json-rpc/client/index.js +2 -0
- package/dest/json-rpc/client/safe_json_rpc_client.d.ts +26 -0
- package/dest/json-rpc/client/safe_json_rpc_client.d.ts.map +1 -0
- package/dest/json-rpc/client/safe_json_rpc_client.js +57 -0
- package/dest/json-rpc/client/undici.d.ts +5 -0
- package/dest/json-rpc/client/undici.d.ts.map +1 -0
- package/dest/json-rpc/client/undici.js +63 -0
- package/dest/json-rpc/convert.d.ts +27 -0
- package/dest/json-rpc/convert.d.ts.map +1 -0
- package/dest/json-rpc/convert.js +48 -0
- package/dest/json-rpc/fixtures/class_a.d.ts +11 -0
- package/dest/json-rpc/fixtures/class_a.d.ts.map +1 -0
- package/dest/json-rpc/fixtures/class_a.js +20 -0
- package/dest/json-rpc/fixtures/class_b.d.ts +11 -0
- package/dest/json-rpc/fixtures/class_b.d.ts.map +1 -0
- package/dest/json-rpc/fixtures/class_b.js +20 -0
- package/dest/json-rpc/fixtures/test_state.d.ts +89 -0
- package/dest/json-rpc/fixtures/test_state.d.ts.map +1 -0
- package/dest/json-rpc/fixtures/test_state.js +131 -0
- package/dest/json-rpc/index.d.ts +2 -0
- package/dest/json-rpc/index.d.ts.map +1 -0
- package/dest/json-rpc/index.js +1 -0
- package/dest/json-rpc/js_utils.d.ts +13 -0
- package/dest/json-rpc/js_utils.d.ts.map +1 -0
- package/dest/json-rpc/js_utils.js +16 -0
- package/dest/json-rpc/server/index.d.ts +2 -0
- package/dest/json-rpc/server/index.d.ts.map +1 -0
- package/dest/json-rpc/server/index.js +1 -0
- package/dest/json-rpc/server/safe_json_rpc_server.d.ts +140 -0
- package/dest/json-rpc/server/safe_json_rpc_server.d.ts.map +1 -0
- package/dest/json-rpc/server/safe_json_rpc_server.js +346 -0
- package/dest/json-rpc/server/telemetry.d.ts +2 -0
- package/dest/json-rpc/server/telemetry.d.ts.map +1 -0
- package/dest/json-rpc/server/telemetry.js +0 -0
- package/dest/json-rpc/test/index.d.ts +2 -0
- package/dest/json-rpc/test/index.d.ts.map +1 -0
- package/dest/json-rpc/test/index.js +1 -0
- package/dest/json-rpc/test/integration.d.ts +15 -0
- package/dest/json-rpc/test/integration.d.ts.map +1 -0
- package/dest/json-rpc/test/integration.js +21 -0
- package/dest/log/console.d.ts +11 -0
- package/dest/log/console.d.ts.map +1 -0
- package/dest/log/console.js +36 -0
- package/dest/log/debug.d.ts +56 -0
- package/dest/log/debug.d.ts.map +1 -0
- package/dest/log/debug.js +75 -0
- package/dest/log/gcloud-logger-config.d.ts +14 -0
- package/dest/log/gcloud-logger-config.d.ts.map +1 -0
- package/dest/log/gcloud-logger-config.js +66 -0
- package/dest/log/index.d.ts +7 -0
- package/dest/log/index.d.ts.map +1 -0
- package/dest/log/index.js +6 -0
- package/dest/log/libp2p_logger.d.ts +7 -0
- package/dest/log/libp2p_logger.d.ts.map +1 -0
- package/dest/log/libp2p_logger.js +55 -0
- package/dest/log/log-filters.d.ts +7 -0
- package/dest/log/log-filters.d.ts.map +1 -0
- package/dest/log/log-filters.js +59 -0
- package/dest/log/log-levels.d.ts +3 -0
- package/dest/log/log-levels.d.ts.map +1 -0
- package/dest/log/log-levels.js +10 -0
- package/dest/log/log_fn.d.ts +7 -0
- package/dest/log/log_fn.d.ts.map +1 -0
- package/dest/log/log_fn.js +1 -0
- package/dest/log/log_history.d.ts +31 -0
- package/dest/log/log_history.d.ts.map +1 -0
- package/dest/log/log_history.js +38 -0
- package/dest/log/pino-logger.d.ts +57 -0
- package/dest/log/pino-logger.d.ts.map +1 -0
- package/dest/log/pino-logger.js +207 -0
- package/dest/message/index.d.ts +32 -0
- package/dest/message/index.d.ts.map +1 -0
- package/dest/message/index.js +27 -0
- package/dest/mutex/index.d.ts +53 -0
- package/dest/mutex/index.d.ts.map +1 -0
- package/dest/mutex/index.js +78 -0
- package/dest/mutex/mutex_database.d.ts +10 -0
- package/dest/mutex/mutex_database.d.ts.map +1 -0
- package/dest/mutex/mutex_database.js +4 -0
- package/dest/noir/index.d.ts +2 -0
- package/dest/noir/index.d.ts.map +1 -0
- package/dest/noir/index.js +1 -0
- package/dest/noir/noir_package_config.d.ts +129 -0
- package/dest/noir/noir_package_config.d.ts.map +1 -0
- package/dest/noir/noir_package_config.js +36 -0
- package/dest/promise/index.d.ts +3 -0
- package/dest/promise/index.d.ts.map +1 -0
- package/dest/promise/index.js +2 -0
- package/dest/promise/running-promise.d.ts +47 -0
- package/dest/promise/running-promise.d.ts.map +1 -0
- package/dest/promise/running-promise.js +110 -0
- package/dest/promise/utils.d.ts +12 -0
- package/dest/promise/utils.d.ts.map +1 -0
- package/dest/promise/utils.js +20 -0
- package/dest/queue/base_memory_queue.d.ts +65 -0
- package/dest/queue/base_memory_queue.d.ts.map +1 -0
- package/dest/queue/base_memory_queue.js +116 -0
- package/dest/queue/batch_queue.d.ts +47 -0
- package/dest/queue/batch_queue.d.ts.map +1 -0
- package/dest/queue/batch_queue.js +105 -0
- package/dest/queue/bounded_serial_queue.d.ts +56 -0
- package/dest/queue/bounded_serial_queue.d.ts.map +1 -0
- package/dest/queue/bounded_serial_queue.js +84 -0
- package/dest/queue/fifo_memory_queue.d.ts +21 -0
- package/dest/queue/fifo_memory_queue.d.ts.map +1 -0
- package/dest/queue/fifo_memory_queue.js +29 -0
- package/dest/queue/index.d.ts +7 -0
- package/dest/queue/index.d.ts.map +1 -0
- package/dest/queue/index.js +6 -0
- package/dest/queue/priority_memory_queue.d.ts +13 -0
- package/dest/queue/priority_memory_queue.d.ts.map +1 -0
- package/dest/queue/priority_memory_queue.js +16 -0
- package/dest/queue/priority_queue.d.ts +14 -0
- package/dest/queue/priority_queue.d.ts.map +1 -0
- package/dest/queue/priority_queue.js +29 -0
- package/dest/queue/semaphore.d.ts +23 -0
- package/dest/queue/semaphore.d.ts.map +1 -0
- package/dest/queue/semaphore.js +26 -0
- package/dest/queue/serial_queue.d.ts +49 -0
- package/dest/queue/serial_queue.d.ts.map +1 -0
- package/dest/queue/serial_queue.js +72 -0
- package/dest/retry/index.d.ts +44 -0
- package/dest/retry/index.d.ts.map +1 -0
- package/dest/retry/index.js +93 -0
- package/dest/running-promise/index.d.ts +2 -0
- package/dest/running-promise/index.d.ts.map +1 -0
- package/dest/running-promise/index.js +1 -0
- package/dest/schemas/api.d.ts +21 -0
- package/dest/schemas/api.d.ts.map +1 -0
- package/dest/schemas/api.js +3 -0
- package/dest/schemas/index.d.ts +6 -0
- package/dest/schemas/index.d.ts.map +1 -0
- package/dest/schemas/index.js +5 -0
- package/dest/schemas/parse.d.ts +9 -0
- package/dest/schemas/parse.d.ts.map +1 -0
- package/dest/schemas/parse.js +22 -0
- package/dest/schemas/schemas.d.ts +45 -0
- package/dest/schemas/schemas.d.ts.map +1 -0
- package/dest/schemas/schemas.js +38 -0
- package/dest/schemas/types.d.ts +3 -0
- package/dest/schemas/types.d.ts.map +1 -0
- package/dest/schemas/types.js +1 -0
- package/dest/schemas/utils.d.ts +53 -0
- package/dest/schemas/utils.d.ts.map +1 -0
- package/dest/schemas/utils.js +60 -0
- package/dest/serialize/buffer_reader.d.ts +239 -0
- package/dest/serialize/buffer_reader.d.ts.map +1 -0
- package/dest/serialize/buffer_reader.js +290 -0
- package/dest/serialize/field_reader.d.ts +112 -0
- package/dest/serialize/field_reader.d.ts.map +1 -0
- package/dest/serialize/field_reader.js +147 -0
- package/dest/serialize/free_funcs.d.ts +105 -0
- package/dest/serialize/free_funcs.d.ts.map +1 -0
- package/dest/serialize/free_funcs.js +189 -0
- package/dest/serialize/index.d.ts +7 -0
- package/dest/serialize/index.d.ts.map +1 -0
- package/dest/serialize/index.js +6 -0
- package/dest/serialize/serialize.d.ts +182 -0
- package/dest/serialize/serialize.d.ts.map +1 -0
- package/dest/serialize/serialize.js +248 -0
- package/dest/serialize/type_registry.d.ts +23 -0
- package/dest/serialize/type_registry.d.ts.map +1 -0
- package/dest/serialize/type_registry.js +61 -0
- package/dest/serialize/types.d.ts +33 -0
- package/dest/serialize/types.d.ts.map +1 -0
- package/dest/serialize/types.js +21 -0
- package/dest/sleep/index.d.ts +51 -0
- package/dest/sleep/index.d.ts.map +1 -0
- package/dest/sleep/index.js +67 -0
- package/dest/string/index.d.ts +11 -0
- package/dest/string/index.d.ts.map +1 -0
- package/dest/string/index.js +24 -0
- package/dest/testing/files/index.d.ts +20 -0
- package/dest/testing/files/index.d.ts.map +1 -0
- package/dest/testing/files/index.js +58 -0
- package/dest/testing/index.d.ts +4 -0
- package/dest/testing/index.d.ts.map +1 -0
- package/dest/testing/index.js +3 -0
- package/dest/testing/port_allocator.d.ts +10 -0
- package/dest/testing/port_allocator.d.ts.map +1 -0
- package/dest/testing/port_allocator.js +29 -0
- package/dest/testing/snapshot_serializer.d.ts +5 -0
- package/dest/testing/snapshot_serializer.d.ts.map +1 -0
- package/dest/testing/snapshot_serializer.js +32 -0
- package/dest/testing/test_data.d.ts +7 -0
- package/dest/testing/test_data.d.ts.map +1 -0
- package/dest/testing/test_data.js +29 -0
- package/dest/timer/date.d.ts +13 -0
- package/dest/timer/date.d.ts.map +1 -0
- package/dest/timer/date.js +24 -0
- package/dest/timer/elapsed.d.ts +13 -0
- package/dest/timer/elapsed.d.ts.map +1 -0
- package/dest/timer/elapsed.js +25 -0
- package/dest/timer/index.d.ts +5 -0
- package/dest/timer/index.d.ts.map +1 -0
- package/dest/timer/index.js +4 -0
- package/dest/timer/timeout.d.ts +41 -0
- package/dest/timer/timeout.d.ts.map +1 -0
- package/dest/timer/timeout.js +66 -0
- package/dest/timer/timer.d.ts +37 -0
- package/dest/timer/timer.d.ts.map +1 -0
- package/dest/timer/timer.js +40 -0
- package/dest/transport/browser/index.d.ts +5 -0
- package/dest/transport/browser/index.d.ts.map +1 -0
- package/dest/transport/browser/index.js +4 -0
- package/dest/transport/browser/message_port_socket.d.ts +37 -0
- package/dest/transport/browser/message_port_socket.d.ts.map +1 -0
- package/dest/transport/browser/message_port_socket.js +42 -0
- package/dest/transport/browser/shared_worker_connector.d.ts +19 -0
- package/dest/transport/browser/shared_worker_connector.d.ts.map +1 -0
- package/dest/transport/browser/shared_worker_connector.js +19 -0
- package/dest/transport/browser/shared_worker_listener.d.ts +38 -0
- package/dest/transport/browser/shared_worker_listener.d.ts.map +1 -0
- package/dest/transport/browser/shared_worker_listener.js +33 -0
- package/dest/transport/browser/worker_connector.d.ts +26 -0
- package/dest/transport/browser/worker_connector.d.ts.map +1 -0
- package/dest/transport/browser/worker_connector.js +30 -0
- package/dest/transport/browser/worker_listener.d.ts +39 -0
- package/dest/transport/browser/worker_listener.d.ts.map +1 -0
- package/dest/transport/browser/worker_listener.js +35 -0
- package/dest/transport/dispatch/create_dispatch_fn.d.ts +25 -0
- package/dest/transport/dispatch/create_dispatch_fn.d.ts.map +1 -0
- package/dest/transport/dispatch/create_dispatch_fn.js +17 -0
- package/dest/transport/dispatch/create_dispatch_proxy.d.ts +102 -0
- package/dest/transport/dispatch/create_dispatch_proxy.d.ts.map +1 -0
- package/dest/transport/dispatch/create_dispatch_proxy.js +59 -0
- package/dest/transport/dispatch/messages.d.ts +52 -0
- package/dest/transport/dispatch/messages.d.ts.map +1 -0
- package/dest/transport/dispatch/messages.js +13 -0
- package/dest/transport/index.d.ts +12 -0
- package/dest/transport/index.d.ts.map +1 -0
- package/dest/transport/index.js +11 -0
- package/dest/transport/interface/connector.d.ts +8 -0
- package/dest/transport/interface/connector.d.ts.map +1 -0
- package/dest/transport/interface/connector.js +3 -0
- package/dest/transport/interface/listener.d.ts +13 -0
- package/dest/transport/interface/listener.d.ts.map +1 -0
- package/dest/transport/interface/listener.js +4 -0
- package/dest/transport/interface/socket.d.ts +13 -0
- package/dest/transport/interface/socket.d.ts.map +1 -0
- package/dest/transport/interface/socket.js +7 -0
- package/dest/transport/interface/transferable.d.ts +68 -0
- package/dest/transport/interface/transferable.d.ts.map +1 -0
- package/dest/transport/interface/transferable.js +63 -0
- package/dest/transport/node/index.d.ts +3 -0
- package/dest/transport/node/index.d.ts.map +1 -0
- package/dest/transport/node/index.js +2 -0
- package/dest/transport/node/node_connector.d.ts +28 -0
- package/dest/transport/node/node_connector.d.ts.map +1 -0
- package/dest/transport/node/node_connector.js +26 -0
- package/dest/transport/node/node_connector_socket.d.ts +42 -0
- package/dest/transport/node/node_connector_socket.d.ts.map +1 -0
- package/dest/transport/node/node_connector_socket.js +44 -0
- package/dest/transport/node/node_listener.d.ts +26 -0
- package/dest/transport/node/node_listener.d.ts.map +1 -0
- package/dest/transport/node/node_listener.js +26 -0
- package/dest/transport/node/node_listener_socket.d.ts +37 -0
- package/dest/transport/node/node_listener_socket.d.ts.map +1 -0
- package/dest/transport/node/node_listener_socket.js +40 -0
- package/dest/transport/transport_client.d.ts +61 -0
- package/dest/transport/transport_client.d.ts.map +1 -0
- package/dest/transport/transport_client.js +96 -0
- package/dest/transport/transport_server.d.ts +56 -0
- package/dest/transport/transport_server.d.ts.map +1 -0
- package/dest/transport/transport_server.js +114 -0
- package/dest/trees/hasher.d.ts +39 -0
- package/dest/trees/hasher.d.ts.map +1 -0
- package/dest/trees/hasher.js +5 -0
- package/dest/trees/index.d.ts +11 -0
- package/dest/trees/index.d.ts.map +1 -0
- package/dest/trees/index.js +10 -0
- package/dest/trees/indexed_merkle_tree.d.ts +13 -0
- package/dest/trees/indexed_merkle_tree.d.ts.map +1 -0
- package/dest/trees/indexed_merkle_tree.js +27 -0
- package/dest/trees/indexed_merkle_tree_calculator.d.ts +23 -0
- package/dest/trees/indexed_merkle_tree_calculator.d.ts.map +1 -0
- package/dest/trees/indexed_merkle_tree_calculator.js +83 -0
- package/dest/trees/indexed_tree_leaf.d.ts +57 -0
- package/dest/trees/indexed_tree_leaf.d.ts.map +1 -0
- package/dest/trees/indexed_tree_leaf.js +5 -0
- package/dest/trees/membership_witness.d.ts +62 -0
- package/dest/trees/membership_witness.d.ts.map +1 -0
- package/dest/trees/membership_witness.js +70 -0
- package/dest/trees/merkle_tree.d.ts +18 -0
- package/dest/trees/merkle_tree.d.ts.map +1 -0
- package/dest/trees/merkle_tree.js +58 -0
- package/dest/trees/merkle_tree_calculator.d.ts +16 -0
- package/dest/trees/merkle_tree_calculator.d.ts.map +1 -0
- package/dest/trees/merkle_tree_calculator.js +61 -0
- package/dest/trees/sibling_path.d.ts +132 -0
- package/dest/trees/sibling_path.d.ts.map +1 -0
- package/dest/trees/sibling_path.js +144 -0
- package/dest/trees/unbalanced_merkle_tree.d.ts +17 -0
- package/dest/trees/unbalanced_merkle_tree.d.ts.map +1 -0
- package/dest/trees/unbalanced_merkle_tree.js +100 -0
- package/dest/trees/unbalanced_tree_store.d.ts +19 -0
- package/dest/trees/unbalanced_tree_store.d.ts.map +1 -0
- package/dest/trees/unbalanced_tree_store.js +94 -0
- package/dest/types/index.d.ts +19 -0
- package/dest/types/index.d.ts.map +1 -0
- package/dest/types/index.js +3 -0
- package/dest/url/index.d.ts +9 -0
- package/dest/url/index.d.ts.map +1 -0
- package/dest/url/index.js +62 -0
- package/dest/validation/index.d.ts +9 -0
- package/dest/validation/index.d.ts.map +1 -0
- package/dest/validation/index.js +15 -0
- package/dest/wasm/empty_wasi_sdk.d.ts +130 -0
- package/dest/wasm/empty_wasi_sdk.d.ts.map +1 -0
- package/dest/wasm/empty_wasi_sdk.js +148 -0
- package/dest/wasm/index.d.ts +2 -0
- package/dest/wasm/index.d.ts.map +1 -0
- package/dest/wasm/index.js +1 -0
- package/dest/wasm/wasm_module.d.ts +136 -0
- package/dest/wasm/wasm_module.d.ts.map +1 -0
- package/dest/wasm/wasm_module.js +196 -0
- package/dest/worker/browser/index.d.ts +3 -0
- package/dest/worker/browser/index.d.ts.map +1 -0
- package/dest/worker/browser/index.js +2 -0
- package/dest/worker/browser/start_web_module.d.ts +7 -0
- package/dest/worker/browser/start_web_module.d.ts.map +1 -0
- package/dest/worker/browser/start_web_module.js +27 -0
- package/dest/worker/browser/web_data_store.d.ts +24 -0
- package/dest/worker/browser/web_data_store.d.ts.map +1 -0
- package/dest/worker/browser/web_data_store.js +29 -0
- package/dest/worker/browser/web_worker.d.ts +10 -0
- package/dest/worker/browser/web_worker.d.ts.map +1 -0
- package/dest/worker/browser/web_worker.js +25 -0
- package/dest/worker/data_store.d.ts +21 -0
- package/dest/worker/data_store.d.ts.map +1 -0
- package/dest/worker/data_store.js +3 -0
- package/dest/worker/index.d.ts +3 -0
- package/dest/worker/index.d.ts.map +1 -0
- package/dest/worker/index.js +1 -0
- package/dest/worker/node/index.d.ts +3 -0
- package/dest/worker/node/index.d.ts.map +1 -0
- package/dest/worker/node/index.js +2 -0
- package/dest/worker/node/node_data_store.d.ts +13 -0
- package/dest/worker/node/node_data_store.d.ts.map +1 -0
- package/dest/worker/node/node_data_store.js +20 -0
- package/dest/worker/node/node_worker.d.ts +6 -0
- package/dest/worker/node/node_worker.d.ts.map +1 -0
- package/dest/worker/node/node_worker.js +22 -0
- package/dest/worker/node/start_node_module.d.ts +7 -0
- package/dest/worker/node/start_node_module.d.ts.map +1 -0
- package/dest/worker/node/start_node_module.js +31 -0
- package/dest/worker/wasm_worker.d.ts +9 -0
- package/dest/worker/wasm_worker.d.ts.map +1 -0
- package/dest/worker/wasm_worker.js +3 -0
- package/dest/worker/worker_pool.d.ts +40 -0
- package/dest/worker/worker_pool.d.ts.map +1 -0
- package/dest/worker/worker_pool.js +51 -0
- package/package.json +176 -0
- package/src/array/array.ts +150 -0
- package/src/array/index.ts +1 -0
- package/src/async-map/index.ts +18 -0
- package/src/async-pool/index.ts +50 -0
- package/src/bigint-buffer/index.ts +87 -0
- package/src/buffer/buffer32.ts +144 -0
- package/src/buffer/index.ts +1 -0
- package/src/collection/array.ts +203 -0
- package/src/collection/index.ts +2 -0
- package/src/collection/object.ts +52 -0
- package/src/committable/committable.ts +46 -0
- package/src/committable/index.ts +1 -0
- package/src/config/env_var.ts +207 -0
- package/src/config/index.ts +167 -0
- package/src/crypto/aes128/index.ts +59 -0
- package/src/crypto/ecdsa/index.ts +70 -0
- package/src/crypto/ecdsa/signature.ts +100 -0
- package/src/crypto/grumpkin/index.ts +97 -0
- package/src/crypto/index.ts +14 -0
- package/src/crypto/keccak/index.ts +283 -0
- package/src/crypto/keys/index.ts +10 -0
- package/src/crypto/pedersen/index.ts +1 -0
- package/src/crypto/pedersen/pedersen.elliptic.ts +584 -0
- package/src/crypto/pedersen/pedersen.noble.ts +573 -0
- package/src/crypto/pedersen/pedersen.wasm.ts +48 -0
- package/src/crypto/poseidon/index.ts +77 -0
- package/src/crypto/random/index.ts +85 -0
- package/src/crypto/random/randomness_singleton.ts +62 -0
- package/src/crypto/schnorr/index.ts +55 -0
- package/src/crypto/schnorr/signature.ts +116 -0
- package/src/crypto/secp256k1/index.ts +57 -0
- package/src/crypto/secp256k1-signer/index.ts +2 -0
- package/src/crypto/secp256k1-signer/secp256k1_signer.ts +38 -0
- package/src/crypto/secp256k1-signer/utils.ts +99 -0
- package/src/crypto/serialize.ts +85 -0
- package/src/crypto/sha256/index.ts +147 -0
- package/src/crypto/sha512/index.ts +16 -0
- package/src/crypto/signature/index.ts +17 -0
- package/src/crypto/sync/index.ts +6 -0
- package/src/crypto/sync/pedersen/index.ts +45 -0
- package/src/crypto/sync/poseidon/index.ts +76 -0
- package/src/decorators/index.ts +1 -0
- package/src/decorators/memoize.ts +11 -0
- package/src/error/index.ts +22 -0
- package/src/eth-address/index.ts +241 -0
- package/src/eth-signature/eth_signature.ts +128 -0
- package/src/eth-signature/index.ts +1 -0
- package/src/fields/coordinate.ts +104 -0
- package/src/fields/fields.ts +505 -0
- package/src/fields/index.ts +3 -0
- package/src/fields/point.ts +300 -0
- package/src/fs/index.ts +1 -0
- package/src/fs/run_in_dir.ts +33 -0
- package/src/index.ts +31 -0
- package/src/iterable/all.ts +32 -0
- package/src/iterable/filter.ts +77 -0
- package/src/iterable/index.ts +7 -0
- package/src/iterable/isAsyncIt.ts +8 -0
- package/src/iterable/map.ts +66 -0
- package/src/iterable/peek.ts +58 -0
- package/src/iterable/sort.ts +39 -0
- package/src/iterable/take.ts +54 -0
- package/src/iterable/toArray.ts +9 -0
- package/src/jest/setup.mjs +9 -0
- package/src/json-rpc/README.md +55 -0
- package/src/json-rpc/client/fetch.ts +103 -0
- package/src/json-rpc/client/index.ts +2 -0
- package/src/json-rpc/client/safe_json_rpc_client.ts +67 -0
- package/src/json-rpc/client/undici.ts +75 -0
- package/src/json-rpc/convert.ts +61 -0
- package/src/json-rpc/fixtures/class_a.ts +15 -0
- package/src/json-rpc/fixtures/class_b.ts +15 -0
- package/src/json-rpc/fixtures/test_state.ts +143 -0
- package/src/json-rpc/index.ts +1 -0
- package/src/json-rpc/js_utils.ts +21 -0
- package/src/json-rpc/server/index.ts +1 -0
- package/src/json-rpc/server/safe_json_rpc_server.ts +376 -0
- package/src/json-rpc/server/telemetry.ts +0 -0
- package/src/json-rpc/test/index.ts +1 -0
- package/src/json-rpc/test/integration.ts +35 -0
- package/src/log/console.ts +39 -0
- package/src/log/debug.ts +104 -0
- package/src/log/gcloud-logger-config.ts +71 -0
- package/src/log/index.ts +6 -0
- package/src/log/libp2p_logger.ts +67 -0
- package/src/log/log-filters.ts +63 -0
- package/src/log/log-levels.ts +3 -0
- package/src/log/log_fn.ts +5 -0
- package/src/log/log_history.ts +44 -0
- package/src/log/pino-logger.ts +243 -0
- package/src/message/index.ts +43 -0
- package/src/mutex/index.ts +84 -0
- package/src/mutex/mutex_database.ts +12 -0
- package/src/noir/index.ts +1 -0
- package/src/noir/noir_package_config.ts +54 -0
- package/src/promise/index.ts +2 -0
- package/src/promise/running-promise.ts +125 -0
- package/src/promise/utils.ts +29 -0
- package/src/queue/base_memory_queue.ts +138 -0
- package/src/queue/batch_queue.ts +120 -0
- package/src/queue/bounded_serial_queue.ts +100 -0
- package/src/queue/fifo_memory_queue.ts +39 -0
- package/src/queue/index.ts +6 -0
- package/src/queue/priority_memory_queue.ts +20 -0
- package/src/queue/priority_queue.ts +34 -0
- package/src/queue/semaphore.ts +33 -0
- package/src/queue/serial_queue.ts +86 -0
- package/src/retry/index.ts +100 -0
- package/src/running-promise/index.ts +1 -0
- package/src/schemas/api.ts +47 -0
- package/src/schemas/index.ts +5 -0
- package/src/schemas/parse.ts +29 -0
- package/src/schemas/schemas.ts +64 -0
- package/src/schemas/types.ts +3 -0
- package/src/schemas/utils.ts +112 -0
- package/src/serialize/buffer_reader.ts +383 -0
- package/src/serialize/field_reader.ts +184 -0
- package/src/serialize/free_funcs.ts +204 -0
- package/src/serialize/index.ts +6 -0
- package/src/serialize/serialize.ts +336 -0
- package/src/serialize/type_registry.ts +75 -0
- package/src/serialize/types.ts +40 -0
- package/src/sleep/index.ts +75 -0
- package/src/string/index.ts +31 -0
- package/src/testing/files/index.ts +69 -0
- package/src/testing/index.ts +3 -0
- package/src/testing/port_allocator.ts +31 -0
- package/src/testing/snapshot_serializer.ts +33 -0
- package/src/testing/test_data.ts +36 -0
- package/src/timer/date.ts +24 -0
- package/src/timer/elapsed.ts +23 -0
- package/src/timer/index.ts +4 -0
- package/src/timer/timeout.ts +70 -0
- package/src/timer/timer.ts +48 -0
- package/src/transport/browser/index.ts +4 -0
- package/src/transport/browser/message_port_socket.ts +48 -0
- package/src/transport/browser/shared_worker_connector.ts +21 -0
- package/src/transport/browser/shared_worker_listener.ts +53 -0
- package/src/transport/browser/worker_connector.ts +30 -0
- package/src/transport/browser/worker_listener.ts +54 -0
- package/src/transport/dispatch/create_dispatch_fn.ts +35 -0
- package/src/transport/dispatch/create_dispatch_proxy.ts +141 -0
- package/src/transport/dispatch/messages.ts +58 -0
- package/src/transport/index.ts +11 -0
- package/src/transport/interface/connector.ts +9 -0
- package/src/transport/interface/listener.ts +16 -0
- package/src/transport/interface/socket.ts +15 -0
- package/src/transport/interface/transferable.ts +125 -0
- package/src/transport/node/index.ts +2 -0
- package/src/transport/node/node_connector.ts +30 -0
- package/src/transport/node/node_connector_socket.ts +52 -0
- package/src/transport/node/node_listener.ts +34 -0
- package/src/transport/node/node_listener_socket.ts +48 -0
- package/src/transport/transport_client.ts +131 -0
- package/src/transport/transport_server.ts +108 -0
- package/src/trees/hasher.ts +39 -0
- package/src/trees/index.ts +10 -0
- package/src/trees/indexed_merkle_tree.ts +36 -0
- package/src/trees/indexed_merkle_tree_calculator.ts +94 -0
- package/src/trees/indexed_tree_leaf.ts +56 -0
- package/src/trees/membership_witness.ts +99 -0
- package/src/trees/merkle_tree.ts +72 -0
- package/src/trees/merkle_tree_calculator.ts +67 -0
- package/src/trees/sibling_path.ts +183 -0
- package/src/trees/unbalanced_merkle_tree.ts +103 -0
- package/src/trees/unbalanced_tree_store.ts +102 -0
- package/src/types/index.ts +25 -0
- package/src/url/index.ts +73 -0
- package/src/validation/index.ts +18 -0
- package/src/wasm/README.md +6 -0
- package/src/wasm/empty_wasi_sdk.ts +166 -0
- package/src/wasm/fixtures/gcd.wasm +0 -0
- package/src/wasm/fixtures/gcd.wat +27 -0
- package/src/wasm/index.ts +1 -0
- package/src/wasm/wasm_module.ts +260 -0
- package/src/worker/browser/index.ts +2 -0
- package/src/worker/browser/start_web_module.ts +24 -0
- package/src/worker/browser/web_data_store.ts +38 -0
- package/src/worker/browser/web_worker.ts +25 -0
- package/src/worker/data_store.ts +19 -0
- package/src/worker/index.ts +2 -0
- package/src/worker/node/index.ts +2 -0
- package/src/worker/node/node_data_store.ts +27 -0
- package/src/worker/node/node_worker.ts +23 -0
- package/src/worker/node/start_node_module.ts +30 -0
- package/src/worker/wasm_worker.ts +7 -0
- package/src/worker/worker_pool.ts +73 -0
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { makeTuple } from '../array/array.js';
|
|
2
|
+
import { pedersenHash } from '../crypto/index.js';
|
|
3
|
+
import { Fr } from '../fields/index.js';
|
|
4
|
+
import { schemas } from '../schemas/index.js';
|
|
5
|
+
import { assertLength, deserializeArrayFromVector, serializeArrayOfBufferableToVector } from '../serialize/index.js';
|
|
6
|
+
import { bufferToHex, hexToBuffer } from '../string/index.js';
|
|
7
|
+
/**
|
|
8
|
+
* Contains functionality to compute and serialize/deserialize a sibling path.
|
|
9
|
+
* E.g. Sibling path for a leaf at index 3 in a tree of depth 3 consists of:
|
|
10
|
+
* d0: [ root ]
|
|
11
|
+
* d1: [ ] [*]
|
|
12
|
+
* d2: [*] [ ] [ ] [ ]
|
|
13
|
+
* d3: [ ] [ ] [*] [ ] [ ] [ ] [ ] [ ].
|
|
14
|
+
*
|
|
15
|
+
* And the elements would be ordered as: [ leaf_at_index_2, node_at_level_2_index_0, node_at_level_1_index_1 ].
|
|
16
|
+
*/ export class SiblingPath {
|
|
17
|
+
pathSize;
|
|
18
|
+
data;
|
|
19
|
+
/**
|
|
20
|
+
* Constructor.
|
|
21
|
+
* @param pathSize - The size of the sibling path.
|
|
22
|
+
* @param path - The sibling path data.
|
|
23
|
+
*/ constructor(/** Size of the sibling path (number of fields it contains). */ pathSize, /** The sibling path data. */ path){
|
|
24
|
+
this.pathSize = pathSize;
|
|
25
|
+
this.data = assertLength(path, pathSize);
|
|
26
|
+
}
|
|
27
|
+
static get schema() {
|
|
28
|
+
return schemas.Buffer.transform((b)=>SiblingPath.fromBuffer(b));
|
|
29
|
+
}
|
|
30
|
+
static schemaFor(size) {
|
|
31
|
+
return schemas.Buffer.transform((b)=>SiblingPath.fromBuffer(b)).refine((path)=>path.pathSize === size, (path)=>({
|
|
32
|
+
message: `Expected sibling path size ${size} but got ${path.pathSize}`
|
|
33
|
+
}));
|
|
34
|
+
}
|
|
35
|
+
toJSON() {
|
|
36
|
+
return this.toBuffer();
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Returns sibling path hashed up from the a element.
|
|
40
|
+
* @param size - The number of elements in a given path.
|
|
41
|
+
* @param zeroElement - Value of the zero element.
|
|
42
|
+
* @param hasher - Implementation of a hasher interface.
|
|
43
|
+
* @returns A sibling path hashed up from a zero element.
|
|
44
|
+
*/ static ZERO(size, zeroElement, hasher) {
|
|
45
|
+
const bufs = [];
|
|
46
|
+
let current = zeroElement;
|
|
47
|
+
for(let i = 0; i < size; ++i){
|
|
48
|
+
bufs.push(current);
|
|
49
|
+
current = hasher.hash(current, current);
|
|
50
|
+
}
|
|
51
|
+
return new SiblingPath(size, bufs);
|
|
52
|
+
}
|
|
53
|
+
static random(number) {
|
|
54
|
+
const data = Array.from({
|
|
55
|
+
length: number
|
|
56
|
+
}, ()=>Fr.random().toBuffer());
|
|
57
|
+
return new SiblingPath(number, data);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Serializes this SiblingPath object to a buffer.
|
|
61
|
+
* @returns The buffer representation of this object.
|
|
62
|
+
*/ toBuffer() {
|
|
63
|
+
return serializeArrayOfBufferableToVector(this.data);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Returns the path buffer underlying the sibling path.
|
|
67
|
+
* @returns The Buffer array representation of this object.
|
|
68
|
+
*/ toBufferArray() {
|
|
69
|
+
return this.data;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Convert the Sibling Path object into an array of field elements.
|
|
73
|
+
* @returns The field array representation of this object.
|
|
74
|
+
*/ toFields() {
|
|
75
|
+
return this.data.map((buf)=>Fr.fromBuffer(buf));
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Convert Sibling Path object into a tuple of field elements.
|
|
79
|
+
* @returns A tuple representation of the sibling path.
|
|
80
|
+
*/ toTuple() {
|
|
81
|
+
const array = this.toFields();
|
|
82
|
+
return makeTuple(array.length, (i)=>array[i], 0);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Deserializes a SiblingPath from a buffer.
|
|
86
|
+
* @param buf - A buffer containing the buffer representation of SiblingPath.
|
|
87
|
+
* @param offset - An offset to start deserializing from.
|
|
88
|
+
* @returns A SiblingPath object.
|
|
89
|
+
*/ static fromBuffer(buf, offset = 0) {
|
|
90
|
+
const { elem } = SiblingPath.deserialize(buf, offset);
|
|
91
|
+
return elem;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Deserializes a SiblingPath object from a slice of a part of a buffer and returns the amount of bytes advanced.
|
|
95
|
+
* @param buf - A buffer representation of the sibling path.
|
|
96
|
+
* @param offset - An offset to start deserializing from.
|
|
97
|
+
* @returns The deserialized sibling path and the number of bytes advanced.
|
|
98
|
+
*/ static deserialize(buf, offset = 0) {
|
|
99
|
+
const deserializePath = (buf, offset)=>({
|
|
100
|
+
elem: buf.slice(offset, offset + 32),
|
|
101
|
+
adv: 32
|
|
102
|
+
});
|
|
103
|
+
const { elem, adv } = deserializeArrayFromVector(deserializePath, buf, offset);
|
|
104
|
+
const size = elem.length;
|
|
105
|
+
return {
|
|
106
|
+
elem: new SiblingPath(size, elem),
|
|
107
|
+
adv
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Serializes this SiblingPath object to a hex string representation.
|
|
112
|
+
* @returns A hex string representation of the sibling path.
|
|
113
|
+
*/ toString() {
|
|
114
|
+
return bufferToHex(this.toBuffer());
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Deserializes a SiblingPath object from a hex string representation.
|
|
118
|
+
* @param repr - A hex string representation of the sibling path.
|
|
119
|
+
* @returns A SiblingPath object.
|
|
120
|
+
*/ static fromString(repr) {
|
|
121
|
+
return SiblingPath.fromBuffer(hexToBuffer(repr));
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Generate a subtree path from the current sibling path.
|
|
125
|
+
* @param subtreeHeight - The size of the subtree that we are getting the path for.
|
|
126
|
+
* @returns A new sibling path that is the for the requested subtree.
|
|
127
|
+
*/ getSubtreeSiblingPath(subtreeHeight) {
|
|
128
|
+
// Drop the size of the subtree from the path, and return the rest.
|
|
129
|
+
const subtreeData = this.data.slice(subtreeHeight);
|
|
130
|
+
const subtreePathSize = this.pathSize - subtreeHeight;
|
|
131
|
+
return new SiblingPath(subtreePathSize, subtreeData);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
/** Computes the expected root of a merkle tree given a leaf and its sibling path. */ export async function computeRootFromSiblingPath(leaf, siblingPath, index, hasher = async (left, right)=>(await pedersenHash([
|
|
135
|
+
left,
|
|
136
|
+
right
|
|
137
|
+
])).toBuffer()) {
|
|
138
|
+
let result = leaf;
|
|
139
|
+
for (const sibling of siblingPath){
|
|
140
|
+
result = index & 1 ? await hasher(sibling, result) : await hasher(result, sibling);
|
|
141
|
+
index >>= 1;
|
|
142
|
+
}
|
|
143
|
+
return result;
|
|
144
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
3
|
+
import { sha256Trunc } from '../crypto/sha256/index.js';
|
|
4
|
+
/**
|
|
5
|
+
* Computes the merkle root for an unbalanced tree.
|
|
6
|
+
*
|
|
7
|
+
* @dev Adapted from unbalanced_tree.ts.
|
|
8
|
+
* Calculates the tree upwards layer by layer until we reach the root.
|
|
9
|
+
* The L1 calculation instead computes the tree from right to left (slightly cheaper gas).
|
|
10
|
+
* TODO: A more thorough investigation of which method is cheaper, then use that method everywhere.
|
|
11
|
+
*/
|
|
12
|
+
export declare function computeUnbalancedMerkleRoot(leaves: Buffer[], emptyLeaf?: Buffer, hasher?: typeof sha256Trunc): Buffer;
|
|
13
|
+
export declare function findLeafLevelAndIndex(numLeaves: number, leafIndex: number): {
|
|
14
|
+
level: number;
|
|
15
|
+
indexAtLevel: number;
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=unbalanced_merkle_tree.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unbalanced_merkle_tree.d.ts","sourceRoot":"","sources":["../../src/trees/unbalanced_merkle_tree.ts"],"names":[],"mappings":";;AACA,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAExD;;;;;;;GAOG;AACH,wBAAgB,2BAA2B,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,SAAS,CAAC,EAAE,MAAM,EAAE,MAAM,qBAAc,GAAG,MAAM,CAwC9G;AAgDD,wBAAgB,qBAAqB,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM;;;EAGzE"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { padArrayEnd } from '../collection/array.js';
|
|
2
|
+
import { sha256Trunc } from '../crypto/sha256/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* Computes the merkle root for an unbalanced tree.
|
|
5
|
+
*
|
|
6
|
+
* @dev Adapted from unbalanced_tree.ts.
|
|
7
|
+
* Calculates the tree upwards layer by layer until we reach the root.
|
|
8
|
+
* The L1 calculation instead computes the tree from right to left (slightly cheaper gas).
|
|
9
|
+
* TODO: A more thorough investigation of which method is cheaper, then use that method everywhere.
|
|
10
|
+
*/ export function computeUnbalancedMerkleRoot(leaves, emptyLeaf, hasher = sha256Trunc) {
|
|
11
|
+
// Pad leaves to 2
|
|
12
|
+
if (leaves.length < 2) {
|
|
13
|
+
if (emptyLeaf === undefined) {
|
|
14
|
+
throw new Error('Cannot compute a Merkle root with less than 2 leaves');
|
|
15
|
+
} else {
|
|
16
|
+
leaves = padArrayEnd(leaves, emptyLeaf, 2);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
const depth = Math.ceil(Math.log2(leaves.length));
|
|
20
|
+
let [layerWidth, nodeToShift] = leaves.length & 1 ? [
|
|
21
|
+
leaves.length - 1,
|
|
22
|
+
leaves[leaves.length - 1]
|
|
23
|
+
] : [
|
|
24
|
+
leaves.length,
|
|
25
|
+
Buffer.alloc(0)
|
|
26
|
+
];
|
|
27
|
+
// Allocate this layer's leaves and init the next layer up
|
|
28
|
+
let thisLayer = leaves.slice(0, layerWidth);
|
|
29
|
+
let nextLayer = [];
|
|
30
|
+
for(let i = 0; i < depth; i++){
|
|
31
|
+
for(let j = 0; j < layerWidth; j += 2){
|
|
32
|
+
// Store the hash of each pair one layer up
|
|
33
|
+
nextLayer[j / 2] = hasher(Buffer.concat([
|
|
34
|
+
thisLayer[j],
|
|
35
|
+
thisLayer[j + 1]
|
|
36
|
+
]));
|
|
37
|
+
}
|
|
38
|
+
layerWidth /= 2;
|
|
39
|
+
if (layerWidth & 1) {
|
|
40
|
+
if (nodeToShift.length) {
|
|
41
|
+
// If the next layer has odd length, and we have a node that needs to be shifted up, add it here
|
|
42
|
+
nextLayer.push(nodeToShift);
|
|
43
|
+
layerWidth += 1;
|
|
44
|
+
nodeToShift = Buffer.alloc(0);
|
|
45
|
+
} else {
|
|
46
|
+
// If we don't have a node waiting to be shifted, store the next layer's final node to be shifted
|
|
47
|
+
layerWidth -= 1;
|
|
48
|
+
nodeToShift = nextLayer[layerWidth];
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
// reset the layers
|
|
52
|
+
thisLayer = nextLayer;
|
|
53
|
+
nextLayer = [];
|
|
54
|
+
}
|
|
55
|
+
// return the root
|
|
56
|
+
return thisLayer[0];
|
|
57
|
+
}
|
|
58
|
+
function getMaxBalancedTreeDepth(numLeaves) {
|
|
59
|
+
return Math.floor(Math.log2(numLeaves));
|
|
60
|
+
}
|
|
61
|
+
function getMaxUnbalancedTreeDepth(numLeaves) {
|
|
62
|
+
return Math.ceil(Math.log2(numLeaves));
|
|
63
|
+
}
|
|
64
|
+
function findPosition(rootLevel, leafLevel, numLeaves, indexOffset, targetIndex) {
|
|
65
|
+
if (numLeaves <= 1) {
|
|
66
|
+
// Single leaf.
|
|
67
|
+
return {
|
|
68
|
+
level: rootLevel,
|
|
69
|
+
indexAtLevel: indexOffset
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
// The largest balanced tree that can be created with the given number of leaves.
|
|
73
|
+
const maxBalancedTreeDepth = getMaxBalancedTreeDepth(numLeaves);
|
|
74
|
+
const numBalancedLeaves = 2 ** maxBalancedTreeDepth;
|
|
75
|
+
const numRemainingLeaves = numLeaves - numBalancedLeaves;
|
|
76
|
+
if (targetIndex < numBalancedLeaves) {
|
|
77
|
+
// Target is in the balanced tree.
|
|
78
|
+
// - If numRemainingLeaves is 0: this balanced tree is grown from the current root.
|
|
79
|
+
// - If numRemainingLeaves is not 0: the remaining leaves will form another tree, which will become the right child of the root.
|
|
80
|
+
// And the balanced tree will be the left child of the root.
|
|
81
|
+
// There will be an extra level between the root of the balanced tree and the current root.
|
|
82
|
+
const extraLevel = numRemainingLeaves ? 1 : 0;
|
|
83
|
+
return {
|
|
84
|
+
level: rootLevel + maxBalancedTreeDepth + extraLevel,
|
|
85
|
+
indexAtLevel: indexOffset + targetIndex
|
|
86
|
+
};
|
|
87
|
+
} else {
|
|
88
|
+
// Target is in the right branch.
|
|
89
|
+
const rightBranchMaxLevel = getMaxUnbalancedTreeDepth(numRemainingLeaves);
|
|
90
|
+
const shiftedUp = leafLevel - rootLevel - rightBranchMaxLevel - 1;
|
|
91
|
+
const nextLeafLevel = leafLevel - shiftedUp;
|
|
92
|
+
const newIndexOffset = indexOffset + numBalancedLeaves >> shiftedUp;
|
|
93
|
+
const shiftedTargetIndex = targetIndex - numBalancedLeaves;
|
|
94
|
+
return findPosition(rootLevel + 1, nextLeafLevel, numRemainingLeaves, newIndexOffset, shiftedTargetIndex);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
export function findLeafLevelAndIndex(numLeaves, leafIndex) {
|
|
98
|
+
const maxLevel = getMaxUnbalancedTreeDepth(numLeaves);
|
|
99
|
+
return findPosition(0, maxLevel, numLeaves, 0, leafIndex);
|
|
100
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export interface TreeNodeLocation {
|
|
2
|
+
level: number;
|
|
3
|
+
index: number;
|
|
4
|
+
}
|
|
5
|
+
export declare class UnbalancedTreeStore<T> {
|
|
6
|
+
#private;
|
|
7
|
+
constructor(numLeaves: number);
|
|
8
|
+
setLeaf(leafIndex: number, value: T): TreeNodeLocation;
|
|
9
|
+
setNode({ level, index }: TreeNodeLocation, value: T): void;
|
|
10
|
+
getParentLocation({ level, index }: TreeNodeLocation): TreeNodeLocation;
|
|
11
|
+
getSiblingLocation({ level, index }: TreeNodeLocation): TreeNodeLocation;
|
|
12
|
+
getChildLocations({ level, index }: TreeNodeLocation): [TreeNodeLocation, TreeNodeLocation];
|
|
13
|
+
getLeaf(leafIndex: number): T | undefined;
|
|
14
|
+
getNode(location: TreeNodeLocation): T | undefined;
|
|
15
|
+
getParent(location: TreeNodeLocation): T | undefined;
|
|
16
|
+
getSibling(location: TreeNodeLocation): T | undefined;
|
|
17
|
+
getChildren(location: TreeNodeLocation): [T | undefined, T | undefined];
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=unbalanced_tree_store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unbalanced_tree_store.d.ts","sourceRoot":"","sources":["../../src/trees/unbalanced_tree_store.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACf;AAOD,qBAAa,mBAAmB,CAAC,CAAC;;gBAIpB,SAAS,EAAE,MAAM;IAI7B,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,gBAAgB;IAiBtD,OAAO,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,gBAAgB,EAAE,KAAK,EAAE,CAAC;IAWpD,iBAAiB,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,gBAAgB,GAAG,gBAAgB;IAQvE,kBAAkB,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,gBAAgB,GAAG,gBAAgB;IAQxE,iBAAiB,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,gBAAgB,GAAG,CAAC,gBAAgB,EAAE,gBAAgB,CAAC;IAM3F,OAAO,CAAC,SAAS,EAAE,MAAM;IASzB,OAAO,CAAC,QAAQ,EAAE,gBAAgB,GAAG,CAAC,GAAG,SAAS;IAIlD,SAAS,CAAC,QAAQ,EAAE,gBAAgB,GAAG,CAAC,GAAG,SAAS;IAKpD,UAAU,CAAC,QAAQ,EAAE,gBAAgB,GAAG,CAAC,GAAG,SAAS;IAKrD,WAAW,CAAC,QAAQ,EAAE,gBAAgB,GAAG,CAAC,CAAC,GAAG,SAAS,EAAE,CAAC,GAAG,SAAS,CAAC;CAQxE"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { findLeafLevelAndIndex } from './unbalanced_merkle_tree.js';
|
|
2
|
+
export class UnbalancedTreeStore {
|
|
3
|
+
#nodeMapping = new Map();
|
|
4
|
+
#numLeaves;
|
|
5
|
+
constructor(numLeaves){
|
|
6
|
+
this.#numLeaves = numLeaves;
|
|
7
|
+
}
|
|
8
|
+
setLeaf(leafIndex, value) {
|
|
9
|
+
if (leafIndex >= this.#numLeaves) {
|
|
10
|
+
throw new Error(`Expected at most ${this.#numLeaves} leaves. Received a leaf at index ${leafIndex}.`);
|
|
11
|
+
}
|
|
12
|
+
const { level, indexAtLevel } = findLeafLevelAndIndex(this.#numLeaves, leafIndex);
|
|
13
|
+
const location = {
|
|
14
|
+
level,
|
|
15
|
+
index: indexAtLevel
|
|
16
|
+
};
|
|
17
|
+
this.#nodeMapping.set(this.#getKey(location), {
|
|
18
|
+
location,
|
|
19
|
+
value
|
|
20
|
+
});
|
|
21
|
+
return location;
|
|
22
|
+
}
|
|
23
|
+
setNode({ level, index }, value) {
|
|
24
|
+
const location = {
|
|
25
|
+
level,
|
|
26
|
+
index
|
|
27
|
+
};
|
|
28
|
+
this.#nodeMapping.set(this.#getKey(location), {
|
|
29
|
+
location,
|
|
30
|
+
value
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
getParentLocation({ level, index }) {
|
|
34
|
+
if (level === 0) {
|
|
35
|
+
throw new Error('Tree root does not have a parent.');
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
level: level - 1,
|
|
39
|
+
index: Math.floor(index / 2)
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
getSiblingLocation({ level, index }) {
|
|
43
|
+
if (level === 0) {
|
|
44
|
+
throw new Error('Tree root does not have a sibling.');
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
level,
|
|
48
|
+
index: index % 2 ? index - 1 : index + 1
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
getChildLocations({ level, index }) {
|
|
52
|
+
const left = {
|
|
53
|
+
level: level + 1,
|
|
54
|
+
index: index * 2
|
|
55
|
+
};
|
|
56
|
+
const right = {
|
|
57
|
+
level: level + 1,
|
|
58
|
+
index: index * 2 + 1
|
|
59
|
+
};
|
|
60
|
+
return [
|
|
61
|
+
left,
|
|
62
|
+
right
|
|
63
|
+
];
|
|
64
|
+
}
|
|
65
|
+
getLeaf(leafIndex) {
|
|
66
|
+
const { level, indexAtLevel } = findLeafLevelAndIndex(this.#numLeaves, leafIndex);
|
|
67
|
+
const location = {
|
|
68
|
+
level,
|
|
69
|
+
index: indexAtLevel
|
|
70
|
+
};
|
|
71
|
+
return this.getNode(location);
|
|
72
|
+
}
|
|
73
|
+
getNode(location) {
|
|
74
|
+
return this.#nodeMapping.get(this.#getKey(location))?.value;
|
|
75
|
+
}
|
|
76
|
+
getParent(location) {
|
|
77
|
+
const parentLocation = this.getParentLocation(location);
|
|
78
|
+
return this.getNode(parentLocation);
|
|
79
|
+
}
|
|
80
|
+
getSibling(location) {
|
|
81
|
+
const siblingLocation = this.getSiblingLocation(location);
|
|
82
|
+
return this.getNode(siblingLocation);
|
|
83
|
+
}
|
|
84
|
+
getChildren(location) {
|
|
85
|
+
const [left, right] = this.getChildLocations(location);
|
|
86
|
+
return [
|
|
87
|
+
this.getNode(left),
|
|
88
|
+
this.getNode(right)
|
|
89
|
+
];
|
|
90
|
+
}
|
|
91
|
+
#getKey(location) {
|
|
92
|
+
return `${location.level}-${location.index}`;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** Strips methods of a type. */
|
|
2
|
+
export type FieldsOf<T> = {
|
|
3
|
+
[P in keyof T as T[P] extends Function ? never : P]: T[P];
|
|
4
|
+
};
|
|
5
|
+
/** Extracts methods of a type. */
|
|
6
|
+
export type FunctionsOf<T> = {
|
|
7
|
+
[P in keyof T as T[P] extends Function ? P : never]: T[P];
|
|
8
|
+
};
|
|
9
|
+
/** Marks a set of properties of a type as optional. */
|
|
10
|
+
export type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
11
|
+
/** Removes readonly modifiers for a type. */
|
|
12
|
+
export type Writeable<T> = {
|
|
13
|
+
-readonly [P in keyof T]: T[P];
|
|
14
|
+
};
|
|
15
|
+
/** Removes readonly modifiers for an object. */
|
|
16
|
+
export declare function unfreeze<T>(obj: T): Writeable<T>;
|
|
17
|
+
/** Maybe exists, maybe not. */
|
|
18
|
+
export type Maybe<T extends object> = T | unknown;
|
|
19
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI;KAEvB,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,QAAQ,GAAG,KAAK,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAC1D,CAAC;AAEF,kCAAkC;AAClC,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI;KAE1B,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,QAAQ,GAAG,CAAC,GAAG,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC;CAC1D,CAAC;AAEF,uDAAuD;AACvD,MAAM,MAAM,SAAS,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,IAAI,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AAE/E,6CAA6C;AAC7C,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI;IAAE,CAAC,UAAU,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAAE,CAAC;AAE9D,gDAAgD;AAChD,wBAAgB,QAAQ,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAEhD;AAED,+BAA+B;AAC/B,MAAM,MAAM,KAAK,CAAC,CAAC,SAAS,MAAM,IAAI,CAAC,GAAG,OAAO,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/url/index.ts"],"names":[],"mappings":"AAoBA;;;;;;GAMG;AAEH,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CA4CjD"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/* eslint-disable */ // Copyright (c) 2014 Nathan Rajlich <nathan@tootallnate.net>
|
|
2
|
+
// Permission is hereby granted, free of charge, to any person obtaining
|
|
3
|
+
// a copy of this software and associated documentation files (the
|
|
4
|
+
// 'Software'), to deal in the Software without restriction, including
|
|
5
|
+
// without limitation the rights to use, copy, modify, merge, publish,
|
|
6
|
+
// distribute, sublicense, and/or sell copies of the Software, and to
|
|
7
|
+
// permit persons to whom the Software is furnished to do so, subject to
|
|
8
|
+
// the following conditions:
|
|
9
|
+
// The above copyright notice and this permission notice shall be
|
|
10
|
+
// included in all copies or substantial portions of the Software.
|
|
11
|
+
// THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
|
12
|
+
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
13
|
+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
14
|
+
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
15
|
+
// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
16
|
+
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
17
|
+
// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
18
|
+
import { sep } from 'path';
|
|
19
|
+
/**
|
|
20
|
+
* File URI to Path function.
|
|
21
|
+
*
|
|
22
|
+
* @param {String} uri
|
|
23
|
+
* @return {String} path
|
|
24
|
+
* @api public
|
|
25
|
+
*/ export function fileURLToPath(uri) {
|
|
26
|
+
if (typeof uri !== 'string' || uri.length <= 7 || uri.substring(0, 7) !== 'file://') {
|
|
27
|
+
throw new TypeError('must pass in a file:// URI to convert to a file path');
|
|
28
|
+
}
|
|
29
|
+
const rest = decodeURI(uri.substring(7));
|
|
30
|
+
const firstSlash = rest.indexOf('/');
|
|
31
|
+
let host = rest.substring(0, firstSlash);
|
|
32
|
+
let path = rest.substring(firstSlash + 1);
|
|
33
|
+
// 2. Scheme Definition
|
|
34
|
+
// As a special case, <host> can be the string "localhost" or the empty
|
|
35
|
+
// string; this is interpreted as "the machine from which the URL is
|
|
36
|
+
// being interpreted".
|
|
37
|
+
if (host === 'localhost') {
|
|
38
|
+
host = '';
|
|
39
|
+
}
|
|
40
|
+
if (host) {
|
|
41
|
+
host = sep + sep + host;
|
|
42
|
+
}
|
|
43
|
+
// 3.2 Drives, drive letters, mount points, file system root
|
|
44
|
+
// Drive letters are mapped into the top of a file URI in various ways,
|
|
45
|
+
// depending on the implementation; some applications substitute
|
|
46
|
+
// vertical bar ("|") for the colon after the drive letter, yielding
|
|
47
|
+
// "file:///c|/tmp/test.txt". In some cases, the colon is left
|
|
48
|
+
// unchanged, as in "file:///c:/tmp/test.txt". In other cases, the
|
|
49
|
+
// colon is simply omitted, as in "file:///c/tmp/test.txt".
|
|
50
|
+
path = path.replace(/^(.+)\|/, '$1:');
|
|
51
|
+
// for Windows, we need to invert the path separators from what a URI uses
|
|
52
|
+
if (sep === '\\') {
|
|
53
|
+
path = path.replace(/\//g, '\\');
|
|
54
|
+
}
|
|
55
|
+
if (/^.+:/.test(path)) {
|
|
56
|
+
// has Windows drive at beginning of path
|
|
57
|
+
} else {
|
|
58
|
+
// unix path…
|
|
59
|
+
path = sep + path;
|
|
60
|
+
}
|
|
61
|
+
return host + path;
|
|
62
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** Utility function to throw an error if a required value is missing. */
|
|
2
|
+
export declare function required<T>(value: T | undefined, errMsg?: string): T;
|
|
3
|
+
/**
|
|
4
|
+
* Helper function to assert a condition is truthy
|
|
5
|
+
* @param x - A boolean condition to assert.
|
|
6
|
+
* @param err - Error message to throw if x isn't met.
|
|
7
|
+
*/
|
|
8
|
+
export declare function assert(x: any, err: string): asserts x;
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/validation/index.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,wBAAgB,QAAQ,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,SAAS,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,CAAC,CAKpE;AAED;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAIrD"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** Utility function to throw an error if a required value is missing. */ export function required(value, errMsg) {
|
|
2
|
+
if (value === undefined) {
|
|
3
|
+
throw new Error(errMsg || 'Value is required');
|
|
4
|
+
}
|
|
5
|
+
return value;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Helper function to assert a condition is truthy
|
|
9
|
+
* @param x - A boolean condition to assert.
|
|
10
|
+
* @param err - Error message to throw if x isn't met.
|
|
11
|
+
*/ export function assert(x, err) {
|
|
12
|
+
if (!x) {
|
|
13
|
+
throw new Error(err);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dummy implementation of a necessary part of the wasi api:
|
|
3
|
+
* https://github.com/WebAssembly/WASI/blob/main/phases/snapshot/docs.md
|
|
4
|
+
* We don't use these functions, but the environment expects them.
|
|
5
|
+
* TODO find a way to update off of wasi 12.
|
|
6
|
+
*/
|
|
7
|
+
export declare const getEmptyWasiSdk: (debug?: import("../log/log_fn.js").LogFn) => {
|
|
8
|
+
/**
|
|
9
|
+
* Retrieves the current time from the system clock.
|
|
10
|
+
* This function is a dummy implementation of the WASI API's `clock_time_get` method,
|
|
11
|
+
* which is expected by the environment but not used in this context.
|
|
12
|
+
*
|
|
13
|
+
* No input parameters or return values are required, as the purpose of this function
|
|
14
|
+
* is solely to satisfy the environment expectations and provide debugging information.
|
|
15
|
+
*/
|
|
16
|
+
clock_time_get(): void;
|
|
17
|
+
/**
|
|
18
|
+
* Dummy implementation of WASI's environ_get function.
|
|
19
|
+
* This function is used to obtain a snapshot of the current environment variables.
|
|
20
|
+
* In this dummy implementation, no actual actions are performed, but the debug logger logs 'environ_get' when called.
|
|
21
|
+
* Environment variables are not used in this context, so the real implementation is not required.
|
|
22
|
+
*
|
|
23
|
+
* @see https://github.com/WebAssembly/WASI/blob/main/phases/snapshot/docs.md#environ_get
|
|
24
|
+
*/
|
|
25
|
+
environ_get(): void;
|
|
26
|
+
/**
|
|
27
|
+
* Retrieves the environment variable sizes from the WebAssembly environment.
|
|
28
|
+
* This function is part of the WASI API and provides a dummy implementation to fulfill the expected APIs.
|
|
29
|
+
* It does not have any actual functionality, but serves as a placeholder in the environment.
|
|
30
|
+
*/
|
|
31
|
+
environ_sizes_get(): void;
|
|
32
|
+
/**
|
|
33
|
+
* Closes a file descriptor, releasing any resources associated with it.
|
|
34
|
+
* This function does not perform any actual closing operation, but exists to
|
|
35
|
+
* satisfy the requirements of the WebAssembly System Interface (WASI) API,
|
|
36
|
+
* which expects certain functions to be present for compatibility purposes.
|
|
37
|
+
*
|
|
38
|
+
* @see https://github.com/WebAssembly/WASI/blob/main/phases/snapshot/docs.md
|
|
39
|
+
*/
|
|
40
|
+
fd_close(): void;
|
|
41
|
+
/**
|
|
42
|
+
* A dummy implementation of the 'fd_read' function from the WASI API.
|
|
43
|
+
* This function is required by the environment, but not used in this context.
|
|
44
|
+
* It would normally read data from a file descriptor into an array buffer,
|
|
45
|
+
* but here it simply logs the invocation for debugging purposes.
|
|
46
|
+
*/
|
|
47
|
+
fd_read(): void;
|
|
48
|
+
/**
|
|
49
|
+
* Handles the file descriptor write operation.
|
|
50
|
+
* This dummy implementation of the WASI 'fd_write' function is part of the wasi API:
|
|
51
|
+
* https://github.com/WebAssembly/WASI/blob/main/phases/snapshot/docs.md
|
|
52
|
+
* The environment expects this function, but it is not used in the current implementation.
|
|
53
|
+
* It is used to write data from WebAssembly memory to a file descriptor.
|
|
54
|
+
*/
|
|
55
|
+
fd_write(): void;
|
|
56
|
+
/**
|
|
57
|
+
* Perform a file seek operation on the given file descriptor to change its current position.
|
|
58
|
+
* The new position is calculated using the provided offset and whence values.
|
|
59
|
+
* Throws an error if the file descriptor is invalid or the operation cannot be performed.
|
|
60
|
+
*
|
|
61
|
+
* @param fd - The file descriptor of the file to perform the seek operation on.
|
|
62
|
+
* @param offset - The relative offset to apply, based on the whence value.
|
|
63
|
+
* @param whence - The reference point from which the offset should be calculated. One of SEEK_SET (start), SEEK_CUR (current), or SEEK_END (end).
|
|
64
|
+
* @returns The new position in the file after the seek operation has been performed.
|
|
65
|
+
*/
|
|
66
|
+
fd_seek(): void;
|
|
67
|
+
/**
|
|
68
|
+
* This function is a dummy implementation of the 'fd_fdstat_get' function in the WebAssembly System Interface (WASI) API.
|
|
69
|
+
* Although not actually used in this context, it is present due to the environment's expectation of its existence.
|
|
70
|
+
* The 'fd_fdstat_get' function is typically responsible for obtaining file descriptor status information.
|
|
71
|
+
*/
|
|
72
|
+
fd_fdstat_get(): void;
|
|
73
|
+
/**
|
|
74
|
+
* Sets the file descriptor flags for a given file descriptor.
|
|
75
|
+
* This function is a dummy implementation of the WASI API function 'fd_fdstat_set_flags'.
|
|
76
|
+
* It currently does not perform any operation but logs the function call with a debug instance.
|
|
77
|
+
* This is provided since the environment expects this function to be present.
|
|
78
|
+
*/
|
|
79
|
+
fd_fdstat_set_flags(): void;
|
|
80
|
+
/**
|
|
81
|
+
* Handles the `fd_prestat_get` function call for the dummy WebAssembly System Interface (WASI) implementation.
|
|
82
|
+
* This function is expected by the WASI environment, although it is not used in this implementation.
|
|
83
|
+
* The `fd_prestat_get` function retrieves pre-opened file descriptor properties.
|
|
84
|
+
*
|
|
85
|
+
* @returns A constant integer value indicating successful completion of the function call.
|
|
86
|
+
*/
|
|
87
|
+
fd_prestat_get(): number;
|
|
88
|
+
/**
|
|
89
|
+
* Provides a dummy implementation for the `fd_prestat_dir_name` function, which is expected to be called by the WASI environment.
|
|
90
|
+
* This function is intended to retrieve the pre-opened directory's path associated with the given file descriptor. However, since it's a dummy implementation,
|
|
91
|
+
* it doesn't perform any actual operation and only logs the function call with the provided debug logger.
|
|
92
|
+
*
|
|
93
|
+
* @returns A constant number representing a dummy return value for the function call.
|
|
94
|
+
*/
|
|
95
|
+
fd_prestat_dir_name(): number;
|
|
96
|
+
/**
|
|
97
|
+
* Handles the opening of a file path within the WASI environment.
|
|
98
|
+
* This function is a dummy implementation required for compatibility with
|
|
99
|
+
* the WebAssembly System Interface (WASI) API, but it does not perform any
|
|
100
|
+
* actual file opening operation. It is mainly used for debugging purposes.
|
|
101
|
+
*/
|
|
102
|
+
path_open(): void;
|
|
103
|
+
/**
|
|
104
|
+
* Retrieve file system information of the specified path.
|
|
105
|
+
* This function retrieves statistics, such as size and permissions, associated with the file or directory
|
|
106
|
+
* identified by the given path. In case of an error or non-existing path, appropriate debug logs will be generated.
|
|
107
|
+
*
|
|
108
|
+
* @returns An object containing file statistics like size, permissions, etc.
|
|
109
|
+
*/
|
|
110
|
+
path_filestat_get(): void;
|
|
111
|
+
/**
|
|
112
|
+
* Terminate the process normally, performing the regular cleanup for terminating programs.
|
|
113
|
+
* The input 'status' represents the exit code and is used to indicate success or failure
|
|
114
|
+
* of the program execution. A zero value typically indicates successful execution,
|
|
115
|
+
* while non-zero values are treated as errors by the operating system.
|
|
116
|
+
*
|
|
117
|
+
* @param status - The exit code representing the success or failure of the program execution.
|
|
118
|
+
* @returns The exit status code.
|
|
119
|
+
*/
|
|
120
|
+
proc_exit(): number;
|
|
121
|
+
/**
|
|
122
|
+
* Generates a random number and returns it.
|
|
123
|
+
* This dummy implementation of 'random_get' method in the wasi API is expected by the environment.
|
|
124
|
+
* In this case, the function always returns 1 to maintain consistency with the environment's expectations.
|
|
125
|
+
*
|
|
126
|
+
* @returns A random number. In this implementation, always returns 1.
|
|
127
|
+
*/
|
|
128
|
+
random_get(): number;
|
|
129
|
+
};
|
|
130
|
+
//# sourceMappingURL=empty_wasi_sdk.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"empty_wasi_sdk.d.ts","sourceRoot":"","sources":["../../src/wasm/empty_wasi_sdk.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AAEH,eAAO,MAAM,eAAe;IAC1B;;;;;;;OAOG;;IAIH;;;;;;;OAOG;;IAIH;;;;OAIG;;IAIH;;;;;;;OAOG;;IAIH;;;;;OAKG;;IAIH;;;;;;OAMG;;IAIH;;;;;;;;;OASG;;IAIH;;;;OAIG;;IAIH;;;;;OAKG;;IAIH;;;;;;OAMG;;IAKH;;;;;;OAMG;;IAKH;;;;;OAKG;;IAIH;;;;;;OAMG;;IAIH;;;;;;;;OAQG;;IAKH;;;;;;OAMG;;CAKH,CAAC"}
|