Skip to content

Commit 49518ef

Browse files
committed
updated website and README
1 parent cb726ea commit 49518ef

16 files changed

Lines changed: 252 additions & 354 deletions

README.md

Lines changed: 8 additions & 255 deletions
Original file line numberDiff line numberDiff line change
@@ -2,272 +2,25 @@
22

33
[![npm version](https://badge.fury.io/js/react-native-sensitive-info.svg)](https://badge.fury.io/js/react-native-sensitive-info)
44
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5-
[![Open Source Love](https://badges.frapsoft.com/os/v2/open-source.png?v=103)](https://github.com/ellerbrock/open-source-badges/)
5+
![npm bundle size](https://img.shields.io/bundlephobia/min/react-native-sensitive-info)
66

77
`react-native-sensitive-info` manages all data stored in Android Shared Preferences, iOS Keychain and Windows Credentials. You can set and get all key/value using simple methods.
88

99
# Install
1010

11-
Install `react-native-sensitive-info` using:
11+
Install `react-native-sensitive-info` into your project using:
1212

13-
``npm i -S react-native-sensitive-info`` or ``yarn add react-native-sensitive-info``
14-
15-
| React Native SDK | RNSI SDK |
16-
| :--------------: | :-------: |
17-
| v0.60+ | v5.5.0 |
18-
| v0.59.0 or lower | v5.4.x |
19-
20-
## Linking project
21-
22-
### Automatically
23-
24-
`react-native link react-native-sensitive-info`
25-
26-
### Manually
27-
28-
#### iOS
29-
30-
If you are using Cocoapods add the following line to your Podfile:
31-
```ruby
32-
pod 'react-native-sensitive-info', path: "../node_modules/react-native-sensitive-info"
33-
```
34-
35-
otherwise follow those steps:
36-
37-
In XCode, in the project navigator:
38-
39-
* Right click Libraries
40-
* Add Files to [your project's name]
41-
* Go to node_modules/react-native-sensitive-info
42-
* Add the .xcodeproj file
43-
44-
In XCode, in the project navigator, select your project.
45-
46-
* Add the libRNSensitiveInfo.a from the RNSensitiveInfo project to your project's Build Phases ➜ Link Binary With Libraries
47-
* Click .xcodeproj file you added before in the project navigator and go the Build Settings tab. Make sure 'All' is toggled on (instead of 'Basic').
48-
* Look for Header Search Paths and make sure it contains both $(SRCROOT)/../react-native/React and $(SRCROOT)/../../React - mark both as recursive. (Should be OK by default.)
49-
50-
Run your project (Cmd+R)
51-
52-
#### macos (https://github.com/ptmt/react-native-macos)
53-
54-
Same steps as iOS but change the Base SDK to macOS in Libraries/RNSensitiveInfo.xcodeproj.
55-
56-
#### Android
57-
58-
Go to `settings.gradle` inside your android project folder and paste this lines there:
59-
60-
```java
61-
include ':react-native-sensitive-info'
62-
63-
project(':react-native-sensitive-info').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-sensitive-info/android')
64-
```
65-
66-
and paste it into `build.gradle`:
67-
68-
```java
69-
compile project(':react-native-sensitive-info')
70-
```
71-
72-
In your `MainApplication.java` add:
73-
```java
74-
import br.com.classapp.RNSensitiveInfo.RNSensitiveInfoPackage; //<- You must import this
75-
76-
protected List<ReactPackage> getPackages() {
77-
return Arrays.<ReactPackage>asList(
78-
new MainReactPackage(),
79-
new RNSensitiveInfoPackage(), // <- Add this line
80-
);
81-
}
82-
```
83-
84-
Sync gradle and go :)
85-
86-
#### Windows
87-
88-
* Open the solution in Visual Studio for your Windows apps.
89-
90-
* Right click your in the Explorer and click Add > Existing Project....
91-
92-
* Navigate to ./<app-name>/node_modules/react-native-sensitive-info/windows/RNSensitiveInfo/RNSensitiveInfo/ and add RNSensitiveInfo.csproj.
93-
94-
* Right click on your React Native Windows app under your solutions directory and click Add > Reference....
95-
96-
* Check the RNSensitiveInfo you just added and press Ok
97-
98-
* Open MainPage.cs in your app
99-
100-
```
101-
using RNSqlite2;
102-
103-
get
104-
{
105-
return new List<IReactPackage>
106-
{
107-
new MainReactPackage(),
108-
new RNSensitiveInfoPackage(),
109-
};
110-
}
111-
```
112-
113-
114-
### Expo
115-
116-
As noted by by [@Palisand](https://github.com/Palisand) in [this issue](https://github.com/mCodex/react-native-sensitive-info/issues/50#issuecomment-334583668), it's not possible to use this module with Expo, unless your project is detached. The same is true for any modules with native code, it's not an issue with `react-native-sensitive-info`. You may want to try [SecureStore](https://docs.expo.io/versions/latest/sdk/securestore.html) from Expo itself.
117-
118-
# Methods
119-
120-
We unified our library's methods to bring more efficiency and simplify the usability for other developers. We hope that you enjoy it. :)
121-
122-
`isHardwareDetected()`: resolves to a boolean that indicates the detection of fingerprint hardware
123-
124-
`hasEnrolledFingerprints()`: resolves to a boolean that indicates the enrollment status of fingerprints on the device
125-
126-
`isSensorAvailable`: resolves to a boolean that indicates the overall availability of fingerprint sensor (a combination of the previous two methods)
127-
128-
`setItem(key, value, options)`: You can insert data into shared preferences & keychain using this promise method.
129-
130-
`getItem(key, options)`: This promise will get value from given key.
131-
132-
`deleteItem(key, options)`: It will delete value from given key
133-
134-
`getAllItems(options)`: Will retrieve all keys and values from Shared Preferences & Keychain
135-
136-
"Options" is a new parameter (optional) that you can pass to our methods. But what does it do? Now, you can select which keychain's service (iOS) and shared preferences's name (android) you can use. To do so:
137-
138-
```javascript
139-
SInfo.setItem('key1', 'value1', {
140-
sharedPreferencesName: 'mySharedPrefs',
141-
keychainService: 'myKeychain'});
142-
```
143-
144-
But if you prefer to not use it, our default sharedPreferencesName is: **shared_preferences** and keychainService is: **app**. For that, use:
145-
146-
```javascript
147-
SInfo.setItem('key1', 'value1', {});
148-
```
149-
150-
If you used Android's getDefaultSharedPreferences in your project the shared preference's name that you are looking for is: **com.mypackage.MyApp_preferences**. On the other hand if you used iOS's Keychain the default service is: **app** which is our default too.
151-
152-
### Android Specific Options
153-
154-
#### showModal & strings
155-
156-
When passing in `touchID` and `showModal` (Android only) options as `true`, an Android native prompt will show up asking for user's authentication. This behavior is similar to that of iOS.
157-
158-
You can control strings associated with a modal prompt via `strings` option:
159-
```javascript
160-
strings: {
161-
header: 'Sign in',
162-
description: 'Place finger to authenticate',
163-
hint: 'Touch',
164-
success: 'Fingerprint recognized',
165-
notRecognized: 'Fingerprint not recognized, try again',
166-
cancel: 'Cancel',
167-
cancelled: 'Authentication was cancelled', // reject error message
168-
}
169-
```
170-
171-
#### setInvalidatedByBiometricEnrollment
172-
173-
If you want to control the behaviour on android when new Fingers are enrolled or removed on the device [https://developer.android.com/reference/android/security/keystore/KeyGenParameterSpec.Builder#setInvalidatedByBiometricEnrollment(boolean)](https://developer.android.com/reference/android/security/keystore/KeyGenParameterSpec.Builder#setInvalidatedByBiometricEnrollment(boolean)) on any device with API level greater than 24 (`Android version >= N`). You should call during the initialization of your app to the function `setInvalidatedByBiometricEnrollment`.
174-
This will re-initialise the internal android Key generator with the flag set to keep/invalidate the credentials upon fingers change.
175-
176-
```javascript
177-
import SInfo from 'react-native-sensitive-info';
178-
179-
SInfo.setInvalidatedByBiometricEnrollment(false);
13+
```bash
14+
npm i -S react-native-sensitive-info
18015
```
181-
If you do not call to this function the default value is set to `true`.
182-
183-
### iOS Specific Options
18416

185-
#### kSecAccessControl
186-
187-
When passing in the `touchID` option as `true`, you can also set `kSecAccessControl`. For example:
188-
189-
```javascript
190-
SInfo.setItem('key1', 'value1', {
191-
keychainService: 'myKeychain',
192-
kSecAccessControl: 'kSecAccessControlTouchIDCurrentSet',
193-
sharedPreferencesName: 'mySharedPrefs',
194-
touchID: true,
195-
});
17+
```bash
18+
yarn add react-native-sensitive-info
19619
```
19720

198-
Note: By default `kSecAccessControl` will get set to `kSecAccessControlUserPresence`.
199-
200-
### Enable Face ID
201-
202-
To enable Face ID, for iOS X and above or iPad Pro, set `kSecAccessControl` to `kSecAccessControlBiometryAny`. For example:
203-
```javascript
204-
SInfo.setItem('key1', 'value1', {
205-
keychainService: 'myKeychain',
206-
kSecAccessControl: 'kSecAccessControlBiometryAny',
207-
...
208-
});
209-
```
210-
211-
Note: This will require a string for the prompt that you have to set the key `NSFaceIDUsageDescription` in your App's Info.plist file. The string value of this key will be added to the Face ID prompt. You can read more about it in the [Apple Docs]("https://developer.apple.com/documentation/localauthentication/logging_a_user_into_your_app_with_face_id_or_touch_id")
212-
213-
#### kSecAttrSynchronizable
214-
215-
You can set this to `true` in order to sync the keychain items with iCloud.
216-
217-
Note: By default `kSecAttrSynchronizable` will get set to `false`.
218-
219-
#### kLocalizedFallbackTitle
220-
221-
You can set this to a string and fallback to pin code authentication.
222-
223-
224-
# How to use?
225-
226-
Here is a simple example:
227-
228-
```javascript
229-
import SInfo from 'react-native-sensitive-info';
230-
231-
SInfo.setItem('key1', 'value1', {
232-
sharedPreferencesName: 'mySharedPrefs',
233-
keychainService: 'myKeychain'
234-
}).then((value) =>
235-
console.log(value) //value 1
236-
);
237-
238-
SInfo.setItem('key2', 'value2', {});
239-
240-
SInfo.getItem('key1', {
241-
sharedPreferencesName: 'mySharedPrefs',
242-
keychainService: 'myKeychain'}).then(value => {
243-
console.log(value) //value1
244-
});
245-
246-
SInfo.getItem('key2',{}).then(value => {
247-
console.log(value) //value2
248-
});
249-
250-
SInfo.getAllItems({
251-
sharedPreferencesName: 'mySharedPrefs',
252-
keychainService: 'myKeychain'}).then(values => {
253-
console.log(values) //value1, value2
254-
});
255-
```
256-
257-
# Protect your item with fingerprint
258-
As jailbroken device can access your iOS Keychain/ Android shared preference and key store in plain text, it is necessary to add another layer of protection so even jailbreaking won't leak your data (like refresh_token or bank account password).
259-
- for iOS it is implemented though [Access Control](https://developer.apple.com/documentation/security/secaccesscontrol). Everytime when app wants to access the protected keychain item, a prompt by iOS will show up. Only when authentication success will the app get the keychain item.
260-
- for Android it is implemented though [FingerprintManager](https://developer.android.com/reference/android/hardware/fingerprint/FingerprintManager.html) + Keystore. Keystore has a function called `setUserAuthenticationRequired` which makes Keystore requires user authentication before getting value. However Android doesn't nicely user to scan their finger, it just throws error. Here is where FingerprintManager comes in. However (AGAIN) FingerprintManager doesn't show prompt for you, so you need to build UI yourself to let user to know that it is time to scan fingerprint.
261-
262-
**The example in the repo shows how to use this feature and how to build some Android UI based on callbacks.**
263-
264-
**NOTE: fingerprint will only work with Android 6.0 and above.**
265-
266-
HELP NEEDED: It will be nice if someone can build an Android native prompt to make Android touch as easy to use as iOS. Maybe we can borrow some code from [google's example](https://github.com/googlesamples/android-FingerprintDialog)
267-
268-
# Use with redux-persist
21+
# Docs
26922

270-
If you would like to use [redux-persist](https://github.com/rt2zz/redux-persist) to store information from your Redux state into secure storage, you can use [redux-persist-sensitive-storage](https://github.com/CodingZeal/redux-persist-sensitive-storage), which provides a custom storage back-end for redux-persist that uses react-native-sensitive-info.
23+
Check out the [docs](https://mcodex.github.io/react-native-sensitive-info/docs)
27124

27225
# Contributing
27326

website/docs/android_options.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ sidebar_label: Android
66

77
Android specific configurations
88

9+
## sharedPreferencesName
10+
11+
You can choose the shared preferences' name which you want to use. Otherwise, the default is **shared_preferences**
12+
913
## showModal & strings
1014

1115
When `showModal` is `true`, an Android native prompt will show up asking for user's authentication. This behavior is similar to that of iOS.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
id: community_libraries
3+
title: Community Libraries
4+
sidebar_label: Community Libraries
5+
---
6+
7+
### redux-persist-sensitive-storage
8+
9+
If you would like to use [redux-persist](https://github.com/rt2zz/redux-persist) to store information from your Redux state into secure storage, you can use [redux-persist-sensitive-storage](https://github.com/CodingZeal/redux-persist-sensitive-storage) which uses [react-native-sensitive-info](https://github.com/mCodex/react-native-sensitive-info) under the hood.

website/docs/deleteItem.md

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,25 @@ title: deleteItem
44
sidebar_label: deleteItem
55
---
66

7-
**WIP**
7+
Delete an item from storage
88

9-
In the meantime checkout our **[README](https://github.com/mCodex/react-native-sensitive-info#methods)** for further information.
9+
```javascript
10+
deleteItem(key, options) : Promise<null>
11+
```
1012

11-
Wanna help? Just send a PR 😉
13+
Example:
14+
15+
```javascript
16+
import RNSInfo from 'react-native-sensitive-info';
17+
18+
const myFunc = async () => {
19+
return SInfo.deleteItem('key1', {
20+
sharedPreferencesName: 'mySharedPrefs',
21+
keychainService: 'myKeychain'
22+
});
23+
}
24+
25+
await myFunc();
26+
27+
// Data successfully deleted
28+
```

website/docs/getAllItems.md

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,29 @@ title: getAllItems
44
sidebar_label: getAllItems
55
---
66

7-
**WIP**
7+
Get all items from storage
88

9-
In the meantime checkout our **[README](https://github.com/mCodex/react-native-sensitive-info#methods)** for further information.
9+
```javascript
10+
getAllItems(options) : Promise<[{
11+
key: string
12+
value: string
13+
service: string
14+
}]>
15+
```
1016

11-
Wanna help? Just send a PR 😉
17+
Example:
18+
19+
```javascript
20+
import RNSInfo from 'react-native-sensitive-info';
21+
22+
const myFunc = async () => {
23+
return SInfo.getAllItems({
24+
sharedPreferencesName: 'mySharedPrefs',
25+
keychainService: 'myKeychain'
26+
});
27+
}
28+
29+
await myFunc();
30+
31+
// The data is retrieved
32+
```

website/docs/getItem.md

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,25 @@ title: getItem
44
sidebar_label: getItem
55
---
66

7-
**WIP**
7+
Get an item from storage
88

9-
In the meantime checkout our **[README](https://github.com/mCodex/react-native-sensitive-info#methods)** for further information.
9+
```javascript
10+
getItem(key, options) : Promise<string>
11+
```
1012

11-
Wanna help? Just send a PR 😉
13+
Example:
14+
15+
```javascript
16+
import RNSInfo from 'react-native-sensitive-info';
17+
18+
const myFunc = async () => {
19+
return SInfo.getItem('key1', {
20+
sharedPreferencesName: 'mySharedPrefs',
21+
keychainService: 'myKeychain'
22+
});
23+
}
24+
25+
await myFunc();
26+
27+
// The data is retrieved
28+
```

0 commit comments

Comments
 (0)