feat: Keychain items array #765
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This MR makes it possible to store an array of items in the keychain.
Reason for MR
I am raising this MR because I wanted to migrate our project from using
react-native-sensitive-infoto usingreact-native-keychain. This repo is actually maintained and has a larger community using it. Also the sensitive info library seems to stop working after upgrading RN0.76.1+mCodex/react-native-sensitive-info#424 (comment). So, time to move on!However, during testing I found that this library only returns a single object from the keychain. Which seems to be intended looking at comments here: #36 (comment), I should be serialising my data structure and storing it as a string in this single object.
This would be fine if I was starting a new project, but losing access to data already in the keychain was not acceptable as we would lose important login keys etc. So I decided to convert the functionality over to this library. Hopefully this will help others convert to this library and add some nice new functionality for existing users.
Changes
I have added these functions:
getItemForKeygetAllItemssetItemForKeyremoveItemForKeyclearItems.Of course a requirement for me was to mirror as best as possible the behaviour of the functions in
react-native-sensitive-info. So I can preserve my data after migrating to this library.I feel like the iOS implementation fits in nicely with the existing code. But I will admit that the Android side was more complex, you guys have a
DataStorePrefsStorageclass that I wasn't sure how exactly to integrate with, so I played it safe and kept to a simple implementation within the mainKeychainModule. Would appreciate any pointers for this.Thanks and any feedback is welcome 🙏