npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

electionguard

v0.1.0

Published

Client-side implementation of ElectionGuard for ballot encryption

Downloads

58

Readme

🗳 ElectionGuard Typescript

A TypeScript library that implements a subset of the ElectionGuard spec, allowing encryption of ballots in browsers or other JavaScript engines.

electionguard npm package

Features

  • Ballot encryption and JSON serialization

    We support a synchronous API, where we encrypt a PlaintextBallot object and return a CiphertextBallot object. We also support an asynchronous API, where PlaintextContest objects are encrypted asynchronously, and a CiphertextBallot can be fetched at the end. This allows the ballot encryption process to be spread across a voting session, minimizing user-visible lag.

    Note: write-ins and overvotes are not supported in our implementation of ElectionGuard 1.0.

  • Compatibility with electionguard-python

  • Support for modern browsers (roughly since 2018) including bigint support

  • Support for NodeJS

Non-features

  • Ballot decryption
  • Ballot or election verification

Installation

Node

npm install electionguard
# or
yarn add electionguard

Browser

As an ES module:

<head>
  <!-- ... -->
  <script type="module">
    import {ManifestParty, bigIntContext4096} from './dist/electionguard.js';
    console.log(new ManifestParty(bigIntContext4096(), 'example'));
  </script>
</head>

As a UMD module:

<head>
  <!-- ... -->
  <script src="./dist/electionguard.umd.js"></script>
</head>
<body>
  <!-- ... -->
  <script>
    console.log(
      new eg.ManifestParty(eg.bigIntContext4096(), 'example')
    );
  </script>
</body>

Usage

import {
  AsyncBallotEncryptor,
  bigIntContext4096,
  EncryptionDevice,
  PlaintextBallot,
  PlaintextContest,
  PlaintextSelection,
} from 'electionguard';

// computational context for subsequent encryptions
const context = bigIntContext4096();

// specification of the "device" computing the encryptions
const device = new EncryptionDevice(context, 55890250559315, 12345, 45678, 'polling-place');
let codeSeed = device.cryptoHashElement;

// data structures that would normally be downloaded alongside an election definition
const manifestObj = {
  election_scope_id: 'hamilton-county-general-election',
  spec_version: '1.0',
  // ...
};
const electionContextObj = {
  number_of_guardians: 5,
  quorum: 3,
  // ...
};

// data structures representing an unencrypted ballot
const ballot = new PlaintextBallot(
  'ballot-8a27eaa6-f1c3-11ec-b605-aaf53b701db4',
  'congress-district-5-hamilton-county',
  [
    new PlaintextContest('president-vice-president-contest', [
      new PlaintextSelection('cramer-vuocolo-selection', 1),
    ]),
    // ...
  ]
);

// asynchronous API for encrypting each contest as the user specifies it
const encryptor = AsyncBallotEncryptor.create(
  context,
  manifestObj,
  electionContextObj,
  false,
  ballot.ballotStyleId,
  ballot.ballotId,
  codeSeed
);
ballot.contests.forEach(contest => encryptor.encrypt(contest));

(async () => {
  // collect the encrypted ballot, blocking until all encryption is complete
  const result = await encryptor.getSerializedEncryptedBallot();

  const {serializedEncryptedBallot, ballotHash, ballotSeed} = result;
  // - serializedEncryptedBallot is a plain JavaScript object, suitable
  //   for converting to JSON, with the encrypted ballot.

  // - ballotHash is a bigint, representing the hash of the encrypted
  //   ballot, which a voter could potentially keep as their "receipt"

  // - ballotSeed is a bigint, representing the source of the randomness
  //   used to encrypt the ballot. This is a sensitive value that
  //   might be printed on the bottom of a human-readable paper ballot
  //   to allow a remote system to exactly recompute the encrypted ballot.

  console.log(JSON.stringify(serializedEncryptedBallot, null, 2));
})();

See the examples directory for more examples.

Check the documentation for a full list of exports.

Documentation

You can generate API documentation using TypeDoc.

npm run docs

Development

# Install dependencies
npm install

# Now you can run various npm commands:
npm run test
npm run coverage
npm run build
npm run elgamal-bench
# ...

# Auto-indenter and linter (uses gts)
npm run fix

To try the browser examples, run npm run build first.

To run the node examples, first run npm pack in the root directory and uncompress the generated .tgz file.

See also:

License

MIT License

Authors