poseidon-h
Version:
Poseidon hash with alt_bn128 implementation in Typescript
42 lines (28 loc) • 1.28 kB
Markdown
# Poseidon Hash over bn254 with Typescript
[](https://github.com/inverse-technology/poseidon-ts/blob/master/LICENSE)
[](https://www.typescriptlang.org)  [](https://github.com/inverse-technology/poseidon-ts/actions/workflows/index.yml)
A [poseidon hash](https://eprint.iacr.org/2019/458.pdf) implementation over BN254. Circom circuit and Groth16 tests.
**Use at your own risk**.
## Install
```shell
$ npm i poseidon-h
```
## Usage
```ts
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
```shell
$ yarn test
```
## Groth16
```shell
$ yarn groth16
```