ByteHelper

@buff-beacon-project/curby-clientDocs


@buff-beacon-project/curby-client / ByteHelper

Interface: ByteHelper

A helper for working with randomness.

Contains methods for reading bits, shuffling arrays, and more.

Example

// BytesHelper from a randomness call
const randomness = await client.randomness()

// Get a list of unsigned numbers formed by reading 10 bits at a time
const bits = Array.from(randomness.bits(10))

// Get a shuffled version of an array
const array = [1, 2, 3, 4, 5]
const shuffled = randomness.shuffled(array)
// shuffled = [3, 1, 5, 2, 4]

Properties

Property
Type
Description
Defined in

maxShuffleLength

number

The maximum length an array can be for shuffling

timestamp

number

The unix timestamp of the randomness

Methods

applyShuffle()

applyShuffle(arr): void

Applies a shuffle to an array

Parameters

Parameter
Type
Description

arr

any[]

The array to shuffle

Returns

void

Example

Defined in

src/byte-helper.ts:95arrow-up-right


bits()

bits(n): Generator<number, any, any>

A generator for reading unsigned numbers

Parameters

Parameter
Type
Description

n

number

The number of bits to read at a time

Returns

Generator<number, any, any>

Example

Defined in

src/byte-helper.ts:47arrow-up-right


bytes()

bytes(): Uint8Array

The bytes of the randomness

Returns

Uint8Array

Defined in

src/byte-helper.ts:33arrow-up-right


reader()

reader(): BitReader

The a BitReader for the randomness

Returns

BitReader

See

https://github.com/buff-beacon-project/rand-utilsarrow-up-right

Defined in

src/byte-helper.ts:65arrow-up-right


shuffled()

shuffled(arr): any[]

Shuffles an array using the randomness

Parameters

Parameter
Type
Description

arr

any[]

The array to shuffle

Returns

any[]

Example

Defined in

src/byte-helper.ts:82arrow-up-right


signedBits()

signedBits(n): Generator<number, any, any>

A generator for reading signed numbers

Parameters

Parameter
Type
Description

n

number

The number of bits to read at a time See ByteHelper.bits for an example

Returns

Generator<number, any, any>

Defined in

src/byte-helper.ts:55arrow-up-right


stream()

stream(): BitStream

The BitStream for the randomness

Returns

BitStream

Defined in

src/byte-helper.ts:59arrow-up-right


unfold()

unfold(cb): Generator<any, any, any>

Unfolds the randomness

Parameters

Parameter
Type
Description

cb

(reader, index) => any

A function to call for each iteration

Returns

Generator<any, any, any>

Example

Defined in

src/byte-helper.ts:114arrow-up-right

Last updated