Skip to content

Commit 842db4c

Browse files
authored
Merge pull request #5 from CoolBitX-Technology/release/0.7.15
🔖 release: 0.7.15
2 parents 0f315f3 + 0034c34 commit 842db4c

File tree

7 files changed

+196
-174
lines changed

7 files changed

+196
-174
lines changed

README-forked.md

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
<a href="https://margelo.io">
2+
<img src="./docs/img/banner.svg" width="100%" />
3+
</a>
4+
5+
# ⚡️ react-native-quick-crypto
6+
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.`);
39+
```
40+
41+
**Without** react-native-quick-crypto 🐢:
42+
43+
```
44+
Creating a Wallet took 16862 ms
45+
```
46+
47+
**With** react-native-quick-crypto ⚡️:
48+
49+
```
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).

README.md

Lines changed: 12 additions & 161 deletions
Original file line numberDiff line numberDiff line change
@@ -1,170 +1,21 @@
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
42

5-
# ⚡️ react-native-quick-crypto
3+
# Install bun
64

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
398
```
409

41-
**Without** react-native-quick-crypto 🐢:
10+
# Bundle libs
4211

43-
```
44-
Creating a Wallet took 16862 ms
12+
```bash
13+
bun install
4514
```
4615

47-
**With** react-native-quick-crypto ⚡️:
16+
# Publish
4817

18+
```bash
19+
npm login
20+
bun release
4921
```
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).

bun.lockb

-8 Bytes
Binary file not shown.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "0.7.13",
2+
"version": "0.7.14",
33
"scripts": {
44
"clean": "bun --filter='*' clean",
55
"deepclean": "bun --filter='*' deepclean && del-cli node_modules",

packages/example/ios/Podfile.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ PODS:
323323
- react-native-quick-base64 (2.1.2):
324324
- RCT-Folly (= 2021.07.22.00)
325325
- React-Core
326-
- react-native-quick-crypto (0.7.13):
326+
- react-native-quick-crypto (0.7.15):
327327
- OpenSSL-Universal
328328
- RCT-Folly (= 2021.07.22.00)
329329
- React
@@ -496,7 +496,7 @@ DEPENDENCIES:
496496
- React-utils (from `../../../node_modules/react-native/ReactCommon/react/utils`)
497497
- ReactCommon/turbomodule/core (from `../../../node_modules/react-native/ReactCommon`)
498498
- "RNCCheckbox (from `../../../node_modules/@react-native-community/checkbox`)"
499-
- RNScreens (from `../node_modules/react-native-screens`)
499+
- RNScreens (from `../../../node_modules/react-native-screens`)
500500
- Yoga (from `../../../node_modules/react-native/ReactCommon/yoga`)
501501

502502
SPEC REPOS:
@@ -596,7 +596,7 @@ EXTERNAL SOURCES:
596596
RNCCheckbox:
597597
:path: "../../../node_modules/@react-native-community/checkbox"
598598
RNScreens:
599-
:path: "../node_modules/react-native-screens"
599+
:path: "../../../node_modules/react-native-screens"
600600
Yoga:
601601
:path: "../../../node_modules/react-native/ReactCommon/yoga"
602602

@@ -628,7 +628,7 @@ SPEC CHECKSUMS:
628628
React-logger: 8edc785c47c8686c7962199a307015e2ce9a0e4f
629629
react-native-fast-encoder: 6f59e9b08e2bc5a8bf1f36e1630cdcfd66dd18af
630630
react-native-quick-base64: 61228d753294ae643294a75fece8e0e80b7558a6
631-
react-native-quick-crypto: 64ea90b3b85d47e6cdcd6c357eb1a48b6cb13498
631+
react-native-quick-crypto: 0e6636e4a9ae327d710d3eee75f1c105584636bd
632632
react-native-safe-area-context: 141eca0fd4e4191288dfc8b96a7c7e1c2983447a
633633
React-NativeModulesApple: b6868ee904013a7923128892ee4a032498a1024a
634634
React-perflogger: 31ea61077185eb1428baf60c0db6e2886f141a5a

0 commit comments

Comments
 (0)