3.6.1 • Published 4 years ago

react-native-randombytes v3.6.1

Weekly downloads
20,851
License
ISC
Repository
github
Last release
4 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-extend@dongtimes2/node-libs-react-native@cybavo/react-native-wallet-service@cpchain-tools/eccjabo-react-native-super-simple-chatsoldibox-sdk@altispeed/rn-matrix-core@affinityproject/affinity-react-native-sdk@affinidi/wallet-react-native-sdk@affinityproject/wallet-react-native-sdk@bytexbyte/berify-scan@57u/lumos-react-native@bonfire-xmpp/verse@dawar2151/bip39-expo@danilo_pereira/react-native-serialize-javascriptvipay-multichain-wallet@hawkingnetwork/node-libs-react-native@functionland/component-library@functionland/fx-components@gimly-blockchain/rn-did-auth-siop-authenticator@kylediggs/pushprotocol-react-native-sdk@luandro/react-native-ssb-shims@legalhighdev/node-libs-react-native@manishoo/rn-matrix-core@manishoo/rn-matrix-ui@medardm/react-native-bip39@klausmikhaelson/react-native-sdk-testing@kalashshah/react-native-sdk@kitzen/react-native-bip39@jsrsc/node-libs-react-native@ikonintegration/reactnative-idmclient@omisego/react-native-omg-js@react-native-oh-tpl/react-native-randombytes@ruvasik/bip39-expo@pushprotocol/react-native-sdk@rn-matrix/core@rn-matrix/ui@pigzbe/react-native-stellar-sdk@phungdaihiep/react-native-bitcoinjs@nuvosphere.io/react-native-nuvo-sdk@particle/react-native-crypto@parsh/react-native-bitcoinjs-lib@pagopa/io-react-native-nodelibs@spostma/rn-did-auth-op-authenticator@sphereon/rn-did-auth-op-authenticatormultichain-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-tweetnaclhsmrn-bitcoinjs-libguricomponentmelbourne-metro-sdkmatrix-reactnative-sdk@zalastax/nolb-react-native-rably-react-nativeairbitz-core-react-nativeairbitz-currency-bitcoin
3.6.1

4 years ago

3.6.0

5 years ago

3.5.3

6 years ago

3.5.2

6 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

7 years ago

3.0.0

8 years ago

2.3.0

8 years ago

2.2.0

8 years ago

2.1.0

9 years ago

2.0.1

9 years ago

2.0.0

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago