Commit 7816ae81 authored by Marek Kotewicz's avatar Marek Kotewicz
Browse files

random words generator using sjcl and first working jest unit tests

parent 6b613e1c
import React from 'react';
import { View } from 'react-native'
import Index from '../index.android.js';
import 'react-native'
import App from '../src/components/App'
// Note: test renderer must be required after react-native.
import renderer from 'react-test-renderer';
it('renders correctly', () => {
const tree = renderer.create(
<View/>
<App/>
)
});
import React from 'react';
import { View } from 'react-native'
import Index from '../index.ios.js'
import 'react-native'
import App from '../src/components/App'
// Note: test renderer must be required after react-native.
import renderer from 'react-test-renderer';
it('renders correctly', () => {
const tree = renderer.create(
<Index/>
<App/>
)
});
......@@ -126,6 +126,7 @@ android {
}
dependencies {
compile project(':react-native-randombytes')
compile project(':react-native-camera')
compile fileTree(dir: "libs", include: ["*.jar"])
compile "com.android.support:appcompat-v7:23.0.1"
......
......@@ -4,6 +4,7 @@ import android.app.Application;
import android.util.Log;
import com.facebook.react.ReactApplication;
import com.bitgo.randombytes.RandomBytesPackage;
import com.lwansbrough.RCTCamera.RCTCameraPackage;
import com.facebook.react.ReactInstanceManager;
import com.facebook.react.ReactNativeHost;
......@@ -26,6 +27,7 @@ public class MainApplication extends Application implements ReactApplication {
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new RandomBytesPackage(),
new RCTCameraPackage()
);
}
......
rootProject.name = 'NativeSigner'
include ':react-native-randombytes'
project(':react-native-randombytes').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-randombytes/android')
include ':react-native-camera'
project(':react-native-camera').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-camera/android')
......
......@@ -25,6 +25,8 @@
5E9157361DD0AC6A00FF2AA8 /* libRCTAnimation.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 5E9157331DD0AC6500FF2AA8 /* libRCTAnimation.a */; };
832341BD1AAA6AB300B99B32 /* libRCTText.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 832341B51AAA6A8300B99B32 /* libRCTText.a */; };
8E82ABE6A351418899C5974A /* libRCTCamera.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 0462DF64F1D24C8E8B6E90B1 /* libRCTCamera.a */; };
AA0792CD4D7F417B8C8D17CF /* libRNRandomBytes.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 24A2115276994AD5AED9321A /* libRNRandomBytes.a */; };
EAB49CE81E482E090066C283 /* libRNRandomBytes.a in Frameworks */ = {isa = PBXBuildFile; fileRef = EAB49CE71E482DBF0066C283 /* libRNRandomBytes.a */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
......@@ -217,6 +219,13 @@
remoteGlobalIDString = 4107012F1ACB723B00C6AA39;
remoteInfo = RCTCamera;
};
EAB49CE61E482DBF0066C283 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 47092C944A6546D5A864B424 /* RNRandomBytes.xcodeproj */;
proxyType = 2;
remoteGlobalIDString = 73EEC9391BFE4B1D00D468EB;
remoteInfo = RNRandomBytes;
};
/* End PBXContainerItemProxy section */
/* Begin PBXFileReference section */
......@@ -240,6 +249,8 @@
13B07FB61A68108700A75B9A /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = NativeSigner/Info.plist; sourceTree = "<group>"; };
13B07FB71A68108700A75B9A /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = main.m; path = NativeSigner/main.m; sourceTree = "<group>"; };
146833FF1AC3E56700842450 /* React.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = React.xcodeproj; path = "../node_modules/react-native/React/React.xcodeproj"; sourceTree = "<group>"; };
24A2115276994AD5AED9321A /* libRNRandomBytes.a */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = archive.ar; path = libRNRandomBytes.a; sourceTree = "<group>"; };
47092C944A6546D5A864B424 /* RNRandomBytes.xcodeproj */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = "wrapper.pb-project"; name = RNRandomBytes.xcodeproj; path = "../node_modules/react-native-randombytes/RNRandomBytes.xcodeproj"; sourceTree = "<group>"; };
5E91572D1DD0AC6500FF2AA8 /* RCTAnimation.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTAnimation.xcodeproj; path = "../node_modules/react-native/Libraries/NativeAnimation/RCTAnimation.xcodeproj"; sourceTree = "<group>"; };
78C398B01ACF4ADC00677621 /* RCTLinking.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTLinking.xcodeproj; path = "../node_modules/react-native/Libraries/LinkingIOS/RCTLinking.xcodeproj"; sourceTree = "<group>"; };
821AED75338B40468A2A8B7A /* RCTCamera.xcodeproj */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = "wrapper.pb-project"; name = RCTCamera.xcodeproj; path = "../node_modules/react-native-camera/ios/RCTCamera.xcodeproj"; sourceTree = "<group>"; };
......@@ -251,6 +262,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
EAB49CE81E482E090066C283 /* libRNRandomBytes.a in Frameworks */,
140ED2AC1D01E1AD002B40FF /* libReact.a in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
......@@ -271,6 +283,7 @@
00C302EA1ABCBA2D00DB3ED1 /* libRCTVibration.a in Frameworks */,
139FDEF61B0652A700C62182 /* libRCTWebSocket.a in Frameworks */,
8E82ABE6A351418899C5974A /* libRCTCamera.a in Frameworks */,
AA0792CD4D7F417B8C8D17CF /* libRNRandomBytes.a in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......@@ -416,6 +429,7 @@
00C302DF1ABCB9EE00DB3ED1 /* RCTVibration.xcodeproj */,
139FDEE61B06529A00C62182 /* RCTWebSocket.xcodeproj */,
821AED75338B40468A2A8B7A /* RCTCamera.xcodeproj */,
47092C944A6546D5A864B424 /* RNRandomBytes.xcodeproj */,
);
name = Libraries;
sourceTree = "<group>";
......@@ -458,6 +472,14 @@
name = Products;
sourceTree = "<group>";
};
EAB49CC91E482DBE0066C283 /* Products */ = {
isa = PBXGroup;
children = (
EAB49CE71E482DBF0066C283 /* libRNRandomBytes.a */,
);
name = Products;
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
......@@ -576,6 +598,10 @@
ProductGroup = 146834001AC3E56700842450 /* Products */;
ProjectRef = 146833FF1AC3E56700842450 /* React.xcodeproj */;
},
{
ProductGroup = EAB49CC91E482DBE0066C283 /* Products */;
ProjectRef = 47092C944A6546D5A864B424 /* RNRandomBytes.xcodeproj */;
},
);
projectRoot = "";
targets = (
......@@ -768,6 +794,13 @@
remoteRef = EA75C3411E3F45880098CCC9 /* PBXContainerItemProxy */;
sourceTree = BUILT_PRODUCTS_DIR;
};
EAB49CE71E482DBF0066C283 /* libRNRandomBytes.a */ = {
isa = PBXReferenceProxy;
fileType = archive.ar;
path = libRNRandomBytes.a;
remoteRef = EAB49CE61E482DBF0066C283 /* PBXContainerItemProxy */;
sourceTree = BUILT_PRODUCTS_DIR;
};
/* End PBXReferenceProxy section */
/* Begin PBXResourcesBuildPhase section */
......@@ -862,6 +895,7 @@
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"\"$(SRCROOT)/$(TARGET_NAME)\"",
"\"$(SRCROOT)/$(TARGET_NAME)\"",
);
OTHER_LDFLAGS = "-lc++";
PRODUCT_NAME = "$(TARGET_NAME)";
......@@ -881,6 +915,7 @@
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"\"$(SRCROOT)/$(TARGET_NAME)\"",
"\"$(SRCROOT)/$(TARGET_NAME)\"",
);
OTHER_LDFLAGS = "-lc++";
PRODUCT_NAME = "$(TARGET_NAME)";
......
......@@ -13,7 +13,8 @@
"react-native-router-flux": "^3.37.0",
"react-native-tabs": "^1.0.9",
"react-redux": "^5.0.2",
"redux": "^3.6.0"
"redux": "^3.6.0",
"sjcl": "^1.0.6"
},
"devDependencies": {
"babel-jest": "18.0.0",
......@@ -24,6 +25,8 @@
},
"jest": {
"preset": "react-native",
"setupFiles": ["<rootDir>/jest-setup.js"]
"setupFiles": [
"<rootDir>/jest-setup.js"
]
}
}
//import words from '../../res/words.json'
import sjcl from 'sjcl'
import words from '../../res/words.json'
//export default function random() {
//var buf = new Uint16Array(11)
//crypto.getRandomValues(buf)
//buf.map(n => words[n % words.length]).join(' ')
//}
export function random() {
let count = 11
let paranoia = 10
let buf = sjcl.random.randomWords(count, paranoia)
return buf.map(n => words[Math.abs(n) % words.length]).join(' ')
}
import { random } from './words'
describe('words', () => {
it('should create a list of 10 random words', () => {
let randomWords = random()
let count = randomWords.split(' ').length
expect(count).toEqual(11)
})
})
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment