Home
Docs
GitHub
Pricing
Blog
Log In

Run Sandworm Audit for your App

Get started
Hold on, we're currently generating a fresh version of this report
Generated on May 10, 2024 via pnpm

bn.js 5.2.1

Big number implementation in pure javascript
Package summary
Share
0
issues
1
license
1
MIT
Package created
26 Apr 2014
Version published
24 May 2022
Maintainers
4
Total deps
1
Direct deps
0
License
MIT

Issues

0
This package has no issues

Licenses

MIT License

Permissive
OSI Approved
This is a human-readable summary of (and not a substitute for) the license. Disclaimer.
Can
commercial-use
modify
distribute
sublicense
private-use
Cannot
hold-liable
Must
include-copyright
include-license
1 Packages, Including:
bn.js@5.2.1
Disclaimer

This deed highlights only some of the key features and terms of the actual license. It is not a license and has no legal value. You should carefully review all of the terms and conditions of the actual license before using the licensed material.

Sandworm is not a law firm and does not provide legal services. Distributing, displaying, or linking to this deed or the license that it summarizes does not create a lawyer-client or any other relationship.

Direct Dependencies

0
All Dependencies CSV
β“˜ This is a list of bn.js 's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.
NameVersionSizeLicenseTypeVulnerabilities

Visualizations

Frequently Asked Questions

What does bn.js do?

The bn.js package provides a high-performance implementation of big numbers natively in JavaScript. This tool allows for processing large integers beyond JavaScript's default number precision limit, making it an essential utility for data-intensive applications or those requiring cryptographic operations, such as blockchain development. It's noteworthy that this library has specific optimization for elliptic curves working with 256-bit numbers, although it does not impose limitations on the number size. However, it's important to know that this library does not support decimals.

How do you use bn.js?

To use the bn.js package, you first need to install it using npm with the command npm install --save bn.js. After installation, you can import the package into your program with const BN = require('bn.js');. You can then create new big number instances by calling the BN constructor with a string representation of the number as the argument. For instance, var a = new BN('dead', 16); creates a new big number a with value 'dead' represented in base 16. The library provides a comprehensive set of methods for big number arithmetic, bitwise, and other operations. Here's an example of using the add method to perform addition:

const BN = require('bn.js');

var a = new BN('dead', 16);
var b = new BN('101010', 2);

var res = a.add(b);
console.log(res.toString(10));  // Output: 57047

This will add two big numbers a and b together. You can convert the result back to a string with the toString method, which takes in an optional base as a parameter (default is base 10).

For complex calculations, bn.js supports reduction operations like modulo with the aim to avoid overflow when dealing with large numbers. When doing a lot of reductions with the same modulo, it might be beneficial to use some tricks like Montgomery multiplication, or using a special algorithm for Mersenne Prime.

Where are the bn.js docs?

All the detailed documentation about the bn.js including its methods and features can be found directly on the GitHub repository. Reading through the readme file on the GitHub page will provide a deeper understanding of how it works and how to use it. The documentation is well-formatted and detailed, including nuances for several instructions, prefixes and postfixes used to affect how instructions work, and specific examples for better comprehension. This rich documentation certainly makes the library more user-friendly and accessible for developers.