0.2.0 • Published 9 years ago
@provably-fair/core v0.2.0
@provably-fair/core
Generic purpose tools for creating and verifying provably fair games.
API Reference
parseUIntFromBuffer
Parses a buffer and tries returning the first unsigned integer which fits the given range.
Parameters
bufBuffer Buffer to be parsed.maxnumber Maximum value of output (excluded).sizenumber Size of parsable chunks in bytes. Must be less than or equal to 6.startOffsetnumber? Where to start reading the buffer. (optional, default0)
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
sizenumber Size of output in bytes. Must be less than or equal to 6.hmacAlgorithmstring 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 ofsecretSeedshall be known before revealingpublicSeed.minnumber? Minimum value of output (included). (optional, default0)maxnumber? Maximum value of output (excluded). (optional, default256**size)hmacBufferUIntParserfunction? Function to be used for parsing a UInt from the generated HMAC buffer. (optional, defaultparseUIntFromBuffer)fallbackProviderfunction? Function to provide a fallback value in a given range whether no appropriate number can be parsed from the generated HMAC buffer. (optional, defaultrange)
Returns number An integer within the given range.