react-native-yoga-jsi 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE CHANGED
@@ -1,27 +1 @@
1
- **react-native-yoga-jsi**
2
1
 
3
- MIT License
4
-
5
- Copyright (c) 2021 Margelo GmbH
6
-
7
- Permission is hereby granted, free of charge, to any person obtaining a copy
8
- of this software and associated documentation files (the "Software"), to deal
9
- in the Software without restriction, including without limitation the rights
10
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
- copies of the Software, and to permit persons to whom the Software is
12
- furnished to do so, subject to the following conditions:
13
-
14
- The above copyright notice and this permission notice shall be included in all
15
- copies or substantial portions of the Software.
16
-
17
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
- SOFTWARE.
24
-
25
- **NodeJS Crypto**
26
-
27
- See https://github.com/nodejs/node/blob/main/LICENSE
package/README.md CHANGED
@@ -1,166 +0,0 @@
1
- <a href="https://margelo.io">
2
- <img src="./docs/img/banner.svg" width="100%" />
3
- </a>
4
-
5
- # ⚡️ react-native-yoga-jsi
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-yoga-jsi 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-yoga-jsi 🐢:
42
-
43
- ```
44
- Creating a Wallet took 16862 ms
45
- ```
46
-
47
- **With** react-native-yoga-jsi ⚡️:
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-yoga-jsi
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-yoga-jsi
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-yoga-jsi';
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-yoga-jsi` 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-yoga-jsi
95
- return context.resolveRequest(context, 'react-native-yoga-jsi', platform);
96
- }
97
- // otherwise chain to the standard Metro resolver.
98
- return context.resolveRequest(context, moduleName, platform);
99
- };
100
- ```
101
-
102
- ### Using babel-plugin-module-resolver
103
-
104
- 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.
105
-
106
- ```sh
107
- yarn add --dev babel-plugin-module-resolver
108
- ```
109
-
110
- Then, in your `babel.config.js`, add the plugin to swap the `crypto`, `stream` and `buffer` dependencies:
111
-
112
- ```diff
113
- module.exports = {
114
- presets: ['module:metro-react-native-babel-preset'],
115
- plugins: [
116
- + [
117
- + 'module-resolver',
118
- + {
119
- + alias: {
120
- + 'crypto': 'react-native-yoga-jsi',
121
- + 'stream': 'readable-stream',
122
- + 'buffer': '@craftzdog/react-native-buffer',
123
- + },
124
- + },
125
- + ],
126
- ...
127
- ],
128
- };
129
- ```
130
-
131
- Then restart your bundler using `yarn start --reset-cache`.
132
-
133
- ## Usage
134
-
135
- For example, to hash a string with SHA256 you can do the following:
136
-
137
- ```ts
138
- import QuickCrypto from 'react-native-yoga-jsi';
139
-
140
- const hashed = QuickCrypto.createHash('sha256')
141
- .update('Damn, Margelo writes hella good software!')
142
- .digest('hex');
143
- ```
144
-
145
- ## Limitations
146
-
147
- 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).
148
-
149
- 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.
150
-
151
- ## Community Discord
152
-
153
- [Join the Margelo Community Discord](https://discord.gg/6CSHz2qAvA) to chat about react-native-yoga-jsi or other Margelo libraries.
154
-
155
- ## Adopting at scale
156
-
157
- react-native-yoga-jsi was built at Margelo, an elite app development agency. For enterprise support or other business inquiries, contact us at <a href="mailto:hello@margelo.io?subject=Adopting react-native-yoga-jsi at scale">hello@margelo.io</a>!
158
-
159
- ## Contributing
160
-
161
- See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.
162
-
163
- ## License
164
-
165
- - react-native-yoga-jsi is licensed under MIT.
166
- - react-native-yoga-jsi is heavily inspired by NodeJS Crypto, which is licensed under [nodejs/LICENSE](https://github.com/nodejs/node/blob/main/LICENSE).
@@ -53,7 +53,6 @@ target_link_libraries(
53
53
  ${LOG_LIB} # <-- Logcat logger
54
54
  ReactAndroid::jsi # <-- RN: JSI
55
55
  android # <-- Android JNI core
56
- openssl::crypto # <-- OpenSSL (Crypto)
57
56
  )
58
57
 
59
58
  # Conditionally link libraries based on ReactAndroid version
@@ -542,7 +542,7 @@ namespace nodeProperties
542
542
  INSTALL_HOST_FUN(setDirtiedFunc, 1, {
543
543
  auto dirtiedFunc = std::make_shared<Function>(arguments[0].asObject(runtime).asFunction(runtime));
544
544
 
545
- YGNodeSetDirtiedFunc(node, [](YGNodeRef node)
545
+ YGNodeSetDirtiedFunc(node, [](YGNodeConstRef node)
546
546
  {
547
547
  auto *context = static_cast<std::pair<std::shared_ptr<Function>, Runtime*> *>(YGNodeGetContext(node));
548
548
  if (!context)
@@ -564,7 +564,7 @@ namespace nodeProperties
564
564
  INSTALL_HOST_FUN(setMeasureFunc, 1, {
565
565
  auto measureFunc = std::make_shared<Function>(arguments[0].asObject(runtime).asFunction(runtime));
566
566
 
567
- YGNodeSetMeasureFunc(node, [](YGNodeRef node, float width, YGMeasureMode widthMode, float height, YGMeasureMode heightMode) -> YGSize
567
+ YGNodeSetMeasureFunc(node, [](YGNodeConstRef node, float width, YGMeasureMode widthMode, float height, YGMeasureMode heightMode) -> YGSize
568
568
  {
569
569
  auto *context = static_cast<std::pair<std::shared_ptr<Function>, Runtime*> *>(YGNodeGetContext(node));
570
570
  if (!context)
@@ -1,5 +1,5 @@
1
1
  #import <React/RCTBridgeModule.h>
2
2
 
3
- @interface QuickCryptoModule : NSObject <RCTBridgeModule>
3
+ @interface YogaJSIModule : NSObject <RCTBridgeModule>
4
4
 
5
5
  @end
@@ -7,7 +7,7 @@
7
7
  #import "../cpp/yogaJSI.h"
8
8
 
9
9
 
10
- @implementation QuickCryptoModule
10
+ @implementation YogaJSIModule
11
11
 
12
12
  @synthesize bridge=_bridge;
13
13
 
@@ -18,7 +18,7 @@ RCT_EXPORT_MODULE(YogaJSI)
18
18
  }
19
19
 
20
20
  RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(install) {
21
- NSLog(@"Installing JSI bindings for react-native-quick-crypto...");
21
+ NSLog(@"Installing JSI bindings for react-native-yoga-jsi...");
22
22
  RCTCxxBridge* cxxBridge = (RCTCxxBridge*)_bridge;
23
23
  if (cxxBridge == nil) {
24
24
  return @false;
@@ -33,7 +33,7 @@ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(install) {
33
33
 
34
34
  yogaJSI::install(*(facebook::jsi::Runtime *)jsiRuntime);
35
35
 
36
- NSLog(@"Successfully installed JSI bindings for react-native-quick-crypto!");
36
+ NSLog(@"Successfully installed JSI bindings for react-native-yoga-jsi!");
37
37
  return @true;
38
38
  }
39
39
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "react-native-yoga-jsi",
3
- "version": "0.0.2",
4
- "description": "A fast implementation of Node's `crypto` module written in C/C++ JSI",
3
+ "version": "0.0.3",
4
+ "description": "Using Yoga with JSI in React Native",
5
5
  "packageManager": "bun@1.1.26",
6
6
  "main": "lib/commonjs/index",
7
7
  "module": "lib/module/index",
@@ -44,7 +44,6 @@
44
44
  "ios",
45
45
  "android",
46
46
  "jsi",
47
- "crypto",
48
47
  "c++",
49
48
  "fast",
50
49
  "web3"
@@ -78,10 +77,9 @@
78
77
  "jest": "^29.7.0",
79
78
  "prettier": "3.3.3",
80
79
  "react": "^18.2.0",
81
- "react-native": "^0.72.7",
80
+ "react-native": "^0.73.0",
82
81
  "react-native-builder-bob": "0.30.2",
83
82
  "release-it": "^17.2.0",
84
- "sscrypto": "^1.1.1",
85
83
  "typescript": "5.6.3",
86
84
  "typescript-eslint": "8.9.0"
87
85
  },