Skip to main content
Version: 11.x

Function: poseidonSponge()

poseidonSponge(opts): () => PoseidonSponge & (...args) => PoseidonSponge & object & object

Defined in: node_modules/@noble/curves/abstract/poseidon.d.ts:197

The method is not defined in spec, but nevertheless used often. Check carefully for compatibility: there are many edge cases, like absorbing an empty array. We cross-test against:

Parameters

opts

TArg<PoseidonSpongeOpts>

Sponge options. See PoseidonSpongeOpts.

Returns

() => PoseidonSponge & (...args) => PoseidonSponge & object & object

Factory for sponge instances.

Throws

If the sponge dimensions or backing permutation options are invalid. Error

Example

Use the sponge helper to absorb several field elements and squeeze one digest.

import { grainGenConstants, poseidonSponge } from '@noble/curves/abstract/poseidon.js';
import { Field } from '@noble/curves/abstract/modular.js';
const Fp = Field(17n);
const constants = grainGenConstants({ Fp, t: 2, roundsFull: 8, roundsPartial: 8 });
const makeSponge = poseidonSponge({
...constants,
Fp,
rate: 1,
capacity: 1,
roundsFull: 8,
roundsPartial: 8,
sboxPower: 3,
});
const sponge = makeSponge();
sponge.absorb([1n]);
const out = sponge.squeeze(1);