Skip to content

Commit 751add5

Browse files
Merge pull request #21 from Web3Auth/feat/consumer_rules
Update proguard and comsumer rules
2 parents 0cecffd + 91f2b1a commit 751add5

24 files changed

+319
-103
lines changed

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ android {
1919

2020
buildTypes {
2121
release {
22-
minifyEnabled false
22+
minifyEnabled true
2323
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
2424
}
2525
}

app/proguard-rules.pro

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,14 @@
1818

1919
# If you keep the line number information, uncomment this to
2020
# hide the original source file name.
21-
#-renamesourcefileattribute SourceFile
21+
#-renamesourcefileattribute SourceFile
22+
# Keep all classes inside JJWT implementation
23+
-keep class io.jsonwebtoken.impl.** { *; }
24+
-keep class io.jsonwebtoken.orgjson.** { *; }
25+
26+
# Keep service loaders
27+
-keepclassmembers class * {
28+
@io.jsonwebtoken.* <methods>;
29+
}
30+
-keepattributes *Annotation*
31+

singlefactorauth/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ android {
1818

1919
buildTypes {
2020
release {
21-
minifyEnabled false
21+
minifyEnabled true
2222
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
2323
}
2424
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Keep all classes and their members under this package
2+
-keep class com.web3auth.singlefactorauth.** { *; }
3+
-keepclassmembers class com.web3auth.singlefactorauth.** { *; }
4+
-keepclassmembers enum com.web3auth.singlefactorauth.** { *; }
5+
6+
# Keep all classes under the 'types' package and their members
7+
-keep class com.web3auth.singlefactorauth.types.** { *; }
8+
-keepclassmembers class com.web3auth.singlefactorauth.types.** { *; }
9+
10+
# Explicitly keep specific classes to avoid confusion
11+
-keep class com.web3auth.singlefactorauth.types.SessionData { *; }
12+
-keep class com.web3auth.singlefactorauth.types.UserInfo { *; }
13+
-keep class com.web3auth.singlefactorauth.types.TorusGenericContainer { *; }
14+
15+
# Prevent method-level optimizations for critical classes
16+
-keepclassmembers class com.web3auth.singlefactorauth.types.UserInfo {
17+
<fields>;
18+
<methods>;
19+
}
20+
-keepclassmembers class com.web3auth.singlefactorauth.types.TorusGenericContainer {
21+
<fields>;
22+
<methods>;
23+
}
24+
25+
# Avoid optimizations like method inlining, class merging, etc.
26+
-optimizations !code/allocation/variable,!field/*,!class/merging/*
27+
28+
# Suppress warnings related to these classes
29+
-dontwarn com.web3auth.singlefactorauth.**
30+
31+
# Preserve FetchNodeDetails and its fields/methods
32+
-keep class org.torusresearch.fetchnodedetails.FetchNodeDetails { *; }
33+
-keep class org.torusresearch.fetchnodedetails.types.** { *; }
34+
35+
-keepnames class org.torusresearch.** { *; }
36+
-keepclassmembers class * {
37+
@com.google.gson.annotations.SerializedName <fields>;
38+
}
39+
40+
# Prevent obfuscation of Torus types, helpers, and utils
41+
-keep class org.torusresearch.torusutils.** { *; }
42+
-keep class org.torusresearch.torusutils.analytics.** { *; }
43+
-keep class org.torusresearch.torusutils.apis.** { *; }
44+
-keep class org.torusresearch.torusutils.helpers.** { *; }
45+
-keep class org.torusresearch.torusutils.types.** { *; }
46+
47+
# Prevent obfuscation of bouncycastle library
48+
-keep class org.bouncycastle.** { *; }
49+
-dontwarn org.bouncycastle.**
50+
-keep class javax.net.ssl.** { *; }
51+
-keep class java.security.** { *; }
52+
-keep class com.android.org.conscrypt.** { *; }
53+
-dontwarn com.android.org.conscrypt.**

singlefactorauth/proguard-rules.pro

Lines changed: 95 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,11 @@
2929

3030
##### okhttp3
3131
# okHttp3
32-
-dontwarn javax.annotation.Nullable
33-
-dontwarn javax.annotation.ParametersAreNonnullByDefault
32+
# Avoid warnings related to OkHttp and other libraries
33+
-dontwarn javax.annotation.**
34+
-dontwarn okhttp3.internal.platform.ConscryptPlatform
35+
-dontwarn okhttp3.internal.**
36+
-dontwarn org.bouncycastle.**
3437
# JSR 305 annotations are for embedding nullability information.
3538
-dontwarn javax.annotation.**
3639
# A resource is loaded with a relative path so the package of this class must be preserved.
@@ -43,9 +46,99 @@
4346
-keep class com.web3auth.session_manager_android.**
4447
-dontwarn javax.annotation.**
4548

49+
-keepclassmembers class com.web3auth.singlefactorauth.types.SessionData {
50+
<fields>;
51+
}
52+
-keepclassmembers class com.web3auth.singlefactorauth.types.UserInfo {
53+
<fields>;
54+
}
55+
-keepclassmembers class com.web3auth.singlefactorauth.types.TorusGenericContainer {
56+
<fields>;
57+
}
58+
59+
-keep class com.web3auth.singlefactorauth.types.** { *; }
60+
-keepclassmembers class com.web3auth.singlefactorauth.types.** { <fields>; }
61+
62+
-keepclassmembers enum * { *; }
63+
64+
-keep class * implements com.google.gson.JsonDeserializer
65+
4666
#### GSON
4767
# Prevent proguard from stripping interface information from TypeAdapterFactory,
4868
# JsonSerializer, JsonDeserializer instances (so they can be used in @JsonAdapter)
4969
-keep class * implements com.google.gson.TypeAdapterFactory
5070
-keep class * implements com.google.gson.JsonSerializer
5171
-keep class * implements com.google.gson.JsonDeserializer
72+
73+
# Ensure the serialization and deserialization of your models works correctly
74+
-keep class com.web3auth.singlefactorauth.types.SessionData { *; }
75+
76+
77+
-keep class com.web3auth.singlefactorauth.types.UserInfo { *; }
78+
-keepclassmembers class com.web3auth.singlefactorauth.types.UserInfo { *; }
79+
-keepclassmembers class com.web3auth.singlefactorauth.types.UserInfo {
80+
<fields>;
81+
<methods>;
82+
}
83+
-dontwarn com.web3auth.singlefactorauth.types.UserInfo
84+
-optimizations !code/allocation/variable,!field/*,!class/merging/*
85+
86+
-keep class com.web3auth.singlefactorauth.types.TorusGenericContainer { *; }
87+
-keepclassmembers class com.web3auth.singlefactorauth.types.TorusGenericContainer { *; }
88+
-keepclassmembers class com.web3auth.singlefactorauth.types.TorusGenericContainer {
89+
<fields>;
90+
<methods>;
91+
}
92+
-dontwarn com.web3auth.singlefactorauth.types.TorusGenericContainer
93+
-optimizations !code/allocation/variable,!field/*,!class/merging/*
94+
95+
# Keep the Gson class and its members
96+
-keep class com.google.gson.** { *; }
97+
-keepnames class com.google.gson.** { *; }
98+
99+
# Keep the GsonBuilder class and its members
100+
-keep class com.google.gson.GsonBuilder { *; }
101+
-keepnames class com.google.gson.GsonBuilder { *; }
102+
103+
# Keep the JsonArray class and its members
104+
-keep class com.google.gson.JsonArray { *; }
105+
-keepnames class com.google.gson.JsonArray { *; }
106+
107+
# Keep the JsonObject class and its members
108+
-keep class com.google.gson.JsonObject { *; }
109+
-keepnames class com.google.gson.JsonObject { *; }
110+
111+
# Keep the TypeToken class and its members (important for generic type handling)
112+
-keep class com.google.gson.reflect.TypeToken { *; }
113+
-keepnames class com.google.gson.reflect.TypeToken { *; }
114+
115+
# Keep generic type information used by TypeToken (very important!)
116+
-keepattributes Signature
117+
-keepattributes *Annotation*
118+
-keepattributes EnclosingMethod
119+
-keepattributes InnerClasses
120+
121+
-keep enum com.web3auth.singlefactorauth.types.LoginType { *; }
122+
123+
-keep class org.torusresearch.torusutils.** { *; }
124+
-keepclassmembers class org.torusresearch.torusutils.** { *; }
125+
126+
# Preserve FetchNodeDetails and its fields/methods
127+
-keep class org.torusresearch.fetchnodedetails.FetchNodeDetails { *; }
128+
-keep class org.torusresearch.fetchnodedetails.types.** { *; }
129+
130+
# Prevent obfuscation of Torus types, helpers, and utils
131+
-keep class org.torusresearch.torusutils.** { *; }
132+
-keep class org.torusresearch.torusutils.analytics.** { *; }
133+
-keep class org.torusresearch.torusutils.apis.** { *; }
134+
-keep class org.torusresearch.torusutils.helpers.** { *; }
135+
-keep class org.torusresearch.torusutils.types.** { *; }
136+
137+
# Keep public APIs used via reflection
138+
-keepnames class org.torusresearch.** { *; }
139+
-keepclassmembers class * {
140+
@com.google.gson.annotations.SerializedName <fields>;
141+
}
142+
143+
144+

singlefactorauth/src/main/java/com/web3auth/singlefactorauth/SingleFactorAuth.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,10 @@ class SingleFactorAuth(
100100
val data = JSONObject(dataFuture.get())
101101
val privateKey = data.getString("privKey")
102102
val publicAddress = data.getString("publicAddress")
103-
val userInfoJson = data.getString("userInfo")
103+
val userInfoJsonObject = data.getJSONObject("userInfo")
104104
val signaturesJson = data.getString("signatures")
105105

106-
val finalUserInfo = Gson().fromJson(userInfoJson, UserInfo::class.java)
106+
val finalUserInfo = Gson().fromJson(userInfoJsonObject.toString(), UserInfo::class.java)
107107
val finalSignatures: List<String> =
108108
Gson().fromJson(signaturesJson, object : TypeToken<List<String>>() {}.type)
109109

singlefactorauth/src/main/java/com/web3auth/singlefactorauth/types/BuildEnv.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
package com.web3auth.singlefactorauth.types
22

3+
import androidx.annotation.Keep
34
import com.google.gson.annotations.SerializedName
5+
import java.io.Serializable
46

5-
enum class BuildEnv {
7+
@Keep
8+
enum class BuildEnv : Serializable {
69
@SerializedName("production")
710
PRODUCTION,
811

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
package com.web3auth.singlefactorauth.types
22

3+
import androidx.annotation.Keep
4+
import java.io.Serializable
5+
6+
@Keep
37
data class ChainConfig(
4-
val chainNamespace: ChainNamespace = ChainNamespace.EIP155,
5-
val decimals: Int? = 18,
6-
val blockExplorerUrl: String? = null,
7-
val chainId: String,
8-
val displayName: String? = null,
9-
val logo: String? = null,
10-
val rpcTarget: String,
11-
val ticker: String? = null,
12-
val tickerName: String? = null,
13-
)
8+
@Keep val chainNamespace: ChainNamespace = ChainNamespace.EIP155,
9+
@Keep val decimals: Int? = 18,
10+
@Keep val blockExplorerUrl: String? = null,
11+
@Keep val chainId: String,
12+
@Keep val displayName: String? = null,
13+
@Keep val logo: String? = null,
14+
@Keep val rpcTarget: String,
15+
@Keep val ticker: String? = null,
16+
@Keep val tickerName: String? = null,
17+
) : Serializable

singlefactorauth/src/main/java/com/web3auth/singlefactorauth/types/ChainNamespace.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
package com.web3auth.singlefactorauth.types
22

3+
import androidx.annotation.Keep
34
import com.google.gson.annotations.SerializedName
5+
import java.io.Serializable
46

5-
enum class ChainNamespace {
7+
@Keep
8+
enum class ChainNamespace : Serializable {
69
@SerializedName("eip155")
710
EIP155,
811

singlefactorauth/src/main/java/com/web3auth/singlefactorauth/types/ErrorCode.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package com.web3auth.singlefactorauth.types
22

3-
enum class ErrorCode {
3+
import androidx.annotation.Keep
4+
import java.io.Serializable
5+
6+
@Keep
7+
enum class ErrorCode : Serializable {
48
USER_ALREADY_ENABLED_MFA,
59
PRIVATE_KEY_NOT_FOUND,
610
RUNTIME_ERROR,

0 commit comments

Comments
 (0)