UNPKG

poseidon-h

Version:

Poseidon hash with alt_bn128 implementation in Typescript

19 lines 816 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.isOverflow = exports.randomFieldElement = exports.P = void 0; // bn256 prime field exports.P = BigInt("0x30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000001"); const randomFieldElement = () => { const lastBit = 0x30644e72; const bit32Max = 0xffffffff; const lastUpperBits = BigInt(Math.floor(Math.random() * lastBit)); return [...Array(7)].reduce((acc, _) => (acc << 32n) | BigInt(Math.floor(Math.random() * bit32Max)), lastUpperBits); }; exports.randomFieldElement = randomFieldElement; const isOverflow = (element) => { if (element >= exports.P) { throw new Error("Field element is greater than the field modulus"); } }; exports.isOverflow = isOverflow; //# sourceMappingURL=ff.js.map