@osmura/merkletreejs 0.6.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.
@@ -0,0 +1,255 @@
1
+ /// <reference types="node" />
2
+ import { MerkleTree, Options } from './MerkleTree';
3
+ export declare type Leaf = Buffer | string | number | BigInt;
4
+ export declare type LeafData = Buffer;
5
+ export declare type HashFunction = (data: any) => Buffer;
6
+ export declare type Proof = {
7
+ position: 'left' | 'right';
8
+ data: Buffer;
9
+ }[];
10
+ export declare type HexProof = string[];
11
+ /**
12
+ * Creates a Merkle tree from an array of leaves
13
+ * @param leaves - Array of leaves (strings, buffers, objects, etc.)
14
+ * @param hashFn - Optional hash function (defaults to SHA256)
15
+ * @param options - Merkle tree options
16
+ * @returns MerkleTree instance
17
+ */
18
+ export declare function createMerkleTree(leaves: LeafData[], hashFn?: HashFunction, options?: Options): MerkleTree;
19
+ /**
20
+ * Gets the root hash of a Merkle tree as hex string
21
+ * @param tree - MerkleTree instance
22
+ * @returns Root hash as hex string
23
+ */
24
+ export declare function getHexRoot(tree: MerkleTree): string;
25
+ /**
26
+ * Gets the root hash of a Merkle tree as Buffer
27
+ * @param tree - MerkleTree instance
28
+ * @returns Root hash as Buffer
29
+ */
30
+ export declare function getRoot(tree: MerkleTree): Buffer;
31
+ /**
32
+ * Adds a leaf to an existing Merkle tree
33
+ * @param tree - MerkleTree instance
34
+ * @param leaf - Leaf to add
35
+ * @param options - Options object with shouldHash property
36
+ * @returns Updated MerkleTree instance
37
+ */
38
+ export declare function addLeaf(tree: MerkleTree, leaf: LeafData, options?: {
39
+ shouldHash?: boolean;
40
+ }): MerkleTree;
41
+ /**
42
+ * Adds multiple leaves to an existing Merkle tree
43
+ * @param tree - MerkleTree instance
44
+ * @param leaves - Array of leaves to add
45
+ * @param options - Options object with shouldHash property
46
+ * @returns Updated MerkleTree instance
47
+ */
48
+ export declare function addLeaves(tree: MerkleTree, leaves: LeafData[], options?: {
49
+ shouldHash?: boolean;
50
+ }): MerkleTree;
51
+ /**
52
+ * Gets a proof for a specific leaf
53
+ * @param tree - MerkleTree instance
54
+ * @param leaf - Target leaf
55
+ * @param index - Optional leaf index (for duplicate leaves)
56
+ * @returns Proof as array of objects with position and data
57
+ */
58
+ export declare function getProof(tree: MerkleTree, leaf: LeafData, index?: number): Proof;
59
+ /**
60
+ * Gets a proof for a specific leaf as hex strings
61
+ * @param tree - MerkleTree instance
62
+ * @param leaf - Target leaf
63
+ * @param index - Optional leaf index (for duplicate leaves)
64
+ * @returns Proof as array of hex strings
65
+ */
66
+ export declare function getHexProof(tree: MerkleTree, leaf: LeafData, index?: number): HexProof;
67
+ /**
68
+ * Verifies a proof against a root and target leaf
69
+ * @param proof - Proof array
70
+ * @param leaf - Target leaf
71
+ * @param root - Merkle root
72
+ * @param hashFn - Hash function used to create the tree
73
+ * @param options - Options used to create the tree
74
+ * @returns Boolean indicating if proof is valid
75
+ */
76
+ export declare function verifyProof(proof: Proof | HexProof, leaf: LeafData, root: string | Buffer, hashFn?: HashFunction, options?: Options): boolean;
77
+ /**
78
+ * Gets all leaves from a Merkle tree
79
+ * @param tree - MerkleTree instance
80
+ * @returns Array of leaves as Buffers
81
+ */
82
+ export declare function getLeaves(tree: MerkleTree): Buffer[];
83
+ /**
84
+ * Gets all leaves from a Merkle tree as hex strings
85
+ * @param tree - MerkleTree instance
86
+ * @returns Array of leaves as hex strings
87
+ */
88
+ export declare function getHexLeaves(tree: MerkleTree): string[];
89
+ /**
90
+ * Gets a leaf from a Merkle tree as hex string
91
+ * @param tree - MerkleTree instance
92
+ * @param index - Leaf index
93
+ * @returns Leaf as hex string
94
+ */
95
+ export declare function getHexLeaf(tree: MerkleTree, index: number): string;
96
+ /**
97
+ * Gets the leaf count
98
+ * @param tree - MerkleTree instance
99
+ * @returns Number of leaves
100
+ */
101
+ export declare function getLeafCount(tree: MerkleTree): number;
102
+ /**
103
+ * Gets a specific leaf by index
104
+ * @param tree - MerkleTree instance
105
+ * @param index - Leaf index
106
+ * @returns Leaf as Buffer
107
+ */
108
+ export declare function getLeaf(tree: MerkleTree, index: number): Buffer;
109
+ /**
110
+ * Gets the index of a specific leaf
111
+ * @param tree - MerkleTree instance
112
+ * @param leaf - Target leaf
113
+ * @returns Leaf index or -1 if not found
114
+ */
115
+ export declare function getLeafIndex(tree: MerkleTree, leaf: LeafData): number;
116
+ /**
117
+ * Removes a leaf by index
118
+ * @param tree - MerkleTree instance
119
+ * @param index - Leaf index to remove
120
+ * @returns Removed leaf as Buffer
121
+ */
122
+ export declare function removeLeaf(tree: MerkleTree, index: number): Buffer;
123
+ /**
124
+ * Updates a leaf at a specific index
125
+ * @param tree - MerkleTree instance
126
+ * @param index - Leaf index to update
127
+ * @param value - New leaf value
128
+ * @param options - Options object with shouldHash property
129
+ */
130
+ export declare function updateLeaf(tree: MerkleTree, index: number, value: LeafData, options?: {
131
+ shouldHash?: boolean;
132
+ }): void;
133
+ /**
134
+ * Gets all proofs for all leaves
135
+ * @param tree - MerkleTree instance
136
+ * @returns Array of all proofs
137
+ */
138
+ export declare function getProofs(tree: MerkleTree): Proof[];
139
+ /**
140
+ * Gets all proofs for all leaves as hex strings
141
+ * @param tree - MerkleTree instance
142
+ * @returns Array of all proofs as hex strings
143
+ */
144
+ export declare function getHexProofs(tree: MerkleTree): string[];
145
+ /**
146
+ * Gets multiproof for multiple indices
147
+ * @param tree - MerkleTree instance
148
+ * @param indices - Array of leaf indices
149
+ * @returns Multiproof as array of Buffers
150
+ */
151
+ export declare function getMultiProof(tree: MerkleTree, indices: number[]): Buffer[];
152
+ /**
153
+ * Gets multiproof for multiple indices as hex strings
154
+ * @param tree - MerkleTree instance
155
+ * @param indices - Array of leaf indices
156
+ * @returns Multiproof as array of hex strings
157
+ */
158
+ export declare function getHexMultiProof(tree: MerkleTree, indices: number[]): string[];
159
+ /**
160
+ * Verifies a multiproof
161
+ * @param root - Merkle root
162
+ * @param proofIndices - Leaf indices for proof
163
+ * @param proofLeaves - Leaf values at indices
164
+ * @param leavesCount - Total number of leaves
165
+ * @param proof - Multiproof
166
+ * @param hashFn - Hash function
167
+ * @param options - Tree options
168
+ * @returns Boolean indicating if multiproof is valid
169
+ */
170
+ export declare function verifyMultiProof(root: string | Buffer, proofIndices: number[], proofLeaves: LeafData[], leavesCount: number, proof: Buffer[] | string[], hashFn?: HashFunction, options?: Options): boolean;
171
+ /**
172
+ * Gets the tree depth
173
+ * @param tree - MerkleTree instance
174
+ * @returns Tree depth (number of layers - 1)
175
+ */
176
+ export declare function getDepth(tree: MerkleTree): number;
177
+ /**
178
+ * Gets all layers of the tree
179
+ * @param tree - MerkleTree instance
180
+ * @returns Array of layers as Buffers
181
+ */
182
+ export declare function getLayers(tree: MerkleTree): Buffer[][];
183
+ /**
184
+ * Gets all layers of the tree as hex strings
185
+ * @param tree - MerkleTree instance
186
+ * @returns Array of layers as hex strings
187
+ */
188
+ export declare function getHexLayers(tree: MerkleTree): string[][];
189
+ /**
190
+ * Gets flattened layers
191
+ * @param tree - MerkleTree instance
192
+ * @returns Flattened array of all nodes
193
+ */
194
+ export declare function getLayersFlat(tree: MerkleTree): Buffer[];
195
+ /**
196
+ * Gets flattened layers as hex strings
197
+ * @param tree - MerkleTree instance
198
+ * @returns Flattened array of all nodes as hex strings
199
+ */
200
+ export declare function getHexLayersFlat(tree: MerkleTree): string[];
201
+ /**
202
+ * Resets the tree by clearing all leaves and layers
203
+ * @param tree - MerkleTree instance
204
+ */
205
+ export declare function resetTree(tree: MerkleTree): void;
206
+ /**
207
+ * Gets tree options
208
+ * @param tree - MerkleTree instance
209
+ * @returns Tree options object
210
+ */
211
+ export declare function getOptions(tree: MerkleTree): Options;
212
+ /**
213
+ * Converts tree to string representation
214
+ * @param tree - MerkleTree instance
215
+ * @returns String representation of the tree
216
+ */
217
+ export declare function treeToString(tree: MerkleTree): string;
218
+ /**
219
+ * Marshals leaves to JSON string
220
+ * @param leaves - Array of leaves
221
+ * @returns JSON string representation
222
+ */
223
+ export declare function marshalLeaves(leaves: LeafData[]): string;
224
+ /**
225
+ * Unmarshals leaves from JSON string
226
+ * @param jsonStr - JSON string or object
227
+ * @returns Array of leaves as Buffers
228
+ */
229
+ export declare function unmarshalLeaves(jsonStr: string | object): Buffer[];
230
+ /**
231
+ * Marshals proof to JSON string
232
+ * @param proof - Proof array
233
+ * @returns JSON string representation
234
+ */
235
+ export declare function marshalProof(proof: Proof | HexProof): string;
236
+ /**
237
+ * Unmarshals proof from JSON string
238
+ * @param jsonStr - JSON string or object
239
+ * @returns Proof array
240
+ */
241
+ export declare function unmarshalProof(jsonStr: string | object): Proof;
242
+ /**
243
+ * Marshals entire tree to JSON string
244
+ * @param tree - MerkleTree instance
245
+ * @returns JSON string representation of the tree
246
+ */
247
+ export declare function marshalTree(tree: MerkleTree): string;
248
+ /**
249
+ * Unmarshals tree from JSON string
250
+ * @param jsonStr - JSON string or object
251
+ * @param hashFn - Hash function
252
+ * @param options - Tree options
253
+ * @returns MerkleTree instance
254
+ */
255
+ export declare function unmarshalTree(jsonStr: string | object, hashFn?: HashFunction, options?: Options): MerkleTree;
@@ -0,0 +1,360 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.unmarshalTree = exports.marshalTree = exports.unmarshalProof = exports.marshalProof = exports.unmarshalLeaves = exports.marshalLeaves = exports.treeToString = exports.getOptions = exports.resetTree = exports.getHexLayersFlat = exports.getLayersFlat = exports.getHexLayers = exports.getLayers = exports.getDepth = exports.verifyMultiProof = exports.getHexMultiProof = exports.getMultiProof = exports.getHexProofs = exports.getProofs = exports.updateLeaf = exports.removeLeaf = exports.getLeafIndex = exports.getLeaf = exports.getLeafCount = exports.getHexLeaf = exports.getHexLeaves = exports.getLeaves = exports.verifyProof = exports.getHexProof = exports.getProof = exports.addLeaves = exports.addLeaf = exports.getRoot = exports.getHexRoot = exports.createMerkleTree = void 0;
7
+ // eslint-disable-next-line no-unused-vars
8
+ const MerkleTree_1 = require("./MerkleTree");
9
+ const sha256_1 = __importDefault(require("crypto-js/sha256"));
10
+ // Default hash function
11
+ const defaultHashFn = sha256_1.default;
12
+ /**
13
+ * Creates a Merkle tree from an array of leaves
14
+ * @param leaves - Array of leaves (strings, buffers, objects, etc.)
15
+ * @param hashFn - Optional hash function (defaults to SHA256)
16
+ * @param options - Merkle tree options
17
+ * @returns MerkleTree instance
18
+ */
19
+ function createMerkleTree(leaves, hashFn = defaultHashFn, options = {}) {
20
+ return new MerkleTree_1.MerkleTree(leaves, hashFn, options);
21
+ }
22
+ exports.createMerkleTree = createMerkleTree;
23
+ /**
24
+ * Gets the root hash of a Merkle tree as hex string
25
+ * @param tree - MerkleTree instance
26
+ * @returns Root hash as hex string
27
+ */
28
+ function getHexRoot(tree) {
29
+ return tree.getHexRoot();
30
+ }
31
+ exports.getHexRoot = getHexRoot;
32
+ /**
33
+ * Gets the root hash of a Merkle tree as Buffer
34
+ * @param tree - MerkleTree instance
35
+ * @returns Root hash as Buffer
36
+ */
37
+ function getRoot(tree) {
38
+ return tree.getRoot();
39
+ }
40
+ exports.getRoot = getRoot;
41
+ /**
42
+ * Adds a leaf to an existing Merkle tree
43
+ * @param tree - MerkleTree instance
44
+ * @param leaf - Leaf to add
45
+ * @param options - Options object with shouldHash property
46
+ * @returns Updated MerkleTree instance
47
+ */
48
+ function addLeaf(tree, leaf, options = {}) {
49
+ tree.addLeaf(leaf, options.shouldHash || false);
50
+ return tree;
51
+ }
52
+ exports.addLeaf = addLeaf;
53
+ /**
54
+ * Adds multiple leaves to an existing Merkle tree
55
+ * @param tree - MerkleTree instance
56
+ * @param leaves - Array of leaves to add
57
+ * @param options - Options object with shouldHash property
58
+ * @returns Updated MerkleTree instance
59
+ */
60
+ function addLeaves(tree, leaves, options = {}) {
61
+ tree.addLeaves(leaves, options.shouldHash || false);
62
+ return tree;
63
+ }
64
+ exports.addLeaves = addLeaves;
65
+ /**
66
+ * Gets a proof for a specific leaf
67
+ * @param tree - MerkleTree instance
68
+ * @param leaf - Target leaf
69
+ * @param index - Optional leaf index (for duplicate leaves)
70
+ * @returns Proof as array of objects with position and data
71
+ */
72
+ function getProof(tree, leaf, index) {
73
+ return tree.getProof(leaf, index);
74
+ }
75
+ exports.getProof = getProof;
76
+ /**
77
+ * Gets a proof for a specific leaf as hex strings
78
+ * @param tree - MerkleTree instance
79
+ * @param leaf - Target leaf
80
+ * @param index - Optional leaf index (for duplicate leaves)
81
+ * @returns Proof as array of hex strings
82
+ */
83
+ function getHexProof(tree, leaf, index) {
84
+ return tree.getHexProof(leaf, index);
85
+ }
86
+ exports.getHexProof = getHexProof;
87
+ /**
88
+ * Verifies a proof against a root and target leaf
89
+ * @param proof - Proof array
90
+ * @param leaf - Target leaf
91
+ * @param root - Merkle root
92
+ * @param hashFn - Hash function used to create the tree
93
+ * @param options - Options used to create the tree
94
+ * @returns Boolean indicating if proof is valid
95
+ */
96
+ function verifyProof(proof, leaf, root, hashFn = defaultHashFn, options = {}) {
97
+ return MerkleTree_1.MerkleTree.verify(proof, leaf, root, hashFn, options);
98
+ }
99
+ exports.verifyProof = verifyProof;
100
+ /**
101
+ * Gets all leaves from a Merkle tree
102
+ * @param tree - MerkleTree instance
103
+ * @returns Array of leaves as Buffers
104
+ */
105
+ function getLeaves(tree) {
106
+ return tree.getLeaves();
107
+ }
108
+ exports.getLeaves = getLeaves;
109
+ /**
110
+ * Gets all leaves from a Merkle tree as hex strings
111
+ * @param tree - MerkleTree instance
112
+ * @returns Array of leaves as hex strings
113
+ */
114
+ function getHexLeaves(tree) {
115
+ return tree.getHexLeaves();
116
+ }
117
+ exports.getHexLeaves = getHexLeaves;
118
+ /**
119
+ * Gets a leaf from a Merkle tree as hex string
120
+ * @param tree - MerkleTree instance
121
+ * @param index - Leaf index
122
+ * @returns Leaf as hex string
123
+ */
124
+ function getHexLeaf(tree, index) {
125
+ return tree.getHexLeaf(index);
126
+ }
127
+ exports.getHexLeaf = getHexLeaf;
128
+ /**
129
+ * Gets the leaf count
130
+ * @param tree - MerkleTree instance
131
+ * @returns Number of leaves
132
+ */
133
+ function getLeafCount(tree) {
134
+ return tree.getLeafCount();
135
+ }
136
+ exports.getLeafCount = getLeafCount;
137
+ /**
138
+ * Gets a specific leaf by index
139
+ * @param tree - MerkleTree instance
140
+ * @param index - Leaf index
141
+ * @returns Leaf as Buffer
142
+ */
143
+ function getLeaf(tree, index) {
144
+ return tree.getLeaf(index);
145
+ }
146
+ exports.getLeaf = getLeaf;
147
+ /**
148
+ * Gets the index of a specific leaf
149
+ * @param tree - MerkleTree instance
150
+ * @param leaf - Target leaf
151
+ * @returns Leaf index or -1 if not found
152
+ */
153
+ function getLeafIndex(tree, leaf) {
154
+ return tree.getLeafIndex(leaf);
155
+ }
156
+ exports.getLeafIndex = getLeafIndex;
157
+ /**
158
+ * Removes a leaf by index
159
+ * @param tree - MerkleTree instance
160
+ * @param index - Leaf index to remove
161
+ * @returns Removed leaf as Buffer
162
+ */
163
+ function removeLeaf(tree, index) {
164
+ return tree.removeLeaf(index);
165
+ }
166
+ exports.removeLeaf = removeLeaf;
167
+ /**
168
+ * Updates a leaf at a specific index
169
+ * @param tree - MerkleTree instance
170
+ * @param index - Leaf index to update
171
+ * @param value - New leaf value
172
+ * @param options - Options object with shouldHash property
173
+ */
174
+ function updateLeaf(tree, index, value, options = {}) {
175
+ tree.updateLeaf(index, value, options.shouldHash || false);
176
+ }
177
+ exports.updateLeaf = updateLeaf;
178
+ /**
179
+ * Gets all proofs for all leaves
180
+ * @param tree - MerkleTree instance
181
+ * @returns Array of all proofs
182
+ */
183
+ function getProofs(tree) {
184
+ return tree.getProofs();
185
+ }
186
+ exports.getProofs = getProofs;
187
+ /**
188
+ * Gets all proofs for all leaves as hex strings
189
+ * @param tree - MerkleTree instance
190
+ * @returns Array of all proofs as hex strings
191
+ */
192
+ function getHexProofs(tree) {
193
+ return tree.getHexProofs();
194
+ }
195
+ exports.getHexProofs = getHexProofs;
196
+ /**
197
+ * Gets multiproof for multiple indices
198
+ * @param tree - MerkleTree instance
199
+ * @param indices - Array of leaf indices
200
+ * @returns Multiproof as array of Buffers
201
+ */
202
+ function getMultiProof(tree, indices) {
203
+ return tree.getMultiProof(indices);
204
+ }
205
+ exports.getMultiProof = getMultiProof;
206
+ /**
207
+ * Gets multiproof for multiple indices as hex strings
208
+ * @param tree - MerkleTree instance
209
+ * @param indices - Array of leaf indices
210
+ * @returns Multiproof as array of hex strings
211
+ */
212
+ function getHexMultiProof(tree, indices) {
213
+ return tree.getHexMultiProof(tree.getLayersFlat(), indices);
214
+ }
215
+ exports.getHexMultiProof = getHexMultiProof;
216
+ /**
217
+ * Verifies a multiproof
218
+ * @param root - Merkle root
219
+ * @param proofIndices - Leaf indices for proof
220
+ * @param proofLeaves - Leaf values at indices
221
+ * @param leavesCount - Total number of leaves
222
+ * @param proof - Multiproof
223
+ * @param hashFn - Hash function
224
+ * @param options - Tree options
225
+ * @returns Boolean indicating if multiproof is valid
226
+ */
227
+ function verifyMultiProof(root, proofIndices, proofLeaves, leavesCount, proof, hashFn = defaultHashFn, options = {}) {
228
+ const tree = new MerkleTree_1.MerkleTree([], hashFn, options);
229
+ return tree.verifyMultiProof(root, proofIndices, proofLeaves, leavesCount, proof);
230
+ }
231
+ exports.verifyMultiProof = verifyMultiProof;
232
+ // Note: getProofFlags function removed due to compilation issue with the underlying method
233
+ // The getProofFlags method exists in the source but is not being compiled correctly
234
+ /**
235
+ * Gets the tree depth
236
+ * @param tree - MerkleTree instance
237
+ * @returns Tree depth (number of layers - 1)
238
+ */
239
+ function getDepth(tree) {
240
+ return tree.getDepth();
241
+ }
242
+ exports.getDepth = getDepth;
243
+ /**
244
+ * Gets all layers of the tree
245
+ * @param tree - MerkleTree instance
246
+ * @returns Array of layers as Buffers
247
+ */
248
+ function getLayers(tree) {
249
+ return tree.getLayers();
250
+ }
251
+ exports.getLayers = getLayers;
252
+ /**
253
+ * Gets all layers of the tree as hex strings
254
+ * @param tree - MerkleTree instance
255
+ * @returns Array of layers as hex strings
256
+ */
257
+ function getHexLayers(tree) {
258
+ return tree.getHexLayers();
259
+ }
260
+ exports.getHexLayers = getHexLayers;
261
+ /**
262
+ * Gets flattened layers
263
+ * @param tree - MerkleTree instance
264
+ * @returns Flattened array of all nodes
265
+ */
266
+ function getLayersFlat(tree) {
267
+ return tree.getLayersFlat();
268
+ }
269
+ exports.getLayersFlat = getLayersFlat;
270
+ /**
271
+ * Gets flattened layers as hex strings
272
+ * @param tree - MerkleTree instance
273
+ * @returns Flattened array of all nodes as hex strings
274
+ */
275
+ function getHexLayersFlat(tree) {
276
+ return tree.getHexLayersFlat();
277
+ }
278
+ exports.getHexLayersFlat = getHexLayersFlat;
279
+ /**
280
+ * Resets the tree by clearing all leaves and layers
281
+ * @param tree - MerkleTree instance
282
+ */
283
+ function resetTree(tree) {
284
+ tree.resetTree();
285
+ }
286
+ exports.resetTree = resetTree;
287
+ /**
288
+ * Gets tree options
289
+ * @param tree - MerkleTree instance
290
+ * @returns Tree options object
291
+ */
292
+ function getOptions(tree) {
293
+ return tree.getOptions();
294
+ }
295
+ exports.getOptions = getOptions;
296
+ /**
297
+ * Converts tree to string representation
298
+ * @param tree - MerkleTree instance
299
+ * @returns String representation of the tree
300
+ */
301
+ function treeToString(tree) {
302
+ return tree.toString();
303
+ }
304
+ exports.treeToString = treeToString;
305
+ /**
306
+ * Marshals leaves to JSON string
307
+ * @param leaves - Array of leaves
308
+ * @returns JSON string representation
309
+ */
310
+ function marshalLeaves(leaves) {
311
+ return MerkleTree_1.MerkleTree.marshalLeaves(leaves);
312
+ }
313
+ exports.marshalLeaves = marshalLeaves;
314
+ /**
315
+ * Unmarshals leaves from JSON string
316
+ * @param jsonStr - JSON string or object
317
+ * @returns Array of leaves as Buffers
318
+ */
319
+ function unmarshalLeaves(jsonStr) {
320
+ return MerkleTree_1.MerkleTree.unmarshalLeaves(jsonStr);
321
+ }
322
+ exports.unmarshalLeaves = unmarshalLeaves;
323
+ /**
324
+ * Marshals proof to JSON string
325
+ * @param proof - Proof array
326
+ * @returns JSON string representation
327
+ */
328
+ function marshalProof(proof) {
329
+ return MerkleTree_1.MerkleTree.marshalProof(proof);
330
+ }
331
+ exports.marshalProof = marshalProof;
332
+ /**
333
+ * Unmarshals proof from JSON string
334
+ * @param jsonStr - JSON string or object
335
+ * @returns Proof array
336
+ */
337
+ function unmarshalProof(jsonStr) {
338
+ return MerkleTree_1.MerkleTree.unmarshalProof(jsonStr);
339
+ }
340
+ exports.unmarshalProof = unmarshalProof;
341
+ /**
342
+ * Marshals entire tree to JSON string
343
+ * @param tree - MerkleTree instance
344
+ * @returns JSON string representation of the tree
345
+ */
346
+ function marshalTree(tree) {
347
+ return MerkleTree_1.MerkleTree.marshalTree(tree);
348
+ }
349
+ exports.marshalTree = marshalTree;
350
+ /**
351
+ * Unmarshals tree from JSON string
352
+ * @param jsonStr - JSON string or object
353
+ * @param hashFn - Hash function
354
+ * @param options - Tree options
355
+ * @returns MerkleTree instance
356
+ */
357
+ function unmarshalTree(jsonStr, hashFn = defaultHashFn, options = {}) {
358
+ return MerkleTree_1.MerkleTree.unmarshalTree(jsonStr, hashFn, options);
359
+ }
360
+ exports.unmarshalTree = unmarshalTree;
@@ -0,0 +1,9 @@
1
+ import MerkleTree from './MerkleTree';
2
+ export { MerkleTree };
3
+ export { MerkleMountainRange } from './MerkleMountainRange';
4
+ export { IncrementalMerkleTree } from './IncrementalMerkleTree';
5
+ export { MerkleSumTree } from './MerkleSumTree';
6
+ export { MerkleRadixTree } from './MerkleRadixTree';
7
+ export { UnifiedBinaryTree } from './UnifiedBinaryTree';
8
+ export * from './functional';
9
+ export default MerkleTree;
package/dist/index.js ADDED
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
11
+ };
12
+ var __importDefault = (this && this.__importDefault) || function (mod) {
13
+ return (mod && mod.__esModule) ? mod : { "default": mod };
14
+ };
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.MerkleTree = void 0;
17
+ const MerkleTree_1 = __importDefault(require("./MerkleTree"));
18
+ exports.MerkleTree = MerkleTree_1.default;
19
+ var MerkleMountainRange_1 = require("./MerkleMountainRange");
20
+ Object.defineProperty(exports, "MerkleMountainRange", { enumerable: true, get: function () { return MerkleMountainRange_1.MerkleMountainRange; } });
21
+ var IncrementalMerkleTree_1 = require("./IncrementalMerkleTree");
22
+ Object.defineProperty(exports, "IncrementalMerkleTree", { enumerable: true, get: function () { return IncrementalMerkleTree_1.IncrementalMerkleTree; } });
23
+ var MerkleSumTree_1 = require("./MerkleSumTree");
24
+ Object.defineProperty(exports, "MerkleSumTree", { enumerable: true, get: function () { return MerkleSumTree_1.MerkleSumTree; } });
25
+ var MerkleRadixTree_1 = require("./MerkleRadixTree");
26
+ Object.defineProperty(exports, "MerkleRadixTree", { enumerable: true, get: function () { return MerkleRadixTree_1.MerkleRadixTree; } });
27
+ var UnifiedBinaryTree_1 = require("./UnifiedBinaryTree");
28
+ Object.defineProperty(exports, "UnifiedBinaryTree", { enumerable: true, get: function () { return UnifiedBinaryTree_1.UnifiedBinaryTree; } });
29
+ __exportStar(require("./functional"), exports);
30
+ exports.default = MerkleTree_1.default;