majurity-protocol-0.0.10.20191104: A cryptographic protocol for the Majority Judgment.
Safe HaskellNone
LanguageHaskell2010

Voting.Protocol.Election

Synopsis

Type Question

data Question v Source #

Instances

Instances details
Eq (Question v) Source # 
Instance details

Defined in Voting.Protocol.Election

Methods

(==) :: Question v -> Question v -> Bool #

(/=) :: Question v -> Question v -> Bool #

Show (Question v) Source # 
Instance details

Defined in Voting.Protocol.Election

Methods

showsPrec :: Int -> Question v -> ShowS #

show :: Question v -> String #

showList :: [Question v] -> ShowS #

Generic (Question v) Source # 
Instance details

Defined in Voting.Protocol.Election

Associated Types

type Rep (Question v) :: Type -> Type #

Methods

from :: Question v -> Rep (Question v) x #

to :: Rep (Question v) x -> Question v #

Reifies v Version => ToJSON (Question v) Source # 
Instance details

Defined in Voting.Protocol.Election

Reifies v Version => FromJSON (Question v) Source # 
Instance details

Defined in Voting.Protocol.Election

NFData (Question v) Source # 
Instance details

Defined in Voting.Protocol.Election

Methods

rnf :: Question v -> () #

type Rep (Question v) Source # 
Instance details

Defined in Voting.Protocol.Election

type Rep (Question v) = D1 ('MetaData "Question" "Voting.Protocol.Election" "majurity-protocol-0.0.10.20191104-inplace" 'False) (C1 ('MetaCons "Question" 'PrefixI 'True) ((S1 ('MetaSel ('Just "question_text") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Text) :*: S1 ('MetaSel ('Just "question_choices") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 [Text])) :*: (S1 ('MetaSel ('Just "question_mini") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Natural) :*: S1 ('MetaSel ('Just "question_maxi") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Natural))))

Type Answer

data Answer crypto v c Source #

Constructors

Answer 

Fields

Instances

Instances details
Eq (G crypto c) => Eq (Answer crypto v c) Source # 
Instance details

Defined in Voting.Protocol.Election

Methods

(==) :: Answer crypto v c -> Answer crypto v c -> Bool #

(/=) :: Answer crypto v c -> Answer crypto v c -> Bool #

(Show (G crypto c), Show (G crypto c)) => Show (Answer crypto v c) Source # 
Instance details

Defined in Voting.Protocol.Election

Methods

showsPrec :: Int -> Answer crypto v c -> ShowS #

show :: Answer crypto v c -> String #

showList :: [Answer crypto v c] -> ShowS #

Generic (Answer crypto v c) Source # 
Instance details

Defined in Voting.Protocol.Election

Associated Types

type Rep (Answer crypto v c) :: Type -> Type #

Methods

from :: Answer crypto v c -> Rep (Answer crypto v c) x #

to :: Rep (Answer crypto v c) x -> Answer crypto v c #

(Reifies v Version, CryptoParams crypto c) => ToJSON (Answer crypto v c) Source # 
Instance details

Defined in Voting.Protocol.Election

Methods

toJSON :: Answer crypto v c -> Value #

toEncoding :: Answer crypto v c -> Encoding #

toJSONList :: [Answer crypto v c] -> Value #

toEncodingList :: [Answer crypto v c] -> Encoding #

(Reifies v Version, CryptoParams crypto c) => FromJSON (Answer crypto v c) Source # 
Instance details

Defined in Voting.Protocol.Election

Methods

parseJSON :: Value -> Parser (Answer crypto v c) #

parseJSONList :: Value -> Parser [Answer crypto v c] #

NFData (G crypto c) => NFData (Answer crypto v c) Source # 
Instance details

Defined in Voting.Protocol.Election

Methods

rnf :: Answer crypto v c -> () #

type Rep (Answer crypto v c) Source # 
Instance details

Defined in Voting.Protocol.Election

type Rep (Answer crypto v c) = D1 ('MetaData "Answer" "Voting.Protocol.Election" "majurity-protocol-0.0.10.20191104-inplace" 'False) (C1 ('MetaCons "Answer" 'PrefixI 'True) (S1 ('MetaSel ('Just "answer_opinions") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 [(Encryption crypto v c, DisjProof crypto v c)]) :*: S1 ('MetaSel ('Just "answer_sumProof") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (DisjProof crypto v c))))

encryptAnswer :: Reifies v Version => CryptoParams crypto c => Monad m => RandomGen r => PublicKey crypto c -> ZKP -> Question v -> [Bool] -> StateT r (ExceptT ErrorAnswer m) (Answer crypto v c) Source #

(encryptAnswer elecPubKey zkp quest opinions) returns an Answer validable by verifyAnswer, unless an ErrorAnswer is returned.

verifyAnswer :: Reifies v Version => CryptoParams crypto c => PublicKey crypto c -> ZKP -> Question v -> Answer crypto v c -> Bool Source #

Type ErrorAnswer

data ErrorAnswer Source #

Error raised by encryptAnswer.

Constructors

ErrorAnswer_WrongNumberOfOpinions Natural Natural

When the number of opinions is different than the number of choices (question_choices).

ErrorAnswer_WrongSumOfOpinions Natural Natural Natural

When the sum of opinions is not within the bounds of question_mini and question_maxi.

Instances

Instances details
Eq ErrorAnswer Source # 
Instance details

Defined in Voting.Protocol.Election

Show ErrorAnswer Source # 
Instance details

Defined in Voting.Protocol.Election

Generic ErrorAnswer Source # 
Instance details

Defined in Voting.Protocol.Election

Associated Types

type Rep ErrorAnswer :: Type -> Type #

NFData ErrorAnswer Source # 
Instance details

Defined in Voting.Protocol.Election

Methods

rnf :: ErrorAnswer -> () #

type Rep ErrorAnswer Source # 
Instance details

Defined in Voting.Protocol.Election

Type Opinion

type Opinion = E Source #

Index of a Disjunction within a list of them. It is encrypted as a GroupExponent by encrypt.

Type Election

data Election crypto v c Source #

Instances

Instances details
(Eq crypto, Eq (G crypto c)) => Eq (Election crypto v c) Source # 
Instance details

Defined in Voting.Protocol.Election

Methods

(==) :: Election crypto v c -> Election crypto v c -> Bool #

(/=) :: Election crypto v c -> Election crypto v c -> Bool #

(Show crypto, Show (G crypto c)) => Show (Election crypto v c) Source # 
Instance details

Defined in Voting.Protocol.Election

Methods

showsPrec :: Int -> Election crypto v c -> ShowS #

show :: Election crypto v c -> String #

showList :: [Election crypto v c] -> ShowS #

Generic (Election crypto v c) Source # 
Instance details

Defined in Voting.Protocol.Election

Associated Types

type Rep (Election crypto v c) :: Type -> Type #

Methods

from :: Election crypto v c -> Rep (Election crypto v c) x #

to :: Rep (Election crypto v c) x -> Election crypto v c #

(Reifies v Version, CryptoParams crypto c, ToJSON crypto) => ToJSON (Election crypto v c) Source # 
Instance details

Defined in Voting.Protocol.Election

Methods

toJSON :: Election crypto v c -> Value #

toEncoding :: Election crypto v c -> Encoding #

toJSONList :: [Election crypto v c] -> Value #

toEncodingList :: [Election crypto v c] -> Encoding #

(NFData crypto, NFData (G crypto c)) => NFData (Election crypto v c) Source # 
Instance details

Defined in Voting.Protocol.Election

Methods

rnf :: Election crypto v c -> () #

type Rep (Election crypto v c) Source # 
Instance details

Defined in Voting.Protocol.Election

type Rep (Election crypto v c) = D1 ('MetaData "Election" "Voting.Protocol.Election" "majurity-protocol-0.0.10.20191104-inplace" 'False) (C1 ('MetaCons "Election" 'PrefixI 'True) (((S1 ('MetaSel ('Just "election_name") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Text) :*: S1 ('MetaSel ('Just "election_description") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Text)) :*: (S1 ('MetaSel ('Just "election_questions") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 [Question v]) :*: S1 ('MetaSel ('Just "election_uuid") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 UUID))) :*: ((S1 ('MetaSel ('Just "election_hash") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Base64SHA256) :*: S1 ('MetaSel ('Just "election_crypto") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 crypto)) :*: (S1 ('MetaSel ('Just "election_version") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Maybe Version)) :*: S1 ('MetaSel ('Just "election_public_key") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (PublicKey crypto c))))))

hashElection :: Reifies v Version => CryptoParams crypto c => ToJSON crypto => Election crypto v c -> Base64SHA256 Source #

readElection :: forall crypto r. FromJSON crypto => ReifyCrypto crypto => FilePath -> (forall v c. Reifies v Version => CryptoParams crypto c => Election crypto v c -> r) -> ExceptT String IO r Source #

Type Ballot

data Ballot crypto v c Source #

Constructors

Ballot 

Instances

Instances details
Generic (Ballot crypto v c) Source # 
Instance details

Defined in Voting.Protocol.Election

Associated Types

type Rep (Ballot crypto v c) :: Type -> Type #

Methods

from :: Ballot crypto v c -> Rep (Ballot crypto v c) x #

to :: Rep (Ballot crypto v c) x -> Ballot crypto v c #

(Reifies v Version, CryptoParams crypto c, ToJSON (G crypto c)) => ToJSON (Ballot crypto v c) Source # 
Instance details

Defined in Voting.Protocol.Election

Methods

toJSON :: Ballot crypto v c -> Value #

toEncoding :: Ballot crypto v c -> Encoding #

toJSONList :: [Ballot crypto v c] -> Value #

toEncodingList :: [Ballot crypto v c] -> Encoding #

(Reifies v Version, CryptoParams crypto c) => FromJSON (Ballot crypto v c) Source # 
Instance details

Defined in Voting.Protocol.Election

Methods

parseJSON :: Value -> Parser (Ballot crypto v c) #

parseJSONList :: Value -> Parser [Ballot crypto v c] #

(NFData (G crypto c), NFData crypto) => NFData (Ballot crypto v c) Source # 
Instance details

Defined in Voting.Protocol.Election

Methods

rnf :: Ballot crypto v c -> () #

type Rep (Ballot crypto v c) Source # 
Instance details

Defined in Voting.Protocol.Election

type Rep (Ballot crypto v c) = D1 ('MetaData "Ballot" "Voting.Protocol.Election" "majurity-protocol-0.0.10.20191104-inplace" 'False) (C1 ('MetaCons "Ballot" 'PrefixI 'True) ((S1 ('MetaSel ('Just "ballot_answers") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 [Answer crypto v c]) :*: S1 ('MetaSel ('Just "ballot_signature") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Maybe (Signature crypto v c)))) :*: (S1 ('MetaSel ('Just "ballot_election_uuid") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 UUID) :*: S1 ('MetaSel ('Just "ballot_election_hash") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Base64SHA256))))

encryptBallot :: Reifies v Version => CryptoParams crypto c => Key crypto => Monad m => RandomGen r => Election crypto v c -> Maybe (SecretKey crypto c) -> [[Bool]] -> StateT r (ExceptT ErrorBallot m) (Ballot crypto v c) Source #

(encryptBallot c (Just ballotSecKey) opinionsByQuest) returns a Ballot signed by secKey (the voter's secret key) where opinionsByQuest is a list of Opinions on each question_choices of each election_questions.

verifyBallot :: Reifies v Version => CryptoParams crypto c => Election crypto v c -> Ballot crypto v c -> Bool Source #

Type ErrorBallot

data ErrorBallot Source #

Error raised by encryptBallot.

Constructors

ErrorBallot_WrongNumberOfAnswers Natural Natural

When the number of answers is different than the number of questions.

ErrorBallot_Answer ErrorAnswer

When encryptAnswer raised an ErrorAnswer.

ErrorBallot_Wrong

TODO: to be more precise.

Instances

Instances details
Eq ErrorBallot Source # 
Instance details

Defined in Voting.Protocol.Election

Show ErrorBallot Source # 
Instance details

Defined in Voting.Protocol.Election

Generic ErrorBallot Source # 
Instance details

Defined in Voting.Protocol.Election

Associated Types

type Rep ErrorBallot :: Type -> Type #

NFData ErrorBallot Source # 
Instance details

Defined in Voting.Protocol.Election

Methods

rnf :: ErrorBallot -> () #

type Rep ErrorBallot Source # 
Instance details

Defined in Voting.Protocol.Election

type Rep ErrorBallot = D1 ('MetaData "ErrorBallot" "Voting.Protocol.Election" "majurity-protocol-0.0.10.20191104-inplace" 'False) (C1 ('MetaCons "ErrorBallot_WrongNumberOfAnswers" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Natural) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Natural)) :+: (C1 ('MetaCons "ErrorBallot_Answer" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ErrorAnswer)) :+: C1 ('MetaCons "ErrorBallot_Wrong" 'PrefixI 'False) (U1 :: Type -> Type)))

Hashing

ballotStatement :: CryptoParams crypto c => [Answer crypto v c] -> [G crypto c] Source #

(ballotStatement ballot) returns the encrypted material to be signed: all the encryption_nonces and encryption_vaults of the given ballot_answers.

ballotCommitments :: CryptoParams crypto c => ToNatural (G crypto c) => ZKP -> Commitment crypto c -> ByteString Source #

(ballotCommitments voterZKP commitment)