@ethereumjs/trie
- BranchNode
- CheckpointDB
- ExtensionNode
- LeafNode
- PrioritizedTaskExecutor
- Trie
- TrieReadStream
- WalkController
- Checkpoint
- EmbeddedNode
- FoundNodeFunction
- HashKeysFunction
- Nibbles
- Proof
- TrieNode
- TrieOptsWithDefaults
- byteTypeToNibbleType
- bytesToNibbles
- compactBytesToNibbles
- decodeNode
- decodeRawNode
- genesisStateRoot
- hasTerminator
- hexToKeybytes
- isRawNode
- mergeAndFormatKeyPaths
- nibbleTypeToByteType
- nibbleTypeToPackedBytes
- nibblesToBytes
- nibblesToCompactBytes
- pathToHexKey
- verifyRangeProof
Ƭ Checkpoint: Object
Name | Type |
---|---|
keyValueMap |
Map <string , Uint8Array | undefined > |
root |
Uint8Array |
packages/trie/src/types.ts:135
Ƭ EmbeddedNode: Uint8Array
| Uint8Array
[]
Ƭ FoundNodeFunction: (nodeRef
: Uint8Array
, node
: TrieNode
| null
, key
: Nibbles
, walkController
: WalkController
) => void
▸ (nodeRef
, node
, key
, walkController
): void
Name | Type |
---|---|
nodeRef |
Uint8Array |
node |
TrieNode | null |
key |
Nibbles |
walkController |
WalkController |
void
Ƭ HashKeysFunction: (msg
: Uint8Array
) => Uint8Array
▸ (msg
): Uint8Array
Name | Type |
---|---|
msg |
Uint8Array |
Uint8Array
Ƭ Nibbles: number
[]
Ƭ Proof: Uint8Array
[]
Ƭ TrieNode: BranchNode
| ExtensionNode
| LeafNode
Ƭ TrieOptsWithDefaults: TrieOpts
& { cacheSize
: number
; useKeyHashing
: boolean
; useKeyHashingFunction
: HashKeysFunction
; useNodePruning
: boolean
; useRootPersistence
: boolean
}
packages/trie/src/types.ts:105
• Const
ROOT_DB_KEY: Uint8Array
packages/trie/src/types.ts:142
▸ byteTypeToNibbleType(key
): Nibbles
Turns each byte into a single nibble, only extracting the lower nibble of each byte
Name | Type | Description |
---|---|---|
key |
Uint8Array |
Uint8Array typed byte array |
Nibble typed nibble array
packages/trie/src/util/encoding.ts:144
▸ bytesToNibbles(str
): Uint8Array
Name | Type |
---|---|
str |
Uint8Array |
Uint8Array
packages/trie/src/util/encoding.ts:77
▸ compactBytesToNibbles(compact
): Uint8Array
Name | Type |
---|---|
compact |
Uint8Array |
Uint8Array
packages/trie/src/util/encoding.ts:91
▸ decodeNode(node
): BranchNode
| ExtensionNode
| LeafNode
Name | Type |
---|---|
node |
Uint8Array |
BranchNode
| ExtensionNode
| LeafNode
packages/trie/src/node/util.ts:30
▸ decodeRawNode(raw
): BranchNode
| ExtensionNode
| LeafNode
Name | Type |
---|---|
raw |
Uint8Array [] |
BranchNode
| ExtensionNode
| LeafNode
packages/trie/src/node/util.ts:12
▸ genesisStateRoot(genesisState
): Promise
<Uint8Array
>
Derives the stateRoot of the genesis block based on genesis allocations
Name | Type |
---|---|
genesisState |
GenesisState |
Promise
<Uint8Array
>
packages/trie/src/util/genesisState.ts:12
▸ hasTerminator(nibbles
): boolean
Name | Type |
---|---|
nibbles |
Uint8Array |
boolean
boolean indicating if input hex nibble sequence has terminator indicating leaf-node terminator is represented with 16 because a nibble ranges from 0 - 15(f)
packages/trie/src/util/encoding.ts:31
▸ hexToKeybytes(hex
): Uint8Array
Name | Type |
---|---|
hex |
Uint8Array |
Uint8Array
packages/trie/src/util/encoding.ts:41
▸ isRawNode(n
): n is Uint8Array[]
Name | Type |
---|---|
n |
Uint8Array | NestedUint8Array |
n is Uint8Array[]
packages/trie/src/node/util.ts:26
▸ mergeAndFormatKeyPaths(pathStrings
): Uint8Array
[][]
Name | Type |
---|---|
pathStrings |
string [] |
Uint8Array
[][]
packages/trie/src/util/encoding.ts:175
▸ nibbleTypeToByteType(arr
): Uint8Array
Converts each nibble into a single byte
Name | Type | Description |
---|---|---|
arr |
Nibbles |
Nibble typed nibble array |
Uint8Array
Uint8Array typed byte array
packages/trie/src/util/encoding.ts:128
▸ nibbleTypeToPackedBytes(arr
): Uint8Array
Packs every two nibbles into a single byte
Name | Type | Description |
---|---|---|
arr |
Nibbles |
Nibble typed nibble array |
Uint8Array
Uint8Array typed byte array
packages/trie/src/util/encoding.ts:112
▸ nibblesToBytes(nibbles
, bytes
): void
Name | Type |
---|---|
nibbles |
Uint8Array |
bytes |
Uint8Array |
void
packages/trie/src/util/encoding.ts:35
▸ nibblesToCompactBytes(nibbles
): Uint8Array
Name | Type |
---|---|
nibbles |
Uint8Array |
Uint8Array
packages/trie/src/util/encoding.ts:55
▸ pathToHexKey(path
, extension
, retType
): Uint8Array
Takes a string path and extends it by the given extension nibbles
Name | Type | Description |
---|---|---|
path |
string |
String node path |
extension |
Nibbles |
nibbles to extend by |
retType |
string |
string indicating whether to return the key in "keybyte" or "hex" encoding |
Uint8Array
hex-encoded key
packages/trie/src/util/encoding.ts:164
▸ verifyRangeProof(rootHash
, firstKey
, lastKey
, keys
, values
, proof
, useKeyHashingFunction
): Promise
<boolean
>
verifyRangeProof checks whether the given leaf nodes and edge proof can prove the given trie leaves range is matched with the specific root.
There are four situations:
-
All elements proof. In this case the proof can be null, but the range should be all the leaves in the trie.
-
One element proof. In this case no matter the edge proof is a non-existent proof or not, we can always verify the correctness of the proof.
-
Zero element proof. In this case a single non-existent proof is enough to prove. Besides, if there are still some other leaves available on the right side, then an error will be returned.
-
Two edge elements proof. In this case two existent or non-existent proof(first and last) should be provided.
NOTE: Currently only supports verification when the length of firstKey and lastKey are the same.
Name | Type | Description |
---|---|---|
rootHash |
Uint8Array |
root hash of state trie this proof is being verified against. |
firstKey |
null | Nibbles |
first key of range being proven. |
lastKey |
null | Nibbles |
last key of range being proven. |
keys |
Nibbles [] |
key list of leaf data being proven. |
values |
Uint8Array [] |
value list of leaf data being proven, one-to-one correspondence with keys. |
proof |
null | Uint8Array [] |
proof node list, if all-elements-proof where no proof is needed, proof should be null, and both firstKey and lastKey must be null as well |
useKeyHashingFunction |
HashKeysFunction |
- |
Promise
<boolean
>
a flag to indicate whether there exists more trie node in the trie