Skip to content

Commit

Permalink
updated latest
Browse files Browse the repository at this point in the history
  • Loading branch information
cf committed Sep 22, 2023
1 parent 18464fd commit 43af358
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 15 deletions.
6 changes: 4 additions & 2 deletions CUSTOM_FIELD_T.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# How to use with other prime fields/t values

1. First lookup the constants for your desired prime field and t value (state size) here https://github.com/HorizenLabs/poseidon2/tree/main/plain_implementations/src/poseidon2.
2. If the constants for your prime field/t have not already been precomputed, compute them using (this sage script)[https://github.com/HorizenLabs/poseidon2/blob/main/poseidon2_rust_params.sage]
2. If the constants for your prime field/t have not already been precomputed, compute them using (this sage script)[https://github.com/HorizenLabs/poseidon2/blob/main/poseidon2_rust_params.sage]
3. Use the proper constants to generate `Poseidon2Params` and create a new `Poseidon2` class instance using your desired prime

```typescript
import {Poseidon2, F1Field, Poseidon2Params} from 'poseidon2';
import { Poseidon2, F1Field, Poseidon2Params } from "poseidon2";

// call this function with your parameters from sage/horizen labs' precomputed constants
function getPoseidon2Params(
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ 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.
SOFTWARE.
38 changes: 27 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
[![Stargazers][stars-shield]][stars-url]
[![Issues][issues-shield]][issues-url]




<!-- PROJECT LOGO -->
<br />
<div align="center">
Expand All @@ -17,38 +14,58 @@ The permutation function exposed by the Poseidon2 class is one-to-one compatible
</p>
</div>


# Install

```bash
npm install poseidon2
```

## Usage For Goldilocks Field, T = 12

### Permute

```javascript
import {permute} from 'poseidon2/goldilocks-12';
const result = permute([1337n, 123456n, 100n, 15n, 1n, 2n, 3n, 4n, 22n, 23n, 24n, 25n]);
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)

```javascript
import {twoToOne} from 'poseidon2/goldilocks-12';
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)

```javascript
import {hashPad} from 'poseidon2/goldilocks-12';
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](./CUSTOM_FIELD_T.md).

## Credits

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

# License

MIT License

Copyright (c) 2023 Zero Knowledge Labs Limited
Expand All @@ -71,15 +88,14 @@ 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.



<!-- MARKDOWN LINKS & IMAGES -->
<!-- https://www.markdownguide.org/basic-syntax/#reference-style-links -->

[contributors-shield]: https://img.shields.io/github/contributors/OpenAssetStandards/poseidon2.svg?style=for-the-badge
[contributors-url]: https://github.com/OpenAssetStandards/poseidon2/graphs/contributors
[forks-shield]: https://img.shields.io/github/forks/OpenAssetStandards/poseidon2.svg?style=for-the-badge
[forks-url]: https://github.com/OpenAssetStandards/poseidon2/network/members
[stars-shield]: https://img.shields.io/github/stars/OpenAssetStandards/poseidon2.svg?style=for-the-badge
[stars-url]: https://github.com/OpenAssetStandards/poseidon2/stargazers
[issues-shield]: https://img.shields.io/github/issues/OpenAssetStandards/poseidon2.svg?style=for-the-badge
[issues-url]: https://github.com/OpenAssetStandards/poseidon2/issues
[issues-url]: https://github.com/OpenAssetStandards/poseidon2/issues
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "poseidon2",
"license": "MIT",
"author": "Open Asset Standards",
"version": "0.1.0",
"version": "0.1.1",
"description": "A zero dependency TypeScript implementation of the Poseidon2 Hash Function",
"main": "./dist/poseidon2.cjs",
"module": "./dist/poseidon2.mjs",
Expand Down

0 comments on commit 43af358

Please sign in to comment.