npm stats
  • Search
  • About
  • Repo
  • Sponsor
  • more
    • Search
    • About
    • Repo
    • Sponsor

Made by Antonio Ramirez

@projectsophon/hashing

0.1.3

@sophonbot

npmHomeRepoSnykSocket
Downloads:0
$ npm install @projectsophon/hashing
DailyWeeklyMonthlyYearly

@projectsophon/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 @projectsophon/hashing
yarn add @projectsophon/hashing

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

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

Table of contents

Interfaces

  • IntegerVector

Variables

  • Fraction
  • MAX_PERLIN_VALUE

Functions

  • getRandomGradientAt
  • mimcHash
  • mimcSponge
  • modPBigInt
  • modPBigIntNative
  • perlin
  • rand
  • seededRandom

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[]) => bigint

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): bigint

Parameters
NameType
...inputsnumber[]
Returns

bigint


mimcSponge

▸ mimcSponge(inputs, nOutputs, rounds, key): bigint[]

Parameters

NameType
inputsbigint[]
nOutputsnumber
roundsnumber
keynumber

Returns

bigint[]


modPBigInt

▸ modPBigInt(x): bigint

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

bigint


modPBigIntNative

▸ modPBigIntNative(x): bigint

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

Parameters

NameTypeDescription
xbigintThe number to modulo against LOCATION_ID_UB

Returns

bigint


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