Documentation
¶
Index ¶
- Variables
- func Assert(condition bool, message string)
- func CheckLeafNode(tree []BytesLike, i int)
- func CheckValidMerkleNode(node BytesLike)
- func Compare(a BytesLike, b BytesLike) (int, error)
- func Concat(values ...BytesLike) ([]byte, error)
- func Invariant(condition bool, message string)
- func InvariantWithDebug(condition bool, message string, debugInfo interface{})
- func IsInternalNode(tree []BytesLike, i int) bool
- func IsLeafNode(tree []BytesLike, i int) bool
- func IsTreeNode(tree []BytesLike, i int) bool
- func IsValidMerkleNode(node BytesLike) bool
- func IsValidMerkleTree(tree []HexString, nodeHash NodeHash) bool
- func LeftChildIndex(i int) int
- func ParentIndex(i int) int
- func RightChildIndex(i int) int
- func SafePanic(message string)
- func SiblingIndex(i int) int
- func ToBytes(value BytesLike) ([]byte, error)
- func ValidateArgument(condition bool, message string)
- func VerifySimpleMerkleTree(root BytesLike, leaf BytesLike, proof []BytesLike, nodeHash NodeHash) bool
- func VerifyStandardMerkleTree[T any](root BytesLike, leaf T, proof []BytesLike) bool
- type BytesLike
- type HexString
- func FormatLeaf(value BytesLike) HexString
- func GetProof(tree []BytesLike, index int) []HexString
- func MakeMerkleTree(hashes []BytesLike, nodeHash NodeHash) []HexString
- func PrepareMerkleTree[T any](values []T, options MerkleTreeOptions, leafHash func(T) HexString, ...) ([]HexString, []struct{ ... })
- func ProcessMultiProof(multiproof MultiProof, nodeHash NodeHash) HexString
- func ProcessProof(leaf BytesLike, proof []BytesLike, nodeHash NodeHash) HexString
- func StandardLeafHash[T any](value T) HexString
- func StandardNodeHash(a BytesLike, b BytesLike) HexString
- func ToHex(value BytesLike) (HexString, error)
- type LeafHash
- type MerkleTreeImpl
- func (m *MerkleTreeImpl[T]) GetProof(leaf interface{}) []HexString
- func (m *MerkleTreeImpl[T]) LeafHashFromInput(leaf interface{}) HexString
- func (m *MerkleTreeImpl[T]) Root() HexString
- func (m *MerkleTreeImpl[T]) Validate()
- func (m *MerkleTreeImpl[T]) Verify(leaf interface{}, proof []HexString) bool
- type MerkleTreeOptions
- type MultiProof
- type NodeHash
- type SimpleMerkleTree
- type SimpleMerkleTreeData
- type SimpleMerkleTreeOptions
- type StandardMerkleTree
- type StandardMerkleTreeData
Constants ¶
This section is empty.
Variables ¶
var DefaultOptions = MerkleTreeOptions{ SortLeaves: true, }
DefaultOptions rappresenta la configurazione predefinita per un Merkle Tree
Functions ¶
func CheckLeafNode ¶
CheckLeafNode verifica se un indice è una foglia nell'albero di Merkle
func CheckValidMerkleNode ¶
func CheckValidMerkleNode(node BytesLike)
func Compare ¶
Compare confronta due BytesLike e restituisce -1, 0, 1 (equivalente alla funzione compare in TypeScript)
func InvariantWithDebug ¶
InvariantWithDebug permette di fornire messaggi più dettagliati per il debug
func IsInternalNode ¶
IsInternalNode verifica se l'indice `i` è un nodo interno dell'albero di Merkle
func IsLeafNode ¶
IsLeafNode verifica se un indice `i` è una foglia nell'albero di Merkle
func IsTreeNode ¶
IsTreeNode verifica se l'indice `i` è un nodo valido nell'albero
func IsValidMerkleNode ¶
func IsValidMerkleTree ¶
IsValidMerkleTree verifica se un Merkle Tree è valido
func LeftChildIndex ¶
func ParentIndex ¶
Funzioni di supporto per gli indici degli alberi di Merkle ParentIndex restituisce l'indice del nodo genitore per un nodo dato
func RightChildIndex ¶
func SafePanic ¶
func SafePanic(message string)
SafePanic permette di catturare gli errori e fornire messaggi dettagliati senza crash immediato
func SiblingIndex ¶
SiblingIndex restituisce l'indice del nodo fratello per un nodo dato
func ToBytes ¶
ToBytes converte un BytesLike in un array di byte (equivalente a hexToBytes in TypeScript)
func ValidateArgument ¶
ValidateArgument verifica una condizione e causa un panic se la condizione è falsa
Types ¶
type BytesLike ¶
type BytesLike interface{}
BytesLike rappresenta i tipi di dati compatibili con le operazioni di hashing
type HexString ¶
type HexString string
HexString rappresenta una stringa esadecimale
func FormatLeaf ¶
FormatLeaf converte un valore in un formato hashato per l'inserimento nel Merkle Tree
func MakeMerkleTree ¶
MakeMerkleTree costruisce un albero di Merkle a partire da una lista di hash delle foglie
func PrepareMerkleTree ¶
func PrepareMerkleTree[T any](values []T, options MerkleTreeOptions, leafHash func(T) HexString, nodeHash NodeHash) ([]HexString, []struct { Value T TreeIndex int })
PrepareMerkleTree costruisce l'albero di Merkle e assegna gli indici corretti alle foglie
func ProcessMultiProof ¶
func ProcessMultiProof(multiproof MultiProof, nodeHash NodeHash) HexString
ProcessMultiProof verifica una proof multipla e calcola la root risultante
func ProcessProof ¶
ProcessProof verifica la proof data e calcola la root risultante
func StandardLeafHash ¶
StandardLeafHash calcola l'hash standard di una foglia, utilizzando l'encoding ABI come su Ethereum
func StandardNodeHash ¶
StandardNodeHash calcola l'hash standard di due nodi
type MerkleTreeImpl ¶
type MerkleTreeImpl[T any] struct { Tree []HexString Values []struct { Value T TreeIndex int } LeafHash func(T) HexString NodeHash NodeHash HashLookup map[HexString]int }
MerkleTreeImpl è la struttura base del Merkle Tree
func (*MerkleTreeImpl[T]) GetProof ¶
func (m *MerkleTreeImpl[T]) GetProof(leaf interface{}) []HexString
GetProof genera una proof per un valore specifico
func (*MerkleTreeImpl[T]) LeafHashFromInput ¶
func (m *MerkleTreeImpl[T]) LeafHashFromInput(leaf interface{}) HexString
LeafHashFromInput calcola l'hash della foglia, assicurando coerenza con la costruzione
func (*MerkleTreeImpl[T]) Root ¶
func (m *MerkleTreeImpl[T]) Root() HexString
Root restituisce la root dell'albero di Merkle
func (*MerkleTreeImpl[T]) Validate ¶
func (m *MerkleTreeImpl[T]) Validate()
Validate verifica se l'albero è strutturalmente valido
func (*MerkleTreeImpl[T]) Verify ¶
func (m *MerkleTreeImpl[T]) Verify(leaf interface{}, proof []HexString) bool
Verify verifica se una proof è valida
type MerkleTreeOptions ¶
type MerkleTreeOptions struct {
SortLeaves bool `json:"sortLeaves"` // Se true, le foglie vengono ordinate per facilitare le multiproof
}
MerkleTreeOptions definisce le opzioni di configurazione per la costruzione dell'albero di Merkle.
func NewMerkleTreeOptions ¶
func NewMerkleTreeOptions(options *MerkleTreeOptions) MerkleTreeOptions
NewMerkleTreeOptions crea un oggetto `MerkleTreeOptions` con valori predefiniti se non specificati
type MultiProof ¶
type MultiProof struct {
Leaves []HexString // Hash delle foglie incluse nella proof
Proof []HexString // Lista dei nodi necessari per il calcolo della root
ProofFlags []bool // Indica quali nodi devono essere combinati
}
func GetMultiProof ¶
func GetMultiProof(tree []BytesLike, indices []int) MultiProof
GetMultiProof genera una proof multipla per un insieme di foglie
type SimpleMerkleTree ¶
type SimpleMerkleTree struct {
MerkleTreeImpl[BytesLike]
}
SimpleMerkleTree rappresenta un Merkle Tree con hashing standard
func NewSimpleMerkleTree ¶
func NewSimpleMerkleTree(values []BytesLike, options SimpleMerkleTreeOptions) *SimpleMerkleTree
NewSimpleMerkleTree crea un nuovo SimpleMerkleTree con i valori dati
func (*SimpleMerkleTree) Dump ¶
func (m *SimpleMerkleTree) Dump() SimpleMerkleTreeData
Dump esporta i dati dell'albero per debugging o archiviazione
type SimpleMerkleTreeData ¶
type SimpleMerkleTreeData struct {
Format string
Tree []HexString
Values []struct {
Value BytesLike
TreeIndex int
}
Hash string
}
SimpleMerkleTreeData rappresenta i dati di un Simple Merkle Tree
type SimpleMerkleTreeOptions ¶
type SimpleMerkleTreeOptions struct {
MerkleTreeOptions // Includiamo le opzioni base del Merkle Tree
NodeHash NodeHash
}
SimpleMerkleTreeOptions rappresenta le opzioni per il Simple Merkle Tree
type StandardMerkleTree ¶
type StandardMerkleTree[T any] struct { MerkleTreeImpl[T] }
StandardMerkleTree rappresenta un Merkle Tree con encoding standard
func NewStandardMerkleTree ¶
func NewStandardMerkleTree[T any](values []T, options MerkleTreeOptions) *StandardMerkleTree[T]
NewStandardMerkleTree crea un nuovo StandardMerkleTree con i valori dati
func (*StandardMerkleTree[T]) Dump ¶
func (m *StandardMerkleTree[T]) Dump() StandardMerkleTreeData[T]
Dump esporta i dati dell'albero per debugging o archiviazione