diff --git a/embedded-wallets/authentication/custom-connections/auth0.mdx b/embedded-wallets/authentication/custom-connections/auth0.mdx index 44f0a9b1bb0..e9931cc1ddc 100644 --- a/embedded-wallets/authentication/custom-connections/auth0.mdx +++ b/embedded-wallets/authentication/custom-connections/auth0.mdx @@ -173,51 +173,52 @@ In your `main.dart` file, initialize the `Web3AuthFlutter` plugin at the start o ```dart Future initPlatformState() async { - - Uri redirectUrl; + late final String redirectUrl; if (Platform.isAndroid) { - redirectUrl = Uri.parse('{SCHEME}://{HOST}/auth'); - // w3a://com.example.w3aflutter/auth + redirectUrl = 'w3a://com.example.w3aflutter'; } else if (Platform.isIOS) { - redirectUrl = Uri.parse('{bundleId}://auth'); - // com.example.w3aflutter://openlogin + redirectUrl = 'com.example.w3aflutter://openlogin'; } else { throw UnKnownException('Unknown platform'); } // focus-start - final loginConfig = HashMap(); - loginConfig['jwt'] = LoginConfigItem( - verifier: "VERIFIER-NAME", // get it from MetaMask Developer Dashboard - typeOfLogin: TypeOfLogin.jwt, - name: "Web3Auth Flutter Auth0 Example", - clientId: "AUTH0-CLIENT-ID" // auth0 client id - ); + final authConnectionConfig = [ + AuthConnectionConfig( + authConnection: AuthConnection.custom, + authConnectionId: "VERIFIER-NAME", + clientId: "AUTH0-CLIENT-ID", + name: "Web3Auth Flutter Auth0 Example", + ), + ]; // focus-end await Web3AuthFlutter.init(Web3AuthOptions( - clientId:'YOUR WEB3AUTH CLIENT ID FROM DASHBOARD', - network: Network.sapphire_mainnet, - redirectUri: redirectUrl, - loginConfig: loginConfig + clientId: 'YOUR WEB3AUTH CLIENT ID FROM DASHBOARD', + web3AuthNetwork: Web3AuthNetwork.sapphire_mainnet, + redirectUrl: redirectUrl, + authConnectionConfig: authConnectionConfig, )); await Web3AuthFlutter.initialize(); } ``` -##### Logging in +##### Signing in -Once initialized, you can use the `Web3AuthFlutter.login(LoginParams( loginProvider: Provider.google ))` function to authenticate the user when they click the sign-in button. +Once initialized, call `Web3AuthFlutter.connectTo()` to authenticate the user when they click the sign-in button. ```dart Future _withAuth0() { // focus-start - return Web3AuthFlutter.login(LoginParams( - loginProvider: Provider.jwt, + return Web3AuthFlutter.connectTo(LoginParams( + authConnection: AuthConnection.custom, + authConnectionId: "VERIFIER-NAME", mfaLevel: MFALevel.OPTIONAL, extraLoginOptions: ExtraLoginOptions( - domain: 'YOUR_AUTH0_DOMAIN', // eg. https://torus.us.auth0.com - verifierIdField: 'sub'))); + domain: 'YOUR_AUTH0_DOMAIN', + userIdField: 'sub', + ), + )); // focus-end } ``` diff --git a/embedded-wallets/authentication/custom-connections/firebase.mdx b/embedded-wallets/authentication/custom-connections/firebase.mdx index e624b0c9400..b0db92d9d76 100644 --- a/embedded-wallets/authentication/custom-connections/firebase.mdx +++ b/embedded-wallets/authentication/custom-connections/firebase.mdx @@ -205,45 +205,45 @@ void initState() { } Future initPlatformState() async { - final Uri redirectUrl; + late final String redirectUrl; if (Platform.isAndroid) { - redirectUrl = Uri.parse('{SCHEME}://{HOST}/auth'); + redirectUrl = 'w3a://com.example.w3aflutter'; } else if (Platform.isIOS) { - redirectUrl = Uri.parse('{bundleId}://auth'); + redirectUrl = 'com.example.w3aflutter://openlogin'; } else { throw UnKnownException('Unknown platform'); } // focus-start - final loginConfig = HashMap(); - - loginConfig['jwt'] = LoginConfigItem( - verifier: "VERIFIER_NAME", // get it from MetaMask Developer Dashboard - typeOfLogin: TypeOfLogin.jwt, - name: "Firebase JWT Login", - clientId: "WEB3AUTH_CLIENT_ID", // web3auth's plug and play client id - ); + final authConnectionConfig = [ + AuthConnectionConfig( + authConnection: AuthConnection.custom, + authConnectionId: "VERIFIER_NAME", + clientId: "WEB3AUTH_CLIENT_ID", + name: "Firebase JWT Login", + ), + ]; await Web3AuthFlutter.init( Web3AuthOptions( - clientId:'YOUR WEB3AUTH CLIENT ID FROM DASHBOARD', - network: Network.cyan, - redirectUri: redirectUrl, - loginConfig: loginConfig, - ) + clientId: 'YOUR WEB3AUTH CLIENT ID FROM DASHBOARD', + web3AuthNetwork: Web3AuthNetwork.sapphire_mainnet, + redirectUrl: redirectUrl, + authConnectionConfig: authConnectionConfig, + ), ); - // focus-end + // focus-end await Web3AuthFlutter.initialize(); } ``` -##### Logging in +##### Signing in -Once initialized, you can use the `Web3AuthFlutter.login(LoginParams( loginProvider: Provider.google ))` function to authenticate the user when they click the sign-in button. +Once initialized, call `Web3AuthFlutter.connectTo()` to authenticate the user when they click the sign-in button. ```dart -Future _withJWT() async { +Future _loginWithFirebase() async { String idToken = ""; try { // focus-start @@ -263,16 +263,14 @@ Future _withJWT() async { } // focus-start - return Web3AuthFlutter.login( + return Web3AuthFlutter.connectTo( LoginParams( - loginProvider: Provider.jwt, - extraLoginOptions: ExtraLoginOptions( - id_token: idToken, - domain: 'firebase', - ), + authConnection: AuthConnection.custom, + authConnectionId: "VERIFIER_NAME", + idToken: idToken, ), ); - // focus-end + // focus-end } ``` diff --git a/embedded-wallets/connect-blockchain/_flutter-connect-blockchain/_evm-get-account.mdx b/embedded-wallets/connect-blockchain/_flutter-connect-blockchain/_evm-get-account.mdx index 5c0df9895ba..d1ba185df69 100644 --- a/embedded-wallets/connect-blockchain/_flutter-connect-blockchain/_evm-get-account.mdx +++ b/embedded-wallets/connect-blockchain/_flutter-connect-blockchain/_evm-get-account.mdx @@ -1,11 +1,11 @@ -Once the user has successfully logged in, you can retrieve the user's private key using the `getPrivKey` method from the Embedded Wallets Flutter SDK. We'll use this private key to generate the Credentials for the user. +Once the user has successfully signed in, you can retrieve the user's private key using the `getPrivateKey` method from the Embedded Wallets Flutter SDK. We'll use this private key to generate the Credentials for the user. -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. +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 signed in and the private key is available. ```dart import 'package:web3dart/web3dart.dart'; -final privateKey = await Web3AuthFlutter.getPrivKey(); +final privateKey = await Web3AuthFlutter.getPrivateKey(); final credentials = EthPrivateKey.fromHex(privateKey); final address = credentials.address; diff --git a/embedded-wallets/connect-blockchain/solana/flutter.mdx b/embedded-wallets/connect-blockchain/solana/flutter.mdx index a441958bf74..d493d4512c2 100644 --- a/embedded-wallets/connect-blockchain/solana/flutter.mdx +++ b/embedded-wallets/connect-blockchain/solana/flutter.mdx @@ -156,11 +156,11 @@ Future main() async { // Initialize ServiceLocator ServiceLocator.init(); - final Uri redirectUrl; + late final String redirectUrl; if (Platform.isAndroid) { - redirectUrl = Uri.parse('w3aexample://com.example.flutter_solana_example/auth'); + redirectUrl = 'w3aexample://com.example.flutter_solana_example'; } else { - redirectUrl = Uri.parse('com.web3auth.fluttersolanasample://auth'); + redirectUrl = 'com.web3auth.fluttersolanasample://auth'; } // focus-start @@ -168,7 +168,7 @@ Future main() async { Web3AuthOptions( clientId: "BHgArYmWwSeq21czpcarYh0EVq2WWOzflX-NTK-tY1-1pauPzHKRRLgpABkmYiIV_og9jAvoIxQ8L3Smrwe04Lw", - network: Network.sapphire_devnet, + web3AuthNetwork: Web3AuthNetwork.sapphire_devnet, redirectUrl: redirectUrl, ), ); @@ -190,7 +190,7 @@ class _MainAppState extends State { @override void initState() { super.initState(); - privateKeyFuture = Web3AuthFlutter.getEd25519PrivKey(); + privateKeyFuture = Web3AuthFlutter.getEd25519PrivateKey(); } @override @@ -224,7 +224,7 @@ class _MainAppState extends State { ## Get account and Balance -We can use `getEd25519PrivKey` method in Web3Auth to retrive the priavte key for the Solana ecosystem. +We can use `getEd25519PrivateKey` method in Web3Auth to retrive the priavte key for the Solana ecosystem. In the following code block, we'll use the Ed25519 private key to retive user's public address, and Solana balance. We'll use `SolanaProvider` class to interact with Solana cluster and fetch user balance. @@ -288,7 +288,7 @@ class _HomeScreenState extends State { Future loadAccount(BuildContext context) async { try { - final privateKey = await Web3AuthFlutter.getEd25519PrivKey(); + final privateKey = await Web3AuthFlutter.getEd25519PrivateKey(); // .. // Additional code diff --git a/embedded-wallets/migration-guides/README.mdx b/embedded-wallets/migration-guides/README.mdx index d8af3709f80..c01514caaf7 100644 --- a/embedded-wallets/migration-guides/README.mdx +++ b/embedded-wallets/migration-guides/README.mdx @@ -34,7 +34,7 @@ current SDK in one pass. | [Android](/embedded-wallets/migration-guides/android) | v9 | v4 through v8 | | [iOS](/embedded-wallets/migration-guides/ios) | v12 | v6 through v11 | | [React Native](/embedded-wallets/migration-guides/react-native) | v9 | v3 through v8 | -| [Flutter](/embedded-wallets/migration-guides/flutter) | v6 | v3 through v5 | +| [Flutter](/embedded-wallets/migration-guides/flutter) | v7 | v3 through v6 | Each guide includes install steps, breaking changes grouped by version, a summary table, and platform-specific release notes. diff --git a/embedded-wallets/migration-guides/flutter.mdx b/embedded-wallets/migration-guides/flutter.mdx index 29b1f81e63e..b0587d7e7f8 100644 --- a/embedded-wallets/migration-guides/flutter.mdx +++ b/embedded-wallets/migration-guides/flutter.mdx @@ -1,12 +1,12 @@ --- -title: Flutter SDK v6 Migration Guide -sidebar_label: Flutter SDK v6 -description: Upgrade the Embedded Wallets Flutter SDK directly from older versions to v6. -keywords: [migration, v6, flutter, web3auth, embedded wallets, dart] +title: Flutter SDK v7 Migration Guide +sidebar_label: Flutter SDK v7 +description: Upgrade the Embedded Wallets Flutter SDK directly from older versions to v7. +keywords: [migration, v7, flutter, web3auth, embedded wallets, dart] --- -This guide upgrades Embedded Wallets Flutter SDK integrations from **v3 through v5** directly to -**v6**. +This guide upgrades Embedded Wallets Flutter SDK integrations from **v3 through v6** directly to +**v7**. ## AI-assisted migration @@ -19,21 +19,29 @@ Copy the prompt below into your AI coding assistant (Cursor, Claude Code, Codex, similar): ```txt -Migrate my MetaMask Embedded Wallets Flutter (web3auth_flutter) project to v6. +Migrate my MetaMask Embedded Wallets Flutter (web3auth_flutter) project to v7. Before changing code: 1. Use the web3auth skill and MCP tools (search_docs, get_doc, get_example, get_sdk_reference). -2. Read the migration guide: https://docs.metamask.io/embedded-wallets/migration-guides/flutter-v6 +2. Read the migration guide: https://docs.metamask.io/embedded-wallets/migration-guides/flutter/ 3. Detect my current SDK version from pubspec.yaml and list which breaking changes apply. -Then migrate my codebase directly to v6: -- Update web3auth_flutter to ^6.1.2 in pubspec.yaml. +Then migrate my codebase directly to v7: +- Update web3auth_flutter to ^7.0.0 in pubspec.yaml. - Set Android minSdkVersion to 26 and compileSdkVersion to 34. -- Replace getSignResponse() with the response returned from request(). +- Replace Web3AuthFlutter.login() with Web3AuthFlutter.connectTo(). +- Replace Provider with AuthConnection and loginProvider with authConnection. +- Replace loginConfig with authConnectionConfig and LoginConfigItem with AuthConnectionConfig. +- Replace Network with Web3AuthNetwork and network: with web3AuthNetwork:. +- Replace redirectUrl: Uri with redirectUrl: String. +- Replace getPrivKey() with getPrivateKey() and getEd25519PrivKey() with getEd25519PrivateKey(). +- Replace launchWalletServices(ChainConfig) with showWalletUI() and move chains to Web3AuthOptions. +- Replace request(ChainConfig, method, params) with request(method, params). +- Replace useCoreKitKey with useSFAKey and buildEnv with authBuildEnv. +- For Firebase and other JWT providers, pass idToken on LoginParams instead of extraLoginOptions.id_token. - Remove any setResultUrl calls (removed in v4). -- Use Web3AuthFlutter.setCustomTabsClosed() on Android for login cancellation handling. -- Configure platform-specific redirectUrl (Android: {SCHEME}://{HOST}/auth, iOS: {bundleId}://auth). -- Do not change my Client ID or Sapphire network unless I ask; that would change wallet addresses. +- Use Web3AuthFlutter.setCustomTabsClosed() on Android for sign-in cancellation handling. +- Do not change my Client ID, Sapphire network, or auth connection IDs unless I ask; that would change wallet addresses. After migrating, list every file you changed and any manual dashboard steps I still need to do. ``` @@ -45,13 +53,13 @@ Review the plan before generating code; config mistakes can change wallet addres ::: -## Install v6 +## Install v7 Update `pubspec.yaml`: ```yaml dependencies: - web3auth_flutter: ^6.1.2 + web3auth_flutter: ^7.0.0 ``` Or run: @@ -75,33 +83,96 @@ android { Add JitPack to your project-level Gradle file and configure platform redirects. See the [Flutter SDK get started](/embedded-wallets/sdk/flutter/) for Android and iOS setup. -## Breaking changes +v7 aligns with Android SDK v10 and iOS SDK v12. + +## v7 breaking changes {#v7-changes} + +### API renames + +| v6 | v7 | +| -------------------------------------- | ---------------------------------------- | +| `Network` | `Web3AuthNetwork` | +| `network:` | `web3AuthNetwork:` | +| `Provider` / `TypeOfLogin` | `AuthConnection` | +| `Provider.jwt` | `AuthConnection.custom` | +| `Web3AuthFlutter.login()` | `Web3AuthFlutter.connectTo()` | +| `loginProvider:` | `authConnection:` | +| `redirectUrl: Uri` | `redirectUrl: String` | +| `loginConfig` | `authConnectionConfig` | +| `LoginConfigItem` | `AuthConnectionConfig` | +| `verifier` | `authConnectionId` | +| `verifierSubIdentifier` | `groupedAuthConnectionId` | +| `verifierIdField` | `userIdField` | +| `getPrivKey()` | `getPrivateKey()` | +| `getEd25519PrivKey()` | `getEd25519PrivateKey()` | +| `TorusUserInfo` | `UserInfo` | +| `response.privKey` | `response.privateKey` | +| `launchWalletServices(ChainConfig)` | `showWalletUI()` | +| `request(ChainConfig, method, params)` | `request(method, params)` | +| SDK `ChainConfig` | `Web3AuthOptions(chains: [Chains(...)])` | +| `useCoreKitKey` | `useSFAKey` | +| `buildEnv` | `authBuildEnv` | + +### Sign in with `connectTo` -Apply the sections below that match your current version. -If you're already on v5, focus on the [v6 changes](#v6-changes). +```dart +final Web3AuthResponse response = await Web3AuthFlutter.connectTo( + LoginParams(authConnection: AuthConnection.google), +); +``` -### `setResultUrl` removed (from v4) +### Custom JWT and Firebase -v4 removes `setResultUrl`. -On Android, use `Web3AuthFlutter.setCustomTabsClosed()` in your app lifecycle observer to detect -when the user closes the custom tab: +Pass the JWT on `LoginParams.idToken` with `authConnectionId`: ```dart -@override -void didChangeAppLifecycleState(final AppLifecycleState state) { - if (state == AppLifecycleState.resumed) { - Web3AuthFlutter.setCustomTabsClosed(); - } -} +final Web3AuthResponse response = await Web3AuthFlutter.connectTo( + LoginParams( + authConnection: AuthConnection.custom, + authConnectionId: "w3a-firebase-demo", + idToken: firebaseIdToken, + ), +); ``` -Register the observer in `initState` with `WidgetsBinding.instance.addObserver(this)`. +Configure the connection during initialization: + +```dart +authConnectionConfig: [ + AuthConnectionConfig( + authConnection: AuthConnection.custom, + authConnectionId: "w3a-firebase-demo", + clientId: "WEB3AUTH_CLIENT_ID", + ), +], +``` -### `request` and sign response (from v4, updated in v6) +### Wallet Services and signing -From v4, use `Web3AuthFlutter.request()` with `ChainConfig` for templated signing screens. -From v6, `getSignResponse()` is removed. -Read the result from `request()` directly: +Configure chains in `Web3AuthOptions`, then call Wallet Services without a chain argument: + +```dart +await Web3AuthFlutter.init( + Web3AuthOptions( + clientId: "WEB3AUTH_CLIENT_ID", + web3AuthNetwork: Web3AuthNetwork.sapphire_mainnet, + redirectUrl: redirectUrl, + chains: [ + Chains( + chainId: "0x1", + rpcTarget: "https://mainnet.infura.io/v3/", + displayName: "Ethereum Mainnet", + ticker: "ETH", + ), + ], + defaultChainId: "0x1", + ), +); + +await Web3AuthFlutter.showWalletUI(); +``` + +Read signing results from `request()` directly: ```dart try { @@ -110,10 +181,6 @@ try { params.add(""); final response = await Web3AuthFlutter.request( - ChainConfig( - chainId: "0x1", - rpcTarget: "https://mainnet.infura.io/v3/", - ), "personal_sign", params, ); @@ -126,49 +193,43 @@ try { } ``` -### v6 changes {#v6-changes} - -- **`getSignResponse()` removed**: use the return value of `request()` (see example above). -- **Minimum Android SDK 26**: update `minSdkVersion` in your app-level Gradle file. - -v6 also adds support for Web3Auth Auth Service v9 and Wallet Services v3 (including swap in the -prebuilt wallet UI). +## Earlier breaking changes -## New APIs (non-breaking) +Apply the sections below if you are upgrading from versions older than v6. -These APIs were added in v4. -If you're upgrading from v3, adopt them as part of your v6 migration. - -| API | Added in | Purpose | -| ------------------------ | -------- | --------------------------------------------- | -| `enableMFA()` | v4 | Initiate MFA setup for logged-in users | -| `launchWalletServices()` | v4 | Open the templated wallet UI | -| `request()` | v4 | Sign transactions with confirmation screens | -| SMS Passwordless login | v4 | `Provider.sms_passwordless` with `login_hint` | -| Farcaster login | v4 | `Provider.farcaster` | +### `setResultUrl` removed (from v4) -Example `launchWalletServices`: +v4 removes `setResultUrl`. +On Android, use `Web3AuthFlutter.setCustomTabsClosed()` in your app lifecycle observer to detect +when the user closes the custom tab: ```dart -await Web3AuthFlutter.launchWalletServices( - ChainConfig( - chainId: "0x1", - rpcTarget: "https://mainnet.infura.io/v3/", - ), -); +@override +void didChangeAppLifecycleState(final AppLifecycleState state) { + if (state == AppLifecycleState.resumed) { + Web3AuthFlutter.setCustomTabsClosed(); + } +} ``` -See [Wallet Services](/embedded-wallets/sdk/flutter/usage/launch-wallet-services) and -[MFA](/embedded-wallets/sdk/flutter/advanced/mfa) for usage details. +Register the observer in `initState` with `WidgetsBinding.instance.addObserver(this)`. + +### v6 changes (if upgrading from v4-v5) + +- **`getSignResponse()` removed**: use the return value of `request()`. +- **Minimum Android SDK 26**: update `minSdkVersion` in your app-level Gradle file. ## Summary table -| Area | v3 and earlier | v4-v5 | v6 | -| --------------- | --------------- | ------------------- | --------------------------- | -| `setResultUrl` | Used on Android | Removed | Removed | -| Sign result | N/A | `getSignResponse()` | Return value of `request()` | -| Android minSdk | 24 | 24 | 26 | -| Wallet Services | N/A | Available | Wallet Services v3 | +| Area | v3 and earlier | v4-v5 | v6 | v7 | +| -------------- | --------------- | ------------------------ | --------------------------- | --------------------------- | +| `setResultUrl` | Used on Android | Removed | Removed | Removed | +| Sign result | N/A | `getSignResponse()` | Return value of `request()` | Return value of `request()` | +| Sign in | `login()` | `login()` | `login()` | `connectTo()` | +| Private key | `getPrivKey()` | `getPrivKey()` | `getPrivKey()` | `getPrivateKey()` | +| Wallet UI | N/A | `launchWalletServices()` | `launchWalletServices()` | `showWalletUI()` | +| Chain config | N/A | Per-method `ChainConfig` | Per-method `ChainConfig` | `Web3AuthOptions.chains` | +| Android minSdk | 24 | 24 | 26 | 26 | ## Next steps diff --git a/embedded-wallets/sdk/flutter/README.mdx b/embedded-wallets/sdk/flutter/README.mdx index fe17c159de9..a0f4baedea8 100644 --- a/embedded-wallets/sdk/flutter/README.mdx +++ b/embedded-wallets/sdk/flutter/README.mdx @@ -9,7 +9,7 @@ import Tabs from '@theme/Tabs' ## Overview -MetaMask Embedded Wallets SDK (formerly Web3Auth Plug and Play) provides authentication for Flutter applications with social logins, external wallets, and more. Our Flutter SDK, written in Dart, simplifies connecting users to their preferred wallets and manage authentication state across both iOS and Android platforms. +MetaMask Embedded Wallets SDK (formerly Web3Auth Plug and Play) provides social login authentication for Flutter applications. The Flutter SDK, written in Dart, helps you manage authentication state across both iOS and Android platforms. After sign-in, export the private key and use platform-native blockchain libraries such as web3dart or solana. ## Requirements @@ -37,7 +37,7 @@ Add `web3auth_flutter` as a dependency to your `pubspec.yaml`: ```yaml dependencies: - web3auth_flutter: ^6.1.2 + web3auth_flutter: ^7.0.0 ``` ### Add via Flutter pub add @@ -171,21 +171,22 @@ import 'package:web3auth_flutter/output.dart'; import 'dart:io'; Future initWeb3Auth() async { - late final Uri redirectUrl; + late final String redirectUrl; if (Platform.isAndroid) { - redirectUrl = Uri.parse('{SCHEME}://{HOST}/auth'); - // w3a://com.example.w3aflutter/auth + redirectUrl = 'w3a://com.example.w3aflutter'; + // w3a://com.example.w3aflutter } else { - redirectUrl = Uri.parse('{bundleId}://auth'); + redirectUrl = 'com.example.w3aflutter://auth'; // com.example.w3aflutter://auth } // focus-start await Web3AuthFlutter.init(Web3AuthOptions( clientId: "YOUR_WEB3AUTH_CLIENT_ID", // Pass your Web3Auth Client ID, ideally using an environment variable // Get your Client ID from Embedded Wallets dashboard - network: Network.sapphire_mainnet, // or Network.sapphire_devnet + web3AuthNetwork: Web3AuthNetwork.sapphire_mainnet, // or Web3AuthNetwork.sapphire_devnet redirectUrl: redirectUrl, + authBuildEnv: BuildEnv.production, )); // focus-end } @@ -214,7 +215,7 @@ class _MyAppState extends State with WidgetsBindingObserver { // focus-start await Web3AuthFlutter.initialize(); // focus-end - final privateKey = await Web3AuthFlutter.getPrivKey(); + final privateKey = await Web3AuthFlutter.getPrivateKey(); if (privateKey.isNotEmpty) { setState(() { @@ -265,7 +266,7 @@ See the [advanced configuration sections](./advanced/) to learn more about each ```dart await Web3AuthFlutter.init(Web3AuthOptions( clientId: "YOUR_WEB3AUTH_CLIENT_ID", // Pass your Web3Auth Client ID, ideally using an environment variable - network: Network.sapphire_mainnet, // or Network.sapphire_devnet + web3AuthNetwork: Web3AuthNetwork.sapphire_mainnet, // or Web3AuthNetwork.sapphire_devnet redirectUrl: redirectUrl, )); ``` @@ -277,8 +278,19 @@ await Web3AuthFlutter.init(Web3AuthOptions( ```dart await Web3AuthFlutter.init(Web3AuthOptions( clientId: "YOUR_WEB3AUTH_CLIENT_ID", // Pass your Web3Auth Client ID, ideally using an environment variable - network: Network.sapphire_mainnet, + web3AuthNetwork: Web3AuthNetwork.sapphire_mainnet, redirectUrl: redirectUrl, + defaultChainId: "0x1", + chains: [ + Chains( + chainId: "0x1", + rpcTarget: "https://rpc.ankr.com/eth", + displayName: "Ethereum Mainnet", + blockExplorerUrl: "https://etherscan.io", + ticker: "ETH", + tickerName: "Ethereum", + ), + ], mfaSettings: MfaSettings( deviceShareFactor: MfaSetting( enable: true, @@ -316,7 +328,7 @@ For Ethereum integration, you can get the private key and use it with web3dart o import 'package:web3dart/web3dart.dart'; // Use your Web3Auth instance to get the private key -final privateKey = await Web3AuthFlutter.getPrivKey(); +final privateKey = await Web3AuthFlutter.getPrivateKey(); // Generate the Credentials final credentials = EthPrivateKey.fromHex(privateKey); @@ -344,7 +356,7 @@ import 'package:solana/solana.dart'; import 'package:web3auth_flutter/web3auth_flutter.dart'; // Use your Web3Auth instance to get the ED25519 private key -final privateKey = await Web3AuthFlutter.getED25519PrivKey(); +final privateKey = await Web3AuthFlutter.getEd25519PrivateKey(); // Generate the KeyPair final keyPair = await Ed25519HDKeyPair.fromPrivateKeyBytes( diff --git a/embedded-wallets/sdk/flutter/advanced/README.mdx b/embedded-wallets/sdk/flutter/advanced/README.mdx index cd70cb9b63d..88a6fa9e9a2 100644 --- a/embedded-wallets/sdk/flutter/advanced/README.mdx +++ b/embedded-wallets/sdk/flutter/advanced/README.mdx @@ -22,21 +22,19 @@ import 'dart:io'; Future initWeb3Auth() async { - late final Uri redirectUrl; + late final String redirectUrl; if (Platform.isAndroid) { - redirectUrl = Uri.parse('{SCHEME}://{HOST}/auth'); - // w3a://com.example.w3aflutter/auth + redirectUrl = 'w3a://com.example.w3aflutter'; } else { - redirectUrl = Uri.parse('{bundleId}://auth'); - // com.example.w3aflutter://auth + redirectUrl = 'com.example.w3aflutter://auth'; } // focus-start await Web3AuthFlutter.init(Web3AuthOptions( clientId: "YOUR_WEB3AUTH_CLIENT_ID", // Pass your Web3Auth Client ID, ideally using an environment variable // Get your Client ID from MetaMask Developer Dashboard dashboard - network: Network.sapphire_mainnet, // or Network.sapphire_devnet + web3AuthNetwork: Web3AuthNetwork.sapphire_mainnet, // or Web3AuthNetwork.sapphire_devnet redirectUrl: redirectUrl, )); @@ -58,15 +56,17 @@ The Web3Auth Constructor takes an object with `Web3AuthOptions` as input. -| Parameter | Description | -| -------------- | ----------------------------------------------------------------------------------------------------------------------------------- | -| `clientId` | Your Web3Auth Client ID from the [Dashboard](https://developer.metamask.io/). It's a mandatory field of type `String`. | -| `network` | Web3Auth Network: `sapphire_mainnet`, `sapphire_devnet`, `mainnet`, `cyan`, `aqua` or `testnet`. Mandatory field of type `Network`. | -| `redirectUrl` | URL that Web3Auth will redirect API responses upon successful authentication. It's a mandatory field of type `Uri`. | -| `whiteLabel?` | Whitelabel options for custom UI, branding, and translations. Takes `WhiteLabelData` as a value. | -| `loginConfig?` | Login config for custom verifiers. Takes `HashMap` as a value. | -| `mfaSettings?` | Configure MFA settings for authentication. Takes `MfaSettings` as a value. | -| `sessionTime?` | Configure session management time in seconds. Default is 86400 seconds (1 day). Max 30 days. | +| Parameter | Description | +| ----------------------- | ------------------------------------------------------------------------------------------------------------------------------ | +| `clientId` | Your Web3Auth Client ID from the [Dashboard](https://developer.metamask.io/). Mandatory `String`. | +| `web3AuthNetwork` | Web3Auth Network: `sapphire_mainnet`, `sapphire_devnet`, `mainnet`, `cyan`, `aqua`, or `testnet`. Mandatory `Web3AuthNetwork`. | +| `redirectUrl` | URL that Web3Auth redirects to after successful authentication. Mandatory `String`. | +| `whiteLabel?` | Whitelabel options for custom UI, branding, and translations. Takes `WhiteLabelData` as a value. | +| `authConnectionConfig?` | Auth connection config for custom connections. Takes `List` as a value. | +| `chains?` | Chain configuration for Wallet Services and signing. Takes `List` as a value. | +| `defaultChainId?` | Default chain ID from the `chains` list. | +| `mfaSettings?` | Configure MFA settings for authentication. Takes `MfaSettings` as a value. | +| `sessionTime?` | Configure session management time in seconds. Default is 30 days. Max 30 days. | @@ -75,46 +75,30 @@ The Web3Auth Constructor takes an object with `Web3AuthOptions` as input. ```dart class Web3AuthOptions { final String clientId; - final Network network; - final BuildEnv? buildEnv; - final String? sdkUrl; - final Uri redirectUrl; + final Web3AuthNetwork web3AuthNetwork; + final BuildEnv? authBuildEnv; + final String redirectUrl; final WhiteLabelData? whiteLabel; - final HashMap? loginConfig; - final bool? useCoreKitKey; - final ChainNamespace? chainNamespace; + final List? authConnectionConfig; + final List? chains; + final String? defaultChainId; + final bool? useSFAKey; final MfaSettings? mfaSettings; - final int? sessionTime; + final int sessionTime; Web3AuthOptions({ required this.clientId, - required this.network, - this.buildEnv = BuildEnv.production, - String? sdkUrl, + required this.web3AuthNetwork, + this.authBuildEnv = BuildEnv.production, required this.redirectUrl, this.whiteLabel, - this.loginConfig, - this.useCoreKitKey, - this.chainNamespace = ChainNamespace.eip155, - this.sessionTime = 86400, + this.authConnectionConfig = const [], + this.chains, + this.defaultChainId, + this.useSFAKey = false, + this.sessionTime = 30 * 86400, this.mfaSettings, - }): sdkUrl = sdkUrl ?? getSdkUrl(buildEnv ?? BuildEnv.production); - - Map toJson() { - return { - 'clientId': clientId, - 'network': network.name, - 'sdkUrl': sdkUrl, - 'buildEnv': buildEnv?.name, - 'redirectUrl': redirectUrl.toString(), - 'whiteLabel': whiteLabel?.toJson(), - 'loginConfig': loginConfig, - 'useCoreKitKey': useCoreKitKey, - 'chainNamespace': chainNamespace?.name, - 'mfaSettings': mfaSettings, - 'sessionTime': sessionTime, - }; - } + }); } ``` @@ -130,13 +114,13 @@ Control how long users stay authenticated and how sessions persist. The session - `sessionTime` - Session duration in seconds. Controls how long users remain authenticated before needing to log in again. - Minimum: 1 second (`1`). - Maximum: 30 days (`86400 * 30`). - - Default: 7 days (`86400 * 7`). + - Default: 30 days (`30 * 86400`). ```dart await Web3AuthFlutter.init(Web3AuthOptions( clientId: "YOUR_WEB3AUTH_CLIENT_ID", // Pass your Web3Auth Client ID, ideally using an environment variable // Get your Client ID from MetaMask Developer Dashboard dashboard - network: Network.sapphire_mainnet, // or Network.sapphire_devnet - sessionTime: 86400 * 7, // 7 days (in seconds) + web3AuthNetwork: Web3AuthNetwork.sapphire_mainnet, // or Web3AuthNetwork.sapphire_devnet + sessionTime: 30 * 86400, // 30 days (in seconds) redirectUrl: redirectUrl, )); ``` diff --git a/embedded-wallets/sdk/flutter/advanced/custom-authentication.mdx b/embedded-wallets/sdk/flutter/advanced/custom-authentication.mdx index 93274b3bb98..b952bac23fe 100644 --- a/embedded-wallets/sdk/flutter/advanced/custom-authentication.mdx +++ b/embedded-wallets/sdk/flutter/advanced/custom-authentication.mdx @@ -8,21 +8,21 @@ import TabItem from '@theme/TabItem' import Tabs from '@theme/Tabs' import GrowthPlanNote from '../../_common/_growth_plan_note.mdx' -Custom authentication is a way to authenticate users with your custom authentication service. For example, while authenticating with Google, you can use your own Google Client ID to authenticate users directly. +Custom authentication lets users sign in with your own OAuth provider or JWT issuer. For example, you can use your own Google Client ID, Firebase ID token, or Auth0 application. This feature, with MFA turned off, can make Embedded Wallets invisible to the end user. -## Getting an Auth Connection ID +## Getting an auth connection ID :::info prerequisite -To enable this, you need to [create a connection](/embedded-wallets/dashboard/authentication) from the **Authentication** tab of your project from the [Embedded Wallets developer dashboard](https://developer.metamask.io) with your desired configuration. +To enable this, [create a connection](/embedded-wallets/dashboard/authentication) from the **Authentication** tab of your project in the [Embedded Wallets developer dashboard](https://developer.metamask.io) with your desired configuration. ::: -To configure a connection, you need to provide the particular details of the connection into our Embedded Wallets dashboard. This enables us to map a `authConnectionId` with your connection details. This `authConnectionId` helps us to identify the connection details while initializing the SDK. You can configure multiple connections for the same project, and you can also update the connection details anytime. +To configure a connection, provide the connection details in the Embedded Wallets dashboard. This maps an `authConnectionId` to your connection configuration. You can configure multiple connections for the same project and update connection details at any time. :::tip @@ -32,23 +32,15 @@ Learn more about the [auth provider setup](/embedded-wallets/authentication) and ## Configuration -:::warning +To use custom authentication (social providers, Auth0, AWS Cognito, Firebase, or your own JWT login), add `authConnectionConfig` during initialization. -**"Auth Connection"** is called **"Verifier"** in the Android SDK. It is the older terminology which we will be updating in the upcoming releases. - -Consequentially, you will see the terms **"Verifier ID"** and **"Aggregate Verifier"** used in the codebase and documentation referring to **"Auth Connection ID"** and **"Grouped Auth Connection"** respectively. - -::: - -To use custom authentication (using supported Social providers or Login providers like Auth0, AWS Cognito, Firebase, or your own custom JWT login), you can add the configuration using `loginConfig` parameter during the initialization. - -The `loginConfig` parameter is a key value map. The key should be one of the `Web3AuthProvider` in its string form, and the value should be a `LoginConfigItem` instance. +`authConnectionConfig` is a list of `AuthConnectionConfig` objects. ### Parameters -After creating the verifier, you can use the following parameters in the `LoginConfigItem`. +After creating the connection, use the following parameters in `AuthConnectionConfig`. -| Parameter | Description | -| ------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `verifier` | The name of the verifier that you have registered on the Embedded Wallets dashboard. It's a mandatory field, and it accepts a string value. | -| `typeOfLogin` | Type of login of this verifier, this value will affect the login flow that is adapted. For example, if you choose `google`, a Google sign-in flow will be used. If you choose `jwt`, you should be providing your own JWT token, no sign-in flow will be presented. It's a mandatory field, and accepts `TypeOfLogin` as a value. | -| `clientId` | Client ID provided by your login provider used for custom verifier. for example, Google's Client ID or Web3Auth's client ID if using JWT as `TypeOfLogin`. It's a mandatory field, and it accepts a string value. | -| `name?` | Display name for the verifier. If null, the default name is used. It accepts a string value. | -| `description?` | Description for the button. If provided, it renders as a full length button. else, icon button. It accepts a string value. | -| `verifierSubIdentifier?` | The field in JWT token which maps to verifier ID. Ensure you selected correct JWT verifier ID in the developer dashboard. It accepts a string value. | -| `logoHover?` | Logo to be shown on mouse hover. It accepts a string value. | -| `logoLight?` | Light logo for dark background. It accepts a string value. | -| `logoDark?` | Dark logo for light background. It accepts a string value. | -| `mainOption?` | Show login button on the main list. It accepts a boolean value. | -| `showOnModal?` | Whether to show the login button on modal or not. | -| `showOnDesktop?` | Whether to show the login button on desktop. | -| `showOnMobile?` | Whether to show the login button on mobile. | +| Parameter | Description | +| -------------------------- | ---------------------------------------------------------------------------------------------------------------- | +| `authConnection` | Type of sign-in for the connection. For example, `google` for Google OAuth or `custom` for JWT. Mandatory. | +| `authConnectionId` | Auth connection ID registered in the Embedded Wallets dashboard. Mandatory. | +| `clientId` | Client ID from your login provider. Mandatory. | +| `name?` | Display name for the connection. If null, the default name is used. | +| `description?` | Description for the button. If provided, renders as a full-length button; otherwise, an icon button. | +| `groupedAuthConnectionId?` | Grouped auth connection ID. If provided, `authConnectionId` becomes a sub-identifier for the grouped connection. | +| `logoHover?` | Logo shown on mouse hover. | +| `logoLight?` | Light logo for dark backgrounds. | +| `logoDark?` | Dark logo for light backgrounds. | +| `mainOption?` | Show the sign-in button on the main list. | +| `showOnModal?` | Whether to show the sign-in button on the modal. | +| `showOnDesktop?` | Whether to show the sign-in button on desktop. | +| `showOnMobile?` | Whether to show the sign-in button on mobile. | +| `jwtParameters?` | Extra JWT options for custom connections. | ```dart -class LoginConfigItem { - final String verifier; - final TypeOfLogin typeOfLogin; +class AuthConnectionConfig { + final AuthConnection authConnection; + final String authConnectionId; final String clientId; final String? name; final String? description; - final String? verifierSubIdentifier; + final String? groupedAuthConnectionId; final String? logoHover; final String? logoLight; final String? logoDark; @@ -95,14 +88,15 @@ class LoginConfigItem { final bool? showOnModal; final bool? showOnDesktop; final bool? showOnMobile; + final ExtraLoginOptions? jwtParameters; - LoginConfigItem({ - required this.verifier, - required this.typeOfLogin, + AuthConnectionConfig({ + required this.authConnection, + required this.authConnectionId, required this.clientId, this.name, this.description, - this.verifierSubIdentifier, + this.groupedAuthConnectionId, this.logoHover, this.logoLight, this.logoDark, @@ -110,46 +104,8 @@ class LoginConfigItem { this.showOnModal, this.showOnDesktop, this.showOnMobile, + this.jwtParameters, }); - - Map toJson() { - return { - 'verifier': verifier, - 'typeOfLogin': typeOfLogin.name, - 'clientId': clientId, - 'name': name, - 'description': description, - 'verifierSubIdentifier': verifierSubIdentifier, - 'logoHover': logoHover, - 'logoLight': logoLight, - 'logoDark': logoDark, - 'mainOption': mainOption, - 'showOnModal': showOnModal, - 'showOnDesktop': showOnDesktop, - 'showOnMobile': showOnMobile - }; - } -} - -enum TypeOfLogin { - google, - facebook, - reddit, - discord, - twitch, - github, - apple, - kakao, - linkedin, - twitter, - weibo, - wechat, - line, - email_passwordless, - email_password, - jwt, - sms_passwordless, - farcaster, } ``` @@ -162,8 +118,8 @@ enum TypeOfLogin { defaultValue="google" values={[ { label: "Google", value: "google" }, - { label: "Facebook", value: "facebook" }, - { label: "JWT", value: "jwt" }, + { label: "Firebase JWT", value: "firebase" }, + { label: "Auth0", value: "auth0" }, ]} > @@ -171,537 +127,214 @@ enum TypeOfLogin { ```dart title="Usage" Future initWeb3Auth() async { - final themeMap = HashMap(); - themeMap['primary'] = "#229954"; - - // focus-start - final loginConfig = new HashMap(); - loginConfig['google'] = LoginConfigItem( - verifier: "verifier-name", // get it from MetaMask Developer Dashboard - typeOfLogin: TypeOfLogin.google, - clientId: "google_client_id" // google's client id - ); - // focus-end + final authConnectionConfig = [ + AuthConnectionConfig( + authConnection: AuthConnection.google, + authConnectionId: "YOUR_AUTH_CONNECTION_ID", + clientId: "YOUR_GOOGLE_CLIENT_ID", + ), + ]; - Uri redirectUrl; + late final String redirectUrl; if (Platform.isAndroid) { - redirectUrl = Uri.parse('{SCHEME}://{HOST}/auth'); - // w3a://com.example.w3aflutter/auth - } else if (Platform.isIOS) { - redirectUrl = Uri.parse('{bundleId}://auth'); - // com.example.w3aflutter://openlogin + redirectUrl = 'w3a://com.example.w3aflutter'; } else { - throw UnKnownException('Unknown platform'); + redirectUrl = 'com.example.w3aflutter://auth'; } await Web3AuthFlutter.init( Web3AuthOptions( clientId: "WEB3AUTH_CLIENT_ID", - network: Network.sapphire_mainnet, + web3AuthNetwork: Web3AuthNetwork.sapphire_mainnet, redirectUrl: redirectUrl, - // focus-next-line - loginConfig: loginConfig + authConnectionConfig: authConnectionConfig, ), ); } -// Login -final Web3AuthResponse response = await Web3AuthFlutter.login( - // focus-next-line - LoginParams(loginProvider: Provider.google) +final Web3AuthResponse response = await Web3AuthFlutter.connectTo( + LoginParams(authConnection: AuthConnection.google), ); ``` - + ```dart title="Usage" Future initWeb3Auth() async { - final themeMap = HashMap(); - themeMap['primary'] = "#229954"; - - // focus-start - final loginConfig = new HashMap(); - loginConfig['facebook'] = LoginConfigItem( - verifier: "verifier-name", // get it from MetaMask Developer Dashboard - typeOfLogin: TypeOfLogin.facebook, - clientId: "facebook_client_id" // facebook's client id - ); - // focus-end - - Uri redirectUrl; - if (Platform.isAndroid) { - redirectUrl = Uri.parse('{SCHEME}://{HOST}/auth'); - // w3a://com.example.w3aflutter/auth - } else if (Platform.isIOS) { - redirectUrl = Uri.parse('{bundleId}://auth'); - // com.example.w3aflutter://openlogin - } else { - throw UnKnownException('Unknown platform'); - } - - await Web3AuthFlutter.init( - Web3AuthOptions( + final authConnectionConfig = [ + AuthConnectionConfig( + authConnection: AuthConnection.custom, + authConnectionId: "w3a-firebase-demo", clientId: "WEB3AUTH_CLIENT_ID", - network: Network.testnet, - redirectUrl: redirectUrl, - // focus-next-line - loginConfig: loginConfig ), - ); -} - -// Login -final Web3AuthResponse response = await Web3AuthFlutter.login( - // focus-next-line - LoginParams(loginProvider: Provider.facebook) -); -``` - - + ]; - - -```dart title="Usage" -Future initWeb3Auth() async { - final themeMap = HashMap(); - themeMap['primary'] = "#229954"; - - // focus-start - final loginConfig = new HashMap(); - loginConfig['jwt'] = LoginConfigItem( - verifier: "verifier-name", // get it from MetaMask Developer Dashboard - typeOfLogin: TypeOfLogin.jwt, - clientId: "web3auth_client_id" // web3auth's plug and play client id - ); - // focus-end - - Uri redirectUrl; + late final String redirectUrl; if (Platform.isAndroid) { - redirectUrl = Uri.parse('{SCHEME}://{HOST}/auth'); - // w3a://com.example.w3aflutter/auth - } else if (Platform.isIOS) { - redirectUrl = Uri.parse('{bundleId}://auth'); - // com.example.w3aflutter://openlogin + redirectUrl = 'w3a://com.example.w3aflutter'; } else { - throw UnKnownException('Unknown platform'); + redirectUrl = 'com.example.w3aflutter://openlogin'; } await Web3AuthFlutter.init( Web3AuthOptions( clientId: "WEB3AUTH_CLIENT_ID", - network: Network.testnet, + web3AuthNetwork: Web3AuthNetwork.sapphire_mainnet, redirectUrl: redirectUrl, - // focus-next-line - loginConfig: loginConfig + authConnectionConfig: authConnectionConfig, ), ); } -// Login -final Web3AuthResponse response = await Web3AuthFlutter.login( +// Obtain a Firebase ID token from your auth provider, then: +final Web3AuthResponse response = await Web3AuthFlutter.connectTo( LoginParams( - // focus-start - loginProvider: Provider.jwt, - extraLoginOptions: ExtraLoginOptions( - id_token: "YOUR_JWT_TOKEN" - ) - // focus-end - ) + authConnection: AuthConnection.custom, + authConnectionId: "w3a-firebase-demo", + idToken: firebaseIdToken, + ), ); ``` - - -## Congfigure extra login options - -Additional to the loginConfig during initialization, you can pass extra options to the `login` method to configure the login flow for cases requiring additional info for authorization. The `ExtraLoginOptions` accepts the following parameters. - -### Parameters - - - - - -| Parameter | Description | -| ---------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `additionalParams?` | Additional params in `Map` format for OAuth login, use id_token(JWT) to authenticate with Web3Auth. | -| `domain?` | Your custom authentication domain in `String` format. For example, if you are using Auth0, it can be example.au.auth0.com. | -| `client_id?` | Client ID in string format, provided by your login provider used for custom verifier. | -| `leeway?` | The value used to account for clock skew in JWT expirations. The value is in the seconds, and ideally should no more than 60 seconds or 120 seconds at max. It accepts a string value. | -| `verifierIdField?` | The field in JWT token which maps to verifier ID. Please make sure you selected correct JWT verifier ID in the developer dashboard. It accepts a string value. | -| `isVerifierIdCaseSensitive?` | Boolean to confirm Whether the verifier ID field is case sensitive or not. | -| `display?` | Allows developers the configure the display of UI. It takes `Display` as a value. | -| `prompt?` | Prompt shown to the user during authentication process. It takes `Prompt` as a value. | -| `max_age?` | Max time allowed without reauthentication. If the last time user authenticated is greater than this value, then user must reauthenticate. It accepts a string value. | -| `ui_locales?` | The space separated list of language tags, ordered by preference. For instance `fr-CA fr en`. | -| `id_token_hint?` | It denotes the previously issued ID token. It accepts a string value. | -| `id_token?` | JWT (ID token) to be passed for login. | -| `login_hint?` | It is used to send the user's email address during email passwordless login. It accepts a string value. | -| `acr_values?` | acr_values | -| `scope?` | The default scope to be used on authentication requests. The defaultScope defined in the Auth0Client is included along with this scope. It accepts a string value. | -| `audience?` | The audience, presented as the aud claim in the access token, defines the intended consumer of the token. It accepts a string value. | -| `connection?` | The name of the connection configured for your application. If null, it will redirect to the Auth0 Login Page and show the Login Widget. It accepts a string value. | -| `state?` | state | -| `response_type?` | Defines which grant to execute for the authorization server. It accepts a string value. | -| `nonce?` | nonce | -| `redirect_uri?` | It can be used to specify the default URL, where your custom JWT verifier can redirect your browser to with the result. If you are using Auth0, it must be allowlisted in the Allowed Callback URLs in your Auth0's application. | - - - - - -```dart -class ExtraLoginOptions { - final Map? additionalParams; - final String? domain; - final String? client_id; - final String? leeway; - final String? verifierIdField; - final bool? isVerifierIdCaseSensitive; - final Display? display; - final Prompt? prompt; - final String? max_age; - final String? ui_locales; - final String? id_token_hint; - final String? id_token; - final String? login_hint; - final String? acr_values; - final String? scope; - final String? audience; - final String? connection; - final String? state; - final String? response_type; - final String? nonce; - final String? redirect_uri; - - ExtraLoginOptions({ - this.additionalParams = const {}, - this.domain, - this.client_id, - this.leeway, - this.verifierIdField, - this.isVerifierIdCaseSensitive, - this.display, - this.prompt, - this.max_age, - this.ui_locales, - this.id_token_hint, - this.id_token, - this.login_hint, - this.acr_values, - this.scope, - this.audience, - this.connection, - this.state, - this.response_type, - this.nonce, - this.redirect_uri, - }); - - Map toJson() => { - "additionalParams": additionalParams, - "domain": domain, - "client_id": client_id, - "leeway": leeway, - "verifierIdField": verifierIdField, - "isVerifierIdCaseSensitive": isVerifierIdCaseSensitive, - "display": display?.name, - "prompt": prompt?.name, - "max_age": max_age, - "ui_locales": ui_locales, - "id_token_hint": id_token_hint, - "id_token": id_token, - "login_hint": login_hint, - "acr_values": acr_values, - "scope": scope, - "audience": audience, - "connection": connection, - "state": state, - "response_type": response_type, - "nonce": nonce, - "redirect_uri": redirect_uri, - }; -} -``` - - - - -### Single verifer example - - -Auth0 has a special login flow, called the SPA flow. This flow requires a `client_id` and `domain` -to be passed, and Web3Auth will get the JWT `id_token` from Auth0 directly. You can pass these -configurations in the `ExtraLoginOptions` object in the `login` function. -```dart +```dart title="Usage" Future initWeb3Auth() async { - final themeMap = HashMap(); - themeMap['primary'] = "#229954"; - - // focus-start - final loginConfig = new HashMap(); - loginConfig['jwt'] = LoginConfigItem( - verifier: "verifier-name", // get it from MetaMask Developer Dashboard for auth0 configuration - typeOfLogin: TypeOfLogin.jwt, - clientId: "auth0_client_id" // get it from auth0 dashboard - ); - // focus-end + final authConnectionConfig = [ + AuthConnectionConfig( + authConnection: AuthConnection.custom, + authConnectionId: "w3a-auth0-demo", + clientId: "YOUR_AUTH0_CLIENT_ID", + ), + ]; - Uri redirectUrl; + late final String redirectUrl; if (Platform.isAndroid) { - redirectUrl = Uri.parse('{SCHEME}://{HOST}/auth'); - // w3a://com.example.w3aflutter/auth - } else if (Platform.isIOS) { - redirectUrl = Uri.parse('{bundleId}://auth'); - // com.example.w3aflutter://openlogin + redirectUrl = 'w3a://com.example.w3aflutter'; } else { - throw UnKnownException('Unknown platform'); + redirectUrl = 'com.example.w3aflutter://openlogin'; } await Web3AuthFlutter.init( Web3AuthOptions( clientId: "WEB3AUTH_CLIENT_ID", - network: Network.sapphire_mainnet, + web3AuthNetwork: Web3AuthNetwork.sapphire_mainnet, redirectUrl: redirectUrl, - // focus-next-line - loginConfig: loginConfig, + authConnectionConfig: authConnectionConfig, ), ); } -// Login -final Web3AuthResponse response = await Web3AuthFlutter.login( +final Web3AuthResponse response = await Web3AuthFlutter.connectTo( LoginParams( - // focus-start - loginProvider: Provider.jwt, + authConnection: AuthConnection.custom, + authConnectionId: "w3a-auth0-demo", extraLoginOptions: ExtraLoginOptions( - domain: "https://tenant-name.us.auth0.com", // Domain of your auth0 app - verifierIdField: "sub", // The field in jwt token which maps to verifier id. - ) - // focus-end - ) -); -``` - - - - -If you're using any other provider like Firebase, AWS Cognito or deploying your own Custom JWT -server, you need to put the JWT token into the `id_token` parameter of the `ExtraLoginOptions`. - -```dart -Future initWeb3Auth() async { - final themeMap = HashMap(); - themeMap['primary'] = "#229954"; - - // focus-start - final loginConfig = new HashMap(); - loginConfig['jwt'] = LoginConfigItem( - verifier: "verifier-name", // get it from MetaMask Developer Dashboard - typeOfLogin: TypeOfLogin.jwt, - ); - // focus-end - - Uri redirectUrl; - if (Platform.isAndroid) { - redirectUrl = Uri.parse('{SCHEME}://{HOST}/auth'); - // w3a://com.example.w3aflutter/auth - } else if (Platform.isIOS) { - redirectUrl = Uri.parse('{bundleId}://auth'); - // com.example.w3aflutter://openlogin - } else { - throw UnKnownException('Unknown platform'); - } - - await Web3AuthFlutter.init( - Web3AuthOptions( - clientId: 'WEB3AUTH_CLIENT_ID', - network: Network.sapphire_mainnet, - redirectUrl: redirectUrl, - // focus-next-line - loginConfig: loginConfig, + domain: "https://tenant-name.us.auth0.com", + userIdField: "sub", ), - ); -} - -// Login -final Web3AuthResponse response = await Web3AuthFlutter.login( - LoginParams( - // focus-start - loginProvider: Provider.jwt, - extraLoginOptions: ExtraLoginOptions( - id_token: "YOUR_ID_TOKEN", - ) - // focus-end - ) + ), ); ``` + - -To use the email passwordless login, you need to put the email into the `login_hint` parameter of -the `ExtraLoginOptions`. By default, the login flow will be `code` flow, if you want to use the -`link` flow, you need to put `flow_type` into the `additionalParams` parameter of the -`ExtraLoginOptions`. +## Configure extra login options -```dart -Future initWeb3Auth() async { - final themeMap = HashMap(); - themeMap['primary'] = "#229954"; - - final additionalParams = HashMap(); - additionalParams['flow_type'] = "link"; // default is 'code' +In addition to `authConnectionConfig` during initialization, you can pass extra options to `connectTo` for authorization flows that need additional parameters. `ExtraLoginOptions` accepts the following parameters. - Uri redirectUrl; - if (Platform.isAndroid) { - redirectUrl = Uri.parse('{SCHEME}://{HOST}/auth'); - // w3a://com.example.w3aflutter/auth - } else if (Platform.isIOS) { - redirectUrl = Uri.parse('{bundleId}://auth'); - // com.example.w3aflutter://openlogin - } else { - throw UnKnownException('Unknown platform'); - } +### Parameters - await Web3AuthFlutter.init( - Web3AuthOptions( - clientId: "WEB3AUTH_CLIENT_ID", - network: Network.sapphire_mainnet, - redirectUrl: redirectUrl, - ), - ); -} +| Parameter | Description | +| ------------------------ | ------------------------------------------------------------------------------------------------------------------- | +| `additionalParams?` | Additional params in `Map` format for OAuth sign-in. | +| `domain?` | Your custom authentication domain. For example, `example.au.auth0.com` for Auth0. | +| `client_id?` | Client ID provided by your login provider for custom connections. | +| `leeway?` | Clock skew allowance for JWT expiration, in seconds. Ideally no more than 60–120 seconds. | +| `userIdField?` | JWT field that maps to the user ID. Ensure you selected the correct JWT user identifier in the developer dashboard. | +| `isUserIdCaseSensitive?` | Whether the user ID field is case sensitive. | +| `display?` | Configures the display of the UI. Takes `Display` as a value. | +| `prompt?` | Prompt shown during authentication. Takes `Prompt` as a value. | +| `max_age?` | Max time allowed without reauthentication. | +| `ui_locales?` | Space-separated list of language tags, ordered by preference. For instance `fr-CA fr en`. | +| `id_token_hint?` | Previously issued ID token. | +| `id_token?` | JWT (ID token) for legacy custom flows. Prefer `LoginParams.idToken` for Firebase and other JWT providers. | +| `login_hint?` | User's email address for email passwordless sign-in. | +| `flow_type?` | Email passwordless flow type. Defaults to `EmailFlowType.code`. Use `EmailFlowType.link` for magic-link flow. | +| `redirect_uri?` | Default redirect URL for custom JWT verifiers. If you use Auth0, allowlist it in Allowed Callback URLs. | + +### Email and SMS passwordless -// Login -final Web3AuthResponse response = await Web3AuthFlutter.login( - LoginParams(loginProvider: Provider.email_passwordless, - // focus-start +```dart +final Web3AuthResponse response = await Web3AuthFlutter.connectTo( + LoginParams( + authConnection: AuthConnection.email_passwordless, extraLoginOptions: ExtraLoginOptions( login_hint: "hello@web3auth.io", - additionalParams: additionalParams ), - // focus-end ), ); ``` - +For SMS passwordless, use the format `+{country_code}-{phone_number}` (for example, `+91-9911223311`). - -To use the SMS Passwordless login, send the phone number as the `login_hint` parameter of the -`ExtraLoginOptions`. Please ensure the phone number takes the format: -+\{country_code}-\{phone_number}, that is, (+91-09xx901xx1). +### Grouped connections -```dart title="Usage" -Future initWeb3Auth() async { - Uri redirectUrl; - if (Platform.isAndroid) { - redirectUrl = Uri.parse('{SCHEME}://{HOST}/auth'); - // w3a://com.example.w3aflutter/auth - } else if (Platform.isIOS) { - redirectUrl = Uri.parse('{bundleId}://auth'); - // com.example.w3aflutter://openlogin - } else { - throw UnKnownException('Unknown platform'); - } - - await Web3AuthFlutter.init( - Web3AuthOptions( - clientId: "WEB3AUTH_CLIENT_ID", - network: Network.sapphire_mainnet, - redirectUrl: redirectUrl, - ), - ); -} - -// Login -final Web3AuthResponse response = await Web3AuthFlutter.login( - LoginParams(loginProvider: Provider.sms_passwordless, - // focus-start - extraLoginOptions: ExtraLoginOptions( - // The phone number should be in format of +{country_code}-{phone_number} - login_hint: "+91-9911223311", - ), - // focus-end - ), -); -``` - - - - -### Aggregate verifier example - -You can use aggregate verifier to combine multiple sign-in methods to get the same address for the users regardless of their sign-in providers. For example, combining a Google and email passwordless sign-in, or Google and GitHub via Auth0 to access the same address for your user. +Use grouped connections so the same user gets the same wallet address across multiple sign-in methods: ```dart -// focus-start -final loginConfig = HashMap(); - -loginConfig['google'] = LoginConfigItem( - verifier: "aggregate-sapphire", - verifierSubIdentifier: "w3a-google", - typeOfLogin: TypeOfLogin.google, - clientId: "YOUR_GOOGLE_CLIENT_ID", -); - -loginConfig['jwt'] = LoginConfigItem( - verifier: "aggregate-sapphire", - verifierSubIdentifier: "w3a-a0-github", - typeOfLogin: TypeOfLogin.jwt, - clientId: "YOUR_AUTHO_CLIENT_ID", -); -// focus-end +final authConnectionConfig = [ + AuthConnectionConfig( + authConnection: AuthConnection.google, + authConnectionId: "w3a-google", + groupedAuthConnectionId: "aggregate-sapphire", + clientId: "YOUR_GOOGLE_CLIENT_ID", + ), + AuthConnectionConfig( + authConnection: AuthConnection.custom, + authConnectionId: "w3a-a0-github", + groupedAuthConnectionId: "aggregate-sapphire", + clientId: "YOUR_AUTH0_CLIENT_ID", + ), +]; await Web3AuthFlutter.init( Web3AuthOptions( - clientId: 'YOUR_WEB3AUTH_CLIENT_ID', - network: Network.sapphire_mainnet, + clientId: "WEB3AUTH_CLIENT_ID", + web3AuthNetwork: Web3AuthNetwork.sapphire_mainnet, redirectUrl: redirectUrl, - // focus-next-line - loginConfig: loginConfig, + authConnectionConfig: authConnectionConfig, ), ); -await Web3AuthFlutter.initialize(); - -// Login with Google -// focus-next-line -await Web3AuthFlutter.login(LoginParams(loginProvider: Provider.google)); +// Sign in with Google +await Web3AuthFlutter.connectTo( + LoginParams( + authConnection: AuthConnection.google, + authConnectionId: "w3a-google", + groupedAuthConnectionId: "aggregate-sapphire", + ), +); -// Login With GitHub -// focus-start -await Web3AuthFlutter.login( +// Sign in with GitHub via Auth0 +await Web3AuthFlutter.connectTo( LoginParams( - loginProvider: Provider.jwt, + authConnection: AuthConnection.custom, + authConnectionId: "w3a-a0-github", + groupedAuthConnectionId: "aggregate-sapphire", extraLoginOptions: ExtraLoginOptions( - domain: 'https://web3auth.au.auth0.com', - verifierIdField: 'email', - connection: 'github', - isVerifierIdCaseSensitive: false, + domain: "https://web3auth.au.auth0.com", + userIdField: "email", + connection: "github", + isUserIdCaseSensitive: false, ), ), ); -// focus-end ``` + +See [grouped connections](/embedded-wallets/authentication/group-connections) for dashboard setup. diff --git a/embedded-wallets/sdk/flutter/advanced/dapp-share.mdx b/embedded-wallets/sdk/flutter/advanced/dapp-share.mdx index 71b590c00a7..daafc9970e4 100644 --- a/embedded-wallets/sdk/flutter/advanced/dapp-share.mdx +++ b/embedded-wallets/sdk/flutter/advanced/dapp-share.mdx @@ -34,10 +34,10 @@ After a successful login from a user, the user details are returned as a respons "email": "w3a-heroes@web3auth.com", "name": "Web3Auth Heroes", "profileImage": "https://lh3.googleusercontent.com/a/Ajjjsdsmdjmnm...", - "verifier": "torus", - "verifierId": "w3a-heroes@web3auth.com", - "typeOfLogin": "google", - "aggregateVerifier": "w3a-google-sapphire", + "authConnectionId": "torus", + "userId": "w3a-heroes@web3auth.com", + "authConnection": "google", + "groupedAuthConnectionId": "w3a-google-sapphire", "dappShare": "", // 24 words of seed phrase will be sent only incase of custom verifiers "idToken": "", "oAuthIdToken": "", // will be sent only incase of custom verifiers @@ -53,15 +53,15 @@ While logging in, the user can use their social accounts to obtain one share, an :::note -It's important to note that the `dappShare` is only available for custom verifiers and not the standard Web3Auth verifiers. This is done to make sure that an application only has access to the corresponding share to the private key of their application's user. Hence, to use dapp share, one has to use the custom authentication feature of Web3Auth. Also, the dapp share is only returned to users who have enabled 2FA to their account. +It's important to note that the `dappShare` is only available for custom auth connections and not the standard Embedded Wallets connections. This is done to make sure that an application only has access to the corresponding share to the private key of their application's user. Hence, to use dapp share, one has to use the custom authentication feature of Web3Auth. Also, the dapp share is only returned to users who have enabled 2FA to their account. ::: ```dart -final Web3AuthResponse response = await Web3AuthFlutter.login(LoginParams( - loginProvider: Provider.google, +final Web3AuthResponse response = await Web3AuthFlutter.connectTo(LoginParams( + authConnection: AuthConnection.google, // focus-next-line - dappShare: "<24 words seed phrase>" + dappShare: "<24 words seed phrase>", )); ``` @@ -72,13 +72,11 @@ Future initWeb3Auth() async { HashMap themeMap = HashMap(); themeMap['primary'] = "#229954"; - Uri redirectUrl; + late final String redirectUrl; if (Platform.isAndroid) { - redirectUrl = Uri.parse('{SCHEME}://{HOST}/auth'); - // w3a://com.example.w3aflutter/auth + redirectUrl = 'w3a://com.example.w3aflutter'; } else if (Platform.isIOS) { - redirectUrl = Uri.parse('{bundleId}://auth'); - // com.example.w3aflutter://openlogin + redirectUrl = 'com.example.w3aflutter://auth'; } else { throw UnKnownException('Unknown platform'); } @@ -86,15 +84,15 @@ Future initWeb3Auth() async { await Web3AuthFlutter.init( Web3AuthOptions( clientId: "WEB3AUTH_CLIENT_ID", - network: Network.testnet, + web3AuthNetwork: Web3AuthNetwork.sapphire_devnet, redirectUrl: redirectUrl, ), ); } -final Web3AuthResponse response = await Web3AuthFlutter.login(LoginParams( - loginProvider: Provider.google, +final Web3AuthResponse response = await Web3AuthFlutter.connectTo(LoginParams( + authConnection: AuthConnection.google, // focus-next-line - dappShare: "<24 words seed phrase>" + dappShare: "<24 words seed phrase>", )); ``` diff --git a/embedded-wallets/sdk/flutter/advanced/mfa.mdx b/embedded-wallets/sdk/flutter/advanced/mfa.mdx index fdb84f66287..55bf61d3c58 100644 --- a/embedded-wallets/sdk/flutter/advanced/mfa.mdx +++ b/embedded-wallets/sdk/flutter/advanced/mfa.mdx @@ -14,11 +14,11 @@ At Web3Auth, we prioritize your security by offering Multi-Factor Authentication ## Enable using the Multi-Factor Authentication level -For a dapp, we provide various options to set up MFA. You can customize the MFA screen by passing the `mfaLevel` parameter in `login` method. You can enable or disable a backup factor and change their order. Currently, there are four values for MFA level. +For a dapp, we provide various options to set up MFA. You can customize the MFA screen by passing the `mfaLevel` parameter in the `connectTo` method. You can enable or disable a backup factor and change their order. Currently, there are four values for MFA level. :::caution Note -If you are using default verifiers, your users may have set up MFA on other dapps that also use default Web3Auth verifiers. In this case, the MFA screen will continue to appear if the user has enabled MFA on other dapps. This is because MFA cannot be turned off once it is enabled. +If you are using default auth connections, your users may have set up MFA on other dapps that also use default Embedded Wallets connections. In this case, the MFA screen will continue to appear if the user has enabled MFA on other dapps. This is because MFA cannot be turned off once it is enabled. ::: @@ -34,9 +34,9 @@ If you are using default verifiers, your users may have set up MFA on other dapp ### Usage ```dart -Web3AuthFlutter.login( +Web3AuthFlutter.connectTo( LoginParams( - loginProvider: Provider.google, + authConnection: AuthConnection.google, // focus-next-line mfaLevel: MFALevel.MANDATORY, ), @@ -45,13 +45,13 @@ Web3AuthFlutter.login( ## Explicitly enable Multi-Factor Authentication -The `enableMFA` method is used to trigger MFA setup flow for users. The method takes `LoginParams` which will used during custom verifiers. If you are using default login providers, you don't need to pass `LoginParams`. If you are using custom JWT verifiers, you need to pass the JWT token in `loginParams` as well. +The `enableMFA` method is used to trigger MFA setup flow for users. The method takes optional `LoginParams` for custom connections. If you are using default social login providers, you don't need to pass `LoginParams`. If you are using custom JWT connections, pass the JWT token in `loginParams` using `LoginParams.idToken`. @@ -75,14 +75,13 @@ try { ```dart title="Usage" try { final loginParams = LoginParams( - loginProvider: Provider.jwt, - extraLoginOptions: ExtraLoginOptions( - id_token: "YOUR_JWT_TOKEN", - ), + authConnection: AuthConnection.custom, + authConnectionId: "YOUR_AUTH_CONNECTION_ID", + idToken: "YOUR_JWT_TOKEN", ); // focus-next-line - await Web3AuthFlutter.enableMFA(loginParams); + await Web3AuthFlutter.enableMFA(loginParams: loginParams); } on UserCancelledException { log("User cancelled."); } catch(e) { log("Unknown exception occurred"); } @@ -211,20 +210,18 @@ class MfaSetting { ```dart Future initWeb3Auth() async { - late final Uri redirectUrl; + late final String redirectUrl; if (Platform.isAndroid) { - redirectUrl = Uri.parse('{SCHEME}://{HOST}/auth'); - // w3a://com.example.w3aflutter/auth + redirectUrl = 'w3a://com.example.w3aflutter'; } else { - redirectUrl = Uri.parse('{bundleId}://auth'); - // com.example.w3aflutter://auth + redirectUrl = 'com.example.w3aflutter://auth'; } await Web3AuthFlutter.init( Web3AuthOptions( clientId: "WEB3AUTH_CLIENT_ID", - network: Network.sapphire_mainnet, + web3AuthNetwork: Web3AuthNetwork.sapphire_mainnet, redirectUrl: redirectUrl, // focus-start mfaSettings: MfaSettings( diff --git a/embedded-wallets/sdk/flutter/advanced/whitelabel.mdx b/embedded-wallets/sdk/flutter/advanced/whitelabel.mdx index ba032ae1f00..9fb14bbee51 100644 --- a/embedded-wallets/sdk/flutter/advanced/whitelabel.mdx +++ b/embedded-wallets/sdk/flutter/advanced/whitelabel.mdx @@ -106,13 +106,11 @@ Future initWeb3Auth() async { themeMap['primary'] = "#229954"; // focus-end - Uri redirectUrl; + late final String redirectUrl; if (Platform.isAndroid) { - redirectUrl = Uri.parse('{SCHEME}://{HOST}/auth'); - // w3a://com.example.w3aflutter/auth + redirectUrl = 'w3a://com.example.w3aflutter'; } else if (Platform.isIOS) { - redirectUrl = Uri.parse('{bundleId}://auth'); - // com.example.w3aflutter://openlogin + redirectUrl = 'com.example.w3aflutter://auth'; } else { throw UnKnownException('Unknown platform'); } @@ -120,7 +118,7 @@ Future initWeb3Auth() async { await Web3AuthFlutter.init( Web3AuthOptions( clientId: "WEB3AUTH_CLIENT_ID", - network: Network.sapphire_mainnet, + web3AuthNetwork: Web3AuthNetwork.sapphire_mainnet, redirectUrl: redirectUrl, // focus-start whiteLabel: WhiteLabelData( diff --git a/embedded-wallets/sdk/flutter/usage/README.mdx b/embedded-wallets/sdk/flutter/usage/README.mdx index df5c402832d..a156d824bc8 100644 --- a/embedded-wallets/sdk/flutter/usage/README.mdx +++ b/embedded-wallets/sdk/flutter/usage/README.mdx @@ -4,7 +4,7 @@ sidebar_label: Overview description: 'Web3Auth Flutter SDK Functions | Embedded Wallets' --- -Embedded Wallets provides a comprehensive set of functions to handle authentication, user management, and blockchain interactions in your Flutter applications. These functions allow you to implement features like user login, Multi-Factor Authentication (MFA), private key retrieval, and Wallet Services with minimal effort. Each function is designed to handle a specific aspect of Embedded Wallets' functionality, making it easy to integrate into your Flutter projects. +Embedded Wallets provides a comprehensive set of functions to handle authentication, user management, and blockchain interactions in your Flutter applications. These functions allow you to implement features like user sign-in, Multi-Factor Authentication (MFA), private key retrieval, and Wallet Services with minimal effort. Each function is designed to handle a specific aspect of Embedded Wallets' functionality, making it easy to integrate into your Flutter projects. ## List of functions @@ -16,10 +16,10 @@ For detailed usage, configuration options, and code examples, refer to the dedic ### Authentication functions -| Function Name | Description | -| -------------------------- | -------------------------------------------------- | -| [`login()`](./login.mdx) | Logs the user in with the selected login provider. | -| [`logout()`](./logout.mdx) | Logs the user out from the current session. | +| Function Name | Description | +| --------------------------------- | ---------------------------------------------------- | +| [`connectTo()`](./connect-to.mdx) | Signs the user in with the selected auth connection. | +| [`logout()`](./logout.mdx) | Signs the user out from the current session. | ### User management functions @@ -29,10 +29,10 @@ For detailed usage, configuration options, and code examples, refer to the dedic ### Private key functions -| Function Name | Description | -| ------------------------------------------------------ | ------------------------------------------------------------------------------- | -| [`getPrivKey()`](./get-private-key.mdx) | Retrieve the user's secp256k1 private key for EVM-compatible chains. | -| [`getEd25519PrivKey()`](./get-ed25519-private-key.mdx) | Retrieve the user's ed25519 private key for chains like Solana, Near, Algorand. | +| Function Name | Description | +| --------------------------------------------------------- | ------------------------------------------------------------------------------- | +| [`getPrivateKey()`](./get-private-key.mdx) | Retrieve the user's secp256k1 private key for EVM-compatible chains. | +| [`getEd25519PrivateKey()`](./get-ed25519-private-key.mdx) | Retrieve the user's ed25519 private key for chains like Solana, Near, Algorand. | ### Security functions @@ -43,7 +43,7 @@ For detailed usage, configuration options, and code examples, refer to the dedic ### Wallet Services functions -| Function Name | Description | -| -------------------------------------------------------- | ----------------------------------------------------------------- | -| [`launchWalletServices()`](./launch-wallet-services.mdx) | Launches the templated wallet UI in WebView. | -| [`request()`](./request.mdx) | Opens templated transaction screens for signing EVM transactions. | +| Function Name | Description | +| ---------------------------------------- | ----------------------------------------------------------------- | +| [`showWalletUI()`](./show-wallet-ui.mdx) | Launches the templated wallet UI in WebView. | +| [`request()`](./request.mdx) | Opens templated transaction screens for signing EVM transactions. | diff --git a/embedded-wallets/sdk/flutter/usage/connect-to.mdx b/embedded-wallets/sdk/flutter/usage/connect-to.mdx new file mode 100644 index 00000000000..17af8145355 --- /dev/null +++ b/embedded-wallets/sdk/flutter/usage/connect-to.mdx @@ -0,0 +1,238 @@ +--- +title: Sign in a user +sidebar_label: Sign in a user +description: 'Web3Auth Flutter SDK - connectTo Function | Embedded Wallets' +--- + +import TabItem from '@theme/TabItem' +import Tabs from '@theme/Tabs' + +To sign in a user, use the `connectTo` method. It triggers the sign-in flow and opens an in-app browser so the user can authenticate with the selected provider. Pass supported `AuthConnection` values for social logins (such as Google, Apple, Facebook) or custom JWT connections. + +## Parameters + +The `connectTo` method takes `LoginParams` as a required input. + + + + + +| Parameter | Description | +| -------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `authConnection` | Sets the OAuth sign-in method to use. Supported values include `google`, `facebook`, `reddit`, `discord`, `twitch`, `apple`, `line`, `github`, `kakao`, `linkedin`, `twitter`, `email_passwordless`, `custom`, `sms_passwordless`, `email_password`, and `farcaster`. | +| `authConnectionId?` | Auth connection ID from the Embedded Wallets dashboard. Required for `custom` connections. | +| `groupedAuthConnectionId?` | Grouped auth connection ID for aggregate connections. | +| `extraLoginOptions?` | OAuth options for the corresponding `authConnection`. For example, pass the user's email address as `login_hint` for `email_passwordless`. Defaults to `null`. | +| `appState?` | Tracks app state when the user returns after sign-in. Defaults to `null`. | +| `mfaLevel?` | Customizes the MFA screen during OAuth authentication. Defaults to `MFALevel.DEFAULT`, which shows MFA every third sign-in. | +| `dappShare?` | Custom connection logins can return a dapp share after successful sign-in. Useful if your dapp uses this share to let users sign in without repeating the full flow. | +| `curve?` | Determines the public key encoded in the JWT returned by `getUserInfo`. Does not change the private key format from Web3Auth. `getPrivateKey` always returns secp256k1. Use `getEd25519PrivateKey` for ed25519. Defaults to `Curve.secp256k1`. | +| `idToken?` | JWT (ID token) for `custom` connections. Pass Firebase, Auth0, or other provider tokens here instead of `extraLoginOptions.id_token`. | +| `loginHint?` | Optional login hint (for example, email or phone number) passed directly on `LoginParams`. | + + + + + +```dart +class LoginParams { + final AuthConnection authConnection; + final String? authConnectionId; + final String? groupedAuthConnectionId; + final String? appState; + final MFALevel? mfaLevel; + final ExtraLoginOptions? extraLoginOptions; + final String? dappShare; + final Curve? curve; + final String? dappUrl; + final String? loginHint; + final String? idToken; + + LoginParams({ + required this.authConnection, + this.authConnectionId, + this.groupedAuthConnectionId, + this.appState, + this.mfaLevel, + this.extraLoginOptions, + this.dappShare, + this.curve = Curve.secp256k1, + this.dappUrl, + this.loginHint, + this.idToken, + }); +} + +enum AuthConnection { + google, + facebook, + reddit, + discord, + twitch, + apple, + kakao, + linkedin, + twitter, + weibo, + wechat, + line, + email_passwordless, + email_password, + custom, + sms_passwordless, + farcaster, +} +``` + + + + +## Usage + +```dart +final Web3AuthResponse response = await Web3AuthFlutter.connectTo( + LoginParams(authConnection: AuthConnection.google), +); +``` + +## Examples + + + + + +```dart title="Usage" +Future initWeb3Auth() async { + late final String redirectUrl; + + if (Platform.isAndroid) { + redirectUrl = 'w3a://com.example.w3aflutter'; + } else if (Platform.isIOS) { + redirectUrl = 'com.example.w3aflutter://auth'; + } else { + throw UnKnownException('Unknown platform'); + } + + await Web3AuthFlutter.init(Web3AuthOptions( + clientId: "WEB3AUTH_CLIENT_ID", + web3AuthNetwork: Web3AuthNetwork.sapphire_mainnet, + redirectUrl: redirectUrl, + )); + + await Web3AuthFlutter.initialize(); +} + +// Sign in +final Web3AuthResponse response = await Web3AuthFlutter.connectTo( + // focus-next-line + LoginParams(authConnection: AuthConnection.google), +); +``` + + + + + +```dart title="Usage" +final Web3AuthResponse response = await Web3AuthFlutter.connectTo( + // focus-next-line + LoginParams(authConnection: AuthConnection.facebook), +); +``` + + + + + +```dart title="Usage" +final Web3AuthResponse response = await Web3AuthFlutter.connectTo( + // focus-next-line + LoginParams(authConnection: AuthConnection.discord), +); +``` + + + + + +```dart title="Usage" +final Web3AuthResponse response = await Web3AuthFlutter.connectTo( + // focus-next-line + LoginParams(authConnection: AuthConnection.twitch), +); +``` + + + + + +```dart title="Usage" +final Web3AuthResponse response = await Web3AuthFlutter.connectTo( + LoginParams( + authConnection: AuthConnection.email_passwordless, + // focus-next-line + extraLoginOptions: ExtraLoginOptions(login_hint: "hello@web3auth.io"), + ), +); +``` + + + + + +```dart title="Usage" +final Web3AuthResponse response = await Web3AuthFlutter.connectTo( + LoginParams( + authConnection: AuthConnection.sms_passwordless, + // focus-next-line + extraLoginOptions: ExtraLoginOptions(login_hint: "+91-9911223344"), + ), +); +``` + + + + + +```dart title="Usage" +final Web3AuthResponse response = await Web3AuthFlutter.connectTo( + // focus-next-line + LoginParams(authConnection: AuthConnection.farcaster), +); +``` + + + + + +```dart title="Usage" +final Web3AuthResponse response = await Web3AuthFlutter.connectTo( + LoginParams( + authConnection: AuthConnection.custom, + authConnectionId: "YOUR_AUTH_CONNECTION_ID", + // focus-next-line + idToken: "YOUR_JWT_TOKEN", + ), +); +``` + + + diff --git a/embedded-wallets/sdk/flutter/usage/enable-mfa.mdx b/embedded-wallets/sdk/flutter/usage/enable-mfa.mdx index ad5560ca7fe..8ac8ba71038 100644 --- a/embedded-wallets/sdk/flutter/usage/enable-mfa.mdx +++ b/embedded-wallets/sdk/flutter/usage/enable-mfa.mdx @@ -7,15 +7,15 @@ description: 'Web3Auth Flutter SDK - enableMFA Function | Embedded Wallets' import TabItem from '@theme/TabItem' import Tabs from '@theme/Tabs' -The `enableMFA` method is used to trigger MFA setup flow for users. The method takes `LoginParams` which will used during custom verifiers. If you are using default login providers, you don't need to pass `LoginParams`. If you are using custom JWT verifiers, you need to pass the JWT token in `loginParams` as well. +The `enableMFA` method is used to trigger MFA setup flow for users. The method takes optional `LoginParams` for custom connections. If you are using default social login providers, you don't need to pass `LoginParams`. If you are using custom JWT connections, pass the JWT token in `loginParams` using `LoginParams.idToken`. ## Usage @@ -27,7 +27,7 @@ try { await Web3AuthFlutter.enableMFA(); } on UserCancelledException { log("User cancelled."); -} catch(e) { +} catch (e) { log("Unknown exception occurred"); } ``` @@ -38,18 +38,17 @@ try { ```dart title="Usage" try { - final loginParams = LoginParams( - loginProvider: Provider.jwt, - extraLoginOptions: ExtraLoginOptions( - id_token: "YOUR_JWT_TOKEN", - ), - ); - - // focus-next-line - await Web3AuthFlutter.enableMFA(loginParams); + final loginParams = LoginParams( + authConnection: AuthConnection.custom, + authConnectionId: "YOUR_AUTH_CONNECTION_ID", + idToken: "YOUR_JWT_TOKEN", + ); + + // focus-next-line + await Web3AuthFlutter.enableMFA(loginParams: loginParams); } on UserCancelledException { log("User cancelled."); -} catch(e) { +} catch (e) { log("Unknown exception occurred"); } ``` diff --git a/embedded-wallets/sdk/flutter/usage/get-ed25519-private-key.mdx b/embedded-wallets/sdk/flutter/usage/get-ed25519-private-key.mdx index aa6da305741..af6a7bedf0b 100644 --- a/embedded-wallets/sdk/flutter/usage/get-ed25519-private-key.mdx +++ b/embedded-wallets/sdk/flutter/usage/get-ed25519-private-key.mdx @@ -1,15 +1,15 @@ --- title: Ed25519 private key sidebar_label: Get Ed25519 private key -description: 'Web3Auth Flutter SDK - getEd25519PrivKey Function | Embedded Wallets' +description: 'Web3Auth Flutter SDK - getEd25519PrivateKey Function | Embedded Wallets' --- -To retrieve the secp256k1 private key of the user., use `getEd25519PrivKey` method. This private key can be used to sign transactions on Solana, Near, Algorand, and other chains that use the ed25519 curve. +To retrieve the ed25519 private key of the user, use the `getEd25519PrivateKey` method. This private key can be used to sign transactions on Solana, Near, Algorand, and other chains that use the ed25519 curve. ## Usage ```dart -final privateKey = await Web3AuthFlutter.getEd25519PrivKey(); +final privateKey = await Web3AuthFlutter.getEd25519PrivateKey(); ``` :::note diff --git a/embedded-wallets/sdk/flutter/usage/get-private-key.mdx b/embedded-wallets/sdk/flutter/usage/get-private-key.mdx index cab3c2bd15d..31d9ea7fae7 100644 --- a/embedded-wallets/sdk/flutter/usage/get-private-key.mdx +++ b/embedded-wallets/sdk/flutter/usage/get-private-key.mdx @@ -1,15 +1,15 @@ --- title: Secp256k1 private key sidebar_label: Get Secp256k1 private key -description: 'Web3Auth Flutter SDK - getPrivKey Function | Embedded Wallets' +description: 'Web3Auth Flutter SDK - getPrivateKey Function | Embedded Wallets' --- -To retrieve the secp256k1 private key of the user., use `getPrivkey` method. The method returns an EVM compatible private key which can be used to sign transactions on EVM compatible chains. +To retrieve the secp256k1 private key of the user, use the `getPrivateKey` method. The method returns an EVM compatible private key which can be used to sign transactions on EVM compatible chains. ## Usage ```dart -final privateKey = await Web3AuthFlutter.getPrivKey(); +final privateKey = await Web3AuthFlutter.getPrivateKey(); ``` :::note diff --git a/embedded-wallets/sdk/flutter/usage/get-user-info.mdx b/embedded-wallets/sdk/flutter/usage/get-user-info.mdx index 8d3bcc90ce2..c56d9683d3d 100644 --- a/embedded-wallets/sdk/flutter/usage/get-user-info.mdx +++ b/embedded-wallets/sdk/flutter/usage/get-user-info.mdx @@ -4,15 +4,15 @@ sidebar_label: Get user info description: 'Web3Auth Flutter SDK - getUserInfo Function | Embedded Wallets' --- -You can use the `getUserInfo` method to retrieve various details about the user, such as their login type, whether multi-factor authentication (MFA) is enabled, profile image, name, and other relevant information. +You can use the `getUserInfo` method to retrieve various details about the user, such as their auth connection, whether multi-factor authentication (MFA) is enabled, profile image, name, and other relevant information. ## Usage ```dart -final userInfo = Web3AuthFlutter.getUserInfo(); +final userInfo = await Web3AuthFlutter.getUserInfo(); ``` -## UserInfo Response +## UserInfo response ```json { @@ -20,9 +20,10 @@ final userInfo = Web3AuthFlutter.getUserInfo(); "email": "w3a-heroes@web3auth.com", "name": "Web3Auth Heroes", "profileImage": "https://lh3.googleusercontent.com/a/Ajjjsdsmdjmnm...", - "verifier": "torus", - "verifierId": "w3a-heroes@web3auth.com", - "typeOfLogin": "google", + "authConnectionId": "torus", + "userId": "w3a-heroes@web3auth.com", + "authConnection": "google", + "groupedAuthConnectionId": "", "dappShare": "", "idToken": "eyJhbGciOiJSUzI1NiIsImtpZCI6IjFjZjQ4Y...", "oAuthIdToken": "eyJhbGciOiJSUzI1NiIsImtpZCI6IjFjZjQ4Y...", diff --git a/embedded-wallets/sdk/flutter/usage/launch-wallet-services.mdx b/embedded-wallets/sdk/flutter/usage/launch-wallet-services.mdx deleted file mode 100644 index c736d17152d..00000000000 --- a/embedded-wallets/sdk/flutter/usage/launch-wallet-services.mdx +++ /dev/null @@ -1,88 +0,0 @@ ---- -title: Launch Wallet Services -sidebar_label: Show wallet UI -description: 'Web3Auth Flutter SDK - launchWalletServices Function | Embedded Wallets' ---- - -import TabItem from '@theme/TabItem' -import Tabs from '@theme/Tabs' - -The `launchWalletServices` method launches the templated wallet UI in WebView. The template wallet allows the user to view their account details, tokens, and additional features to interact with connected blockchain network. - -## Parameters - -The `launchWalletServices` method takes in `ChainConfig` as a required input. - - - - - -| Parameter | Description | -| ------------------- | -------------------------------------------------------------------------- | -| `chainNamespace` | Custom chain namespace for the chain. Defaults to `ChainNamespace.eip155`. | -| `decimals?` | Number of decimals for the native currency. Defaults to `18`. | -| `blockExplorerUrl?` | URL of the block explorer for the chain. | -| `chainId` | Chain ID of the chain. | -| `displayName?` | Display name for the chain. | -| `logo?` | Logo URL for the chain. | -| `rpcTarget` | RPC target URL for the chain. | -| `ticker?` | Ticker symbol for the native currency. | -| `tickerName?` | Name of the native currency. | - - - - - -```dart -class ChainConfig { - final ChainNamespace chainNamespace; - final int? decimals; - final String? blockExplorerUrl; - final String chainId; - final String? displayName; - final String? logo; - final String rpcTarget; - final String? ticker; - final String? tickerName; - - ChainConfig({ - this.chainNamespace = ChainNamespace.eip155, - this.decimals = 18, - this.blockExplorerUrl, - required this.chainId, - this.displayName, - this.logo, - required this.rpcTarget, - this.ticker, - this.tickerName, - }); -} -``` - - - - -## Usage - -```dart title="Usage" -try { - // focus-start - await Web3AuthFlutter.launchWalletServices( - ChainConfig( - chainId: "0x1", - rpcTarget: "https://mainnet.infura.io/v3/$key", - ), - ); - // focus-end -} on UserCancelledException { - log("User cancelled."); -} catch(e) { - log("Unknown exception occurred"); -} -``` diff --git a/embedded-wallets/sdk/flutter/usage/login.mdx b/embedded-wallets/sdk/flutter/usage/login.mdx deleted file mode 100644 index 01a844b2328..00000000000 --- a/embedded-wallets/sdk/flutter/usage/login.mdx +++ /dev/null @@ -1,230 +0,0 @@ ---- -title: Logging in a user -sidebar_label: Sign in a user -description: 'Web3Auth Flutter SDK - Login Function | Embedded Wallets' ---- - -import TabItem from '@theme/TabItem' -import Tabs from '@theme/Tabs' - -To login in a user, you can use the `login` method. It will trigger login flow will navigate the user to a browser model allowing the user to login into the service. You can pass in the supported providers to the login method for specific social logins (such as Google, Apple, Facebook) and do a whitelabel login. - -## Parameters - -The `login` method takes in `LoginParams` as a required input. - - - - - -| Parameter | Description | -| -------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `loginProvider` | It sets the OAuth login method to be used. You can use any of the supported values are `google`, `facebook`, `reddit`, `discord`, `twitch`, `apple`, `line`, `github`, `kakao`, `linkedin`, `twitter`, `email_passwordless`, `jwt`, `sms_passwordless`, `email_password`, and `farcaster`. | -| `extraLoginOptions?` | It can be used to set the OAuth login options for corresponding `loginProvider`. For instance, you'll need to pass user's email address as. Default value for the field is `null`, and it accepts `ExtraLoginOptions` as a value. | -| `redirectUrl?` | URL where user will be redirected after successful login. By default user will be redirected to same page where login will be initiated. Default value for the field is `null` | -| `appState?` | It can be used to keep track of the app state when user will be redirected to app after login. Default is `null`, and it accepts a string value. | -| `mfaLevel?` | Customize the MFA screen shown to the user during OAuth authentication. Default value for field is `MFALevel.DEFAULT`, which shows MFA screen every 3rd login. It accepts `MFALevel` as a value. | -| `dappShare?` | Custom verifier logins can get a dapp share returned to them post successful login. This is useful if the dapps want to use this share to allow users to sign in without repeating the full flow. It accepts a string value. | -| `curve?` | It will be used to determine the public key encoded in the JWT token which returned in `getUserInfo` function after user login. This parameter won't change format of private key returned by We3Auth. Private key returned by `getPrivKey` is always secp256k1. To get the ed25519 key you can use `getEd25519PrivKey` method. The default value is `Curve.secp256k1`. | - - - - - -```dart -class LoginParams { - final Provider loginProvider; - final String? dappShare; - final ExtraLoginOptions? extraLoginOptions; - final String? redirectUrl; - final String? appState; - final MFALevel? mfaLevel; - final Curve? curve; - - LoginParams({ - required this.loginProvider, - this.dappShare, - this.extraLoginOptions, - this.redirectUrl, - this.appState, - this.mfaLevel, - this.curve = Curve.secp256k1, - }); -} - -enum Provider { - google, - facebook, - reddit, - discord, - twitch, - apple, - line, - github, - kakao, - linkedin, - twitter, - weibo, - wechat, - email_passwordless, - jwt, - sms_passwordless, - farcaster, -} -``` - - - - -## Usage - -```dart -final Web3AuthResponse response = await Web3AuthFlutter.login( - LoginParams(loginProvider: Provider.google) -); -``` - -## Examples - - - - - -```dart title="Usage" -Future initWeb3Auth() async { - Uri redirectUrl; - - if (Platform.isAndroid) { - redirectUrl = Uri.parse('{SCHEME}://{HOST}/auth'); - // w3a://com.example.w3aflutter/auth - } else if (Platform.isIOS) { - redirectUrl = Uri.parse('{bundleId}://auth'); - // com.example.w3aflutter://openlogin - } else { - throw UnKnownException('Unknown platform'); - } - - await Web3AuthFlutter.init(Web3AuthOptions( - clientId: "WEB3AUTH_CLIENT_ID", - network: Network.sapphire_mainnet, - redirectUrl: redirectUrl, - )); - - await Web3AuthFlutter.initialize(); -} - -// Login -final Web3AuthResponse response = await Web3AuthFlutter.login( - // focus-next-line - LoginParams(loginProvider: Provider.google) -); -``` - - - - - -```dart title="Usage" -final Web3AuthResponse response = await Web3AuthFlutter.login( - // focus-next-line - LoginParams(loginProvider: Provider.facebook) -); -``` - - - - - -```dart title="Usage" -final Web3AuthResponse response = await Web3AuthFlutter.login( - // focus-next-line - LoginParams(loginProvider: Provider.discord) -); -``` - - - - - -```dart title="Usage" -final Web3AuthResponse response = await Web3AuthFlutter.login( - // focus-next-line - LoginParams(loginProvider: Provider.twitch) -); -``` - - - - - -```dart title="Usage" -final Web3AuthResponse response = await Web3AuthFlutter.login( - LoginParams( - loginProvider: Provider.email_passwordless, - // focus-next-line - extraLoginOptions: ExtraLoginOptions(login_hint: "hello@web3auth.io") - ) -); -``` - - - - - -```dart title="Usage" -final Web3AuthResponse response = await Web3AuthFlutter.login( - LoginParams( - loginProvider: Provider.sms_passwordless, - // focus-next-line - extraLoginOptions: ExtraLoginOptions(login_hint: "+91-9911223344") - ) -); -``` - - - - - -```dart title="Usage" -final Web3AuthResponse response = await Web3AuthFlutter.login( - // focus-next-line - LoginParams(loginProvider: Provider.farcaster) -); -``` - - - - - -```dart title="Usage" -final Web3AuthResponse response = await Web3AuthFlutter.login( - LoginParams( - loginProvider: Provider.jwt, - extraLoginOptions: ExtraLoginOptions( - // focus-next-line - id_token: "YOUR_JWT_TOKEN", - ) - ) -); -``` - - - diff --git a/embedded-wallets/sdk/flutter/usage/request.mdx b/embedded-wallets/sdk/flutter/usage/request.mdx index 6b9f33fdace..bf4a841e7fe 100644 --- a/embedded-wallets/sdk/flutter/usage/request.mdx +++ b/embedded-wallets/sdk/flutter/usage/request.mdx @@ -4,7 +4,9 @@ sidebar_label: Send requests description: 'Web3Auth Flutter SDK - request Function | Embedded Wallets' --- -The `request` method facilitates the use of prebuilt transaction screens for signing transactions. The method will return [SignResponse](#signresponse). It can be used to sign transactions for any EVM chain and screens can be customized to match your branding. +The `request` method facilitates the use of prebuilt transaction screens for signing transactions. The method returns [SignResponse](#signresponse). It can be used to sign transactions for any EVM chain and screens can be customized to match your branding. + +Configure chains during initialization with `Web3AuthOptions(chains: [...])`. The `request` method uses those chains; you no longer pass a separate chain configuration argument. Please check the list of [JSON RPC methods](https://docs.metamask.io/wallet/reference/json-rpc-api/), noting that the request method currently supports only the signing methods. @@ -18,9 +20,10 @@ Please check the list of [JSON RPC methods](https://docs.metamask.io/wallet/refe | Arguments | Description | | --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -| `chainConfig` | Defines the chain to be used for signature. | | `method` | JSON RPC method name in `String`. Currently, the request method only supports the signing methods. | | `requestParams` | Parameters for the corresponding method. The parameters should be in the list and correct sequence. Take a look at [RPC methods](https://docs.metamask.io/wallet/reference/json-rpc-api) to know more. | +| `path?` | Wallet request path. Defaults to `"wallet/request"`. | +| `appState?` | Optional app state string passed to the wallet UI. | ## Usage @@ -35,10 +38,6 @@ try { // focus-start final response = await Web3AuthFlutter.request( - ChainConfig( - chainId: "0x1", - rpcTarget: "https://mainnet.infura.io/v3/$key", - ), "personal_sign", params, ); @@ -47,7 +46,7 @@ try { // focus-end } on UserCancelledException { log("User cancelled."); -} catch(e) { +} catch (e) { log("Unknown exception occurred"); } ``` diff --git a/embedded-wallets/sdk/flutter/usage/show-wallet-ui.mdx b/embedded-wallets/sdk/flutter/usage/show-wallet-ui.mdx new file mode 100644 index 00000000000..8847ec1d112 --- /dev/null +++ b/embedded-wallets/sdk/flutter/usage/show-wallet-ui.mdx @@ -0,0 +1,53 @@ +--- +title: Show wallet UI +sidebar_label: Show wallet UI +description: 'Web3Auth Flutter SDK - showWalletUI Function | Embedded Wallets' +--- + +The `showWalletUI` method launches the templated wallet UI in a WebView. The wallet UI lets users view account details, tokens, and other features for the chains configured in `Web3AuthOptions`. + +Configure chains during initialization with the `chains` and `defaultChainId` parameters on `Web3AuthOptions`. See [Get started](/embedded-wallets/sdk/flutter/) for chain configuration examples. + +## Parameters + +| Parameter | Description | +| --------- | --------------------------------------- | +| `path?` | Wallet UI path. Defaults to `"wallet"`. | + +## Usage + +```dart title="Usage" +try { + // focus-start + await Web3AuthFlutter.showWalletUI(); + // focus-end +} on UserCancelledException { + log("User cancelled."); +} catch (e) { + log("Unknown exception occurred"); +} +``` + +## Chain configuration + +Pass chain details when you initialize the SDK: + +```dart +await Web3AuthFlutter.init( + Web3AuthOptions( + clientId: "WEB3AUTH_CLIENT_ID", + web3AuthNetwork: Web3AuthNetwork.sapphire_mainnet, + redirectUrl: redirectUrl, + chains: [ + Chains( + chainId: "0x1", + rpcTarget: "https://mainnet.infura.io/v3/", + displayName: "Ethereum Mainnet", + ticker: "ETH", + tickerName: "Ethereum", + ), + ], + defaultChainId: "0x1", + ), +); +``` diff --git a/ew-sidebar.js b/ew-sidebar.js index fc2c1a27a75..0141c1466d6 100644 --- a/ew-sidebar.js +++ b/ew-sidebar.js @@ -938,14 +938,14 @@ const sidebar = { label: 'Usage', items: [ 'sdk/flutter/usage/README', - 'sdk/flutter/usage/login', + 'sdk/flutter/usage/connect-to', 'sdk/flutter/usage/get-user-info', 'sdk/flutter/usage/get-private-key', 'sdk/flutter/usage/get-ed25519-private-key', 'sdk/flutter/usage/logout', 'sdk/flutter/usage/enable-mfa', 'sdk/flutter/usage/manage-mfa', - 'sdk/flutter/usage/launch-wallet-services', + 'sdk/flutter/usage/show-wallet-ui', 'sdk/flutter/usage/request', ], }, diff --git a/gator_versioned_docs/version-2.0.0/reference/types.md b/gator_versioned_docs/version-2.0.0/reference/types.md index c7986ead3d1..845e488bb3d 100644 --- a/gator_versioned_docs/version-2.0.0/reference/types.md +++ b/gator_versioned_docs/version-2.0.0/reference/types.md @@ -260,8 +260,7 @@ Represents a value that can be provided directly or derived at runtime from [`Pa ```ts type MaybeDeferred = - | TResult - | ((requirements: PaymentRequirements) => Promise | TResult) + TResult | ((requirements: PaymentRequirements) => Promise | TResult) ``` ### `PaymentRequirements` diff --git a/src/pages/quickstart/builder/embedded-wallets/flutter/stepContent/installation.mdx b/src/pages/quickstart/builder/embedded-wallets/flutter/stepContent/installation.mdx index 644c584c46e..4829dcb03ec 100644 --- a/src/pages/quickstart/builder/embedded-wallets/flutter/stepContent/installation.mdx +++ b/src/pages/quickstart/builder/embedded-wallets/flutter/stepContent/installation.mdx @@ -11,7 +11,7 @@ or ```yaml dependencies: - web3auth_flutter: ^3.1.1 ### or the latest version + web3auth_flutter: ^7.0.0 ``` :::warning Update to the latest SDK diff --git a/src/pages/quickstart/builder/embedded-wallets/flutter/stepContent/requirementsAndroid.mdx b/src/pages/quickstart/builder/embedded-wallets/flutter/stepContent/requirementsAndroid.mdx index f8232364042..9c4b36348b7 100644 --- a/src/pages/quickstart/builder/embedded-wallets/flutter/stepContent/requirementsAndroid.mdx +++ b/src/pages/quickstart/builder/embedded-wallets/flutter/stepContent/requirementsAndroid.mdx @@ -2,7 +2,7 @@ Ensure your Android environment meets the following version requirements: -- Android API version 24 or later +- Android API version 26 or later - `compileSdk` version 34 or later Refer to the `android/app/build.gradle` file in your Flutter project to update the versions. diff --git a/src/pages/quickstart/builder/embedded-wallets/flutter/stepContent/signin.mdx b/src/pages/quickstart/builder/embedded-wallets/flutter/stepContent/signin.mdx index f8201660370..a6ed9c186af 100644 --- a/src/pages/quickstart/builder/embedded-wallets/flutter/stepContent/signin.mdx +++ b/src/pages/quickstart/builder/embedded-wallets/flutter/stepContent/signin.mdx @@ -1,6 +1,6 @@ ### Sign in the user -Use the [`login`](/embedded-wallets/sdk/flutter/usage/login) function to access +Use the [`connectTo`](/embedded-wallets/sdk/flutter/usage/connect-to) function to access the sign-in functionality. You can trigger this function from a button or other user action. diff --git a/src/pages/tutorials/flutter-wallet.mdx b/src/pages/tutorials/flutter-wallet.mdx index 7744d393045..074b6ca669f 100644 --- a/src/pages/tutorials/flutter-wallet.mdx +++ b/src/pages/tutorials/flutter-wallet.mdx @@ -72,7 +72,7 @@ Add `web3auth_flutter` as a dependency to your `pubspec.yaml`. ```yaml dependencies: - web3auth_flutter: ^6.1.2 + web3auth_flutter: ^7.0.0 ``` @@ -88,18 +88,17 @@ Future main() async { // Additional code - final Uri redirectUrl; + late final String redirectUrl; if (Platform.isAndroid) { - redirectUrl = - Uri.parse('w3aexample://com.example.flutter_solana_example/auth'); + redirectUrl = 'w3aexample://com.example.flutter_solana_example'; } else { - redirectUrl = Uri.parse('com.web3auth.fluttersolanasample://auth'); + redirectUrl = 'com.web3auth.fluttersolanasample://auth'; } await Web3AuthFlutter.init( Web3AuthOptions( clientId: "YOUR_WEB3AUTH_CLIENT_ID", // Pass your Web3Auth Client ID, ideally using an environment variable - network: Network.sapphire_mainnet, + web3AuthNetwork: Web3AuthNetwork.sapphire_mainnet, redirectUrl: redirectUrl, ), ); @@ -118,7 +117,7 @@ Learn more about [Web3Auth initialization](/embedded-wallets/sdk/flutter#initial ### 2.3 Session management -To check whether the user is authenticated, you can use the `getPrivateKey` or `getEd25519PrivKey` method. For an authenticated user, the result would be a non-empty string. You can navigate to different views based on the result. If the user is already authenticated, we'll navigate them to `HomeScreen`. In case of no active session, we'll navigate to `LoginScreen` to authenticate again. +To check whether the user is authenticated, you can use the `getPrivateKey` or `getEd25519PrivateKey` method. For an authenticated user, the result would be a non-empty string. You can navigate to different views based on the result. If the user is already authenticated, we'll navigate them to `HomeScreen`. In case of no active session, we'll navigate to `LoginScreen` to authenticate again. :::tip @@ -139,7 +138,7 @@ class _MainAppState extends State { @override void initState() { super.initState(); - privateKeyFuture = Web3AuthFlutter.getEd25519PrivKey(); + privateKeyFuture = Web3AuthFlutter.getEd25519PrivateKey(); } @override @@ -173,7 +172,7 @@ We'll create a helper function, `_login` inside `LoginScreen`. The sign-in flow :::tip -Learn more about [Embedded Wallets' `LoginParams`](/embedded-wallets/sdk/flutter/usage/login#parameters). +Learn more about [Embedded Wallets' `LoginParams`](/embedded-wallets/sdk/flutter/usage/connect-to#parameters). ::: @@ -203,11 +202,11 @@ class _LoginScreenState extends State with WidgetsBindingObserver { } // It can be used to set the OAuth login options for corresponding - // loginProvider. For instance, you'll need to pass user's email address as - // login_hint when the Provider is email_passwordless. - await Web3AuthFlutter.login( + // authConnection. For instance, you'll need to pass user's email address as + // login_hint when the auth connection is email_passwordless. + await Web3AuthFlutter.connectTo( LoginParams( - loginProvider: Provider.email_passwordless, + authConnection: AuthConnection.email_passwordless, mfaLevel: MFALevel.DEFAULT, extraLoginOptions: ExtraLoginOptions( login_hint: emailController.text, @@ -370,10 +369,10 @@ class EthereumProvider extends ChainProvider { // Prepares the Credentials used for signing the message, // and transaction on EVM chains. EVM ecosystem uses the - // secp256k1 curve. You can use the Web3AuthFlutter.getPrivKey + // secp256k1 curve. You can use the Web3AuthFlutter.getPrivateKey // to retrieve the secp256k1 compatible private key. Future _prepareCredentials() async { - final privateKey = await Web3AuthFlutter.getPrivKey(); + final privateKey = await Web3AuthFlutter.getPrivateKey(); final Credentials credentials = EthPrivateKey.fromHex(privateKey); return credentials; } @@ -430,7 +429,7 @@ class EthereumProvider extends ChainProvider { ### Solana provider -Extend `ChainProvider` and create `SolanaProvider`. In `SolanaProvider`, only implement the `getBalance`, `sendTransaction`, and `signMessage` methods. Add `_generateKeyPair()`to generate an `Ed25519HDKeyPair`which `SolanaProvider` uses to sign transactions and messages in the Solana ecosystem. Because Solana uses the `ed25519` curve, we can use `Web3AuthFlutter.getEd25519PrivKey` to retrieve the private key. +Extend `ChainProvider` and create `SolanaProvider`. In `SolanaProvider`, only implement the `getBalance`, `sendTransaction`, and `signMessage` methods. Add `_generateKeyPair()`to generate an `Ed25519HDKeyPair`which `SolanaProvider` uses to sign transactions and messages in the Solana ecosystem. Because Solana uses the `ed25519` curve, we can use `Web3AuthFlutter.getEd25519PrivateKey` to retrieve the private key. ```dart class SolanaProvider extends ChainProvider { @@ -480,7 +479,7 @@ class SolanaProvider extends ChainProvider { } Future _generateKeyPair() async { - final privateKey = await Web3AuthFlutter.getEd25519PrivKey(); + final privateKey = await Web3AuthFlutter.getEd25519PrivateKey(); return await Ed25519HDKeyPair.fromPrivateKeyBytes( privateKey: privateKey.hexToBytes.take(32).toList(), ); diff --git a/src/utils/w3a-sdk-map.js b/src/utils/w3a-sdk-map.js index d75bbc6bfb9..cdd52b17d19 100644 --- a/src/utils/w3a-sdk-map.js +++ b/src/utils/w3a-sdk-map.js @@ -17,8 +17,8 @@ export const pnpWebVersion = `11` export const pnpAndroidVersion = `10` export const pnpIOSVersion = `11` export const pnpRNVersion = `9` -export const pnpNodeVersion = `6` -export const pnpFlutterVersion = `6` +export const pnpNodeVersion = `5` +export const pnpFlutterVersion = `7` export const pnpUnityVersion = `7` export const pnpUnrealVersion = `4` diff --git a/vercel.json b/vercel.json index 573af65795b..ed28d5f1a16 100644 --- a/vercel.json +++ b/vercel.json @@ -933,11 +933,21 @@ "destination": "/embedded-wallets/sdk/flutter/usage/get-ed25519-private-key/", "permanent": true }, + { + "source": "/embedded-wallets/sdk/flutter/usage/getEd25519PrivateKey/", + "destination": "/embedded-wallets/sdk/flutter/usage/get-ed25519-private-key/", + "permanent": true + }, { "source": "/embedded-wallets/sdk/flutter/usage/getPrivKey/", "destination": "/embedded-wallets/sdk/flutter/usage/get-private-key/", "permanent": true }, + { + "source": "/embedded-wallets/sdk/flutter/usage/getPrivateKey/", + "destination": "/embedded-wallets/sdk/flutter/usage/get-private-key/", + "permanent": true + }, { "source": "/embedded-wallets/sdk/flutter/usage/getUserInfo/", "destination": "/embedded-wallets/sdk/flutter/usage/get-user-info/", @@ -945,7 +955,27 @@ }, { "source": "/embedded-wallets/sdk/flutter/usage/launchWalletServices/", - "destination": "/embedded-wallets/sdk/flutter/usage/launch-wallet-services/", + "destination": "/embedded-wallets/sdk/flutter/usage/show-wallet-ui/", + "permanent": true + }, + { + "source": "/embedded-wallets/sdk/flutter/usage/launch-wallet-services/", + "destination": "/embedded-wallets/sdk/flutter/usage/show-wallet-ui/", + "permanent": true + }, + { + "source": "/embedded-wallets/sdk/flutter/usage/showWalletUI/", + "destination": "/embedded-wallets/sdk/flutter/usage/show-wallet-ui/", + "permanent": true + }, + { + "source": "/embedded-wallets/sdk/flutter/usage/login/", + "destination": "/embedded-wallets/sdk/flutter/usage/connect-to/", + "permanent": true + }, + { + "source": "/embedded-wallets/sdk/flutter/usage/connectTo/", + "destination": "/embedded-wallets/sdk/flutter/usage/connect-to/", "permanent": true }, {