Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/margelo/react-native-bignumber
๐ข The fastest Big Number library for React Native
https://github.com/margelo/react-native-bignumber
app big bignumber crypto cryptography jsi library math native number react react-native wallet
Last synced: 2 days ago
JSON representation
๐ข The fastest Big Number library for React Native
- Host: GitHub
- URL: https://github.com/margelo/react-native-bignumber
- Owner: margelo
- License: mit
- Created: 2022-03-03T08:52:46.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-04-29T10:12:49.000Z (7 months ago)
- Last Synced: 2024-10-30T00:10:07.591Z (14 days ago)
- Topics: app, big, bignumber, crypto, cryptography, jsi, library, math, native, number, react, react-native, wallet
- Language: JavaScript
- Homepage: https://margelo.io
- Size: 1.37 MB
- Stars: 344
- Watchers: 6
- Forks: 13
- Open Issues: 15
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# ๐ข react-native-bignumber
The fastest Big Number library for React Native.
* ๐๏ธ Up to 300x faster than all other solutions
* โก๏ธ Lightning fast implementation with pure C++ and JSI
* ๐งช Well tested in JS and C++ (OpenSSL)
* ๐ฐ Made for crypto apps and Wallets
* ๐ค Up to 5x smaller in JS-bundle size
* ๐ข Store numbers as big as your Phone's RAM can store
* ๐ Easy drop-in replacement for [BN.js](https://github.com/indutny/bn.js/)## Installation
React Native ย```sh
yarn add react-native-bignumber
cd ios && pod install
```
Expo ย```sh
expo install react-native-bignumber
expo prebuild
```## Usage
### ..as a normal library
The exposed `BN` class is used to create new BigNumber instances from strings (binary, hex, decimal), ArrayBuffers, Buffers, numbers, or other BigNumber instances.
```ts
import { BN } from 'react-native-bignumber'const a = new BN(3274556)
const b = new BN(9856712)
const c = a.mul(b) // 32.276.355.419.872
```Refer to [BN.js' documentation](https://github.com/indutny/bn.js/#instructions) for a full API reference and usage guide.
For example, this is how you calculate large Fibonacci numbers:
```ts
function fibonacci(n: number): BN {
let prev = new BN(0)
let prevPrev = new BN(1)
let number = new BN(1)for (let i = 1; i < n; i++) {
prevPrev = prev
prev = number
number = prevPrev.add(prev)
}return number
}const f = fibonacci(50) // 12.586.269.025
```### ..as a drop-in replacement
Since popular libraries like [ethers.js](https://github.com/ethers-io/ethers.js/) or [elliptic](https://github.com/indutny/elliptic) use [BN.js](https://github.com/indutny/bn.js/) under the hood, react-native-bignumber exposes exactly the same API as [BN.js](https://github.com/indutny/bn.js/) so it can be used as a drop-in replacement and promises much greater speed at common crypto operations.
In your `babel.config.js`, add a module resolver to replace `bn.js` with `react-native-bignumber`:
```diff
+const path = require('path');module.exports = {
presets: ['module:metro-react-native-babel-preset'],
plugins: [
+ [
+ 'module-resolver',
+ {
+ alias: {
+ 'bn.js': 'react-native-bignumber',
+ },
+ },
+ ],
...
],
};
```Now, all imports for `bn.js` will be resolved as `react-native-bignumber` instead.
In the Exodus app, this single line change reduced app launch time by **4 seconds**! ๐
## Community Discord
[Join the Margelo Community Discord](https://discord.gg/6CSHz2qAvA) to chat about react-native-bignumber or other Margelo libraries.
## Sponsors
This library is supported by [**Exodus**](https://exodus.com).
Send, receive, and exchange Bitcoin and 160+ cryptocurrencies with ease on the world's leading Desktop, Mobile and Hardware crypto wallets: [exodus.com](https://www.exodus.com/)## Adopting at scale
react-native-bignumber was built at Margelo, an elite app development agency. For enterprise support or other business inquiries, contact us at [email protected]!