3.6.1 • Published 3 years ago

react-native-randombytes v3.6.1

Weekly downloads
20,851
License
ISC
Repository
github
Last release
3 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-cipherjabo-react-native-super-simple-chatguricomponenthsmrn-bitcoinjs-libedocu-sdk-react-nativeesignus_hw_coinseth-hbwalletnode-libs-react-nativenode-libs-react-native-buffer4node-libs-react-native-fsmultichain-wallet-sdkmultichain-wallet-vipaymelbourne-metro-sdkmatrix-reactnative-sdkreact-native-goldenjsreact-native-eosjs-eccreact-native-gelf-proreact-native-hdwalletreact-native-jolocomreact-native-jsontokensreact-native-airbitz-ioreact-native-bip39react-native-bitcoinjsreact-native-bitcoinjs-libreact-native-casper-storagereact-native-cotterreact-native-musicreact-native-onvifreact-native-mclreact-native-matrix-uireact-native-securam-otcreact-native-tweetnaclreact-native-xml-cryptorn-eosjs-eccrn-cloudkitrn-bitcoinjs-librn-chat-matrixrn-wappsto-networksrn-wallet-sdk-testrn-g8c-sdkrn-matrixstanza-extendstanza-shimssoldibox-sdk@phungdaihiep/react-native-bitcoinjs@pigzbe/react-native-stellar-sdk@pushprotocol/react-native-sdk@functionland/component-library@functionland/fx-components@ruvasik/bip39-expo@rn-matrix/core@rn-matrix/ui@nuvosphere.io/react-native-nuvo-sdk@parsh/react-native-bitcoinjs-lib@particle/react-native-crypto@pagopa/io-react-native-nodelibs@luandro/react-native-ssb-shims@omisego/react-native-omg-js@medardm/react-native-bip39@manishoo/rn-matrix-core@manishoo/rn-matrix-ui@gimly-blockchain/rn-did-auth-siop-authenticatordg-suite-protocolswallet-appvipay-multichain-walletcreate-rn-mobile-dapp@jsrsc/node-libs-react-native@hawkingnetwork/node-libs-react-native@kalashshah/react-native-sdk@kitzen/react-native-bip39@klausmikhaelson/react-native-sdk-testing@ikonintegration/reactnative-idmclient@57u/lumos-react-native@affinityproject/wallet-react-native-sdk@affinidi/wallet-react-native-sdk@affinityproject/affinity-react-native-sdk@spostma/rn-did-auth-op-authenticator@velas/account-rn-sdk@velas/react-native-account@verida/client-rn@vlad8096/stanza@sphereon/rn-did-auth-op-authenticator@bonfire-xmpp/verse@umpc/node-libs-react-native@zalastax/nolb-react-native-rably-react-native@cpchain-tools/eccairbitz-core-react-nativeairbitz-currency-bitcoin@cybavo/react-native-wallet-service@dawar2151/bip39-expo@danilo_pereira/react-native-serialize-javascript
3.6.1

3 years ago

3.6.0

4 years ago

3.5.3

5 years ago

3.5.2

5 years ago

3.5.1

6 years ago

3.5.0

6 years ago

3.4.0

6 years ago

3.3.0

6 years ago

3.2.0

6 years ago

3.1.0

6 years ago

3.0.0

7 years ago

2.3.0

7 years ago

2.2.0

7 years ago

2.1.0

8 years ago

2.0.1

8 years ago

2.0.0

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago