ffjavascript is a Finite Field Library implemented in JavaScript, designed for cryptographic applications, particularly those involving zk-SNARKs and other zero-knowledge proof systems. It provides core functionalities for performing arithmetic operations within finite fields, which are fundamental building blocks for many advanced cryptographic primitives. The library is currently at version 0.3.1 and sees an active, though not rapid, release cadence with minor updates and fixes. It is distinguished by its broad environment compatibility, supporting NodeJS, browser environments, Chrome Extensions, and Metamask Snaps (with SES compatibility), making it versatile for both backend and frontend cryptographic computations. Its primary differentiator is its focus on providing the underlying finite field arithmetic necessary for complex cryptographic protocols, often serving as a dependency for higher-level SNARK libraries.
npm install ffjavascriptVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize the BN128 finite field and perform basic arithmetic operations with field elements like addition, multiplication, subtraction, inverse, and division.
Disable the `splitChunks` optimization in your Webpack configuration. Add `optimization: { splitChunks: false }` to your `module.exports` object in `webpack.config.js` or `next.config.js`.Developers targeting SES environments should test their integrations thoroughly after upgrading to v0.3.0+. Ensure no code directly or indirectly relies on dynamic `eval` calls that are not compatible with SES strictures. For non-SES environments, this change is largely backward compatible.
For new projects, prefer ESM `import` statements. For Node.js, ensure your `package.json` has `"type": "module"` or explicitly use `.mjs` extensions for ESM files. If you must use CJS, verify that your bundler or Node.js setup correctly resolves the CJS entry point specified in `package.json`'s `exports` map (e.g., `"require": "./build/main.cjs"`).
Ensure your webpack configuration disables `splitChunks` by adding `optimization: { splitChunks: false }` to your `module.exports` in `webpack.config.js` or equivalent.Always use `await` when calling `buildBn128()` or similar field builder functions, as they are asynchronous. Example: `const Fr = await buildBn128();`.