Skip to content

Commit

Permalink
Initial release
Browse files Browse the repository at this point in the history
  • Loading branch information
chaitanyapotti committed Aug 3, 2020
1 parent 196f179 commit d2a71c1
Show file tree
Hide file tree
Showing 14 changed files with 38 additions and 34 deletions.
8 changes: 3 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 29
compileSdkVersion 30
buildToolsVersion "29.0.3"

defaultConfig {
applicationId "org.torusresearch.torusdirectandroid"
minSdkVersion 26
targetSdkVersion 29
targetSdkVersion 30
versionCode 1
versionName "1.0"

Expand Down Expand Up @@ -42,11 +42,9 @@ android {

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.browser:browser:1.2.0'
implementation 'com.google.androidbrowserhelper:androidbrowserhelper:1.2.0'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
testImplementation 'junit:junit:4.13'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation project(path: ':torusdirect')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@
import org.torusresearch.torusdirect.types.TorusLoginResponse;
import org.torusresearch.torusdirect.types.TorusNetwork;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executors;

import java8.util.concurrent.CompletableFuture;

public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -31,19 +32,19 @@ protected void onCreate(Bundle savedInstanceState) {
public void launch(View view) {
DirectSdkArgs args = new DirectSdkArgs("torusapp://org.torusresearch.torusdirectandroid/redirect", TorusNetwork.TESTNET, "0x4023d2a0D330bF11426B12C6144Cfb96B7fa6183");
TorusDirectSdk sdk = new TorusDirectSdk(args, this);
CompletableFuture<TorusLoginResponse> torusLoginResponseCompletableFuture = sdk.triggerLogin(new SubVerifierDetails(LoginType.GOOGLE,
"google-lrc",
"221898609709-obfn3p63741l5333093430j3qeiinaa8.apps.googleusercontent.com",
new Auth0ClientOptions.Auth0ClientOptionsBuilder("").build()));
Executors.newFixedThreadPool(10).submit(() -> {
try {
CompletableFuture<TorusLoginResponse> torusLoginResponseCompletableFuture = sdk.triggerLogin(new SubVerifierDetails(LoginType.GOOGLE,
"google-lrc",
"221898609709-obfn3p63741l5333093430j3qeiinaa8.apps.googleusercontent.com",
new Auth0ClientOptions.Auth0ClientOptionsBuilder("").build()));
TorusLoginResponse torusLoginResponse = torusLoginResponseCompletableFuture.get();
Log.d(MainActivity.class.getSimpleName(), "Private Key:: " + torusLoginResponse.getPrivateKey());
Log.d(MainActivity.class.getSimpleName(), "Public Address:: " + torusLoginResponse.getPublicAddress());
runOnUiThread(() -> ((TextView)findViewById(R.id.output)).setText("Private Key:: " + torusLoginResponse.getPrivateKey() + "\n" + "Public Address:: " + torusLoginResponse.getPublicAddress()));
Log.d(MainActivity.class.getSimpleName(), "Private Key: " + torusLoginResponse.getPrivateKey());
Log.d(MainActivity.class.getSimpleName(), "Public Address: " + torusLoginResponse.getPublicAddress());
runOnUiThread(() -> ((TextView) findViewById(R.id.output)).setText("Private Key: " + torusLoginResponse.getPrivateKey() + "\n" + "Public Address: " + torusLoginResponse.getPublicAddress()));
} catch (ExecutionException | InterruptedException e) {
e.printStackTrace();
runOnUiThread(() -> ((TextView)findViewById(R.id.output)).setText("Something went wrong."));
runOnUiThread(() -> ((TextView) findViewById(R.id.output)).setText("Something went wrong."));
}
});
}
Expand Down
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ buildscript {
dependencies {
classpath 'com.android.tools.build:gradle:4.0.1'
classpath "de.mannodermaus.gradle.plugins:android-junit5:1.3.2.0"
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'


// NOTE: Do not place your application dependencies here; they belong
Expand Down
12 changes: 8 additions & 4 deletions torusdirect/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'

group='org.torusresearch'

android {
compileSdkVersion 30
Expand Down Expand Up @@ -29,13 +32,14 @@ android {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
api 'androidx.browser:browser:1.2.0'
api 'com.google.androidbrowserhelper:androidbrowserhelper:1.3.2'
// api 'com.google.androidbrowserhelper:androidbrowserhelper:1.3.2'
implementation 'com.auth0:java-jwt:3.10.3'
implementation 'com.squareup.okhttp3:okhttp:4.8.0'
implementation 'com.github.torusresearch:fetch-node-details-java:1.0.5'
implementation 'org.torusresearch:torus-utils-java:1.0.0'
implementation 'org.torusresearch:fetch-node-details-java:1.0.7'
implementation 'org.torusresearch:torus-utils-java:1.0.1'
implementation 'com.google.code.gson:gson:2.8.6'
implementation 'org.web3j:crypto:4.6.1'
//noinspection GradleDependency
api 'org.web3j:crypto:4.6.0-android'
implementation 'androidx.appcompat:appcompat:1.1.0'
testImplementation "org.junit.jupiter:junit-jupiter-api:5.6.2"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:5.6.2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;

import java8.util.concurrent.CompletableFuture;


public class TorusDirectSdk {
private final DirectSdkArgs directSdkArgs;
Expand Down Expand Up @@ -66,8 +67,11 @@ public CompletableFuture<TorusLoginResponse> triggerLogin(SubVerifierDetails sub
return this.getTorusKey(subVerifierDetails.getVerifier(), userInfo.getVerifierId(), verifierParams, !Helpers.isEmpty(response.getIdToken()) ? response.getIdToken() : response.getAccessToken());
}).thenApplyAsync(torusKey -> {
TorusVerifierResponse torusVerifierResponse = torusVerifierResponseAtomicReference.get();
LoginWindowResponse loginWindowResponse = loginWindowResponseAtomicReference.get();
TorusVerifierUnionResponse response = new TorusVerifierUnionResponse(torusVerifierResponse.getEmail(), torusVerifierResponse.getName(), torusVerifierResponse.getProfileImage(),
torusVerifierResponse.getVerifier(), torusVerifierResponse.getVerifierId(), torusVerifierResponse.getTypeOfLogin());
response.setAccessToken(loginWindowResponse.getAccessToken());
response.setIdToken(loginWindowResponse.getIdToken());
return new TorusLoginResponse(response, torusKey.getPrivateKey(), torusKey.getPublicAddress());
});
}
Expand Down Expand Up @@ -141,7 +145,7 @@ public CompletableFuture<TorusKey> getTorusKey(String verifier, String verifierI
}
}).thenApplyAsync(shareResponse -> {
if (shareResponse == null) return null;
if (!shareResponse.getEthAddress().equals(torusPublicKeyAtomicReference.get().getAddress()))
if (!shareResponse.getEthAddress().toLowerCase().equals(torusPublicKeyAtomicReference.get().getAddress().toLowerCase()))
return null;
return new TorusKey(shareResponse.getPrivKey(), shareResponse.getEthAddress());
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@

import java.util.Base64;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;

import java8.util.concurrent.CompletableFuture;

public abstract class AbstractLoginHandler implements ILoginHandler {
protected final String nonce = UUID.randomUUID().toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
import org.torusresearch.torusdirect.utils.Helpers;
import org.torusresearch.torusdirect.utils.HttpHelpers;

import java.util.concurrent.CompletableFuture;

import java8.util.concurrent.CompletableFuture;
import okhttp3.HttpUrl;
import okhttp3.internal.http2.Header;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
import org.torusresearch.torusdirect.types.TorusVerifierResponse;
import org.torusresearch.torusdirect.utils.HttpHelpers;

import java.util.concurrent.CompletableFuture;

import java8.util.concurrent.CompletableFuture;
import okhttp3.HttpUrl;
import okhttp3.internal.http2.Header;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
import org.torusresearch.torusdirect.types.TorusVerifierResponse;
import org.torusresearch.torusdirect.utils.HttpHelpers;

import java.util.concurrent.CompletableFuture;

import java8.util.concurrent.CompletableFuture;
import okhttp3.HttpUrl;
import okhttp3.internal.http2.Header;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.CompletableFuture;

import java8.util.concurrent.CompletableFuture;
import okhttp3.HttpUrl;
import okhttp3.internal.http2.Header;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
import org.torusresearch.torusdirect.types.TorusVerifierResponse;
import org.torusresearch.torusdirect.utils.HttpHelpers;

import java.util.concurrent.CompletableFuture;

import java8.util.concurrent.CompletableFuture;
import okhttp3.HttpUrl;
import okhttp3.internal.http2.Header;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
import org.torusresearch.torusdirect.types.TorusVerifierResponse;
import org.torusresearch.torusdirect.utils.HttpHelpers;

import java.util.concurrent.CompletableFuture;

import java8.util.concurrent.CompletableFuture;
import okhttp3.HttpUrl;
import okhttp3.internal.http2.Header;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import org.torusresearch.torusdirect.types.LoginWindowResponse;
import org.torusresearch.torusdirect.types.TorusVerifierResponse;

import java.util.concurrent.CompletableFuture;
import java8.util.concurrent.CompletableFuture;

public interface ILoginHandler {
CompletableFuture<TorusVerifierResponse> getUserInfo(LoginWindowResponse params);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

import java.io.IOException;
import java.util.Objects;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;

import java8.util.concurrent.CompletableFuture;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.MediaType;
Expand Down

0 comments on commit d2a71c1

Please sign in to comment.