Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Readme #13

Merged
merged 2 commits into from
Nov 14, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 32 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,37 @@ $ yarn add react-native-sssa react-native-securerandom react-native-aes-crypto r
$ react-native link
```

This package relies on [react-native-securerandom](https://github.com/rh389/react-native-securerandom) to provide entropy in shamir's secret sharing algorithm, [react-native-aes-crypto] to provide encryption to secret before being processed by sssa, and [react-native-secure-storage] to safetly store and retrieve private key
It has native dependencies that need linking.
If need be,
their documentation provides instructions for [manual linking](https://github.com/rh389/react-native-securerandom#manual-linking)
**react-native-securerandom** is used to provide entropy in shamir's secret sharing algorithm

**react-native-aes-crypto** is used to encrypt a file with AES before being encrypted with SSSA

**react-native-secure-storage** is used to securely stored the private key

If need be,
their documentation provides instructions for manual linking:
[react-native-securerandom](https://github.com/rh389/react-native-securerandom#manual-linking)
[react-native-secure-storage](https://github.com/oyyq99999/react-native-secure-storage#manual-installation)
[react-native-aes-crypto] (https://github.com/tectiv3/react-native-aes#Installation)
## Usage
To put a plain text secret through the entire pipeline (encrypt with. AES, generate shares of the secret with Shamir's Secret Sharing Algorithm, and distribute shares to IPFS (via Infura), use the following:

```javascript
import {encryptSplitAndSpreadSecret} from 'react-native-sssa';
let ipfsHashes = await encryptSplitAndSpreadSecret(secret,numShares,threshold)
```
To collect shares back from IPFS, use Shamir's secret sharing algorithm to reconstruct the encrypted file, and then decrypt the file back to the plain-text secret, do:

```javascript
import {collectCombineAndDecryptSecret} from 'react-native-sssa';
let secret = await collectCombineAndDecryptSecret(ipfsHashes)
```
If you just want to use Shamir's Secret Sharing Algorithm alone without encryption and IPFS, do the following:

```javascript
import SSSA from 'react-native-sssa';
//This does secret sharing with 3 bit coefficients in the field GF(2^3).
let sssa = new SSSA(3);
let shares = sssa.generateShares(base64Secret,numShares,threshold);
let secret = sssa.combine(shares);