# @react-native-module/randombytes

> implementation of randomBytes for React Native

Latest version **4.0.0** (published 2022-08-04) · ISC license · 0 weekly downloads

## Install

```sh
npm install @react-native-module/randombytes
pnpm add @react-native-module/randombytes
yarn add @react-native-module/randombytes
bun add @react-native-module/randombytes
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 4.0.0 |
| Published | 2022-08-04 |
| First published | 2022-07-14 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 600.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | sacru2red |
| Maintainers | sacru2red |
| Keywords | react native, react-native, randomBytes, random-bytes, rng, ios, android, web |

## Links

- npm: https://www.npmjs.com/package/@react-native-module/randombytes
- Repository: https://github.com/react-native-module/randombytes
- Issues: https://github.com/react-native-module/randombytes/issues
- npm.io page: https://npm.io/package/@react-native-module/randombytes

## Dependencies (2)

- [buffer](https://npm.io/package/buffer.md) ^6.0.3
- [random-js](https://npm.io/package/random-js.md) ^2.1.0

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 4.0.0 (latest) — 2022-08-04
- 3.6.7-2 (next) — 2022-08-04
- 3.6.7-1 — 2022-07-25
- 3.6.7-0 — 2022-07-25
- 3.6.6 — 2022-07-25
- 3.6.6-7 — 2022-07-25
- 3.6.6-6 — 2022-07-25
- 3.6.6-5 — 2022-07-24
- 3.6.6-4 — 2022-07-22
- 3.6.6-3 — 2022-07-20
- 3.6.6-2 — 2022-07-19
- 3.6.6-1 — 2022-07-19
- 3.6.6-0 — 2022-07-19
- 3.6.5 — 2022-07-18
- 3.6.5-0 — 2022-07-18
- … 8 more at https://npm.io/package/@react-native-module/randombytes/versions

## README

# react-native-module/randombytes

## Usage

```js
import { randomBytes } from "@react-native-module/randombytes";

// synchronous API
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

This module has peerDependency "react", "react-native"

A typical workflow:

```
npm install --save @react-native-module/randombytes
```

```
yarn add @react-native-module/randombytes
```

### Automatic - Android / iOS (recommended)

```bash
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](http://facebook.github.io/react-native/docs/linking-libraries-ios.html#content)

#### `Android`

- Update Gradle Settings

```gradle
// file: android/settings.gradle
...

include ':randombytes', ':app'
project(':randombytes').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-randombytes/android')
```

- Update Gradle Build

```gradle
// file: android/app/build.gradle
...

dependencies {
    ...
    compile project(':randombytes')
}
```

- Register React Package

```java
...
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`

```bash
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

---
_Source: https://npm.io/package/@react-native-module/randombytes · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
