@taceo/poseidon2
v0.2.0
Published
Poseidon2 hash function over the BN254 scalar field (state sizes t=2,3,4,8,12,16)
Readme
@taceo/poseidon2
Poseidon2 permutation for the BN254 scalar field, with parity to the Rust taceo-poseidon2 crate.
Based on Poseidon2 (eprint.iacr.org/2023/323). Parameters are compatible with the HorizenLabs parameter script.
Installation
pnpm add @taceo/poseidon2Usage
import { bn254 } from '@taceo/poseidon2';
// State sizes t=2, t=3, t=4, t=8, t=12, t=16
const state = [0n, 1n, 2n, 3n];
const out = bn254.t4.permutation(state); // returns new array
bn254.t4.permutationInPlace(state); // mutates in placeField elements are BN254 scalar field elements (bigint in the range [0, p)), we use @noble/curves’s bn254_Fr internally.
API
bn254.t2…bn254.t16— permutation for state size 2, 3, 4, 8, 12, 16permutation(state: readonly bigint[]): bigint[]— returns new statepermutationInPlace(state: bigint[]): void— mutates state
License
MIT or Apache 2.0
