types

package
v0.4.7-alpha Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2023 License: BSD-3-Clause Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CiphervotesToPairs

func CiphervotesToPairs(ciphervotes []Ciphervote) (X [][]kyber.Point, Y [][]kyber.Point)

CiphervotesToPairs converts a slice of ciphervote to X, Y

func RandomID

func RandomID() (string, error)

RandomID returns the hex encoding of a randomly created 32 byte ID.

func RegisterCiphervoteFormat

func RegisterCiphervoteFormat(f serde.Format, e serde.FormatEngine)

RegisterCiphervoteFormat registers the engine for the provided format

func RegisterFormFormat

func RegisterFormFormat(format serde.Format, engine serde.FormatEngine)

RegisterFormFormat registers the engine for the provided format

func RegisterTransactionFormat

func RegisterTransactionFormat(f serde.Format, e serde.FormatEngine)

RegisterTransactionFormat registers the engine for the provided format

Types

type Ballot

type Ballot struct {

	// SelectResult contains the result of each Select question. The result of a
	// select is a list of boolean that says for each choice if it has been
	// selected or not.  The ID slice is used to map a question ID to its index
	// in the SelectResult slice
	SelectResultIDs []ID
	SelectResult    [][]bool

	// RankResult contains the result of each Rank question. The result of a
	// rank question is the list of ranks for each choice. A choice that hasn't
	// been ranked will have a value < 0. The ID slice is used to map a question
	// ID to its index in the RankResult slice
	RankResultIDs []ID
	RankResult    [][]int8

	// TextResult contains the result of each Text question. The result of a
	// text question is the list of text answer for each choice. The ID slice is
	// used to map a question ID to its index in the TextResult slice
	TextResultIDs []ID
	TextResult    [][]string
}

Ballot contains all information about a simple ballot

func (*Ballot) Equal

func (b *Ballot) Equal(other Ballot) bool

Equal performs a loose comparison of a ballot.

func (*Ballot) Unmarshal

func (b *Ballot) Unmarshal(marshalledBallot string, form Form) error

Unmarshal decodes the given string according to the format described in "state of smart contract.md"

type CancelForm

type CancelForm struct {
	// FormID is hex-encoded
	FormID string
	UserID string
}

CancelForm defines the transaction to cancel the form

- implements serde.Message

func (CancelForm) Serialize

func (ce CancelForm) Serialize(ctx serde.Context) ([]byte, error)

Serialize implements serde.Message

type CastVote

type CastVote struct {
	// FormID is hex-encoded
	FormID string
	UserID string
	Ballot Ciphervote
}

CastVote defines the transaction to cast a vote

- implements serde.Message

func (CastVote) Serialize

func (cv CastVote) Serialize(ctx serde.Context) ([]byte, error)

Serialize implements serde.Message

type Ciphervote

type Ciphervote []EGPair

Ciphervote represents an encrypted vote. It consists of a list of ElGamal pairs.

- implements serde.Message - implements serde.Fingerprinter

func CiphervotesFromPairs

func CiphervotesFromPairs(X, Y [][]kyber.Point) ([]Ciphervote, error)

CiphervotesFromPairs transforms two parallel lists of EGPoints to a list of Ciphervotes.

func (Ciphervote) Copy

func (c Ciphervote) Copy() Ciphervote

Copy returns a copy of a ciphervote

func (Ciphervote) Equal

func (c Ciphervote) Equal(other Ciphervote) bool

Equal returns if the other ciphervote is equal

func (Ciphervote) FingerPrint

func (c Ciphervote) FingerPrint(writer io.Writer) error

FingerPrint implements serde.Fingerprinter

func (Ciphervote) GetElGPairs

func (c Ciphervote) GetElGPairs() (ks []kyber.Point, cs []kyber.Point)

GetElGPairs returns corresponding kyber.Points from the ciphertexts

func (Ciphervote) Serialize

func (c Ciphervote) Serialize(ctx serde.Context) ([]byte, error)

Serialize implements serde.Message

type CiphervoteFactory

type CiphervoteFactory struct{}

CiphervoteFactory provides the mean to deserialize a ciphervote. It naturally uses the formFormat.

- implements serde.Factory

func (CiphervoteFactory) Deserialize

func (CiphervoteFactory) Deserialize(ctx serde.Context, data []byte) (serde.Message, error)

Deserialize implements serde.Factory

type CiphervoteKey

type CiphervoteKey struct{}

CiphervoteKey is the factory key for Ciphervote

type CloseForm

type CloseForm struct {
	// FormID is hex-encoded
	FormID string
	UserID string
}

CloseForm defines the transaction to close a form

- implements serde.Message

func (CloseForm) Serialize

func (ce CloseForm) Serialize(ctx serde.Context) ([]byte, error)

Serialize implements serde.Message

type CombineShares

type CombineShares struct {
	// FormID is hex-encoded
	FormID string
	UserID string
}

CombineShares defines the transaction to decrypt the ballots by combining all the public shares.

- implements serde.Message

func (CombineShares) Serialize

func (db CombineShares) Serialize(ctx serde.Context) ([]byte, error)

Serialize implements serde.Message

type Configuration

type Configuration struct {
	MainTitle string
	Scaffold  []Subject
}

Configuration contains the configuration of a new poll.

func (*Configuration) GetQuestion

func (c *Configuration) GetQuestion(ID ID) Question

GetQuestion finds the question associated to a given ID and returns it. Returns nil if no question found.

func (*Configuration) IsValid

func (c *Configuration) IsValid() bool

IsValid returns true if and only if the whole configuration is coherent and valid.

func (*Configuration) MaxBallotSize

func (c *Configuration) MaxBallotSize() int

MaxBallotSize returns the maximum number of bytes required to store a ballot

type CreateForm

type CreateForm struct {
	Configuration Configuration
	AdminID       string
}

CreateForm defines the transaction to create a form

- implements serde.Message

func (CreateForm) Serialize

func (ce CreateForm) Serialize(ctx serde.Context) ([]byte, error)

Serialize implements serde.Message

type DeleteForm

type DeleteForm struct {
	// FormID is hex-encoded
	FormID string
}

DeleteForm defines the transaction to delete the form

- implements serde.Message

func (DeleteForm) Serialize

func (ce DeleteForm) Serialize(ctx serde.Context) ([]byte, error)

Serialize implements serde.Message

type EGPair

type EGPair struct {
	K kyber.Point
	C kyber.Point
}

EGPair defines an ElGamal pair.

func (EGPair) Copy

func (ct EGPair) Copy() EGPair

Copy returns a copy of EGPair

func (EGPair) String

func (ct EGPair) String() string

String returns a string representation of an ElGamal pair

type Form

type Form struct {
	Configuration Configuration

	// FormID is the hex-encoded SHA256 of the transaction ID that creates
	// the form
	FormID string

	Status Status
	Pubkey kyber.Point

	// BallotSize represents the total size in bytes of one ballot. It is used
	// to pad smaller ballots such that all  ballots cast have the same size
	BallotSize int

	// Suffragia is a map from User ID to their encrypted ballot
	Suffragia Suffragia

	// ShuffleInstances is all the shuffles, along with their proof and identity
	// of shuffler.
	ShuffleInstances []ShuffleInstance

	// ShuffleThreshold is set based on the roster. We save it so we do not have
	// to compute it based on the roster each time we need it.
	ShuffleThreshold int

	// PubsharesUnits is an array containing all the submission of pubShares.
	// Each node submits its share to its personal index from the DKG service.
	PubsharesUnits PubsharesUnits

	DecryptedBallots []Ballot

	Roster authority.Authority
}

Form contains all information about a simple form

- implements serde.Message

func (*Form) ChunksPerBallot

func (e *Form) ChunksPerBallot() int

ChunksPerBallot returns the number of chunks of El Gamal pairs needed to represent an encrypted ballot, knowing that one chunk is 29 bytes at most.

func (Form) Serialize

func (e Form) Serialize(ctx serde.Context) ([]byte, error)

Serialize implements serde.Message

type FormFactory

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

FormFactory provides the mean to deserialize a form. It naturally uses the formFormat.

- implements serde.Factory

func NewFormFactory

func NewFormFactory(cf serde.Factory, rf authority.Factory) FormFactory

NewFormFactory creates a new Form factory

func (FormFactory) Deserialize

func (e FormFactory) Deserialize(ctx serde.Context, data []byte) (serde.Message, error)

Deserialize implements serde.Factory

type FormIDs

type FormIDs []string

FormIDs is a slice of hex-encoded form IDs

func (*FormIDs) Add

func (e *FormIDs) Add(id string) error

Add adds a form ID or returns an error if already present

func (FormIDs) Contains

func (e FormIDs) Contains(el string) int

Contains checks if el is present. Return < 0 if not.

func (*FormIDs) Remove

func (e *FormIDs) Remove(id string)

Remove removes a form ID from the list, if it exists

type FormKey

type FormKey struct{}

FormKey is the key of the form factory

type FormsMetadata

type FormsMetadata struct {
	FormsIDs FormIDs
}

FormsMetadata ...

type ID

type ID string

ID defines the ID of a ballot question

type OpenForm

type OpenForm struct {
	// FormID is hex-encoded
	FormID string
}

OpenForm defines the transaction to open a form

- implements serde.Message

func (OpenForm) Serialize

func (oe OpenForm) Serialize(ctx serde.Context) ([]byte, error)

Serialize implements serde.Message

type Pubshare

type Pubshare kyber.Point

Pubshare represents a public share.

type PubsharesUnit

type PubsharesUnit [][]Pubshare

PubsharesUnit holds all the public shares produced by a given node, 1 for each ElGamal pair

func (PubsharesUnit) Fingerprint

func (p PubsharesUnit) Fingerprint(writer io.Writer) error

Fingerprint implements serde.Fingerprinter

type PubsharesUnits

type PubsharesUnits struct {
	// Pubshares holds the nodes' public shares
	Pubshares []PubsharesUnit
	// PubKeys contains the pubKey of the nodes who made each corresponding
	// PubsharesUnit
	PubKeys [][]byte
	// Indexes is the index of the nodes who made each corresponding
	// PubsharesUnit
	Indexes []int
}

PubsharesUnits contains the pubshares submitted in parallel with the necessary data to identify the nodes who submitted them and their index.

type Question

type Question interface {
	GetMaxN() uint
	GetMinN() uint
	GetChoicesLength() int
	GetID() string
}

Question is an offering the primitives all questions should have to verify the validity of an answer on a decrypted ballot.

type RandomVector

type RandomVector [][]byte

RandomVector is a slice of kyber.Scalar (encoded) which is used to prove and verify the proof of a shuffle

func (*RandomVector) LoadFromScalars

func (r *RandomVector) LoadFromScalars(e []kyber.Scalar) error

LoadFromScalars marshals a given vector of scalars into the current RandomVector

func (RandomVector) Unmarshal

func (r RandomVector) Unmarshal() ([]kyber.Scalar, error)

Unmarshal returns the native type of a random vector

type Rank

type Rank struct {
	ID ID

	Title   string
	MaxN    uint
	MinN    uint
	Choices []string
	Hint    string
}

Rank describes a "rank" question, which requires the user to rank choices. implements Question

func (Rank) GetChoicesLength

func (r Rank) GetChoicesLength() int

GetChoicesLength implements Question

func (Rank) GetID

func (r Rank) GetID() string

func (Rank) GetMaxN

func (r Rank) GetMaxN() uint

GetMaxN implements Question

func (Rank) GetMinN

func (r Rank) GetMinN() uint

GetMinN implements Question

type RegisterPubShares

type RegisterPubShares struct {
	FormID string
	// Index is the index of the node making the submission
	Index int
	// Pubshares are the public shares of the node submitting the transaction
	// so that they can be used for decryption.
	Pubshares PubsharesUnit
	// Signature is the signature of the result of HashPubShares() with the
	// private key corresponding to PublicKey
	Signature []byte
	// PublicKey is the public key of the signer
	PublicKey []byte
}

RegisterPubShares defines the transaction used by a node to send its pubshares on the chain.

- implements serde.Message

func (RegisterPubShares) Fingerprint

func (rp RegisterPubShares) Fingerprint(writer io.Writer) error

Fingerprint implements serde.Fingerprinter

func (RegisterPubShares) Serialize

func (rp RegisterPubShares) Serialize(ctx serde.Context) ([]byte, error)

Serialize implements serde.Message

type Select

type Select struct {
	ID ID

	Title   string
	MaxN    uint
	MinN    uint
	Choices []string
	Hint    string
}

Select describes a "select" question, which requires the user to select one or multiple choices. implements Question

func (Select) GetChoicesLength

func (s Select) GetChoicesLength() int

GetChoicesLength implements Question

func (Select) GetID

func (s Select) GetID() string

GetID implements Question

func (Select) GetMaxN

func (s Select) GetMaxN() uint

GetMaxN implements Question

func (Select) GetMinN

func (s Select) GetMinN() uint

GetMinN implements Question

type ShuffleBallots

type ShuffleBallots struct {
	FormID          string
	Round           int
	ShuffledBallots []Ciphervote
	// RandomVector is the vector to be used to generate the proof of the next
	// shuffle
	RandomVector RandomVector
	// Proof is the proof corresponding to the shuffle of this transaction
	Proof []byte
	// Signature is the signature of the result of HashShuffle() with the private
	// key corresponding to PublicKey
	Signature []byte
	//PublicKey is the public key of the signer.
	PublicKey []byte
}

ShuffleBallots defines the transaction to shuffle the ballots

- implements serde.Message - implements serde.Fingerprinter

func (ShuffleBallots) Fingerprint

func (sb ShuffleBallots) Fingerprint(writer io.Writer) error

Fingerprint implements serde.Fingerprinter. If creates a fingerprint only based on the formID and the shuffled ballots.

func (ShuffleBallots) Serialize

func (sb ShuffleBallots) Serialize(ctx serde.Context) ([]byte, error)

Serialize implements serde.Message

type ShuffleInstance

type ShuffleInstance struct {
	// ShuffledBallots contains the list of shuffled ciphertext for this round
	ShuffledBallots []Ciphervote

	// ShuffleProofs is the proof of the shuffle for this round
	ShuffleProofs []byte

	// ShufflerPublicKey is the key of the node who made the given shuffle.
	ShufflerPublicKey []byte
}

ShuffleInstance is an instance of a shuffle, it contains the shuffled ballots, the proofs and the identity of the shuffler.

type Status

type Status uint16

Status defines the status of the form

const (
	// DecryptedBallots = 4
	// Initial is when the form has just been created
	Initial Status = 0
	// Open is when the form is open, i.e. it fetched the public key
	Open Status = 1
	// Closed is when no more users can cast ballots
	Closed Status = 2
	// ShuffledBallots is when the ballots have been shuffled
	ShuffledBallots Status = 3
	// PubSharesSubmitted is when we have enough shares to decrypt the ballots
	PubSharesSubmitted Status = 4
	// ResultAvailable is when the ballots have been decrypted
	ResultAvailable Status = 5
	// Canceled is when the form has been cancel
	Canceled Status = 6
)

type Subject

type Subject struct {
	ID ID

	Title string

	// Order defines the order of the different question, which all have a unique
	// identifier. This is purely for display purpose.
	Order []ID

	Subjects []Subject
	Selects  []Select
	Ranks    []Rank
	Texts    []Text
}

Subject is a wrapper around multiple questions that can be of type "select", "rank", or "text".

func (*Subject) GetQuestion

func (s *Subject) GetQuestion(ID ID) Question

GetQuestion finds the question associated to a given ID and returns it Returns nil if no question found.

func (*Subject) MaxEncodedSize

func (s *Subject) MaxEncodedSize() int

MaxEncodedSize returns the maximum amount of bytes taken to store the questions in this subject once encoded in a ballot

type Suffragia

type Suffragia struct {
	UserIDs     []string
	Ciphervotes []Ciphervote
}

func (*Suffragia) CastVote

func (s *Suffragia) CastVote(userID string, ciphervote Ciphervote)

CastVote adds a new vote and its associated user or updates a user's vote.

type Text

type Text struct {
	ID ID

	Title     string
	MaxN      uint
	MinN      uint
	MaxLength uint
	Regex     string
	Choices   []string
	Hint      string
}

Text describes a "text" question, which allows the user to enter free text. implements Question

func (Text) GetChoicesLength

func (t Text) GetChoicesLength() int

GetChoicesLength implements Question

func (Text) GetID

func (t Text) GetID() string

func (Text) GetMaxN

func (t Text) GetMaxN() uint

GetMaxN implements Question

func (Text) GetMinN

func (t Text) GetMinN() uint

GetMinN implements Question

type TransactionFactory

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

TransactionFactory provides the mean to deserialize a transaction.

- implements serde.Factory

func NewTransactionFactory

func NewTransactionFactory(cf serde.Factory) TransactionFactory

NewTransactionFactory creates a new transaction factory

func (TransactionFactory) Deserialize

func (t TransactionFactory) Deserialize(ctx serde.Context, data []byte) (serde.Message, error)

Deserialize implements serde.Factory

type TransactionKey

type TransactionKey struct{}

TransactionKey is the key for the transaction factory

Jump to

Keyboard shortcuts

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