sealchain

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2026 License: AGPL-3.0 Imports: 16 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

sealchain

sealchain is a Go library for append-only, tamper-evident audit logs backed by SHA-256 hash chains and Ed25519 signatures.

Why sealchain

  • Dual-mechanism integrity — a SHA-256 hash chain proves ordering and continuity within a log; Ed25519 signatures prove actor authenticity. Each mechanism catches what the other cannot.
  • Domain extensibility — define your own event types and payload fields. sealchain has no opinion about what you log.
  • JSONL on disk — one JSON object per line. Human-readable, greppable, no database required.
  • Log rotation — split logs across files with unbroken cryptographic chain. CFR Part 11 compliant.

Quick Start

go get github.com/parallelhours/sealchain@latest
package main

import (
    "crypto/ed25519"
    "crypto/rand"
    "encoding/binary"
    "fmt"
    "log"

    "github.com/mr-tron/base58"
    sealchain "github.com/parallelhours/sealchain"
)

// Define your own event types.
const EventDocumentStored sealchain.EventType = "DOCUMENT_STORED"

// actor implements sealchain.Signer using Ed25519.
type actor struct {
    did     string
    privKey ed25519.PrivateKey
}

func (a *actor) Sign(msg []byte) ([]byte, error) {
    return ed25519.Sign(a.privKey, msg), nil
}

func newActor() (*actor, error) {
    pub, priv, err := ed25519.GenerateKey(rand.Reader)
    if err != nil {
        return nil, err
    }
    buf := make([]byte, binary.MaxVarintLen64+len(pub))
    n := binary.PutUvarint(buf, 0xed)
    copy(buf[n:], pub)
    did := "did:key:z" + base58.Encode(buf[:n+len(pub)])
    return &actor{did: did, privKey: priv}, nil
}

func main() {
    a, err := newActor()
    if err != nil {
        log.Fatal(err)
    }

    l := sealchain.NewLog("/var/log/myapp/audit-log.000.jsonl")

    err = l.Append(sealchain.Entry{
        Event:  EventDocumentStored,
        Domain: sealchain.DomainEntry{"document": "report-q1.pdf", "user": "alice"},
    }, a.did, a)
    if err != nil {
        log.Fatal(err)
    }

    if err := l.Verify(); err != nil {
        log.Fatal("log integrity check failed:", err)
    }
    fmt.Println("log verified OK")
}

Log Rotation

Rotate logs while preserving cryptographic chain integrity:

// Rotate to next generation (e.g., audit-log.000.jsonl -> audit-log.001.jsonl)
newLog, err := log.Rotate(sealchain.RotationManual, actorDID, signer)
if err != nil {
    log.Fatal(err)
}
// newLog is the next generation log (audit-log.001.jsonl)

Logs use numbered naming (audit-log.000.jsonl, audit-log.001.jsonl). Each rotation writes a terminus entry (end of old log) and genesis entry (start of new log), cross-linked by fingerprints.

Verify the entire chain across rotated logs:

if err := sealchain.VerifyChain("/var/log/myapp", "audit-log"); err != nil {
    log.Fatal("chain verification failed:", err)
}

sealcheck CLI

Verify an audit log file from the command line — no code required:

go install github.com/parallelhours/sealchain/cmd/sealcheck@latest

# Verify single log
sealcheck verify /var/log/myapp/audit-log.000.jsonl
# OK: 42 entries verified

# Verify cross-log chain (with rotation)
sealcheck verify-chain /var/log/myapp audit-log
# verify-chain: chain valid

Exit codes: 0 = valid, 1 = tampered or corrupt, 2 = usage error.

Documentation

  • Core Concepts — hash chains, genesis sentinel, signature scope, and security guarantees
  • Integration Guide — embedding sealchain in your Go project
  • Log Rotation — rotation design, CFR Part 11 compliance, API reference
  • Licensing — AGPL v3 and commercial license options

License

sealchain is dual-licensed:

  • AGPL v3 — free for open source use. If you distribute or run a service that includes sealchain, your project must also be licensed under AGPL v3. See LICENSE.
  • Commercial license — for closed-source products or SaaS deployments without copyleft obligations. Contact support@parallelhours.io.

See docs/licensing.md for details.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultRotatePath added in v0.3.0

func DefaultRotatePath(currentPath string) (string, error)

DefaultRotatePath returns the next rotated log path for the given current path. Rotated logs use zero-padded sequence numbers: audit-log.001.jsonl, audit-log.002.jsonl, etc.

func MarshalForSign

func MarshalForSign(v any) ([]byte, error)

func VerifyChain added in v0.3.0

func VerifyChain(logDir string, baseName string) error

VerifyChain validates the cross-log rotation integrity. All logs use the naming pattern: baseName.NNN.jsonl (e.g., audit-log.000.jsonl) Logs are ordered by generation number and verified in sequence.

Types

type Domain

type Domain interface {
	Fields() map[string]any
}

type DomainEntry

type DomainEntry map[string]any

func (DomainEntry) Fields

func (d DomainEntry) Fields() map[string]any

type Entry

type Entry struct {
	Foundation Foundation `json:"foundation"`
	Domain     Domain     `json:"domain,omitempty"`
	Event      EventType  `json:"event"`
}

func (Entry) MarshalJSON

func (e Entry) MarshalJSON() ([]byte, error)

MarshalJSON implements custom JSON marshaling to ensure stable field ordering for the Domain field, which is critical for signature verification.

func (*Entry) UnmarshalJSON

func (e *Entry) UnmarshalJSON(data []byte) error

type EventType

type EventType string
const (
	EventLogTerminus EventType = "log.terminus"
	EventLogGenesis  EventType = "log.genesis"
)

Library-internal event types for the rotation feature. These are not domain-specific; callers define their own EventType constants.

type Foundation

type Foundation struct {
	Seq       uint64 `json:"seq"`
	PrevHash  string `json:"prev_hash"`
	ActorDID  string `json:"actor_did"`
	Timestamp string `json:"timestamp"`
	Signature string `json:"signature"`

	// Rotation fields (only populated for genesis/terminus entries)
	LogRole string `json:"log_role,omitempty"` // "genesis" or "terminus"
	LogRef  string `json:"log_ref,omitempty"`  // for genesis: previous log path; for terminus: next log path
}

type Log

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

func NewLog

func NewLog(path string) *Log

func (*Log) Append

func (l *Log) Append(e Entry, did string, s Signer) error

func (*Log) Entries

func (l *Log) Entries() ([]Entry, error)

func (*Log) Fingerprint added in v0.3.0

func (l *Log) Fingerprint() (string, error)

Fingerprint returns the SHA-256 hash of the entire log file.

func (*Log) IsGenesis added in v0.3.0

func (l *Log) IsGenesis() bool

IsGenesis returns true if the first entry is a genesis entry.

func (*Log) IsTerminus added in v0.3.0

func (l *Log) IsTerminus() bool

IsTerminus returns true if the last entry is a terminus entry.

func (*Log) Path added in v0.3.0

func (l *Log) Path() string

Path returns the file path of the log.

func (*Log) Rotate added in v0.3.0

func (l *Log) Rotate(reason RotationReason, did string, s Signer) (*Log, error)

Rotate performs atomic log rotation. It writes a terminus entry to the current log, then creates a new log at the NEXT sequence number with a genesis entry. Returns the new Log instance (next generation).

func (*Log) Verify

func (l *Log) Verify() error

type RotationReason added in v0.3.0

type RotationReason string
const (
	RotationSize   RotationReason = "size_threshold"
	RotationTime   RotationReason = "time_threshold"
	RotationManual RotationReason = "manual"
)

type Signer

type Signer interface {
	Sign(message []byte) ([]byte, error)
}

Directories

Path Synopsis
cmd
sealcheck command

Jump to

Keyboard shortcuts

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