From 21a213353bdde43ad7e1d25d39999926a6807d13 Mon Sep 17 00:00:00 2001 From: Gaurav Goel Date: Fri, 3 May 2024 15:17:11 +0530 Subject: [PATCH 01/15] feat: added fetch project config api and sms-passwordless example with ui Signed-off-by: Gaurav Goel --- .../java/com/web3auth/app/MainActivity.kt | 20 ++++- core/src/main/java/com/web3auth/core/Utils.kt | 18 +++++ .../main/java/com/web3auth/core/Web3Auth.kt | 77 +++++++++++++++++++ .../java/com/web3auth/core/api/ApiHelper.kt | 38 +++++++++ .../java/com/web3auth/core/api/ApiService.kt | 15 ++++ .../web3auth/core/types/LoginConfigItem.kt | 24 +++--- .../core/types/ProjectConfigResponse.kt | 18 +++++ .../java/com/web3auth/core/types/Provider.kt | 14 +++- .../web3auth/core/types/Web3AuthOptions.kt | 2 +- .../com/web3auth/core/types/WhiteLabelData.kt | 16 ++-- 10 files changed, 217 insertions(+), 25 deletions(-) create mode 100644 core/src/main/java/com/web3auth/core/api/ApiService.kt create mode 100644 core/src/main/java/com/web3auth/core/types/ProjectConfigResponse.kt diff --git a/app/src/main/java/com/web3auth/app/MainActivity.kt b/app/src/main/java/com/web3auth/app/MainActivity.kt index 2947417..c680083 100644 --- a/app/src/main/java/com/web3auth/app/MainActivity.kt +++ b/app/src/main/java/com/web3auth/app/MainActivity.kt @@ -14,6 +14,7 @@ import com.google.gson.Gson import com.google.gson.JsonArray import com.web3auth.core.Web3Auth import com.web3auth.core.isEmailValid +import com.web3auth.core.isPhoneNumberValid import com.web3auth.core.types.* import org.json.JSONObject import org.web3j.crypto.Credentials @@ -36,7 +37,10 @@ class MainActivity : AppCompatActivity(), AdapterView.OnItemClickListener { LoginVerifier("LinkedIn", Provider.LINKEDIN), LoginVerifier("Twitter", Provider.TWITTER), LoginVerifier("Line", Provider.LINE), - LoginVerifier("Hosted Email Passwordless", Provider.EMAIL_PASSWORDLESS) + LoginVerifier("Hosted Email Passwordless", Provider.EMAIL_PASSWORDLESS), + LoginVerifier("SMS Passwordless", Provider.SMS_PASSWORDLESS), + LoginVerifier("JWT", Provider.JWT), + LoginVerifier("Farcaster", Provider.FARCASTER) ) private var selectedLoginProvider: Provider = Provider.GOOGLE @@ -54,6 +58,16 @@ class MainActivity : AppCompatActivity(), AdapterView.OnItemClickListener { } extraLoginOptions = ExtraLoginOptions(login_hint = hintEmail) } + + if (selectedLoginProvider == Provider.SMS_PASSWORDLESS) { + val hintPhNo = hintEmailEditText.text.toString() + if (hintPhNo.isBlank() || !hintPhNo.isPhoneNumberValid()) { + Toast.makeText(this, "Please enter a valid Number.", Toast.LENGTH_LONG).show() + return + } + extraLoginOptions = ExtraLoginOptions(login_hint = hintPhNo) + } + val loginCompletableFuture: CompletableFuture = web3Auth.login( LoginParams( selectedLoginProvider, @@ -148,7 +162,7 @@ class MainActivity : AppCompatActivity(), AdapterView.OnItemClickListener { "loginConfig" to LoginConfigItem( "web3auth-auth0-email-passwordless-sapphire-devnet", typeOfLogin = TypeOfLogin.JWT, - clientId = "d84f6xvbdV75VTGmHiMWfZLeSPk8M07C" + clientId = "d84f6xvbdV75VTGmHiMWfZLeSPk8M07C", ) ), buildEnv = BuildEnv.TESTING, @@ -288,7 +302,7 @@ class MainActivity : AppCompatActivity(), AdapterView.OnItemClickListener { selectedLoginProvider = verifierList[p2].loginProvider val hintEmailEditText = findViewById(R.id.etEmailHint) - if (selectedLoginProvider == Provider.EMAIL_PASSWORDLESS) { + if (selectedLoginProvider == Provider.EMAIL_PASSWORDLESS || selectedLoginProvider == Provider.SMS_PASSWORDLESS) { hintEmailEditText.visibility = View.VISIBLE } else { hintEmailEditText.visibility = View.GONE diff --git a/core/src/main/java/com/web3auth/core/Utils.kt b/core/src/main/java/com/web3auth/core/Utils.kt index c7255c9..9334c34 100644 --- a/core/src/main/java/com/web3auth/core/Utils.kt +++ b/core/src/main/java/com/web3auth/core/Utils.kt @@ -7,6 +7,7 @@ import android.net.Uri import android.util.Base64 import android.util.Patterns import androidx.browser.customtabs.CustomTabsService +import com.web3auth.core.types.WhiteLabelData const val BASE64_URL_FLAGS = Base64.URL_SAFE or Base64.NO_WRAP or Base64.NO_PADDING @@ -41,6 +42,10 @@ fun String.isEmailValid(): Boolean { return Patterns.EMAIL_ADDRESS.matcher(this).matches() } +fun String.isPhoneNumberValid(): Boolean { + return Patterns.PHONE.matcher(this).matches() +} + fun Context.getDefaultBrowser(): String? { val intent = Intent(Intent.ACTION_VIEW, Uri.parse("https://web3auth.io")) val resolveInfo = packageManager.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY) @@ -62,4 +67,17 @@ fun Context.getCustomTabsBrowsers(): List { } } return customTabsBrowsers +} + +fun WhiteLabelData.merge(other: WhiteLabelData): WhiteLabelData { + return WhiteLabelData( + appName = other.appName ?: this.appName, + appUrl = other.appUrl ?: this.appUrl, + logoLight = other.logoLight ?: this.logoLight, + logoDark = other.logoDark ?: this.logoDark, + defaultLanguage = other.defaultLanguage ?: this.defaultLanguage, + mode = other.mode ?: this.mode, + useLogoLoader = other.useLogoLoader ?: this.useLogoLoader, + theme = other.theme ?: this.theme + ) } \ No newline at end of file diff --git a/core/src/main/java/com/web3auth/core/Web3Auth.kt b/core/src/main/java/com/web3auth/core/Web3Auth.kt index 47da40e..5de49ee 100644 --- a/core/src/main/java/com/web3auth/core/Web3Auth.kt +++ b/core/src/main/java/com/web3auth/core/Web3Auth.kt @@ -2,14 +2,20 @@ package com.web3auth.core import android.content.Intent import android.net.Uri +import android.os.Handler +import android.os.Looper import androidx.browser.customtabs.CustomTabsIntent +import androidx.core.os.postDelayed import com.google.gson.GsonBuilder import com.google.gson.JsonArray import com.google.gson.JsonObject import com.web3auth.core.api.ApiHelper +import com.web3auth.core.api.ApiService import com.web3auth.core.keystore.KeyStoreManagerUtils import com.web3auth.core.types.* import com.web3auth.session_manager_android.SessionManager +import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.launch import org.json.JSONObject import java.util.* import java.util.concurrent.CompletableFuture @@ -24,6 +30,7 @@ class Web3Auth(web3AuthOptions: Web3AuthOptions) { private var web3AuthResponse: Web3AuthResponse? = null private var web3AuthOption = web3AuthOptions private var sessionManager: SessionManager = SessionManager(web3AuthOption.context) + private var projectConfigResponse: ProjectConfigResponse? = null /** * Initializes the KeyStoreManager. @@ -100,6 +107,25 @@ class Web3Auth(web3AuthOptions: Web3AuthOptions) { val initOptions = getInitOptions() val initParams = getInitParams(params) + if (params?.loginProvider == Provider.SMS_PASSWORDLESS) { + if (initOptions.has("loginConfig")) { + val loginConfigJson = initOptions.getString("loginConfig") + val jsonObject = JSONObject(loginConfigJson) + val loginConfigObject = jsonObject.getJSONObject("loginConfig") + val loginConfigItem = + gson.fromJson(loginConfigObject.toString(), LoginConfigItem::class.java) + projectConfigResponse?.sms_otp_enabled?.let { smsOtpEnabled -> + loginConfigItem.showOnMobile = smsOtpEnabled + loginConfigItem.showOnDesktop = smsOtpEnabled + loginConfigItem.showOnModal = smsOtpEnabled + initOptions.put( + "loginConfig", + gson.toJson(mapOf("loginConfig" to loginConfigItem)) + ) + } + } + } + val paramMap = JSONObject() paramMap.put( "options", initOptions @@ -165,6 +191,19 @@ class Web3Auth(web3AuthOptions: Web3AuthOptions) { //initiate keyStore initiateKeyStoreManager() + //fetch project config + fetchProjectConfig().whenComplete { response, error -> + if (error == null) { + projectConfigResponse = response + if (response?.whiteLabelData != null) { + web3AuthOption.whiteLabel = + web3AuthOption.whiteLabel?.merge(response.whiteLabelData) + } + } else { + initializeCf.completeExceptionally(Exception(Web3AuthError.getError(ErrorCode.SOMETHING_WENT_WRONG))) + } + } + //authorize session if (ApiHelper.isNetworkAvailable(web3AuthOption.context)) { this.authorizeSession().whenComplete { resp, error -> @@ -367,6 +406,44 @@ class Web3Auth(web3AuthOptions: Web3AuthOptions) { return sessionCompletableFuture } + private fun fetchProjectConfig(): CompletableFuture { + val projectConfigCompletableFuture: CompletableFuture = + CompletableFuture() + val web3AuthApi = + ApiHelper.getInstance(web3AuthOption.network.name).create(ApiService::class.java) + GlobalScope.launch { + try { + val result = web3AuthApi.fetchProjectConfig( + web3AuthOption.clientId, + web3AuthOption.network.name + ) + if (result.isSuccessful && result.body() != null) { + Handler(Looper.getMainLooper()).postDelayed(10) { + projectConfigCompletableFuture.complete(result.body()) + } + } else { + projectConfigCompletableFuture.completeExceptionally( + Exception( + Web3AuthError.getError( + ErrorCode.RUNTIME_ERROR + ) + ) + ) + } + } catch (ex: Exception) { + ex.printStackTrace() + projectConfigCompletableFuture.completeExceptionally( + Exception( + Web3AuthError.getError( + ErrorCode.SOMETHING_WENT_WRONG + ) + ) + ) + } + } + return projectConfigCompletableFuture + } + /** * Retrieves the login ID from the provided JSONObject asynchronously. * diff --git a/core/src/main/java/com/web3auth/core/api/ApiHelper.kt b/core/src/main/java/com/web3auth/core/api/ApiHelper.kt index c27818b..2b7228b 100644 --- a/core/src/main/java/com/web3auth/core/api/ApiHelper.kt +++ b/core/src/main/java/com/web3auth/core/api/ApiHelper.kt @@ -4,9 +4,47 @@ import android.content.Context import android.net.ConnectivityManager import android.net.NetworkCapabilities import android.os.Build +import com.google.gson.GsonBuilder +import com.web3auth.core.types.Network +import com.web3auth.session_manager_android.BuildConfig +import okhttp3.OkHttpClient +import okhttp3.logging.HttpLoggingInterceptor +import retrofit2.Retrofit +import retrofit2.converter.gson.GsonConverterFactory +import java.util.concurrent.TimeUnit object ApiHelper { + val SIGNER_MAP: Map = mapOf( + Network.MAINNET to "https://signer.web3auth.io", + Network.TESTNET to "https://signer.web3auth.io", + Network.CYAN to "https://signer-polygon.web3auth.io", + Network.AQUA to "https://signer-polygon.web3auth.io", + Network.SAPPHIRE_MAINNET to "https://signer.web3auth.io", + Network.SAPPHIRE_DEVNET to "https://signer.web3auth.io" + ) + + private const val baseUrl = "https://session.web3auth.io" + + private val okHttpClient = OkHttpClient().newBuilder() + .readTimeout(60, TimeUnit.SECONDS) + .connectTimeout(20, TimeUnit.SECONDS) + .addInterceptor(HttpLoggingInterceptor().apply { + if (BuildConfig.DEBUG) { + level = HttpLoggingInterceptor.Level.BODY + } + }) + .build() + + private val builder = GsonBuilder().disableHtmlEscaping().create() + + fun getInstance(network: String): Retrofit { + return Retrofit.Builder().baseUrl(SIGNER_MAP[Network.valueOf(network)]) + .addConverterFactory(GsonConverterFactory.create(builder)) + .client(okHttpClient) + .build() + } + fun isNetworkAvailable(context: Context?): Boolean { if (context == null) return false val connectivityManager = diff --git a/core/src/main/java/com/web3auth/core/api/ApiService.kt b/core/src/main/java/com/web3auth/core/api/ApiService.kt new file mode 100644 index 0000000..84eb069 --- /dev/null +++ b/core/src/main/java/com/web3auth/core/api/ApiService.kt @@ -0,0 +1,15 @@ +package com.web3auth.core.api + +import com.web3auth.core.types.ProjectConfigResponse +import retrofit2.Response +import retrofit2.http.GET +import retrofit2.http.Query + +interface ApiService { + + @GET("/api/configuration") + suspend fun fetchProjectConfig( + @Query("project_id") project_id: String, @Query("network") network: String, + @Query("whitelist") whitelist: String = "true" + ): Response +} \ No newline at end of file diff --git a/core/src/main/java/com/web3auth/core/types/LoginConfigItem.kt b/core/src/main/java/com/web3auth/core/types/LoginConfigItem.kt index 423b3fd..83bdb8d 100644 --- a/core/src/main/java/com/web3auth/core/types/LoginConfigItem.kt +++ b/core/src/main/java/com/web3auth/core/types/LoginConfigItem.kt @@ -2,16 +2,16 @@ package com.web3auth.core.types data class LoginConfigItem( var verifier: String, - private var typeOfLogin: TypeOfLogin, - private var name: String? = null, - private var description: String? = null, - private var clientId: String, - private var verifierSubIdentifier: String? = null, - private var logoHover: String? = null, - private var logoLight: String? = null, - private var logoDark: String? = null, - private var mainOption: Boolean? = false, - private var showOnModal: Boolean? = true, - private var showOnDesktop: Boolean? = true, - private var showOnMobile: Boolean? = true, + var typeOfLogin: TypeOfLogin, + var name: String? = null, + var description: String? = null, + var clientId: String, + var verifierSubIdentifier: String? = null, + var logoHover: String? = null, + var logoLight: String? = null, + var logoDark: String? = null, + var mainOption: Boolean? = false, + var showOnModal: Boolean? = true, + var showOnDesktop: Boolean? = true, + var showOnMobile: Boolean? = true, ) \ No newline at end of file diff --git a/core/src/main/java/com/web3auth/core/types/ProjectConfigResponse.kt b/core/src/main/java/com/web3auth/core/types/ProjectConfigResponse.kt new file mode 100644 index 0000000..2e3f65b --- /dev/null +++ b/core/src/main/java/com/web3auth/core/types/ProjectConfigResponse.kt @@ -0,0 +1,18 @@ +package com.web3auth.core.types + +import androidx.annotation.Keep + +@Keep +data class WhitelistResponse( + val urls: List, + val signed_urls: Map +) + +@Keep +data class ProjectConfigResponse( + val whiteLabelData: WhiteLabelData? = null, + val sms_otp_enabled: Boolean, + val wallet_connect_enabled: Boolean, + val wallet_connect_project_id: String?, + val whitelist: WhitelistResponse?, +) diff --git a/core/src/main/java/com/web3auth/core/types/Provider.kt b/core/src/main/java/com/web3auth/core/types/Provider.kt index ec6394d..e334e1b 100644 --- a/core/src/main/java/com/web3auth/core/types/Provider.kt +++ b/core/src/main/java/com/web3auth/core/types/Provider.kt @@ -21,16 +21,28 @@ enum class Provider { GITHUB, @SerializedName("kakao") KAKAO, + @SerializedName("linkedin") LINKEDIN, + @SerializedName("twitter") TWITTER, + @SerializedName("weibo") WEIBO, + @SerializedName("wechat") WECHAT, + @SerializedName("email_passwordless") EMAIL_PASSWORDLESS, + + @SerializedName("sms_passwordless") + SMS_PASSWORDLESS, + @SerializedName("jwt") - JWT + JWT, + + @SerializedName("farcaster") + FARCASTER } \ No newline at end of file diff --git a/core/src/main/java/com/web3auth/core/types/Web3AuthOptions.kt b/core/src/main/java/com/web3auth/core/types/Web3AuthOptions.kt index 702df52..77437b5 100644 --- a/core/src/main/java/com/web3auth/core/types/Web3AuthOptions.kt +++ b/core/src/main/java/com/web3auth/core/types/Web3AuthOptions.kt @@ -10,7 +10,7 @@ data class Web3AuthOptions( var buildEnv: BuildEnv? = BuildEnv.PRODUCTION, @Transient var redirectUrl: Uri? = null, var sdkUrl: String = getSdkUrl(buildEnv), - val whiteLabel: WhiteLabelData? = null, + var whiteLabel: WhiteLabelData? = null, val loginConfig: HashMap? = null, val useCoreKitKey: Boolean? = false, val chainNamespace: ChainNamespace? = ChainNamespace.EIP155, diff --git a/core/src/main/java/com/web3auth/core/types/WhiteLabelData.kt b/core/src/main/java/com/web3auth/core/types/WhiteLabelData.kt index 56e0942..205db54 100644 --- a/core/src/main/java/com/web3auth/core/types/WhiteLabelData.kt +++ b/core/src/main/java/com/web3auth/core/types/WhiteLabelData.kt @@ -1,12 +1,12 @@ package com.web3auth.core.types data class WhiteLabelData( - private var appName: String? = null, - private var appUrl: String? = null, - private var logoLight: String? = null, - private var logoDark: String? = null, - private var defaultLanguage: Language? = Language.EN, - private var mode: ThemeModes? = null, - private var useLogoLoader: Boolean? = false, - private var theme: HashMap? = null + var appName: String? = null, + var appUrl: String? = null, + var logoLight: String? = null, + var logoDark: String? = null, + var defaultLanguage: Language? = Language.EN, + var mode: ThemeModes? = null, + var useLogoLoader: Boolean? = false, + var theme: HashMap? = null ) \ No newline at end of file From 168fdc6b19ed9965d78a065793e3f7327ab43037 Mon Sep 17 00:00:00 2001 From: Gaurav Goel Date: Fri, 3 May 2024 15:19:13 +0530 Subject: [PATCH 02/15] feat: minor updates Signed-off-by: Gaurav Goel --- app/src/main/java/com/web3auth/app/MainActivity.kt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/src/main/java/com/web3auth/app/MainActivity.kt b/app/src/main/java/com/web3auth/app/MainActivity.kt index c680083..a33e7e6 100644 --- a/app/src/main/java/com/web3auth/app/MainActivity.kt +++ b/app/src/main/java/com/web3auth/app/MainActivity.kt @@ -302,6 +302,13 @@ class MainActivity : AppCompatActivity(), AdapterView.OnItemClickListener { selectedLoginProvider = verifierList[p2].loginProvider val hintEmailEditText = findViewById(R.id.etEmailHint) + + if (selectedLoginProvider == Provider.EMAIL_PASSWORDLESS) { + hintEmailEditText.hint = "Enter Email" + } else if (selectedLoginProvider == Provider.SMS_PASSWORDLESS) { + hintEmailEditText.hint = "Enter Phone Number" + } + if (selectedLoginProvider == Provider.EMAIL_PASSWORDLESS || selectedLoginProvider == Provider.SMS_PASSWORDLESS) { hintEmailEditText.visibility = View.VISIBLE } else { From df1da4f8fe712e1b94b2a2c431bdcf81d1f446b3 Mon Sep 17 00:00:00 2001 From: Gaurav Goel Date: Mon, 6 May 2024 09:40:51 +0530 Subject: [PATCH 03/15] feat: minor updates Signed-off-by: Gaurav Goel --- .../main/java/com/web3auth/core/Web3Auth.kt | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/core/src/main/java/com/web3auth/core/Web3Auth.kt b/core/src/main/java/com/web3auth/core/Web3Auth.kt index 5de49ee..9159067 100644 --- a/core/src/main/java/com/web3auth/core/Web3Auth.kt +++ b/core/src/main/java/com/web3auth/core/Web3Auth.kt @@ -107,25 +107,6 @@ class Web3Auth(web3AuthOptions: Web3AuthOptions) { val initOptions = getInitOptions() val initParams = getInitParams(params) - if (params?.loginProvider == Provider.SMS_PASSWORDLESS) { - if (initOptions.has("loginConfig")) { - val loginConfigJson = initOptions.getString("loginConfig") - val jsonObject = JSONObject(loginConfigJson) - val loginConfigObject = jsonObject.getJSONObject("loginConfig") - val loginConfigItem = - gson.fromJson(loginConfigObject.toString(), LoginConfigItem::class.java) - projectConfigResponse?.sms_otp_enabled?.let { smsOtpEnabled -> - loginConfigItem.showOnMobile = smsOtpEnabled - loginConfigItem.showOnDesktop = smsOtpEnabled - loginConfigItem.showOnModal = smsOtpEnabled - initOptions.put( - "loginConfig", - gson.toJson(mapOf("loginConfig" to loginConfigItem)) - ) - } - } - } - val paramMap = JSONObject() paramMap.put( "options", initOptions From d4661e90432cfa90f9293996ef28502217b26f9a Mon Sep 17 00:00:00 2001 From: Gaurav Goel Date: Thu, 9 May 2024 12:14:12 +0530 Subject: [PATCH 04/15] feat: added originData in web3AuthOptions constructors Signed-off-by: Gaurav Goel --- core/src/main/java/com/web3auth/core/Web3Auth.kt | 4 ++++ core/src/main/java/com/web3auth/core/types/Web3AuthOptions.kt | 1 + 2 files changed, 5 insertions(+) diff --git a/core/src/main/java/com/web3auth/core/Web3Auth.kt b/core/src/main/java/com/web3auth/core/Web3Auth.kt index 9159067..5d1763b 100644 --- a/core/src/main/java/com/web3auth/core/Web3Auth.kt +++ b/core/src/main/java/com/web3auth/core/Web3Auth.kt @@ -61,6 +61,9 @@ class Web3Auth(web3AuthOptions: Web3AuthOptions) { if (web3AuthOption.sessionTime != null) initOptions.put( "sessionTime", web3AuthOption.sessionTime ) + if (web3AuthOption.originData != null) initOptions.put( + "originData", gson.toJson(web3AuthOption.originData) + ) return initOptions } @@ -176,6 +179,7 @@ class Web3Auth(web3AuthOptions: Web3AuthOptions) { fetchProjectConfig().whenComplete { response, error -> if (error == null) { projectConfigResponse = response + web3AuthOption.originData = response.whitelist?.signed_urls if (response?.whiteLabelData != null) { web3AuthOption.whiteLabel = web3AuthOption.whiteLabel?.merge(response.whiteLabelData) diff --git a/core/src/main/java/com/web3auth/core/types/Web3AuthOptions.kt b/core/src/main/java/com/web3auth/core/types/Web3AuthOptions.kt index 77437b5..27875ff 100644 --- a/core/src/main/java/com/web3auth/core/types/Web3AuthOptions.kt +++ b/core/src/main/java/com/web3auth/core/types/Web3AuthOptions.kt @@ -17,6 +17,7 @@ data class Web3AuthOptions( val mfaSettings: MfaSettings? = null, val sessionTime: Int? = 86400, var walletSdkUrl: String? = getWalletSdkUrl(buildEnv), + var originData: Map? = null ) fun getSdkUrl(buildEnv: BuildEnv?): String { From ce2009a475f539e8c92a1c0e11dc27b5f6b0433c Mon Sep 17 00:00:00 2001 From: Gaurav Goel Date: Fri, 10 May 2024 12:23:00 +0530 Subject: [PATCH 05/15] feat: minor changes Signed-off-by: Gaurav Goel --- core/src/main/java/com/web3auth/core/Web3Auth.kt | 2 -- 1 file changed, 2 deletions(-) diff --git a/core/src/main/java/com/web3auth/core/Web3Auth.kt b/core/src/main/java/com/web3auth/core/Web3Auth.kt index 5d1763b..68d1f94 100644 --- a/core/src/main/java/com/web3auth/core/Web3Auth.kt +++ b/core/src/main/java/com/web3auth/core/Web3Auth.kt @@ -30,7 +30,6 @@ class Web3Auth(web3AuthOptions: Web3AuthOptions) { private var web3AuthResponse: Web3AuthResponse? = null private var web3AuthOption = web3AuthOptions private var sessionManager: SessionManager = SessionManager(web3AuthOption.context) - private var projectConfigResponse: ProjectConfigResponse? = null /** * Initializes the KeyStoreManager. @@ -178,7 +177,6 @@ class Web3Auth(web3AuthOptions: Web3AuthOptions) { //fetch project config fetchProjectConfig().whenComplete { response, error -> if (error == null) { - projectConfigResponse = response web3AuthOption.originData = response.whitelist?.signed_urls if (response?.whiteLabelData != null) { web3AuthOption.whiteLabel = From d6d08eb04b67736072734d3b922267eeed42a091 Mon Sep 17 00:00:00 2001 From: Gaurav Goel Date: Mon, 13 May 2024 13:24:33 +0530 Subject: [PATCH 06/15] feat: resolved PR comments Signed-off-by: Gaurav Goel --- core/src/main/java/com/web3auth/core/Utils.kt | 34 +++++++++++++++++-- .../main/java/com/web3auth/core/Web3Auth.kt | 34 ++++++++----------- .../java/com/web3auth/core/api/ApiHelper.kt | 2 +- .../com/web3auth/core/types/WhiteLabelData.kt | 2 +- 4 files changed, 48 insertions(+), 24 deletions(-) diff --git a/core/src/main/java/com/web3auth/core/Utils.kt b/core/src/main/java/com/web3auth/core/Utils.kt index 9334c34..e11eaed 100644 --- a/core/src/main/java/com/web3auth/core/Utils.kt +++ b/core/src/main/java/com/web3auth/core/Utils.kt @@ -70,6 +70,16 @@ fun Context.getCustomTabsBrowsers(): List { } fun WhiteLabelData.merge(other: WhiteLabelData): WhiteLabelData { + val mergedTheme = HashMap() + this.theme.let { + if (it != null) { + mergedTheme.putAll(it) + } + } + other.theme?.forEach { (key, value) -> + mergedTheme[key] = value ?: mergedTheme[key] + } + return WhiteLabelData( appName = other.appName ?: this.appName, appUrl = other.appUrl ?: this.appUrl, @@ -78,6 +88,26 @@ fun WhiteLabelData.merge(other: WhiteLabelData): WhiteLabelData { defaultLanguage = other.defaultLanguage ?: this.defaultLanguage, mode = other.mode ?: this.mode, useLogoLoader = other.useLogoLoader ?: this.useLogoLoader, - theme = other.theme ?: this.theme + theme = mergedTheme ) -} \ No newline at end of file +} + +fun Map?.mergeMaps(other: Map?): Map? { + if (this == null && other == null) { + return null + } else if (this == null) { + return other + } else if (other == null) { + return this + } + + val mergedMap = LinkedHashMap() + mergedMap.putAll(this) + + other.forEach { (key, value) -> + mergedMap[key] = value + } + + return mergedMap +} + diff --git a/core/src/main/java/com/web3auth/core/Web3Auth.kt b/core/src/main/java/com/web3auth/core/Web3Auth.kt index 68d1f94..56b86c4 100644 --- a/core/src/main/java/com/web3auth/core/Web3Auth.kt +++ b/core/src/main/java/com/web3auth/core/Web3Auth.kt @@ -2,10 +2,7 @@ package com.web3auth.core import android.content.Intent import android.net.Uri -import android.os.Handler -import android.os.Looper import androidx.browser.customtabs.CustomTabsIntent -import androidx.core.os.postDelayed import com.google.gson.GsonBuilder import com.google.gson.JsonArray import com.google.gson.JsonObject @@ -174,21 +171,15 @@ class Web3Auth(web3AuthOptions: Web3AuthOptions) { //initiate keyStore initiateKeyStoreManager() - //fetch project config - fetchProjectConfig().whenComplete { response, error -> - if (error == null) { - web3AuthOption.originData = response.whitelist?.signed_urls - if (response?.whiteLabelData != null) { - web3AuthOption.whiteLabel = - web3AuthOption.whiteLabel?.merge(response.whiteLabelData) - } - } else { - initializeCf.completeExceptionally(Exception(Web3AuthError.getError(ErrorCode.SOMETHING_WENT_WRONG))) - } - } - //authorize session if (ApiHelper.isNetworkAvailable(web3AuthOption.context)) { + + //fetch project config + val sessionId = sessionManager.getSessionId() + if (sessionId.isBlank()) { + fetchProjectConfig() + } + this.authorizeSession().whenComplete { resp, error -> if (error == null) { web3AuthResponse = resp @@ -389,7 +380,7 @@ class Web3Auth(web3AuthOptions: Web3AuthOptions) { return sessionCompletableFuture } - private fun fetchProjectConfig(): CompletableFuture { + private fun fetchProjectConfig() { val projectConfigCompletableFuture: CompletableFuture = CompletableFuture() val web3AuthApi = @@ -401,8 +392,12 @@ class Web3Auth(web3AuthOptions: Web3AuthOptions) { web3AuthOption.network.name ) if (result.isSuccessful && result.body() != null) { - Handler(Looper.getMainLooper()).postDelayed(10) { - projectConfigCompletableFuture.complete(result.body()) + val response = result.body() + web3AuthOption.originData = + web3AuthOption.originData.mergeMaps(response?.whitelist?.signed_urls) + if (response?.whiteLabelData != null) { + web3AuthOption.whiteLabel = + web3AuthOption.whiteLabel?.merge(response.whiteLabelData) } } else { projectConfigCompletableFuture.completeExceptionally( @@ -424,7 +419,6 @@ class Web3Auth(web3AuthOptions: Web3AuthOptions) { ) } } - return projectConfigCompletableFuture } /** diff --git a/core/src/main/java/com/web3auth/core/api/ApiHelper.kt b/core/src/main/java/com/web3auth/core/api/ApiHelper.kt index 2b7228b..a73dc5d 100644 --- a/core/src/main/java/com/web3auth/core/api/ApiHelper.kt +++ b/core/src/main/java/com/web3auth/core/api/ApiHelper.kt @@ -24,7 +24,7 @@ object ApiHelper { Network.SAPPHIRE_DEVNET to "https://signer.web3auth.io" ) - private const val baseUrl = "https://session.web3auth.io" + private const val sessionBaseUrl = "https://session.web3auth.io" private val okHttpClient = OkHttpClient().newBuilder() .readTimeout(60, TimeUnit.SECONDS) diff --git a/core/src/main/java/com/web3auth/core/types/WhiteLabelData.kt b/core/src/main/java/com/web3auth/core/types/WhiteLabelData.kt index 205db54..fdd7927 100644 --- a/core/src/main/java/com/web3auth/core/types/WhiteLabelData.kt +++ b/core/src/main/java/com/web3auth/core/types/WhiteLabelData.kt @@ -8,5 +8,5 @@ data class WhiteLabelData( var defaultLanguage: Language? = Language.EN, var mode: ThemeModes? = null, var useLogoLoader: Boolean? = false, - var theme: HashMap? = null + var theme: HashMap? = null ) \ No newline at end of file From 6f3871c4d686a7cc11ce1d4148855cfe3195bd1c Mon Sep 17 00:00:00 2001 From: Gaurav Goel Date: Thu, 16 May 2024 13:07:08 +0530 Subject: [PATCH 07/15] feat: new login providers added in TypeOfLogin enum Signed-off-by: Gaurav Goel --- .../java/com/web3auth/core/types/TypeOfLogin.kt | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/com/web3auth/core/types/TypeOfLogin.kt b/core/src/main/java/com/web3auth/core/types/TypeOfLogin.kt index d996cc8..5acfdc2 100644 --- a/core/src/main/java/com/web3auth/core/types/TypeOfLogin.kt +++ b/core/src/main/java/com/web3auth/core/types/TypeOfLogin.kt @@ -23,16 +23,25 @@ enum class TypeOfLogin { KAKAO, @SerializedName("linkedin") LINKEDIN, + @SerializedName("twitter") TWITTER, + @SerializedName("weibo") WEIBO, + @SerializedName("wechat") WECHAT, + @SerializedName("email_passwordless") EMAIL_PASSWORDLESS, - @SerializedName("email_password") - EMAIL_PASSWORD, + @SerializedName("jwt") - JWT + JWT, + + @SerializedName("sms_passwordless") + SMS_PASSWORDLESS, + + @SerializedName("farcaster") + FARCASTER } \ No newline at end of file From feb8782f82e2bb27be7accb4723b1fc697baaaea Mon Sep 17 00:00:00 2001 From: Gaurav Goel Date: Thu, 16 May 2024 14:41:04 +0530 Subject: [PATCH 08/15] feat: code refactored Signed-off-by: Gaurav Goel --- core/src/main/java/com/web3auth/core/Web3Auth.kt | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/core/src/main/java/com/web3auth/core/Web3Auth.kt b/core/src/main/java/com/web3auth/core/Web3Auth.kt index 6795c35..5b28bf0 100644 --- a/core/src/main/java/com/web3auth/core/Web3Auth.kt +++ b/core/src/main/java/com/web3auth/core/Web3Auth.kt @@ -175,10 +175,7 @@ class Web3Auth(web3AuthOptions: Web3AuthOptions) { if (ApiHelper.isNetworkAvailable(web3AuthOption.context)) { //fetch project config - val sessionId = sessionManager.getSessionId() - if (sessionId.isBlank()) { - fetchProjectConfig() - } + fetchProjectConfig() this.authorizeSession().whenComplete { resp, error -> if (error == null) { From 215fd33f292e44edb8f2b05829c6cd40372ef71b Mon Sep 17 00:00:00 2001 From: Gaurav Goel Date: Tue, 21 May 2024 15:17:03 +0530 Subject: [PATCH 09/15] feat: code refactored and example updated for config API. Signed-off-by: Gaurav Goel --- app/src/main/java/com/web3auth/app/MainActivity.kt | 2 +- core/src/main/java/com/web3auth/core/Utils.kt | 14 +++++++------- core/src/main/java/com/web3auth/core/Web3Auth.kt | 4 ++-- .../web3auth/core/types/ProjectConfigResponse.kt | 2 +- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/com/web3auth/app/MainActivity.kt b/app/src/main/java/com/web3auth/app/MainActivity.kt index 99f3712..e87e267 100644 --- a/app/src/main/java/com/web3auth/app/MainActivity.kt +++ b/app/src/main/java/com/web3auth/app/MainActivity.kt @@ -146,7 +146,7 @@ class MainActivity : AppCompatActivity(), AdapterView.OnItemClickListener { val options = Web3AuthOptions( context = this, - clientId = "BHgArYmWwSeq21czpcarYh0EVq2WWOzflX-NTK-tY1-1pauPzHKRRLgpABkmYiIV_og9jAvoIxQ8L3Smrwe04Lw", + clientId = "BFuUqebV5I8Pz5F7a5A2ihW7YVmbv_OHXnHYDv6OltAD5NGr6e-ViNvde3U4BHdn6HvwfkgobhVu4VwC-OSJkik", network = Network.SAPPHIRE_DEVNET, redirectUrl = Uri.parse("torusapp://org.torusresearch.web3authexample"), // sdkUrl = "https://auth.mocaverse.xyz", diff --git a/core/src/main/java/com/web3auth/core/Utils.kt b/core/src/main/java/com/web3auth/core/Utils.kt index e11eaed..78fa87c 100644 --- a/core/src/main/java/com/web3auth/core/Utils.kt +++ b/core/src/main/java/com/web3auth/core/Utils.kt @@ -81,13 +81,13 @@ fun WhiteLabelData.merge(other: WhiteLabelData): WhiteLabelData { } return WhiteLabelData( - appName = other.appName ?: this.appName, - appUrl = other.appUrl ?: this.appUrl, - logoLight = other.logoLight ?: this.logoLight, - logoDark = other.logoDark ?: this.logoDark, - defaultLanguage = other.defaultLanguage ?: this.defaultLanguage, - mode = other.mode ?: this.mode, - useLogoLoader = other.useLogoLoader ?: this.useLogoLoader, + appName = this.appName ?: other.appName, + appUrl = this.appUrl ?: other.appUrl, + logoLight = this.logoLight ?: other.logoLight, + logoDark = this.logoDark ?: other.logoDark, + defaultLanguage = this.defaultLanguage ?: other.defaultLanguage, + mode = this.mode ?: other.mode, + useLogoLoader = this.useLogoLoader ?: other.useLogoLoader, theme = mergedTheme ) } diff --git a/core/src/main/java/com/web3auth/core/Web3Auth.kt b/core/src/main/java/com/web3auth/core/Web3Auth.kt index 5b28bf0..5358f65 100644 --- a/core/src/main/java/com/web3auth/core/Web3Auth.kt +++ b/core/src/main/java/com/web3auth/core/Web3Auth.kt @@ -392,9 +392,9 @@ class Web3Auth(web3AuthOptions: Web3AuthOptions) { val response = result.body() web3AuthOption.originData = web3AuthOption.originData.mergeMaps(response?.whitelist?.signed_urls) - if (response?.whiteLabelData != null) { + if (response?.whitelabel != null) { web3AuthOption.whiteLabel = - web3AuthOption.whiteLabel?.merge(response.whiteLabelData) + web3AuthOption.whiteLabel?.merge(response.whitelabel) } } else { projectConfigCompletableFuture.completeExceptionally( diff --git a/core/src/main/java/com/web3auth/core/types/ProjectConfigResponse.kt b/core/src/main/java/com/web3auth/core/types/ProjectConfigResponse.kt index 2e3f65b..8eb51b9 100644 --- a/core/src/main/java/com/web3auth/core/types/ProjectConfigResponse.kt +++ b/core/src/main/java/com/web3auth/core/types/ProjectConfigResponse.kt @@ -10,7 +10,7 @@ data class WhitelistResponse( @Keep data class ProjectConfigResponse( - val whiteLabelData: WhiteLabelData? = null, + val whitelabel: WhiteLabelData? = null, val sms_otp_enabled: Boolean, val wallet_connect_enabled: Boolean, val wallet_connect_project_id: String?, From 5db6063cd3698d37e92319aba1b9e6144151eed2 Mon Sep 17 00:00:00 2001 From: Gaurav Goel Date: Mon, 3 Jun 2024 15:56:30 +0800 Subject: [PATCH 10/15] feat: code refactored Signed-off-by: Gaurav Goel --- core/src/main/java/com/web3auth/core/Utils.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/com/web3auth/core/Utils.kt b/core/src/main/java/com/web3auth/core/Utils.kt index 78fa87c..aaeae2a 100644 --- a/core/src/main/java/com/web3auth/core/Utils.kt +++ b/core/src/main/java/com/web3auth/core/Utils.kt @@ -77,7 +77,9 @@ fun WhiteLabelData.merge(other: WhiteLabelData): WhiteLabelData { } } other.theme?.forEach { (key, value) -> - mergedTheme[key] = value ?: mergedTheme[key] + if (!mergedTheme.containsKey(key)) { + mergedTheme[key] = value ?: mergedTheme[key] + } } return WhiteLabelData( From df7a0cb295bcac2a985f1c0e94d78033e5a9e420 Mon Sep 17 00:00:00 2001 From: AyushBherwani1998 Date: Wed, 5 Jun 2024 16:11:06 +0530 Subject: [PATCH 11/15] update checks for whitelabel --- core/src/main/java/com/web3auth/core/Web3Auth.kt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/com/web3auth/core/Web3Auth.kt b/core/src/main/java/com/web3auth/core/Web3Auth.kt index 5358f65..89a4193 100644 --- a/core/src/main/java/com/web3auth/core/Web3Auth.kt +++ b/core/src/main/java/com/web3auth/core/Web3Auth.kt @@ -393,8 +393,12 @@ class Web3Auth(web3AuthOptions: Web3AuthOptions) { web3AuthOption.originData = web3AuthOption.originData.mergeMaps(response?.whitelist?.signed_urls) if (response?.whitelabel != null) { - web3AuthOption.whiteLabel = - web3AuthOption.whiteLabel?.merge(response.whitelabel) + if(web3AuthOption.whiteLabel == null) { + web3AuthOption.whiteLabel = response.whitelabel + } else { + web3AuthOption.whiteLabel = + web3AuthOption.whiteLabel!!.merge(response.whitelabel) + } } } else { projectConfigCompletableFuture.completeExceptionally( From 4e8cbc01bd9826c2bf94eeb9e73dbb894d142a33 Mon Sep 17 00:00:00 2001 From: Gaurav Goel Date: Wed, 15 May 2024 09:41:52 +0530 Subject: [PATCH 12/15] feat: upadted request() method and added platform paramater in url values. Signed-off-by: Gaurav Goel --- .../main/java/com/web3auth/app/MainActivity.kt | 8 ++++---- core/src/main/java/com/web3auth/core/Web3Auth.kt | 15 ++++++++------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/com/web3auth/app/MainActivity.kt b/app/src/main/java/com/web3auth/app/MainActivity.kt index e87e267..5f362b2 100644 --- a/app/src/main/java/com/web3auth/app/MainActivity.kt +++ b/app/src/main/java/com/web3auth/app/MainActivity.kt @@ -226,10 +226,10 @@ class MainActivity : AppCompatActivity(), AdapterView.OnItemClickListener { add("Android") } val signMsgCompletableFuture = web3Auth.request( - loginParams = LoginParams( - selectedLoginProvider, - extraLoginOptions = null, - mfaLevel = MFALevel.NONE, + chainConfig = ChainConfig( + chainId = "0x89", + rpcTarget = "https://polygon-rpc.com/", + chainNamespace = ChainNamespace.EIP155 ), "personal_sign", requestParams = params ) signMsgCompletableFuture.whenComplete { _, error -> diff --git a/core/src/main/java/com/web3auth/core/Web3Auth.kt b/core/src/main/java/com/web3auth/core/Web3Auth.kt index 89a4193..e482913 100644 --- a/core/src/main/java/com/web3auth/core/Web3Auth.kt +++ b/core/src/main/java/com/web3auth/core/Web3Auth.kt @@ -445,14 +445,13 @@ class Web3Auth(web3AuthOptions: Web3AuthOptions) { /** * Launches the wallet services asynchronously. * - * @param loginParams The login parameters required for authentication. * @param chainConfig The configuration details of the blockchain network. * @param path The path where the wallet services will be launched. Default value is "wallet". * @return A CompletableFuture representing the asynchronous operation. */ fun launchWalletServices( chainConfig: ChainConfig, - path: String? = "wallet" + path: String? = "wallet", ): CompletableFuture { val launchWalletServiceCF: CompletableFuture = CompletableFuture() val sessionId = sessionManager.getSessionId() @@ -479,7 +478,7 @@ class Web3Auth(web3AuthOptions: Web3AuthOptions) { "loginId", loginId ) walletMap.addProperty("sessionId", sessionId) - walletMap.addProperty("isAndroid", true) + walletMap.addProperty("platform", "android") val walletHash = "b64Params=" + gson.toJson(walletMap).toByteArray(Charsets.UTF_8) @@ -506,14 +505,14 @@ class Web3Auth(web3AuthOptions: Web3AuthOptions) { /** * Signs a message asynchronously. * - * @param loginParams The login parameters required for authentication. + * @param chainConfig The configuration details of the blockchain network. * @param method The method name of the request. * @param requestParams The parameters of the request in JSON array format. * @param path The path where the signing service is located. Default value is "wallet/request". * @return A CompletableFuture representing the asynchronous operation. */ fun request( - loginParams: LoginParams, + chainConfig: ChainConfig, method: String, requestParams: JsonArray, path: String? = "wallet/request" @@ -524,12 +523,13 @@ class Web3Auth(web3AuthOptions: Web3AuthOptions) { val sdkUrl = Uri.parse(web3AuthOption.walletSdkUrl) val context = web3AuthOption.context val initOptions = getInitOptions() - val initParams = getInitParams(loginParams) + initOptions.put( + "chainConfig", gson.toJson(chainConfig) + ) val paramMap = JSONObject() paramMap.put( "options", initOptions ) - paramMap.put("params", initParams) val loginIdCf = getLoginId(paramMap) @@ -538,6 +538,7 @@ class Web3Auth(web3AuthOptions: Web3AuthOptions) { val signMessageMap = JsonObject() signMessageMap.addProperty("loginId", loginId) signMessageMap.addProperty("sessionId", sessionId) + signMessageMap.addProperty("platform", "android") val requestData = JsonObject().apply { addProperty("method", method) From bcbcb8eb37d1102602c826070a673e05c3d1ada2 Mon Sep 17 00:00:00 2001 From: AyushBherwani1998 Date: Tue, 21 May 2024 12:26:30 +0530 Subject: [PATCH 13/15] make redirectUrl mandatory --- core/src/main/java/com/web3auth/core/types/Web3AuthOptions.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/com/web3auth/core/types/Web3AuthOptions.kt b/core/src/main/java/com/web3auth/core/types/Web3AuthOptions.kt index 095fefc..c1e4a78 100644 --- a/core/src/main/java/com/web3auth/core/types/Web3AuthOptions.kt +++ b/core/src/main/java/com/web3auth/core/types/Web3AuthOptions.kt @@ -8,7 +8,7 @@ data class Web3AuthOptions( val clientId: String, val network: Network, var buildEnv: BuildEnv? = BuildEnv.PRODUCTION, - @Transient var redirectUrl: Uri? = null, + @Transient var redirectUrl: Uri, var sdkUrl: String = getSdkUrl(buildEnv), var whiteLabel: WhiteLabelData? = null, val loginConfig: HashMap? = null, From 9a55a8e3ddd16c99088297199c97c8cfded5aff4 Mon Sep 17 00:00:00 2001 From: uther Date: Sun, 19 May 2024 02:21:57 +0900 Subject: [PATCH 14/15] fix: add consumerProguardFiles for r8 full mode. --- core/build.gradle | 2 +- core/gson.pro | 72 ++++++++++++++++++++++++++++++++++++++++++++++ core/retrofit2.pro | 48 +++++++++++++++++++++++++++++++ 3 files changed, 121 insertions(+), 1 deletion(-) create mode 100644 core/gson.pro create mode 100644 core/retrofit2.pro diff --git a/core/build.gradle b/core/build.gradle index 26d8a7f..2ae97e1 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -19,7 +19,7 @@ android { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' - consumerProguardFiles 'proguard-rules.pro' + consumerProguardFiles 'proguard-rules.pro', 'gson.pro', 'retrofit2.pro' } } compileOptions { diff --git a/core/gson.pro b/core/gson.pro new file mode 100644 index 0000000..30d847f --- /dev/null +++ b/core/gson.pro @@ -0,0 +1,72 @@ +### Gson ProGuard and R8 rules which are relevant for all users +### This file is automatically recognized by ProGuard and R8, see https://developer.android.com/build/shrink-code#configuration-files +### +### IMPORTANT: +### - These rules are additive; don't include anything here which is not specific to Gson (such as completely +### disabling obfuscation for all classes); the user would be unable to disable that then +### - These rules are not complete; users will most likely have to add additional rules for their specific +### classes, for example to disable obfuscation for certain fields or to keep no-args constructors +### + +# Keep generic signatures; needed for correct type resolution +-keepattributes Signature + +# Keep Gson annotations +# Note: Cannot perform finer selection here to only cover Gson annotations, see also https://stackoverflow.com/q/47515093 +-keepattributes RuntimeVisibleAnnotations,AnnotationDefault + +### The following rules are needed for R8 in "full mode" which only adheres to `-keepattribtues` if +### the corresponding class or field is matches by a `-keep` rule as well, see +### https://r8.googlesource.com/r8/+/refs/heads/main/compatibility-faq.md#r8-full-mode + +# Keep class TypeToken (respectively its generic signature) if present +-if class com.google.gson.reflect.TypeToken +-keep,allowobfuscation class com.google.gson.reflect.TypeToken + +# Keep any (anonymous) classes extending TypeToken +-keep,allowobfuscation class * extends com.google.gson.reflect.TypeToken + +# Keep classes with @JsonAdapter annotation +-keep,allowobfuscation,allowoptimization @com.google.gson.annotations.JsonAdapter class * + +# Keep fields with any other Gson annotation +# Also allow obfuscation, assuming that users will additionally use @SerializedName or +# other means to preserve the field names +-keepclassmembers,allowobfuscation class * { + @com.google.gson.annotations.Expose ; + @com.google.gson.annotations.JsonAdapter ; + @com.google.gson.annotations.Since ; + @com.google.gson.annotations.Until ; +} + +# Keep no-args constructor of classes which can be used with @JsonAdapter +# By default their no-args constructor is invoked to create an adapter instance +-keepclassmembers class * extends com.google.gson.TypeAdapter { + (); +} +-keepclassmembers class * implements com.google.gson.TypeAdapterFactory { + (); +} +-keepclassmembers class * implements com.google.gson.JsonSerializer { + (); +} +-keepclassmembers class * implements com.google.gson.JsonDeserializer { + (); +} + +# Keep fields annotated with @SerializedName for classes which are referenced. +# If classes with fields annotated with @SerializedName have a no-args +# constructor keep that as well. Based on +# https://issuetracker.google.com/issues/150189783#comment11. +# See also https://github.com/google/gson/pull/2420#discussion_r1241813541 +# for a more detailed explanation. +-if class * +-keepclasseswithmembers,allowobfuscation class <1> { + @com.google.gson.annotations.SerializedName ; +} +-if class * { + @com.google.gson.annotations.SerializedName ; +} +-keepclassmembers,allowobfuscation,allowoptimization class <1> { + (); +} \ No newline at end of file diff --git a/core/retrofit2.pro b/core/retrofit2.pro new file mode 100644 index 0000000..6c1daaf --- /dev/null +++ b/core/retrofit2.pro @@ -0,0 +1,48 @@ +# Retrofit does reflection on generic parameters. InnerClasses is required to use Signature and +# EnclosingMethod is required to use InnerClasses. +-keepattributes Signature, InnerClasses, EnclosingMethod + +# Retrofit does reflection on method and parameter annotations. +-keepattributes RuntimeVisibleAnnotations, RuntimeVisibleParameterAnnotations + +# Keep annotation default values (e.g., retrofit2.http.Field.encoded). +-keepattributes AnnotationDefault + +# Retain service method parameters when optimizing. +-keepclassmembers,allowshrinking,allowobfuscation interface * { + @retrofit2.http.* ; +} + +# Ignore annotation used for build tooling. +-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement + +# Ignore JSR 305 annotations for embedding nullability information. +-dontwarn javax.annotation.** + +# Guarded by a NoClassDefFoundError try/catch and only used when on the classpath. +-dontwarn kotlin.Unit + +# Top-level functions that can only be used by Kotlin. +-dontwarn retrofit2.KotlinExtensions +-dontwarn retrofit2.KotlinExtensions$* + +# With R8 full mode, it sees no subtypes of Retrofit interfaces since they are created with a Proxy +# and replaces all potential values with null. Explicitly keeping the interfaces prevents this. +-if interface * { @retrofit2.http.* ; } +-keep,allowobfuscation interface <1> + +# Keep inherited services. +-if interface * { @retrofit2.http.* ; } +-keep,allowobfuscation interface * extends <1> + +# With R8 full mode generic signatures are stripped for classes that are not +# kept. Suspend functions are wrapped in continuations where the type argument +# is used. +-keep,allowobfuscation,allowshrinking class kotlin.coroutines.Continuation + +# R8 full mode strips generic signatures from return types if not kept. +-if interface * { @retrofit2.http.* public *** *(...); } +-keep,allowoptimization,allowshrinking,allowobfuscation class <3> + +# With R8 full mode generic signatures are stripped for classes that are not kept. +-keep,allowobfuscation,allowshrinking class retrofit2.Response \ No newline at end of file From 002721a47d1a60bfb34ac3c00176e328864ebfa4 Mon Sep 17 00:00:00 2001 From: Gaurav Goel Date: Mon, 10 Jun 2024 16:01:55 +0800 Subject: [PATCH 15/15] feat: code refractored. Signed-off-by: Gaurav Goel --- .../java/com/web3auth/app/MainActivity.kt | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/web3auth/app/MainActivity.kt b/app/src/main/java/com/web3auth/app/MainActivity.kt index 5f362b2..b1cc945 100644 --- a/app/src/main/java/com/web3auth/app/MainActivity.kt +++ b/app/src/main/java/com/web3auth/app/MainActivity.kt @@ -6,7 +6,13 @@ import android.os.Bundle import android.text.method.ScrollingMovementMethod import android.util.Log import android.view.View -import android.widget.* +import android.widget.AdapterView +import android.widget.ArrayAdapter +import android.widget.AutoCompleteTextView +import android.widget.Button +import android.widget.EditText +import android.widget.TextView +import android.widget.Toast import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AppCompatActivity import com.google.android.material.textfield.TextInputLayout @@ -15,7 +21,22 @@ import com.google.gson.JsonArray import com.web3auth.core.Web3Auth import com.web3auth.core.isEmailValid import com.web3auth.core.isPhoneNumberValid -import com.web3auth.core.types.* +import com.web3auth.core.types.BuildEnv +import com.web3auth.core.types.ChainConfig +import com.web3auth.core.types.ChainNamespace +import com.web3auth.core.types.ExtraLoginOptions +import com.web3auth.core.types.Language +import com.web3auth.core.types.LoginConfigItem +import com.web3auth.core.types.LoginParams +import com.web3auth.core.types.MFALevel +import com.web3auth.core.types.Network +import com.web3auth.core.types.Provider +import com.web3auth.core.types.ThemeModes +import com.web3auth.core.types.TypeOfLogin +import com.web3auth.core.types.UserInfo +import com.web3auth.core.types.Web3AuthOptions +import com.web3auth.core.types.Web3AuthResponse +import com.web3auth.core.types.WhiteLabelData import org.json.JSONObject import org.web3j.crypto.Credentials import java.util.concurrent.CompletableFuture @@ -155,7 +176,8 @@ class MainActivity : AppCompatActivity(), AdapterView.OnItemClickListener { "Web3Auth Sample App", null, null, null, Language.EN, ThemeModes.LIGHT, true, hashMapOf( - "primary" to "#123456" + "primary" to "#123456", + "onPrimary" to "#0000FF" ) ), loginConfig = hashMapOf(