sqlitestore

package
v0.0.0-...-fa82db8 Latest Latest
Warning

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

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

Documentation

Overview

Package sqlitestore is the SQLCipher-backed implementation of anonauth.PseudonymStore. The pseudonym database lives in its own encrypted file with a key derived from the deployment's master seed via a dedicated HKDF info string, so the queue-storage seed and this file's seed never share derivation paths even when they share the same underlying secret.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Store

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

Store is the SQLCipher-backed pseudonym store.

func New

func New(seed [masterSeedBytes]byte, dataDir string) (*Store, error)

New opens (or creates) the pseudonym database under dataDir. dataDir is created with 0700 permissions if it does not exist; the database file is encrypted with a key derived from seed via the package's dedicated HKDF info string.

func (*Store) CheckAndIncrement

func (s *Store) CheckAndIncrement(ctx context.Context, pub ed25519.PublicKey, epoch int64, limit uint32, now time.Time) error

CheckAndIncrement runs the per-epoch counter logic atomically. The SELECT-then-UPDATE happens inside a transaction; the package mutex guards against the SQLITE_BUSY-free race between two writers reaching the same row at the same instant.

The sequence:

  1. SELECT the current row inside a transaction.
  2. If expires_at <= now, abort with ErrPseudonymExpired.
  3. If last_epoch != epoch, the row's counter is stale and we treat the current value as 0. Otherwise we use it as is.
  4. If the (possibly reset) counter is already at the limit, abort with ErrRateLimited.
  5. UPDATE the row to the new (epoch, counter+1) and commit.

func (*Store) Close

func (s *Store) Close() error

Close releases the underlying database handle.

func (*Store) DeleteExpired

func (s *Store) DeleteExpired(ctx context.Context, before time.Time) (int, error)

DeleteExpired removes records whose expiry is at or before before.

func (*Store) Register

func (s *Store) Register(ctx context.Context, pub ed25519.PublicKey, created, expires time.Time) error

Register persists a pseudonym record. Returns anonauth.ErrPseudonymExists if the pubkey is already registered.

Jump to

Keyboard shortcuts

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