Help us shape the future of Go! Take the 2026 Go Developer Survey

store

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AggregateTally added in v0.5.2

type AggregateTally struct {
	Counts        map[string]int `json:"counts"` // choice index (as string) → count
	RevealedTotal int            `json:"revealedTotal"`
}

AggregateTally holds per-choice vote counts with no link to individual voters.

type DiagramInfo

type DiagramInfo struct {
	CID         string    `json:"cid"`
	Name        string    `json:"name,omitempty"`
	Description string    `json:"description,omitempty"`
	CreatedAt   time.Time `json:"createdAt"`
	AuthorID    string    `json:"authorId,omitempty"`
	AuthorName  string    `json:"authorName,omitempty"`
}

DiagramInfo holds metadata about a diagram for listing

type FSStore

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

FSStore is a simple file-system-backed store for sealed objects and user containers. Structure:

{base}/o/{cid}              -> original JSON-LD bytes
{base}/o/canonical/{cid}.nq -> canonical n-quads text
{base}/u/{login}/g/{slug}/latest -> text file containing CID
{base}/u/{login}/g/{slug}/_history -> JSON array of history entries

func NewFSStore

func NewFSStore(base string) *FSStore

func (*FSStore) AppendEvent added in v0.6.2

func (s *FSStore) AppendEvent(pollID string, event PollEvent) error

AppendEvent appends an event to a poll's event log.

func (*FSStore) AppendHistory

func (s *FSStore) AppendHistory(user, slug, cidStr string) error

AppendHistory appends a history entry (CID + timestamp) to _history (JSON array).

func (*FSStore) DeleteObject

func (s *FSStore) DeleteObject(cid string) error

DeleteObject removes an object and its associated files

func (*FSStore) EnsureUserContainer

func (s *FSStore) EnsureUserContainer(user string) error

Utility: Create container for user (e.g., when user logs in)

func (*FSStore) GetObjectAuthor

func (s *FSStore) GetObjectAuthor(cid string) (githubUser, githubID string, err error)

GetObjectAuthor retrieves the author information from a stored object

func (*FSStore) IncrementTally added in v0.6.1

func (s *FSStore) IncrementTally(pollID string, choice int) error

IncrementTally adds one vote to the aggregate tally for a choice. The tally file only contains totals — no link to individual voters.

func (*FSStore) ListNullifiers added in v0.5.0

func (s *FSStore) ListNullifiers(pollID string) ([]string, error)

ListNullifiers returns all used nullifiers for a poll.

func (*FSStore) ListPolls added in v0.5.0

func (s *FSStore) ListPolls() ([]Poll, error)

ListPolls returns all polls, newest first.

func (*FSStore) ListRevealBundles added in v1.1.0

func (s *FSStore) ListRevealBundles(pollID string) ([]RevealBundle, error)

ListRevealBundles returns all reveal bundles for a poll in insertion order. Returns an empty slice if no reveals have been recorded.

func (*FSStore) ListUserDiagrams

func (s *FSStore) ListUserDiagrams(githubID string) ([]DiagramInfo, error)

ListUserDiagrams returns all diagrams authored by a specific GitHub user ID

func (*FSStore) ListVotes added in v0.5.0

func (s *FSStore) ListVotes(pollID string) ([]VoteRecord, error)

ListVotes returns all vote records for a poll.

func (*FSStore) ObjectPath

func (s *FSStore) ObjectPath(cid string) string

ObjectPath returns the path where the original JSON-LD for a CID is stored.

func (*FSStore) ReadCanonical

func (s *FSStore) ReadCanonical(cid string) ([]byte, error)

Utility: Read canonical n-quads for a cid

func (*FSStore) ReadEvents added in v0.6.2

func (s *FSStore) ReadEvents(pollID string) ([]PollEvent, error)

ReadEvents returns all events for a poll.

func (*FSStore) ReadHistory

func (s *FSStore) ReadHistory(user, slug string) ([]HistoryEntry, error)

ReadHistory reads and returns the history entries for a gist.

func (*FSStore) ReadLatest

func (s *FSStore) ReadLatest(user, slug string) (string, error)

ReadLatest returns the CID stored in latest (or empty string if not present).

func (*FSStore) ReadObject

func (s *FSStore) ReadObject(cid string) ([]byte, error)

Utility: Read object raw JSON-LD

func (*FSStore) ReadPoll added in v0.5.0

func (s *FSStore) ReadPoll(pollID string) (*Poll, error)

ReadPoll loads a poll by ID.

func (*FSStore) ReadSignature

func (s *FSStore) ReadSignature(cid string) (*SignatureMetadata, error)

ReadSignature reads signature metadata for a CID.

func (*FSStore) ReadTally added in v0.5.2

func (s *FSStore) ReadTally(pollID string) (*AggregateTally, error)

ReadTally returns the aggregate tally for a poll.

func (*FSStore) ReadTallyProof added in v1.1.0

func (s *FSStore) ReadTallyProof(pollID string) (*TallyProofArtifact, error)

ReadTallyProof returns the cached tally proof, or os.ErrNotExist if none has been generated yet.

func (*FSStore) RevealVote added in v0.5.1

func (s *FSStore) RevealVote(pollID string, nullifier string, choice int) error

RevealVote marks a vote as revealed and increments the aggregate tally. The choice is verified against the commitment but NEVER stored per-vote — only the aggregate counter is updated, preserving individual ballot secrecy.

func (*FSStore) SaveIdentity

func (s *FSStore) SaveIdentity(githubID string, doc []byte) error

Utility: Save identity doc at /id/github:{id}

func (*FSStore) SaveObject

func (s *FSStore) SaveObject(cid string, raw []byte, canonical []byte) error

SaveObject writes the raw JSON-LD and canonical bytes to disk. It injects the computed CID as the @id field into the stored JSON-LD.

func (*FSStore) SaveObjectWithAuthor

func (s *FSStore) SaveObjectWithAuthor(cid string, raw []byte, canonical []byte, githubUser, githubID string) error

SaveObjectWithAuthor writes the raw JSON-LD and canonical bytes to disk. It injects the computed CID as the @id field and author information into the stored JSON-LD.

func (*FSStore) SavePoll added in v0.5.0

func (s *FSStore) SavePoll(poll *Poll) error

SavePoll persists a poll configuration.

func (*FSStore) SaveRevealBundle added in v1.1.0

func (s *FSStore) SaveRevealBundle(pollID string, bundle RevealBundle) error

SaveRevealBundle appends a reveal bundle to the poll's reveals.json. Appended, not indexed by nullifier, so we keep insertion order for deterministic witness builds.

func (*FSStore) SaveSignature

func (s *FSStore) SaveSignature(cid, signature, signerAddr string, usePersonalSign bool) error

SaveSignature writes signature metadata to disk.

func (*FSStore) SaveTallyProof added in v1.1.0

func (s *FSStore) SaveTallyProof(pollID string, artifact *TallyProofArtifact) error

SaveTallyProof persists a generated tally proof artifact.

func (*FSStore) SaveVote added in v0.5.0

func (s *FSStore) SaveVote(pollID string, vote *VoteRecord) error

SaveVote stores a verified vote for a poll. Returns error if nullifier already used.

func (*FSStore) SignaturePath

func (s *FSStore) SignaturePath(cid string) string

SignaturePath returns the path where the signature metadata for a CID is stored.

func (*FSStore) UpdateLatest

func (s *FSStore) UpdateLatest(user, slug, cid string) error

UpdateLatest writes the pointer file /u/{login}/g/{slug}/latest containing the CID.

type HistoryEntry

type HistoryEntry struct {
	CID       string    `json:"cid"`
	CreatedAt time.Time `json:"createdAt"`
}

type Poll added in v0.5.0

type Poll struct {
	ID          string    `json:"id"`
	Title       string    `json:"title"`
	Description string    `json:"description,omitempty"`
	Choices     []string  `json:"choices"`
	Creator     string    `json:"creator"` // Ethereum address of poll creator
	CreatedAt   time.Time `json:"createdAt"`
	ExpiresAt   time.Time `json:"expiresAt,omitempty"`
	Status      string    `json:"status"` // "active", "closed"

	// Voter registry: commitments for Merkle tree construction
	VoterCommitments []string `json:"voterCommitments"`
	RegistryRoot     string   `json:"registryRoot,omitempty"`

	// VoteSchemaVersion selects the secret-derivation protocol.
	// 1 = legacy: voterSecret = BigInt(sig.slice(2, 64)), fully
	//     reconstructable from the wallet signature — coercion-exposed.
	// 2 = nonce-augmented: voterSecret = mimcHash(sigDerived, voterNonce)
	//     where voterNonce is a per-voter random field element the voter
	//     alone possesses (localStorage + auto-downloaded backup). A
	//     coerced wallet signature no longer deanonymizes the voter.
	// Polls stored before this field existed unmarshal as 0; the server
	// treats 0 and 1 identically (both are legacy). New polls created
	// via handleCreatePoll are stamped with 2.
	VoteSchemaVersion int `json:"voteSchemaVersion,omitempty"`

	// RegistryRootSigs is an append-only log of creator signatures over
	// registry-root transitions. Each entry binds (root, count) so a voter
	// can verify — before casting — that the root the server returned has
	// actually been acknowledged by the creator. Without this, the server
	// can silently inject a shadow voter (commitment in registry but not
	// in the signed set) and accept a vote from it.
	//
	// Semantics:
	//   - handleRegisterVoter appends to VoterCommitments WITHOUT signing;
	//     creator signs in batches via POST .../sign-registry-root.
	//   - handleCastVote rejects unless the current RegistryRoot matches
	//     the Root in the most recent RegistryRootSigs entry.
	//   - Each signature commits to (pollId, root, count); replaying an
	//     old sig with a lower count is caught by the count field.
	RegistryRootSigs []RegistryRootSig `json:"registryRootSigs,omitempty"`
}

Poll represents a ZK poll configuration.

type PollEvent added in v0.6.2

type PollEvent struct {
	Action   string            `json:"action"`
	Bindings map[string]string `json:"bindings,omitempty"`
}

PollEvent represents a single action fired on a poll's state machine.

type PollResults added in v0.5.0

type PollResults struct {
	PollID     string   `json:"pollId"`
	VoteCount  int      `json:"voteCount"`
	Nullifiers []string `json:"nullifiers"`
	Status     string   `json:"status"`
}

PollResults holds tallied results for a poll.

type RegistryRootSig added in v1.1.0

type RegistryRootSig struct {
	Root      string    `json:"root"`
	Count     int       `json:"count"`
	Signature string    `json:"signature"`
	SignedAt  time.Time `json:"signedAt"`
}

RegistryRootSig is one entry in the creator's signed registry log.

type RevealBundle added in v1.1.0

type RevealBundle struct {
	Nullifier string `json:"nullifier"`
	Choice    int    `json:"choice"`
	Secret    string `json:"secret"` // voterSecret as decimal/hex big int
}

RevealBundle records the private data a voter surrendered during the reveal phase, kept so the server can later build the tally-proof witness. This is the ONLY place on the server where per-vote secrets are persisted. Once a tally proof has been generated and the poll is finalized, these bundles can be purged (PurgeReveals) — the proof stands on its own.

type SignatureMetadata

type SignatureMetadata struct {
	Signature       string `json:"signature"`
	SignerAddress   string `json:"signerAddress"`
	UsePersonalSign bool   `json:"usePersonalSign"`
}

SignatureMetadata holds information about a signature.

type TallyProofArtifact added in v1.1.0

type TallyProofArtifact struct {
	PollID             string    `json:"pollId"`
	GeneratedAt        time.Time `json:"generatedAt"`
	CircuitName        string    `json:"circuitName"`
	ProofBytes         string    `json:"proofBytes"`         // base64 gnark proof
	PublicWitnessBytes string    `json:"publicWitnessBytes"` // base64 gnark public witness — consumed by in-browser Verify
	PublicInputs       []string  `json:"publicInputs"`       // hex-encoded public witness, circuit order (human-readable)
	Tallies            []int64   `json:"tallies"`            // the claimed tally vector (also in PublicInputs)
	NumReveals         int       `json:"numReveals"`
}

TallyProofArtifact is what we persist to tallyproof.json after a successful prove — everything a verifier needs to independently check the proof against the circuit's verifying key.

type VoteRecord added in v0.5.0

type VoteRecord struct {
	Nullifier      string    `json:"nullifier"`
	VoteCommitment string    `json:"voteCommitment"` // mimcHash(voterSecret, voteChoice) — blinded, can't reverse
	Proof          string    `json:"proof"`
	Timestamp      time.Time `json:"timestamp"`
	Revealed       bool      `json:"revealed,omitempty"` // true after voter revealed (choice NOT stored here)
}

VoteRecord stores a verified vote submission. Note: individual vote choices are NEVER stored — only the blinded commitment. Tallying is done via aggregate counters that can't be linked back to individual voters.

Jump to

Keyboard shortcuts

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