@aztec/foundation 0.7.0 → 0.7.2
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/Dockerfile +15 -0
- package/package.json +1 -1
- package/src/abi/abi.ts +1 -1
- package/src/abi/decoder.ts +1 -1
- package/.tsbuildinfo +0 -1
- package/dest/abi/abi.d.ts +0 -232
- package/dest/abi/abi.d.ts.map +0 -1
- package/dest/abi/abi.js +0 -37
- package/dest/abi/abi_coder.d.ts +0 -8
- package/dest/abi/abi_coder.d.ts.map +0 -1
- package/dest/abi/abi_coder.js +0 -24
- package/dest/abi/decoder.d.ts +0 -57
- package/dest/abi/decoder.d.ts.map +0 -1
- package/dest/abi/decoder.js +0 -149
- package/dest/abi/decoder.test.d.ts +0 -2
- package/dest/abi/decoder.test.d.ts.map +0 -1
- package/dest/abi/decoder.test.js +0 -70
- package/dest/abi/encoder.d.ts +0 -10
- package/dest/abi/encoder.d.ts.map +0 -1
- package/dest/abi/encoder.js +0 -89
- package/dest/abi/encoder.test.d.ts +0 -2
- package/dest/abi/encoder.test.d.ts.map +0 -1
- package/dest/abi/encoder.test.js +0 -74
- package/dest/abi/function_selector.d.ts +0 -73
- package/dest/abi/function_selector.d.ts.map +0 -1
- package/dest/abi/function_selector.js +0 -104
- package/dest/abi/index.d.ts +0 -6
- package/dest/abi/index.d.ts.map +0 -1
- package/dest/abi/index.js +0 -6
- package/dest/async-map/async_map.test.d.ts +0 -2
- package/dest/async-map/async_map.test.d.ts.map +0 -1
- package/dest/async-map/async_map.test.js +0 -9
- package/dest/async-map/index.d.ts +0 -13
- package/dest/async-map/index.d.ts.map +0 -1
- package/dest/async-map/index.js +0 -19
- package/dest/aztec-address/index.d.ts +0 -114
- package/dest/aztec-address/index.d.ts.map +0 -1
- package/dest/aztec-address/index.js +0 -148
- package/dest/bigint-buffer/bigint-buffer.test.d.ts +0 -2
- package/dest/bigint-buffer/bigint-buffer.test.d.ts.map +0 -1
- package/dest/bigint-buffer/bigint-buffer.test.js +0 -18
- package/dest/bigint-buffer/index.d.ts +0 -35
- package/dest/bigint-buffer/index.d.ts.map +0 -1
- package/dest/bigint-buffer/index.js +0 -68
- package/dest/collection/array.d.ts +0 -30
- package/dest/collection/array.d.ts.map +0 -1
- package/dest/collection/array.js +0 -47
- package/dest/collection/index.d.ts +0 -2
- package/dest/collection/index.d.ts.map +0 -1
- package/dest/collection/index.js +0 -2
- package/dest/committable/committable.d.ts +0 -28
- package/dest/committable/committable.d.ts.map +0 -1
- package/dest/committable/committable.js +0 -41
- package/dest/committable/committable.test.d.ts +0 -2
- package/dest/committable/committable.test.d.ts.map +0 -1
- package/dest/committable/committable.test.js +0 -26
- package/dest/committable/index.d.ts +0 -2
- package/dest/committable/index.d.ts.map +0 -1
- package/dest/committable/index.js +0 -2
- package/dest/crypto/index.d.ts +0 -4
- package/dest/crypto/index.d.ts.map +0 -1
- package/dest/crypto/index.js +0 -4
- package/dest/crypto/keccak/index.d.ts +0 -20
- package/dest/crypto/keccak/index.d.ts.map +0 -1
- package/dest/crypto/keccak/index.js +0 -31
- package/dest/crypto/random/index.d.ts +0 -3
- package/dest/crypto/random/index.d.ts.map +0 -1
- package/dest/crypto/random/index.js +0 -36
- package/dest/crypto/random/index.test.d.ts +0 -2
- package/dest/crypto/random/index.test.d.ts.map +0 -1
- package/dest/crypto/random/index.test.js +0 -13
- package/dest/crypto/sha256/index.d.ts +0 -11
- package/dest/crypto/sha256/index.d.ts.map +0 -1
- package/dest/crypto/sha256/index.js +0 -14
- package/dest/crypto/sha256/index.test.d.ts +0 -2
- package/dest/crypto/sha256/index.test.d.ts.map +0 -1
- package/dest/crypto/sha256/index.test.js +0 -11
- package/dest/errors/index.d.ts +0 -8
- package/dest/errors/index.d.ts.map +0 -1
- package/dest/errors/index.js +0 -8
- package/dest/eth-address/eth_address.test.d.ts +0 -2
- package/dest/eth-address/eth_address.test.d.ts.map +0 -1
- package/dest/eth-address/eth_address.test.js +0 -95
- package/dest/eth-address/index.d.ts +0 -144
- package/dest/eth-address/index.d.ts.map +0 -1
- package/dest/eth-address/index.js +0 -228
- package/dest/fields/coordinate.d.ts +0 -67
- package/dest/fields/coordinate.d.ts.map +0 -1
- package/dest/fields/coordinate.js +0 -95
- package/dest/fields/coordinate.test.d.ts +0 -2
- package/dest/fields/coordinate.test.d.ts.map +0 -1
- package/dest/fields/coordinate.test.js +0 -22
- package/dest/fields/fields.d.ts +0 -177
- package/dest/fields/fields.d.ts.map +0 -1
- package/dest/fields/fields.js +0 -219
- package/dest/fields/grumpkin_scalar.d.ts +0 -96
- package/dest/fields/grumpkin_scalar.d.ts.map +0 -1
- package/dest/fields/grumpkin_scalar.js +0 -125
- package/dest/fields/grumpkin_scalar.test.d.ts +0 -2
- package/dest/fields/grumpkin_scalar.test.d.ts.map +0 -1
- package/dest/fields/grumpkin_scalar.test.js +0 -45
- package/dest/fields/index.d.ts +0 -5
- package/dest/fields/index.d.ts.map +0 -1
- package/dest/fields/index.js +0 -5
- package/dest/fields/point.d.ts +0 -105
- package/dest/fields/point.d.ts.map +0 -1
- package/dest/fields/point.js +0 -125
- package/dest/fifo/bounded_serial_queue.d.ts +0 -56
- package/dest/fifo/bounded_serial_queue.d.ts.map +0 -1
- package/dest/fifo/bounded_serial_queue.js +0 -94
- package/dest/fifo/index.d.ts +0 -5
- package/dest/fifo/index.d.ts.map +0 -1
- package/dest/fifo/index.js +0 -5
- package/dest/fifo/memory_fifo.d.ts +0 -55
- package/dest/fifo/memory_fifo.d.ts.map +0 -1
- package/dest/fifo/memory_fifo.js +0 -109
- package/dest/fifo/semaphore.d.ts +0 -23
- package/dest/fifo/semaphore.d.ts.map +0 -1
- package/dest/fifo/semaphore.js +0 -30
- package/dest/fifo/serial_queue.d.ts +0 -48
- package/dest/fifo/serial_queue.d.ts.map +0 -1
- package/dest/fifo/serial_queue.js +0 -74
- package/dest/json-rpc/class_converter.d.ts +0 -144
- package/dest/json-rpc/class_converter.d.ts.map +0 -1
- package/dest/json-rpc/class_converter.js +0 -100
- package/dest/json-rpc/client/index.d.ts +0 -2
- package/dest/json-rpc/client/index.d.ts.map +0 -1
- package/dest/json-rpc/client/index.js +0 -2
- package/dest/json-rpc/client/json_rpc_client.d.ts +0 -29
- package/dest/json-rpc/client/json_rpc_client.d.ts.map +0 -1
- package/dest/json-rpc/client/json_rpc_client.js +0 -104
- package/dest/json-rpc/client/json_rpc_client.test.d.ts +0 -2
- package/dest/json-rpc/client/json_rpc_client.test.d.ts.map +0 -1
- package/dest/json-rpc/client/json_rpc_client.test.js +0 -20
- package/dest/json-rpc/convert.d.ts +0 -28
- package/dest/json-rpc/convert.d.ts.map +0 -1
- package/dest/json-rpc/convert.js +0 -139
- package/dest/json-rpc/convert.test.d.ts +0 -2
- package/dest/json-rpc/convert.test.d.ts.map +0 -1
- package/dest/json-rpc/convert.test.js +0 -68
- package/dest/json-rpc/fixtures/class_a.d.ts +0 -11
- package/dest/json-rpc/fixtures/class_a.d.ts.map +0 -1
- package/dest/json-rpc/fixtures/class_a.js +0 -17
- package/dest/json-rpc/fixtures/class_b.d.ts +0 -11
- package/dest/json-rpc/fixtures/class_b.d.ts.map +0 -1
- package/dest/json-rpc/fixtures/class_b.js +0 -17
- package/dest/json-rpc/fixtures/test_state.d.ts +0 -47
- package/dest/json-rpc/fixtures/test_state.d.ts.map +0 -1
- package/dest/json-rpc/fixtures/test_state.js +0 -62
- package/dest/json-rpc/index.d.ts +0 -3
- package/dest/json-rpc/index.d.ts.map +0 -1
- package/dest/json-rpc/index.js +0 -3
- package/dest/json-rpc/js_utils.d.ts +0 -13
- package/dest/json-rpc/js_utils.d.ts.map +0 -1
- package/dest/json-rpc/js_utils.js +0 -18
- package/dest/json-rpc/server/index.d.ts +0 -3
- package/dest/json-rpc/server/index.d.ts.map +0 -1
- package/dest/json-rpc/server/index.js +0 -3
- package/dest/json-rpc/server/json_proxy.d.ts +0 -18
- package/dest/json-rpc/server/json_proxy.d.ts.map +0 -1
- package/dest/json-rpc/server/json_proxy.js +0 -36
- package/dest/json-rpc/server/json_rpc_server.d.ts +0 -34
- package/dest/json-rpc/server/json_rpc_server.d.ts.map +0 -1
- package/dest/json-rpc/server/json_rpc_server.js +0 -133
- package/dest/json-rpc/server/json_rpc_server.test.d.ts +0 -2
- package/dest/json-rpc/server/json_rpc_server.test.d.ts.map +0 -1
- package/dest/json-rpc/server/json_rpc_server.test.js +0 -22
- package/dest/log/console.d.ts +0 -11
- package/dest/log/console.d.ts.map +0 -1
- package/dest/log/console.js +0 -38
- package/dest/log/debug.d.ts +0 -43
- package/dest/log/debug.d.ts.map +0 -1
- package/dest/log/debug.js +0 -75
- package/dest/log/index.d.ts +0 -9
- package/dest/log/index.d.ts.map +0 -1
- package/dest/log/index.js +0 -5
- package/dest/log/log_history.d.ts +0 -31
- package/dest/log/log_history.d.ts.map +0 -1
- package/dest/log/log_history.js +0 -42
- package/dest/log/log_history.test.d.ts +0 -2
- package/dest/log/log_history.test.d.ts.map +0 -1
- package/dest/log/log_history.test.js +0 -78
- package/dest/log/logger.d.ts +0 -34
- package/dest/log/logger.d.ts.map +0 -1
- package/dest/log/logger.js +0 -78
- package/dest/mutex/index.d.ts +0 -53
- package/dest/mutex/index.d.ts.map +0 -1
- package/dest/mutex/index.js +0 -74
- package/dest/mutex/mutex.test.d.ts +0 -9
- package/dest/mutex/mutex.test.d.ts.map +0 -1
- package/dest/mutex/mutex.test.js +0 -58
- package/dest/mutex/mutex_database.d.ts +0 -10
- package/dest/mutex/mutex_database.d.ts.map +0 -1
- package/dest/mutex/mutex_database.js +0 -2
- package/dest/retry/index.d.ts +0 -44
- package/dest/retry/index.d.ts.map +0 -1
- package/dest/retry/index.js +0 -89
- package/dest/running-promise/index.d.ts +0 -35
- package/dest/running-promise/index.d.ts.map +0 -1
- package/dest/running-promise/index.js +0 -59
- package/dest/serialize/buffer_reader.d.ts +0 -188
- package/dest/serialize/buffer_reader.d.ts.map +0 -1
- package/dest/serialize/buffer_reader.js +0 -229
- package/dest/serialize/buffer_reader.test.d.ts +0 -2
- package/dest/serialize/buffer_reader.test.d.ts.map +0 -1
- package/dest/serialize/buffer_reader.test.js +0 -156
- package/dest/serialize/deserializer.d.ts +0 -134
- package/dest/serialize/deserializer.d.ts.map +0 -1
- package/dest/serialize/deserializer.js +0 -145
- package/dest/serialize/free_funcs.d.ts +0 -203
- package/dest/serialize/free_funcs.d.ts.map +0 -1
- package/dest/serialize/free_funcs.js +0 -250
- package/dest/serialize/index.d.ts +0 -6
- package/dest/serialize/index.d.ts.map +0 -1
- package/dest/serialize/index.js +0 -6
- package/dest/serialize/serialize.test.d.ts +0 -2
- package/dest/serialize/serialize.test.d.ts.map +0 -1
- package/dest/serialize/serialize.test.js +0 -68
- package/dest/serialize/serializer.d.ts +0 -89
- package/dest/serialize/serializer.d.ts.map +0 -1
- package/dest/serialize/serializer.js +0 -111
- package/dest/serialize/types.d.ts +0 -33
- package/dest/serialize/types.d.ts.map +0 -1
- package/dest/serialize/types.js +0 -22
- package/dest/sleep/index.d.ts +0 -52
- package/dest/sleep/index.d.ts.map +0 -1
- package/dest/sleep/index.js +0 -70
- package/dest/timer/index.d.ts +0 -3
- package/dest/timer/index.d.ts.map +0 -1
- package/dest/timer/index.js +0 -3
- package/dest/timer/timeout.d.ts +0 -41
- package/dest/timer/timeout.d.ts.map +0 -1
- package/dest/timer/timeout.js +0 -62
- package/dest/timer/timer.d.ts +0 -33
- package/dest/timer/timer.d.ts.map +0 -1
- package/dest/timer/timer.js +0 -38
- package/dest/transport/browser/index.d.ts +0 -5
- package/dest/transport/browser/index.d.ts.map +0 -1
- package/dest/transport/browser/index.js +0 -5
- package/dest/transport/browser/message_port_socket.d.ts +0 -37
- package/dest/transport/browser/message_port_socket.d.ts.map +0 -1
- package/dest/transport/browser/message_port_socket.js +0 -46
- package/dest/transport/browser/shared_worker_connector.d.ts +0 -19
- package/dest/transport/browser/shared_worker_connector.d.ts.map +0 -1
- package/dest/transport/browser/shared_worker_connector.js +0 -21
- package/dest/transport/browser/shared_worker_listener.d.ts +0 -38
- package/dest/transport/browser/shared_worker_listener.d.ts.map +0 -1
- package/dest/transport/browser/shared_worker_listener.js +0 -37
- package/dest/transport/browser/worker_connector.d.ts +0 -26
- package/dest/transport/browser/worker_connector.d.ts.map +0 -1
- package/dest/transport/browser/worker_connector.js +0 -30
- package/dest/transport/browser/worker_listener.d.ts +0 -39
- package/dest/transport/browser/worker_listener.d.ts.map +0 -1
- package/dest/transport/browser/worker_listener.js +0 -39
- package/dest/transport/dispatch/create_dispatch_fn.d.ts +0 -25
- package/dest/transport/dispatch/create_dispatch_fn.d.ts.map +0 -1
- package/dest/transport/dispatch/create_dispatch_fn.js +0 -18
- package/dest/transport/dispatch/create_dispatch_proxy.d.ts +0 -102
- package/dest/transport/dispatch/create_dispatch_proxy.d.ts.map +0 -1
- package/dest/transport/dispatch/create_dispatch_proxy.js +0 -56
- package/dest/transport/dispatch/messages.d.ts +0 -52
- package/dest/transport/dispatch/messages.d.ts.map +0 -1
- package/dest/transport/dispatch/messages.js +0 -12
- package/dest/transport/index.d.ts +0 -12
- package/dest/transport/index.d.ts.map +0 -1
- package/dest/transport/index.js +0 -12
- package/dest/transport/interface/connector.d.ts +0 -8
- package/dest/transport/interface/connector.d.ts.map +0 -1
- package/dest/transport/interface/connector.js +0 -2
- package/dest/transport/interface/listener.d.ts +0 -13
- package/dest/transport/interface/listener.d.ts.map +0 -1
- package/dest/transport/interface/listener.js +0 -2
- package/dest/transport/interface/socket.d.ts +0 -13
- package/dest/transport/interface/socket.d.ts.map +0 -1
- package/dest/transport/interface/socket.js +0 -2
- package/dest/transport/interface/transferable.d.ts +0 -68
- package/dest/transport/interface/transferable.d.ts.map +0 -1
- package/dest/transport/interface/transferable.js +0 -63
- package/dest/transport/node/index.d.ts +0 -3
- package/dest/transport/node/index.d.ts.map +0 -1
- package/dest/transport/node/index.js +0 -3
- package/dest/transport/node/node_connector.d.ts +0 -28
- package/dest/transport/node/node_connector.d.ts.map +0 -1
- package/dest/transport/node/node_connector.js +0 -28
- package/dest/transport/node/node_connector_socket.d.ts +0 -42
- package/dest/transport/node/node_connector_socket.d.ts.map +0 -1
- package/dest/transport/node/node_connector_socket.js +0 -48
- package/dest/transport/node/node_listener.d.ts +0 -26
- package/dest/transport/node/node_listener.d.ts.map +0 -1
- package/dest/transport/node/node_listener.js +0 -30
- package/dest/transport/node/node_listener_socket.d.ts +0 -37
- package/dest/transport/node/node_listener_socket.d.ts.map +0 -1
- package/dest/transport/node/node_listener_socket.js +0 -44
- package/dest/transport/transport_client.d.ts +0 -61
- package/dest/transport/transport_client.d.ts.map +0 -1
- package/dest/transport/transport_client.js +0 -94
- package/dest/transport/transport_server.d.ts +0 -56
- package/dest/transport/transport_server.d.ts.map +0 -1
- package/dest/transport/transport_server.js +0 -101
- package/dest/types/index.d.ts +0 -7
- package/dest/types/index.d.ts.map +0 -1
- package/dest/types/index.js +0 -2
- package/dest/url/index.d.ts +0 -9
- package/dest/url/index.d.ts.map +0 -1
- package/dest/url/index.js +0 -66
- package/dest/wasm/empty_wasi_sdk.d.ts +0 -130
- package/dest/wasm/empty_wasi_sdk.d.ts.map +0 -1
- package/dest/wasm/empty_wasi_sdk.js +0 -166
- package/dest/wasm/index.d.ts +0 -2
- package/dest/wasm/index.d.ts.map +0 -1
- package/dest/wasm/index.js +0 -2
- package/dest/wasm/wasm_module.d.ts +0 -135
- package/dest/wasm/wasm_module.d.ts.map +0 -1
- package/dest/wasm/wasm_module.js +0 -205
- package/dest/wasm/wasm_module.test.d.ts +0 -2
- package/dest/wasm/wasm_module.test.d.ts.map +0 -1
- package/dest/wasm/wasm_module.test.js +0 -24
- package/dest/worker/browser/index.d.ts +0 -3
- package/dest/worker/browser/index.d.ts.map +0 -1
- package/dest/worker/browser/index.js +0 -3
- package/dest/worker/browser/start_web_module.d.ts +0 -7
- package/dest/worker/browser/start_web_module.d.ts.map +0 -1
- package/dest/worker/browser/start_web_module.js +0 -22
- package/dest/worker/browser/web_data_store.d.ts +0 -23
- package/dest/worker/browser/web_data_store.d.ts.map +0 -1
- package/dest/worker/browser/web_data_store.js +0 -32
- package/dest/worker/browser/web_worker.d.ts +0 -10
- package/dest/worker/browser/web_worker.d.ts.map +0 -1
- package/dest/worker/browser/web_worker.js +0 -23
- package/dest/worker/data_store.d.ts +0 -20
- package/dest/worker/data_store.d.ts.map +0 -1
- package/dest/worker/data_store.js +0 -2
- package/dest/worker/index.d.ts +0 -3
- package/dest/worker/index.d.ts.map +0 -1
- package/dest/worker/index.js +0 -2
- package/dest/worker/node/index.d.ts +0 -3
- package/dest/worker/node/index.d.ts.map +0 -1
- package/dest/worker/node/index.js +0 -3
- package/dest/worker/node/node_data_store.d.ts +0 -12
- package/dest/worker/node/node_data_store.d.ts.map +0 -1
- package/dest/worker/node/node_data_store.js +0 -21
- package/dest/worker/node/node_worker.d.ts +0 -6
- package/dest/worker/node/node_worker.d.ts.map +0 -1
- package/dest/worker/node/node_worker.js +0 -20
- package/dest/worker/node/start_node_module.d.ts +0 -7
- package/dest/worker/node/start_node_module.d.ts.map +0 -1
- package/dest/worker/node/start_node_module.js +0 -26
- package/dest/worker/wasm_worker.d.ts +0 -9
- package/dest/worker/wasm_worker.d.ts.map +0 -1
- package/dest/worker/wasm_worker.js +0 -2
- package/dest/worker/worker_pool.d.ts +0 -40
- package/dest/worker/worker_pool.d.ts.map +0 -1
- package/dest/worker/worker_pool.js +0 -62
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { GrumpkinScalar } from './grumpkin_scalar.js';
|
|
2
|
-
describe('GrumpkinScalar Serialization', () => {
|
|
3
|
-
// Test case for GrumpkinScalar.fromHighLow
|
|
4
|
-
it('fromHighLow should serialize and deserialize correctly', () => {
|
|
5
|
-
const original = GrumpkinScalar.random();
|
|
6
|
-
const high = original.high;
|
|
7
|
-
const low = original.low;
|
|
8
|
-
const deserialized = GrumpkinScalar.fromHighLow(high, low);
|
|
9
|
-
// Check if the deserialized instance is equal to the original
|
|
10
|
-
expect(deserialized).toEqual(original);
|
|
11
|
-
});
|
|
12
|
-
// Test case for GrumpkinScalar.fromBuffer
|
|
13
|
-
it('fromBuffer should serialize and deserialize correctly', () => {
|
|
14
|
-
const original = GrumpkinScalar.random();
|
|
15
|
-
const buffer = original.toBuffer();
|
|
16
|
-
const deserialized = GrumpkinScalar.fromBuffer(buffer);
|
|
17
|
-
// Check if the deserialized instance is equal to the original
|
|
18
|
-
expect(deserialized).toEqual(original);
|
|
19
|
-
});
|
|
20
|
-
// Test case for GrumpkinScalar.fromString
|
|
21
|
-
it('fromString should serialize and deserialize correctly', () => {
|
|
22
|
-
const original = GrumpkinScalar.random();
|
|
23
|
-
const hexString = original.toString();
|
|
24
|
-
const deserialized = GrumpkinScalar.fromString(hexString);
|
|
25
|
-
// Check if the deserialized instance is equal to the original
|
|
26
|
-
expect(deserialized).toEqual(original);
|
|
27
|
-
});
|
|
28
|
-
// Test case for GrumpkinScalar.toBuffer
|
|
29
|
-
it('toBuffer should serialize and deserialize correctly', () => {
|
|
30
|
-
const original = GrumpkinScalar.random();
|
|
31
|
-
const buffer = original.toBuffer();
|
|
32
|
-
const deserialized = GrumpkinScalar.fromBuffer(buffer);
|
|
33
|
-
// Check if the deserialized instance is equal to the original
|
|
34
|
-
expect(deserialized).toEqual(original);
|
|
35
|
-
});
|
|
36
|
-
// Test case for GrumpkinScalar.toString
|
|
37
|
-
it('toString should serialize and deserialize correctly', () => {
|
|
38
|
-
const original = GrumpkinScalar.random();
|
|
39
|
-
const hexString = original.toString();
|
|
40
|
-
const deserialized = GrumpkinScalar.fromString(hexString);
|
|
41
|
-
// Check if the deserialized instance is equal to the original
|
|
42
|
-
expect(deserialized).toEqual(original);
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZ3J1bXBraW5fc2NhbGFyLnRlc3QuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvZ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MsQ0FBQyxPQUFPLENBQUMsUUFBUSxDQUFDLENBQUM7SUFDekMsQ0FBQyxDQUFDLENBQUM7QUFDTCxDQUFDLENBQUMsQ0FBQyJ9
|
package/dest/fields/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/fields/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC;AAChC,cAAc,sBAAsB,CAAC"}
|
package/dest/fields/index.js
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
export * from './fields.js';
|
|
2
|
-
export * from './point.js';
|
|
3
|
-
export * from './coordinate.js';
|
|
4
|
-
export * from './grumpkin_scalar.js';
|
|
5
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvZmllbGRzL2luZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLGNBQWMsYUFBYSxDQUFDO0FBQzVCLGNBQWMsWUFBWSxDQUFDO0FBQzNCLGNBQWMsaUJBQWlCLENBQUM7QUFDaEMsY0FBYyxzQkFBc0IsQ0FBQyJ9
|
package/dest/fields/point.d.ts
DELETED
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
-
import { BufferReader } from '../serialize/buffer_reader.js';
|
|
3
|
-
import { Fr } from './fields.js';
|
|
4
|
-
/**
|
|
5
|
-
* Represents a Point on an elliptic curve with x and y coordinates.
|
|
6
|
-
* The Point class provides methods for creating instances from different input types,
|
|
7
|
-
* converting instances to various output formats, and checking the equality of points.
|
|
8
|
-
*/
|
|
9
|
-
export declare class Point {
|
|
10
|
-
/**
|
|
11
|
-
* The point's x coordinate
|
|
12
|
-
*/
|
|
13
|
-
readonly x: Fr;
|
|
14
|
-
/**
|
|
15
|
-
* The point's y coordinate
|
|
16
|
-
*/
|
|
17
|
-
readonly y: Fr;
|
|
18
|
-
static ZERO: Point;
|
|
19
|
-
static SIZE_IN_BYTES: number;
|
|
20
|
-
/** Used to differentiate this class from AztecAddress */
|
|
21
|
-
readonly kind = "point";
|
|
22
|
-
constructor(
|
|
23
|
-
/**
|
|
24
|
-
* The point's x coordinate
|
|
25
|
-
*/
|
|
26
|
-
x: Fr,
|
|
27
|
-
/**
|
|
28
|
-
* The point's y coordinate
|
|
29
|
-
*/
|
|
30
|
-
y: Fr);
|
|
31
|
-
/**
|
|
32
|
-
* Generate a random Point instance.
|
|
33
|
-
*
|
|
34
|
-
* @returns A randomly generated Point instance.
|
|
35
|
-
*/
|
|
36
|
-
static random(): Point;
|
|
37
|
-
/**
|
|
38
|
-
* Create a Point instance from a given buffer or BufferReader.
|
|
39
|
-
* The input 'buffer' should have exactly 64 bytes representing the x and y coordinates.
|
|
40
|
-
*
|
|
41
|
-
* @param buffer - The buffer or BufferReader containing the x and y coordinates of the point.
|
|
42
|
-
* @returns A Point instance.
|
|
43
|
-
*/
|
|
44
|
-
static fromBuffer(buffer: Buffer | BufferReader): Point;
|
|
45
|
-
/**
|
|
46
|
-
* Create a Point instance from a hex-encoded string.
|
|
47
|
-
* The input 'address' should be prefixed with '0x' or not, and have exactly 128 hex characters representing the x and y coordinates.
|
|
48
|
-
* Throws an error if the input length is invalid or coordinate values are out of range.
|
|
49
|
-
*
|
|
50
|
-
* @param address - The hex-encoded string representing the Point coordinates.
|
|
51
|
-
* @returns A Point instance.
|
|
52
|
-
*/
|
|
53
|
-
static fromString(address: string): Point;
|
|
54
|
-
/**
|
|
55
|
-
* Returns the contents of the point as an array of 2 fields.
|
|
56
|
-
* @returns The point as an array of 2 fields
|
|
57
|
-
*/
|
|
58
|
-
toFields(): Fr[];
|
|
59
|
-
/**
|
|
60
|
-
* Returns the contents of the point as BigInts.
|
|
61
|
-
* @returns The point as BigInts
|
|
62
|
-
*/
|
|
63
|
-
toBigInts(): {
|
|
64
|
-
x: bigint;
|
|
65
|
-
y: bigint;
|
|
66
|
-
};
|
|
67
|
-
/**
|
|
68
|
-
* Converts the Point instance to a Buffer representaion of the coordinates.
|
|
69
|
-
* The outputs buffer length will be 64, the length of both coordinates not represented as fields.
|
|
70
|
-
* @returns A Buffer representation of the Point instance.
|
|
71
|
-
*/
|
|
72
|
-
toBuffer(): Buffer;
|
|
73
|
-
/**
|
|
74
|
-
* Convert the Point instance to a hexadecimal string representation.
|
|
75
|
-
* The output string is prefixed with '0x' and consists of exactly 128 hex characters,
|
|
76
|
-
* representing the concatenated x and y coordinates of the point.
|
|
77
|
-
*
|
|
78
|
-
* @returns A hex-encoded string representing the Point instance.
|
|
79
|
-
*/
|
|
80
|
-
toString(): string;
|
|
81
|
-
/**
|
|
82
|
-
* Generate a short string representation of the Point instance.
|
|
83
|
-
* The returned string includes the first 10 and last 4 characters of the full string representation,
|
|
84
|
-
* with '...' in between to indicate truncation. This is useful for displaying or logging purposes
|
|
85
|
-
* when the full string representation may be too long.
|
|
86
|
-
*
|
|
87
|
-
* @returns A truncated string representation of the Point instance.
|
|
88
|
-
*/
|
|
89
|
-
toShortString(): string;
|
|
90
|
-
/**
|
|
91
|
-
* Check if two Point instances are equal by comparing their buffer values.
|
|
92
|
-
* Returns true if the buffer values are the same, and false otherwise.
|
|
93
|
-
*
|
|
94
|
-
* @param rhs - The Point instance to compare with the current instance.
|
|
95
|
-
* @returns A boolean indicating whether the two Point instances are equal.
|
|
96
|
-
*/
|
|
97
|
-
equals(rhs: Point): boolean;
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Does this object look like a point?
|
|
101
|
-
* @param obj - Object to test if it is a point.
|
|
102
|
-
* @returns Whether it looks like a point.
|
|
103
|
-
*/
|
|
104
|
-
export declare function isPoint(obj: object): obj is Point;
|
|
105
|
-
//# sourceMappingURL=point.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"point.d.ts","sourceRoot":"","sources":["../../src/fields/point.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAC7D,OAAO,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AAEjC;;;;GAIG;AACH,qBAAa,KAAK;IAQd;;OAEG;aACa,CAAC,EAAE,EAAE;IACrB;;OAEG;aACa,CAAC,EAAE,EAAE;IAdvB,MAAM,CAAC,IAAI,QAA+B;IAC1C,MAAM,CAAC,aAAa,SAAwB;IAE5C,yDAAyD;IACzD,SAAgB,IAAI,WAAW;;IAG7B;;OAEG;IACa,CAAC,EAAE,EAAE;IACrB;;OAEG;IACa,CAAC,EAAE,EAAE;IAGvB;;;;OAIG;IACH,MAAM,CAAC,MAAM;IAKb;;;;;;OAMG;IACH,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY;IAK/C;;;;;;;OAOG;IACH,MAAM,CAAC,UAAU,CAAC,OAAO,EAAE,MAAM;IAIjC;;;OAGG;IACH,QAAQ;IAIR;;;OAGG;IACH,SAAS;;;;IAOT;;;;OAIG;IACH,QAAQ;IAIR;;;;;;OAMG;IACH,QAAQ;IAIR;;;;;;;OAOG;IACH,aAAa;IAKb;;;;;;OAMG;IACH,MAAM,CAAC,GAAG,EAAE,KAAK;CAGlB;AAED;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,IAAI,KAAK,CAIjD"}
|
package/dest/fields/point.js
DELETED
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import { BufferReader } from '../serialize/buffer_reader.js';
|
|
2
|
-
import { Fr } from './fields.js';
|
|
3
|
-
/**
|
|
4
|
-
* Represents a Point on an elliptic curve with x and y coordinates.
|
|
5
|
-
* The Point class provides methods for creating instances from different input types,
|
|
6
|
-
* converting instances to various output formats, and checking the equality of points.
|
|
7
|
-
*/
|
|
8
|
-
export class Point {
|
|
9
|
-
constructor(
|
|
10
|
-
/**
|
|
11
|
-
* The point's x coordinate
|
|
12
|
-
*/
|
|
13
|
-
x,
|
|
14
|
-
/**
|
|
15
|
-
* The point's y coordinate
|
|
16
|
-
*/
|
|
17
|
-
y) {
|
|
18
|
-
this.x = x;
|
|
19
|
-
this.y = y;
|
|
20
|
-
/** Used to differentiate this class from AztecAddress */
|
|
21
|
-
this.kind = 'point';
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Generate a random Point instance.
|
|
25
|
-
*
|
|
26
|
-
* @returns A randomly generated Point instance.
|
|
27
|
-
*/
|
|
28
|
-
static random() {
|
|
29
|
-
// TODO is this a random point on the curve?
|
|
30
|
-
return new Point(Fr.random(), Fr.random());
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Create a Point instance from a given buffer or BufferReader.
|
|
34
|
-
* The input 'buffer' should have exactly 64 bytes representing the x and y coordinates.
|
|
35
|
-
*
|
|
36
|
-
* @param buffer - The buffer or BufferReader containing the x and y coordinates of the point.
|
|
37
|
-
* @returns A Point instance.
|
|
38
|
-
*/
|
|
39
|
-
static fromBuffer(buffer) {
|
|
40
|
-
const reader = BufferReader.asReader(buffer);
|
|
41
|
-
return new this(Fr.fromBuffer(reader.readBytes(32)), Fr.fromBuffer(reader.readBytes(32)));
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Create a Point instance from a hex-encoded string.
|
|
45
|
-
* The input 'address' should be prefixed with '0x' or not, and have exactly 128 hex characters representing the x and y coordinates.
|
|
46
|
-
* Throws an error if the input length is invalid or coordinate values are out of range.
|
|
47
|
-
*
|
|
48
|
-
* @param address - The hex-encoded string representing the Point coordinates.
|
|
49
|
-
* @returns A Point instance.
|
|
50
|
-
*/
|
|
51
|
-
static fromString(address) {
|
|
52
|
-
return this.fromBuffer(Buffer.from(address.replace(/^0x/i, ''), 'hex'));
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Returns the contents of the point as an array of 2 fields.
|
|
56
|
-
* @returns The point as an array of 2 fields
|
|
57
|
-
*/
|
|
58
|
-
toFields() {
|
|
59
|
-
return [this.x, this.y];
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Returns the contents of the point as BigInts.
|
|
63
|
-
* @returns The point as BigInts
|
|
64
|
-
*/
|
|
65
|
-
toBigInts() {
|
|
66
|
-
return {
|
|
67
|
-
x: this.x.value,
|
|
68
|
-
y: this.y.value,
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Converts the Point instance to a Buffer representaion of the coordinates.
|
|
73
|
-
* The outputs buffer length will be 64, the length of both coordinates not represented as fields.
|
|
74
|
-
* @returns A Buffer representation of the Point instance.
|
|
75
|
-
*/
|
|
76
|
-
toBuffer() {
|
|
77
|
-
return Buffer.concat([this.x.toBuffer(), this.y.toBuffer()]);
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Convert the Point instance to a hexadecimal string representation.
|
|
81
|
-
* The output string is prefixed with '0x' and consists of exactly 128 hex characters,
|
|
82
|
-
* representing the concatenated x and y coordinates of the point.
|
|
83
|
-
*
|
|
84
|
-
* @returns A hex-encoded string representing the Point instance.
|
|
85
|
-
*/
|
|
86
|
-
toString() {
|
|
87
|
-
return '0x' + this.toBuffer().toString('hex');
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Generate a short string representation of the Point instance.
|
|
91
|
-
* The returned string includes the first 10 and last 4 characters of the full string representation,
|
|
92
|
-
* with '...' in between to indicate truncation. This is useful for displaying or logging purposes
|
|
93
|
-
* when the full string representation may be too long.
|
|
94
|
-
*
|
|
95
|
-
* @returns A truncated string representation of the Point instance.
|
|
96
|
-
*/
|
|
97
|
-
toShortString() {
|
|
98
|
-
const str = this.toString();
|
|
99
|
-
return `${str.slice(0, 10)}...${str.slice(-4)}`;
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Check if two Point instances are equal by comparing their buffer values.
|
|
103
|
-
* Returns true if the buffer values are the same, and false otherwise.
|
|
104
|
-
*
|
|
105
|
-
* @param rhs - The Point instance to compare with the current instance.
|
|
106
|
-
* @returns A boolean indicating whether the two Point instances are equal.
|
|
107
|
-
*/
|
|
108
|
-
equals(rhs) {
|
|
109
|
-
return this.x.equals(rhs.x) && this.y.equals(rhs.y);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
Point.ZERO = new Point(Fr.ZERO, Fr.ZERO);
|
|
113
|
-
Point.SIZE_IN_BYTES = Fr.SIZE_IN_BYTES * 2;
|
|
114
|
-
/**
|
|
115
|
-
* Does this object look like a point?
|
|
116
|
-
* @param obj - Object to test if it is a point.
|
|
117
|
-
* @returns Whether it looks like a point.
|
|
118
|
-
*/
|
|
119
|
-
export function isPoint(obj) {
|
|
120
|
-
if (!obj)
|
|
121
|
-
return false;
|
|
122
|
-
const point = obj;
|
|
123
|
-
return point.kind === 'point' && point.x !== undefined && point.y !== undefined;
|
|
124
|
-
}
|
|
125
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicG9pbnQuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvZmllbGRzL3BvaW50LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFBRSxZQUFZLEVBQUUsTUFBTSwrQkFBK0IsQ0FBQztBQUM3RCxPQUFPLEVBQUUsRUFBRSxFQUFFLE1BQU0sYUFBYSxDQUFDO0FBRWpDOzs7O0dBSUc7QUFDSCxNQUFNLE9BQU8sS0FBSztJQU9oQjtJQUNFOztPQUVHO0lBQ2EsQ0FBSztJQUNyQjs7T0FFRztJQUNhLENBQUs7UUFKTCxNQUFDLEdBQUQsQ0FBQyxDQUFJO1FBSUwsTUFBQyxHQUFELENBQUMsQ0FBSTtRQVh2Qix5REFBeUQ7UUFDekMsU0FBSSxHQUFHLE9BQU8sQ0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7QUFrSDlDOzs7O0dBSUc7QUFDSCxNQUFNLFVBQVUsT0FBTyxDQUFDLEdBQVc7SUFDakMsSUFBSSxDQUFDLEdBQUc7UUFBRSxPQUFPLEtBQUssQ0FBQztJQUN2QixNQUFNLEtBQUssR0FBRyxHQUFZLENBQUM7SUFDM0IsT0FBTyxLQUFLLENBQUMsSUFBSSxLQUFLLE9BQU8sSUFBSSxLQUFLLENBQUMsQ0FBQyxLQUFLLFNBQVMsSUFBSSxLQUFLLENBQUMsQ0FBQyxLQUFLLFNBQVMsQ0FBQztBQUNsRixDQUFDIn0=
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Leverages the unbounded SerialQueue and Semaphore to create a SerialQueue that will block when putting an item
|
|
3
|
-
* if the queue size = maxQueueSize.
|
|
4
|
-
*/
|
|
5
|
-
export declare class BoundedSerialQueue {
|
|
6
|
-
private log;
|
|
7
|
-
private readonly queue;
|
|
8
|
-
private semaphore;
|
|
9
|
-
constructor(maxQueueSize: number, log?: import("../log/logger.js").DebugLogger);
|
|
10
|
-
/**
|
|
11
|
-
* Initializes the underlying SerialQueue instance, allowing items to be processed from the queue.
|
|
12
|
-
* The start method should be called before using the BoundedSerialQueue to ensure proper functionality.
|
|
13
|
-
*/
|
|
14
|
-
start(): void;
|
|
15
|
-
/**
|
|
16
|
-
* Returns the current number of items in the queue.
|
|
17
|
-
* This is useful for monitoring the size of BoundedSerialQueue and understanding its utilization.
|
|
18
|
-
*
|
|
19
|
-
* @returns The length of the queue as an integer value.
|
|
20
|
-
*/
|
|
21
|
-
length(): number;
|
|
22
|
-
/**
|
|
23
|
-
* Cancels the current operation in the SerialQueue, if any, and clears the queue.
|
|
24
|
-
* Any pending tasks in the queue will not be executed, and the queue will be emptied.
|
|
25
|
-
* This method is useful for cleaning up resources and stopping ongoing processes when they are no longer needed.
|
|
26
|
-
* @returns A promise, resolved once cancelled.
|
|
27
|
-
*/
|
|
28
|
-
cancel(): Promise<void>;
|
|
29
|
-
/**
|
|
30
|
-
* Ends the queue processing gracefully, preventing new items from being added.
|
|
31
|
-
* The currently executing item, if any, will complete and remaining queued items
|
|
32
|
-
* will be processed in order. Once all items have been processed, the queue becomes
|
|
33
|
-
* permanently unusable.
|
|
34
|
-
*
|
|
35
|
-
* @returns A promise that resolves when all items in the queue have been processed.
|
|
36
|
-
*/
|
|
37
|
-
end(): Promise<void>;
|
|
38
|
-
/**
|
|
39
|
-
* The caller will block until fn is succesfully enqueued.
|
|
40
|
-
* The fn itself is execute asyncronously and its result discarded.
|
|
41
|
-
* TODO(AD) do we need this if we have exec()?
|
|
42
|
-
* @param fn - The function to call once unblocked.
|
|
43
|
-
*/
|
|
44
|
-
put(fn: () => Promise<void>): Promise<void>;
|
|
45
|
-
/**
|
|
46
|
-
* The caller will block until fn is successfully executed, and it's result returned.
|
|
47
|
-
* @param fn - The function.
|
|
48
|
-
* @returns A promise that resolves with the result once exceuted.
|
|
49
|
-
*/
|
|
50
|
-
exec<T>(fn: () => Promise<T>): Promise<T>;
|
|
51
|
-
/**
|
|
52
|
-
* Awaiting this ensures the queue is empty before resuming.
|
|
53
|
-
*/
|
|
54
|
-
syncPoint(): Promise<void>;
|
|
55
|
-
}
|
|
56
|
-
//# sourceMappingURL=bounded_serial_queue.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bounded_serial_queue.d.ts","sourceRoot":"","sources":["../../src/fifo/bounded_serial_queue.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,qBAAa,kBAAkB;IAIK,OAAO,CAAC,GAAG;IAH7C,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAqB;IAC3C,OAAO,CAAC,SAAS,CAAY;gBAEjB,YAAY,EAAE,MAAM,EAAU,GAAG,yCAA6D;IAI1G;;;OAGG;IACI,KAAK;IAIZ;;;;;OAKG;IACI,MAAM;IAIb;;;;;OAKG;IACI,MAAM;IAIb;;;;;;;OAOG;IACI,GAAG;IAIV;;;;;OAKG;IACU,GAAG,CAAC,EAAE,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAexD;;;;OAIG;IACU,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IAWtD;;OAEG;IACU,SAAS;CAGvB"}
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import { createDebugLogger } from '../log/index.js';
|
|
2
|
-
import { Semaphore } from './semaphore.js';
|
|
3
|
-
import { SerialQueue } from './serial_queue.js';
|
|
4
|
-
/**
|
|
5
|
-
* Leverages the unbounded SerialQueue and Semaphore to create a SerialQueue that will block when putting an item
|
|
6
|
-
* if the queue size = maxQueueSize.
|
|
7
|
-
*/
|
|
8
|
-
export class BoundedSerialQueue {
|
|
9
|
-
constructor(maxQueueSize, log = createDebugLogger('aztec:foundation:bounded_serial_queue')) {
|
|
10
|
-
this.log = log;
|
|
11
|
-
this.queue = new SerialQueue();
|
|
12
|
-
this.semaphore = new Semaphore(maxQueueSize);
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Initializes the underlying SerialQueue instance, allowing items to be processed from the queue.
|
|
16
|
-
* The start method should be called before using the BoundedSerialQueue to ensure proper functionality.
|
|
17
|
-
*/
|
|
18
|
-
start() {
|
|
19
|
-
this.queue.start();
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Returns the current number of items in the queue.
|
|
23
|
-
* This is useful for monitoring the size of BoundedSerialQueue and understanding its utilization.
|
|
24
|
-
*
|
|
25
|
-
* @returns The length of the queue as an integer value.
|
|
26
|
-
*/
|
|
27
|
-
length() {
|
|
28
|
-
return this.queue.length();
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Cancels the current operation in the SerialQueue, if any, and clears the queue.
|
|
32
|
-
* Any pending tasks in the queue will not be executed, and the queue will be emptied.
|
|
33
|
-
* This method is useful for cleaning up resources and stopping ongoing processes when they are no longer needed.
|
|
34
|
-
* @returns A promise, resolved once cancelled.
|
|
35
|
-
*/
|
|
36
|
-
cancel() {
|
|
37
|
-
return this.queue.cancel();
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Ends the queue processing gracefully, preventing new items from being added.
|
|
41
|
-
* The currently executing item, if any, will complete and remaining queued items
|
|
42
|
-
* will be processed in order. Once all items have been processed, the queue becomes
|
|
43
|
-
* permanently unusable.
|
|
44
|
-
*
|
|
45
|
-
* @returns A promise that resolves when all items in the queue have been processed.
|
|
46
|
-
*/
|
|
47
|
-
end() {
|
|
48
|
-
return this.queue.end();
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* The caller will block until fn is succesfully enqueued.
|
|
52
|
-
* The fn itself is execute asyncronously and its result discarded.
|
|
53
|
-
* TODO(AD) do we need this if we have exec()?
|
|
54
|
-
* @param fn - The function to call once unblocked.
|
|
55
|
-
*/
|
|
56
|
-
async put(fn) {
|
|
57
|
-
await this.semaphore.acquire();
|
|
58
|
-
this.queue
|
|
59
|
-
.put(async () => {
|
|
60
|
-
try {
|
|
61
|
-
await fn();
|
|
62
|
-
}
|
|
63
|
-
finally {
|
|
64
|
-
this.semaphore.release();
|
|
65
|
-
}
|
|
66
|
-
})
|
|
67
|
-
.catch(err => {
|
|
68
|
-
this.log.error('BoundedSerialQueue handler exception:', err);
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* The caller will block until fn is successfully executed, and it's result returned.
|
|
73
|
-
* @param fn - The function.
|
|
74
|
-
* @returns A promise that resolves with the result once exceuted.
|
|
75
|
-
*/
|
|
76
|
-
async exec(fn) {
|
|
77
|
-
await this.semaphore.acquire();
|
|
78
|
-
return this.queue.put(async () => {
|
|
79
|
-
try {
|
|
80
|
-
return await fn();
|
|
81
|
-
}
|
|
82
|
-
finally {
|
|
83
|
-
this.semaphore.release();
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Awaiting this ensures the queue is empty before resuming.
|
|
89
|
-
*/
|
|
90
|
-
async syncPoint() {
|
|
91
|
-
await this.queue.syncPoint();
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYm91bmRlZF9zZXJpYWxfcXVldWUuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvZmlmby9ib3VuZGVkX3NlcmlhbF9xdWV1ZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUUsaUJBQWlCLEVBQUUsTUFBTSxpQkFBaUIsQ0FBQztBQUNwRCxPQUFPLEVBQUUsU0FBUyxFQUFFLE1BQU0sZ0JBQWdCLENBQUM7QUFDM0MsT0FBTyxFQUFFLFdBQVcsRUFBRSxNQUFNLG1CQUFtQixDQUFDO0FBRWhEOzs7R0FHRztBQUNILE1BQU0sT0FBTyxrQkFBa0I7SUFJN0IsWUFBWSxZQUFvQixFQUFVLE1BQU0saUJBQWlCLENBQUMsdUNBQXVDLENBQUM7UUFBaEUsUUFBRyxHQUFILEdBQUcsQ0FBNkQ7UUFIekYsVUFBSyxHQUFHLElBQUksV0FBVyxFQUFFLENBQUM7UUFJekMsSUFBSSxDQUFDLFNBQVMsR0FBRyxJQUFJLFNBQVMsQ0FBQyxZQUFZLENBQUMsQ0FBQztJQUMvQyxDQUFDO0lBRUQ7OztPQUdHO0lBQ0ksS0FBSztRQUNWLElBQUksQ0FBQyxLQUFLLENBQUMsS0FBSyxFQUFFLENBQUM7SUFDckIsQ0FBQztJQUVEOzs7OztPQUtHO0lBQ0ksTUFBTTtRQUNYLE9BQU8sSUFBSSxDQUFDLEtBQUssQ0FBQyxNQUFNLEVBQUUsQ0FBQztJQUM3QixDQUFDO0lBRUQ7Ozs7O09BS0c7SUFDSSxNQUFNO1FBQ1gsT0F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UQ7O09BRUc7SUFDSSxLQUFLLENBQUMsU0FBUztRQUNwQixNQUFNLElBQUksQ0FBQyxLQUFLLENBQUMsU0FBUyxFQUFFLENBQUM7SUFDL0IsQ0FBQztDQUNGIn0=
|
package/dest/fifo/index.d.ts
DELETED
package/dest/fifo/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/fifo/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,gBAAgB,CAAC"}
|
package/dest/fifo/index.js
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
export * from './memory_fifo.js';
|
|
2
|
-
export * from './serial_queue.js';
|
|
3
|
-
export * from './bounded_serial_queue.js';
|
|
4
|
-
export * from './semaphore.js';
|
|
5
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvZmlmby9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxjQUFjLGtCQUFrQixDQUFDO0FBQ2pDLGNBQWMsbUJBQW1CLENBQUM7QUFDbEMsY0FBYywyQkFBMkIsQ0FBQztBQUMxQyxjQUFjLGdCQUFnQixDQUFDIn0=
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A simple fifo queue. It can grow unbounded. It can have multiple producers and consumers.
|
|
3
|
-
* Putting an item onto the queue always succeeds, unless either end() or cancel() has been called in which case
|
|
4
|
-
* the item being pushed is simply discarded.
|
|
5
|
-
*/
|
|
6
|
-
export declare class MemoryFifo<T> {
|
|
7
|
-
private log;
|
|
8
|
-
private waiting;
|
|
9
|
-
private items;
|
|
10
|
-
private flushing;
|
|
11
|
-
constructor(log?: import("../log/logger.js").DebugLogger);
|
|
12
|
-
/**
|
|
13
|
-
* Returns the current number of items in the queue.
|
|
14
|
-
* The length represents the size of the queue at the time of invocation and may change as new items are added or consumed.
|
|
15
|
-
*
|
|
16
|
-
* @returns The number of items in the queue.
|
|
17
|
-
*/
|
|
18
|
-
length(): number;
|
|
19
|
-
/**
|
|
20
|
-
* Returns next item within the queue, or blocks until and item has been put into the queue.
|
|
21
|
-
* If given a timeout, the promise will reject if no item is received after `timeout` seconds.
|
|
22
|
-
* If the queue is flushing, `null` is returned.
|
|
23
|
-
* @param timeout - The timeout in seconds.
|
|
24
|
-
* @returns A result promise.
|
|
25
|
-
*/
|
|
26
|
-
get(timeout?: number): Promise<T | null>;
|
|
27
|
-
/**
|
|
28
|
-
* Put an item onto back of the queue.
|
|
29
|
-
* @param item - The item to enqueue.
|
|
30
|
-
*/
|
|
31
|
-
put(item: T): void;
|
|
32
|
-
/**
|
|
33
|
-
* Once ended, no further items are added to queue. Consumers will consume remaining items within the queue.
|
|
34
|
-
* The queue is not reusable after calling `end()`.
|
|
35
|
-
* Any consumers waiting for an item receive null.
|
|
36
|
-
*/
|
|
37
|
-
end(): void;
|
|
38
|
-
/**
|
|
39
|
-
* Once cancelled, all items are discarded from the queue, and no further items are added to the queue.
|
|
40
|
-
* The queue is not reusable after calling `cancel()`.
|
|
41
|
-
* Any consumers waiting for an item receive null.
|
|
42
|
-
*/
|
|
43
|
-
cancel(): void;
|
|
44
|
-
/**
|
|
45
|
-
* Process items from the queue using a provided handler function.
|
|
46
|
-
* The function iterates over items in the queue, invoking the handler for each item until the queue is empty or flushing.
|
|
47
|
-
* If the handler throws an error, it will be caught and logged as 'Queue handler exception:', but the iteration will continue.
|
|
48
|
-
* The process function returns a promise that resolves when there are no more items in the queue or the queue is flushing.
|
|
49
|
-
*
|
|
50
|
-
* @param handler - A function that takes an item of type T and returns a Promise<void> after processing the item.
|
|
51
|
-
* @returns A Promise<void> that resolves when the queue is finished processing.
|
|
52
|
-
*/
|
|
53
|
-
process(handler: (item: T) => Promise<void>): Promise<void>;
|
|
54
|
-
}
|
|
55
|
-
//# sourceMappingURL=memory_fifo.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"memory_fifo.d.ts","sourceRoot":"","sources":["../../src/fifo/memory_fifo.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,qBAAa,UAAU,CAAC,CAAC;IAKX,OAAO,CAAC,GAAG;IAJvB,OAAO,CAAC,OAAO,CAAoC;IACnD,OAAO,CAAC,KAAK,CAAW;IACxB,OAAO,CAAC,QAAQ,CAAS;gBAEL,GAAG,yCAAoD;IAE3E;;;;;OAKG;IACI,MAAM;IAIb;;;;;;OAMG;IACI,GAAG,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC;IAyB/C;;;OAGG;IACI,GAAG,CAAC,IAAI,EAAE,CAAC;IAUlB;;;;OAIG;IACI,GAAG;IAKV;;;;OAIG;IACI,MAAM;IAMb;;;;;;;;OAQG;IACU,OAAO,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC;CAazD"}
|
package/dest/fifo/memory_fifo.js
DELETED
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import { createDebugLogger } from '../log/index.js';
|
|
2
|
-
/**
|
|
3
|
-
* A simple fifo queue. It can grow unbounded. It can have multiple producers and consumers.
|
|
4
|
-
* Putting an item onto the queue always succeeds, unless either end() or cancel() has been called in which case
|
|
5
|
-
* the item being pushed is simply discarded.
|
|
6
|
-
*/
|
|
7
|
-
export class MemoryFifo {
|
|
8
|
-
constructor(log = createDebugLogger('aztec:foundation:memory_fifo')) {
|
|
9
|
-
this.log = log;
|
|
10
|
-
this.waiting = [];
|
|
11
|
-
this.items = [];
|
|
12
|
-
this.flushing = false;
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Returns the current number of items in the queue.
|
|
16
|
-
* The length represents the size of the queue at the time of invocation and may change as new items are added or consumed.
|
|
17
|
-
*
|
|
18
|
-
* @returns The number of items in the queue.
|
|
19
|
-
*/
|
|
20
|
-
length() {
|
|
21
|
-
return this.items.length;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Returns next item within the queue, or blocks until and item has been put into the queue.
|
|
25
|
-
* If given a timeout, the promise will reject if no item is received after `timeout` seconds.
|
|
26
|
-
* If the queue is flushing, `null` is returned.
|
|
27
|
-
* @param timeout - The timeout in seconds.
|
|
28
|
-
* @returns A result promise.
|
|
29
|
-
*/
|
|
30
|
-
get(timeout) {
|
|
31
|
-
if (this.items.length) {
|
|
32
|
-
return Promise.resolve(this.items.shift());
|
|
33
|
-
}
|
|
34
|
-
if (this.items.length === 0 && this.flushing) {
|
|
35
|
-
return Promise.resolve(null);
|
|
36
|
-
}
|
|
37
|
-
return new Promise((resolve, reject) => {
|
|
38
|
-
this.waiting.push(resolve);
|
|
39
|
-
if (timeout) {
|
|
40
|
-
setTimeout(() => {
|
|
41
|
-
const index = this.waiting.findIndex(r => r === resolve);
|
|
42
|
-
if (index > -1) {
|
|
43
|
-
this.waiting.splice(index, 1);
|
|
44
|
-
const err = new Error('Timeout getting item from queue.');
|
|
45
|
-
reject(err);
|
|
46
|
-
}
|
|
47
|
-
}, timeout * 1000);
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Put an item onto back of the queue.
|
|
53
|
-
* @param item - The item to enqueue.
|
|
54
|
-
*/
|
|
55
|
-
put(item) {
|
|
56
|
-
if (this.flushing) {
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
else if (this.waiting.length) {
|
|
60
|
-
this.waiting.shift()(item);
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
63
|
-
this.items.push(item);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Once ended, no further items are added to queue. Consumers will consume remaining items within the queue.
|
|
68
|
-
* The queue is not reusable after calling `end()`.
|
|
69
|
-
* Any consumers waiting for an item receive null.
|
|
70
|
-
*/
|
|
71
|
-
end() {
|
|
72
|
-
this.flushing = true;
|
|
73
|
-
this.waiting.forEach(resolve => resolve(null));
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Once cancelled, all items are discarded from the queue, and no further items are added to the queue.
|
|
77
|
-
* The queue is not reusable after calling `cancel()`.
|
|
78
|
-
* Any consumers waiting for an item receive null.
|
|
79
|
-
*/
|
|
80
|
-
cancel() {
|
|
81
|
-
this.flushing = true;
|
|
82
|
-
this.items = [];
|
|
83
|
-
this.waiting.forEach(resolve => resolve(null));
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Process items from the queue using a provided handler function.
|
|
87
|
-
* The function iterates over items in the queue, invoking the handler for each item until the queue is empty or flushing.
|
|
88
|
-
* If the handler throws an error, it will be caught and logged as 'Queue handler exception:', but the iteration will continue.
|
|
89
|
-
* The process function returns a promise that resolves when there are no more items in the queue or the queue is flushing.
|
|
90
|
-
*
|
|
91
|
-
* @param handler - A function that takes an item of type T and returns a Promise<void> after processing the item.
|
|
92
|
-
* @returns A Promise<void> that resolves when the queue is finished processing.
|
|
93
|
-
*/
|
|
94
|
-
async process(handler) {
|
|
95
|
-
try {
|
|
96
|
-
while (true) {
|
|
97
|
-
const item = await this.get();
|
|
98
|
-
if (item === null) {
|
|
99
|
-
break;
|
|
100
|
-
}
|
|
101
|
-
await handler(item);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
catch (err) {
|
|
105
|
-
this.log.error('Queue handler exception:', err);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWVtb3J5X2ZpZm8uanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvZmlmby9tZW1vcnl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