randomBytes for react-native
Go to file
Volodymyr Kozieiev 028cc2d48e
Fixed errors in react-native-randombytes desktop implementation
2017-12-23 13:34:34 +02:00
RNRandomBytes.xcodeproj rm xcuserdata, project.xcworkspace 2017-09-05 10:42:48 -04:00
RNRandomBytesTests Initial commit 2015-11-19 19:50:48 +00:00
android Removed override notation for deprecated method (createJSModules) of RN 0.47.0 2017-08-28 21:51:43 -04:00
.gitignore rm xcuserdata, project.xcworkspace 2017-09-05 10:42:48 -04:00
CMakeLists.txt Fixed errors in react-native-randombytes desktop implementation 2017-12-23 13:34:34 +02:00
LICENSE Initial commit 2015-11-19 19:50:48 +00:00
README.md Remove outdated note from README. 2016-11-10 17:18:04 +01:00
RNRandomBytes.h Update [just the] iOS headers for RN 0.40+ (#15) 2017-08-28 21:55:32 -04:00
RNRandomBytes.m Update [just the] iOS headers for RN 0.40+ (#15) 2017-08-28 21:55:32 -04:00
build.gradle add android versoin 2016-01-13 15:53:44 -08:00
index.js rm log statement 2016-05-01 14:03:31 -04:00
package.json Add repository section to package.json 2017-09-05 10:40:17 -04:00
rnrandombytesdesktop.cpp Fixed errors in react-native-randombytes desktop implementation 2017-12-23 13:34:34 +02:00
rnrandombytesdesktop.h Fixed errors in react-native-randombytes desktop implementation 2017-12-23 13:34:34 +02:00
settings.gradle add android versoin 2016-01-13 15:53:44 -08:00

README.md

react-native-randombytes

Usage

var randomBytes = require('react-native-randombytes')

// synchronous API
// uses SJCL
var rand = randomBytes(4)

// asynchronous API
// uses iOS-side SecRandomCopyBytes
randomBytes(4, (err, bytes) => {
  console.log(bytes.toString('hex'))
})

Installation

rnpm link

Manual

iOS

  • Drag RNRandomBytes.xcodeproj from node_modules/react-native-randombytes into your XCode project.

  • Click on the project in XCode, go to Build Phases, then Link Binary With Libraries and add libRNRandomBytes.a

Confused? See an example with screenshots here

Android

  • Update Gradle Settings
// file: android/settings.gradle
...

include ':randombytes', ':app'
project(':randombytes').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-randombytes/android')
  • Update Gradle Build
// file: android/app/build.gradle
...

dependencies {
    ...
    compile project(':randombytes')
}
  • Register React Package
...
import com.bitgo.randombytes.RandomBytesPackage // import

public class MainActivity extends Activity implements DefaultHardwareBackBtnHandler {

    private ReactInstanceManager mReactInstanceManager;
    private ReactRootView mReactRootView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mReactRootView = new ReactRootView(this);
        mReactInstanceManager = ReactInstanceManager.builder()
                .setApplication(getApplication())
                .setBundleAssetName("index.android.bundle")
                .setJSMainModuleName("index.android")
                .addPackage(new MainReactPackage())
                .addPackage(new RandomBytesPackage()) // register package here
                .setUseDeveloperSupport(BuildConfig.DEBUG)
                .setInitialLifecycleState(LifecycleState.RESUMED)
                .build();
        mReactRootView.startReactApplication(mReactInstanceManager, "AwesomeProject", null);
        setContentView(mReactRootView);
    }
...