# Proguard rules that are applied to all library modules

##---------------Begin: proguard configuration for Gson  ----------
# For using GSON annotations
-keepattributes *Annotation*

# Prevent proguard from stripping interface information from TypeAdapter, TypeAdapterFactory,
# JsonSerializer, JsonDeserializer instances (so they can be used in @JsonAdapter)
-keep class * extends com.google.gson.TypeAdapter
-keep class * implements com.google.gson.TypeAdapterFactory
-keep class * implements com.google.gson.JsonSerializer
-keep class * implements com.google.gson.JsonDeserializer

-keepclassmembers,allowobfuscation class * {
  @com.google.gson.annotations.SerializedName <fields>;
}
# common consumer proguard rules for third party libraries used by 3DS SDK
-dontwarn java.lang.instrument.ClassFileTransformer
-dontwarn sun.misc.SignalHandler
-dontwarn org.conscrypt.**
-dontwarn org.bouncycastle.**
-dontwarn org.openjsse.**
-dontwarn com.google.errorprone.annotations.Immutable
# Consumer ProGuard rules for the Checkout 3DS SDK.
# These rules are automatically applied to merchant apps that depend on this AAR.
#
# By the time a merchant consumes this AAR, the SDK's own R8 pass (proguard-rules.pro)
# has already run: internals are repackaged into com.checkout.threedsobfuscation, while
# the public API and a small set of reflection-/framework-dependent internals are
# retained under their original com.checkout.threeds.* names. The rules below protect
# that surviving surface from the merchant app's own R8 pass.
#
# These rules are intentionally EXPLICIT — one rule per public-API package, mirroring
# threeds/api/threeds.api — rather than a single blanket `-keep class
# com.checkout.threeds.** { *; }`. This keeps the merchant-facing contract auditable
# against the API baseline: every public type is protected on purpose, not incidentally.

# =====================================================================
# 1. Public API surface — mirrors threeds/api/threeds.api
# =====================================================================
# Entry point, result callback and environment.
-keep public class com.checkout.threeds.Checkout3DSService { *; }
-keep public interface com.checkout.threeds.AuthenticationCallback { *; }
-keep public class com.checkout.threeds.Environment { *; }

# Error codes. BaseErrorCode is the shared public abstract supertype of both hierarchies.
-keep public class com.checkout.threeds.domain.error.BaseErrorCode { *; }
-keep public class com.checkout.threeds.domain.error.AuthenticationProcessErrorCode { *; }
-keep public class com.checkout.threeds.domain.error.AuthenticationProcessErrorCode$* { *; }
-keep public class com.checkout.threeds.domain.error.ConnectivityErrorCode { *; }
-keep public class com.checkout.threeds.domain.error.ConnectivityErrorCode$* { *; }

# Authentication results and the UI customization model tree.
-keep public class com.checkout.threeds.domain.model.* { *; }

# Sessions environment: abstract base + PRODUCTION/SANDBOX objects.
-keep public class com.checkout.threeds.sessions.Environment { *; }
-keep public class com.checkout.threeds.sessions.Environment$* { *; }

# Standalone (merchant-hosted 3DS server) API.
-keep public class com.checkout.threeds.standalone.Standalone3DSService { *; }
-keep public class com.checkout.threeds.standalone.Standalone3DSService$* { *; }
-keep public interface com.checkout.threeds.standalone.api.* { *; }
-keep public class com.checkout.threeds.standalone.dochallenge.models.* { *; }
-keep public class com.checkout.threeds.standalone.models.* { *; }
# ThreeDSConstantsKt exposes the public CHALLENGE_TIMEOUT constant.
-keep public class com.checkout.threeds.standalone.utils.ThreeDSConstantsKt { *; }

# =====================================================================
# 2. Repackaged internals — name preservation
# =====================================================================
# The SDK's own R8 pass moved internals into com.checkout.threedsobfuscation.
# FragmentManager persists Fragment class names as strings for process-death
# restoration; if the merchant's R8 renames them a second time, Class.forName()
# throws ClassNotFoundException when Android restores the 3DS challenge screen.
-keepnames class com.checkout.threedsobfuscation.**
-dontwarn com.checkout.threedsobfuscation.**

# Checkout event logger (internal SDK support library) is invoked reflectively.
-keep class com.checkout.eventlogger.** { *; }

# =====================================================================
# 3. Internals retained under original names for reflection / framework
# =====================================================================
# Loaded by fully-qualified string name via Class.forName() in
# CkoIntegrityTamperChecker; renaming breaks the integrity/tamper security check.
-keep class com.checkout.threeds.data.deviceInfo.SecurityWarningsCollector { *; }

# Declared in the SDK's AndroidManifest and instantiated by the framework by name.
-keep class com.checkout.threeds.ui.Checkout3DSActivity { *; }
-keep class com.checkout.threeds.sec.PackageUpdateBroadcastReceiver {
    <init>(...);
    void onReceive(android.content.Context, android.content.Intent);
}

# Custom Views inflated from the SDK's bundled layout XML need their reflective
# (Context, AttributeSet[, int]) constructors. AAPT normally generates these keep
# rules from the merged resources; these are defensive explicit rules.
-keepclasseswithmembers class com.checkout.threeds.ui.widgets.** {
    public <init>(android.content.Context, android.util.AttributeSet);
}
-keepclasseswithmembers class com.checkout.threeds.ui.widgets.** {
    public <init>(android.content.Context, android.util.AttributeSet, int);
}

# Sessions REST layer. SessionsRestApi's suspend-fun return types are inspected
# reflectively (ParameterizedType/getRawType) by SessionsCallAdapterFactory to
# unwrap SessionsResponse<T> before handing the body to Gson. Without these kept,
# that reflection can fail and Retrofit falls back to its default converter, which
# tries to Gson-instantiate the abstract SessionsResponse itself and throws
# "Abstract classes can't be instantiated". Mirrors the equivalent keeps already
# present in the SDK's own proguard-rules.pro (which this consumer-facing pass does
# not inherit).
-keep class com.checkout.threeds.sessions.data.SessionsRestApi { *; }
-keep class com.checkout.threeds.sessions.data.network.SessionsResponse {
    public <methods>;
    public <fields>;
}
-keep class com.checkout.threeds.sessions.data.network.SessionsCallAdapterFactory { *; }
-keep class com.checkout.threeds.sessions.data.mapper.KeyMapper* {
    public <methods>;
    public <fields>;
}
-keep class com.checkout.threeds.sessions.data.validator.Base64UrlValidatorExtensionKt* {
    public <methods>;
    public <fields>;
}
-keep class com.checkout.threeds.sessions.CheckoutSessionsApi* {
    public <methods>;
    public <fields>;
}
-keep class com.checkout.threeds.sessions.domain.model.* {
    public <methods>;
    public <fields>;
}
-keep class com.checkout.threeds.sessions.data.model.* {
    public <fields>;
}

# ACS network layer — same reflection-based generic-wrapper pattern as the Sessions
# layer above, for the ACS challenge round-trip (AcsApi/ThreeDS1AcsApi's suspend funs
# return AcsResponse<T>, unwrapped by AcsCallAdapterFactory). Without these, creq/cres
# calls hit the same "Abstract classes can't be instantiated" Gson failure on
# AcsResponse. Mirrors the equivalent keeps in the SDK's own proguard-rules.pro.
-keep class com.checkout.threeds.data.network.api.AcsApi { *; }
-keep class com.checkout.threeds.data.network.api.ThreeDS1AcsApi { *; }
-keep class com.checkout.threeds.data.network.impl.AcsResponse { *; }
-keep class com.checkout.threeds.data.network.impl.AcsCallAdapterFactory { *; }

# =====================================================================
# 4. Reflection member safety nets
# =====================================================================
# Previously these were covered incidentally by the blanket keep. They are now
# explicit so the internal reflection contract survives the merchant's R8 pass even
# though the internal classes themselves may be renamed.

# Parcelable CREATOR required by the Android framework. Scoped to the SDK's own
# packages — a global `class *` match would also block shrinking of the merchant
# app's own unrelated Parcelable classes.
-keepclassmembers class com.checkout.threeds.** implements android.os.Parcelable {
    public static final ** CREATOR;
}
-keepclassmembers class com.checkout.threedsobfuscation.** implements android.os.Parcelable {
    public static final ** CREATOR;
}

# Gson: model classes annotated with @JsonAdapter plus custom adapters registered in
# Checkout3DSContext / SessionContext. (@SerializedName <fields> and TypeAdapter /
# JsonSerializer / JsonDeserializer keeps are provided by common-consumer-rules.pro.)
# Scoped to the SDK's own packages for the same reason as the Parcelable rule above.
-keep @com.google.gson.annotations.JsonAdapter class com.checkout.threeds.** { *; }
-keep @com.google.gson.annotations.JsonAdapter class com.checkout.threedsobfuscation.** { *; }

# Enums matched against server / client strings by name via toEnumOrNull() / valueOf().
# Renaming the constants silently turns every lookup into null / UNKNOWN.
# Enums retained under original names (ACS models, sessions models, challenge models):
-keepclassmembers enum com.checkout.threeds.data.acs.** {
    <fields>;
    public static **[] values();
    public static ** valueOf(java.lang.String);
}
-keepclassmembers enum com.checkout.threeds.sessions.data.model.** {
    <fields>;
    public static **[] values();
    public static ** valueOf(java.lang.String);
}
-keepclassmembers enum com.checkout.threeds.domain.model.** {
    <fields>;
    public static **[] values();
    public static ** valueOf(java.lang.String);
}
# Enums repackaged into the obfuscation package (e.g. Scheme, ThreeDS1ChallengeStatus).
-keepclassmembers enum com.checkout.threedsobfuscation.** {
    <fields>;
    public static **[] values();
    public static ** valueOf(java.lang.String);
}

# =====================================================================
# 5. Third-party runtime dependencies used by the SDK
# =====================================================================
# Bouncy Castle is an internal runtime dependency (not exposed as a compile-time API).
# These -keep rules prevent R8 from stripping BC algorithm implementation classes
# that are registered via string-based reflection inside BouncyCastleProvider.
#
# The `!org.bouncycastle.pqc.**` negator (evaluated first) drops the post-quantum crypto
# family, which 3DS never uses (~1 MB of DEX) — see AUTH-6482 for rationale.
# Everything else under org.bouncycastle is still kept verbatim for the
# reflective provider registration. NOTE: BouncyCastleProvider resolves algorithm classes
# reflectively at init, so an over-tight rule can break crypto at runtime. Any change to
# these rules must therefore be validated on a minified release build that exercises a real
# 3DS2 authentication end to end (device-data collection through challenge completion) before
# release — a successful compile proves nothing here.
-keep class !org.bouncycastle.pqc.**, org.bouncycastle.** { *; }
-keep interface !org.bouncycastle.pqc.**, org.bouncycastle.** { *; }
-keep class com.nimbusds.** { *; }
-keep interface com.nimbusds.** { *; }

# NOTE: the previous blanket `-keep class com.google.gson.** { *; }` and
# `-keep class/interface okhttp3.** { *; }` rules were removed (AUTH-6482): both libraries
# are R8-friendly and ship their own rules, and defeating tree-shaking on them kept unused
# code (okhttp3.internal.ws/http2, gson.internal.sql, …) in every merchant APK. Gson's
# reflection contract is preserved by the @SerializedName / TypeAdapter / @JsonAdapter keeps
# in common-consumer-rules.pro and section 4 above.

# ===== Suppress warnings for optional / platform dependencies =====
-dontwarn com.google.crypto.tink.**
