This package provides an efficient JavaScript/TypeScript implementation of the Miller-Rabin primality test. It is a probabilistic algorithm used to determine if a large number (represented as a `BigInt`) is *probably* prime, rather than definitively prime. The current stable version is 1.0.1, indicating a stable API with infrequent updates typical for a specialized mathematical algorithm. Key differentiators include its focus solely on the Miller-Rabin test, making it a lightweight option for applications requiring primality testing without a broader cryptographic suite. It ships with TypeScript types, facilitating its use in modern TypeScript projects and ensuring type safety. The library is suitable for scenarios where a high probability of primality is sufficient, such as in certain cryptographic key generation processes or number theory applications.
npm install crypto-miller-rabinVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to import and use the `isProbablyPrime` function with several `BigInt` examples and explains the role of the `rounds` parameter for confidence.
Always understand the probabilistic nature of the algorithm. For cryptographic applications requiring high assurance, consult security best practices for the recommended number of rounds (e.g., 40-64 rounds) or use a deterministic primality test if absolute certainty is required for smaller numbers.
Ensure all numerical inputs are explicitly cast to `BigInt` (e.g., by appending `n` to integer literals like `123n`) or are generated as `BigInt`s from other operations.
Change `import { isProbablyPrime } from 'crypto-miller-rabin';` to `import isProbablyPrime from 'crypto-miller-rabin';`.Ensure your project is configured for ES Modules by adding `"type": "module"` to your `package.json` file, or if targeting older Node.js/environments, use a transpiler like Babel or TypeScript to compile to CommonJS.
No dependency data recorded yet.