Skip to content
This repository was archived by the owner on Feb 24, 2018. It is now read-only.

Add react-native optimizations #580

Merged
merged 2 commits into from
Nov 11, 2017
Merged
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
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,9 @@ npm-debug.log

es
lib

ios/RNAWSCognito.xcodeproj/xcuserdata/
ios/RNAWSCognito.project.xcworkspace/xcuserdata/
ios/RNAWSCognito.xcodeproj/project.xcworkspace/xcuserdata/

.DS_Store
25 changes: 25 additions & 0 deletions NOTICE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,28 @@ Copyright 2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.

This product includes software developed by Tom Wu at Stanford University.
http://www-cs-students.stanford.edu/%7Etjw/jsbn/jsbn.js

=========================================================================
== JKBigInteger library Notice ==
=========================================================================

This product includes the JKBigInteger library licensed under the MIT license.

Copyright (C) 2013 Jānis Kiršteins

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,27 @@ migration.

* Build your application bundle with `npm run build`

## Install for React Native

See [Using NPM and Webpack](https://github.com/aws/amazon-cognito-identity-js#using-npm-and-webpack) for more information on NPM.

* Install and add to your dependencies the Amazon Cognito Identity SDK for JavaScript:

```
npm install --save amazon-cognito-identity-js
```

* Install react-native-cli if you have not already:

```
npm install -g react-native-cli
```

* Link the native modules to your project:

```
react-native link amazon-cognito-identity-js
```

## Configuration

Expand Down
34 changes: 34 additions & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
buildscript {
repositories {
jcenter()
}

dependencies {
classpath 'com.android.tools.build:gradle:1.3.1'
}
}

apply plugin: 'com.android.library'

android {
compileSdkVersion 23
buildToolsVersion "23.0.1"

defaultConfig {
minSdkVersion 16
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
lintOptions {
abortOnError false
}
}

repositories {
mavenCentral()
}

dependencies {
compile 'com.facebook.react:react-native:+'
}
4 changes: 4 additions & 0 deletions android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.amazonaws">

</manifest>
73 changes: 73 additions & 0 deletions android/src/main/java/com/amazonaws/RNAWSCognitoModule.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package com.amazonaws;

import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.Callback;
import java.math.BigInteger;

public class RNAWSCognitoModule extends ReactContextBaseJavaModule {

private final ReactApplicationContext reactContext;

private static final String HEX_N = "FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1"
+ "29024E088A67CC74020BBEA63B139B22514A08798E3404DD"
+ "EF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245"
+ "E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED"
+ "EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3D"
+ "C2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F"
+ "83655D23DCA3AD961C62F356208552BB9ED529077096966D"
+ "670C354E4ABC9804F1746C08CA18217C32905E462E36CE3B"
+ "E39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9"
+ "DE2BCBF6955817183995497CEA956AE515D2261898FA0510"
+ "15728E5A8AAAC42DAD33170D04507A33A85521ABDF1CBA64"
+ "ECFB850458DBEF0A8AEA71575D060C7DB3970F85A6E1E4C7"
+ "ABF5AE8CDB0933D71E8C94E04A25619DCEE3D2261AD2EE6B"
+ "F12FFA06D98A0864D87602733EC86A64521F2B18177B200C"
+ "BBE117577A615D6C770988C0BAD946E208E24FA074E5AB31"
+ "43DB5BFCE0FD108E4B82D120A93AD2CAFFFFFFFFFFFFFFFF";

private static final BigInteger N = new BigInteger(HEX_N, 16);

public RNAWSCognitoModule(ReactApplicationContext reactContext) {
super(reactContext);
this.reactContext = reactContext;
}

@Override
public String getName() {
return "RNAWSCognito";
}

@ReactMethod
public void computeModPow(final ReadableMap values, final Callback callback) {
try {
final BigInteger target = new BigInteger(values.getString("target"), 16);
final BigInteger value = new BigInteger(values.getString("value"), 16);
final BigInteger modifier = new BigInteger(values.getString("modifier"), 16);
final BigInteger result = target.modPow(value, modifier);
callback.invoke(null, result.toString(16));
} catch (final Exception e) {
callback.invoke(e.getMessage(), null);
}
}

@ReactMethod
public void computeS(final ReadableMap values, final Callback callback) {
try {
final BigInteger g = new BigInteger(values.getString("g"), 16);
final BigInteger x = new BigInteger(values.getString("x"), 16);
final BigInteger k = new BigInteger(values.getString("k"), 16);
final BigInteger a = new BigInteger(values.getString("a"), 16);
final BigInteger b = new BigInteger(values.getString("b"), 16);
final BigInteger u = new BigInteger(values.getString("u"), 16);
final BigInteger exp = a.add(u.multiply(x));
final BigInteger base = b.subtract(k.multiply(g.modPow(x, N)));
final BigInteger result = base.modPow(exp, N).mod(N);
callback.invoke(null, result.toString(16));
} catch (final Exception e) {
callback.invoke(e.getMessage(), null);
}
}
}
27 changes: 27 additions & 0 deletions android/src/main/java/com/amazonaws/RNAWSCognitoPackage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.amazonaws;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import com.facebook.react.ReactPackage;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.uimanager.ViewManager;
import com.facebook.react.bridge.JavaScriptModule;

public class RNAWSCognitoPackage implements ReactPackage {
@Override
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
return Arrays.<NativeModule>asList(new RNAWSCognitoModule(reactContext));
}

public List<Class<? extends JavaScriptModule>> createJSModules() {
return Collections.emptyList();
}

@Override
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
return Collections.emptyList();
}
}
Loading