Skip to content

Commit 43f7ff1

Browse files
update examples
1 parent 9076a4c commit 43f7ff1

File tree

11 files changed

+283
-194
lines changed

11 files changed

+283
-194
lines changed

android-aggregate-verifier-example/app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ dependencies {
3838
implementation 'com.google.android.material:material:1.6.1'
3939
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
4040
implementation 'com.google.code.gson:gson:2.9.1'
41-
implementation 'com.github.web3auth:web3auth-android-sdk:9.0.4'
41+
implementation 'com.github.grvgoel81:web3auth-android-sdk:3.0.0.2'
4242
implementation 'org.web3j:core:4.8.7-android'
4343
testImplementation 'junit:junit:4.13.2'
4444
androidTestImplementation 'androidx.test.ext:junit:1.1.3'

android-aggregate-verifier-example/app/src/main/java/com/sbz/web3authdemoapp/MainActivity.kt

Lines changed: 59 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ import androidx.appcompat.app.AppCompatActivity
1212
import com.google.gson.Gson
1313
import com.web3auth.core.Web3Auth
1414
import com.web3auth.core.types.*
15+
import org.torusresearch.fetchnodedetails.types.Web3AuthNetwork
1516
import org.web3j.crypto.Credentials
1617
import org.web3j.crypto.Hash
1718
import org.web3j.crypto.RawTransaction
1819
import org.web3j.crypto.Sign
1920
import org.web3j.crypto.TransactionEncoder
21+
import org.web3j.protocol.Network
2022
import org.web3j.protocol.Web3j
2123
import org.web3j.protocol.core.DefaultBlockParameterName
2224
import org.web3j.protocol.core.methods.response.EthChainId
@@ -43,47 +45,34 @@ class MainActivity : AppCompatActivity() {
4345
setContentView(R.layout.activity_main)
4446
web3 = Web3j.build(HttpService(rpcUrl))
4547

48+
val authConnectionConfig = ArrayList<AuthConnectionConfig>()
49+
authConnectionConfig.add(
50+
AuthConnectionConfig(
51+
authConnectionId = "w3a-google",
52+
groupedAuthConnectionId = "aggregate-sapphire",
53+
authConnection = AuthConnection.GOOGLE,
54+
clientId = getString(R.string.web3auth_google_client_id),
55+
)
56+
)
57+
58+
authConnectionConfig.add(
59+
AuthConnectionConfig(
60+
authConnectionId = "w3a-a0-email-passwordless",
61+
groupedAuthConnectionId = "aggregate-sapphire",
62+
authConnection = AuthConnection.CUSTOM,
63+
clientId = getString(R.string.web3auth_auth0_client_id),
64+
)
65+
)
66+
4667
web3Auth = Web3Auth(
4768
Web3AuthOptions(
4869
clientId = getString(R.string.web3auth_project_id), // pass over your Web3Auth Client ID from Developer Dashboard
49-
network = Network.SAPPHIRE_MAINNET, // pass over the network you want to use (MAINNET or TESTNET or CYAN, AQUA, SAPPHIRE_MAINNET or SAPPHIRE_TESTNET)
50-
buildEnv = BuildEnv.PRODUCTION,
51-
redirectUrl = Uri.parse("com.sbz.web3authdemoapp://auth"), // your app's redirect URL
52-
whiteLabel = WhiteLabelData(
53-
"Web3Auth Android Example",
54-
null,
55-
"https://cryptologos.cc/logos/ethereum-eth-logo.png",
56-
"https://cryptologos.cc/logos/ethereum-eth-logo.png",
57-
Language.EN,
58-
ThemeModes.LIGHT,
59-
true,
60-
hashMapOf(
61-
"primary" to "#eb5424"
62-
)
63-
),
64-
mfaSettings = MfaSettings(
65-
deviceShareFactor = MfaSetting(true, 1, true),
66-
socialBackupFactor = MfaSetting(true, 2, true),
67-
passwordFactor = MfaSetting(true, 3, false),
68-
backUpShareFactor = MfaSetting(true, 4, false),
69-
),
70-
loginConfig = hashMapOf(
71-
"google" to LoginConfigItem(
72-
verifier = "aggregate-sapphire",
73-
verifierSubIdentifier= "w3a-google",
74-
typeOfLogin = TypeOfLogin.GOOGLE,
75-
name = "Aggregate Login",
76-
clientId = getString(R.string.web3auth_google_client_id)
77-
),
78-
"jwt" to LoginConfigItem(
79-
verifier = "aggregate-sapphire",
80-
verifierSubIdentifier= "w3a-a0-email-passwordless",
81-
typeOfLogin = TypeOfLogin.JWT,
82-
name = "Aggregate Login",
83-
clientId = getString(R.string.web3auth_auth0_client_id)
84-
)
85-
)
70+
web3AuthNetwork = Web3AuthNetwork.SAPPHIRE_MAINNET, // pass over the network you want to use (MAINNET or TESTNET or CYAN, AQUA, SAPPHIRE_MAINNET or SAPPHIRE_TESTNET)
71+
authBuildEnv = BuildEnv.PRODUCTION,
72+
redirectUrl = "com.sbz.web3authdemoapp://auth", // your app's redirect URL
73+
authConnectionConfig = ArrayList<AuthConnectionConfig>()
8674
), context = this
75+
8776
)
8877

8978
// Handle user signing in when app is not alive
@@ -94,10 +83,10 @@ class MainActivity : AppCompatActivity() {
9483
sessionResponse.whenComplete { _, error ->
9584
if (error == null) {
9685
reRender()
97-
println("PrivKey: " + web3Auth.getPrivkey())
98-
println("ed25519PrivKey: " + web3Auth.getEd25519PrivKey())
86+
println("PrivKey: " + web3Auth.getPrivateKey())
87+
println("ed25519PrivKey: " + web3Auth.getEd25519PrivateKey())
9988
println("Web3Auth UserInfo" + web3Auth.getUserInfo())
100-
credentials = Credentials.create(web3Auth.getPrivkey())
89+
credentials = Credentials.create(web3Auth.getPrivateKey())
10190
Log.d("MainActivity_Web3Auth", web3Auth.getUserInfo().toString())
10291
} else {
10392
Log.d("MainActivity_Web3Auth", error.message ?: "Something went wrong")
@@ -158,12 +147,23 @@ class MainActivity : AppCompatActivity() {
158147
}
159148

160149
private fun signInEP() {
161-
val selectedLoginProvider = Provider.JWT
162-
val loginCompletableFuture: CompletableFuture<Web3AuthResponse> = web3Auth.login(LoginParams(selectedLoginProvider, extraLoginOptions = ExtraLoginOptions(domain = "https://web3auth.au.auth0.com", verifierIdField = "email", isVerifierIdCaseSensitive = false)))
150+
val selectedLoginProvider = AuthConnection.CUSTOM
151+
val loginCompletableFuture: CompletableFuture<Web3AuthResponse> = web3Auth.connectTo(
152+
LoginParams(
153+
selectedLoginProvider,
154+
authConnectionId = "w3a-a0-email-passwordless",
155+
groupedAuthConnectionId = "aggregate-sapphire",
156+
extraLoginOptions = ExtraLoginOptions(
157+
domain = "https://web3auth.au.auth0.com",
158+
userIdField = "email",
159+
isUserIdCaseSensitive = false
160+
)
161+
)
162+
)
163163

164164
loginCompletableFuture.whenComplete { _, error ->
165165
if (error == null) {
166-
credentials = Credentials.create(web3Auth.getPrivkey())
166+
credentials = Credentials.create(web3Auth.getPrivateKey())
167167
reRender()
168168
} else {
169169
Log.d("MainActivity_Web3Auth", error.message ?: "Something went wrong")
@@ -172,12 +172,13 @@ class MainActivity : AppCompatActivity() {
172172
}
173173

174174
private fun signInGoogle() {
175-
val selectedLoginProvider = Provider.GOOGLE
176-
val loginCompletableFuture: CompletableFuture<Web3AuthResponse> = web3Auth.login(LoginParams(selectedLoginProvider))
175+
val selectedLoginProvider = AuthConnection.GOOGLE
176+
val loginCompletableFuture: CompletableFuture<Web3AuthResponse> =
177+
web3Auth.connectTo(LoginParams(selectedLoginProvider, authConnectionId = "w3a-google", groupedAuthConnectionId = "aggregate-sapphire"))
177178

178179
loginCompletableFuture.whenComplete { _, error ->
179180
if (error == null) {
180-
credentials = Credentials.create(web3Auth.getPrivkey())
181+
credentials = Credentials.create(web3Auth.getPrivateKey())
181182
reRender()
182183
} else {
183184
Log.d("MainActivity_Web3Auth", error.message ?: "Something went wrong")
@@ -200,23 +201,23 @@ class MainActivity : AppCompatActivity() {
200201
}
201202

202203
private fun prepareLoginParams(): LoginParams {
203-
val loginParams = if(web3Auth.getUserInfo()!!.typeOfLogin == TypeOfLogin.GOOGLE.name) {
204-
LoginParams(Provider.GOOGLE)
204+
val loginParams = if(web3Auth.getUserInfo()!!.authConnection == AuthConnection.GOOGLE.name) {
205+
LoginParams(AuthConnection.GOOGLE)
205206
} else {
206-
LoginParams(Provider.JWT, extraLoginOptions = ExtraLoginOptions(domain = "https://web3auth.au.auth0.com", verifierIdField = "email", isVerifierIdCaseSensitive = false))
207+
LoginParams(
208+
AuthConnection.CUSTOM,
209+
extraLoginOptions = ExtraLoginOptions(
210+
domain = "https://web3auth.au.auth0.com",
211+
userIdField = "email",
212+
isUserIdCaseSensitive = false
213+
)
214+
)
207215
}
208216
return loginParams
209217
}
210218

211219
private fun launchWalletServices() {
212-
val completableFuture = web3Auth.launchWalletServices(
213-
ChainConfig(
214-
chainId = "0x1",
215-
rpcTarget = "https://1rpc.io/eth",
216-
ticker = "ETH",
217-
chainNamespace = ChainNamespace.EIP155
218-
)
219-
)
220+
val completableFuture = web3Auth.showWalletUI()
220221

221222
completableFuture.whenComplete{_, error ->
222223
if(error == null) {
@@ -320,7 +321,7 @@ class MainActivity : AppCompatActivity() {
320321
var key: String? = null
321322
var userInfo: UserInfo? = null
322323
try {
323-
key = web3Auth.getPrivkey()
324+
key = web3Auth.getPrivateKey()
324325
userInfo = web3Auth.getUserInfo()
325326
} catch (ex: Exception) {
326327
print(ex)

android-firebase-example/app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ dependencies {
3737
implementation 'com.google.android.material:material:1.7.0'
3838
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
3939
implementation 'com.google.code.gson:gson:2.9.1'
40-
implementation 'com.github.grvgoel81:web3auth-android-sdk:2.0.0.5'
40+
implementation 'com.github.grvgoel81:web3auth-android-sdk:3.0.0.1'
4141
implementation 'org.web3j:core:4.8.7-android'
4242
implementation platform('com.google.firebase:firebase-bom:31.0.2')
4343
implementation 'com.google.firebase:firebase-auth-ktx'

android-firebase-example/app/src/main/java/com/sbz/web3authdemoapp/MainActivity.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import com.google.firebase.auth.GetTokenResult
1414
import com.google.firebase.auth.ktx.auth
1515
import com.google.firebase.ktx.Firebase
1616
import com.google.gson.Gson
17+
import com.google.gson.JsonArray
1718
import com.web3auth.core.Web3Auth
1819
import com.web3auth.core.types.*
1920
import org.torusresearch.fetchnodedetails.types.Web3AuthNetwork
@@ -207,8 +208,15 @@ class MainActivity : AppCompatActivity() {
207208
}
208209

209210
private fun launchWalletServices() {
211+
val params = JsonArray().apply {
212+
// Message to be signed
213+
add("Hello, World!")
214+
// User's EOA address
215+
add(credentials.address)
216+
}
217+
210218

211-
val completableFuture = web3Auth.showWalletUI()
219+
val completableFuture = web3Auth.request("personal_sign", params)
212220

213221
completableFuture.whenComplete{_, error ->
214222
if(error == null) {

android-quick-start/app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ dependencies {
4444
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
4545
implementation 'com.google.code.gson:gson:2.9.1'
4646
// IMP START - Installation
47-
implementation 'com.github.grvgoel81:web3auth-android-sdk:2.0.0.5'
47+
implementation 'com.github.grvgoel81:web3auth-android-sdk:3.0.0.1'
4848
// IMP END - Installation
4949
implementation 'org.web3j:core:4.8.7-android'
5050
testImplementation 'junit:junit:4.13.2'

android-quick-start/app/src/main/java/com/sbz/web3authdemoapp/MainActivity.kt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,9 @@ class MainActivity : AppCompatActivity() {
5454
web3Auth = Web3Auth(
5555
Web3AuthOptions(
5656
clientId = getString(R.string.web3auth_project_id),
57-
web3AuthNetwork = Web3AuthNetwork.SAPPHIRE_MAINNET, // pass over the network you want to use (MAINNET or TESTNET or CYAN, AQUA, SAPPHIRE_MAINNET or SAPPHIRE_TESTNET)
58-
redirectUrl = "com.sbz.web3authdemoapp://auth"
57+
web3AuthNetwork = Web3AuthNetwork.SAPPHIRE_DEVNET, // pass over the network you want to use (MAINNET or TESTNET or CYAN, AQUA, SAPPHIRE_MAINNET or SAPPHIRE_TESTNET)
58+
redirectUrl = "com.sbz.web3authdemoapp://auth",
59+
defaultChainId = "0xaa36a7"
5960
), this
6061
)
6162
// IMP END - Initialize Web3Auth
@@ -100,7 +101,13 @@ class MainActivity : AppCompatActivity() {
100101
Log.i("Is MFA Enabled", web3Auth.getUserInfo()?.isMfaEnabled.toString())
101102
try {
102103
val enableMFACF = web3Auth.showWalletUI()
103-
val isSuccess = enableMFACF.get()
104+
val isSuccess = enableMFACF.whenComplete{ result, _ ->
105+
// if(result.result != null) {
106+
// Log.i("Result", result.result.toString())
107+
// } else {
108+
// Log.i("Error", result.error.toString())
109+
// }
110+
}
104111
Log.i("Is Success", isSuccess.toString())
105112
} catch (e: Exception) {
106113
Log.e("MFA ERROR", e.toString())

android-quick-start/app/src/main/res/values/strings.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<resources>
22
<string name="app_name">Web3Auth Android QuickStart App</string>
33
<!-- // IMP START - Get your Web3Auth Client ID from Dashboard -->
4-
<string name="web3auth_project_id">BPi5PB_UiIZ-cPz1GtV5i1I2iOSOHuimiXBI0e-Oe_u6X3oVAbCiAZOTEBtTXw4tsluTITPqA8zMsfxIKMjiqNQ</string>
4+
<string name="web3auth_project_id">BJFT2n2Nc-2HY9yJCacDygMvuJQc8do8bF7GMWig2KiZgJJ5ks-Hiw_JvcJvqiJ5yYTkRptfwoeQFkqJZAG65do</string>
55
<!-- // IMP END - Get your Web3Auth Client ID from Dashboard -->
66
<string name="web3auth_android_demo">Web3Auth Android Example Demo</string>
77
<string name="login_with_google">Login</string>
-15.3 KB
Binary file not shown.
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
#Thu Apr 13 13:56:35 IST 2023
21
distributionBase=GRADLE_USER_HOME
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
42
distributionPath=wrapper/dists
5-
zipStorePath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
4+
networkTimeout=10000
5+
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME
7+
zipStorePath=wrapper/dists

0 commit comments

Comments
 (0)