Skip to main content
Version: 2.0.0-beta-4

Helpers

SNARK_SCALAR_FIELD

A decimal string representing the field prime.

import { SNARK_SCALAR_FIELD } from '@unirep/utils'

F

A bigint representation of the field prime.

import { F } from '@unirep/utils'

MAX_EPOCH

A number representation of the maximum epoch value. Equivalent to 2**48-1.

import { MAX_EPOCH } from '@unirep/utils'

genEpochKey

Calculate an epoch key.

import { genEpochKey } from '@unirep/utils'

genEpochKey(
identitySecret: bigint,
attesterId: bigint | string,
epoch: bigint | number,
nonce: bigint | number,
): bigint

genIdentityHash

Calculate an identity hash for a user. It is used for user signup. The state tree leaf should follow the format:
stateTreeLeaf = H(identityHash, H(data)) where
identityHash = H(identitySecret, attesterId + (epoch << 160)).

info

See state tree for more details.

import { genIdentityHash } from '@unirep/utils'

genIdentityHash(
idSecret: bigint,
attesterId: bigint | string,
epoch: bigint | number
): bigint

genStateTreeLeaf

Calculate a state tree leaf for a user.

import { genStateTreeLeaf } from '@unirep/utils'

genStateTreeLeaf(
idSecret: bigint,
attesterId: bigint | string,
epoch: bigint | number,
data: (bigint | string | number)[]
): bigint

genEpochTreeLeaf

Calculate an epoch tree leaf in an epoch tree.

import { genEpochTreeLeaf } from '@unirep/utils'

genEpochTreeLeaf(
epochKey: bigint | string,
data: (bigint | string | number)[]
): bigint

stringifyBigInts

Stringify all bigints in an object, a string, or an array

import { stringifyBigInts } from '@unirep/utils'

stringifyBigInts(BigInt(3))
// '3'

stringifyBigInts([BigInt(3)])
// ['3']

stringifyBigInts({
item: BigInt(3)
})
// { item: '3' }

unstringifyBigInts

Unstringify all strings in an object, a string, or an array to bigints

import { unstringifyBigInts } from '@unirep/utils'

const values = {
input1: '1',
input2: '2',
input3: '3',
}

unstringifyBigInts(values)
// { input1: 1n, input2: 2n, input3: 3n }