Skip to content

Commit 9f146c3

Browse files
committed
feat: initial commit for combined sdk
Signed-off-by: Gaurav Goel <[email protected]>
1 parent f787920 commit 9f146c3

File tree

12 files changed

+230
-65
lines changed

12 files changed

+230
-65
lines changed

app/src/main/java/com/web3auth/app/MainActivity.kt

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,18 @@ import com.web3auth.core.isPhoneNumberValid
2424
import com.web3auth.core.types.AuthConnection
2525
import com.web3auth.core.types.AuthConnectionConfig
2626
import com.web3auth.core.types.BuildEnv
27-
import com.web3auth.core.types.ChainConfig
2827
import com.web3auth.core.types.ChainNamespace
28+
import com.web3auth.core.types.Chains
2929
import com.web3auth.core.types.ExtraLoginOptions
3030
import com.web3auth.core.types.Language
3131
import com.web3auth.core.types.LoginParams
32-
import com.web3auth.core.types.MFALevel
3332
import com.web3auth.core.types.ThemeModes
3433
import com.web3auth.core.types.UserInfo
35-
import com.web3auth.core.types.Web3AuthNetwork
3634
import com.web3auth.core.types.Web3AuthOptions
3735
import com.web3auth.core.types.Web3AuthResponse
3836
import com.web3auth.core.types.WhiteLabelData
3937
import org.json.JSONObject
38+
import org.torusresearch.fetchnodedetails.types.Web3AuthNetwork
4039
import org.web3j.crypto.Credentials
4140
import java.util.concurrent.CompletableFuture
4241

@@ -85,12 +84,11 @@ class MainActivity : AppCompatActivity(), AdapterView.OnItemClickListener {
8584
extraLoginOptions = ExtraLoginOptions(login_hint = hintPhNo)
8685
}
8786

88-
val loginCompletableFuture: CompletableFuture<Web3AuthResponse> = web3Auth.login(
87+
val loginCompletableFuture: CompletableFuture<Web3AuthResponse> = web3Auth.connectTo(
8988
LoginParams(
90-
selectedLoginProvider,
91-
extraLoginOptions = extraLoginOptions,
92-
mfaLevel = MFALevel.OPTIONAL
93-
)
89+
AuthConnection.GOOGLE,
90+
authConnectionId = "w3ads", groupedAuthConnectionId = "aggregate-mobile"
91+
), ctx = this.applicationContext
9492
)
9593
loginCompletableFuture.whenComplete { _, error ->
9694
if (error == null) {
@@ -164,10 +162,28 @@ class MainActivity : AppCompatActivity(), AdapterView.OnItemClickListener {
164162
override fun onCreate(savedInstanceState: Bundle?) {
165163
super.onCreate(savedInstanceState)
166164
setContentView(R.layout.activity_main)
165+
val authConfig = ArrayList<AuthConnectionConfig>()
166+
authConfig.add(
167+
AuthConnectionConfig(
168+
authConnection = AuthConnection.GOOGLE,
169+
authConnectionId = "w3ads",
170+
groupedAuthConnectionId = "aggregate-mobile",
171+
clientId = "519228911939-snh959gvvmjieoo4j14kkaancbkjp34r.apps.googleusercontent.com"
172+
)
173+
)
174+
175+
authConfig.add(
176+
AuthConnectionConfig(
177+
authConnection = AuthConnection.CUSTOM,
178+
authConnectionId = "auth0-test",
179+
groupedAuthConnectionId = "aggregate-mobile",
180+
clientId = "hUVVf4SEsZT7syOiL0gLU9hFEtm2gQ6O"
181+
)
182+
)
167183

168184
val options = Web3AuthOptions(
169-
clientId = "BFuUqebV5I8Pz5F7a5A2ihW7YVmbv_OHXnHYDv6OltAD5NGr6e-ViNvde3U4BHdn6HvwfkgobhVu4VwC-OSJkik",
170-
web3AuthNetwork = Web3AuthNetwork.SAPPHIRE_DEVNET,
185+
clientId = "BPi5PB_UiIZ-cPz1GtV5i1I2iOSOHuimiXBI0e-Oe_u6X3oVAbCiAZOTEBtTXw4tsluTITPqA8zMsfxIKMjiqNQ",
186+
web3AuthNetwork = Web3AuthNetwork.SAPPHIRE_MAINNET,
171187
redirectUrl = Uri.parse("torusapp://org.torusresearch.web3authexample"),
172188
//sdkUrl = "https://auth.mocaverse.xyz",
173189
//walletSdkUrl = "https://lrc-mocaverse.web3auth.io",
@@ -179,13 +195,14 @@ class MainActivity : AppCompatActivity(), AdapterView.OnItemClickListener {
179195
"onPrimary" to "#0000FF"
180196
)
181197
),
182-
authConnectionConfig = listOf(
183-
AuthConnectionConfig(
184-
authConnectionId = "web3auth-auth0-email-passwordless-sapphire-devnet",
185-
authConnection = AuthConnection.CUSTOM,
186-
clientId = "d84f6xvbdV75VTGmHiMWfZLeSPk8M07C"
187-
)
188-
),
198+
authConnectionConfig = authConfig,
199+
/*listOf(
200+
AuthConnectionConfig(
201+
authConnectionId = "web3auth-auth0-email-passwordless-sapphire-devnet",
202+
authConnection = AuthConnection.GOOGLE,
203+
clientId = "d84f6xvbdV75VTGmHiMWfZLeSPk8M07C"
204+
)
205+
),*/
189206
authBuildEnv = BuildEnv.TESTING,
190207
sessionTime = 86400,
191208
)
@@ -225,7 +242,7 @@ class MainActivity : AppCompatActivity(), AdapterView.OnItemClickListener {
225242
launchWalletButton.setOnClickListener {
226243
val launchWalletCompletableFuture = web3Auth.showWalletUI(
227244
chainConfig = listOf(
228-
ChainConfig(
245+
Chains(
229246
chainId = "0x89",
230247
rpcTarget = "https://1rpc.io/matic",
231248
chainNamespace = ChainNamespace.EIP155
@@ -251,7 +268,7 @@ class MainActivity : AppCompatActivity(), AdapterView.OnItemClickListener {
251268
add("Android")
252269
}
253270
val signMsgCompletableFuture = web3Auth.request(
254-
chainConfig = ChainConfig(
271+
chainConfig = Chains(
255272
chainId = "0x89",
256273
rpcTarget = "https://polygon-rpc.com/",
257274
chainNamespace = ChainNamespace.EIP155

core/build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ dependencies {
7878

7979
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.2.0-alpha01"
8080

81+
api 'org.torusresearch:torus-utils-java:4.0.3'
82+
api 'org.torusresearch:fetch-node-details-java:5.0.0'
83+
implementation 'com.auth0.android:jwtdecode:2.0.2'
84+
8185
// Test
8286
testImplementation 'junit:junit:4.+'
8387
androidTestImplementation 'androidx.test.ext:junit:1.2.1'

core/src/main/java/com/web3auth/core/api/ApiHelper.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ import android.net.ConnectivityManager
55
import android.net.NetworkCapabilities
66
import android.os.Build
77
import com.google.gson.GsonBuilder
8-
import com.web3auth.core.types.Web3AuthNetwork
98
import com.web3auth.session_manager_android.BuildConfig
109
import okhttp3.OkHttpClient
1110
import okhttp3.logging.HttpLoggingInterceptor
11+
import org.torusresearch.fetchnodedetails.types.Web3AuthNetwork
1212
import retrofit2.Retrofit
1313
import retrofit2.converter.gson.GsonConverterFactory
1414
import java.util.concurrent.TimeUnit
1515

1616
object ApiHelper {
1717
// TODO: Abstract this to a single common source, i.e torus-common, then add these to here and fetch-node-details, etc respectively
18-
val SIGNER_MAP: Map<Web3AuthNetwork, String> = mapOf(
18+
private val SIGNER_MAP: Map<Web3AuthNetwork, String> = mapOf(
1919
Web3AuthNetwork.MAINNET to "https://signer.web3auth.io",
2020
Web3AuthNetwork.TESTNET to "https://signer.web3auth.io",
2121
Web3AuthNetwork.CYAN to "https://signer-polygon.web3auth.io",

core/src/main/java/com/web3auth/core/types/ChainConfig.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import androidx.annotation.Keep
44
import java.io.Serializable
55

66
@Keep
7-
data class ChainConfig(
7+
data class Chains(
88
@Keep val chainNamespace: ChainNamespace = ChainNamespace.EIP155,
99
@Keep val decimals: Int? = 18,
1010
@Keep val blockExplorerUrl: String? = null,
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
package com.web3auth.core.types
22

3-
import android.net.Uri
43
import androidx.annotation.Keep
54

65
@Keep
76
data class LoginParams(
87
@Keep val authConnection: AuthConnection,
98
@Keep val authConnectionId: String? = null,
109
@Keep val groupedAuthConnectionId: String? = null,
11-
@Keep var dappShare: String? = null,
12-
@Keep val extraLoginOptions: ExtraLoginOptions? = null,
13-
@Keep @Transient var redirectUrl: Uri? = null,
1410
@Keep val appState: String? = null,
1511
@Keep val mfaLevel: MFALevel? = null,
12+
@Keep val extraLoginOptions: ExtraLoginOptions? = null,
13+
@Keep var dappShare: String? = null,
1614
@Keep val curve: Curve? = Curve.SECP256K1,
17-
@Keep val dappUrl: String? = null
15+
@Keep val dappUrl: String? = null,
16+
@Keep var login_hint: String? = null,
17+
@Keep val idToken: String? = null,
1818
)
Lines changed: 82 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.web3auth.core.types
22

33
import androidx.annotation.Keep
4+
import com.google.gson.annotations.SerializedName
45

56
@Keep
67
data class WhitelistResponse(
@@ -10,9 +11,88 @@ data class WhitelistResponse(
1011

1112
@Keep
1213
data class ProjectConfigResponse(
13-
@Keep val whitelabel: WhiteLabelData? = null,
14+
@Keep var userDataIncludedInToken: Boolean? = true,
15+
@Keep val sessionTime: Int? = 30 * 86400,
16+
@Keep val enableKeyExport: Boolean? = false,
17+
@Keep val whitelist: WhitelistResponse?,
18+
@Keep val chains: Chains? = null,
19+
@Keep val smartAccounts: SmartAccountsConfig? = null,
20+
@Keep val walletUiConfig: WalletUiConfig? = null,
21+
@Keep val embeddedWalletAuth: AuthConnectionConfig? = null,
1422
@Keep val sms_otp_enabled: Boolean,
1523
@Keep val wallet_connect_enabled: Boolean,
1624
@Keep val wallet_connect_project_id: String?,
17-
@Keep val whitelist: WhitelistResponse?,
25+
@Keep val whitelabel: WhiteLabelData? = null,
26+
27+
)
28+
29+
@Keep
30+
data class SmartAccountsConfig(
31+
@SerializedName("smartAccountType")
32+
val smartAccountType: SmartAccountType,
33+
34+
@SerializedName("walletScope")
35+
val walletScope: SmartAccountWalletScope,
36+
37+
@SerializedName("chains")
38+
val chains: List<ChainConfig>
39+
)
40+
41+
@Keep
42+
data class ChainConfig(
43+
@SerializedName("chainId")
44+
val chainId: String,
45+
46+
@SerializedName("bundlerConfig")
47+
val bundlerConfig: BundlerConfig,
48+
49+
@SerializedName("paymasterConfig")
50+
val paymasterConfig: PaymasterConfig? = null
51+
)
52+
53+
@Keep
54+
data class BundlerConfig(
55+
@SerializedName("url")
56+
val url: String
1857
)
58+
59+
@Keep
60+
data class PaymasterConfig(
61+
@SerializedName("url")
62+
val url: String
63+
)
64+
65+
@Keep
66+
enum class SmartAccountType {
67+
@SerializedName("biconomy")
68+
BICONOMY,
69+
70+
@SerializedName("kernel")
71+
KERNEL,
72+
73+
@SerializedName("safe")
74+
SAFE,
75+
76+
@SerializedName("trust")
77+
TRUST,
78+
79+
@SerializedName("light")
80+
LIGHT,
81+
82+
@SerializedName("simple")
83+
SIMPLE,
84+
85+
@SerializedName("nexus")
86+
NEXUS
87+
}
88+
89+
@Keep
90+
enum class SmartAccountWalletScope {
91+
@SerializedName("embedded")
92+
EMBEDDED,
93+
94+
@SerializedName("all")
95+
ALL
96+
}
97+
98+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.web3auth.core.types
2+
3+
import androidx.annotation.Keep
4+
import java.io.Serializable
5+
6+
@Keep
7+
data class TorusGenericContainer(
8+
@Keep val params: Map<String, String>
9+
) : Serializable
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.web3auth.core.types
2+
3+
import androidx.annotation.Keep
4+
import com.google.gson.annotations.SerializedName
5+
6+
@Keep
7+
data class WalletServicesConfig(
8+
@Keep val confirmationStrategy: ConfirmationStrategy? = ConfirmationStrategy.DEFAULT,
9+
@Keep val whiteLabelData: WhiteLabelData? = null
10+
)
11+
12+
@Keep
13+
enum class ConfirmationStrategy {
14+
@SerializedName("popup")
15+
POPUP,
16+
17+
@SerializedName("modal")
18+
MODAL,
19+
20+
@SerializedName("auto-approve")
21+
AUTO_APPROVE,
22+
23+
@SerializedName("default")
24+
DEFAULT
25+
}
26+
27+
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.web3auth.core.types
2+
3+
import com.google.gson.annotations.SerializedName
4+
5+
data class WalletUiConfig(
6+
val enablePortfolioWidget: Boolean? = null,
7+
val enableConfirmationModal: Boolean? = null,
8+
val enableWalletConnect: Boolean? = null,
9+
val enableTokenDisplay: Boolean? = null,
10+
val enableNftDisplay: Boolean? = null,
11+
val enableShowAllTokensButton: Boolean? = null,
12+
val enableBuyButton: Boolean? = null,
13+
val enableSendButton: Boolean? = null,
14+
val enableSwapButton: Boolean? = null,
15+
val enableReceiveButton: Boolean? = null,
16+
val portfolioWidgetPosition: ButtonPositionType? = null,
17+
val defaultPortfolio: DefaultPortfolioType? = null
18+
)
19+
20+
enum class ButtonPositionType {
21+
@SerializedName("bottom-left")
22+
BOTTOM_LEFT,
23+
24+
@SerializedName("top-left")
25+
TOP_LEFT,
26+
27+
@SerializedName("bottom-right")
28+
BOTTOM_RIGHT,
29+
30+
@SerializedName("top-right")
31+
TOP_RIGHT
32+
}
33+
34+
enum class DefaultPortfolioType {
35+
@SerializedName("token")
36+
TOKEN,
37+
38+
@SerializedName("nft")
39+
NFT
40+
}

core/src/main/java/com/web3auth/core/types/Web3AuthError.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ object Web3AuthError {
4646
ErrorCode.USER_CANCELLED -> {
4747
"User Cancelled"
4848
}
49+
50+
ErrorCode.USER_ALREADY_ENABLED_MFA -> {
51+
"User has already enabled MFA"
52+
}
4953
}
5054
}
5155
}
@@ -61,5 +65,6 @@ enum class ErrorCode {
6165
INVALID_LOGIN,
6266
MFA_ALREADY_ENABLED,
6367
MFA_NOT_ENABLED,
64-
USER_CANCELLED
68+
USER_CANCELLED,
69+
USER_ALREADY_ENABLED_MFA
6570
}

0 commit comments

Comments
 (0)