@bountygg/provably-fair
TypeScript icon, indicating that this package has built-in type declarations

1.1.1 • Public • Published

Hello from the bounty.gg team 👋

We feel it's important to stay transparent, which is why we're making the official provably fair implementation used on the bounty.gg servers public here

Usage

const pf = require("@bountygg/provably-fair");

async function aQuickTestRun() {
	const ticketCount = 10000; // lets pretend there are 10k tickets in the jackpot round

	// generate a random string
	const serverSeed = pf.getRandomBytes();
	// get a random string from a third party (here random.org)
	const thirdPartySalt = (await pf.getThirdPartySalt()).value;
	// concat both seeds
	const fullSeed = `${serverSeed}-${thirdPartySeed}`;
	// get winning percentage based on both the locally-generated `serverSeed` and the third-party `thirdPartySeed`
	// see https://chancejs.com/usage/seed.html for an example implementation
	const winningPercentage = pf.getPseudoRandomPercentage(fullSeed);

	// we're done! now we're able to get the winning ticket
	const winningTicket = pf.getWinningTicket(winningPercentage, ticketCount);

	console.table({
		ticketCount,
		serverSeed,
		thirdPartySeed,
		fullSeed,
		winningPercentage: winningPercentage.toNumber(),
		winningTicket
	});
}

aQuickTestRun();

Run the example above with

RANDOM_ORG_API_KEY=\<your random.org api key\> node index.js

You can get a free api key for the random.org gRPC api from api.random.org

Readme

Keywords

none

Package Sidebar

Install

npm i @bountygg/provably-fair

Weekly Downloads

0

Version

1.1.1

License

UNLICENSED

Unpacked Size

8.11 kB

Total Files

6

Last publish

Collaborators

  • bobtheshoplifter
  • gameghostify