Giter Site home page Giter Site logo

numandev1 / react-native-keys Goto Github PK

View Code? Open in Web Editor NEW
266.0 8.0 18.0 3.7 MB

πŸ” Protected .ENVs variables in React Native πŸš€βœ¨

License: MIT License

CMake 0.20% C++ 91.64% Groovy 0.54% Java 2.09% JavaScript 1.65% TypeScript 1.10% Objective-C 0.56% Ruby 0.72% Objective-C++ 1.46% C 0.01% Swift 0.01%
react-native secure jni keys jni-android jni-ios config env environment environment-variables

react-native-keys's Introduction

GitHub Repo stars GitHub Repo stars GitHub Repo stars GitHub Repo stars npm

REACT-NATIVE-KEYS is a react-native package, which helps us to protect our ENVs and manage different environments like dev, staging, production

Why should we use react-native-keys over react-native-config?

We should use react-native-keys instead of react-native-config because react-native-keys gives guarantee of protected 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.

Making protected Envs library for React Native.

  • πŸ” Made for protected ENVs on react native apps
  • πŸ—„οΈ Manage different enviroments (dev, staging, production)
  • 🏎️ Up to 200x faster than all other solutions
  • ⚑️ Lightning fast implementation with pure C++ and JSI instead of the "old" Bridge
  • πŸ§ͺ Well tested in JS and C++

We can Manage secure(protected) and public enviroment through react-native-keys supporting iOS and Android

secure: Secure environment variables with the highest encryption which are protected

public: Public environment variables are stored on the native side like Java and Objective-C which can decompile or hack. Note: in public, we mostly store Bundle Id, Package Id, App Name or any other AndroidManifest.xml env

Would you like to support me?

Table of Contents

Open Table of Contents

Installation

yarn add react-native-keys

You can give feedback on Discord channel

Managed Expo

Click here to Expand Managed Expo plugin Config
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):

{
  "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 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 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"
  }
}

Basic Usage

Create a new file keys.development.json in the root of your React Native app and add Envs in secure object for protected envs variables and add Envs in public for public usage this:

{
  "secure": {
    "GOOGLE_API": "ABCD",
    "BRANCH_API": "ABCDEF"
  },
  "public": {
    "APP_NAME": "Keys Example",
    "BUNDLE_ID": "com.example.rnkeys.dev",
    "ANDROID_CODE": "50",
    "PACKAGE_ID": "com.example.rnkeys.dev"
  }
}

Note: Dont forgot to follow other steps for Android and IOS to use these keys

later on you can define other enviroment files like keys.staging.json and keys.production.json

Javascript

Public Keys

import Keys from 'react-native-keys';

Keys.API_URL; // https://example.com'
Keys.URI_SCHEME; // fb://

Secure Keys

import Keys from 'react-native-keys';

Keys.secureFor('API_TOKEN'); // 'ABCSE#$DDSD
Keys.secureFor('GOOGLE_API_KEY'); // 'ABCSE#$DDSD
Keys.secureFor('SECRET_KEY'); // 'ABCSE#$DDSD

Keep in mind It's basically impossible to prevent users from reverse engineering mobile app secrets but this library is more secure.

Setup

Install the package:

yarn add react-native-keys

Link the library:

(Note: For React Native 0.60 or greater, autolinking is available)

or later. For earlier versions you need to manually link the module.)

react-native link react-native-keys

IOS

if cocoapods are used in the project then pod has to be installed as well:

(cd ios; pod install)

Note: If you get Undefined symbols _BIO_f_base64 error during Xcode build then follow the below stackoverflow solution

Solution: StackOverFlow

  • Manual Link (iOS)

    1. In XCode, in the project navigator, right click Libraries ➜ Add Files to [your project's name]
    2. Go to node_modules ➜ react-native-keys and add Keys.xcodeproj
    3. Expand the Keys.xcodeproj ➜ Products folder
    4. In the project navigator, select your project. Add Keys.a to your project's Build Phases ➜ Link Binary With Libraries
    5. And go the Build Settings tab. Make sure All is toggled on (instead of Basic)
    6. Look for Header Search Paths and add $(SRCROOT)/../node_modules/react-native-keys/ios/** as non-recursive
  • Mandatory Step

With one extra step environment values can be exposed to "Info.plist" and Build settings in the native project.

  1. click on the file tree and create new file of type XCConfig img img

  2. save it under ios folder as "Config.xcconfig" with the following content:

    #include? "tmp.xcconfig"
    
  3. add the following to your ".gitignore":

ios/tmp.xcconfig
  1. go to project settings

  2. apply config to your configurations img

  3. Go to Edit scheme... -> Build -> Pre-actions, click + and select New Run Script Action. Paste below code which will generate "tmp.xcconfig" before each build exposing values to Build Settings and Info.plist. Make sure to select your target under Provide build settings from and Shared checkbox is ticked/enabled, so $SRCROOT environment variables is available to the script..

    "${SRCROOT}/../node_modules/react-native-keys/keysIOS.js"
    

    if you face env: node: No such file or directory issue due to Nvm, Fnm or notion please follow this guide

img

  1. You can now access your env variables in the Info.plist, for example $(MY_ENV_VARIABLE). If you face issues accessing variables, please open a new issue and provide as much details as possible so above steps can be improved.
  • Go to Edit scheme... -> Build -> Pre-actions, click + and select New Run Script Action. Paste below code which will generate KEYS keys on native ios side (into nodemodules) Make sure to select your target under _Provide build settings from, so $SRCROOT environment variables is available to the script.
export KEYSFILE=keys.development.json

"${SRCROOT}/../node_modules/react-native-keys/keysIOS.js"

Alternatively, you can define a map in Pre-actions associating builds with env files:

    export KEYSFILE = "path_to_env"
   "${SRCROOT}/../node_modules/react-native-keys/keysIOS.js"

Android

  • Manual Link (Android)

    android/settings.gradle

    + include ':react-native-keys'
    + project(':react-native-keys').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-keys/android')

    android/app/build.gradle

    dependencies {
     implementation "com.facebook.react:react-native:+"  // From node_modules
    + implementation project(':react-native-keys')
    }

    MainApplication.java

    + import com.reactnativekeysjsi.KeysPackage;
    
    @Override
    protected List<ReactPackage> getPackages() {
        return Arrays.asList(
              new MainReactPackage()
    +        new KeysPackage()
        );
    }
  • Mandatory Step

app/build.gradle

you can define a map in build.gradle associating builds with env files. Do it before the apply from call, and use build cases in lowercase, like:

project.ext.keyFiles = [
  debug: "keys.development.json",
  release: "keys.staging.json",
]

apply from: project(':react-native-keys').projectDir.getPath() + "/RNKeys.gradle"

Native Usage

Android

Public Keys

you can only read jni key into java file.like this

URL url = new URL(BuildConfig.API_URL);  // https://example.com

You can also read them from your Gradle configuration(only public keys):

defaultConfig {
    applicationId project.keys.get("APP_ID")
}

And use them to configure libraries in AndroidManifest.xml and others:

<meta-data
  android:name="io.branch.sdk.BranchKey.test"
  android:value="@string/BRANCH_KEY" />

All variables are strings, so you may need to cast them. For instance, in Gradle:

versionCode project.keys.get("VERSION_CODE").toInteger()

Advanced Android Setup

In android/app/build.gradle, if you use applicationIdSuffix or applicationId that is different from the package name indicated in AndroidManifest.xml in <manifest package="..."> tag, for example, to support different build variants: Add this in android/app/build.gradle

defaultConfig {
    ...
    resValue "string", "build_config_package", "YOUR_PACKAGE_NAME_IN_ANDROIDMANIFEST_XML_OR_YOUR_NAME_SPACE"
}

Secure Keys (JNI)

import static com.reactnativekeysjsi.KeysModule.getSecureFor;

String secureValue = getSecureFor("BRANCH_KEY");   // key_test_omQ7YYKiq57vOqEJsdcsdfeEsiWkwxE

Android troubleshoot

iOS

Public Keys

Read variables declared in keys.development.json from your Obj-C classes like:

// import header
#import "Keys.h"

// then read individual keys like:
NSString *value = [Keys publicFor:@"API_URL"];   // https://example.com

// or just fetch all keys
NSDictionary *allKeys = [Keys public_keys];

Secure Keys

// import header
#import "Keys.h"

// then read individual keys like:
NSString *value = [Keys secureFor:@"BRANCH_KEY"];   //key_test_omQ7YYKiq57vOqEJsdcsdfeEsiWkwxE

call, and use build cases in lowercase, like:

Different environments

Save config for different environments in different files: keys.staging.json, keys.production.json, etc.

By default react-native-keys will read from keys.development.json, but you can change it when building or releasing your app.

The simplest approach is to tell it what file to read with an environment variable, like:

KEYSFILE=keys.staging.json react-native run-ios           # bash
SET KEYSFILE=keys.staging.json && react-native run-ios    # windows
env:KEYSFILE="keys.staging.json"; react-native run-ios    # powershell

This also works for run-android. Alternatively, there are platform-specific options below.

Android

The same environment variable can be used to assemble releases with a different config:

cd android && KEYSFILE=keys.staging.json ./gradlew assembleRelease

Advanced Android Setup

In android/app/build.gradle, if you use applicationIdSuffix or applicationId that is different from the package name indicated in AndroidManifest.xml in <manifest package="..."> tag, for example, to support different build variants: Add this in android/app/build.gradle

defaultConfig {
    ...
    resValue "string", "build_config_package", "YOUR_PACKAGE_NAME_IN_ANDROIDMANIFEST_XML"
}

if you are using Proguard then you should read Problems with Proguard

iOS

The basic idea in iOS is to have one scheme per environment file, so you can easily alternate between them.

Start by creating a new scheme:

  • In the Xcode menu, go to Product > Scheme > Edit Scheme
  • Click Duplicate Scheme on the bottom
  • Give it a proper name on the top left. For instance: "Myapp (staging)"

Then edit the newly created scheme to make it use a different env file. From the same "manage scheme" window:

  • Expand the "Build" settings on left
  • Click "Pre-actions", and under the plus sign select "New Run Script Action"
  • Where it says "Type a script or drag a script file", type:

you can also set different file for debug and release build like this.

#DEBUG_KEYSFILE will choose env file
export KEYSFILE=keys.production.json

#if you wannna use different keys for same scheme
export DEBUG_KEYSFILE=keys.debug.json  # in running metro
export RELEASE_KEYSFILE=keys.staging.json  # in IPA

#above DEBUG_KEYSFILE and RELEASE_KEYSFILE variable are optional

"${SRCROOT}/../node_modules/react-native-keys/keysIOS.js"

Also ensure that "Provide build settings from", just above the script, has a value selected so that PROJECT_DIR is set.

Test Security

you can decompile APK/IPA by this package react-native-decompiler and can find public and secure keys. you will not find secure keys.

Troubleshooting

Problems with Proguard

When Proguard is enabled (which it is by default for Android release builds), it can rename the BuildConfig Java class in the minification process and prevent React Native Keys from referencing it. To avoid this, add an exception to android/app/proguard-rules.pro:

-keep class com.mypackage.BuildConfig { *; }

com.mypackage should match the package value in your app/src/main/AndroidManifest.xml file.

we can find BuildConfig file at android/app/build/generated/source/buildConfig/debug/com.mypackage/BuildConfig.java

If using Dexguard, the shrinking phase will remove resources it thinks are unused. It is necessary to add an exception to preserve the build config package name.

-keepresources string/build_config_package

2 files found with path '**/libcrypto.so

if you face 2 files found with path '**/libcrypto.so' then inside android/app/build.gradle just add this:

android {
...
packagingOptions {
        pickFirst 'lib/x86/libcrypto.so'
        pickFirst 'lib/x86_64/libcrypto.so'
        pickFirst 'lib/armeabi-v7a/libcrypto.so'
        pickFirst 'lib/arm64-v8a/libcrypto.so'
    }
}

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:

# Setup nvm and set node

[ -z "$NVM_DIR" ] && export NVM_DIR="$HOME/.nvm"

if [[-s "$HOME/.nvm/nvm.sh"]]; then
. "$HOME/.nvm/nvm.sh"
elif [[ -x "$(command -v brew)" && -s "$(brew --prefix nvm)/nvm.sh" ]]; then
. "$(brew --prefix nvm)/nvm.sh"
fi

# Set up the nodenv node version manager if present

if [[-x "$HOME/.nodenv/bin/nodenv"]]; then
eval "$("$HOME/.nodenv/bin/nodenv" init -)"
fi

# Set up the fnm node version manager if present

if [[-s "$HOME/.fnm/fnm"]]; then
eval "`$HOME/.fnm/fnm env --multi`"
fi

# Trying notion

if [ -z "$NODE_BINARY" ]; then
if [[-s "$HOME/.notion/bin/node"]]; then
export NODE_BINARY="$HOME/.notion/bin/node"
fi
fi

[ -z "$NODE_BINARY" ] && export NODE_BINARY="node"

$NODE_BINARY "${SRCROOT}/../node_modules/react-native-keys/keysIOS.js"

Alternative Package

This package full alternative of react-native-config and react-native-dotenv

The above-mentioned packages do not provide any security for environment variables as well as these packages are not as fast as the react-native-keys package because it does not use JSI (JavaScript Interface).

Consider supporting with a ⭐️ star on GitHub

If you are using the library in one of your projects, consider supporting it with a star. It takes a lot of time and effort to keep this maintained and address issues and bugs. Thank you.

react-native-keys's People

Contributors

awaisibrar8 avatar ddikodroid avatar efstathiosntonas avatar gh-action-bump-version avatar irekrog avatar ngocle2497 avatar numandev1 avatar talaikis avatar wolfant avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-native-keys's Issues

Not working on iOS

Hi,

I was able to add the lib to my project and make it work on Android.

On iOS I don't have any errors but I can't see the secure/public keys from my keys.json file. What I can see is the keys that you added by default on the generatedDotEnvFile.

My logfile inclues: env: node: No such file or directory

Is anyone aware of what this issue is or the route cause ? I can't find a solution for it. I did follow all the spects on README but I can't make it work.

Thanks!

Cannot build iOS

Current behavior

Run pre-actions
Build | Scheme MyProject
Run custom shell script 
SchemeAction Run\ Script /var/folders/qp/ygqy3bwj78v_8vp2nhfs_2hh0000gn/T/SchemeScriptAction-SDT73q.sh
    cd /var/folders/qp/ygqy3bwj78v_8vp2nhfs_2hh0000gn/T/
...
env: node: No such file or directory

Expected behavior

Should work fine

Platform

  • iOS

React Native Version

0.71.7

React Native Compressor Version

Reproducible Steps And Demo

cmake error on Android Build

Hi, I hope your doing well,
I added react-native-keys to my project everything works find in ios, but for android I can't build the project and I've got this error

Execution failed for task ':react-native-keys:generateJsonModelDebug'
executing external native build for cmake ..../node_modules/react-native/keys/android/CMakeLists.txt


React-native version 0.63
classpath("com.android.tools.build:gradle:4.1.3")
gradle-wrapper: dradle-7.3.3-all.zip

Release build not work with iOS simulator

Current behavior

Release build not work with iOS simulator

below build error occurred

Undefined symbol: _BIO_f_base64
Undefined symbol: _BIO_free_all
...

because react-native-keys use OpenSSL-Universal
It can be avoid to make OpenSSL.xcframework into dynamic framework (via using Frameworks, Libraries, and Embedded Content option)
but I'm not sure this is best solution

Expected behavior

Release build work properly with iOS simulator

Platform

  • Android
  • iOS

React Native Version

React Native Compressor Version

Reproducible Steps And Demo

[Docs issue] Please add Proguard(or Dexguard) troubleshooting comment

Current behavior

I get an error when using Proguard, but there is no guide in the documentation about it.

Platform

  • Android
  • iOS

Expected behavior

I would you like to add below οΏ½comment related to Proguard

Troubleshooting

Problems with Proguard

When Proguard is enabled (which it is by default for Android release builds), it can rename the BuildConfig Java class in the minification process and prevent React Native Config from referencing it. To avoid this, add an exception to android/app/proguard-rules.pro:

-keep class com.mypackage.BuildConfig { *; }

com.mypackage should match the package value in your app/src/main/AndroidManifest.xml file.

If using Dexguard, the shrinking phase will remove resources it thinks are unused. It is necessary to add an exception to preserve the build config package name.

-keepresources string/build_config_package

(above comment from react-native-config's ReadMe)

DEFAULT_FILE_NAME disturbs some Gradle task when use with alternative use case

Current behavior

Hi,
we use this library with below config

project.ext.keyFiles = [
    debug: "keys.dev.json",
    staging: "keys.stage.json",
    release: "keys.prod.json",
]

but above config makes gradle task(like ./gradlew clean) failing
because we can't custom DEFAULT_FILE_NAME value(keys.development.json) within your lib and clean task doesn't recognize our gradle config value
(only solution is patching DEFAULT_FILE_NAME value)

Expected behavior

Gradle tasks are work well

Platform

  • Android
  • iOS

React Native Version

any version

React Native Compressor Version

Reproducible Steps And Demo

IOS Xcode 15 archive failed

Current behavior

Archive failed when use xcode 15

Expected behavior

Platform

  • iOS

React Native Version

0.72.2
Undefined symbols for architecture arm64:
"_BIO_f_base64", referenced from:
decryptor::base64_decode(std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator> const&) in libreact-native-keys.a(decryptor.o)
"_BIO_free_all", referenced from:
decryptor::base64_decode(std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator> const&) in libreact-native-keys.a(decryptor.o)
"_BIO_new", referenced from:
decryptor::base64_decode(std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator> const&) in libreact-native-keys.a(decryptor.o)
"_BIO_new_mem_buf", referenced from:
decryptor::base64_decode(std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator> const&) in libreact-native-keys.a(decryptor.o)
"_BIO_push", referenced from:
decryptor::base64_decode(std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator> const&) in libreact-native-keys.a(decryptor.o)
"_BIO_read", referenced from:
decryptor::base64_decode(std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator> const&) in libreact-native-keys.a(decryptor.o)
"_BIO_set_flags", referenced from:
decryptor::base64_decode(std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator> const&) in libreact-native-keys.a(decryptor.o)
"_EVP_BytesToKey", referenced from:
decryptor::openSSLKey(std::__1::vector<unsigned char, std::__1::allocator> const&, std::__1::vector<unsigned char, std::__1::allocator> const&) in libreact-native-keys.a(decryptor.o)
"_EVP_CIPHER_CTX_free", referenced from:
decryptor::rawDecrypt(std::__1::vector<unsigned char, std::__1::allocator> const&, std::__1::vector<unsigned char, std::__1::allocator> const&, std::__1::vector<unsigned char, std::__1::allocator> const&) in libreact-native-keys.a(decryptor.o)
"_EVP_CIPHER_CTX_new", referenced from:
decryptor::rawDecrypt(std::__1::vector<unsigned char, std::__1::allocator> const&, std::__1::vector<unsigned char, std::__1::allocator> const&, std::__1::vector<unsigned char, std::__1::allocator> const&) in libreact-native-keys.a(decryptor.o)
"_EVP_CIPHER_iv_length", referenced from:
decryptor::openSSLKey(std::__1::vector<unsigned char, std::__1::allocator> const&, std::__1::vector<unsigned char, std::__1::allocator> const&) in libreact-native-keys.a(decryptor.o)
"_EVP_CIPHER_key_length", referenced from:
decryptor::openSSLKey(std::__1::vector<unsigned char, std::__1::allocator> const&, std::__1::vector<unsigned char, std::__1::allocator> const&) in libreact-native-keys.a(decryptor.o)
"_EVP_DecryptFinal_ex", referenced from:
decryptor::rawDecrypt(std::__1::vector<unsigned char, std::__1::allocator> const&, std::__1::vector<unsigned char, std::__1::allocator> const&, std::__1::vector<unsigned char, std::__1::allocator> const&) in libreact-native-keys.a(decryptor.o)
"_EVP_DecryptInit_ex", referenced from:
decryptor::rawDecrypt(std::__1::vector<unsigned char, std::__1::allocator> const&, std::__1::vector<unsigned char, std::__1::allocator> const&, std::__1::vector<unsigned char, std::__1::allocator> const&) in libreact-native-keys.a(decryptor.o)
"_EVP_DecryptUpdate", referenced from:
decryptor::rawDecrypt(std::__1::vector<unsigned char, std::__1::allocator> const&, std::__1::vector<unsigned char, std::__1::allocator> const&, std::__1::vector<unsigned char, std::__1::allocator> const&) in libreact-native-keys.a(decryptor.o)
"_EVP_aes_256_cbc", referenced from:
decryptor::rawDecrypt(std::__1::vector<unsigned char, std::__1::allocator> const&, std::__1::vector<unsigned char, std::__1::allocator> const&, std::__1::vector<unsigned char, std::__1::allocator> const&) in libreact-native-keys.a(decryptor.o)
"_EVP_get_cipherbyname", referenced from:
decryptor::openSSLKey(std::__1::vector<unsigned char, std::__1::allocator> const&, std::__1::vector<unsigned char, std::__1::allocator> const&) in libreact-native-keys.a(decryptor.o)
"_EVP_md5", referenced from:
decryptor::openSSLKey(std::__1::vector<unsigned char, std::__1::allocator> const&, std::__1::vector<unsigned char, std::__1::allocator> const&) in libreact-native-keys.a(decryptor.o)
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

[Proposal] JSON integrate

When we use react-native-keys, we need to add multiple JSON files for multiple build variants. and this approach is similar to using Dotenv. with JSON, however, we can handle multiple builds in a single file.

It also has the advantage of having a single set of common keys, which prevents the human error of managing multiple JSONs.

So I propose some schemas.

Sample1
  • react-native-keys.json
{
  "__common__": { // reserved key (optional)
    "secure": {
      "KEY1": "hi",
      "KEY2": "hi",
    },
    "public": {
      "KEY1": "hi",
      "KEY2": "hi",
    },
  },
  "development": {
    "secure": {
      "KEY1" : "bye" // overwrite
      "KEY3" : "new key"
    },
    "public": {
      ...
    },
  },
  "production": { // key could be customizable
    "secure": {
      ...
    },
    "public": {
      ...
    },
  },
}

or
Sample2
  • react-native-keys.json
{
  "secure": {
    "__common__": { // reserved key (optional)
      "KEY1": "hi",
      "KEY2": "hi",
    },
    "development": { // key could be customizable
      "KEY1": "bye", // overwrite
      "KEY3": "new key",
    },
    "production": { // key could be customizable
      "KEY3": "new key",
      "KEY4": "new key",
    }
  },
  "public": {
    "__common": {
      ...
    },
    "development": {
      ...
    },
    "production": {
      ...
    }
  }
}

I'd be grateful if you could consider it.

Fails to build on ANdroid

Current behavior

When trying to build on Android, it's giving the error:

Execution failed for task ':app:mergeDebugNativeLibs'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.MergeNativeLibsTask$MergeNativeLibsTaskWorkAction > 2 files found with path 'lib/arm64-v8a/libcrypto.so' from inputs: - /Users/justintoth/Dev/m365-mobile-app/node_modules/react-native-keys/android/build/intermediates/library_jni/debug/jni/arm64-v8a/libcrypto.so - /Users/justintoth/.gradle/caches/transforms-3/21df3bd3ae107d2ee802eb869f41fec9/transformed/jetified-flipper-0.182.0/jni/arm64-v8a/libcrypto.so If you are using jniLibs and CMake IMPORTED targets, see https://developer.android.com/r/tools/jniLibs-vs-imported-targets 

Expected behavior

It should build properly.

Platform

  • Android
  • [] iOS

React Native Version

0.72.1

Cannot run in DEBUG mode in IOS & android

Current behavior

The application ran successfully without debug mode but when we ran debug mode we got the error "Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication). A frequent cause of the error is that the application entry file path is incorrect."
Simulator Screenshot - iPhone 15 Pro Max - 2024-01-22 at 15 37 40

Expected behavior

Platform

  • [βœ“] Android
  • [βœ“] iOS

React Native Version

React: 17.0.2
React Native: 0.66.3

React Native Compressor Version

Reproducible Steps And Demo

[fix] crash in release mode (Android, proguard off)

Current behavior

Working fine in debug mode, On release crashes the app upon opening without errors.

Expected behavior

Working release build.

Platform

  • Android
  • [] iOS

React Native Version

0.72.6

React Native Compressor Version

Reproducible Steps And Demo

  1. import 'react-native-keys'
  2. Builld budnle or apk
  3. Install on physical device or emulator
  4. Open app

Keys not working on iOS

Current behavior

Installed the package, did pod install, created keys.development.json file with secure entries:

{ "secure": { "APP_URL": "website-url.com", } }

but I can't access them, they return empty when I do console.log('keys', Keys.secureFor('APP_URL'))

Expected behavior

console.log('keys 2', Keys.secureFor('APP_URL')) should return the expected data in secure: { "APP_URL": "url"}

Platform

  • iOS

Versions

React Native Version -> 0.71.11
React Native Keys -> 0.5.14

Cannot add task 'callCL' as a task with that name already exists

Followed the readme instruction but getting below error while building

1: Task failed with an exception.
-----------
* Where:
Script '/Users/deepakverma/work/zepton-app/node_modules/react-native-keys/android/RNKeys.gradle' line: 92

* What went wrong:
A problem occurred evaluating script.
> Cannot add task 'callCL' as a task with that name already exists.

[Proposal] Adding File Encryption Feature

Hello and thanks for your hard work!

I'd like to suggest adding a keys file encryption feature to enhance secure storage in the repository. This could prove highly beneficial for development purposes.

In our Rails projects, we've found a similar encryption approach quite valuable, and it seems to be a missing piece in your library.

As an example of file encryption, I can point to the senv library which we are using with react-native-config library

Thank you for considering this enhancement!

Not working on react native 0.71.12 on windows

  • React Native ---> 0.71.12
  • react-native-keys ---> 0.5.11
  • OS ---> windows 10
  • newArchEnabled ---> false

I simply create a keys.development.json in the root of my project with secure and public objects. then build the project with npx react-native run-android command. but I cannot get strings in my components neither with Keys.secureFor('some secret') nor Keys.somePublicString. I checked the example folder but it did not help me!

Can anyone tell me what I miss here?

Add support key path

Current behavior

I have multiple env, i want to store env to 1 folders(env/...). But i saw this library only support env file name, env file must belong to root folder.
image

Expected behavior

Custom path env instead file name.

Platform

  • Android
  • iOS

React Native Version

0.71.8

React Native Compressor Version

Reproducible Steps And Demo

Xcode 15 Exited with status code 127

Current behavior

Hi, when I try to build on Xcode 15 it throws Exited with status code 127. I've tried it on my project and the example project, both throw the same error.

See atached .txt for the logs, it seems that it exits on /bin/sh -c /var/folders/tc/sj1dwpmd3wx006fkwntygshh0000gn/T/SchemeScriptAction-fuoWNX.sh, I've tried to run the script on my terminal and it throws No such file or directory

Build KeysExample-Dev_2023-09-27T10-42-05.txt

Expected behavior

Platform

  • [] Android
  • iOS

React Native Version 0.72.5

React Native Compressor Version

Reproducible Steps And Demo

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.