@aztec/merkle-tree 0.0.0-test.1 → 0.0.1-commit.03f7ef2
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/hasher_with_stats.d.ts +1 -2
- package/dest/hasher_with_stats.d.ts.map +1 -1
- package/dest/index.d.ts +1 -2
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +0 -1
- package/dest/interfaces/append_only_tree.d.ts +2 -4
- package/dest/interfaces/append_only_tree.d.ts.map +1 -1
- package/dest/interfaces/indexed_tree.d.ts +1 -3
- package/dest/interfaces/indexed_tree.d.ts.map +1 -1
- package/dest/interfaces/merkle_tree.d.ts +1 -3
- package/dest/interfaces/merkle_tree.d.ts.map +1 -1
- package/dest/interfaces/update_only_tree.d.ts +1 -3
- package/dest/interfaces/update_only_tree.d.ts.map +1 -1
- package/dest/load_tree.d.ts +1 -3
- package/dest/load_tree.d.ts.map +1 -1
- package/dest/new_tree.d.ts +1 -1
- package/dest/pedersen.d.ts +3 -5
- package/dest/pedersen.d.ts.map +1 -1
- package/dest/pedersen.js +1 -1
- package/dest/poseidon.d.ts +3 -5
- package/dest/poseidon.d.ts.map +1 -1
- package/dest/poseidon.js +1 -1
- package/dest/snapshots/append_only_snapshot.d.ts +4 -3
- package/dest/snapshots/append_only_snapshot.d.ts.map +1 -1
- package/dest/snapshots/base_full_snapshot.d.ts +6 -7
- package/dest/snapshots/base_full_snapshot.d.ts.map +1 -1
- package/dest/snapshots/full_snapshot.d.ts +1 -3
- package/dest/snapshots/full_snapshot.d.ts.map +1 -1
- package/dest/snapshots/indexed_tree_snapshot.d.ts +1 -3
- package/dest/snapshots/indexed_tree_snapshot.d.ts.map +1 -1
- package/dest/snapshots/snapshot_builder.d.ts +4 -5
- package/dest/snapshots/snapshot_builder.d.ts.map +1 -1
- package/dest/snapshots/snapshot_builder_test_suite.d.ts +1 -1
- package/dest/snapshots/snapshot_builder_test_suite.d.ts.map +1 -1
- package/dest/snapshots/snapshot_builder_test_suite.js +20 -19
- package/dest/sparse_tree/sparse_tree.d.ts +4 -3
- package/dest/sparse_tree/sparse_tree.d.ts.map +1 -1
- package/dest/standard_indexed_tree/standard_indexed_tree.d.ts +5 -6
- package/dest/standard_indexed_tree/standard_indexed_tree.d.ts.map +1 -1
- package/dest/standard_indexed_tree/standard_indexed_tree.js +3 -2
- package/dest/standard_indexed_tree/test/standard_indexed_tree_with_append.d.ts +2 -4
- package/dest/standard_indexed_tree/test/standard_indexed_tree_with_append.d.ts.map +1 -1
- package/dest/standard_indexed_tree/test/standard_indexed_tree_with_append.js +0 -1
- package/dest/standard_tree/standard_tree.d.ts +5 -6
- package/dest/standard_tree/standard_tree.d.ts.map +1 -1
- package/dest/standard_tree/standard_tree.js +0 -1
- package/dest/tree_base.d.ts +4 -6
- package/dest/tree_base.d.ts.map +1 -1
- package/dest/unbalanced_tree.d.ts +2 -4
- package/dest/unbalanced_tree.d.ts.map +1 -1
- package/package.json +17 -14
- package/src/index.ts +0 -1
- package/src/interfaces/append_only_tree.ts +1 -1
- package/src/pedersen.ts +8 -5
- package/src/poseidon.ts +8 -5
- package/src/snapshots/append_only_snapshot.ts +9 -8
- package/src/snapshots/base_full_snapshot.ts +9 -5
- package/src/snapshots/full_snapshot.ts +5 -1
- package/src/snapshots/indexed_tree_snapshot.ts +5 -1
- package/src/snapshots/snapshot_builder.ts +3 -2
- package/src/snapshots/snapshot_builder_test_suite.ts +20 -19
- package/src/sparse_tree/sparse_tree.ts +3 -2
- package/src/standard_indexed_tree/standard_indexed_tree.ts +7 -6
- package/src/standard_indexed_tree/test/standard_indexed_tree_with_append.ts +1 -3
- package/src/standard_tree/standard_tree.ts +4 -5
- package/src/tree_base.ts +2 -2
- package/dest/sha_256.d.ts +0 -22
- package/dest/sha_256.d.ts.map +0 -1
- package/dest/sha_256.js +0 -44
- package/src/sha_256.ts +0 -49
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
|
+
import { randomBigInt } from '@aztec/foundation/crypto/random';
|
|
2
3
|
import type { Bufferable } from '@aztec/foundation/serialize';
|
|
3
4
|
|
|
4
5
|
import { jest } from '@jest/globals';
|
|
@@ -29,14 +30,14 @@ export function describeSnapshotBuilderTestSuite<
|
|
|
29
30
|
it('takes snapshots', async () => {
|
|
30
31
|
await modifyTree(tree);
|
|
31
32
|
await tree.commit();
|
|
32
|
-
await expect(snapshotBuilder.snapshot(1)).resolves.toBeDefined();
|
|
33
|
+
await expect(snapshotBuilder.snapshot(BlockNumber(1))).resolves.toBeDefined();
|
|
33
34
|
});
|
|
34
35
|
|
|
35
36
|
it('is idempotent', async () => {
|
|
36
37
|
await modifyTree(tree);
|
|
37
38
|
await tree.commit();
|
|
38
39
|
|
|
39
|
-
const block = 1;
|
|
40
|
+
const block = BlockNumber(1);
|
|
40
41
|
const snapshot = await snapshotBuilder.snapshot(block);
|
|
41
42
|
const newSnapshot = await snapshotBuilder.snapshot(block);
|
|
42
43
|
|
|
@@ -46,7 +47,7 @@ export function describeSnapshotBuilderTestSuite<
|
|
|
46
47
|
it('returns the same path if tree has not diverged', async () => {
|
|
47
48
|
await modifyTree(tree);
|
|
48
49
|
await tree.commit();
|
|
49
|
-
const snapshot = await snapshotBuilder.snapshot(1);
|
|
50
|
+
const snapshot = await snapshotBuilder.snapshot(BlockNumber(1));
|
|
50
51
|
|
|
51
52
|
const historicPaths = await Promise.all(leaves.map(leaf => snapshot.getSiblingPath(leaf)));
|
|
52
53
|
const expectedPaths = await Promise.all(leaves.map(leaf => tree.getSiblingPath(leaf, false)));
|
|
@@ -59,7 +60,7 @@ export function describeSnapshotBuilderTestSuite<
|
|
|
59
60
|
it('returns historic paths if tree has diverged and no new snapshots have been taken', async () => {
|
|
60
61
|
await modifyTree(tree);
|
|
61
62
|
await tree.commit();
|
|
62
|
-
const snapshot = await snapshotBuilder.snapshot(1);
|
|
63
|
+
const snapshot = await snapshotBuilder.snapshot(BlockNumber(1));
|
|
63
64
|
|
|
64
65
|
const expectedPaths = await Promise.all(leaves.map(leaf => tree.getSiblingPath(leaf, false)));
|
|
65
66
|
|
|
@@ -79,12 +80,12 @@ export function describeSnapshotBuilderTestSuite<
|
|
|
79
80
|
|
|
80
81
|
const expectedPaths = await Promise.all(leaves.map(leaf => tree.getSiblingPath(leaf, false)));
|
|
81
82
|
|
|
82
|
-
const snapshot = await snapshotBuilder.snapshot(1);
|
|
83
|
+
const snapshot = await snapshotBuilder.snapshot(BlockNumber(1));
|
|
83
84
|
|
|
84
85
|
await modifyTree(tree);
|
|
85
86
|
await tree.commit();
|
|
86
87
|
|
|
87
|
-
await snapshotBuilder.snapshot(2);
|
|
88
|
+
await snapshotBuilder.snapshot(BlockNumber(2));
|
|
88
89
|
|
|
89
90
|
// check that snapshot 2 has not influenced snapshot(1) at all
|
|
90
91
|
const historicPaths = await Promise.all(leaves.map(leaf => snapshot.getSiblingPath(leaf)));
|
|
@@ -100,12 +101,12 @@ export function describeSnapshotBuilderTestSuite<
|
|
|
100
101
|
|
|
101
102
|
const expectedPaths = await Promise.all(leaves.map(leaf => tree.getSiblingPath(leaf, false)));
|
|
102
103
|
|
|
103
|
-
const snapshot = await snapshotBuilder.snapshot(1);
|
|
104
|
+
const snapshot = await snapshotBuilder.snapshot(BlockNumber(1));
|
|
104
105
|
|
|
105
106
|
await modifyTree(tree);
|
|
106
107
|
await tree.commit();
|
|
107
108
|
|
|
108
|
-
await snapshotBuilder.snapshot(2);
|
|
109
|
+
await snapshotBuilder.snapshot(BlockNumber(2));
|
|
109
110
|
|
|
110
111
|
await modifyTree(tree);
|
|
111
112
|
await tree.commit();
|
|
@@ -125,15 +126,15 @@ export function describeSnapshotBuilderTestSuite<
|
|
|
125
126
|
await modifyTree(tree);
|
|
126
127
|
await tree.commit();
|
|
127
128
|
const expectedPaths = await Promise.all(leaves.map(leaf => tree.getSiblingPath(leaf, false)));
|
|
128
|
-
await snapshotBuilder.snapshot(1);
|
|
129
|
+
await snapshotBuilder.snapshot(BlockNumber(1));
|
|
129
130
|
|
|
130
131
|
for (let i = 2; i < 5; i++) {
|
|
131
132
|
await modifyTree(tree);
|
|
132
133
|
await tree.commit();
|
|
133
|
-
await snapshotBuilder.snapshot(i);
|
|
134
|
+
await snapshotBuilder.snapshot(BlockNumber(i));
|
|
134
135
|
}
|
|
135
136
|
|
|
136
|
-
const firstSnapshot = await snapshotBuilder.getSnapshot(1);
|
|
137
|
+
const firstSnapshot = await snapshotBuilder.getSnapshot(BlockNumber(1));
|
|
137
138
|
const historicPaths = await Promise.all(leaves.map(leaf => firstSnapshot.getSiblingPath(leaf)));
|
|
138
139
|
|
|
139
140
|
for (const [index, path] of historicPaths.entries()) {
|
|
@@ -144,9 +145,9 @@ export function describeSnapshotBuilderTestSuite<
|
|
|
144
145
|
it('throws if an unknown snapshot is requested', async () => {
|
|
145
146
|
await modifyTree(tree);
|
|
146
147
|
await tree.commit();
|
|
147
|
-
await snapshotBuilder.snapshot(1);
|
|
148
|
+
await snapshotBuilder.snapshot(BlockNumber(1));
|
|
148
149
|
|
|
149
|
-
await expect(snapshotBuilder.getSnapshot(2)).rejects.toThrow();
|
|
150
|
+
await expect(snapshotBuilder.getSnapshot(BlockNumber(2))).rejects.toThrow();
|
|
150
151
|
});
|
|
151
152
|
});
|
|
152
153
|
|
|
@@ -154,7 +155,7 @@ export function describeSnapshotBuilderTestSuite<
|
|
|
154
155
|
it('returns the historical root of the tree when the snapshot was taken', async () => {
|
|
155
156
|
await modifyTree(tree);
|
|
156
157
|
await tree.commit();
|
|
157
|
-
const snapshot = await snapshotBuilder.snapshot(1);
|
|
158
|
+
const snapshot = await snapshotBuilder.snapshot(BlockNumber(1));
|
|
158
159
|
const historicalRoot = tree.getRoot(false);
|
|
159
160
|
|
|
160
161
|
await modifyTree(tree);
|
|
@@ -169,7 +170,7 @@ export function describeSnapshotBuilderTestSuite<
|
|
|
169
170
|
it('returns the same depth as the tree', async () => {
|
|
170
171
|
await modifyTree(tree);
|
|
171
172
|
await tree.commit();
|
|
172
|
-
const snapshot = await snapshotBuilder.snapshot(1);
|
|
173
|
+
const snapshot = await snapshotBuilder.snapshot(BlockNumber(1));
|
|
173
174
|
expect(snapshot.getDepth()).toEqual(tree.getDepth());
|
|
174
175
|
});
|
|
175
176
|
});
|
|
@@ -178,7 +179,7 @@ export function describeSnapshotBuilderTestSuite<
|
|
|
178
179
|
it('returns the historical leaves count when the snapshot was taken', async () => {
|
|
179
180
|
await modifyTree(tree);
|
|
180
181
|
await tree.commit();
|
|
181
|
-
const snapshot = await snapshotBuilder.snapshot(1);
|
|
182
|
+
const snapshot = await snapshotBuilder.snapshot(BlockNumber(1));
|
|
182
183
|
const historicalNumLeaves = tree.getNumLeaves(false);
|
|
183
184
|
|
|
184
185
|
await modifyTree(tree);
|
|
@@ -192,7 +193,7 @@ export function describeSnapshotBuilderTestSuite<
|
|
|
192
193
|
it('returns the historical leaf value when the snapshot was taken', async () => {
|
|
193
194
|
await modifyTree(tree);
|
|
194
195
|
await tree.commit();
|
|
195
|
-
const snapshot = await snapshotBuilder.snapshot(1);
|
|
196
|
+
const snapshot = await snapshotBuilder.snapshot(BlockNumber(1));
|
|
196
197
|
const historicalLeafValue = tree.getLeafValue(0n, false);
|
|
197
198
|
expect(snapshot.getLeafValue(0n)).toEqual(historicalLeafValue);
|
|
198
199
|
|
|
@@ -207,7 +208,7 @@ export function describeSnapshotBuilderTestSuite<
|
|
|
207
208
|
it('returns the historical leaf index when the snapshot was taken', async () => {
|
|
208
209
|
await modifyTree(tree);
|
|
209
210
|
await tree.commit();
|
|
210
|
-
const snapshot = await snapshotBuilder.snapshot(1);
|
|
211
|
+
const snapshot = await snapshotBuilder.snapshot(BlockNumber(1));
|
|
211
212
|
|
|
212
213
|
const initialLastLeafIndex = tree.getNumLeaves(false) - 1n;
|
|
213
214
|
let lastLeaf = tree.getLeafValue(initialLastLeafIndex, false);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { BlockNumber } from '@aztec/foundation/branded-types';
|
|
1
2
|
import { type Bufferable, serializeToBuffer } from '@aztec/foundation/serialize';
|
|
2
3
|
|
|
3
4
|
import type { UpdateOnlyTree } from '../interfaces/update_only_tree.js';
|
|
@@ -38,11 +39,11 @@ export class SparseTree<T extends Bufferable> extends TreeBase<T> implements Upd
|
|
|
38
39
|
return Promise.resolve();
|
|
39
40
|
}
|
|
40
41
|
|
|
41
|
-
public snapshot(block:
|
|
42
|
+
public snapshot(block: BlockNumber): Promise<TreeSnapshot<T>> {
|
|
42
43
|
return this.#snapshotBuilder.snapshot(block);
|
|
43
44
|
}
|
|
44
45
|
|
|
45
|
-
public getSnapshot(block:
|
|
46
|
+
public getSnapshot(block: BlockNumber): Promise<TreeSnapshot<T>> {
|
|
46
47
|
return this.#snapshotBuilder.getSnapshot(block);
|
|
47
48
|
}
|
|
48
49
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { toBufferBE } from '@aztec/foundation/bigint-buffer';
|
|
2
|
+
import type { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
3
|
import type { FromBuffer } from '@aztec/foundation/serialize';
|
|
3
4
|
import { Timer } from '@aztec/foundation/timer';
|
|
4
5
|
import { SiblingPath } from '@aztec/foundation/trees';
|
|
@@ -60,7 +61,7 @@ export const noopDeserializer: FromBuffer<Buffer> = {
|
|
|
60
61
|
* Standard implementation of an indexed tree.
|
|
61
62
|
*/
|
|
62
63
|
export class StandardIndexedTree extends TreeBase<Buffer> implements IndexedTree {
|
|
63
|
-
#snapshotBuilder
|
|
64
|
+
#snapshotBuilder: IndexedTreeSnapshotBuilder;
|
|
64
65
|
|
|
65
66
|
protected cachedLeafPreimages: { [key: string]: IndexedTreeLeafPreimage } = {};
|
|
66
67
|
protected leaves: AztecMap<ReturnType<typeof buildDbKeyForPreimage>, Buffer>;
|
|
@@ -79,6 +80,7 @@ export class StandardIndexedTree extends TreeBase<Buffer> implements IndexedTree
|
|
|
79
80
|
super(store, hasher, name, depth, size, noopDeserializer, root);
|
|
80
81
|
this.leaves = store.openMap(`tree_${name}_leaves`);
|
|
81
82
|
this.leafIndex = store.openMap(`tree_${name}_leaf_index`);
|
|
83
|
+
this.#snapshotBuilder = new IndexedTreeSnapshotBuilder(this.store, this, this.leafPreimageFactory);
|
|
82
84
|
}
|
|
83
85
|
|
|
84
86
|
/**
|
|
@@ -87,7 +89,7 @@ export class StandardIndexedTree extends TreeBase<Buffer> implements IndexedTree
|
|
|
87
89
|
* @returns Empty promise.
|
|
88
90
|
* @remarks Use batchInsert method instead.
|
|
89
91
|
*/
|
|
90
|
-
override appendLeaves(_leaves: Buffer[]):
|
|
92
|
+
override appendLeaves(_leaves: Buffer[]): void {
|
|
91
93
|
throw new Error('Not implemented');
|
|
92
94
|
}
|
|
93
95
|
|
|
@@ -217,7 +219,7 @@ export class StandardIndexedTree extends TreeBase<Buffer> implements IndexedTree
|
|
|
217
219
|
public getLatestLeafPreimageCopy(index: bigint, includeUncommitted: boolean): IndexedTreeLeafPreimage | undefined {
|
|
218
220
|
const preimage = !includeUncommitted
|
|
219
221
|
? this.getDbPreimage(index)
|
|
220
|
-
: this.getCachedPreimage(index) ?? this.getDbPreimage(index);
|
|
222
|
+
: (this.getCachedPreimage(index) ?? this.getDbPreimage(index));
|
|
221
223
|
return preimage && this.leafPreimageFactory.clone(preimage);
|
|
222
224
|
}
|
|
223
225
|
|
|
@@ -318,7 +320,6 @@ export class StandardIndexedTree extends TreeBase<Buffer> implements IndexedTree
|
|
|
318
320
|
}
|
|
319
321
|
}
|
|
320
322
|
|
|
321
|
-
/* eslint-disable jsdoc/require-description-complete-sentence */
|
|
322
323
|
/* The following doc block messes up with complete-sentence, so we just disable it */
|
|
323
324
|
|
|
324
325
|
/**
|
|
@@ -595,11 +596,11 @@ export class StandardIndexedTree extends TreeBase<Buffer> implements IndexedTree
|
|
|
595
596
|
return fullSiblingPath.getSubtreeSiblingPath(subtreeHeight);
|
|
596
597
|
}
|
|
597
598
|
|
|
598
|
-
snapshot(blockNumber:
|
|
599
|
+
snapshot(blockNumber: BlockNumber): Promise<IndexedTreeSnapshot> {
|
|
599
600
|
return this.#snapshotBuilder.snapshot(blockNumber);
|
|
600
601
|
}
|
|
601
602
|
|
|
602
|
-
getSnapshot(blockNumber:
|
|
603
|
+
getSnapshot(blockNumber: BlockNumber): Promise<IndexedTreeSnapshot> {
|
|
603
604
|
return this.#snapshotBuilder.getSnapshot(blockNumber);
|
|
604
605
|
}
|
|
605
606
|
|
|
@@ -12,12 +12,10 @@ export class StandardIndexedTreeWithAppend extends StandardIndexedTree {
|
|
|
12
12
|
* @returns Empty promise.
|
|
13
13
|
* @remarks This method is inefficient and is here mostly for testing. Use batchInsert instead.
|
|
14
14
|
*/
|
|
15
|
-
public override appendLeaves(leaves: Buffer[])
|
|
15
|
+
public override appendLeaves(leaves: Buffer[]) {
|
|
16
16
|
for (const leaf of leaves) {
|
|
17
17
|
this.appendLeaf(leaf);
|
|
18
18
|
}
|
|
19
|
-
|
|
20
|
-
return Promise.resolve();
|
|
21
19
|
}
|
|
22
20
|
|
|
23
21
|
private appendEmptyLeaf() {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { BlockNumber } from '@aztec/foundation/branded-types';
|
|
1
2
|
import { type Bufferable, serializeToBuffer } from '@aztec/foundation/serialize';
|
|
2
3
|
import { Timer } from '@aztec/foundation/timer';
|
|
3
4
|
import type { TreeInsertionStats } from '@aztec/stdlib/stats';
|
|
@@ -18,7 +19,7 @@ export class StandardTree<T extends Bufferable = Buffer> extends TreeBase<T> imp
|
|
|
18
19
|
* @param leaves - The leaves to append.
|
|
19
20
|
* @returns Empty promise.
|
|
20
21
|
*/
|
|
21
|
-
public override appendLeaves(leaves: T[]):
|
|
22
|
+
public override appendLeaves(leaves: T[]): void {
|
|
22
23
|
this.hasher.reset();
|
|
23
24
|
const timer = new Timer();
|
|
24
25
|
super.appendLeaves(leaves);
|
|
@@ -31,15 +32,13 @@ export class StandardTree<T extends Bufferable = Buffer> extends TreeBase<T> imp
|
|
|
31
32
|
treeType: 'append-only',
|
|
32
33
|
...this.hasher.stats(),
|
|
33
34
|
} satisfies TreeInsertionStats);
|
|
34
|
-
|
|
35
|
-
return Promise.resolve();
|
|
36
35
|
}
|
|
37
36
|
|
|
38
|
-
public snapshot(blockNumber:
|
|
37
|
+
public snapshot(blockNumber: BlockNumber): Promise<TreeSnapshot<T>> {
|
|
39
38
|
return this.#snapshotBuilder.snapshot(blockNumber);
|
|
40
39
|
}
|
|
41
40
|
|
|
42
|
-
public getSnapshot(blockNumber:
|
|
41
|
+
public getSnapshot(blockNumber: BlockNumber): Promise<TreeSnapshot<T>> {
|
|
43
42
|
return this.#snapshotBuilder.getSnapshot(blockNumber);
|
|
44
43
|
}
|
|
45
44
|
|
package/src/tree_base.ts
CHANGED
|
@@ -92,7 +92,7 @@ export abstract class TreeBase<T extends Bufferable> implements MerkleTree<T> {
|
|
|
92
92
|
* @returns The root of the tree.
|
|
93
93
|
*/
|
|
94
94
|
public getRoot(includeUncommitted: boolean): Buffer {
|
|
95
|
-
return !includeUncommitted ? this.root : this.cache[indexToKeyHash(this.name, 0, 0n)] ?? this.root;
|
|
95
|
+
return !includeUncommitted ? this.root : (this.cache[indexToKeyHash(this.name, 0, 0n)] ?? this.root);
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
/**
|
|
@@ -101,7 +101,7 @@ export abstract class TreeBase<T extends Bufferable> implements MerkleTree<T> {
|
|
|
101
101
|
* @returns The number of leaves in the tree.
|
|
102
102
|
*/
|
|
103
103
|
public getNumLeaves(includeUncommitted: boolean) {
|
|
104
|
-
return !includeUncommitted ? this.size : this.cachedSize ?? this.size;
|
|
104
|
+
return !includeUncommitted ? this.size : (this.cachedSize ?? this.size);
|
|
105
105
|
}
|
|
106
106
|
|
|
107
107
|
/**
|
package/dest/sha_256.d.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
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
|
package/dest/sha_256.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
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
|
-
}
|
package/src/sha_256.ts
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { sha256 } from '@aztec/foundation/crypto';
|
|
2
|
-
import { truncateAndPad } from '@aztec/foundation/serialize';
|
|
3
|
-
import type { Hasher } from '@aztec/foundation/trees';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* A helper class encapsulating SHA256 hash functionality.
|
|
7
|
-
* @deprecated Don't call SHA256 directly in production code. Instead, create suitably-named functions for specific
|
|
8
|
-
* purposes.
|
|
9
|
-
*/
|
|
10
|
-
export class SHA256 implements Hasher {
|
|
11
|
-
/*
|
|
12
|
-
* @deprecated Don't call SHA256 directly in production code. Instead, create suitably-named functions for specific
|
|
13
|
-
* purposes.
|
|
14
|
-
*/
|
|
15
|
-
public hash(lhs: Uint8Array, rhs: Uint8Array): Buffer {
|
|
16
|
-
return sha256(Buffer.concat([Buffer.from(lhs), Buffer.from(rhs)]));
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/*
|
|
20
|
-
* @deprecated Don't call SHA256 directly in production code. Instead, create suitably-named functions for specific
|
|
21
|
-
* purposes.
|
|
22
|
-
*/
|
|
23
|
-
public hashInputs(inputs: Buffer[]): Buffer {
|
|
24
|
-
return sha256(Buffer.concat(inputs));
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* A helper class encapsulating truncated SHA256 hash functionality.
|
|
30
|
-
* @deprecated Don't call SHA256 directly in production code. Instead, create suitably-named functions for specific
|
|
31
|
-
* purposes.
|
|
32
|
-
*/
|
|
33
|
-
export class SHA256Trunc implements Hasher {
|
|
34
|
-
/*
|
|
35
|
-
* @deprecated Don't call SHA256 directly in production code. Instead, create suitably-named functions for specific
|
|
36
|
-
* purposes.
|
|
37
|
-
*/
|
|
38
|
-
public hash(lhs: Uint8Array, rhs: Uint8Array): Buffer {
|
|
39
|
-
return truncateAndPad(sha256(Buffer.concat([Buffer.from(lhs), Buffer.from(rhs)])));
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/*
|
|
43
|
-
* @deprecated Don't call SHA256 directly in production code. Instead, create suitably-named functions for specific
|
|
44
|
-
* purposes.
|
|
45
|
-
*/
|
|
46
|
-
public hashInputs(inputs: Buffer[]): Buffer {
|
|
47
|
-
return truncateAndPad(sha256(Buffer.concat(inputs)));
|
|
48
|
-
}
|
|
49
|
-
}
|