diff --git a/android-aggregate-verifier-example/app/build.gradle b/android-aggregate-verifier-example/app/build.gradle index 6fdaa6b..1858aaa 100644 --- a/android-aggregate-verifier-example/app/build.gradle +++ b/android-aggregate-verifier-example/app/build.gradle @@ -38,7 +38,7 @@ dependencies { implementation 'com.google.android.material:material:1.6.1' implementation 'androidx.constraintlayout:constraintlayout:2.1.4' implementation 'com.google.code.gson:gson:2.9.1' - implementation 'com.github.web3auth:web3auth-android-sdk:9.0.4' + implementation 'com.github.web3auth:web3auth-android-sdk:10.0.0' implementation 'org.web3j:core:4.8.7-android' testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test.ext:junit:1.1.3' diff --git a/android-aggregate-verifier-example/app/src/main/java/com/sbz/web3authdemoapp/MainActivity.kt b/android-aggregate-verifier-example/app/src/main/java/com/sbz/web3authdemoapp/MainActivity.kt index 1acca2f..2567916 100644 --- a/android-aggregate-verifier-example/app/src/main/java/com/sbz/web3authdemoapp/MainActivity.kt +++ b/android-aggregate-verifier-example/app/src/main/java/com/sbz/web3authdemoapp/MainActivity.kt @@ -1,7 +1,6 @@ package com.sbz.web3authdemoapp import android.content.Intent -import android.net.Uri import android.os.Bundle import android.util.Log import android.view.View @@ -11,7 +10,21 @@ import android.widget.Toast import androidx.appcompat.app.AppCompatActivity import com.google.gson.Gson import com.web3auth.core.Web3Auth -import com.web3auth.core.types.* +import com.web3auth.core.types.AuthConnection +import com.web3auth.core.types.AuthConnectionConfig +import com.web3auth.core.types.BuildEnv +import com.web3auth.core.types.ExtraLoginOptions +import com.web3auth.core.types.Language +import com.web3auth.core.types.LoginParams +import com.web3auth.core.types.MfaSetting +import com.web3auth.core.types.MfaSettings +import com.web3auth.core.types.ThemeModes +import com.web3auth.core.types.UserInfo +import com.web3auth.core.types.WalletServicesConfig +import com.web3auth.core.types.Web3AuthOptions +import com.web3auth.core.types.Web3AuthResponse +import com.web3auth.core.types.WhiteLabelData +import org.torusresearch.fetchnodedetails.types.Web3AuthNetwork import org.web3j.crypto.Credentials import org.web3j.crypto.Hash import org.web3j.crypto.RawTransaction @@ -32,9 +45,17 @@ import java.util.concurrent.CompletableFuture class MainActivity : AppCompatActivity() { + companion object { + private const val GROUPED_AUTH_CONNECTION_ID = "aggregate-sapphire" + private const val GOOGLE_AUTH_CONNECTION_ID = "w3a-google" + private const val AUTH0_AUTH_CONNECTION_ID = "w3a-a0-email-passwordless" + private const val AUTH0_DOMAIN = "https://web3auth.au.auth0.com" + private const val DEFAULT_CHAIN_ID = "0xaa36a7" // Sepolia + } + private lateinit var web3Auth: Web3Auth private lateinit var web3: Web3j - private lateinit var credentials: Credentials + private var credentials: Credentials? = null private val rpcUrl = "https://1rpc.io/sepolia" private val gson = Gson() @@ -43,69 +64,79 @@ class MainActivity : AppCompatActivity() { setContentView(R.layout.activity_main) web3 = Web3j.build(HttpService(rpcUrl)) + val whiteLabelData = WhiteLabelData( + "Web3Auth Android Example", + null, + "https://cryptologos.cc/logos/ethereum-eth-logo.png", + "https://cryptologos.cc/logos/ethereum-eth-logo.png", + Language.EN, + ThemeModes.LIGHT, + true, + hashMapOf("primary" to "#eb5424") + ) + + val authConnections = listOf( + AuthConnectionConfig( + authConnectionId = GOOGLE_AUTH_CONNECTION_ID, + authConnection = AuthConnection.GOOGLE, + clientId = getString(R.string.web3auth_google_client_id), + groupedAuthConnectionId = GROUPED_AUTH_CONNECTION_ID + ), + AuthConnectionConfig( + authConnectionId = AUTH0_AUTH_CONNECTION_ID, + authConnection = AuthConnection.CUSTOM, + clientId = getString(R.string.web3auth_auth0_client_id), + groupedAuthConnectionId = GROUPED_AUTH_CONNECTION_ID, + jwtParameters = ExtraLoginOptions( + domain = AUTH0_DOMAIN, + userIdField = "email", + isUserIdCaseSensitive = false + ) + ) + ) + web3Auth = Web3Auth( - Web3AuthOptions( - clientId = getString(R.string.web3auth_project_id), // pass over your Web3Auth Client ID from Developer Dashboard - network = Network.SAPPHIRE_MAINNET, // pass over the network you want to use (MAINNET or TESTNET or CYAN, AQUA, SAPPHIRE_MAINNET or SAPPHIRE_TESTNET) - buildEnv = BuildEnv.PRODUCTION, - redirectUrl = Uri.parse("com.sbz.web3authdemoapp://auth"), // your app's redirect URL - whiteLabel = WhiteLabelData( - "Web3Auth Android Example", - null, - "https://cryptologos.cc/logos/ethereum-eth-logo.png", - "https://cryptologos.cc/logos/ethereum-eth-logo.png", - Language.EN, - ThemeModes.LIGHT, - true, - hashMapOf( - "primary" to "#eb5424" - ) - ), - mfaSettings = MfaSettings( - deviceShareFactor = MfaSetting(true, 1, true), - socialBackupFactor = MfaSetting(true, 2, true), - passwordFactor = MfaSetting(true, 3, false), - backUpShareFactor = MfaSetting(true, 4, false), - ), - loginConfig = hashMapOf( - "google" to LoginConfigItem( - verifier = "aggregate-sapphire", - verifierSubIdentifier= "w3a-google", - typeOfLogin = TypeOfLogin.GOOGLE, - name = "Aggregate Login", - clientId = getString(R.string.web3auth_google_client_id) - ), - "jwt" to LoginConfigItem( - verifier = "aggregate-sapphire", - verifierSubIdentifier= "w3a-a0-email-passwordless", - typeOfLogin = TypeOfLogin.JWT, - name = "Aggregate Login", - clientId = getString(R.string.web3auth_auth0_client_id) - ) - ) - ), context = this + Web3AuthOptions( + clientId = getString(R.string.web3auth_project_id), + web3AuthNetwork = Web3AuthNetwork.SAPPHIRE_MAINNET, + authBuildEnv = BuildEnv.PRODUCTION, + redirectUrl = "com.sbz.web3authdemoapp://auth", + whiteLabel = whiteLabelData, + walletServicesConfig = WalletServicesConfig(whiteLabel = whiteLabelData), + authConnectionConfig = authConnections, + mfaSettings = MfaSettings( + deviceShareFactor = MfaSetting(true, 1, true), + socialBackupFactor = MfaSetting(true, 2, true), + passwordFactor = MfaSetting(true, 3, false), + backUpShareFactor = MfaSetting(true, 4, false), + ), + defaultChainId = DEFAULT_CHAIN_ID + ), this ) - // Handle user signing in when app is not alive web3Auth.setResultUrl(intent?.data) - // Call initialize() in onCreate() to check for any existing session. val sessionResponse: CompletableFuture = web3Auth.initialize() sessionResponse.whenComplete { _, error -> if (error == null) { + setCredentialsIfPresent() reRender() - println("PrivKey: " + web3Auth.getPrivkey()) - println("ed25519PrivKey: " + web3Auth.getEd25519PrivKey()) - println("Web3Auth UserInfo" + web3Auth.getUserInfo()) - credentials = Credentials.create(web3Auth.getPrivkey()) - Log.d("MainActivity_Web3Auth", web3Auth.getUserInfo().toString()) + try { + println("PrivKey: ${web3Auth.getPrivateKey()}") + println("ed25519PrivKey: ${web3Auth.getEd25519PrivateKey()}") + } catch (ex: Exception) { + Log.d("MainActivity_Web3Auth", ex.message ?: "Unable to fetch keys") + } + println("Web3Auth UserInfo ${web3Auth.getUserInfo()}") + Log.d( + "MainActivity_Web3Auth", + web3Auth.getUserInfo()?.toString() ?: "No user logged in" + ) } else { Log.d("MainActivity_Web3Auth", error.message ?: "Something went wrong") - // Ideally, you should initiate the login function here. } } - // Setup UI and event handlers val signInGoogleButton = findViewById