@aztec/merkle-tree 0.1.0-alpha23 → 0.1.0-alpha40
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/.tsbuildinfo +1 -1
- package/dest/index.d.ts +0 -2
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -3
- package/dest/interfaces/indexed_tree.d.ts +2 -1
- package/dest/interfaces/indexed_tree.d.ts.map +1 -1
- package/dest/interfaces/merkle_tree.d.ts +1 -1
- package/dest/interfaces/merkle_tree.d.ts.map +1 -1
- package/dest/load_tree.d.ts +1 -1
- package/dest/load_tree.d.ts.map +1 -1
- package/dest/load_tree.js +1 -1
- package/dest/new_tree.d.ts +1 -1
- package/dest/new_tree.d.ts.map +1 -1
- package/dest/new_tree.js +1 -1
- package/dest/pedersen.d.ts +1 -28
- package/dest/pedersen.d.ts.map +1 -1
- package/dest/pedersen.js +1 -28
- package/dest/sparse_tree/sparse_tree.test.js +12 -11
- package/dest/standard_indexed_tree/standard_indexed_tree.d.ts +1 -1
- package/dest/standard_indexed_tree/standard_indexed_tree.d.ts.map +1 -1
- package/dest/standard_indexed_tree/standard_indexed_tree.js +4 -4
- package/dest/standard_indexed_tree/test/standard_indexed_tree.test.js +5 -6
- 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 +1 -1
- package/dest/standard_tree/standard_tree.test.js +4 -4
- package/dest/test/standard_based_test_suite.d.ts +1 -1
- package/dest/test/standard_based_test_suite.d.ts.map +1 -1
- package/dest/test/standard_based_test_suite.js +5 -4
- package/dest/test/test_suite.d.ts +1 -1
- package/dest/test/test_suite.d.ts.map +1 -1
- package/dest/test/test_suite.js +4 -3
- package/dest/test/utils/create_mem_down.d.ts +2 -2
- package/dest/test/utils/create_mem_down.d.ts.map +1 -1
- package/dest/test/utils/create_mem_down.js +1 -1
- package/dest/tree_base.d.ts +1 -2
- package/dest/tree_base.d.ts.map +1 -1
- package/dest/tree_base.js +2 -2
- package/package.json +4 -3
- package/src/index.ts +0 -2
- package/src/interfaces/indexed_tree.ts +3 -1
- package/src/interfaces/merkle_tree.ts +1 -1
- package/src/load_tree.ts +3 -1
- package/src/new_tree.ts +3 -1
- package/src/pedersen.ts +2 -29
- package/src/sparse_tree/sparse_tree.test.ts +15 -13
- package/src/standard_indexed_tree/standard_indexed_tree.ts +4 -3
- package/src/standard_indexed_tree/test/standard_indexed_tree.test.ts +7 -7
- package/src/standard_indexed_tree/test/standard_indexed_tree_with_append.ts +1 -0
- package/src/standard_tree/standard_tree.test.ts +6 -4
- package/src/test/standard_based_test_suite.ts +9 -6
- package/src/test/test_suite.ts +7 -4
- package/src/test/utils/create_mem_down.ts +1 -1
- package/src/tree_base.ts +4 -3
- package/tsconfig.json +3 -0
- package/dest/hasher.d.ts +0 -11
- package/dest/hasher.d.ts.map +0 -1
- package/dest/hasher.js +0 -2
- package/dest/sibling_path/sibling_path.d.ts +0 -92
- package/dest/sibling_path/sibling_path.d.ts.map +0 -1
- package/dest/sibling_path/sibling_path.js +0 -120
- package/src/hasher.ts +0 -9
- package/src/sibling_path/sibling_path.ts +0 -139
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import { assertLength, deserializeArrayFromVector, serializeBufferArrayToVector, } from '@aztec/foundation/serialize';
|
|
2
|
-
import { Fr } from '@aztec/foundation/fields';
|
|
3
|
-
/**
|
|
4
|
-
* Contains functionality to compute and serialize/deserialize a sibling path.
|
|
5
|
-
* E.g. Sibling path for a leaf at index 3 in a tree of depth 3 consists of:
|
|
6
|
-
* d0: [ root ]
|
|
7
|
-
* d1: [ ] [*]
|
|
8
|
-
* d2: [*] [ ] [ ] [ ]
|
|
9
|
-
* d3: [ ] [ ] [*] [ ] [ ] [ ] [ ] [ ].
|
|
10
|
-
*
|
|
11
|
-
* And the elements would be ordered as: [ leaf_at_index_2, node_at_level_2_index_0, node_at_level_1_index_1 ].
|
|
12
|
-
*/
|
|
13
|
-
export class SiblingPath {
|
|
14
|
-
/**
|
|
15
|
-
* Returns sibling path hashed up from the a element.
|
|
16
|
-
* @param size - The number of elements in a given path.
|
|
17
|
-
* @param zeroElement - Value of the zero element.
|
|
18
|
-
* @param pedersen - Implementation of a hasher interface using the Pedersen hash.
|
|
19
|
-
* @returns A sibling path hashed up from a zero element.
|
|
20
|
-
*/
|
|
21
|
-
static ZERO(size, zeroElement, pedersen) {
|
|
22
|
-
const bufs = [];
|
|
23
|
-
let current = zeroElement;
|
|
24
|
-
for (let i = 0; i < size; ++i) {
|
|
25
|
-
bufs.push(current);
|
|
26
|
-
current = pedersen.compress(current, current);
|
|
27
|
-
}
|
|
28
|
-
return new SiblingPath(size, bufs);
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Constructor.
|
|
32
|
-
* @param pathSize - The size of the sibling path.
|
|
33
|
-
* @param path - The sibling path data.
|
|
34
|
-
*/
|
|
35
|
-
constructor(
|
|
36
|
-
/**
|
|
37
|
-
* Size of the sibling path (number of fields it contains).
|
|
38
|
-
*/
|
|
39
|
-
pathSize,
|
|
40
|
-
/**
|
|
41
|
-
* The sibling path data.
|
|
42
|
-
*/
|
|
43
|
-
path) {
|
|
44
|
-
this.pathSize = pathSize;
|
|
45
|
-
this.data = assertLength(path, pathSize);
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Serializes this SiblingPath object to a buffer.
|
|
49
|
-
* @returns The buffer representation of this object.
|
|
50
|
-
*/
|
|
51
|
-
toBuffer() {
|
|
52
|
-
return serializeBufferArrayToVector(this.data);
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Returns the path buffer underlying the sibling path.
|
|
56
|
-
* @returns The Buffer array representation of this object.
|
|
57
|
-
*/
|
|
58
|
-
toBufferArray() {
|
|
59
|
-
return this.data;
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Convert the Sibling Path object into an array of field elements.
|
|
63
|
-
* @returns The field array representation of this object.
|
|
64
|
-
*/
|
|
65
|
-
toFieldArray() {
|
|
66
|
-
return this.data.map(buf => Fr.fromBuffer(buf));
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Deserializes a SiblingPath from a buffer.
|
|
70
|
-
* @param buf - A buffer containing the buffer representation of SiblingPath.
|
|
71
|
-
* @param offset - An offset to start deserializing from.
|
|
72
|
-
* @returns A SiblingPath object.
|
|
73
|
-
*/
|
|
74
|
-
static fromBuffer(buf, offset = 0) {
|
|
75
|
-
const { elem } = SiblingPath.deserialize(buf, offset);
|
|
76
|
-
return elem;
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Deserializes a SiblingPath object from a slice of a part of a buffer and returns the amount of bytes advanced.
|
|
80
|
-
* @param buf - A buffer representation of the sibling path.
|
|
81
|
-
* @param offset - An offset to start deserializing from.
|
|
82
|
-
* @returns The deserialized sibling path and the number of bytes advanced.
|
|
83
|
-
*/
|
|
84
|
-
static deserialize(buf, offset = 0) {
|
|
85
|
-
const deserializePath = (buf, offset) => ({
|
|
86
|
-
elem: buf.slice(offset, offset + 32),
|
|
87
|
-
adv: 32,
|
|
88
|
-
});
|
|
89
|
-
const { elem, adv } = deserializeArrayFromVector(deserializePath, buf, offset);
|
|
90
|
-
const size = elem.length;
|
|
91
|
-
return { elem: new SiblingPath(size, elem), adv };
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Serializes this SiblingPath object to a hex string representation.
|
|
95
|
-
* @returns A hex string representation of the sibling path.
|
|
96
|
-
*/
|
|
97
|
-
toString() {
|
|
98
|
-
return this.toBuffer().toString('hex');
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Deserializes a SiblingPath object from a hex string representation.
|
|
102
|
-
* @param repr - A hex string representation of the sibling path.
|
|
103
|
-
* @returns A SiblingPath object.
|
|
104
|
-
*/
|
|
105
|
-
static fromString(repr) {
|
|
106
|
-
return SiblingPath.fromBuffer(Buffer.from(repr, 'hex'));
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* Generate a subtree path from the current sibling path.
|
|
110
|
-
* @param subtreeHeight - The size of the subtree that we are getting the path for.
|
|
111
|
-
* @returns A new sibling path that is the for the requested subtree.
|
|
112
|
-
*/
|
|
113
|
-
getSubtreeSiblingPath(subtreeHeight) {
|
|
114
|
-
// Drop the size of the subtree from the path, and return the rest.
|
|
115
|
-
const subtreeData = this.data.slice(subtreeHeight);
|
|
116
|
-
const subtreePathSize = (this.pathSize - subtreeHeight);
|
|
117
|
-
return new SiblingPath(subtreePathSize, subtreeData);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2libGluZ19wYXRoLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL3NpYmxpbmdfcGF0aC9zaWJsaW5nX3BhdGgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUVMLFlBQVksRUFDWiwwQkFBMEIsRUFDMUIsNEJBQTRCLEdBQzdCLE1BQU0sNkJBQTZCLENBQUM7QUFFckMsT0FBTyxFQUFFLEVBQUUsRUFBRSxNQUFNLDBCQUEwQixDQUFDO0FBRTlDOzs7Ozs7Ozs7R0FTRztBQUNILE1BQU0sT0FBTyxXQUFXO0lBR3RCOzs7Ozs7T0FNRztJQUNJLE1BQU0sQ0FBQyxJQUFJLENBQW1CLElBQU8sRUFBRSxXQUFtQixFQUFFLFFBQWtCO1FBQ25GLE1BQU0sSUFBSSxHQUFhLEVBQUUsQ0FBQztRQUMxQixJQUFJLE9BQU8sR0FBRyxXQUFXLENBQUM7UUFDMUIsS0FBSyxJQUFJLENBQUMsR0FBRyxDQUFDLEVBQUUsQ0FBQyxHQUFHLElBQUksRUFBRSxFQUFFLENBQUMsRUFBRTtZQUM3QixJQUFJLENBQUMsSUFBSSxDQUFDLE9BQU8sQ0FBQ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UFBUSxHQUFHLGFBQWEsQ0FBNkIsQ0FBQztRQUNwRixPQUFPLElBQUksV0FBVyxDQUFDLGVBQWUsRUFBRSxXQUFXLENBQUMsQ0FBQztJQUN2RCxDQUFDO0NBQ0YifQ==
|
package/src/hasher.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Defines hasher interface used by Merkle trees.
|
|
3
|
-
*/
|
|
4
|
-
export interface Hasher {
|
|
5
|
-
compress(lhs: Uint8Array, rhs: Uint8Array): Buffer;
|
|
6
|
-
compressInputs(inputs: Buffer[]): Buffer;
|
|
7
|
-
hashToField(data: Uint8Array): Buffer;
|
|
8
|
-
hashToTree(leaves: Buffer[]): Promise<Buffer[]>;
|
|
9
|
-
}
|
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Tuple,
|
|
3
|
-
assertLength,
|
|
4
|
-
deserializeArrayFromVector,
|
|
5
|
-
serializeBufferArrayToVector,
|
|
6
|
-
} from '@aztec/foundation/serialize';
|
|
7
|
-
import { Pedersen } from '../pedersen.js';
|
|
8
|
-
import { Fr } from '@aztec/foundation/fields';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Contains functionality to compute and serialize/deserialize a sibling path.
|
|
12
|
-
* E.g. Sibling path for a leaf at index 3 in a tree of depth 3 consists of:
|
|
13
|
-
* d0: [ root ]
|
|
14
|
-
* d1: [ ] [*]
|
|
15
|
-
* d2: [*] [ ] [ ] [ ]
|
|
16
|
-
* d3: [ ] [ ] [*] [ ] [ ] [ ] [ ] [ ].
|
|
17
|
-
*
|
|
18
|
-
* And the elements would be ordered as: [ leaf_at_index_2, node_at_level_2_index_0, node_at_level_1_index_1 ].
|
|
19
|
-
*/
|
|
20
|
-
export class SiblingPath<N extends number> {
|
|
21
|
-
private data: Tuple<Buffer, N>;
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Returns sibling path hashed up from the a element.
|
|
25
|
-
* @param size - The number of elements in a given path.
|
|
26
|
-
* @param zeroElement - Value of the zero element.
|
|
27
|
-
* @param pedersen - Implementation of a hasher interface using the Pedersen hash.
|
|
28
|
-
* @returns A sibling path hashed up from a zero element.
|
|
29
|
-
*/
|
|
30
|
-
public static ZERO<N extends number>(size: N, zeroElement: Buffer, pedersen: Pedersen): SiblingPath<N> {
|
|
31
|
-
const bufs: Buffer[] = [];
|
|
32
|
-
let current = zeroElement;
|
|
33
|
-
for (let i = 0; i < size; ++i) {
|
|
34
|
-
bufs.push(current);
|
|
35
|
-
current = pedersen.compress(current, current);
|
|
36
|
-
}
|
|
37
|
-
return new SiblingPath(size, bufs);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Constructor.
|
|
42
|
-
* @param pathSize - The size of the sibling path.
|
|
43
|
-
* @param path - The sibling path data.
|
|
44
|
-
*/
|
|
45
|
-
constructor(
|
|
46
|
-
/**
|
|
47
|
-
* Size of the sibling path (number of fields it contains).
|
|
48
|
-
*/
|
|
49
|
-
public pathSize: N,
|
|
50
|
-
/**
|
|
51
|
-
* The sibling path data.
|
|
52
|
-
*/
|
|
53
|
-
path: Buffer[],
|
|
54
|
-
) {
|
|
55
|
-
this.data = assertLength(path, pathSize);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Serializes this SiblingPath object to a buffer.
|
|
60
|
-
* @returns The buffer representation of this object.
|
|
61
|
-
*/
|
|
62
|
-
public toBuffer(): Buffer {
|
|
63
|
-
return serializeBufferArrayToVector(this.data);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Returns the path buffer underlying the sibling path.
|
|
68
|
-
* @returns The Buffer array representation of this object.
|
|
69
|
-
*/
|
|
70
|
-
public toBufferArray(): Buffer[] {
|
|
71
|
-
return this.data;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Convert the Sibling Path object into an array of field elements.
|
|
76
|
-
* @returns The field array representation of this object.
|
|
77
|
-
*/
|
|
78
|
-
public toFieldArray(): Fr[] {
|
|
79
|
-
return this.data.map(buf => Fr.fromBuffer(buf));
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Deserializes a SiblingPath from a buffer.
|
|
84
|
-
* @param buf - A buffer containing the buffer representation of SiblingPath.
|
|
85
|
-
* @param offset - An offset to start deserializing from.
|
|
86
|
-
* @returns A SiblingPath object.
|
|
87
|
-
*/
|
|
88
|
-
static fromBuffer<N extends number>(buf: Buffer, offset = 0): SiblingPath<N> {
|
|
89
|
-
const { elem } = SiblingPath.deserialize<N>(buf, offset);
|
|
90
|
-
return elem;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Deserializes a SiblingPath object from a slice of a part of a buffer and returns the amount of bytes advanced.
|
|
95
|
-
* @param buf - A buffer representation of the sibling path.
|
|
96
|
-
* @param offset - An offset to start deserializing from.
|
|
97
|
-
* @returns The deserialized sibling path and the number of bytes advanced.
|
|
98
|
-
*/
|
|
99
|
-
static deserialize<N extends number>(buf: Buffer, offset = 0) {
|
|
100
|
-
const deserializePath = (buf: Buffer, offset: number) => ({
|
|
101
|
-
elem: buf.slice(offset, offset + 32),
|
|
102
|
-
adv: 32,
|
|
103
|
-
});
|
|
104
|
-
const { elem, adv } = deserializeArrayFromVector(deserializePath, buf, offset);
|
|
105
|
-
const size = elem.length;
|
|
106
|
-
return { elem: new SiblingPath<N>(size as N, elem), adv };
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* Serializes this SiblingPath object to a hex string representation.
|
|
111
|
-
* @returns A hex string representation of the sibling path.
|
|
112
|
-
*/
|
|
113
|
-
public toString(): string {
|
|
114
|
-
return this.toBuffer().toString('hex');
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Deserializes a SiblingPath object from a hex string representation.
|
|
119
|
-
* @param repr - A hex string representation of the sibling path.
|
|
120
|
-
* @returns A SiblingPath object.
|
|
121
|
-
*/
|
|
122
|
-
public static fromString<N extends number>(repr: string): SiblingPath<N> {
|
|
123
|
-
return SiblingPath.fromBuffer<N>(Buffer.from(repr, 'hex'));
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* Generate a subtree path from the current sibling path.
|
|
128
|
-
* @param subtreeHeight - The size of the subtree that we are getting the path for.
|
|
129
|
-
* @returns A new sibling path that is the for the requested subtree.
|
|
130
|
-
*/
|
|
131
|
-
public getSubtreeSiblingPath<SubtreeHeight extends number, SubtreeSiblingPathHeight extends number>(
|
|
132
|
-
subtreeHeight: SubtreeHeight,
|
|
133
|
-
): SiblingPath<SubtreeSiblingPathHeight> {
|
|
134
|
-
// Drop the size of the subtree from the path, and return the rest.
|
|
135
|
-
const subtreeData = this.data.slice(subtreeHeight);
|
|
136
|
-
const subtreePathSize = (this.pathSize - subtreeHeight) as SubtreeSiblingPathHeight;
|
|
137
|
-
return new SiblingPath(subtreePathSize, subtreeData);
|
|
138
|
-
}
|
|
139
|
-
}
|