Skip to content

invers-technology/poseidon-ts

Repository files navigation

Poseidon Hash over bn254 with Typescript

MIT License Language npm version CI Check

A poseidon hash implementation over BN254. Circom circuit and Groth16 tests.

Use at your own risk.

Install

$ npm i poseidon-h

Usage

import { poseidon, randomFieldElement } from "poseidon-h";
const wasm = require("circom_tester").wasm;

const hash = poseidon([1n, 2n]);
const hash2 = poseidon([randomFieldElement(), randomFieldElement()]);
const circuit = await wasm(path.join("circuit", "poseidon.circom"));
const witness = await circuit.calculateWitness({ inputs });
const hash = poseidon(inputs);

await circuit.assertOut(witness, { out: hash });

Test

$ yarn test

Groth16

$ yarn groth16