Skip to content

Commit

Permalink
Merge pull request #10 from Web3Auth/removing-fetchNodeDetails-depend…
Browse files Browse the repository at this point in the history
…ency-from-example

feat: Removing fetch-node-details sdk dependency from example app.
  • Loading branch information
chaitanyapotti authored Sep 19, 2024
2 parents a6ba193 + 16d4b5a commit ed8f8d1
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 9 deletions.
1 change: 0 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
12 changes: 9 additions & 3 deletions app/src/main/java/com/web3auth/sfaexample/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions singlefactorauth/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ 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
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'
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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,
Expand All @@ -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<SFAKey> {
val sfaCF = CompletableFuture<SFAKey>()
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<String?> {
Expand Down

0 comments on commit ed8f8d1

Please sign in to comment.