Skip to content

Commit c5f4331

Browse files
committed
Add file
1 parent a97e042 commit c5f4331

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

sdk/zklogin/src/poseidon.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,16 @@ const poseidonNumToHashFN = [
3939
poseidon16,
4040
];
4141

42+
export const BN254_FIELD_SIZE = 21888242871839275222246405745257275088548364400416034343698204186575808495617n;
43+
4244
export function poseidonHash(inputs: (number | bigint | string)[]): bigint {
45+
inputs.forEach(x => {
46+
const b = BigInt(x);
47+
if (b < 0 || b >= BN254_FIELD_SIZE) {
48+
throw new Error(`Element ${b} not in the BN254 field`);
49+
}
50+
});
51+
4352
const hashFN = poseidonNumToHashFN[inputs.length - 1];
4453

4554
if (hashFN) {

0 commit comments

Comments
 (0)