@aztec/merkle-tree 0.0.0-test.0
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/README.md +41 -0
- package/dest/hasher_with_stats.d.ts +22 -0
- package/dest/hasher_with_stats.d.ts.map +1 -0
- package/dest/hasher_with_stats.js +40 -0
- package/dest/index.d.ts +20 -0
- package/dest/index.d.ts.map +1 -0
- package/dest/index.js +19 -0
- package/dest/interfaces/append_only_tree.d.ts +16 -0
- package/dest/interfaces/append_only_tree.d.ts.map +1 -0
- package/dest/interfaces/append_only_tree.js +3 -0
- package/dest/interfaces/indexed_tree.d.ts +69 -0
- package/dest/interfaces/indexed_tree.d.ts.map +1 -0
- package/dest/interfaces/indexed_tree.js +3 -0
- package/dest/interfaces/merkle_tree.d.ts +64 -0
- package/dest/interfaces/merkle_tree.d.ts.map +1 -0
- package/dest/interfaces/merkle_tree.js +3 -0
- package/dest/interfaces/update_only_tree.d.ts +17 -0
- package/dest/interfaces/update_only_tree.d.ts.map +1 -0
- package/dest/interfaces/update_only_tree.js +3 -0
- package/dest/load_tree.d.ts +16 -0
- package/dest/load_tree.d.ts.map +1 -0
- package/dest/load_tree.js +13 -0
- package/dest/new_tree.d.ts +16 -0
- package/dest/new_tree.d.ts.map +1 -0
- package/dest/new_tree.js +14 -0
- package/dest/pedersen.d.ts +13 -0
- package/dest/pedersen.d.ts.map +1 -0
- package/dest/pedersen.js +24 -0
- package/dest/poseidon.d.ts +13 -0
- package/dest/poseidon.d.ts.map +1 -0
- package/dest/poseidon.js +24 -0
- package/dest/sha_256.d.ts +22 -0
- package/dest/sha_256.d.ts.map +1 -0
- package/dest/sha_256.js +44 -0
- package/dest/snapshots/append_only_snapshot.d.ts +32 -0
- package/dest/snapshots/append_only_snapshot.d.ts.map +1 -0
- package/dest/snapshots/append_only_snapshot.js +216 -0
- package/dest/snapshots/base_full_snapshot.d.ts +66 -0
- package/dest/snapshots/base_full_snapshot.d.ts.map +1 -0
- package/dest/snapshots/base_full_snapshot.js +201 -0
- package/dest/snapshots/full_snapshot.d.ts +27 -0
- package/dest/snapshots/full_snapshot.d.ts.map +1 -0
- package/dest/snapshots/full_snapshot.js +23 -0
- package/dest/snapshots/indexed_tree_snapshot.d.ts +16 -0
- package/dest/snapshots/indexed_tree_snapshot.d.ts.map +1 -0
- package/dest/snapshots/indexed_tree_snapshot.js +79 -0
- package/dest/snapshots/snapshot_builder.d.ts +84 -0
- package/dest/snapshots/snapshot_builder.d.ts.map +1 -0
- package/dest/snapshots/snapshot_builder.js +1 -0
- package/dest/snapshots/snapshot_builder_test_suite.d.ts +6 -0
- package/dest/snapshots/snapshot_builder_test_suite.d.ts.map +1 -0
- package/dest/snapshots/snapshot_builder_test_suite.js +167 -0
- package/dest/sparse_tree/sparse_tree.d.ts +21 -0
- package/dest/sparse_tree/sparse_tree.d.ts.map +1 -0
- package/dest/sparse_tree/sparse_tree.js +44 -0
- package/dest/standard_indexed_tree/standard_indexed_tree.d.ts +291 -0
- package/dest/standard_indexed_tree/standard_indexed_tree.d.ts.map +1 -0
- package/dest/standard_indexed_tree/standard_indexed_tree.js +478 -0
- package/dest/standard_indexed_tree/test/standard_indexed_tree_with_append.d.ts +25 -0
- package/dest/standard_indexed_tree/test/standard_indexed_tree_with_append.d.ts.map +1 -0
- package/dest/standard_indexed_tree/test/standard_indexed_tree_with_append.js +56 -0
- package/dest/standard_tree/standard_tree.d.ts +23 -0
- package/dest/standard_tree/standard_tree.d.ts.map +1 -0
- package/dest/standard_tree/standard_tree.js +47 -0
- package/dest/tree_base.d.ts +158 -0
- package/dest/tree_base.d.ts.map +1 -0
- package/dest/tree_base.js +290 -0
- package/dest/unbalanced_tree.d.ts +109 -0
- package/dest/unbalanced_tree.d.ts.map +1 -0
- package/dest/unbalanced_tree.js +208 -0
- package/package.json +85 -0
- package/src/hasher_with_stats.ts +51 -0
- package/src/index.ts +19 -0
- package/src/interfaces/append_only_tree.ts +17 -0
- package/src/interfaces/indexed_tree.ts +83 -0
- package/src/interfaces/merkle_tree.ts +70 -0
- package/src/interfaces/update_only_tree.ts +18 -0
- package/src/load_tree.ts +33 -0
- package/src/new_tree.ts +29 -0
- package/src/pedersen.ts +27 -0
- package/src/poseidon.ts +27 -0
- package/src/sha_256.ts +49 -0
- package/src/snapshots/append_only_snapshot.ts +278 -0
- package/src/snapshots/base_full_snapshot.ts +222 -0
- package/src/snapshots/full_snapshot.ts +33 -0
- package/src/snapshots/indexed_tree_snapshot.ts +108 -0
- package/src/snapshots/snapshot_builder.ts +92 -0
- package/src/snapshots/snapshot_builder_test_suite.ts +226 -0
- package/src/sparse_tree/sparse_tree.ts +56 -0
- package/src/standard_indexed_tree/standard_indexed_tree.ts +640 -0
- package/src/standard_indexed_tree/test/standard_indexed_tree_with_append.ts +81 -0
- package/src/standard_tree/standard_tree.ts +60 -0
- package/src/tree_base.ts +359 -0
- package/src/unbalanced_tree.ts +239 -0
package/README.md
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# Merkle Tree
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
The Merkle Trees package contains typescript implementations of the various Merkle Trees required by the system.
|
|
6
|
+
|
|
7
|
+
- Append only 'Standard' merkle trees. New values are inserted into the next available leaf index. Values are never updated.
|
|
8
|
+
- Indexed trees are also append only in nature but retain the ability to update leaves. The reason for this is that the Indexed Tree leaves not only store the value but the index of the next highest leaf. New insertions can require prior leaves to be updated.
|
|
9
|
+
- Sparse trees that can be updated at any index. The 'size' of the tree is defined by the number of non-empty leaves, not by the highest populated leaf index as is the case with a Standard Tree.
|
|
10
|
+
|
|
11
|
+
## Implementations
|
|
12
|
+
|
|
13
|
+
All implementations require the following arguments:
|
|
14
|
+
|
|
15
|
+
- An instance of level db for storing information at a tree node level as well as some tree level metadata.
|
|
16
|
+
- An instance of a Hasher object. Used for hashing the nodes of the Merkle Tree.
|
|
17
|
+
- A name, for namespacing the tree's nodes within the db.
|
|
18
|
+
- The depth of the tree, this is exclusive of the root.
|
|
19
|
+
|
|
20
|
+
Implementations have commit/rollback semantics with modifications stored only in memory until being committed. Rolling back returns the tree discards the cached modifications and returns the tree to it's previous committed state.
|
|
21
|
+
|
|
22
|
+
## Tree Operations
|
|
23
|
+
|
|
24
|
+
The primary operations available on the various implementations are:
|
|
25
|
+
|
|
26
|
+
- Create a new, empty tree
|
|
27
|
+
- Restore a tree from the provided DB
|
|
28
|
+
- Append new leaves (Standard and Indexed trees only)
|
|
29
|
+
- Update a leaf (Sparse tree and Indexed trees only)
|
|
30
|
+
- Retrieve the number of leaves. This is the number of non empty leaves for a Sparse tree and the highest populated index for Standard and Indexed trees.
|
|
31
|
+
- Commit modifications
|
|
32
|
+
- Rollback modifications
|
|
33
|
+
- Retrieve a Sibling Path for a given index. For performing Merkle proofs it is necessary to derive the set of nodes from a leaf index to the root of the tree, known as the 'hash path'. Given a leaf, it is therefore required to have the 'sibling' node at each tree level in order for the hash path to be computed.
|
|
34
|
+
|
|
35
|
+
Note: Tree operations are not 'thread' safe. Operations should be queued or otherwise executed serially to ensure consistency of the data structures and any data retrieved from them.
|
|
36
|
+
|
|
37
|
+
## Building/Testing
|
|
38
|
+
|
|
39
|
+
To build the package, execute `yarn build` in the root.
|
|
40
|
+
|
|
41
|
+
To run the tests, execute `yarn test`.
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
import type { Hasher } from '@aztec/foundation/trees';
|
|
3
|
+
/**
|
|
4
|
+
* A helper class to track stats for a Hasher
|
|
5
|
+
*/
|
|
6
|
+
export declare class HasherWithStats implements Hasher {
|
|
7
|
+
hashCount: number;
|
|
8
|
+
hashInputsCount: number;
|
|
9
|
+
hashHistogram: import("perf_hooks").RecordableHistogram;
|
|
10
|
+
hashInputsHistogram: import("perf_hooks").RecordableHistogram;
|
|
11
|
+
hash: Hasher['hash'];
|
|
12
|
+
hashInputs: Hasher['hashInputs'];
|
|
13
|
+
constructor(hasher: Hasher);
|
|
14
|
+
stats(): {
|
|
15
|
+
hashCount: number;
|
|
16
|
+
hashDuration: number;
|
|
17
|
+
hashInputsCount: number;
|
|
18
|
+
hashInputsDuration: number;
|
|
19
|
+
};
|
|
20
|
+
reset(): void;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=hasher_with_stats.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hasher_with_stats.d.ts","sourceRoot":"","sources":["../src/hasher_with_stats.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAItD;;GAEG;AACH,qBAAa,eAAgB,YAAW,MAAM;IAC5C,SAAS,SAAK;IACd,eAAe,SAAK;IACpB,aAAa,2CAAqB;IAClC,mBAAmB,2CAAqB;IAExC,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC,YAAY,CAAC,CAAC;gBAErB,MAAM,EAAE,MAAM;IAiB1B,KAAK;;;;;;IAUL,KAAK;CAON"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { createHistogram, performance } from 'perf_hooks';
|
|
2
|
+
/**
|
|
3
|
+
* A helper class to track stats for a Hasher
|
|
4
|
+
*/ export class HasherWithStats {
|
|
5
|
+
hashCount = 0;
|
|
6
|
+
hashInputsCount = 0;
|
|
7
|
+
hashHistogram = createHistogram();
|
|
8
|
+
hashInputsHistogram = createHistogram();
|
|
9
|
+
hash;
|
|
10
|
+
hashInputs;
|
|
11
|
+
constructor(hasher){
|
|
12
|
+
this.hash = performance.timerify((lhs, rhs)=>{
|
|
13
|
+
this.hashCount++;
|
|
14
|
+
return hasher.hash(lhs, rhs);
|
|
15
|
+
}, {
|
|
16
|
+
histogram: this.hashHistogram
|
|
17
|
+
});
|
|
18
|
+
this.hashInputs = performance.timerify((inputs)=>{
|
|
19
|
+
this.hashInputsCount++;
|
|
20
|
+
return hasher.hashInputs(inputs);
|
|
21
|
+
}, {
|
|
22
|
+
histogram: this.hashInputsHistogram
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
stats() {
|
|
26
|
+
return {
|
|
27
|
+
hashCount: this.hashCount,
|
|
28
|
+
// timerify records in ns, convert to ms
|
|
29
|
+
hashDuration: this.hashHistogram.mean / 1e6,
|
|
30
|
+
hashInputsCount: this.hashInputsCount,
|
|
31
|
+
hashInputsDuration: this.hashInputsHistogram.mean / 1e6
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
reset() {
|
|
35
|
+
this.hashCount = 0;
|
|
36
|
+
this.hashHistogram.reset();
|
|
37
|
+
this.hashInputsCount = 0;
|
|
38
|
+
this.hashInputsHistogram.reset();
|
|
39
|
+
}
|
|
40
|
+
}
|
package/dest/index.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
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 './poseidon.js';
|
|
7
|
+
export * from './sha_256.js';
|
|
8
|
+
export * from './sparse_tree/sparse_tree.js';
|
|
9
|
+
export { StandardIndexedTree } from './standard_indexed_tree/standard_indexed_tree.js';
|
|
10
|
+
export { StandardIndexedTreeWithAppend } from './standard_indexed_tree/test/standard_indexed_tree_with_append.js';
|
|
11
|
+
export * from './standard_tree/standard_tree.js';
|
|
12
|
+
export * from './unbalanced_tree.js';
|
|
13
|
+
export { INITIAL_LEAF, getTreeMeta } from './tree_base.js';
|
|
14
|
+
export { newTree } from './new_tree.js';
|
|
15
|
+
export { loadTree } from './load_tree.js';
|
|
16
|
+
export * from './snapshots/snapshot_builder.js';
|
|
17
|
+
export * from './snapshots/full_snapshot.js';
|
|
18
|
+
export * from './snapshots/append_only_snapshot.js';
|
|
19
|
+
export * from './snapshots/indexed_tree_snapshot.js';
|
|
20
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +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,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,8BAA8B,CAAC;AAC7C,OAAO,EAAE,mBAAmB,EAAE,MAAM,kDAAkD,CAAC;AACvF,OAAO,EAAE,6BAA6B,EAAE,MAAM,mEAAmE,CAAC;AAClH,cAAc,kCAAkC,CAAC;AACjD,cAAc,sBAAsB,CAAC;AACrC,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
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
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 './poseidon.js';
|
|
7
|
+
export * from './sha_256.js';
|
|
8
|
+
export * from './sparse_tree/sparse_tree.js';
|
|
9
|
+
export { StandardIndexedTree } from './standard_indexed_tree/standard_indexed_tree.js';
|
|
10
|
+
export { StandardIndexedTreeWithAppend } from './standard_indexed_tree/test/standard_indexed_tree_with_append.js';
|
|
11
|
+
export * from './standard_tree/standard_tree.js';
|
|
12
|
+
export * from './unbalanced_tree.js';
|
|
13
|
+
export { INITIAL_LEAF, getTreeMeta } from './tree_base.js';
|
|
14
|
+
export { newTree } from './new_tree.js';
|
|
15
|
+
export { loadTree } from './load_tree.js';
|
|
16
|
+
export * from './snapshots/snapshot_builder.js';
|
|
17
|
+
export * from './snapshots/full_snapshot.js';
|
|
18
|
+
export * from './snapshots/append_only_snapshot.js';
|
|
19
|
+
export * from './snapshots/indexed_tree_snapshot.js';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
3
|
+
import type { Bufferable } from '@aztec/foundation/serialize';
|
|
4
|
+
import type { TreeSnapshot, TreeSnapshotBuilder } from '../snapshots/snapshot_builder.js';
|
|
5
|
+
import type { MerkleTree } from './merkle_tree.js';
|
|
6
|
+
/**
|
|
7
|
+
* A Merkle tree that supports only appending leaves and not updating existing leaves.
|
|
8
|
+
*/
|
|
9
|
+
export interface AppendOnlyTree<T extends Bufferable = Buffer> extends MerkleTree<T>, TreeSnapshotBuilder<TreeSnapshot<T>> {
|
|
10
|
+
/**
|
|
11
|
+
* Appends a set of leaf values to the tree.
|
|
12
|
+
* @param leaves - The set of leaves to be appended.
|
|
13
|
+
*/
|
|
14
|
+
appendLeaves(leaves: T[]): Promise<void>;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=append_only_tree.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"append_only_tree.d.ts","sourceRoot":"","sources":["../../src/interfaces/append_only_tree.ts"],"names":[],"mappings":";;AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAE9D,OAAO,KAAK,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAC1F,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD;;GAEG;AACH,MAAM,WAAW,cAAc,CAAC,CAAC,SAAS,UAAU,GAAG,MAAM,CAC3D,SAAQ,UAAU,CAAC,CAAC,CAAC,EACnB,mBAAmB,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;IACtC;;;OAGG;IACH,YAAY,CAAC,MAAM,EAAE,CAAC,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1C"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
3
|
+
import type { IndexedTreeLeaf, IndexedTreeLeafPreimage } from '@aztec/foundation/trees';
|
|
4
|
+
import type { BatchInsertionResult } from '@aztec/stdlib/trees';
|
|
5
|
+
import type { IndexedTreeSnapshot, TreeSnapshot, TreeSnapshotBuilder } from '../snapshots/snapshot_builder.js';
|
|
6
|
+
import type { AppendOnlyTree } from './append_only_tree.js';
|
|
7
|
+
import type { MerkleTree } from './merkle_tree.js';
|
|
8
|
+
/**
|
|
9
|
+
* Factory for creating leaf preimages.
|
|
10
|
+
*/
|
|
11
|
+
export interface PreimageFactory {
|
|
12
|
+
/**
|
|
13
|
+
* Creates a new preimage from a leaf.
|
|
14
|
+
* @param leaf - Leaf to create a preimage from.
|
|
15
|
+
* @param nextKey - Next key of the leaf.
|
|
16
|
+
* @param nextIndex - Next index of the leaf.
|
|
17
|
+
*/
|
|
18
|
+
fromLeaf(leaf: IndexedTreeLeaf, nextKey: bigint, nextIndex: bigint): IndexedTreeLeafPreimage;
|
|
19
|
+
/**
|
|
20
|
+
* Creates a new preimage from a buffer.
|
|
21
|
+
* @param buffer - Buffer to create a preimage from.
|
|
22
|
+
*/
|
|
23
|
+
fromBuffer(buffer: Buffer): IndexedTreeLeafPreimage;
|
|
24
|
+
/**
|
|
25
|
+
* Creates an empty preimage.
|
|
26
|
+
*/
|
|
27
|
+
empty(): IndexedTreeLeafPreimage;
|
|
28
|
+
/**
|
|
29
|
+
* Creates a copy of a preimage.
|
|
30
|
+
* @param preimage - Preimage to be cloned.
|
|
31
|
+
*/
|
|
32
|
+
clone(preimage: IndexedTreeLeafPreimage): IndexedTreeLeafPreimage;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Indexed merkle tree.
|
|
36
|
+
*/
|
|
37
|
+
export interface IndexedTree extends MerkleTree<Buffer>, TreeSnapshotBuilder<IndexedTreeSnapshot>, Omit<AppendOnlyTree<Buffer>, keyof TreeSnapshotBuilder<TreeSnapshot<Buffer>>> {
|
|
38
|
+
/**
|
|
39
|
+
* Finds the index of the largest leaf whose value is less than or equal to the provided value.
|
|
40
|
+
* @param newValue - The new value to be inserted into the tree.
|
|
41
|
+
* @param includeUncommitted - If true, the uncommitted changes are included in the search.
|
|
42
|
+
* @returns The found leaf index and a flag indicating if the corresponding leaf's value is equal to `newValue`.
|
|
43
|
+
*/
|
|
44
|
+
findIndexOfPreviousKey(newValue: bigint, includeUncommitted: boolean): {
|
|
45
|
+
/**
|
|
46
|
+
* The index of the found leaf.
|
|
47
|
+
*/
|
|
48
|
+
index: bigint;
|
|
49
|
+
/**
|
|
50
|
+
* A flag indicating if the corresponding leaf's value is equal to `newValue`.
|
|
51
|
+
*/
|
|
52
|
+
alreadyPresent: boolean;
|
|
53
|
+
} | undefined;
|
|
54
|
+
/**
|
|
55
|
+
* Gets the latest LeafPreimage copy.
|
|
56
|
+
* @param index - Index of the leaf of which to obtain the LeafPreimage copy.
|
|
57
|
+
* @param includeUncommitted - If true, the uncommitted changes are included in the search.
|
|
58
|
+
* @returns A copy of the leaf preimage at the given index or undefined if the leaf was not found.
|
|
59
|
+
*/
|
|
60
|
+
getLatestLeafPreimageCopy(index: bigint, includeUncommitted: boolean): IndexedTreeLeafPreimage | undefined;
|
|
61
|
+
/**
|
|
62
|
+
* Batch insert multiple leaves into the tree.
|
|
63
|
+
* @param leaves - Leaves to insert into the tree.
|
|
64
|
+
* @param subtreeHeight - Height of the subtree.
|
|
65
|
+
* @param includeUncommitted - If true, the uncommitted changes are included in the search.
|
|
66
|
+
*/
|
|
67
|
+
batchInsert<TreeHeight extends number, SubtreeHeight extends number, SubtreeSiblingPathHeight extends number>(leaves: Buffer[], subtreeHeight: SubtreeHeight, includeUncommitted: boolean): Promise<BatchInsertionResult<TreeHeight, SubtreeSiblingPathHeight>>;
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=indexed_tree.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"indexed_tree.d.ts","sourceRoot":"","sources":["../../src/interfaces/indexed_tree.ts"],"names":[],"mappings":";;AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AACxF,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAEhE,OAAO,KAAK,EAAE,mBAAmB,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAC/G,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B;;;;;OAKG;IACH,QAAQ,CAAC,IAAI,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,uBAAuB,CAAC;IAC7F;;;OAGG;IACH,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,uBAAuB,CAAC;IACpD;;OAEG;IACH,KAAK,IAAI,uBAAuB,CAAC;IACjC;;;OAGG;IACH,KAAK,CAAC,QAAQ,EAAE,uBAAuB,GAAG,uBAAuB,CAAC;CACnE;AAED;;GAEG;AACH,MAAM,WAAW,WACf,SAAQ,UAAU,CAAC,MAAM,CAAC,EACxB,mBAAmB,CAAC,mBAAmB,CAAC,EACxC,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,EAAE,MAAM,mBAAmB,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC;IAC/E;;;;;OAKG;IACH,sBAAsB,CACpB,QAAQ,EAAE,MAAM,EAChB,kBAAkB,EAAE,OAAO,GAEzB;QACE;;WAEG;QACH,KAAK,EAAE,MAAM,CAAC;QACd;;WAEG;QACH,cAAc,EAAE,OAAO,CAAC;KACzB,GACD,SAAS,CAAC;IAEd;;;;;OAKG;IACH,yBAAyB,CAAC,KAAK,EAAE,MAAM,EAAE,kBAAkB,EAAE,OAAO,GAAG,uBAAuB,GAAG,SAAS,CAAC;IAE3G;;;;;OAKG;IACH,WAAW,CAAC,UAAU,SAAS,MAAM,EAAE,aAAa,SAAS,MAAM,EAAE,wBAAwB,SAAS,MAAM,EAC1G,MAAM,EAAE,MAAM,EAAE,EAChB,aAAa,EAAE,aAAa,EAC5B,kBAAkB,EAAE,OAAO,GAC1B,OAAO,CAAC,oBAAoB,CAAC,UAAU,EAAE,wBAAwB,CAAC,CAAC,CAAC;CACxE"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
3
|
+
import type { Bufferable } from '@aztec/foundation/serialize';
|
|
4
|
+
import type { SiblingPath } from '@aztec/foundation/trees';
|
|
5
|
+
/**
|
|
6
|
+
* Defines the interface for a source of sibling paths.
|
|
7
|
+
*/
|
|
8
|
+
export interface SiblingPathSource {
|
|
9
|
+
/**
|
|
10
|
+
* Returns the sibling path for a requested leaf index.
|
|
11
|
+
* @param index - The index of the leaf for which a sibling path is required.
|
|
12
|
+
* @param includeUncommitted - Set to true to include uncommitted updates in the sibling path.
|
|
13
|
+
*/
|
|
14
|
+
getSiblingPath<N extends number>(index: bigint, includeUncommitted: boolean): Promise<SiblingPath<N>>;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Defines the interface for a Merkle tree.
|
|
18
|
+
*/
|
|
19
|
+
export interface MerkleTree<T extends Bufferable = Buffer> extends SiblingPathSource {
|
|
20
|
+
/**
|
|
21
|
+
* Returns the current root of the tree.
|
|
22
|
+
* @param includeUncommitted - Set to true to include uncommitted updates in the calculated root.
|
|
23
|
+
*/
|
|
24
|
+
getRoot(includeUncommitted: boolean): Buffer;
|
|
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
|
+
* Commit pending updates to the tree.
|
|
32
|
+
*/
|
|
33
|
+
commit(): Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* Returns the depth of the tree.
|
|
36
|
+
*/
|
|
37
|
+
getDepth(): number;
|
|
38
|
+
/**
|
|
39
|
+
* Rollback pending update to the tree.
|
|
40
|
+
*/
|
|
41
|
+
rollback(): Promise<void>;
|
|
42
|
+
/**
|
|
43
|
+
* Returns the value of a leaf at the specified index.
|
|
44
|
+
* @param index - The index of the leaf value to be returned.
|
|
45
|
+
* @param includeUncommitted - Set to true to include uncommitted updates in the data set.
|
|
46
|
+
*/
|
|
47
|
+
getLeafValue(index: bigint, includeUncommitted: boolean): T | undefined;
|
|
48
|
+
/**
|
|
49
|
+
* Returns the index of a leaf given its value, or undefined if no leaf with that value is found.
|
|
50
|
+
* @param leaf - The leaf value to look for.
|
|
51
|
+
* @param includeUncommitted - Indicates whether to include uncommitted data.
|
|
52
|
+
* @returns The index of the first leaf found with a given value (undefined if not found).
|
|
53
|
+
*/
|
|
54
|
+
findLeafIndex(leaf: T, includeUncommitted: boolean): bigint | undefined;
|
|
55
|
+
/**
|
|
56
|
+
* Returns the first index containing a leaf value after `startIndex`.
|
|
57
|
+
* @param leaf - The leaf value to look for.
|
|
58
|
+
* @param startIndex - The index to start searching from (used when skipping nullified messages)
|
|
59
|
+
* @param includeUncommitted - Indicates whether to include uncommitted data.
|
|
60
|
+
* @returns The index of the first leaf found with a given value (undefined if not found).
|
|
61
|
+
*/
|
|
62
|
+
findLeafIndexAfter(leaf: T, startIndex: bigint, includeUncommitted: boolean): bigint | undefined;
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=merkle_tree.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"merkle_tree.d.ts","sourceRoot":"","sources":["../../src/interfaces/merkle_tree.ts"],"names":[],"mappings":";;AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAE3D;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC;;;;OAIG;IACH,cAAc,CAAC,CAAC,SAAS,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,kBAAkB,EAAE,OAAO,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;CACvG;AAED;;GAEG;AACH,MAAM,WAAW,UAAU,CAAC,CAAC,SAAS,UAAU,GAAG,MAAM,CAAE,SAAQ,iBAAiB;IAClF;;;OAGG;IACH,OAAO,CAAC,kBAAkB,EAAE,OAAO,GAAG,MAAM,CAAC;IAE7C;;;OAGG;IACH,YAAY,CAAC,kBAAkB,EAAE,OAAO,GAAG,MAAM,CAAC;IAElD;;OAEG;IACH,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAExB;;OAEG;IACH,QAAQ,IAAI,MAAM,CAAC;IAEnB;;OAEG;IACH,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAE1B;;;;OAIG;IACH,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,kBAAkB,EAAE,OAAO,GAAG,CAAC,GAAG,SAAS,CAAC;IAExE;;;;;OAKG;IACH,aAAa,CAAC,IAAI,EAAE,CAAC,EAAE,kBAAkB,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAAC;IAExE;;;;;;OAMG;IACH,kBAAkB,CAAC,IAAI,EAAE,CAAC,EAAE,UAAU,EAAE,MAAM,EAAE,kBAAkB,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAAC;CAClG"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
3
|
+
import type { Bufferable } from '@aztec/foundation/serialize';
|
|
4
|
+
import type { TreeSnapshot, TreeSnapshotBuilder } from '../snapshots/snapshot_builder.js';
|
|
5
|
+
import type { MerkleTree } from './merkle_tree.js';
|
|
6
|
+
/**
|
|
7
|
+
* A Merkle tree that supports updates at arbitrary indices but not appending.
|
|
8
|
+
*/
|
|
9
|
+
export interface UpdateOnlyTree<T extends Bufferable = Buffer> extends MerkleTree<T>, TreeSnapshotBuilder<TreeSnapshot<T>> {
|
|
10
|
+
/**
|
|
11
|
+
* Updates a leaf at a given index in the tree.
|
|
12
|
+
* @param leaf - The leaf value to be updated.
|
|
13
|
+
* @param index - The leaf to be updated.
|
|
14
|
+
*/
|
|
15
|
+
updateLeaf(leaf: T, index: bigint): Promise<void>;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=update_only_tree.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"update_only_tree.d.ts","sourceRoot":"","sources":["../../src/interfaces/update_only_tree.ts"],"names":[],"mappings":";;AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAE9D,OAAO,KAAK,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAC1F,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD;;GAEG;AACH,MAAM,WAAW,cAAc,CAAC,CAAC,SAAS,UAAU,GAAG,MAAM,CAC3D,SAAQ,UAAU,CAAC,CAAC,CAAC,EACnB,mBAAmB,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;IACtC;;;;OAIG;IACH,UAAU,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACnD"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
3
|
+
import type { Bufferable, FromBuffer } from '@aztec/foundation/serialize';
|
|
4
|
+
import type { Hasher } from '@aztec/foundation/trees';
|
|
5
|
+
import type { AztecKVStore } from '@aztec/kv-store';
|
|
6
|
+
import { type TreeBase } from './tree_base.js';
|
|
7
|
+
/**
|
|
8
|
+
* Creates a new tree and sets its root, depth and size based on the meta data which are associated with the name.
|
|
9
|
+
* @param c - The class of the tree to be instantiated.
|
|
10
|
+
* @param db - A database used to store the Merkle tree data.
|
|
11
|
+
* @param hasher - A hasher used to compute hash paths.
|
|
12
|
+
* @param name - Name of the tree.
|
|
13
|
+
* @returns The newly created tree.
|
|
14
|
+
*/
|
|
15
|
+
export declare function loadTree<T extends TreeBase<Bufferable>, D extends FromBuffer<Bufferable>>(c: new (store: AztecKVStore, hasher: Hasher, name: string, depth: number, size: bigint, deserializer: D, root: Buffer) => T, store: AztecKVStore, hasher: Hasher, name: string, deserializer: D): Promise<T>;
|
|
16
|
+
//# sourceMappingURL=load_tree.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"load_tree.d.ts","sourceRoot":"","sources":["../src/load_tree.ts"],"names":[],"mappings":";;AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAC1E,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEpD,OAAO,EAAE,KAAK,QAAQ,EAAe,MAAM,gBAAgB,CAAC;AAE5D;;;;;;;GAOG;AACH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC,SAAS,UAAU,CAAC,UAAU,CAAC,EACvF,CAAC,EAAE,KACD,KAAK,EAAE,YAAY,EACnB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,MAAM,EACZ,YAAY,EAAE,CAAC,EACf,IAAI,EAAE,MAAM,KACT,CAAC,EACN,KAAK,EAAE,YAAY,EACnB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,YAAY,EAAE,CAAC,GACd,OAAO,CAAC,CAAC,CAAC,CAIZ"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { getTreeMeta } from './tree_base.js';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a new tree and sets its root, depth and size based on the meta data which are associated with the name.
|
|
4
|
+
* @param c - The class of the tree to be instantiated.
|
|
5
|
+
* @param db - A database used to store the Merkle tree data.
|
|
6
|
+
* @param hasher - A hasher used to compute hash paths.
|
|
7
|
+
* @param name - Name of the tree.
|
|
8
|
+
* @returns The newly created tree.
|
|
9
|
+
*/ export function loadTree(c, store, hasher, name, deserializer) {
|
|
10
|
+
const { root, depth, size } = getTreeMeta(store, name);
|
|
11
|
+
const tree = new c(store, hasher, name, depth, size, deserializer, root);
|
|
12
|
+
return Promise.resolve(tree);
|
|
13
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Bufferable, FromBuffer } from '@aztec/foundation/serialize';
|
|
2
|
+
import type { Hasher } from '@aztec/foundation/trees';
|
|
3
|
+
import type { AztecKVStore } from '@aztec/kv-store';
|
|
4
|
+
import type { TreeBase } from './tree_base.js';
|
|
5
|
+
/**
|
|
6
|
+
* Creates a new tree.
|
|
7
|
+
* @param c - The class of the tree to be instantiated.
|
|
8
|
+
* @param db - A database used to store the Merkle tree data.
|
|
9
|
+
* @param hasher - A hasher used to compute hash paths.
|
|
10
|
+
* @param name - Name of the tree.
|
|
11
|
+
* @param depth - Depth of the tree.
|
|
12
|
+
* @param prefilledSize - A number of leaves that are prefilled with values.
|
|
13
|
+
* @returns The newly created tree.
|
|
14
|
+
*/
|
|
15
|
+
export declare function newTree<T extends TreeBase<Bufferable>, D extends FromBuffer<Bufferable>>(c: new (store: AztecKVStore, hasher: Hasher, name: string, depth: number, size: bigint, deserializer: D) => T, store: AztecKVStore, hasher: Hasher, name: string, deserializer: D, depth: number, prefilledSize?: number): Promise<T>;
|
|
16
|
+
//# sourceMappingURL=new_tree.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"new_tree.d.ts","sourceRoot":"","sources":["../src/new_tree.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAC1E,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEpD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE/C;;;;;;;;;GASG;AACH,wBAAsB,OAAO,CAAC,CAAC,SAAS,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC,SAAS,UAAU,CAAC,UAAU,CAAC,EAC5F,CAAC,EAAE,KAAK,KAAK,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC,KAAK,CAAC,EAC7G,KAAK,EAAE,YAAY,EACnB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,YAAY,EAAE,CAAC,EACf,KAAK,EAAE,MAAM,EACb,aAAa,SAAI,GAChB,OAAO,CAAC,CAAC,CAAC,CAIZ"}
|
package/dest/new_tree.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a new tree.
|
|
3
|
+
* @param c - The class of the tree to be instantiated.
|
|
4
|
+
* @param db - A database used to store the Merkle tree data.
|
|
5
|
+
* @param hasher - A hasher used to compute hash paths.
|
|
6
|
+
* @param name - Name of the tree.
|
|
7
|
+
* @param depth - Depth of the tree.
|
|
8
|
+
* @param prefilledSize - A number of leaves that are prefilled with values.
|
|
9
|
+
* @returns The newly created tree.
|
|
10
|
+
*/ export async function newTree(c, store, hasher, name, deserializer, depth, prefilledSize = 1) {
|
|
11
|
+
const tree = new c(store, hasher, name, depth, 0n, deserializer);
|
|
12
|
+
await tree.init(prefilledSize);
|
|
13
|
+
return tree;
|
|
14
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
3
|
+
import type { Hasher } from '@aztec/foundation/trees';
|
|
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 declare class Pedersen implements Hasher {
|
|
10
|
+
hash(lhs: Uint8Array, rhs: Uint8Array): Buffer;
|
|
11
|
+
hashInputs(inputs: Buffer[]): Buffer;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=pedersen.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pedersen.d.ts","sourceRoot":"","sources":["../src/pedersen.ts"],"names":[],"mappings":";;AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAEtD;;;;GAIG;AACH,qBAAa,QAAS,YAAW,MAAM;IAK9B,IAAI,CAAC,GAAG,EAAE,UAAU,EAAE,GAAG,EAAE,UAAU,GAAG,MAAM;IAQ9C,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM;CAI5C"}
|
package/dest/pedersen.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { pedersenHash } from '@aztec/foundation/crypto/sync';
|
|
2
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
3
|
+
/**
|
|
4
|
+
* A helper class encapsulating Pedersen hash functionality.
|
|
5
|
+
* @deprecated Don't call pedersen directly in production code. Instead, create suitably-named functions for specific
|
|
6
|
+
* purposes.
|
|
7
|
+
*/ export class Pedersen {
|
|
8
|
+
/*
|
|
9
|
+
* @deprecated Don't call pedersen directly in production code. Instead, create suitably-named functions for specific
|
|
10
|
+
* purposes.
|
|
11
|
+
*/ hash(lhs, rhs) {
|
|
12
|
+
return pedersenHash([
|
|
13
|
+
Fr.fromBuffer(Buffer.from(lhs)),
|
|
14
|
+
Fr.fromBuffer(Buffer.from(rhs))
|
|
15
|
+
]).toBuffer();
|
|
16
|
+
}
|
|
17
|
+
/*
|
|
18
|
+
* @deprecated Don't call pedersen directly in production code. Instead, create suitably-named functions for specific
|
|
19
|
+
* purposes.
|
|
20
|
+
*/ hashInputs(inputs) {
|
|
21
|
+
const inputFields = inputs.map((i)=>Fr.fromBuffer(i));
|
|
22
|
+
return pedersenHash(inputFields).toBuffer();
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
3
|
+
import type { Hasher } from '@aztec/foundation/trees';
|
|
4
|
+
/**
|
|
5
|
+
* A helper class encapsulating poseidon2 hash functionality.
|
|
6
|
+
* @deprecated Don't call poseidon2 directly in production code. Instead, create suitably-named functions for specific
|
|
7
|
+
* purposes.
|
|
8
|
+
*/
|
|
9
|
+
export declare class Poseidon implements Hasher {
|
|
10
|
+
hash(lhs: Uint8Array, rhs: Uint8Array): Buffer;
|
|
11
|
+
hashInputs(inputs: Buffer[]): Buffer;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=poseidon.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"poseidon.d.ts","sourceRoot":"","sources":["../src/poseidon.ts"],"names":[],"mappings":";;AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAEtD;;;;GAIG;AACH,qBAAa,QAAS,YAAW,MAAM;IAK9B,IAAI,CAAC,GAAG,EAAE,UAAU,EAAE,GAAG,EAAE,UAAU,GAAG,MAAM;IAQ9C,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM;CAI5C"}
|
package/dest/poseidon.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { poseidon2Hash } from '@aztec/foundation/crypto/sync';
|
|
2
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
3
|
+
/**
|
|
4
|
+
* A helper class encapsulating poseidon2 hash functionality.
|
|
5
|
+
* @deprecated Don't call poseidon2 directly in production code. Instead, create suitably-named functions for specific
|
|
6
|
+
* purposes.
|
|
7
|
+
*/ export class Poseidon {
|
|
8
|
+
/*
|
|
9
|
+
* @deprecated Don't call poseidon2 directly in production code. Instead, create suitably-named functions for specific
|
|
10
|
+
* purposes.
|
|
11
|
+
*/ hash(lhs, rhs) {
|
|
12
|
+
return poseidon2Hash([
|
|
13
|
+
Fr.fromBuffer(Buffer.from(lhs)),
|
|
14
|
+
Fr.fromBuffer(Buffer.from(rhs))
|
|
15
|
+
]).toBuffer();
|
|
16
|
+
}
|
|
17
|
+
/*
|
|
18
|
+
* @deprecated Don't call poseidon2 directly in production code. Instead, create suitably-named functions for specific
|
|
19
|
+
* purposes.
|
|
20
|
+
*/ hashInputs(inputs) {
|
|
21
|
+
const inputFields = inputs.map((i)=>Fr.fromBuffer(i));
|
|
22
|
+
return poseidon2Hash(inputFields).toBuffer();
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
3
|
+
import type { Hasher } from '@aztec/foundation/trees';
|
|
4
|
+
/**
|
|
5
|
+
* A helper class encapsulating SHA256 hash functionality.
|
|
6
|
+
* @deprecated Don't call SHA256 directly in production code. Instead, create suitably-named functions for specific
|
|
7
|
+
* purposes.
|
|
8
|
+
*/
|
|
9
|
+
export declare class SHA256 implements Hasher {
|
|
10
|
+
hash(lhs: Uint8Array, rhs: Uint8Array): Buffer;
|
|
11
|
+
hashInputs(inputs: Buffer[]): Buffer;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* A helper class encapsulating truncated SHA256 hash functionality.
|
|
15
|
+
* @deprecated Don't call SHA256 directly in production code. Instead, create suitably-named functions for specific
|
|
16
|
+
* purposes.
|
|
17
|
+
*/
|
|
18
|
+
export declare class SHA256Trunc implements Hasher {
|
|
19
|
+
hash(lhs: Uint8Array, rhs: Uint8Array): Buffer;
|
|
20
|
+
hashInputs(inputs: Buffer[]): Buffer;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=sha_256.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sha_256.d.ts","sourceRoot":"","sources":["../src/sha_256.ts"],"names":[],"mappings":";;AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAEtD;;;;GAIG;AACH,qBAAa,MAAO,YAAW,MAAM;IAK5B,IAAI,CAAC,GAAG,EAAE,UAAU,EAAE,GAAG,EAAE,UAAU,GAAG,MAAM;IAQ9C,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM;CAG5C;AAED;;;;GAIG;AACH,qBAAa,WAAY,YAAW,MAAM;IAKjC,IAAI,CAAC,GAAG,EAAE,UAAU,EAAE,GAAG,EAAE,UAAU,GAAG,MAAM;IAQ9C,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM;CAG5C"}
|
package/dest/sha_256.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { sha256 } from '@aztec/foundation/crypto';
|
|
2
|
+
import { truncateAndPad } from '@aztec/foundation/serialize';
|
|
3
|
+
/**
|
|
4
|
+
* A helper class encapsulating SHA256 hash functionality.
|
|
5
|
+
* @deprecated Don't call SHA256 directly in production code. Instead, create suitably-named functions for specific
|
|
6
|
+
* purposes.
|
|
7
|
+
*/ export class SHA256 {
|
|
8
|
+
/*
|
|
9
|
+
* @deprecated Don't call SHA256 directly in production code. Instead, create suitably-named functions for specific
|
|
10
|
+
* purposes.
|
|
11
|
+
*/ hash(lhs, rhs) {
|
|
12
|
+
return sha256(Buffer.concat([
|
|
13
|
+
Buffer.from(lhs),
|
|
14
|
+
Buffer.from(rhs)
|
|
15
|
+
]));
|
|
16
|
+
}
|
|
17
|
+
/*
|
|
18
|
+
* @deprecated Don't call SHA256 directly in production code. Instead, create suitably-named functions for specific
|
|
19
|
+
* purposes.
|
|
20
|
+
*/ hashInputs(inputs) {
|
|
21
|
+
return sha256(Buffer.concat(inputs));
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* A helper class encapsulating truncated SHA256 hash functionality.
|
|
26
|
+
* @deprecated Don't call SHA256 directly in production code. Instead, create suitably-named functions for specific
|
|
27
|
+
* purposes.
|
|
28
|
+
*/ export class SHA256Trunc {
|
|
29
|
+
/*
|
|
30
|
+
* @deprecated Don't call SHA256 directly in production code. Instead, create suitably-named functions for specific
|
|
31
|
+
* purposes.
|
|
32
|
+
*/ hash(lhs, rhs) {
|
|
33
|
+
return truncateAndPad(sha256(Buffer.concat([
|
|
34
|
+
Buffer.from(lhs),
|
|
35
|
+
Buffer.from(rhs)
|
|
36
|
+
])));
|
|
37
|
+
}
|
|
38
|
+
/*
|
|
39
|
+
* @deprecated Don't call SHA256 directly in production code. Instead, create suitably-named functions for specific
|
|
40
|
+
* purposes.
|
|
41
|
+
*/ hashInputs(inputs) {
|
|
42
|
+
return truncateAndPad(sha256(Buffer.concat(inputs)));
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type Bufferable, type FromBuffer } from '@aztec/foundation/serialize';
|
|
2
|
+
import type { Hasher } from '@aztec/foundation/trees';
|
|
3
|
+
import type { AztecKVStore } from '@aztec/kv-store';
|
|
4
|
+
import type { AppendOnlyTree } from '../interfaces/append_only_tree.js';
|
|
5
|
+
import type { TreeBase } from '../tree_base.js';
|
|
6
|
+
import type { TreeSnapshot, TreeSnapshotBuilder } from './snapshot_builder.js';
|
|
7
|
+
/**
|
|
8
|
+
* A more space-efficient way of storing snapshots of AppendOnlyTrees that trades space need for slower
|
|
9
|
+
* sibling path reads.
|
|
10
|
+
*
|
|
11
|
+
* Complexity:
|
|
12
|
+
*
|
|
13
|
+
* N - count of non-zero nodes in tree
|
|
14
|
+
* M - count of snapshots
|
|
15
|
+
* H - tree height
|
|
16
|
+
*
|
|
17
|
+
* Space complexity: O(N + M) (N nodes - stores the last snapshot for each node and M - ints, for each snapshot stores up to which leaf its written to)
|
|
18
|
+
* Sibling path access:
|
|
19
|
+
* Best case: O(H) database reads + O(1) hashes
|
|
20
|
+
* Worst case: O(H) database reads + O(H) hashes
|
|
21
|
+
*/
|
|
22
|
+
export declare class AppendOnlySnapshotBuilder<T extends Bufferable> implements TreeSnapshotBuilder<TreeSnapshot<T>> {
|
|
23
|
+
#private;
|
|
24
|
+
private db;
|
|
25
|
+
private tree;
|
|
26
|
+
private hasher;
|
|
27
|
+
private deserializer;
|
|
28
|
+
constructor(db: AztecKVStore, tree: TreeBase<T> & AppendOnlyTree<T>, hasher: Hasher, deserializer: FromBuffer<T>);
|
|
29
|
+
getSnapshot(block: number): Promise<TreeSnapshot<T>>;
|
|
30
|
+
snapshot(block: number): Promise<TreeSnapshot<T>>;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=append_only_snapshot.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"append_only_snapshot.d.ts","sourceRoot":"","sources":["../../src/snapshots/append_only_snapshot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAAE,KAAK,UAAU,EAAqB,MAAM,6BAA6B,CAAC;AAElG,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,KAAK,EAAE,YAAY,EAAY,MAAM,iBAAiB,CAAC;AAE9D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AACxE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,KAAK,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAkB/E;;;;;;;;;;;;;;GAcG;AACH,qBAAa,yBAAyB,CAAC,CAAC,SAAS,UAAU,CAAE,YAAW,mBAAmB,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;;IAMxG,OAAO,CAAC,EAAE;IACV,OAAO,CAAC,IAAI;IACZ,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,YAAY;gBAHZ,EAAE,EAAE,YAAY,EAChB,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,cAAc,CAAC,CAAC,CAAC,EACrC,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,UAAU,CAAC,CAAC,CAAC;IAQrC,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;IAqBpD,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;CA4ElD"}
|