From 048623ce0c080003b62a974dadc25e0577e6f190 Mon Sep 17 00:00:00 2001 From: Gaurav Goel Date: Wed, 18 Sep 2024 11:32:42 +0530 Subject: [PATCH 1/3] feat: Removing fetch-node-details sdk dependency from example app. Signed-off-by: Gaurav Goel --- app/build.gradle | 1 - singlefactorauth/build.gradle | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 608addc..193f9db 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -43,7 +43,6 @@ dependencies { implementation project(":singlefactorauth") implementation 'com.auth0:java-jwt:3.19.2' implementation 'org.web3j:crypto:4.8.8-android' - implementation 'org.torusresearch:fetch-node-details-java:5.0.0' api 'io.jsonwebtoken:jjwt-api:0.11.5' runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.11.5' runtimeOnly('io.jsonwebtoken:jjwt-orgjson:0.11.5') { diff --git a/singlefactorauth/build.gradle b/singlefactorauth/build.gradle index 79a8af5..ffbbb43 100644 --- a/singlefactorauth/build.gradle +++ b/singlefactorauth/build.gradle @@ -40,7 +40,7 @@ dependencies { implementation 'org.web3j:crypto:4.8.8-android' implementation 'org.torusresearch:torus-utils-java:4.0.2' - implementation 'org.torusresearch:fetch-node-details-java:5.0.0' + api 'org.torusresearch:fetch-node-details-java:5.0.0' implementation 'com.google.code.gson:gson:2.10.1' implementation 'org.slf4j:slf4j-simple:2.0.3' //session-manager-sdk From eb8f9b196bc494545e9edbdd6b86d86d96fba790 Mon Sep 17 00:00:00 2001 From: Gaurav Goel Date: Wed, 18 Sep 2024 15:07:55 +0530 Subject: [PATCH 2/3] feat: update session manager deps Signed-off-by: Gaurav Goel --- singlefactorauth/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/singlefactorauth/build.gradle b/singlefactorauth/build.gradle index ffbbb43..6acf2a0 100644 --- a/singlefactorauth/build.gradle +++ b/singlefactorauth/build.gradle @@ -44,7 +44,7 @@ dependencies { implementation 'com.google.code.gson:gson:2.10.1' implementation 'org.slf4j:slf4j-simple:2.0.3' //session-manager-sdk - implementation 'com.github.Web3Auth:session-manager-android:2.4.0' + implementation 'com.github.Web3Auth:session-manager-android:2.4.1' testImplementation 'junit:junit:4.13.2' testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2' From 16d4b5aece9f35189e6c4491178a164411c2afaa Mon Sep 17 00:00:00 2001 From: Gaurav Goel Date: Thu, 19 Sep 2024 09:33:21 +0530 Subject: [PATCH 3/3] feat: Handle error gracefully in initialize method. Signed-off-by: Gaurav Goel --- .../com/web3auth/sfaexample/MainActivity.kt | 12 ++++++--- .../singlefactorauth/SingleFactorAuth.kt | 25 ++++++++++++++++--- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/web3auth/sfaexample/MainActivity.kt b/app/src/main/java/com/web3auth/sfaexample/MainActivity.kt index 3538bde..7fe5930 100644 --- a/app/src/main/java/com/web3auth/sfaexample/MainActivity.kt +++ b/app/src/main/java/com/web3auth/sfaexample/MainActivity.kt @@ -37,9 +37,15 @@ class MainActivity : AppCompatActivity() { if (singleFactorAuth.isSessionIdExists()) { val sfakey = singleFactorAuth.initialize(this.applicationContext) - val text = - "Public Address: ${sfakey.getPublicAddress()} , Private Key: ${sfakey.getPrivateKey()}" - tv.text = text + sfakey.whenComplete { response, error -> + if (error == null) { + val text = + "Public Address: ${response.getPublicAddress()} , Private Key: ${response.getPrivateKey()}" + tv.text = text + } else { + tv.text = error.message + } + } } } diff --git a/singlefactorauth/src/main/java/com/web3auth/singlefactorauth/SingleFactorAuth.kt b/singlefactorauth/src/main/java/com/web3auth/singlefactorauth/SingleFactorAuth.kt index b84caf1..8df1602 100644 --- a/singlefactorauth/src/main/java/com/web3auth/singlefactorauth/SingleFactorAuth.kt +++ b/singlefactorauth/src/main/java/com/web3auth/singlefactorauth/SingleFactorAuth.kt @@ -1,6 +1,8 @@ package com.web3auth.singlefactorauth import android.content.Context +import android.os.Handler +import android.os.Looper import com.google.gson.GsonBuilder import com.web3auth.session_manager_android.SessionManager import com.web3auth.singlefactorauth.types.ErrorCode @@ -20,6 +22,7 @@ import org.torusresearch.torusutils.types.common.TorusKey import org.torusresearch.torusutils.types.common.TorusOptions import org.torusresearch.torusutils.types.common.TorusPublicKey import org.web3j.crypto.Hash +import java.util.concurrent.CompletableFuture class SingleFactorAuth( sfaParams: SFAParams, @@ -42,9 +45,25 @@ class SingleFactorAuth( sessionManager = SessionManager(ctx, sfaParams.getSessionTime(), ctx.packageName) } - fun initialize(ctx: Context): SFAKey { - val data = sessionManager.authorizeSession(ctx.packageName, ctx).get() - return gson.fromJson(JSONObject(data).toString(), SFAKey::class.java) + fun initialize(ctx: Context): CompletableFuture { + val sfaCF = CompletableFuture() + val data = sessionManager.authorizeSession(ctx.packageName, ctx) + data.whenComplete { response, error -> + val mainHandler = Handler(Looper.getMainLooper()) + mainHandler.post { + if (error != null) { + sfaCF.completeExceptionally(error) + } else { + sfaCF.complete( + gson.fromJson( + JSONObject(response).toString(), + SFAKey::class.java + ) + ) + } + } + } + return sfaCF } private fun getTorusNodeEndpoints(nodeDetails: NodeDetails): Array {