@aztec/foundation 0.7.2 → 0.7.4
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/.tsbuildinfo +1 -0
- package/dest/abi/abi.d.ts +237 -0
- package/dest/abi/abi.d.ts.map +1 -0
- package/dest/abi/abi.js +37 -0
- package/dest/abi/abi_coder.d.ts +8 -0
- package/dest/abi/abi_coder.d.ts.map +1 -0
- package/dest/abi/abi_coder.js +24 -0
- package/dest/abi/decoder.d.ts +57 -0
- package/dest/abi/decoder.d.ts.map +1 -0
- package/dest/abi/decoder.js +149 -0
- package/dest/abi/decoder.test.d.ts +2 -0
- package/dest/abi/decoder.test.d.ts.map +1 -0
- package/dest/abi/decoder.test.js +70 -0
- package/dest/abi/encoder.d.ts +10 -0
- package/dest/abi/encoder.d.ts.map +1 -0
- package/dest/abi/encoder.js +92 -0
- package/dest/abi/encoder.test.d.ts +2 -0
- package/dest/abi/encoder.test.d.ts.map +1 -0
- package/dest/abi/encoder.test.js +74 -0
- package/dest/abi/function_selector.d.ts +73 -0
- package/dest/abi/function_selector.d.ts.map +1 -0
- package/dest/abi/function_selector.js +104 -0
- package/dest/abi/index.d.ts +6 -0
- package/dest/abi/index.d.ts.map +1 -0
- package/dest/abi/index.js +6 -0
- package/dest/async-map/async_map.test.d.ts +2 -0
- package/dest/async-map/async_map.test.d.ts.map +1 -0
- package/dest/async-map/async_map.test.js +9 -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 +19 -0
- package/dest/aztec-address/index.d.ts +114 -0
- package/dest/aztec-address/index.d.ts.map +1 -0
- package/dest/aztec-address/index.js +148 -0
- package/dest/bigint-buffer/bigint-buffer.test.d.ts +2 -0
- package/dest/bigint-buffer/bigint-buffer.test.d.ts.map +1 -0
- package/dest/bigint-buffer/bigint-buffer.test.js +18 -0
- package/dest/bigint-buffer/index.d.ts +35 -0
- package/dest/bigint-buffer/index.d.ts.map +1 -0
- package/dest/bigint-buffer/index.js +68 -0
- package/dest/collection/array.d.ts +30 -0
- package/dest/collection/array.d.ts.map +1 -0
- package/dest/collection/array.js +47 -0
- package/dest/collection/index.d.ts +2 -0
- package/dest/collection/index.d.ts.map +1 -0
- package/dest/collection/index.js +2 -0
- package/dest/committable/committable.d.ts +28 -0
- package/dest/committable/committable.d.ts.map +1 -0
- package/dest/committable/committable.js +41 -0
- package/dest/committable/committable.test.d.ts +2 -0
- package/dest/committable/committable.test.d.ts.map +1 -0
- package/dest/committable/committable.test.js +26 -0
- package/dest/committable/index.d.ts +2 -0
- package/dest/committable/index.d.ts.map +1 -0
- package/dest/committable/index.js +2 -0
- package/dest/crypto/index.d.ts +4 -0
- package/dest/crypto/index.d.ts.map +1 -0
- package/dest/crypto/index.js +4 -0
- package/dest/crypto/keccak/index.d.ts +20 -0
- package/dest/crypto/keccak/index.d.ts.map +1 -0
- package/dest/crypto/keccak/index.js +31 -0
- package/dest/crypto/random/index.d.ts +3 -0
- package/dest/crypto/random/index.d.ts.map +1 -0
- package/dest/crypto/random/index.js +36 -0
- package/dest/crypto/random/index.test.d.ts +2 -0
- package/dest/crypto/random/index.test.d.ts.map +1 -0
- package/dest/crypto/random/index.test.js +13 -0
- package/dest/crypto/sha256/index.d.ts +11 -0
- package/dest/crypto/sha256/index.d.ts.map +1 -0
- package/dest/crypto/sha256/index.js +14 -0
- package/dest/crypto/sha256/index.test.d.ts +2 -0
- package/dest/crypto/sha256/index.test.d.ts.map +1 -0
- package/dest/crypto/sha256/index.test.js +11 -0
- package/dest/errors/index.d.ts +8 -0
- package/dest/errors/index.d.ts.map +1 -0
- package/dest/errors/index.js +8 -0
- package/dest/eth-address/eth_address.test.d.ts +2 -0
- package/dest/eth-address/eth_address.test.d.ts.map +1 -0
- package/dest/eth-address/eth_address.test.js +95 -0
- package/dest/eth-address/index.d.ts +144 -0
- package/dest/eth-address/index.d.ts.map +1 -0
- package/dest/eth-address/index.js +228 -0
- package/dest/fields/coordinate.d.ts +67 -0
- package/dest/fields/coordinate.d.ts.map +1 -0
- package/dest/fields/coordinate.js +95 -0
- package/dest/fields/coordinate.test.d.ts +2 -0
- package/dest/fields/coordinate.test.d.ts.map +1 -0
- package/dest/fields/coordinate.test.js +22 -0
- package/dest/fields/fields.d.ts +177 -0
- package/dest/fields/fields.d.ts.map +1 -0
- package/dest/fields/fields.js +219 -0
- package/dest/fields/grumpkin_scalar.d.ts +96 -0
- package/dest/fields/grumpkin_scalar.d.ts.map +1 -0
- package/dest/fields/grumpkin_scalar.js +125 -0
- package/dest/fields/grumpkin_scalar.test.d.ts +2 -0
- package/dest/fields/grumpkin_scalar.test.d.ts.map +1 -0
- package/dest/fields/grumpkin_scalar.test.js +45 -0
- package/dest/fields/index.d.ts +5 -0
- package/dest/fields/index.d.ts.map +1 -0
- package/dest/fields/index.js +5 -0
- package/dest/fields/point.d.ts +105 -0
- package/dest/fields/point.d.ts.map +1 -0
- package/dest/fields/point.js +125 -0
- package/dest/fifo/bounded_serial_queue.d.ts +56 -0
- package/dest/fifo/bounded_serial_queue.d.ts.map +1 -0
- package/dest/fifo/bounded_serial_queue.js +94 -0
- package/dest/fifo/index.d.ts +5 -0
- package/dest/fifo/index.d.ts.map +1 -0
- package/dest/fifo/index.js +5 -0
- package/dest/fifo/memory_fifo.d.ts +55 -0
- package/dest/fifo/memory_fifo.d.ts.map +1 -0
- package/dest/fifo/memory_fifo.js +109 -0
- package/dest/fifo/semaphore.d.ts +23 -0
- package/dest/fifo/semaphore.d.ts.map +1 -0
- package/dest/fifo/semaphore.js +30 -0
- package/dest/fifo/serial_queue.d.ts +48 -0
- package/dest/fifo/serial_queue.d.ts.map +1 -0
- package/dest/fifo/serial_queue.js +74 -0
- package/dest/json-rpc/class_converter.d.ts +144 -0
- package/dest/json-rpc/class_converter.d.ts.map +1 -0
- package/dest/json-rpc/class_converter.js +100 -0
- package/dest/json-rpc/client/index.d.ts +2 -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/json_rpc_client.d.ts +29 -0
- package/dest/json-rpc/client/json_rpc_client.d.ts.map +1 -0
- package/dest/json-rpc/client/json_rpc_client.js +104 -0
- package/dest/json-rpc/client/json_rpc_client.test.d.ts +2 -0
- package/dest/json-rpc/client/json_rpc_client.test.d.ts.map +1 -0
- package/dest/json-rpc/client/json_rpc_client.test.js +20 -0
- package/dest/json-rpc/convert.d.ts +28 -0
- package/dest/json-rpc/convert.d.ts.map +1 -0
- package/dest/json-rpc/convert.js +139 -0
- package/dest/json-rpc/convert.test.d.ts +2 -0
- package/dest/json-rpc/convert.test.d.ts.map +1 -0
- package/dest/json-rpc/convert.test.js +68 -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 +17 -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 +17 -0
- package/dest/json-rpc/fixtures/test_state.d.ts +47 -0
- package/dest/json-rpc/fixtures/test_state.d.ts.map +1 -0
- package/dest/json-rpc/fixtures/test_state.js +62 -0
- package/dest/json-rpc/index.d.ts +3 -0
- package/dest/json-rpc/index.d.ts.map +1 -0
- package/dest/json-rpc/index.js +3 -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 +18 -0
- package/dest/json-rpc/server/index.d.ts +3 -0
- package/dest/json-rpc/server/index.d.ts.map +1 -0
- package/dest/json-rpc/server/index.js +3 -0
- package/dest/json-rpc/server/json_proxy.d.ts +18 -0
- package/dest/json-rpc/server/json_proxy.d.ts.map +1 -0
- package/dest/json-rpc/server/json_proxy.js +36 -0
- package/dest/json-rpc/server/json_rpc_server.d.ts +34 -0
- package/dest/json-rpc/server/json_rpc_server.d.ts.map +1 -0
- package/dest/json-rpc/server/json_rpc_server.js +133 -0
- package/dest/json-rpc/server/json_rpc_server.test.d.ts +2 -0
- package/dest/json-rpc/server/json_rpc_server.test.d.ts.map +1 -0
- package/dest/json-rpc/server/json_rpc_server.test.js +22 -0
- package/dest/log/console.d.ts +11 -0
- package/dest/log/console.d.ts.map +1 -0
- package/dest/log/console.js +38 -0
- package/dest/log/debug.d.ts +43 -0
- package/dest/log/debug.d.ts.map +1 -0
- package/dest/log/debug.js +75 -0
- package/dest/log/index.d.ts +9 -0
- package/dest/log/index.d.ts.map +1 -0
- package/dest/log/index.js +5 -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 +42 -0
- package/dest/log/log_history.test.d.ts +2 -0
- package/dest/log/log_history.test.d.ts.map +1 -0
- package/dest/log/log_history.test.js +78 -0
- package/dest/log/logger.d.ts +34 -0
- package/dest/log/logger.d.ts.map +1 -0
- package/dest/log/logger.js +78 -0
- package/dest/mutex/index.d.ts +53 -0
- package/dest/mutex/index.d.ts.map +1 -0
- package/dest/mutex/index.js +74 -0
- package/dest/mutex/mutex.test.d.ts +9 -0
- package/dest/mutex/mutex.test.d.ts.map +1 -0
- package/dest/mutex/mutex.test.js +58 -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 +2 -0
- package/dest/retry/index.d.ts +44 -0
- package/dest/retry/index.d.ts.map +1 -0
- package/dest/retry/index.js +89 -0
- package/dest/running-promise/index.d.ts +35 -0
- package/dest/running-promise/index.d.ts.map +1 -0
- package/dest/running-promise/index.js +59 -0
- package/dest/serialize/buffer_reader.d.ts +188 -0
- package/dest/serialize/buffer_reader.d.ts.map +1 -0
- package/dest/serialize/buffer_reader.js +229 -0
- package/dest/serialize/buffer_reader.test.d.ts +2 -0
- package/dest/serialize/buffer_reader.test.d.ts.map +1 -0
- package/dest/serialize/buffer_reader.test.js +156 -0
- package/dest/serialize/deserializer.d.ts +134 -0
- package/dest/serialize/deserializer.d.ts.map +1 -0
- package/dest/serialize/deserializer.js +145 -0
- package/dest/serialize/free_funcs.d.ts +203 -0
- package/dest/serialize/free_funcs.d.ts.map +1 -0
- package/dest/serialize/free_funcs.js +250 -0
- package/dest/serialize/index.d.ts +6 -0
- package/dest/serialize/index.d.ts.map +1 -0
- package/dest/serialize/index.js +6 -0
- package/dest/serialize/serialize.test.d.ts +2 -0
- package/dest/serialize/serialize.test.d.ts.map +1 -0
- package/dest/serialize/serialize.test.js +68 -0
- package/dest/serialize/serializer.d.ts +89 -0
- package/dest/serialize/serializer.d.ts.map +1 -0
- package/dest/serialize/serializer.js +111 -0
- package/dest/serialize/types.d.ts +33 -0
- package/dest/serialize/types.d.ts.map +1 -0
- package/dest/serialize/types.js +22 -0
- package/dest/sleep/index.d.ts +52 -0
- package/dest/sleep/index.d.ts.map +1 -0
- package/dest/sleep/index.js +70 -0
- package/dest/timer/index.d.ts +3 -0
- package/dest/timer/index.d.ts.map +1 -0
- package/dest/timer/index.js +3 -0
- package/dest/timer/timeout.d.ts +41 -0
- package/dest/timer/timeout.d.ts.map +1 -0
- package/dest/timer/timeout.js +62 -0
- package/dest/timer/timer.d.ts +33 -0
- package/dest/timer/timer.d.ts.map +1 -0
- package/dest/timer/timer.js +38 -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 +5 -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 +46 -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 +21 -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 +37 -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 +39 -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 +18 -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 +56 -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 +12 -0
- package/dest/transport/index.d.ts +12 -0
- package/dest/transport/index.d.ts.map +1 -0
- package/dest/transport/index.js +12 -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 +2 -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 +2 -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 +2 -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 +3 -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 +28 -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 +48 -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 +30 -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 +44 -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 +94 -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 +101 -0
- package/dest/types/index.d.ts +7 -0
- package/dest/types/index.d.ts.map +1 -0
- package/dest/types/index.js +2 -0
- package/dest/url/index.d.ts +9 -0
- package/dest/url/index.d.ts.map +1 -0
- package/dest/url/index.js +66 -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 +166 -0
- package/dest/wasm/index.d.ts +2 -0
- package/dest/wasm/index.d.ts.map +1 -0
- package/dest/wasm/index.js +2 -0
- package/dest/wasm/wasm_module.d.ts +135 -0
- package/dest/wasm/wasm_module.d.ts.map +1 -0
- package/dest/wasm/wasm_module.js +205 -0
- package/dest/wasm/wasm_module.test.d.ts +2 -0
- package/dest/wasm/wasm_module.test.d.ts.map +1 -0
- package/dest/wasm/wasm_module.test.js +24 -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 +3 -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 +22 -0
- package/dest/worker/browser/web_data_store.d.ts +23 -0
- package/dest/worker/browser/web_data_store.d.ts.map +1 -0
- package/dest/worker/browser/web_data_store.js +32 -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 +23 -0
- package/dest/worker/data_store.d.ts +20 -0
- package/dest/worker/data_store.d.ts.map +1 -0
- package/dest/worker/data_store.js +2 -0
- package/dest/worker/index.d.ts +3 -0
- package/dest/worker/index.d.ts.map +1 -0
- package/dest/worker/index.js +2 -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 +3 -0
- package/dest/worker/node/node_data_store.d.ts +12 -0
- package/dest/worker/node/node_data_store.d.ts.map +1 -0
- package/dest/worker/node/node_data_store.js +21 -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 +20 -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 +26 -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 +2 -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 +62 -0
- package/package.json +1 -1
- package/src/abi/abi.ts +8 -2
- package/src/abi/encoder.ts +5 -3
- package/Dockerfile +0 -15
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { asyncMap } from './index.js';
|
|
2
|
+
describe('asyncMap', () => {
|
|
3
|
+
test('execute list item sequentially', async () => {
|
|
4
|
+
const sleepAndLog = (ms, idx) => new Promise(resolve => setTimeout(() => resolve(idx), ms));
|
|
5
|
+
const result = await asyncMap([100, 0, 30, 1], (ms, i) => sleepAndLog(ms, i));
|
|
6
|
+
expect(result).toEqual([0, 1, 2, 3]);
|
|
7
|
+
});
|
|
8
|
+
});
|
|
9
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYXN5bmNfbWFwLnRlc3QuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvYXN5bmMtbWFwL2FzeW5jX21hcC50ZXN0LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFBRSxRQUFRLEVBQUUsTUFBTSxZQUFZLENBQUM7QUFFdEMsUUFBUSxDQUFDLFVBQVUsRUFBRSxHQUFHLEVBQUU7SUFDeEIsSUFBSSxDQUFDLGdDQUFnQyxFQUFFLEtBQUssSUFBSSxFQUFFO1FBQ2hELE1BQU0sV0FBVyxHQUFHLENBQUMsRUFBVSxFQUFFLEdBQVcsRUFBRSxFQUFFLENBQUMsSUFBSSxPQUFPLENBQUMsT0FBTyxDQUFDLEVBQUUsQ0FBQyxVQUFVLENBQUMsR0FBRyxFQUFFLENBQUMsT0FBTyxDQUFDLEdBQUcsQ0FBQyxFQUFFLEVBQUUsQ0FBQyxDQUFDLENBQUM7UUFDNUcsTUFBTSxNQUFNLEdBQUcsTUFBTSxRQUFRLENBQUMsQ0FBQyxHQUFHLEVBQUUsQ0FBQyxFQUFFLEVBQUUsRUFBRSxDQUFDLENBQUMsRUFBRSxDQUFDLEVBQUUsRUFBRSxDQUFDLEVBQUUsRUFBRSxDQUFDLFdBQVcsQ0FBQyxFQUFFLEVBQUUsQ0FBQyxDQUFDLENBQUMsQ0FBQztRQUM5RSxNQUFNLENBQUMsTUFBTSxDQUFDLENBQUMsT0FBTyxDQUFDLENBQUMsQ0FBQyxFQUFFLENBQUMsRUFBRSxDQUFDLEVBQUUsQ0FBQyxDQUFDLENBQUMsQ0FBQztJQUN2QyxDQUFDLENBQUMsQ0FBQztBQUNMLENBQUMsQ0FBQyxDQUFDIn0=
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Maps an array of elements by applying an asynchronous function to each element in sequence,
|
|
3
|
+
* and returns a new array with the results. The function receives each element of the array
|
|
4
|
+
* and its index as arguments, and should return a Promise that resolves to the desired value.
|
|
5
|
+
*
|
|
6
|
+
* @typeParam T - The original array element type.
|
|
7
|
+
* @typeParam U - The resulting array element type.
|
|
8
|
+
* @param arr - The array to map.
|
|
9
|
+
* @param fn - The async function to apply on each element of the array.
|
|
10
|
+
* @returns A Promise that resolves to a new array containing the mapped values.
|
|
11
|
+
*/
|
|
12
|
+
export declare function asyncMap<T, U>(arr: T[], fn: (e: T, i: number) => Promise<U>): Promise<U[]>;
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/async-map/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,wBAAsB,QAAQ,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,EAAE,CAAC,CAMhG"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Maps an array of elements by applying an asynchronous function to each element in sequence,
|
|
3
|
+
* and returns a new array with the results. The function receives each element of the array
|
|
4
|
+
* and its index as arguments, and should return a Promise that resolves to the desired value.
|
|
5
|
+
*
|
|
6
|
+
* @typeParam T - The original array element type.
|
|
7
|
+
* @typeParam U - The resulting array element type.
|
|
8
|
+
* @param arr - The array to map.
|
|
9
|
+
* @param fn - The async function to apply on each element of the array.
|
|
10
|
+
* @returns A Promise that resolves to a new array containing the mapped values.
|
|
11
|
+
*/
|
|
12
|
+
export async function asyncMap(arr, fn) {
|
|
13
|
+
const results = [];
|
|
14
|
+
for (let i = 0; i < arr.length; ++i) {
|
|
15
|
+
results.push(await fn(arr[i], i));
|
|
16
|
+
}
|
|
17
|
+
return results;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvYXN5bmMtbWFwL2luZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOzs7Ozs7Ozs7O0dBVUc7QUFDSCxNQUFNLENBQUMsS0FBSyxVQUFVLFFBQVEsQ0FBTyxHQUFRLEVBQUUsRUFBbUM7SUFDaEYsTUFBTSxPQUFPLEdBQVEsRUFBRSxDQUFDO0lBQ3hCLEtBQUssSUFBSSxDQUFDLEdBQUcsQ0FBQyxFQUFFLENBQUMsR0FBRyxHQUFHLENBQUMsTUFBTSxFQUFFLEVBQUUsQ0FBQyxFQUFFO1FBQ25DLE9BQU8sQ0FBQyxJQUFJLENBQUMsTUFBTSxFQUFFLENBQUMsR0FBRyxDQUFDLENBQUMsQ0FBQyxFQUFFLENBQUMsQ0FBQyxDQUFDLENBQUM7S0FDbkM7SUFDRCxPQUFPLE9BQU8sQ0FBQztBQUNqQixDQUFDIn0=
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
import { Fr } from '../fields/index.js';
|
|
3
|
+
import { BufferReader } from '../serialize/buffer_reader.js';
|
|
4
|
+
/**
|
|
5
|
+
* AztecAddress represents a 32-byte address in the Aztec Protocol. It provides methods to create, manipulate, and
|
|
6
|
+
* compare addresses. The maximum value of an address is determined by the field modulus and all instances of AztecAddress
|
|
7
|
+
* should have a value less than or equal to this max value. This class also provides helper functions to convert
|
|
8
|
+
* addresses from strings, buffers, and other formats.
|
|
9
|
+
*/
|
|
10
|
+
export declare class AztecAddress {
|
|
11
|
+
/**
|
|
12
|
+
* The buffer field.
|
|
13
|
+
*/
|
|
14
|
+
readonly buffer: Buffer;
|
|
15
|
+
static SIZE_IN_BYTES: number;
|
|
16
|
+
static ZERO: AztecAddress;
|
|
17
|
+
static MODULUS: bigint;
|
|
18
|
+
static MAX_VALUE: bigint;
|
|
19
|
+
constructor(
|
|
20
|
+
/**
|
|
21
|
+
* The buffer field.
|
|
22
|
+
*/
|
|
23
|
+
buffer: Buffer);
|
|
24
|
+
/**
|
|
25
|
+
* Generates a random AztecAddress instance, using the Fr field (a finite field) to create a random value
|
|
26
|
+
* within a valid range and then converting it into a Buffer of a fixed size in bytes.
|
|
27
|
+
*
|
|
28
|
+
* @returns A new AztecAddress instance with a random value.
|
|
29
|
+
*/
|
|
30
|
+
static random(): AztecAddress;
|
|
31
|
+
/**
|
|
32
|
+
* Creates an AztecAddress instance from a given buffer or BufferReader.
|
|
33
|
+
* If the input is a Buffer, it wraps it in a BufferReader before processing.
|
|
34
|
+
* Throws an error if the input length is not equal to the expected size.
|
|
35
|
+
*
|
|
36
|
+
* @param buffer - The input buffer or BufferReader containing the address data.
|
|
37
|
+
* @returns - A new AztecAddress instance with the extracted address data.
|
|
38
|
+
*/
|
|
39
|
+
static fromBuffer(buffer: Buffer | BufferReader): AztecAddress;
|
|
40
|
+
/**
|
|
41
|
+
* Create an AztecAddress instance from a hex-encoded string.
|
|
42
|
+
* The input 'address' should be prefixed with '0x' or not, and have exactly 64 hex characters.
|
|
43
|
+
* Throws an error if the input length is invalid or address value is out of range.
|
|
44
|
+
*
|
|
45
|
+
* @param address - The hex-encoded string representing the Aztec address.
|
|
46
|
+
* @returns An AztecAddress instance.
|
|
47
|
+
*/
|
|
48
|
+
static fromString(address: string): AztecAddress;
|
|
49
|
+
/**
|
|
50
|
+
* Creates an AztecAddress from a bigint.
|
|
51
|
+
* The provided value must be within the range of a field.
|
|
52
|
+
* @param address - The bigint representation of the address.
|
|
53
|
+
* @returns An AztecAddress instance.
|
|
54
|
+
*/
|
|
55
|
+
static fromBigInt(address: bigint): AztecAddress;
|
|
56
|
+
/**
|
|
57
|
+
* Converts the AztecAddress instance into a Buffer.
|
|
58
|
+
* This method should be used when encoding the address for storage, transmission or serialization purposes.
|
|
59
|
+
*
|
|
60
|
+
* @returns A Buffer representation of the AztecAddress instance.
|
|
61
|
+
*/
|
|
62
|
+
toBuffer(): Buffer;
|
|
63
|
+
/**
|
|
64
|
+
* Convert the AztecAddress to a hexadecimal string representation, with a "0x" prefix.
|
|
65
|
+
* The resulting string will have a length of 66 characters (including the prefix).
|
|
66
|
+
*
|
|
67
|
+
* @returns A hexadecimal string representation of the AztecAddress.
|
|
68
|
+
*/
|
|
69
|
+
toString(): `0x${string}`;
|
|
70
|
+
/**
|
|
71
|
+
* Returns a shortened string representation of the AztecAddress, displaying only the first 10 characters and last 4 characters.
|
|
72
|
+
* This is useful for human-readable displays where the full address is not necessary.
|
|
73
|
+
*
|
|
74
|
+
* @returns A shortened string representation of the address.
|
|
75
|
+
*/
|
|
76
|
+
toShortString(): string;
|
|
77
|
+
/**
|
|
78
|
+
* Returns this address from a Field element.
|
|
79
|
+
* @param field - The Field element to convert.
|
|
80
|
+
* @returns An Address Object from a Field element with the same value.
|
|
81
|
+
*/
|
|
82
|
+
static fromField(field: Fr): AztecAddress;
|
|
83
|
+
/**
|
|
84
|
+
* Returns this address as a field element.
|
|
85
|
+
* @returns A field element with the same value as the address.
|
|
86
|
+
*/
|
|
87
|
+
toField(): Fr;
|
|
88
|
+
/**
|
|
89
|
+
* Returns this address as a bigint. Useful for creating maps indexed by addresses.
|
|
90
|
+
* @returns A bigint with the same value as the address.
|
|
91
|
+
*/
|
|
92
|
+
toBigInt(): bigint;
|
|
93
|
+
/**
|
|
94
|
+
* Determines if this AztecAddress instance is equal to the given AztecAddress instance.
|
|
95
|
+
* Equality is based on the content of their respective buffers.
|
|
96
|
+
*
|
|
97
|
+
* @param other - The AztecAddress instance to compare against.
|
|
98
|
+
* @returns True if the buffers of both instances are equal, false otherwise.
|
|
99
|
+
*/
|
|
100
|
+
equals(other: AztecAddress): boolean;
|
|
101
|
+
/**
|
|
102
|
+
* Checks if the AztecAddress is zero.
|
|
103
|
+
*
|
|
104
|
+
* @returns Returns true if the AztecAddress is equal to the zero address, otherwise returns false.
|
|
105
|
+
*/
|
|
106
|
+
isZero(): boolean;
|
|
107
|
+
/**
|
|
108
|
+
* Friendly representation for debugging purposes.
|
|
109
|
+
*
|
|
110
|
+
* @returns A hex string representing the address.
|
|
111
|
+
*/
|
|
112
|
+
toFriendlyJSON(): `0x${string}`;
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/aztec-address/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,EAAE,EAAE,MAAM,oBAAoB,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAE7D;;;;;GAKG;AACH,qBAAa,YAAY;IAOrB;;OAEG;aACa,MAAM,EAAE,MAAM;IAThC,MAAM,CAAC,aAAa,SAAM;IAC1B,MAAM,CAAC,IAAI,eAA8D;IACzE,MAAM,CAAC,OAAO,SAAuE;IACrF,MAAM,CAAC,SAAS,SAA6B;;IAG3C;;OAEG;IACa,MAAM,EAAE,MAAM;IAQhC;;;;;OAKG;IACH,MAAM,CAAC,MAAM;IAIb;;;;;;;OAOG;IACH,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY;IAK/C;;;;;;;OAOG;IACH,MAAM,CAAC,UAAU,CAAC,OAAO,EAAE,MAAM;IAQjC;;;;;OAKG;IACH,MAAM,CAAC,UAAU,CAAC,OAAO,EAAE,MAAM;IAIjC;;;;;OAKG;IACH,QAAQ;IAIR;;;;;OAKG;IACH,QAAQ,IAAI,KAAK,MAAM,EAAE;IAIzB;;;;;OAKG;IACH,aAAa;IAKb;;;;OAIG;IACH,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,EAAE,GAAG,YAAY;IAIzC;;;OAGG;IACH,OAAO;IAIP;;;OAGG;IACH,QAAQ;IAIR;;;;;;OAMG;IACH,MAAM,CAAC,KAAK,EAAE,YAAY;IAI1B;;;;OAIG;IACH,MAAM;IAIN;;;;OAIG;IACH,cAAc;CAGf"}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { toBigIntBE, toBufferBE } from '../bigint-buffer/index.js';
|
|
2
|
+
import { Fr } from '../fields/index.js';
|
|
3
|
+
import { BufferReader } from '../serialize/buffer_reader.js';
|
|
4
|
+
/**
|
|
5
|
+
* AztecAddress represents a 32-byte address in the Aztec Protocol. It provides methods to create, manipulate, and
|
|
6
|
+
* compare addresses. The maximum value of an address is determined by the field modulus and all instances of AztecAddress
|
|
7
|
+
* should have a value less than or equal to this max value. This class also provides helper functions to convert
|
|
8
|
+
* addresses from strings, buffers, and other formats.
|
|
9
|
+
*/
|
|
10
|
+
export class AztecAddress {
|
|
11
|
+
constructor(
|
|
12
|
+
/**
|
|
13
|
+
* The buffer field.
|
|
14
|
+
*/
|
|
15
|
+
buffer) {
|
|
16
|
+
this.buffer = buffer;
|
|
17
|
+
const value = toBigIntBE(buffer);
|
|
18
|
+
if (value > AztecAddress.MAX_VALUE) {
|
|
19
|
+
throw new Error(`AztecAddress out of range ${value}.`);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Generates a random AztecAddress instance, using the Fr field (a finite field) to create a random value
|
|
24
|
+
* within a valid range and then converting it into a Buffer of a fixed size in bytes.
|
|
25
|
+
*
|
|
26
|
+
* @returns A new AztecAddress instance with a random value.
|
|
27
|
+
*/
|
|
28
|
+
static random() {
|
|
29
|
+
return new AztecAddress(toBufferBE(Fr.random().value, AztecAddress.SIZE_IN_BYTES));
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Creates an AztecAddress instance from a given buffer or BufferReader.
|
|
33
|
+
* If the input is a Buffer, it wraps it in a BufferReader before processing.
|
|
34
|
+
* Throws an error if the input length is not equal to the expected size.
|
|
35
|
+
*
|
|
36
|
+
* @param buffer - The input buffer or BufferReader containing the address data.
|
|
37
|
+
* @returns - A new AztecAddress instance with the extracted address data.
|
|
38
|
+
*/
|
|
39
|
+
static fromBuffer(buffer) {
|
|
40
|
+
const reader = BufferReader.asReader(buffer);
|
|
41
|
+
return new this(reader.readBytes(this.SIZE_IN_BYTES));
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Create an AztecAddress instance from a hex-encoded string.
|
|
45
|
+
* The input 'address' should be prefixed with '0x' or not, and have exactly 64 hex characters.
|
|
46
|
+
* Throws an error if the input length is invalid or address value is out of range.
|
|
47
|
+
*
|
|
48
|
+
* @param address - The hex-encoded string representing the Aztec address.
|
|
49
|
+
* @returns An AztecAddress instance.
|
|
50
|
+
*/
|
|
51
|
+
static fromString(address) {
|
|
52
|
+
const buf = Buffer.from(address.replace(/^0x/i, ''), 'hex');
|
|
53
|
+
if (buf.length !== AztecAddress.SIZE_IN_BYTES) {
|
|
54
|
+
throw new Error(`Invalid length ${buf.length}.`);
|
|
55
|
+
}
|
|
56
|
+
return new AztecAddress(buf);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Creates an AztecAddress from a bigint.
|
|
60
|
+
* The provided value must be within the range of a field.
|
|
61
|
+
* @param address - The bigint representation of the address.
|
|
62
|
+
* @returns An AztecAddress instance.
|
|
63
|
+
*/
|
|
64
|
+
static fromBigInt(address) {
|
|
65
|
+
return new AztecAddress(toBufferBE(address, AztecAddress.SIZE_IN_BYTES));
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Converts the AztecAddress instance into a Buffer.
|
|
69
|
+
* This method should be used when encoding the address for storage, transmission or serialization purposes.
|
|
70
|
+
*
|
|
71
|
+
* @returns A Buffer representation of the AztecAddress instance.
|
|
72
|
+
*/
|
|
73
|
+
toBuffer() {
|
|
74
|
+
return this.buffer;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Convert the AztecAddress to a hexadecimal string representation, with a "0x" prefix.
|
|
78
|
+
* The resulting string will have a length of 66 characters (including the prefix).
|
|
79
|
+
*
|
|
80
|
+
* @returns A hexadecimal string representation of the AztecAddress.
|
|
81
|
+
*/
|
|
82
|
+
toString() {
|
|
83
|
+
return `0x${this.buffer.toString('hex')}`;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Returns a shortened string representation of the AztecAddress, displaying only the first 10 characters and last 4 characters.
|
|
87
|
+
* This is useful for human-readable displays where the full address is not necessary.
|
|
88
|
+
*
|
|
89
|
+
* @returns A shortened string representation of the address.
|
|
90
|
+
*/
|
|
91
|
+
toShortString() {
|
|
92
|
+
const str = this.toString();
|
|
93
|
+
return `${str.slice(0, 10)}...${str.slice(-4)}`;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Returns this address from a Field element.
|
|
97
|
+
* @param field - The Field element to convert.
|
|
98
|
+
* @returns An Address Object from a Field element with the same value.
|
|
99
|
+
*/
|
|
100
|
+
static fromField(field) {
|
|
101
|
+
return new AztecAddress(toBufferBE(field.value, AztecAddress.SIZE_IN_BYTES));
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Returns this address as a field element.
|
|
105
|
+
* @returns A field element with the same value as the address.
|
|
106
|
+
*/
|
|
107
|
+
toField() {
|
|
108
|
+
return Fr.fromBuffer(this.toBuffer());
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Returns this address as a bigint. Useful for creating maps indexed by addresses.
|
|
112
|
+
* @returns A bigint with the same value as the address.
|
|
113
|
+
*/
|
|
114
|
+
toBigInt() {
|
|
115
|
+
return toBigIntBE(this.buffer);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Determines if this AztecAddress instance is equal to the given AztecAddress instance.
|
|
119
|
+
* Equality is based on the content of their respective buffers.
|
|
120
|
+
*
|
|
121
|
+
* @param other - The AztecAddress instance to compare against.
|
|
122
|
+
* @returns True if the buffers of both instances are equal, false otherwise.
|
|
123
|
+
*/
|
|
124
|
+
equals(other) {
|
|
125
|
+
return this.buffer.equals(other.buffer);
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Checks if the AztecAddress is zero.
|
|
129
|
+
*
|
|
130
|
+
* @returns Returns true if the AztecAddress is equal to the zero address, otherwise returns false.
|
|
131
|
+
*/
|
|
132
|
+
isZero() {
|
|
133
|
+
return this.equals(AztecAddress.ZERO);
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Friendly representation for debugging purposes.
|
|
137
|
+
*
|
|
138
|
+
* @returns A hex string representing the address.
|
|
139
|
+
*/
|
|
140
|
+
toFriendlyJSON() {
|
|
141
|
+
return this.toString();
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
AztecAddress.SIZE_IN_BYTES = 32;
|
|
145
|
+
AztecAddress.ZERO = new AztecAddress(Buffer.alloc(AztecAddress.SIZE_IN_BYTES));
|
|
146
|
+
AztecAddress.MODULUS = 0x30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000001n;
|
|
147
|
+
AztecAddress.MAX_VALUE = AztecAddress.MODULUS - 1n;
|
|
148
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvYXp0ZWMtYWRkcmVzcy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUUsVUFBVSxFQUFFLFVBQVUsRUFBRSxNQUFNLDJCQUEyQixDQUFDO0FBQ25FLE9BQU8sRUFBRSxFQUFFLEVBQUUsTUFBTSxvQkFBb0IsQ0FBQztBQUN4QyxPQUFPLEVBQUUsWUFBWSxFQUFFLE1BQU0sK0JBQStCLENBQUM7QUFFN0Q7Ozs7O0dBS0c7QUFDSCxNQUFNLE9BQU8sWUFBWTtJQU12QjtJQUNFOztPQUVHO0lBQ2EsTUFBYztRQUFkLFdBQU0sR0FBTixNQUFNLENBQVE7UUFFOUIsTUFBTSx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DLE1BQU0sQ0FBQyxDQUFDO0lBQ2pDLENBQUM7SUFFRDs7Ozs7O09BTUc7SUFDSCxNQUFNLENBQUMsS0FBbUI7UUFDeEIsT0FBTyxJQUFJLENBQUMsTUFBTSxDQUFDLE1BQU0sQ0FBQyxLQUFLLENBQUMsTUFBTSxDQUFDLENBQUM7SUFDMUMsQ0FBQztJQUVEOzs7O09BSUc7SUFDSCxNQUFNO1FBQ0osT0FBTyxJQUFJLENBQUMsTUFBTSxDQUFDLFlBQVksQ0FBQyxJQUFJLENBQUMsQ0FBQztJQUN4QyxDQUFDO0lBRUQ7Ozs7T0FJRztJQUNILGNBQWM7UUFDWixPQUFPLElBQUksQ0FBQyxRQUFRLEVBQUUsQ0FBQztJQUN6QixDQUFDOztBQXJKTSwwQkFBYSxHQUFHLEVBQUUsQ0FBQztBQUNuQixpQkFBSSxHQUFHLElBQUksWUFBWSxDQUFDLE1BQU0sQ0FBQyxLQUFLLENBQUMsWUFBWSxDQUFDLGFBQWEsQ0FBQyxDQUFDLENBQUM7QUFDbEUsb0JBQU8sR0FBRyxtRUFBbUUsQ0FBQztBQUM5RSxzQkFBUyxHQUFHLFlBQVksQ0FBQyxPQUFPLEdBQUcsRUFBRSxDQUFDIn0=
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bigint-buffer.test.d.ts","sourceRoot":"","sources":["../../src/bigint-buffer/bigint-buffer.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { toHex } from './index.js';
|
|
2
|
+
describe('bigint-buffer', () => {
|
|
3
|
+
describe('toHex', () => {
|
|
4
|
+
it('does not pad even length', () => {
|
|
5
|
+
expect(toHex(16n)).toEqual('0x10');
|
|
6
|
+
});
|
|
7
|
+
it('pads odd length hex to even length', () => {
|
|
8
|
+
expect(toHex(10n)).toEqual('0x0a');
|
|
9
|
+
});
|
|
10
|
+
it('pads zero to even length', () => {
|
|
11
|
+
expect(toHex(0n)).toEqual('0x00');
|
|
12
|
+
});
|
|
13
|
+
it('pads zero to 32 bytes', () => {
|
|
14
|
+
expect(toHex(0n, true)).toEqual('0x0000000000000000000000000000000000000000000000000000000000000000');
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYmlnaW50LWJ1ZmZlci50ZXN0LmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL2JpZ2ludC1idWZmZXIvYmlnaW50LWJ1ZmZlci50ZXN0LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFBRSxLQUFLLEVBQUUsTUFBTSxZQUFZLENBQUM7QUFFbkMsUUFBUSxDQUFDLGVBQWUsRUFBRSxHQUFHLEVBQUU7SUFDN0IsUUFBUSxDQUFDLE9BQU8sRUFBRSxHQUFHLEVBQUU7UUFDckIsRUFBRSxDQUFDLDBCQUEwQixFQUFFLEdBQUcsRUFBRTtZQUNsQyxNQUFNLENBQUMsS0FBSyxDQUFDLEdBQUcsQ0FBQyxDQUFDLENBQUMsT0FBTyxDQUFDLE1BQU0sQ0FBQyxDQUFDO1FBQ3JDLENBQUMsQ0FBQyxDQUFDO1FBRUgsRUFBRSxDQUFDLG9DQUFvQyxFQUFFLEdBQUcsRUFBRTtZQUM1QyxNQUFNLENBQUMsS0FBSyxDQUFDLEdBQUcsQ0FBQyxDQUFDLENBQUMsT0FBTyxDQUFDLE1BQU0sQ0FBQyxDQUFDO1FBQ3JDLENBQUMsQ0FBQyxDQUFDO1FBRUgsRUFBRSxDQUFDLDBCQUEwQixFQUFFLEdBQUcsRUFBRTtZQUNsQyxNQUFNLENBQUMsS0FBSyxDQUFDLEVBQUUsQ0FBQyxDQUFDLENBQUMsT0FBTyxDQUFDLE1BQU0sQ0FBQyxDQUFDO1FBQ3BDLENBQUMsQ0FBQyxDQUFDO1FBRUgsRUFBRSxDQUFDLHVCQUF1QixFQUFFLEdBQUcsRUFBRTtZQUMvQixNQUFNLENBQUMsS0FBSyxDQUFDLEVBQUUsRUFBRSxJQUFJLENBQUMsQ0FBQyxDQUFDLE9BQU8sQ0FBQyxvRUFBb0UsQ0FBQyxDQUFDO1FBQ3hHLENBQUMsQ0FBQyxDQUFDO0lBQ0wsQ0FBQyxDQUFDLENBQUM7QUFDTCxDQUFDLENBQUMsQ0FBQyJ9
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
/**
|
|
3
|
+
* Convert a little-endian buffer into a BigInt.
|
|
4
|
+
* @param buf - The little-endian buffer to convert.
|
|
5
|
+
* @returns A BigInt with the little-endian representation of buf.
|
|
6
|
+
*/
|
|
7
|
+
export declare function toBigIntLE(buf: Buffer): bigint;
|
|
8
|
+
/**
|
|
9
|
+
* Convert a big-endian buffer into a BigInt.
|
|
10
|
+
* @param buf - The big-endian buffer to convert.
|
|
11
|
+
* @returns A BigInt with the big-endian representation of buf.
|
|
12
|
+
*/
|
|
13
|
+
export declare function toBigIntBE(buf: Buffer): bigint;
|
|
14
|
+
/**
|
|
15
|
+
* Convert a BigInt to a little-endian buffer.
|
|
16
|
+
* @param num - The BigInt to convert.
|
|
17
|
+
* @param width - The number of bytes that the resulting buffer should be.
|
|
18
|
+
* @returns A little-endian buffer representation of num.
|
|
19
|
+
*/
|
|
20
|
+
export declare function toBufferLE(num: bigint, width: number): Buffer;
|
|
21
|
+
/**
|
|
22
|
+
* Convert a BigInt to a big-endian buffer.
|
|
23
|
+
* @param num - The BigInt to convert.
|
|
24
|
+
* @param width - The number of bytes that the resulting buffer should be.
|
|
25
|
+
* @returns A big-endian buffer representation of num.
|
|
26
|
+
*/
|
|
27
|
+
export declare function toBufferBE(num: bigint, width: number): Buffer;
|
|
28
|
+
/**
|
|
29
|
+
* Converts a BigInt to its hex representation.
|
|
30
|
+
* @param num - The BigInt to convert.
|
|
31
|
+
* @param padTo32 - Whether to pad the resulting string to 32 bytes.
|
|
32
|
+
* @returns An even-length 0x-prefixed string.
|
|
33
|
+
*/
|
|
34
|
+
export declare function toHex(num: bigint, padTo32?: boolean): `0x${string}`;
|
|
35
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/bigint-buffer/index.ts"],"names":[],"mappings":";AAAA;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAQ9C;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAM9C;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAM7D;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAM7D;AAED;;;;;GAKG;AACH,wBAAgB,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,UAAQ,GAAG,KAAK,MAAM,EAAE,CAKjE"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert a little-endian buffer into a BigInt.
|
|
3
|
+
* @param buf - The little-endian buffer to convert.
|
|
4
|
+
* @returns A BigInt with the little-endian representation of buf.
|
|
5
|
+
*/
|
|
6
|
+
export function toBigIntLE(buf) {
|
|
7
|
+
const reversed = Buffer.from(buf);
|
|
8
|
+
reversed.reverse();
|
|
9
|
+
const hex = reversed.toString('hex');
|
|
10
|
+
if (hex.length === 0) {
|
|
11
|
+
return BigInt(0);
|
|
12
|
+
}
|
|
13
|
+
return BigInt(`0x${hex}`);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Convert a big-endian buffer into a BigInt.
|
|
17
|
+
* @param buf - The big-endian buffer to convert.
|
|
18
|
+
* @returns A BigInt with the big-endian representation of buf.
|
|
19
|
+
*/
|
|
20
|
+
export function toBigIntBE(buf) {
|
|
21
|
+
const hex = buf.toString('hex');
|
|
22
|
+
if (hex.length === 0) {
|
|
23
|
+
return BigInt(0);
|
|
24
|
+
}
|
|
25
|
+
return BigInt(`0x${hex}`);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Convert a BigInt to a little-endian buffer.
|
|
29
|
+
* @param num - The BigInt to convert.
|
|
30
|
+
* @param width - The number of bytes that the resulting buffer should be.
|
|
31
|
+
* @returns A little-endian buffer representation of num.
|
|
32
|
+
*/
|
|
33
|
+
export function toBufferLE(num, width) {
|
|
34
|
+
if (num < BigInt(0))
|
|
35
|
+
throw new Error(`Cannot convert negative bigint ${num.toString()} to buffer with toBufferLE.`);
|
|
36
|
+
const hex = num.toString(16);
|
|
37
|
+
const buffer = Buffer.from(hex.padStart(width * 2, '0').slice(0, width * 2), 'hex');
|
|
38
|
+
buffer.reverse();
|
|
39
|
+
return buffer;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Convert a BigInt to a big-endian buffer.
|
|
43
|
+
* @param num - The BigInt to convert.
|
|
44
|
+
* @param width - The number of bytes that the resulting buffer should be.
|
|
45
|
+
* @returns A big-endian buffer representation of num.
|
|
46
|
+
*/
|
|
47
|
+
export function toBufferBE(num, width) {
|
|
48
|
+
if (num < BigInt(0))
|
|
49
|
+
throw new Error(`Cannot convert negative bigint ${num.toString()} to buffer with toBufferBE.`);
|
|
50
|
+
const hex = num.toString(16);
|
|
51
|
+
const buffer = Buffer.from(hex.padStart(width * 2, '0').slice(0, width * 2), 'hex');
|
|
52
|
+
if (buffer.length > width)
|
|
53
|
+
throw new Error(`Number ${num.toString(16)} does not fit in ${width}`);
|
|
54
|
+
return buffer;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Converts a BigInt to its hex representation.
|
|
58
|
+
* @param num - The BigInt to convert.
|
|
59
|
+
* @param padTo32 - Whether to pad the resulting string to 32 bytes.
|
|
60
|
+
* @returns An even-length 0x-prefixed string.
|
|
61
|
+
*/
|
|
62
|
+
export function toHex(num, padTo32 = false) {
|
|
63
|
+
const str = num.toString(16);
|
|
64
|
+
const targetLen = str.length % 2 === 0 ? str.length : str.length + 1;
|
|
65
|
+
const paddedStr = str.padStart(padTo32 ? 64 : targetLen, '0');
|
|
66
|
+
return `0x${paddedStr}`;
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvYmlnaW50LWJ1ZmZlci9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTs7OztHQUlHO0FBQ0gsTUFBTSxVQUFVLFVBQVUsQ0FBQyxHQUFXO0lBQ3BDLE1BQU0sUUFBUSxHQUFHLE1BQU0sQ0FBQyxJQUFJLENBQUMsR0FBRyxDQUFDLENBQUM7SUFDbEMsUUFBUSxDQUFDLE9BQU8sRUFBRSxDQUFDO0lBQ25CLE1BQU0sR0FBRyxHQUFHLFFBQVEsQ0FBQyxRQUFRLENBQUMsS0FBSyxDQUFDLENBQUM7SUFDckMsSUFBSSxHQUFHLENBQUMsTUFBTSxLQUFLLENBQUMsRUFBRTtRQUNwQixPQUFPLE1BQU0sQ0FBQyxDQUFDLENBQUMsQ0FBQztLQUNsQjtJQUNELE9BQU8sTUFBTSxDQUFDLEtBQUssR0FBRyxFQUFFLENBQUMsQ0FBQztBQUM1QixDQUFDO0FBRUQ7Ozs7R0FJRztBQUNILE1BQU0sVUFBVSxVQUFVLENBQUMsR0FBVztJQUNwQyxNQUFNLEdBQUcsR0FBRyxHQUFHLENBQUMsUUFBUSxDQUFDLEtBQUssQ0FBQyxDQUFDO0lBQ2hDLElBQUksR0FBRyxDQUFDLE1BQU0sS0FBSyxDQUFDLE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ws if target length exceeds the input array length. Does not modify the input array.
|
|
4
|
+
* @param arr - Array with elements to pad.
|
|
5
|
+
* @param elem - Element to use for padding.
|
|
6
|
+
* @param length - Target length.
|
|
7
|
+
* @returns A new padded array.
|
|
8
|
+
*/
|
|
9
|
+
export declare function padArrayEnd<T, N extends number>(arr: T[], elem: T, length: N): Tuple<T, N>;
|
|
10
|
+
/**
|
|
11
|
+
* Pads an array to the target length by prepending elements at the beginning. Throws if target length exceeds the input array length. Does not modify the input array.
|
|
12
|
+
* @param arr - Array with elements to pad.
|
|
13
|
+
* @param elem - Element to use for padding.
|
|
14
|
+
* @param length - Target length.
|
|
15
|
+
* @returns A new padded array.
|
|
16
|
+
*/
|
|
17
|
+
export declare function padArrayStart<T, N extends number>(arr: T[], elem: T, length: N): Tuple<T, N>;
|
|
18
|
+
/**
|
|
19
|
+
* Returns if an array is composed of empty items.
|
|
20
|
+
* @param arr - Array to check.
|
|
21
|
+
* @returns True if every item in the array isEmpty.
|
|
22
|
+
*/
|
|
23
|
+
export declare function isArrayEmpty<T>(arr: T[], isEmpty: (item: T) => boolean): boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Returns the number of non-empty items in an array.
|
|
26
|
+
* @param arr - Array to check.
|
|
27
|
+
* @returns Number of non-empty items in an array.
|
|
28
|
+
*/
|
|
29
|
+
export declare function arrayNonEmptyLength<T>(arr: T[], isEmpty: (item: T) => boolean): number;
|
|
30
|
+
//# sourceMappingURL=array.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"array.d.ts","sourceRoot":"","sources":["../../src/collection/array.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAE9C;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,EAAE,GAAG,EAAE,CAAC,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,GAAG,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAI1F;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,EAAE,GAAG,EAAE,CAAC,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,GAAG,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAI5F;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,EAAE,OAAO,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,OAAO,GAAG,OAAO,CAKhF;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,EAAE,OAAO,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,OAAO,GAAG,MAAM,CAEtF"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pads an array to the target length by appending an element to its end. Throws if target length exceeds the input array length. Does not modify the input array.
|
|
3
|
+
* @param arr - Array with elements to pad.
|
|
4
|
+
* @param elem - Element to use for padding.
|
|
5
|
+
* @param length - Target length.
|
|
6
|
+
* @returns A new padded array.
|
|
7
|
+
*/
|
|
8
|
+
export function padArrayEnd(arr, elem, length) {
|
|
9
|
+
if (arr.length > length)
|
|
10
|
+
throw new Error(`Array size exceeds target length`);
|
|
11
|
+
// Since typescript cannot always deduce that something is a tuple, we cast
|
|
12
|
+
return [...arr, ...Array(length - arr.length).fill(elem)];
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Pads an array to the target length by prepending elements at the beginning. Throws if target length exceeds the input array length. Does not modify the input array.
|
|
16
|
+
* @param arr - Array with elements to pad.
|
|
17
|
+
* @param elem - Element to use for padding.
|
|
18
|
+
* @param length - Target length.
|
|
19
|
+
* @returns A new padded array.
|
|
20
|
+
*/
|
|
21
|
+
export function padArrayStart(arr, elem, length) {
|
|
22
|
+
if (arr.length > length)
|
|
23
|
+
throw new Error(`Array size exceeds target length`);
|
|
24
|
+
// Since typescript cannot always deduce that something is a tuple, we cast
|
|
25
|
+
return [...Array(length - arr.length).fill(elem), ...arr];
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Returns if an array is composed of empty items.
|
|
29
|
+
* @param arr - Array to check.
|
|
30
|
+
* @returns True if every item in the array isEmpty.
|
|
31
|
+
*/
|
|
32
|
+
export function isArrayEmpty(arr, isEmpty) {
|
|
33
|
+
for (const item of arr) {
|
|
34
|
+
if (!isEmpty(item))
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Returns the number of non-empty items in an array.
|
|
41
|
+
* @param arr - Array to check.
|
|
42
|
+
* @returns Number of non-empty items in an array.
|
|
43
|
+
*/
|
|
44
|
+
export function arrayNonEmptyLength(arr, isEmpty) {
|
|
45
|
+
return arr.reduce((sum, item) => (isEmpty(item) ? sum : sum + 1), 0);
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYXJyYXkuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvY29sbGVjdGlvbi9hcnJheS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFFQTs7Ozs7O0dBTUc7QUFDSCxNQUFNLFVBQVUsV0FBVyxDQUFzQixHQUFRLEVBQUUsSUFBTyxFQUFFLE1BQVM7SUFDM0UsSUFBSSxHQUFHLENBQUMsTUFBTSxHQUFHLE1BQU07UUFBRSxNQUFNLElBQUksS0FBSyxDQUFDLGtDQUFrQyxDQUFDLENBQUM7SUFDN0UsMkVBQTJFO0lBQzNFLE9BQU8sQ0FBQyxHQUFHLEdBQUcsRUFBRSxHQUFHLEtBQUssQ0FBQyxNQUFNLEdBQUcsR0FBRyxDQUFDLE1BQU0sQ0FBQyxDQUFDLElB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sourceRoot":"","sources":["../../src/collection/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A class that allows for a value to be committed or rolled back.
|
|
3
|
+
*/
|
|
4
|
+
export declare class Committable<T> {
|
|
5
|
+
private currentValue;
|
|
6
|
+
private nextValue;
|
|
7
|
+
constructor(initialValue: T);
|
|
8
|
+
/**
|
|
9
|
+
* Commits the uncommitted value.
|
|
10
|
+
*/
|
|
11
|
+
commit(): void;
|
|
12
|
+
/**
|
|
13
|
+
* Rolls back the uncommitted value.
|
|
14
|
+
*/
|
|
15
|
+
rollback(): void;
|
|
16
|
+
/**
|
|
17
|
+
* Gets the current value.
|
|
18
|
+
* @param includeUncommitted - Whether to include the uncommitted value.
|
|
19
|
+
* @returns The current value if includeUncommitted is false, otherwise the uncommitted value.
|
|
20
|
+
*/
|
|
21
|
+
get(includeUncommitted?: boolean): T;
|
|
22
|
+
/**
|
|
23
|
+
* Sets the next value to be committed to.
|
|
24
|
+
* @param value - The new value to be set.
|
|
25
|
+
*/
|
|
26
|
+
set(value: T): void;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=committable.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"committable.d.ts","sourceRoot":"","sources":["../../src/committable/committable.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,WAAW,CAAC,CAAC;IACxB,OAAO,CAAC,YAAY,CAAI;IACxB,OAAO,CAAC,SAAS,CAA4B;gBAEjC,YAAY,EAAE,CAAC;IAI3B;;OAEG;IACI,MAAM;IAQb;;OAEG;IACI,QAAQ;IAIf;;;;OAIG;IACI,GAAG,CAAC,kBAAkB,GAAE,OAAe,GAAG,CAAC;IAIlD;;;OAGG;IACI,GAAG,CAAC,KAAK,EAAE,CAAC;CAGpB"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A class that allows for a value to be committed or rolled back.
|
|
3
|
+
*/
|
|
4
|
+
export class Committable {
|
|
5
|
+
constructor(initialValue) {
|
|
6
|
+
this.nextValue = undefined;
|
|
7
|
+
this.currentValue = initialValue;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Commits the uncommitted value.
|
|
11
|
+
*/
|
|
12
|
+
commit() {
|
|
13
|
+
if (this.nextValue === undefined) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
this.currentValue = this.nextValue;
|
|
17
|
+
this.nextValue = undefined;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Rolls back the uncommitted value.
|
|
21
|
+
*/
|
|
22
|
+
rollback() {
|
|
23
|
+
this.nextValue === undefined;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Gets the current value.
|
|
27
|
+
* @param includeUncommitted - Whether to include the uncommitted value.
|
|
28
|
+
* @returns The current value if includeUncommitted is false, otherwise the uncommitted value.
|
|
29
|
+
*/
|
|
30
|
+
get(includeUncommitted = false) {
|
|
31
|
+
return includeUncommitted && this.nextValue ? this.nextValue : this.currentValue;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Sets the next value to be committed to.
|
|
35
|
+
* @param value - The new value to be set.
|
|
36
|
+
*/
|
|
37
|
+
set(value) {
|
|
38
|
+
this.nextValue = value;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29tbWl0dGFibGUuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvY29tbWl0dGFibGUvY29tbWl0dGFibGUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7O0dBRUc7QUFDSCxNQUFNLE9BQU8sV0FBVztJQUl0QixZQUFZLFlBQWU7UUFGbkIsY0FBUyxHQUFrQixTQUFTLENBQUM7UUFHM0MsSUFBSSxDQUFDLFlBQVksR0FBRyxZQUFZLENBQUM7SUFDbkMsQ0FBQztJQUVEOztPQUVHO0lBQ0ksTUFBTTtRQUNYLElBQUksSUFBSSxDQUFDLFNBQVMsS0FBSyxTQUFTLEVBQUU7WUFDaEMsT0FBTztTQUNSO1FBQ0QsSUFBSSxDQUFDLFlBQVksR0FBRyxJQUFJLENBQUMsU0FBUyxDQUFDO1FBQ25DLElBQUksQ0FBQyxTQUFTLEdBQUcsU0FBUyxDQUFDO0lBQzdCLENBQUM7SUFFRDs7T0FFRztJQUNJLFFBQVE7UUFDYixJQUFJLENBQUMsU0FBUyxLQUFLLFNBQVMsQ0FBQztJQUMvQixDQUFDO0lBRUQ7Ozs7T0FJRztJQUNJLEdBQUcsQ0FBQyxxQkFBOEIsS0FBSztRQUM1QyxPQUFPLGtCQUFrQixJQUFJLElBQUksQ0FBQyxTQUFTLENBQUMsQ0FBQyxDQUFDLElBQUksQ0FBQyxTQUFTLENBQUMsQ0FBQyxDQUFDLElBQUksQ0FBQyxZQUFZLENBQUM7SUFDbkYsQ0FBQztJQUVEOzs7T0FHRztJQUNJLEdBQUcsQ0FBQyxLQUFRO1FBQ2pCLElBQUksQ0FBQyxTQUFTLEdBQUcsS0FBSyxDQUFDO0lBQ3pCLENBQUM7Q0FDRiJ9
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"committable.test.d.ts","sourceRoot":"","sources":["../../src/committable/committable.test.ts"],"names":[],"mappings":""}
|