@ensdomains/merkle-builder 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +43 -0
- package/dist/index.cjs +945 -0
- package/dist/index.d.cts +92 -0
- package/dist/index.d.ts +92 -0
- package/dist/index.js +882 -0
- package/package.json +48 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,882 @@
|
|
|
1
|
+
// src/utils.ts
|
|
2
|
+
import { keccak, bytes_from_hex, hex_from_bytes } from "@adraffy/keccak";
|
|
3
|
+
function keccak256(v) {
|
|
4
|
+
return keccak().update(v).bytes;
|
|
5
|
+
}
|
|
6
|
+
function concat(...args) {
|
|
7
|
+
const n = args.reduce((a, x) => a + x.length, 0);
|
|
8
|
+
const v = new Uint8Array(n);
|
|
9
|
+
let pos = 0;
|
|
10
|
+
for (const x of args) {
|
|
11
|
+
v.set(x, pos);
|
|
12
|
+
pos += x.length;
|
|
13
|
+
}
|
|
14
|
+
return v;
|
|
15
|
+
}
|
|
16
|
+
function followSlot(slot, key) {
|
|
17
|
+
return keccak256(concat(key, toBytes(slot, 32)));
|
|
18
|
+
}
|
|
19
|
+
function trimLeadingZeros(v) {
|
|
20
|
+
let i = 0;
|
|
21
|
+
while (v[i] === 0) ++i;
|
|
22
|
+
return v.slice(i);
|
|
23
|
+
}
|
|
24
|
+
function toBytes(x, size) {
|
|
25
|
+
if (typeof x === "string") {
|
|
26
|
+
if (x.startsWith("0x")) x = x.slice(2);
|
|
27
|
+
} else {
|
|
28
|
+
x = x ? x.toString(16) : "";
|
|
29
|
+
}
|
|
30
|
+
size ??= x.length + 1 >> 1;
|
|
31
|
+
size <<= 1;
|
|
32
|
+
return bytes_from_hex(x.padStart(size, "0").slice(-size));
|
|
33
|
+
}
|
|
34
|
+
function toBigInt(v) {
|
|
35
|
+
return v.length ? BigInt(toHex(v)) : 0n;
|
|
36
|
+
}
|
|
37
|
+
function toHex(v) {
|
|
38
|
+
return `0x${hex_from_bytes(v)}`;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// src/trie.ts
|
|
42
|
+
var EMPTY_BYTES = new Uint8Array(0);
|
|
43
|
+
var EMPTY_LEAF = Object.freeze({
|
|
44
|
+
path: EMPTY_BYTES,
|
|
45
|
+
data: EMPTY_BYTES
|
|
46
|
+
});
|
|
47
|
+
var RLP_NULL = encodeRlpBytes(EMPTY_BYTES);
|
|
48
|
+
var RLP_EMPTY = encodeRlpList([encodeRlpList([])]);
|
|
49
|
+
var HASH_NULL = keccak256(RLP_NULL);
|
|
50
|
+
function isBranch(node) {
|
|
51
|
+
return !!node && "children" in node;
|
|
52
|
+
}
|
|
53
|
+
function isExtension(node) {
|
|
54
|
+
return !!node && "child" in node;
|
|
55
|
+
}
|
|
56
|
+
function isLeaf(node) {
|
|
57
|
+
return !!node && "data" in node;
|
|
58
|
+
}
|
|
59
|
+
function isEmptyLeaf(node) {
|
|
60
|
+
return isLeaf(node) && !node.path.length && !node.data.length;
|
|
61
|
+
}
|
|
62
|
+
function common(a, b) {
|
|
63
|
+
let i = 0;
|
|
64
|
+
while (i < a.length && i < b.length && a[i] === b[i]) ++i;
|
|
65
|
+
return i;
|
|
66
|
+
}
|
|
67
|
+
function startsWith(path, prefix) {
|
|
68
|
+
const n = prefix.length;
|
|
69
|
+
if (path.length < n) return 0;
|
|
70
|
+
for (let i = 0; i < n; ++i) if (path[i] !== prefix[i]) return 0;
|
|
71
|
+
return n;
|
|
72
|
+
}
|
|
73
|
+
function copyNode(node, copyPath = true) {
|
|
74
|
+
if (isLeaf(node)) {
|
|
75
|
+
return newLeaf(
|
|
76
|
+
copyPath && node.path.length ? node.path.slice() : node.path,
|
|
77
|
+
node.data
|
|
78
|
+
);
|
|
79
|
+
} else if (isExtension(node)) {
|
|
80
|
+
const copy = { ...node };
|
|
81
|
+
if (copyPath && copy.path.length) copy.path = copy.path.slice();
|
|
82
|
+
copy.child = copyNode(copy.child, copyPath);
|
|
83
|
+
return copy;
|
|
84
|
+
} else if (isBranch(node)) {
|
|
85
|
+
const copy = { ...node };
|
|
86
|
+
copy.children = copy.children.map((x) => copyNode(x, copyPath));
|
|
87
|
+
return copy;
|
|
88
|
+
} else {
|
|
89
|
+
return node;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
function findLeaf(node, path) {
|
|
93
|
+
while (node) {
|
|
94
|
+
if (isBranch(node)) {
|
|
95
|
+
if (!path.length) return;
|
|
96
|
+
node = node.children[path[0]];
|
|
97
|
+
path = path.subarray(1);
|
|
98
|
+
} else if (isExtension(node)) {
|
|
99
|
+
const i = startsWith(path, node.path);
|
|
100
|
+
if (!i) return;
|
|
101
|
+
node = node.child;
|
|
102
|
+
path = path.subarray(i);
|
|
103
|
+
} else if (startsWith(path, node.path)) {
|
|
104
|
+
return node;
|
|
105
|
+
} else {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
function getProof(node, path) {
|
|
111
|
+
const ret = [];
|
|
112
|
+
do {
|
|
113
|
+
ret.push(encodeNode(node));
|
|
114
|
+
if (isBranch(node)) {
|
|
115
|
+
if (!path.length) break;
|
|
116
|
+
node = node.children[path[0]];
|
|
117
|
+
path = path.subarray(1);
|
|
118
|
+
} else if (isExtension(node)) {
|
|
119
|
+
const i = startsWith(path, node.path);
|
|
120
|
+
if (!i) break;
|
|
121
|
+
node = node.child;
|
|
122
|
+
path = path.subarray(i);
|
|
123
|
+
} else {
|
|
124
|
+
break;
|
|
125
|
+
}
|
|
126
|
+
} while (node);
|
|
127
|
+
return ret;
|
|
128
|
+
}
|
|
129
|
+
function insertLeaf(node, path, data) {
|
|
130
|
+
if (!node) {
|
|
131
|
+
return newLeaf(path, data);
|
|
132
|
+
} else if (isBranch(node)) {
|
|
133
|
+
const i = path[0];
|
|
134
|
+
const children = node.children.slice();
|
|
135
|
+
children[i] = insertLeaf(children[i], path.subarray(1), data);
|
|
136
|
+
return { children };
|
|
137
|
+
} else if (isExtension(node)) {
|
|
138
|
+
const other = node.path;
|
|
139
|
+
const i = common(other, path);
|
|
140
|
+
if (i === other.length) {
|
|
141
|
+
return {
|
|
142
|
+
path: other,
|
|
143
|
+
child: insertLeaf(node.child, path.subarray(i), data)
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
const b = newBranch();
|
|
147
|
+
const rest = other.subarray(i + 1);
|
|
148
|
+
b.children[other[i]] = rest.length ? { path: rest, child: node.child } : node.child;
|
|
149
|
+
b.children[path[i]] = newLeaf(path.subarray(i + 1), data);
|
|
150
|
+
return i ? { path: path.subarray(0, i), child: b } : b;
|
|
151
|
+
} else {
|
|
152
|
+
const other = node.path;
|
|
153
|
+
const i = common(other, path);
|
|
154
|
+
if (i === other.length && i === path.length) {
|
|
155
|
+
return newLeaf(path, data);
|
|
156
|
+
}
|
|
157
|
+
const b = newBranch();
|
|
158
|
+
if (i < other.length) {
|
|
159
|
+
b.children[other[i]] = newLeaf(other.subarray(i + 1), node.data);
|
|
160
|
+
}
|
|
161
|
+
b.children[path[i]] = newLeaf(path.subarray(i + 1), data);
|
|
162
|
+
return i ? { path: path.subarray(0, i), child: b } : b;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
function extractNode(node, path) {
|
|
166
|
+
while (node) {
|
|
167
|
+
if (!path.length) return node;
|
|
168
|
+
if (isBranch(node)) {
|
|
169
|
+
node = node.children[path[0]];
|
|
170
|
+
path = path.subarray(1);
|
|
171
|
+
} else if (isExtension(node)) {
|
|
172
|
+
const part = node.path;
|
|
173
|
+
const i = common(path, part);
|
|
174
|
+
if (i === part.length) {
|
|
175
|
+
node = node.child;
|
|
176
|
+
path = path.subarray(i);
|
|
177
|
+
} else if (i === path.length) {
|
|
178
|
+
return { path: part.subarray(i), child: node.child };
|
|
179
|
+
} else {
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
} else {
|
|
183
|
+
const part = node.path;
|
|
184
|
+
const i = common(path, part);
|
|
185
|
+
if (i === path.length) {
|
|
186
|
+
return { path: part.subarray(i), data: node.data };
|
|
187
|
+
} else {
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
function deleteNode(node, path) {
|
|
194
|
+
if (!node || !path.length) return;
|
|
195
|
+
if (isBranch(node)) {
|
|
196
|
+
const i = path[0];
|
|
197
|
+
if (!node.children[i]) return node;
|
|
198
|
+
const children = node.children.slice();
|
|
199
|
+
let child = children[i] = deleteNode(children[i], path.subarray(1));
|
|
200
|
+
if (child) return { children };
|
|
201
|
+
let index = -1;
|
|
202
|
+
for (let j = 0; j < children.length; ++j) {
|
|
203
|
+
if (children[j]) {
|
|
204
|
+
if (index >= 0) return { children };
|
|
205
|
+
index = j;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
child = children[index];
|
|
209
|
+
if (isBranch(child)) return { path: Uint8Array.of(index), child };
|
|
210
|
+
path = Uint8Array.of(index, ...child.path);
|
|
211
|
+
return isExtension(child) ? { path, child: child.child } : newLeaf(path, child.data);
|
|
212
|
+
} else if (isExtension(node)) {
|
|
213
|
+
const i = common(node.path, path);
|
|
214
|
+
if (!i) return node;
|
|
215
|
+
if (i === path.length) return;
|
|
216
|
+
const child = deleteNode(node.child, path.subarray(i));
|
|
217
|
+
if (!child) return;
|
|
218
|
+
if (isBranch(child)) return { path: node.path, child };
|
|
219
|
+
path = concat(node.path, child.path);
|
|
220
|
+
return isExtension(child) ? { path, child: child.child } : newLeaf(path, child.data);
|
|
221
|
+
} else {
|
|
222
|
+
if (common(node.path, path) === path.length) return;
|
|
223
|
+
return node;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
function newLeaf(path, data) {
|
|
227
|
+
if (!data.length) {
|
|
228
|
+
data = EMPTY_BYTES;
|
|
229
|
+
if (!path.length) return EMPTY_LEAF;
|
|
230
|
+
} else if (!data[0]) {
|
|
231
|
+
throw new Error(`not trim: ${toHex(data)}`);
|
|
232
|
+
}
|
|
233
|
+
return { path, data };
|
|
234
|
+
}
|
|
235
|
+
function newBranch() {
|
|
236
|
+
return { children: Array(16).fill(void 0) };
|
|
237
|
+
}
|
|
238
|
+
function encodeNode(node) {
|
|
239
|
+
if (!node) {
|
|
240
|
+
return RLP_NULL;
|
|
241
|
+
} else if (isBranch(node)) {
|
|
242
|
+
return node.cache ??= encodeRlpList([
|
|
243
|
+
...node.children.map(encodeNodeRef),
|
|
244
|
+
RLP_NULL
|
|
245
|
+
]);
|
|
246
|
+
} else if (isExtension(node)) {
|
|
247
|
+
return encodeRlpList([
|
|
248
|
+
encodeRlpBytes(encodePath(node.path, false)),
|
|
249
|
+
encodeNodeRef(node.child)
|
|
250
|
+
]);
|
|
251
|
+
} else {
|
|
252
|
+
return encodeRlpList([
|
|
253
|
+
encodeRlpBytes(encodePath(node.path, true)),
|
|
254
|
+
encodeRlpBytes(encodeRlpBytes(node.data))
|
|
255
|
+
]);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
function encodeNodeRef(node) {
|
|
259
|
+
if (!node) {
|
|
260
|
+
return RLP_NULL;
|
|
261
|
+
} else if (isEmptyLeaf(node)) {
|
|
262
|
+
return RLP_EMPTY;
|
|
263
|
+
} else {
|
|
264
|
+
const v = encodeNode(node);
|
|
265
|
+
return encodeRlpBytes(v.length < 32 ? v : keccak256(v));
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
function clearCache(node) {
|
|
269
|
+
if (isBranch(node)) {
|
|
270
|
+
node.cache = void 0;
|
|
271
|
+
node.children.forEach(clearCache);
|
|
272
|
+
} else if (isExtension(node)) {
|
|
273
|
+
clearCache(node.child);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
function getRootHash(node) {
|
|
277
|
+
if (!node) return HASH_NULL;
|
|
278
|
+
const v = encodeNode(node);
|
|
279
|
+
return v.length < 32 ? v : keccak256(v);
|
|
280
|
+
}
|
|
281
|
+
function toNibblePath(v) {
|
|
282
|
+
if (!v.length) return EMPTY_BYTES;
|
|
283
|
+
const u = new Uint8Array(v.length << 1);
|
|
284
|
+
let i = 0;
|
|
285
|
+
for (const x of v) {
|
|
286
|
+
u[i++] = x >> 4;
|
|
287
|
+
u[i++] = x & 15;
|
|
288
|
+
}
|
|
289
|
+
return u;
|
|
290
|
+
}
|
|
291
|
+
function encodePath(path, leaf) {
|
|
292
|
+
const v = new Uint8Array(1 + (path.length >> 1));
|
|
293
|
+
if (leaf) v[0] = 32;
|
|
294
|
+
const odd = path.length & 1;
|
|
295
|
+
if (path.length & 1) v[0] |= 16 | path[0];
|
|
296
|
+
for (let i = odd, j = 1; i < path.length; i += 2, ++j) {
|
|
297
|
+
v[j] = path[i] << 4 | path[i + 1];
|
|
298
|
+
}
|
|
299
|
+
return v;
|
|
300
|
+
}
|
|
301
|
+
function encodeRlpLength(start, length) {
|
|
302
|
+
const max = 55;
|
|
303
|
+
if (length <= max) return Uint8Array.of(start + length);
|
|
304
|
+
const v = new Uint8Array(8);
|
|
305
|
+
let i = v.length;
|
|
306
|
+
for (; length; length >>= 8, ++start) {
|
|
307
|
+
v[--i] = length;
|
|
308
|
+
}
|
|
309
|
+
v[--i] = start + max;
|
|
310
|
+
return v.subarray(i);
|
|
311
|
+
}
|
|
312
|
+
function encodeRlpList(m) {
|
|
313
|
+
return concat(
|
|
314
|
+
encodeRlpLength(
|
|
315
|
+
192,
|
|
316
|
+
m.reduce((a, x) => a + x.length, 0)
|
|
317
|
+
),
|
|
318
|
+
...m
|
|
319
|
+
);
|
|
320
|
+
}
|
|
321
|
+
function encodeRlpBytes(v) {
|
|
322
|
+
const max = 128;
|
|
323
|
+
if (v.length === 1 && v[0] < max) return v;
|
|
324
|
+
return concat(encodeRlpLength(max, v.length), v);
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
// src/coder.ts
|
|
328
|
+
var TY_NULL = 0;
|
|
329
|
+
var TY_BRANCH = 1;
|
|
330
|
+
var TY_EXTENSION = 2;
|
|
331
|
+
var TY_EMPTY_LEAF = 3;
|
|
332
|
+
var TY_LEAF = 4;
|
|
333
|
+
var TY_BRANCH_WITH_CACHE = 5;
|
|
334
|
+
var MAX_SIZE = (1 << 22) - 1;
|
|
335
|
+
var Coder = class {
|
|
336
|
+
constructor(buf = new Uint8Array(1024)) {
|
|
337
|
+
this.buf = buf;
|
|
338
|
+
}
|
|
339
|
+
static getByteCount(node) {
|
|
340
|
+
const c = new this();
|
|
341
|
+
c.writeNode(node);
|
|
342
|
+
return c.pos;
|
|
343
|
+
}
|
|
344
|
+
pos = 0;
|
|
345
|
+
reset() {
|
|
346
|
+
this.pos = 0;
|
|
347
|
+
}
|
|
348
|
+
expand(need) {
|
|
349
|
+
const required = this.pos + need;
|
|
350
|
+
let size = this.buf.length;
|
|
351
|
+
if (required <= size) return;
|
|
352
|
+
while (size < required) size <<= 1;
|
|
353
|
+
const v = new Uint8Array(size);
|
|
354
|
+
v.set(this.buf);
|
|
355
|
+
this.buf = v;
|
|
356
|
+
}
|
|
357
|
+
require(need) {
|
|
358
|
+
if (need && this.pos + need > this.buf.length) {
|
|
359
|
+
throw new Error(`eof: ${this.pos + need} > ${this.buf.length}`);
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
readByte() {
|
|
363
|
+
this.require(1);
|
|
364
|
+
return this.buf[this.pos++];
|
|
365
|
+
}
|
|
366
|
+
writeByte(x) {
|
|
367
|
+
this.expand(1);
|
|
368
|
+
this.buf[this.pos++] = x;
|
|
369
|
+
}
|
|
370
|
+
readSize() {
|
|
371
|
+
let size = this.readByte();
|
|
372
|
+
if (size & 128) {
|
|
373
|
+
const next = this.readByte();
|
|
374
|
+
size = (size & 127) + ((next & 127) << 7);
|
|
375
|
+
if (next & 128) {
|
|
376
|
+
size += this.readByte() << 14;
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
return size;
|
|
380
|
+
}
|
|
381
|
+
writeSize(size) {
|
|
382
|
+
if (size < 128) {
|
|
383
|
+
this.writeByte(size);
|
|
384
|
+
} else {
|
|
385
|
+
this.writeByte(size | 128);
|
|
386
|
+
size >>= 7;
|
|
387
|
+
if (size < 128) {
|
|
388
|
+
this.writeByte(size);
|
|
389
|
+
} else {
|
|
390
|
+
this.writeByte(size | 128);
|
|
391
|
+
size >>= 7;
|
|
392
|
+
if (size >> 8) throw new RangeError("overflow");
|
|
393
|
+
this.writeByte(size);
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
readBytes(n) {
|
|
398
|
+
if (!n) return EMPTY_BYTES;
|
|
399
|
+
this.require(n);
|
|
400
|
+
return this.buf.slice(this.pos, this.pos += n);
|
|
401
|
+
}
|
|
402
|
+
writeBytes(v) {
|
|
403
|
+
this.expand(v.length);
|
|
404
|
+
this.buf.set(v, this.pos);
|
|
405
|
+
this.pos += v.length;
|
|
406
|
+
}
|
|
407
|
+
readSizedBytes() {
|
|
408
|
+
return this.readBytes(this.readSize());
|
|
409
|
+
}
|
|
410
|
+
writeSizedBytes(v) {
|
|
411
|
+
this.writeSize(v.length);
|
|
412
|
+
this.writeBytes(v);
|
|
413
|
+
}
|
|
414
|
+
readPath() {
|
|
415
|
+
const n = this.readByte();
|
|
416
|
+
return toNibblePath(this.readBytes(n + 1 >> 1)).subarray(0, n);
|
|
417
|
+
}
|
|
418
|
+
writePath(v) {
|
|
419
|
+
const n = v.length + 1 >> 1;
|
|
420
|
+
this.expand(1 + n);
|
|
421
|
+
this.buf[this.pos++] = v.length;
|
|
422
|
+
for (let i = 0; i < v.length; i += 2) {
|
|
423
|
+
this.buf[this.pos++] = v[i] << 4 | (v[i + 1] ?? 0);
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
readNodes(length = 16) {
|
|
427
|
+
return Array.from({ length }, () => this.readNode());
|
|
428
|
+
}
|
|
429
|
+
readNode() {
|
|
430
|
+
const ty = this.readByte();
|
|
431
|
+
switch (ty) {
|
|
432
|
+
case TY_NULL:
|
|
433
|
+
return;
|
|
434
|
+
case TY_BRANCH_WITH_CACHE:
|
|
435
|
+
return {
|
|
436
|
+
children: this.readNodes(),
|
|
437
|
+
cache: this.readSizedBytes()
|
|
438
|
+
};
|
|
439
|
+
case TY_BRANCH:
|
|
440
|
+
return { children: this.readNodes() };
|
|
441
|
+
case TY_EXTENSION: {
|
|
442
|
+
const path = this.readPath();
|
|
443
|
+
const child = this.readNode();
|
|
444
|
+
if (!isBranch(child)) throw new Error("bug");
|
|
445
|
+
return { path, child };
|
|
446
|
+
}
|
|
447
|
+
case TY_EMPTY_LEAF:
|
|
448
|
+
return EMPTY_LEAF;
|
|
449
|
+
case TY_LEAF:
|
|
450
|
+
return {
|
|
451
|
+
path: this.readPath(),
|
|
452
|
+
data: this.readSizedBytes()
|
|
453
|
+
};
|
|
454
|
+
default:
|
|
455
|
+
throw new Error(`unknown type: ${ty}`);
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
writeNode(node, includeCache) {
|
|
459
|
+
if (!node) {
|
|
460
|
+
this.writeByte(TY_NULL);
|
|
461
|
+
} else if (isBranch(node)) {
|
|
462
|
+
const cache = includeCache === void 0 ? node.cache : includeCache ? encodeNode(node) : void 0;
|
|
463
|
+
this.writeByte(cache ? TY_BRANCH_WITH_CACHE : TY_BRANCH);
|
|
464
|
+
for (const x of node.children) {
|
|
465
|
+
this.writeNode(x, includeCache);
|
|
466
|
+
}
|
|
467
|
+
if (cache) this.writeSizedBytes(cache);
|
|
468
|
+
} else if (isExtension(node)) {
|
|
469
|
+
this.writeByte(TY_EXTENSION);
|
|
470
|
+
this.writePath(node.path);
|
|
471
|
+
this.writeNode(node.child, includeCache);
|
|
472
|
+
} else if (isEmptyLeaf(node)) {
|
|
473
|
+
this.writeByte(TY_EMPTY_LEAF);
|
|
474
|
+
} else {
|
|
475
|
+
this.writeByte(TY_LEAF);
|
|
476
|
+
this.writePath(node.path);
|
|
477
|
+
this.writeSizedBytes(node.data);
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
get bytes() {
|
|
481
|
+
return this.buf.subarray(0, this.pos);
|
|
482
|
+
}
|
|
483
|
+
};
|
|
484
|
+
|
|
485
|
+
// src/inspect.ts
|
|
486
|
+
function getByteCount(node, sizeOf = (v) => v.length) {
|
|
487
|
+
if (!node) {
|
|
488
|
+
return 0;
|
|
489
|
+
} else if (isLeaf(node)) {
|
|
490
|
+
return sizeOf(node.path) + sizeOf(node.data);
|
|
491
|
+
} else if (isExtension(node)) {
|
|
492
|
+
return sizeOf(node.path) + getByteCount(node.child, sizeOf);
|
|
493
|
+
} else {
|
|
494
|
+
return node.children.reduce(
|
|
495
|
+
(a, x) => a + getByteCount(x, sizeOf),
|
|
496
|
+
(node.cache ? sizeOf(node.cache) : 0) + node.children.length
|
|
497
|
+
);
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
function getLeafCount(node) {
|
|
501
|
+
if (!node) {
|
|
502
|
+
return 0;
|
|
503
|
+
} else if (isLeaf(node)) {
|
|
504
|
+
return 1;
|
|
505
|
+
} else if (isExtension(node)) {
|
|
506
|
+
return getLeafCount(node.child);
|
|
507
|
+
} else {
|
|
508
|
+
return node.children.reduce((a, x) => a + getLeafCount(x), 0);
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
function getNodeCount(node) {
|
|
512
|
+
if (!node) {
|
|
513
|
+
return 0;
|
|
514
|
+
} else if (isLeaf(node)) {
|
|
515
|
+
return 1;
|
|
516
|
+
} else if (isExtension(node)) {
|
|
517
|
+
return 1 + getNodeCount(node.child);
|
|
518
|
+
} else {
|
|
519
|
+
return node.children.reduce((a, x) => a + getNodeCount(x), 1);
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
function getNodeType(node) {
|
|
523
|
+
if (isBranch(node)) {
|
|
524
|
+
return "branch";
|
|
525
|
+
} else if (isExtension(node)) {
|
|
526
|
+
return "extension";
|
|
527
|
+
} else if (isLeaf(node)) {
|
|
528
|
+
return "leaf";
|
|
529
|
+
} else {
|
|
530
|
+
return "null";
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
// src/json.ts
|
|
535
|
+
import { hex_from_bytes as hex_from_bytes2 } from "@adraffy/keccak";
|
|
536
|
+
var MORE = {
|
|
537
|
+
[/* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom")]() {
|
|
538
|
+
return "\x1B[37m...\x1B[0m";
|
|
539
|
+
}
|
|
540
|
+
};
|
|
541
|
+
function toJSON(node, depth = Infinity) {
|
|
542
|
+
if (!node) return null;
|
|
543
|
+
if (depth < 0) return MORE;
|
|
544
|
+
if (isBranch(node)) {
|
|
545
|
+
return Object.fromEntries(
|
|
546
|
+
node.children.flatMap(
|
|
547
|
+
(x, i) => x ? [[toNibbleChar(i), x && toJSON(x, depth - 1)]] : []
|
|
548
|
+
)
|
|
549
|
+
);
|
|
550
|
+
} else if (isExtension(node)) {
|
|
551
|
+
return [nibbleStr(node.path), toJSON(node.child, depth - 1)];
|
|
552
|
+
} else if (node.path.length) {
|
|
553
|
+
return [nibbleStr(node.path), hex_from_bytes2(node.data)];
|
|
554
|
+
} else {
|
|
555
|
+
return hex_from_bytes2(node.data);
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
function fromJSON(json) {
|
|
559
|
+
switch (typeof json) {
|
|
560
|
+
case "string":
|
|
561
|
+
return newLeaf(EMPTY_BYTES, toBytes(json));
|
|
562
|
+
case "object": {
|
|
563
|
+
if (json === null) return;
|
|
564
|
+
if (Array.isArray(json) && json.length === 2) {
|
|
565
|
+
const path = Uint8Array.from(json[0], fromNibbleChar);
|
|
566
|
+
const child = fromJSON(json[1]);
|
|
567
|
+
if (isBranch(child)) {
|
|
568
|
+
return { path, child };
|
|
569
|
+
} else if (isExtension(child)) {
|
|
570
|
+
return { path: concat(path, child.path), child: child.child };
|
|
571
|
+
} else if (child) {
|
|
572
|
+
return newLeaf(concat(path, child.path), child.data);
|
|
573
|
+
}
|
|
574
|
+
} else if (json.constructor === Object) {
|
|
575
|
+
const b = newBranch();
|
|
576
|
+
for (const [k, x] of Object.entries(json)) {
|
|
577
|
+
b.children[fromNibbleChar(k)] = fromJSON(x);
|
|
578
|
+
}
|
|
579
|
+
return b;
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
throw new TypeError("invalid json");
|
|
584
|
+
}
|
|
585
|
+
function nibbleStr(path) {
|
|
586
|
+
return Array.from(path, toNibbleChar).join("");
|
|
587
|
+
}
|
|
588
|
+
function toNibbleChar(nibble) {
|
|
589
|
+
return String.fromCharCode((nibble < 10 ? 48 : 55) + nibble);
|
|
590
|
+
}
|
|
591
|
+
function fromNibbleChar(ch) {
|
|
592
|
+
if (ch.length === 1) {
|
|
593
|
+
const cp = ch.charCodeAt(0);
|
|
594
|
+
if (cp >= 48 && cp <= 57) {
|
|
595
|
+
return cp - 48;
|
|
596
|
+
} else if (cp >= 65 && cp <= 70) {
|
|
597
|
+
return cp - 55;
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
throw new TypeError(`invalid nibble: "${ch}"`);
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
// src/kv.ts
|
|
604
|
+
function insertBytes(node, slot, value, mode = "delete") {
|
|
605
|
+
if (slot.length !== 32) throw new Error(`expected bytes32 slot`);
|
|
606
|
+
const key = keccak256(slot);
|
|
607
|
+
const path = toNibblePath(key);
|
|
608
|
+
let oldSize = 0;
|
|
609
|
+
if (mode !== "ignore") {
|
|
610
|
+
const prior = findLeaf(node, path)?.data;
|
|
611
|
+
if (prior?.length && prior[prior.length - 1] & 1) {
|
|
612
|
+
oldSize = Number(toBigInt(prior) >> 1n);
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
let pos = 0;
|
|
616
|
+
if (value.length < 32) {
|
|
617
|
+
if (!value.length && mode === "delete") {
|
|
618
|
+
node = deleteNode(node, path);
|
|
619
|
+
} else {
|
|
620
|
+
const word = bytes32(value);
|
|
621
|
+
word[31] = value.length << 1;
|
|
622
|
+
node = insertLeaf(node, path, trimLeadingZeros(word));
|
|
623
|
+
}
|
|
624
|
+
} else {
|
|
625
|
+
node = insertLeaf(node, path, toBytes(BigInt(value.length) << 1n | 1n));
|
|
626
|
+
for (; pos < value.length; increment(key)) {
|
|
627
|
+
const end = pos + 32;
|
|
628
|
+
node = insertLeaf(
|
|
629
|
+
node,
|
|
630
|
+
toNibblePath(keccak256(key)),
|
|
631
|
+
trimLeadingZeros(
|
|
632
|
+
end > value.length ? bytes32(value.subarray(pos)) : value.subarray(pos, end)
|
|
633
|
+
)
|
|
634
|
+
);
|
|
635
|
+
pos = end;
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
if (mode === "delete") {
|
|
639
|
+
for (; pos < oldSize; increment(key), pos += 32) {
|
|
640
|
+
node = deleteNode(node, toNibblePath(keccak256(key)));
|
|
641
|
+
}
|
|
642
|
+
} else if (mode === "zero") {
|
|
643
|
+
for (; pos < oldSize; increment(key), pos += 32) {
|
|
644
|
+
node = insertLeaf(node, toNibblePath(keccak256(key)), EMPTY_BYTES);
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
return node;
|
|
648
|
+
}
|
|
649
|
+
function increment(v, max = 255) {
|
|
650
|
+
let i = v.length;
|
|
651
|
+
while (i && v[i - 1] === max) --i;
|
|
652
|
+
if (i) {
|
|
653
|
+
++v[i - 1];
|
|
654
|
+
v.fill(0, i);
|
|
655
|
+
} else {
|
|
656
|
+
v.fill(0);
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
function bytes32(v) {
|
|
660
|
+
const word = new Uint8Array(32);
|
|
661
|
+
word.set(v);
|
|
662
|
+
return word;
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
// src/mimc.ts
|
|
666
|
+
var FIELD = 0x12ab655e9a2ca55660b44d1e5c37b00159aa76fed00000010a11800000000001n;
|
|
667
|
+
var ROUND_CONSTANTS = [
|
|
668
|
+
0x0efda9332fcec268a3bbd0567797ce650be481c79da27f58b1a51ada4a91b014n,
|
|
669
|
+
0x05253862ca9b15c2bd33e1a2b830659b7ae3657aacfa8986eec35d8ec2dd3446n,
|
|
670
|
+
0x0db5be05400d438b9facd4a269a49031e8c7f947887a7c8653aae1675075f08dn,
|
|
671
|
+
0x07850deb84c4b38c891c03f7acc0f0e0602877a2ae969dcd0b10d7facf26dddbn,
|
|
672
|
+
0x01c2e148c40ea201b748bee72845b349bfa4a4497837af0d569ae47afc6e4243n,
|
|
673
|
+
0x005a472abfb0d5d4b09a0da6d9d4c7ab93bf68299dc5222dc6ef81407825dba9n,
|
|
674
|
+
0x03b0d15d7b62c8b4cfbce18816baeabb2e3df2d9a731d9d248d2f0498bdec1e4n,
|
|
675
|
+
0x04e8da009db8982a082983402626f1f68655a4a3c83be89c165ba656be14d726n,
|
|
676
|
+
0x02dcc7fbe0034e4fd51853c69fa7161a043c6757df0b3022fd8628c221b04c01n,
|
|
677
|
+
0x0ef15ea4cf191c23a6eba0d9f4c6c978a7bb172b196d13438c30c1ce50aeefecn,
|
|
678
|
+
0x0ddda0ea4d7aeda047f66513386eab0c970ea0f302b6227a1a7e64aef63840e9n,
|
|
679
|
+
0x11c526b58d39911c310b2a808cf84fd690f713c06d4016ff30c05aded412af7an,
|
|
680
|
+
0x056b338761a8093e7575ab89a9f375f59c61049079a2e5d1120dbf4adf7a9bb5n,
|
|
681
|
+
0x05fc79e450ea6c00b641fdf50f5ee15c0ec5baf629ccb26d553553adf1792b00n,
|
|
682
|
+
0x1168acb1e68011e4b6ff861a9f84e4ac38d250941c8536f214a0ce4f68bdb5a3n,
|
|
683
|
+
0x06d4d245e2259b3166774189238cfc1b4ae5defd98f62899f0d846d20a005b91n,
|
|
684
|
+
0x123313cced613293c40586b110f8e4244cd67cc4380c8f5df4ec60f42216ce28n,
|
|
685
|
+
0x0acf9981fe2d6f97d7fa27873a0a368c2b19b10d15f2460a59512c4381ca0379n,
|
|
686
|
+
0x011e73f99cc798e236f1fb1f38144984fed0a2cdd836d7860099423cce8c491en,
|
|
687
|
+
0x0a8d98d4f22ed367167e54617b0701e64f0f9a4b17e0808eeac420473c18bcben,
|
|
688
|
+
0x0e9d4c3fe8fed7780e4b179314207924caebf54185c786400384a8679b6c7252n,
|
|
689
|
+
0x11d37287b2e163e78261cdcc9e4d723b0a81099340c5cfa245eccfb9ee920142n,
|
|
690
|
+
0x05b231b706fb2967b2b90bade17c758c62201b5a4e04f020cdf2af76c12422f0n,
|
|
691
|
+
0x0dcfd40018b5bf7bb3397d4ce2a24130ae7d74c41e48f2a25a48132f897a5ac2n,
|
|
692
|
+
0x0534aaf5c42188955008e47ba93e156c7d32406566cb85f6183bf6144d8a3ee2n,
|
|
693
|
+
0x023cd78594054aa62b3292f3429491566819cb081159afef6c0d12a945aa0590n,
|
|
694
|
+
0x007ca89d69ee508f26d2500ece5b01925c9728aef78493806f58a2b807c6da4dn,
|
|
695
|
+
0x05192bd62077895fa33a95382ba2ea0dd65ed66281c6b7a09acc94003238df37n,
|
|
696
|
+
0x0d0ead8a1699babd8e6b7e3f3811463e8cfafae1915967ad4342ca59465c4014n,
|
|
697
|
+
0x11c0cabe4b1e2444d8915e6a411908faf20cf1feeb59918abde560595ebb5f4fn,
|
|
698
|
+
0x0f0c1c73b3c6463138527609f33d4981b21444c39d1f00c172f51c3c9aa43574n,
|
|
699
|
+
0x0861d628f74762a601963dd1823ed11b9dd2456940b41659ac02fe1232355a64n,
|
|
700
|
+
0x110df129163a9336afa7b9757f15f300aeb954e92b3af524222b84096d1274fdn,
|
|
701
|
+
0x04c609941ec5da50d43b8d6d7d45fdd4faa8bb69929fc3337ddfc1bee29f7b94n,
|
|
702
|
+
0x07a63ade8da839446b58f5d1b7fdc9432dbe55467a2b87c1779e4ce62a59e432n,
|
|
703
|
+
0x120dbf222fc5d5337f22cfe76ea5597030bc328f5ef7b927678f123be9c2a394n,
|
|
704
|
+
0x0b33e4820a40248cdbc3c27d7dfab70fd4b31ee9f62b2e1e048e23f9b12d5b71n,
|
|
705
|
+
0x10b998b32a4e17a795d120a590e238dead3a2761cfcc9cce00b0b5c9a8656086n,
|
|
706
|
+
0x0a98ebc6e3643fb6112262f125da98c0dc9eeb5c5e652716f368cf96b8888ed3n,
|
|
707
|
+
0x0006ce51116858059370af176e5d32b99b8fd443d520fe34588c6254df7514f5n,
|
|
708
|
+
0x0b2dddc8994767c7d3632cc7bc089becf8ef3b65540fb4709b8cc78ba12b044bn,
|
|
709
|
+
0x08837cf3399fbfff03fc2e6cbb1a3b205a5a28757c827730ccd0c2f0c90fff3bn,
|
|
710
|
+
0x0c238d5f2c384a72477fbdce23d461ad73d4a20f8acb2de069ec6b034b7d8c54n,
|
|
711
|
+
0x0f0e46c03bd29b0cad6857149959c77f9e4f96c6688d3c2c64e228bcc0893ba4n,
|
|
712
|
+
0x0d7dbd25add9892e2ea8951086a653298f4e4261e6bcdb3d980b9a45c9f4f3a9n,
|
|
713
|
+
0x1197bc33ae17572ff6c8671d7a3a52f761305ba4f3a93c582e95c9f6d21dd600n,
|
|
714
|
+
0x10c0f787b87b60b08241ca6547299f3afe7d86374858661f3db021676d573566n,
|
|
715
|
+
0x0d527557a2a71d92e0b0c5230b02b5db478d6abd87d24caee5e9f325efec0298n,
|
|
716
|
+
0x046e586141d405df5efb10855b7ea8009fdac1732b676f90de97a3e65fab3f42n,
|
|
717
|
+
0x02e91572a13a6baf97560b43b5b862aebd8b7d95c0fda9c097d823cc9ef0599en,
|
|
718
|
+
0x0a12c428ae449ef925394565ac50d0adb37e9e48873cf7df892b08a7b5c02875n,
|
|
719
|
+
0x053d51710289df29fdcd07b74954d10edb2a29ce26f58b0868bfa608b976d162n,
|
|
720
|
+
0x107983a1ea61c3c634124a87ab1271bc68dbbf1f455033dba37f441e942da248n,
|
|
721
|
+
0x02f05b8c3d5883d63ad8e0fb9d5dfd79fed0a7476208a11ca79905cf50a8627an,
|
|
722
|
+
0x0728f029842765bb9a7b662cc646a328bea710b0def51f6c6a0d8e3ee9286a2fn,
|
|
723
|
+
0x07aee6d598f4aed60276e302085feae4608f4b249347f581ea9e246aa7b2bd2dn,
|
|
724
|
+
0x0973293a99aab1398c81147a84d50bfa6aa95c659b7a4a2c153f21a13294caa6n,
|
|
725
|
+
0x0f56f597f2a94ff70aed4abd9b14a863808ecffcd706f566a9065b6bf515cba5n,
|
|
726
|
+
0x08d6e679d99527436d1b27315b5933cf75aaad990d3a2969032bc5595f72ed37n,
|
|
727
|
+
0x0ecf9edc13aa60341dde23bdadf7a719337256129297b85719cd06d173e54320n,
|
|
728
|
+
0x0f647c810044463684d83b28b6a17aef6a71db48f9af54c58c9919ded4974d2en,
|
|
729
|
+
0x0f63f31b9849bcdbf503fd3b51ab77ca37a73a892a2eb5f9328fd4f2e234d20an
|
|
730
|
+
];
|
|
731
|
+
function pow2(x) {
|
|
732
|
+
return x * x % FIELD;
|
|
733
|
+
}
|
|
734
|
+
function mimcHash(v) {
|
|
735
|
+
let h = 0n;
|
|
736
|
+
for (const x of v) {
|
|
737
|
+
let y = x;
|
|
738
|
+
for (const c of ROUND_CONSTANTS) {
|
|
739
|
+
const temp = (y + h + c) % FIELD;
|
|
740
|
+
y = pow2(pow2(pow2(pow2(temp)))) * temp;
|
|
741
|
+
}
|
|
742
|
+
h += x + y + h;
|
|
743
|
+
}
|
|
744
|
+
return h % FIELD;
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
// src/surgery.ts
|
|
748
|
+
function pluckLimbs(node, depth) {
|
|
749
|
+
if (!node || depth <= 0) return { trunk: node, limbs: [] };
|
|
750
|
+
const queue = [];
|
|
751
|
+
if (isBranch(node)) {
|
|
752
|
+
queue.push([node, []]);
|
|
753
|
+
} else if (isExtension(node)) {
|
|
754
|
+
if (node.path.length >= depth) {
|
|
755
|
+
const extension = node.path.length === depth ? node.child : { path: node.path.subarray(depth), child: node.child };
|
|
756
|
+
return {
|
|
757
|
+
trunk: void 0,
|
|
758
|
+
limbs: [[node.path.subarray(0, depth), extension]]
|
|
759
|
+
};
|
|
760
|
+
}
|
|
761
|
+
queue.push([node.child, [...node.path]]);
|
|
762
|
+
} else if (node.path.length >= depth) {
|
|
763
|
+
const leaf = newLeaf(node.path.subarray(depth), node.data);
|
|
764
|
+
return {
|
|
765
|
+
trunk: void 0,
|
|
766
|
+
limbs: [[node.path.subarray(0, depth), leaf]]
|
|
767
|
+
};
|
|
768
|
+
} else {
|
|
769
|
+
return { trunk: node, limbs: [] };
|
|
770
|
+
}
|
|
771
|
+
const limbs = [];
|
|
772
|
+
while (queue.length) {
|
|
773
|
+
const [parent, path] = queue.pop();
|
|
774
|
+
const rest = depth - path.length - 1;
|
|
775
|
+
parent.children.forEach((child, i) => {
|
|
776
|
+
if (!child) return;
|
|
777
|
+
if (!rest) {
|
|
778
|
+
parent.children[i] = void 0;
|
|
779
|
+
limbs.push([Uint8Array.of(...path, i), child]);
|
|
780
|
+
} else if (isBranch(child)) {
|
|
781
|
+
queue.push([child, [...path, i]]);
|
|
782
|
+
} else if (child.path.length > rest) {
|
|
783
|
+
parent.children[i] = void 0;
|
|
784
|
+
const copy = { ...child };
|
|
785
|
+
copy.path = child.path.subarray(rest);
|
|
786
|
+
limbs.push([
|
|
787
|
+
Uint8Array.of(...path, i, ...child.path.subarray(0, rest)),
|
|
788
|
+
copy
|
|
789
|
+
]);
|
|
790
|
+
} else if (isExtension(child)) {
|
|
791
|
+
queue.push([child.child, [...path, i, ...child.path]]);
|
|
792
|
+
}
|
|
793
|
+
});
|
|
794
|
+
}
|
|
795
|
+
return { trunk: node, limbs };
|
|
796
|
+
}
|
|
797
|
+
function graftLimb(trunk, path, limb) {
|
|
798
|
+
if (!path.length) return limb;
|
|
799
|
+
if (!trunk) {
|
|
800
|
+
if (isBranch(limb)) {
|
|
801
|
+
return { path: path.slice(), child: limb };
|
|
802
|
+
} else {
|
|
803
|
+
const copy = { ...limb };
|
|
804
|
+
copy.path = concat(path, copy.path);
|
|
805
|
+
return copy;
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
let start = 0;
|
|
809
|
+
let index = 0;
|
|
810
|
+
let node = trunk;
|
|
811
|
+
while (index < path.length - 1) {
|
|
812
|
+
if (isBranch(node)) {
|
|
813
|
+
const child = node.children[path[index]];
|
|
814
|
+
if (!child) {
|
|
815
|
+
start = index;
|
|
816
|
+
index = path.length - 1;
|
|
817
|
+
break;
|
|
818
|
+
}
|
|
819
|
+
start = ++index;
|
|
820
|
+
node = child;
|
|
821
|
+
} else if (isExtension(node)) {
|
|
822
|
+
++start;
|
|
823
|
+
index += node.path.length;
|
|
824
|
+
node = node.child;
|
|
825
|
+
} else {
|
|
826
|
+
break;
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
if (!isBranch(node)) throw new RangeError("invalid graft");
|
|
830
|
+
if (start === index) {
|
|
831
|
+
node.children[path[start]] = limb;
|
|
832
|
+
} else if (isBranch(limb)) {
|
|
833
|
+
node.children[path[start]] = {
|
|
834
|
+
path: path.slice(start + 1),
|
|
835
|
+
child: limb
|
|
836
|
+
};
|
|
837
|
+
} else {
|
|
838
|
+
const copy = { ...limb };
|
|
839
|
+
copy.path = concat(path.subarray(start + 1), copy.path);
|
|
840
|
+
node.children[path[start]] = copy;
|
|
841
|
+
}
|
|
842
|
+
return trunk;
|
|
843
|
+
}
|
|
844
|
+
export {
|
|
845
|
+
Coder,
|
|
846
|
+
EMPTY_BYTES,
|
|
847
|
+
EMPTY_LEAF,
|
|
848
|
+
MAX_SIZE,
|
|
849
|
+
clearCache,
|
|
850
|
+
concat,
|
|
851
|
+
copyNode,
|
|
852
|
+
deleteNode,
|
|
853
|
+
encodeNode,
|
|
854
|
+
extractNode,
|
|
855
|
+
findLeaf,
|
|
856
|
+
followSlot,
|
|
857
|
+
fromJSON,
|
|
858
|
+
getByteCount,
|
|
859
|
+
getLeafCount,
|
|
860
|
+
getNodeCount,
|
|
861
|
+
getNodeType,
|
|
862
|
+
getProof,
|
|
863
|
+
getRootHash,
|
|
864
|
+
graftLimb,
|
|
865
|
+
insertBytes,
|
|
866
|
+
insertLeaf,
|
|
867
|
+
isBranch,
|
|
868
|
+
isEmptyLeaf,
|
|
869
|
+
isExtension,
|
|
870
|
+
isLeaf,
|
|
871
|
+
keccak256,
|
|
872
|
+
mimcHash,
|
|
873
|
+
newBranch,
|
|
874
|
+
newLeaf,
|
|
875
|
+
pluckLimbs,
|
|
876
|
+
toBigInt,
|
|
877
|
+
toBytes,
|
|
878
|
+
toHex,
|
|
879
|
+
toJSON,
|
|
880
|
+
toNibblePath,
|
|
881
|
+
trimLeadingZeros
|
|
882
|
+
};
|