npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

rn-secure-storage

v3.0.1

Published

Secure Storage for React Native (Android & iOS) - Keychain & Keystore

Downloads

19,992

Readme

RNSecureStorage

npm version npm downloads GitHub license

Secure Storage for React Native (Android & iOS) - Keychain & Keystore

If you like this library, please consider supporting my work by buying me a coffee

"Buy Me A Coffee"

Thanks for using this library

Please read my disclaimer about maintaining this library here

For Android I need your reviews

Getting Started

With NPM

npm install --save rn-secure-storage

With YARN

yarn add rn-secure-storage

What's changed in v3.0.0

  • Rewritten Android module with enhanced security features.
  • Android minSdkVersion is now 23 (Android 6.0 Marshmallow)
  • iOS module redeveloped using Swift and updated APIs.
  • Comprehensive renaming and expansion of APIs.
  • Modifications to the return types of some APIs.
  • Added clear for comprehensive data clearance.
  • Introduced getAllKeys for retrieving all stored keys.
  • Implemented multiSet for setting multiple values simultaneously.
  • New multiGet feature for fetching multiple values at once.
  • multiRemove added for bulk deletion of items.
  • getSupportedBiometryType introduced for iOS (supports biometric authentication types).

API

setItem

To set the item, you need to pass the key and value as parameters. You can also pass the options as a third parameter. If the key exists, the value will be updated, otherwise, it will be created. You can use the exists method to check if the key exists. You can also pass the accessible option to set the accessibility of the keychain item (only for IOS).

import RNSecureStorage, {ACCESSIBLE} from 'rn-secure-storage';

RNSecureStorage.setItem("key", "value", {accessible: ACCESSIBLE.WHEN_UNLOCKED}).then((res) => {
	console.log(res);
}).catch((err) => {
	console.log(err);
});

getItem

To get the item, you need to pass the key as a parameter. If the key exists, the value will be returned, otherwise, it will return an error.

RNSecureStorage.getItem("key").then((res) => {
	console.log(res);
}).catch((err) => {
	console.log(err);
});

removeItem

To remove the item, you need to pass the key as a parameter. If the key exists, the value will be removed, otherwise, it will return an error.

RNSecureStorage.removeItem("key").then((res) => {
	console.log(res);
}).catch((err) => {
	console.log(err);
});

exists

To check if the item exists, you need to pass the key as a parameter. If the key exists it will return true, otherwise, it will return false. Mostly you don't need to use this method because getItem will return an error if the key doesn't exist. But for performance you can just check if the key exists before calling getItem.

RNSecureStorage.exist("key").then((res) => {
	console.log(res ? "exists" : "does not exist");
}).catch((err) => {
	console.log(err);
});

getAllKeys

To get all keys, you need to call getAllKeys method. It will return an array of keys.

RNSecureStorage.getAllKeys().then((res) => {
	console.log(res);
}).catch((err) => {
	console.log(err);
});

clear

To clear all data, you need to call clear method. It will return true if the operation is successful. Otherwise, it will return remaining keys.

RNSecureStorage.clear().then((res) => {
	console.log(res);
}).catch((err) => {
	console.log(err);
});

multiSet

Multi set is a new feature that allows you to set multiple values simultaneously. You need to pass an object as the first parameter

import RNSecureStorage, {ACCESSIBLE} from 'rn-secure-storage';

const items = {"key_1": "multi key 1", "key_2": "multi key 2"};
RNSecureStorage.multiSet(items, {accessible: ACCESSIBLE.WHEN_UNLOCKED}).then((res) => {
	console.log(res);
}).catch((err) => {
	console.log(err);
});

multiGet

With multi get you can fetch multiple values at once. You need to pass an array of keys as the first parameter.

RNSecureStorage.multiGet(["key_1", "key_2"]).then((res) => {
	console.log(res);
}).catch((err) => {
	console.log(err);
});

multiRemove

With multi remove you can delete multiple values at once. You need to pass an array of keys as the first parameter. If your keys are removed/not found, it will return an array of keys that are not removed/found.

RNSecureStorage.multiRemove(["key_1", "key_2"]).then((res) => {
	console.log(res);
}).catch((err) => {
	console.log(err);
});

Options

| Key | Platform | Description | Default | |------------------|----------|--------------------------------------------------------------------------------------------------|---------------------------------------| | accessible | iOS only | This indicates when a keychain item is accessible, see possible values in Keychain.ACCESSIBLE. | Keychain.ACCESSIBLE.WHEN_UNLOCKED |

Keychain.ACCESSIBLE enum

| Key | Description | |-------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | WHEN_UNLOCKED | The data in the keychain item can be accessed only while the device is unlocked by the user. | | AFTER_FIRST_UNLOCK | The data in the keychain item cannot be accessed after a restart until the device has been unlocked once by the user. | | ALWAYS | The data in the keychain item can always be accessed regardless of whether the device is locked. | | WHEN_PASSCODE_SET_THIS_DEVICE_ONLY | The data in the keychain can only be accessed when the device is unlocked. Only available if a passcode is set on the device. Items with this attribute never migrate to a new device. | | WHEN_UNLOCKED_THIS_DEVICE_ONLY | The data in the keychain item can be accessed only while the device is unlocked by the user. Items with this attribute do not migrate to a new device. | | AFTER_FIRST_UNLOCK_THIS_DEVICE_ONLY | The data in the keychain item cannot be accessed after a restart until the device has been unlocked once by the user. Items with this attribute never migrate to a new device. | | ALWAYS_THIS_DEVICE_ONLY | The data in the keychain item can always be accessed regardless of whether the device is locked. Items with this attribute never migrate to a new device. |

You can also check out sample project for more details

License

This project is licensed under the MIT License - see the LICENSE.md file for details

I need your reviews

I have rewritten the Android module with enhanced security features. I need your reviews. Please test the new version and let me know your thoughts. I will be happy to hear your suggestions and comments. I'm planning to release the new version to handle biometric authentication on Android.

Connect with me

Disclaimer

As an open-source enthusiast and developer, I originally created this library for professional use. However, with recent changes in my career, my focus has shifted away from React Native, limiting my involvement to personal projects. Consequently, my time to address issues and review pull requests for this library has become restricted. I remain committed to maintaining and improving this library, but my response times might be longer. I greatly appreciate your patience and understanding.

The beauty of open-source is in collaboration. If you find this library useful and would like to contribute, whether through code, addressing issues, or even buying a coffee to show support, it would be immensely appreciated. Together, we can ensure the continued development and enhancement of this library.

"Buy Me A Coffee"