1.0.0 • Published 5 years ago

@femto-apps/random-number v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
5 years ago

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:
UserGenerated NumberNonceHash
Alice25h4wh5663653j356j
Bob7w45hh56j35j35j535
Eve5wzghkzdfg34t4353y
  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)
1.0.0

5 years ago