-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
76 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,47 @@ | ||
# react-native-random-bytes | ||
# react-native-securerandom | ||
[![npm version](https://badge.fury.io/js/react-native-securerandom.svg)](https://badge.fury.io/js/react-native-securerandom) | ||
|
||
A library to generate cryptographically-secure random bytes. Uses `SecRandomCopyBytes` on iOS and `SecureRandom` on Android. | ||
|
||
## Usage | ||
The library exports a single function: | ||
### generateRandomBytes(length: number) => Promise\<Uint8Array\> | ||
### generateSecureRandom(length: number) => Promise\<Uint8Array\> | ||
Takes a length, the number of bytes to generate, and returns a `Promise` that resolves with a `Uint8Array`. | ||
|
||
```javascript | ||
import { generateRandomBytes } from 'react-native-random-bytes'; | ||
import { generateSecureRandom } from 'react-native-securerandom'; | ||
|
||
generateRandomBytes(12).then(randomBytes => console.log(randomBytes)); | ||
generateSecureRandom(12).then(randomBytes => console.log(randomBytes)); | ||
``` | ||
|
||
## Installation | ||
|
||
`$ yarn add react-native-random-bytes` | ||
`$ yarn add react-native-securerandom` | ||
|
||
### Automatic linking with react-native link | ||
|
||
`$ react-native link react-native-random-bytes` | ||
`$ react-native link react-native-securerandom` | ||
|
||
### Manual linking | ||
|
||
#### iOS | ||
|
||
1. In XCode, in the project navigator, right click `Libraries` ➜ `Add Files to [your project's name]` | ||
2. Go to `node_modules` ➜ `react-native-random-bytes` and add `RNRandomBytes.xcodeproj` | ||
3. In XCode, in the project navigator, select your project. Add `libRNRandomBytes.a` to your project's `Build Phases` ➜ `Link Binary With Libraries` | ||
2. Go to `node_modules` ➜ `react-native-securerandom` and add `RNSecureRandom.xcodeproj` | ||
3. In XCode, in the project navigator, select your project. Add `libRNSecureRandom.a` to your project's `Build Phases` ➜ `Link Binary With Libraries` | ||
4. Run your project (`Cmd+R`)< | ||
|
||
#### Android | ||
|
||
1. Open up `android/app/src/main/java/[...]/MainActivity.java` | ||
- Add `import net.rhogan.rnrandombytes.RNRandomBytesPackage;` to the imports at the top of the file | ||
- Add `new RNRandomBytesPackage()` to the list returned by the `getPackages()` method | ||
- Add `import net.rhogan.rnsecurerandom.RNSecureRandomPackage;` to the imports at the top of the file | ||
- Add `new RNSecureRandomPackage()` to the list returned by the `getPackages()` method | ||
2. Append the following lines to `android/settings.gradle`: | ||
``` | ||
include ':react-native-random-bytes' | ||
project(':react-native-random-bytes').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-random-bytes/android') | ||
include ':react-native-securerandom' | ||
project(':react-native-securerandom').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-securerandom/android') | ||
``` | ||
3. Insert the following lines inside the dependencies block in `android/app/build.gradle`: | ||
``` | ||
compile project(':react-native-random-bytes') | ||
compile project(':react-native-securerandom') | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="net.rhogan.rnrandombytes"> | ||
package="net.rhogan.rnsecurerandom"> | ||
|
||
</manifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,16 +3,16 @@ require "json" | |
package = JSON.parse(File.read(File.join(__dir__, "package.json"))) | ||
|
||
Pod::Spec.new do |s| | ||
s.name = "RNRandomBytes" | ||
s.name = "RNSecureRandom" | ||
s.version = package["version"] | ||
s.summary = "RNRandomBytes" | ||
s.summary = "RNSecureRandom" | ||
s.description = package["description"] | ||
s.homepage = package["homepage"] | ||
s.license = "MIT" | ||
s.author = { "Rob Hogan" => "[email protected]" } | ||
s.platform = :ios, "7.0" | ||
s.source = { :git => "https://github.com/author/RNRandomBytes.git", :tag => "master" } | ||
s.source_files = "RNRandomBytes/**/*.{h,m}" | ||
s.source = { :git => "https://github.com/author/RNSecureRandom.git", :tag => "master" } | ||
s.source_files = "RNSecureRandom/**/*.{h,m}" | ||
s.requires_arc = true | ||
s.dependency "React" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ytes.xcworkspace/contents.xcworkspacedata → ...ndom.xcworkspace/contents.xcworkspacedata
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.