Skip to content

TypeScript Implementation of the Poseidon2 Hash Function (3kb ๐ŸŽ‰)

License

Notifications You must be signed in to change notification settings

OpenAssetStandards/poseidon2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

16 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Contributors Forks Stargazers Issues


poseidon2

A zero dependency implementation of the Poseidon2 hash function. The permutation function exposed by the Poseidon2 class is one-to-one compatible with HorizenLabs/poseidon2. 3kb gzipped ๐ŸŽ‰

Install

npm install poseidon2

Note For TypeScript Users:

If you see the error "Cannot find module 'poseidon2/goldilocks-12' or its corresponding type declarations.ts(2307)", update your tsconfig.json to set "moduleResolution": "NodeNext".

Usage For Goldilocks Field, T = 12

Permute

import { permute } from "poseidon2/goldilocks-12";
const result = permute([
  1337n,
  123456n,
  100n,
  15n,
  1n,
  2n,
  3n,
  4n,
  22n,
  23n,
  24n,
  25n,
]);

Two to One (Hash two 4-element-wide values)

import { twoToOne } from "poseidon2/goldilocks-12";
const result = twoToOne([1337n, 123456n, 100n, 15n], [1n, 2n, 3n, 4n]);

Sponge Hash with Pad (Hash n elements with padding)

import { hashPad } from "poseidon2/goldilocks-12";
const result = hashPad([1n, 2n, 3n, 1337n, 9999n, 123n]);

How to use with other prime fields/t values

See Working with other prime fields and t values.

Credits

Original implementation of poseidon2 by https://github.com/HorizenLabs

License

MIT License

Copyright (c) 2023 Zero Knowledge Labs Limited

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

TypeScript Implementation of the Poseidon2 Hash Function (3kb ๐ŸŽ‰)

Resources

License

Stars

Watchers

Forks

Packages

No packages published