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

Aes #10

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open

Aes #10

Show file tree
Hide file tree
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
1 change: 0 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
node_modules/
e2e/
RNSecureRandom/__tests__
36 changes: 33 additions & 3 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,51 @@ module.exports = {
mocha: true
},
globals: {
__DEV__: false
__DEV__: false,
device: false,
element: false,
by: false
},
extends: [
'eslint:recommended',
'plugin:react/recommended',
'plugin:prettier/recommended'
],
plugins: ['react', 'react-native', 'jasmine', 'detox'],
plugins: ['react', 'react-native', 'jasmine', 'detox', 'jsdoc'],
settings: {
react: {
pragma: 'React',
version: '16.5.0'
}
},
rules: {
'react/display-name': 'off'
'react/display-name': 'off',
'jsdoc/check-param-names': 2,
'jsdoc/check-tag-names': 2,
'jsdoc/check-types': 2,
'jsdoc/newline-after-description': 2,
'jsdoc/require-hyphen-before-param-description': 2,
'jsdoc/require-param': 2,
'jsdoc/require-param-description': 2,
'jsdoc/require-param-type': 2,
'jsdoc/require-returns-description': 2,
'jsdoc/require-returns-type': 2,
'require-jsdoc': [
2,
{
require: {
FunctionDeclaration: true,
MethodDefinition: true,
ClassDeclaration: true,
ArrowFunctionExpression: true
}
}
],
'valid-jsdoc': [
2,
{
requireReturn: false
}
]
}
};
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ node_js:
branches:
only:
- master
- develop
80 changes: 80 additions & 0 deletions ExampleGrinder/@
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* @format
*/
/*eslint no-unused-vars: "warn"*/
import React, { Component } from 'react';
import { Platform, StyleSheet, Text, View } from 'react-native';
import { randomBitGenerator } from '../lib/randomBitGenerator.js';
import { SSSA } from '../lib/sssa';
import { base64ToBits, bin2hex } from '../lib/utils';
const instructions = Platform.select({
ios: 'Press Cmd+R to reload,\n' + 'Cmd+D or shake for dev menu',
android:
'Double tap R on your keyboard to reload,\n' +
'Shake or press menu button for dev menu'
});

type Props = {};

export default class App extends Component<Props> {
state = { randomBits: '', shamirShares: [''] };
async componentDidMount() {
let randomNumber = await randomBitGenerator(14);
let sssa = new SSSA(3);
let secret = 'aaA=';
let shares = await sssa.generateShares(secret, 7, 2, 1);
this.setState({
randomBits: randomNumber,
shamirShares: shares,
shareLength: this.verifyLengthOfShare(secret, 3)
});
console.warn(bin2hex(shares[0]).length);
}
verifyLengthOfShare(secret, coeffLength) {
var secretLengthInBits = base64ToBits(secret);
var expectedLength =
(Math.ceil(secretLengthInBits.length / coeffLength) + 1) * coeffLength;
console.warn(expectedLength);
}
render() {
return (
<View style={styles.container}>
<Text testID="welcome" style={styles.welcome}>
{this.state.randomBits}
</Text>
<Text style={styles.instructions}>To get started, edit App.js</Text>
<Text testID="randombits" style={styles.instructions}>
{this.state.randomBits.length}
</Text>
<Text testID="shares" style={styles.instructions}>
{this.state.shamirShares.length}
</Text>
<Text testID="oneShare" style={styles.instructions}>
{this.state.shamirShares[0].length === this.state.shareLength}
</Text>
</View>
);
}
}

const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF'
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5
}
});
58 changes: 45 additions & 13 deletions ExampleGrinder/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,57 @@
*/
/*eslint no-unused-vars: "warn"*/
import React, { Component } from 'react';
import { Platform, StyleSheet, Text, View } from 'react-native';
import { generateSecureRandom } from '../RNSecureRandom/index';
const instructions = Platform.select({
ios: 'Press Cmd+R to reload,\n' + 'Cmd+D or shake for dev menu',
android:
'Double tap R on your keyboard to reload,\n' +
'Shake or press menu button for dev menu'
});

import { StyleSheet, Text, View } from 'react-native';
import { SSSA } from '../lib/sssa';
import { encryptAndSplitSecret, combineAndDecryptSecret } from '../index';
const secret = 'aaA=';
type Props = {};
/**
* Main App, demonstrating how to use react-native-sssa in a project
*/
export default class App extends Component<Props> {
state = { randomBits: '', shamirShares: [''], shareLength: 0, iv: '' };

/**Runs after component mounts
* Good place for data fetching
*/
async componentDidMount() {
let sssa = new SSSA(3);
let shares = await sssa.generateShares(secret, 7, 2, 100);
let combinedShares = sssa.combine(shares);
let sharesAndIv = await encryptAndSplitSecret('hadas zeilberger', 7, 7);
let combinedAndDecryptedSecret = await combineAndDecryptSecret(
sharesAndIv.shares,
sharesAndIv.iv
);
this.setState({
shamirShares: JSON.stringify(shares),
regeneratedSecret: combinedShares,
sharesandiv: JSON.stringify(sharesAndIv),
combinedSecret: combinedAndDecryptedSecret
});
}
/**
*Renders the App
*@returns {React.Element} rendered component
*/
render() {
return (
<View style={styles.container}>
<Text testID="welcome" style={styles.welcome}>
Welcome to React Native!
<Text style={styles.welcome}>Secret</Text>
<Text style={styles.instructions}>{secret}</Text>
<Text testID="shares" style={styles.welcome}>
Array of shares
</Text>
<Text style={styles.instructions}>{this.state.shamirShares}</Text>
<Text style={styles.welcome}>Regenerated Secret</Text>
<Text testID="secret" style={styles.instructions}>
{this.state.regeneratedSecret}
</Text>
<Text style={styles.instructions}>To get started, edit App.js</Text>
<Text style={styles.instructions}>{instructions}</Text>
<Text style={styles.welcome}>shares and iv</Text>
<Text style={styles.instructions}>{this.state.sharesandiv}</Text>
<Text style={styles.welcome}>Combined and decrypted secret</Text>
<Text style={styles.instructions}>{this.state.combinedSecret}</Text>
</View>
);
}
Expand Down
Loading