hash_chain

package
v1.0.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 14, 2026 License: MIT Imports: 6 Imported by: 0

README

Hash Chain Validation Package - Provides cryptographic hash chain validation with Merkle tree integration for feed history integrity. Features include feed history integrity validation, tamper detection mechanisms, Merkle tree integration, audit logging, and integration with threat intel packages. API includes HashChainService and HashChainValidationService.

Documentation

Overview

Package hash_chain provides hash chain validation with Merkle tree integration.

This package implements a cryptographic hash chain system that provides:

  • Feed history integrity validation
  • Tamper detection mechanisms
  • Merkle tree integration for efficient verification
  • Audit logging for compliance
  • Integration with threat intel packages

The hash chain validation system is designed to work with feed-specific trust domains in AegisGate v0.19.0.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Hash

type Hash []byte

Hash is a generic hash value

func (Hash) String

func (h Hash) String() string

Hash.String returns hex representation of the hash

type HashChain

type HashChain struct {
	Entries    []*HashChainEntry
	MerkleTree []*merkleNode
	// contains filtered or unexported fields
}

HashChain represents a hash chain for a specific feed

func NewHashChain

func NewHashChain(feedID string, hashType HashType) *HashChain

NewHashChain creates a new hash chain for a feed

func (*HashChain) AddEntry

func (hc *HashChain) AddEntry(data []byte) (*HashChainEntry, error)

AddEntry adds a new entry to the hash chain

func (*HashChain) GetAuditLog

func (hc *HashChain) GetAuditLog() []*HashChainEntry

GetAuditLog returns the audit log entries

func (*HashChain) GetChainLength

func (hc *HashChain) GetChainLength() int

GetChainLength returns the number of entries in the chain

func (*HashChain) GetChainVerificationReport

func (hc *HashChain) GetChainVerificationReport() string

GetChainVerificationReport returns a verification report

func (*HashChain) GetEntry

func (hc *HashChain) GetEntry(seqNum uint64) (*HashChainEntry, bool)

GetEntry retrieves an entry by sequence number

func (*HashChain) GetEntryByHash

func (hc *HashChain) GetEntryByHash(hash Hash) (*HashChainEntry, bool)

GetEntryByHash retrieves an entry by its hash

func (*HashChain) GetEntryRange

func (hc *HashChain) GetEntryRange(start, end uint64) ([]*HashChainEntry, error)

GetEntryRange returns a range of entries

func (*HashChain) GetLastEntry

func (hc *HashChain) GetLastEntry() (*HashChainEntry, bool)

GetLastEntry returns the last entry in the chain

func (*HashChain) GetMerkleRoot

func (hc *HashChain) GetMerkleRoot() Hash

GetMerkleRoot returns the Merkle root hash

func (*HashChain) GetProof

func (hc *HashChain) GetProof(entry *HashChainEntry) ([]Hash, error)

GetProof generates a Merkle proof for an entry

func (*HashChain) IsValidChain

func (hc *HashChain) IsValidChain() bool

IsValidChain is a convenience method

func (*HashChain) VerifyChain

func (hc *HashChain) VerifyChain() (bool, error)

VerifyChain verifies the entire hash chain FIXED: Uses correct verification logic

func (*HashChain) VerifyChainFixed

func (hc *HashChain) VerifyChainFixed() (bool, error)

VerifyChainFixed is an alias for VerifyChain (for backward compatibility)

func (*HashChain) VerifyEntry

func (hc *HashChain) VerifyEntry(entry *HashChainEntry) (bool, error)

VerifyEntry verifies a single entry in the hash chain This is the correct implementation with proper locking

func (*HashChain) VerifyEntryFixed

func (hc *HashChain) VerifyEntryFixed(entry *HashChainEntry) (bool, error)

VerifyEntryFixed is an alias for VerifyEntry (for backward compatibility)

func (*HashChain) VerifyProof

func (hc *HashChain) VerifyProof(entryHash Hash, proof []Hash, root Hash) (bool, error)

VerifyProof verifies a Merkle proof

type HashChainEntry

type HashChainEntry struct {
	Hash         Hash      // Hash of the entry (computed from PayloadHash + PreviousHash + etc)
	PayloadHash  Hash      // Hash of the original data payload
	PreviousHash Hash      // Hash of the previous entry
	SequenceNum  uint64    // Sequence number of this entry
	Operation    string    // Operation performed
	Timestamp    time.Time // Timestamp of the entry
}

HashChainEntry represents a single entry in the hash chain

type HashStore

type HashStore interface {
	// GetChain returns a hash chain for a feed
	GetChain(feedID string) (*HashChain, error)

	// StoreHash stores a hash in the chain
	StoreHash(feedID string, hash string, previousHash string) error

	// VerifyHash verifies a hash in the chain
	VerifyHash(feedID string, hash string, previousHash string) (bool, error)

	// GetChainHashes returns all hashes for a feed
	GetChainHashes(feedID string) ([]string, error)

	// DeleteFeedHashes deletes all hashes for a feed
	DeleteFeedHashes(feedID string) error

	// VerifyChain verifies the integrity of a hash chain
	VerifyChain(feedID string) (bool, error)
}

HashStore defines the interface for hash storage

type HashType

type HashType int

HashType defines the hashing algorithm to use

const (
	SHA256 HashType = iota
	SHA512
)

type MemoryHashStore

type MemoryHashStore struct {
	// contains filtered or unexported fields
}

MemoryHashStore provides in-memory storage for hash chains

func NewMemoryHashStore

func NewMemoryHashStore() *MemoryHashStore

NewMemoryHashStore creates a new memory hash store

func (*MemoryHashStore) DeleteFeedHashes

func (mhs *MemoryHashStore) DeleteFeedHashes(feedID string) error

DeleteFeedHashes deletes all hashes for a feed

func (*MemoryHashStore) GetChain

func (mhs *MemoryHashStore) GetChain(feedID string) (string, error)

GetChain retrieves hashes for a feed

func (*MemoryHashStore) GetChainHashes

func (mhs *MemoryHashStore) GetChainHashes(feedID string) ([]string, error)

GetChainHashes returns all hashes for a feed

func (*MemoryHashStore) StoreHash

func (mhs *MemoryHashStore) StoreHash(feedID, hash, previousHash string) error

StoreHash stores a hash in the store

func (*MemoryHashStore) VerifyChain

func (mhs *MemoryHashStore) VerifyChain(feedID string) (bool, error)

VerifyChain verifies a chain in the store

func (*MemoryHashStore) VerifyHash

func (mhs *MemoryHashStore) VerifyHash(feedID, hash, previousHash string) (bool, error)

VerifyHash verifies a hash exists in the store

type ValidationError

type ValidationError struct {
	Code    string
	Message string
}

ValidationError represents an error during chain verification

func (*ValidationError) Error

func (e *ValidationError) Error() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL