Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,12 @@ web3Auth.setResultUrl(intent?.data)

##### Logging in

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

```kotlin
private fun signIn() {
val selectedLoginProvider = Provider.JWT // For Auth0, we use JWT
val loginCompletableFuture: CompletableFuture<Web3AuthResponse> = web3Auth.login(
val loginCompletableFuture: CompletableFuture<Web3AuthResponse> = web3Auth.connectTo(
// focus-start
LoginParams(
selectedLoginProvider,
Expand All @@ -184,7 +184,7 @@ private fun signIn() {
}
```

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.
When connecting, the `connectTo` function takes the LoginParams arguments for the login. See the [LoginParams](../../../sdk/android/usage/connectTo#parameters) for more details.

### Flutter

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ web3Auth.setResultUrl(intent?.data)

##### Logging in

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

```kotlin
private fun signIn() {
Expand All @@ -177,7 +177,7 @@ private fun signIn() {
Log.d(TAG, "GetTokenResult result = $idToken")
val selectedLoginProvider = Provider.JWT
// focus-start
val loginCompletableFuture: CompletableFuture<Web3AuthResponse> = web3Auth.login(
val loginCompletableFuture: CompletableFuture<Web3AuthResponse> = web3Auth.connectTo(
LoginParams(
selectedLoginProvider,
extraLoginOptions = ExtraLoginOptions(
Expand Down Expand Up @@ -207,7 +207,7 @@ private fun signIn() {
}
```

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.
When connecting, the `connectTo` function takes the LoginParams arguments for the login. See the [LoginParams](../../../sdk/android/usage/connectTo#parameters) for more details.

### Flutter

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ To interact with Ethereum in Android, you can use any [`EIP1193`](https://eips.e
```groovy
dependencies {
// ...
implementation 'org.web3j:core:4.8.7-android'
implementation 'org.web3j:core:4.8.8-android'
}
```
78 changes: 51 additions & 27 deletions embedded-wallets/sdk/android/README.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ MetaMask Embedded Wallets SDK (formerly Web3Auth Plug and Play) provides a seaml

## Requirements

- Android API version `24` or newer
- Android API version `26` or newer
- Android Compile and Target SDK: `34`
- Basic knowledge of Java or Kotlin development

Expand Down Expand Up @@ -55,7 +55,7 @@ Then, in your app-level `build.gradle` dependencies section, add the following:
dependencies {
// ...
// focus-next-line
implementation 'com.github.web3auth:web3auth-android-sdk:9.1.2'
implementation 'com.github.web3auth:web3auth-android-sdk:10.0.0'
}
```

Expand Down Expand Up @@ -154,15 +154,16 @@ Create an Embedded Wallets instance and configure it with your project settings:
```kotlin
import com.web3auth.core.Web3Auth
import com.web3auth.core.types.Web3AuthOptions
import org.torusresearch.fetchnodedetails.types.Web3AuthNetwork

// focus-start
var web3Auth = Web3Auth(
Web3AuthOptions(
context = this,
clientId = "YOUR_WEB3AUTH_CLIENT_ID", // Pass your Web3Auth Client ID, ideally using an environment variable
network = Network.MAINNET,
redirectUrl = Uri.parse("{YOUR_APP_PACKAGE_NAME}://auth"),
)
clientId = "YOUR_WEB3AUTH_CLIENT_ID", // Pass over your Web3Auth Client ID from Developer Dashboard
web3AuthNetwork = Web3AuthNetwork.SAPPHIRE_MAINNET, // or Web3AuthNetwork.SAPPHIRE_DEVNET
redirectUrl = "{YOUR_APP_PACKAGE_NAME}://auth",
),
this
)
// focus-end

Expand All @@ -187,11 +188,17 @@ override fun onNewIntent(intent: Intent?) {

After instantiating Embedded Wallets, the next step is to initialize it using the `initialize` method. This method is essential for setting up the SDK, checking for any active sessions, and fetching the whitelabel configuration from your dashboard.

Once the `initialize` method executes successfully, you can use the `getPrivKey` or `getEd25519PrivKey` methods to verify if an active session exists. If there is no active session, these methods will return an empty string; otherwise, they will return the respective private key.
Once the `initialize` method executes successfully, you can use the `getPrivateKey` or `getEd25519PrivateKey` methods to verify if an active session exists. If there is no active session, these methods will return an empty string; otherwise, they will return the respective private key.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is changed, the initialize method will throw an error that needs to be swallowed if the session is not present.

initialize method can fail if the session is not present, or if there is an network issue to get the dashboard configuration, or session validation.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added extra context


:::note

If the API call to fetch the project configuration fails, the method will throw an error.
The `initialize` method may throw an error in the following situations:

- No active session exists for the user.
- A network error occurs while fetching the project configuration from the dashboard.
- Session validation fails (for example, the stored session token is invalid or expired).

Wrap the call in a `whenComplete` handler and treat any non-null error as a failed initialization rather than an absent session.

:::

Expand All @@ -200,7 +207,7 @@ val initializeCF: CompletableFuture<Void> = web3Auth.initialize()
initializeCF.whenComplete { _, error ->
if (error == null) {
// Check for the active session
if(web3Auth.getPrivKey()isNotEmpty()) {
if(web3Auth.getPrivateKey().isNotEmpty()) {
// Active session found
}
// No active session is not present
Expand Down Expand Up @@ -239,11 +246,11 @@ See the [advanced configuration sections](./advanced/) to learn more about each
```kotlin
val web3Auth = Web3Auth(
Web3AuthOptions(
context = this,
clientId = "YOUR_WEB3AUTH_CLIENT_ID", // Pass your Web3Auth Client ID, ideally using an environment variable
network = Network.SAPPHIRE_MAINNET, // or Network.SAPPHIRE_DEVNET
clientId = "YOUR_CLIENT_ID",
web3AuthNetwork = Web3AuthNetwork.SAPPHIRE_MAINNET, // or Web3AuthNetwork.SAPPHIRE_DEVNET
redirectUrl = "YOUR_APP_SCHEME://auth"
)
),
this
)
```

Expand All @@ -254,13 +261,12 @@ val web3Auth = Web3Auth(
```kotlin
val web3Auth = Web3Auth(
Web3AuthOptions(
context = this,
clientId = "YOUR_WEB3AUTH_CLIENT_ID", // Pass your Web3Auth Client ID, ideally using an environment variable
network = Network.SAPPHIRE_MAINNET, // or Network.SAPPHIRE_DEVNET
redirectUrl = "YOUR_APP_SCHEME://auth"
loginConfig = hashMapOf("google" to LoginConfigItem(
verifier = "verifier-name", // Get it from Web3Auth dashboard
typeOfLogin = TypeOfLogin.GOOGLE,
clientId = "YOUR_CLIENT_ID",
web3AuthNetwork = Web3AuthNetwork.SAPPHIRE_MAINNET, // or Web3AuthNetwork.SAPPHIRE_DEVNET
redirectUrl = "YOUR_APP_SCHEME://auth",
authConnectionConfig = listOf(AuthConnectionConfig(
authConnectionId = "auth-connection-id", // Get it from Web3Auth dashboard
authConnection = AuthConnection.GOOGLE,
clientId = getString(R.string.google_client_id) // Google's client id
)),
mfaSettings = MfaSettings(
Expand All @@ -271,21 +277,39 @@ val web3Auth = Web3Auth(
passkeysFactor = MfaSetting(true, 5, true),
authenticatorFactor = MfaSetting(true, 6, true),
)
)
),
this
)
```

</TabItem>

</Tabs>

## Blockchain integration
## Single Factor Auth (SFA) Support

Web3Auth Android SDK includes built-in support for Single Factor Auth (SFA), allowing for seamless authentication when you already have a JWT token from your authentication system. When MFA is disabled, users won't even notice Web3Auth's presence - they'll be automatically authenticated using just your JWT token, making the login experience completely frictionless.

```kotlin
// SFA login with custom JWT
val loginCompletableFuture = web3Auth.connectTo(
LoginParams(
AuthConnection.CUSTOM,
authConnectionId = "your_verifier_id",
idToken = "your_jwt_token"
)
)
```

SFA mode is automatically activated when you provide an `idToken` parameter. This enables direct authentication without additional social login steps, perfect for applications that already have their own authentication system.

## Blockchain Integration

Embedded Wallets is blockchain agnostic, enabling integration with any blockchain network. Out of the box, Embedded Wallets offers robust support for both **Solana** and **Ethereum**.

### Ethereum integration

For Ethereum integration, you can get the private key using the `getPrivKey` method and use it with web3j or other Ethereum libraries:
For Ethereum integration, you can get the private key using the `getPrivateKey` method and use it with web3j or other Ethereum libraries:

```kotlin
import org.web3j.crypto.Credentials
Expand All @@ -294,7 +318,7 @@ import org.web3j.protocol.Web3j
import org.web3j.protocol.http.HttpService

// Use your Web3Auth instance to get the private key
val privateKey = web3Auth.getPrivKey()
val privateKey = web3Auth.getPrivateKey()

// Generate the Credentials
val credentials = Credentials.create(privateKey)
Expand All @@ -314,7 +338,7 @@ val ethBalance = BigDecimal.valueOf(balanceResponse.balance.toDouble()).divide(B

### Solana integration

For Solana integration, you can get the Ed25519 private key using the `getEd25519PrivKey` method and use it with sol4k or any other Solana libraries:
For Solana integration, you can get the Ed25519 private key using the `getEd25519PrivateKey` method and use it with sol4k or any other Solana libraries:

```kotlin
import org.sol4k.Connection
Expand All @@ -323,7 +347,7 @@ import org.sol4k.Keypair
val connection = Connection(RpcUrl.DEVNET)

// Use your Web3Auth instance to get the private key
val ed25519PrivateKey = web3Auth.getEd25519PrivKey()
val ed25519PrivateKey = web3Auth.getEd25519PrivateKey()

// Generate the Solana KeyPair
val solanaKeyPair = Keypair.fromSecretKey(ed25519PrivateKey.hexToByteArray())
Expand Down
Loading
Loading