diff --git a/Assets/Plugins/Web3AuthSDK/Api/Models/ProjectConfigResponse.cs b/Assets/Plugins/Web3AuthSDK/Api/Models/ProjectConfigResponse.cs index 5627de5..e2e8695 100644 --- a/Assets/Plugins/Web3AuthSDK/Api/Models/ProjectConfigResponse.cs +++ b/Assets/Plugins/Web3AuthSDK/Api/Models/ProjectConfigResponse.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using Plugins.Web3AuthSDK.Types; public class WhitelistResponse { @@ -8,9 +9,16 @@ public class WhitelistResponse public class ProjectConfigResponse { - public WhiteLabelData whitelabel { get; set; } + public bool? userDataInIdToken { get; set; } = true; + public int? sessionTime { get; set; } = 30 * 86400; + public bool? enableKeyExport { get; set; } = false; + public WhitelistResponse whitelist { get; set; } + public List chains { get; set; } + public SmartAccountsConfig smartAccounts { get; set; } + public WalletUiConfig walletUiConfig { get; set; } + public List embeddedWalletAuth { get; set; } public bool sms_otp_enabled { get; set; } public bool wallet_connect_enabled { get; set; } - public string wallet_connect_project_id { get; set; } - public WhitelistResponse whitelist { get; set; } + public string walletConnectProjectId { get; set; } + public WhiteLabelData whitelabel { get; set; } } \ No newline at end of file diff --git a/Assets/Plugins/Web3AuthSDK/Api/Web3AuthApi.cs b/Assets/Plugins/Web3AuthSDK/Api/Web3AuthApi.cs index 3f9001a..3fb045f 100644 --- a/Assets/Plugins/Web3AuthSDK/Api/Web3AuthApi.cs +++ b/Assets/Plugins/Web3AuthSDK/Api/Web3AuthApi.cs @@ -99,11 +99,11 @@ public IEnumerator createSession(LogoutApiRequest logoutApiRequest, Action callback) + public IEnumerator fetchProjectConfig(string project_id, string network, string build_env, Action callback) { //Debug.Log("network =>" + network); string baseUrl = SIGNER_MAP[network]; - var requestURL = $"{baseUrl}/api/configuration?project_id={project_id}&network={network}&whitelist=true"; + var requestURL = $"{baseUrl}/api/v2/configuration?project_id={project_id}&network={network}&build_env={build_env}"; var request = UnityWebRequest.Get(requestURL); yield return request.SendWebRequest(); @@ -111,6 +111,7 @@ public IEnumerator fetchProjectConfig(string project_id, string network, Action< if (request.result == UnityWebRequest.Result.Success) { string result = request.downloadHandler.text; + //Debug.Log("fetch config raw API result: " + result); callback(Newtonsoft.Json.JsonConvert.DeserializeObject(result)); } else diff --git a/Assets/Plugins/Web3AuthSDK/Samples/LoginVerifier.cs b/Assets/Plugins/Web3AuthSDK/Samples/LoginVerifier.cs index d2a7cd8..29f9d4f 100644 --- a/Assets/Plugins/Web3AuthSDK/Samples/LoginVerifier.cs +++ b/Assets/Plugins/Web3AuthSDK/Samples/LoginVerifier.cs @@ -1,10 +1,10 @@ public class LoginVerifier { public string name { get; set; } - public Provider loginProvider { get; set; } + public AuthConnection authConnection { get; set; } - public LoginVerifier(string name, Provider loginProvider) + public LoginVerifier(string name, AuthConnection authConnection) { this.name = name; - this.loginProvider = loginProvider; + this.authConnection = authConnection; } } \ No newline at end of file diff --git a/Assets/Plugins/Web3AuthSDK/Samples/Web3AuthSample.cs b/Assets/Plugins/Web3AuthSDK/Samples/Web3AuthSample.cs index 91f6c09..260104c 100644 --- a/Assets/Plugins/Web3AuthSDK/Samples/Web3AuthSample.cs +++ b/Assets/Plugins/Web3AuthSDK/Samples/Web3AuthSample.cs @@ -1,36 +1,34 @@ using System; -using System.Linq; using System.Collections.Generic; -using UnityEngine; -using UnityEngine.UI; +using System.Linq; using Newtonsoft.Json; using Newtonsoft.Json.Linq; -using static Web3Auth; using Org.BouncyCastle.Asn1.Sec; -using Org.BouncyCastle.Crypto.Parameters; +using Org.BouncyCastle.Crypto.Digests; using Org.BouncyCastle.Math; using Org.BouncyCastle.Math.EC; -using Org.BouncyCastle.Security; using Org.BouncyCastle.Utilities.Encoders; -using Org.BouncyCastle.Crypto.Digests; +using UnityEngine; +using UnityEngine.UI; +using static Web3Auth; public class Web3AuthSample : MonoBehaviour { List verifierList = new List { - new LoginVerifier("Google", Provider.GOOGLE), - new LoginVerifier("Facebook", Provider.FACEBOOK), - // new LoginVerifier("CUSTOM_VERIFIER", Provider.CUSTOM_VERIFIER), - new LoginVerifier("Twitch", Provider.TWITCH), - new LoginVerifier("Discord", Provider.DISCORD), - new LoginVerifier("Reddit", Provider.REDDIT), - new LoginVerifier("Apple", Provider.APPLE), - new LoginVerifier("Github", Provider.GITHUB), - new LoginVerifier("LinkedIn", Provider.LINKEDIN), - new LoginVerifier("Twitter", Provider.TWITTER), - new LoginVerifier("Line", Provider.LINE), - new LoginVerifier("Email Passwordless", Provider.EMAIL_PASSWORDLESS), - new LoginVerifier("SMS Passwordless", Provider.SMS_PASSWORDLESS), - new LoginVerifier("Farcaster", Provider.FARCASTER), + new LoginVerifier("Google", AuthConnection.GOOGLE), + new LoginVerifier("Facebook", AuthConnection.FACEBOOK), + // new LoginVerifier("CUSTOM_VERIFIER", AuthConnection.CUSTOM_VERIFIER), + new LoginVerifier("Twitch", AuthConnection.TWITCH), + new LoginVerifier("Discord", AuthConnection.DISCORD), + new LoginVerifier("Reddit", AuthConnection.REDDIT), + new LoginVerifier("Apple", AuthConnection.APPLE), + new LoginVerifier("Github", AuthConnection.GITHUB), + new LoginVerifier("LinkedIn", AuthConnection.LINKEDIN), + new LoginVerifier("Twitter", AuthConnection.TWITTER), + new LoginVerifier("Line", AuthConnection.LINE), + new LoginVerifier("Email Passwordless", AuthConnection.EMAIL_PASSWORDLESS), + new LoginVerifier("SMS Passwordless", AuthConnection.SMS_PASSWORDLESS), + new LoginVerifier("Farcaster", AuthConnection.FARCASTER), }; Web3Auth web3Auth; @@ -64,12 +62,13 @@ public class Web3AuthSample : MonoBehaviour void Start() { - var loginConfigItem = new LoginConfigItem() + var authConnectionItem = new AuthConnectionConfig() { - verifier = "your_verifierid_from_web3auth_dashboard", - typeOfLogin = TypeOfLogin.GOOGLE, + authConnectionId = "your_verifierid_from_web3auth_dashboard", // corresponds to `verifier` + authConnection = AuthConnection.GOOGLE, clientId = "your_clientId_from_web3auth_dashboard" }; + var authConnectionConfig = new List { authConnectionItem }; web3Auth = GetComponent(); web3Auth.setOptions(new Web3AuthOptions() @@ -94,10 +93,20 @@ void Start() {"CUSTOM_VERIFIER", loginConfigItem} } */ - clientId = "BFuUqebV5I8Pz5F7a5A2ihW7YVmbv_OHXnHYDv6OltAD5NGr6e-ViNvde3U4BHdn6HvwfkgobhVu4VwC-OSJkik", - buildEnv = BuildEnv.PRODUCTION, + authConnectionConfig = new List() + { + new AuthConnectionConfig() + { + authConnectionId = "web3auth-auth0-email-passwordless-sapphire-devnet", + authConnection = AuthConnection.CUSTOM, + clientId = "d84f6xvbdV75VTGmHiMWfZLeSPk8M07C" + } + }, + clientId = "BHgArYmWwSeq21czpcarYh0EVq2WWOzflX-NTK-tY1-1pauPzHKRRLgpABkmYiIV_og9jAvoIxQ8L3Smrwe04Lw", + authBuildEnv = BuildEnv.TESTING, redirectUrl = new Uri("torusapp://com.torus.Web3AuthUnity"), - network = Web3Auth.Network.SAPPHIRE_DEVNET, + web3AuthNetwork = Web3Auth.Network.SAPPHIRE_DEVNET, + defaultChainId = "0x1", sessionTime = 86400 }); web3Auth.onLogin += onLogin; @@ -116,7 +125,7 @@ void Start() loginButton.onClick.AddListener(login); logoutButton.onClick.AddListener(logout); mfaSetupButton.onClick.AddListener(enableMFA); - launchWalletServicesButton.onClick.AddListener(launchWalletServices); + launchWalletServicesButton.onClick.AddListener(showWalletUI); signMessageButton.onClick.AddListener(request); signResponseButton.onClick.AddListener(manageMFA); @@ -168,7 +177,7 @@ private void onManageMFA(bool response) { private void onVerifierDropDownChange(int selectedIndex) { - if (verifierList[selectedIndex].loginProvider == Provider.EMAIL_PASSWORDLESS) + if (verifierList[selectedIndex].authConnection == AuthConnection.EMAIL_PASSWORDLESS) emailAddressField.gameObject.SetActive(true); else emailAddressField.gameObject.SetActive(false); @@ -176,21 +185,21 @@ private void onVerifierDropDownChange(int selectedIndex) private void login() { - var selectedProvider = verifierList[verifierDropdown.value].loginProvider; + var selectedProvider = verifierList[verifierDropdown.value].authConnection; var options = new LoginParams() { - loginProvider = selectedProvider + authConnection = selectedProvider }; - if (selectedProvider == Provider.EMAIL_PASSWORDLESS) + if (selectedProvider == AuthConnection.EMAIL_PASSWORDLESS) { options.extraLoginOptions = new ExtraLoginOptions() { login_hint = emailAddressField.text }; } - if (selectedProvider == Provider.SMS_PASSWORDLESS) + if (selectedProvider == AuthConnection.SMS_PASSWORDLESS) { options.extraLoginOptions = new ExtraLoginOptions() { @@ -208,15 +217,15 @@ private void logout() private void enableMFA() { - var selectedProvider = verifierList[verifierDropdown.value].loginProvider; + var selectedProvider = verifierList[verifierDropdown.value].authConnection; var options = new LoginParams() { - loginProvider = selectedProvider, + authConnection = selectedProvider, mfaLevel = MFALevel.MANDATORY }; - if (selectedProvider == Provider.EMAIL_PASSWORDLESS) + if (selectedProvider == AuthConnection.EMAIL_PASSWORDLESS) { options.extraLoginOptions = new ExtraLoginOptions() { @@ -228,15 +237,15 @@ private void enableMFA() private void manageMFA() { - var selectedProvider = verifierList[verifierDropdown.value].loginProvider; + var selectedProvider = verifierList[verifierDropdown.value].authConnection; var options = new LoginParams() { - loginProvider = selectedProvider, + authConnection = selectedProvider, mfaLevel = MFALevel.MANDATORY }; - if (selectedProvider == Provider.EMAIL_PASSWORDLESS) + if (selectedProvider == AuthConnection.EMAIL_PASSWORDLESS) { options.extraLoginOptions = new ExtraLoginOptions() { @@ -246,37 +255,42 @@ private void manageMFA() web3Auth.manageMFA(options); } - private void launchWalletServices() { - var selectedProvider = verifierList[verifierDropdown.value].loginProvider; + private void showWalletUI() { + var selectedProvider = verifierList[verifierDropdown.value].authConnection; - var chainConfig = new ChainConfig() + var chainConfig = new Chains() { chainId = "0x1", rpcTarget = "https://mainnet.infura.io/v3/daeee53504be4cd3a997d4f2718d33e0", ticker = "ETH", - chainNamespace = Web3Auth.ChainNamespace.EIP155 + chainNamespace = ChainNamespace.eip155 }; - web3Auth.launchWalletServices(chainConfig); + var chainConfigList = new List { chainConfig }; + foreach (var config in chainConfigList) + { + Debug.Log($"Chain ID: {config.chainId}, RPC Target: {config.rpcTarget}, Ticker: {config.ticker}, Namespace: {config.chainNamespace}"); + } + web3Auth.showWalletUI("0x1"); } private void request() { - var selectedProvider = verifierList[verifierDropdown.value].loginProvider; + var selectedProvider = verifierList[verifierDropdown.value].authConnection; - var chainConfig = new ChainConfig() + var chainConfig = new Chains() { chainId = "0x89", rpcTarget = "https://1rpc.io/matic", - chainNamespace = Web3Auth.ChainNamespace.EIP155 + chainNamespace = ChainNamespace.eip155 }; JArray paramsArray = new JArray { "Hello, World!", - getPublicAddressFromPrivateKey(web3Auth.getPrivKey()), + getPublicAddressFromPrivateKey(web3Auth.getPrivateKey()), "Android" }; - web3Auth.request(chainConfig, "personal_sign", paramsArray); + web3Auth.request("personal_sign", paramsArray); } public string getPublicAddressFromPrivateKey(string privateKeyHex) diff --git a/Assets/Plugins/Web3AuthSDK/Types/Provider.cs b/Assets/Plugins/Web3AuthSDK/Types/AuthConnection.cs similarity index 93% rename from Assets/Plugins/Web3AuthSDK/Types/Provider.cs rename to Assets/Plugins/Web3AuthSDK/Types/AuthConnection.cs index 3b926c8..472aaf3 100644 --- a/Assets/Plugins/Web3AuthSDK/Types/Provider.cs +++ b/Assets/Plugins/Web3AuthSDK/Types/AuthConnection.cs @@ -3,7 +3,7 @@ using System.Runtime.Serialization; [JsonConverter(typeof(StringEnumConverter))] -public enum Provider +public enum AuthConnection { [EnumMember(Value = "google")] GOOGLE, @@ -35,8 +35,8 @@ 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, [EnumMember(Value = "sms_passwordless")] diff --git a/Assets/Plugins/Web3AuthSDK/Types/LoginConfigItem.cs b/Assets/Plugins/Web3AuthSDK/Types/AuthConnectionConfig.cs similarity index 63% rename from Assets/Plugins/Web3AuthSDK/Types/LoginConfigItem.cs rename to Assets/Plugins/Web3AuthSDK/Types/AuthConnectionConfig.cs index 0f3ec18..c3393b5 100644 --- a/Assets/Plugins/Web3AuthSDK/Types/LoginConfigItem.cs +++ b/Assets/Plugins/Web3AuthSDK/Types/AuthConnectionConfig.cs @@ -1,10 +1,10 @@ -public class LoginConfigItem { - public string verifier { get; set; } - public TypeOfLogin typeOfLogin { get; set; } +public class AuthConnectionConfig { + public string authConnectionId { get; set; } + public AuthConnection authConnection { get; set; } public string name { get; set; } public string description { get; set; } public string clientId { get; set; } - public string verifierSubIdentifier { get; set; } + public string groupedAuthConnectionId { get; set; } public string logoHover { get; set; } public string logoLight { get; set; } public string logoDark { get; set; } @@ -12,4 +12,5 @@ public bool showOnModal { get; set; } = true; public bool showOnDesktop { get; set; } = true; public bool showOnMobile { get; set; } = true; + public ExtraLoginOptions extraLoginOptions { get; set; } } \ No newline at end of file diff --git a/Assets/Plugins/Web3AuthSDK/Types/BundlerConfig.cs b/Assets/Plugins/Web3AuthSDK/Types/BundlerConfig.cs new file mode 100644 index 0000000..f93bf51 --- /dev/null +++ b/Assets/Plugins/Web3AuthSDK/Types/BundlerConfig.cs @@ -0,0 +1,7 @@ +namespace Plugins.Web3AuthSDK.Types +{ + public class BundlerConfig + { + public string url { get; set; } + } +} \ No newline at end of file diff --git a/Assets/Plugins/Web3AuthSDK/Types/BundlerConfig.cs.meta b/Assets/Plugins/Web3AuthSDK/Types/BundlerConfig.cs.meta new file mode 100644 index 0000000..db199d7 --- /dev/null +++ b/Assets/Plugins/Web3AuthSDK/Types/BundlerConfig.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: f7937f8f3db14dfea557ef526d300942 +timeCreated: 1750061363 \ No newline at end of file diff --git a/Assets/Plugins/Web3AuthSDK/Types/ChainConfig.cs b/Assets/Plugins/Web3AuthSDK/Types/Chains.cs similarity index 73% rename from Assets/Plugins/Web3AuthSDK/Types/ChainConfig.cs rename to Assets/Plugins/Web3AuthSDK/Types/Chains.cs index 27df1de..85e2787 100644 --- a/Assets/Plugins/Web3AuthSDK/Types/ChainConfig.cs +++ b/Assets/Plugins/Web3AuthSDK/Types/Chains.cs @@ -1,7 +1,12 @@ -using System.Collections.Generic; #nullable enable -public class ChainConfig { - public Web3Auth.ChainNamespace? chainNamespace { get; set; } = Web3Auth.ChainNamespace.EIP155; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; + +public class Chains { + + [JsonConverter(typeof(StringEnumConverter))] + 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; } diff --git a/Assets/Plugins/Web3AuthSDK/Types/ExtraLoginOptions.cs b/Assets/Plugins/Web3AuthSDK/Types/ExtraLoginOptions.cs index 65dfe5d..b0d1c9a 100644 --- a/Assets/Plugins/Web3AuthSDK/Types/ExtraLoginOptions.cs +++ b/Assets/Plugins/Web3AuthSDK/Types/ExtraLoginOptions.cs @@ -5,13 +5,15 @@ 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; } public string ui_locales { get; set; } public string id_token { get; set; } + public string access_token { get; set; } + private EmailFlowType flow_type { get; set; } = EmailFlowType.link; public string id_token_hint { get; set; } public string login_hint { get; set; } public string acr_values { get; set; } @@ -22,4 +24,9 @@ public class ExtraLoginOptions { public string response_type { get; set; } public string nonce { get; set; } public string redirect_uri { get; set; } +} + +public enum EmailFlowType +{ + link, code } \ No newline at end of file diff --git a/Assets/Plugins/Web3AuthSDK/Types/LoginConfigItem.cs.meta b/Assets/Plugins/Web3AuthSDK/Types/LoginConfigItem.cs.meta deleted file mode 100644 index 2f5e627..0000000 --- a/Assets/Plugins/Web3AuthSDK/Types/LoginConfigItem.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: f2084deef0ee33142b69d4593c983a90 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Plugins/Web3AuthSDK/Types/LoginParams.cs b/Assets/Plugins/Web3AuthSDK/Types/LoginParams.cs index ff3f7f4..f1c96a1 100644 --- a/Assets/Plugins/Web3AuthSDK/Types/LoginParams.cs +++ b/Assets/Plugins/Web3AuthSDK/Types/LoginParams.cs @@ -1,14 +1,14 @@ -using System; - -public class LoginParams +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 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; } + } \ No newline at end of file diff --git a/Assets/Plugins/Web3AuthSDK/Types/PaymasterConfig.cs b/Assets/Plugins/Web3AuthSDK/Types/PaymasterConfig.cs new file mode 100644 index 0000000..84e9b81 --- /dev/null +++ b/Assets/Plugins/Web3AuthSDK/Types/PaymasterConfig.cs @@ -0,0 +1,7 @@ +namespace Plugins.Web3AuthSDK.Types +{ + public class PaymasterConfig + { + public string url { get; set; } + } +} \ No newline at end of file diff --git a/Assets/Plugins/Web3AuthSDK/Types/PaymasterConfig.cs.meta b/Assets/Plugins/Web3AuthSDK/Types/PaymasterConfig.cs.meta new file mode 100644 index 0000000..6402c23 --- /dev/null +++ b/Assets/Plugins/Web3AuthSDK/Types/PaymasterConfig.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 526533185c3841fc8a5d6f901c5f73ec +timeCreated: 1750061393 \ No newline at end of file diff --git a/Assets/Plugins/Web3AuthSDK/Types/Provider.cs.meta b/Assets/Plugins/Web3AuthSDK/Types/Provider.cs.meta deleted file mode 100644 index 82d8ae8..0000000 --- a/Assets/Plugins/Web3AuthSDK/Types/Provider.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: d726f63285867184a9016460e6f380f4 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Plugins/Web3AuthSDK/Types/SmartAccountsConfig.cs b/Assets/Plugins/Web3AuthSDK/Types/SmartAccountsConfig.cs new file mode 100644 index 0000000..fb675f0 --- /dev/null +++ b/Assets/Plugins/Web3AuthSDK/Types/SmartAccountsConfig.cs @@ -0,0 +1,31 @@ +using System.Collections.Generic; + +namespace Plugins.Web3AuthSDK.Types +{ + public class SmartAccountsConfig + { + public SmartAccountType SmartAccountType { get; set; } + + public SmartAccountWalletScope walletScope { get; set; } + + public List chains { get; set; } + } + + public class ChainConfig + { + public string chainId { get; set; } + public BundlerConfig bundlerConfig { get; set; } + public PaymasterConfig paymasterConfig { get; set; } + } +} + +public enum SmartAccountWalletScope +{ + embedded, + all +} + +public enum SmartAccountType +{ + biconomy, kernel, safe, trust, light, simple, nexus +} \ No newline at end of file diff --git a/Assets/Plugins/Web3AuthSDK/Types/SmartAccountsConfig.cs.meta b/Assets/Plugins/Web3AuthSDK/Types/SmartAccountsConfig.cs.meta new file mode 100644 index 0000000..48728ce --- /dev/null +++ b/Assets/Plugins/Web3AuthSDK/Types/SmartAccountsConfig.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: e5f50c644c2544d8894b5b60b03f365d +timeCreated: 1750060901 \ No newline at end of file diff --git a/Assets/Plugins/Web3AuthSDK/Types/TypeOfLogin.cs b/Assets/Plugins/Web3AuthSDK/Types/TypeOfLogin.cs deleted file mode 100644 index 4960f4b..0000000 --- a/Assets/Plugins/Web3AuthSDK/Types/TypeOfLogin.cs +++ /dev/null @@ -1,40 +0,0 @@ -using Newtonsoft.Json; -using Newtonsoft.Json.Converters; -using System.Runtime.Serialization; - -[JsonConverter(typeof(StringEnumConverter))] -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 -} \ No newline at end of file diff --git a/Assets/Plugins/Web3AuthSDK/Types/TypeOfLogin.cs.meta b/Assets/Plugins/Web3AuthSDK/Types/TypeOfLogin.cs.meta deleted file mode 100644 index 5659d28..0000000 --- a/Assets/Plugins/Web3AuthSDK/Types/TypeOfLogin.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 1465d9a3f378eb64692b5d08c2dee5a9 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Plugins/Web3AuthSDK/Types/UserInfo.cs b/Assets/Plugins/Web3AuthSDK/Types/UserInfo.cs index 9de1c61..807ee0c 100644 --- a/Assets/Plugins/Web3AuthSDK/Types/UserInfo.cs +++ b/Assets/Plugins/Web3AuthSDK/Types/UserInfo.cs @@ -3,10 +3,10 @@ public string email { get; set; } public string name { get; set; } public string profileImage { get; set; } - public string aggregateVerifier { get; set; } - public string verifier { get; set; } - public string verifierId { get; set; } - public string typeOfLogin { get; set; } + public string groupedAuthConnectionId { get; set; } + public string authConnectionId { get; set; } + public string userId { get; set; } + public string authConnection { get; set; } public string dappShare { get; set; } public string idToken { get; set; } public string oAuthIdToken { get; set; } diff --git a/Assets/Plugins/Web3AuthSDK/Types/WalletServicesConfig.cs b/Assets/Plugins/Web3AuthSDK/Types/WalletServicesConfig.cs new file mode 100644 index 0000000..3d6f44f --- /dev/null +++ b/Assets/Plugins/Web3AuthSDK/Types/WalletServicesConfig.cs @@ -0,0 +1,26 @@ +using Newtonsoft.Json; + +namespace Plugins.Web3AuthSDK.Types +{ + public class WalletServicesConfig + { + public ConfirmationStrategy? confirmationStrategy { get; set; } = ConfirmationStrategy.DEFAULT; + + public WhiteLabelData? whiteLabel { get; set; } + } +} + +public enum ConfirmationStrategy +{ + [JsonProperty("popup")] + POPUP, + + [JsonProperty("modal")] + MODAL, + + [JsonProperty("auto-approve")] + AUTO_APPROVE, + + [JsonProperty("default")] + DEFAULT +} \ No newline at end of file diff --git a/Assets/Plugins/Web3AuthSDK/Types/WalletServicesConfig.cs.meta b/Assets/Plugins/Web3AuthSDK/Types/WalletServicesConfig.cs.meta new file mode 100644 index 0000000..479be9e --- /dev/null +++ b/Assets/Plugins/Web3AuthSDK/Types/WalletServicesConfig.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 1194c63acb8a40528f551ca2f9d7b5f3 +timeCreated: 1750059054 \ No newline at end of file diff --git a/Assets/Plugins/Web3AuthSDK/Types/WalletUiConfig.cs b/Assets/Plugins/Web3AuthSDK/Types/WalletUiConfig.cs new file mode 100644 index 0000000..cbb3059 --- /dev/null +++ b/Assets/Plugins/Web3AuthSDK/Types/WalletUiConfig.cs @@ -0,0 +1,51 @@ +using Newtonsoft.Json; + +namespace Plugins.Web3AuthSDK.Types +{ + public class WalletUiConfig + { + public bool? enablePortfolioWidget { get; set; } + + public bool? enableConfirmationModal { get; set; } + + public bool? enableWalletConnect { get; set; } + + public bool? enableTokenDisplay { get; set; } + + public bool? enableNftDisplay { get; set; } + + public bool? enableShowAllTokensButton { get; set; } + + public bool? enableBuyButton { get; set; } + + public bool? enableSendButton { get; set; } + + public bool? enableSwapButton { get; set; } + + public bool? enableReceiveButton { get; set; } + + public ButtonPositionType? portfolioWidgetPosition { get; set; } + + public DefaultPortfolioType? defaultPortfolio { get; set; } + } +} + +public enum ButtonPositionType +{ + [JsonProperty("bottom-left")] + BOTTOM_LEFT, + + [JsonProperty("top-left")] + TOP_LEFT, + + [JsonProperty("bottom-right")] + BOTTOM_RIGHT, + + [JsonProperty("top-right")] + TOP_RIGHT +} + +public enum DefaultPortfolioType +{ + token , nft +} \ No newline at end of file diff --git a/Assets/Plugins/Web3AuthSDK/Types/WalletUiConfig.cs.meta b/Assets/Plugins/Web3AuthSDK/Types/WalletUiConfig.cs.meta new file mode 100644 index 0000000..0bd31e3 --- /dev/null +++ b/Assets/Plugins/Web3AuthSDK/Types/WalletUiConfig.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 845b4eaa6fcf4ba09c241466a1c8efc9 +timeCreated: 1750062059 \ No newline at end of file diff --git a/Assets/Plugins/Web3AuthSDK/Types/Web3AuthOptions.cs b/Assets/Plugins/Web3AuthSDK/Types/Web3AuthOptions.cs index 92543f1..283825c 100644 --- a/Assets/Plugins/Web3AuthSDK/Types/Web3AuthOptions.cs +++ b/Assets/Plugins/Web3AuthSDK/Types/Web3AuthOptions.cs @@ -1,50 +1,37 @@ -using System; +#nullable enable + +using System; using System.Collections.Generic; -#nullable enable +using Newtonsoft.Json; +using Plugins.Web3AuthSDK.Types; public class Web3AuthOptions { public string clientId { get; set; } - public Web3Auth.Network network { get; set; } - - public Web3Auth.BuildEnv buildEnv { get; set; } = Web3Auth.BuildEnv.PRODUCTION; public Uri redirectUrl { get; set; } + public Dictionary originData { get; set; } = null; + + [JsonProperty("buildEnv")] + public Web3Auth.BuildEnv authBuildEnv { get; set; } = Web3Auth.BuildEnv.PRODUCTION; public string sdkUrl { - get { - if (buildEnv == Web3Auth.BuildEnv.STAGING) - return "https://staging-auth.web3auth.io/v9"; - else if (buildEnv == Web3Auth.BuildEnv.TESTING) - return "https://develop-auth.web3auth.io"; - else - return "https://auth.web3auth.io/v9"; + get + { + return authBuildEnv switch + { + Web3Auth.BuildEnv.STAGING => "https://staging-auth.web3auth.io/v10", + Web3Auth.BuildEnv.TESTING => "https://develop-auth.web3auth.io", + _ => "https://auth.web3auth.io/v10" + }; } set { } } - - public string walletSdkUrl { - get { - if (buildEnv == Web3Auth.BuildEnv.STAGING) - return "https://staging-wallet.web3auth.io/v3"; - else if (buildEnv == Web3Auth.BuildEnv.TESTING) - return "https://develop-wallet.web3auth.io"; - else - return "https://wallet.web3auth.io/v3"; - } - set { } - } + + public List? authConnectionConfig { get; set; } = new List(); public WhiteLabelData? whiteLabel { get; set; } - public Dictionary? loginConfig { get; set; } - public bool? useCoreKitKey { get; set; } = false; - public Web3Auth.ChainNamespace? chainNamespace { get; set; } = Web3Auth.ChainNamespace.EIP155; - public MfaSettings? mfaSettings { get; set; } = null; - public int sessionTime { get; set; } = 86400; - public ChainConfig? chainConfig { get; set; } - public Dictionary originData { get; set; } = null; - public string dashboardUrl { get { - return buildEnv switch + return authBuildEnv switch { Web3Auth.BuildEnv.STAGING => $"https://staging-account.web3auth.io/{authDashboardVersion}/{walletAccountConstant}", Web3Auth.BuildEnv.TESTING => $"https://develop-account.web3auth.io/{walletAccountConstant}", @@ -53,6 +40,31 @@ public string dashboardUrl } set { } } + public string? accountAbstractionConfig { get; set; } + public string walletSdkUrl { + get + { + return authBuildEnv switch + { + Web3Auth.BuildEnv.STAGING => "https://staging-wallet.web3auth.io/v5", + Web3Auth.BuildEnv.TESTING => "https://develop-wallet.web3auth.io", + _ => "https://wallet.web3auth.io/v5" + }; + } + set { } + } + public bool? includeUserDataInToken { get; set; } = true; + public Chains? chains { get; set; } + public String? defaultChainId { get; set; } = "0x1"; + public bool? enableLogging { get; set; } = false; + public int sessionTime { get; set; } = 86400; + + [JsonProperty("network")] + public Web3Auth.Network web3AuthNetwork { get; set; } + + public bool? useSFAKey { get; set; } = false; + public WalletServicesConfig? walletServicesConfig { get; set; } + public MfaSettings? mfaSettings { get; set; } = null; private const string authDashboardVersion = "v9"; private const string walletAccountConstant = "wallet/account"; diff --git a/Assets/Plugins/Web3AuthSDK/Types/Web3AuthResponse.cs b/Assets/Plugins/Web3AuthSDK/Types/Web3AuthResponse.cs index 607e47b..8200a96 100644 --- a/Assets/Plugins/Web3AuthSDK/Types/Web3AuthResponse.cs +++ b/Assets/Plugins/Web3AuthSDK/Types/Web3AuthResponse.cs @@ -1,7 +1,11 @@ -public class Web3AuthResponse +using Newtonsoft.Json; +public class Web3AuthResponse { - public string privKey { get; set; } - public string ed25519PrivKey { get; set; } + [JsonProperty("privKey")] + public string privateKey { get; set; } + + [JsonProperty("ed25519PrivKey")] + public string ed25519PrivateKey { get; set; } public UserInfo userInfo { get; set; } public string error { get; set; } public string sessionId { get; set; } diff --git a/Assets/Plugins/Web3AuthSDK/Web3Auth.cs b/Assets/Plugins/Web3AuthSDK/Web3Auth.cs index 8b29eb4..a522090 100644 --- a/Assets/Plugins/Web3AuthSDK/Web3Auth.cs +++ b/Assets/Plugins/Web3AuthSDK/Web3Auth.cs @@ -1,15 +1,16 @@ -using Newtonsoft.Json; -using Newtonsoft.Json.Converters; -using System; +using System; +using System.Collections; using System.Collections.Generic; -using System.Text; +using System.IO; using System.Linq; -using UnityEngine; using System.Net; -using System.Collections; -using Org.BouncyCastle.Math; -using Newtonsoft.Json.Linq; +using System.Text; using System.Threading.Tasks; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; +using Newtonsoft.Json.Linq; +using Org.BouncyCastle.Math; +using UnityEngine; public class Web3Auth : MonoBehaviour { @@ -18,9 +19,10 @@ public enum Network MAINNET, TESTNET, CYAN, AQUA, SAPPHIRE_DEVNET, SAPPHIRE_MAINNET } + [JsonConverter(typeof(StringEnumConverter))] public enum ChainNamespace { - EIP155, SOLANA + eip155, solana, other } public enum BuildEnv @@ -42,6 +44,7 @@ public enum Language private Dictionary initParams; private Web3AuthResponse web3AuthResponse; + private ProjectConfigResponse projectConfigResponse; private bool isRequestResponse = false; public event Action onLogin; @@ -64,7 +67,7 @@ public static void setSignResponse(SignResponse _response) private string redirectUri; [SerializeField] - private Web3Auth.Network network; + private Network network; private string redirectUrl; private static readonly Queue _executionQueue = new Queue(); @@ -125,22 +128,19 @@ public async void setOptions(Web3AuthOptions web3AuthOptions) if (this.web3AuthOptions.whiteLabel != null) this.initParams["whiteLabel"] = JsonConvert.SerializeObject(this.web3AuthOptions.whiteLabel, settings); - if (this.web3AuthOptions.loginConfig != null) - this.initParams["loginConfig"] = JsonConvert.SerializeObject(this.web3AuthOptions.loginConfig, settings); + if (this.web3AuthOptions.authConnectionConfig != null) + this.initParams["authConnectionConfig"] = JsonConvert.SerializeObject(this.web3AuthOptions.authConnectionConfig, settings); if (this.web3AuthOptions.clientId != null) this.initParams["clientId"] = this.web3AuthOptions.clientId; - if (this.web3AuthOptions.buildEnv != null) - this.initParams["buildEnv"] = this.web3AuthOptions.buildEnv.ToString().ToLower(); + if (this.web3AuthOptions.authBuildEnv != null) + this.initParams["authBuildEnv"] = this.web3AuthOptions.authBuildEnv.ToString().ToLower(); - this.initParams["network"] = this.web3AuthOptions.network.ToString().ToLower(); + this.initParams["network"] = this.web3AuthOptions.web3AuthNetwork.ToString().ToLower(); - if (this.web3AuthOptions.useCoreKitKey.HasValue) - this.initParams["useCoreKitKey"] = this.web3AuthOptions.useCoreKitKey.Value; - - if (this.web3AuthOptions.chainNamespace != null) - this.initParams["chainNamespace"] = this.web3AuthOptions.chainNamespace; + if (this.web3AuthOptions.useSFAKey.HasValue) + this.initParams["useCoreKitKey"] = this.web3AuthOptions.useSFAKey.Value; if (this.web3AuthOptions.mfaSettings != null) this.initParams["mfaSettings"] = JsonConvert.SerializeObject(this.web3AuthOptions.mfaSettings, settings); @@ -150,7 +150,6 @@ public async void setOptions(Web3AuthOptions web3AuthOptions) if (this.web3AuthOptions.dashboardUrl != null) this.initParams["dashboardUrl"] = this.web3AuthOptions.dashboardUrl; - } } @@ -238,10 +237,10 @@ private void IncomingHttpRequest(IAsyncResult result) "; - byte[] buffer = System.Text.Encoding.UTF8.GetBytes(responseString); + byte[] buffer = Encoding.UTF8.GetBytes(responseString); httpResponse.ContentLength64 = buffer.Length; - System.IO.Stream output = httpResponse.OutputStream; + Stream output = httpResponse.OutputStream; output.Write(buffer, 0, buffer.Length); output.Close(); @@ -251,10 +250,10 @@ private void IncomingHttpRequest(IAsyncResult result) { var responseString = @"ok"; - byte[] buffer = System.Text.Encoding.UTF8.GetBytes(responseString); + byte[] buffer = Encoding.UTF8.GetBytes(responseString); httpResponse.ContentLength64 = buffer.Length; - System.IO.Stream output = httpResponse.OutputStream; + Stream output = httpResponse.OutputStream; output.Write(buffer, 0, buffer.Length); output.Close(); string code = httpRequest.QueryString.Get("code"); @@ -283,12 +282,12 @@ private async void processRequest(string path, LoginParams loginParams = null) this.initParams["redirectUrl"] = Utils.GetCurrentURL(); #endif - loginParams.redirectUrl = loginParams.redirectUrl ?? new Uri(this.initParams["redirectUrl"].ToString()); + //loginParams.redirectUrl = loginParams.redirectUrl ?? new Uri(this.initParams["redirectUrl"].ToString()); //Debug.Log("loginParams.redirectUrl: =>" + loginParams.redirectUrl); var sessionId = KeyStoreManagerUtils.generateRandomSessionKey(); if(path == "manage_mfa") { loginParams.dappUrl = this.initParams["redirectUrl"].ToString(); - loginParams.redirectUrl = new Uri(this.initParams["dashboardUrl"].ToString()); + //loginParams.redirectUrl = new Uri(this.initParams["dashboardUrl"].ToString()); this.initParams["redirectUrl"] = new Uri(this.initParams["dashboardUrl"].ToString()); var loginIdObject = new Dictionary { @@ -314,7 +313,7 @@ private async void processRequest(string path, LoginParams loginParams = null) paramMap["sessionId"] = savedSessionId; } - //Debug.Log("paramMap: =>" + JsonConvert.SerializeObject(paramMap)); + Debug.Log("paramMap: =>" + JsonConvert.SerializeObject(paramMap)); string loginId = await createSession(JsonConvert.SerializeObject(paramMap, Formatting.None, new JsonSerializerSettings { @@ -353,71 +352,102 @@ private async void processRequest(string path, LoginParams loginParams = null) } } - public async void launchWalletServices(ChainConfig chainConfig, string path = "wallet") + public async void showWalletUI(string path = "wallet") { string sessionId = KeyStoreManagerUtils.getPreferencesData(KeyStoreManagerUtils.SESSION_ID); if (!string.IsNullOrEmpty(sessionId)) { - redirectUrl = this.initParams["redirectUrl"].ToString(); - if (redirectUrl.EndsWith("/")) - { - redirectUrl = redirectUrl.TrimEnd('/'); - } - #if UNITY_STANDALONE || UNITY_EDITOR - this.initParams["redirectUrl"] = StartLocalWebserver(); - redirectUrl = this.initParams["redirectUrl"].ToString().Replace("/complete/", ""); - #elif UNITY_WEBGL + redirectUrl = this.initParams["redirectUrl"].ToString(); + if (redirectUrl.EndsWith("/")) + { + redirectUrl = redirectUrl.TrimEnd('/'); + } +#if UNITY_STANDALONE || UNITY_EDITOR + this.initParams["redirectUrl"] = StartLocalWebserver(); + redirectUrl = this.initParams["redirectUrl"].ToString().Replace("/complete/", ""); +#elif UNITY_WEBGL this.initParams["redirectUrl"] = Utils.GetCurrentURL(); - #endif - - this.initParams["chainConfig"] = chainConfig; - Dictionary paramMap = new Dictionary(); - paramMap["options"] = this.initParams; +#endif - //Debug.Log("paramMap: =>" + JsonConvert.SerializeObject(paramMap)); - var newSessionId = KeyStoreManagerUtils.generateRandomSessionKey(); - string loginId = await createSession(JsonConvert.SerializeObject(paramMap, Formatting.None, - new JsonSerializerSettings + if (projectConfigResponse?.chains != null && projectConfigResponse.chains.Count > 0) + { + string chainsJson = JsonConvert.SerializeObject(projectConfigResponse.chains, Formatting.None, new JsonSerializerSettings + { + Converters = new List { new StringEnumConverter() }, + NullValueHandling = NullValueHandling.Ignore + }); + + this.initParams["chains"] = chainsJson; + + // Set defaultChainId and chainId based on the first chain + var firstChainId = projectConfigResponse.chains[0]?.chainId ?? web3AuthOptions.defaultChainId ?? "0x1"; + this.initParams["defaultChainId"] = firstChainId; + this.initParams["chainId"] = firstChainId; + } + else + { + // Fallback to web3AuthOptions.defaultChainId or "0x1" + string fallbackChainId = web3AuthOptions.defaultChainId ?? "0x1"; + this.initParams["defaultChainId"] = fallbackChainId; + this.initParams["chainId"] = fallbackChainId; + } + + if (projectConfigResponse?.embeddedWalletAuth != null) { - NullValueHandling = NullValueHandling.Ignore - }), 600, "*", newSessionId); - - if (!string.IsNullOrEmpty(loginId)) - { - var loginIdObject = new Dictionary - { - { "loginId", loginId }, - { "sessionId", sessionId }, - { "platform", "unity" } - }; - string hash = Convert.ToBase64String(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(loginIdObject, Formatting.None, + this.initParams["embeddedWalletAuth"] = projectConfigResponse.embeddedWalletAuth; + } + + if (projectConfigResponse?.smartAccounts != null) + { + this.initParams["smartAccounts"] = projectConfigResponse.smartAccounts; + } + Dictionary paramMap = new Dictionary(); + paramMap["options"] = this.initParams; + + //Debug.Log("paramMap: =>" + JsonConvert.SerializeObject(paramMap)); + var newSessionId = KeyStoreManagerUtils.generateRandomSessionKey(); + string loginId = await createSession(JsonConvert.SerializeObject(paramMap, Formatting.None, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore - }))); + }), 600, "*", newSessionId); - UriBuilder uriBuilder = new UriBuilder(this.web3AuthOptions.walletSdkUrl); - if(this.web3AuthOptions.sdkUrl.Contains("develop")) + if (!string.IsNullOrEmpty(loginId)) { - uriBuilder.Path = "/" + path; + var loginIdObject = new Dictionary + { + { "loginId", loginId }, + { "sessionId", sessionId }, + { "platform", "unity" } + }; + string hash = Convert.ToBase64String(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(loginIdObject, Formatting.None, + new JsonSerializerSettings + { + NullValueHandling = NullValueHandling.Ignore + }))); + + UriBuilder uriBuilder = new UriBuilder(this.web3AuthOptions.walletSdkUrl); + if(this.web3AuthOptions.sdkUrl.Contains("develop")) + { + uriBuilder.Path = "/" + path; + } + else + { + uriBuilder.Path += "/" + path; + } + uriBuilder.Fragment = "b64Params=" + hash; + //Debug.Log("finalUriBuilderToOpen: =>" + uriBuilder.ToString()); + isRequestResponse = false; + Utils.LaunchUrl(uriBuilder.ToString(), this.initParams["redirectUrl"].ToString(), gameObject.name); } else { - uriBuilder.Path += "/" + path; + throw new Exception("Some went wrong. Please try again later."); } - uriBuilder.Fragment = "b64Params=" + hash; - //Debug.Log("finalUriBuilderToOpen: =>" + uriBuilder.ToString()); - isRequestResponse = false; - Utils.LaunchUrl(uriBuilder.ToString(), this.initParams["redirectUrl"].ToString(), gameObject.name); - } - else + } else { - throw new Exception("Some went wrong. Please try again later."); + throw new Exception("SessionId not found. Please login first."); } - } else - { - throw new Exception("SessionId not found. Please login first."); - } } public void setResultUrl(Uri uri) @@ -518,16 +548,16 @@ private string decodeBase64Params(string base64Params) base64Params += d % 2 > 0 ? "=" : "=="; } byte[] bytes = Convert.FromBase64String(base64Params); - var decodedString = System.Text.Encoding.UTF8.GetString(bytes); + var decodedString = Encoding.UTF8.GetString(bytes); return decodedString; } public void login(LoginParams loginParams) { - if (web3AuthOptions.loginConfig != null) + if (web3AuthOptions.authConnectionConfig != null) { - var loginConfigItem = web3AuthOptions.loginConfig?.Values.First(); - var share = KeyStoreManagerUtils.getPreferencesData(loginConfigItem?.verifier); + var authConnectionItem = web3AuthOptions.authConnectionConfig?.FirstOrDefault(); + var share = KeyStoreManagerUtils.getPreferencesData(authConnectionItem?.authConnectionId); if (!string.IsNullOrEmpty(share)) { @@ -564,10 +594,10 @@ public void enableMFA(LoginParams loginParams) string sessionId = KeyStoreManagerUtils.getPreferencesData(KeyStoreManagerUtils.SESSION_ID); if (!string.IsNullOrEmpty(sessionId)) { - if (web3AuthOptions.loginConfig != null) + if (web3AuthOptions.authConnectionConfig != null) { - var loginConfigItem = web3AuthOptions.loginConfig?.Values.First(); - var share = KeyStoreManagerUtils.getPreferencesData(loginConfigItem?.verifier); + var authConnectionItem = web3AuthOptions.authConnectionConfig?.FirstOrDefault(); + var share = KeyStoreManagerUtils.getPreferencesData(authConnectionItem?.authConnectionId); if (!string.IsNullOrEmpty(share)) { loginParams.dappShare = share; @@ -590,10 +620,10 @@ public void manageMFA(LoginParams loginParams) string sessionId = KeyStoreManagerUtils.getPreferencesData(KeyStoreManagerUtils.SESSION_ID); if (!string.IsNullOrEmpty(sessionId)) { - if (web3AuthOptions.loginConfig != null) + if (web3AuthOptions.authConnectionConfig != null) { - var loginConfigItem = web3AuthOptions.loginConfig?.Values.First(); - var share = KeyStoreManagerUtils.getPreferencesData(loginConfigItem?.verifier); + var authConnectionItem = web3AuthOptions.authConnectionConfig?.FirstOrDefault(); + var share = KeyStoreManagerUtils.getPreferencesData(authConnectionItem?.authConnectionId); if (!string.IsNullOrEmpty(share)) { loginParams.dappShare = share; @@ -607,7 +637,7 @@ public void manageMFA(LoginParams loginParams) } } - public async void request(ChainConfig chainConfig, string method, JArray requestParams, string path = "wallet/request") { + public async void request(string method, JArray requestParams, string path = "wallet/request") { string sessionId = KeyStoreManagerUtils.getPreferencesData(KeyStoreManagerUtils.SESSION_ID); if (!string.IsNullOrEmpty(sessionId)) { @@ -615,19 +645,56 @@ public async void request(ChainConfig chainConfig, string method, JArray request if (redirectUrl.EndsWith("/")) { redirectUrl = redirectUrl.TrimEnd('/'); - } - #if UNITY_STANDALONE || UNITY_EDITOR + } +#if UNITY_STANDALONE || UNITY_EDITOR this.initParams["redirectUrl"] = StartLocalWebserver(); redirectUrl = this.initParams["redirectUrl"].ToString().Replace("/complete/", ""); - #elif UNITY_WEBGL +#elif UNITY_WEBGL this.initParams["redirectUrl"] = Utils.GetCurrentURL(); - #endif +#endif - this.initParams["chainConfig"] = chainConfig; + if (projectConfigResponse?.chains != null && projectConfigResponse.chains.Count > 0) + { + string chainsJson = JsonConvert.SerializeObject(projectConfigResponse.chains, Formatting.None, new JsonSerializerSettings + { + Converters = new List { new StringEnumConverter() }, + NullValueHandling = NullValueHandling.Ignore + }); + Debug.Log("Chain JSON:\n" + chainsJson); + this.initParams["chains"] = chainsJson; + + // Set defaultChainId and chainId based on the first chain + var firstChainId = projectConfigResponse.chains[0]?.chainId ?? web3AuthOptions.defaultChainId ?? "0x1"; + this.initParams["defaultChainId"] = firstChainId; + this.initParams["chainId"] = firstChainId; + } + else + { + // Fallback to web3AuthOptions.defaultChainId or "0x1" + string fallbackChainId = web3AuthOptions.defaultChainId ?? "0x1"; + this.initParams["defaultChainId"] = fallbackChainId; + this.initParams["chainId"] = fallbackChainId; + } + + if (projectConfigResponse?.embeddedWalletAuth != null) + { + this.initParams["embeddedWalletAuth"] = projectConfigResponse.embeddedWalletAuth; + } + + if (projectConfigResponse?.smartAccounts != null) + { + this.initParams["smartAccounts"] = projectConfigResponse.smartAccounts; + } Dictionary paramMap = new Dictionary(); paramMap["options"] = this.initParams; + foreach (KeyValuePair entry in paramMap) + { + Debug.Log($"Key: {entry.Key}, Value: {JsonUtility.ToJson(entry.Value)}"); + } + var newSessionId = KeyStoreManagerUtils.generateRandomSessionKey(); + //Debug.Log("paramMap durinr request func: =>" + JsonConvert.SerializeObject(paramMap)); string loginId = await createSession(JsonConvert.SerializeObject(paramMap, Formatting.None, new JsonSerializerSettings { @@ -686,7 +753,7 @@ private void authorizeSession(string newSessionId, string origin) if (string.IsNullOrEmpty(newSessionId)) { sessionId = KeyStoreManagerUtils.getPreferencesData(KeyStoreManagerUtils.SESSION_ID); - Debug.Log("sessionId during authorizeSession in if part =>" + sessionId); + //Debug.Log("sessionId during authorizeSession in if part =>" + sessionId); } else { @@ -699,9 +766,9 @@ private void authorizeSession(string newSessionId, string origin) //Debug.Log("origin: =>" + origin); StartCoroutine(Web3AuthApi.getInstance().authorizeSession(pubKey, origin, (response => { - if (response != null) + if (response != null && !string.IsNullOrEmpty(response.message)) { - var shareMetadata = Newtonsoft.Json.JsonConvert.DeserializeObject(response.message); + var shareMetadata = JsonConvert.DeserializeObject(response.message); var aes256cbc = new AES256CBC( sessionId, @@ -711,7 +778,7 @@ private void authorizeSession(string newSessionId, string origin) var encryptedShareBytes = AES256CBC.toByteArray(new BigInteger(shareMetadata.ciphertext, 16)); var share = aes256cbc.decrypt(encryptedShareBytes, shareMetadata.mac); - var tempJson = JsonConvert.DeserializeObject(System.Text.Encoding.UTF8.GetString(share)); + var tempJson = JsonConvert.DeserializeObject(Encoding.UTF8.GetString(share)); this.web3AuthResponse = JsonConvert.DeserializeObject(tempJson.ToString()); if (this.web3AuthResponse != null) @@ -730,11 +797,11 @@ private void authorizeSession(string newSessionId, string origin) if (!string.IsNullOrEmpty(web3AuthResponse.userInfo?.dappShare)) { KeyStoreManagerUtils.savePreferenceData( - web3AuthResponse.userInfo?.verifier, web3AuthResponse.userInfo?.dappShare + web3AuthResponse.userInfo?.authConnectionId, web3AuthResponse.userInfo?.dappShare ); } - if (string.IsNullOrEmpty(this.web3AuthResponse.privKey) || string.IsNullOrEmpty(this.web3AuthResponse.privKey.Trim('0'))) + if (string.IsNullOrEmpty(this.web3AuthResponse.privateKey) || string.IsNullOrEmpty(this.web3AuthResponse.privateKey.Trim('0'))) this.Enqueue(() => this.onLogout?.Invoke()); else this.Enqueue(() => this.onLogin?.Invoke(this.web3AuthResponse)); @@ -757,7 +824,7 @@ private void sessionTimeOutAPI() { if (response != null) { - var shareMetadata = Newtonsoft.Json.JsonConvert.DeserializeObject(response.message); + var shareMetadata = JsonConvert.DeserializeObject(response.message); var aes256cbc = new AES256CBC( sessionId, @@ -765,7 +832,7 @@ private void sessionTimeOutAPI() shareMetadata.iv ); - var encryptedData = aes256cbc.encrypt(System.Text.Encoding.UTF8.GetBytes("")); + var encryptedData = aes256cbc.encrypt(Encoding.UTF8.GetBytes("")); var encryptedMetadata = new ShareMetadata() { iv = shareMetadata.iv, @@ -792,8 +859,8 @@ private void sessionTimeOutAPI() try { KeyStoreManagerUtils.deletePreferencesData(KeyStoreManagerUtils.SESSION_ID); - if (web3AuthOptions.loginConfig != null) - KeyStoreManagerUtils.deletePreferencesData(web3AuthOptions.loginConfig?.Values.First()?.verifier); + if (web3AuthOptions.authConnectionConfig != null) + KeyStoreManagerUtils.deletePreferencesData(web3AuthOptions.authConnectionConfig?.FirstOrDefault()?.authConnectionId); this.Enqueue(() => this.onLogout?.Invoke()); } @@ -822,7 +889,7 @@ private async Task createSession(string data, long sessionTime, string a ephemKey, KeyStoreManagerUtils.convertByteToHexadecimal(ivKey) ); - var encryptedData = aes256cbc.encrypt(System.Text.Encoding.UTF8.GetBytes(data)); + var encryptedData = aes256cbc.encrypt(Encoding.UTF8.GetBytes(data)); var mac = aes256cbc.getMac(encryptedData); var encryptedMetadata = new ShareMetadata() { @@ -870,22 +937,26 @@ private async Task createSession(string data, long sessionTime, string a private async Task fetchProjectConfig() { TaskCompletionSource fetchProjectConfigResponse = new TaskCompletionSource(); - StartCoroutine(Web3AuthApi.getInstance().fetchProjectConfig(this.web3AuthOptions.clientId, this.web3AuthOptions.network.ToString().ToLower(), (response => + StartCoroutine(Web3AuthApi.getInstance().fetchProjectConfig(this.web3AuthOptions.clientId, this.web3AuthOptions.web3AuthNetwork.ToString().ToLower(), + this.web3AuthOptions.authBuildEnv.ToString().ToLower(), (response => { + projectConfigResponse = response; if (response != null) { this.web3AuthOptions.originData = this.web3AuthOptions.originData.mergeMaps(response.whitelist?.signed_urls); if (response?.whitelabel != null) - { - if (this.web3AuthOptions.whiteLabel == null) - { - this.web3AuthOptions.whiteLabel = response.whitelabel; - } - else - { - this.web3AuthOptions.whiteLabel = this.web3AuthOptions.whiteLabel?.merge(response.whitelabel); - } - } + { + var whitelabel = response.whitelabel; + + this.web3AuthOptions.whiteLabel = this.web3AuthOptions.whiteLabel?.merge(whitelabel) ?? whitelabel; + + if (this.web3AuthOptions.walletServicesConfig != null) + { + this.web3AuthOptions.walletServicesConfig.whiteLabel = + this.web3AuthOptions.walletServicesConfig.whiteLabel?.merge(whitelabel) ?? whitelabel; + } + } + //Debug.Log("this.web3AuthOptions: =>" + JsonConvert.SerializeObject(this.web3AuthOptions)); JsonSerializerSettings settings = new JsonSerializerSettings @@ -899,7 +970,7 @@ private async Task fetchProjectConfig() if(this.web3AuthOptions.originData != null) this.initParams["originData"] = JsonConvert.SerializeObject(this.web3AuthOptions.originData, settings); - fetchProjectConfigResponse.SetResult(true); + fetchProjectConfigResponse.SetResult(true); } else { @@ -910,20 +981,20 @@ private async Task fetchProjectConfig() return await fetchProjectConfigResponse.Task; } - public string getPrivKey() + public string getPrivateKey() { if (web3AuthResponse == null) return ""; - return web3AuthOptions.useCoreKitKey.Value ? web3AuthResponse.coreKitKey : web3AuthResponse.privKey; + return web3AuthOptions.useSFAKey.Value ? web3AuthResponse.coreKitKey : web3AuthResponse.privateKey; } - public string getEd25519PrivKey() + public string getEd25519PrivateKey() { if (web3AuthResponse == null) return ""; - return web3AuthOptions.useCoreKitKey.Value ? web3AuthResponse.coreKitEd25519PrivKey : web3AuthResponse.ed25519PrivKey; + return web3AuthOptions.useSFAKey.Value ? web3AuthResponse.coreKitEd25519PrivKey : web3AuthResponse.ed25519PrivateKey; } public UserInfo getUserInfo()