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

@wavesenterprise/voting-encrypt

v3.1.0

Published

```js

Downloads

7

Readme

Usage example

Get params and encrypt one bulletin


// Get config from cryptolib GET /v1/getParamSet. E.g https://voting.welocal.dev/cryptoService/v1/getParamSet
const cryplolibParams = {
	"a": "0",
	"b": "7",
	"basePoint": [
		"55066263022277343669578718895168534326250603453777594175500187360389116729240",
		"32670510020758816978083085130507043184471273380659243275938904335757337482424"
	],
	"hashLength": "256",
	"p": "115792089237316195423570985008687907853269984665640564039457584007908834671663",
	"pedersenBase": [
		"31840000124805594708716908823730049919282872088758887139161784794466556143989",
		"34159713578909946807425318728956240239794987299568203108985430402093588737051"
	],
	"q": "115792089237316195423570985008687907852837564279074904382605163141518161494337",
}

/* Dimesion type
 *  [
 *    [
 *      min: number,      // minimum amount of selected options
 *      max: number,      // maximum amount of selected options
 *      total: number   // total options num in question
 *    ],
 *    ..
 *  ]
 */
const dimension = [[1,1,2],[1,2,3]]

// get from poll info. e.g https://voting-dev.welocal.dev/decryptServiceMaster/v1/poll/2012
// everything except mainKey will be constant after poll creation.
// Main key will be generated during dkg proccess before dateStart and then never changes.
const type='common'
const mainKey = [
	"57524282568728082791232576457478242943818952557343747344126049585929786788758",
	"38787228570461587633267528340413718686005272951935064150467570181538022969944",
]
const txId = '7RJXEBC73cELphuoQNKWmQFbDcrXgEenrAAPoVHAz1uF'
const multiplier=1

const weight = 1
// selected 1st option in the 1st question and 1st and 3rd in the 2dn question
const bulletin = [[1,0], [1,0,1]]

const encryptedBulletin = encrypt({
	...cryplolibParams,
	mainKey,
	type,
	dimension,
	bulletin,
})

console.log('encryptedBulletin', JSON.stringify(encryptedBulletin))

/// ...

Encode to bytes / Decode from bytes

// ...
const encrypted = encrypt(encryptOptions)
const binary = serialize(encrypted)
const decoded = deserialize(binary)
console.log(`Binary size: ${binary.length}`)

Calculating mainKey from Pedersen's commitments and scalars

const { mainKey, dkgCommits, dkgScalars } = {
  "mainKey": [
    "57524282568728082791232576457478242943818952557343747344126049585929786788758",
    "38787228570461587633267528340413718686005272951935064150467570181538022969944"
  ],
  "dkgScalars": [
    "60205190671371004052027574671005427581107002065061497157579481218698888136211",
    "59574457923147341647686899237823522695249872693694764462154125327640876089030",
    "62412122924432091887200600446458193045824422914909193997032220320572755918169"
  ],
  "dkgCommits": [
    {
      "x": "53223510927926924044821712271603075123426104274557218213053365857469041906786",
      "y": "63812211576732480897403235008742810396190456041389943747378921353807308231394"
    },
    {
      "x": "31487217581766849517295031273817794483626722217369663455992733898856595599183",
      "y": "82028928866030698176659688780576011462734544450397693113073209813925075425706"
    },
    {
      "x": "91417142484544224273770657056726197723275714351299031732568048344701157739195",
      "y": "111868356246544901009252079534910516693040811004478292518237552911866514740597"
    }
  ]
}

const keyPairs = dkgCommits
  .map(utils.mapPointTuple)
  .map((publicKey, i) => ({
    publicKey,
    privateKey: dkgScalars[i],
  }))

console.log('\nVerify main key:')
console.log('FROM BLOCKCHAIN:', mainKey)
console.log('COMPUTED:', calculateMainKey(config, keyPairs))

Bulletins and dimension generator

// generator settings
const bulletinsNum = 1
const questionsNum = 3
const optionsNum = 8
const maxSelected = 4
const minSelected = 0

const bulletins = Array(bulletinsNum)
  .fill(0)
  .map(() => Array(questionsNum)
    .fill(0)
    .map(() => {
      const selected = minSelected + Math.round(Math.random() * maxSelected - minSelected)
      return [
        ...Array(selected).fill(1),
        ...Array(optionsNum - selected).fill(0)
      ].sort(() => Math.random() - 0.5)
    })
  )

const dimension = Array(questionsNum)
	.fill(0)
	.map((_, i) => ([
		minSelected,
		maxSelected,
		bulletins[0][i].length
	]))