From d2a71c1e14f3a7195486fc93a2cf0ecb099045ee Mon Sep 17 00:00:00 2001 From: chaitanyapotti Date: Mon, 3 Aug 2020 17:13:35 +0800 Subject: [PATCH] Initial release --- app/build.gradle | 8 +++----- .../torusdirectandroid/MainActivity.java | 19 ++++++++++--------- build.gradle | 1 + torusdirect/build.gradle | 12 ++++++++---- .../torusdirect/TorusDirectSdk.java | 8 ++++++-- .../handlers/AbstractLoginHandler.java | 3 ++- .../torusdirect/handlers/DiscordHandler.java | 3 +-- .../torusdirect/handlers/FacebookHandler.java | 3 +-- .../torusdirect/handlers/GoogleHandler.java | 3 +-- .../torusdirect/handlers/JwtHandler.java | 2 +- .../torusdirect/handlers/RedditHandler.java | 3 +-- .../torusdirect/handlers/TwitchHandler.java | 3 +-- .../torusdirect/interfaces/ILoginHandler.java | 2 +- .../torusdirect/utils/HttpHelpers.java | 2 +- 14 files changed, 38 insertions(+), 34 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index d2160f5..58a013b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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" @@ -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') diff --git a/app/src/main/java/org/torusresearch/torusdirectandroid/MainActivity.java b/app/src/main/java/org/torusresearch/torusdirectandroid/MainActivity.java index cecdfa6..1f95895 100644 --- a/app/src/main/java/org/torusresearch/torusdirectandroid/MainActivity.java +++ b/app/src/main/java/org/torusresearch/torusdirectandroid/MainActivity.java @@ -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) { @@ -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 torusLoginResponseCompletableFuture = sdk.triggerLogin(new SubVerifierDetails(LoginType.GOOGLE, - "google-lrc", - "221898609709-obfn3p63741l5333093430j3qeiinaa8.apps.googleusercontent.com", - new Auth0ClientOptions.Auth0ClientOptionsBuilder("").build())); Executors.newFixedThreadPool(10).submit(() -> { try { + CompletableFuture 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.")); } }); } diff --git a/build.gradle b/build.gradle index 9da5b53..915e2ea 100644 --- a/build.gradle +++ b/build.gradle @@ -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 diff --git a/torusdirect/build.gradle b/torusdirect/build.gradle index 0c18ab6..2bbc692 100644 --- a/torusdirect/build.gradle +++ b/torusdirect/build.gradle @@ -1,4 +1,7 @@ apply plugin: 'com.android.library' +apply plugin: 'com.github.dcendents.android-maven' + +group='org.torusresearch' android { compileSdkVersion 30 @@ -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" diff --git a/torusdirect/src/main/java/org/torusresearch/torusdirect/TorusDirectSdk.java b/torusdirect/src/main/java/org/torusresearch/torusdirect/TorusDirectSdk.java index e555ff7..f486d67 100644 --- a/torusdirect/src/main/java/org/torusresearch/torusdirect/TorusDirectSdk.java +++ b/torusdirect/src/main/java/org/torusresearch/torusdirect/TorusDirectSdk.java @@ -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; @@ -66,8 +67,11 @@ public CompletableFuture 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()); }); } @@ -141,7 +145,7 @@ public CompletableFuture 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()); }); diff --git a/torusdirect/src/main/java/org/torusresearch/torusdirect/handlers/AbstractLoginHandler.java b/torusdirect/src/main/java/org/torusresearch/torusdirect/handlers/AbstractLoginHandler.java index f492264..fa7b902 100644 --- a/torusdirect/src/main/java/org/torusresearch/torusdirect/handlers/AbstractLoginHandler.java +++ b/torusdirect/src/main/java/org/torusresearch/torusdirect/handlers/AbstractLoginHandler.java @@ -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(); diff --git a/torusdirect/src/main/java/org/torusresearch/torusdirect/handlers/DiscordHandler.java b/torusdirect/src/main/java/org/torusresearch/torusdirect/handlers/DiscordHandler.java index ea0af91..bceb9bc 100644 --- a/torusdirect/src/main/java/org/torusresearch/torusdirect/handlers/DiscordHandler.java +++ b/torusdirect/src/main/java/org/torusresearch/torusdirect/handlers/DiscordHandler.java @@ -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; diff --git a/torusdirect/src/main/java/org/torusresearch/torusdirect/handlers/FacebookHandler.java b/torusdirect/src/main/java/org/torusresearch/torusdirect/handlers/FacebookHandler.java index 977a568..01a39ae 100644 --- a/torusdirect/src/main/java/org/torusresearch/torusdirect/handlers/FacebookHandler.java +++ b/torusdirect/src/main/java/org/torusresearch/torusdirect/handlers/FacebookHandler.java @@ -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; diff --git a/torusdirect/src/main/java/org/torusresearch/torusdirect/handlers/GoogleHandler.java b/torusdirect/src/main/java/org/torusresearch/torusdirect/handlers/GoogleHandler.java index bb117b3..25d8925 100644 --- a/torusdirect/src/main/java/org/torusresearch/torusdirect/handlers/GoogleHandler.java +++ b/torusdirect/src/main/java/org/torusresearch/torusdirect/handlers/GoogleHandler.java @@ -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; diff --git a/torusdirect/src/main/java/org/torusresearch/torusdirect/handlers/JwtHandler.java b/torusdirect/src/main/java/org/torusresearch/torusdirect/handlers/JwtHandler.java index 176e75a..ca92fc6 100644 --- a/torusdirect/src/main/java/org/torusresearch/torusdirect/handlers/JwtHandler.java +++ b/torusdirect/src/main/java/org/torusresearch/torusdirect/handlers/JwtHandler.java @@ -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; diff --git a/torusdirect/src/main/java/org/torusresearch/torusdirect/handlers/RedditHandler.java b/torusdirect/src/main/java/org/torusresearch/torusdirect/handlers/RedditHandler.java index bb68d04..b2eb68b 100644 --- a/torusdirect/src/main/java/org/torusresearch/torusdirect/handlers/RedditHandler.java +++ b/torusdirect/src/main/java/org/torusresearch/torusdirect/handlers/RedditHandler.java @@ -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; diff --git a/torusdirect/src/main/java/org/torusresearch/torusdirect/handlers/TwitchHandler.java b/torusdirect/src/main/java/org/torusresearch/torusdirect/handlers/TwitchHandler.java index 930e523..476f57b 100644 --- a/torusdirect/src/main/java/org/torusresearch/torusdirect/handlers/TwitchHandler.java +++ b/torusdirect/src/main/java/org/torusresearch/torusdirect/handlers/TwitchHandler.java @@ -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; diff --git a/torusdirect/src/main/java/org/torusresearch/torusdirect/interfaces/ILoginHandler.java b/torusdirect/src/main/java/org/torusresearch/torusdirect/interfaces/ILoginHandler.java index 9ffafad..cb507c8 100644 --- a/torusdirect/src/main/java/org/torusresearch/torusdirect/interfaces/ILoginHandler.java +++ b/torusdirect/src/main/java/org/torusresearch/torusdirect/interfaces/ILoginHandler.java @@ -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 getUserInfo(LoginWindowResponse params); diff --git a/torusdirect/src/main/java/org/torusresearch/torusdirect/utils/HttpHelpers.java b/torusdirect/src/main/java/org/torusresearch/torusdirect/utils/HttpHelpers.java index 9b6529a..6f2172e 100644 --- a/torusdirect/src/main/java/org/torusresearch/torusdirect/utils/HttpHelpers.java +++ b/torusdirect/src/main/java/org/torusresearch/torusdirect/utils/HttpHelpers.java @@ -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;