Package Exports
- voting-lib
- voting-lib/dist/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (voting-lib) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
voting-lib
A library to manage voting systems, having its own voting rules and options while giving its consumer the choice on how to store the data and manage user security.
Objectives
- Transparency: to have open and traceable votes without revealing real user data
- Flexibility: to support multiple voting methods, including:
- Election: each person votes for one candidate and the elected candidate is the one with the most votes
- Judgement: each person votes for one or more candidates and the guilty ones are the ones with more votes for guilty than for innocent
Installation
$ npm i voting-libSetup
You should configure all the callbacks necessary to handle the data (wherever and however it is stored). This can be done using the method setCallbacks passing all or some of the callbacks.
import { setCallbacks } from 'voting-lib'
setCallbacks({
persistVote: () => {...},
persistVoters: () => {...},
persistVoting: () => {...},
retrieveVoting: () => {...},
retrieveVoter: () => {...},
retrieveVotes: () => {...},
...
})This method can be called any number of times to change all or some of the callbacks, but it is important that all the callbacks are set before calling any of the functions that manipulate the data.
Rules
- All participants must be registered prior to starting the voting
- A voting cannot be started by a candidate
Usage
Registering a voter
const request = {
userIds: ['<userId1>', '<userId2>', ...],
}
const response = await registerVoters(request)Election
Starting an election
const request = {
votingParams: {
votingDescription: {
'en-US': 'Test voting',
},
votingType: 'election',
startedBy: '<voterId>',
candidates: ['<candidateId>', ...],
startsAt: new Date(),
endsAt: (() => {
const tomorrow = new Date()
tomorrow.setDate(tomorrow.getDate() + 1)
return tomorrow
})(),
},
}
const response = await startVoting(request)Registering an election vote
const request = {
voteParams: {
votingId: '<votingId>',
voterId: '<voterId>',
choices: [
{
candidateId: '<candidateId>',
veredict: 'elect',
},
],
},
}
const response = await registerVote(request)Judgement
Starting a judgement
const request = {
votingParams: {
votingDescription: {
'en-US': 'Test voting',
},
votingType: 'judgement',
startedBy: '<voterId>',
candidates: ['<candidateId>', ...],
startsAt: new Date(),
endsAt: (() => {
const tomorrow = new Date()
tomorrow.setDate(tomorrow.getDate() + 1)
return tomorrow
})(),
evidences: [
{
type: 'text',
data: 'This is the evidence',
},
{
type: 'image',
data: '<imageUrl>',
},
]
},
}
const response = await startVoting(request)Registering a judgement vote
const request = {
voteParams: {
votingId: '<votingId>',
voterId: '<voterId>',
choices: [
{
candidateId: '<candidateId>',
veredict: 'guilty',
},
],
},
}
const response = await registerVote(request)Retrieving the summary
const request = {
votingId: '<votingId>',
}
const result = await retrieveVotingSummary(request)