@aztec/foundation 0.0.1-commit.9b94fc1 → 0.0.1-commit.9d2bcf6d
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 +10 -0
- package/dest/array/sorted_array.d.ts.map +1 -0
- package/dest/array/sorted_array.js +106 -0
- package/dest/branded-types/block_number.d.ts +56 -0
- package/dest/branded-types/block_number.d.ts.map +1 -0
- package/dest/branded-types/block_number.js +78 -0
- package/dest/branded-types/checkpoint_number.d.ts +54 -0
- package/dest/branded-types/checkpoint_number.d.ts.map +1 -0
- package/dest/branded-types/checkpoint_number.js +77 -0
- package/dest/branded-types/index.d.ts +4 -1
- package/dest/branded-types/index.d.ts.map +1 -1
- package/dest/branded-types/index.js +3 -0
- 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/buffer/buffer16.d.ts +5 -2
- package/dest/buffer/buffer16.d.ts.map +1 -1
- package/dest/buffer/buffer16.js +4 -2
- package/dest/buffer/buffer32.d.ts +5 -2
- package/dest/buffer/buffer32.d.ts.map +1 -1
- package/dest/buffer/buffer32.js +4 -2
- package/dest/collection/array.d.ts +12 -1
- package/dest/collection/array.d.ts.map +1 -1
- package/dest/collection/array.js +51 -0
- 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 +15 -4
- package/dest/config/index.d.ts.map +1 -1
- package/dest/config/index.js +32 -9
- package/dest/config/network_config.d.ts +13 -1
- package/dest/config/network_config.d.ts.map +1 -1
- package/dest/config/network_config.js +3 -1
- 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.js +3 -1
- package/dest/crypto/bls/bn254_keystore.js +1 -1
- package/dest/crypto/bls/index.js +1 -1
- package/dest/crypto/bn254/index.d.ts +35 -51
- package/dest/crypto/bn254/index.d.ts.map +1 -1
- package/dest/crypto/bn254/index.js +51 -140
- package/dest/crypto/ecdsa/signature.d.ts +11 -2
- package/dest/crypto/ecdsa/signature.d.ts.map +1 -1
- package/dest/crypto/ecdsa/signature.js +2 -2
- package/dest/crypto/grumpkin/index.d.ts +4 -2
- package/dest/crypto/grumpkin/index.d.ts.map +1 -1
- package/dest/crypto/grumpkin/index.js +2 -1
- package/dest/crypto/keys/index.d.ts +2 -2
- package/dest/crypto/keys/index.d.ts.map +1 -1
- package/dest/crypto/keys/index.js +1 -1
- package/dest/crypto/pedersen/pedersen.wasm.d.ts +2 -2
- package/dest/crypto/pedersen/pedersen.wasm.d.ts.map +1 -1
- package/dest/crypto/pedersen/pedersen.wasm.js +1 -1
- package/dest/crypto/poseidon/index.d.ts +2 -3
- package/dest/crypto/poseidon/index.d.ts.map +1 -1
- package/dest/crypto/poseidon/index.js +1 -10
- 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 +3 -2
- package/dest/crypto/schnorr/index.d.ts.map +1 -1
- package/dest/crypto/schnorr/index.js +1 -1
- package/dest/crypto/schnorr/signature.d.ts +2 -2
- package/dest/crypto/schnorr/signature.d.ts.map +1 -1
- package/dest/crypto/schnorr/signature.js +2 -2
- package/dest/crypto/sha256/index.d.ts +2 -2
- package/dest/crypto/sha256/index.d.ts.map +1 -1
- package/dest/crypto/sha256/index.js +1 -1
- package/dest/crypto/sha512/index.d.ts +2 -2
- package/dest/crypto/sha512/index.d.ts.map +1 -1
- package/dest/crypto/sha512/index.js +1 -1
- package/dest/crypto/signature/index.d.ts +2 -2
- package/dest/crypto/signature/index.d.ts.map +1 -1
- package/dest/crypto/sync/pedersen/index.d.ts +2 -2
- package/dest/crypto/sync/pedersen/index.d.ts.map +1 -1
- package/dest/crypto/sync/pedersen/index.js +1 -1
- package/dest/crypto/sync/poseidon/index.d.ts +2 -3
- package/dest/crypto/sync/poseidon/index.d.ts.map +1 -1
- package/dest/crypto/sync/poseidon/index.js +1 -9
- package/dest/{fields/bls12_fields.d.ts → curves/bls12/field.d.ts} +3 -3
- package/dest/curves/bls12/field.d.ts.map +1 -0
- package/dest/{fields/bls12_fields.js → curves/bls12/field.js} +12 -9
- package/dest/curves/bls12/index.d.ts +3 -0
- package/dest/curves/bls12/index.d.ts.map +1 -0
- package/dest/curves/bls12/index.js +2 -0
- package/dest/{fields/bls12_point.d.ts → curves/bls12/point.d.ts} +13 -4
- package/dest/curves/bls12/point.d.ts.map +1 -0
- package/dest/{fields/bls12_point.js → curves/bls12/point.js} +10 -8
- package/dest/{fields/fields.d.ts → curves/bn254/field.d.ts} +7 -15
- package/dest/curves/bn254/field.d.ts.map +1 -0
- package/dest/{fields/fields.js → curves/bn254/field.js} +35 -49
- package/dest/curves/bn254/index.d.ts +3 -0
- package/dest/curves/bn254/index.d.ts.map +1 -0
- package/dest/curves/bn254/index.js +2 -0
- package/dest/curves/bn254/point.d.ts +54 -0
- package/dest/curves/bn254/point.d.ts.map +1 -0
- package/dest/curves/bn254/point.js +143 -0
- package/dest/curves/grumpkin/index.d.ts +10 -0
- package/dest/curves/grumpkin/index.d.ts.map +1 -0
- package/dest/curves/grumpkin/index.js +3 -0
- package/dest/{fields → curves/grumpkin}/point.d.ts +13 -4
- package/dest/curves/grumpkin/point.d.ts.map +1 -0
- package/dest/{fields → curves/grumpkin}/point.js +7 -7
- package/dest/error/index.d.ts +4 -4
- package/dest/error/index.d.ts.map +1 -1
- package/dest/eth-address/index.d.ts +3 -2
- package/dest/eth-address/index.d.ts.map +1 -1
- package/dest/eth-address/index.js +10 -3
- package/dest/eth-signature/eth_signature.d.ts +4 -1
- package/dest/eth-signature/eth_signature.d.ts.map +1 -1
- package/dest/iterator/filter.d.ts +3 -0
- package/dest/iterator/filter.d.ts.map +1 -0
- package/dest/iterator/filter.js +7 -0
- package/dest/iterator/index.d.ts +2 -0
- package/dest/iterator/index.d.ts.map +1 -0
- package/dest/iterator/index.js +1 -0
- package/dest/jest/setup.js +4 -1
- 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 +21 -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/server/safe_json_rpc_server.js +1 -1
- 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/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 +116 -27
- package/dest/queue/semaphore.d.ts +5 -1
- package/dest/queue/semaphore.d.ts.map +1 -1
- package/dest/retry/index.d.ts +11 -1
- package/dest/retry/index.d.ts.map +1 -1
- package/dest/retry/index.js +11 -0
- package/dest/schemas/schemas.d.ts +7 -3
- package/dest/schemas/schemas.d.ts.map +1 -1
- package/dest/schemas/schemas.js +9 -3
- package/dest/schemas/types.d.ts +31 -1
- package/dest/schemas/types.d.ts.map +1 -1
- package/dest/schemas/types.js +25 -1
- package/dest/serialize/buffer_reader.d.ts +7 -4
- package/dest/serialize/buffer_reader.d.ts.map +1 -1
- package/dest/serialize/buffer_reader.js +13 -4
- package/dest/serialize/field_reader.d.ts +2 -2
- package/dest/serialize/field_reader.d.ts.map +1 -1
- package/dest/serialize/field_reader.js +1 -1
- package/dest/serialize/free_funcs.d.ts +2 -2
- package/dest/serialize/free_funcs.d.ts.map +1 -1
- package/dest/serialize/free_funcs.js +1 -1
- package/dest/serialize/serialize.d.ts +2 -2
- package/dest/serialize/serialize.d.ts.map +1 -1
- package/dest/serialize/serialize.js +1 -1
- package/dest/sleep/index.d.ts +3 -1
- package/dest/sleep/index.d.ts.map +1 -1
- package/dest/sleep/index.js +4 -0
- package/dest/timer/date.d.ts +2 -1
- package/dest/timer/date.d.ts.map +1 -1
- package/dest/timer/date.js +3 -0
- package/dest/trees/balanced_merkle_tree_root.d.ts +17 -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} +2 -15
- package/dest/trees/hasher.d.ts +3 -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.js +1 -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 +10 -1
- package/dest/trees/merkle_tree_calculator.d.ts +1 -1
- package/dest/trees/merkle_tree_calculator.d.ts.map +1 -1
- package/dest/trees/merkle_tree_calculator.js +2 -2
- package/dest/trees/sibling_path.d.ts +3 -2
- package/dest/trees/sibling_path.d.ts.map +1 -1
- package/dest/trees/sibling_path.js +3 -3
- 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} +3 -5
- package/dest/trees/unbalanced_merkle_tree_root.d.ts.map +1 -0
- package/dest/trees/{unbalanced_merkle_tree.js → unbalanced_merkle_tree_root.js} +11 -49
- 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 +6 -2
- package/dest/types/index.d.ts.map +1 -1
- package/dest/types/index.js +6 -0
- package/package.json +28 -9
- package/src/array/index.ts +1 -0
- package/src/array/sorted_array.ts +133 -0
- package/src/branded-types/block_number.ts +117 -0
- package/src/branded-types/checkpoint_number.ts +115 -0
- package/src/branded-types/index.ts +3 -0
- package/src/branded-types/index_within_checkpoint.ts +88 -0
- package/src/buffer/buffer16.ts +2 -2
- package/src/buffer/buffer32.ts +2 -2
- package/src/collection/array.ts +52 -0
- package/src/config/env_var.ts +47 -12
- package/src/config/index.ts +39 -6
- package/src/config/network_config.ts +2 -0
- package/src/config/parse-env.ts +4 -0
- package/src/crypto/bls/bn254_keystore.ts +1 -1
- package/src/crypto/bls/index.ts +1 -1
- package/src/crypto/bn254/index.ts +50 -159
- package/src/crypto/ecdsa/signature.ts +2 -2
- package/src/crypto/grumpkin/index.ts +3 -1
- package/src/crypto/keys/index.ts +1 -1
- package/src/crypto/pedersen/pedersen.wasm.ts +1 -1
- package/src/crypto/poseidon/index.ts +1 -11
- package/src/crypto/random/randomness_singleton.ts +6 -4
- package/src/crypto/schnorr/index.ts +2 -1
- package/src/crypto/schnorr/signature.ts +2 -2
- package/src/crypto/sha256/index.ts +1 -1
- package/src/crypto/sha512/index.ts +1 -1
- package/src/crypto/signature/index.ts +1 -1
- package/src/crypto/sync/pedersen/index.ts +1 -1
- package/src/crypto/sync/poseidon/index.ts +1 -10
- package/src/{fields/bls12_fields.ts → curves/bls12/field.ts} +6 -6
- package/src/curves/bls12/index.ts +2 -0
- package/src/{fields/bls12_point.ts → curves/bls12/point.ts} +7 -7
- package/src/{fields/fields.ts → curves/bn254/field.ts} +33 -56
- package/src/curves/bn254/index.ts +2 -0
- package/src/curves/bn254/point.ts +170 -0
- package/src/curves/grumpkin/index.ts +11 -0
- package/src/{fields → curves/grumpkin}/point.ts +7 -7
- package/src/eth-address/index.ts +8 -2
- package/src/iterator/filter.ts +11 -0
- package/src/iterator/index.ts +1 -0
- package/src/jest/setup.mjs +4 -1
- package/src/json-rpc/client/undici.ts +21 -3
- package/src/json-rpc/server/safe_json_rpc_server.ts +1 -1
- package/src/log/libp2p_logger.ts +12 -5
- package/src/log/pino-logger-server.ts +25 -0
- package/src/log/pino-logger.ts +138 -37
- package/src/queue/semaphore.ts +5 -0
- package/src/retry/index.ts +18 -0
- package/src/schemas/schemas.ts +14 -3
- package/src/schemas/types.ts +33 -0
- package/src/serialize/buffer_reader.ts +21 -9
- package/src/serialize/field_reader.ts +1 -1
- package/src/serialize/free_funcs.ts +1 -1
- package/src/serialize/serialize.ts +1 -1
- package/src/sleep/index.ts +6 -0
- package/src/timer/date.ts +4 -0
- package/src/trees/{balanced_merkle_tree.ts → balanced_merkle_tree_root.ts} +2 -16
- package/src/trees/hasher.ts +9 -0
- package/src/trees/index.ts +3 -3
- package/src/trees/indexed_merkle_tree.ts +1 -1
- package/src/trees/membership_witness.ts +9 -1
- package/src/trees/merkle_tree_calculator.ts +2 -2
- package/src/trees/sibling_path.ts +3 -3
- package/src/trees/unbalanced_merkle_tree_calculator.ts +1 -12
- package/src/trees/{unbalanced_merkle_tree.ts → unbalanced_merkle_tree_root.ts} +17 -61
- package/src/trees/unbalanced_tree_store.ts +57 -2
- package/src/types/index.ts +11 -1
- package/dest/crypto/bn254/bn254_utils.d.ts +0 -39
- package/dest/crypto/bn254/bn254_utils.d.ts.map +0 -1
- package/dest/crypto/bn254/bn254_utils.js +0 -56
- package/dest/crypto/index.d.ts +0 -17
- package/dest/crypto/index.d.ts.map +0 -1
- package/dest/crypto/index.js +0 -16
- package/dest/fields/bls12_fields.d.ts.map +0 -1
- package/dest/fields/bls12_point.d.ts.map +0 -1
- package/dest/fields/coordinate.d.ts +0 -63
- package/dest/fields/coordinate.d.ts.map +0 -1
- package/dest/fields/coordinate.js +0 -96
- package/dest/fields/fields.d.ts.map +0 -1
- package/dest/fields/index.d.ts +0 -6
- package/dest/fields/index.d.ts.map +0 -1
- package/dest/fields/index.js +0 -5
- package/dest/fields/point.d.ts.map +0 -1
- package/dest/index.d.ts +0 -31
- package/dest/index.d.ts.map +0 -1
- package/dest/index.js +0 -31
- 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/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/bn254/bn254_utils.ts +0 -64
- package/src/crypto/index.ts +0 -16
- package/src/fields/coordinate.ts +0 -104
- package/src/fields/index.ts +0 -5
- package/src/index.ts +0 -31
- package/src/json-rpc/server/telemetry.ts +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { makeTuple } from '../array/array.js';
|
|
2
|
-
import {
|
|
3
|
-
import { Fr } from '../
|
|
2
|
+
import { poseidon2Hash } from '../crypto/poseidon/index.js';
|
|
3
|
+
import { Fr } from '../curves/bn254/index.js';
|
|
4
4
|
import { schemas } from '../schemas/index.js';
|
|
5
5
|
import { assertLength, deserializeArrayFromVector, serializeArrayOfBufferableToVector } from '../serialize/index.js';
|
|
6
6
|
import { bufferToHex, hexToBuffer } from '../string/index.js';
|
|
@@ -131,7 +131,7 @@ import { bufferToHex, hexToBuffer } from '../string/index.js';
|
|
|
131
131
|
return new SiblingPath(subtreePathSize, subtreeData);
|
|
132
132
|
}
|
|
133
133
|
}
|
|
134
|
-
/** Computes the expected root of a merkle tree given a leaf and its sibling path. */ export async function computeRootFromSiblingPath(leaf, siblingPath, index, hasher = async (left, right)=>(await
|
|
134
|
+
/** Computes the expected root of a merkle tree given a leaf and its sibling path. */ export async function computeRootFromSiblingPath(leaf, siblingPath, index, hasher = async (left, right)=>(await poseidon2Hash([
|
|
135
135
|
left,
|
|
136
136
|
right
|
|
137
137
|
])).toBuffer()) {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Hasher } from './hasher.js';
|
|
2
2
|
import { SiblingPath } from './sibling_path.js';
|
|
3
3
|
import { type TreeNodeLocation } from './unbalanced_tree_store.js';
|
|
4
|
-
export declare function computeCompressedUnbalancedMerkleTreeRoot(leaves: Buffer[], valueToCompress?: Buffer<ArrayBuffer>, emptyRoot?: Buffer<ArrayBuffer>, hasher?: Hasher['hash']): Buffer;
|
|
5
4
|
/**
|
|
6
5
|
* An ephemeral unbalanced Merkle tree implementation.
|
|
7
6
|
* Follows the rollup implementation which greedily hashes pairs of nodes up the tree.
|
|
@@ -46,4 +45,4 @@ export declare class UnbalancedMerkleTreeCalculator {
|
|
|
46
45
|
private shiftNodeUp;
|
|
47
46
|
private collectNodesToShift;
|
|
48
47
|
}
|
|
49
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
48
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidW5iYWxhbmNlZF9tZXJrbGVfdHJlZV9jYWxjdWxhdG9yLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvdHJlZXMvdW5iYWxhbmNlZF9tZXJrbGVfdHJlZV9jYWxjdWxhdG9yLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFBRSxLQUFLLE1BQU0sRUFBaUIsTUFBTSxhQUFhLENBQUM7QUFDekQsT0FBTyxFQUFFLFdBQVcsRUFBRSxNQUFNLG1CQUFtQixDQUFDO0FBQ2hELE9BQU8sRUFBRSxLQUFLLGdCQUFnQixFQUF1QixNQUFNLDRCQUE0QixDQUFDO0FBT3hGOzs7Ozs7O0dBT0c7QUFDSCxxQkFBYSw4QkFBOEI7SUFLdkMsT0FBTyxDQUFDLFFBQVEsQ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ced_merkle_tree_calculator.d.ts","sourceRoot":"","sources":["../../src/trees/unbalanced_merkle_tree_calculator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"unbalanced_merkle_tree_calculator.d.ts","sourceRoot":"","sources":["../../src/trees/unbalanced_merkle_tree_calculator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAiB,MAAM,aAAa,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,KAAK,gBAAgB,EAAuB,MAAM,4BAA4B,CAAC;AAOxF;;;;;;;GAOG;AACH,qBAAa,8BAA8B;IAKvC,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,eAAe;IAChC,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,MAAM;IAPzB,OAAO,CAAC,KAAK,CAAgC;IAC7C,OAAO,CAAC,aAAa,CAA0B;IAE/C,YACmB,MAAM,EAAE,MAAM,EAAE,EAChB,eAAe,EAAE,MAAM,EACvB,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,EAIxC;IAED,MAAM,CAAC,MAAM,CACX,MAAM,EAAE,MAAM,EAAE,EAChB,eAAe,sBAAkB,EACjC,SAAS,sBAAmB,EAC5B,MAAM,8FAAgB,kCAGvB;IAED;;;OAGG;IACI,OAAO,IAAI,MAAM,CAEvB;IAED;;;;;OAKG;IACI,cAAc,CAAC,CAAC,SAAS,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,WAAW,CAAC,CAAC,CAAC,CAOrE;IAED;;;;OAIG;IACI,yBAAyB,CAAC,CAAC,SAAS,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,WAAW,CAAC,CAAC,CAAC,CAmBpF;IAEM,eAAe,CAAC,SAAS,EAAE,MAAM,oBAEvC;IAED;;;OAGG;IACH,OAAO,CAAC,SAAS;IA+CjB,OAAO,CAAC,WAAW;IAYnB,OAAO,CAAC,mBAAmB;CAmB5B"}
|
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
import { shaMerkleHash } from './
|
|
1
|
+
import { shaMerkleHash } from './hasher.js';
|
|
2
2
|
import { SiblingPath } from './sibling_path.js';
|
|
3
3
|
import { UnbalancedTreeStore } from './unbalanced_tree_store.js';
|
|
4
|
-
export function computeCompressedUnbalancedMerkleTreeRoot(leaves, valueToCompress = Buffer.alloc(32), emptyRoot = Buffer.alloc(32), hasher) {
|
|
5
|
-
const calculator = UnbalancedMerkleTreeCalculator.create(leaves, valueToCompress, emptyRoot, hasher);
|
|
6
|
-
return calculator.getRoot();
|
|
7
|
-
}
|
|
8
4
|
/**
|
|
9
5
|
* An ephemeral unbalanced Merkle tree implementation.
|
|
10
6
|
* Follows the rollup implementation which greedily hashes pairs of nodes up the tree.
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export declare const computeUnbalancedShaRoot: (leaves: Buffer<ArrayBufferLike>[]) => Buffer<ArrayBufferLike>;
|
|
2
2
|
export declare const computeUnbalancedPoseidonRoot: (leaves: Buffer<ArrayBufferLike>[]) => Promise<Buffer<ArrayBufferLike>>;
|
|
3
|
+
export declare const computeWonkyShaRoot: (leaves: Buffer<ArrayBufferLike>[]) => Buffer<ArrayBufferLike>;
|
|
3
4
|
/**
|
|
4
5
|
* Computes the Merkle root of an unbalanced tree.
|
|
5
6
|
*
|
|
@@ -23,8 +24,5 @@ export declare const computeUnbalancedPoseidonRoot: (leaves: Buffer<ArrayBufferL
|
|
|
23
24
|
*/
|
|
24
25
|
export declare function computeUnbalancedMerkleTreeRoot(leaves: Buffer[], hasher?: (lhs: Uint8Array<ArrayBufferLike>, rhs: Uint8Array<ArrayBufferLike>) => Buffer<ArrayBuffer>, emptyRoot?: Buffer<ArrayBuffer>): Buffer;
|
|
25
26
|
export declare function computeUnbalancedMerkleTreeRootAsync(leaves: Buffer[], hasher?: (lhs: Uint8Array<ArrayBufferLike>, rhs: Uint8Array<ArrayBufferLike>) => Promise<Buffer<ArrayBuffer>>, emptyRoot?: Buffer<ArrayBuffer>): Promise<Buffer>;
|
|
26
|
-
export declare function
|
|
27
|
-
|
|
28
|
-
indexAtLevel: number;
|
|
29
|
-
};
|
|
30
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidW5iYWxhbmNlZF9tZXJrbGVfdHJlZS5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL3RyZWVzL3VuYmFsYW5jZWRfbWVya2xlX3RyZWUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBT0EsZUFBTyxNQUFNLHdCQUF3QixnRUFBK0UsQ0FBQztBQUVySCxlQUFPLE1BQU0sNkJBQTZCLHlFQUM4QixDQUFDO0FBRXpFOzs7Ozs7Ozs7Ozs7Ozs7Ozs7OztHQW9CRztBQUNILHdCQUFnQiwrQkFBK0IsQ0FDN0MsTUFBTSxFQUFFLE1BQU0sRUFBRSxFQUNoQixNQUFNLDhGQUFnQixFQUN0QixTQUFTLHNCQUFtQixHQUMzQixNQUFNLENBNkJSO0FBRUQsd0JBQXNCLG9DQUFvQyxDQUN4RCxNQUFNLEVBQUUsTUFBTSxFQUFFLEVBQ2hCLE1BQU0sdUdBQXFCLEVBQzNCLFNBQVMsc0JBQW1CLEdBQzNCLE9BQU8sQ0FBQyxNQUFNLENBQUMsQ0E2QmpCO0FBc0RELHdCQUFnQixxQkFBcUIsQ0FBQyxTQUFTLEVBQUUsTUFBTSxFQUFFLFNBQVMsRUFBRSxNQUFNOzs7RUFHekUifQ==
|
|
27
|
+
export declare function computeWonkyMerkleTreeRoot(leaves: Buffer[], valueToCompress?: Buffer<ArrayBuffer>, emptyRoot?: Buffer<ArrayBuffer>, hasher?: (lhs: Uint8Array<ArrayBufferLike>, rhs: Uint8Array<ArrayBufferLike>) => Buffer<ArrayBuffer>): Buffer;
|
|
28
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidW5iYWxhbmNlZF9tZXJrbGVfdHJlZV9yb290LmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvdHJlZXMvdW5iYWxhbmNlZF9tZXJrbGVfdHJlZV9yb290LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUlBLGVBQU8sTUFBTSx3QkFBd0IsZ0VBQStFLENBQUM7QUFFckgsZUFBTyxNQUFNLDZCQUE2Qix5RUFDOEIsQ0FBQztBQUV6RSxlQUFPLE1BQU0sbUJBQW1CLGdFQUEyRCxDQUFDO0FBRTVGOzs7Ozs7Ozs7Ozs7Ozs7Ozs7OztHQW9CRztBQUNILHdCQUFnQiwrQkFBK0IsQ0FDN0MsTUFBTSxFQUFFLE1BQU0sRUFBRSxFQUNoQixNQUFNLDhGQUFnQixFQUN0QixTQUFTLHNCQUFtQixHQUMzQixNQUFNLENBNkJSO0FBRUQsd0JBQXNCLG9DQUFvQyxDQUN4RCxNQUFNLEVBQUUsTUFBTSxFQUFFLEVBQ2hCLE1BQU0sdUdBQXFCLEVBQzNCLFNBQVMsc0JBQW1CLEdBQzNCLE9BQU8sQ0FBQyxNQUFNLENBQUMsQ0E2QmpCO0FBTUQsd0JBQWdCLDBCQUEwQixDQUN4QyxNQUFNLEVBQUUsTUFBTSxFQUFFLEVBQ2hCLGVBQWUsc0JBQW1CLEVBQ2xDLFNBQVMsc0JBQW1CLEVBQzVCLE1BQU0sOEZBQWdCLEdBQ3JCLE1BQU0sQ0FHUiJ9
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unbalanced_merkle_tree_root.d.ts","sourceRoot":"","sources":["../../src/trees/unbalanced_merkle_tree_root.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,wBAAwB,gEAA+E,CAAC;AAErH,eAAO,MAAM,6BAA6B,yEAC8B,CAAC;AAEzE,eAAO,MAAM,mBAAmB,gEAA2D,CAAC;AAE5F;;;;;;;;;;;;;;;;;;;;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;AAMD,wBAAgB,0BAA0B,CACxC,MAAM,EAAE,MAAM,EAAE,EAChB,eAAe,sBAAmB,EAClC,SAAS,sBAAmB,EAC5B,MAAM,8FAAgB,GACrB,MAAM,CAGR"}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import { computeBalancedMerkleTreeRoot, computeBalancedMerkleTreeRootAsync
|
|
1
|
+
import { computeBalancedMerkleTreeRoot, computeBalancedMerkleTreeRootAsync } from './balanced_merkle_tree_root.js';
|
|
2
|
+
import { poseidonMerkleHash, shaMerkleHash } from './hasher.js';
|
|
3
|
+
import { UnbalancedMerkleTreeCalculator } from './unbalanced_merkle_tree_calculator.js';
|
|
2
4
|
export const computeUnbalancedShaRoot = (leaves)=>computeUnbalancedMerkleTreeRoot(leaves, shaMerkleHash);
|
|
3
5
|
export const computeUnbalancedPoseidonRoot = async (leaves)=>await computeUnbalancedMerkleTreeRootAsync(leaves, poseidonMerkleHash);
|
|
6
|
+
export const computeWonkyShaRoot = (leaves)=>computeWonkyMerkleTreeRoot(leaves);
|
|
4
7
|
/**
|
|
5
8
|
* Computes the Merkle root of an unbalanced tree.
|
|
6
9
|
*
|
|
@@ -71,52 +74,11 @@ export async function computeUnbalancedMerkleTreeRootAsync(leaves, hasher = pose
|
|
|
71
74
|
}
|
|
72
75
|
return root;
|
|
73
76
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
return
|
|
81
|
-
}
|
|
82
|
-
/// Get the maximum depth of an unbalanced tree that can be created with the given number of leaves.
|
|
83
|
-
function getMaxUnbalancedTreeDepth(numLeaves) {
|
|
84
|
-
return Math.ceil(Math.log2(numLeaves));
|
|
85
|
-
}
|
|
86
|
-
function findPosition(rootLevel, leafLevel, numLeaves, indexOffset, targetIndex) {
|
|
87
|
-
if (numLeaves <= 1) {
|
|
88
|
-
// Single leaf.
|
|
89
|
-
return {
|
|
90
|
-
level: rootLevel,
|
|
91
|
-
indexAtLevel: indexOffset
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
// The largest balanced tree that can be created with the given number of leaves.
|
|
95
|
-
const maxBalancedTreeDepth = getMaxBalancedSubtreeDepth(numLeaves);
|
|
96
|
-
const numBalancedLeaves = 2 ** maxBalancedTreeDepth;
|
|
97
|
-
const numRemainingLeaves = numLeaves - numBalancedLeaves;
|
|
98
|
-
if (targetIndex < numBalancedLeaves) {
|
|
99
|
-
// Target is in the balanced tree.
|
|
100
|
-
// - If numRemainingLeaves is 0: this balanced tree is grown from the current root.
|
|
101
|
-
// - If numRemainingLeaves is not 0: the remaining leaves will form another tree, which will become the right child of the root.
|
|
102
|
-
// And the balanced tree will be the left child of the root.
|
|
103
|
-
// There will be an extra level between the root of the balanced tree and the current root.
|
|
104
|
-
const extraLevel = numRemainingLeaves ? 1 : 0;
|
|
105
|
-
return {
|
|
106
|
-
level: rootLevel + maxBalancedTreeDepth + extraLevel,
|
|
107
|
-
indexAtLevel: indexOffset + targetIndex
|
|
108
|
-
};
|
|
109
|
-
} else {
|
|
110
|
-
// Target is in the right branch.
|
|
111
|
-
const rightBranchMaxLevel = getMaxUnbalancedTreeDepth(numRemainingLeaves);
|
|
112
|
-
const shiftedUp = leafLevel - rootLevel - rightBranchMaxLevel - 1;
|
|
113
|
-
const nextLeafLevel = leafLevel - shiftedUp;
|
|
114
|
-
const newIndexOffset = indexOffset + numBalancedLeaves >> shiftedUp;
|
|
115
|
-
const shiftedTargetIndex = targetIndex - numBalancedLeaves;
|
|
116
|
-
return findPosition(rootLevel + 1, nextLeafLevel, numRemainingLeaves, newIndexOffset, shiftedTargetIndex);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
export function findLeafLevelAndIndex(numLeaves, leafIndex) {
|
|
120
|
-
const maxLevel = getMaxUnbalancedTreeDepth(numLeaves);
|
|
121
|
-
return findPosition(0, maxLevel, numLeaves, 0, leafIndex);
|
|
77
|
+
// A **wonky** tree is a "compressed" unbalanced Merkle tree.
|
|
78
|
+
// It is constructed in the same way as an unbalanced tree: by first creating the largest possible left subtree, with
|
|
79
|
+
// the remaining leaves forming a right subtree that follows the same process recursively.
|
|
80
|
+
// During construction, leaves equal to `valueToCompress` are skipped (compressed) and do not contribute to the tree.
|
|
81
|
+
export function computeWonkyMerkleTreeRoot(leaves, valueToCompress = Buffer.alloc(32), emptyRoot = Buffer.alloc(32), hasher = shaMerkleHash) {
|
|
82
|
+
const calculator = UnbalancedMerkleTreeCalculator.create(leaves, valueToCompress, emptyRoot, hasher);
|
|
83
|
+
return calculator.getRoot();
|
|
122
84
|
}
|
|
@@ -17,4 +17,8 @@ export declare class UnbalancedTreeStore<T> {
|
|
|
17
17
|
getSibling(location: TreeNodeLocation): T | undefined;
|
|
18
18
|
getChildren(location: TreeNodeLocation): [T | undefined, T | undefined];
|
|
19
19
|
}
|
|
20
|
-
|
|
20
|
+
export declare function findLeafLevelAndIndex(numLeaves: number, leafIndex: number): {
|
|
21
|
+
level: number;
|
|
22
|
+
indexAtLevel: number;
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidW5iYWxhbmNlZF90cmVlX3N0b3JlLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvdHJlZXMvdW5iYWxhbmNlZF90cmVlX3N0b3JlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3M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yxDQUdwRDtJQUVELFdBQVcsQ0FBQyxRQUFRLEVBQUUsZ0JBQWdCLEdBQUcsQ0FBQyxDQUFDLEdBQUcsU0FBUyxFQUFFLENBQUMsR0FBRyxTQUFTLENBQUMsQ0FHdEU7Q0FLRjtBQXNERCx3QkFBZ0IscUJBQXFCLENBQUMsU0FBUyxFQUFFLE1BQU0sRUFBRSxTQUFTLEVBQUUsTUFBTTs7O0VBR3pFIn0=
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unbalanced_tree_store.d.ts","sourceRoot":"","sources":["../../src/trees/unbalanced_tree_store.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"unbalanced_tree_store.d.ts","sourceRoot":"","sources":["../../src/trees/unbalanced_tree_store.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACf;AAOD,qBAAa,mBAAmB,CAAC,CAAC;;IAIhC,YAAY,SAAS,EAAE,MAAM,EAE5B;IAED,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,gBAAgB,CAerD;IAED,OAAO,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,gBAAgB,EAAE,KAAK,EAAE,CAAC,QASnD;IAED,iBAAiB,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,gBAAgB,GAAG,gBAAgB,CAMtE;IAED,kBAAkB,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,gBAAgB,GAAG,gBAAgB,CAMvE;IAED,iBAAiB,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,gBAAgB,GAAG,CAAC,gBAAgB,EAAE,gBAAgB,CAAC,CAI1F;IAED,OAAO,CAAC,SAAS,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS,CAOxC;IAED,OAAO,CAAC,QAAQ,EAAE,gBAAgB,GAAG,CAAC,GAAG,SAAS,CAEjD;IAED,OAAO,IAAI,CAAC,GAAG,SAAS,CAEvB;IAED,SAAS,CAAC,QAAQ,EAAE,gBAAgB,GAAG,CAAC,GAAG,SAAS,CAGnD;IAED,UAAU,CAAC,QAAQ,EAAE,gBAAgB,GAAG,CAAC,GAAG,SAAS,CAGpD;IAED,WAAW,CAAC,QAAQ,EAAE,gBAAgB,GAAG,CAAC,CAAC,GAAG,SAAS,EAAE,CAAC,GAAG,SAAS,CAAC,CAGtE;CAKF;AAsDD,wBAAgB,qBAAqB,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM;;;EAGzE"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { findLeafLevelAndIndex } from './unbalanced_merkle_tree.js';
|
|
2
1
|
export class UnbalancedTreeStore {
|
|
3
2
|
#nodeMapping = new Map();
|
|
4
3
|
#numLeaves;
|
|
@@ -98,3 +97,52 @@ export class UnbalancedTreeStore {
|
|
|
98
97
|
return `${location.level}-${location.index}`;
|
|
99
98
|
}
|
|
100
99
|
}
|
|
100
|
+
/// Get the depth of the maximum balanced tree that can be created with the given number of leaves. The subtree will be
|
|
101
|
+
/// the left most subtree of the unbalanced tree with a total of `numLeaves` leaves.
|
|
102
|
+
///
|
|
103
|
+
/// Note: All the leaves may not be used to form the tree. For example, if there are 5 leaves, the maximum depth is 2,
|
|
104
|
+
/// only 4 leaves are used to form a balanced tree.
|
|
105
|
+
function getMaxBalancedSubtreeDepth(numLeaves) {
|
|
106
|
+
return Math.floor(Math.log2(numLeaves));
|
|
107
|
+
}
|
|
108
|
+
/// Get the maximum depth of an unbalanced tree that can be created with the given number of leaves.
|
|
109
|
+
function getMaxUnbalancedTreeDepth(numLeaves) {
|
|
110
|
+
return Math.ceil(Math.log2(numLeaves));
|
|
111
|
+
}
|
|
112
|
+
function findPosition(rootLevel, leafLevel, numLeaves, indexOffset, targetIndex) {
|
|
113
|
+
if (numLeaves <= 1) {
|
|
114
|
+
// Single leaf.
|
|
115
|
+
return {
|
|
116
|
+
level: rootLevel,
|
|
117
|
+
indexAtLevel: indexOffset
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
// The largest balanced tree that can be created with the given number of leaves.
|
|
121
|
+
const maxBalancedTreeDepth = getMaxBalancedSubtreeDepth(numLeaves);
|
|
122
|
+
const numBalancedLeaves = 2 ** maxBalancedTreeDepth;
|
|
123
|
+
const numRemainingLeaves = numLeaves - numBalancedLeaves;
|
|
124
|
+
if (targetIndex < numBalancedLeaves) {
|
|
125
|
+
// Target is in the balanced tree.
|
|
126
|
+
// - If numRemainingLeaves is 0: this balanced tree is grown from the current root.
|
|
127
|
+
// - If numRemainingLeaves is not 0: the remaining leaves will form another tree, which will become the right child of the root.
|
|
128
|
+
// And the balanced tree will be the left child of the root.
|
|
129
|
+
// There will be an extra level between the root of the balanced tree and the current root.
|
|
130
|
+
const extraLevel = numRemainingLeaves ? 1 : 0;
|
|
131
|
+
return {
|
|
132
|
+
level: rootLevel + maxBalancedTreeDepth + extraLevel,
|
|
133
|
+
indexAtLevel: indexOffset + targetIndex
|
|
134
|
+
};
|
|
135
|
+
} else {
|
|
136
|
+
// Target is in the right branch.
|
|
137
|
+
const rightBranchMaxLevel = getMaxUnbalancedTreeDepth(numRemainingLeaves);
|
|
138
|
+
const shiftedUp = leafLevel - rootLevel - rightBranchMaxLevel - 1;
|
|
139
|
+
const nextLeafLevel = leafLevel - shiftedUp;
|
|
140
|
+
const newIndexOffset = indexOffset + numBalancedLeaves >> shiftedUp;
|
|
141
|
+
const shiftedTargetIndex = targetIndex - numBalancedLeaves;
|
|
142
|
+
return findPosition(rootLevel + 1, nextLeafLevel, numRemainingLeaves, newIndexOffset, shiftedTargetIndex);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
export function findLeafLevelAndIndex(numLeaves, leafIndex) {
|
|
146
|
+
const maxLevel = getMaxUnbalancedTreeDepth(numLeaves);
|
|
147
|
+
return findPosition(0, maxLevel, numLeaves, 0, leafIndex);
|
|
148
|
+
}
|
package/dest/types/index.d.ts
CHANGED
|
@@ -14,6 +14,10 @@ export type Writeable<T> = {
|
|
|
14
14
|
};
|
|
15
15
|
/** Removes readonly modifiers for an object. */
|
|
16
16
|
export declare function unfreeze<T>(obj: T): Writeable<T>;
|
|
17
|
+
/** Is defined type guard */
|
|
18
|
+
export declare function isDefined<T>(value: T | undefined): value is T;
|
|
19
|
+
/** Type guard for error classes */
|
|
20
|
+
export declare function isErrorClass<T extends Error>(value: unknown, errorClass: new (...args: any[]) => T): value is T;
|
|
17
21
|
/** Resolves a record-like type. Lifted from viem. */
|
|
18
22
|
export type Prettify<T> = {
|
|
19
23
|
[K in keyof T]: T[K];
|
|
@@ -22,7 +26,7 @@ export type Prettify<T> = {
|
|
|
22
26
|
* Type-safe Event Emitter type
|
|
23
27
|
* @example
|
|
24
28
|
* export type ArchiverEmitter = TypedEventEmitter<{
|
|
25
|
-
* [L2BlockSourceEvents.
|
|
29
|
+
* [L2BlockSourceEvents.L2PruneUnproven]: (args: L2BlockSourceEvent) => void;
|
|
26
30
|
* [L2BlockSourceEvents.L2BlockProven]: (args: L2BlockSourceEvent) => void;
|
|
27
31
|
* }>;
|
|
28
32
|
* class Archiver extends (EventEmitter as new () => ArchiverEmitter) {
|
|
@@ -39,4 +43,4 @@ export interface TypedEventEmitter<TEventMap extends {
|
|
|
39
43
|
removeListener<K extends keyof TEventMap>(event: K, listener: TEventMap[K]): this;
|
|
40
44
|
removeAllListeners<K extends keyof TEventMap>(event: K): this;
|
|
41
45
|
}
|
|
42
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
46
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy90eXBlcy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxnQ0FBZ0M7QUFDaE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CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CACrB,GAAG,EAAE,CAAC;AAEP;;;;;;;;;;GAUG;AACH,MAAM,WAAW,iBAAiB,CAAC,SAAS,SAAS;KAAG,GAAG,IAAI,MAAM,SAAS,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI;CAAE;IACzG,IAAI,CAAC,CAAC,SAAS,MAAM,SAAS,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IACxE,EAAE,CAAC,CAAC,SAAS,MAAM,SAAS,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IACtE,GAAG,CAAC,CAAC,SAAS,MAAM,SAAS,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IACvE,IAAI,CAAC,CAAC,SAAS,MAAM,SAAS,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,IAAI,EAAE,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC;IACtF,cAAc,CAAC,CAAC,SAAS,MAAM,SAAS,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IAClF,kBAAkB,CAAC,CAAC,SAAS,MAAM,SAAS,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI,CAAC;CAE/D"}
|
package/dest/types/index.js
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
1
|
/** Strips methods of a type. */ /** Removes readonly modifiers for an object. */ export function unfreeze(obj) {
|
|
2
2
|
return obj;
|
|
3
3
|
}
|
|
4
|
+
/** Is defined type guard */ export function isDefined(value) {
|
|
5
|
+
return value !== undefined;
|
|
6
|
+
}
|
|
7
|
+
/** Type guard for error classes */ export function isErrorClass(value, errorClass) {
|
|
8
|
+
return value instanceof errorClass || value instanceof Error && value.name === errorClass.name;
|
|
9
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/foundation",
|
|
3
|
-
"version": "0.0.1-commit.
|
|
3
|
+
"version": "0.0.1-commit.9d2bcf6d",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dest/index.js",
|
|
6
6
|
"types": "./dest/index.d.ts",
|
|
@@ -15,9 +15,27 @@
|
|
|
15
15
|
"./branded-types": "./dest/branded-types/index.js",
|
|
16
16
|
"./collection": "./dest/collection/index.js",
|
|
17
17
|
"./config": "./dest/config/index.js",
|
|
18
|
-
"./crypto": "./dest/crypto/index.js",
|
|
19
|
-
"./crypto/
|
|
18
|
+
"./crypto/aes128": "./dest/crypto/aes128/index.js",
|
|
19
|
+
"./crypto/bls": "./dest/crypto/bls/index.js",
|
|
20
20
|
"./crypto/bls/bn254_keystore": "./dest/crypto/bls/bn254_keystore.js",
|
|
21
|
+
"./crypto/bn254": "./dest/crypto/bn254/index.js",
|
|
22
|
+
"./crypto/ecdsa": "./dest/crypto/ecdsa/index.js",
|
|
23
|
+
"./crypto/grumpkin": "./dest/crypto/grumpkin/index.js",
|
|
24
|
+
"./crypto/keccak": "./dest/crypto/keccak/index.js",
|
|
25
|
+
"./crypto/keys": "./dest/crypto/keys/index.js",
|
|
26
|
+
"./crypto/pedersen": "./dest/crypto/pedersen/index.js",
|
|
27
|
+
"./crypto/poseidon": "./dest/crypto/poseidon/index.js",
|
|
28
|
+
"./crypto/random": "./dest/crypto/random/index.js",
|
|
29
|
+
"./crypto/schnorr": "./dest/crypto/schnorr/index.js",
|
|
30
|
+
"./crypto/secp256k1": "./dest/crypto/secp256k1/index.js",
|
|
31
|
+
"./crypto/secp256k1-signer": "./dest/crypto/secp256k1-signer/index.js",
|
|
32
|
+
"./crypto/sha256": "./dest/crypto/sha256/index.js",
|
|
33
|
+
"./crypto/sha512": "./dest/crypto/sha512/index.js",
|
|
34
|
+
"./crypto/signature": "./dest/crypto/signature/index.js",
|
|
35
|
+
"./crypto/sync": "./dest/crypto/sync/index.js",
|
|
36
|
+
"./curves/bn254": "./dest/curves/bn254/index.js",
|
|
37
|
+
"./curves/grumpkin": "./dest/curves/grumpkin/index.js",
|
|
38
|
+
"./curves/bls12": "./dest/curves/bls12/index.js",
|
|
21
39
|
"./decorators": "./dest/decorators/index.js",
|
|
22
40
|
"./error": "./dest/error/index.js",
|
|
23
41
|
"./eth-address": "./dest/eth-address/index.js",
|
|
@@ -31,9 +49,10 @@
|
|
|
31
49
|
"./json-rpc/undici": "./dest/json-rpc/client/undici.js",
|
|
32
50
|
"./json-rpc/test": "./dest/json-rpc/test/index.js",
|
|
33
51
|
"./iterable": "./dest/iterable/index.js",
|
|
52
|
+
"./iterator": "./dest/iterator/index.js",
|
|
34
53
|
"./log": "./dest/log/index.js",
|
|
54
|
+
"./log/server": "./dest/log/pino-logger-server.js",
|
|
35
55
|
"./mutex": "./dest/mutex/index.js",
|
|
36
|
-
"./fields": "./dest/fields/index.js",
|
|
37
56
|
"./retry": "./dest/retry/index.js",
|
|
38
57
|
"./running-promise": "./dest/running-promise/index.js",
|
|
39
58
|
"./serialize": "./dest/serialize/index.js",
|
|
@@ -58,8 +77,8 @@
|
|
|
58
77
|
"./number": "./dest/number/index.js"
|
|
59
78
|
},
|
|
60
79
|
"scripts": {
|
|
61
|
-
"build": "yarn clean &&
|
|
62
|
-
"build:dev": "
|
|
80
|
+
"build": "yarn clean && ../scripts/tsc.sh",
|
|
81
|
+
"build:dev": "../scripts/tsc.sh --watch",
|
|
63
82
|
"clean": "rm -rf ./dest .tsbuildinfo",
|
|
64
83
|
"generate": "true",
|
|
65
84
|
"test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}"
|
|
@@ -105,7 +124,7 @@
|
|
|
105
124
|
"testEnvironment": "../../foundation/src/jest/env.mjs"
|
|
106
125
|
},
|
|
107
126
|
"dependencies": {
|
|
108
|
-
"@aztec/bb.js": "0.0.1-commit.
|
|
127
|
+
"@aztec/bb.js": "0.0.1-commit.9d2bcf6d",
|
|
109
128
|
"@koa/cors": "^5.0.0",
|
|
110
129
|
"@noble/curves": "=1.7.0",
|
|
111
130
|
"@noble/hashes": "^1.6.1",
|
|
@@ -144,11 +163,11 @@
|
|
|
144
163
|
"@types/node": "^22.15.17",
|
|
145
164
|
"@types/pako": "^2.0.0",
|
|
146
165
|
"@types/supertest": "^2.0.12",
|
|
147
|
-
"@typescript/native-preview": "7.0.0-dev.
|
|
166
|
+
"@typescript/native-preview": "7.0.0-dev.20260113.1",
|
|
148
167
|
"comlink": "^4.4.1",
|
|
149
168
|
"eslint": "^9.26.0",
|
|
150
169
|
"eslint-config-prettier": "^10.1.5",
|
|
151
|
-
"eslint-plugin-import": "^
|
|
170
|
+
"eslint-plugin-import-x": "^4.6.1",
|
|
152
171
|
"eslint-plugin-jsdoc": "^50.6.14",
|
|
153
172
|
"eslint-plugin-no-only-tests": "^3.3.0",
|
|
154
173
|
"eslint-plugin-tsdoc": "^0.4.0",
|
package/src/array/index.ts
CHANGED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
type Cmp<T> = (a: T, b: T) => -1 | 0 | 1;
|
|
2
|
+
|
|
3
|
+
export function dedupeSortedArray<T>(arr: T[], cmp: Cmp<T>): void {
|
|
4
|
+
for (let i = 0; i < arr.length; i++) {
|
|
5
|
+
let j = i + 1;
|
|
6
|
+
for (; j < arr.length; j++) {
|
|
7
|
+
const res = cmp(arr[i], arr[j]);
|
|
8
|
+
if (res === 0) {
|
|
9
|
+
continue;
|
|
10
|
+
} else if (res < 0) {
|
|
11
|
+
break;
|
|
12
|
+
} else {
|
|
13
|
+
throw new Error('Array not sorted');
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (j - i > 1) {
|
|
18
|
+
arr.splice(i + 1, j - i - 1);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function insertIntoSortedArray<T>(arr: T[], item: T, cmp: Cmp<T>, allowDuplicates = true): boolean {
|
|
24
|
+
let start = 0;
|
|
25
|
+
let end = arr.length;
|
|
26
|
+
|
|
27
|
+
while (start < end) {
|
|
28
|
+
const mid = start + (((end - start) / 2) | 0);
|
|
29
|
+
const comparison = cmp(arr[mid], item);
|
|
30
|
+
|
|
31
|
+
if (comparison < 0) {
|
|
32
|
+
start = mid + 1;
|
|
33
|
+
} else {
|
|
34
|
+
end = mid;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (!allowDuplicates) {
|
|
39
|
+
// Check element at insertion point
|
|
40
|
+
if (start < arr.length && cmp(arr[start], item) === 0) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Check element before insertion point (in case we landed after duplicates)
|
|
45
|
+
if (start > 0 && cmp(arr[start - 1], item) === 0) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
arr.splice(start, 0, item);
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function findIndexInSortedArray<T, N>(values: T[], needle: N, cmp: (a: T, b: N) => number): number {
|
|
55
|
+
let start = 0;
|
|
56
|
+
let end = values.length - 1;
|
|
57
|
+
|
|
58
|
+
while (start <= end) {
|
|
59
|
+
const mid = start + (((end - start) / 2) | 0);
|
|
60
|
+
const comparison = cmp(values[mid], needle);
|
|
61
|
+
|
|
62
|
+
if (comparison === 0) {
|
|
63
|
+
return mid;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (comparison > 0) {
|
|
67
|
+
end = mid - 1;
|
|
68
|
+
} else {
|
|
69
|
+
start = mid + 1;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return -1;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function findInSortedArray<T, N>(values: T[], needle: N, cmp: (a: T, b: N) => number): T | undefined {
|
|
77
|
+
const idx = findIndexInSortedArray(values, needle, cmp);
|
|
78
|
+
return idx > -1 ? values[idx] : undefined;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export function removeAnyOf<T, N>(arr: T[], vals: N[], cmp: (a: T, b: N) => -1 | 0 | 1): void {
|
|
82
|
+
let writeIdx = 0;
|
|
83
|
+
let readIdx = 0;
|
|
84
|
+
let valIdx = 0;
|
|
85
|
+
|
|
86
|
+
while (readIdx < arr.length && valIdx < vals.length) {
|
|
87
|
+
const comparison = cmp(arr[readIdx], vals[valIdx]);
|
|
88
|
+
|
|
89
|
+
if (comparison < 0) {
|
|
90
|
+
arr[writeIdx++] = arr[readIdx++];
|
|
91
|
+
} else if (comparison > 0) {
|
|
92
|
+
valIdx++;
|
|
93
|
+
} else {
|
|
94
|
+
readIdx++;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
while (readIdx < arr.length) {
|
|
99
|
+
arr[writeIdx++] = arr[readIdx++];
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
arr.length = writeIdx;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export function removeFromSortedArray<T, N>(arr: T[], val: N, cmp: (a: T, b: N) => -1 | 0 | 1) {
|
|
106
|
+
const idx = findIndexInSortedArray(arr, val, cmp);
|
|
107
|
+
if (idx > -1) {
|
|
108
|
+
arr.splice(idx, 1);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export function merge<T>(arr: T[], toInsert: T[], cmp: (a: T, b: T) => -1 | 0 | 1): void {
|
|
113
|
+
const result = new Array<T>(arr.length + toInsert.length);
|
|
114
|
+
let i = 0,
|
|
115
|
+
j = 0,
|
|
116
|
+
k = 0;
|
|
117
|
+
|
|
118
|
+
while (i < arr.length && j < toInsert.length) {
|
|
119
|
+
result[k++] = cmp(arr[i], toInsert[j]) <= 0 ? arr[i++] : toInsert[j++];
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
while (i < arr.length) {
|
|
123
|
+
result[k++] = arr[i++];
|
|
124
|
+
}
|
|
125
|
+
while (j < toInsert.length) {
|
|
126
|
+
result[k++] = toInsert[j++];
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
for (i = 0; i < result.length; i++) {
|
|
130
|
+
arr[i] = result[i];
|
|
131
|
+
}
|
|
132
|
+
arr.length = result.length;
|
|
133
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
import type { CheckpointNumber } from './checkpoint_number.js';
|
|
4
|
+
import type { Branded } from './types.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A branded type representing an Aztec (L2) block number.
|
|
8
|
+
* Block numbers are sequential identifiers for blocks in the Aztec rollup chain.
|
|
9
|
+
*
|
|
10
|
+
* This is a nominal type backed by a number, but TypeScript will treat it as
|
|
11
|
+
* incompatible with plain numbers and other branded numeric types (like EpochNumber, SlotNumber, etc.).
|
|
12
|
+
*
|
|
13
|
+
* Note: This type should ONLY be used for Aztec L2 block numbers, NOT for Ethereum L1 block numbers.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* const blockNumber = BlockNumber(100);
|
|
18
|
+
* const plainNumber: number = blockNumber; // OK - BlockNumber is assignable to number
|
|
19
|
+
* const blockFromNumber: BlockNumber = 100; // ERROR - number is not assignable to BlockNumber
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export type BlockNumber = Branded<number, 'BlockNumber'>;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Creates a BlockNumber from a number.
|
|
26
|
+
* @param value - The block number (must be a non-negative integer)
|
|
27
|
+
* @returns The branded BlockNumber value
|
|
28
|
+
* @throws If the value is negative or not an integer
|
|
29
|
+
*/
|
|
30
|
+
export function BlockNumber(value: number): BlockNumber {
|
|
31
|
+
if (!Number.isInteger(value)) {
|
|
32
|
+
throw new Error(`BlockNumber must be an integer, got ${value}`);
|
|
33
|
+
}
|
|
34
|
+
if (value < 0) {
|
|
35
|
+
throw new Error(`BlockNumber must be non-negative, got ${value}`);
|
|
36
|
+
}
|
|
37
|
+
return value as BlockNumber;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Creates a BlockNumber from a bigint.
|
|
42
|
+
* @param value - The block number as bigint (must be a non-negative integer within safe integer range)
|
|
43
|
+
* @returns The branded BlockNumber value
|
|
44
|
+
* @throws If the value is negative or exceeds Number.MAX_SAFE_INTEGER
|
|
45
|
+
*/
|
|
46
|
+
BlockNumber.fromBigInt = function (value: bigint): BlockNumber {
|
|
47
|
+
if (value < 0n) {
|
|
48
|
+
throw new Error(`BlockNumber must be non-negative, got ${value}`);
|
|
49
|
+
}
|
|
50
|
+
if (value > BigInt(Number.MAX_SAFE_INTEGER)) {
|
|
51
|
+
throw new Error(`BlockNumber ${value} exceeds MAX_SAFE_INTEGER`);
|
|
52
|
+
}
|
|
53
|
+
return Number(value) as BlockNumber;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Creates a BlockNumber from a string.
|
|
58
|
+
* @param value - The block number as a string
|
|
59
|
+
* @returns The branded BlockNumber value
|
|
60
|
+
* @throws If the string cannot be parsed as a valid block number
|
|
61
|
+
*/
|
|
62
|
+
BlockNumber.fromString = function (value: string): BlockNumber {
|
|
63
|
+
const parsed = parseInt(value, 10);
|
|
64
|
+
if (isNaN(parsed)) {
|
|
65
|
+
throw new Error(`Cannot parse BlockNumber from string: ${value}`);
|
|
66
|
+
}
|
|
67
|
+
return BlockNumber(parsed);
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Converts a CheckpointNumber to a BlockNumber.
|
|
72
|
+
* This is used in checkpoint-based systems where checkpoint numbers align with block numbers.
|
|
73
|
+
* WARNING: This should only be used when you know the checkpoint number corresponds to a block number.
|
|
74
|
+
* @param value - The checkpoint number to convert
|
|
75
|
+
* @returns The corresponding BlockNumber
|
|
76
|
+
*/
|
|
77
|
+
BlockNumber.fromCheckpointNumber = function (value: CheckpointNumber): BlockNumber {
|
|
78
|
+
return value as unknown as BlockNumber;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Type guard to check if a value is a valid BlockNumber.
|
|
83
|
+
* Note: At runtime, a BlockNumber is just a number, so this checks if the value
|
|
84
|
+
* is a non-negative integer.
|
|
85
|
+
*/
|
|
86
|
+
BlockNumber.isValid = function (value: unknown): value is BlockNumber {
|
|
87
|
+
return typeof value === 'number' && Number.isInteger(value) && value >= 0;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
/** Increments a BlockNumber by a given value. */
|
|
91
|
+
BlockNumber.add = function (bn: BlockNumber, increment: number): BlockNumber {
|
|
92
|
+
return BlockNumber(bn + increment);
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* The zero block value (genesis block).
|
|
97
|
+
*/
|
|
98
|
+
BlockNumber.ZERO = BlockNumber(0);
|
|
99
|
+
|
|
100
|
+
function makeBlockNumberSchema(minValue: number) {
|
|
101
|
+
return z
|
|
102
|
+
.union([z.number(), z.bigint(), z.string()])
|
|
103
|
+
.pipe(z.coerce.number().int().min(minValue))
|
|
104
|
+
.transform(value => BlockNumber(value));
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Zod schema for parsing and validating BlockNumber values.
|
|
109
|
+
* Accepts numbers, bigints, or strings and coerces them to BlockNumber.
|
|
110
|
+
*/
|
|
111
|
+
export const BlockNumberSchema = makeBlockNumberSchema(0);
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Zod schema for parsing and validating BlockNumber values that are strictly positive.
|
|
115
|
+
* Accepts numbers, bigints, or strings and coerces them to BlockNumber.
|
|
116
|
+
*/
|
|
117
|
+
export const BlockNumberPositiveSchema = makeBlockNumberSchema(1);
|