@aztec/merkle-tree 0.23.0 → 0.26.1

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/index.d.ts CHANGED
@@ -5,6 +5,7 @@ export * from './interfaces/update_only_tree.js';
5
5
  export * from './pedersen.js';
6
6
  export * from './sparse_tree/sparse_tree.js';
7
7
  export { StandardIndexedTree } from './standard_indexed_tree/standard_indexed_tree.js';
8
+ export { StandardIndexedTreeWithAppend } from './standard_indexed_tree/test/standard_indexed_tree_with_append.js';
8
9
  export * from './standard_tree/standard_tree.js';
9
10
  export { INITIAL_LEAF, getTreeMeta } from './tree_base.js';
10
11
  export { newTree } from './new_tree.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kCAAkC,CAAC;AACjD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,kCAAkC,CAAC;AACjD,cAAc,eAAe,CAAC;AAC9B,cAAc,8BAA8B,CAAC;AAC7C,OAAO,EAAE,mBAAmB,EAAE,MAAM,kDAAkD,CAAC;AACvF,cAAc,kCAAkC,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC3D,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,cAAc,iCAAiC,CAAC;AAChD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,qCAAqC,CAAC;AACpD,cAAc,sCAAsC,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kCAAkC,CAAC;AACjD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,kCAAkC,CAAC;AACjD,cAAc,eAAe,CAAC;AAC9B,cAAc,8BAA8B,CAAC;AAC7C,OAAO,EAAE,mBAAmB,EAAE,MAAM,kDAAkD,CAAC;AACvF,OAAO,EAAE,6BAA6B,EAAE,MAAM,mEAAmE,CAAC;AAClH,cAAc,kCAAkC,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC3D,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,cAAc,iCAAiC,CAAC;AAChD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,qCAAqC,CAAC;AACpD,cAAc,sCAAsC,CAAC"}
package/dest/index.js CHANGED
@@ -5,6 +5,7 @@ export * from './interfaces/update_only_tree.js';
5
5
  export * from './pedersen.js';
6
6
  export * from './sparse_tree/sparse_tree.js';
7
7
  export { StandardIndexedTree } from './standard_indexed_tree/standard_indexed_tree.js';
8
+ export { StandardIndexedTreeWithAppend } from './standard_indexed_tree/test/standard_indexed_tree_with_append.js';
8
9
  export * from './standard_tree/standard_tree.js';
9
10
  export { INITIAL_LEAF, getTreeMeta } from './tree_base.js';
10
11
  export { newTree } from './new_tree.js';
@@ -13,4 +14,4 @@ export * from './snapshots/snapshot_builder.js';
13
14
  export * from './snapshots/full_snapshot.js';
14
15
  export * from './snapshots/append_only_snapshot.js';
15
16
  export * from './snapshots/indexed_tree_snapshot.js';
16
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsY0FBYyxrQ0FBa0MsQ0FBQztBQUNqRCxjQUFjLDhCQUE4QixDQUFDO0FBQzdDLGNBQWMsNkJBQTZCLENBQUM7QUFDNUMsY0FBYyxrQ0FBa0MsQ0FBQztBQUNqRCxjQU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UFFLE1BQU0sZUFBZSxDQUFDO0FBQ3hDLE9BQU8sRUFBRSxRQUFRLEVBQUUsTUFBTSxnQkFBZ0IsQ0FBQztBQUMxQyxjQUFjLGlDQUFpQyxDQUFDO0FBQ2hELGNBQWMsOEJBQThCLENBQUM7QUFDN0MsY0FBYyxxQ0FBcUMsQ0FBQztBQUNwRCxjQUFjLHNDQUFzQyxDQUFDIn0=
package/dest/pedersen.js CHANGED
@@ -10,14 +10,14 @@ export class Pedersen {
10
10
  * purposes.
11
11
  */
12
12
  hash(lhs, rhs) {
13
- return pedersenHash([Buffer.from(lhs), Buffer.from(rhs)]);
13
+ return pedersenHash([Buffer.from(lhs), Buffer.from(rhs)]).toBuffer();
14
14
  }
15
15
  /*
16
16
  * @deprecated Don't call pedersen directly in production code. Instead, create suitably-named functions for specific
17
17
  * purposes.
18
18
  */
19
19
  hashInputs(inputs) {
20
- return pedersenHash(inputs);
20
+ return pedersenHash(inputs).toBuffer();
21
21
  }
22
22
  }
23
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicGVkZXJzZW4uanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvcGVkZXJzZW4udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLFlBQVksRUFBRSxNQUFNLDBCQUEwQixDQUFDO0FBR3hEOzs7O0dBSUc7QUFDSCxNQUFNLE9BQU8sUUFBUTtJQUNuQjs7O09BR0c7SUFDSSxJQUFJLENBQUMsR0FBZSxFQUFFLEdBQWU7UUFDMUMsT0FBTyxZQUFZLENBQUMsQ0FBQyxNQUFNLENBQUMsSUFBSSxDQUFDLEdBQUcsQ0FBQyxFQUFFLE1BQU0sQ0FBQyxJQUFJLENBQUMsR0FBRyxDQUFDLENBQUMsQ0FBQyxDQUFDO0lBQzVELENBQUM7SUFFRDs7O09BR0c7SUFDSSxVQUFVLENBQUMsTUFBZ0I7UUFDaEMsT0FBTyxZQUFZLENBQUMsTUFBTSxDQUFDLENBQUM7SUFDOUIsQ0FBQztDQUNGIn0=
23
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicGVkZXJzZW4uanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvcGVkZXJzZW4udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLFlBQVksRUFBRSxNQUFNLDBCQUEwQixDQUFDO0FBR3hEOzs7O0dBSUc7QUFDSCxNQUFNLE9BQU8sUUFBUTtJQUNuQjs7O09BR0c7SUFDSSxJQUFJLENBQUMsR0FBZSxFQUFFLEdBQWU7UUFDMUMsT0FBTyxZQUFZLENBQUMsQ0FBQyxNQUFNLENBQUMsSUFBSSxDQUFDLEdBQUcsQ0FBQyxFQUFFLE1BQU0sQ0FBQyxJQUFJLENBQUMsR0FBRyxDQUFDLENBQUMsQ0FBQyxDQUFDLFFBQVEsRUFBRSxDQUFDO0lBQ3ZFLENBQUM7SUFFRDs7O09BR0c7SUFDSSxVQUFVLENBQUMsTUFBZ0I7UUFDaEMsT0FBTyxZQUFZLENBQUMsTUFBTSxDQUFDLENBQUMsUUFBUSxFQUFFLENBQUM7SUFDekMsQ0FBQztDQUNGIn0=
@@ -1,5 +1,5 @@
1
1
  /// <reference types="node" resolution-mode="require"/>
2
- import { StandardIndexedTree } from '../../index.js';
2
+ import { StandardIndexedTree } from '../standard_indexed_tree.js';
3
3
  /**
4
4
  * A testing utility which is here to store the original implementation of StandardIndexedTree.appendLeaves method
5
5
  * that was replaced by the more efficient batchInsert method. We keep the original implementation around as it useful
@@ -1 +1 @@
1
- {"version":3,"file":"standard_indexed_tree_with_append.d.ts","sourceRoot":"","sources":["../../../src/standard_indexed_tree/test/standard_indexed_tree_with_append.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAErD;;;;GAIG;AACH,qBAAa,6BAA8B,SAAQ,mBAAmB;IACpE;;;;;OAKG;IACI,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAQpD,OAAO,CAAC,eAAe;IAQvB;;;;OAIG;IACH,OAAO,CAAC,UAAU;CA6CnB"}
1
+ {"version":3,"file":"standard_indexed_tree_with_append.d.ts","sourceRoot":"","sources":["../../../src/standard_indexed_tree/test/standard_indexed_tree_with_append.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAElE;;;;GAIG;AACH,qBAAa,6BAA8B,SAAQ,mBAAmB;IACpE;;;;;OAKG;IACI,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAQpD,OAAO,CAAC,eAAe;IAQvB;;;;OAIG;IACH,OAAO,CAAC,UAAU;CA6CnB"}
@@ -1,4 +1,4 @@
1
- import { StandardIndexedTree } from '../../index.js';
1
+ import { StandardIndexedTree } from '../standard_indexed_tree.js';
2
2
  /**
3
3
  * A testing utility which is here to store the original implementation of StandardIndexedTree.appendLeaves method
4
4
  * that was replaced by the more efficient batchInsert method. We keep the original implementation around as it useful
@@ -58,4 +58,4 @@ export class StandardIndexedTreeWithAppend extends StandardIndexedTree {
58
58
  }
59
59
  }
60
60
  }
61
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic3RhbmRhcmRfaW5kZXhlZF90cmVlX3dpdGhfYXBwZW5kLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL3N0YW5kYXJkX2luZGV4ZWRfdHJlZS90ZXN0L3N0YW5kYXJkX2luZGV4ZWRfdHJlZV93aXRoX2FwcGVuZC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUUsbUJBQW1CLEVBQUUsTUFBTSxnQkF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6 @@
1
1
  {
2
2
  "name": "@aztec/merkle-tree",
3
- "version": "0.23.0",
3
+ "version": "0.26.1",
4
4
  "type": "module",
5
5
  "exports": "./dest/index.js",
6
6
  "typedocOptions": {
@@ -32,10 +32,10 @@
32
32
  "testTimeout": 15000
33
33
  },
34
34
  "dependencies": {
35
- "@aztec/circuit-types": "0.23.0",
36
- "@aztec/foundation": "0.23.0",
37
- "@aztec/kv-store": "0.23.0",
38
- "@aztec/types": "0.23.0",
35
+ "@aztec/circuit-types": "0.26.1",
36
+ "@aztec/foundation": "0.26.1",
37
+ "@aztec/kv-store": "0.26.1",
38
+ "@aztec/types": "0.26.1",
39
39
  "sha256": "^0.2.0",
40
40
  "tslib": "^2.4.0"
41
41
  },
@@ -0,0 +1,51 @@
1
+ import { Hasher } from '@aztec/types/interfaces';
2
+
3
+ import { createHistogram, performance } from 'perf_hooks';
4
+
5
+ /**
6
+ * A helper class to track stats for a Hasher
7
+ */
8
+ export class HasherWithStats implements Hasher {
9
+ hashCount = 0;
10
+ hashInputsCount = 0;
11
+ hashHistogram = createHistogram();
12
+ hashInputsHistogram = createHistogram();
13
+
14
+ hash: Hasher['hash'];
15
+ hashInputs: Hasher['hashInputs'];
16
+
17
+ constructor(hasher: Hasher) {
18
+ this.hash = performance.timerify(
19
+ (lhs, rhs) => {
20
+ this.hashCount++;
21
+ return hasher.hash(lhs, rhs);
22
+ },
23
+ { histogram: this.hashHistogram },
24
+ );
25
+ this.hashInputs = performance.timerify(
26
+ (inputs: Buffer[]) => {
27
+ this.hashInputsCount++;
28
+ return hasher.hashInputs(inputs);
29
+ },
30
+ { histogram: this.hashInputsHistogram },
31
+ );
32
+ }
33
+
34
+ stats() {
35
+ return {
36
+ hashCount: this.hashCount,
37
+ // timerify records in ns, convert to ms
38
+ hashDuration: this.hashHistogram.mean / 1e6,
39
+ hashInputsCount: this.hashInputsCount,
40
+ hashInputsDuration: this.hashInputsHistogram.mean / 1e6,
41
+ };
42
+ }
43
+
44
+ reset() {
45
+ this.hashCount = 0;
46
+ this.hashHistogram.reset();
47
+
48
+ this.hashInputsCount = 0;
49
+ this.hashInputsHistogram.reset();
50
+ }
51
+ }
package/src/index.ts ADDED
@@ -0,0 +1,16 @@
1
+ export * from './interfaces/append_only_tree.js';
2
+ export * from './interfaces/indexed_tree.js';
3
+ export * from './interfaces/merkle_tree.js';
4
+ export * from './interfaces/update_only_tree.js';
5
+ export * from './pedersen.js';
6
+ export * from './sparse_tree/sparse_tree.js';
7
+ export { StandardIndexedTree } from './standard_indexed_tree/standard_indexed_tree.js';
8
+ export { StandardIndexedTreeWithAppend } from './standard_indexed_tree/test/standard_indexed_tree_with_append.js';
9
+ export * from './standard_tree/standard_tree.js';
10
+ export { INITIAL_LEAF, getTreeMeta } from './tree_base.js';
11
+ export { newTree } from './new_tree.js';
12
+ export { loadTree } from './load_tree.js';
13
+ export * from './snapshots/snapshot_builder.js';
14
+ export * from './snapshots/full_snapshot.js';
15
+ export * from './snapshots/append_only_snapshot.js';
16
+ export * from './snapshots/indexed_tree_snapshot.js';
@@ -0,0 +1,13 @@
1
+ import { TreeSnapshotBuilder } from '../snapshots/snapshot_builder.js';
2
+ import { MerkleTree } from './merkle_tree.js';
3
+
4
+ /**
5
+ * A Merkle tree that supports only appending leaves and not updating existing leaves.
6
+ */
7
+ export interface AppendOnlyTree extends MerkleTree, TreeSnapshotBuilder {
8
+ /**
9
+ * Appends a set of leaf values to the tree.
10
+ * @param leaves - The set of leaves to be appended.
11
+ */
12
+ appendLeaves(leaves: Buffer[]): Promise<void>;
13
+ }
@@ -0,0 +1,118 @@
1
+ import { SiblingPath } from '@aztec/circuit-types';
2
+ import { IndexedTreeLeaf, IndexedTreeLeafPreimage } from '@aztec/foundation/trees';
3
+
4
+ import { AppendOnlyTree } from './append_only_tree.js';
5
+
6
+ /**
7
+ * Factory for creating leaf preimages.
8
+ */
9
+ export interface PreimageFactory {
10
+ /**
11
+ * Creates a new preimage from a leaf.
12
+ * @param leaf - Leaf to create a preimage from.
13
+ * @param nextKey - Next key of the leaf.
14
+ * @param nextIndex - Next index of the leaf.
15
+ */
16
+ fromLeaf(leaf: IndexedTreeLeaf, nextKey: bigint, nextIndex: bigint): IndexedTreeLeafPreimage;
17
+ /**
18
+ * Creates a new preimage from a buffer.
19
+ * @param buffer - Buffer to create a preimage from.
20
+ */
21
+ fromBuffer(buffer: Buffer): IndexedTreeLeafPreimage;
22
+ /**
23
+ * Creates an empty preimage.
24
+ */
25
+ empty(): IndexedTreeLeafPreimage;
26
+ /**
27
+ * Creates a copy of a preimage.
28
+ * @param preimage - Preimage to be cloned.
29
+ */
30
+ clone(preimage: IndexedTreeLeafPreimage): IndexedTreeLeafPreimage;
31
+ }
32
+
33
+ /**
34
+ * All of the data to be return during batch insertion.
35
+ */
36
+ export interface LowLeafWitnessData<N extends number> {
37
+ /**
38
+ * Preimage of the low nullifier that proves non membership.
39
+ */
40
+ leafPreimage: IndexedTreeLeafPreimage;
41
+ /**
42
+ * Sibling path to prove membership of low nullifier.
43
+ */
44
+ siblingPath: SiblingPath<N>;
45
+ /**
46
+ * The index of low nullifier.
47
+ */
48
+ index: bigint;
49
+ }
50
+
51
+ /**
52
+ * The result of a batch insertion in an indexed merkle tree.
53
+ */
54
+ export interface BatchInsertionResult<TreeHeight extends number, SubtreeSiblingPathHeight extends number> {
55
+ /**
56
+ * Data for the leaves to be updated when inserting the new ones.
57
+ */
58
+ lowLeavesWitnessData?: LowLeafWitnessData<TreeHeight>[];
59
+ /**
60
+ * Sibling path "pointing to" where the new subtree should be inserted into the tree.
61
+ */
62
+ newSubtreeSiblingPath: SiblingPath<SubtreeSiblingPathHeight>;
63
+ /**
64
+ * The new leaves being inserted in high to low order. This order corresponds with the order of the low leaves witness.
65
+ */
66
+ sortedNewLeaves: Buffer[];
67
+ /**
68
+ * The indexes of the sorted new leaves to the original ones.
69
+ */
70
+ sortedNewLeavesIndexes: number[];
71
+ }
72
+
73
+ /**
74
+ * Indexed merkle tree.
75
+ */
76
+ export interface IndexedTree extends AppendOnlyTree {
77
+ /**
78
+ * Finds the index of the largest leaf whose value is less than or equal to the provided value.
79
+ * @param newValue - The new value to be inserted into the tree.
80
+ * @param includeUncommitted - If true, the uncommitted changes are included in the search.
81
+ * @returns The found leaf index and a flag indicating if the corresponding leaf's value is equal to `newValue`.
82
+ */
83
+ findIndexOfPreviousKey(
84
+ newValue: bigint,
85
+ includeUncommitted: boolean,
86
+ ):
87
+ | {
88
+ /**
89
+ * The index of the found leaf.
90
+ */
91
+ index: bigint;
92
+ /**
93
+ * A flag indicating if the corresponding leaf's value is equal to `newValue`.
94
+ */
95
+ alreadyPresent: boolean;
96
+ }
97
+ | undefined;
98
+
99
+ /**
100
+ * Gets the latest LeafPreimage copy.
101
+ * @param index - Index of the leaf of which to obtain the LeafPreimage copy.
102
+ * @param includeUncommitted - If true, the uncommitted changes are included in the search.
103
+ * @returns A copy of the leaf preimage at the given index or undefined if the leaf was not found.
104
+ */
105
+ getLatestLeafPreimageCopy(index: bigint, includeUncommitted: boolean): IndexedTreeLeafPreimage | undefined;
106
+
107
+ /**
108
+ * Batch insert multiple leaves into the tree.
109
+ * @param leaves - Leaves to insert into the tree.
110
+ * @param subtreeHeight - Height of the subtree.
111
+ * @param includeUncommitted - If true, the uncommitted changes are included in the search.
112
+ */
113
+ batchInsert<TreeHeight extends number, SubtreeHeight extends number, SubtreeSiblingPathHeight extends number>(
114
+ leaves: Buffer[],
115
+ subtreeHeight: SubtreeHeight,
116
+ includeUncommitted: boolean,
117
+ ): Promise<BatchInsertionResult<TreeHeight, SubtreeSiblingPathHeight>>;
118
+ }
@@ -0,0 +1,60 @@
1
+ import { SiblingPath } from '@aztec/circuit-types';
2
+
3
+ /**
4
+ * Defines the interface for a source of sibling paths.
5
+ */
6
+ export interface SiblingPathSource {
7
+ /**
8
+ * Returns the sibling path for a requested leaf index.
9
+ * @param index - The index of the leaf for which a sibling path is required.
10
+ * @param includeUncommitted - Set to true to include uncommitted updates in the sibling path.
11
+ */
12
+ getSiblingPath<N extends number>(index: bigint, includeUncommitted: boolean): Promise<SiblingPath<N>>;
13
+ }
14
+
15
+ /**
16
+ * Defines the interface for a Merkle tree.
17
+ */
18
+ export interface MerkleTree extends SiblingPathSource {
19
+ /**
20
+ * Returns the current root of the tree.
21
+ * @param includeUncommitted - Set to true to include uncommitted updates in the calculated root.
22
+ */
23
+ getRoot(includeUncommitted: boolean): Buffer;
24
+
25
+ /**
26
+ * Returns the number of leaves in the tree.
27
+ * @param includeUncommitted - Set to true to include uncommitted updates in the returned value.
28
+ */
29
+ getNumLeaves(includeUncommitted: boolean): bigint;
30
+
31
+ /**
32
+ * Commit pending updates to the tree.
33
+ */
34
+ commit(): Promise<void>;
35
+
36
+ /**
37
+ * Returns the depth of the tree.
38
+ */
39
+ getDepth(): number;
40
+
41
+ /**
42
+ * Rollback pending update to the tree.
43
+ */
44
+ rollback(): Promise<void>;
45
+
46
+ /**
47
+ * Returns the value of a leaf at the specified index.
48
+ * @param index - The index of the leaf value to be returned.
49
+ * @param includeUncommitted - Set to true to include uncommitted updates in the data set.
50
+ */
51
+ getLeafValue(index: bigint, includeUncommitted: boolean): Buffer | undefined;
52
+
53
+ /**
54
+ * Returns the index of a leaf given its value, or undefined if no leaf with that value is found.
55
+ * @param leaf - The leaf value to look for.
56
+ * @param includeUncommitted - Indicates whether to include uncommitted data.
57
+ * @returns The index of the first leaf found with a given value (undefined if not found).
58
+ */
59
+ findLeafIndex(leaf: Buffer, includeUncommitted: boolean): bigint | undefined;
60
+ }
@@ -0,0 +1,14 @@
1
+ import { TreeSnapshotBuilder } from '../snapshots/snapshot_builder.js';
2
+ import { MerkleTree } from './merkle_tree.js';
3
+
4
+ /**
5
+ * A Merkle tree that supports updates at arbitrary indices but not appending.
6
+ */
7
+ export interface UpdateOnlyTree extends MerkleTree, TreeSnapshotBuilder {
8
+ /**
9
+ * Updates a leaf at a given index in the tree.
10
+ * @param leaf - The leaf value to be updated.
11
+ * @param index - The leaf to be updated.
12
+ */
13
+ updateLeaf(leaf: Buffer, index: bigint): Promise<void>;
14
+ }
@@ -0,0 +1,23 @@
1
+ import { AztecKVStore } from '@aztec/kv-store';
2
+ import { Hasher } from '@aztec/types/interfaces';
3
+
4
+ import { TreeBase, getTreeMeta } from './tree_base.js';
5
+
6
+ /**
7
+ * Creates a new tree and sets its root, depth and size based on the meta data which are associated with the name.
8
+ * @param c - The class of the tree to be instantiated.
9
+ * @param db - A database used to store the Merkle tree data.
10
+ * @param hasher - A hasher used to compute hash paths.
11
+ * @param name - Name of the tree.
12
+ * @returns The newly created tree.
13
+ */
14
+ export function loadTree<T extends TreeBase>(
15
+ c: new (store: AztecKVStore, hasher: Hasher, name: string, depth: number, size: bigint, root: Buffer) => T,
16
+ store: AztecKVStore,
17
+ hasher: Hasher,
18
+ name: string,
19
+ ): Promise<T> {
20
+ const { root, depth, size } = getTreeMeta(store, name);
21
+ const tree = new c(store, hasher, name, depth, size, root);
22
+ return Promise.resolve(tree);
23
+ }
@@ -0,0 +1,27 @@
1
+ import { AztecKVStore } from '@aztec/kv-store';
2
+ import { Hasher } from '@aztec/types/interfaces';
3
+
4
+ import { TreeBase } from './tree_base.js';
5
+
6
+ /**
7
+ * Creates a new tree.
8
+ * @param c - The class of the tree to be instantiated.
9
+ * @param db - A database used to store the Merkle tree data.
10
+ * @param hasher - A hasher used to compute hash paths.
11
+ * @param name - Name of the tree.
12
+ * @param depth - Depth of the tree.
13
+ * @param prefilledSize - A number of leaves that are prefilled with values.
14
+ * @returns The newly created tree.
15
+ */
16
+ export async function newTree<T extends TreeBase>(
17
+ c: new (store: AztecKVStore, hasher: Hasher, name: string, depth: number, size: bigint) => T,
18
+ store: AztecKVStore,
19
+ hasher: Hasher,
20
+ name: string,
21
+ depth: number,
22
+ prefilledSize = 1,
23
+ ): Promise<T> {
24
+ const tree = new c(store, hasher, name, depth, 0n);
25
+ await tree.init(prefilledSize);
26
+ return tree;
27
+ }
@@ -0,0 +1,25 @@
1
+ import { pedersenHash } from '@aztec/foundation/crypto';
2
+ import { Hasher } from '@aztec/types/interfaces';
3
+
4
+ /**
5
+ * A helper class encapsulating Pedersen hash functionality.
6
+ * @deprecated Don't call pedersen directly in production code. Instead, create suitably-named functions for specific
7
+ * purposes.
8
+ */
9
+ export class Pedersen implements Hasher {
10
+ /*
11
+ * @deprecated Don't call pedersen directly in production code. Instead, create suitably-named functions for specific
12
+ * purposes.
13
+ */
14
+ public hash(lhs: Uint8Array, rhs: Uint8Array): Buffer {
15
+ return pedersenHash([Buffer.from(lhs), Buffer.from(rhs)]).toBuffer();
16
+ }
17
+
18
+ /*
19
+ * @deprecated Don't call pedersen directly in production code. Instead, create suitably-named functions for specific
20
+ * purposes.
21
+ */
22
+ public hashInputs(inputs: Buffer[]): Buffer {
23
+ return pedersenHash(inputs).toBuffer();
24
+ }
25
+ }