11package com.sbz.web3authdemoapp
22
33import android.content.Intent
4- import android.net.Uri
54import android.os.Bundle
65import android.util.Log
76import android.view.View
@@ -12,6 +11,7 @@ import androidx.appcompat.app.AppCompatActivity
1211import com.google.gson.Gson
1312import com.web3auth.core.Web3Auth
1413import com.web3auth.core.types.*
14+ import org.torusresearch.fetchnodedetails.types.Web3AuthNetwork
1515import org.web3j.crypto.Credentials
1616import org.web3j.crypto.Hash
1717import org.web3j.crypto.RawTransaction
@@ -38,49 +38,42 @@ class MainActivity : AppCompatActivity() {
3838 private val gson = Gson ()
3939 private lateinit var web3: Web3j
4040 private lateinit var credentials: Credentials
41- private lateinit var loginParams: LoginParams
4241 private val rpcUrl = " https://1rpc.io/sepolia"
4342
4443 override fun onCreate (savedInstanceState : Bundle ? ) {
4544 super .onCreate(savedInstanceState)
4645 setContentView(R .layout.activity_main)
4746
4847 web3 = Web3j .build(HttpService (rpcUrl))
49- loginParams = LoginParams (Provider .JWT , extraLoginOptions = ExtraLoginOptions (domain = " https://web3auth.au.auth0.com" , verifierIdField = " sub" ))
5048
5149 web3Auth = Web3Auth (
5250 Web3AuthOptions (
53-
5451 clientId = getString(R .string.web3auth_project_id), // pass over your Web3Auth Client ID from Developer Dashboard
55- network = Network .SAPPHIRE_MAINNET , // pass over the network you want to use (MAINNET or TESTNET or CYAN)
56- buildEnv = BuildEnv .PRODUCTION ,
57- redirectUrl = Uri .parse(" com.sbz.web3authdemoapp://auth" ), // your app's redirect URL
52+ web3AuthNetwork = Web3AuthNetwork .SAPPHIRE_MAINNET , // pass over the network you want to use
53+ redirectUrl = " com.sbz.web3authdemoapp://auth" , // your app's redirect URL
5854 // Optional parameters
59- whiteLabel = WhiteLabelData (
60- " Web3Auth Android Auth0 Example" ,
61- null ,
62- " https://cryptologos.cc/logos/ethereum-eth-logo.png" ,
63- " https://cryptologos.cc/logos/ethereum-eth-logo.png" ,
64- Language .EN ,
65- ThemeModes .LIGHT ,
66- true ,
67- hashMapOf(
68- " primary" to " #eb5424"
55+ walletServicesConfig = WalletServicesConfig (
56+ whiteLabel = WhiteLabelData (
57+ " Web3Auth Android Auth0 Example" ,
58+ null ,
59+ " https://cryptologos.cc/logos/ethereum-eth-logo.png" ,
60+ " https://cryptologos.cc/logos/ethereum-eth-logo.png" ,
61+ Language .EN ,
62+ ThemeModes .LIGHT ,
63+ true ,
64+ hashMapOf(
65+ " primary" to " #eb5424"
66+ )
6967 )
7068 ),
71- mfaSettings = MfaSettings (
72- deviceShareFactor = MfaSetting (true , 1 , true ),
73- socialBackupFactor = MfaSetting (true , 2 , true ),
74- passwordFactor = MfaSetting (true , 3 , false ),
75- backUpShareFactor = MfaSetting (true , 4 , false ),
76- ),
77- loginConfig = hashMapOf(" jwt" to LoginConfigItem (
78- verifier = " w3a-auth0-demo" ,
79- typeOfLogin = TypeOfLogin .JWT ,
80- name = " Auth0 Login" ,
81- clientId = getString(R .string.web3auth_auth0_client_id)
82- ))
83- ), context = this
69+ authConnectionConfig = listOf (
70+ AuthConnectionConfig (
71+ authConnection = AuthConnection .CUSTOM ,
72+ authConnectionId = " w3a-auth0-demo" ,
73+ clientId = getString(R .string.web3auth_auth0_client_id)
74+ )
75+ )
76+ ), this
8477 )
8578
8679 // Handle user signing in when app is not alive
@@ -91,10 +84,10 @@ class MainActivity : AppCompatActivity() {
9184 sessionResponse.whenComplete { _, error ->
9285 if (error == null ) {
9386 reRender()
94- println (" PrivKey: " + web3Auth.getPrivkey ())
95- println (" ed25519PrivKey: " + web3Auth.getEd25519PrivKey ())
87+ println (" PrivKey: " + web3Auth.getPrivateKey ())
88+ println (" ed25519PrivKey: " + web3Auth.getEd25519PrivateKey ())
9689 println (" Web3Auth UserInfo" + web3Auth.getUserInfo())
97- credentials = Credentials .create(web3Auth.getPrivkey ())
90+ credentials = Credentials .create(web3Auth.getPrivateKey ())
9891 } else {
9992 Log .d(" MainActivity_Web3Auth" , error.message ? : " Something went wrong" )
10093 // Ideally, you should initiate the login function here.
@@ -151,19 +144,34 @@ class MainActivity : AppCompatActivity() {
151144 }
152145
153146 private fun signIn () {
154- val loginCompletableFuture: CompletableFuture <Web3AuthResponse > = web3Auth.login(loginParams)
155-
156- // For Email Passwordless, use the below code and pass email id into extraLoginOptions of LoginParams.
157- // val selectedLoginProvider = Provider.EMAIL_PASSWORDLESS
158- // val loginCompletableFuture: CompletableFuture<Web3AuthResponse> = web3Auth.login(LoginParams(selectedLoginProvider, extraLoginOptions = ExtraLoginOptions(login_hint = "[email protected] "))) 159-
160- // For login with Custom JWT, use the below code and pass email id into extraLoginOptions of LoginParams.
161- // val selectedLoginProvider = Provider.JWT
162- // val loginCompletableFuture: CompletableFuture<Web3AuthResponse> = web3Auth.login(LoginParams(selectedLoginProvider, extraLoginOptions = ExtraLoginOptions(id_token = "<id-token>", domain: "your-domain")))
147+ val extraLoginOptionsData = ExtraLoginOptions (
148+ domain = " https://web3auth.au.auth0.com"
149+ )
150+ val loginParams = LoginParams (
151+ authConnection = AuthConnection .CUSTOM ,
152+ authConnectionId = " w3a-auth0-demo" ,
153+ extraLoginOptions = extraLoginOptionsData
154+ )
155+ val loginCompletableFuture: CompletableFuture <Web3AuthResponse > = web3Auth.connectTo(loginParams)
156+
157+ // For Email Passwordless, use the below code and pass email id into loginHint of LoginParams.
158+ // val loginParams = LoginParams(
159+ // authConnection = AuthConnection.EMAIL_PASSWORDLESS,
160+ // loginHint = "[email protected] " 161+ // )
162+ // val loginCompletableFuture: CompletableFuture<Web3AuthResponse> = web3Auth.connectTo(loginParams)
163+
164+ // For login with Custom JWT, use the below code and pass idToken into LoginParams.
165+ // val loginParams = LoginParams(
166+ // authConnection = AuthConnection.CUSTOM,
167+ // authConnectionId = "your-verifier-id",
168+ // idToken = "<id-token>"
169+ // )
170+ // val loginCompletableFuture: CompletableFuture<Web3AuthResponse> = web3Auth.connectTo(loginParams)
163171
164172 loginCompletableFuture.whenComplete { _, error ->
165173 if (error == null ) {
166- credentials = Credentials .create(web3Auth.getPrivkey ())
174+ credentials = Credentials .create(web3Auth.getPrivateKey ())
167175 reRender()
168176 } else {
169177 Log .d(" MainActivity_Web3Auth" , error.message ? : " Something went wrong" )
@@ -172,7 +180,14 @@ class MainActivity : AppCompatActivity() {
172180 }
173181
174182 private fun enableMFA () {
175-
183+ val extraLoginOptionsData = ExtraLoginOptions (
184+ domain = " https://web3auth.au.auth0.com"
185+ )
186+ val loginParams = LoginParams (
187+ authConnection = AuthConnection .CUSTOM ,
188+ authConnectionId = " w3a-auth0-demo" ,
189+ extraLoginOptions = extraLoginOptionsData
190+ )
176191 val completableFuture = web3Auth.enableMFA(loginParams)
177192
178193 completableFuture.whenComplete{_, error ->
@@ -187,21 +202,11 @@ class MainActivity : AppCompatActivity() {
187202 }
188203
189204 private fun launchWalletServices () {
190- val completableFuture = web3Auth.launchWalletServices(
191- ChainConfig (
192- chainId = " 0x1" ,
193- rpcTarget = " https://1rpc.io/eth" ,
194- ticker = " ETH" ,
195- chainNamespace = ChainNamespace .EIP155
196- )
197- )
198-
199- completableFuture.whenComplete{_, error ->
200- if (error == null ) {
201- // Add your logic
202- Log .d(" MainActivity_Web3Auth" , " Wallet services launched successfully" )
205+ val launchWalletCompletableFuture = web3Auth.showWalletUI()
206+ launchWalletCompletableFuture.whenComplete { _, error ->
207+ if (error == null ) {
208+ Log .d(" MainActivity_Web3Auth" , " Wallet launched successfully" )
203209 } else {
204- // Add your logic for error
205210 Log .d(" MainActivity_Web3Auth" , error.message ? : " Something went wrong" )
206211 }
207212 }
@@ -297,7 +302,7 @@ class MainActivity : AppCompatActivity() {
297302 var key: String? = null
298303 var userInfo: UserInfo ? = null
299304 try {
300- key = web3Auth.getPrivkey ()
305+ key = web3Auth.getPrivateKey ()
301306 userInfo = web3Auth.getUserInfo()
302307 } catch (ex: Exception ) {
303308 print (ex)
0 commit comments