UNPKG

@provably-fair/shuffle

Version:

Array shuffling functionality for provably fair games

28 lines (18 loc) 1.71 kB
# @provably-fair/shuffle Array shuffling functionality for provably fair games. [![Version (npm)](https://img.shields.io/npm/v/@provably-fair/shuffle.svg)](https://www.npmjs.com/package/@provably-fair/shuffle) ## API Reference <!-- Generated by documentation.js. Update this documentation by updating the source code. --> ### shuffle Shuffles an array based on the given seeds, using the given HMAC algorithm. **Parameters** - `arr` **\[]** Array to be shuffled. - `hmacAlgorithm` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** Algorithm used for computing the HMAC of the given seed pair. - `secretSeed` **([string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) \| [Buffer](https://nodejs.org/api/buffer.html))** Secret seed used as HMAC key. - `publicSeed` **([string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) \| [Buffer](https://nodejs.org/api/buffer.html))?** Public seed used as HMAC data. To prove fairness of random outputs, the hash of `secretSeed` shall be known before revealing `publicSeed`. - `hmacBufferUIntParser` **[function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)?** Function to be used for parsing a UInt from the generated HMAC buffer. - `fallbackProvider` **[function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)?** Function to provide a fallback value in a given range whether no appropriate number can be parsed from the generated HMAC buffer. Returns **\[]** A new array instance containing every element of the input.