election

package
v0.6.7 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2024 License: MPL-2.0 Imports: 29 Imported by: 0

Documentation

Overview

Copyright (C) 2019-2023 David Florness SPDX-License-Identifier: MPL-2.0

Copyright (C) 2019-2023 David Florness SPDX-License-Identifier: MPL-2.0

Copyright (C) 2019-2023 David Florness SPDX-License-Identifier: MPL-2.0

Copyright (C) 2019-2023 David Florness SPDX-License-Identifier: MPL-2.0

Copyright (C) 2019-2023 David Florness SPDX-License-Identifier: MPL-2.0

Copyright (C) 2019-2023 David Florness SPDX-License-Identifier: MPL-2.0

Copyright (C) 2019-2023 David Florness SPDX-License-Identifier: MPL-2.0

Copyright (C) 2019-2023 David Florness SPDX-License-Identifier: MPL-2.0

Copyright (C) 2019-2023 David Florness SPDX-License-Identifier: MPL-2.0

Copyright (C) 2019-2023 David Florness SPDX-License-Identifier: MPL-2.0

Index

Constants

This section is empty.

Variables

View Source
var (
	// sent when user wants to create an election
	CreateElectionMessage = event.Type{
		Type:  "xyz.tallyard.new",
		Class: event.MessageEventType,
	}
	// sent when a user wants to join an election
	JoinElectionMessage = event.Type{
		Type:  "xyz.tallyard.join",
		Class: event.MessageEventType,
	}
	// sent when a user wants to start a previously-create election. The
	// user who sends this message must be the one who created the election
	StartElectionMessage = event.Type{
		Type:  "xyz.tallyard.start",
		Class: event.MessageEventType,
	}
	// contains keys needed to do zero knowledge proofs
	KeysMessage = event.Type{
		Type:  "xyz.tallyard.keys",
		Class: event.MessageEventType,
	}
	// indicate's user's evaluations of their polynomial using others' inputs
	EvalsMessage = event.Type{
		Type:  "xyz.tallyard.evals",
		Class: event.MessageEventType,
	}
	// indicates a user's individual summation
	SumMessage = event.Type{
		Type:  "xyz.tallyard.sum",
		Class: event.MessageEventType,
	}
)
View Source
var SchemaVersionError error = errors.New("the stored elections schema version is incompitable with the latest schema version")

Functions

func CalculateCommitment added in v0.4.0

func CalculateCommitment(prerequisiteEventContent ...event.Content) (string, error)

func LogUpload added in v0.4.0

func LogUpload(contentURI id.ContentURI)

Types

type Candidate

type Candidate string

type CreateElectionContent

type CreateElectionContent struct {
	Version string `json:"version"`

	Candidates []Candidate `json:"candidates"`
	Title      string      `json:"title"`
}

type CreateEvent

type CreateEvent struct {
	*event.Event
	*CreateElectionContent
}

type Election

type Election struct {
	sync.RWMutex

	Candidates   []Candidate           `json:"candidates"`
	CreateEvt    event.Event           `json:"create_evt"`
	FinalJoinIDs *[]id.EventID         `json:"final_voters,omitempty"`
	Joins        map[id.EventID]*Voter `json:"joins"`
	LocalVoter   *LocalVoter           `json:"local_voter,omitempty"`
	Result       *[32]byte             `json:"result,omitempty"`
	RoomID       id.RoomID             `json:"room_id"`
	StartID      *id.EventID           `json:"start_id,omitempty"`
	Title        string                `json:"title"`

	// Save election to disk.  Set by the containing ElectionsMap at runtime
	Save func() `json:"-"`
}

func NewElection

func NewElection(candidates []Candidate, createEvt event.Event, roomID id.RoomID, title string) *Election

func (*Election) JoinElection

func (el *Election) JoinElection(client *mautrix.Client, eventStore *EventStore) error

func (*Election) PrintResults

func (el *Election) PrintResults()

func (*Election) RedactEvents added in v0.4.0

func (el *Election) RedactEvents(client *mautrix.Client)

func (*Election) SendEvals

func (el *Election) SendEvals(client *mautrix.Client, eventStore *EventStore) error

func (*Election) SendProvingKeys added in v0.4.0

func (el *Election) SendProvingKeys(client *mautrix.Client, eventStore *EventStore) error

func (*Election) SendSum

func (el *Election) SendSum(client *mautrix.Client, eventStore *EventStore) error

func (*Election) StartElection

func (el *Election) StartElection(client *mautrix.Client, eventStore *EventStore) error

func (*Election) UnmarshalJSON

func (el *Election) UnmarshalJSON(b []byte) error

type ElectionsMap

type ElectionsMap struct {
	sync.RWMutex
	// The version of the elections map.  If the version in the file doesn't
	// match the current version then we can give a clear error message
	// telling the user to update their file to the current version.  The
	// version in the file should only be different if there has been a
	// breaking change to the elections map format.
	Version int `json:"version"`
	// Maps election create event IDs to the corresponding election.
	Elections map[id.EventID]*Election `json:"elections"`
	// See EventStore doc for explanation
	EventStore *EventStore `json:"event_store,omitempty"`
	// State store
	NextBatch string              `json:"next_batch"`
	Rooms     map[id.RoomID]*Room `json:"rooms"`
	UserID    id.UserID           `json:"user_id"`
	// contains filtered or unexported fields
}

func NewElectionsMap added in v0.4.0

func NewElectionsMap(userID id.UserID, save func(*ElectionsMap)) *ElectionsMap

func UnmarshalElectionsMapFrom added in v0.4.2

func UnmarshalElectionsMapFrom(jsonBytes []byte, userID id.UserID, save func(*ElectionsMap)) (*ElectionsMap, error)

func (*ElectionsMap) AddElection

func (em *ElectionsMap) AddElection(el *Election)

func (*ElectionsMap) CreateElection

func (elections *ElectionsMap) CreateElection(client *mautrix.Client, candidates []Candidate, title string, roomID id.RoomID) (*Election, error)

func (*ElectionsMap) GetElection

func (em *ElectionsMap) GetElection(createID id.EventID) *Election

func (*ElectionsMap) Save

func (em *ElectionsMap) Save()

func (*ElectionsMap) SetEventStore

func (em *ElectionsMap) SetEventStore(eventStore *EventStore)

func (*ElectionsMap) SetupEventHooks

func (elections *ElectionsMap) SetupEventHooks(client *mautrix.Client, syncer mautrix.ExtensibleSyncer)

func (*ElectionsMap) UnmarshalJSON

func (em *ElectionsMap) UnmarshalJSON(b []byte) error

type Eval added in v0.4.0

type Eval struct {
	// encrypted for specific voter
	Output string `json:"output"`
	// public; used by everyone in summation proofs
	OutputHash string `json:"output_hash"`
	// encrypted for specific voter
	Proof string `json:"proof"`
}

type EvalsEvent

type EvalsEvent struct {
	*event.Event
	*EvalsMessageContent
}

type EvalsMessageContent

type EvalsMessageContent struct {
	Version string `json:"version"`

	Commitment string       `json:"commitment"`
	Evals      []Eval       `json:"evals"`
	JoinID     id.EventID   `json:"join_id"`
	KeysIDs    []id.EventID `json:"keys_ids"`
}

type EventStore

type EventStore struct {
	sync.RWMutex
	Events map[id.EventID]*event.Event `json:"events"`

	Client        *mautrix.Client                        `json:"-"`
	EventHandlers map[event.Type]func(*event.Event) bool `json:"-"`
	Processing    map[id.EventID]<-chan struct{}         `json:"-"`
}

Used to store all relevant election Events that we've tried processing. A value of nil for a given event ID key in the Events map means that the corresponding event was processed unsuccessfully. Likewise, a non-nil value indicates that the event was processed successfully.

This EventStore also uses the provided Client to fetch missing events and pipe them through the corresponding EventHandlers when needed.

func NewEventStore

func NewEventStore(client *mautrix.Client, eventHandlers map[event.Type]func(*event.Event) bool) *EventStore

func (*EventStore) GetCreateEvent

func (store *EventStore) GetCreateEvent(roomID id.RoomID, createID id.EventID) *CreateEvent

func (*EventStore) GetEvalsEvent

func (store *EventStore) GetEvalsEvent(roomID id.RoomID, evalsID id.EventID) *EvalsEvent

func (*EventStore) GetJoinEvent

func (store *EventStore) GetJoinEvent(roomID id.RoomID, joinID id.EventID) *JoinEvent

func (*EventStore) GetKeysEvent added in v0.4.0

func (store *EventStore) GetKeysEvent(roomID id.RoomID, keysID id.EventID) *KeysEvent

func (*EventStore) GetStartEvent

func (store *EventStore) GetStartEvent(roomID id.RoomID, startID id.EventID) *StartEvent

func (*EventStore) GetSumEvent

func (store *EventStore) GetSumEvent(roomID id.RoomID, sumID id.EventID) *SumEvent

func (*EventStore) UnmarshalJSON

func (store *EventStore) UnmarshalJSON(b []byte) error

type JoinElectionContent

type JoinElectionContent struct {
	Version string `json:"version"`

	Commitment string     `json:"commitment"`
	CreateID   id.EventID `json:"create_id"`
	Input      string     `json:"input"`
	PubKey     string     `json:"pub_key"`
}

type JoinEvent

type JoinEvent struct {
	*event.Event
	*JoinElectionContent
}

type KeysEvent added in v0.4.0

type KeysEvent struct {
	*event.Event
	*KeysMessageContent
}

type KeysMessageContent added in v0.4.0

type KeysMessageContent struct {
	Version string `json:"version"`

	Commitment        string        `json:"commitment"`
	EvalProvingKeyURI id.ContentURI `json:"eval_proving_key_uri"`
	JoinID            id.EventID    `json:"join_id"`
	StartID           id.EventID    `json:"start_id"`
	SumProvingKeyURI  id.ContentURI `json:"sum_proving_key_uri"`
}

type LocalVoter

type LocalVoter struct {
	*Voter

	PrivKey [32]byte `json:"priv_key"`

	EvalVerifyingKey *VerifyingKeyFile `json:"eval_verifying_key,omitempty"`
	Poly             *math.Poly        `json:"poly,omitempty"`
	SumVerifyingKey  *VerifyingKeyFile `json:"sum_verifying_key,omitempty"`
}

func NewLocalVoter

func NewLocalVoter(voter *Voter, privKey *[32]byte) *LocalVoter

type ProvingKeyFile added in v0.4.2

type ProvingKeyFile struct {
	FileID string `json:"file_id"`
	// contains filtered or unexported fields
}

func NewProvingKeyFile added in v0.4.2

func NewProvingKeyFile(fileID string, pk groth16.ProvingKey) *ProvingKeyFile

func (*ProvingKeyFile) Pk added in v0.4.2

func (provingKey *ProvingKeyFile) Pk() groth16.ProvingKey

type Room added in v0.4.0

type Room struct {
	*mautrix.Room
	// contains filtered or unexported fields
}

func NewRoom added in v0.4.0

func NewRoom(mroom *mautrix.Room, electionsMap *ElectionsMap) *Room

func (*Room) GetElections added in v0.4.0

func (room *Room) GetElections() []*Election

func (*Room) HasElections added in v0.4.0

func (room *Room) HasElections() bool

type StartElectionContent

type StartElectionContent struct {
	Version string `json:"version"`

	Commitment string       `json:"commitment"`
	CreateID   id.EventID   `json:"create_id"`
	JoinIDs    []id.EventID `json:"join_ids"`
}

type StartEvent

type StartEvent struct {
	*event.Event
	*StartElectionContent
}

type SumEvent

type SumEvent struct {
	*event.Event
	*SumMessageContent
}

type SumMessageContent

type SumMessageContent struct {
	Version string `json:"version"`

	Commitment string       `json:"commitment"`
	EvalsIDs   []id.EventID `json:"evals_ids"`
	JoinID     id.EventID   `json:"join_id"`
	Sum        string       `json:"sum"`
	Proofs     []string     `json:"proofs"`
}

type VerifyingKeyFile added in v0.4.2

type VerifyingKeyFile struct {
	FileID string `json:"file_id"`
	// contains filtered or unexported fields
}

func NewVerifyingKeyFile added in v0.4.2

func NewVerifyingKeyFile(vk groth16.VerifyingKey) *VerifyingKeyFile

func (*VerifyingKeyFile) Vk added in v0.4.2

func (verifyingKey *VerifyingKeyFile) Vk() groth16.VerifyingKey

type Voter

type Voter struct {
	Input   fr.Element  `json:"input"`
	JoinEvt event.Event `json:"join_evt"`
	PubKey  [32]byte    `json:"pub_key"`

	JoinIDIndex  *uint       `json:"join_id_index,omitempty"`
	Output       *fr.Element `json:"output,omitempty"`
	OutputHashes *[][]byte   `json:"output_hashes,omitempty"`
	KeysID       *id.EventID `json:"keys_id,omitempty"`
	EvalsID      *id.EventID `json:"evals_id,omitempty"`
	Sum          *fr.Element `json:"sum,omitempty"`
	SumID        *id.EventID `json:"sum_id,omitempty"`

	EvalProvingKey *ProvingKeyFile `json:"eval_proving_key,omitempty"`
	SumProvingKey  *ProvingKeyFile `json:"sum_proving_key,omitempty"`
}

func NewVoter

func NewVoter(input *fr.Element, joinEvt *event.Event, pubKey *[32]byte) *Voter

Jump to

Keyboard shortcuts

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