React Native Storage Module - tKey JS SDK
@tkey/react-native-storage
The React Native Storage Module helps you store and recall key shares from the React Native Encrypted Store/ Expo Secure Store.
Installation
- npm
- Yarn
- pnpm
npm install --save @tkey/react-native-storage
yarn add @tkey/react-native-storage
pnpm add @tkey/react-native-storage
Initialization
- Bare React Native
- Expo React Native
import { ReactNativeStorageModule } from "@tkey/react-native-storage";
import EncryptedStorage from "react-native-encrypted-storage";
const reactNativeStorageModule = new ReactNativeStorageModule(EncryptedStorage);
import { ReactNativeStorageModule } from "@tkey/react-native-storage";
import * as SecureStore from "expo-secure-store";
const reactNativeStorageModule = new ReactNativeStorageModule(SecureStore);
Usage
With the ReactNativeStorageModules
, you have access to the multiple functions as mentioned in the
type reference, however, the most important ones are:
Get ShareStore from Storage
getStoreFromReactNativeStorage(): Promise<ShareStore>;
Example
const share = await(
tKeyInstance.modules.reactNativeStorage as ReactNativeStorageModule,
).getStoreFromReactNativeStorage();
Store Device Share
storeDeviceShare(deviceShareStore: ShareStore, customDeviceInfo?: StringifiedType): Promise<void>;
This function takes the following arguments:
deviceShareStore
: TheShareStore
object to store.customDeviceInfo?
: Optional, Information about the device to store.
Example
const generateShareResult = await tKeyInstance.generateNewShare();
const share = await tKeyInstance.outputShareStore(generateShareResult.newShareIndex);
await(tKeyInstance.modules.reactNativeStorage as ReactNativeStorageModule).storeDeviceShare(share);
Type Reference
ReactNativeStorageModule
export default class ReactNativeStorageModule implements IModule {
moduleName: string;
tbSDK: ITKeyApi;
private keyStore;
constructor(storage: SecureStore | EncryptedStorage);
setModuleReferences(tbSDK: ITKeyApi): void;
initialize(): Promise<void>;
storeDeviceShare(deviceShareStore: ShareStore, customDeviceInfo?: StringifiedType): Promise<void>;
storeShareOnReactNativeStorage(share: ShareStore): Promise<void>;
getStoreFromReactNativeStorage(): Promise<ShareStore>;
inputShareFromReactNativeStorage(): Promise<void>;
}
ShareStore
class ShareStore implements ISerializable {
share: Share;
polynomialID: PolynomialID;
constructor(share: Share, polynomialID: PolynomialID);
static fromJSON(value: StringifiedType): ShareStore;
toJSON(): StringifiedType;
}
interface ISerializable {
toJSON(): StringifiedType;
}