Skip to content

Commit

Permalink
Lint
Browse files Browse the repository at this point in the history
  • Loading branch information
mskd12 committed Aug 12, 2024
1 parent c5f4331 commit 66261ed
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 3 additions & 2 deletions sdk/zklogin/src/poseidon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@ const poseidonNumToHashFN = [
poseidon16,
];

export const BN254_FIELD_SIZE = 21888242871839275222246405745257275088548364400416034343698204186575808495617n;
export const BN254_FIELD_SIZE =
21888242871839275222246405745257275088548364400416034343698204186575808495617n;

export function poseidonHash(inputs: (number | bigint | string)[]): bigint {
inputs.forEach(x => {
inputs.forEach((x) => {
const b = BigInt(x);
if (b < 0 || b >= BN254_FIELD_SIZE) {
throw new Error(`Element ${b} not in the BN254 field`);
Expand Down
7 changes: 6 additions & 1 deletion sdk/zklogin/test/poseidon.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0
import { expect, test } from 'vitest';

import { BN254_FIELD_SIZE, poseidonHash } from '../src/poseidon';

test('can hash single input', () => {
Expand All @@ -16,5 +19,7 @@ test('throws error for invalid input', () => {
});

test('throws error for invalid input greater than BN254_FIELD_SIZE', () => {
expect(() => poseidonHash([BN254_FIELD_SIZE])).toThrowError('Element 21888242871839275222246405745257275088548364400416034343698204186575808495617 not in the BN254 field');
expect(() => poseidonHash([BN254_FIELD_SIZE])).toThrowError(
'Element 21888242871839275222246405745257275088548364400416034343698204186575808495617 not in the BN254 field',
);
});

0 comments on commit 66261ed

Please sign in to comment.