@femto-apps/random-number

1.0.0 • Public • Published

Random Numbers

A library which allows the selection of a random number between a group of people that do not trust each other. Uses the following algorithm (where n is the highest number to select, 0 is always the lowest):

  1. All users select a random number between 0 and 2 ^ ceil(log2(n)). The results are hashed with a nonce using a secure hashing algorithm and shared with the group:
User Generated Number Nonce Hash
Alice 2 5h4wh 5663653j356j
Bob 7 w45hh 56j35j35j535
Eve 5 wzghk zdfg34t4353y
  1. Once a user receives the hash of every other participant, they reveal their randomly generated number and their nonce.

  2. All generated numbers are then xor'd together and normalised to

Usage:

const { RandInt } = require('@femto-host/randomNumber')

// pick a random integer from 1 to 20 (inclusive)
const generator = new RandInt(1, 20)

const myPart = generator.gen()

/* implement some part sharing method

1. share `myPart.hash` with others
2. share `myPart` with others after everyone has shown you their hash
*/

generator.finalise(parts)

Readme

Keywords

none

Package Sidebar

Install

npm i @femto-apps/random-number

Weekly Downloads

2

Version

1.0.0

License

MIT

Unpacked Size

3.31 kB

Total Files

4

Last publish

Collaborators

  • codefined