1 | import { Hash256 } from './types/hash-256';
|
2 | import { BytesList } from './serdes/binary-serializer';
|
3 |
|
4 |
|
5 |
|
6 | declare abstract class ShaMapNode {
|
7 | abstract hashPrefix(): Uint8Array;
|
8 | abstract isLeaf(): boolean;
|
9 | abstract isInner(): boolean;
|
10 | abstract toBytesSink(list: BytesList): void;
|
11 | abstract hash(): Hash256;
|
12 | }
|
13 |
|
14 |
|
15 |
|
16 | declare class ShaMapLeaf extends ShaMapNode {
|
17 | index: Hash256;
|
18 | item?: ShaMapNode | undefined;
|
19 | constructor(index: Hash256, item?: ShaMapNode | undefined);
|
20 | /**
|
21 | * @returns true as ShaMapLeaf is a leaf node
|
22 | */
|
23 | isLeaf(): boolean;
|
24 | /**
|
25 | * @returns false as ShaMapLeaf is not an inner node
|
26 | */
|
27 | isInner(): boolean;
|
28 | /**
|
29 | * Get the prefix of the this.item
|
30 | *
|
31 | * @returns The hash prefix, unless this.item is undefined, then it returns an empty Uint8Array
|
32 | */
|
33 | hashPrefix(): Uint8Array;
|
34 | /**
|
35 | * Hash the bytes representation of this
|
36 | *
|
37 | * @returns hash of this.item concatenated with this.index
|
38 | */
|
39 | hash(): Hash256;
|
40 | /**
|
41 | * Write the bytes representation of this to a BytesList
|
42 | * @param list BytesList to write bytes to
|
43 | */
|
44 | toBytesSink(list: BytesList): void;
|
45 | }
|
46 | /**
|
47 | * Class defining an Inner Node of a SHAMap
|
48 | */
|
49 | declare class ShaMapInner extends ShaMapNode {
|
50 | private depth;
|
51 | private slotBits;
|
52 | private branches;
|
53 | constructor(depth?: number);
|
54 | /**
|
55 | * @returns true as ShaMapInner is an inner node
|
56 | */
|
57 | isInner(): boolean;
|
58 | /**
|
59 | * @returns false as ShaMapInner is not a leaf node
|
60 | */
|
61 | isLeaf(): boolean;
|
62 | /**
|
63 | * Get the hash prefix for this node
|
64 | *
|
65 | * @returns hash prefix describing an inner node
|
66 | */
|
67 | hashPrefix(): Uint8Array;
|
68 | /**
|
69 | * Set a branch of this node to be another node
|
70 | *
|
71 | * @param slot Slot to add branch to this.branches
|
72 | * @param branch Branch to add
|
73 | */
|
74 | setBranch(slot: number, branch: ShaMapNode): void;
|
75 | /**
|
76 | * @returns true if node is empty
|
77 | */
|
78 | empty(): boolean;
|
79 | /**
|
80 | * Compute the hash of this node
|
81 | *
|
82 | * @returns The hash of this node
|
83 | */
|
84 | hash(): Hash256;
|
85 | /**
|
86 | * Writes the bytes representation of this node to a BytesList
|
87 | *
|
88 | * @param list BytesList to write bytes to
|
89 | */
|
90 | toBytesSink(list: BytesList): void;
|
91 | /**
|
92 | * Add item to the SHAMap
|
93 | *
|
94 | * @param index Hash of the index of the item being inserted
|
95 | * @param item Item to insert in the map
|
96 | * @param leaf Leaf node to insert when branch doesn't exist
|
97 | */
|
98 | addItem(index?: Hash256, item?: ShaMapNode, leaf?: ShaMapLeaf): void;
|
99 | }
|
100 | declare class ShaMap extends ShaMapInner {
|
101 | }
|
102 | export { ShaMap, ShaMapNode, ShaMapLeaf };
|