Skip to main content

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 install --save @tkey/react-native-storage

Initialization

import { ReactNativeStorageModule } from "@tkey/react-native-storage";
import EncryptedStorage from "react-native-encrypted-storage";
const reactNativeStorageModule = new ReactNativeStorageModule(EncryptedStorage);

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: The ShareStore 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;
}