Documentation
¶
Index ¶
- type BatchMetadata
- type Block
- type Chain
- type Checkpoint
- type LocalChain
- func (lc *LocalChain) ChainHeight(ctx context.Context) (uint64, error)
- func (lc *LocalChain) GetBlock(ctx context.Context, height uint64) (*Block, error)
- func (lc *LocalChain) GetLatestCheckpoint(ctx context.Context) (*Checkpoint, error)
- func (lc *LocalChain) SubmitBatch(ctx context.Context, root []byte, metadata BatchMetadata) (string, uint64, error)
- func (lc *LocalChain) VerifyBatch(ctx context.Context, txHash string, expectedRoot []byte) (bool, error)
- func (lc *LocalChain) VerifyChainIntegrity(ctx context.Context) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BatchMetadata ¶
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 ¶
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) 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.