diff --git a/embedded-wallets/connect-blockchain/_unity-connect-blockchain/_evm-get-account.mdx b/embedded-wallets/connect-blockchain/_unity-connect-blockchain/_evm-get-account.mdx index 45af306aa9f..dbe0b55138a 100644 --- a/embedded-wallets/connect-blockchain/_unity-connect-blockchain/_evm-get-account.mdx +++ b/embedded-wallets/connect-blockchain/_unity-connect-blockchain/_evm-get-account.mdx @@ -1,60 +1,15 @@ -import CopyableNoFollow from '@site/src/components/CopyableNoFollow' +Use the Nethereum account created from the user's private key to get the EVM address: -In this reference, we're using the `Nethereum` library to demonstrate how to make blockchain calls -using it with Web3Auth. +```cs +using System; -# Package installation instructions +public string getAccount() +{ + if (account == null) + { + throw new InvalidOperationException("Sign in before requesting an account."); + } -See the [official repository](https://github.com/Nethereum/Nethereum.Unity) - -Install via **Package Manager** using OpenUpm: - -- open Edit/Project Settings/Package Manager - -- add a new **Scoped Registry** (or edit the existing OpenUPM entry) - - Name package.openupm.com - - - URL - - - `Scope(s)` com.nethereum.unity - -- click Save or Apply - -- Open **Window/Package Manager** - -- click **+** - -- select Add package by name... or Add package from git URL... - -- paste **com.nethereum.unity** into name - -- paste **4.19.2** into version (or your preferred one) - -- click **Add** - -# Installing package for old version - -- Download the latest `net461dllsAOT.zip` package from Nethereum's - [latest release](https://github.com/Nethereum/Nethereum/releases) - -- Extract and the rename the folder to `NethereumLib` for easy identification. - -- Move the folder to the `Assets/Plugins` folder of your Unity project. - -- You might have to delete a few files from the `NethereumLib` fold er, if you're getting any errors - while building the project. For our implementation, we deleted the following files: - `Newtonsoft.Json.dll`, all the files starting with `System.*`, `UnityEngine.dll`, - `Nethereum.Web3Lite.dll`, `Nethereum.HdWallet.dll`, `NBitcoin.dll`, `Nethereum.RPC.Reactive.dll` - and `Common.Logging.Core.dll`. - -:::info - -We have followed [this guide](https://docs.nethereum.com/) to set up -the `Nethereum` package in our app. You can check their sample applications as well for a decent -reference. - -You can also check the -[Web3Auth Unity Sample Apps](https://github.com/Web3Auth/web3auth-unity-examples), where we -have added the required packages. - -::: + return account.Address; +} +``` diff --git a/embedded-wallets/connect-blockchain/_unity-connect-blockchain/_evm-initialisation.mdx b/embedded-wallets/connect-blockchain/_unity-connect-blockchain/_evm-initialisation.mdx index fa58e9b6439..bf46061310c 100644 --- a/embedded-wallets/connect-blockchain/_unity-connect-blockchain/_evm-initialisation.mdx +++ b/embedded-wallets/connect-blockchain/_unity-connect-blockchain/_evm-initialisation.mdx @@ -1,40 +1,28 @@ ```cs using Nethereum.Web3; -using Nethereum.Util; -using Nethereum.Signer; -using Nethereum.Hex.HexConvertors.Extensions; -using Nethereum.ABI.Encoders; -using Nethereum.Hex.HexTypes; using Nethereum.Web3.Accounts; -using Nethereum.Web3.Accounts.Managed; public class Web3AuthScript : MonoBehaviour { - Web3 web3; - Web3Auth web3Auth; + private Web3 web3; + private Web3Auth web3Auth; private string privateKey; private Account account; - const string rpcURL = "" // EVM chain RPC URL + private const string rpcUrl = ""; void Start() { - - web3Auth = GetComponent(); - - // Add Web3Auth Unity SDK Initialisation Code here - - web3Auth.onLogin += onLogin; - web3Auth.onLogout += onLogout; - web3 = new Web3(rpcURL); + web3Auth = GetComponent(); + // Add the Embedded Wallet SDK initialization code here. + web3Auth.onLogin += onLogin; } private void onLogin(Web3AuthResponse response) { - privateKey = response.privKey; - var newAccount = new Account(privateKey); - account = newAccount; + privateKey = response.privateKey; + account = new Account(privateKey); + web3 = new Web3(account, rpcUrl); } -// ... } ``` diff --git a/embedded-wallets/connect-blockchain/_unity-connect-blockchain/_evm-installation.mdx b/embedded-wallets/connect-blockchain/_unity-connect-blockchain/_evm-installation.mdx index 4024dddc92c..277be66bdbf 100644 --- a/embedded-wallets/connect-blockchain/_unity-connect-blockchain/_evm-installation.mdx +++ b/embedded-wallets/connect-blockchain/_unity-connect-blockchain/_evm-installation.mdx @@ -54,7 +54,6 @@ the `Nethereum` package in our app. You can check their sample applications as w reference. You can also check the -[Web3Auth Unity Sample Apps](https://github.com/Web3Auth/web3auth-unity-examples), where we -have added the required packages. +[Unity SDK sample](https://github.com/Web3Auth/web3auth-unity-sdk/tree/master/Assets/Plugins/Web3AuthSDK/Samples). ::: diff --git a/embedded-wallets/connect-blockchain/evm/ethereum/unity.mdx b/embedded-wallets/connect-blockchain/evm/ethereum/unity.mdx index d56ddaaf379..7ebfe5863c2 100644 --- a/embedded-wallets/connect-blockchain/evm/ethereum/unity.mdx +++ b/embedded-wallets/connect-blockchain/evm/ethereum/unity.mdx @@ -27,10 +27,6 @@ While using the Embedded Wallets Unity SDK, you get the private key within the u -## Chain details for Ethereum - - - ## Initialize diff --git a/embedded-wallets/connect-blockchain/evm/monad/unity.mdx b/embedded-wallets/connect-blockchain/evm/monad/unity.mdx index 0de9a7fe53a..2992e5a8b80 100644 --- a/embedded-wallets/connect-blockchain/evm/monad/unity.mdx +++ b/embedded-wallets/connect-blockchain/evm/monad/unity.mdx @@ -27,10 +27,6 @@ While using the Embedded Wallets Unity SDK, you get the private key within the u -## Chain details for Monad - - - ## Initialize diff --git a/embedded-wallets/connect-blockchain/solana/unity.mdx b/embedded-wallets/connect-blockchain/solana/unity.mdx index bfc8f2f2a27..86e75107401 100644 --- a/embedded-wallets/connect-blockchain/solana/unity.mdx +++ b/embedded-wallets/connect-blockchain/solana/unity.mdx @@ -74,28 +74,38 @@ Alternatively, you can use other Solana Unity SDKs or create custom C# bindings ## Initialize -First, initialize the Web3Auth Unity SDK and retrieve the Ed25519 private key after successful authentication: +Initialize the Embedded Wallet SDK and retrieve the Ed25519 private key from the sign-in callback: ```csharp -using Web3Auth; - public class SolanaIntegration : MonoBehaviour { private Web3Auth web3Auth; private string ed25519PrivateKey; - async void Start() + void Start() { - // Initialize Web3Auth web3Auth = GetComponent(); + web3Auth.setOptions(new Web3AuthOptions + { + clientId = "", + web3AuthNetwork = Web3Auth.Network.SAPPHIRE_DEVNET, + redirectUrl = new Uri(":///auth") + }); + web3Auth.onLogin += onLogin; + } - // After successful login - await web3Auth.login(); - - // Get Ed25519 private key for Solana - ed25519PrivateKey = await web3Auth.GetEd25519PrivKey(); + public void login() + { + web3Auth.login(new LoginParams + { + authConnection = AuthConnection.GOOGLE, + curve = Curve.ED25519 + }); + } - Debug.Log("Ed25519 Private Key retrieved for Solana"); + private void onLogin(Web3AuthResponse response) + { + ed25519PrivateKey = response.ed25519PrivateKey; } } ``` @@ -104,10 +114,13 @@ public class SolanaIntegration : MonoBehaviour ```csharp // After successful Web3Auth login -string ed25519PrivateKey = await web3auth.GetEd25519PrivKey(); +string ed25519PrivateKey = web3Auth.getEd25519PrivateKey(); -// Convert to byte array if needed for Solana SDK -byte[] privateKeyBytes = Convert.FromHexString(ed25519PrivateKey); +byte[] privateKeyBytes = new byte[ed25519PrivateKey.Length / 2]; +for (int index = 0; index < privateKeyBytes.Length; index++) +{ + privateKeyBytes[index] = Convert.ToByte(ed25519PrivateKey.Substring(index * 2, 2), 16); +} ``` ## Create a Solana keypair diff --git a/embedded-wallets/migration-guides/unity.mdx b/embedded-wallets/migration-guides/unity.mdx new file mode 100644 index 00000000000..83cc1dc7b55 --- /dev/null +++ b/embedded-wallets/migration-guides/unity.mdx @@ -0,0 +1,143 @@ +--- +title: Unity SDK v8 migration guide +sidebar_label: Unity SDK v8 +description: Upgrade the MetaMask Embedded Wallet SDK for Unity from v7 to v8. +keywords: [migration, v8, v7, unity, web3auth, embedded wallets, csharp] +--- + +Unity SDK v8 updates authentication and Wallet Services to the latest service APIs. +It also renames several public types and properties. + +:::caution Preserve wallet addresses + +Don't change your client ID, Sapphire network, or authentication connection configuration during +the migration. +Changing these values can change your users' wallet addresses. + +::: + +## Install v8 + +Download the +[latest v8 `.unitypackage`](https://github.com/Web3Auth/web3auth-unity-sdk/releases/latest), remove +the previous SDK files from your project, and import the new package. + +Ensure `Packages/manifest.json` includes Newtonsoft.Json: + +```json +{ + "dependencies": { + "com.unity.nuget.newtonsoft-json": "3.2.1" + } +} +``` + +## Update initialization + +Rename `network` to `web3AuthNetwork`. +Replace `loginConfig` and `LoginConfigItem` with `authConnectionConfig` and +`AuthConnectionConfig`. + +```cs +var connection = new AuthConnectionConfig +{ + authConnectionId = "", + authConnection = AuthConnection.GOOGLE, + clientId = "" +}; + +web3Auth.setOptions(new Web3AuthOptions +{ + clientId = "", + redirectUrl = new Uri(":///auth"), + web3AuthNetwork = Web3Auth.Network.SAPPHIRE_MAINNET, + authConnectionConfig = new List + { + connection + } +}); +``` + +## Update sign-in parameters + +Replace `Provider` with `AuthConnection`. +In `LoginParams`, rename `loginProvider` to `authConnection`. +Replace `Provider.JWT` with `AuthConnection.CUSTOM`. +For custom authentication, pass the dashboard connection ID as `authConnectionId`. + +```cs +web3Auth.login(new LoginParams +{ + authConnection = AuthConnection.CUSTOM, + authConnectionId = "", + extraLoginOptions = new ExtraLoginOptions + { + id_token = "", + userIdField = "sub" + } +}); +``` + +Also rename these `ExtraLoginOptions` properties: + +- `verifierIdField` to `userIdField` +- `isVerifierIdCaseSensitive` to `isUserIdCaseSensitive` + +## Update response and key properties + +Rename the response properties: + +- `privKey` to `privateKey` +- `ed25519PrivKey` to `ed25519PrivateKey` + +Rename the session key methods: + +- `getPrivKey()` to `getPrivateKey()` +- `getEd25519PrivKey()` to `getEd25519PrivateKey()` + +Update `UserInfo` property names: + +- `aggregateVerifier` to `groupedAuthConnectionId` +- `verifier` to `authConnectionId` +- `verifierId` to `userId` +- `typeOfLogin` to `authConnection` + +```cs +private void onLogin(Web3AuthResponse response) +{ + var privateKey = response.privateKey; + var ed25519PrivateKey = response.ed25519PrivateKey; +} +``` + +## Update Wallet Services + +Configure chains in the Embedded Wallets dashboard. +Replace `launchWalletServices(ChainConfig)` with `showWalletUI()`: + +```cs +web3Auth.showWalletUI(); +``` + +Remove `ChainConfig` from `request`. +Pass only the method and its parameters: + +```cs +var requestParams = new JArray +{ + "Hello World", + account.Address +}; + +web3Auth.request("personal_sign", requestParams); +``` + +Subscribe to `onSignResponse` to receive the request result. + +## Verify the migration + +1. Confirm the redirect URL matches the dashboard allowlist and the Unity deep-link configuration. +2. Test sign-in and sign-out on every target platform. +3. Confirm an existing user receives the same wallet address as before the migration. +4. Test custom and grouped authentication connections, if configured. +5. Test Wallet Services and signing requests on every configured chain. diff --git a/embedded-wallets/sdk/unity/README.mdx b/embedded-wallets/sdk/unity/README.mdx index 5825e0305c1..f428444e947 100644 --- a/embedded-wallets/sdk/unity/README.mdx +++ b/embedded-wallets/sdk/unity/README.mdx @@ -1,7 +1,7 @@ --- title: Embedded Wallets SDK for Unity sidebar_label: Get started -description: 'MetaMask Embedded Wallets SDK for Unity | Web3Auth Plug and Play for Unity' +description: 'Install and configure the MetaMask Embedded Wallet SDK for Unity.' --- import TabItem from '@theme/TabItem' @@ -9,15 +9,15 @@ import Tabs from '@theme/Tabs' ## Overview -MetaMask Embedded Wallets SDK (formerly Web3Auth Plug and Play) provides authentication for Unity game applications with social logins, external wallets, and more. Our Unity SDK, written in C#, simplifies how you connect users to their preferred wallets and manage authentication state across all mobile platforms. +The MetaMask Embedded Wallet SDK for Unity provides social and custom authentication for games +and other Unity applications. +The SDK supports Android, iOS, WebGL, macOS, and Windows. ## Requirements - Unity Editor 2019.4.9f1 or greater - .Net Framework 4.x -- iOS Platform Target Version 14 and above -- Android Target SDK Version 24 and above -- Basic knowledge of C# and Unity Development +- Basic knowledge of C# and Unity development ## Prerequisites @@ -31,11 +31,15 @@ See the [dashboard setup](../../dashboard/README.mdx) guide to learn more. ## Installation -Install the Web3Auth Unity SDK using one of the following methods: +Install the MetaMask Embedded Wallet SDK for Unity using the following method. ### Download Unity package -Download the [.unitypackage](https://github.com/Web3Auth/web3auth-unity-sdk/releases/latest) from our latest release and import the package file into your existing Unity3D project. +Download the +[latest `.unitypackage`](https://github.com/Web3Auth/web3auth-unity-sdk/releases/latest) and import +it into your Unity project. + +If you're upgrading from v7, follow the [Unity SDK v8 migration guide](../../migration-guides/unity.mdx). :::warning @@ -53,42 +57,44 @@ To fix this problem you need to add the following line into the dependencies obj ### Configure Web3Auth project -- From the [Embedded Wallets dashboard](https://developer.metamask.io/), create or select an Web3Auth project: -- Add `{{SCHEMA}}://{YOUR_APP_PACKAGE_NAME}/auth` to **Allowlist URLs**. -- Copy the `Client ID` for usage later. +1. Create or select an Embedded Wallets project in the + [MetaMask Developer dashboard](https://developer.metamask.io/). +2. Add `:///auth` to **Allowlist URLs**. +3. Copy your client ID. +4. In Unity, select **Window > Web3Auth > Generate Deep Link**, enter the same redirect URL, and + select **Generate**. ## Initialize Web3Auth -### 1. Create Web3Auth instance +### 1. Add the Web3Auth component -Attach a `Web3Auth.cs` script to your game object where you want to write your authentication code: +Add the SDK's `Web3Auth` component to a game object. +Create a separate script for your authentication logic and attach it to the same game object: -```cs title="/Assets/Web3Auth.cs" +```cs title="/Assets/AuthManager.cs" using System; -using System.Linq; using System.Collections.Generic; using UnityEngine; -using UnityEngine.UI; -using Newtonsoft.Json; -public class Web3Auth : MonoBehaviour +public class AuthManager : MonoBehaviour { - // Start is called before the first frame update - void Start() {} - public void login() {} - private void onLogin(Web3AuthResponse response) {} - public void logout() {} - private void onLogout() {} + private Web3Auth web3Auth; + + void Start() {} + public void login() {} + private void onLogin(Web3AuthResponse response) {} + public void logout() {} + private void onLogout() {} } ``` -Within your script, import the `Web3Auth` component in your class: +Declare a field for the SDK component: ```cs -Web3Auth web3Auth; +private Web3Auth web3Auth; ``` -Create an instance within your `Start()` function by creating an instance of the component you just imported: +Get the component in `Start()`: ```cs web3Auth = GetComponent(); @@ -100,9 +106,9 @@ After instantiation, within your `Start()` function, set up the Web3Auth Options ```cs web3Auth.setOptions(new Web3AuthOptions(){ - clientId = "YOUR_WEB3AUTH_CLIENT_ID", // Pass your Web3Auth Client ID, ideally using an environment variable // Get your Client ID from MetaMask Developer Dashboard - network = Web3Auth.Network.SAPPHIRE_MAINNET, // or Web3Auth.Network.SAPPHIRE_DEVNET - redirectUrl = new Uri("torusapp://com.torus.Web3AuthUnity/auth"), + clientId = "", + web3AuthNetwork = Web3Auth.Network.SAPPHIRE_MAINNET, + redirectUrl = new Uri(":///auth"), }); ``` @@ -116,9 +122,9 @@ void Start() web3Auth = GetComponent(); web3Auth.setOptions(new Web3AuthOptions() { - clientId = "YOUR_WEB3AUTH_CLIENT_ID", // Pass your Web3Auth Client ID, ideally using an environment variable - network = Web3Auth.Network.SAPPHIRE_MAINNET, - redirectUrl = new Uri("torusapp://com.torus.Web3AuthUnity/auth"), + clientId = "", + web3AuthNetwork = Web3Auth.Network.SAPPHIRE_MAINNET, + redirectUrl = new Uri(":///auth"), }); // Set up event handlers @@ -129,7 +135,7 @@ void Start() private void onLogin(Web3AuthResponse response) { Debug.Log("Login successful!"); - Debug.Log("Private Key: " + response.privKey); + var privateKey = response.privateKey; } private void onLogout() @@ -168,9 +174,9 @@ web3Auth = GetComponent(); //focus-start web3Auth.setOptions(new Web3AuthOptions(){ - clientId = "YOUR_WEB3AUTH_CLIENT_ID", // Pass your Web3Auth Client ID, ideally using an environment variable - network = Web3Auth.Network.SAPPHIRE_MAINNET, // or Web3Auth.Network.SAPPHIRE_DEVNET - redirectUrl = new Uri("torusapp://com.torus.Web3AuthUnity/auth"), + clientId = "", + web3AuthNetwork = Web3Auth.Network.SAPPHIRE_MAINNET, + redirectUrl = new Uri(":///auth"), }); //focus-end ``` @@ -182,40 +188,30 @@ web3Auth.setOptions(new Web3AuthOptions(){ ```cs web3Auth = GetComponent(); -var loginConfigItem = new LoginConfigItem() +var authConnection = new AuthConnectionConfig() { - verifier = "google-verifier", // Get this from the MetaMask Developer Dashboard - typeOfLogin = TypeOfLogin.GOOGLE, - clientId = "YOUR_GOOGLE_CLIENT_ID" // Google's client ID + authConnectionId = "", + authConnection = AuthConnection.GOOGLE, + clientId = "" }; //focus-start web3Auth.setOptions(new Web3AuthOptions(){ - clientId = "YOUR_WEB3AUTH_CLIENT_ID", // Pass your Web3Auth Client ID, ideally using an environment variable - network = Web3Auth.Network.SAPPHIRE_MAINNET, // or Web3Auth.Network.SAPPHIRE_DEVNET - redirectUrl = new Uri("torusapp://com.torus.Web3AuthUnity/auth"), - loginConfig = new Dictionary + clientId = "", + web3AuthNetwork = Web3Auth.Network.SAPPHIRE_MAINNET, + redirectUrl = new Uri(":///auth"), + authConnectionConfig = new List { - {"google", loginConfigItem} - } - mfaSettings = new MfaSettings() { - deviceShareFactor = new MfaSetting() { - enable = true, - priority = 1 - }, - backUpShareFactor = new MfaSetting() { - enable = true, - priority = 2 - }, - socialBackupFactor = new MfaSetting() { - enable = true, - priority = 3 - }, - passwordFactor = new MfaSetting() { - enable = true, - priority = 4 - } - } + authConnection + }, + mfaSettings = new MfaSettings( + new MfaSetting(true, 1, true), + new MfaSetting(true, 2, true), + new MfaSetting(true, 3, false), + new MfaSetting(true, 4, false), + null, + null + ) }); //focus-end ``` @@ -240,53 +236,33 @@ For Ethereum integration, you can get the private key and use it with Nethereum: ```cs using Nethereum.Web3; -using Nethereum.Util; -using Nethereum.Signer; -using Nethereum.Hex.HexConvertors.Extensions; -using Nethereum.ABI.Encoders; -using Nethereum.Hex.HexTypes; using Nethereum.Web3.Accounts; -using Nethereum.Web3.Accounts.Managed; public class Web3AuthScript : MonoBehaviour { - Web3 web3; - Web3Auth web3Auth; + private Web3 web3; + private Web3Auth web3Auth; private string privateKey; private Account account; - const string rpcURL = "" // EVM chain RPC URL + private const string rpcUrl = ""; void Start() { - - web3Auth = GetComponent(); - - // Add Web3Auth Unity SDK Initialisation Code here - - web3Auth.onLogin += onLogin; - web3Auth.onLogout += onLogout; - web3 = new Web3(rpcURL); + web3Auth = GetComponent(); + // Add the Embedded Wallet SDK initialization code here. + web3Auth.onLogin += onLogin; } - private void onLogin(Web3AuthResponse response) + private async void onLogin(Web3AuthResponse response) { //focus-start - // get the private key from web3auth response - privateKey = response.privKey; - // generate the user account - var account = new Account(privateKey); - // get the user address - address = account.Address; - - // create the web3 instance - web3 = new Web3("rpcURL"); - - // get the user balance - var balance = web3.Eth.GetBalance.SendRequestAsync(address).Result.Value; + privateKey = response.privateKey; + account = new Account(privateKey); + web3 = new Web3(account, rpcUrl); + var balance = await web3.Eth.GetBalance.SendRequestAsync(account.Address); //focus-end } -// ... } ``` @@ -297,8 +273,7 @@ For Solana integration, you can get the Ed25519 private key: ```cs private void onLogin(Web3AuthResponse response) { - var ed25519PrivKey = response.ed25519PrivKey; + var ed25519PrivateKey = response.ed25519PrivateKey; // Use Ed25519 private key with Solana libraries - Debug.Log("Solana Ed25519 Private Key: " + ed25519PrivKey); } ``` diff --git a/embedded-wallets/sdk/unity/advanced/README.mdx b/embedded-wallets/sdk/unity/advanced/README.mdx index c45b8e95feb..63e7eb77311 100644 --- a/embedded-wallets/sdk/unity/advanced/README.mdx +++ b/embedded-wallets/sdk/unity/advanced/README.mdx @@ -1,7 +1,7 @@ --- title: Advanced configuration sidebar_label: Overview -description: 'Web3Auth Unity SDK - Advanced Configuration | Embedded Wallets' +description: 'Configure advanced options for the MetaMask Embedded Wallet SDK for Unity.' --- import TabItem from '@theme/TabItem' @@ -11,23 +11,23 @@ The Embedded Wallets SDK provides extensive configuration options that allow you ## Configuration structure -When setting up Web3Auth, you'll pass in the options to the constructor. This consists of: +Pass a `Web3AuthOptions` instance to `setOptions` when you initialize the SDK: ```cs web3Auth = GetComponent(); // focus-start web3Auth.setOptions(new Web3AuthOptions(){ - clientId = "YOUR_WEB3AUTH_CLIENT_ID", // Pass your Web3Auth Client ID, ideally using an environment variable // Get your Client ID from MetaMask Developer Dashboard - network = Web3Auth.Network.SAPPHIRE_MAINNET, // or Web3Auth.Network.SAPPHIRE_DEVNET - redirectUrl = new Uri("torusapp://com.torus.Web3AuthUnity/auth"), + clientId = "", + web3AuthNetwork = Web3Auth.Network.SAPPHIRE_MAINNET, + redirectUrl = new Uri(":///auth"), }); // focus-end ``` ### `Web3AuthOptions` -The Web3Auth Constructor takes an object with `Web3AuthOptions` as input. +The `setOptions` method takes a `Web3AuthOptions` instance. -| 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 `Web3Auth.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 `LoginConfigItem` 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` | Client ID from the [MetaMask Developer dashboard](https://developer.metamask.io/). | +| `web3AuthNetwork` | Sapphire network. Use `SAPPHIRE_DEVNET` for testing and `SAPPHIRE_MAINNET` for production. | +| `redirectUrl` | URL that receives the authentication response. It must match the dashboard and deep-link settings. | +| `authConnectionConfig?` | Custom authentication connections as a `List`. | +| `whiteLabel?` | Branding and localization settings as `WhiteLabelData`. | +| `walletServicesConfig?` | Wallet Services confirmation and branding settings as `WalletServicesConfig`. | +| `defaultChainId?` | Initial Wallet Services chain ID. The default is `0x1`. | +| `mfaSettings?` | MFA factor settings as `MfaSettings`. | +| `sessionTime?` | Session duration in seconds. The default is 86,400 seconds. | +| `enableLogging?` | Whether SDK logging is enabled. The default is `false`. | @@ -57,12 +60,15 @@ The Web3Auth Constructor takes an object with `Web3AuthOptions` as input. public class Web3AuthOptions { public string clientId { get; set; } - public Web3Auth.Network network { get; set; } public Uri redirectUrl { get; set; } + public Web3Auth.Network web3AuthNetwork { get; set; } + public List authConnectionConfig { get; set; } public WhiteLabelData whiteLabel { get; set; } - public LoginConfigItem loginConfig { get; set; } + public WalletServicesConfig walletServicesConfig { get; set; } + public string defaultChainId { get; set; } = "0x1"; public MfaSettings mfaSettings { get; set; } public int sessionTime { get; set; } = 86400; + public bool enableLogging { get; set; } = false; } ``` @@ -75,17 +81,18 @@ Control how long users stay authenticated and how sessions persist in Unity. **Key Configuration Options:** -- `sessionTime` - Session duration in seconds. Controls how long users remain authenticated before needing to log in again. +- `sessionTime` - Session duration in seconds. Controls how long users remain authenticated before + they must sign in again. - Minimum: 1 second (`1`). - Maximum: 30 days (`86400 * 30`). - Default: 1 day (`86400`). ```cs web3Auth.setOptions(new Web3AuthOptions(){ - clientId = "YOUR_WEB3AUTH_CLIENT_ID", // Pass your Web3Auth Client ID, ideally using an environment variable - network = Web3Auth.Network.SAPPHIRE_MAINNET, + clientId = "", + web3AuthNetwork = Web3Auth.Network.SAPPHIRE_MAINNET, sessionTime = 86400 * 7, // 7 days (in seconds) - redirectUrl = new Uri("torusapp://com.torus.Web3AuthUnity/auth"), + redirectUrl = new Uri(":///auth"), }); ``` diff --git a/embedded-wallets/sdk/unity/advanced/custom-authentication.mdx b/embedded-wallets/sdk/unity/advanced/custom-authentication.mdx index 7f0ecd96f6e..49a353baf5c 100644 --- a/embedded-wallets/sdk/unity/advanced/custom-authentication.mdx +++ b/embedded-wallets/sdk/unity/advanced/custom-authentication.mdx @@ -1,7 +1,7 @@ --- -title: Using custom authentication in PnP Unity SDK +title: Use custom authentication in Unity sidebar_label: Custom authentication -description: 'Web3Auth PnP Unity SDK - Using Custom Authentication | Embedded Wallets' +description: 'Use custom authentication with the MetaMask Embedded Wallet SDK for Unity.' --- import TabItem from '@theme/TabItem' @@ -14,7 +14,7 @@ This feature, with MFA turned off, can make Embedded Wallets invisible to the en -## Get an Auth Connection ID +## Get an auth connection ID :::info prerequisite @@ -22,7 +22,9 @@ To enable this, you need to [create a connection](/embedded-wallets/dashboard/au ::: -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. +Configure the connection in the Embedded Wallets dashboard, then pass its +`authConnectionId` to the SDK. +You can configure multiple connections for the same project. :::tip @@ -32,118 +34,68 @@ Learn more about the [auth provider setup](/embedded-wallets/authentication) and ## Configuration -:::warning - -**"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. +Pass custom connection details to `authConnectionConfig` when you initialize the SDK. +The property accepts a `List`. ### Parameters -#### `LoginConfigItem` - -The `LoginConfigItem` struct contains various parameters that define the behavior of the custom authentication process. Below are the details of the `LoginConfigItem` struct: - -| Parameter | Description | -| ------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `verifier` | The name of the verifier that you have registered on the Embedded Wallets dashboard. It's a mandatory field, and accepts `string` as a value. | -| `typeOfLogin` | Type of login for this verifier. This value will affect the login flow. For example, if you choose `google`, a Google sign-in flow will be used. If you choose `jwt`, you should provide your own JWT token, and 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, such as Google's Client ID or Web3Auth's client ID if using `jwt` as `TypeOfLogin`. It's a mandatory field, and accepts `string` as a value. | -| `name?` | Display name for the verifier. If null, the default name is used. It accepts `string` as a value. | -| `description?` | Description for the button. If provided, it renders as a full-length button; otherwise, an icon button is shown. It accepts `string` as a value. | -| `verifierSubIdentifier?` | The field in the JWT token that maps to the verifier ID. Ensure you selected the correct JWT verifier ID in the developer dashboard. It accepts `string` as a value. | -| `logoHover?` | Logo to be shown on mouse hover. It accepts `string` as a value. | -| `logoLight?` | Light logo for dark backgrounds. It accepts `string` as a value. | -| `logoDark?` | Dark logo for light backgrounds. It accepts `string` as a value. | -| `mainOption?` | shows the login button on the main list. It accepts `bool` as a value. The default value is `false`. | -| `showOnModal?` | Whether to show the login button on the modal. The default value is `true`. | -| `showOnDesktop?` | Whether to show the login button on the desktop. The default value is `true`. | -| `showOnMobile?` | Whether to show the login button on mobile. The default value is `true`. | - -#### `TypeOfLogin` - -```csharp -public enum TypeOfLogin -{ - [EnumMember(Value = "google")] - GOOGLE, - [EnumMember(Value = "facebook")] - FACEBOOK, - [EnumMember(Value = "reddit")] - REDDIT, - [EnumMember(Value = "discord")] - DISCORD, - [EnumMember(Value = "twitch")] - TWITCH, - [EnumMember(Value = "apple")] - APPLE, - [EnumMember(Value = "line")] - LINE, - [EnumMember(Value = "github")] - GITHUB, - [EnumMember(Value = "kakao")] - KAKAO, - [EnumMember(Value = "linkedin")] - LINKEDIN, - [EnumMember(Value = "twitter")] - TWITTER, - [EnumMember(Value = "weibo")] - WEIBO, - [EnumMember(Value = "wechat")] - WECHAT, - [EnumMember(Value = "email_passwordless")] - EMAIL_PASSWORDLESS, - [EnumMember(Value = "email_password")] - EMAIL_PASSWORD, - [EnumMember(Value = "jwt")] - JWT -} -``` +#### `AuthConnectionConfig` + +| Parameter | Description | +| -------------------------- | --------------------------------------------------------------------- | +| `authConnectionId` | Connection ID from the Embedded Wallets dashboard. | +| `authConnection` | Authentication method as an `AuthConnection` value. | +| `clientId?` | OAuth client ID for the identity provider. | +| `groupedAuthConnectionId?` | Grouped connection ID when several methods must produce the same key. | +| `name?` | Display name for the connection. | +| `description?` | Description displayed with the connection. | +| `logoHover?` | Logo shown on hover. | +| `logoLight?` | Logo shown on dark backgrounds. | +| `logoDark?` | Logo shown on light backgrounds. | +| `mainOption?` | Whether to show the connection as a primary option. | +| `showOnModal?` | Whether to show the connection in the modal. | +| `showOnDesktop?` | Whether to show the connection on desktop. | +| `showOnMobile?` | Whether to show the connection on mobile. | +| `extraLoginOptions?` | Provider-specific options as `ExtraLoginOptions`. | #### `extraLoginOptions` The `extraLoginOptions` parameter can be used to pass additional options required by specific login providers. -| Parameter | Description | -| ---------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `domain?` | Your custom authentication domain in `string` format. For example, if you are using Auth0, it can be `example.auth0.com`. | -| `client_id?` | Client ID in `string` format, provided by your login provider and used for the custom verifier. | -| `verifierIdField?` | The field in JWT token which maps to verifier ID. Ensure you select the correct JWT verifier ID in the developer dashboard. It takes a `string` as a value. | -| `isVerifierIdCaseSensitive?` | Boolean to confirm whether the verifier ID field is case-sensitive or not. | -| `prompt?` | Prompt shown to the user during the authentication process. 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. Accepts a string value. | +| Parameter | Description | +| ------------------------ | ------------------------------------------------------------------------------------------------------------------------- | +| `domain?` | Your custom authentication domain in `string` format. For example, if you are using Auth0, it can be `example.auth0.com`. | +| `client_id?` | Client ID in `string` format, provided by your login provider and used for the custom verifier. | +| `userIdField?` | Field in the JWT that maps to the user ID configured in the dashboard. | +| `isUserIdCaseSensitive?` | Whether the user ID field is case-sensitive. | +| `prompt?` | Prompt shown to the user during the authentication process. 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. Accepts a string value. | -## Single verifier +## Single connection -To use custom authentication with a single verifier, configure the `loginConfig` parameter of the `Web3AuthOptions` class. The `loginConfig` parameter is a key-value map where the key should be one of the `Web3AuthProvider` in its string form, and the value should be a `LoginConfigItem` struct instance. +Configure `authConnectionConfig` with the connection ID and authentication method. ```csharp void Start() { web3Auth = GetComponent(); - var loginConfigItem = new LoginConfigItem() + var authConnectionConfig = new AuthConnectionConfig() { - verifier = "google-verifier", // Get this from the MetaMask Developer Dashboard - typeOfLogin = TypeOfLogin.GOOGLE, - clientId = "YOUR_GOOGLE_CLIENT_ID" // Google's client ID + authConnectionId = "", + authConnection = AuthConnection.GOOGLE, + clientId = "" }; web3Auth.setOptions(new Web3AuthOptions() { - redirectUrl = new Uri("torusapp://com.torus.Web3AuthUnity/auth"), - clientId = "YOUR_WEB3AUTH_CLIENT_ID", // Pass your Web3Auth Client ID, ideally using an environment variable // Web3Auth's client ID - network = Web3Auth.Network.TESTNET, // or other networks - loginConfig = new Dictionary + redirectUrl = new Uri(":///auth"), + clientId = "", + web3AuthNetwork = Web3Auth.Network.SAPPHIRE_DEVNET, + authConnectionConfig = new List { - {"google", loginConfigItem} + authConnectionConfig } }); } @@ -156,11 +108,10 @@ void Start() ```csharp public void loginGoogle() { - var selectedProvider = Provider.GOOGLE; - var options = new LoginParams() { - loginProvider = selectedProvider, + authConnection = AuthConnection.GOOGLE, + authConnectionId = "" }; web3Auth.login(options); @@ -174,16 +125,14 @@ To use JWT login (for example, Auth0): ```csharp public void loginJWT() { - var selectedProvider = Provider.JWT; - var options = new LoginParams() { - loginProvider = selectedProvider, + authConnection = AuthConnection.CUSTOM, + authConnectionId = "", extraLoginOptions = new ExtraLoginOptions() { - domain = "https://example.auth0.com", // Auth0 domain - verifierIdField = "sub", // The field in JWT token mapping to verifier ID - id_token = "YOUR_JWT_ID_TOKEN" // JWT ID token + id_token = "", + userIdField = "sub" } }; @@ -191,42 +140,42 @@ public void loginJWT() } ``` -## Aggregate verifier - -You can use an aggregate verifier to combine multiple login methods, allowing users to log in using different providers but receive the same address. +## Grouped connection -To use aggregate verifiers, set up the `loginConfig` object with multiple providers under a single verifier. +Use a grouped connection to let users sign in with different methods and receive the same wallet +address. +Configure each item with its own `authConnectionId` and the same `groupedAuthConnectionId`. ```csharp void Start() { web3Auth = GetComponent(); - var googleConfig = new LoginConfigItem() + var googleConfig = new AuthConnectionConfig() { - verifier = "aggregate-sapphire", - verifierSubIdentifier = "google-sub-id", - clientId = "YOUR_GOOGLE_CLIENT_ID", - typeOfLogin = TypeOfLogin.GOOGLE, + authConnectionId = "", + groupedAuthConnectionId = "", + clientId = "", + authConnection = AuthConnection.GOOGLE, }; - var auth0GitHubConfig = new LoginConfigItem() + var auth0GitHubConfig = new AuthConnectionConfig() { - verifier = "aggregate-sapphire", - verifierSubIdentifier = "github-sub-id", - clientId = "YOUR_GITHUB_CLIENT_ID", - typeOfLogin = TypeOfLogin.JWT, + authConnectionId = "", + groupedAuthConnectionId = "", + clientId = "", + authConnection = AuthConnection.CUSTOM, }; web3Auth.setOptions(new Web3AuthOptions() { - clientId = "YOUR_WEB3AUTH_CLIENT_ID", // Pass your Web3Auth Client ID, ideally using an environment variable - redirectUrl = new System.Uri("w3aexample://com.web3auth.unityaggregateexample"), - network = Web3Auth.Network.SAPPHIRE_MAINNET, - loginConfig = new Dictionary + clientId = "", + redirectUrl = new Uri(":///auth"), + web3AuthNetwork = Web3Auth.Network.SAPPHIRE_MAINNET, + authConnectionConfig = new List { - {"google", googleConfig}, - {"github", auth0GitHubConfig} + googleConfig, + auth0GitHubConfig } }); } @@ -239,11 +188,11 @@ void Start() ```csharp public void loginGoogle() { - var selectedProvider = Provider.GOOGLE; - var options = new LoginParams() { - loginProvider = selectedProvider, + authConnection = AuthConnection.GOOGLE, + authConnectionId = "", + groupedAuthConnectionId = "" }; web3Auth.login(options); @@ -251,16 +200,16 @@ public void loginGoogle() public void loginGitHub() { - var selectedProvider = Provider.GITHUB; - var options = new LoginParams() { - loginProvider = selectedProvider, + authConnection = AuthConnection.CUSTOM, + authConnectionId = "", + groupedAuthConnectionId = "", extraLoginOptions = new ExtraLoginOptions() { - domain = "https://example.auth0.com", - verifierIdField = "email", - isVerifierIdCaseSensitive = false, + id_token = "", + userIdField = "email", + isUserIdCaseSensitive = false, prompt = Prompt.LOGIN, } }; diff --git a/embedded-wallets/sdk/unity/advanced/dapp-share.mdx b/embedded-wallets/sdk/unity/advanced/dapp-share.mdx index 993e911846e..0924da3bab3 100644 --- a/embedded-wallets/sdk/unity/advanced/dapp-share.mdx +++ b/embedded-wallets/sdk/unity/advanced/dapp-share.mdx @@ -1,7 +1,7 @@ --- -title: Using dapp share in PnP Unity SDK +title: Use a dapp share in Unity sidebar_label: Dapp share -description: 'Web3Auth PnP Unity SDK - dapp share | Embedded Wallets' +description: 'Use a dapp share with the MetaMask Embedded Wallet SDK for Unity.' --- ## Embedded Wallets infrastructure at a glance @@ -37,18 +37,18 @@ After a successful login from a user, the user details are returned as a respons "sessionId": "....", "error": "....", "userInfo": { - "aggregateVerifier": "w3a-google", + "groupedAuthConnectionId": "grouped-google", + "authConnectionId": "google", + "authConnection": "google", + "userId": "john@gmail.com", "email": "john@gmail.com", "name": "John Dash", "profileImage": "https://lh3.googleusercontent.com/a/Ajjjsdsmdjmnm...", - "typeOfLogin": "google", - "verifier": "torus", - "verifierId": "john@gmail.com", - "dappShare": "<24 words seed phrase>", // will be sent only incase of custom verifiers + "dappShare": "", "idToken": "", - "oAuthIdToken": "", // will be sent only incase of custom verifiers - "oAuthAccessToken": "", // will be sent only incase of custom verifiers - "isMfaEnabled": true // returns true if user has enabled mfa + "oAuthIdToken": "", + "oAuthAccessToken": "", + "isMfaEnabled": true } } ``` @@ -68,11 +68,11 @@ One major thing to note here is that the `dappShare` is only available for custo ```cs public void login() { - var selectedProvider = Provider.GOOGLE; var options = new LoginParams() { - loginProvider = selectedProvider, - dappShare = "enter your dapp share" + authConnection = AuthConnection.GOOGLE, + authConnectionId = "", + dappShare = "" }; web3Auth.login(options); } diff --git a/embedded-wallets/sdk/unity/advanced/mfa.mdx b/embedded-wallets/sdk/unity/advanced/mfa.mdx index 27268924519..0b8e45942aa 100644 --- a/embedded-wallets/sdk/unity/advanced/mfa.mdx +++ b/embedded-wallets/sdk/unity/advanced/mfa.mdx @@ -1,7 +1,7 @@ --- -title: Multi-factor authentication in PnP Unity SDK +title: Multi-factor authentication in Unity sidebar_label: Multi-factor authentication -description: 'Web3Auth PnP Unity SDK - Multi Factor Authentication | Embedded Wallets' +description: 'Configure MFA with the MetaMask Embedded Wallet SDK for Unity.' --- import TabItem from '@theme/TabItem' @@ -57,10 +57,10 @@ public enum MFALevel ```cs title="Usage" public void login() { - var selectedProvider = Provider.GOOGLE; + var authConnection = AuthConnection.GOOGLE; var options = new LoginParams() { - loginProvider = selectedProvider, + authConnection = authConnection, mfaLevel = MFALevel.MANDATORY }; web3Auth.login(options); @@ -71,7 +71,8 @@ public void login() :::note -This is a paid feature and the minimum [pricing plan](https://web3auth.io/pricing.html) to use this SDK in a production environment is the **SCALE Plan**. You can use this feature at no cost on `sapphire_devnet`. +You can use MFA on Sapphire Devnet at no cost. +See [MetaMask Developer pricing](https://metamask.io/developer/pricing) for production access. ::: @@ -87,11 +88,11 @@ This is a paid feature and the minimum [pricing plan](https://web3auth.io/pricin -| Parameter | Description | -| ------------ | ------------------------------------------------------------------------------- | -| `enable` | Enable/Disable MFA. It accepts `bool` as a value. | -| `priority?` | Priority of MFA. It accepts `int` as a value, where valid range is from 1 to 4. | -| `mandatory?` | Mandatory/Optional MFA. It acccepts `bool` as a value. | +| Parameter | Description | +| ------------ | ---------------------------------------------------------------- | +| `enable` | Enable/Disable MFA. It accepts `bool` as a value. | +| `priority?` | Order in which the SDK presents the factor. It accepts an `int`. | +| `mandatory?` | Mandatory/Optional MFA. It acccepts `bool` as a value. | @@ -135,8 +136,8 @@ public class Web3custom : MonoBehaviour web3Auth.setOptions(new Web3AuthOptions() { redirectUrl = new Uri("torusapp://com.torus.Web3AuthUnity/auth"), - clientId = "BAwFgL-r7wzQKmtcdiz2uHJKNZdK7gzEf2q-m55xfzSZOw8jLOyIi4AVvvzaEQO5nv2dFLEmf9LBkF8kaq3aErg", - network = Web3Auth.Network.TESTNET, + clientId = "", + web3AuthNetwork = Web3Auth.Network.SAPPHIRE_DEVNET, mfaSettings = new MfaSettings( new MfaSetting(true, 1, true), new MfaSetting(true, 1, true), @@ -160,7 +161,7 @@ public class Web3custom : MonoBehaviour :::note Note - At least two factors are mandatory when setting up the mfaSettings. -- If you set `mandatory: true` for all factors, the user must set up all four factors. +- If you set `mandatory: true` for every enabled factor, the user must set up every enabled factor. - If you set `mandatory: false` for all factors, the user can skip setting up MFA. But at least two factors are mandatory. - If you set `mandatory: true` for some factors and `mandatory: false` for others, the user must set up the mandatory factors and can skip the optional factors. But, the user must set up at least two factors. - The `priority` field is used to set the order of the factors. The factor with the lowest priority will be the first factor to be set up. The factor with the highest priority will be the last factor to be set up. diff --git a/embedded-wallets/sdk/unity/advanced/whitelabel.mdx b/embedded-wallets/sdk/unity/advanced/whitelabel.mdx index ef24854782c..a2ca85a6eb4 100644 --- a/embedded-wallets/sdk/unity/advanced/whitelabel.mdx +++ b/embedded-wallets/sdk/unity/advanced/whitelabel.mdx @@ -1,7 +1,7 @@ --- -title: Whitelabel PnP Unity SDK +title: Customize the Unity SDK UI sidebar_label: Whitelabel -description: 'Web3Auth PnP Unity SDK - Whitelabel | Embedded Wallets' +description: 'Customize the MetaMask Embedded Wallet SDK for Unity UI.' --- import TabItem from '@theme/TabItem' @@ -78,15 +78,15 @@ void Start() web3Auth.setOptions(new Web3AuthOptions() { redirectUrl = new Uri("torusapp://com.torus.Web3AuthUnity/auth"), - clientId = "BAwFgL-r7wzQKmtcdiz2uHJKNZdK7gzEf2q-m55xfzSZOw8jLOyIi4AVvvzaEQO5nv2dFLEmf9LBkF8kaq3aErg", - network = Web3Auth.Network.TESTNET, + clientId = "", + web3AuthNetwork = Web3Auth.Network.SAPPHIRE_DEVNET, // focus-start whiteLabel = new WhiteLabelData() { appName = "Web3Auth Sample App", logoLight = null, logoDark = null, - defaultLanguage = "en", - mode = "dark", + defaultLanguage = Web3Auth.Language.en, + mode = Web3Auth.ThemeModes.dark, theme = new Dictionary < string, string > { { "primary", diff --git a/embedded-wallets/sdk/unity/examples.mdx b/embedded-wallets/sdk/unity/examples.mdx index fe29d45e289..6de9be54489 100644 --- a/embedded-wallets/sdk/unity/examples.mdx +++ b/embedded-wallets/sdk/unity/examples.mdx @@ -1,7 +1,7 @@ --- -title: Examples - PnP Unity SDK +title: Unity examples sidebar_label: Examples -description: 'PnP Unity Examples | Embedded Wallets' +description: 'Explore examples for the MetaMask Embedded Wallet SDK for Unity.' hide_table_of_contents: true --- diff --git a/embedded-wallets/sdk/unity/usage/README.mdx b/embedded-wallets/sdk/unity/usage/README.mdx index c4449a1fc2d..4c23dfbdb64 100644 --- a/embedded-wallets/sdk/unity/usage/README.mdx +++ b/embedded-wallets/sdk/unity/usage/README.mdx @@ -1,10 +1,11 @@ --- -title: Using Unity SDK +title: Use the Unity SDK sidebar_label: Overview -description: 'Web3Auth Unity SDK Functions | Embedded Wallets' +description: 'Use authentication, key, MFA, and Wallet Services methods in the Unity SDK.' --- -Embedded Wallets provides a comprehensive set of functions to handle authentication, user management, and blockchain interactions in your Unity applications. These functions allow you to implement features like user login, multi-factor authentication, 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 Unity projects. +Use the Unity SDK methods to sign users in and out, retrieve account data, configure +multi-factor authentication (MFA), and open Wallet Services. ## List of functions @@ -16,10 +17,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 | +| -------------------------- | -------------------------------------------------------------- | +| [`login()`](./login.mdx) | Signs the user in with the selected authentication connection. | +| [`logout()`](./logout.mdx) | Signs the user out of the current session. | ### User management functions @@ -29,20 +30,21 @@ 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 compatible chains. | ### Security functions -| Function Name | Description | -| --------------------------------- | ------------------------------------------------- | -| [`enableMFA()`](./enable-mfa.mdx) | Enables Multi-Factor Authentication for the user. | +| Function name | Description | +| --------------------------------- | ------------------------------------- | +| [`enableMFA()`](./enable-mfa.mdx) | Enables MFA for the user. | +| [`manageMFA()`](./manage-mfa.mdx) | Opens the user's MFA management flow. | ### 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 transactions. | +| Function Name | Description | +| ------------------------------------------------ | ------------------------------------------------------------- | +| [`showWalletUI()`](./launch-wallet-services.mdx) | Opens the Wallet Services UI in a web view. | +| [`request()`](./request.mdx) | Opens templated transaction screens for signing transactions. | diff --git a/embedded-wallets/sdk/unity/usage/enable-mfa.mdx b/embedded-wallets/sdk/unity/usage/enable-mfa.mdx index c3945ba11c4..46ae0b50f8f 100644 --- a/embedded-wallets/sdk/unity/usage/enable-mfa.mdx +++ b/embedded-wallets/sdk/unity/usage/enable-mfa.mdx @@ -1,13 +1,15 @@ --- title: Enable MFA sidebar_label: Enable MFA -description: 'Web3Auth Unity SDK - enableMFA | Embedded Wallets' +description: 'Enable MFA with the MetaMask Embedded Wallet SDK for Unity.' --- 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. +Call `enableMFA` with the user's `LoginParams` to start the multi-factor authentication (MFA) +setup flow. +For custom authentication, include the connection ID and identity token. :::tip @@ -47,12 +49,11 @@ private void onMFASetup(bool response) ```cs +public void enableMFA() { - var selectedProvider = Provider.GOOGLE; - var options = new LoginParams() { - loginProvider = selectedProvider, + authConnection = AuthConnection.GOOGLE }; web3Auth.enableMFA(options); @@ -64,16 +65,16 @@ private void onMFASetup(bool response) ```cs +public void enableMFA() { - var selectedProvider = Provider.JWT; - var options = new LoginParams() { - loginProvider = selectedProvider, + authConnection = AuthConnection.CUSTOM, + authConnectionId = "", extraLoginOptions = new ExtraLoginOptions() { - domain = "https://web3auth.au.auth0.com", - verifierIdField = "sub", + id_token = "", + userIdField = "sub", prompt = Prompt.LOGIN, } }; diff --git a/embedded-wallets/sdk/unity/usage/get-ed25519-private-key.mdx b/embedded-wallets/sdk/unity/usage/get-ed25519-private-key.mdx index 0570db92e0c..abfaad6b6ba 100644 --- a/embedded-wallets/sdk/unity/usage/get-ed25519-private-key.mdx +++ b/embedded-wallets/sdk/unity/usage/get-ed25519-private-key.mdx @@ -1,19 +1,27 @@ --- title: Get Ed25519 private key sidebar_label: Get Ed25519 private key -description: 'Web3Auth Unity SDK - getEd25519PrivKey | Embedded Wallets' +description: 'Get an Ed25519 private key with the MetaMask Embedded Wallet SDK for Unity.' --- -To retrieve the Ed25519 private key of the user, you can access it from the login response. This private key can be used to sign transactions on Solana, Near, Algorand, and other chains that use the ed25519 curve. +After a user signs in, retrieve their Ed25519 private key from the sign-in response or by calling +`getEd25519PrivateKey()`. +Use this key with a compatible library to sign transactions on chains that use Ed25519. +Never log or persist an unencrypted private key. ## Usage ```cs private void onLogin(Web3AuthResponse response) { - var ed25519PrivKey = response.ed25519PrivKey; - Debug.Log("Ed25519 Private Key: " + ed25519PrivKey); + var ed25519PrivateKey = response.ed25519PrivateKey; - // Use Ed25519 private key for Solana, Near, Algorand transactions + // Use the Ed25519 private key with a compatible blockchain library } ``` + +You can also retrieve the key from the active session: + +```cs +var ed25519PrivateKey = web3Auth.getEd25519PrivateKey(); +``` diff --git a/embedded-wallets/sdk/unity/usage/get-private-key.mdx b/embedded-wallets/sdk/unity/usage/get-private-key.mdx index b3eac29a655..dd1e842400b 100644 --- a/embedded-wallets/sdk/unity/usage/get-private-key.mdx +++ b/embedded-wallets/sdk/unity/usage/get-private-key.mdx @@ -1,19 +1,27 @@ --- -title: Get Secp256k1 private key -sidebar_label: Get Secp256k1 private key -description: 'Web3Auth Unity SDK - getPrivKey | Embedded Wallets' +title: Get secp256k1 private key +sidebar_label: Get secp256k1 private key +description: 'Get a secp256k1 private key with the MetaMask Embedded Wallet SDK for Unity.' --- -To retrieve the secp256k1 private key of the user, you can access it from the login response. The method returns an EVM compatible private key which can be used to sign transactions on EVM compatible chains. +After a user signs in, retrieve their secp256k1 private key from the sign-in response or by calling +`getPrivateKey()`. +Use this key with a Unity-compatible library to sign transactions on EVM-compatible chains. +Never log or persist an unencrypted private key. ## Usage ```cs private void onLogin(Web3AuthResponse response) { - var privateKey = response.privKey; - Debug.Log("Secp256k1 Private Key: " + privateKey); + var privateKey = response.privateKey; // Use private key for EVM transactions } ``` + +You can also retrieve the key from the active session: + +```cs +var privateKey = web3Auth.getPrivateKey(); +``` diff --git a/embedded-wallets/sdk/unity/usage/get-user-info.mdx b/embedded-wallets/sdk/unity/usage/get-user-info.mdx index dbc39b54507..34276f77d07 100644 --- a/embedded-wallets/sdk/unity/usage/get-user-info.mdx +++ b/embedded-wallets/sdk/unity/usage/get-user-info.mdx @@ -1,7 +1,7 @@ --- title: Get user info sidebar_label: Get user info -description: 'Web3Auth Unity SDK - getUserInfo | Embedded Wallets' +description: 'Get user information with the MetaMask Embedded Wallet SDK for Unity.' --- 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. @@ -9,28 +9,36 @@ You can use the `getUserInfo` method to retrieve various details about the user, ## Usage ```cs +using Newtonsoft.Json; + private void onLogin(Web3AuthResponse response) { var userInfo = response.userInfo; - Debug.Log("User Info: " + JsonUtility.ToJson(userInfo)); + Debug.Log("User Info: " + JsonConvert.SerializeObject(userInfo)); } ``` +You can also retrieve the user information from the active session: + +```cs +var userInfo = web3Auth.getUserInfo(); +``` + ## UserInfo response ```json { - "aggregateVerifier": "w3a-google", + "groupedAuthConnectionId": "grouped-google", + "authConnectionId": "google", + "authConnection": "google", + "userId": "john@gmail.com", "email": "john@gmail.com", "name": "John Dash", "profileImage": "https://lh3.googleusercontent.com/a/Ajjjsdsmdjmnm...", - "typeOfLogin": "google", - "verifier": "torus", - "verifierId": "john@gmail.com", - "dappShare": "<24 words seed phrase>", // will be sent only incase of custom verifiers + "dappShare": "", "idToken": "", - "oAuthIdToken": "", // will be sent only incase of custom verifiers - "oAuthAccessToken": "", // will be sent only incase of custom verifiers - "isMfaEnabled": true // returns true if user has enabled mfa + "oAuthIdToken": "", + "oAuthAccessToken": "", + "isMfaEnabled": true } ``` diff --git a/embedded-wallets/sdk/unity/usage/launch-wallet-services.mdx b/embedded-wallets/sdk/unity/usage/launch-wallet-services.mdx index 4155d0e557b..c5b1489858e 100644 --- a/embedded-wallets/sdk/unity/usage/launch-wallet-services.mdx +++ b/embedded-wallets/sdk/unity/usage/launch-wallet-services.mdx @@ -1,80 +1,24 @@ --- -title: Launch Wallet Services +title: Show wallet UI sidebar_label: Show wallet UI -description: 'Web3Auth Unity SDK - launchWalletServices | Embedded Wallets' +description: 'Show Wallet Services with the MetaMask Embedded Wallet SDK for Unity.' --- -import TabItem from '@theme/TabItem' -import Tabs from '@theme/Tabs' - -The `launchWalletServices` method launches a WebView which allows you to use the templated wallet UI services. The method takes `ChainConfig` as the required input. Wallet Services is currently only available for EVM chains. +The `showWalletUI` method opens Wallet Services in a web view. +Wallet Services is available for EVM chains. :::note -Access to Wallet Services is gated. You can use this feature in `sapphire_devnet` for free. The minimum [pricing plan](https://web3auth.io/pricing.html) to use this feature in a production environment is the **Scale Plan**. +You can use Wallet Services on Sapphire Devnet at no cost. +See [MetaMask Developer pricing](https://metamask.io/developer/pricing) for production access. ::: -## Parameters - -`ChainConfig` - - - - - -| Parameter | Description | -| ------------------- | --------------------------------------------------------------------------------------------------------------------------- | -| `chainNamespace` | Custom configuration for your preferred blockchain. As of now only EVM supported. Default value is `ChainNamespace.eip155`. | -| `decimals?` | Number of decimals for the currency ticker. Default value is 18, and accepts `int` as value. | -| `blockExplorerUrl?` | Blockchain's explorer URL. (for example, `https://etherscan.io`) | -| `chainId` | The chain ID of the selected blockchain in hex `String`. | -| `displayName?` | Display Name for the chain. | -| `logo?` | Logo for the selected `chainNamespace` and `chainId`. | -| `rpcTarget` | RPC Target URL for the selected `chainNamespace` & `chainId`. | -| `ticker?` | Default currency ticker of the network (for example, `ETH`) | -| `tickerName?` | Name for currency ticker (for example, `Ethereum`) | - - - - - -```cs -using System.Collections.Generic; -#nullable enable -public class ChainConfig { - public Web3Auth.ChainNamespace? chainNamespace { get; set; } = Web3Auth.ChainNamespace.EIP155; - public int decimals { get; set; } = 18; - public string blockExplorerUrl { get; set; } = null; - public string chainId { get; set; } - public string displayName { get; set; } = null; - public string logo { get; set; } = null; - public string rpcTarget { get; set; } - public string ticker { get; set; } = null; - public string tickerName { get; set; } = null; -} -``` - - - +Configure Wallet Services and the supported chains in your Embedded Wallets dashboard. +You can set `defaultChainId` in `Web3AuthOptions` to select the initial chain. ## Usage ```cs -{ - var chainConfig = new ChainConfig() - { - chainId = "0x1", - rpcTarget = rpcURL, - ticker = "ETH", - chainNamespace = Web3Auth.ChainNamespace.EIP155 - }; - web3Auth.launchWalletServices(chainConfig); -} +web3Auth.showWalletUI(); ``` diff --git a/embedded-wallets/sdk/unity/usage/login.mdx b/embedded-wallets/sdk/unity/usage/login.mdx index e6cde2a4509..d4209f5d22b 100644 --- a/embedded-wallets/sdk/unity/usage/login.mdx +++ b/embedded-wallets/sdk/unity/usage/login.mdx @@ -1,13 +1,13 @@ --- -title: Login user +title: Sign in a user sidebar_label: Sign in a user -description: 'Web3Auth Unity SDK - login | Embedded Wallets' +description: 'Sign in a user with the MetaMask Embedded Wallet SDK for Unity.' --- import TabItem from '@theme/TabItem' import Tabs from '@theme/Tabs' -This function helps your users to trigger the login process. The login flow is triggered based on the selected Provider. +Call `login` with `LoginParams` to start the sign-in flow for an authentication connection. :::tip @@ -50,16 +50,17 @@ private void onLogin(Web3AuthResponse response) -| Parameter | Description | -| -------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `loginProvider` | 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`, `WEIBO`, `WECHAT`, `EMAIL_PASSWORDLESS`. | -| `extraLoginOptions?` | It can be used to set the OAuth login options for corresponding `loginProvider`. For instance, you'll need to pass the user's email address as. The 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`, and accepts `URI` as a value. | -| `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 accepts `string` as a 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 after a 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 `string` as a value. | -| `curve?` | It is used to determine the public key encoded in the JWT token which returned in `getUserInfo` function after user login. This parameter won't change the format of private key returned by Web3Auth. Private key returned by `getPrivKey` is always secp256k1. The default value is `Curve.SECP256K1`. | -| `sessionTime?` | Allows developers to configure the session management time. Session Time is in seconds, and takes an `int` as a value. | +| Parameter | Description | +| -------------------------- | ---------------------------------------------------------------------------------------------- | +| `authConnection` | Authentication method, such as `AuthConnection.GOOGLE` or `AuthConnection.EMAIL_PASSWORDLESS`. | +| `authConnectionId?` | ID of a custom authentication connection configured in the Embedded Wallets dashboard. | +| `groupedAuthConnectionId?` | ID of a grouped authentication connection configured in the dashboard. | +| `extraLoginOptions?` | Provider-specific options, such as an email address or custom identity provider token. | +| `appState?` | State to preserve through the browser redirect. | +| `mfaLevel?` | Controls when the multi-factor authentication (MFA) setup screen appears. | +| `dappShare?` | Existing dapp share for a custom authentication connection. | +| `curve?` | Curve used for key generation. The default is `Curve.SECP256K1`. | +| `loginHint?` | Optional hint that identifies the user to the authentication provider. | @@ -68,14 +69,16 @@ private void onLogin(Web3AuthResponse response) ```cs public class LoginParams { - public Provider loginProvider { get; set; } - public string dappShare { get; set; } - public ExtraLoginOptions extraLoginOptions { get; set; } - public Uri redirectUrl { get; set; } + public AuthConnection authConnection { get; set; } + public string authConnectionId { get; set; } + public string groupedAuthConnectionId { get; set; } public string appState { get; set; } public MFALevel mfaLevel { get; set; } - public int sessionTime { get; set; } - public Curve curve { get; set; } + public ExtraLoginOptions extraLoginOptions { get; set; } + public string dappShare { get; set; } + public Curve curve { get; set; } = Curve.SECP256K1; + public string dappUrl { get; set; } + public string loginHint { get; set; } } ``` @@ -83,10 +86,10 @@ public class LoginParams -### `Provider` +### `AuthConnection` ```cs -public enum Provider +public enum AuthConnection { [EnumMember(Value = "google")] GOOGLE, @@ -118,20 +121,21 @@ public enum Provider EMAIL_PASSWORDLESS, [EnumMember(Value = "email_password")] EMAIL_PASSWORD, - [EnumMember(Value = "jwt")] - JWT, + [EnumMember(Value = "custom")] + CUSTOM, [EnumMember(Value = "CUSTOM_VERIFIER")] - CUSTOM_VERIFIER + CUSTOM_VERIFIER, + [EnumMember(Value = "sms_passwordless")] + SMS_PASSWORDLESS, + [EnumMember(Value = "farcaster")] + FARCASTER } ``` ### `ExtraLoginOptions` -The `LoginParams` class accepts the `ExtraLoginOptions` as an optional input, containing advanced options for custom authentication, email passwordless login, among others. This parameter can be considered as advanced login options needed for specific cases. - -```cs -LoginParams() { selectedLoginProvider, extraLoginOptions = ExtraLoginOptions() } -``` +Use `extraLoginOptions` for provider-specific values, including email hints and custom +authentication tokens. -| Parameter | Description | -| ---------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `additionalParams?` | Additional params in `Dictionary` format for OAuth login, use id_token (JWT) to authenticate with Embedded Wallets. | -| `domain?` | Your custom authentication domain in `string` format. For example, if you are using Auth0, this could 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 be no more than 60 seconds, with a maximum of 120 seconds. String value. | -| `verifierIdField?` | The field in the JWT token that maps to verifier ID. Please make sure you have selected the correct JWT verifier ID in the Developer Dashboard. String value. | -| `isVerifierIdCaseSensitive?` | Boolean to confirm whether the verifier ID field is case sensitive or not. | -| `display?` | Allows developers to configure the display of UI. It takes `Display` as a value. | -| `prompt?` | Prompt shown to the user during the authentication process. It takes `Prompt` as a value. | -| `max_age?` | Maximum time allowed without reauthentication. If the last time the user authenticated is greater than this value, then the user must reauthenticate. String value. | -| `ui_locales?` | The space separated list of language tags, ordered by preference. For example `fr-CA fr en`. | -| `id_token_hint?` | It specify the previously issued ID token. 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. String value. | -| `acr_values?` | acr_values | -| `scope?` | The default scope to be used on authentication requests. The default scope defined in the Auth0Client is included along with this scope. String value. | -| `audience?` | The audience, presented as the aud claim in the access token, defines the intended consumer of the token. 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. String value. | -| `state?` | State | -| `response_type?` | Defines which grant to be execute for the authorization server. String value. | -| `nonce?` | Nonce value | -| `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. | +| Parameter | Description | +| ------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `additionalParams?` | Additional params in `Dictionary` format for OAuth login, use id_token (JWT) to authenticate with Embedded Wallets. | +| `domain?` | Your custom authentication domain in `string` format. For example, if you are using Auth0, this could 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 be no more than 60 seconds, with a maximum of 120 seconds. String value. | +| `userIdField?` | Field in the JWT that maps to the user ID configured in the dashboard. | +| `isUserIdCaseSensitive?` | Whether the user ID field is case-sensitive. | +| `display?` | Allows developers to configure the display of UI. It takes `Display` as a value. | +| `prompt?` | Prompt shown to the user during the authentication process. It takes `Prompt` as a value. | +| `max_age?` | Maximum time allowed without reauthentication. If the last time the user authenticated is greater than this value, then the user must reauthenticate. String value. | +| `ui_locales?` | The space separated list of language tags, ordered by preference. For example `fr-CA fr en`. | +| `id_token_hint?` | It specify the previously issued ID token. String value. | +| `id_token?` | JWT (ID token) to be passed for login. | +| `access_token?` | Access token to pass to the authentication provider. | +| `flow_type?` | Email passwordless flow. Use `EmailFlowType.link` or `EmailFlowType.code`. | +| `login_hint?` | It is used to send the user's email address during email passwordless login. String value. | +| `acr_values?` | acr_values | +| `scope?` | The default scope to be used on authentication requests. The default scope defined in the Auth0Client is included along with this scope. String value. | +| `audience?` | The audience, presented as the aud claim in the access token, defines the intended consumer of the token. 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. String value. | +| `state?` | State | +| `response_type?` | Defines which grant to be execute for the authorization server. String value. | +| `nonce?` | Nonce value | +| `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. | @@ -177,8 +183,8 @@ public class ExtraLoginOptions { public string domain { get; set; } public string client_id { get; set; } public string leeway { get; set; } - public string verifierIdField { get; set; } - public bool isVerifierIdCaseSensitive { get; set; } + public string userIdField { get; set; } + public bool isUserIdCaseSensitive { get; set; } public Display display { get; set; } public Prompt prompt { get; set; } public string max_age { get; set; } @@ -186,6 +192,8 @@ public class ExtraLoginOptions { public string id_token_hint { get; set; } public string login_hint { get; set; } public string id_token { get; set; } + public string access_token { get; set; } + public EmailFlowType flow_type { get; set; } = EmailFlowType.link; public string acr_values { get; set; } public string scope { get; set; } public string audience { get; set; } @@ -205,10 +213,6 @@ public class ExtraLoginOptions { The `LoginParams` class accepts a `curve` parameter. This parameter can be used to select the elliptic curve to use for the signature. -```cs -LoginParams() { selectedLoginProvider, curve = Curve.SECP256K1 } -``` - ", // will be sent only incase of custom verifiers + "dappShare": "", "idToken": "", - "oAuthIdToken": "", // will be sent only incase of custom verifiers - "oAuthAccessToken": "", // will be sent only incase of custom verifiers - "isMfaEnabled": true // returns true if user has enabled mfa + "oAuthIdToken": "", + "oAuthAccessToken": "", + "isMfaEnabled": true } } ``` @@ -301,10 +305,10 @@ public void login() ```cs public void login() { - var selectedProvider = Provider.GOOGLE; + var authConnection = AuthConnection.GOOGLE; var options = new LoginParams() { - loginProvider = selectedProvider + authConnection = authConnection }; web3Auth.login(options); } @@ -317,10 +321,10 @@ public void login() ```cs public void login() { - var selectedProvider = Provider.FACEBOOK; + var authConnection = AuthConnection.FACEBOOK; var options = new LoginParams() { - loginProvider = selectedProvider + authConnection = authConnection }; web3Auth.login(options); } @@ -333,10 +337,10 @@ public void login() ```cs public void login() { - var selectedProvider = Provider.DISCORD; + var authConnection = AuthConnection.DISCORD; var options = new LoginParams() { - loginProvider = selectedProvider + authConnection = authConnection }; web3Auth.login(options); } @@ -349,10 +353,10 @@ public void login() ```cs public void login() { - var selectedProvider = Provider.TWITCH; + var authConnection = AuthConnection.TWITCH; var options = new LoginParams() { - loginProvider = selectedProvider + authConnection = authConnection }; web3Auth.login(options); } @@ -365,10 +369,10 @@ public void login() ```cs public void login() { - var selectedProvider = Provider.EMAIL_PASSWORDLESS; + var authConnection = AuthConnection.EMAIL_PASSWORDLESS; var options = new LoginParams() { - loginProvider = selectedProvider, + authConnection = authConnection, extraLoginOptions = new ExtraLoginOptions() { login_hint = "hello@web3auth.io" @@ -385,13 +389,13 @@ public void login() ```cs public void login() { - var selectedProvider = Provider.JWT; - var options = new LoginParams() + var options = new LoginParams { - loginProvider = selectedProvider, + authConnection = AuthConnection.CUSTOM, + authConnectionId = "", extraLoginOptions = new ExtraLoginOptions() { - id_token = "your_jwt_token" + id_token = "" } }; web3Auth.login(options); diff --git a/embedded-wallets/sdk/unity/usage/logout.mdx b/embedded-wallets/sdk/unity/usage/logout.mdx index 52f51a3edf9..ee2c8a60f29 100644 --- a/embedded-wallets/sdk/unity/usage/logout.mdx +++ b/embedded-wallets/sdk/unity/usage/logout.mdx @@ -1,15 +1,14 @@ --- -title: Logout user +title: Sign out a user sidebar_label: Sign out -description: 'Web3Auth Unity SDK - logout | Embedded Wallets' +description: 'Sign out a user with the MetaMask Embedded Wallet SDK for Unity.' --- -Trigger logout flow. This function doesn't take parameters. A completable future containing a void object will be returned on successfull logout otherwise an error response is returned. +Call `logout` to end the current session. +Subscribe to `onLogout` to run code after sign-out completes. :::tip -Additionally you can associate a function to be triggered on successful logout. - ```cs void Start() { @@ -37,6 +36,10 @@ private void onLogout() public void logout() { web3Auth.logout(); - Debug.Log("Logged out!"); +} + +private void onLogout() +{ + Debug.Log("Signed out"); } ``` diff --git a/embedded-wallets/sdk/unity/usage/manage-mfa.mdx b/embedded-wallets/sdk/unity/usage/manage-mfa.mdx new file mode 100644 index 00000000000..ee97b8c7b8c --- /dev/null +++ b/embedded-wallets/sdk/unity/usage/manage-mfa.mdx @@ -0,0 +1,30 @@ +--- +title: Manage MFA +description: 'Manage MFA factors with the MetaMask Embedded Wallet SDK for Unity.' +--- + +Call `manageMFA` after a user with multi-factor authentication (MFA) enabled signs in. +Subscribe to `onManageMFA` to run code after the user finishes managing their factors. + +```cs +void Start() +{ + web3Auth.onManageMFA += onManageMFA; +} + +public void manageMFA() +{ + web3Auth.manageMFA(new LoginParams + { + authConnection = AuthConnection.GOOGLE + }); +} + +private void onManageMFA(bool completed) +{ + Debug.Log("Manage MFA completed: " + completed); +} +``` + +For custom authentication, also pass `authConnectionId` and the provider-specific values in +`extraLoginOptions`. diff --git a/embedded-wallets/sdk/unity/usage/request.mdx b/embedded-wallets/sdk/unity/usage/request.mdx index 0d5d8b7fe9f..f263ee8068b 100644 --- a/embedded-wallets/sdk/unity/usage/request.mdx +++ b/embedded-wallets/sdk/unity/usage/request.mdx @@ -1,24 +1,26 @@ --- title: Request signature sidebar_label: Send requests -description: 'Web3Auth Unity SDK - request | Embedded Wallets' +description: 'Request a signature with the MetaMask Embedded Wallet SDK for Unity.' --- -The `request` method facilitates the use of templated transaction screens for signing transactions. +The `request` method opens a Wallet Services confirmation screen for a signing request. -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. +The method supports signing methods from the +[MetaMask JSON-RPC API](/metamask-connect/evm/reference/json-rpc-api/). +Configure the chains and default chain in your Embedded Wallets dashboard. ## Parameters -| 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 singing 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. | +| Argument | Description | +| --------------- | ------------------------------------------------------------------------------------------ | +| `method` | Signing method name as a `string`. | +| `requestParams` | Parameters for the method as a Newtonsoft.Json.Linq `JArray`, in the required order. | +| `path?` | Wallet Services path. The default is `wallet/request`; most integrations should omit this. | :::tip -Additionally you can associate a `getSignResponse` function to retrieve the signature for the request. +Subscribe to `onSignResponse` before making a request to receive its result. ```cs void Start() @@ -44,31 +46,23 @@ private void onSignResponse(SignResponse signResponse) ## Usage ```cs - public void PopupSignMessageUI() { - var chainConfig = new ChainConfig() - { - chainId = "0xaa36a7", - rpcTarget = "https://ethereum-sepolia.publicnode.com", - ticker = "ETH", - chainNamespace = Web3Auth.ChainNamespace.EIP155 - }; +using Nethereum.Web3.Accounts; +using Newtonsoft.Json.Linq; +public void requestSignature() +{ + var account = new Account(web3Auth.getPrivateKey()); JArray paramsArray = new JArray { - "Hello World", - account.Address, - "Android" + "Hello World", + account.Address }; - web3Auth.request(chainConfig, "personal_sign", paramsArray); + web3Auth.request("personal_sign", paramsArray); } - private void onSignResponse(SignResponse signResponse) - { Debug.Log("Retrieved SignResponse: " + signResponse); - updateConsole("Retrieved SignResponse: " + signResponse); } - ``` diff --git a/ew-sidebar.js b/ew-sidebar.js index edfb33f092e..a69f6476fb1 100644 --- a/ew-sidebar.js +++ b/ew-sidebar.js @@ -1011,11 +1011,17 @@ const sidebar = { 'sdk/unity/usage/get-ed25519-private-key', 'sdk/unity/usage/logout', 'sdk/unity/usage/enable-mfa', + 'sdk/unity/usage/manage-mfa', 'sdk/unity/usage/launch-wallet-services', 'sdk/unity/usage/request', ], }, 'sdk/unity/examples', + { + type: 'link', + label: 'Migration Guide', + href: '/embedded-wallets/migration-guides/unity/', + }, { type: 'link', label: 'Troubleshooting', @@ -1024,7 +1030,7 @@ const sidebar = { { type: 'link', label: 'Support forum', - href: 'https://web3auth.io/community/c/help-pnp/pnp-unity/20', + href: 'https://builder.metamask.io/c/embedded-wallets/5', }, { type: 'link', diff --git a/src/components/PasswordlessLoginExamples/index.tsx b/src/components/PasswordlessLoginExamples/index.tsx index 77e81b84f92..0be9e634ec2 100644 --- a/src/components/PasswordlessLoginExamples/index.tsx +++ b/src/components/PasswordlessLoginExamples/index.tsx @@ -160,11 +160,12 @@ await connectTo({ );`} ) } - case 'unity': + case 'unity': { + const idLine = custom ? ',\n authConnectionId = ""' : '' return ( {`var options = new LoginParams { - loginProvider = Provider.${c.unityProvider}, + authConnection = AuthConnection.${c.unityProvider}${idLine}, extraLoginOptions = new ExtraLoginOptions { login_hint = "${c.hint}" @@ -173,6 +174,7 @@ await connectTo({ web3Auth.login(options);`} ) + } default: return null } diff --git a/src/components/SocialLoginExamples/index.tsx b/src/components/SocialLoginExamples/index.tsx index 1e01f653bde..f15c7c22d22 100644 --- a/src/components/SocialLoginExamples/index.tsx +++ b/src/components/SocialLoginExamples/index.tsx @@ -137,7 +137,7 @@ await connectTo({ return ( {`var options = new LoginParams { - loginProvider = Provider.${unityProvider ?? authConnection} + authConnection = AuthConnection.${unityProvider ?? authConnection} }; web3Auth.login(options);`} @@ -208,7 +208,8 @@ function nativeCustomImplicit(platform: SocialLoginPlatform, props: Props) { return ( {`var options = new LoginParams { - loginProvider = Provider.${props.unityProvider} + authConnection = AuthConnection.${props.unityProvider ?? authConnection}, + authConnectionId = "" }; web3Auth.login(options);`} @@ -305,11 +306,12 @@ function auth0Implicit(platform: SocialLoginPlatform, auth0Connection: string) { return ( {`var options = new LoginParams { - loginProvider = Provider.JWT, + authConnection = AuthConnection.CUSTOM, + authConnectionId = "", extraLoginOptions = new ExtraLoginOptions { domain = "https://", - verifierIdField = "sub", + userIdField = "sub", connection = "${auth0Connection}" } }; @@ -401,7 +403,8 @@ await connectTo({ return ( {`var options = new LoginParams { - loginProvider = Provider.JWT, + authConnection = AuthConnection.CUSTOM, + authConnectionId = "", extraLoginOptions = new ExtraLoginOptions { id_token = idToken diff --git a/src/utils/example-maps.tsx b/src/utils/example-maps.tsx index 6f4e9c6a0bc..027b9809190 100644 --- a/src/utils/example-maps.tsx +++ b/src/utils/example-maps.tsx @@ -28,7 +28,8 @@ export const quickStartSourceCode = { REACT_NATIVE: 'https://github.com/Web3Auth/web3auth-react-native-examples/tree/main/rn-bare-quick-start', FLUTTER: 'https://github.com/Web3Auth/web3auth-flutter-examples/tree/main/flutter-quick-start', - UNITY: 'https://github.com/Web3Auth/web3auth-unity-examples/tree/main/unity-quick-start', + UNITY: + 'https://github.com/Web3Auth/web3auth-unity-sdk/tree/master/Assets/Plugins/Web3AuthSDK/Samples', UNREAL: 'https://github.com/Web3Auth/web3auth-unreal-example/tree/master', } @@ -1133,7 +1134,7 @@ export const pnpFlutterExamples: ExamplesInterface[] = [ ] export const pnpUnityExamples: ExamplesInterface[] = [ { - title: 'Web3Auth PnP Unity SDK Quick Start', + title: 'MetaMask Embedded Wallet SDK for Unity quickstart', description: 'A quick integration of MetaMask Embedded Wallets Unity SDK in Android, iOS and WebGL', image: 'img/embedded-wallets/banners/unity.png', @@ -1143,53 +1144,6 @@ export const pnpUnityExamples: ExamplesInterface[] = [ id: 'unity-quick-start', githubLink: quickStartSourceCode.UNITY, }, - { - title: 'Using Auth0 with Web3Auth PnP Unity SDK', - description: - 'Using Auth0 Single Page App (Implicit Mode) in MetaMask Embedded Wallets Unity SDK in Android, iOS and WebGL', - image: 'img/embedded-wallets/banners/unity-auth0.png', - type: SAMPLE_APP, - tags: [ - tags.pnp, - tags.unity, - 'csharp', - tags.android, - tags.ios, - 'webgl', - 'auth0', - 'implicit mode', - tags.evm, - ], - link: 'https://github.com/Web3Auth/web3auth-unity-examples/tree/main/unity-auth0-example', - id: 'unity-auth0-example', - githubLink: 'https://github.com/Web3Auth/web3auth-unity-examples/tree/main/unity-auth0-example', - }, - { - title: 'Using Aggregate Verifiers in Web3Auth PnP Unity SDK', - description: - 'Combine multiple logins (Google, Facebook and GitHub) using Aggregate Verifiers in MetaMask Embedded Wallets Unity SDK for Android, iOS and WebGL', - image: 'img/embedded-wallets/banners/unity-auth0.png', - type: SAMPLE_APP, - tags: [ - tags.pnp, - tags.unity, - 'csharp', - tags.android, - tags.ios, - 'webgl', - 'aggregate verifier', - 'implicit mode', - 'auth0', - 'google', - 'github', - 'facebook', - tags.evm, - ], - link: 'https://github.com/Web3Auth/web3auth-unity-examples/tree/main/unity-aggregate-verifier-example', - id: 'unity-aggregate-verifier-example', - githubLink: - 'https://github.com/Web3Auth/web3auth-unity-examples/tree/main/unity-aggregate-verifier-example', - }, ] export const pnpUnrealExamples: ExamplesInterface[] = [ { diff --git a/src/utils/qs-file-links.json b/src/utils/qs-file-links.json index bfbbe7545b0..20dff471905 100644 --- a/src/utils/qs-file-links.json +++ b/src/utils/qs-file-links.json @@ -49,9 +49,9 @@ "EW_VUE_GET_BALANCE_TSX": "Web3Auth/web3auth-examples/refs/heads/main/quick-starts/vue-quick-start/src/components/Balance.vue", "EW_VUE_SEND_TRANSACTION_TSX": "Web3Auth/web3auth-examples/refs/heads/main/quick-starts/vue-quick-start/src/components/SendTransaction.vue", "EW_VUE_SWITCH_NETWORK_TSX": "Web3Auth/web3auth-examples/refs/heads/main/quick-starts/vue-quick-start/src/components/SwitchNetwork.vue", - "EW_PNP_UNITY_WEB3AUTHSCRIPT_CS": "Web3Auth/web3auth-unity-examples/refs/heads/main/unity-quick-start/Assets/Web3AuthScript.cs", - "EW_PNP_UNITY_ANDROID_MANIFEST": "Web3Auth/web3auth-unity-examples/refs/heads/main/unity-quick-start/Assets/Plugins/Android/AndroidManifest.xml", - "EW_PNP_UNITY_MANIFEST_JSON": "Web3Auth/web3auth-unity-examples/refs/heads/main/unity-quick-start/Packages/manifest.json", + "EW_PNP_UNITY_WEB3AUTHSCRIPT_CS": "Web3Auth/web3auth-unity-sdk/refs/heads/master/Assets/Plugins/Web3AuthSDK/Samples/Web3AuthSample.cs", + "EW_PNP_UNITY_ANDROID_MANIFEST": "Web3Auth/web3auth-unity-sdk/refs/heads/master/Assets/Plugins/Android/AndroidManifest.xml", + "EW_PNP_UNITY_MANIFEST_JSON": "Web3Auth/web3auth-unity-sdk/refs/heads/master/Packages/manifest.json", "EW_PNP_REACT_NATIVE_APP_TSX": "Web3Auth/web3auth-react-native-examples/main/rn-bare-quick-start/App.tsx", "EW_PNP_REACT_NATIVE_PACKAGE_JSON": "Web3Auth/web3auth-react-native-examples/main/rn-bare-quick-start/package.json", "EW_PNP_REACT_NATIVE_METRO_CONFIG_JS": "Web3Auth/web3auth-react-native-examples/main/rn-bare-quick-start/metro.config.js", diff --git a/src/utils/qs-map.tsx b/src/utils/qs-map.tsx index 4558b6b5825..5f52617a591 100644 --- a/src/utils/qs-map.tsx +++ b/src/utils/qs-map.tsx @@ -39,7 +39,8 @@ export const EWQuickStartSourceCode = { REACT_NATIVE: 'https://github.com/Web3Auth/web3auth-react-native-examples/tree/main/rn-bare-quick-start', FLUTTER: 'https://github.com/Web3Auth/web3auth-flutter-examples/tree/main/flutter-quick-start', - UNITY: 'https://github.com/Web3Auth/web3auth-unity-examples/tree/main/unity-quick-start', + UNITY: + 'https://github.com/Web3Auth/web3auth-unity-sdk/tree/master/Assets/Plugins/Web3AuthSDK/Samples', UNREAL: 'https://github.com/Web3Auth/web3auth-unreal-example/tree/master', } diff --git a/src/utils/w3a-sdk-map.js b/src/utils/w3a-sdk-map.js index d75bbc6bfb9..a0747d7a0a9 100644 --- a/src/utils/w3a-sdk-map.js +++ b/src/utils/w3a-sdk-map.js @@ -19,7 +19,7 @@ export const pnpIOSVersion = `11` export const pnpRNVersion = `9` export const pnpNodeVersion = `6` export const pnpFlutterVersion = `6` -export const pnpUnityVersion = `7` +export const pnpUnityVersion = `8` export const pnpUnrealVersion = `4` export function getPnPVersion(platform) {