blockchain

package
v0.0.0-...-e617a74 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2026 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BatchMetadata

type BatchMetadata struct {
	SourceFile string
	LeafCount  int
	TreeHeight int
	NodeDID    string
}

BatchMetadata holds information about a Merkle batch being anchored.

type Block

type Block struct {
	Height     uint64
	MerkleRoot []byte
	PrevHash   []byte
	Hash       []byte
	Timestamp  time.Time
	NodeDID    string
	Signature  []byte
	Metadata   BatchMetadata
}

Block represents a single block in the local chain.

type Chain

type Chain interface {
	// SubmitBatch anchors a Merkle root hash on the chain.
	SubmitBatch(ctx context.Context, root []byte, metadata BatchMetadata) (txHash string, blockHeight uint64, err error)

	// VerifyBatch checks that a previously submitted batch matches the chain.
	VerifyBatch(ctx context.Context, txHash string, expectedRoot []byte) (bool, error)

	// GetLatestCheckpoint returns the most recent anchored checkpoint.
	GetLatestCheckpoint(ctx context.Context) (*Checkpoint, error)

	// GetBlock returns a specific block by height.
	GetBlock(ctx context.Context, height uint64) (*Block, error)

	// ChainHeight returns the current chain height.
	ChainHeight(ctx context.Context) (uint64, error)
}

Chain is the interface for blockchain backends. The local chain is the default; Ethereum/Polygon can be added later.

type Checkpoint

type Checkpoint struct {
	Height    uint64
	BlockHash []byte
	RootHash  []byte
	Timestamp time.Time
}

Checkpoint represents a verified point in the blockchain.

type LocalChain

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

LocalChain implements Chain using an append-only SQLite-backed block store.

func NewLocalChain

func NewLocalChain(s *store.Store, nodeDID string, privateKey ed25519.PrivateKey) *LocalChain

NewLocalChain creates a new local blockchain instance.

func (*LocalChain) ChainHeight

func (lc *LocalChain) ChainHeight(ctx context.Context) (uint64, error)

ChainHeight returns the current chain height.

func (*LocalChain) GetBlock

func (lc *LocalChain) GetBlock(ctx context.Context, height uint64) (*Block, error)

GetBlock returns a specific block by height.

func (*LocalChain) GetLatestCheckpoint

func (lc *LocalChain) GetLatestCheckpoint(ctx context.Context) (*Checkpoint, error)

GetLatestCheckpoint returns the most recent block as a checkpoint.

func (*LocalChain) SubmitBatch

func (lc *LocalChain) SubmitBatch(ctx context.Context, root []byte, metadata BatchMetadata) (string, uint64, error)

SubmitBatch creates a new block containing the given Merkle root.

func (*LocalChain) VerifyBatch

func (lc *LocalChain) VerifyBatch(ctx context.Context, txHash string, expectedRoot []byte) (bool, error)

VerifyBatch checks that a block at the given txHash contains the expected root.

func (*LocalChain) VerifyChainIntegrity

func (lc *LocalChain) VerifyChainIntegrity(ctx context.Context) error

VerifyChainIntegrity walks the entire chain and verifies hash linkage.

Jump to

Keyboard shortcuts

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