{"_id":"@alxss/react-native-encrypted-storage","name":"@alxss/react-native-encrypted-storage","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@alxss/react-native-encrypted-storage","version":"1.0.0","description":"A React Native wrapper over SharedPreferences and Keychain to provide a secure alternative to Async Storage","main":"lib/commonjs/index","module":"lib/module/index","types":"lib/typescript/index.d.ts","react-native":"src/index","source":"src/index","scripts":{"test":"jest","typescript":"tsc --noEmit","lint":"eslint \"**/*.{js,ts,tsx}\"","prepare":"bob build","example":"yarn --cwd example","pods":"cd example && pod-install --quiet","bootstrap":"yarn example && yarn && yarn pods"},"keywords":["react-native","ios","android"],"repository":{"type":"git","url":"git+https://github.com/emeraldsanto/react-native-encrypted-storage.git"},"author":{"name":"emeraldsanto","email":"yanick.belanger@yahoo.com","url":"https://github.com/emeraldsanto"},"license":"MIT","bugs":{"url":"https://github.com/emeraldsanto/react-native-encrypted-storage/issues"},"homepage":"https://github.com/emeraldsanto/react-native-encrypted-storage#readme","publishConfig":{"registry":"https://registry.npmjs.org/"},"devDependencies":{"@types/jest":"26.0.0","@types/react":"16.9.19","@types/react-native":"0.62.13","eslint":"7.2.0","eslint-config-prettier":"7.0.0","eslint-plugin-prettier":"3.1.3","jest":"26.0.1","pod-install":"0.1.0","prettier":"2.0.5","react":"16.13.1","react-native":"^0.70.6","react-native-builder-bob":"^0.20.3","typescript":"4.1.3"},"peerDependencies":{"react":"*","react-native":"*"},"jest":{"preset":"react-native","modulePathIgnorePatterns":["<rootDir>/example/node_modules","<rootDir>/lib/"]},"eslintConfig":{"root":true,"extends":["@react-native-community","prettier"],"rules":{"prettier/prettier":["error",{"quoteProps":"consistent","singleQuote":true,"tabWidth":2,"trailingComma":"es5","useTabs":false}]}},"eslintIgnore":["node_modules/","lib/"],"prettier":{"quoteProps":"consistent","singleQuote":true,"tabWidth":2,"trailingComma":"es5","useTabs":false},"react-native-builder-bob":{"source":"src","output":"lib","targets":["commonjs","module",["typescript",{"project":"tsconfig.build.json"}]]},"directories":{"example":"example"},"gitHead":"3c9f56430a3e8f6d25049cd253dd7d4cf4603aa7","_id":"@alxss/react-native-encrypted-storage@1.0.0","_nodeVersion":"16.14.2","_npmVersion":"8.19.1","dist":{"integrity":"sha512-RRHtE+rAUsUV2a99W+Ab1Su8gz2dRSrpWw6B7rxaKQzNX1R/zZuhQDHU8l30wPJyYzTMPXA0Xwc9NrMzHYG8JA==","shasum":"5f30c4b574a0539d804584364cff71620f01ae71","tarball":"https://registry.npmjs.org/@alxss/react-native-encrypted-storage/-/react-native-encrypted-storage-1.0.0.tgz","fileCount":32,"unpackedSize":119938,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIHK7Flp+oG269XtNWNj0ms4HxouYy3+LSTtltiIGLqKdAiBXXfYMj8AIh1uUnrdqfrkmiNPzR5nGYao8pM3wOEmbAg=="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjqvUjACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmqY9w/+OOSEexqqa5aF7Mxollk9vY9e6SU1/F9++0WeOHG2g2OHk7KQ\r\nP2ucsQsA+6A3t/kbLFKBhRyExbEdJsFvJ048cDZ+dnsEb7tneSMDpldLWZ/d\r\nYbeEiBe4sQZEM16hMOwHJuFB+y0KFWVsYbCu9sUyFq4J6acpPmW+uRxX0Ozk\r\ngcxHmeNq8cidEtbZSfSsbP0y8uLF+e29emTduLlVX513fhS/PYe1uifBSVoq\r\nv6wR4lTz9oSveBK+FveMQ4fHkT3QjFbKuxF3HLtpJVBtWnY1gFGMQCKr2nU8\r\np92x+9NPJ61SHZ6YsnpFtcnFxKWgyt6dkpXVVN+6fJDl2/cCi1f898y0oZ1/\r\nPKXgbmweeJ3ob74o1EaBgsBB1RpoMLGUcl5p90XXh0rFUkj6FDlTPqvBXYHj\r\nJWJxfSeIG4/0FiQ/QY3c0s36ZwBNXhsWhft44nlqMvtAbz061iB+rKNDiW7o\r\nFheDdEXXtcc8+EusiG0mjF1/gXMJIgeSOQEKMmaqvnva0vQIdx5hLPFpbu3Y\r\n9qKAtbfmOHjHN8F6+pxiI1FXjHaZitdVT6agBZ86pxeoLfnFem9+eKs6HR7S\r\ngpcgXpLiSB5I8HIhyjwZZuz6AoTXIP4MwF/26Nhd064kkPMucmrBCWoFGJzM\r\nrZRaPTuEHmfRZr8Y26bcxyItuekUAU7yjbk=\r\n=I97k\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"alxss","email":"alexis.smadja@gmail.com"},"maintainers":[{"name":"alxss","email":"alexis.smadja@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/react-native-encrypted-storage_1.0.0_1672148259055_0.022957472824220337"},"_hasShrinkwrap":false}},"time":{"created":"2022-12-27T13:37:38.981Z","1.0.0":"2022-12-27T13:37:39.254Z","modified":"2022-12-27T13:37:39.416Z"},"maintainers":[{"name":"alxss","email":"alexis.smadja@gmail.com"}],"description":"A React Native wrapper over SharedPreferences and Keychain to provide a secure alternative to Async Storage","homepage":"https://github.com/emeraldsanto/react-native-encrypted-storage#readme","keywords":["react-native","ios","android"],"repository":{"type":"git","url":"git+https://github.com/emeraldsanto/react-native-encrypted-storage.git"},"author":{"name":"emeraldsanto","email":"yanick.belanger@yahoo.com","url":"https://github.com/emeraldsanto"},"bugs":{"url":"https://github.com/emeraldsanto/react-native-encrypted-storage/issues"},"license":"MIT","readme":"# React Native Encrypted Storage\nReact Native wrapper around SharedPreferences and Keychain to provide a secure alternative to [Async Storage](https://github.com/react-native-community/async-storage).\n\n## Why ?\n\n[Async Storage](https://github.com/react-native-community/async-storage) is great but it lacks security. This is less than ideal when storing sensitive data such as access tokens, payment information and so on. This module aims to solve this problem by providing a wrapper around Android's `EncryptedSharedPreferences` and iOS' `Keychain`, complete with support for TypeScript.\n\n## Version Requirements\n\n- Android API 21+ (5.0)\n- iOS 2.0\n\n## Installation\n\n### Via `yarn`\n\n```bash\n$ yarn add react-native-encrypted-storage\n```\n\n### Via `npm`\n\n```bash\n$ npm install react-native-encrypted-storage\n```\n\n## Linking\n\n- React Native 0.60+\n\nSince version 0.60, React Native supports auto linking. This means no additional step is needed on your end.\n\n- React Native <= 0.59\n\n```bash\n$ react-native link react-native-encrypted-storage\n```\n\nSpecial note for iOS using `cocoapods`, run:\n\n```bash\n$ npx pod-install\n```\n\n## Usage\n\nThis module exposes four (4) native functions to store, retrieve, remove and clear values. They can be used like so:\n\n### Import\n\n```js\nimport EncryptedStorage from 'react-native-encrypted-storage';\n```\n\n### Storing a value\n\n```js\nasync function storeUserSession() {\n    try {\n        await EncryptedStorage.setItem(\n            \"user_session\",\n            JSON.stringify({\n                age : 21,\n                token : \"ACCESS_TOKEN\",\n                username : \"emeraldsanto\",\n                languages : [\"fr\", \"en\", \"de\"]\n            })\n        );\n\n        // Congrats! You've just stored your first value!\n    } catch (error) {\n        // There was an error on the native side\n    }\n}\n```\n\n### Retrieving a value\n\n```js\nasync function retrieveUserSession() {\n    try {   \n        const session = await EncryptedStorage.getItem(\"user_session\");\n    \n        if (session !== undefined) {\n            // Congrats! You've just retrieved your first value!\n        }\n    } catch (error) {\n        // There was an error on the native side\n    }\n}\n```\n\n### Removing a value\n\n```js\nasync function removeUserSession() {\n    try {\n        await EncryptedStorage.removeItem(\"user_session\");\n        // Congrats! You've just removed your first value!\n    } catch (error) {\n        // There was an error on the native side\n    }\n}\n```\n\n### Clearing all previously saved values\n\n```js\nasync function clearStorage() {\n    try {\n        await EncryptedStorage.clear();\n        // Congrats! You've just cleared the device storage!\n    } catch (error) {\n        // There was an error on the native side\n    }\n}\n```\n\n### Error handling\n\nTake the `removeItem` example, an error can occur when trying to remove a value which does not exist, or for any other reason. This module forwards the native iOS Security framework error codes to help with debugging.\n\n```js\nasync function removeUserSession() {\n    try {\n        await EncryptedStorage.removeItem(\"user_session\");\n    } catch (error) {\n        // There was an error on the native side\n        // You can find out more about this error by using the `error.code` property\n        console.log(error.code); // ex: -25300 (errSecItemNotFound)\n    }\n}\n```\n\n## Note regarding `Keychain` persistence\n\nYou'll notice that the iOS `Keychain` is not cleared when your app is uninstalled, this is the expected behaviour. However, if you do want to achieve a different behaviour, you can use the below snippet to clear the `Keychain` on the first launch of your app.\n\n```objc\n// AppDelegate.m\n\n/**\n Deletes all Keychain items accessible by this app if this is the first time the user launches the app\n */\nstatic void ClearKeychainIfNecessary() {\n    // Checks wether or not this is the first time the app is run\n    if ([[NSUserDefaults standardUserDefaults] boolForKey:@\"HAS_RUN_BEFORE\"] == NO) {\n        // Set the appropriate value so we don't clear next time the app is launched\n        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@\"HAS_RUN_BEFORE\"];\n\n        NSArray *secItemClasses = @[\n            (__bridge id)kSecClassGenericPassword,\n            (__bridge id)kSecClassInternetPassword,\n            (__bridge id)kSecClassCertificate,\n            (__bridge id)kSecClassKey,\n            (__bridge id)kSecClassIdentity\n        ];\n\n        // Maps through all Keychain classes and deletes all items that match\n        for (id secItemClass in secItemClasses) {\n            NSDictionary *spec = @{(__bridge id)kSecClass: secItemClass};\n            SecItemDelete((__bridge CFDictionaryRef)spec);\n        }\n    }\n}\n\n@implementation AppDelegate\n\n- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions\n{\n    // Add this line to call the above function\n    ClearKeychainIfNecessary();\n\n    RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];\n    RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge moduleName:@\"APP_NAME\" initialProperties:nil];\n\n    rootView.backgroundColor = [UIColor colorWithRed:1.0f green:1.0f blue:1.0f alpha:1];\n\n    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];\n    UIViewController *rootViewController = [UIViewController new];\n    rootViewController.view = rootView;\n\n    self.window.rootViewController = rootViewController;\n    [self.window makeKeyAndVisible];\n\n    return YES;\n}\n\n// ...\n\n@end\n```\n\n# Limitations\n\nThere seems to be some confusion around the maximum size of items that can be stored, especially on iOS. According to this [StackOverflow question](https://stackoverflow.com/questions/13488793/is-there-any-length-limit-of-string-stored-in-keychain), the actual Keychain limit is much lower than what it should theoretically be. This does not affect Android as the `EncryptedSharedPreferences` API relies on the phone's storage, via XML files.\n\n## License\n\nMIT\n","readmeFilename":"README.md"}