@provably-fair/core
v0.2.0
Published
Generic purpose tools for creating and verifying provably fair games
Downloads
4
Readme
@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
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, 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
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 ofsecretSeed
shall be known before revealingpublicSeed
.min
number? Minimum value of output (included). (optional, default0
)max
number? Maximum value of output (excluded). (optional, default256**size
)hmacBufferUIntParser
function? Function to be used for parsing a UInt from the generated HMAC buffer. (optional, defaultparseUIntFromBuffer
)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, defaultrange
)
Returns number An integer within the given range.