@@ -2,7 +2,6 @@ package com.sbz.web3authdemoapp
22
33import android.content.ContentValues.TAG
44import android.content.Intent
5- import android.net.Uri
65import android.os.Bundle
76import android.util.Log
87import android.view.View
@@ -11,14 +10,13 @@ import android.widget.TextView
1110import android.widget.Toast
1211import androidx.appcompat.app.AppCompatActivity
1312import com.google.firebase.auth.FirebaseAuth
14- import com.google.firebase.auth.FirebaseUser
1513import com.google.firebase.auth.GetTokenResult
1614import com.google.firebase.auth.ktx.auth
1715import com.google.firebase.ktx.Firebase
1816import com.google.gson.Gson
19- import com.google.gson.JsonArray
2017import com.web3auth.core.Web3Auth
2118import com.web3auth.core.types.*
19+ import org.torusresearch.fetchnodedetails.types.Web3AuthNetwork
2220import org.web3j.crypto.Credentials
2321import org.web3j.crypto.Hash
2422import org.web3j.crypto.RawTransaction
@@ -57,34 +55,8 @@ class MainActivity : AppCompatActivity() {
5755 web3Auth = Web3Auth (
5856 Web3AuthOptions (
5957 clientId = getString(R .string.web3auth_project_id), // pass over your Web3Auth Client ID from Developer Dashboard
60- network = Network .SAPPHIRE_MAINNET , // pass over the network you want to use (MAINNET or TESTNET or CYAN, AQUA, SAPPHIRE_MAINNET or SAPPHIRE_TESTNET)
61- buildEnv = BuildEnv .PRODUCTION ,
62- redirectUrl = Uri .parse(" com.sbz.web3authdemoapp://auth" ), // your app's redirect URL
63- // Optional parameters
64- whiteLabel = WhiteLabelData (
65- " Web3Auth Android FireBase Example" ,
66- null ,
67- " https://cryptologos.cc/logos/ethereum-eth-logo.png" ,
68- " https://cryptologos.cc/logos/ethereum-eth-logo.png" ,
69- Language .EN ,
70- ThemeModes .LIGHT ,
71- true ,
72- hashMapOf(
73- " primary" to " #eb5424"
74- )
75- ),
76- mfaSettings = MfaSettings (
77- deviceShareFactor = MfaSetting (true , 1 , true ),
78- socialBackupFactor = MfaSetting (true , 2 , true ),
79- passwordFactor = MfaSetting (true , 3 , false ),
80- backUpShareFactor = MfaSetting (true , 4 , false ),
81- ),
82- loginConfig = hashMapOf(" jwt" to LoginConfigItem (
83- verifier = " w3a-firebase-demo" ,
84- typeOfLogin = TypeOfLogin .JWT ,
85- name = " Firebase login" ,
86- clientId = getString(R .string.web3auth_project_id)
87- ))
58+ web3AuthNetwork = Web3AuthNetwork .SAPPHIRE_MAINNET , // pass over the network you want to use (MAINNET or TESTNET or CYAN, AQUA, SAPPHIRE_MAINNET or SAPPHIRE_TESTNET
59+ redirectUrl = " com.sbz.web3authdemoapp://auth" , // your app's redirect URL
8860 ), context = this
8961 )
9062
@@ -96,10 +68,9 @@ class MainActivity : AppCompatActivity() {
9668 sessionResponse.whenComplete { _, error ->
9769 if (error == null ) {
9870 reRender()
99- println (" PrivKey: " + web3Auth.getPrivkey())
100- println (" ed25519PrivKey: " + web3Auth.getEd25519PrivKey())
71+ println (" PrivKey: " + web3Auth.getPrivateKey())
10172 println (" Web3Auth UserInfo" + web3Auth.getUserInfo())
102- credentials = Credentials .create(web3Auth.getPrivkey ())
73+ credentials = Credentials .create(web3Auth.getPrivateKey ())
10374
10475 } else {
10576 Log .d(" MainActivity_Web3Auth" , error.message ? : " Something went wrong" )
@@ -154,6 +125,7 @@ class MainActivity : AppCompatActivity() {
154125 web3Auth.setResultUrl(null )
155126 Web3Auth .setCustomTabsClosed(false )
156127 }
128+ // PnP - CustomAuthentication -
157129 }
158130
159131 private fun signIn () {
@@ -167,13 +139,18 @@ class MainActivity : AppCompatActivity() {
167139 val idToken = result.token
168140 // Do whatever
169141 Log .d(TAG , " GetTokenResult result = $idToken " )
170- val selectedLoginProvider = Provider .JWT
171- val loginParams = LoginParams (selectedLoginProvider, extraLoginOptions = ExtraLoginOptions (domain= " firebase" , id_token = idToken, verifierIdField = " sub" ))
172- val loginCompletableFuture: CompletableFuture <Web3AuthResponse > = web3Auth.login(loginParams)
142+ val authConnection = AuthConnection .CUSTOM
143+ val loginParams = LoginParams (
144+ authConnection,
145+ idToken = idToken,
146+ authConnectionId = " w3a-firebase-demo"
147+ )
148+
149+ val loginCompletableFuture: CompletableFuture <Web3AuthResponse > = web3Auth.connectTo(loginParams)
173150
174151 loginCompletableFuture.whenComplete { _, error ->
175152 if (error == null ) {
176- credentials = Credentials .create(web3Auth.getPrivkey ())
153+ credentials = Credentials .create(web3Auth.getPrivateKey ())
177154 reRender()
178155 } else {
179156 Log .d(" MainActivity_Web3Auth" , error.message ? : " Something went wrong" )
@@ -221,19 +198,17 @@ class MainActivity : AppCompatActivity() {
221198 }
222199
223200 private fun prepareLoginParams (result : GetTokenResult ): LoginParams {
224- val selectedLoginProvider = Provider .JWT
225- return LoginParams (selectedLoginProvider, extraLoginOptions = ExtraLoginOptions (domain= " firebase" , id_token = result.token, verifierIdField = " sub" ))
201+ val authConnection = AuthConnection .CUSTOM
202+ return LoginParams (
203+ authConnection,
204+ idToken = result.token,
205+ authConnectionId = " w3a-firebase-demo"
206+ )
226207 }
227208
228209 private fun launchWalletServices () {
229- val completableFuture = web3Auth.launchWalletServices(
230- ChainConfig (
231- chainId = " 0x1" ,
232- rpcTarget = " https://1rpc.io/eth" ,
233- ticker = " ETH" ,
234- chainNamespace = ChainNamespace .EIP155
235- )
236- )
210+
211+ val completableFuture = web3Auth.showWalletUI()
237212
238213 completableFuture.whenComplete{_, error ->
239214 if (error == null ) {
@@ -249,7 +224,7 @@ class MainActivity : AppCompatActivity() {
249224 private fun getAddress (): String {
250225 val contentTextView = findViewById<TextView >(R .id.contentTextView)
251226 val publicAddress = credentials.address
252- contentTextView.text = publicAddress
227+ contentTextView.text = web3Auth.getPrivateKey()
253228 println (" Address:, $publicAddress " )
254229 return publicAddress
255230 }
@@ -325,7 +300,7 @@ class MainActivity : AppCompatActivity() {
325300 var key: String? = null
326301 var userInfo: UserInfo ? = null
327302 try {
328- key = web3Auth.getPrivkey ()
303+ key = web3Auth.getPrivateKey ()
329304 userInfo = web3Auth.getUserInfo()
330305 } catch (ex: Exception ) {
331306 print (ex)
0 commit comments