|
1 | | -<a href="https://margelo.io"> |
2 | | - <img src="./docs/img/banner.svg" width="100%" /> |
3 | | -</a> |
| 1 | +npm module: https://www.npmjs.com/package/@coolwallet-app/react-native-quick-crypto |
4 | 2 |
|
5 | | -# ⚡️ react-native-quick-crypto |
| 3 | +# Install bun |
6 | 4 |
|
7 | | -A fast implementation of Node's `crypto` module. |
8 | | - |
9 | | -> Note: This version `0.x` is the Old Architecture, Bridged version for React Native. The `1.x` and higher branches are refactored to work with the New Architecture, Bridgeless, and [`Nitro Modules`](https://github.com/mrousavy/react-native-nitro). Status, as always, will be represented in [implementation-coverage.md](../0.x/docs/implementation-coverage.md). |
10 | | -
|
11 | | -## Features |
12 | | - |
13 | | -Unlike any other current JS-based polyfills, react-native-quick-crypto is written in C/C++ JSI and provides much greater performance - especially on mobile devices. |
14 | | -QuickCrypto can be used as a drop-in replacement for your Web3/Crypto apps to speed up common cryptography functions. |
15 | | - |
16 | | -- 🏎️ Up to 58x faster than all other solutions |
17 | | -- ⚡️ Lightning fast implementation with pure C++ and JSI, instead of JS |
18 | | -- 🧪 Well tested in JS and C++ (OpenSSL) |
19 | | -- 💰 Made for crypto apps and Wallets |
20 | | -- 🔢 Secure native compiled cryptography |
21 | | -- 🔁 Easy drop-in replacement for [crypto-browserify](https://github.com/browserify/crypto-browserify) or [react-native-crypto](https://github.com/tradle/react-native-crypto) |
22 | | - |
23 | | -## Versions |
24 | | - |
25 | | -| Version | RN Architecture | Modules | |
26 | | -| ------- | ------ | ------- | |
27 | | -| `0.x` (you are here) | old | Bridge & JSI | |
28 | | -| `1.x`+ | new [->](https://github.com/reactwg/react-native-new-architecture/blob/main/docs/enable-apps.md) | Nitro Modules [->](https://github.com/margelo/react-native-nitro) | |
29 | | - |
30 | | -## Benchmarks |
31 | | - |
32 | | -For example, creating a Wallet using ethers.js uses complex algorithms to generate a private-key/mnemonic-phrase pair: |
33 | | - |
34 | | -```ts |
35 | | -const start = performance.now(); |
36 | | -const wallet = ethers.Wallet.createRandom(); |
37 | | -const end = performance.now(); |
38 | | -console.log(`Creating a Wallet took ${end - start} ms.`); |
| 5 | +```bash |
| 6 | +brew install oven-sh/bun/ [email protected] |
| 7 | +bun --version |
39 | 8 | ``` |
40 | 9 |
|
41 | | -**Without** react-native-quick-crypto 🐢: |
| 10 | +# Bundle libs |
42 | 11 |
|
43 | | -``` |
44 | | -Creating a Wallet took 16862 ms |
| 12 | +```bash |
| 13 | +bun install |
45 | 14 | ``` |
46 | 15 |
|
47 | | -**With** react-native-quick-crypto ⚡️: |
| 16 | +# Publish |
48 | 17 |
|
| 18 | +```bash |
| 19 | +npm login |
| 20 | +bun release |
49 | 21 | ``` |
50 | | -Creating a Wallet took 289 ms |
51 | | -``` |
52 | | - |
53 | | ---- |
54 | | - |
55 | | -## Installation |
56 | | - |
57 | | -<h3> |
58 | | - React Native <a href="#"><img src="./docs/img/react-native.png" height="15" /></a> |
59 | | -</h3> |
60 | | - |
61 | | -```sh |
62 | | -yarn add react-native-quick-crypto |
63 | | -cd ios && pod install |
64 | | -``` |
65 | | - |
66 | | -<h3> |
67 | | - Expo <a href="#"><img src="./docs/img/expo.png" height="12" /></a> |
68 | | -</h3> |
69 | | - |
70 | | -```sh |
71 | | -expo install react-native-quick-crypto |
72 | | -expo prebuild |
73 | | -``` |
74 | | - |
75 | | -Optional: override `global.Buffer` and `global.crypto` in your application as early as possible for example in index.js. |
76 | | - |
77 | | -```ts |
78 | | -import { install } from 'react-native-quick-crypto'; |
79 | | - |
80 | | -install(); |
81 | | -``` |
82 | | - |
83 | | -## Replace `crypto-browserify` |
84 | | - |
85 | | -If you are using a library that depends on `crypto`, instead of polyfilling it with `crypto-browserify` (or `react-native-crypto`) you can use `react-native-quick-crypto` for a fully native implementation. This way you can get much faster crypto operations with just a single-line change! |
86 | | - |
87 | | -### Using metro config |
88 | | - |
89 | | -Use the [`resolveRequest`](https://facebook.github.io/metro/docs/resolution#resolverequest-customresolver) configuration option in your `metro.config.js` |
90 | | - |
91 | | -```js |
92 | | -config.resolver.resolveRequest = (context, moduleName, platform) => { |
93 | | - if (moduleName === 'crypto') { |
94 | | - // when importing crypto, resolve to react-native-quick-crypto |
95 | | - return context.resolveRequest( |
96 | | - context, |
97 | | - 'react-native-quick-crypto', |
98 | | - platform, |
99 | | - ) |
100 | | - } |
101 | | - // otherwise chain to the standard Metro resolver. |
102 | | - return context.resolveRequest(context, moduleName, platform) |
103 | | -} |
104 | | -``` |
105 | | - |
106 | | -### Using babel-plugin-module-resolver |
107 | | - |
108 | | -You need to install `babel-plugin-module-resolver`, it's a babel plugin that will alias any imports in the code with the values you pass to it. It tricks any module that will try to import certain dependencies with the native versions we require for React Native. |
109 | | - |
110 | | -```sh |
111 | | -yarn add --dev babel-plugin-module-resolver |
112 | | -``` |
113 | | - |
114 | | -Then, in your `babel.config.js`, add the plugin to swap the `crypto`, `stream` and `buffer` dependencies: |
115 | | - |
116 | | -```diff |
117 | | -module.exports = { |
118 | | - presets: ['module:metro-react-native-babel-preset'], |
119 | | - plugins: [ |
120 | | -+ [ |
121 | | -+ 'module-resolver', |
122 | | -+ { |
123 | | -+ alias: { |
124 | | -+ 'crypto': 'react-native-quick-crypto', |
125 | | -+ 'stream': 'readable-stream', |
126 | | -+ 'buffer': '@craftzdog/react-native-buffer', |
127 | | -+ }, |
128 | | -+ }, |
129 | | -+ ], |
130 | | - ... |
131 | | - ], |
132 | | -}; |
133 | | -``` |
134 | | - |
135 | | -Then restart your bundler using `yarn start --reset-cache`. |
136 | | - |
137 | | -## Usage |
138 | | - |
139 | | -For example, to hash a string with SHA256 you can do the following: |
140 | | - |
141 | | -```ts |
142 | | -import QuickCrypto from 'react-native-quick-crypto'; |
143 | | - |
144 | | -const hashed = QuickCrypto.createHash('sha256') |
145 | | - .update('Damn, Margelo writes hella good software!') |
146 | | - .digest('hex'); |
147 | | -``` |
148 | | - |
149 | | -## Limitations |
150 | | - |
151 | | -As the library uses JSI for synchronous native methods access, remote debugging (e.g. with Chrome) is no longer possible. Instead, you should use [Flipper](https://fbflipper.com). |
152 | | - |
153 | | -Not all cryptographic algorithms are supported yet. See the [implementation coverage](./docs/implementation-coverage.md) document for more details. If you need a specific algorithm, please open a `feature request` issue and we'll see what we can do. |
154 | | - |
155 | | -## Community Discord |
156 | | - |
157 | | -[Join the Margelo Community Discord](https://discord.gg/6CSHz2qAvA) to chat about react-native-quick-crypto or other Margelo libraries. |
158 | | - |
159 | | -## Adopting at scale |
160 | | - |
161 | | -react-native-quick-crypto was built at Margelo, an elite app development agency. For enterprise support or other business inquiries, contact us at < a href= "mailto:[email protected]?subject=Adopting react-native-quick-crypto at scale"> [email protected]</ a>! |
162 | | - |
163 | | -## Contributing |
164 | | - |
165 | | -See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow. |
166 | | - |
167 | | -## License |
168 | | - |
169 | | -- react-native-quick-crypto is licensed under MIT. |
170 | | -- react-native-quick-crypto is heavily inspired by NodeJS Crypto, which is licensed under [nodejs/LICENSE](https://github.com/nodejs/node/blob/main/LICENSE). |
0 commit comments