Skip to content

Commit

Permalink
feat: add expo support
Browse files Browse the repository at this point in the history
  • Loading branch information
numandev1 committed Sep 26, 2023
1 parent d6fb07d commit e8e9917
Show file tree
Hide file tree
Showing 113 changed files with 12,440 additions and 40 deletions.
108 changes: 100 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div align="center">
<h1 align="center">🔐 Undecryptable .ENVs variables</h1>
<img width="500" src="./media/keys.png">
</div>

<div align="center">
Expand All @@ -19,11 +19,8 @@
We should use **react-native-keys** instead of **react-native-config** because **react-native-keys** gives guarantee of undecryptable **envs** whereas **react-native-config** **envs** can be decompile and hack

**Note:** We highly recommend utilizing `third-party client-side API KEYS`, such as `Google Map` or `Branch.io`, in the secure section of this package.
#### See the [ Migration from react-native-config](docs/react-native-config-migration-guide.md)

<div align="center">
<img align="right" width="250" style="margin-right: 55px;" src="./media/key.png">
</div>
#### See the [ Migration from react-native-config](docs/react-native-config-migration-guide.md)

Making undecryptable **Envs** library for React Native.

Expand Down Expand Up @@ -62,6 +59,8 @@ We can Manage **secure**(undecryptable) and **public** enviroment through **reac
<summary>Open Table of Contents</summary>

- [Installation](#installation)
- [For React Native](#installation)
- [Managed Expo](#managed-expo)
- [Basic Usage](#basic-usage)
- [Javascript](#javascript)
- [Public Keys](#public-keys)
Expand Down Expand Up @@ -93,8 +92,100 @@ yarn add react-native-keys
```

##### [New Architecture (Turbo Module) Supported](https://reactnative.dev/docs/new-architecture-intro)

You can give feedback on [Discord channel](https://discord.gg/fgPHnZpH9d)

<h3>Managed Expo</h3>
<details>
<summary><b>Click here to Expand Managed Expo plugin Config</b></summary>

```
expo install react-native-keys
```

Add `keys.development.json`, `keys.staging.json` and `keys.production.json` at project root directory

Add the Keys plugin to your Expo config (`app.json`, `app.config.json` or `app.config.js`):

```json
{
"name": "my app",
"plugins": [
[
"react-native-keys",
{
"android": {
"defaultKeyFile": "keys.staging.json" //default: keys.development.json
},
"ios": {
"defaultKeyFile": "keys.staging.json" //default: keys.development.json
}
}
]
]
}
```

Finally, compile the mods:

```
expo prebuild
```

**Optional** If you wanna use different [Variants](https://docs.expo.dev/build-reference/variants/) then the you should write `eas.json` like this

```
{
"build": {
"development": {
"env": {
"APP_VARIANT": "development",
"KEYSFILE": "keys.development.json"
}
},
"staging": {
"env": {
"APP_VARIANT": "staging",
"KEYSFILE": "keys.staging.json"
}
},
"production": {
"env": {
"APP_VARIANT": "production",
"KEYSFILE": "keys.production.json"
}
}
},
"submit": {
"production": {}
}
}
```

To apply the changes, build a new binary with EAS:

```
eas build
```

use different [Variants](https://docs.expo.dev/build-reference/variants/) script into `package.json` like this

```
{
"scripts": {
"dev:android": "KEYSFILE=keys.development.json npx expo run:android",
"staging:android": "KEYSFILE=keys.staging.json npx expo run:android",
"prod:android": "KEYSFILE=keys.production.json npx expo run:android",
"dev:ios": "KEYSFILE=keys.development.json npx expo run:ios",
"staging:ios": "KEYSFILE=keys.staging.json npx expo run:ios",
"prod:ios": "KEYSFILE=keys.production.json npx expo run:ios"
}
}
```

</details>

## Basic Usage

Create a new file `keys.development.json` in the root of your React Native app and add Envs in `secure` object for `undecryptable` envs variables and add Envs in public for public usage this:
Expand Down Expand Up @@ -228,7 +319,6 @@ Alternatively, you can define a map in `Pre-actions` associating builds with env
"${SRCROOT}/../node_modules/react-native-keys/keysIOS.js"
```


### Android

- **Manual Link (Android)**
Expand Down Expand Up @@ -359,7 +449,7 @@ NSDictionary *allKeys = [Keys public_keys];
NSString *value = [Keys secureFor:@"BRANCH_KEY"]; //key_test_omQ7YYKiq57vOqEJsdcsdfeEsiWkwxE
```

call, and use build cases in lowercase, like:
call, and use build cases in lowercase, like:

### Different environments

Expand Down Expand Up @@ -453,10 +543,12 @@ If using Dexguard, the shrinking phase will remove resources it thinks are unuse
-keepresources string/build_config_package
### Using node with nvm, fnm or notion
Build failure in Xcode looks something like:
> env: node: No such file or directory
Change the **Pre-actions script** scripts in Xcode to:
Change the **Pre-actions script** scripts in Xcode to:
```
# Setup nvm and set node
Expand Down
6 changes: 6 additions & 0 deletions android/RNKeys.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ def loadKeys() {
if (System.env['KEYSFILE']) {
keysFile = System.env['KEYSFILE']
exportCommand = "export KEYSFILE=" + keysFile + " && ";
} else if (System.env['DEFAULT_FILE_NAME']) {
keysFile = System.env['DEFAULT_FILE_NAME']
exportCommand = "export KEYSFILE=" + keysFile + " && ";
} else if (project.hasProperty("DEFAULT_FILE_NAME")) {
keysFile = project.ext.DEFAULT_FILE_NAME
exportCommand = "export KEYSFILE=" + keysFile + " && ";
} else if (project.hasProperty("keyFiles")) {
project.ext.keyFiles.any { pair ->
if (flavor.startsWith(pair.key.toLowerCase())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
package com.reactnativekeysjsi;

public class PrivateKey {
public static String privatekey="pZoshfXIdCfwBqsc57d31atAUMf0lxCX5NWnCtWzHwFa4YazE8aHeQ009f8GiurSFBtjDNMSoog33YYHZtebu0+PrCTX8su4Y1df5FK1Rg==";
public static String privatekey="k0bymYdpGsZVFHIEEZVtzWgvGs0R6xxSgFN7wxkm/50HMLQZFQt55CR4VItVw6nrLfXATPXRxSiLHSDXvsvUupzfYPAodZsxx9VxlWBZ7g==";
}
1 change: 1 addition & 0 deletions app.plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('./plugin/build');
8 changes: 4 additions & 4 deletions cpp/crypto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
}

string Crypto::getJniJsonStringifyData(string key) {
std::string base64Secret1 = "U2FsdGVkX199+I364h5jWqyctRTxfs71VpO171cahBoWf4m/sExs57WYLzGBfHT7YviRpyAt";
std::string base64Secret2 = "s/Dk7rj1VsY7MvElsDbaLj4jhHT/y0EpT/wCSJw6NgZ3SIlM6eJKqvwDjRCZfMrBoPMwO3Aw";
std::string base64Secret3 = "pj8YZTX+0gzzQ4OhdLiZpOUa8iPTyjSbUwelLLqD2nWAXT+dWzbsAeN8inNXNaJKbFMSpg==";
std::string base64Secret1 = "U2FsdGVkX19lgRN4srwXt2D2LYi+baTRYsKl2mygm7ASNIWFynY+bxsDrbKAr2MZnI0flTXS";
std::string base64Secret2 = "DPWi+ilmqhX7RviqMInOjQ/dRUApNhJW3/Sqk0bymYdpGsZVFHIEEZVtzWgvGs0R6xxSgFN7";
std::string base64Secret3 = "wxkm/50HMLQZFQt55CR4VItVw6nrLfXATPXRxSiLHSDXvsvUupzfYPAodZsxx9VxlWBZ7g==";
std::string base64Secret = base64Secret1 + base64Secret2 + base64Secret3;
std::string password = "3seCzMfVxah8";
std::string password = "u4IxXxapI6zg";
bool binary = false;
std::string plaintext = decryptor::dec(base64Secret, password,binary);

Expand Down
2 changes: 1 addition & 1 deletion docs/workflow.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ we are using dynamic [Ciper](https://en.wikipedia.org/wiki/Cipher) for encoding
> It’s important to understand that no system is completely secure from attacks, even every wifi device or laptop password is also hackable, I made this for making a good security measurement for preventing 3rd party API key abuse, Good security measure is better than nothing to do
> Before using this package our 3rd party API key had a 99% hackable probability but after using this package hack probability will be 0.5%
as far as I know, we can abuse all types of 3rd parties unless that 3rd party uses
as far as I know, we can abuse all types of 3rd parties unless these 3rd party uses

- DeviceCheck or App Attest for IOS
- Play Integrity or SafetyNet for Android
Expand Down
8 changes: 4 additions & 4 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ PODS:
- React-jsinspector (0.72.3)
- React-logger (0.72.3):
- glog
- react-native-keys (0.5.9):
- react-native-keys (0.6.0):
- OpenSSL-Universal
- RCT-Folly (= 2021.07.22.00)
- React-Core
Expand Down Expand Up @@ -694,7 +694,7 @@ SPEC CHECKSUMS:
React-jsiexecutor: 59d1eb03af7d30b7d66589c410f13151271e8006
React-jsinspector: b511447170f561157547bc0bef3f169663860be7
React-logger: c5b527272d5f22eaa09bb3c3a690fee8f237ae95
react-native-keys: 593e083793a140f8151db432f0a781d497d5d155
react-native-keys: e9c8e5d5891896181ab692c5f3378d7e90e0bbdc
React-NativeModulesApple: c57f3efe0df288a6532b726ad2d0322a9bf38472
React-perflogger: 6bd153e776e6beed54c56b0847e1220a3ff92ba5
React-RCTActionSheet: c0b62af44e610e69d9a2049a682f5dba4e9dff17
Expand All @@ -716,6 +716,6 @@ SPEC CHECKSUMS:
Yoga: 8796b55dba14d7004f980b54bcc9833ee45b28ce
YogaKit: f782866e155069a2cca2517aafea43200b01fd5a

PODFILE CHECKSUM: 781a791ed65dc65c0001147158c0af034ef7c70e
PODFILE CHECKSUM: 713d4856e51f06c61696065aa31f30450735cea9

COCOAPODS: 1.11.3
COCOAPODS: 1.12.1
1 change: 1 addition & 0 deletions exampleExpo/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './src/App';
15 changes: 15 additions & 0 deletions exampleExpo/android/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# OSX
#
.DS_Store

# Android/IntelliJ
#
build/
.idea
.gradle
local.properties
*.iml
*.hprof

# Bundle artifacts
*.jsbundle
Loading

0 comments on commit e8e9917

Please sign in to comment.