@aztec/foundation 0.1.0-alpha10
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/.eslintrc.cjs +103 -0
- package/.prettierrc.json +6 -0
- package/.tsbuildinfo +1 -0
- package/README.md +1 -0
- package/dest/abi/index.d.ts +137 -0
- package/dest/abi/index.d.ts.map +1 -0
- package/dest/abi/index.js +18 -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 +96 -0
- package/dest/aztec-address/index.d.ts.map +1 -0
- package/dest/aztec-address/index.js +124 -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/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 +87 -0
- package/dest/eth-address/index.d.ts +139 -0
- package/dest/eth-address/index.d.ts.map +1 -0
- package/dest/eth-address/index.js +221 -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 +170 -0
- package/dest/fields/fields.d.ts.map +1 -0
- package/dest/fields/fields.js +210 -0
- package/dest/fields/index.d.ts +4 -0
- package/dest/fields/index.d.ts.map +1 -0
- package/dest/fields/index.js +4 -0
- package/dest/fields/point.d.ts +111 -0
- package/dest/fields/point.d.ts.map +1 -0
- package/dest/fields/point.js +133 -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 +109 -0
- package/dest/json-rpc/class_converter.d.ts.map +1 -0
- package/dest/json-rpc/class_converter.js +85 -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 +22 -0
- package/dest/json-rpc/client/json_rpc_client.d.ts.map +1 -0
- package/dest/json-rpc/client/json_rpc_client.js +83 -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 +22 -0
- package/dest/json-rpc/convert.d.ts.map +1 -0
- package/dest/json-rpc/convert.js +93 -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 +14 -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 +4 -0
- package/dest/json-rpc/index.d.ts.map +1 -0
- package/dest/json-rpc/index.js +4 -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 +35 -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 +109 -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 +16 -0
- package/dest/log/console.d.ts.map +1 -0
- package/dest/log/console.js +39 -0
- package/dest/log/debug.d.ts +46 -0
- package/dest/log/debug.d.ts.map +1 -0
- package/dest/log/debug.js +75 -0
- package/dest/log/index.d.ts +4 -0
- package/dest/log/index.d.ts.map +1 -0
- package/dest/log/index.js +4 -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/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 +33 -0
- package/dest/retry/index.d.ts.map +1 -0
- package/dest/retry/index.js +70 -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/wasm/index.d.ts +5 -0
- package/dest/wasm/index.d.ts.map +1 -0
- package/dest/wasm/index.js +5 -0
- package/dest/wasm/wasm/empty_wasi_sdk.d.ts +130 -0
- package/dest/wasm/wasm/empty_wasi_sdk.d.ts.map +1 -0
- package/dest/wasm/wasm/empty_wasi_sdk.js +166 -0
- package/dest/wasm/wasm/index.d.ts +2 -0
- package/dest/wasm/wasm/index.d.ts.map +1 -0
- package/dest/wasm/wasm/index.js +2 -0
- package/dest/wasm/wasm/wasm_module.d.ts +135 -0
- package/dest/wasm/wasm/wasm_module.d.ts.map +1 -0
- package/dest/wasm/wasm/wasm_module.js +205 -0
- package/dest/wasm/wasm/wasm_module.test.d.ts +2 -0
- package/dest/wasm/wasm/wasm_module.test.d.ts.map +1 -0
- package/dest/wasm/wasm/wasm_module.test.js +24 -0
- package/dest/wasm/worker/browser/index.d.ts +3 -0
- package/dest/wasm/worker/browser/index.d.ts.map +1 -0
- package/dest/wasm/worker/browser/index.js +3 -0
- package/dest/wasm/worker/browser/start_web_module.d.ts +7 -0
- package/dest/wasm/worker/browser/start_web_module.d.ts.map +1 -0
- package/dest/wasm/worker/browser/start_web_module.js +22 -0
- package/dest/wasm/worker/browser/web_data_store.d.ts +23 -0
- package/dest/wasm/worker/browser/web_data_store.d.ts.map +1 -0
- package/dest/wasm/worker/browser/web_data_store.js +32 -0
- package/dest/wasm/worker/browser/web_worker.d.ts +10 -0
- package/dest/wasm/worker/browser/web_worker.d.ts.map +1 -0
- package/dest/wasm/worker/browser/web_worker.js +23 -0
- package/dest/wasm/worker/data_store.d.ts +9 -0
- package/dest/wasm/worker/data_store.d.ts.map +1 -0
- package/dest/wasm/worker/data_store.js +2 -0
- package/dest/wasm/worker/index.d.ts +3 -0
- package/dest/wasm/worker/index.d.ts.map +1 -0
- package/dest/wasm/worker/index.js +2 -0
- package/dest/wasm/worker/node/index.d.ts +3 -0
- package/dest/wasm/worker/node/index.d.ts.map +1 -0
- package/dest/wasm/worker/node/index.js +3 -0
- package/dest/wasm/worker/node/node_data_store.d.ts +22 -0
- package/dest/wasm/worker/node/node_data_store.d.ts.map +1 -0
- package/dest/wasm/worker/node/node_data_store.js +31 -0
- package/dest/wasm/worker/node/node_worker.d.ts +6 -0
- package/dest/wasm/worker/node/node_worker.d.ts.map +1 -0
- package/dest/wasm/worker/node/node_worker.js +20 -0
- package/dest/wasm/worker/node/start_node_module.d.ts +7 -0
- package/dest/wasm/worker/node/start_node_module.d.ts.map +1 -0
- package/dest/wasm/worker/node/start_node_module.js +26 -0
- package/dest/wasm/worker/wasm_worker.d.ts +9 -0
- package/dest/wasm/worker/wasm_worker.d.ts.map +1 -0
- package/dest/wasm/worker/wasm_worker.js +2 -0
- package/dest/wasm/worker/worker_pool.d.ts +40 -0
- package/dest/wasm/worker/worker_pool.d.ts.map +1 -0
- package/dest/wasm/worker/worker_pool.js +62 -0
- package/package.json +44 -0
- package/src/abi/index.ts +147 -0
- package/src/async-map/async_map.test.ts +9 -0
- package/src/async-map/index.ts +18 -0
- package/src/aztec-address/index.ts +135 -0
- package/src/bigint-buffer/bigint-buffer.test.ts +21 -0
- package/src/bigint-buffer/index.ts +68 -0
- package/src/collection/array.ts +48 -0
- package/src/collection/index.ts +1 -0
- package/src/crypto/index.ts +3 -0
- package/src/crypto/keccak/index.ts +33 -0
- package/src/crypto/random/index.test.ts +13 -0
- package/src/crypto/random/index.ts +38 -0
- package/src/crypto/sha256/index.test.ts +13 -0
- package/src/crypto/sha256/index.ts +15 -0
- package/src/errors/index.ts +6 -0
- package/src/eth-address/eth_address.test.ts +104 -0
- package/src/eth-address/index.ts +236 -0
- package/src/fields/coordinate.test.ts +26 -0
- package/src/fields/coordinate.ts +104 -0
- package/src/fields/fields.ts +234 -0
- package/src/fields/index.ts +3 -0
- package/src/fields/point.ts +143 -0
- package/src/fifo/bounded_serial_queue.ts +100 -0
- package/src/fifo/index.ts +4 -0
- package/src/fifo/memory_fifo.ts +114 -0
- package/src/fifo/semaphore.ts +33 -0
- package/src/fifo/serial_queue.ts +78 -0
- package/src/json-rpc/README.md +55 -0
- package/src/json-rpc/class_converter.ts +160 -0
- package/src/json-rpc/client/index.ts +1 -0
- package/src/json-rpc/client/json_rpc_client.test.ts +20 -0
- package/src/json-rpc/client/json_rpc_client.ts +103 -0
- package/src/json-rpc/convert.test.ts +15 -0
- package/src/json-rpc/convert.ts +109 -0
- package/src/json-rpc/fixtures/test_state.ts +59 -0
- package/src/json-rpc/index.ts +3 -0
- package/src/json-rpc/js_utils.ts +20 -0
- package/src/json-rpc/server/index.ts +2 -0
- package/src/json-rpc/server/json_proxy.ts +36 -0
- package/src/json-rpc/server/json_rpc_server.test.ts +23 -0
- package/src/json-rpc/server/json_rpc_server.ts +124 -0
- package/src/log/console.ts +45 -0
- package/src/log/debug.ts +86 -0
- package/src/log/index.ts +3 -0
- package/src/log/log_history.test.ts +87 -0
- package/src/log/log_history.ts +44 -0
- package/src/mutex/index.ts +83 -0
- package/src/mutex/mutex.test.ts +75 -0
- package/src/mutex/mutex_database.ts +9 -0
- package/src/retry/index.ts +78 -0
- package/src/running-promise/index.ts +60 -0
- package/src/serialize/buffer_reader.test.ts +175 -0
- package/src/serialize/buffer_reader.ts +272 -0
- package/src/serialize/deserializer.ts +180 -0
- package/src/serialize/free_funcs.ts +285 -0
- package/src/serialize/index.ts +5 -0
- package/src/serialize/serialize.test.ts +89 -0
- package/src/serialize/serializer.ts +128 -0
- package/src/serialize/types.ts +40 -0
- package/src/sleep/index.ts +71 -0
- package/src/timer/index.ts +2 -0
- package/src/timer/timeout.ts +64 -0
- package/src/timer/timer.ts +41 -0
- package/src/transport/browser/index.ts +4 -0
- package/src/transport/browser/message_port_socket.ts +48 -0
- package/src/transport/browser/shared_worker_connector.ts +21 -0
- package/src/transport/browser/shared_worker_listener.ts +52 -0
- package/src/transport/browser/worker_connector.ts +30 -0
- package/src/transport/browser/worker_listener.ts +53 -0
- package/src/transport/dispatch/create_dispatch_fn.ts +33 -0
- package/src/transport/dispatch/create_dispatch_proxy.ts +140 -0
- package/src/transport/dispatch/messages.ts +58 -0
- package/src/transport/index.ts +11 -0
- package/src/transport/interface/connector.ts +8 -0
- package/src/transport/interface/listener.ts +14 -0
- package/src/transport/interface/socket.ts +12 -0
- package/src/transport/interface/transferable.ts +121 -0
- package/src/transport/node/index.ts +2 -0
- package/src/transport/node/node_connector.ts +29 -0
- package/src/transport/node/node_connector_socket.ts +51 -0
- package/src/transport/node/node_listener.ts +33 -0
- package/src/transport/node/node_listener_socket.ts +47 -0
- package/src/transport/transport_client.ts +125 -0
- package/src/transport/transport_server.ts +108 -0
- package/src/types/index.ts +7 -0
- package/src/wasm/README.md +6 -0
- package/src/wasm/fixtures/gcd.wasm +0 -0
- package/src/wasm/fixtures/gcd.wat +27 -0
- package/src/wasm/index.ts +4 -0
- package/src/wasm/wasm/empty_wasi_sdk.ts +166 -0
- package/src/wasm/wasm/index.ts +1 -0
- package/src/wasm/wasm/wasm_module.test.ts +27 -0
- package/src/wasm/wasm/wasm_module.ts +257 -0
- package/src/wasm/worker/browser/index.ts +2 -0
- package/src/wasm/worker/browser/start_web_module.ts +23 -0
- package/src/wasm/worker/browser/web_data_store.ts +37 -0
- package/src/wasm/worker/browser/web_worker.ts +24 -0
- package/src/wasm/worker/data_store.ts +7 -0
- package/src/wasm/worker/index.ts +2 -0
- package/src/wasm/worker/node/index.ts +2 -0
- package/src/wasm/worker/node/node_data_store.ts +36 -0
- package/src/wasm/worker/node/node_worker.ts +21 -0
- package/src/wasm/worker/node/start_node_module.ts +28 -0
- package/src/wasm/worker/wasm_worker.ts +7 -0
- package/src/wasm/worker/worker_pool.ts +73 -0
- package/tsconfig.json +10 -0
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { toBigIntBE } from '../bigint-buffer/index.js';
|
|
2
|
+
import { Fr } from './fields.js';
|
|
3
|
+
/**
|
|
4
|
+
* Class to wrap a single point coordinate.
|
|
5
|
+
* This class handles the complexities of representing point coordinates as 32 byte buffers as well as fields.
|
|
6
|
+
* The coordinate value is split across 2 fields to ensure that the max size of a field is not breached.
|
|
7
|
+
* This is achieved by placing the most significant byte of the lower field into the least significant byte of the higher field.
|
|
8
|
+
* Calls to 'toBuffer' or 'toBigInt' undo this change and simply return the original 32 byte value.
|
|
9
|
+
* Calls to 'toFieldsBuffer' will return a 64 bytes buffer containing the serialised fields.
|
|
10
|
+
*/
|
|
11
|
+
export class Coordinate {
|
|
12
|
+
constructor(
|
|
13
|
+
/**
|
|
14
|
+
* The fields of the coordinate value. Least significant limb at index 0.
|
|
15
|
+
*/
|
|
16
|
+
fields) {
|
|
17
|
+
this.fields = fields;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Converts the coordinate data into a tuple of fields
|
|
21
|
+
* @returns A tuple of the coordinate fields
|
|
22
|
+
*/
|
|
23
|
+
toFields() {
|
|
24
|
+
return this.fields;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Generates a random coordinate value
|
|
28
|
+
* @returns The random coordinate
|
|
29
|
+
*/
|
|
30
|
+
static random() {
|
|
31
|
+
return this.fromField(Fr.random());
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Serialises the oblect to buffer of 2 fields.
|
|
35
|
+
* @returns A buffer serialisation of the object.
|
|
36
|
+
*/
|
|
37
|
+
toFieldsBuffer() {
|
|
38
|
+
return Buffer.concat([this.fields[0].toBuffer(), this.fields[1].toBuffer()]);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Serialises the coordinate to a single 32 byte buffer.
|
|
42
|
+
* @returns A buffer serialisation of the object.
|
|
43
|
+
*/
|
|
44
|
+
toBuffer() {
|
|
45
|
+
const buf0 = this.fields[0].toBuffer();
|
|
46
|
+
const buf1 = this.fields[1].toBuffer();
|
|
47
|
+
buf0[0] = buf1[31];
|
|
48
|
+
return buf0;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Returns true if this coordinate is equal to the one provided
|
|
52
|
+
* @param other - The coordinate against which to compare
|
|
53
|
+
* @returns True if the coordinates are the same, false otherwise
|
|
54
|
+
*/
|
|
55
|
+
equals(other) {
|
|
56
|
+
return this.toBigInt() === other.toBigInt();
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Returns the coordinate's value as a bigint
|
|
60
|
+
* @returns The coordinate value as a bigint
|
|
61
|
+
*/
|
|
62
|
+
toBigInt() {
|
|
63
|
+
return toBigIntBE(this.toBuffer());
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Creates a coordinate object from a 32 byte coordinate value
|
|
67
|
+
* @param coordinate - A buffer containing the 32 byte coordinate value
|
|
68
|
+
* @returns The new coordinate object
|
|
69
|
+
*/
|
|
70
|
+
static fromBuffer(coordinate) {
|
|
71
|
+
if (coordinate.length != 32) {
|
|
72
|
+
throw new Error(`Invalid size of coordinate buffer`);
|
|
73
|
+
}
|
|
74
|
+
const buf0 = Buffer.alloc(32);
|
|
75
|
+
coordinate.copy(buf0, 0, 0, 32);
|
|
76
|
+
const buf1 = Buffer.alloc(32);
|
|
77
|
+
buf1[31] = buf0[0];
|
|
78
|
+
buf0[0] = 0;
|
|
79
|
+
return new Coordinate([Fr.fromBuffer(buf0), Fr.fromBuffer(buf1)]);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Creates a coordinate object from a field
|
|
83
|
+
* @param coordinate - The field containing the coordinate
|
|
84
|
+
* @returns The new coordinate object
|
|
85
|
+
*/
|
|
86
|
+
static fromField(coordinate) {
|
|
87
|
+
const buf0 = coordinate.toBuffer();
|
|
88
|
+
const buf1 = Buffer.alloc(32);
|
|
89
|
+
buf1[31] = buf0[0];
|
|
90
|
+
buf0[0] = 0;
|
|
91
|
+
return new Coordinate([Fr.fromBuffer(buf0), Fr.fromBuffer(buf1)]);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
Coordinate.ZERO = new Coordinate([Fr.ZERO, Fr.ZERO]);
|
|
95
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29vcmRpbmF0ZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9maWVsZHMvY29vcmRpbmF0ZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUUsVUFBVSxFQUFFLE1BQU0sMkJBQTJCLENBQUM7QUFFdkQsT0FBTyxFQUFFLEVBQUUsRUFBRSxNQUFNLGFBQWEsQ0FBQztBQUVqQzs7Ozs7OztHQU9HO0FBQ0gsTUFBTSxPQUFPLFVBQVU7SUFHckI7SUFDRTs7T0FFRztJQUNJLE1BQW9CO1FBQXBCLFdBQU0sR0FBTixNQUFNLENBQWM7SUFDMUIsQ0FBQztJQUVKOzs7T0FHRztJQUNILFFBQVE7UUFDTixPQUFPLElBQUksQ0FBQyxNQUFNLENBQUM7SUFDckIsQ0FBQztJQUVEOzs7T0FHRztJQUNILE1BQU0sQ0FBQyxNQUFNO1FBQ1gsT0FBTyxJQUFJLENBQUMsU0FBUyxDQUFDLEVBQUUsQ0FBQyxNQUFNLEVBQUUsQ0FBQyxDQUFDO0lBQ3JDLENBQUM7SUFFRDs7O09BR0c7SUFDSCxjQUFjO1FBQ1osT0FBTyxNQU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DQUFDLENBQUMsQ0FBQyJ9
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"coordinate.test.d.ts","sourceRoot":"","sources":["../../src/fields/coordinate.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { toBufferBE } from '../bigint-buffer/index.js';
|
|
2
|
+
import { Coordinate } from './coordinate.js';
|
|
3
|
+
import { Fr } from './fields.js';
|
|
4
|
+
const MAX_256_VALUE = 2n ** 256n - 1n;
|
|
5
|
+
describe('coordinate', () => {
|
|
6
|
+
it('stores 256 bits in fields', () => {
|
|
7
|
+
const max256Value = toBufferBE(MAX_256_VALUE, 32);
|
|
8
|
+
const coordinate = Coordinate.fromBuffer(max256Value);
|
|
9
|
+
// this returns a buffer containing the bit pattern split across 2 fields
|
|
10
|
+
expect(coordinate.toFieldsBuffer()).toEqual(Buffer.concat([Buffer.alloc(1, 0), Buffer.alloc(31, 0xff), Buffer.alloc(31, 0), Buffer.alloc(1, 0xff)]));
|
|
11
|
+
// this returns the value in a single 32 byte buffer
|
|
12
|
+
expect(coordinate.toBuffer()).toEqual(max256Value);
|
|
13
|
+
// this returns the value as a big int
|
|
14
|
+
expect(coordinate.toBigInt()).toBe(MAX_256_VALUE);
|
|
15
|
+
});
|
|
16
|
+
it('can be constructed from a field', () => {
|
|
17
|
+
const field = Fr.random();
|
|
18
|
+
const coordinate = Coordinate.fromField(field);
|
|
19
|
+
expect(coordinate.toBuffer()).toEqual(field.toBuffer());
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29vcmRpbmF0ZS50ZXN0LmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL2ZpZWxkcy9jb29yZGluYXRlLnRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLFVBQVUsR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sQ0FBQyxJQUFJLENBQUMsYUFBYSxDQUFDLENBQUM7SUFDcEQsQ0FBQyxDQUFDLENBQUM7SUFFSCxFQUFFLENBQUMsaUNBQWlDLEVBQUUsR0FBRyxFQUFFO1FBQ3pDLE1BQU0sS0FBSyxHQUFHLEVBQUUsQ0FBQyxNQUFNLEVBQUUsQ0FBQztRQUMxQixNQUFNLFVBQVUsR0FBRyxVQUFVLENBQUMsU0FBUyxDQUFDLEtBQUssQ0FBQyxDQUFDO1FBQy9DLE1BQU0sQ0FBQyxVQUFVLENBQUMsUUFBUSxFQUFFLENBQUMsQ0FBQyxPQUFPLENBQUMsS0FBSyxDQUFDLFFBQVEsRUFBRSxDQUFDLENBQUM7SUFDMUQsQ0FBQyxDQUFDLENBQUM7QUFDTCxDQUFDLENBQUMsQ0FBQyJ9
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
import { BufferReader } from '../serialize/buffer_reader.js';
|
|
3
|
+
/**
|
|
4
|
+
* Fr represents a field of integers modulo the prime number MODULUS.
|
|
5
|
+
* It provides utility functions to work with elements in this field, such as conversions between different representations and checks for equality and zero values. The elements can be serialized to and deserialized from byte buffers or strings.
|
|
6
|
+
* Some use cases include working with cryptographic operations and finite fields.
|
|
7
|
+
*/
|
|
8
|
+
export declare class Fr {
|
|
9
|
+
static ZERO: Fr;
|
|
10
|
+
static MODULUS: bigint;
|
|
11
|
+
static MAX_VALUE: bigint;
|
|
12
|
+
static SIZE_IN_BYTES: number;
|
|
13
|
+
/**
|
|
14
|
+
* The numeric value of the field element as a bigint.
|
|
15
|
+
*/
|
|
16
|
+
readonly value: bigint;
|
|
17
|
+
constructor(value: bigint | number);
|
|
18
|
+
/**
|
|
19
|
+
* Generates a random Fr or Fq instance with a value modulo the respective class' MODULUS.
|
|
20
|
+
* This method uses randomBytes to generate a random 32-byte buffer, converts it to a bigint
|
|
21
|
+
* and takes the modulus of the result with the class' MODULUS constant.
|
|
22
|
+
*
|
|
23
|
+
* @returns A new Fr or Fq instance with a random value.
|
|
24
|
+
*/
|
|
25
|
+
static random(): Fr;
|
|
26
|
+
/**
|
|
27
|
+
* Returns a new zero-value field.
|
|
28
|
+
* @returns A new zero-value field.
|
|
29
|
+
*/
|
|
30
|
+
static zero(): Fr;
|
|
31
|
+
/**
|
|
32
|
+
* Create an instance of the corresponding class (Fr or Fq) from a Buffer or a BufferReader.
|
|
33
|
+
* Reads 'SIZE_IN_BYTES' bytes from the given Buffer or BufferReader and constructs an instance with the decoded value.
|
|
34
|
+
* If the input is a Buffer, it is internally converted to a BufferReader before reading.
|
|
35
|
+
* Throws an error if the input length is invalid or the decoded value is out of range.
|
|
36
|
+
*
|
|
37
|
+
* @param buffer - The Buffer or BufferReader containing the bytes representing the value.
|
|
38
|
+
* @returns An instance of the corresponding class (Fr or Fq) with the decoded value.
|
|
39
|
+
*/
|
|
40
|
+
static fromBuffer(buffer: Buffer | BufferReader): Fr;
|
|
41
|
+
/**
|
|
42
|
+
* Create a Fr instance from a hex-encoded string.
|
|
43
|
+
* The input 'address' can be either prefixed with '0x' or not, and should have exactly 64 hex characters.
|
|
44
|
+
* Throws an error if the input length is invalid or the address value is out of range.
|
|
45
|
+
*
|
|
46
|
+
* @param address - The hex-encoded string representing the field element.
|
|
47
|
+
* @returns A Fr instance.
|
|
48
|
+
*/
|
|
49
|
+
static fromString(address: string): Fr;
|
|
50
|
+
/**
|
|
51
|
+
* Converts the value of the instance to a buffer with a specified length.
|
|
52
|
+
* The method uses the provided value and size in bytes to create a buffer representation
|
|
53
|
+
* of the numeric value. This can be useful for serialization and communication purposes.
|
|
54
|
+
*
|
|
55
|
+
* @returns A buffer representing the instance's value.
|
|
56
|
+
*/
|
|
57
|
+
toBuffer(): Buffer;
|
|
58
|
+
/**
|
|
59
|
+
* Converts the value of the Fr or Fq class instance to a hexadecimal string.
|
|
60
|
+
* The resulting string is prefixed with '0x' and represents the bigint value
|
|
61
|
+
* in base 16.
|
|
62
|
+
*
|
|
63
|
+
* @param padTo32 - Whether to pad the string to 32 bytes.
|
|
64
|
+
* @returns A hex-encoded string representing the value of the class instance.
|
|
65
|
+
*/
|
|
66
|
+
toString(padTo32?: boolean): `0x${string}`;
|
|
67
|
+
/**
|
|
68
|
+
* Returns a shortened string representation of the Fr value, formatted with '0x' prefix and ellipsis in the middle.
|
|
69
|
+
* The resulting string has first 10 characters (including '0x') and last 4 characters of the full hexadecimal value.
|
|
70
|
+
*
|
|
71
|
+
* @returns A shorter, human-readable string representation of the Fr value.
|
|
72
|
+
*/
|
|
73
|
+
toShortString(): string;
|
|
74
|
+
/**
|
|
75
|
+
* Checks if the provided Fr instance is equal to the current instance.
|
|
76
|
+
* Two instances are considered equal if their 'value' properties are the same.
|
|
77
|
+
*
|
|
78
|
+
* @param rhs - The Fr instance to compare with the current instance.
|
|
79
|
+
* @returns A boolean indicating whether the two instances are equal.
|
|
80
|
+
*/
|
|
81
|
+
equals(rhs: Fr): boolean;
|
|
82
|
+
/**
|
|
83
|
+
* Check if the instance value is zero.
|
|
84
|
+
* The method returns true if the value of the instance is 0n (zero in BigInt representation),
|
|
85
|
+
* otherwise, it returns false.
|
|
86
|
+
*
|
|
87
|
+
* @returns A boolean indicating whether the instance value is zero or not.
|
|
88
|
+
*/
|
|
89
|
+
isZero(): boolean;
|
|
90
|
+
/**
|
|
91
|
+
* Converts the current value of the Fq or Fr instance to a friendly JSON representation.
|
|
92
|
+
* The output will be a hexadecimal string prefixed with '0x'.
|
|
93
|
+
*
|
|
94
|
+
* @returns A '0x' prefixed hexadecimal string representing the current value.
|
|
95
|
+
*/
|
|
96
|
+
toFriendlyJSON(): `0x${string}`;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Fq represents a field element in a prime finite field with modulus defined by the constant MODULUS.
|
|
100
|
+
* It provides methods for creating, manipulating, and comparing field elements, as well as converting
|
|
101
|
+
* them to/from different data types like Buffers and hex strings. Field elements are used in various
|
|
102
|
+
* cryptographic protocols and operations, such as elliptic curve cryptography.
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* const fqElem = new Fq(BigInt("123456789"));
|
|
106
|
+
* const randomFqElem = Fq.random();
|
|
107
|
+
* const fromBufferFqElem = Fq.fromBuffer(buffer);
|
|
108
|
+
*/
|
|
109
|
+
export declare class Fq {
|
|
110
|
+
/**
|
|
111
|
+
* The element's value as a bigint in the finite field.
|
|
112
|
+
*/
|
|
113
|
+
readonly value: bigint;
|
|
114
|
+
static MODULUS: bigint;
|
|
115
|
+
static MAX_VALUE: bigint;
|
|
116
|
+
static SIZE_IN_BYTES: number;
|
|
117
|
+
constructor(
|
|
118
|
+
/**
|
|
119
|
+
* The element's value as a bigint in the finite field.
|
|
120
|
+
*/
|
|
121
|
+
value: bigint);
|
|
122
|
+
/**
|
|
123
|
+
* Generates a random Fr or Fq instance with a value within the range of their respective modulus.
|
|
124
|
+
* The random value is generated from a byte array of length equal to SIZE_IN_BYTES, then truncated
|
|
125
|
+
* to the appropriate modulus before creating the new Fr or Fq instance.
|
|
126
|
+
*
|
|
127
|
+
* @returns A new Fr or Fq instance with a randomly generated value.
|
|
128
|
+
*/
|
|
129
|
+
static random(): Fq;
|
|
130
|
+
/**
|
|
131
|
+
* Create an instance of the calling class (Fr or Fq) from a given buffer or BufferReader.
|
|
132
|
+
* Reads SIZE_IN_BYTES from the provided buffer and converts it to a bigint, then creates a new instance
|
|
133
|
+
* with that value. Throws an error if the value is out of range for the calling class.
|
|
134
|
+
*
|
|
135
|
+
* @param buffer - The input buffer or BufferReader containing the bytes representing the value.
|
|
136
|
+
* @returns An instance of the calling class (Fr or Fq) initialized with the bigint value.
|
|
137
|
+
*/
|
|
138
|
+
static fromBuffer(buffer: Buffer | BufferReader): Fq;
|
|
139
|
+
/**
|
|
140
|
+
* Converts the bigint value of the instance to a Buffer representation.
|
|
141
|
+
* The output buffer has a fixed size, determined by the 'SIZE_IN_BYTES' constant.
|
|
142
|
+
*
|
|
143
|
+
* @returns A Buffer containing the byte representation of the instance's value.
|
|
144
|
+
*/
|
|
145
|
+
toBuffer(): Buffer;
|
|
146
|
+
/**
|
|
147
|
+
* Converts the Fq value to a hexadecimal string representation.
|
|
148
|
+
* The resulting string is prefixed with '0x' and contains the exact number of hex characters required
|
|
149
|
+
* to represent the numeric value of this instance.
|
|
150
|
+
*
|
|
151
|
+
* @returns A hexadecimal string representing the Fq value.
|
|
152
|
+
*/
|
|
153
|
+
toString(): `0x${string}`;
|
|
154
|
+
/**
|
|
155
|
+
* Check if the value of the current instance is zero.
|
|
156
|
+
* This function compares the internal 'value' property with 0n (BigInt representation of zero).
|
|
157
|
+
* Returns true if the value is zero, otherwise returns false.
|
|
158
|
+
*
|
|
159
|
+
* @returns A boolean indicating whether the value is zero or not.
|
|
160
|
+
*/
|
|
161
|
+
isZero(): boolean;
|
|
162
|
+
/**
|
|
163
|
+
* Converts the value of the Fr or Fq instance to a friendly JSON format.
|
|
164
|
+
* The output is a hexadecimal string representation of the value with '0x' prefix.
|
|
165
|
+
*
|
|
166
|
+
* @returns A string representing the value in the JSON format.
|
|
167
|
+
*/
|
|
168
|
+
toFriendlyJSON(): `0x${string}`;
|
|
169
|
+
}
|
|
170
|
+
//# sourceMappingURL=fields.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fields.d.ts","sourceRoot":"","sources":["../../src/fields/fields.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAG7D;;;;GAIG;AACH,qBAAa,EAAE;IACb,MAAM,CAAC,IAAI,KAAc;IACzB,MAAM,CAAC,OAAO,SAAuE;IACrF,MAAM,CAAC,SAAS,SAAmB;IACnC,MAAM,CAAC,aAAa,SAAM;IAE1B;;OAEG;IACH,SAAgB,KAAK,SAAC;gBAEV,KAAK,EAAE,MAAM,GAAG,MAAM;IAOlC;;;;;;OAMG;IACH,MAAM,CAAC,MAAM;IAKb;;;OAGG;IACH,MAAM,CAAC,IAAI;IAIX;;;;;;;;OAQG;IACH,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY;IAK/C;;;;;;;OAOG;IACH,MAAM,CAAC,UAAU,CAAC,OAAO,EAAE,MAAM;IAIjC;;;;;;OAMG;IACH,QAAQ;IAIR;;;;;;;OAOG;IACH,QAAQ,CAAC,OAAO,UAAQ,GAAG,KAAK,MAAM,EAAE;IAIxC;;;;;OAKG;IACH,aAAa;IAKb;;;;;;OAMG;IACH,MAAM,CAAC,GAAG,EAAE,EAAE;IAId;;;;;;OAMG;IACH,MAAM;IAIN;;;;;OAKG;IACH,cAAc;CAGf;AAED;;;;;;;;;;GAUG;AACH,qBAAa,EAAE;IAMX;;OAEG;aACa,KAAK,EAAE,MAAM;IAR/B,MAAM,CAAC,OAAO,SAAuE;IACrF,MAAM,CAAC,SAAS,SAAmB;IACnC,MAAM,CAAC,aAAa,SAAM;;IAGxB;;OAEG;IACa,KAAK,EAAE,MAAM;IAO/B;;;;;;OAMG;IACH,MAAM,CAAC,MAAM;IAKb;;;;;;;OAOG;IACH,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY;IAK/C;;;;;OAKG;IACH,QAAQ;IAIR;;;;;;OAMG;IACH,QAAQ;IAIR;;;;;;OAMG;IACH,MAAM;IAIN;;;;;OAKG;IACH,cAAc;CAGf"}
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { randomBytes } from 'crypto';
|
|
2
|
+
import { BufferReader } from '../serialize/buffer_reader.js';
|
|
3
|
+
import { toBigIntBE, toBufferBE, toHex } from '../bigint-buffer/index.js';
|
|
4
|
+
/**
|
|
5
|
+
* Fr represents a field of integers modulo the prime number MODULUS.
|
|
6
|
+
* It provides utility functions to work with elements in this field, such as conversions between different representations and checks for equality and zero values. The elements can be serialized to and deserialized from byte buffers or strings.
|
|
7
|
+
* Some use cases include working with cryptographic operations and finite fields.
|
|
8
|
+
*/
|
|
9
|
+
export class Fr {
|
|
10
|
+
constructor(value) {
|
|
11
|
+
this.value = BigInt(value);
|
|
12
|
+
// if (value > Fr.MAX_VALUE) {
|
|
13
|
+
// throw new Error(`Fr out of range ${value}.`);
|
|
14
|
+
// }
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Generates a random Fr or Fq instance with a value modulo the respective class' MODULUS.
|
|
18
|
+
* This method uses randomBytes to generate a random 32-byte buffer, converts it to a bigint
|
|
19
|
+
* and takes the modulus of the result with the class' MODULUS constant.
|
|
20
|
+
*
|
|
21
|
+
* @returns A new Fr or Fq instance with a random value.
|
|
22
|
+
*/
|
|
23
|
+
static random() {
|
|
24
|
+
const r = toBigIntBE(randomBytes(Fr.SIZE_IN_BYTES)) % Fr.MODULUS;
|
|
25
|
+
return new Fr(r);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Returns a new zero-value field.
|
|
29
|
+
* @returns A new zero-value field.
|
|
30
|
+
*/
|
|
31
|
+
static zero() {
|
|
32
|
+
return new Fr(0n);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Create an instance of the corresponding class (Fr or Fq) from a Buffer or a BufferReader.
|
|
36
|
+
* Reads 'SIZE_IN_BYTES' bytes from the given Buffer or BufferReader and constructs an instance with the decoded value.
|
|
37
|
+
* If the input is a Buffer, it is internally converted to a BufferReader before reading.
|
|
38
|
+
* Throws an error if the input length is invalid or the decoded value is out of range.
|
|
39
|
+
*
|
|
40
|
+
* @param buffer - The Buffer or BufferReader containing the bytes representing the value.
|
|
41
|
+
* @returns An instance of the corresponding class (Fr or Fq) with the decoded value.
|
|
42
|
+
*/
|
|
43
|
+
static fromBuffer(buffer) {
|
|
44
|
+
const reader = BufferReader.asReader(buffer);
|
|
45
|
+
return new Fr(toBigIntBE(reader.readBytes(Fr.SIZE_IN_BYTES)));
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Create a Fr instance from a hex-encoded string.
|
|
49
|
+
* The input 'address' can be either prefixed with '0x' or not, and should have exactly 64 hex characters.
|
|
50
|
+
* Throws an error if the input length is invalid or the address value is out of range.
|
|
51
|
+
*
|
|
52
|
+
* @param address - The hex-encoded string representing the field element.
|
|
53
|
+
* @returns A Fr instance.
|
|
54
|
+
*/
|
|
55
|
+
static fromString(address) {
|
|
56
|
+
return Fr.fromBuffer(Buffer.from(address.replace(/^0x/i, ''), 'hex'));
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Converts the value of the instance to a buffer with a specified length.
|
|
60
|
+
* The method uses the provided value and size in bytes to create a buffer representation
|
|
61
|
+
* of the numeric value. This can be useful for serialization and communication purposes.
|
|
62
|
+
*
|
|
63
|
+
* @returns A buffer representing the instance's value.
|
|
64
|
+
*/
|
|
65
|
+
toBuffer() {
|
|
66
|
+
return toBufferBE(this.value, Fr.SIZE_IN_BYTES);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Converts the value of the Fr or Fq class instance to a hexadecimal string.
|
|
70
|
+
* The resulting string is prefixed with '0x' and represents the bigint value
|
|
71
|
+
* in base 16.
|
|
72
|
+
*
|
|
73
|
+
* @param padTo32 - Whether to pad the string to 32 bytes.
|
|
74
|
+
* @returns A hex-encoded string representing the value of the class instance.
|
|
75
|
+
*/
|
|
76
|
+
toString(padTo32 = false) {
|
|
77
|
+
return toHex(this.value, padTo32);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Returns a shortened string representation of the Fr value, formatted with '0x' prefix and ellipsis in the middle.
|
|
81
|
+
* The resulting string has first 10 characters (including '0x') and last 4 characters of the full hexadecimal value.
|
|
82
|
+
*
|
|
83
|
+
* @returns A shorter, human-readable string representation of the Fr value.
|
|
84
|
+
*/
|
|
85
|
+
toShortString() {
|
|
86
|
+
const str = this.toString();
|
|
87
|
+
return `${str.slice(0, 10)}...${str.slice(-4)}`;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Checks if the provided Fr instance is equal to the current instance.
|
|
91
|
+
* Two instances are considered equal if their 'value' properties are the same.
|
|
92
|
+
*
|
|
93
|
+
* @param rhs - The Fr instance to compare with the current instance.
|
|
94
|
+
* @returns A boolean indicating whether the two instances are equal.
|
|
95
|
+
*/
|
|
96
|
+
equals(rhs) {
|
|
97
|
+
return this.value === rhs.value;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Check if the instance value is zero.
|
|
101
|
+
* The method returns true if the value of the instance is 0n (zero in BigInt representation),
|
|
102
|
+
* otherwise, it returns false.
|
|
103
|
+
*
|
|
104
|
+
* @returns A boolean indicating whether the instance value is zero or not.
|
|
105
|
+
*/
|
|
106
|
+
isZero() {
|
|
107
|
+
return this.value === 0n;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Converts the current value of the Fq or Fr instance to a friendly JSON representation.
|
|
111
|
+
* The output will be a hexadecimal string prefixed with '0x'.
|
|
112
|
+
*
|
|
113
|
+
* @returns A '0x' prefixed hexadecimal string representing the current value.
|
|
114
|
+
*/
|
|
115
|
+
toFriendlyJSON() {
|
|
116
|
+
return this.toString();
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
Fr.ZERO = new Fr(0n);
|
|
120
|
+
Fr.MODULUS = 0x30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000001n;
|
|
121
|
+
Fr.MAX_VALUE = Fr.MODULUS - 1n;
|
|
122
|
+
Fr.SIZE_IN_BYTES = 32;
|
|
123
|
+
/**
|
|
124
|
+
* Fq represents a field element in a prime finite field with modulus defined by the constant MODULUS.
|
|
125
|
+
* It provides methods for creating, manipulating, and comparing field elements, as well as converting
|
|
126
|
+
* them to/from different data types like Buffers and hex strings. Field elements are used in various
|
|
127
|
+
* cryptographic protocols and operations, such as elliptic curve cryptography.
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* const fqElem = new Fq(BigInt("123456789"));
|
|
131
|
+
* const randomFqElem = Fq.random();
|
|
132
|
+
* const fromBufferFqElem = Fq.fromBuffer(buffer);
|
|
133
|
+
*/
|
|
134
|
+
export class Fq {
|
|
135
|
+
constructor(
|
|
136
|
+
/**
|
|
137
|
+
* The element's value as a bigint in the finite field.
|
|
138
|
+
*/
|
|
139
|
+
value) {
|
|
140
|
+
this.value = value;
|
|
141
|
+
if (value > Fq.MAX_VALUE) {
|
|
142
|
+
throw new Error(`Fr out of range ${value}.`);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Generates a random Fr or Fq instance with a value within the range of their respective modulus.
|
|
147
|
+
* The random value is generated from a byte array of length equal to SIZE_IN_BYTES, then truncated
|
|
148
|
+
* to the appropriate modulus before creating the new Fr or Fq instance.
|
|
149
|
+
*
|
|
150
|
+
* @returns A new Fr or Fq instance with a randomly generated value.
|
|
151
|
+
*/
|
|
152
|
+
static random() {
|
|
153
|
+
const r = toBigIntBE(randomBytes(64)) % Fq.MODULUS;
|
|
154
|
+
return new this(r);
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Create an instance of the calling class (Fr or Fq) from a given buffer or BufferReader.
|
|
158
|
+
* Reads SIZE_IN_BYTES from the provided buffer and converts it to a bigint, then creates a new instance
|
|
159
|
+
* with that value. Throws an error if the value is out of range for the calling class.
|
|
160
|
+
*
|
|
161
|
+
* @param buffer - The input buffer or BufferReader containing the bytes representing the value.
|
|
162
|
+
* @returns An instance of the calling class (Fr or Fq) initialized with the bigint value.
|
|
163
|
+
*/
|
|
164
|
+
static fromBuffer(buffer) {
|
|
165
|
+
const reader = BufferReader.asReader(buffer);
|
|
166
|
+
return new this(toBigIntBE(reader.readBytes(this.SIZE_IN_BYTES)));
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Converts the bigint value of the instance to a Buffer representation.
|
|
170
|
+
* The output buffer has a fixed size, determined by the 'SIZE_IN_BYTES' constant.
|
|
171
|
+
*
|
|
172
|
+
* @returns A Buffer containing the byte representation of the instance's value.
|
|
173
|
+
*/
|
|
174
|
+
toBuffer() {
|
|
175
|
+
return toBufferBE(this.value, Fq.SIZE_IN_BYTES);
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Converts the Fq value to a hexadecimal string representation.
|
|
179
|
+
* The resulting string is prefixed with '0x' and contains the exact number of hex characters required
|
|
180
|
+
* to represent the numeric value of this instance.
|
|
181
|
+
*
|
|
182
|
+
* @returns A hexadecimal string representing the Fq value.
|
|
183
|
+
*/
|
|
184
|
+
toString() {
|
|
185
|
+
return toHex(this.value);
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Check if the value of the current instance is zero.
|
|
189
|
+
* This function compares the internal 'value' property with 0n (BigInt representation of zero).
|
|
190
|
+
* Returns true if the value is zero, otherwise returns false.
|
|
191
|
+
*
|
|
192
|
+
* @returns A boolean indicating whether the value is zero or not.
|
|
193
|
+
*/
|
|
194
|
+
isZero() {
|
|
195
|
+
return this.value === 0n;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Converts the value of the Fr or Fq instance to a friendly JSON format.
|
|
199
|
+
* The output is a hexadecimal string representation of the value with '0x' prefix.
|
|
200
|
+
*
|
|
201
|
+
* @returns A string representing the value in the JSON format.
|
|
202
|
+
*/
|
|
203
|
+
toFriendlyJSON() {
|
|
204
|
+
return this.toString();
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
Fq.MODULUS = 0x30644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd47n;
|
|
208
|
+
Fq.MAX_VALUE = Fr.MODULUS - 1n;
|
|
209
|
+
Fq.SIZE_IN_BYTES = 32;
|
|
210
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZmllbGRzLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL2ZpZWxkcy9maWVsZHMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLFdBQVcsRUFB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sQ0FBQyxhQUFhLENBQUMsQ0FBQztJQUNsRCxDQUFDO0lBRUQ7Ozs7OztPQU1HO0lBQ0gsUUFBUTtRQUNOLE9BQU8sS0FBSyxDQUFDLElBQUksQ0FBQyxLQUFLLENBQUMsQ0FBQztJQUMzQixDQUFDO0lBRUQ7Ozs7OztPQU1HO0lBQ0gsTUFBTTtRQUNKLE9BQU8sSUFBSSxDQUFDLEtBQUssS0FBSyxFQUFFLENBQUM7SUFDM0IsQ0FBQztJQUVEOzs7OztPQUtHO0lBQ0gsY0FBYztRQUNaLE9BQU8sSUFBSSxDQUFDLFFBQVEsRUFBRSxDQUFDO0lBQ3pCLENBQUM7O0FBaEZNLFVBQU8sR0FBRyxtRUFBbUUsQ0FBQztBQUM5RSxZQUFTLEdBQUcsRUFBRSxDQUFDLE9BQU8sR0FBRyxFQUFFLENBQUM7QUFDNUIsZ0JBQWEsR0FBRyxFQUFFLENBQUMifQ==
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export * from './fields.js';
|
|
2
|
+
export * from './point.js';
|
|
3
|
+
export * from './coordinate.js';
|
|
4
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvZmllbGRzL2luZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLGNBQWMsYUFBYSxDQUFDO0FBQzVCLGNBQWMsWUFBWSxDQUFDO0FBQzNCLGNBQWMsaUJBQWlCLENBQUMifQ==
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
import { BufferReader } from '../serialize/buffer_reader.js';
|
|
3
|
+
import { Coordinate } from './coordinate.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: Coordinate;
|
|
14
|
+
/**
|
|
15
|
+
* The point's y coordinate
|
|
16
|
+
*/
|
|
17
|
+
readonly y: Coordinate;
|
|
18
|
+
static ZERO: Point;
|
|
19
|
+
/** Used to differentiate this class from AztecAddress */
|
|
20
|
+
readonly kind = "point";
|
|
21
|
+
constructor(
|
|
22
|
+
/**
|
|
23
|
+
* The point's x coordinate
|
|
24
|
+
*/
|
|
25
|
+
x: Coordinate,
|
|
26
|
+
/**
|
|
27
|
+
* The point's y coordinate
|
|
28
|
+
*/
|
|
29
|
+
y: Coordinate);
|
|
30
|
+
/**
|
|
31
|
+
* Generate a random Point instance.
|
|
32
|
+
*
|
|
33
|
+
* @returns A randomly generated Point instance.
|
|
34
|
+
*/
|
|
35
|
+
static random(): Point;
|
|
36
|
+
/**
|
|
37
|
+
* Create a Point instance from a given buffer or BufferReader.
|
|
38
|
+
* The input 'buffer' should have exactly 64 bytes representing the x and y coordinates.
|
|
39
|
+
*
|
|
40
|
+
* @param buffer - The buffer or BufferReader containing the x and y coordinates of the point.
|
|
41
|
+
* @returns A Point instance.
|
|
42
|
+
*/
|
|
43
|
+
static fromBuffer(buffer: Buffer | BufferReader): Point;
|
|
44
|
+
/**
|
|
45
|
+
* Creates a point instance from its x and y coordinates.
|
|
46
|
+
* @param x - X coordinate.
|
|
47
|
+
* @param y - Y coordinate.
|
|
48
|
+
* @returns A Point instance.
|
|
49
|
+
*/
|
|
50
|
+
static fromCoordinates(x: Coordinate, y: Coordinate): Point;
|
|
51
|
+
/**
|
|
52
|
+
* Create a Point instance from a hex-encoded string.
|
|
53
|
+
* The input 'address' should be prefixed with '0x' or not, and have exactly 128 hex characters representing the x and y coordinates.
|
|
54
|
+
* Throws an error if the input length is invalid or coordinate values are out of range.
|
|
55
|
+
*
|
|
56
|
+
* @param address - The hex-encoded string representing the Point coordinates.
|
|
57
|
+
* @returns A Point instance.
|
|
58
|
+
*/
|
|
59
|
+
static fromString(address: string): Point;
|
|
60
|
+
/**
|
|
61
|
+
* Convert the Point instance to a Buffer representation of fields
|
|
62
|
+
* The output buffer's length will be (128 bytes).
|
|
63
|
+
* This method is useful for serialization and deserialization of the Point object.
|
|
64
|
+
*
|
|
65
|
+
* @returns A Buffer representation of the Point instance.
|
|
66
|
+
*/
|
|
67
|
+
toFieldsBuffer(): Buffer;
|
|
68
|
+
/**
|
|
69
|
+
* Returns the contents of the point as an array of 4 fields.
|
|
70
|
+
* @returns The point as an array of 4 fields
|
|
71
|
+
*/
|
|
72
|
+
toFields(): import("./fields.js").Fr[];
|
|
73
|
+
/**
|
|
74
|
+
* Converts the Point instance to a Buffer representaion of the coordinates.
|
|
75
|
+
* The outputs buffer length will be 64, the length of both coordinates not represented as fields.
|
|
76
|
+
* @returns A Buffer representation of the Point instance.
|
|
77
|
+
*/
|
|
78
|
+
toBuffer(): Buffer;
|
|
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(): string;
|
|
87
|
+
/**
|
|
88
|
+
* Generate a short string representation of the Point instance.
|
|
89
|
+
* The returned string includes the first 10 and last 4 characters of the full string representation,
|
|
90
|
+
* with '...' in between to indicate truncation. This is useful for displaying or logging purposes
|
|
91
|
+
* when the full string representation may be too long.
|
|
92
|
+
*
|
|
93
|
+
* @returns A truncated string representation of the Point instance.
|
|
94
|
+
*/
|
|
95
|
+
toShortString(): string;
|
|
96
|
+
/**
|
|
97
|
+
* Check if two Point instances are equal by comparing their buffer values.
|
|
98
|
+
* Returns true if the buffer values are the same, and false otherwise.
|
|
99
|
+
*
|
|
100
|
+
* @param rhs - The Point instance to compare with the current instance.
|
|
101
|
+
* @returns A boolean indicating whether the two Point instances are equal.
|
|
102
|
+
*/
|
|
103
|
+
equals(rhs: Point): boolean;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Does this object look like a point?
|
|
107
|
+
* @param obj - Object to test if it is a point.
|
|
108
|
+
* @returns Whether it looks like a point.
|
|
109
|
+
*/
|
|
110
|
+
export declare function isPoint(obj: object): obj is Point;
|
|
111
|
+
//# sourceMappingURL=point.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C;;;;GAIG;AACH,qBAAa,KAAK;IAOd;;OAEG;aACa,CAAC,EAAE,UAAU;IAC7B;;OAEG;aACa,CAAC,EAAE,UAAU;IAb/B,MAAM,CAAC,IAAI,QAA+C;IAE1D,yDAAyD;IACzD,SAAgB,IAAI,WAAW;;IAG7B;;OAEG;IACa,CAAC,EAAE,UAAU;IAC7B;;OAEG;IACa,CAAC,EAAE,UAAU;IAG/B;;;;OAIG;IACH,MAAM,CAAC,MAAM;IAKb;;;;;;OAMG;IACH,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY;IAK/C;;;;;OAKG;IACH,MAAM,CAAC,eAAe,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,UAAU;IAInD;;;;;;;OAOG;IACH,MAAM,CAAC,UAAU,CAAC,OAAO,EAAE,MAAM;IAIjC;;;;;;OAMG;IACH,cAAc;IAId;;;OAGG;IACH,QAAQ;IAIR;;;;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"}
|