MerkleTrie

org.sigilaris.core.merkle.MerkleTrie
object MerkleTrie

Merkle Trie operations providing key-value storage with cryptographic verification.

A Merkle Trie is a tree structure where:

  • Keys are represented as Nibbles (4-bit sequences)
  • Each node has a hash computed from its contents
  • The root hash uniquely identifies the entire tree state

All operations are effectful and maintain state through MerkleTrieState, which tracks the root hash and accumulated differences.

Attributes

See also

MerkleTrieNode for node structure

MerkleTrieState for state management

Nibbles for key representation

Source
MerkleTrie.scala
Graph
Supertypes
class Object
trait Matchable
class Any
Self type
MerkleTrie.type

Members list

Type members

Classlikes

Attributes

Companion
trait
Source
MerkleTrie.scala
Supertypes
trait Sum
trait Mirror
class Object
trait Matchable
class Any
Self type
sealed trait StrictTraversalError extends Product, Serializable

Typed failures returned by strict trie traversal APIs.

Typed failures returned by strict trie traversal APIs.

Attributes

Companion
object
Source
MerkleTrie.scala
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
Known subtypes

Identifies where a strict traversal failed to resolve a referenced node.

Identifies where a strict traversal failed to resolve a referenced node.

Attributes

Source
MerkleTrie.scala
Supertypes
trait Enum
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Types

type NodeStore[F[_]] = Kleisli[[_] =>> EitherT[F, String, _$2], MerkleHash, Option[MerkleTrieNode]]

Storage layer for retrieving nodes by hash.

Storage layer for retrieving nodes by hash.

Type parameters

F

the effect type

Attributes

Source
MerkleTrie.scala

Value members

Concrete methods

def get[F[_] : Monad : NodeStore](key: Nibbles): StateT[[_] =>> EitherT[F, String, _$4], MerkleTrieState, Option[ByteVector]]

Retrieves a value by key from the Merkle Trie.

Retrieves a value by key from the Merkle Trie.

Traverses the trie from the root, following the nibble path to find the value associated with the given key.

Type parameters

F

the effect type

Value parameters

key

the key to look up

Attributes

Returns

stateful computation returning the value if found

Source
MerkleTrie.scala

Computes the common prefix and remainders of two Nibbles.

Computes the common prefix and remainders of two Nibbles.

Finds the longest common prefix and splits both Nibbles accordingly.

Value parameters

nibbles0

first Nibbles

nibbles1

second Nibbles

Attributes

Returns

(common prefix, remainder0, remainder1)

Source
MerkleTrie.scala
def getNode[F[_]](state: MerkleTrieState)(using evidence$1: Monad[F], ns: NodeStore[F]): EitherT[F, String, Option[MerkleTrieNode]]

Retrieves the root node from state.

Retrieves the root node from state.

Checks the diff first, then falls back to the node store.

Type parameters

F

the effect type

Value parameters

ns

the node store

state

the trie state

Attributes

Returns

Some(node) if root exists, None otherwise

Source
MerkleTrie.scala
def getNodeAndStateRoot[F[_]](state: MerkleTrieState)(using evidence$1: Monad[F], ns: NodeStore[F]): EitherT[F, String, Option[(MerkleTrieNode, MerkleHash)]]

Retrieves the root node and its hash from state.

Retrieves the root node and its hash from state.

Checks the diff first, then falls back to the node store.

Type parameters

F

the effect type

Value parameters

ns

the node store

state

the trie state

Attributes

Returns

Some((node, hash)) if root exists, None otherwise

Source
MerkleTrie.scala
def put[F[_] : Monad : NodeStore](key: Nibbles, value: ByteVector): StateT[[_] =>> EitherT[F, String, _$10], MerkleTrieState, Unit]

Inserts or updates a key-value pair in the Merkle Trie.

Inserts or updates a key-value pair in the Merkle Trie.

Updates the trie structure, creating or modifying nodes as needed. The state is updated with the new root hash and accumulated differences.

Type parameters

F

the effect type

Value parameters

key

the key to insert

value

the value to associate with the key

Attributes

Returns

stateful computation that updates the trie

Source
MerkleTrie.scala
def remove[F[_] : Monad : NodeStore](key: Nibbles): StateT[[_] =>> EitherT[F, String, _$12], MerkleTrieState, Boolean]

Removes a key-value pair from the Merkle Trie.

Removes a key-value pair from the Merkle Trie.

Deletes the node at the given key and updates parent nodes. May collapse branches when they become unnecessary.

Type parameters

F

the effect type

Value parameters

key

the key to remove

Attributes

Returns

stateful computation returning true if key was found and removed

Source
MerkleTrie.scala
def reverseStreamFrom[F[_] : Monad : NodeStore](keyPrefix: Nibbles, keySuffix: Option[Nibbles]): StateT[[_] =>> EitherT[F, String, _$31], MerkleTrieState, Stream[[_] =>> EitherT[F, String, _$32], (Nibbles, ByteVector)]]

Streams key-value pairs in reverse lexicographic order.

Streams key-value pairs in reverse lexicographic order.

Returns pairs starting with keyPrefix, up to (but not including) keyPrefix

  • keySuffix if provided.

Type parameters

F

the effect type

Value parameters

keyPrefix

the key prefix (inclusive)

keySuffix

optional suffix to limit the range (exclusive)

Attributes

Returns

stateful computation returning a reverse stream of (key, value) pairs

Source
MerkleTrie.scala
def streamFrom[F[_] : Monad : NodeStore](key: Nibbles): StateT[[_] =>> EitherT[F, String, _$17], MerkleTrieState, Stream[[_] =>> EitherT[F, String, _$18], (Nibbles, ByteVector)]]

Streams all key-value pairs starting from the given key.

Streams all key-value pairs starting from the given key.

Returns pairs in lexicographic order by key.

Type parameters

F

the effect type

Value parameters

key

the starting key (inclusive)

Attributes

Returns

stateful computation returning a stream of (key, value) pairs

Source
MerkleTrie.scala
def strictReverseStreamFrom[F[_] : Monad : NodeStore](keyPrefix: Nibbles, keySuffix: Option[Nibbles]): StateT[[_] =>> EitherT[F, StrictTraversalError, _$35], MerkleTrieState, Stream[[_] =>> EitherT[F, StrictTraversalError, _$36], (Nibbles, ByteVector)]]

Strictly streams key-value pairs in reverse lexicographic order.

Strictly streams key-value pairs in reverse lexicographic order.

A non-empty root or referenced descendant that cannot be resolved is a typed failure rather than an empty or partial stream.

Attributes

Source
MerkleTrie.scala
def strictStreamFrom[F[_] : Monad : NodeStore](key: Nibbles): StateT[[_] =>> EitherT[F, StrictTraversalError, _$21], MerkleTrieState, Stream[[_] =>> EitherT[F, StrictTraversalError, _$22], (Nibbles, ByteVector)]]

Strictly streams all key-value pairs starting from the given key.

Strictly streams all key-value pairs starting from the given key.

Unlike streamFrom, a non-empty root or referenced descendant that cannot be resolved from the state diff or node store is returned as a typed StrictTraversalError.MissingNode failure.

Attributes

Source
MerkleTrie.scala