This implements verifiable secret sharing on top of bls-lib. Its is based on Shamir's scheme but has the added benefit that ths recipients can verify their shares against a verifcation vector. This insures that dealer cannot hand out invalid shares.
npm install vss
const vss = require('vss')
const bls = require('bls-lib')
bls.onModuleInit(() => {
bls.init()
const threshold = 5
const numOfPlayers = 7
const setup = vss.createShare(bls, numOfPlayers, threshold)
// use `setup.secret` to encrypt something, it is a random 32 byte Uint8Array
// post `setup.verificationVector` somewhere public
// then send each share in `setup.shares` to someone
// when the recipients recieve thier share they can verify that it was created
// corectly with the verifcationVector
setup.shares.forEach(share => {
const verified = vss.verifyShare(bls, share, setup.verifcationVector)
console.log(verified)
})
// when `threshold` number of recipients combine their shares the secert key
// can be recovered
const secret = vss.recoverSecret(bls, setup.shares.slice(0, threshold))
// secret === setup.secret
})