deepgitUT / vrf.js

A pure Javascript Implementation of Verifiable Random Functions

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

A pure Javascript Implementation of Verifiable Random Functions

Install

$ yarn add vrf.js

Usage

ECVRF

const {utils, ecvrf, sortition} = require('vrf.js')
const X = Buffer.from('test')

const [publicKey, privateKey] = utils.generatePair()

const {value, proof} = ecvrf.vrf(publicKey, privateKey, X)

ecvrf.verify(publicKey, X, proof, value)
// true

VRF Sortition

const {utils, ecvrf, sortition} = require('vrf.js')
const seed = Buffer.from('sortition')
const role = Buffer.from('test')
const w = utils.N(100)
const W = utils.N(1000)
const tau = utils.N(10)


const [publicKey, privateKey] = utils.generatePair()
const [value, proof, j] = sortition.sortition(
  privateKey, publicKey,
  seed, tau, role, w, W
)

if (+j > 0) {
  // next
}

more examples

APIs

  • utils.generatePair
  • utils.B
  • utils.N
  • ecvrf.vrf
  • ecvrf.prove
  • ecvrf.verify
  • ecvrf.proofToHash
  • ecvrf.hashToCurve
  • sortition.sortition
  • sortition.verifySort

TODOs

  • browser support
  • web examples
  • visualization
  • RSA-FDH-VRF

About

A pure Javascript Implementation of Verifiable Random Functions

License:MIT License


Languages

Language:JavaScript 53.6%Language:TypeScript 46.4%