6.8.14 • Published 5 days ago

@dfares/hashing v6.8.14

Weekly downloads
-
License
MIT
Repository
-
Last release
5 days ago

@dfares/hashing

This package contains MiMC hashing utilities for use with Dark Forest. The MiMC algorithm is used for both finding planet hashes and calculating the perlin in-game. Among other things, these values are often needed for generating Snarks.

Installation

You can install this package using npm or yarn by running:

npm install --save @dfares/hashing
yarn add @dfares/hashing

When using this in a plugin, you might want to load it with skypack

import * as hashing from 'http://cdn.skypack.dev/@dfares/hashing';

Table of contents

Interfaces

Variables

Functions

Variables

Fraction

Fraction: IFraction


MAX_PERLIN_VALUE

Const MAX_PERLIN_VALUE: 32

Functions

getRandomGradientAt

getRandomGradientAt(point, scale, randFn): Vector

Parameters

NameType
pointVector
scaleIFraction
randFnHashFn

Returns

Vector


mimcHash

mimcHash(key): (...inputs: number[]) => BigInteger

The primary function used to build any MiMC hashing algorithm for Dark Forest.

Parameters

NameTypeDescription
keynumberThe key for the MiMC algorithm. Will usually be PLANETHASH_KEY, SPACETYPE_KEY, or BIOMEBASE_KEY.

Returns

fn

▸ (...inputs): BigInteger

Parameters
NameType
...inputsnumber[]
Returns

BigInteger


mimcSponge

mimcSponge(inputs, nOutputs, rounds, key): BigInteger[]

Parameters

NameType
inputsBigInteger[]
nOutputsnumber
roundsnumber
keynumber

Returns

BigInteger[]


modPBigInt

modPBigInt(x): BigInteger

Modulo a number with the LOCATION_ID_UB constant. If the result is < 0, the LOCATION_ID_UB will then be added.

Parameters

NameTypeDescription
xnumberThe number to modulo against LOCATION_ID_UB

Returns

BigInteger


modPBigIntNative

modPBigIntNative(x): BigInteger

Modulo a BigInt with the LOCATION_ID_UB constant. If the result is < 0, the LOCATION_ID_UB will then be added.

Parameters

NameTypeDescription
xBigIntegerThe number to modulo against LOCATION_ID_UB

Returns

BigInteger


perlin

perlin(coords, options): number

Calculates the perlin for a location, given the x,y pair and the PerlinConfig for the game.

Parameters

NameTypeDescription
coordsIntegerVectorAn object of the x,y coordinates for which perlin is being calculated.
optionsPerlinConfigAn object containing the configuration for the perlin algorithm.

Returns

number


rand

rand(key): (...args: number[]) => number

Parameters

NameType
keynumber

Returns

fn

▸ (...args): number

Parameters
NameType
...argsnumber[]
Returns

number


seededRandom

seededRandom(seed): number

Generate a random number based on some seed. Useful for procedural generation.

Parameters

NameTypeDescription
seednumberThe seed of the random number.

Returns

number

6.8.14

5 days ago

6.8.13

14 days ago

6.8.12

29 days ago

6.8.11

29 days ago

6.8.10

2 months ago

6.8.9

2 months ago

6.8.8

2 months ago

6.8.7

2 months ago

6.8.6

4 months ago

6.8.5

6 months ago

6.8.4

10 months ago

6.8.3

10 months ago

6.8.2

10 months ago

6.8.1

10 months ago

6.9.3

10 months ago

6.9.2

10 months ago

6.9.1

10 months ago

6.8.0

10 months ago

6.8.0-dev.0

10 months ago