Skip to content

Commit 00aa9f2

Browse files
Update android SDK (#2295)
* Update android SDK * Updates wrt comments in PR * Fix checklist * Add params for web3auth options * Delete smart-accounts.mdx * temp * Update android-wallet.mdx * Update README.mdx * fixes * cursor fix * Updates * Run vale and consensys style guide --------- Co-authored-by: Yashovardhan Agrawal <21066442+yashovardhan@users.noreply.github.com> Co-authored-by: Alexandra Carrillo <alexandra.carrillo@consensys.net>
1 parent 1556d80 commit 00aa9f2

29 files changed

Lines changed: 1676 additions & 989 deletions

File tree

embedded-wallets/authentication/custom-connections/auth0.mdx

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
2-
title: Auth0 Login with Embedded Wallets
2+
title: Auth0 sign-in with Embedded Wallets
33
sidebar_label: Auth0
4-
description: 'Auth0 Login with Embedded Wallets | Embedded Wallets'
4+
description: 'Auth0 sign-in with Embedded Wallets | Embedded Wallets'
55
---
66

77
import Tabs from '@theme/Tabs'
@@ -17,7 +17,7 @@ import ImplicitLoginAuth0Spa from '../../sdk/react/advanced/_custom-authenticati
1717

1818
[Auth0](https://auth0.com/docs/get-started/auth0-overview) is an authentication and authorization platform that enables developers to securely manage user identities. Web3Auth offers native support for integrating Auth0 as a service provider, allowing projects to leverage Auth0's robust authentication mechanisms within the Web3Auth ecosystem.
1919

20-
Auth0 supports a [wide set of social logins](https://marketplace.auth0.com/categories/social-login).
20+
Auth0 supports a [wide set of social sign-in providers](https://marketplace.auth0.com/categories/social-login).
2121

2222
## Create an Auth0 application
2323

@@ -43,7 +43,7 @@ export const Auth0Setup = [
4343
path: 'https://auth0.com/docs/quickstart/native/android/interactive',
4444
},
4545
{
46-
key: 'ios',
46+
key: 'iOS',
4747
title: 'iOS',
4848
icon: 'logo-apple.png',
4949
path: 'https://auth0.com/docs/quickstart/native/ios-swift/interactive',
@@ -123,54 +123,53 @@ In your activity, create a `Web3Auth` instance with your Web3Auth project's conf
123123
```kotlin
124124
web3Auth = Web3Auth(
125125
Web3AuthOptions(
126-
context = this,
127126
clientId = getString(R.string.web3auth_project_id), // pass over your Web3Auth Client ID from Embedded Wallets dashboard
128-
network = Network.SAPPHIRE_MAINNET
129-
redirectUrl = Uri.parse("{YOUR_APP_PACKAGE_NAME}://auth"), // your app's redirect URL
127+
web3AuthNetwork = Web3AuthNetwork.SAPPHIRE_MAINNET,
128+
redirectUrl = "{YOUR_APP_PACKAGE_NAME}://auth", // your app's redirect URL
130129
// focus-start
131-
loginConfig = hashMapOf("jwt" to LoginConfigItem(
132-
verifier = "web3auth-auth0-demo",
133-
typeOfLogin = TypeOfLogin.JWT,
134-
name = "Auth0 Login",
130+
authConnectionConfig = listOf(
131+
AuthConnectionConfig(
132+
authConnection = AuthConnection.CUSTOM,
133+
authConnectionId = "web3auth-auth0-demo",
135134
clientId = getString(R.string.web3auth_auth0_client_id)
136-
)
135+
)
137136
)
138137
// focus-end
139-
)
138+
),
139+
this
140140
)
141141

142142
// Handle user signing in when app is not alive
143143
web3Auth.setResultUrl(intent?.data)
144144
```
145145

146-
##### Logging in
146+
##### Signing in
147147

148-
Once initialized, you can use the `web3Auth.login(LoginParams("{selectedLoginProvider}"))` function to authenticate the user when they click the login button.
148+
Once initialized, you can use the `web3Auth.connectTo(LoginParams(...))` function to authenticate the user when they click the sign-in button.
149149

150150
```kotlin
151151
private fun signIn() {
152-
val selectedLoginProvider = Provider.JWT // For Auth0, we use JWT
153-
val loginCompletableFuture: CompletableFuture<Web3AuthResponse> = web3Auth.login(
152+
val loginCompletableFuture: CompletableFuture<Web3AuthResponse> = web3Auth.connectTo(
154153
// focus-start
155154
LoginParams(
156-
selectedLoginProvider,
155+
authConnection = AuthConnection.CUSTOM,
156+
authConnectionId = "web3auth-auth0-demo",
157157
extraLoginOptions = ExtraLoginOptions(
158-
domain = "https://YOUR_AUTH0_DOMAIN",
159-
verifierIdField = "sub"
158+
domain = "https://YOUR_AUTH0_DOMAIN"
160159
)
161160
)
162161
// focus-end
163162
)
164163
}
165164
```
166165

167-
When connecting, the `login` function takes the LoginParams arguments for the login. See the [LoginParams](/embedded-wallets/sdk/android/usage/login#parameters) for more details.
166+
When connecting, the `connectTo` function takes the `LoginParams` arguments for sign-in. See the [LoginParams](/embedded-wallets/sdk/android/usage/connect-to#parameters) for more details.
168167

169168
### Flutter
170169

171170
##### Create a Web3Auth instance
172171

173-
In your `main.dart` file, initialize the `Web3AuthFlutter` plugin at the very beginning such as in the overriden `initState` function
172+
In your `main.dart` file, initialize the `Web3AuthFlutter` plugin at the start of your app, such as in the overridden `initState` function
174173

175174
```dart
176175
Future<void> initPlatformState() async {
@@ -208,7 +207,7 @@ Future<void> initPlatformState() async {
208207

209208
##### Logging in
210209

211-
Once initialized, you can use the `Web3AuthFlutter.login(LoginParams( loginProvider: Provider.google ))` function to authenticate the user when they click the login button.
210+
Once initialized, you can use the `Web3AuthFlutter.login(LoginParams( loginProvider: Provider.google ))` function to authenticate the user when they click the sign-in button.
212211

213212
```dart
214213
Future<Web3AuthResponse> _withAuth0() {

embedded-wallets/authentication/custom-connections/firebase.mdx

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
2-
title: Firebase Login with Embedded Wallets
2+
title: Firebase sign-in with Embedded Wallets
33
sidebar_label: Firebase
4-
description: 'Firebase Login with Embedded Wallets | Embedded Wallets'
4+
description: 'Firebase sign-in with Embedded Wallets | Embedded Wallets'
55
---
66

77
import Tiles from '@theme/Tiles'
@@ -10,9 +10,9 @@ import CustomConnectionOptions from '@site/static/img/embedded-wallets/dev-dashb
1010
import FirebaseConnection from '@site/static/img/embedded-wallets/dev-dashboard/firebase-connection.png'
1111
import JwtLoginFirebase from '../../sdk/react/advanced/_custom-authentication-snippets/_jwt_login_firebase.mdx'
1212

13-
[Firebase](https://firebase.google.com/) is a popular backend platform that enables developers to integrate authentication, databases, and other services into their applications. Embedded Wallets supports Firebase as an authentication provider, allowing developers to leverage Firebase Authentication within the Web3Auth framework for secure user login and key management.
13+
[Firebase](https://firebase.google.com/) is a popular backend platform that enables developers to integrate authentication, databases, and other services into their applications. Embedded Wallets supports Firebase as an authentication provider, allowing developers to leverage Firebase Authentication within the Web3Auth framework for secure user sign-in and key management.
1414

15-
Firebase [supports a wide set of social logins](https://firebase.google.com/docs/auth).
15+
Firebase [supports a wide set of social sign-in providers](https://firebase.google.com/docs/auth).
1616

1717
## Create a Firebase project
1818

@@ -25,6 +25,8 @@ Web3Auth's Firebase integration enables the use of Firebase-issued ID tokens to
2525
For detailed implementation steps and platform-specific instructions, developers can follow the [Firebase documentation](https://firebase.google.com/docs).
2626
:::
2727

28+
<!-- vale off -->
29+
2830
export const FirebaseSetup = [
2931
{
3032
name: '',
@@ -43,7 +45,7 @@ export const FirebaseSetup = [
4345
path: 'https://firebase.google.com/docs/android/setup',
4446
},
4547
{
46-
key: 'ios',
48+
key: 'iOS',
4749
title: 'iOS',
4850
icon: 'logo-apple.png',
4951
path: 'https://firebase.google.com/docs/ios/setup',
@@ -64,6 +66,8 @@ export const FirebaseSetup = [
6466
},
6567
]
6668

69+
<!-- vale on -->
70+
6771
<Tiles tileGroups={FirebaseSetup} />
6872

6973
## Create a Firebase connection
@@ -87,7 +91,7 @@ Follow these steps to create a Firebase connection:
8791
1. Select the **JWT user identifier**: `email`, `sub` or `custom`.
8892
1. (Optional) Toggle the case sensitivity of **User Identifier**.
8993
1. Click on **Add Custom Validations** to add validations manually.
90-
1. Type iss as a field and `https://securetoken.google.com/FIREBASE-PROJECT-ID` as a value.
94+
1. Type `iss` as a field and `https://securetoken.google.com/FIREBASE-PROJECT-ID` as a value.
9195
1. Next, type aud as a field and `FIREBASE-PROJECT-ID` as a value.
9296
1. Click on the **Add Connection** button to save the settings.
9397

@@ -116,29 +120,29 @@ In your activity, create a `Web3Auth` instance with your Web3Auth project's conf
116120
```kotlin
117121
web3Auth = Web3Auth(
118122
Web3AuthOptions(
119-
context = this,
120123
clientId = getString(R.string.web3auth_project_id), // pass over your Web3Auth Client ID from Embedded Wallets dashboard
121-
network = Network.SAPPHIRE_MAINNET
122-
redirectUrl = Uri.parse("{YOUR_APP_PACKAGE_NAME}://auth"), // your app's redirect URL
124+
web3AuthNetwork = Web3AuthNetwork.SAPPHIRE_MAINNET,
125+
redirectUrl = "{YOUR_APP_PACKAGE_NAME}://auth", // your app's redirect URL
123126
// focus-start
124-
loginConfig = hashMapOf("jwt" to LoginConfigItem(
125-
verifier = "web3auth-firebase-examples",
126-
typeOfLogin = TypeOfLogin.JWT,
127-
name = "Firebase Login",
127+
authConnectionConfig = listOf(
128+
AuthConnectionConfig(
129+
authConnection = AuthConnection.CUSTOM,
130+
authConnectionId = "web3auth-firebase-examples",
128131
clientId = getString(R.string.web3auth_project_id)
129-
)
132+
)
130133
)
131134
// focus-end
132-
)
135+
),
136+
this
133137
)
134138

135139
// Handle user signing in when app is not alive
136140
web3Auth.setResultUrl(intent?.data)
137141
```
138142

139-
##### Logging in
143+
##### Signing in
140144

141-
Once initialized, you can use the `web3Auth.login(LoginParams("{selectedLoginProvider}"))` function to authenticate the user when they click the login button.
145+
Once initialized, you can use the `web3Auth.connectTo(LoginParams(...))` function to authenticate the user when they click the sign-in button.
142146

143147
```kotlin
144148
private fun signIn() {
@@ -155,17 +159,15 @@ private fun signIn() {
155159
val idToken = result.token
156160

157161
Log.d(TAG, "GetTokenResult result = $idToken")
158-
val selectedLoginProvider = Provider.JWT
159162
// focus-start
160-
val loginCompletableFuture: CompletableFuture<Web3AuthResponse> = web3Auth.login(
163+
val loginCompletableFuture: CompletableFuture<Web3AuthResponse> = web3Auth.connectTo(
161164
LoginParams(
162-
selectedLoginProvider,
163-
extraLoginOptions = ExtraLoginOptions(
164-
domain = "firebase", id_token = idToken
165-
)
166-
)
165+
authConnection = AuthConnection.CUSTOM,
166+
authConnectionId = "web3auth-firebase-examples",
167+
idToken = idToken
167168
)
168-
// focus-end
169+
)
170+
// focus-end
169171

170172
loginCompletableFuture.whenComplete { loginResponse, error ->
171173
if (error == null) {
@@ -187,13 +189,13 @@ private fun signIn() {
187189
}
188190
```
189191

190-
When connecting, the `login` function takes the LoginParams arguments for the login. See the [LoginParams](/embedded-wallets/sdk/android/usage/login#parameters) for more details.
192+
When connecting, the `connectTo` function takes the `LoginParams` arguments for sign-in. See the [LoginParams](/embedded-wallets/sdk/android/usage/connect-to#parameters) for more details.
191193

192194
### Flutter
193195

194196
##### Create a Web3Auth instance
195197

196-
In your `main.dart` file, initialize the `Web3AuthFlutter` plugin at the very beginning such as in the overriden `initState` function
198+
In your `main.dart` file, initialize the `Web3AuthFlutter` plugin at the start of your app, such as in the overridden `initState` function
197199

198200
```dart
199201
@override
@@ -238,7 +240,7 @@ Future<void> initPlatformState() async {
238240

239241
##### Logging in
240242

241-
Once initialized, you can use the `Web3AuthFlutter.login(LoginParams( loginProvider: Provider.google ))` function to authenticate the user when they click the login button.
243+
Once initialized, you can use the `Web3AuthFlutter.login(LoginParams( loginProvider: Provider.google ))` function to authenticate the user when they click the sign-in button.
242244

243245
```dart
244246
Future<Web3AuthResponse> _withJWT() async {

embedded-wallets/connect-blockchain/_android-connect-blockchain/_evm-get-account.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
Once user has successfully logged in, you can retrieve the user's private key using the `getPrivKey` method from the Embedded Wallets Android SDK. We'll use this private key to generate the Credentials for the user.
1+
Once user has successfully logged in, you can retrieve the user's private key using the `getPrivateKey` method from the Embedded Wallets Android SDK. We'll use this private key to generate the Credentials for the user.
22

33
This Credentials object has the user's keypair of private key and public key, and can be used to sign the transactions. Please note, that this assumes that the user has already logged in and the private key is available.
44

55
```kotlin
66
import org.web3j.crypto.Credentials
77

88
// Use your Embedded Wallets SDK instance to get the private key
9-
val privateKey = web3Auth.getPrivKey()
9+
val privateKey = web3Auth.getPrivateKey()
1010

1111
// Generate the Credentials
1212
val credentials = Credentials.create(privateKey)

embedded-wallets/connect-blockchain/_android-connect-blockchain/_evm-installation.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ To interact with Ethereum in Android, you can use any [`EIP1193`](https://eips.e
33
```groovy
44
dependencies {
55
// ...
6-
implementation 'org.web3j:core:4.8.7-android'
6+
implementation 'org.web3j:core:4.8.8-android'
77
}
88
```

embedded-wallets/connect-blockchain/solana/android.mdx

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ description: 'Integrate Embedded Wallets with the Solana Blockchain in Android |
1010
import TabItem from '@theme/TabItem'
1111
import Tabs from '@theme/Tabs'
1212

13-
While using the Embedded Wallets Android SDK (formerly Web3Auth), you can retrieve the Ed25519 private key upon successful authentication. This private key can be used to derive the user's public address and interact with the [Solana](https://solana.org/) chain. We've highlighted a few methods here to get you started quickly.
13+
While using the Embedded Wallets Android SDK (formerly Web3Auth), you can retrieve the Ed25519 private key upon successful authentication. This private key can be used to derive the user's public address and interact with the [Solana](https://solana.org/) chain. We've highlighted a few methods here to help you get started.
1414

1515
::::note
1616

@@ -77,7 +77,7 @@ In your app-level `build.gradle` dependencies section, add the following:
7777
<Tabs defaultValue = "groovy"
7878
values={[
7979
{ label: "Groovy", value: "groovy", },
80-
{ label: "Kotlin", value: "kotlin", },
80+
{ label: "Kotlin DSL", value: "kotlin-dsl", },
8181
]}
8282
>
8383

@@ -91,7 +91,7 @@ dependencies {
9191

9292
</TabItem>
9393

94-
<TabItem value="kotlin">
94+
<TabItem value="kotlin-dsl">
9595

9696
```kotlin
9797
dependencies {
@@ -104,7 +104,7 @@ dependencies {
104104

105105
## Initialize
106106

107-
To Initialize the `Connection` we require a RPC URL. The `Connection` object will provide a gateway and protocol to interact with Solana cluster while sending requests and receving response. The `sol4k` SDK also provides `RpcUrl` constant for all the supported clusters. For this example, we are using `RpcUrl.DEVNET` for Devnet-beta. To interact with Testnet or Mainnet, change the `RpcUrl`.
107+
To Initialize the `Connection` we require a RPC URL. The `Connection` object will provide a gateway and protocol to interact with Solana cluster while sending requests and receiving responses. The `sol4k` SDK also provides `RpcUrl` constant for all the supported clusters. For this example, we are using `RpcUrl.DEVNET` for Devnet-beta. To interact with Testnet or Mainnet, change the `RpcUrl`.
108108

109109
### Initializing the Solana SDK
110110

@@ -131,42 +131,43 @@ The session can be persisted for up to 30 days max.
131131

132132
```kotlin
133133
import com.web3auth.core.Web3Auth
134-
import com.web3auth.core.types.Network
135134
import com.web3auth.core.types.Web3AuthOptions
135+
import org.torusresearch.fetchnodedetails.types.Web3AuthNetwork
136136

137137
// Initialize Web3Auth SDK
138138
// focus-start
139139
val web3Auth: Web3Auth = Web3Auth(
140140
Web3AuthOptions(
141141
clientId = "BPi5PB_UiIZ-cPz1GtV5i1I2iOSOHuimiXBI0e-Oe_u6X3oVAbCiAZOTEBtTXw4tsluTITPqA8zMsfxIKMjiqNQ",
142-
context = context,
143-
network = Network.SAPPHIRE_MAINNET,
144-
redirectUrl = Uri.parse( "com.example.androidsolanaexample://auth")
145-
)
142+
web3AuthNetwork = Web3AuthNetwork.SAPPHIRE_MAINNET,
143+
redirectUrl = "com.example.androidsolanaexample://auth"
144+
),
145+
context
146146
)
147147
// focus-end
148148

149149
// Check whether private key is empty or not for user authentication status.
150-
val isUserAuthenticated = web3Auth.getPrivkey().isNotEmpty()
150+
val isUserAuthenticated = web3Auth.getEd25519PrivateKey().isNotEmpty()
151151

152152
// Customize your logic to perform operations or navigation
153153
```
154154

155155
## Get account
156156

157-
We can use `getEd25519PrivKey` method in Web3Auth to retrieve the private key for the Solana ecosystem. In the following code block, we'll use the Ed25519 private key to retrieve user's public address by creating `Keypair`. The `Keypair` instance from `sol4k` SDK once created can be used to sign the Solana transactions.
157+
We can use `getEd25519PrivateKey` method in Web3Auth to retrieve the private key for the Solana ecosystem. In the following code block, we'll use the Ed25519 private key to retrieve user's public address by creating `Keypair`. The `Keypair` instance from `sol4k` SDK once created can be used to sign the Solana transactions.
158158

159159
```kotlin
160-
val ed25519PrivateKey = web3Auth.getEd25519PrivKey()
160+
val ed25519PrivateKey = web3Auth.getEd25519PrivateKey()
161161
val solanaKeyPair = Keypair.fromSecretKey(ed25519PrivateKey.hexToByteArray())
162162

163163
// focus-next-line
164-
val userAccount = solanaKeyPair.publicKey.toBase58()
164+
// Get the user's public key
165+
val publicKey = solanaKeyPair.publicKey.toBase58()
165166
```
166167

167168
## Get user balance
168169

169-
Once we have retrieved userAccount, we can use it to fetch user balance. We'll use `getBalance` method from `Connection` instance to interact with Solana cluster and fetch user balance. The response of `getBalance` is BigInteger, we will need to divide it by 10^9, because Solana's token decimals is 9.
170+
Once you have the user's public key, you can use it to fetch the user balance. We'll use `getBalance` method from `Connection` instance to interact with Solana cluster and fetch user balance. The response of `getBalance` is BigInteger, we will need to divide it by 10^9, because Solana's token decimals is 9.
170171

171172
```kotlin
172173
try {
@@ -186,7 +187,7 @@ try {
186187

187188
## Sign a transaction
188189

189-
Let's now go through how can we sign the transaction. In the below codeblock, we'll create a new function `prepareSignedTransaction` which can be used to retrieve the Base58 signature as well as broadcast transaction to the cluster. We'll use `TransferInstruction` to create the transaction to self transfer 0.01 Sol and sign it.
190+
Let's now go through how can we sign the transaction. In the below code block, we'll create a new function `prepareSignedTransaction` which can be used to retrieve the Base58 signature as well as broadcast transaction to the cluster. We'll use `TransferInstruction` to create the transaction to self transfer 0.01 Sol and sign it.
190191

191192
```kotlin
192193
private suspend fun prepareSignedTransaction(sender: Keypair) : Transaction = withContext(Dispatchers.IO) {

embedded-wallets/migration-guides/README.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ current SDK in one pass.
3030
| Platform | Upgrade to | Covers upgrades from |
3131
| ---------------------------------------------------------------------- | ---------- | -------------------- |
3232
| [Web (JavaScript, React, Vue)](/embedded-wallets/migration-guides/web) | v11 | v9 through v10 |
33-
| [Android](/embedded-wallets/migration-guides/android) | v9 | v4 through v8 |
33+
| [Android](/embedded-wallets/migration-guides/android) | v10 | v4 through v9 |
3434
| [iOS](/embedded-wallets/migration-guides/ios) | v10 | v6 through v9 |
3535
| [React Native](/embedded-wallets/migration-guides/react-native) | v9 | v3 through v8 |
3636
| [Flutter](/embedded-wallets/migration-guides/flutter) | v6 | v3 through v5 |

0 commit comments

Comments
 (0)