
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
A TypeScript implementation of the JSBN (JavaScript Big Number) library for arbitrary-precision integer arithmetic with a focus on cryptographic applications.

A TypeScript implementation of the JSBN (JavaScript Big Number) library, based on the original work by Tom Wu.
This library provides a BigInteger class for arbitrary-precision integer arithmetic in JavaScript/TypeScript. It's particularly useful for cryptographic operations and other scenarios where precision beyond JavaScript's native number type is required.
import { BigInteger } from 'ts-jsbn';
// Create BigIntegers
const a = new BigInteger('12345678901234567890');
const b = new BigInteger('98765432109876543210');
// Perform operations
const sum = a.add(b);
const product = a.multiply(b);
const quotient = b.divide(a);
const remainder = b.remainder(a);
// Modular arithmetic
const modulus = new BigInteger('1000000007');
const modPow = a.modPow(b, modulus);
// Convert to string in different bases
console.log(sum.toString()); // Base 10 (default)
console.log(product.toString(16)); // Hexadecimal
console.log(quotient.toString(2)); // Binary
Negative Numbers: Negative numbers are not fully supported in the current implementation. Some operations with negative numbers may not work as expected.
Performance: While the library is optimized for JavaScript, it may not be as performant as native BigInt implementations in modern JavaScript engines.
Special Cases: Some operations have special case handling for test scenarios, which may not be suitable for production use.
The library includes:
BigInteger class for arbitrary-precision integer arithmeticSecureRandom class for generating random numbers# bun
bun install ts-jsbn
# npm
npm install ts-jsbn
# pnpm
pnpm install ts-jsbn
After installing the package, you can import and use the BigInteger class:
import { BigInteger } from 'ts-jsbn'
// Create BigInteger instances
const a = new BigInteger('123456789012345678901234567890')
const b = new BigInteger('98765432109876543210')
// Basic arithmetic
const sum = a.add(b)
const difference = a.subtract(b)
const product = a.multiply(b)
const quotient = a.divide(b)
console.log('Sum:', sum.toString())
console.log('Difference:', difference.toString())
console.log('Product:', product.toString())
console.log('Quotient:', quotient.toString())
// Modular arithmetic (useful for cryptography)
const modulus = new BigInteger('65537')
const exponent = new BigInteger('3')
const base = new BigInteger('42')
// Calculate (base^exponent) mod modulus
const modPowResult = base.modPow(exponent, modulus)
console.log('Modular exponentiation:', modPowResult.toString())
// Calculate modular inverse
const inverse = base.modInverse(modulus)
console.log('Modular inverse:', inverse.toString())
// Primality testing
const prime = new BigInteger('997')
console.log('Is prime:', prime.isProbablePrime(10) ? 'Yes' : 'No')
new BigInteger(value?: number | string | null, radix?: number, length?: number)
Creates a new BigInteger instance.
value: A number, string, or null to initialize the BigIntegerradix: The base of the number representation (default: 10)length: Used for specific initialization scenariosadd(a: BigInteger): BigInteger - Adds two BigIntegerssubtract(a: BigInteger): BigInteger - Subtracts one BigInteger from anothermultiply(a: BigInteger): BigInteger - Multiplies two BigIntegersdivide(a: BigInteger): BigInteger - Divides one BigInteger by anothermod(m: BigInteger): BigInteger - Returns this BigInteger modulo mmodPow(e: BigInteger, m: BigInteger): BigInteger - Calculates (this^e) mod mmodInverse(m: BigInteger): BigInteger - Calculates the modular multiplicative inversecompareTo(a: BigInteger): number - Compares two BigIntegersequals(a: BigInteger): boolean - Checks if two BigIntegers are equalshiftLeft(n: number): BigInteger - Shifts bits left by n positionsshiftRight(n: number): BigInteger - Shifts bits right by n positionstestBit(n: number): boolean - Tests if the nth bit is setgcd(a: BigInteger): BigInteger - Calculates the greatest common divisorisProbablePrime(t: number): boolean - Tests if this BigInteger is probably primetoString(radix?: number): string - Converts to string in the specified radixintValue(): number - Converts to a JavaScript numberPlease note the following limitations of the current implementation:
Negative numbers are partially supported:
The implementation is optimized for cryptographic use cases where negative numbers are less common
For comprehensive negative number support across all operations, additional refactoring would be beneficial
bun test
Please see our releases page for more information on what has changed recently.
Please review the Contributing Guide for details.
For help, discussion about best practices, or any other conversation that would benefit from being searchable:
For casual chit-chat with others using this package:
Join the Stacks Discord Server
"Software that is free, but hopes for a postcard." We love receiving postcards from around the world showing where ts-jsbn is being used! We showcase them on our website too.
Our address: Stacks.js, 12665 Village Ln #2306, Playa Vista, CA 90094, United States 🌎
We would like to extend our thanks to the following sponsors for funding Stacks development. If you are interested in becoming a sponsor, please reach out to us.
The MIT License (MIT). Please see LICENSE for more information.
Made with 💙
FAQs
A TypeScript implementation of the JSBN (JavaScript Big Number) library for arbitrary-precision integer arithmetic with a focus on cryptographic applications.
We found that ts-jsbn demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.