0.2.0 • Published 7 years ago

@provably-fair/core v0.2.0

Weekly downloads
1
License
MIT
Repository
github
Last release
7 years ago

@provably-fair/core

Generic purpose tools for creating and verifying provably fair games.

Version (npm)

API Reference

parseUIntFromBuffer

Parses a buffer and tries returning the first unsigned integer which fits the given range.

Parameters

  • buf Buffer Buffer to be parsed.
  • max number Maximum value of output (excluded).
  • size number Size of parsable chunks in bytes. Must be less than or equal to 6.
  • startOffset number? Where to start reading the buffer. (optional, default 0)

Returns number An unsigned integer parsed from the given buffer. If no appropriate number can be parsed, NaN is returned.

randomInt

Generates a random integer based on the given seeds, using the given HMAC algorithm.

Parameters

  • size number Size of output in bytes. Must be less than or equal to 6.
  • hmacAlgorithm string Algorithm used for computing the HMAC of the given seed pair.
  • secretSeed (string | Buffer) Secret seed used as HMAC key.
  • publicSeed (string | Buffer)? Public seed used as HMAC data. To prove fairness of random outputs, the hash of secretSeed shall be known before revealing publicSeed.
  • min number? Minimum value of output (included). (optional, default 0)
  • max number? Maximum value of output (excluded). (optional, default 256**size)
  • hmacBufferUIntParser function? Function to be used for parsing a UInt from the generated HMAC buffer. (optional, default parseUIntFromBuffer)
  • fallbackProvider function? Function to provide a fallback value in a given range whether no appropriate number can be parsed from the generated HMAC buffer. (optional, default range)

Returns number An integer within the given range.