@aztec/foundation 0.0.1-commit.03f7ef2 → 0.0.1-commit.04d373f
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/array/index.d.ts +2 -1
- package/dest/array/index.d.ts.map +1 -1
- package/dest/array/index.js +1 -0
- package/dest/array/sorted_array.d.ts +15 -0
- package/dest/array/sorted_array.d.ts.map +1 -0
- package/dest/array/sorted_array.js +109 -0
- package/dest/bigint-buffer/index.d.ts +1 -1
- package/dest/bigint-buffer/index.d.ts.map +1 -1
- package/dest/bigint-buffer/index.js +6 -1
- package/dest/branded-types/block_number.d.ts +6 -3
- package/dest/branded-types/block_number.d.ts.map +1 -1
- package/dest/branded-types/block_number.js +18 -4
- package/dest/branded-types/buffer32_hash.d.ts +27 -0
- package/dest/branded-types/buffer32_hash.d.ts.map +1 -0
- package/dest/branded-types/buffer32_hash.js +12 -0
- package/dest/branded-types/checkpoint_number.d.ts +17 -3
- package/dest/branded-types/checkpoint_number.d.ts.map +1 -1
- package/dest/branded-types/checkpoint_number.js +28 -8
- package/dest/branded-types/epoch.d.ts +2 -2
- package/dest/branded-types/epoch.d.ts.map +1 -1
- package/dest/branded-types/index.d.ts +4 -2
- package/dest/branded-types/index.d.ts.map +1 -1
- package/dest/branded-types/index.js +3 -1
- package/dest/branded-types/index_within_checkpoint.d.ts +42 -0
- package/dest/branded-types/index_within_checkpoint.d.ts.map +1 -0
- package/dest/branded-types/index_within_checkpoint.js +59 -0
- package/dest/branded-types/slot.d.ts +5 -2
- package/dest/branded-types/slot.d.ts.map +1 -1
- package/dest/branded-types/slot.js +3 -0
- package/dest/buffer/buffer16.d.ts +6 -1
- package/dest/buffer/buffer16.d.ts.map +1 -1
- package/dest/buffer/buffer16.js +3 -1
- package/dest/buffer/buffer32.d.ts +28 -58
- package/dest/buffer/buffer32.d.ts.map +1 -1
- package/dest/buffer/buffer32.js +32 -64
- package/dest/buffer/index.d.ts +2 -1
- package/dest/buffer/index.d.ts.map +1 -1
- package/dest/buffer/index.js +1 -0
- package/dest/buffer/utils.d.ts +3 -0
- package/dest/buffer/utils.d.ts.map +1 -0
- package/dest/buffer/utils.js +7 -0
- package/dest/collection/array.d.ts +22 -1
- package/dest/collection/array.d.ts.map +1 -1
- package/dest/collection/array.js +84 -0
- package/dest/collection/index.d.ts +3 -1
- package/dest/collection/index.d.ts.map +1 -1
- package/dest/collection/index.js +2 -0
- package/dest/collection/lru_map.d.ts +41 -0
- package/dest/collection/lru_map.d.ts.map +1 -0
- package/dest/collection/lru_map.js +119 -0
- package/dest/collection/lru_set.d.ts +35 -0
- package/dest/collection/lru_set.d.ts.map +1 -0
- package/dest/collection/lru_set.js +95 -0
- package/dest/committable/committable.js +1 -1
- package/dest/config/env_var.d.ts +2 -2
- package/dest/config/env_var.d.ts.map +1 -1
- package/dest/config/index.d.ts +51 -31
- package/dest/config/index.d.ts.map +1 -1
- package/dest/config/index.js +59 -50
- package/dest/config/network_config.d.ts +15 -41
- package/dest/config/network_config.d.ts.map +1 -1
- package/dest/config/network_config.js +4 -1
- package/dest/config/network_name.d.ts +2 -2
- package/dest/config/network_name.d.ts.map +1 -1
- package/dest/config/network_name.js +2 -2
- package/dest/config/parse-env.d.ts +3 -0
- package/dest/config/parse-env.d.ts.map +1 -0
- package/dest/config/parse-env.js +7 -0
- package/dest/config/secret_value.d.ts +2 -2
- package/dest/config/secret_value.d.ts.map +1 -1
- package/dest/config/secret_value.js +3 -1
- package/dest/crypto/aes128/index.d.ts +2 -1
- package/dest/crypto/aes128/index.d.ts.map +1 -1
- package/dest/crypto/aes128/index.js +11 -2
- package/dest/crypto/bls/bn254_keystore.d.ts +9 -176
- package/dest/crypto/bls/bn254_keystore.d.ts.map +1 -1
- package/dest/crypto/bls/bn254_keystore.js +0 -17
- package/dest/crypto/ecdsa/signature.d.ts +10 -1
- package/dest/crypto/ecdsa/signature.d.ts.map +1 -1
- package/dest/crypto/poseidon/index.d.ts +1 -2
- package/dest/crypto/poseidon/index.d.ts.map +1 -1
- package/dest/crypto/poseidon/index.js +40 -42
- package/dest/crypto/random/randomness_singleton.d.ts +4 -3
- package/dest/crypto/random/randomness_singleton.d.ts.map +1 -1
- package/dest/crypto/random/randomness_singleton.js +5 -5
- package/dest/crypto/schnorr/index.d.ts +8 -7
- package/dest/crypto/schnorr/index.d.ts.map +1 -1
- package/dest/crypto/schnorr/index.js +6 -6
- package/dest/crypto/schnorr/signature.d.ts +9 -29
- package/dest/crypto/schnorr/signature.d.ts.map +1 -1
- package/dest/crypto/schnorr/signature.js +20 -36
- package/dest/crypto/secp256k1-signer/utils.d.ts +12 -1
- package/dest/crypto/secp256k1-signer/utils.d.ts.map +1 -1
- package/dest/crypto/secp256k1-signer/utils.js +26 -0
- package/dest/crypto/sync/poseidon/index.d.ts +1 -2
- package/dest/crypto/sync/poseidon/index.d.ts.map +1 -1
- package/dest/crypto/sync/poseidon/index.js +0 -8
- package/dest/curves/bls12/field.d.ts +3 -3
- package/dest/curves/bls12/field.d.ts.map +1 -1
- package/dest/curves/bls12/field.js +6 -8
- package/dest/curves/bls12/point.d.ts +11 -2
- package/dest/curves/bls12/point.d.ts.map +1 -1
- package/dest/curves/bls12/point.js +3 -1
- package/dest/curves/bn254/field.d.ts +25 -19
- package/dest/curves/bn254/field.d.ts.map +1 -1
- package/dest/curves/bn254/field.js +36 -21
- package/dest/curves/grumpkin/point.d.ts +21 -26
- package/dest/curves/grumpkin/point.d.ts.map +1 -1
- package/dest/curves/grumpkin/point.js +29 -43
- package/dest/error/index.d.ts +4 -4
- package/dest/error/index.d.ts.map +1 -1
- package/dest/eth-address/index.d.ts +2 -2
- package/dest/eth-address/index.d.ts.map +1 -1
- package/dest/eth-address/index.js +4 -5
- package/dest/eth-signature/eth_signature.d.ts +6 -2
- package/dest/eth-signature/eth_signature.d.ts.map +1 -1
- package/dest/eth-signature/eth_signature.js +7 -2
- package/dest/fifo/fifo_frame_reader.d.ts +41 -0
- package/dest/fifo/fifo_frame_reader.d.ts.map +1 -0
- package/dest/fifo/fifo_frame_reader.js +74 -0
- package/dest/fifo/index.d.ts +2 -0
- package/dest/fifo/index.d.ts.map +1 -0
- package/dest/fifo/index.js +1 -0
- package/dest/fifo_set/fifo_set.d.ts +15 -0
- package/dest/fifo_set/fifo_set.d.ts.map +1 -0
- package/dest/fifo_set/fifo_set.js +39 -0
- package/dest/fifo_set/index.d.ts +2 -0
- package/dest/fifo_set/index.d.ts.map +1 -0
- package/dest/fifo_set/index.js +1 -0
- package/dest/jest/setup.js +28 -1
- package/dest/json-rpc/client/fetch.d.ts +1 -1
- package/dest/json-rpc/client/fetch.d.ts.map +1 -1
- package/dest/json-rpc/client/fetch.js +4 -3
- package/dest/json-rpc/client/safe_json_rpc_client.d.ts +2 -1
- package/dest/json-rpc/client/safe_json_rpc_client.d.ts.map +1 -1
- package/dest/json-rpc/client/safe_json_rpc_client.js +3 -3
- package/dest/json-rpc/client/undici.d.ts +1 -1
- package/dest/json-rpc/client/undici.d.ts.map +1 -1
- package/dest/json-rpc/client/undici.js +23 -4
- package/dest/json-rpc/fixtures/class_a.d.ts +3 -3
- package/dest/json-rpc/fixtures/class_a.d.ts.map +1 -1
- package/dest/json-rpc/fixtures/class_b.d.ts +3 -3
- package/dest/json-rpc/fixtures/class_b.d.ts.map +1 -1
- package/dest/json-rpc/fixtures/test_state.d.ts +4 -8
- package/dest/json-rpc/fixtures/test_state.d.ts.map +1 -1
- package/dest/json-rpc/fixtures/test_state.js +57 -17
- package/dest/json-rpc/server/api_key_auth.d.ts +19 -0
- package/dest/json-rpc/server/api_key_auth.d.ts.map +1 -0
- package/dest/json-rpc/server/api_key_auth.js +57 -0
- package/dest/json-rpc/server/index.d.ts +2 -1
- package/dest/json-rpc/server/index.d.ts.map +1 -1
- package/dest/json-rpc/server/index.js +1 -0
- package/dest/json-rpc/server/safe_json_rpc_server.d.ts +8 -3
- package/dest/json-rpc/server/safe_json_rpc_server.d.ts.map +1 -1
- package/dest/json-rpc/server/safe_json_rpc_server.js +28 -14
- package/dest/log/bigint-utils.d.ts +5 -0
- package/dest/log/bigint-utils.d.ts.map +1 -0
- package/dest/log/bigint-utils.js +21 -0
- package/dest/log/gcloud-logger-config.d.ts +1 -1
- package/dest/log/gcloud-logger-config.d.ts.map +1 -1
- package/dest/log/gcloud-logger-config.js +3 -0
- package/dest/log/libp2p_logger.d.ts +5 -2
- package/dest/log/libp2p_logger.d.ts.map +1 -1
- package/dest/log/libp2p_logger.js +14 -4
- package/dest/log/log-filters.d.ts +17 -4
- package/dest/log/log-filters.d.ts.map +1 -1
- package/dest/log/log-filters.js +26 -12
- package/dest/log/pino-logger-server.d.ts +9 -0
- package/dest/log/pino-logger-server.d.ts.map +1 -0
- package/dest/log/pino-logger-server.js +18 -0
- package/dest/log/pino-logger.d.ts +37 -8
- package/dest/log/pino-logger.d.ts.map +1 -1
- package/dest/log/pino-logger.js +138 -30
- package/dest/noir/noir_package_config.d.ts +19 -104
- package/dest/noir/noir_package_config.d.ts.map +1 -1
- package/dest/noir/noir_package_config.js +1 -1
- package/dest/queue/base_memory_queue.d.ts +2 -2
- package/dest/queue/base_memory_queue.d.ts.map +1 -1
- package/dest/queue/batch_queue.d.ts +1 -1
- package/dest/queue/batch_queue.d.ts.map +1 -1
- package/dest/queue/batch_queue.js +1 -0
- package/dest/queue/semaphore.d.ts +5 -1
- package/dest/queue/semaphore.d.ts.map +1 -1
- package/dest/retry/index.d.ts +22 -1
- package/dest/retry/index.d.ts.map +1 -1
- package/dest/retry/index.js +32 -0
- package/dest/schemas/api.d.ts +12 -10
- package/dest/schemas/api.d.ts.map +1 -1
- package/dest/schemas/api.js +7 -1
- package/dest/schemas/parse.d.ts +4 -4
- package/dest/schemas/parse.d.ts.map +1 -1
- package/dest/schemas/parse.js +6 -5
- package/dest/schemas/schemas.d.ts +15 -15
- package/dest/schemas/types.d.ts +3 -3
- package/dest/schemas/types.d.ts.map +1 -1
- package/dest/schemas/utils.d.ts +7 -11
- package/dest/schemas/utils.d.ts.map +1 -1
- package/dest/schemas/utils.js +2 -18
- package/dest/serialize/buffer_reader.d.ts +14 -4
- package/dest/serialize/buffer_reader.d.ts.map +1 -1
- package/dest/serialize/buffer_reader.js +26 -4
- package/dest/serialize/buffer_sink.d.ts +134 -0
- package/dest/serialize/buffer_sink.d.ts.map +1 -0
- package/dest/serialize/buffer_sink.js +297 -0
- package/dest/serialize/index.d.ts +2 -1
- package/dest/serialize/index.d.ts.map +1 -1
- package/dest/serialize/index.js +1 -0
- package/dest/serialize/serialize.d.ts +19 -1
- package/dest/serialize/serialize.d.ts.map +1 -1
- package/dest/serialize/serialize.js +31 -0
- package/dest/sleep/index.d.ts +2 -1
- package/dest/sleep/index.d.ts.map +1 -1
- package/dest/sleep/index.js +10 -1
- package/dest/string/index.js +1 -1
- package/dest/timer/date.d.ts +25 -1
- package/dest/timer/date.d.ts.map +1 -1
- package/dest/timer/date.js +33 -0
- package/dest/timer/index.d.ts +2 -2
- package/dest/timer/index.d.ts.map +1 -1
- package/dest/timer/index.js +1 -1
- package/dest/timer/timeout.d.ts +3 -1
- package/dest/timer/timeout.d.ts.map +1 -1
- package/dest/timer/timeout.js +26 -0
- package/dest/transport/dispatch/create_dispatch_proxy.d.ts +11 -2
- package/dest/transport/dispatch/create_dispatch_proxy.d.ts.map +1 -1
- package/dest/transport/index.d.ts +1 -2
- package/dest/transport/index.d.ts.map +1 -1
- package/dest/transport/index.js +0 -1
- package/dest/transport/transport_client.js +2 -2
- package/dest/trees/balanced_merkle_tree_root.d.ts +16 -0
- package/dest/trees/balanced_merkle_tree_root.d.ts.map +1 -0
- package/dest/trees/{balanced_merkle_tree.js → balanced_merkle_tree_root.js} +3 -19
- package/dest/trees/hasher.d.ts +4 -1
- package/dest/trees/hasher.d.ts.map +1 -1
- package/dest/trees/hasher.js +10 -5
- package/dest/trees/index.d.ts +4 -4
- package/dest/trees/index.d.ts.map +1 -1
- package/dest/trees/index.js +3 -3
- package/dest/trees/indexed_merkle_tree_calculator.d.ts +1 -1
- package/dest/trees/indexed_merkle_tree_calculator.d.ts.map +1 -1
- package/dest/trees/indexed_merkle_tree_calculator.js +5 -1
- package/dest/trees/membership_witness.d.ts +12 -2
- package/dest/trees/membership_witness.d.ts.map +1 -1
- package/dest/trees/membership_witness.js +9 -0
- package/dest/trees/merkle_tree_calculator.d.ts +4 -2
- package/dest/trees/merkle_tree_calculator.d.ts.map +1 -1
- package/dest/trees/merkle_tree_calculator.js +1 -5
- package/dest/trees/sibling_path.d.ts +6 -4
- package/dest/trees/sibling_path.d.ts.map +1 -1
- package/dest/trees/sibling_path.js +10 -8
- package/dest/trees/unbalanced_merkle_tree_calculator.d.ts +2 -3
- package/dest/trees/unbalanced_merkle_tree_calculator.d.ts.map +1 -1
- package/dest/trees/unbalanced_merkle_tree_calculator.js +1 -5
- package/dest/trees/{unbalanced_merkle_tree.d.ts → unbalanced_merkle_tree_root.d.ts} +4 -7
- package/dest/trees/unbalanced_merkle_tree_root.d.ts.map +1 -0
- package/dest/trees/{unbalanced_merkle_tree.js → unbalanced_merkle_tree_root.js} +12 -51
- package/dest/trees/unbalanced_tree_store.d.ts +5 -1
- package/dest/trees/unbalanced_tree_store.d.ts.map +1 -1
- package/dest/trees/unbalanced_tree_store.js +49 -1
- package/dest/types/index.d.ts +12 -2
- package/dest/types/index.d.ts.map +1 -1
- package/dest/types/index.js +3 -0
- package/package.json +29 -6
- package/src/array/index.ts +1 -0
- package/src/array/sorted_array.ts +138 -0
- package/src/bigint-buffer/index.ts +6 -1
- package/src/branded-types/block_number.ts +25 -2
- package/src/branded-types/buffer32_hash.ts +38 -0
- package/src/branded-types/checkpoint_number.ts +37 -7
- package/src/branded-types/epoch.ts +1 -1
- package/src/branded-types/index.ts +3 -1
- package/src/branded-types/index_within_checkpoint.ts +88 -0
- package/src/branded-types/slot.ts +6 -1
- package/src/buffer/buffer16.ts +3 -0
- package/src/buffer/buffer32.ts +39 -68
- package/src/buffer/index.ts +1 -0
- package/src/buffer/utils.ts +8 -0
- package/src/collection/array.ts +86 -0
- package/src/collection/index.ts +2 -0
- package/src/collection/lru_map.ts +143 -0
- package/src/collection/lru_set.ts +115 -0
- package/src/committable/committable.ts +1 -1
- package/src/config/env_var.ts +96 -30
- package/src/config/index.ts +134 -99
- package/src/config/network_config.ts +3 -0
- package/src/config/network_name.ts +4 -4
- package/src/config/parse-env.ts +4 -0
- package/src/config/secret_value.ts +1 -1
- package/src/crypto/aes128/index.ts +11 -2
- package/src/crypto/bls/bn254_keystore.ts +0 -23
- package/src/crypto/poseidon/index.ts +42 -44
- package/src/crypto/random/randomness_singleton.ts +6 -4
- package/src/crypto/schnorr/index.ts +9 -8
- package/src/crypto/schnorr/signature.ts +17 -46
- package/src/crypto/secp256k1-signer/utils.ts +32 -0
- package/src/crypto/sync/poseidon/index.ts +0 -9
- package/src/curves/bls12/field.ts +0 -7
- package/src/curves/bn254/field.ts +45 -36
- package/src/curves/grumpkin/point.ts +23 -40
- package/src/eth-address/index.ts +1 -5
- package/src/eth-signature/eth_signature.ts +7 -1
- package/src/fifo/fifo_frame_reader.ts +98 -0
- package/src/fifo/index.ts +1 -0
- package/src/fifo_set/fifo_set.ts +52 -0
- package/src/fifo_set/index.ts +1 -0
- package/src/jest/setup.mjs +31 -1
- package/src/json-rpc/client/fetch.ts +4 -3
- package/src/json-rpc/client/safe_json_rpc_client.ts +4 -2
- package/src/json-rpc/client/undici.ts +23 -3
- package/src/json-rpc/fixtures/test_state.ts +10 -10
- package/src/json-rpc/server/api_key_auth.ts +63 -0
- package/src/json-rpc/server/index.ts +1 -0
- package/src/json-rpc/server/safe_json_rpc_server.ts +32 -14
- package/src/log/bigint-utils.ts +25 -0
- package/src/log/gcloud-logger-config.ts +5 -0
- package/src/log/libp2p_logger.ts +12 -5
- package/src/log/log-filters.ts +29 -11
- package/src/log/pino-logger-server.ts +25 -0
- package/src/log/pino-logger.ts +162 -40
- package/src/noir/noir_package_config.ts +32 -20
- package/src/queue/base_memory_queue.ts +1 -1
- package/src/queue/batch_queue.ts +1 -0
- package/src/queue/semaphore.ts +5 -0
- package/src/retry/index.ts +48 -0
- package/src/schemas/api.ts +25 -25
- package/src/schemas/parse.ts +9 -6
- package/src/schemas/schemas.ts +4 -4
- package/src/schemas/types.ts +2 -2
- package/src/schemas/utils.ts +4 -38
- package/src/serialize/buffer_reader.ts +36 -9
- package/src/serialize/buffer_sink.ts +350 -0
- package/src/serialize/index.ts +1 -0
- package/src/serialize/serialize.ts +32 -0
- package/src/sleep/index.ts +10 -1
- package/src/string/index.ts +1 -1
- package/src/timer/date.ts +48 -0
- package/src/timer/index.ts +1 -1
- package/src/timer/timeout.ts +31 -0
- package/src/transport/dispatch/create_dispatch_proxy.ts +11 -1
- package/src/transport/index.ts +0 -1
- package/src/transport/transport_client.ts +2 -2
- package/src/trees/{balanced_merkle_tree.ts → balanced_merkle_tree_root.ts} +3 -22
- package/src/trees/hasher.ts +12 -0
- package/src/trees/index.ts +3 -3
- package/src/trees/indexed_merkle_tree_calculator.ts +5 -1
- package/src/trees/membership_witness.ts +8 -0
- package/src/trees/merkle_tree_calculator.ts +4 -10
- package/src/trees/sibling_path.ts +11 -6
- package/src/trees/unbalanced_merkle_tree_calculator.ts +1 -12
- package/src/trees/{unbalanced_merkle_tree.ts → unbalanced_merkle_tree_root.ts} +17 -64
- package/src/trees/unbalanced_tree_store.ts +57 -2
- package/src/types/index.ts +20 -1
- package/dest/crypto/serialize.d.ts +0 -51
- package/dest/crypto/serialize.d.ts.map +0 -1
- package/dest/crypto/serialize.js +0 -68
- package/dest/json-rpc/server/telemetry.d.ts +0 -2
- package/dest/json-rpc/server/telemetry.d.ts.map +0 -1
- package/dest/json-rpc/server/telemetry.js +0 -0
- 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 -17
- package/dest/trees/balanced_merkle_tree.d.ts +0 -22
- package/dest/trees/balanced_merkle_tree.d.ts.map +0 -1
- package/dest/trees/unbalanced_merkle_tree.d.ts.map +0 -1
- package/src/crypto/serialize.ts +0 -85
- package/src/json-rpc/server/telemetry.ts +0 -0
- package/src/transport/dispatch/create_dispatch_fn.ts +0 -35
|
@@ -1,26 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { poseidon2Hash } from '@aztec/foundation/crypto/poseidon';
|
|
3
|
-
import { sha256Trunc } from '@aztec/foundation/crypto/sha256';
|
|
4
|
-
|
|
5
|
-
import type { AsyncHasher, Hasher } from './hasher.js';
|
|
6
|
-
|
|
7
|
-
export const shaMerkleHash: Hasher['hash'] = (left: Buffer, right: Buffer) =>
|
|
8
|
-
sha256Trunc(Buffer.concat([left, right])) as Buffer<ArrayBuffer>;
|
|
9
|
-
|
|
10
|
-
export const pedersenMerkleHash: AsyncHasher['hash'] = async (left: Buffer, right: Buffer) =>
|
|
11
|
-
(await pedersenHashArray([left, right])).toBuffer() as Buffer<ArrayBuffer>;
|
|
12
|
-
|
|
13
|
-
export const poseidonMerkleHash: AsyncHasher['hash'] = async (left: Buffer, right: Buffer) =>
|
|
14
|
-
(await poseidon2Hash([left, right])).toBuffer() as Buffer<ArrayBuffer>;
|
|
1
|
+
import { shaMerkleHash } from './hasher.js';
|
|
15
2
|
|
|
16
3
|
export const computeBalancedShaRoot = (leaves: Buffer[]) => computeBalancedMerkleTreeRoot(leaves);
|
|
17
4
|
|
|
18
|
-
export const computeBalancedPedersenRoot = async (leaves: Buffer[]) =>
|
|
19
|
-
await computeBalancedMerkleTreeRootAsync(leaves, pedersenMerkleHash);
|
|
20
|
-
|
|
21
|
-
export const computeBalancedPoseidonRoot = async (leaves: Buffer[]) =>
|
|
22
|
-
await computeBalancedMerkleTreeRootAsync(leaves, poseidonMerkleHash);
|
|
23
|
-
|
|
24
5
|
/**
|
|
25
6
|
* Computes the Merkle root with the provided leaves **synchronously**.
|
|
26
7
|
* This method uses a synchronous hash function (defaults to `sha256Trunc`).
|
|
@@ -46,13 +27,13 @@ export function computeBalancedMerkleTreeRoot(leaves: Buffer[], hasher = shaMerk
|
|
|
46
27
|
|
|
47
28
|
/**
|
|
48
29
|
* Computes the Merkle root with the provided leaves **asynchronously**.
|
|
49
|
-
* This method uses an asynchronous hash function (defaults to `
|
|
30
|
+
* This method uses an asynchronous hash function (defaults to `poseidon2Hash`).
|
|
50
31
|
*
|
|
51
32
|
* @throws If the number of leaves is not a power of two.
|
|
52
33
|
*/
|
|
53
34
|
export async function computeBalancedMerkleTreeRootAsync(
|
|
54
35
|
leaves: Buffer[],
|
|
55
|
-
hasher
|
|
36
|
+
hasher: (left: Buffer, right: Buffer) => Promise<Buffer<ArrayBuffer>>,
|
|
56
37
|
): Promise<Buffer> {
|
|
57
38
|
const height = getTreeHeight(leaves);
|
|
58
39
|
let nodes = leaves.slice();
|
package/src/trees/hasher.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { poseidon2HashWithSeparator } from '../crypto/poseidon/index.js';
|
|
2
|
+
import { sha256Trunc } from '../crypto/sha256/index.js';
|
|
3
|
+
|
|
1
4
|
/**
|
|
2
5
|
* Defines hasher interface used by Merkle trees.
|
|
3
6
|
*/
|
|
@@ -37,3 +40,12 @@ export interface AsyncHasher {
|
|
|
37
40
|
*/
|
|
38
41
|
hashInputs(inputs: Buffer[]): Promise<Buffer<ArrayBuffer>>;
|
|
39
42
|
}
|
|
43
|
+
|
|
44
|
+
export const shaMerkleHash: Hasher['hash'] = (left: Buffer, right: Buffer) =>
|
|
45
|
+
sha256Trunc(Buffer.concat([left, right])) as Buffer<ArrayBuffer>;
|
|
46
|
+
|
|
47
|
+
/** Creates a poseidon2 merkle hasher with the given domain separator. */
|
|
48
|
+
export const makePoseidonMerkleHash =
|
|
49
|
+
(separator: number): AsyncHasher['hash'] =>
|
|
50
|
+
async (left: Buffer, right: Buffer) =>
|
|
51
|
+
(await poseidon2HashWithSeparator([left, right], separator)).toBuffer() as Buffer<ArrayBuffer>;
|
package/src/trees/index.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
export * from './
|
|
2
|
-
export * from './unbalanced_merkle_tree.js';
|
|
3
|
-
export * from './unbalanced_tree_store.js';
|
|
1
|
+
export * from './balanced_merkle_tree_root.js';
|
|
4
2
|
export * from './merkle_tree_calculator.js';
|
|
5
3
|
export * from './merkle_tree.js';
|
|
6
4
|
export * from './indexed_merkle_tree_calculator.js';
|
|
@@ -10,3 +8,5 @@ export * from './membership_witness.js';
|
|
|
10
8
|
export * from './hasher.js';
|
|
11
9
|
export * from './indexed_tree_leaf.js';
|
|
12
10
|
export * from './unbalanced_merkle_tree_calculator.js';
|
|
11
|
+
export * from './unbalanced_merkle_tree_root.js';
|
|
12
|
+
export * from './unbalanced_tree_store.js';
|
|
@@ -40,7 +40,11 @@ export class IndexedMerkleTreeCalculator<T extends IndexedTreeLeafPreimage, N ex
|
|
|
40
40
|
}
|
|
41
41
|
const sorted = values
|
|
42
42
|
.map((v, i) => ({ value: v, index: i }))
|
|
43
|
-
.sort((a, b)
|
|
43
|
+
.sort((a, b): -1 | 0 | 1 => {
|
|
44
|
+
const aBigInt = toBigIntBE(a.value);
|
|
45
|
+
const bBigInt = toBigIntBE(b.value);
|
|
46
|
+
return aBigInt < bBigInt ? 1 : aBigInt > bBigInt ? -1 : 0;
|
|
47
|
+
});
|
|
44
48
|
const indexedLeaves = sorted.map((item, i) => ({
|
|
45
49
|
leaf: this.factory.fromBuffer(
|
|
46
50
|
Buffer.concat([
|
|
@@ -38,6 +38,14 @@ export class MembershipWitness<N extends number> {
|
|
|
38
38
|
return [new Fr(this.leafIndex), ...this.siblingPath];
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
+
/**
|
|
42
|
+
* Returns a representation of the membership witness as expected by intrinsic Noir deserialization.
|
|
43
|
+
*/
|
|
44
|
+
public toNoirRepresentation(): (string | string[])[] {
|
|
45
|
+
// TODO(#12874): remove the stupid as string conversion by modifying ForeignCallOutput type in acvm.js
|
|
46
|
+
return [new Fr(this.leafIndex).toString() as string, this.siblingPath.map(fr => fr.toString()) as string[]];
|
|
47
|
+
}
|
|
48
|
+
|
|
41
49
|
static schemaFor<N extends number>(size: N) {
|
|
42
50
|
return schemas.Buffer.transform(b => MembershipWitness.fromBuffer(b, size));
|
|
43
51
|
}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { pedersenHash } from '@aztec/foundation/crypto/pedersen';
|
|
2
|
-
|
|
3
|
-
import type { AsyncHasher } from './hasher.js';
|
|
4
1
|
import { MerkleTree } from './merkle_tree.js';
|
|
5
2
|
|
|
3
|
+
type MerkleHashFn = (left: Buffer, right: Buffer) => Promise<Buffer<ArrayBuffer>>;
|
|
4
|
+
|
|
6
5
|
/**
|
|
7
6
|
* Merkle tree calculator.
|
|
8
7
|
*/
|
|
@@ -10,17 +9,12 @@ export class MerkleTreeCalculator {
|
|
|
10
9
|
private constructor(
|
|
11
10
|
private height: number,
|
|
12
11
|
private zeroHashes: Buffer[],
|
|
13
|
-
private hasher:
|
|
12
|
+
private hasher: MerkleHashFn,
|
|
14
13
|
) {
|
|
15
14
|
this.hasher = hasher;
|
|
16
15
|
}
|
|
17
16
|
|
|
18
|
-
static async create(
|
|
19
|
-
height: number,
|
|
20
|
-
zeroLeaf: Buffer = Buffer.alloc(32),
|
|
21
|
-
hasher = async (left: Buffer, right: Buffer) =>
|
|
22
|
-
(await pedersenHash([left, right])).toBuffer() as Buffer<ArrayBuffer>,
|
|
23
|
-
) {
|
|
17
|
+
static async create(height: number, zeroLeaf: Buffer = Buffer.alloc(32), hasher: MerkleHashFn) {
|
|
24
18
|
const zeroHashes = [zeroLeaf];
|
|
25
19
|
for (let i = 0; i < height; i++) {
|
|
26
20
|
zeroHashes.push((await hasher(zeroHashes[i], zeroHashes[i])) as Buffer<ArrayBuffer>);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
1
3
|
import { makeTuple } from '../array/array.js';
|
|
2
|
-
import { pedersenHash } from '../crypto/pedersen/index.js';
|
|
3
4
|
import { Fr } from '../curves/bn254/index.js';
|
|
4
5
|
import { schemas } from '../schemas/index.js';
|
|
5
6
|
import {
|
|
@@ -43,10 +44,14 @@ export class SiblingPath<N extends number> {
|
|
|
43
44
|
}
|
|
44
45
|
|
|
45
46
|
static schemaFor<N extends number>(size: N) {
|
|
46
|
-
return schemas.Buffer.transform(b => SiblingPath.fromBuffer(b) as SiblingPath<N>).
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
return schemas.Buffer.transform(b => SiblingPath.fromBuffer(b) as SiblingPath<N>).superRefine((path, ctx) => {
|
|
48
|
+
if (path.pathSize !== size) {
|
|
49
|
+
ctx.addIssue({
|
|
50
|
+
code: z.ZodIssueCode.custom,
|
|
51
|
+
message: `Expected sibling path size ${size} but got ${path.pathSize}`,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
});
|
|
50
55
|
}
|
|
51
56
|
|
|
52
57
|
toJSON() {
|
|
@@ -172,7 +177,7 @@ export async function computeRootFromSiblingPath(
|
|
|
172
177
|
leaf: Buffer,
|
|
173
178
|
siblingPath: Buffer[],
|
|
174
179
|
index: number,
|
|
175
|
-
hasher
|
|
180
|
+
hasher: (left: Buffer, right: Buffer) => Promise<Buffer>,
|
|
176
181
|
) {
|
|
177
182
|
let result = leaf;
|
|
178
183
|
for (const sibling of siblingPath) {
|
|
@@ -1,18 +1,7 @@
|
|
|
1
|
-
import { shaMerkleHash } from './
|
|
2
|
-
import type { Hasher } from './hasher.js';
|
|
1
|
+
import { type Hasher, shaMerkleHash } from './hasher.js';
|
|
3
2
|
import { SiblingPath } from './sibling_path.js';
|
|
4
3
|
import { type TreeNodeLocation, UnbalancedTreeStore } from './unbalanced_tree_store.js';
|
|
5
4
|
|
|
6
|
-
export function computeCompressedUnbalancedMerkleTreeRoot(
|
|
7
|
-
leaves: Buffer[],
|
|
8
|
-
valueToCompress = Buffer.alloc(32),
|
|
9
|
-
emptyRoot = Buffer.alloc(32),
|
|
10
|
-
hasher?: Hasher['hash'],
|
|
11
|
-
): Buffer {
|
|
12
|
-
const calculator = UnbalancedMerkleTreeCalculator.create(leaves, valueToCompress, emptyRoot, hasher);
|
|
13
|
-
return calculator.getRoot();
|
|
14
|
-
}
|
|
15
|
-
|
|
16
5
|
interface TreeNode {
|
|
17
6
|
value: Buffer;
|
|
18
7
|
leafIndex?: number;
|
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
poseidonMerkleHash,
|
|
5
|
-
shaMerkleHash,
|
|
6
|
-
} from './balanced_merkle_tree.js';
|
|
1
|
+
import { computeBalancedMerkleTreeRoot, computeBalancedMerkleTreeRootAsync } from './balanced_merkle_tree_root.js';
|
|
2
|
+
import { shaMerkleHash } from './hasher.js';
|
|
3
|
+
import { UnbalancedMerkleTreeCalculator } from './unbalanced_merkle_tree_calculator.js';
|
|
7
4
|
|
|
8
5
|
export const computeUnbalancedShaRoot = (leaves: Buffer[]) => computeUnbalancedMerkleTreeRoot(leaves, shaMerkleHash);
|
|
9
6
|
|
|
10
|
-
export const
|
|
11
|
-
await computeUnbalancedMerkleTreeRootAsync(leaves, poseidonMerkleHash);
|
|
7
|
+
export const computeWonkyShaRoot = (leaves: Buffer[]) => computeWonkyMerkleTreeRoot(leaves);
|
|
12
8
|
|
|
13
9
|
/**
|
|
14
10
|
* Computes the Merkle root of an unbalanced tree.
|
|
@@ -68,7 +64,7 @@ export function computeUnbalancedMerkleTreeRoot(
|
|
|
68
64
|
|
|
69
65
|
export async function computeUnbalancedMerkleTreeRootAsync(
|
|
70
66
|
leaves: Buffer[],
|
|
71
|
-
hasher
|
|
67
|
+
hasher: (left: Uint8Array, right: Uint8Array) => Promise<Buffer<ArrayBuffer>>,
|
|
72
68
|
emptyRoot = Buffer.alloc(32),
|
|
73
69
|
): Promise<Buffer> {
|
|
74
70
|
if (!leaves.length) {
|
|
@@ -101,59 +97,16 @@ export async function computeUnbalancedMerkleTreeRootAsync(
|
|
|
101
97
|
return root!;
|
|
102
98
|
}
|
|
103
99
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
return
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
function findPosition(
|
|
119
|
-
rootLevel: number,
|
|
120
|
-
leafLevel: number,
|
|
121
|
-
numLeaves: number,
|
|
122
|
-
indexOffset: number,
|
|
123
|
-
targetIndex: number,
|
|
124
|
-
): { level: number; indexAtLevel: number } {
|
|
125
|
-
if (numLeaves <= 1) {
|
|
126
|
-
// Single leaf.
|
|
127
|
-
return { level: rootLevel, indexAtLevel: indexOffset };
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
// The largest balanced tree that can be created with the given number of leaves.
|
|
131
|
-
const maxBalancedTreeDepth = getMaxBalancedSubtreeDepth(numLeaves);
|
|
132
|
-
const numBalancedLeaves = 2 ** maxBalancedTreeDepth;
|
|
133
|
-
const numRemainingLeaves = numLeaves - numBalancedLeaves;
|
|
134
|
-
|
|
135
|
-
if (targetIndex < numBalancedLeaves) {
|
|
136
|
-
// Target is in the balanced tree.
|
|
137
|
-
|
|
138
|
-
// - If numRemainingLeaves is 0: this balanced tree is grown from the current root.
|
|
139
|
-
// - If numRemainingLeaves is not 0: the remaining leaves will form another tree, which will become the right child of the root.
|
|
140
|
-
// And the balanced tree will be the left child of the root.
|
|
141
|
-
// There will be an extra level between the root of the balanced tree and the current root.
|
|
142
|
-
const extraLevel = numRemainingLeaves ? 1 : 0;
|
|
143
|
-
|
|
144
|
-
return { level: rootLevel + maxBalancedTreeDepth + extraLevel, indexAtLevel: indexOffset + targetIndex };
|
|
145
|
-
} else {
|
|
146
|
-
// Target is in the right branch.
|
|
147
|
-
const rightBranchMaxLevel = getMaxUnbalancedTreeDepth(numRemainingLeaves);
|
|
148
|
-
const shiftedUp = leafLevel - rootLevel - rightBranchMaxLevel - 1;
|
|
149
|
-
const nextLeafLevel = leafLevel - shiftedUp;
|
|
150
|
-
const newIndexOffset = (indexOffset + numBalancedLeaves) >> shiftedUp;
|
|
151
|
-
const shiftedTargetIndex = targetIndex - numBalancedLeaves;
|
|
152
|
-
return findPosition(rootLevel + 1, nextLeafLevel, numRemainingLeaves, newIndexOffset, shiftedTargetIndex);
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
export function findLeafLevelAndIndex(numLeaves: number, leafIndex: number) {
|
|
157
|
-
const maxLevel = getMaxUnbalancedTreeDepth(numLeaves);
|
|
158
|
-
return findPosition(0, maxLevel, numLeaves, 0, leafIndex);
|
|
100
|
+
// A **wonky** tree is a "compressed" unbalanced Merkle tree.
|
|
101
|
+
// It is constructed in the same way as an unbalanced tree: by first creating the largest possible left subtree, with
|
|
102
|
+
// the remaining leaves forming a right subtree that follows the same process recursively.
|
|
103
|
+
// During construction, leaves equal to `valueToCompress` are skipped (compressed) and do not contribute to the tree.
|
|
104
|
+
export function computeWonkyMerkleTreeRoot(
|
|
105
|
+
leaves: Buffer[],
|
|
106
|
+
valueToCompress = Buffer.alloc(32),
|
|
107
|
+
emptyRoot = Buffer.alloc(32),
|
|
108
|
+
hasher = shaMerkleHash,
|
|
109
|
+
): Buffer {
|
|
110
|
+
const calculator = UnbalancedMerkleTreeCalculator.create(leaves, valueToCompress, emptyRoot, hasher);
|
|
111
|
+
return calculator.getRoot();
|
|
159
112
|
}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { findLeafLevelAndIndex } from './unbalanced_merkle_tree.js';
|
|
2
|
-
|
|
3
1
|
export interface TreeNodeLocation {
|
|
4
2
|
level: number;
|
|
5
3
|
index: number;
|
|
@@ -104,3 +102,60 @@ export class UnbalancedTreeStore<T> {
|
|
|
104
102
|
return `${location.level}-${location.index}`;
|
|
105
103
|
}
|
|
106
104
|
}
|
|
105
|
+
|
|
106
|
+
/// Get the depth of the maximum balanced tree that can be created with the given number of leaves. The subtree will be
|
|
107
|
+
/// the left most subtree of the unbalanced tree with a total of `numLeaves` leaves.
|
|
108
|
+
///
|
|
109
|
+
/// Note: All the leaves may not be used to form the tree. For example, if there are 5 leaves, the maximum depth is 2,
|
|
110
|
+
/// only 4 leaves are used to form a balanced tree.
|
|
111
|
+
function getMaxBalancedSubtreeDepth(numLeaves: number) {
|
|
112
|
+
return Math.floor(Math.log2(numLeaves));
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/// Get the maximum depth of an unbalanced tree that can be created with the given number of leaves.
|
|
116
|
+
function getMaxUnbalancedTreeDepth(numLeaves: number) {
|
|
117
|
+
return Math.ceil(Math.log2(numLeaves));
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function findPosition(
|
|
121
|
+
rootLevel: number,
|
|
122
|
+
leafLevel: number,
|
|
123
|
+
numLeaves: number,
|
|
124
|
+
indexOffset: number,
|
|
125
|
+
targetIndex: number,
|
|
126
|
+
): { level: number; indexAtLevel: number } {
|
|
127
|
+
if (numLeaves <= 1) {
|
|
128
|
+
// Single leaf.
|
|
129
|
+
return { level: rootLevel, indexAtLevel: indexOffset };
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// The largest balanced tree that can be created with the given number of leaves.
|
|
133
|
+
const maxBalancedTreeDepth = getMaxBalancedSubtreeDepth(numLeaves);
|
|
134
|
+
const numBalancedLeaves = 2 ** maxBalancedTreeDepth;
|
|
135
|
+
const numRemainingLeaves = numLeaves - numBalancedLeaves;
|
|
136
|
+
|
|
137
|
+
if (targetIndex < numBalancedLeaves) {
|
|
138
|
+
// Target is in the balanced tree.
|
|
139
|
+
|
|
140
|
+
// - If numRemainingLeaves is 0: this balanced tree is grown from the current root.
|
|
141
|
+
// - If numRemainingLeaves is not 0: the remaining leaves will form another tree, which will become the right child of the root.
|
|
142
|
+
// And the balanced tree will be the left child of the root.
|
|
143
|
+
// There will be an extra level between the root of the balanced tree and the current root.
|
|
144
|
+
const extraLevel = numRemainingLeaves ? 1 : 0;
|
|
145
|
+
|
|
146
|
+
return { level: rootLevel + maxBalancedTreeDepth + extraLevel, indexAtLevel: indexOffset + targetIndex };
|
|
147
|
+
} else {
|
|
148
|
+
// Target is in the right branch.
|
|
149
|
+
const rightBranchMaxLevel = getMaxUnbalancedTreeDepth(numRemainingLeaves);
|
|
150
|
+
const shiftedUp = leafLevel - rootLevel - rightBranchMaxLevel - 1;
|
|
151
|
+
const nextLeafLevel = leafLevel - shiftedUp;
|
|
152
|
+
const newIndexOffset = (indexOffset + numBalancedLeaves) >> shiftedUp;
|
|
153
|
+
const shiftedTargetIndex = targetIndex - numBalancedLeaves;
|
|
154
|
+
return findPosition(rootLevel + 1, nextLeafLevel, numRemainingLeaves, newIndexOffset, shiftedTargetIndex);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export function findLeafLevelAndIndex(numLeaves: number, leafIndex: number) {
|
|
159
|
+
const maxLevel = getMaxUnbalancedTreeDepth(numLeaves);
|
|
160
|
+
return findPosition(0, maxLevel, numLeaves, 0, leafIndex);
|
|
161
|
+
}
|
package/src/types/index.ts
CHANGED
|
@@ -24,16 +24,35 @@ export function isDefined<T>(value: T | undefined): value is T {
|
|
|
24
24
|
return value !== undefined;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
+
/** Type guard for error classes */
|
|
28
|
+
export function isErrorClass<T extends Error>(value: unknown, errorClass: new (...args: any[]) => T): value is T {
|
|
29
|
+
return value instanceof errorClass || (value instanceof Error && value.name === errorClass.name);
|
|
30
|
+
}
|
|
31
|
+
|
|
27
32
|
/** Resolves a record-like type. Lifted from viem. */
|
|
28
33
|
export type Prettify<T> = {
|
|
29
34
|
[K in keyof T]: T[K];
|
|
30
35
|
} & {};
|
|
31
36
|
|
|
37
|
+
/** Returns a type with fields conditionally required based on a flag */
|
|
38
|
+
export type IfFlag<
|
|
39
|
+
OptsSchema,
|
|
40
|
+
Opts extends OptsSchema,
|
|
41
|
+
Key extends keyof OptsSchema,
|
|
42
|
+
Field extends object,
|
|
43
|
+
> = Opts extends { [K in Key]: true }
|
|
44
|
+
? Field
|
|
45
|
+
: Opts extends { [K in Key]: false }
|
|
46
|
+
? {}
|
|
47
|
+
: Opts extends { [K in Key]?: boolean }
|
|
48
|
+
? Partial<Field>
|
|
49
|
+
: {};
|
|
50
|
+
|
|
32
51
|
/**
|
|
33
52
|
* Type-safe Event Emitter type
|
|
34
53
|
* @example
|
|
35
54
|
* export type ArchiverEmitter = TypedEventEmitter<{
|
|
36
|
-
* [L2BlockSourceEvents.
|
|
55
|
+
* [L2BlockSourceEvents.L2PruneUnproven]: (args: L2BlockSourceEvent) => void;
|
|
37
56
|
* [L2BlockSourceEvents.L2BlockProven]: (args: L2BlockSourceEvent) => void;
|
|
38
57
|
* }>;
|
|
39
58
|
* class Archiver extends (EventEmitter as new () => ArchiverEmitter) {
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { Buffer } from 'buffer';
|
|
2
|
-
/**
|
|
3
|
-
* For serializing an array of fixed length buffers.
|
|
4
|
-
* TODO move to foundation pkg.
|
|
5
|
-
* @param arr - Array of bufffers.
|
|
6
|
-
* @returns The serialized buffers.
|
|
7
|
-
*/
|
|
8
|
-
export declare function serializeBufferArrayToVector(arr: Buffer[]): Buffer<ArrayBuffer>;
|
|
9
|
-
/**
|
|
10
|
-
* Helper function for deserializeArrayFromVector.
|
|
11
|
-
*/
|
|
12
|
-
type DeserializeFn<T> = (buf: Buffer, offset: number) => {
|
|
13
|
-
/**
|
|
14
|
-
* The deserialized type.
|
|
15
|
-
*/
|
|
16
|
-
elem: T;
|
|
17
|
-
/**
|
|
18
|
-
* How many bytes to advance by.
|
|
19
|
-
*/
|
|
20
|
-
adv: number;
|
|
21
|
-
};
|
|
22
|
-
/**
|
|
23
|
-
* For deserializing numbers to 32-bit little-endian form.
|
|
24
|
-
* TODO move to foundation pkg.
|
|
25
|
-
* @param n - The number.
|
|
26
|
-
* @returns The endian-corrected number.
|
|
27
|
-
*/
|
|
28
|
-
export declare function deserializeArrayFromVector<T>(deserialize: DeserializeFn<T>, vector: Buffer, offset?: number): {
|
|
29
|
-
elem: T[];
|
|
30
|
-
adv: number;
|
|
31
|
-
};
|
|
32
|
-
/**
|
|
33
|
-
* For serializing numbers to 32 bit little-endian form.
|
|
34
|
-
* TODO move to foundation pkg.
|
|
35
|
-
* @param n - The number.
|
|
36
|
-
* @returns The endian-corrected number.
|
|
37
|
-
*/
|
|
38
|
-
export declare function numToUInt32LE(n: number, bufferSize?: number): Buffer<ArrayBuffer>;
|
|
39
|
-
/**
|
|
40
|
-
* Deserialize the 256-bit number at address `offset`.
|
|
41
|
-
* @param buf - The buffer.
|
|
42
|
-
* @param offset - The address.
|
|
43
|
-
* @returns The derserialized 256-bit field.
|
|
44
|
-
*/
|
|
45
|
-
export declare function deserializeField(buf: Buffer, offset?: number): {
|
|
46
|
-
elem: Buffer<ArrayBuffer>;
|
|
47
|
-
adv: number;
|
|
48
|
-
};
|
|
49
|
-
export declare function concatenateUint8Arrays(arrayOfUint8Arrays: Uint8Array[]): Uint8Array<ArrayBuffer>;
|
|
50
|
-
export {};
|
|
51
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2VyaWFsaXplLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvY3J5cHRvL3NlcmlhbGl6ZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFFQSxPQUFPLEVBQUUsTUFBTSxFQUFFLE1BQU0sUUFBUSxDQUFDO0FBRWhDOzs7OztHQUtHO0FBQ0gsd0JBQWdCLDRCQUE0QixDQUFDLEdBQUcsRUFBRSxNQUFNLEVBQUUsdUJBSXpEO0FBRUQ7O0dBRUc7QUFDSCxLQUFLLGFBQWEsQ0FBQyxDQUFDLElBQUksQ0FDdEIsR0FBRyxFQUFFLE1BQU0sRUFDWCxNQUFNLEVBQUUsTUFBTSxLQUNYO0lBQ0g7O09BRUc7SUFDSCxJQUFJLEVBQUUsQ0FBQyxDQUFDO0lBQ1I7O09BRUc7SUFDSCxHQUFHLEVBQUUsTUFBTSxDQUFDO0NBQ2IsQ0FBQztBQUVGOzs7OztHQUtHO0FBQ0gsd0JBQWdCLDBCQUEwQixDQUFDLENBQUMsRUFBRSxXQUFXLEVBQUUsYUFBYSxDQUFDLENBQUMsQ0FBQyxFQUFFLE1BQU0sRUFBRSxNQUFNLEVBQUUsTUFBTSxTQUFJOzs7RUFXdEc7QUFFRDs7Ozs7R0FLRztBQUNILHdCQUFnQixhQUFhLENBQUMsQ0FBQyxFQUFFLE1BQU0sRUFBRSxVQUFVLFNBQUksdUJBSXREO0FBRUQ7Ozs7O0dBS0c7QUFDSCx3QkFBZ0IsZ0JBQWdCLENBQUMsR0FBRyxFQUFFLE1BQU0sRUFBRSxNQUFNLFNBQUk7OztFQUd2RDtBQUVELHdCQUFnQixzQkFBc0IsQ0FBQyxrQkFBa0IsRUFBRSxVQUFVLEVBQUUsMkJBU3RFIn0=
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"serialize.d.ts","sourceRoot":"","sources":["../../src/crypto/serialize.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC;;;;;GAKG;AACH,wBAAgB,4BAA4B,CAAC,GAAG,EAAE,MAAM,EAAE,uBAIzD;AAED;;GAEG;AACH,KAAK,aAAa,CAAC,CAAC,IAAI,CACtB,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,MAAM,KACX;IACH;;OAEG;IACH,IAAI,EAAE,CAAC,CAAC;IACR;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;CACb,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,0BAA0B,CAAC,CAAC,EAAE,WAAW,EAAE,aAAa,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,SAAI;;;EAWtG;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,MAAM,EAAE,UAAU,SAAI,uBAItD;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,SAAI;;;EAGvD;AAED,wBAAgB,sBAAsB,CAAC,kBAAkB,EAAE,UAAU,EAAE,2BAStE"}
|
package/dest/crypto/serialize.js
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
// TODO find a new home for this as we move to external bb.js
|
|
2
|
-
// See https://github.com/AztecProtocol/aztec-packages/issues/782
|
|
3
|
-
import { Buffer } from 'buffer';
|
|
4
|
-
/**
|
|
5
|
-
* For serializing an array of fixed length buffers.
|
|
6
|
-
* TODO move to foundation pkg.
|
|
7
|
-
* @param arr - Array of bufffers.
|
|
8
|
-
* @returns The serialized buffers.
|
|
9
|
-
*/ export function serializeBufferArrayToVector(arr) {
|
|
10
|
-
const lengthBuf = Buffer.alloc(4);
|
|
11
|
-
lengthBuf.writeUInt32BE(arr.length, 0);
|
|
12
|
-
return Buffer.concat([
|
|
13
|
-
lengthBuf,
|
|
14
|
-
...arr
|
|
15
|
-
]);
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* For deserializing numbers to 32-bit little-endian form.
|
|
19
|
-
* TODO move to foundation pkg.
|
|
20
|
-
* @param n - The number.
|
|
21
|
-
* @returns The endian-corrected number.
|
|
22
|
-
*/ export function deserializeArrayFromVector(deserialize, vector, offset = 0) {
|
|
23
|
-
let pos = offset;
|
|
24
|
-
const size = vector.readUInt32BE(pos);
|
|
25
|
-
pos += 4;
|
|
26
|
-
const arr = new Array(size);
|
|
27
|
-
for(let i = 0; i < size; ++i){
|
|
28
|
-
const { elem, adv } = deserialize(vector, pos);
|
|
29
|
-
pos += adv;
|
|
30
|
-
arr[i] = elem;
|
|
31
|
-
}
|
|
32
|
-
return {
|
|
33
|
-
elem: arr,
|
|
34
|
-
adv: pos - offset
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* For serializing numbers to 32 bit little-endian form.
|
|
39
|
-
* TODO move to foundation pkg.
|
|
40
|
-
* @param n - The number.
|
|
41
|
-
* @returns The endian-corrected number.
|
|
42
|
-
*/ export function numToUInt32LE(n, bufferSize = 4) {
|
|
43
|
-
const buf = Buffer.alloc(bufferSize);
|
|
44
|
-
buf.writeUInt32LE(n, bufferSize - 4);
|
|
45
|
-
return buf;
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Deserialize the 256-bit number at address `offset`.
|
|
49
|
-
* @param buf - The buffer.
|
|
50
|
-
* @param offset - The address.
|
|
51
|
-
* @returns The derserialized 256-bit field.
|
|
52
|
-
*/ export function deserializeField(buf, offset = 0) {
|
|
53
|
-
const adv = 32;
|
|
54
|
-
return {
|
|
55
|
-
elem: buf.slice(offset, offset + adv),
|
|
56
|
-
adv
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
export function concatenateUint8Arrays(arrayOfUint8Arrays) {
|
|
60
|
-
const totalLength = arrayOfUint8Arrays.reduce((prev, curr)=>prev + curr.length, 0);
|
|
61
|
-
const result = new Uint8Array(totalLength);
|
|
62
|
-
let length = 0;
|
|
63
|
-
for (const array of arrayOfUint8Arrays){
|
|
64
|
-
result.set(array, length);
|
|
65
|
-
length += array.length;
|
|
66
|
-
}
|
|
67
|
-
return result;
|
|
68
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"telemetry.d.ts","sourceRoot":"","sources":["../../../src/json-rpc/server/telemetry.ts"],"names":[],"mappings":""}
|
|
File without changes
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Represents a message object for dispatching function calls.
|
|
3
|
-
* Contains the function name ('fn') and an array of arguments ('args') required to call the target method.
|
|
4
|
-
*/
|
|
5
|
-
export interface DispatchMsg {
|
|
6
|
-
/**
|
|
7
|
-
* Name of the target method to be called.
|
|
8
|
-
*/
|
|
9
|
-
fn: string;
|
|
10
|
-
/**
|
|
11
|
-
* An array of arguments to be passed to the target method.
|
|
12
|
-
*/
|
|
13
|
-
args: any[];
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Creates a dispatch function that calls the target's specified method with provided arguments.
|
|
17
|
-
* The created dispatch function takes a DispatchMsg object as input, which contains the name of
|
|
18
|
-
* the method to be called ('fn') and an array of arguments to be passed to the method ('args').
|
|
19
|
-
*
|
|
20
|
-
* @param targetFn - A function that returns the target object containing the methods to be dispatched.
|
|
21
|
-
* @param log - Optional logging function for debugging purposes.
|
|
22
|
-
* @returns A dispatch function that accepts a DispatchMsg object and calls the target's method with provided arguments.
|
|
23
|
-
*/
|
|
24
|
-
export declare function createDispatchFn(targetFn: () => any, log?: import("../../log/pino-logger.js").Logger): ({ fn, args }: DispatchMsg) => Promise<any>;
|
|
25
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY3JlYXRlX2Rpc3BhdGNoX2ZuLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvdHJhbnNwb3J0L2Rpc3BhdGNoL2NyZWF0ZV9kaXNwYXRjaF9mbi50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFJQTs7O0dBR0c7QUFDSCxNQUFNLFdBQVcsV0FBVztJQUMxQjs7T0FFRztJQUNILEVBQUUsRUFBRSxNQUFNLENBQUM7SUFDWDs7T0FFRztJQUNILElBQUksRUFBRSxHQUFHLEVBQUUsQ0FBQztDQUNiO0FBRUQ7Ozs7Ozs7O0dBUUc7QUFDSCx3QkFBZ0IsZ0JBQWdCLENBQUMsUUFBUSxFQUFFLE1BQU0sR0FBRyxFQUFFLEdBQUcsNENBQXNDLCtDQU05RiJ9
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"create_dispatch_fn.d.ts","sourceRoot":"","sources":["../../../src/transport/dispatch/create_dispatch_fn.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC1B;;OAEG;IACH,EAAE,EAAE,MAAM,CAAC;IACX;;OAEG;IACH,IAAI,EAAE,GAAG,EAAE,CAAC;CACb;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,EAAE,GAAG,4CAAsC,+CAM9F"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { format } from 'util';
|
|
2
|
-
import { createLogger } from '../../log/index.js';
|
|
3
|
-
/**
|
|
4
|
-
* Creates a dispatch function that calls the target's specified method with provided arguments.
|
|
5
|
-
* The created dispatch function takes a DispatchMsg object as input, which contains the name of
|
|
6
|
-
* the method to be called ('fn') and an array of arguments to be passed to the method ('args').
|
|
7
|
-
*
|
|
8
|
-
* @param targetFn - A function that returns the target object containing the methods to be dispatched.
|
|
9
|
-
* @param log - Optional logging function for debugging purposes.
|
|
10
|
-
* @returns A dispatch function that accepts a DispatchMsg object and calls the target's method with provided arguments.
|
|
11
|
-
*/ export function createDispatchFn(targetFn, log = createLogger('foundation:dispatch')) {
|
|
12
|
-
return async ({ fn, args })=>{
|
|
13
|
-
const target = targetFn();
|
|
14
|
-
log.debug(format(`dispatching to ${target}: ${fn}`, args));
|
|
15
|
-
return await target[fn](...args);
|
|
16
|
-
};
|
|
17
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type { AsyncHasher, Hasher } from './hasher.js';
|
|
2
|
-
export declare const shaMerkleHash: Hasher['hash'];
|
|
3
|
-
export declare const pedersenMerkleHash: AsyncHasher['hash'];
|
|
4
|
-
export declare const poseidonMerkleHash: AsyncHasher['hash'];
|
|
5
|
-
export declare const computeBalancedShaRoot: (leaves: Buffer<ArrayBufferLike>[]) => Buffer<ArrayBufferLike>;
|
|
6
|
-
export declare const computeBalancedPedersenRoot: (leaves: Buffer<ArrayBufferLike>[]) => Promise<Buffer<ArrayBufferLike>>;
|
|
7
|
-
export declare const computeBalancedPoseidonRoot: (leaves: Buffer<ArrayBufferLike>[]) => Promise<Buffer<ArrayBufferLike>>;
|
|
8
|
-
/**
|
|
9
|
-
* Computes the Merkle root with the provided leaves **synchronously**.
|
|
10
|
-
* This method uses a synchronous hash function (defaults to `sha256Trunc`).
|
|
11
|
-
*
|
|
12
|
-
* @throws If the number of leaves is not a power of two.
|
|
13
|
-
*/
|
|
14
|
-
export declare function computeBalancedMerkleTreeRoot(leaves: Buffer[], hasher?: (lhs: Uint8Array<ArrayBufferLike>, rhs: Uint8Array<ArrayBufferLike>) => Buffer<ArrayBuffer>): Buffer;
|
|
15
|
-
/**
|
|
16
|
-
* Computes the Merkle root with the provided leaves **asynchronously**.
|
|
17
|
-
* This method uses an asynchronous hash function (defaults to `pedersenHash`).
|
|
18
|
-
*
|
|
19
|
-
* @throws If the number of leaves is not a power of two.
|
|
20
|
-
*/
|
|
21
|
-
export declare function computeBalancedMerkleTreeRootAsync(leaves: Buffer[], hasher?: (lhs: Uint8Array<ArrayBufferLike>, rhs: Uint8Array<ArrayBufferLike>) => Promise<Buffer<ArrayBuffer>>): Promise<Buffer>;
|
|
22
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYmFsYW5jZWRfbWVya2xlX3RyZWUuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy90cmVlcy9iYWxhbmNlZF9tZXJrbGVfdHJlZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFJQSxPQUFPLEtBQUssRUFBRSxXQUFXLEVBQUUsTUFBTSxFQUFFLE1BQU0sYUFBYSxDQUFDO0FBRXZELGVBQU8sTUFBTSxhQUFhLEVBQUUsTUFBTSxDQUFDLE1BQU0sQ0FDeUIsQ0FBQztBQUVuRSxlQUFPLE1BQU0sa0JBQWtCLEVBQUUsV0FBVyxDQUFDLE1BQU0sQ0FDeUIsQ0FBQztBQUU3RSxlQUFPLE1BQU0sa0JBQWtCLEVBQUUsV0FBVyxDQUFDLE1BQU0sQ0FDcUIsQ0FBQztBQUV6RSxlQUFPLE1BQU0sc0JBQXNCLGdFQUE4RCxDQUFDO0FBRWxHLGVBQU8sTUFBTSwyQkFBMkIseUVBQzhCLENBQUM7QUFFdkUsZUFBTyxNQUFNLDJCQUEyQix5RUFDOEIsQ0FBQztBQUV2RTs7Ozs7R0FLRztBQUNILHdCQUFnQiw2QkFBNkIsQ0FBQyxNQUFNLEVBQUUsTUFBTSxFQUFFLEVBQUUsTUFBTSw4RkFBZ0IsR0FBRyxNQUFNLENBZTlGO0FBRUQ7Ozs7O0dBS0c7QUFDSCx3QkFBc0Isa0NBQWtDLENBQ3RELE1BQU0sRUFBRSxNQUFNLEVBQUUsRUFDaEIsTUFBTSx1R0FBcUIsR0FDMUIsT0FBTyxDQUFDLE1BQU0sQ0FBQyxDQWVqQiJ9
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"balanced_merkle_tree.d.ts","sourceRoot":"","sources":["../../src/trees/balanced_merkle_tree.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAEvD,eAAO,MAAM,aAAa,EAAE,MAAM,CAAC,MAAM,CACyB,CAAC;AAEnE,eAAO,MAAM,kBAAkB,EAAE,WAAW,CAAC,MAAM,CACyB,CAAC;AAE7E,eAAO,MAAM,kBAAkB,EAAE,WAAW,CAAC,MAAM,CACqB,CAAC;AAEzE,eAAO,MAAM,sBAAsB,gEAA8D,CAAC;AAElG,eAAO,MAAM,2BAA2B,yEAC8B,CAAC;AAEvE,eAAO,MAAM,2BAA2B,yEAC8B,CAAC;AAEvE;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,MAAM,8FAAgB,GAAG,MAAM,CAe9F;AAED;;;;;GAKG;AACH,wBAAsB,kCAAkC,CACtD,MAAM,EAAE,MAAM,EAAE,EAChB,MAAM,uGAAqB,GAC1B,OAAO,CAAC,MAAM,CAAC,CAejB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"unbalanced_merkle_tree.d.ts","sourceRoot":"","sources":["../../src/trees/unbalanced_merkle_tree.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,wBAAwB,gEAA+E,CAAC;AAErH,eAAO,MAAM,6BAA6B,yEAC8B,CAAC;AAEzE;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,+BAA+B,CAC7C,MAAM,EAAE,MAAM,EAAE,EAChB,MAAM,8FAAgB,EACtB,SAAS,sBAAmB,GAC3B,MAAM,CA6BR;AAED,wBAAsB,oCAAoC,CACxD,MAAM,EAAE,MAAM,EAAE,EAChB,MAAM,uGAAqB,EAC3B,SAAS,sBAAmB,GAC3B,OAAO,CAAC,MAAM,CAAC,CA6BjB;AAsDD,wBAAgB,qBAAqB,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM;;;EAGzE"}
|