react-native-sssa
v0.1.0
Published
shamir secret sharing algorithm for react-native
Downloads
12
Maintainers
Readme
A library to generate cryptographically secure shares of a secret.
Installation
$ yarn add react-native-sssa react-native-securerandom react-native-aes-crypto react-native-secure-storage
$ react-native link
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 processed with SSSA
react-native-secure-storage is used to securely stored the private key
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:
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:
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:
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);