3.6.1 • Published 5 years ago

react-native-randombytes v3.6.1

Weekly downloads
20,851
License
ISC
Repository
github
Last release
5 years ago

react-native-randombytes

Usage

import { randomBytes } from 'react-native-randombytes'

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

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

Installation

  1. Follow the steps in the next section
  2. You have two options depending on your needs:

    1. if you're trying to get Node.js or browser crypto modules working in React Native, follow the installation workflow in react-native-crypto.
    2. if you only need asynchronous random bytes generation, and don't care about getting back Buffer objects, you can do the following:
    import { NativeModules } from 'react-native'
    const { RNRandomBytes } = NativeModules
    RNRandomBytes.randomBytes(32, (err, bytes) => {
      // bytes is a base64string
    })

Automatic - Android / iOS (recommended)

react-native link

Manual

If Automatic installation failed you, dry your tears and read on.

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);
    }
...

Windows

react-native link react-native-randombytes

Depending on your project versions and the state of RN-Windows this may not always work. If it does not, a manual installation guide can be found here:

https://github.com/Microsoft/react-native-windows/blob/master/docs/LinkingLibrariesWindows.md

@ripzery/omg-js-react-native@ripzery/react-native-omg-jswocode-wallet-qitmeerwocode-wallet-ubreact-native-bitcoincashjs-lib@sphereon/rn-did-siop-auth-lib@infinitebrahmanuniverse/nolb-react-native-r@everything-registry/sub-chunk-2589@finan-me/react-native-hex-cipherwallet-appstanza-shimsstanza-extendjabo-react-native-super-simple-chathsmrn-bitcoinjs-libguricomponentmelbourne-metro-sdkmatrix-reactnative-sdk@velas/account-rn-sdk@velas/react-native-account@umpc/node-libs-react-native@vlad8096/stanza@verida/client-rn@zalastax/nolb-react-native-rairbitz-core-react-nativeairbitz-currency-bitcoinably-react-nativeasli-wallet@57u/lumos-react-native@affinidi/wallet-react-native-sdk@affinityproject/affinity-react-native-sdk@affinityproject/wallet-react-native-sdk@cpchain-tools/ecc@altispeed/rn-matrix-core@hawkingnetwork/node-libs-react-nativesoldibox-sdk@bytexbyte/berify-scan@bonfire-xmpp/versevipay-multichain-wallet@kylediggs/pushprotocol-react-native-sdk@legalhighdev/node-libs-react-native@pushprotocol/react-native-sdkmultichain-wallet-sdkmultichain-wallet-vipaympc-crypto-testpaytionjs-sdkreact-native-dankexreact-native-eosjs-eccreact-native-jolocomreact-native-goldenjsreact-native-hdwalletreact-native-gelf-prorn-bitcoinjs-librn-matrixrn-chat-matrixrn-wallet-sdk-testrn-wappsto-networksrn-g8c-sdkrn-eosjs-eccreact-native-airbitz-ioreact-native-casper-storagereact-native-bip39react-native-bitcoinjsreact-native-bitcoinjs-libreact-native-musicreact-native-onvifreact-native-jsontokensreact-native-matrix-uireact-native-mclreact-native-p2p-securereact-native-cotterreact-native-securam-otcreact-native-xml-cryptonode-libs-react-nativenode-libs-react-native-buffer4node-libs-react-native-fsrn-cloudkitreact-native-tweetnaclcreate-rn-mobile-dappbip39expandtsbitcoinjs-lib_react-nativedg-suite-protocols@spostma/rn-did-auth-op-authenticator@sphereon/rn-did-auth-op-authenticatoredocu-sdk-react-nativeesignus_hw_coinseth-hbwalletfabric-gateway-nhatthanhfabric-gateway-nhatthanh2801fabric-gateway-thanh@rn-matrix/core@rn-matrix/ui@particle/react-native-crypto@parsh/react-native-bitcoinjs-lib@medardm/react-native-bip39@pagopa/io-react-native-nodelibs@nuvosphere.io/react-native-nuvo-sdk@openfort/react-native@omisego/react-native-omg-js@ruvasik/bip39-expo@manishoo/rn-matrix-core
3.6.1

5 years ago

3.6.0

5 years ago

3.5.3

6 years ago

3.5.2

7 years ago

3.5.1

7 years ago

3.5.0

7 years ago

3.4.0

7 years ago

3.3.0

7 years ago

3.2.0

7 years ago

3.1.0

8 years ago

3.0.0

8 years ago

2.3.0

8 years ago

2.2.0

9 years ago

2.1.0

9 years ago

2.0.1

9 years ago

2.0.0

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago